Jump to content

iwato

Members
  • Posts

    1,506
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by iwato

  1. In answer to your question: I am including one of two script tags referenced by the FireFox Debugger panel whose $ namespace is not defined. In this example, the Debugger panel points specifically to the jQuery ready function. <body ng-app="app" class="widgetized"> <div piwik-popover-handler></div> <div class="widget"> <script type="text/javascript" charset="utf-8"> $(document).ready(function () { var segment = broadcast.getValueFromHash('segment'); if (!segment) { segment = broadcast.getValueFromUrl('segment'); } $('#visitsLive').liveWidget({ interval: 5000, onUpdate: function () { //updates the numbers of total visits in startbox var ajaxRequest = new ajaxHelper(); ajaxRequest.setFormat('html'); ajaxRequest.addParams({ module: 'Live', action: 'ajaxTotalVisitors', segment: segment }, 'GET'); ajaxRequest.setCallback(function (r) { $("#visitsTotal").html(r); }); ajaxRequest.send(false); }, maxRows: 10, fadeInSpeed: 600, dataUrlParams: { module: 'Live', action: 'getLastVisitsStart', segment: segment } }); }); </script> In the <head> tag the following several additional scripts appear. The three dots ... represent script content that I have eliminated for the sake of brevity and better clarity. <script type="text/javascript"> var piwik = {}; piwik.token_auth = "..."; piwik.piwik_url = "https://.../matomo/"; piwik.cacheBuster = "..."; piwik.numbers = { patternNumber: "#,##0.###", patternPercent: "#,##0%", patternCurrency: "ยค#,##0.00", symbolPlus: "+", symbolMinus: "-", symbolPercent: "%", symbolGroup: ",", symbolDecimal: "." }; piwik.userLogin = "..."; piwik.idSite = "1"; piwik.siteName = "Grammar\x20Captive"; piwik.siteMainUrl = "https\x3A\x2F\x2F...matomo"; piwik.period = "day"; piwik.currentDateString = "2018-06-09"; piwik.startDateString = "2018-06-09"; piwik.endDateString = "2018-06-09"; piwik.minDateYear = 2018; piwik.minDateMonth = parseInt("02", 10); piwik.minDateDay = parseInt("22", 10); piwik.maxDateYear = 2018; piwik.maxDateMonth = parseInt("06", 10); piwik.maxDateDay = parseInt("09", 10); piwik.language = "en"; piwik.hasSuperUserAccess = 1; piwik.config = {}; piwik.config = {"action_url_category_delimiter":"\/","action_title_category_delimiter":"\/","autocomplete_min_sites":5,"datatable_export_range_as_day":"rss","datatable_row_limits":["5","10","25","50","100","250","500","-1"],"are_ads_enabled":true}; piwik.hasServerDetectedHttps = true; piwik.languageName = 'English'; </script> <!--[if lt IE 9]> <script language="javascript" type="text/javascript" src="libs/jqplot/excanvas.min.js"></script> <![endif]--> <link rel="stylesheet" type="text/css" href="index.php?module=Proxy&amp;action=getCss&amp;cb=..." /> <script type="text/javascript"> var translations = {"CorePluginsAdmin_NoZipFileSelected":"Please select a ZIP file.", ... { piwik_translations[i] = translations[i];} </script> <script type="text/javascript"> var translations = {"CorePluginsAdmin_NoZipFileSelected":"Please select a ZIP file."," ... ", LogViewer_ExportThisSearch":"Export this search as %1$s containing the latest %2$s entries. The download may take a few minutes..."}; if (typeof(piwik_translations) == 'undefined') { var piwik_translations = new Object; }for(var i in translations) { piwik_translations[i] = translations[i];} </script><script type="text/javascript" src="index.php?module=Proxy&action=getCoreJs&cb=..."></script> <script type="text/javascript" src="index.php?module=Proxy&action=getNonCoreJs&cb=..."></script> For what it is worth I am also including the attributes of the <html> tag. <!DOCTYPE html> <html id="ng-app" ng-app="piwikApp"> Roddy
  2. QUESTION: As far as the loading of jQuery -- or Javascript of any sort, for that matter -- is there any difference between an HTTP Request using say, "https://..." or "http://...", and a relative link say, "../../widget.html"? Please allow me to explain. I have a file located on my local server. When this file is loaded the following things happen: 1) The jQuery library is loaded in the <head> element with a <script> tag. 2) An iframe is created with a src attribute that makes a request to the Matomo reporting API on a third party server The prefix used to make the HTTP request is https://. 3) An iframe is created with a src attribute whose value is a relative link that points to another file on my local server. This file bears a .php extension and makes an HTTP request via cURL to the same address as indicated in Item 2) above. The iframe filled in Item 2) is filled with a fully functional widget produced by Matomo. The iframe filled in Item 3) contains much of the same data and text that the widget in Item 2) contains, but much of the widgets formatting and all of its functionality are missing. When the PHP file that makes the request is examined via the Firefox Debugger tab, Firefox reports that the jQuery namespace -- namely, $ -- cannot be found. What I understand from this is: 1) the contents of the iframe must be complete before it is introduced into the page, else it will not render properly. 2) the cURL call to the Matomo API is improperly specified and is capturing the full nature of the widget -- namely, the missing jQuery. Does this make sense to you? If so, can you provide any suggesting in regard to what is missing in the cURL request. Roddy
  3. Alas! I believe that I have discovered the reason why the Matomo widgets are not rendering properly when I import them indirectly via a relative link. While using FireFox's Debugger Menu in the WebConsole I discovered that the imported widget does not recognize the $ sign. Upon closer examination it was determined that, yes, like me, Matomo makes use of jQuery. This raises at least two questions: Why does the jQuery present on the page when the Matomo widget is introduced via an HTTP request allow the widget to behave properly, but the jQuery on the page does not permit the widget to function properly when the widget is introduced via a relative link to a page whose contents are filled with a cURL call to the Matomo reporting API. Is it a matter of timing -- i.e. when the Javascript is called? If all that is missing is a link to the jQuery CDN (this is still an untested hypothesis) where must I enter it so that it is called "on time"? And, via what means? If my hypothesis is true, and the above two problems are solved, then what is the best way to read the widget into the iframe element, if it is not recommended to fill a src tag with a relative link. Is this a job for the jQuery $.get() request? Roddy
  4. Matomo does so much more, and it is the only free package that I know that offers so much. What is more, I did not discover the current hurdle until I was already far along into understanding how the package works. It is quite involved. Roddy
  5. Please, I can make the second button work by simply declaring the secTranslate( ) function in the body of the document -- thus, placing it within the scope of the document -- this, I have known for a very long time. At least, now I have a good explanation for why this works. It is something that has always worked, but I have never clearly understood. The problem, then, has to do with the ready( ) function, and why it sometimes works and sometimes does not in similar, but obviously different contexts. Even now I believe to have the answer to this. According to StackOverflow functions declared within the ready() function are not within the global scope, and it is within the global scope that the onclick() function is looking. Surely you must agree with this interpretation. It has been a great lesson for me! Hooray! Hooray! Roddy
  6. Great! This means that we are making progress. Now, if you are able, why would the first button-alert work, but not the second. For, this is, indeed, the issue, is it not? Roddy
  7. And, I would not expect there to be. For, I have already stated that I can achieve the same on load in the ready() function without the alert-button. Roddy
  8. The problem is where you are using it, the scope. You haven't shown that context, so this is a lot of assuming from me but it's all I can do with the limited information. But, I have shown the context. All that is left is HTML, and I have checked this as well. Nothing bad is reported.
  9. Do the terms undefined and not defined mean the same thing? I have seen the term undefined returned when a value for a variable is not present. So, would it not apply here as well? Roddy
  10. That we not become distracted. It is only in the following context that the secTranslate( ) function fails. <script> var num = 5; </script> <button onclick="alert(num.annotate('sec'));">Alert!</button> <script> var sec_num = 59039; </script> <button onclick="alert(secTranslate(sec_num));">Alert!</button> When run at load time within the jQuery ready() function the following two lines of code produce the desired result var sec_num = 59039; alert(secTranslate(sec_num)); -- namely, Roddy
  11. With no argument about the failure of the modification to produce the desired result, why would having placed the .annotate( ) declaration inside the secTranslate( ) not have been a potential source of solution? After all, if the return value of the .annotate( ) function were not achieved, then the secTranslate( ) function would necessarily fail. Roddy
  12. So, I placed the declaration(definition) of the .annotate() function inside the secTranslate() function and commented out the original declaration. Obviously the first button-alert was no longer possible, but it did nothing to remove the error response for the second button-alert. Roddy
  13. It is a plain simple function that makes use of the function that precedes it in the ready statement. Number.prototype.annotate = function(unit) { var s = String(this); var unit = String(unit); s = s + " " + unit; return s; } function secTranslate(sec_duration) { var hrCount = Math.floor(sec_duration / 3600); sec_duration %= 3600; var minCount = Math.floor(sec_duration / 60); var secCount = sec_duration % 60; return hrCount.annotate('hr') + " " + minCount.annotate('min') + " " + secCount.annotate('sec'); } Roddy
  14. BACKGROUND I have created two functions both of which have been tested and function as expected -- so well, in fact, that one of them can be used to enhance the output of the other. The problem arises when I seek to call these functions with separate button alerts provided below in the order given. Both functions are defined in a jQuery ready statement. BUTTON ALERTS <script> var num = 5; </script> <button onclick="alert(num.annotate('sec'));">Alert!</button> <script> var sec_num = 59039; </script> <button onclick="alert(secTranslate(sec_num));">Alert!</button> DILEMMA: Although the first button-alert works, the second fails with the following error message: "ReferenceError: secTranslate is not defined." with a reference to the onclick attribute. QUESTION: How does one explain this phenomenon? Roddy
  15. You are not the only one to complain about connectivity with my host server. I have also been suffering significant delays. In any case, I sent that portion of the above entry to Lunarpages and asked that they look into the problem. In regard to the authorization token, it is not the information per se that I am concerned about; rather, it is how the information is interpreted and by whom. My goal is to present Grammar Captive in the best way possible -- not to stand naked before the world. I am going through a lot of trouble to explain each statistic that I present. Did you not click on any of the variable names? I, too, have noted that the splash panel is resource-intensive, but its value as an introductory tool has yet to be tested. Certainly it is one of my priorities. Also, it should not appear, but once in any single session, and return users know to dump it just as you have already learned to do. Eventually, I will squelch it automatically via a cookie and counter after the third return visit. Did you not read the casual FAQ that goes with the Looking Glass? It responds well to your very criticism. By the way, your IP address is obtained indirectly via the Matomo reporting API; it is only one of many pieces of information returned when the relevant request is sent to Matomo. It is that delay, in part, that i am seeking to eliminate via direct PHP functional calls.
  16. But it does eliminate having to expose the authorization token. The whole purpose of this and another discussion. If I took the easy route I would expose, in effect, my entire Matomo data base to read access. This has been confirmed by Matomo's forum monitors. I do not wish to take the easy route in this case. Roddy
  17. Rather than asking me to expose my already very vulnerable operating environment, please provide me with the syntax error so that I might fix the problem. Roddy
  18. This would mean curtailing what I have already set out to do. See Your Data and You and Sponsors Overview at Grammar Captive overview. The authorization token is invisible on these pages. What everyone else does is stupidly expose their token thus giving to knowledgeable Matomo users full access to the reporting API. There are things in the API that even I whom am now somewhat knowledgeable to not know how to interpret. By the way, one must strike a balance between coding, learning to code, and user experience. View the aforementioned sections and try to convince me that the delay is created by jQuery. Your best logic and experimentation will not succeed. And, mind you, I am well -open to both. Roddy
  19. OK. I have now tried my first Number function. Unfortunately, I did not succeed. Please find the original workable code followed by the unworkable newly introduced code. WORKABLE CODE: $('#so_average_time_spent').html(visitsSummary[0].avg_time_on_site); The FUNCTION: Number.prototype.annotate = function(String(unit)) { var s = String(this); s = s + " " + unit; return s; } The APPLICATION: var avgSiteTime = visitsSummary[0].avg_time_on_site; $('#so_average_time_spent').html(avgSiteTime.annotate('sec')); There are no error messages. Roddy
  20. Dsonesuk: Please read the phrase "is returned as' to mean "is returned by the FireFox Web Console as". So, I have experimented with your code in a fresh document with some minor alterations of my own to test its robustness in a new CSS environment. It performs as expected in one way, but not in another. Can you explain why the following code works, but what follows does not. Are they not both doing the same thing? Dsonesuk's Expression <script> arrayObject4 = ["a", "b", "c", "d", "e", "f", "g", "h"]; var x = document.getElementById("specificID"); arrayObject4.testArray4(undefined, x); </script> Roddy's Expression <script> arrayObject4 = ["a", "b", "c", "d", "e", "f", "g", "h"]; var x = $('#specificID'); arrayObject4.testArray4(undefined, x); </script> Roddy
  21. Dsonesuk: this.parentElem.appendChild(this.newElem); is returned as this.appendChild(this.newElem); and appendChild(this.newElem) is declared to be "not a function". Roddy
  22. If, by file URL, you mean links that are preceded by the prefix file://, it is not my intention. I am using what are popularly known as relative links. The host file and src file reside on the same server. Content of the file is being loaded via cURL It is helpful that you mention that cURL does not involved the browser. I did not know this, but it certainly explains why it is often invoked via terminal. In the end, it would be much better that I could avoid having to use HTTP requests all together. Matomo already takes forever to load. Roddy
  23. The goal is to write a PHP class that will allow me to by-pass having to use HTTP requests to access the Matomo reporting API. As I mentioned very early Matomo is a thicket of interlacing classes and namespaces that on the surface appears impenetrable. When i look at the following public function I am inspired because its arguments mirror one-for-one, although structured differently, the content of a Matomo HTTP request query string. The processRequest( ) Function public static function processRequest($method, $paramOverride = array(), $defaultRequest = null) { $params = array(); $params['format'] = 'original'; $params['serialize'] = '0'; $params['module'] = 'API'; $params['method'] = $method; $params = $paramOverride + $params; // process request $request = new Request($params, $defaultRequest); return $request->process(); } The process( ) Function public function process() { // read the format requested for the output data $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $this->request)); $disablePostProcessing = $this->shouldDisablePostProcessing(); // create the response $response = new ResponseBuilder($outputFormat, $this->request); if ($disablePostProcessing) { $response->disableDataTablePostProcessor(); } $corsHandler = new CORSHandler(); $corsHandler->handle(); $tokenAuth = Common::getRequestVar('token_auth', '', 'string', $this->request); $shouldReloadAuth = false; try { // IP check is needed here as we cannot listen to API.Request.authenticate as it would then not return proper API format response. // We can also not do it by listening to API.Request.dispatch as by then the user is already authenticated and we want to make sure // to not expose any information in case the IP is not whitelisted. $whitelist = new LoginWhitelist(); if ($whitelist->shouldCheckWhitelist() && $whitelist->shouldWhitelistApplyToAPI()) { $ip = IP::getIpFromHeader(); $whitelist->checkIsWhitelisted($ip); } // read parameters $moduleMethod = Common::getRequestVar('method', null, 'string', $this->request); list($module, $method) = $this->extractModuleAndMethod($moduleMethod); list($module, $method) = self::getRenamedModuleAndAction($module, $method); PluginManager::getInstance()->checkIsPluginActivated($module); $apiClassName = self::getClassNameAPI($module); if ($shouldReloadAuth = self::shouldReloadAuthUsingTokenAuth($this->request)) { $access = Access::getInstance(); $tokenAuthToRestore = $access->getTokenAuth(); $hadSuperUserAccess = $access->hasSuperUserAccess(); self::forceReloadAuthUsingTokenAuth($tokenAuth); } // call the method $returnedValue = Proxy::getInstance()->call($apiClassName, $method, $this->request); $toReturn = $response->getResponse($returnedValue, $module, $method); } catch (Exception $e) { Log::debug($e); $toReturn = $response->getResponseException($e); } if ($shouldReloadAuth) { $this->restoreAuthUsingTokenAuth($tokenAuthToRestore, $hadSuperUserAccess); } return $toReturn; } The getRequestVar( ) Function $tokenAuth = Common::getRequestVar('token_auth', '', 'string', $this->request); I suppose, for example, that i could satisfy the values of this function manually. Looking Forward It would appear that I have two avenues ahead: one, figure out how to overcome the missing format of the imported widgets; or two how to access the Matomo reporting API through direct PHP calls. This latter is likely the more difficult route, but it is also likely to result in overall better efficiency, as it would circumvent the need for HTTP requests. Roddy
  24. JSG: Yes, jQuery is Javascript, but it is specially wrapped Javascript, and I am still trying to understand the prototype object and use of the prototype property. Ingolme: Yes, I have used document .write() many times in my own notes, because I tire quickly of the alert( ) function. When the document is properly opened and closed the side effects that you mentioned can be avoided. I was hoping that jQuery would allow me to get around having to use it. Dsoneuk: Yes, your .testArray3( ) function works as far as the vertical structure of the document is concerned, but it simply ignores the CSS context into which it is inserted. Could this be avoided by assigning as a parent element something more specific than that of the document's body? If so, how would one go about selecting a named, rather than a generic element? If no, what would you suggest. Roddy
  25. Sometimes we appear to talk past one another. Roddy
×
×
  • Create New...