Esempio n. 1
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), '');
 }
Esempio n. 2
0
 protected function buildView()
 {
     $view = new Piwik_View($this->dataTableTemplate);
     $this->uniqueIdViewDataTable = $this->getUniqueIdViewDataTable();
     $view->graphType = $this->graphType;
     $this->chartDivId = $this->uniqueIdViewDataTable . "Chart_swf";
     $this->parametersToModify['action'] = $this->currentControllerAction;
     $this->parametersToModify = array_merge($this->variablesDefault, $this->parametersToModify);
     $url = Piwik_Url::getCurrentQueryStringWithParametersModified($this->parametersToModify);
     $this->includeData = !Zend_Registry::get('config')->Debug->disable_merged_requests;
     $idSite = Piwik_Common::getRequestVar('idSite', 1, 'int');
     Piwik_API_Request::reloadAuthUsingTokenAuth();
     if (!Piwik::isUserHasViewAccess($idSite)) {
         throw new Exception(Piwik_TranslateException('General_ExceptionPrivilegeAccessWebsite', array("'view'", $idSite)));
     }
     if ($this->includeData) {
         $this->chartData = $this->getFlashData();
     } else {
         $this->chartData = null;
     }
     $view->flashParameters = $this->getFlashParameters();
     $view->urlGraphData = $url;
     $view->chartDivId = $this->chartDivId;
     $view->formEmbedId = "formEmbed" . $this->uniqueIdViewDataTable;
     $view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
     $view->properties = $this->getViewProperties();
     return $view;
 }
	function init()
	{
		$this->addElement('text', 'form_login')
		     ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('General_Username')));

		$password = $this->addElement('password', 'form_password');
		$password->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_Password')));

		$passwordBis = $this->addElement('password', 'form_password_bis');
		$passwordBis->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_PasswordRepeat')));
		$passwordBis->addRule('eq', Piwik_Translate( 'Login_PasswordsDoNotMatch'), $password);

		$this->addElement('text', 'form_token')
		     ->addRule('required', Piwik_Translate('General_Required', Piwik_Translate('Login_PasswordResetToken')));

		$this->addElement('hidden', 'form_nonce');

		$this->addElement('submit', 'submit');

		$resetToken = Piwik_Common::getRequestVar('token', '', 'string');
		if(!empty($resetToken)) {
			// default values
			$this->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
				'form_token' => $resetToken,
			)));

			$this->attributes['action'] = 'index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified( array('token' => null) );
		}
	}
Esempio n. 4
0
/**
 * Smarty {hiddenurl} function plugin.
 * Writes an input Hidden field for every parameter in the URL.
 * Useful when using GET forms because we need to print the current parameters 
 * in hidden input so they are to the next URL after the form is submitted.
 *
 * 
 * Examples:
 * <pre>
 * {hiddenurl module="API"} with a URL 'index.php?action=test&module=CoreHome' will output
 *  <input type=hidden name=action value=test>
 *  <input type=hidden name=module value=API>
 * </pre>
 * 
 * Set a value to null if you want this value not to be passed in the submitted form.
 * 
 * @param	array
 * @param	Smarty
 * @return	string
 */
function smarty_function_hiddenurl($params, &$smarty)
{
    $queryStringModified = Piwik_Url::getCurrentQueryStringWithParametersModified($params);
    $urlValues = Piwik_Common::getArrayFromQueryString($queryStringModified);
    $out = '';
    foreach ($urlValues as $name => $value) {
        $out .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />';
    }
    return $out;
}
Esempio n. 5
0
 /**
  * @group Core
  * @group Url
  */
 public function testAllMethods()
 {
     $this->assertEquals(Piwik_Url::getCurrentQueryStringWithParametersModified(array()), Piwik_Url::getCurrentQueryString());
     $this->assertEquals(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentUrlWithoutQueryString());
     $this->assertEquals(Piwik_Url::getCurrentUrl(), Piwik_Url::getCurrentScheme() . '://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName());
     $_SERVER['QUERY_STRING'] = 'q=test';
     $parameters = array_keys(Piwik_Url::getArrayFromCurrentQueryString());
     $parametersNameToValue = array();
     foreach ($parameters as $name) {
         $parametersNameToValue[$name] = null;
     }
     $this->assertEquals('', Piwik_Url::getCurrentQueryStringWithParametersModified($parametersNameToValue));
 }
 protected function buildView()
 {
     $view = new Piwik_View($this->dataTableTemplate);
     $this->uniqueIdViewDataTable = $this->getUniqueIdViewDataTable();
     $view->graphType = $this->graphType;
     $this->chartDivId = $this->uniqueIdViewDataTable . "Chart_swf";
     $this->parametersToModify['action'] = $this->currentControllerAction;
     $this->parametersToModify = array_merge($this->variablesDefault, $this->parametersToModify);
     $url = Piwik_Url::getCurrentQueryStringWithParametersModified($this->parametersToModify);
     $view->jsInvocationTag = $this->getFlashInvocationCode($url);
     $view->urlGraphData = $url;
     $view->chartDivId = $this->chartDivId;
     $view->formEmbedId = "formEmbed" . $this->uniqueIdViewDataTable;
     $view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
     $view->properties = $this->getViewProperties();
     return $view;
 }
Esempio n. 7
0
 public static function setBasicVariablesAdminView($view)
 {
     $view->currentAdminMenuName = Piwik_GetCurrentAdminMenuName();
     $view->enableFrames = Piwik_Config::getInstance()->General['enable_framed_settings'];
     if (!$view->enableFrames) {
         $view->setXFrameOptions('sameorigin');
     }
     $view->isSuperUser = Piwik::isUserIsSuperUser();
     // for old geoip plugin warning
     $view->usingOldGeoIPPlugin = Piwik_PluginsManager::getInstance()->isPluginActivated('GeoIP');
     // for cannot find installed plugin warning
     $missingPlugins = Piwik_PluginsManager::getInstance()->getMissingPlugins();
     if (!empty($missingPlugins)) {
         $pluginsLink = Piwik_Url::getCurrentQueryStringWithParametersModified(array('module' => 'CorePluginsAdmin', 'action' => 'index'));
         $view->missingPluginsWarning = Piwik_Translate('CoreAdminHome_MissingPluginsWarning', array('<strong>' . implode('</strong>,&nbsp;<strong>', $missingPlugins) . '</strong>', '<a href="' . $pluginsLink . '"/>', '</a>'));
     }
 }
/**
 * Rewrites the given URL so that it looks like a URL that can be loaded directly.
 * Useful for users who don't handle javascript / ajax, they can still use piwik with these rewritten URLs.
 * 
 * @return string
 */
function smarty_modifier_urlRewriteBasicView($parameters)
{
    // replace module=X by moduleToLoad=X
    // replace action=Y by actionToLoad=Y
    $parameters['moduleToLoad'] = $parameters['module'];
    unset($parameters['module']);
    if (isset($parameters['action'])) {
        $parameters['actionToLoad'] = $parameters['action'];
        unset($parameters['action']);
    } else {
        $parameters['actionToLoad'] = null;
    }
    $url = Piwik_Url::getCurrentQueryStringWithParametersModified($parameters);
    // add module=CoreHome&action=showInContext
    $url = $url . '&amp;module=CoreHome&amp;action=showInContext';
    return htmlspecialchars($url);
}
Esempio n. 9
0
 /**
  * @see Piwik_ViewDataTable::main()
  *
  */
 public function main()
 {
     if ($this->mainAlreadyExecuted) {
         return;
     }
     $this->mainAlreadyExecuted = true;
     $view = new Piwik_View($this->dataTableTemplate);
     $this->id = $this->getUniqIdTable();
     $view->graphType = $this->graphType;
     $this->parametersToModify['action'] = $this->currentControllerAction;
     $url = Piwik_Url::getCurrentQueryStringWithParametersModified($this->parametersToModify);
     $view->jsInvocationTag = $this->getFlashInvocationCode($url);
     $view->urlData = $url;
     $view->formId = "formEmbed" . $this->id;
     $view->codeEmbed = $this->codeEmbed;
     $view->id = $this->id;
     $view->method = $this->method;
     $view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
     $view->showFooter = $this->getShowFooter();
     $this->view = $view;
 }
/**
 * Rewrites the given URL so that it looks like an Admin URL.
 * 
 * @return string
 */
function smarty_modifier_urlRewriteAdminView($parameters)
{
    // replace module=X by moduleToLoad=X
    // replace action=Y by actionToLoad=Y
    if (!is_array($parameters)) {
        // if parameters is not an array, parse URL parameteres
        $parameters = Piwik_Common::getArrayFromQueryString(htmlspecialchars($parameters));
    }
    $parameters['moduleToLoad'] = $parameters['module'];
    unset($parameters['module']);
    if (isset($parameters['action'])) {
        $parameters['actionToLoad'] = $parameters['action'];
        unset($parameters['action']);
    } else {
        $parameters['actionToLoad'] = null;
    }
    $url = Piwik_Url::getCurrentQueryStringWithParametersModified($parameters);
    // add module=Home&action=showInContext
    $url = $url . '&module=AdminHome&action=showInContext';
    return $url;
}
Esempio n. 11
0
 function customizeGraph()
 {
     parent::customizeGraph();
     $this->prepareData();
     $this->set_y_max($this->maxData);
     $line_1 = new line_hollow(1, 3, '0x3357A0');
     $line_1->key('visits', 10);
     $i = 0;
     foreach ($this->arrayData as $value) {
         // hack until we have proper date handling
         $spacePosition = strpos($this->arrayLabel[$i], ' ');
         if ($spacePosition === false) {
             $spacePosition = strlen($this->arrayLabel[$i]);
         }
         // generate the link on the dot, to the given day' statistics
         $link = Piwik_Url::getCurrentScriptName() . Piwik_Url::getCurrentQueryStringWithParametersModified(array('date' => substr($this->arrayLabel[$i], 0, $spacePosition), 'module' => 'Home', 'action' => 'index', 'viewDataTable' => null));
         $line_1->add_link($value, $link);
         $i++;
     }
     $this->data_sets[] = $line_1;
     $this->set_x_labels($this->arrayLabel);
     $this->area_hollow(1, 3, 4, '0x3357A0', ' visits', 10);
 }
Esempio n. 12
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), '');
 }
Esempio n. 13
0
 protected function buildView()
 {
     $view = new Piwik_View($this->dataTableTemplate);
     $this->uniqueIdViewDataTable = $this->getUniqueIdViewDataTable();
     $view->graphType = $this->graphType;
     $this->chartDivId = $this->uniqueIdViewDataTable . "Chart_swf";
     $this->parametersToModify['action'] = $this->currentControllerAction;
     $this->parametersToModify = array_merge($this->variablesDefault, $this->parametersToModify);
     $url = Piwik_Url::getCurrentQueryStringWithParametersModified($this->parametersToModify);
     $this->includeData = Zend_Registry::get('config')->General->serve_widget_and_data;
     $idSite = Piwik_Common::getRequestVar('idSite', 1);
     if (Piwik::isUserHasViewAccess($idSite) && $this->includeData) {
         $this->chartData = $this->getFlashData();
     } else {
         $this->chartData = null;
     }
     $view->flashParameters = $this->getFlashParameters();
     $view->urlGraphData = $url;
     $view->chartDivId = $this->chartDivId;
     $view->formEmbedId = "formEmbed" . $this->uniqueIdViewDataTable;
     $view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
     $view->properties = $this->getViewProperties();
     return $view;
 }
Esempio n. 14
0
    /**
     * Checks if the current host is valid and sets variables on the given view, including:
     * 
     * isValidHost - true if host is valid, false if otherwise
     * invalidHostMessage - message to display if host is invalid (only set if host is invalid)
     * invalidHost - the invalid hostname (only set if host is invalid)
     * mailLinkStart - the open tag of a link to email the super user of this problem (only set
     *                 if host is invalid)
     */
    public static function setHostValidationVariablesView($view)
    {
        // check if host is valid
        $view->isValidHost = Piwik_Url::isValidHost();
        if (!$view->isValidHost) {
            // invalid host, so display warning to user
            $validHost = Piwik_Config::getInstance()->General['trusted_hosts'][0];
            $invalidHost = Piwik_Common::sanitizeInputValue($_SERVER['HTTP_HOST']);
            $emailSubject = rawurlencode(Piwik_Translate('CoreHome_InjectedHostEmailSubject', $invalidHost));
            $emailBody = rawurlencode(Piwik_Translate('CoreHome_InjectedHostEmailBody'));
            $superUserEmail = Piwik::getSuperUserEmail();
            $mailToUrl = "mailto:{$superUserEmail}?subject={$emailSubject}&body={$emailBody}";
            $mailLinkStart = "<a href=\"{$mailToUrl}\">";
            $invalidUrl = Piwik_Url::getCurrentUrlWithoutQueryString($checkIfTrusted = false);
            $validUrl = Piwik_Url::getCurrentScheme() . '://' . $validHost . Piwik_Url::getCurrentScriptName();
            $validLink = "<a href=\"{$validUrl}\">{$validUrl}</a>";
            $changeTrustedHostsUrl = "index.php" . Piwik_Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'generalSettings')) . "#trustedHostsSection";
            $warningStart = Piwik_Translate('CoreHome_InjectedHostWarningIntro', array('<strong>' . $invalidUrl . '</strong>', '<strong>' . $validUrl . '</strong>')) . ' <br/>';
            if (Piwik::isUserIsSuperUser()) {
                $view->invalidHostMessage = $warningStart . ' ' . Piwik_Translate('CoreHome_InjectedHostSuperUserWarning', array("<a href=\"{$changeTrustedHostsUrl}\">", $invalidHost, '</a>', "<br/><a href=\"{$validUrl}\">", $validHost, '</a>'));
            } else {
                $view->invalidHostMessage = $warningStart . ' ' . Piwik_Translate('CoreHome_InjectedHostNonSuperUserWarning', array("<br/><a href=\"{$validUrl}\">", '</a>', $mailLinkStart, '</a>'));
            }
            $view->invalidHostMessageHowToFix = '<b>How do I fix this problem and how do I login again?</b><br/> The Piwik Super User can manually edit the file piwik/config/config.ini.php
						and add the following lines: <pre>[General]' . "\n" . 'trusted_hosts[] = "' . $validHost . '"</pre><br/>After making the change, you will be able to login again.<br/><br/>
						You may also <i>disable this security feature (not recommended)</i>. To do so edit config/config.ini.php and add:
						<pre>[General]' . "\n" . 'enable_trusted_host_check=0</pre>';
            $view->invalidHost = $invalidHost;
            // for UserSettings warning
            $view->invalidHostMailLinkStart = $mailLinkStart;
        }
    }
Esempio n. 15
0
/**
 * Smarty {url} function plugin.
 * Generates a piwik URL with the specified parameters modified.
 *
 * Examples:
 * <pre>
 * {url module="API"} will rewrite the URL modifying the module GET parameter
 * {url module="API" method="getKeywords"} will rewrite the URL modifying the parameters module=API method=getKeywords
 * </pre>
 *
 * @see Piwik_Url::getCurrentQueryStringWithParametersModified()
 *
 * @param array $params $name=>$value pairs of the parameters to modify in the generated URL
 * @param Smarty &smarty Smarty object
 * @return    string Something like index.php?module=X&action=Y
 */
function smarty_function_url($params, &$smarty)
{
    return Piwik_Common::sanitizeInputValue('index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified($params));
}
Esempio n. 16
0
 /**
  * returns false if the URL to redirect to is already this URL
  */
 public static function redirectToModule($newModule, $newAction = '')
 {
     $currentModule = self::getModule();
     $currentAction = self::getAction();
     if ($currentModule != $newModule || $currentAction != $newAction) {
         $newUrl = 'index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified(array('module' => $newModule, 'action' => $newAction));
         Piwik_Url::redirectToUrl($newUrl);
     }
     return false;
 }
/**
 * Rewrites the given URL and modify the given parameters.
 * @see Piwik_Url::getCurrentQueryStringWithParametersModified()
 *
 * @param $parameters
 * @return string
 */
function smarty_modifier_urlRewriteWithParameters($parameters)
{
    $parameters['updated'] = null;
    $url = Piwik_Url::getCurrentQueryStringWithParametersModified($parameters);
    return Piwik_Common::sanitizeInputValue($url);
}
Esempio n. 18
0
/**
 * Smarty {url} function plugin.
 * Generates a piwik URL with the specified parameters modified.
 *
 * Examples:
 * <pre>
 * {url module="API"} will rewrite the URL modifying the module GET parameter
 * {url module="API" method="getKeywords"} will rewrite the URL modifying the parameters module=API method=getKeywords
 * </pre>
 * 
 * @see Piwik_Url::getCurrentQueryStringWithParametersModified()
 * @param $name=$value of the parameters to modify in the generated URL
 * @return	string Something like index.php?module=X&action=Y 
 */
function smarty_function_url($params, &$smarty)
{
    return Piwik_Url::getCurrentScriptName() . Piwik_Url::getCurrentQueryStringWithParametersModified($params);
}
/**
 * Rewrites the given URL and modify the given parameters.
 * @see Piwik_Url::getCurrentQueryStringWithParametersModified()
 * 
 * @return string
 */
function smarty_modifier_urlRewriteWithParameters($parameters)
{
    $url = Piwik_Url::getCurrentQueryStringWithParametersModified($parameters);
    return htmlspecialchars($url);
}
Esempio n. 20
0
 /**
  * Checks if a datatable for a view is empty and if so, displays a message in the footer
  * telling users to configure GeoIP.
  */
 private function checkIfNoDataForGeoIpReport($view)
 {
     // only display on HTML tables since the datatable for HTML graphs aren't accessible
     if (!$view instanceof Piwik_ViewDataTable_HtmlTable) {
         return;
     }
     // if there's only one row whose label is 'Unknown', display a message saying there's no data
     $view->main();
     $dataTable = $view->getDataTable();
     if ($dataTable->getRowsCount() == 1 && $dataTable->getFirstRow()->getColumn('label') == Piwik_Translate('General_Unknown')) {
         $params = array('module' => 'UserCountry', 'action' => 'adminIndex');
         $footerMessage = Piwik_Translate('UserCountry_NoDataForGeoIPReport', array('<a target="_blank" href="' . Piwik_Url::getCurrentQueryStringWithParametersModified($params) . '">', '</a>', '<a target="_blank" href="http://dev.maxmind.com/geoip/geolite?rId=piwik">', '</a>', '<a target="_blank" href="http://piwik.org/faq/how-to/#faq_167">', '</a>'));
         // HACK! Can't use setFooterMessage because the view gets built in the main function,
         // so instead we set the property by hand.
         $realView = $view->getView();
         $properties = $realView->properties;
         $properties['show_footer_message'] = $footerMessage;
         $realView->properties = $properties;
     }
 }
Esempio n. 21
0
	/**
	 * Returns the current URL to use in a img src=X to display a sparkline.
	 * $action must be the name of a Controller method that requests data using the Piwik_ViewDataTable::factory
	 * It will automatically build a sparkline by setting the viewDataTable=sparkline parameter in the URL.
	 * It will also computes automatically the 'date' for the 'last30' days/weeks/etc. 
	 *
	 * @param string $action Method name of the controller to call in the img src
	 * @param array Array of name => value of parameters to set in the generated GET url 
	 * @return string The generated URL
	 */
	protected function getUrlSparkline( $action, $customParameters = array() )
	{
		$params = $this->getGraphParamsModified( 
					array(	'viewDataTable' => 'sparkline', 
							'action' => $action,
							'module' => $this->pluginName)
					+ $customParameters
				);
		// convert array values to comma separated
		foreach($params as &$value)
		{
			if(is_array($value))
			{
				$value = implode(',', $value);
			}
		}
		$url = Piwik_Url::getCurrentQueryStringWithParametersModified($params);
		return $url;
	}
Esempio n. 22
0
 function sparklines()
 {
     require_once PIWIK_INCLUDE_PATH . '/core/SmartyPlugins/function.sparkline.php';
     $srcSparkline1 = Piwik_Url::getCurrentQueryStringWithParametersModified(array('action' => 'generateSparkline', 'server' => 'server1', 'rand' => rand()));
     $htmlSparkline1 = smarty_function_sparkline(array('src' => $srcSparkline1));
     echo "<div class='sparkline'>{$htmlSparkline1} Evolution of temperature for server piwik.org</div>";
     $srcSparkline2 = Piwik_Url::getCurrentQueryStringWithParametersModified(array('action' => 'generateSparkline', 'server' => 'server2', 'rand' => rand()));
     $htmlSparkline2 = smarty_function_sparkline(array('src' => $srcSparkline2));
     echo "<div class='sparkline'>{$htmlSparkline2} Evolution of temperature for server dev.piwik.org</div>";
 }
Esempio n. 23
0
 public function getInformation()
 {
     return array('description' => Piwik_Translate('ImageGraph_PluginDescription') . ' Debug: <a href="' . Piwik_Url::getCurrentQueryStringWithParametersModified(array('module' => 'ImageGraph', 'action' => 'index')) . '">All images</a>', 'author' => 'Piwik', 'author_homepage' => 'http://piwik.org/', 'version' => Piwik_Version::VERSION);
 }
Esempio n. 24
0
/**
 * Smarty {url} function plugin.
 * Generates a piwik URL with the specified parameters modified.
 *
 * Examples:
 * <pre>
 * {url module="API"} will rewrite the URL modifying the module GET parameter
 * {url module="API" method="getKeywords"} will rewrite the URL modifying the parameters module=API method=getKeywords
 * </pre>
 * 
 * @see Piwik_Url::getCurrentQueryStringWithParametersModified()
 * @param $name=$value of the parameters to modify in the generated URL
 * @return	string Something like index.php?module=X&action=Y 
 */
function smarty_function_url($params, &$smarty)
{
    return htmlspecialchars('index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified($params));
}
Esempio n. 25
0
 /**
  * Returns the current URL to use in a img src=X to display a sparkline.
  * $action must be the name of a Controller method that requests data using the Piwik_ViewDataTable::factory
  * It will automatically build a sparkline by setting the viewDataTable=sparkline parameter in the URL.
  * It will also computes automatically the 'date' for the 'last30' days/weeks/etc. 
  *
  * @param string $action, eg. method name of the controller to call in the img src
  * @param array array of name => value of parameters to set in the generated GET url 
  * @return string the generated URL
  */
 protected function getUrlSparkline($action, $customParameters = array())
 {
     $params = $this->getGraphParamsModified(array('viewDataTable' => 'sparkline', 'action' => $action, 'module' => $this->pluginName) + $customParameters);
     $url = Piwik_Url::getCurrentQueryStringWithParametersModified($params);
     return $url;
 }
Esempio n. 26
0
 /**
  * Redirect to module (and action)
  *
  * @param string $newModule Target module
  * @param string $newAction Target action
  * @param array $parameters Parameters to modify in the URL
  * @return bool false if the URL to redirect to is already this URL
  */
 public static function redirectToModule($newModule, $newAction = '', $parameters = array())
 {
     $newUrl = 'index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified(array('module' => $newModule, 'action' => $newAction) + $parameters);
     Piwik_Url::redirectToUrl($newUrl);
 }
Esempio n. 27
0
 /**
  * Returns URL for this report w/o any filter parameters.
  * 
  * @param string $module
  * @param string $action
  * @param array $queryParams
  */
 private function getBaseReportUrl($module, $action, $queryParams = array())
 {
     $params = array_merge($queryParams, array('module' => $module, 'action' => $action));
     // unset all filter query params so the related report will show up in its default state,
     // unless the filter param was in $queryParams
     $genericFiltersInfo = Piwik_API_DataTableGenericFilter::getGenericFiltersInformation();
     foreach ($genericFiltersInfo as $filter) {
         foreach ($filter as $queryParamName => $queryParamInfo) {
             if (!isset($params[$queryParamName])) {
                 $params[$queryParamName] = null;
             }
         }
     }
     // add the related report
     $url = Piwik_Url::getCurrentQueryStringWithParametersModified($params);
     return $url;
 }