/**
  * @expectedException \Exception
  * @expectedExceptionMessage The segment 'pageUrl=!1.0' is not valid.
  */
 public function test_getHumanReadable_ShouldThrowAnException_IfSegmentCannotBeParsedBecauseOfInvalidFormat()
 {
     $invalidOperator = '=!';
     $this->formatter->getHumanReadable($segment = 'pageUrl' . $invalidOperator . '1.0', $this->idSite);
 }
示例#2
0
 /** 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');
     $segment = Request::getRawSegmentFromRequest();
     $currentUrl = Common::unsanitizeInputValue($currentUrl);
     $segmentSidebar = '';
     $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);
     $params = array('idSite' => $idSite, 'date' => $date, 'period' => $period, 'label' => $label, 'format' => 'original', 'format_metrics' => 0);
     if (!empty($segment)) {
         $params['segment'] = $segment;
     }
     $dataTable = Request::processRequest('Actions.getPageUrls', $params);
     $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');
         $segmentSidebar = $row->getMetadata('segment');
         if (!empty($segmentSidebar) && !empty($segment)) {
             $segmentSidebar = $segment . ';' . $segmentSidebar;
         }
         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;
     $view->segment = $segmentSidebar;
     $view->segmentDescription = $this->segmentFormatter->getHumanReadable($segment, $idSite);
     $this->outputCORSHeaders();
     return $view->render();
 }