function Piwik_getPathFromUrl($url) { $path = Piwik_Common::getPathAndQueryFromUrl($url); if (empty($path)) { return 'index'; } return $path; }
/** * 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; }
/** * Generates the name of the action from the URL or the specified name. * Sets the name as $this->actionName * * @return void */ protected function extractUrlAndActionNameFromRequest() { // download? $downloadVariableName = Piwik_Tracker_Config::getInstance()->Tracker['download_url_var_name']; $downloadUrl = Piwik_Common::getRequestVar($downloadVariableName, '', 'string', $this->request); if (!empty($downloadUrl)) { $actionType = self::TYPE_DOWNLOAD; $url = $downloadUrl; } // outlink? if (empty($actionType)) { $outlinkVariableName = Piwik_Tracker_Config::getInstance()->Tracker['outlink_url_var_name']; $outlinkUrl = Piwik_Common::getRequestVar($outlinkVariableName, '', 'string', $this->request); if (!empty($outlinkUrl)) { $actionType = self::TYPE_OUTLINK; $url = $outlinkUrl; } } // defaults to page view if (empty($actionType)) { $actionType = self::TYPE_ACTION; $url = Piwik_Common::getRequestVar('url', '', 'string', $this->request); $actionName = Piwik_Common::getRequestVar('action_name', '', 'string', $this->request); if (empty($actionName)) { $cleanedUrl = str_replace(array("\n", "\r", "\t"), "", $url); $actionName = Piwik_Common::getPathAndQueryFromUrl($cleanedUrl); // in case the $actionName is empty or ending with a slash, // we append the defaultActionName: a/b/ becomes a/b/index if (empty($actionName) || substr($actionName, -1) == '/') { $actionName .= $this->getDefaultActionName(); } } // get the delimiter, by default '/' $actionCategoryDelimiter = Piwik_Tracker_Config::getInstance()->General['action_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 = trim($url); $url = str_replace(array("\n", "\r"), "", $url); if (empty($actionName)) { $actionName = $url; } return array('name' => $actionName, 'type' => $actionType, 'url' => $url); }
/** * @group Core * @group Common * @group getPathAndQueryFromUrl */ public function testGetPathAndQueryFromUrl() { $this->assertEquals('test/index.php?module=CoreHome', Piwik_Common::getPathAndQueryFromUrl('http://piwik.org/test/index.php?module=CoreHome')); }