/** 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(); }
private function getMetricTranslations($metricsToTranslate) { $translations = Metrics::getDefaultMetricTranslations(); $metrics = array(); foreach ($metricsToTranslate as $metric) { if (!empty($translations[$metric])) { $metrics[$metric] = $translations[$metric]; } else { $metrics[$metric] = $metric; } } return $metrics; }
/** * Translate column names to the current language. * Used in subclasses. * * @param array $names * @return array */ protected function translateColumnNames($names) { if (!$this->apiMethod) { return $names; } // load the translations only once // when multiple dates are requested (date=...,...&period=day), the meta data would // be loaded lots of times otherwise if ($this->columnTranslations === false) { $meta = $this->getApiMetaData(); if ($meta === false) { return $names; } $t = Metrics::getDefaultMetricTranslations(); foreach (array('metrics', 'processedMetrics', 'metricsGoal', 'processedMetricsGoal') as $index) { if (isset($meta[$index]) && is_array($meta[$index])) { $t = array_merge($t, $meta[$index]); } } $this->columnTranslations =& $t; } foreach ($names as &$name) { if (isset($this->columnTranslations[$name])) { $name = $this->columnTranslations[$name]; } } return $names; }
/** * Default translations for many core metrics. * This is used for exports with translated labels. The exports contain columns that * are not visible in the UI and not present in the API meta data. These columns are * translated here. * @return array * @deprecated since Piwik 2.15.1 */ public function getDefaultMetricTranslations() { return Metrics::getDefaultMetricTranslations(); }
public function __construct() { parent::__construct(); $this->translations = Metrics::getDefaultMetricTranslations(); }
private function getMetricTranslations($metricsToTranslate) { $translations = Metrics::getDefaultMetricTranslations(); $metrics = array(); foreach ($metricsToTranslate as $metric) { if ($metric instanceof Metric) { $metricName = $metric->getName(); $translation = $metric->getTranslatedName(); } else { $metricName = $metric; $translation = @$translations[$metric]; } $metrics[$metricName] = $translation ?: $metricName; } return $metrics; }