iwato Posted June 9, 2018 Author Share Posted June 9, 2018 (edited) In answer to your question: Quote Also do the widget files use '$' at all? are you mixing? 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&action=getCss&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 Edited June 9, 2018 by iwato Link to comment Share on other sites More sharing options...
iwato Posted June 9, 2018 Author Share Posted June 9, 2018 If the absence of the jQuery library is, indeed, the source of the problem, then how would I add the <script> element that loads the library to the file imported by the cURL call? It appears that cURL has several options to achieve such a task. Roccy Link to comment Share on other sites More sharing options...
dsonesuk Posted June 9, 2018 Share Posted June 9, 2018 You can test it yourself, add simple jQuery code with $(document).ready(function() { }); (or simply just this) with no link to jQuery library files, and see if you get the same message. Unless the links to jQuery library files are present either by linking directly to jQuery files at their website, your website server folder, or from imported link from wherever, and they don't include JQ library files, or the jquery code is placed above these links you will get this error " '$' is undefined ". 28 minutes ago, iwato said: If the absence of the jQuery library is, indeed, the source of the problem, then how would I add the <script> element that loads the library to the file imported by the cURL call? It appears that cURL has several options to achieve such a task. Roccy changed your name? If you can't include links manually, then, if curl has, as you said, has several ways of doing this, then try them. Link to comment Share on other sites More sharing options...
iwato Posted June 9, 2018 Author Share Posted June 9, 2018 Quote You can test it yourself, add simple jQuery code with $(document).ready(function() { }); (or simply just this) with no link to jQuery library files, and see if you get the same message. But where, and how? If I knew how to do this, I would have done it long ago. Already, before I wrote the above entry, i had tried placing a <script> tag with a src attribute pointing to the jQuery library outside of the <?php ... ?> in the same file in which the cURL resides. It was simply ignored -- perhaps due to the absence of a document or head tag. I know to little about the general use of headers and browsers to know why it failed. Roddy (spelled correctly) Link to comment Share on other sites More sharing options...
iwato Posted June 9, 2018 Author Share Posted June 9, 2018 Do you agree with the following statement from StackOverflow? Quote cURL will only get you the markup of the page. It won't load any additional resources or process the page. You probably want to look at something like PhantomJS for this. PhantomJS is a headless WebKit browser. It has its own API that lets you "script" behavior. So you can tell PhantomJS to load the page and dump out the data you need. Roddy Link to comment Share on other sites More sharing options...
dsonesuk Posted June 9, 2018 Share Posted June 9, 2018 if you use curl_setopt($c, CURLOPT_RETURNTRANSFER, true); where 'true' returns as a string value and assign it to a variable, by doing a simple str_replace () of for instance <html id="ng-app" ng-app="piwikApp"> with <html id="ng-app" ng-app="piwikApp"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> should work. then echo out the amended content. Link to comment Share on other sites More sharing options...
dsonesuk Posted June 9, 2018 Share Posted June 9, 2018 if it loaded link to jQuery library externally from a domain i.E jquery, google. etc, it wouldn't be a problem, however, if the jQuery file is link to from their server folder, then yes! as it is a resource, it would not be downloaded obviously, along with html content data returned. Link to comment Share on other sites More sharing options...
iwato Posted June 9, 2018 Author Share Posted June 9, 2018 Using str_replace( ) was a great idea, and I am a little embarrassed that I did not think of it myself. Although it achieves the task, it does not solve the problem, for as soon as the ready() function is successfully invoked an error is triggered ReferenceError: broadcast is not defined <anonymous> n.Callbacks/j() jquery.min.js:2 n.Callbacks/k.fireWith() jquery.min.js:2 K() widget_map.php:61:13 POST XHR https://www.nudge.online/_utilities/php/matomo/index.php [HTTP/1.1 200 OK 1201ms] and then the POST call is repeated over and over as if in an unending loop. The line of code that triggers the error is, of course, var segment = broadcast.getValueFromHash('segment'); Roddy Link to comment Share on other sites More sharing options...
dsonesuk Posted June 10, 2018 Share Posted June 10, 2018 Are you saying that the code in the document.ready() is not required and causing problem when triggered? if so remove it or edit it with str_replace or preg_replace, so its removed or commented out. This is code i used to remove specific tags and content $html is the code return from curl $html = curl_exec($c); $ElementAndTextRemovalArray = ['<title>', '<style>', '<script>', '<script type="text\/javascript">']; foreach ($ElementAndTextRemovalArray as $eatra) { $html = strip_tags_content($html, $eatra, TRUE); } function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags); $tags = array_unique($tags[1]); if (is_array($tags) AND count($tags) > 0) { if ($invert == FALSE) { return preg_replace('@<(?!(?:' . implode('|', $tags) . ')\b)(\w+)\b.*?>.*?</\1>@si', '', $text); } else { return preg_replace('@<(' . implode('|', $tags) . ')\b.*?>.*?</\1>@si', '', $text); } } elseif ($invert == FALSE) { return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text); } return $text; } Link to comment Share on other sites More sharing options...
iwato Posted June 11, 2018 Author Share Posted June 11, 2018 Quote Are you saying that the code in the document.ready() is not required and causing problem when triggered? if so remove it or edit it with str_replace or preg_replace, so its removed or commented out. No, I am saying that adding the script <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> via the str_replace() removes the namespace problem, but it generates a new problem that I do not understand. For the moment, I have decided to return to the old problem of getting Matomo to work without HTTP requests. There must be a way to simply enter the information contained in the query statement without having to generate an HTTP request. In exploration of this route I have stumbled on something that I have never seen before: a class without a constructor function. The whole of it is given below. It is brief. <?php /** * Piwik - free/libre analytics platform * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ namespace Piwik\Http; use Piwik\Url; /** * Router */ class Router { /** * Filters some malformed URL by suggesting to redirect them. * * E.g. /index.php/.html?... can be interpreted as HTML by old browsers * even though the Content-Type says JSON. * @link https://github.com/piwik/piwik/issues/6156 * * @param string $url The URL to filter. * * @return string|null If not null, then the application should redirect to that URL. */ public function filterUrl($url) { $path = parse_url($url, PHP_URL_PATH); if (strpos($path, 'index.php/') !== false) { return preg_replace('#index\.php/([^\?]*)#', 'index.php', $url, 1); } return null; } } How do you explain such a thing? Roddy Link to comment Share on other sites More sharing options...
Ingolme Posted June 11, 2018 Share Posted June 11, 2018 A constructor is not required for a class. The constructor is merely a place where you can put code that you want to be executed at the moment the object is instantiated. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now