Beispiel #1
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);
 }
Beispiel #2
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), '');
 }
Beispiel #3
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;
        }
    }
Beispiel #4
0
 /**
  * Check force_ssl_login and redirect if connection isn't secure and not using a reverse proxy
  *
  * @param none
  * @return void
  */
 protected function checkForceSslLogin()
 {
     $forceSslLogin = Zend_Registry::get('config')->General->force_ssl_login;
     if ($forceSslLogin) {
         if (!Piwik::isHttps()) {
             $url = 'https://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName() . Piwik_Url::getCurrentQueryString();
             Piwik_Url::redirectToUrl($url);
         }
     }
 }
Beispiel #5
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);
}
Beispiel #6
0
 /**
  * Check force_ssl_login and redirect if connection isn't secure and not using a reverse proxy
  *
  * @param none
  * @return void
  */
 protected function checkForceSslLogin()
 {
     $forceSslLogin = Piwik_Config::getInstance()->General['force_ssl_login'];
     if ($forceSslLogin && !Piwik::isHttps()) {
         $url = 'https://' . Piwik_Url::getCurrentHost() . Piwik_Url::getCurrentScriptName() . Piwik_Url::getCurrentQueryString();
         Piwik_Url::redirectToUrl($url);
     }
 }
Beispiel #7
0
 /**
  * @group Core
  * @group Url
  */
 public function test_getCurrentScriptName()
 {
     $names = array('PATH_INFO', 'REQUEST_URI', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'argv', 'HTTPS', 'HTTP_HOST', 'QUERY_STRING', 'HTTP_REFERER');
     foreach ($names as $name) {
         unset($_SERVER[$name]);
     }
     $tests = array(array('/', 'http://example.com/', null), array('/', '/', null), array('/index.php', '/index.php', null), array('/index.php', '/index.php?module=Foo', null), array('/index.php', '/index.php/route/1', '/route/1'), array('/index.php', '/index.php/route/2?module=Bar', '/route/2'), array('/path/index.php', '/path/index.php/route/3/?module=Fu&action=Bar#Hash', '/route/3/'));
     foreach ($tests as $test) {
         list($expected, $uri, $pathInfo) = $test;
         $_SERVER['REQUEST_URI'] = $uri;
         $_SERVER['PATH_INFO'] = $pathInfo;
         $scriptPathName = Piwik_Url::getCurrentScriptName();
         $this->assertEquals($expected, $scriptPathName);
     }
 }