Example #1
0
 public function __construct($templateFile, $smConf = array(), $filter = true)
 {
     $this->template = $templateFile;
     $this->smarty = new Piwik_Smarty();
     if (count($smConf) == 0) {
         $smConf = Zend_Registry::get('config')->smarty;
     }
     foreach ($smConf as $key => $value) {
         $this->smarty->{$key} = $value;
     }
     $this->smarty->template_dir = $smConf->template_dir->toArray();
     array_walk($this->smarty->template_dir, array("Piwik_View", "addPiwikPath"), PIWIK_INCLUDE_PATH);
     $this->smarty->plugins_dir = $smConf->plugins_dir->toArray();
     array_walk($this->smarty->plugins_dir, array("Piwik_View", "addPiwikPath"), PIWIK_INCLUDE_PATH);
     $this->smarty->compile_dir = $smConf->compile_dir;
     Piwik_View::addPiwikPath($this->smarty->compile_dir, null, PIWIK_USER_PATH);
     $this->smarty->cache_dir = $smConf->cache_dir;
     Piwik_View::addPiwikPath($this->smarty->cache_dir, null, PIWIK_USER_PATH);
     $error_reporting = $smConf->error_reporting;
     if ($error_reporting != (string) (int) $error_reporting) {
         $error_reporting = self::bitwise_eval($error_reporting);
     }
     $this->smarty->error_reporting = $error_reporting;
     $this->smarty->assign('tag', 'piwik=' . Piwik_Version::VERSION);
     if ($filter) {
         $this->smarty->load_filter('output', 'cachebuster');
         $this->smarty->load_filter('output', 'ajaxcdn');
         $this->smarty->load_filter('output', 'trimwhitespace');
     }
     // global value accessible to all templates: the piwik base URL for the current request
     $this->piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
 }
Example #2
0
 public function __construct($templateFile, $smConf = array())
 {
     require_once "Smarty.php";
     $this->template = $templateFile;
     $this->smarty = new Piwik_Smarty();
     if (count($smConf) == 0) {
         $smConf = Zend_Registry::get('config')->smarty;
     }
     foreach ($smConf as $key => $value) {
         $this->smarty->{$key} = $value;
     }
     $this->smarty->template_dir = $smConf->template_dir->toArray();
     array_walk($this->smarty->template_dir, array("Piwik_View", "addPiwikPath"));
     $this->smarty->plugins_dir = $smConf->plugins_dir->toArray();
     array_walk($this->smarty->plugins_dir, array("Piwik_View", "addPiwikPath"));
     $this->smarty->compile_dir = $smConf->compile_dir;
     Piwik_View::addPiwikPath($this->smarty->compile_dir, null);
     $this->smarty->cache_dir = $smConf->cache_dir;
     Piwik_View::addPiwikPath($this->smarty->cache_dir, null);
     $this->smarty->error_reporting = $smConf->debugging;
     $this->smarty->error_reporting = $smConf->error_reporting;
     $this->smarty->assign('tag', 'piwik=' . Piwik_Version::VERSION);
     $this->smarty->load_filter('output', 'cachebuster');
     $this->smarty->load_filter('output', 'trimwhitespace');
     // global value accessible to all templates: the piwik base URL for the current request
     $this->piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
 }
Example #3
0
    protected function getFlashInvocationCode($url = 'libs/open-flash-chart/data-files/nodata.txt', $use_swfobject = true)
    {
        $width = $this->width;
        $height = $this->height;
        $libPathInPiwik = 'libs/open-flash-chart/';
        $currentPath = Piwik_Url::getCurrentUrlWithoutFileName();
        $pathToLibraryOpenChart = $currentPath . $libPathInPiwik;
        $url = Piwik_Url::getCurrentUrlWithoutQueryString() . $url;
        // escape the & and stuff:
        $url = urlencode($url);
        $obj_id = $this->id . "Chart";
        $div_name = $this->id . "FlashContent";
        $return = '';
        if ($use_swfobject) {
            // Using library for auto-enabling Flash object on IE, disabled-Javascript proof
            $return .= '
				<div id="' . $div_name . '"></div>
				<script type="text/javascript">
				var so = new SWFObject("' . $pathToLibraryOpenChart . 'open-flash-chart.swf", "' . $obj_id . '_swf", "' . $width . '", "' . $height . '", "9", "#FFFFFF");
				so.addVariable("data", "' . $url . '");
				so.addParam("allowScriptAccess", "sameDomain");
				so.write("' . $div_name . '");
				</script>
				<noscript>
				';
        }
        $urlGraph = $pathToLibraryOpenChart . "open-flash-chart.swf?data=" . $url;
        $this->codeEmbed .= "<div><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" . $width . "' height='" . $height . "' id='" . $obj_id . "' >" . "<param name='movie' value='" . $urlGraph . "' />" . "<param name='allowScriptAccess' value='sameDomain' /> " . "<embed src='{$urlGraph}' allowScriptAccess='sameDomain' quality='high' bgcolor='#FFFFFF' width='" . $width . "' height='" . $height . "' name='open-flash-chart' type='application/x-shockwave-flash' id='" . $obj_id . "' />" . "</object></div>";
        $return .= $this->codeEmbed;
        if ($use_swfobject) {
            $return .= '</noscript>';
        }
        return $return;
    }
Example #4
0
 /**
  * display output of all methods
  */
 public function test_allMethods()
 {
     Piwik::createConfigObject();
     Piwik_Config::getInstance()->setTestEnvironment();
     $this->assertEqual(Piwik_Url::getCurrentQueryStringWithParametersModified(array()), Piwik_Url::getCurrentQueryString());
     $expectedUrl = parse_url(Piwik_Url::getCurrentUrl());
     $port = isset($expectedUrl['port']) ? ":{$expectedUrl['port']}" : '';
     $expectedUrl = $expectedUrl['scheme'] . '://' . $expectedUrl['host'] . $port . $expectedUrl['path'];
     $this->assertEqual($expectedUrl, Piwik_Url::getCurrentUrlWithoutQueryString());
     $this->assertEqual($expectedUrl, Piwik_Url::getCurrentScheme() . '://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName());
     print "<br/>\nPiwik_Url::getCurrentUrl() -> " . Piwik_Url::getCurrentUrl();
     print "<br/>\nPiwik_Url::getCurrentUrlWithoutQueryString() -> " . Piwik_Url::getCurrentUrlWithoutQueryString();
     print "<br/>\nPiwik_Url::getCurrentUrlWithoutFileName() -> " . Piwik_Url::getCurrentUrlWithoutFileName();
     print "<br/>\nPiwik_Url::getCurrentScriptPath() -> " . Piwik_Url::getCurrentScriptPath();
     print "<br/>\nPiwik_Url::getCurrentHost() -> " . Piwik_Url::getCurrentHost();
     print "<br/>\nPiwik_Url::getCurrentScriptName() -> " . Piwik_Url::getCurrentScriptName();
     print "<br/>\nPiwik_Url::getCurrentQueryString() -> " . Piwik_Url::getCurrentQueryString();
     print "<br/>\nPiwik_Url::getArrayFromCurrentQueryString() -> ";
     var_dump(Piwik_Url::getArrayFromCurrentQueryString());
     print "<br/>\nPiwik_Url::getCurrentQueryStringWithParametersModified() -> " . Piwik_Url::getCurrentQueryStringWithParametersModified(array());
     echo "<br/>\n\n";
     // setting parameter to null should remove it from url
     // test on Url.test.php?test=value
     $parameters = array_keys(Piwik_Url::getArrayFromCurrentQueryString());
     $parametersNameToValue = array();
     foreach ($parameters as $name) {
         $parametersNameToValue[$name] = null;
     }
     $this->assertEqual(Piwik_Url::getCurrentQueryStringWithParametersModified($parametersNameToValue), '');
 }
Example #5
0
 /**
  * Computes the output for the given data table
  *
  * @param Piwik_DataTable  $table
  * @return string
  * @throws Exception
  */
 protected function renderTable($table)
 {
     if (!$table instanceof Piwik_DataTable_Array || $table->getKeyName() != 'date') {
         throw new Exception("RSS feeds can be generated for one specific website &idSite=X." . "\nPlease specify only one idSite or consider using &format=XML instead.");
     }
     $idSite = Piwik_Common::getRequestVar('idSite', 1, 'int');
     $period = Piwik_Common::getRequestVar('period');
     $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName() . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
     $out = "";
     $moreRecentFirst = array_reverse($table->getArray(), true);
     foreach ($moreRecentFirst as $date => $subtable) {
         $timestamp = $table->metadata[$date]['timestamp'];
         $site = $table->metadata[$date]['site'];
         $pudDate = date('r', $timestamp);
         $dateInSiteTimezone = Piwik_Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
         $thisPiwikUrl = Piwik_Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
         $siteName = $site->getName();
         $title = $siteName . " on " . $date;
         $out .= "\t<item>\n\t\t<pubDate>{$pudDate}</pubDate>\n\t\t<guid>{$thisPiwikUrl}</guid>\n\t\t<link>{$thisPiwikUrl}</link>\n\t\t<title>{$title}</title>\n\t\t<author>http://piwik.org</author>\n\t\t<description>";
         $out .= Piwik_Common::sanitizeInputValue($this->renderDataTable($subtable));
         $out .= "</description>\n\t</item>\n";
     }
     $header = $this->getRssHeader();
     $footer = $this->getRssFooter();
     return $header . $out . $footer;
 }
Example #6
0
 protected function renderTable($table)
 {
     if (!$table instanceof Piwik_DataTable_Array) {
         throw new Exception("RSS Feed only used on DataTable_Array");
     }
     $idSite = Piwik_Common::getRequestVar('idSite', 1);
     $period = Piwik_Common::getRequestVar('period');
     $currentUrl = Piwik_Url::getCurrentUrlWithoutFileName();
     $piwikUrl = $currentUrl . "?module=Home&action=index&idSite=" . $idSite . "&period=" . $period;
     $out = "";
     $moreRecentFirst = array_reverse($table->getArray(), true);
     foreach ($moreRecentFirst as $date => $subtable) {
         $timestamp = $table->metaData[$date]['timestamp'];
         $site = $table->metaData[$date]['site'];
         $pudDate = date('r', $timestamp);
         $dateUrl = date('Y-m-d', $timestamp);
         $thisPiwikUrl = htmlentities($piwikUrl . "&date={$dateUrl}");
         $siteName = $site->getName();
         $title = $siteName . " on " . $date;
         $out .= "\t<item>\n\t\t<pubDate>{$pudDate}</pubDate>\n\t\t<guid>{$thisPiwikUrl}</guid>\n\t\t<link>{$thisPiwikUrl}</link>\n\t\t<title>{$title}</title>\n\t\t<author>http://piwik.org</author>\n\t\t<description>";
         $out .= htmlspecialchars($this->renderDataTable($subtable));
         $out .= "</description>\n\t</item>\n";
     }
     $header = $this->getRssHeader();
     $footer = $this->getRssFooter();
     return $this->output($header . $out . $footer);
 }
Example #7
0
 public function __construct($templateFile, $smConf = array(), $filter = true)
 {
     $this->template = $templateFile;
     $this->smarty = new Piwik_Smarty($smConf, $filter);
     // global value accessible to all templates: the piwik base URL for the current request
     $this->piwik_version = Piwik_Version::VERSION;
     $this->cacheBuster = md5(Piwik_Common::getSalt() . PHP_VERSION . Piwik_Version::VERSION);
     $this->piwikUrl = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName());
 }
Example #8
0
 function displayJavascriptCode()
 {
     $idSite = Piwik_Common::getRequestVar('idsite', 1);
     Piwik::checkUserHasViewAccess($idSite);
     $jsTag = Piwik::getJavascriptCode($idSite, Piwik_Url::getCurrentUrlWithoutFileName());
     $view = new Piwik_View('SitesManager/templates/DisplayJavascriptCode.tpl');
     $view->menu = Piwik_GetAdminMenu();
     $view->jsTag = $jsTag;
     echo $view->render();
 }
Example #9
0
	function displayJavascriptCode()
	{
		$idSite = Piwik_Common::getRequestVar('idsite', 1);
		Piwik::checkUserHasViewAccess($idSite);
		$jsTag = Piwik::getJavascriptCode($idSite, Piwik_Url::getCurrentUrlWithoutFileName());
		$view = Piwik_View::factory('DisplayJavascriptCode');
		$this->setGeneralVariablesView($view);
		$view->menu = Piwik_GetAdminMenu();
		$view->jsTag = $jsTag;
		echo $view->render();
	}
Example #10
0
 /**
  * Returns the javascript tag for the given idSite.
  * This tag must be included on every page to be tracked by Piwik
  *
  * @param int $idSite
  * @param string $customTitle Custom title given to the pageview
  * @return string The Javascript tag ready to be included on the HTML pages
  */
 public function getJavascriptTag($idSite, $piwikUrl = '')
 {
     Piwik::checkUserHasViewAccess($idSite);
     if (empty($piwikUrl)) {
         $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
     }
     $piwikUrl = Piwik_Common::sanitizeInputValues($piwikUrl);
     $htmlEncoded = Piwik::getJavascriptCode($idSite, $piwikUrl);
     $htmlEncoded = str_replace(array('<br>', '<br />', '<br/>'), '', $htmlEncoded);
     return $htmlEncoded;
 }
Example #11
0
 function js()
 {
     $controllerName = Piwik_Common::getRequestVar('moduleToWidgetize');
     $actionName = Piwik_Common::getRequestVar('actionToWidgetize');
     $parameters = array($fetch = true);
     $content = Piwik_FrontController::getInstance()->fetchDispatch($controllerName, $actionName, $parameters);
     $view = Piwik_View::factory('js');
     $view->piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
     $content = str_replace(array("\t", "\n", "\r\n", "\r"), "", $content);
     $view->content = $content;
     echo $view->render();
 }
Example #12
0
 /**
  * Returns the javascript tag for the given idSite.
  * This tag must be included on every page to be tracked by Piwik
  *
  * @param int $idSite
  * @return string The Javascript tag ready to be included on the HTML pages
  */
 public static function getJavascriptTag($idSite, $piwikUrl = '', $actionName = '')
 {
     Piwik::checkUserHasViewAccess($idSite);
     $actionName = "'" . addslashes(Piwik_Common::sanitizeInputValues($actionName)) . "'";
     if (empty($piwikUrl)) {
         $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
     }
     $piwikUrl = addslashes(Piwik_Common::sanitizeInputValues($piwikUrl));
     $htmlEncoded = Piwik::getJavascriptCode($idSite, $piwikUrl, $actionName);
     $htmlEncoded = str_replace(array('<br>', '<br />', '<br/>'), '', $htmlEncoded);
     return html_entity_decode($htmlEncoded);
 }
Example #13
0
 /**
  * Displays the admin UI page showing all tracking tags
  * @return unknown_type
  */
 function displayJavascriptCode()
 {
     $idSite = Piwik_Common::getRequestVar('idSite');
     Piwik::checkUserHasViewAccess($idSite);
     $jsTag = Piwik::getJavascriptCode($idSite, Piwik_Url::getCurrentUrlWithoutFileName());
     $view = Piwik_View::factory('Tracking');
     $this->setBasicVariablesView($view);
     $view->menu = Piwik_GetAdminMenu();
     $view->idSite = $idSite;
     $site = new Piwik_Site($idSite);
     $view->displaySiteName = $site->getName();
     $view->jsTag = $jsTag;
     echo $view->render();
 }
Example #14
0
 public function __construct($templateFile, $smConf = array())
 {
     $this->template = $templateFile;
     $this->smarty = new Smarty();
     if (count($smConf) == 0) {
         $smConf = Zend_Registry::get('config')->smarty;
     }
     foreach ($smConf as $key => $value) {
         $this->smarty->{$key} = $value;
     }
     $this->smarty->template_dir = $smConf->template_dir->toArray();
     $this->smarty->plugins_dir = $smConf->plugins_dir->toArray();
     $this->smarty->compile_dir = $smConf->compile_dir;
     $this->smarty->cache_dir = $smConf->cache_dir;
     $this->smarty->load_filter('output', 'trimwhitespace');
     // global value accessible to all templates: the piwik base URL for the current request
     $this->piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
 }
Example #15
0
	protected function renderTable($table)
	{
		if(!($table instanceof Piwik_DataTable_Array)
			|| $table->getKeyName() != 'date')
		{
			throw new Exception("RSS Feed only used on Piwik_DataTable_Array with keyName = 'date'");
		}
		
		$idSite = Piwik_Common::getRequestVar('idSite', 1, 'int');
		$period = Piwik_Common::getRequestVar('period');
		
		$piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName() 
						. "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
		$out = "";
		$moreRecentFirst = array_reverse($table->getArray(), true);
		foreach($moreRecentFirst as $date => $subtable )
		{
			$timestamp = $table->metadata[$date]['timestamp'];
			$site = $table->metadata[$date]['site'];
	
			$pudDate = date('r', $timestamp);
			 
			$dateInSiteTimezone = Piwik_Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
			$thisPiwikUrl = Piwik_Common::sanitizeInputValue($piwikUrl . "&date=$dateInSiteTimezone");
			$siteName = $site->getName();
			$title = $siteName . " on ". $date;
			
			$out .= "\t<item>
		<pubDate>$pudDate</pubDate>
		<guid>$thisPiwikUrl</guid>
		<link>$thisPiwikUrl</link>
		<title>$title</title>
		<author>http://piwik.org</author>
		<description>";	
			
			$out .= Piwik_Common::sanitizeInputValue( $this->renderDataTable($subtable) );
			$out .= "</description>\n\t</item>\n";
		}
		
		$header = $this->getRssHeader();
		$footer = $this->getRssFooter();
		
		return $header . $out . $footer;
	}
Example #16
0
 /**
  * display output of all methods
  */
 public function test_allMethods()
 {
     $this->assertEqual(Piwik_Url::getCurrentQueryStringWithParametersModified(array()), Piwik_Url::getCurrentQueryString());
     $this->assertEqual(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentUrlWithoutQueryString());
     $this->assertEqual(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName());
     print "<br>\nPiwik_Url::getCurrentQueryStringWithParametersModified() " . Piwik_Url::getCurrentQueryStringWithParametersModified(array());
     print "<br>\nPiwik_Url::getCurrentUrl() " . Piwik_Url::getCurrentUrl();
     print "<br>\nPiwik_Url::getCurrentUrlWithoutQueryString() " . Piwik_Url::getCurrentUrlWithoutQueryString();
     print "<br>\nPiwik_Url::getCurrentUrlWithoutFileName() " . Piwik_Url::getCurrentUrlWithoutFileName();
     print "<br>\nPiwik_Url::getCurrentScriptName() " . Piwik_Url::getCurrentScriptName();
     print "<br>\nPiwik_Url::getCurrentScriptPath() " . Piwik_Url::getCurrentScriptPath();
     print "<br>\nPiwik_Url::getCurrentHost() " . Piwik_Url::getCurrentHost();
     print "<br>\nPiwik_Url::getCurrentQueryString() " . Piwik_Url::getCurrentQueryString();
     print "<br>\nPiwik_Url::getArrayFromCurrentQueryString() ";
     var_dump(Piwik_Url::getArrayFromCurrentQueryString());
     // setting parameter to null should remove it from url
     // test on Url.test.php?test=value
     $parameters = array_keys(Piwik_Url::getArrayFromCurrentQueryString());
     $parametersNameToValue = array();
     foreach ($parameters as $name) {
         $parametersNameToValue[$name] = null;
     }
     $this->assertEqual(Piwik_Url::getCurrentQueryStringWithParametersModified($parametersNameToValue), '');
 }
    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>&lt;?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";
    }
Example #18
0
	/**
	 * The previous step is valid if it is either
	 * - any step before (OK to go back)
	 * - the current step (case when validating a form)
	 * If step is invalid, then exit.
	 *
	 * @param string $currentStep Current step
	 */
	protected function checkPreviousStepIsValid( $currentStep )
	{
		$error = false;

		if(empty($this->session->currentStepDone))
		{
			$error = true;
		}
		else if($currentStep == 'finished' && $this->session->currentStepDone == 'finished')
		{
			// ok to refresh this page or use language selector
		}
		else
		{
			if(file_exists(Piwik_Config::getDefaultUserConfigPath()))
			{
				$error = true;
			}

			$steps = array_keys($this->steps);

			// the currentStep
			$currentStepId = array_search($currentStep, $steps);

			// the step before
			$previousStepId = array_search($this->session->currentStepDone, $steps);

			// not OK if currentStepId > previous+1
			if( $currentStepId > $previousStepId + 1 )
			{
				$error = true;
			}
		}
		if($error)
		{
			Piwik_Login_Controller::clearSession();
			$message = Piwik_Translate('Installation_ErrorInvalidState',
						array( '<br /><b>',
								'</b>',
								'<a href=\''.Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName()).'\'>',
								'</a>')
					);
			Piwik::exitWithErrorMessage( $message );
		}
	}
 /**
  * Returns URL to the proxy script, used to ensure piwik.php
  * uses the test environment, and allows variable overwriting
  *
  * @return string
  */
 protected function getTrackerUrl()
 {
     $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
     $pathBeforeRoot = 'tests';
     // Running from a plugin
     if (strpos($piwikUrl, 'plugins/') !== false) {
         $pathBeforeRoot = 'plugins';
     }
     $piwikUrl = substr($piwikUrl, 0, strpos($piwikUrl, $pathBeforeRoot . '/')) . 'tests/integration/proxy-piwik.php';
     return $piwikUrl;
 }
Example #20
0
<?php

require_once '../../core/Url.php';
$url = Piwik_Url::getCurrentUrlWithoutFileName();
$urlPiwik = join("/", array_slice(split("/", $url), 0, -3));
?>

<div>
You should update the piwik javascript code at the bottom of this page if needed.<br />
And test the tracker by clicking all the links below, with several browsers...<br />
<br />
</div>

<a href="mailto:test@test.com"> mailto test@test.com</a> <br />
<a href="http://www.yahoo.fr"> yahoo france website</a> <br />
<a href="http://www.yahoo.fr/index?test=test2&p_______=idugiduagi8*&*$&%(*^"> yahoo france website</a> <br />
<a href="http://www.google.com"> google world website </a> <br />
<a href="ftp://parcftp.xerox.com"> FTP xerox</a> <br />
<a href="news://news.eclipse.org"> News::eclipse</a> <br />
<a href="http://piwik.org"> piwik website </a> <br />
<a href="http://www.testWithImageAndText.com"><img border=0 src="../../plugins/UserCountry/flags/fr.png"> Test with image + text </a> <br />
<a href="http://www.testWithImageOnly.com"><img border=0 src="../../plugins/UserCountry/flags/pl.png"></a> <br />

<br />
<a class="piwik_ignore" href="./THIS_PDF_SHOULD_NOT_BE_COUNTED.pdf"> PDF wthdownload pdf </a> <br />
<a href="./test.pdf"> download pdf (rel) </a> <br />
<a href="./dir_test/test.pdf"> download pdf + directory (rel) </a> <br />
<a href="../testJavascriptTracker/dir_test/test.pdf"> download pdf + parent directory (rel) </a> <br />
<a href="./test.jpg"> download jpg (rel) </a> <br />
<a href="./test.zip"> download zip (rel) </a> <br />
<a href="./test.php?fileToDownload=test.zip"> download strange URL ?file=test.zip</a> <br />
Example #21
0
 /**
  * Returns the cached the Piwik URL, eg. http://demo.piwik.org/ or http://example.org/piwik/ 
  * If not found, then tries to cache it and returns the value.
  *
  * If the Piwik URL changes (eg. Piwik moved to new server), the value will automatically be refreshed in the cache.
  * @return string
  */
 public static function getPiwikUrl()
 {
     $key = 'piwikUrl';
     $url = Piwik_GetOption($key);
     if (Piwik_Common::isPhpCliMode() || Piwik_Common::isArchivePhpTriggered() || defined('PIWIK_MODE_ARCHIVE')) {
         return $url;
     }
     $currentUrl = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName());
     if (empty($url) || $currentUrl != $url) {
         if (strlen($currentUrl) >= strlen('http://a/')) {
             Piwik_SetOption($key, $currentUrl, $autoload = true);
         }
         $url = $currentUrl;
     }
     return $url;
 }
Example #22
0
 private function initPiwikHost()
 {
     // If archive.php run as a web cron, we use the current hostname
     if (!Piwik_Common::isPhpCliMode()) {
         // example.org/piwik/misc/cron/
         $piwikUrl = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName());
         // example.org/piwik/
         $piwikUrl = $piwikUrl . "../../";
     } else {
         $piwikUrl = $this->isParameterSet("url", true);
         if (!$piwikUrl || !Piwik_Common::isLookLikeUrl($piwikUrl)) {
             $this->logFatalError("archive.php expects the argument --url to be set to your Piwik URL, for example: --url=http://example.org/piwik/ ", $backtrace = false);
         }
         // ensure there is a trailing slash
         if ($piwikUrl[strlen($piwikUrl) - 1] != '/') {
             $piwikUrl .= '/';
         }
     }
     if (Piwik_Config::getInstance()->General['force_ssl'] == 1) {
         $piwikUrl = str_replace('http://', 'https://', $piwikUrl);
     }
     $this->piwikUrl = $piwikUrl . "index.php";
 }
 /**
  * Returns URL to Piwik root.
  *
  * @return string
  */
 protected static function getRootUrl()
 {
     $piwikUrl = Piwik_Url::getCurrentUrlWithoutFileName();
     $pathBeforeRoot = 'tests';
     // Running from a plugin
     if (strpos($piwikUrl, 'plugins/') !== false) {
         $pathBeforeRoot = 'plugins';
     }
     $piwikUrl = substr($piwikUrl, 0, strpos($piwikUrl, $pathBeforeRoot . '/'));
     return $piwikUrl;
 }
Example #24
0
 /**
  * The previous step is valid if it is either 
  * - any step before (OK to go back)
  * - the current step (case when validating a form)
  */
 protected function checkPreviousStepIsValid($currentStep)
 {
     $error = false;
     // first we make sure that the config file is not present, ie. Installation state is expected
     try {
         $config = new Piwik_Config();
         $config->init();
         $error = true;
     } catch (Exception $e) {
     }
     if (empty($this->session->currentStepDone)) {
         $error = true;
     } else {
         // the currentStep
         $currentStepId = array_search($currentStep, $this->steps);
         // the step before
         $previousStepId = array_search($this->session->currentStepDone, $this->steps);
         // not OK if currentStepId > previous+1
         if ($currentStepId > $previousStepId + 1) {
             $error = true;
         }
     }
     if ($error) {
         $message = Piwik_Translate('Installation_ErrorInvalidState', array('<br /><b>', '</b>', '<a href=\'' . Piwik_Url::getCurrentUrlWithoutFileName() . '\'>', '</a>'));
         Piwik::exitWithErrorMessage($message);
     }
 }
Example #25
0
	/**
	 * Returns the cached the Piwik URL, eg. http://demo.piwik.org/ or http://example.org/piwik/ 
	 * If not found, then tries to cache it and returns the value.
	 *
	 * If the Piwik URL changes (eg. Piwik moved to new server), the value will automatically be refreshed in the cache.
         *
	 * @return string
	 */
	static public function getPiwikUrl()
	{
		$key = 'piwikUrl';
		$url = Piwik_GetOption($key);
		if(Piwik_Common::isPhpCliMode())
		{
			return $url;
		}

		$currentUrl = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName());
		if(self::isHttps()
			&& strpos($currentUrl, 'http://') === 0)
		{
			$currentUrl = str_replace('http://', 'https://', $currentUrl);
		}
		
		if(empty($url)
			// if URL changes, always update the cache
			|| $currentUrl != $url) 
		{
			if(strlen($currentUrl) >= strlen('http://a/'))
			{
				Piwik_SetOption($key, $currentUrl, $autoload = true);
			}
			$url = $currentUrl;
		}
		return $url;
	}
Example #26
0
 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;
 }