Beispiel #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();
 }
 /**
  * Translate column names to the current language.
  * Used in subclasses.
  */
 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 = Piwik_API_API::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;
 }