Пример #1
0
 /** Render the area left of the iframe */
 public function renderSidebar()
 {
     $idSite = Piwik_Common::getRequestVar('idSite');
     $period = Piwik_Common::getRequestVar('period');
     $date = Piwik_Common::getRequestVar('date');
     $currentUrl = Piwik_Common::getRequestVar('currentUrl');
     $currentUrl = Piwik_Common::unsanitizeInputValue($currentUrl);
     $normalizedCurrentUrl = Piwik_Tracker_Action::excludeQueryParametersFromUrl($currentUrl, $idSite);
     $normalizedCurrentUrl = Piwik_Common::unsanitizeInputValue($normalizedCurrentUrl);
     // load the appropriate row of the page urls report using the label filter
     Piwik_Actions_ArchivingHelper::reloadConfig();
     $path = Piwik_Actions_ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Piwik_Tracker_Action::TYPE_ACTION_URL);
     $path = array_map('urlencode', $path);
     $label = implode('>', $path);
     $request = new Piwik_API_Request('method=Actions.getPageUrls' . '&idSite=' . urlencode($idSite) . '&date=' . urlencode($date) . '&period=' . urlencode($period) . '&label=' . urlencode($label) . '&format=original');
     $dataTable = $request->process();
     $data = array();
     if ($dataTable->getRowsCount() > 0) {
         $row = $dataTable->getFirstRow();
         $translations = Piwik_API_API::getDefaultMetricTranslations();
         $showMetrics = array('nb_hits', 'nb_visits', 'nb_uniq_visitors', 'bounce_rate', 'exit_rate', 'avg_time_on_page');
         foreach ($showMetrics as $metric) {
             $value = $row->getColumn($metric);
             if ($value === false) {
                 // skip unique visitors for period != day
                 continue;
             }
             if ($metric == 'avg_time_on_page') {
                 $value = Piwik::getPrettyTimeFromSeconds($value);
             }
             $data[] = array('name' => $translations[$metric], 'value' => $value);
         }
     }
     // generate page url string
     foreach ($path as &$part) {
         $part = preg_replace(';^/;', '', urldecode($part));
     }
     $page = '/' . implode('/', $path);
     $page = preg_replace(';/index$;', '/', $page);
     if ($page == '/') {
         $page = '/index';
     }
     // render template
     $view = Piwik_View::factory('sidebar');
     $view->data = $data;
     $view->location = $page;
     $view->normalizedUrl = $normalizedCurrentUrl;
     $view->label = $label;
     $view->idSite = $idSite;
     $view->period = $period;
     $view->date = $date;
     echo $view->render();
 }
 /**
  * @group		Integration
  * @group		BlobReportLimiting
  */
 public function testApiWithRankingQuery()
 {
     // custom setup
     self::deleteArchiveTables();
     $generalConfig['datatable_archiving_maximum_rows_referers'] = 4;
     $generalConfig['datatable_archiving_maximum_rows_subtable_referers'] = 4;
     $generalConfig['datatable_archiving_maximum_rows_actions'] = 4;
     $generalConfig['datatable_archiving_maximum_rows_subtable_actions'] = 4;
     $generalConfig['datatable_archiving_maximum_rows_standard'] = 4;
     Piwik_Config::getInstance()->General['archiving_ranking_query_row_limit'] = 3;
     Piwik_Actions_ArchivingHelper::reloadConfig();
     foreach ($this->getApiForTesting() as $pair) {
         list($apiToCall, $params) = $pair;
         $params['testSuffix'] = '_rankingQuery';
         $this->runApiTests($apiToCall, $params);
     }
 }
Пример #3
0
 public static function clearActionsCache()
 {
     self::$cacheParsedAction = array();
 }
Пример #4
0
 /**
  * Derive the action ID from the request action name and type.
  */
 private function deriveIdAction($actionName, $actionType)
 {
     $actionsPlugin = new Piwik_Actions();
     switch ($actionType) {
         case 'url':
             $originalActionName = $actionName;
             $actionName = Piwik_Common::unsanitizeInputValue($actionName);
             $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url');
             if ($id < 0) {
                 // an example where this is needed is urls containing < or >
                 $actionName = $originalActionName;
                 $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url');
             }
             return $id;
         case 'title':
             $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_name');
             if ($id < 0) {
                 $unkown = Piwik_Actions_ArchivingHelper::getUnknownActionName(Piwik_Tracker_Action::TYPE_ACTION_NAME);
                 if (trim($actionName) == trim($unkown)) {
                     $id = $actionsPlugin->getIdActionFromSegment('', 'idaction_name');
                 }
             }
             return $id;
         default:
             throw new Exception('Unknown action type');
     }
 }
Пример #5
0
 private function getPageLabel(&$pageRecord, $isTitle)
 {
     if ($isTitle) {
         $label = $pageRecord['name'];
         if (empty($label)) {
             $label = Piwik_Actions_ArchivingHelper::getUnknownActionName(Piwik_Tracker_Action::TYPE_ACTION_NAME);
         }
         return $label;
     } else {
         if ($this->returnNormalizedUrls) {
             return $pageRecord['name'];
         } else {
             return Piwik_Tracker_Action::reconstructNormalizedUrl($pageRecord['name'], $pageRecord['url_prefix']);
         }
     }
 }
Пример #6
0
 /**
  * @param $select
  * @param $from
  * @param $where
  * @param $orderBy
  * @param $groupBy
  * @param $sprintfField
  * @param Piwik_ArchiveProcessing $archiveProcessing
  * @param Piwik_RankingQuery|false $rankingQuery
  * @return int
  */
 protected function archiveDayQueryProcess($select, $from, $where, $orderBy, $groupBy, $sprintfField, $archiveProcessing, $rankingQuery = false)
 {
     // idaction field needs to be set in select clause before calling getSelectQuery().
     // if a complex segmentation join is needed, the field needs to be propagated
     // to the outer select. therefore, $segment needs to know about it.
     $select = sprintf($select, $sprintfField);
     $bind = array();
     // get query with segmentation
     $query = $archiveProcessing->getSegment()->getSelectQuery($select, $from, $where, $bind, $orderBy, $groupBy);
     // extend bindings
     $bind = array_merge(array($archiveProcessing->getStartDatetimeUTC(), $archiveProcessing->getEndDatetimeUTC(), $archiveProcessing->idsite), $query['bind']);
     // replace the rest of the %s
     $querySql = str_replace("%s", $sprintfField, $query['sql']);
     // apply ranking query
     if ($rankingQuery) {
         $querySql = $rankingQuery->generateQuery($querySql);
     }
     //      echo '<pre>';var_dump($querySql);
     //      var_dump($bind);
     // get result
     $resultSet = $archiveProcessing->db->query($querySql, $bind);
     $modified = Piwik_Actions_ArchivingHelper::updateActionsTableWithRowQuery($resultSet, $sprintfField, $this->actionsTablesByType);
     return $modified;
 }
Пример #7
0
 /**
  * Will search in the DataTable for a Label matching the searched string
  * and return only the matching row, or an empty datatable
  */
 protected function getFilterPageDatatableSearch($callBackParameters, $search, $actionType, $table = false, $searchTree = false)
 {
     if ($searchTree === false) {
         // build the query parts that are searched inside the tree
         if ($actionType == Piwik_Tracker_Action::TYPE_ACTION_NAME) {
             $searchedString = Piwik_Common::unsanitizeInputValue($search);
         } else {
             $idSite = $callBackParameters[1];
             try {
                 $searchedString = Piwik_Tracker_Action::excludeQueryParametersFromUrl($search, $idSite);
             } catch (Exception $e) {
                 $searchedString = $search;
             }
         }
         Piwik_Actions_ArchivingHelper::reloadConfig();
         $searchTree = Piwik_Actions_ArchivingHelper::getActionExplodedNames($searchedString, $actionType);
     }
     if ($table === false) {
         // fetch the data table
         $table = call_user_func_array(array('Piwik_Archive', 'getDataTableFromArchive'), $callBackParameters);
         if ($table instanceof Piwik_DataTable_Array) {
             // search an array of tables, e.g. when using date=last30
             // note that if the root is an array, we filter all children
             // if an array occurs inside the nested table, we only look for the first match (see below)
             $newTableArray = new Piwik_DataTable_Array();
             $newTableArray->metadata = $table->metadata;
             $newTableArray->setKeyName($table->getKeyName());
             foreach ($table->getArray() as $label => $subTable) {
                 $subTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);
                 $newTableArray->addTable($subTable, $label);
             }
             return $newTableArray;
         }
     }
     return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
 }
Пример #8
0
 /**
  * @dataProvider getActionNameTestData
  * @group        Plugins
  * @group        Actions
  */
 public function testGetActionExplodedNames($params, $expected)
 {
     Piwik_Actions_ArchivingHelper::reloadConfig();
     $processed = Piwik_Actions_ArchivingHelper::getActionExplodedNames($params['name'], $params['type'], isset($params['urlPrefix']) ? $params['urlPrefix'] : null);
     $this->assertEquals($expected, $processed);
 }