Exemple #1
0
 /**
  * Returns singleton
  *
  * @return Piwik_LogStats_Config
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Exemple #2
0
 private function initProcess()
 {
     try {
         $pluginsLogStats = Piwik_LogStats_Config::getInstance()->Plugins_LogStats;
         if (is_array($pluginsLogStats) && count($pluginsLogStats) != 0) {
             Piwik_PluginsManager::getInstance()->doNotLoadAlwaysActivatedPlugins();
             Piwik_PluginsManager::getInstance()->setPluginsToLoad($pluginsLogStats['Plugins_LogStats']);
         }
     } catch (Exception $e) {
     }
     $saveStats = Piwik_LogStats_Config::getInstance()->LogStats['record_statistics'];
     if ($saveStats == 0) {
         $this->setState(self::STATE_LOGGING_DISABLE);
     }
     if (count($_GET) == 0) {
         $this->setState(self::STATE_NO_GET_VARIABLE);
     }
     $downloadVariableName = Piwik_LogStats_Config::getInstance()->LogStats['download_url_var_name'];
     $urlDownload = Piwik_Common::getRequestVar($downloadVariableName, '', 'string');
     if (!empty($urlDownload)) {
         if (Piwik_Common::getRequestVar('redirect', 1, 'int') == 1) {
             $this->setState(self::STATE_TO_REDIRECT_URL);
         }
         $this->setUrlToRedirect($urlDownload);
     }
     $outlinkVariableName = Piwik_LogStats_Config::getInstance()->LogStats['outlink_url_var_name'];
     $urlOutlink = Piwik_Common::getRequestVar($outlinkVariableName, '', 'string');
     if (!empty($urlOutlink)) {
         if (Piwik_Common::getRequestVar('redirect', 1, 'int') == 1) {
             $this->setState(self::STATE_TO_REDIRECT_URL);
         }
         $this->setUrlToRedirect($urlOutlink);
     }
 }
Exemple #3
0
 /**
  * Generates a new action for the current visitor.
  * We random generate some campaigns, action names, download or outlink clicks, etc.
  * We generate a new Referer, that would be read in the case the visit last page is older than 30 minutes.
  * 
  * This function tries to generate actions that use the features of Piwik (campaigns, downloads, outlinks, action_name set in the JS tag, etc.)
  * 
  * @return void
  * 
  */
 protected function generateActionVisit()
 {
     // we don't keep the previous action values
     // reinit them to empty string
     $this->setCurrentRequest(Piwik_LogStats_Config::getInstance()->LogStats['download_outlink_name_var'], '');
     $this->setCurrentRequest(Piwik_LogStats_Config::getInstance()->LogStats['download_url_var_name'], '');
     $this->setCurrentRequest(Piwik_LogStats_Config::getInstance()->LogStats['outlink_url_var_name'], '');
     $this->setCurrentRequest('action_name', '');
     // generate new url referer ; case the visitor stays more than 30min
     // (when the visit is known this value will simply be ignored)
     $this->setCurrentRequest('urlref', $this->getRandom('urlref'));
     // generates the current URL
     $url = $this->getRandomUrlFromHost($this->host);
     // we generate a campaign (partner or newsletter or campaign)
     $urlVars = $this->getRandom('piwik_vars_campaign');
     // if we actually generated a campaign
     if (!empty($urlVars)) {
         // campaign name
         $urlValue = $this->getRandomString(5, 3, 'lower');
         // add the parameter to the url
         $url .= '?' . $urlVars . '=' . $urlValue;
         // for a campaign of the CPC kind, we sometimes generate a keyword
         if ($urlVars == Piwik_LogStats_Config::getInstance()->LogStats['campaign_var_name'] && mt_rand(0, 1) == 0) {
             $url .= '&' . Piwik_LogStats_Config::getInstance()->LogStats['campaign_keyword_var_name'] . '=' . $this->getRandomString(6, 3, 'ALL');
         }
     } else {
         // we generate a download Or Outlink parameter in the GET request so that
         // the current action is counted as a download action OR a outlink click action
         $GETParamToAdd = $this->getRandom('piwik_downloadOrOutlink');
         if (!empty($GETParamToAdd)) {
             $possibleDownloadHosts = array('http://piwik.org/', $this->host);
             $nameDownload = $this->getRandomUrlFromHost($possibleDownloadHosts[mt_rand(0, 1)]);
             $extensions = array('.zip', '.tar.gz');
             $nameDownload .= $extensions[mt_rand(0, 1)];
             $urlValue = $nameDownload;
             // add the parameter to the url
             $this->setCurrentRequest($GETParamToAdd, $urlValue);
             // in 50% we give a special name to the download/outlink
             if (mt_rand(0, 1) == 0) {
                 $nameDownload = $this->getRandomString(6, 3, 'ALL');
                 $this->setCurrentRequest(Piwik_LogStats_Config::getInstance()->LogStats['download_outlink_name_var'], $nameDownload);
             }
         } elseif (rand(0, 2) == 1) {
             $this->setCurrentRequest('action_name', $this->getRandomString(1, 1));
         }
     }
     $this->setCurrentRequest('url', $url);
     // setup the title of the page
     $this->setCurrentRequest('title', $this->getRandomString(15, 5));
 }
Exemple #4
0
 private function detectRefererCampaign()
 {
     if (isset($this->currentUrlParse['query'])) {
         $campaignVariableName = Piwik_LogStats_Config::getInstance()->LogStats['campaign_var_name'];
         $campaignName = Piwik_Common::getParameterFromQueryString($this->currentUrlParse['query'], $campaignVariableName);
         if (!empty($campaignName)) {
             $campaignKeywordVariableName = Piwik_LogStats_Config::getInstance()->LogStats['campaign_keyword_var_name'];
             $campaignKeyword = Piwik_Common::getParameterFromQueryString($this->currentUrlParse['query'], $campaignKeywordVariableName);
             $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_CAMPAIGN;
             $this->nameRefererAnalyzed = $campaignName;
             if (!empty($campaignKeyword)) {
                 $this->keywordRefererAnalyzed = $campaignKeyword;
             }
             return true;
         }
     }
 }
Exemple #5
0
 /**
  * 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;
 }
Exemple #6
0
 /**
  * Returns the table name prefixed by the table prefix.
  * 
  * @param string The table name to prefix, ie "log_visit"
  * @return string The table name prefixed, ie "piwik-production_log_visit"
  */
 public function prefixTable($suffix)
 {
     static $prefix;
     if (!isset($prefix)) {
         $prefix = Piwik_LogStats_Config::getInstance()->database['tables_prefix'];
     }
     return $prefix . $suffix;
 }