function worldMap() { if (!Piwik_PluginsManager::getInstance()->isPluginActivated('UserCountry')) { return ''; } $idSite = Piwik_Common::getRequestVar('idSite', 1, 'int'); Piwik::checkUserHasViewAccess($idSite); $period = Piwik_Common::getRequestVar('period'); $date = Piwik_Common::getRequestVar('date'); $token_auth = Piwik::getCurrentUserTokenAuth(); $view = Piwik_View::factory('worldmap'); $view->dataUrl = "?module=API" . "&method=API.getProcessedReport&format=XML" . "&apiModule=UserCountry&apiAction=getCountry" . "&idSite=" . $idSite . "&period=" . $period . "&date=" . $date . "&token_auth=" . $token_auth . "&segment=" . Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('segment', '')) . "&filter_limit=-1"; // definition of the color scale $view->hueMin = 218; $view->hueMax = 216; $view->satMin = "0.285"; $view->satMax = "0.9"; $view->lgtMin = ".97"; $view->lgtMax = ".44"; $request = new Piwik_API_Request('method=API.getMetadata&format=PHP' . '&apiModule=UserCountry&apiAction=getCountry' . '&idSite=' . $idSite . '&period=' . $period . '&date=' . $date . '&token_auth=' . $token_auth . '&filter_limit=-1'); $metaData = $request->process(); $metrics = array(); foreach ($metaData[0]['metrics'] as $id => $val) { if (Piwik_Common::getRequestVar('period') == 'day' || $id != 'nb_uniq_visitors') { $metrics[] = array($id, $val); } } foreach ($metaData[0]['processedMetrics'] as $id => $val) { $metrics[] = array($id, $val); } $view->metrics = $metrics; $view->defaultMetric = 'nb_visits'; echo $view->render(); }
public function render() { try { $this->currentModule = Piwik::getModule(); $this->currentPluginName = Piwik::getCurrentPlugin()->getName(); $this->userLogin = Piwik::getCurrentUserLogin(); $showWebsiteSelectorInUserInterface = Zend_Registry::get('config')->General->show_website_selector_in_user_interface; if ($showWebsiteSelectorInUserInterface) { $sites = Piwik_SitesManager_API::getSitesWithAtLeastViewAccess(); usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);')); $this->sites = $sites; } $this->showWebsiteSelectorInUserInterface = $showWebsiteSelectorInUserInterface; $this->url = Piwik_Url::getCurrentUrl(); $this->token_auth = Piwik::getCurrentUserTokenAuth(); $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess(); $this->userIsSuperUser = Piwik::isUserIsSuperUser(); $this->piwik_version = Piwik_Version::VERSION; $this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable(); $this->loginModule = Zend_Registry::get('auth')->getName(); } catch (Exception $e) { // can fail, for example at installation (no plugin loaded yet) } $this->totalTimeGeneration = Zend_Registry::get('timer')->getTime(); try { $this->totalNumberOfQueries = Piwik::getQueryCount(); } catch (Exception $e) { $this->totalNumberOfQueries = 0; } header('Content-Type: text/html; charset=utf-8'); header("Pragma: "); header("Cache-Control: no-store, must-revalidate"); return $this->smarty->fetch($this->template); }
function testClearspring() { $view = Piwik_View::factory('test_widget'); $view->url1 = Piwik_Url::getCurrentUrlWithoutQueryString() . '?module=Widgetize&action=iframe&moduleToWidgetize=Referers&actionToWidgetize=getKeywords&idSite=1&period=day&date=yesterday&filter_limit=5&token_auth=' . Piwik::getCurrentUserTokenAuth(); $view->url2 = Piwik_Url::getCurrentUrlWithoutQueryString() . '?module=Widgetize&action=iframe&moduleToWidgetize=VisitTime&actionToWidgetize=getVisitInformationPerServerTime&idSite=1&period=day&date=yesterday&viewDataTable=graphVerticalBar&show_footer=0&token_auth=' . Piwik::getCurrentUserTokenAuth(); $view->url3 = Piwik_Url::getCurrentUrlWithoutQueryString() . '?module=Widgetize&action=iframe&moduleToWidgetize=Referers&actionToWidgetize=getKeywords&idSite=1&period=day&date=yesterday&viewDataTable=cloud&show_footer=1&filter_limit=15&show_search=false&token_auth=' . Piwik::getCurrentUserTokenAuth(); echo $view->render(); }
public function widget($fetch = false) { $view = Piwik_View::factory('index'); $view->idSite = $this->idSite; $view = $this->setCounters($view); $view->liveRefreshAfterMs = (int) Piwik_Config::getInstance()->General['live_widget_refresh_after_seconds'] * 1000; $view->visitors = $this->getLastVisitsStart($fetchPlease = true); $view->liveTokenAuth = Piwik::getCurrentUserTokenAuth(); return $this->render($view, $fetch); }
public function widget($fetch = false) { Piwik_API_Request::reloadAuthUsingTokenAuth(); $view = Piwik_View::factory('index'); $view->idSite = $this->idSite; $view = $this->setCounters($view); $view->liveRefreshAfterMs = (int)Zend_Registry::get('config')->General->live_widget_refresh_after_seconds * 1000; $view->visitors = $this->getLastVisitsStart($fetchPlease = true); $view->liveTokenAuth = Piwik::getCurrentUserTokenAuth(); return $this->render($view, $fetch); }
public function testAllSizes() { Piwik::checkUserIsSuperUser(); $view = Piwik_View::factory('debug_graphs_all_sizes'); $this->setGeneralVariablesView($view); $period = Piwik_Common::getRequestVar('period', 'day', 'string'); $date = Piwik_Common::getRequestVar('date', 'today', 'string'); $_GET['token_auth'] = Piwik::getCurrentUserTokenAuth(); $availableReports = Piwik_API_API::getInstance()->getReportMetadata($this->idSite, $period, $date); $view->availableReports = $availableReports; $view->graphTypes = array(''); $view->graphSizes = array(array(null, null), array(Piwik_ReportRenderer::IMAGE_GRAPH_WIDTH, Piwik_ReportRenderer::IMAGE_GRAPH_HEIGHT), array(460, 150), array(300, 150), array(240, 150), array(800, 150), array(600, 300, $fontSize = 18, 300, 150)); echo $view->render(); }
/** * Returns a HTML page containing help for all the successfully loaded APIs. * For each module it will return a mini help with the method names, parameters to give, * links to get the result in Xml/Csv/etc * * @param bool $outputExampleUrls * @param string $prefixUrls * @return string */ public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '') { if (!empty($prefixUrls)) { $prefixUrls = 'http://demo.piwik.org/'; } $str = $toc = ''; $token_auth = "&token_auth=" . Piwik::getCurrentUserTokenAuth(); $parametersToSet = array('idSite' => Piwik_Common::getRequestVar('idSite', 1, 'int'), 'period' => Piwik_Common::getRequestVar('period', 'day', 'string'), 'date' => Piwik_Common::getRequestVar('date', 'today', 'string')); foreach (Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info) { $moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class); if (in_array($moduleName, $this->modulesToHide)) { continue; } $toc .= "<a href='#{$moduleName}'>{$moduleName}</a><br/>"; $str .= "\n<h2 name='{$moduleName}' id='{$moduleName}'>Module " . $moduleName . "</h2>"; $str .= "<div class='apiDescription'> " . $info['__documentation'] . " </div>"; foreach ($info as $methodName => $infoMethod) { if ($methodName == '__documentation') { continue; } $params = $this->getParametersString($class, $methodName); $str .= "\n <div class='apiMethod'>- <b>{$moduleName}.{$methodName} </b>" . $params . ""; $str .= '<small>'; if ($outputExampleUrls) { // we prefix all URLs with $prefixUrls // used when we include this output in the Piwik official documentation for example $str .= "<span class=\"example\">"; $exampleUrl = $this->getExampleUrl($class, $methodName, $parametersToSet); if ($exampleUrl !== false) { $lastNUrls = ''; if (preg_match('/(&period)|(&date)/', $exampleUrl)) { $exampleUrlRss1 = $prefixUrls . $this->getExampleUrl($class, $methodName, array('date' => 'last10', 'period' => 'day') + $parametersToSet); $exampleUrlRss2 = $prefixUrls . $this->getExampleUrl($class, $methodName, array('date' => 'last5', 'period' => 'week') + $parametersToSet); $lastNUrls = ",\tRSS of the last <a target=_blank href='{$exampleUrlRss1}&format=rss{$token_auth}&translateColumnNames=1'>10 days</a>"; } $exampleUrl = $prefixUrls . $exampleUrl; $str .= " [ Example in \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=xml{$token_auth}'>XML</a>, \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=JSON{$token_auth}'>Json</a>, \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=Tsv{$token_auth}&translateColumnNames=1'>Tsv (Excel)</a> \n\t\t\t\t\t\t\t\t\t{$lastNUrls}\n\t\t\t\t\t\t\t\t\t]"; } else { $str .= " [ No example available ]"; } $str .= "</span>"; } $str .= '</small>'; $str .= "</div>\n"; } $str .= '<div style="margin:15px;"><a href="#topApiRef" style="color:#95AECB">↑ Back to top</a></div>'; } $str = "<h2 id='topApiRef' name='topApiRef'>Quick access to APIs</h2> \n\t\t\t\t{$toc} \n\t\t\t\t{$str}"; return $str; }
/** * Saves the layout for the current user * anonymous = in the session * authenticated user = in the DB */ public function saveLayout() { $layout = Piwik_Common::getRequestVar('layout'); $idDashboard = Piwik_Common::getRequestVar('idDashboard', 1, 'int'); $currentUser = Piwik::getCurrentUserLogin(); if (Piwik_Common::getRequestVar('token_auth', false) != Piwik::getCurrentUserTokenAuth()) { return; } if ($currentUser == 'anonymous') { $session = new Zend_Session_Namespace("Piwik_Dashboard"); $session->dashboardLayout = $layout; } else { $this->saveLayoutForUser($currentUser, $idDashboard, $layout); } }
/** * Renders the current view. * * @return string Generated template */ public function render() { try { $this->currentModule = Piwik::getModule(); $this->currentAction = Piwik::getAction(); $userLogin = Piwik::getCurrentUserLogin(); $this->userLogin = $userLogin; // workaround for #1331 $count = method_exists('Piwik', 'getWebsitesCountToDisplay') ? Piwik::getWebsitesCountToDisplay() : 1; $sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess($count); usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);')); $this->sites = $sites; $this->url = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrl()); $this->token_auth = Piwik::getCurrentUserTokenAuth(); $this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess(); $this->userIsSuperUser = Piwik::isUserIsSuperUser(); $this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable(); $this->disableLink = Piwik_Common::getRequestVar('disableLink', 0, 'int'); $this->isWidget = Piwik_Common::getRequestVar('widget', 0, 'int'); if (Zend_Registry::get('config')->General->autocomplete_min_sites <= count($sites)) { $this->show_autocompleter = true; } else { $this->show_autocompleter = false; } // workaround for #1331 $this->loginModule = method_exists('Piwik', 'getLoginPluginName') ? Piwik::getLoginPluginName() : 'Login'; $user = Piwik_UsersManager_API::getInstance()->getUser($userLogin); $this->userAlias = $user['alias']; } catch (Exception $e) { // can fail, for example at installation (no plugin loaded yet) } $this->totalTimeGeneration = Zend_Registry::get('timer')->getTime(); try { $this->totalNumberOfQueries = Piwik::getQueryCount(); } catch (Exception $e) { $this->totalNumberOfQueries = 0; } // workaround for #1331 if (method_exists('Piwik', 'overrideCacheControlHeaders')) { Piwik::overrideCacheControlHeaders('no-store'); } @header('Content-Type: ' . $this->contentType); if ($this->xFrameOptions) { @header('X-Frame-Options: ' . $this->xFrameOptions); } return $this->smarty->fetch($this->template); }
/** * Returns a HTML page containing help for all the successfully loaded APIs. * For each module it will return a mini help with the method names, parameters to give, * links to get the result in Xml/Csv/etc * * @return string */ public function getAllInterfaceString($outputExampleUrls = true, $prefixUrls = '') { $str = ''; $token_auth = "&token_auth=" . Piwik::getCurrentUserTokenAuth(); $parametersToSet = array('idSite' => Piwik_Common::getRequestVar('idSite', 1, 'int'), 'period' => Piwik_Common::getRequestVar('period', 'day', 'string'), 'date' => Piwik_Common::getRequestVar('date', 'today', 'string')); foreach (Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info) { $moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class); $str .= "\n<h2 id='{$moduleName}'>Module " . $moduleName . "</h2>"; foreach ($info as $methodName => $infoMethod) { $params = $this->getStrListParameters($class, $methodName); $str .= "\n" . "- <b>{$moduleName}.{$methodName} " . $params . "</b>"; $str .= '<small>'; if ($outputExampleUrls) { // we prefix all URLs with $prefixUrls // used when we include this output in the Piwik official documentation for example $str .= "<span class=\"example\">"; $exampleUrl = $this->getExampleUrl($class, $methodName, $parametersToSet); if ($exampleUrl !== false) { $lastNUrls = ''; if (preg_match('/(&period)|(&date)/', $exampleUrl)) { $exampleUrlRss1 = $prefixUrls . $this->getExampleUrl($class, $methodName, array('date' => 'last10') + $parametersToSet); $exampleUrlRss2 = $prefixUrls . $this->getExampleUrl($class, $methodName, array('date' => 'last5', 'period' => 'week') + $parametersToSet); $lastNUrls = ",\tRSS of the last <a target=_blank href='{$exampleUrlRss1}&format=rss{$token_auth}'>10 days</a>, <a target=_blank href='{$exampleUrlRss2}&format=Rss'>5 weeks</a>,\n\t\t\t\t\t\t\t\t\tXML of the <a target=_blank href='{$exampleUrlRss1}&format=xml{$token_auth}'>last 10 days</a>"; } $exampleUrl = $prefixUrls . $exampleUrl; $str .= " [ Example in \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=xml{$token_auth}'>XML</a>, \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=PHP&prettyDisplay=true{$token_auth}'>PHP</a>, \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=JSON{$token_auth}'>Json</a>, \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=Csv{$token_auth}'>Csv</a>, \n\t\t\t\t\t\t\t\t\t<a target=_blank href='{$exampleUrl}&format=Html{$token_auth}'>Basic html</a> \n\t\t\t\t\t\t\t\t\t{$lastNUrls}\n\t\t\t\t\t\t\t\t\t]"; } else { $str .= " [ No example available ]"; } $str .= "</span>"; } $str .= '</small>'; $str .= "\n<br>"; } } return $str; }
function getKeywordsForPage() { Piwik::checkUserHasViewAccess($this->idSite); $requestUrl = '&date=previous1' . '&period=week' . '&idSite=' . $this->idSite; $topPageUrlRequest = $requestUrl . '&method=Actions.getPageUrls' . '&filter_limit=50' . '&format=original'; $request = new Piwik_API_Request($topPageUrlRequest); $request = $request->process(); $tables = $request->getArray(); $topPageUrls = $tables[key($tables)]; $topPageUrls = $topPageUrls->getRowsMetadata('url'); $topPageUrl = current(array_values($topPageUrls)); if (empty($topPageUrl)) { $topPageUrl = $this->site->getMainUrl(); } $url = $topPageUrl; // HTML $api = Piwik_Url::getCurrentUrlWithoutFileName() . '?module=API&method=Referers.getKeywordsForPageUrl' . '&format=php' . '&filter_limit=10' . '&token_auth=' . Piwik::getCurrentUserTokenAuth(); $api .= $requestUrl; $code = ' // This function will call the API to get best keyword for current URL. // Then it writes the list of best keywords in a HTML list function DisplayTopKeywords($url = "") { // Do not spend more than 1 second fetching the data @ini_set("default_socket_timeout", $timeout = 1); // Get the Keywords data $url = empty($url) ? "http://". $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : $url; $api = "' . $api . '&url=" . urlencode($url); $keywords = @unserialize(file_get_contents($api)); if($keywords === false || isset($keywords["result"])) { // DEBUG ONLY: uncomment for troubleshooting an empty output (the URL output reveals the token_auth) // echo "Error while fetching the <a href=\'$api\'>Top Keywords from Piwik</a>"; return; } // Display the list in HTML $output = "<h2>Top Keywords for <a href=\'$url\'>$url</a></h2><ul>"; foreach($keywords as $keyword) { $output .= "<li>". $keyword[0]. "</li>"; } if(empty($keywords)) { $output .= "Nothing yet..."; } $output .= "</ul>"; echo $output; } '; $jsonRequest = str_replace('format=php', 'format=json', $api); echo "<p>This widget is designed to work in your website directly.\n\t\tThis widget makes it easy to use Piwik to <i>automatically display the list of Top Keywords</i>, for each of your website Page URLs.</p>\n\t\t<p>\n\t\t<b>Example API URL</b> - For example if you would like to get the top 10 keywords, used last week, to land on the page <a target='_blank' href='{$topPageUrl}'>{$topPageUrl}</a>,\n\t\tin format JSON: you would dynamically fetch the data using <a target='_blank' href='{$jsonRequest}&url=" . urlencode($topPageUrl) . "'>this API request URL</a>. Make sure you encode the 'url' parameter in the URL.</p>\n\t\t\n\t\t<p><b>PHP Function ready to use!</b> - If you use PHP on your website, we have prepared a small code snippet that you can copy paste in your Website PHP files. You can then simply call the function <code>DisplayTopKeywords();</code> anywhere in your template, at the bottom of the content or in your blog sidebar.\n\t\tIf you run this code in your page {$topPageUrl}, it would output the following:"; echo "<div style='width:400px;margin-left:20px;padding:10px;border:1px solid black;'>"; function DisplayTopKeywords($url = "", $api) { // Do not spend more than 1 second fetching the data @ini_set("default_socket_timeout", $timeout = 1); // Get the Keywords data $url = empty($url) ? "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : $url; $api = $api . "&url=" . urlencode($url); $keywords = @unserialize(file_get_contents($api)); if ($keywords === false || isset($keywords["result"])) { // DEBUG ONLY: uncomment for troubleshooting an empty output (the URL output reveals the token_auth) //echo "Error while fetching the <a href=\'".$api."\'>Top Keywords from Piwik</a>"; return; } // Display the list in HTML $output = "<h2>Top Keywords for <a href=\\'{$url}\\'>{$url}</a></h2><ul>"; foreach ($keywords as $keyword) { $output .= "<li>" . $keyword[0] . "</li>"; } if (empty($keywords)) { $output .= "Nothing yet..."; } $output .= "</ul>"; echo $output; } DisplayTopKeywords($topPageUrl, $api); echo "</div><br/>\n\t\t<p>Here is the PHP function that you can paste in your pages:</P>\n\t\t<textarea cols=60 rows=8><?php\n" . htmlspecialchars($code) . "\n DisplayTopKeywords();</textarea>\n\t\t"; echo "\n\t\t<p><b>Notes</b>: You can for example edit the code to to make the Top search keywords link to your Website search result pages.\n\t\t<br/>On medium to large traffic websites, we recommend to cache this data, as to minimize the performance impact of calling the Piwik API on each page view.\n\t\t</p>\n\t\t"; }
/** * Checks that the specified token matches the current logged in user token. * Note: this protection against CSRF should be limited to controller * actions that are either invoked via AJAX or redirect to a page * within the site. The token should never appear in the browser's * address bar. * * @throws Piwik_Access_NoAccessException if token doesn't match * @return void */ protected function checkTokenInUrl() { if (Piwik_Common::getRequestVar('token_auth', false) != Piwik::getCurrentUserTokenAuth()) { throw new Piwik_Access_NoAccessException(Piwik_TranslateException('General_ExceptionInvalidToken')); } }
/** * Returns a HTML page containing help for all the successfully loaded APIs. * For each module it will return a mini help with the method names, parameters to give, * links to get the result in Xml/Csv/etc * * @return string */ public function getAllInterfaceString( $outputExampleUrls = true, $prefixUrls = '' ) { $str = $toc = ''; $token_auth = "&token_auth=" . Piwik::getCurrentUserTokenAuth(); $parametersToSet = array( 'idSite' => Piwik_Common::getRequestVar('idSite', 1, 'int'), 'period' => Piwik_Common::getRequestVar('period', 'day', 'string'), 'date' => Piwik_Common::getRequestVar('date', 'today', 'string') ); foreach(Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info) { $moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class); if(in_array($moduleName, $this->modulesToHide)) { continue; } $toc .= "<a href='#$moduleName'>$moduleName</a><br/>"; $str .= "\n<h2 name='$moduleName' id='$moduleName'>Module ".$moduleName."</h2>"; $str .= "<div class='apiDescription'> ".$info['__documentation'] . " </div>"; foreach($info as $methodName => $infoMethod) { if($methodName=='__documentation') { continue; } $params = $this->getParametersString($class, $methodName); $str .= "\n <div class='apiMethod'>- <b>$moduleName.$methodName </b>" . $params . ""; $str .= '<small>'; if($outputExampleUrls) { // we prefix all URLs with $prefixUrls // used when we include this output in the Piwik official documentation for example $str .= "<span class=\"example\">"; $exampleUrl = $this->getExampleUrl($class, $methodName, $parametersToSet); if($exampleUrl !== false) { $lastNUrls = ''; if( preg_match('/(&period)|(&date)/',$exampleUrl)) { $exampleUrlRss1 = $prefixUrls . $this->getExampleUrl($class, $methodName, array('date' => 'last10', 'period' => 'day') + $parametersToSet) ; $exampleUrlRss2 = $prefixUrls . $this->getExampleUrl($class, $methodName, array('date' => 'last5','period' => 'week',) + $parametersToSet ); $lastNUrls = ", RSS of the last <a target=_blank href='$exampleUrlRss1&format=rss$token_auth'>10 days</a>"; } $exampleUrl = $prefixUrls . $exampleUrl ; $str .= " [ Example in <a target=_blank href='$exampleUrl&format=xml$token_auth'>XML</a>, <a target=_blank href='$exampleUrl&format=JSON$token_auth'>Json</a>, <a target=_blank href='$exampleUrl&format=Tsv$token_auth'>Tsv (Excel)</a> $lastNUrls ]"; } else { $str .= " [ No example available ]"; } $str .= "</span>"; } $str .= '</small>'; $str .= "</div>\n"; } } $str = "<h2>Quick access to APIs</h2> $toc $str"; return $str; }
/** * View factory method * * @param string $templateName Template name (e.g., 'index') * @param int $viewType View type (e.g., Piwik_View::CLI) */ public static function factory($templateName = null, $viewType = null) { if ($templateName == self::COREUPDATER_ONE_CLICK_DONE) { return new Piwik_View_OneClickDone(Piwik::getCurrentUserTokenAuth()); } Piwik_PostEvent('View.getViewType', $viewType); // get caller $bt = @debug_backtrace(); if ($bt === null || !isset($bt[0])) { throw new Exception("View factory cannot be invoked"); } $path = dirname($bt[0]['file']); // determine best view type if ($viewType === null) { if (Piwik_Common::isPhpCliMode()) { $viewType = self::CLI; } else { $viewType = self::STANDARD; } } // get template filename if ($viewType == self::CLI) { $templateFile = $path . '/templates/cli_' . $templateName . '.tpl'; if (file_exists($templateFile)) { return new Piwik_View($templateFile, array(), false); } $viewType = self::STANDARD; } if ($viewType == self::MOBILE) { $templateFile = $path . '/templates/mobile_' . $templateName . '.tpl'; if (!file_exists($templateFile)) { $viewType = self::STANDARD; } } if ($viewType != self::MOBILE) { $templateFile = $path . '/templates/' . $templateName . '.tpl'; } // Specified template not found // We allow for no specified template if (!empty($templateName) && !file_exists($templateFile)) { throw new Exception('Template not found: ' . $templateFile); } return new Piwik_View($templateFile); }
private function checkTokenInUrl() { if (Piwik_Common::getRequestVar('token_auth', false) != Piwik::getCurrentUserTokenAuth()) { throw new Piwik_Access_NoAccessException('Token is not valid.'); } }
exit; } Piwik::checkUserIsSuperUser(); $token = Piwik_Common::getRequestVar('token_auth', false); if( empty($_GET['choice']) || $_GET['choice'] != 'yes' || $token != Piwik::getCurrentUserTokenAuth()) { echo "<div style='color:red;font-size:large'>WARNING!</div> <br>You are about to generate fake visits which will be recorded in your Piwik database. <br>It will <b>not</b> be possible to easily delete these visits from the piwik logs. <br><br>Are you sure you want to generate fake visits? <br><br> <a href='../index.php'><b>NO</b>, I do not want to generate fake visits</a> <br><br> <a href='?choice=yes&token_auth=".Piwik::getCurrentUserTokenAuth()."'><b>YES</b>, I want to generate fake visits</a> <br><br> Note: you can edit the source code of this file to specify how many visits to generate, how many days, etc. "; return; } $idSite = Piwik_Common::getRequestVar('idSite', $idSite, 'int'); require_once "PluginsManager.php"; require_once "Tracker.php"; //Piwik_PluginsManager::getInstance()->unloadPlugins(); // we have to unload the Provider plugin otherwise it tries to lookup the IP for ahostname, and there is no dns server here if(Piwik_PluginsManager::getInstance()->isPluginActivated('Provider')) {
private function generateVisits($time = false, $idSite = 1) { $logs = $this->getAccessLog(); if (empty($time)) { $time = time(); } $date = date("Y-m-d", $time); $acceptLanguages = array("el,fi;q=0.5", "de-de,de;q=0.8,en-us", "pl,en-us;q=0.7,en;q=", "zh-cn", "fr-ca", "en-us", "en-gb", "fr-be", "fr,de-ch;q=0.5", "fr", "fr-ch", "fr"); $prefix = Piwik_Url::getCurrentUrlWithoutFileName() . "piwik.php"; $count = 0; foreach ($logs as $log) { if (!preg_match('/^(\\S+) \\S+ \\S+ \\[(.*?)\\] "GET (\\S+.*?)" \\d+ \\d+ "(.*?)" "(.*?)"/', $log, $m)) { continue; } $ip = $m[1]; $time = $m[2]; $url = $m[3]; $referrer = $m[4]; $ua = $m[5]; $start = strpos($url, 'piwik.php?') + strlen('piwik.php?'); $url = substr($url, $start, strrpos($url, " ") - $start); $datetime = $date . " " . Piwik_Date::factory($time)->toString("H:i:s"); $ip = strlen($ip) < 10 ? "13.5.111.3" : $ip; // Force date/ip & authenticate $url .= "&cdt=" . urlencode($datetime); if (strpos($url, 'cip') === false) { $url .= "&cip=" . $ip; } $url .= "&token_auth=" . Piwik::getCurrentUserTokenAuth(); $url = $prefix . "?" . $url; // Make order IDs unique per day $url = str_replace("ec_id=", "ec_id={$date}-", $url); // Disable provider plugin $url .= "&dp=1"; // Replace idsite $url = preg_replace("/idsite=[0-9]+/", "idsite={$idSite}", $url); $acceptLanguage = $acceptLanguages[$count % count($acceptLanguages)]; if ($output = Piwik_Http::sendHttpRequest($url, $timeout = 5, $ua, $path = null, $follow = 0, $acceptLanguage)) { // var_dump($output); $count++; } // echo "IP=". $ip; echo "<br>"; // echo "Date=". $datetime; echo "<br>"; // echo "URL=". $url; echo "<br>"; // echo "Referrer=". $referrer; echo "<br>"; // echo "UserAgent=". $ua; echo "<br>"; // echo "<hr>"; // var_dump($url); if ($count == 2) { // return $count; } } return $count; }