/** Render the area left of the iframe */ public function renderSidebar() { $idSite = Common::getRequestVar('idSite'); $period = Common::getRequestVar('period'); $date = Common::getRequestVar('date'); $currentUrl = Common::getRequestVar('currentUrl'); $currentUrl = Common::unsanitizeInputValue($currentUrl); $normalizedCurrentUrl = PageUrl::excludeQueryParametersFromUrl($currentUrl, $idSite); $normalizedCurrentUrl = Common::unsanitizeInputValue($normalizedCurrentUrl); // load the appropriate row of the page urls report using the label filter ArchivingHelper::reloadConfig(); $path = ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Action::TYPE_PAGE_URL); $path = array_map('urlencode', $path); $label = implode('>', $path); $request = new Request('method=Actions.getPageUrls' . '&idSite=' . urlencode($idSite) . '&date=' . urlencode($date) . '&period=' . urlencode($period) . '&label=' . urlencode($label) . '&format=original' . '&format_metrics=0'); $dataTable = $request->process(); $formatter = new Metrics\Formatter\Html(); $data = array(); if ($dataTable->getRowsCount() > 0) { $row = $dataTable->getFirstRow(); $translations = Metrics::getDefaultMetricTranslations(); $showMetrics = array('nb_hits', 'nb_visits', 'nb_users', '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 == 'bounce_rate' || $metric == 'exit_rate') { $value = $formatter->getPrettyPercentFromQuotient($value); } else { if ($metric == 'avg_time_on_page') { $value = $formatter->getPrettyTimeFromSeconds($value, $displayAsSentence = true); } } $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 = new View('@Overlay/renderSidebar'); $view->data = $data; $view->location = $page; $view->normalizedUrl = $normalizedCurrentUrl; $view->label = $label; $view->idSite = $idSite; $view->period = $period; $view->date = $date; $this->outputCORSHeaders(); return $view->render(); }
public function testApiWithRankingQuery() { // custom setup self::deleteArchiveTables(); Config::getInstance()->General['archiving_ranking_query_row_limit'] = 3; ArchivingHelper::reloadConfig(); foreach ($this->getApiForTesting() as $pair) { list($apiToCall, $params) = $pair; if (empty($params['testSuffix'])) { $params['testSuffix'] = ''; } $params['testSuffix'] .= '_rankingQuery'; $this->runApiTests($apiToCall, $params); } }
public function aggregateMultipleReports() { ArchivingHelper::reloadConfig(); $dataTableToSum = array(self::PAGE_TITLES_RECORD_NAME, self::PAGE_URLS_RECORD_NAME); $this->getProcessor()->aggregateDataTableRecords($dataTableToSum, ArchivingHelper::$maximumRowsInDataTableLevelZero, ArchivingHelper::$maximumRowsInSubDataTable, ArchivingHelper::$columnToSortByBeforeTruncation, self::$columnsAggregationOperation, self::$columnsToRenameAfterAggregation); $dataTableToSum = array(self::DOWNLOADS_RECORD_NAME, self::OUTLINKS_RECORD_NAME, self::SITE_SEARCH_RECORD_NAME); $aggregation = null; $nameToCount = $this->getProcessor()->aggregateDataTableRecords($dataTableToSum, ArchivingHelper::$maximumRowsInDataTableLevelZero, ArchivingHelper::$maximumRowsInSubDataTable, ArchivingHelper::$columnToSortByBeforeTruncation, $aggregation, self::$columnsToRenameAfterAggregation); $this->getProcessor()->aggregateNumericMetrics($this->getMetricNames()); // Unique Keywords can't be summed, instead we take the RowsCount() of the keyword table $this->getProcessor()->insertNumericRecord(self::METRIC_KEYWORDS_RECORD_NAME, $nameToCount[self::SITE_SEARCH_RECORD_NAME]['level0']); }
/** * 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 == Action::TYPE_PAGE_TITLE) { $searchedString = Common::unsanitizeInputValue($search); } else { $idSite = $callBackParameters[1]; try { $searchedString = PageUrl::excludeQueryParametersFromUrl($search, $idSite); } catch (Exception $e) { $searchedString = $search; } } ArchivingHelper::reloadConfig(); $searchTree = ArchivingHelper::getActionExplodedNames($searchedString, $actionType); } if ($table === false) { // fetch the data table $table = call_user_func_array(array($this, 'getDataTableFromArchive'), $callBackParameters); if ($table instanceof DataTable\Map) { // 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) $dataTableMap = $table->getEmptyClone(); foreach ($table->getDataTables() as $label => $subTable) { $newSubTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree); $dataTableMap->addTable($newSubTable, $label); } return $dataTableMap; } } return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree); }
/** * @dataProvider getActionNameTestData */ public function testGetActionExplodedNames($params, $expected) { ArchivingHelper::reloadConfig(); $processed = ArchivingHelper::getActionExplodedNames($params['name'], $params['type'], isset($params['urlPrefix']) ? $params['urlPrefix'] : null); $this->assertEquals($expected, $processed); }