コード例 #1
0
ファイル: Common.test.php プロジェクト: nnnnathann/piwik
 function test_isUrl_notvalid()
 {
     $notValid = array('it doesnt look like url', '/index?page=test', 'test.html', '/\\/\\/\\/\\/\\/\\\\http://test.com////', 'jmleslangues.php', 'http://', ' http://', 'testhttp://test.com');
     foreach ($notValid as $url) {
         $this->assertTrue(!Piwik_Common::isLookLikeUrl($url), "{$url} validated");
     }
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: neolf/PIWIK4MOBILE
 function getRank()
 {
     $idSite = Piwik_Common::getRequestVar('idSite');
     $site = new Piwik_Site($idSite);
     $url = urldecode(Piwik_Common::getRequestVar('url', '', 'string'));
     if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
         $url = 'http://' . $url;
     }
     if (empty($url) || !Piwik_Common::isLookLikeUrl($url)) {
         $url = $site->getMainUrl();
     }
     $dataTable = Piwik_SEO_API::getInstance()->getRank($url);
     $view = Piwik_View::factory('index');
     $view->urlToRank = Piwik_SEO_RankChecker::extractDomainFromUrl($url);
     $renderer = Piwik_DataTable_Renderer::factory('php');
     $renderer->setSerialize(false);
     $view->ranks = $renderer->render($dataTable);
     echo $view->render();
 }
コード例 #3
0
ファイル: Url.php プロジェクト: nnnnathann/piwik
 /**
  * Redirects the user to the specified URL
  *
  * @param string $url
  */
 public static function redirectToUrl($url)
 {
     if (Piwik_Common::isLookLikeUrl($url) || strpos($url, 'index.php') === 0) {
         @header("Location: {$url}");
     } else {
         echo "Invalid URL to redirect to.";
     }
     exit;
 }
コード例 #4
0
ファイル: Controller.php プロジェクト: nnnnathann/piwik
 /**
  * Used to generate the doc at http://piwik.org/docs/tracking-api/
  */
 function displayAlternativeTagsHelp()
 {
     $view = Piwik_View::factory('DisplayAlternativeTags');
     $view->idSite = Piwik_Common::getRequestVar('idSite');
     $url = Piwik_Common::getRequestVar('piwikUrl', '', 'string');
     if (empty($url) || !Piwik_Common::isLookLikeUrl($url)) {
         $url = $view->piwikUrl;
     }
     $view->piwikUrlRequest = $url;
     $view->calledExternally = true;
     echo $view->render();
 }
コード例 #5
0
ファイル: Visitor.php プロジェクト: nnnnathann/piwik
 function getRefererUrl()
 {
     if ($this->getRefererType() == 'search') {
         if (Piwik_PluginsManager::getInstance()->isPluginActivated('Referers') && $this->details['referer_keyword'] == Piwik_Referers::LABEL_KEYWORD_NOT_DEFINED) {
             return 'http://piwik.org/faq/general/#faq_144';
         } elseif ($this->getRefererName() == 'Google' && strpos($this->details['referer_url'], '/url')) {
             $refUrl = @parse_url($this->details['referer_url']);
             if (isset($refUrl['host'])) {
                 $url = Piwik_getSearchEngineUrlFromUrlAndKeyword('http://google.com', $this->getKeyword());
                 $url = str_replace('google.com', $refUrl['host'], $url);
                 return $url;
             }
         }
     }
     if (Piwik_Common::isLookLikeUrl($this->details['referer_url'])) {
         return $this->details['referer_url'];
     }
     return null;
 }
コード例 #6
0
ファイル: API.php プロジェクト: BackupTheBerlios/oos-svn
 /**
  * Tests if the URL is a valid URL
  * 
  * @return bool
  */
 private static function isValidUrl($url)
 {
     return Piwik_Common::isLookLikeUrl($url);
 }
コード例 #7
0
ファイル: archive.php プロジェクト: nomoto-ubicast/piwik
 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";
 }
コード例 #8
0
ファイル: Action.php プロジェクト: nnnnathann/piwik
 /**
  * Generates the name of the action from the URL or the specified name.
  * Sets the name as $this->actionName
  *
  * @return array
  */
 protected function extractUrlAndActionNameFromRequest()
 {
     $actionName = null;
     // download?
     $downloadUrl = Piwik_Common::getRequestVar('download', '', 'string', $this->request);
     if (!empty($downloadUrl)) {
         $actionType = self::TYPE_DOWNLOAD;
         $url = $downloadUrl;
     }
     // outlink?
     if (empty($actionType)) {
         $outlinkUrl = Piwik_Common::getRequestVar('link', '', 'string', $this->request);
         if (!empty($outlinkUrl)) {
             $actionType = self::TYPE_OUTLINK;
             $url = $outlinkUrl;
         }
     }
     // handle encoding
     $actionName = Piwik_Common::getRequestVar('action_name', '', 'string', $this->request);
     // defaults to page view
     if (empty($actionType)) {
         $actionType = self::TYPE_ACTION_URL;
         $url = Piwik_Common::getRequestVar('url', '', 'string', $this->request);
         // get the delimiter, by default '/'; BC, we read the old action_category_delimiter first (see #1067)
         $actionCategoryDelimiter = isset(Piwik_Config::getInstance()->General['action_category_delimiter']) ? Piwik_Config::getInstance()->General['action_category_delimiter'] : Piwik_Config::getInstance()->General['action_url_category_delimiter'];
         // create an array of the categories delimited by the delimiter
         $split = explode($actionCategoryDelimiter, $actionName);
         // trim every category
         $split = array_map('trim', $split);
         // remove empty categories
         $split = array_filter($split, 'strlen');
         // rebuild the name from the array of cleaned categories
         $actionName = implode($actionCategoryDelimiter, $split);
     }
     $url = self::cleanupString($url);
     if (!Piwik_Common::isLookLikeUrl($url)) {
         $url = '';
     }
     $actionName = self::cleanupString($actionName);
     return array('name' => empty($actionName) ? '' : $actionName, 'type' => $actionType, 'url' => $url);
 }
コード例 #9
0
ファイル: Visit.php プロジェクト: nnnnathann/piwik
 /**
  * Returns an array containing the following information:
  * - referer_type
  *        - direct            -- absence of referer URL OR referer URL has the same host
  *        - site                -- based on the referer URL
  *        - search_engine        -- based on the referer URL
  *        - campaign            -- based on campaign URL parameter
  *
  * - referer_name
  *         - ()
  *         - piwik.net            -- site host name
  *         - google.fr            -- search engine host name
  *         - adwords-search    -- campaign name
  *
  * - referer_keyword
  *         - ()
  *         - ()
  *         - my keyword
  *         - my paid keyword
  *         - ()
  *         - ()
  *
  * - referer_url : the same for all the referer types
  *
  * @param $refererUrl must be URL Encoded
  * @param $currentUrl
  * @param $idSite
  * @return array
  */
 public function getRefererInformation($refererUrl, $currentUrl, $idSite)
 {
     $this->idsite = $idSite;
     // default values for the referer_* fields
     $refererUrl = Piwik_Common::unsanitizeInputValue($refererUrl);
     if (!empty($refererUrl) && !Piwik_Common::isLookLikeUrl($refererUrl)) {
         $refererUrl = '';
     }
     $currentUrl = Piwik_Tracker_Action::cleanupUrl($currentUrl);
     $this->refererUrl = $refererUrl;
     $this->refererUrlParse = @parse_url($this->refererUrl);
     $this->currentUrlParse = @parse_url($currentUrl);
     $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
     $this->nameRefererAnalyzed = '';
     $this->keywordRefererAnalyzed = '';
     $this->refererHost = '';
     if (isset($this->refererUrlParse['host'])) {
         $this->refererHost = $this->refererUrlParse['host'];
     }
     $refererDetected = false;
     if (!empty($this->currentUrlParse['host']) && $this->detectRefererCampaign()) {
         $refererDetected = true;
     }
     if (!$refererDetected) {
         if ($this->detectRefererDirectEntry() || $this->detectRefererSearchEngine()) {
             $refererDetected = true;
         }
     }
     if (!empty($this->refererHost) && !$refererDetected) {
         $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_WEBSITE;
         $this->nameRefererAnalyzed = mb_strtolower($this->refererHost, 'UTF-8');
     }
     $refererInformation = array('referer_type' => $this->typeRefererAnalyzed, 'referer_name' => $this->nameRefererAnalyzed, 'referer_keyword' => $this->keywordRefererAnalyzed, 'referer_url' => $this->refererUrl);
     return $refererInformation;
 }
コード例 #10
0
ファイル: Action.php プロジェクト: Doluci/tomatocart
 /**
  * Generates the name of the action from the URL or the specified name.
  * Sets the name as $this->finalActionName
  * 
  * @return void
  */
 private function generateInfo()
 {
     $actionName = '';
     if (!empty($this->downloadUrl)) {
         $this->actionType = self::TYPE_DOWNLOAD;
         $url = $this->downloadUrl;
         //$actionName = $this->nameDownloadOutlink;
         $actionName = $url;
     } elseif (!empty($this->outlinkUrl)) {
         $this->actionType = self::TYPE_OUTLINK;
         $url = $this->outlinkUrl;
         //remove the last '/' character if it's present
         if (substr($url, -1) == '/') {
             $url = substr($url, 0, -1);
         }
         $actionName = $this->nameDownloadOutlink;
         if (empty($actionName)) {
             $actionName = $url;
         }
     } else {
         $this->actionType = self::TYPE_ACTION;
         $url = $this->url;
         $actionName = $this->actionName;
     }
     // the ActionName wasn't specified
     if (empty($actionName)) {
         $actionName = trim(Piwik_Common::getPathAndQueryFromUrl($url));
         // in case the $actionName is ending with a slash,
         // which means that it is the index page of a category
         // we append the defaultActionName
         // toto/tata/ becomes toto/tata/index
         if (strlen($actionName) > 0 && $actionName[strlen($actionName) - 1] == '/') {
             $actionName .= $this->defaultActionName;
         }
     }
     /*
      * Clean the action name
      */
     // get the delimiter, by default '/'
     $actionCategoryDelimiter = Piwik_LogStats_Config::getInstance()->General['action_category_delimiter'];
     // case the name is an URL we dont clean the name the same way
     if (Piwik_Common::isLookLikeUrl($actionName)) {
         $actionName = trim($actionName);
     } else {
         // create an array of the categories delimited by the delimiter
         $split = explode($actionCategoryDelimiter, $actionName);
         // trim every category
         $split = array_map('trim', $split);
         // remove empty categories
         $split = array_filter($split);
         // rebuild the name from the array of cleaned categories
         $actionName = implode($actionCategoryDelimiter, $split);
     }
     // remove the extra bad characters if any (shouldn't be any at this point...)
     $actionName = str_replace(array("\n", "\r"), '', $actionName);
     if (empty($actionName)) {
         $actionName = $this->defaultActionName;
     }
     $this->finalActionName = $actionName;
 }
コード例 #11
0
ファイル: CommonTest.php プロジェクト: nnnnathann/piwik
 /**
  * @dataProvider getUrls
  * @group Core
  * @group Common
  * @group isLookLikeUrl
  */
 public function testIsUrl($url, $isValid)
 {
     $this->assertEquals($isValid, Piwik_Common::isLookLikeUrl($url));
 }