The Request class is used throughout Piwik to call API methods. The difference between using Request and calling API methods directly is that Request will do more after calling the API including: applying generic filters, applying queued filters, and handling the **flat** and **label** query parameters. Additionally, the Request class will **forward current query parameters** to the request which is more convenient than calling {@link Piwik\Common::getRequestVar()} many times over. In most cases, using a Request object to query the API is the correct approach. ### Post-processing The return value of API methods undergo some extra processing before being returned by Request. ### Output Formats The value returned by Request will be serialized to a certain format before being returned. ### Examples **Basic Usage** $request = new Request('method=UserLanguage.getLanguage&idSite=1&date=yesterday&period=week' . '&format=xml&filter_limit=5&filter_offset=0') $result = $request->process(); echo $result; **Getting a unrendered DataTable** use the convenience method 'processRequest' $dataTable = Request::processRequest('UserLanguage.getLanguage', array( 'idSite' => 1, 'date' => 'yesterday', 'period' => 'week', 'filter_limit' => 5, 'filter_offset' => 0 'format' => 'original', // this is the important bit )); echo "This DataTable has " . $dataTable->getRowsCount() . " rows.";
또한 보기: http://piwik.org/docs/analytics-api
 /**
  * @depends      testApi
  * @dataProvider getAnotherApiForTesting
  */
 public function testAnotherApi($api, $params)
 {
     $idSite = self::$fixture->idSite;
     $idSite2 = self::$fixture->idSite2;
     // 1) Invalidate old reports for the 2 websites
     // Test invalidate 1 date only
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=4,5,6,55,-1,s',1&dates=2010-01-03");
     $this->assertApiResponseHasNoError($r->process());
     // Test invalidate comma separated dates
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite . "," . $idSite2 . "&dates=2010-01-06,2009-10-30");
     $this->assertApiResponseHasNoError($r->process());
     // test invalidate date in the past
     // Format=original will re-throw exception
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2009-06-29&format=original");
     $this->assertApiResponseHasNoError($r->process());
     // invalidate a date more recent to check the date is only updated when it's earlier than current
     $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2010-03-03");
     $this->assertApiResponseHasNoError($r->process());
     // Make an invalid call
     $idSiteNoAccess = 777;
     try {
         $request = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSiteNoAccess . "&dates=2010-03-03&format=original");
         $request->process();
         $this->fail();
     } catch (Exception $e) {
     }
     // 2) Call API again, with an older date, which should now return data
     $this->runApiTests($api, $params);
 }
예제 #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');
     $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();
 }
예제 #3
0
 public static function loadFromApi($params, $requestUrl)
 {
     $testRequest = new Request($requestUrl);
     // Cast as string is important. For example when calling
     // with format=original, objects or php arrays can be returned.
     $response = (string) $testRequest->process();
     return new Response($response, $params, $requestUrl);
 }
예제 #4
0
 function index()
 {
     // when calling the API through http, we limit the number of returned results
     if (!isset($_GET['filter_limit'])) {
         $_GET['filter_limit'] = Config::getInstance()->General['API_datatable_default_limit'];
     }
     $request = new Request('token_auth=' . Common::getRequestVar('token_auth', 'anonymous', 'string'));
     return $request->process();
 }
예제 #5
0
 public static function loadFromApi($params, $requestUrl)
 {
     $testRequest = new Request($requestUrl);
     // Cast as string is important. For example when calling
     // with format=original, objects or php arrays can be returned.
     // we also hide errors to prevent the 'headers already sent' in the ResponseBuilder (which sends Excel headers multiple times eg.)
     $response = (string) $testRequest->process();
     return new TestRequestResponse($response, $params, $requestUrl);
 }
 public function test_process_shouldKeepSuperUserPermission_IfAccessWasManuallySet()
 {
     $this->access->setSuperUserAccess(true);
     $this->assertAccessReloadedAndRestored('difFenrenT');
     $request = new Request(array('method' => 'API.getPiwikVersion', 'token_auth' => 'difFenrenT'));
     $request->process();
     // make sure token auth was restored after it was loaded with difFenrenT
     $this->assertSameUserAsBeforeIsAuthenticated();
     $this->assertTrue($this->access->hasSuperUserAccess());
 }
예제 #7
0
파일: Model.php 프로젝트: dorelljames/piwik
 public function requestReport($idSite, $period, $date, $reportUniqueId, $metric, $segment)
 {
     $report = $this->getReportByUniqueId($idSite, $reportUniqueId);
     $params = array('method' => $report['module'] . '.' . $report['action'], 'format' => 'original', 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'filter_limit' => 1000, 'showColumns' => $metric);
     if (!empty($segment)) {
         $params['segment'] = $segment;
     }
     if (!empty($report['parameters']) && is_array($report['parameters'])) {
         $params = array_merge($params, $report['parameters']);
     }
     $request = new ApiRequest($params);
     $table = $request->process();
     return $table;
 }
예제 #8
0
 function index()
 {
     $token = 'token_auth=' . Common::getRequestVar('token_auth', 'anonymous', 'string');
     // when calling the API through http, we limit the number of returned results
     if (!isset($_GET['filter_limit'])) {
         $_GET['filter_limit'] = Config::getInstance()->General['API_datatable_default_limit'];
         $token .= '&api_datatable_default_limit=' . $_GET['filter_limit'];
     }
     $request = new Request($token);
     $response = $request->process();
     if (is_array($response)) {
         $response = var_export($response, true);
     }
     return $response;
 }
예제 #9
0
 public function beforeRender()
 {
     if ($this->requestConfig->idSubtable && $this->config->show_embedded_subtable) {
         $this->config->show_visualization_only = true;
     }
     // we do not want to get a datatable\map
     $period = Common::getRequestVar('period', 'day', 'string');
     if (Period\Range::parseDateRange($period)) {
         $period = 'range';
     }
     if ($this->dataTable->getRowsCount()) {
         $request = new ApiRequest(array('method' => 'API.get', 'module' => 'API', 'action' => 'get', 'format' => 'original', 'filter_limit' => '-1', 'disable_generic_filters' => 1, 'expanded' => 0, 'flat' => 0, 'filter_offset' => 0, 'period' => $period, 'showColumns' => implode(',', $this->config->columns_to_display), 'columns' => implode(',', $this->config->columns_to_display), 'pivotBy' => ''));
         $dataTable = $request->process();
         $this->assignTemplateVar('siteSummary', $dataTable);
     }
 }
 private function createTrackToOwnPiwikSetting()
 {
     return $this->makeSetting('ownPiwikSiteId', $default = 0, FieldConfig::TYPE_INT, function (FieldConfig $field) {
         $field->title = 'Site Id';
         // ideally we would use a SELECT control and let user choose an existing site but this would make performance slow
         // since we'd always have to get all site ids in each request
         $field->uiControl = FieldConfig::UI_CONTROL_TEXT;
         $field->introduction = 'Send anonymize usage data to this Piwik';
         $field->description = 'If specified, anonymized usage data will be sent to the specified site in this Piwik.';
         $field->validate = function ($idSite) {
             if (empty($idSite)) {
                 return;
             }
             if (!is_numeric($idSite)) {
                 throw new Exception("Site Id '{$idSite}' should be a number");
             }
             $idSite = (int) $idSite;
             try {
                 $siteExists = Request::processRequest('SitesManager.getSiteFromId', array('idSite' => $idSite));
             } catch (Exception $e) {
                 $siteExists = false;
             }
             if (!$siteExists) {
                 throw new Exception("The specified idSite '{$idSite}' does not exist");
             }
         };
     });
 }
예제 #11
0
 /**
  * @return array  URL to call the API, eg. "method=Referrers.getKeywords&period=day&date=yesterday"...
  */
 public function getRequestArray()
 {
     // we prepare the array to give to the API Request
     // we setup the method and format variable
     // - we request the method to call to get this specific DataTable
     // - the format = original specifies that we want to get the original DataTable structure itself, not rendered
     $requestArray = array('method' => $this->requestConfig->apiMethodToRequestDataTable, 'format' => 'original');
     $toSetEventually = array('filter_limit', 'keep_summary_row', 'filter_sort_column', 'filter_sort_order', 'filter_excludelowpop', 'filter_excludelowpop_value', 'filter_column', 'filter_pattern', 'flat', 'expanded', 'pivotBy', 'pivotByColumn', 'pivotByColumnLimit');
     foreach ($toSetEventually as $varToSet) {
         $value = $this->getDefaultOrCurrent($varToSet);
         if (false !== $value) {
             $requestArray[$varToSet] = $value;
         }
     }
     $segment = ApiRequest::getRawSegmentFromRequest();
     if (!empty($segment)) {
         $requestArray['segment'] = $segment;
     }
     if (ApiRequest::shouldLoadExpanded()) {
         $requestArray['expanded'] = 1;
     }
     $requestArray = array_merge($requestArray, $this->requestConfig->request_parameters_to_modify);
     if (!empty($requestArray['filter_limit']) && $requestArray['filter_limit'] === 0) {
         unset($requestArray['filter_limit']);
     }
     if ($this->requestConfig->disable_generic_filters) {
         $requestArray['disable_generic_filters'] = '1';
     }
     if ($this->requestConfig->disable_queued_filters) {
         $requestArray['disable_queued_filters'] = 1;
     }
     return $requestArray;
 }
예제 #12
0
 protected function getContentNames($websiteId = null, $date = null)
 {
     if (!is_null($websiteId)) {
         return \Piwik\API\Request::processRequest('Contents.getContentNames', array('idSite' => $websiteId, 'period' => 'year', 'date' => $date));
     }
     return Db::fetchAssoc("select `idaction`, `name` from `{$this->tablePrefix}log_action` where `type` = ?", array(\Piwik\Tracker\Action::TYPE_CONTENT_NAME));
 }
예제 #13
0
 /**
  * This widget shows horizontal bars with cpu load, memory use, network traffic and disk use
  **/
 function elementLiveLoadBars()
 {
     $result = Request::processRequest('SimpleSysMon.getLiveSysLoadData');
     $view = new View('@SimpleSysMon/widgetLiveSysLoadBars.twig');
     $this->setBasicVariablesView($view);
     $view->sysLoad = array('avgload' => array('used' => round($result['AvgLoad'], 0), 'free' => round(100.0 - $result['AvgLoad'], 0)), 'memory' => array('procUsed' => round($result['UsedMemProc'], 0), 'procCached' => round($result['CachedMemProc'], 0), 'procFree' => round(100.0 - $result['UsedMemProc'], 0), 'valUsed' => round($result['UsedMemVal'], 0), 'valCached' => round($result['CachedMemVal'], 0), 'valFree' => round($result['FreeMemProc'], 0)), 'net' => array('procUpload' => round($result['UpNetProc'], 0), 'procDownload' => round($result['DownNetProc'], 0), 'procFree' => round(100.0 - $result['DownNetProc'], 0), 'valUpload' => round($result['UpNetVal'], 0), 'valDownload' => round($result['DownNetVal'], 0)), 'disk' => array('procUsed' => round($result['UsedDiskProc'], 0), 'procFree' => round($result['FreeDiskProc'], 0), 'valUsed' => round($result['UsedDiskVal'], 0), 'valFree' => round($result['FreeDiskVal'], 0)));
     return $view->render();
 }
예제 #14
0
 private function makeSureTestRunsInContextOfAnonymousUser()
 {
     Piwik::postEvent('Request.initAuthenticationObject');
     $access = Access::getInstance();
     $this->hasSuperUserAccess = $access->hasSuperUserAccess();
     $access->setSuperUserAccess(false);
     $access->reloadAccess(StaticContainer::get('Piwik\\Auth'));
     Request::reloadAuthUsingTokenAuth(array('token_auth' => 'anonymous'));
 }
예제 #15
0
 /**
  * @depends      testApi
  * @dataProvider getAnotherApiForTesting
  * @group        Integration
  */
 public function testAnotherApi($api, $params)
 {
     // Get the top segment value
     $request = new Request('method=API.getSuggestedValuesForSegment' . '&segmentName=' . $params['segmentToComplete'] . '&idSite=' . $params['idSite'] . '&format=php&serialize=0');
     $response = $request->process();
     $this->checkRequestResponse($response);
     $topSegmentValue = @$response[0];
     if ($topSegmentValue !== false && !is_null($topSegmentValue)) {
         // Now build the segment request
         $segmentValue = rawurlencode(html_entity_decode($topSegmentValue));
         $params['segment'] = $params['segmentToComplete'] . '==' . $segmentValue;
         unset($params['segmentToComplete']);
         $this->runApiTests($api, $params);
         self::$processed++;
     } else {
         self::$skipped[] = $params['segmentToComplete'];
     }
 }
예제 #16
0
 public function findSegment($segmentName, $idSite)
 {
     $segments = Request::processRequest('API.getSegmentsMetadata', array('idSites' => array($idSite)));
     foreach ($segments as $segment) {
         if ($segment['segment'] == $segmentName && !empty($segmentName)) {
             return $segment;
         }
     }
 }
예제 #17
0
파일: API.php 프로젝트: carriercomm/piwik
 /**
  * @param int $idSite
  * @param string $period
  * @param string $date
  * @param bool|string $segment
  * @param bool|array $columns
  * @return mixed
  */
 public function get($idSite, $period, $date, $segment = false, $columns = false)
 {
     $segment = $this->appendReturningVisitorSegment($segment);
     $this->unprefixColumns($columns);
     $params = array('idSite' => $idSite, 'period' => $period, 'date' => $date, 'segment' => $segment, 'columns' => implode(',', $columns), 'format' => 'original', 'serialize' => 0);
     $table = Request::processRequest('VisitsSummary.get', $params);
     $this->prefixColumns($table, $period);
     return $table;
 }
예제 #18
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array('module' => $this->module, 'action' => 'getPageTitles'));
     $view->config->title = $this->name;
     $view->config->addTranslation('label', $this->dimension->getName());
     $view->config->columns_to_display = array('label', 'nb_hits', 'nb_visits', 'bounce_rate', 'avg_time_on_page', 'exit_rate', 'avg_time_generation');
     $this->addPageDisplayProperties($view);
     $this->addBaseDisplayProperties($view);
 }
예제 #19
0
 public function render()
 {
     $userLogins = Request::processRequest('UsersManager.getUsersLogin', array('filter_limit' => '-1'));
     $websites = Request::processRequest('SitesManager.getAllSites', array('filter_limit' => '-1'));
     $numUsers = count($userLogins);
     if (in_array('anonymous', $userLogins)) {
         $numUsers--;
     }
     return $this->renderTemplate('getSystemSummary', array('numWebsites' => count($websites), 'numUsers' => $numUsers, 'numSegments' => $this->getNumSegments(), 'numPlugins' => $this->getNumPlugins(), 'piwikVersion' => Version::VERSION, 'mySqlVersion' => $this->getMySqlVersion(), 'phpVersion' => phpversion()));
 }
 private function executeSomeApiMethods()
 {
     Request::processRequest('API.getPiwikVersion');
     Request::processRequest('API.getSettings');
     Request::processRequest('UsersManager.getUsers');
     Request::processRequest('API.getPiwikVersion');
     Request::processRequest('VisitsSummary.get', array('idSite' => 1, 'period' => 'year', 'date' => 'today'));
     $date = Date::factory('today')->toString();
     Request::processRequest('CoreAdminHome.invalidateArchivedReports', array('idSites' => '1', 'period' => 'year', 'dates' => $date, 'cascadeDown' => '1'));
 }
예제 #21
0
 public function configureView(ViewDataTable $view)
 {
     // link to the page, not just the report, but only if not a widget
     $widget = Common::getRequestVar('widget', false);
     $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array('module' => $this->module, 'action' => $widget === false ? 'indexPageTitles' : 'getPageTitles'));
     $view->config->title = $this->name;
     $view->config->addTranslation('label', $this->dimension->getName());
     $view->config->columns_to_display = array('label', 'nb_hits', 'nb_visits', 'bounce_rate', 'avg_time_on_page', 'exit_rate', 'avg_time_generation');
     $this->addPageDisplayProperties($view);
     $this->addBaseDisplayProperties($view);
 }
예제 #22
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array('module' => 'Actions', 'action' => 'getExitPageUrls'));
     $view->config->addTranslations(array('label' => $this->dimension->getName()));
     $view->config->title = $this->name;
     $view->config->columns_to_display = array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate');
     $view->requestConfig->filter_sort_column = 'exit_nb_visits';
     $view->requestConfig->filter_sort_order = 'desc';
     $this->addPageDisplayProperties($view);
     $this->addBaseDisplayProperties($view);
 }
 /**
  * trigger loading all plugins with an API.php file in the Proxy
  */
 public function __construct()
 {
     $plugins = \Piwik\Plugin\Manager::getInstance()->getLoadedPluginsName();
     foreach ($plugins as $plugin) {
         try {
             $className = Request::getClassNameAPI($plugin);
             Proxy::getInstance()->registerClass($className);
         } catch (Exception $e) {
         }
     }
 }
예제 #24
0
 private function requestApiReport($apiReport)
 {
     if (!$this->canGenerateInsights()) {
         return;
     }
     $idSite = Common::getRequestVar('idSite', null, 'int');
     $period = Common::getRequestVar('period', null, 'string');
     $date = Common::getRequestVar('date', null, 'string');
     $segment = Request::getRawSegmentFromRequest();
     return API::getInstance()->{$apiReport}($idSite, $period, $date, $segment);
 }
 /**
  * @depends      testApi
  * @dataProvider getAnotherApiForTesting
  */
 public function testAnotherApi($api, $params)
 {
     // Get the top segment value
     $request = new Request('method=API.getSuggestedValuesForSegment' . '&segmentName=' . $params['segmentToComplete'] . '&idSite=' . $params['idSite'] . '&format=php&serialize=0');
     $response = $request->process();
     $this->assertApiResponseHasNoError($response);
     $topSegmentValue = @$response[0];
     if ($topSegmentValue !== false && !is_null($topSegmentValue)) {
         if (is_numeric($topSegmentValue) || is_float($topSegmentValue) || preg_match('/^\\d*?,\\d*$/', $topSegmentValue)) {
             $topSegmentValue = Common::forceDotAsSeparatorForDecimalPoint($topSegmentValue);
         }
         // Now build the segment request
         $segmentValue = rawurlencode(html_entity_decode($topSegmentValue));
         $params['segment'] = $params['segmentToComplete'] . '==' . $segmentValue;
         unset($params['segmentToComplete']);
         $this->runApiTests($api, $params);
         self::$processed++;
     } else {
         self::$skipped[] = $params['segmentToComplete'];
     }
 }
예제 #26
0
 public function test_isApiRequest_shouldDetectIfItIsApiRequestOrNot()
 {
     $this->assertFalse(Request::isApiRequest(array()));
     $this->assertFalse(Request::isApiRequest(array('module' => '', 'method' => '')));
     $this->assertFalse(Request::isApiRequest(array('module' => 'API')));
     // no method
     $this->assertFalse(Request::isApiRequest(array('module' => 'CoreHome', 'method' => 'index.test')));
     // not api
     $this->assertFalse(Request::isApiRequest(array('module' => 'API', 'method' => 'testmethod')));
     // no valid action
     $this->assertTrue(Request::isApiRequest(array('module' => 'API', 'method' => 'test.method')));
 }
예제 #27
0
 /**
  * @param DataTable|DataTable\Map $dataTable
  * @param $visualization
  */
 protected function initChartObjectData($dataTable, $visualization)
 {
     // if the loaded datatable is a simple DataTable, it is most likely a plugin plotting some custom data
     // we don't expect plugin developers to return a well defined Set
     if ($dataTable instanceof DataTable) {
         parent::initChartObjectData($dataTable, $visualization);
         return;
     }
     // the X label is extracted from the 'period' object in the table's metadata
     $xLabels = array();
     foreach ($dataTable->getDataTables() as $metadataDataTable) {
         $xLabels[] = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedShortString();
         // eg. "Aug 2009"
     }
     $units = $this->getUnitsForColumnsToDisplay();
     // if rows to display are not specified, default to all rows (TODO: perhaps this should be done elsewhere?)
     $rowsToDisplay = $this->properties['rows_to_display'] ?: array_unique($dataTable->getColumn('label')) ?: array(false);
     // collect series data to show. each row-to-display/column-to-display permutation creates a series.
     $allSeriesData = array();
     $seriesUnits = array();
     foreach ($rowsToDisplay as $rowLabel) {
         foreach ($this->properties['columns_to_display'] as $columnName) {
             $seriesLabel = $this->getSeriesLabel($rowLabel, $columnName);
             $seriesData = $this->getSeriesData($rowLabel, $columnName, $dataTable);
             $allSeriesData[$seriesLabel] = $seriesData;
             $seriesUnits[$seriesLabel] = $units[$columnName];
         }
     }
     $visualization->dataTable = $dataTable;
     $visualization->properties = $this->properties;
     $visualization->setAxisXLabels($xLabels);
     $visualization->setAxisYValues($allSeriesData);
     $visualization->setAxisYUnits($seriesUnits);
     $dataTables = $dataTable->getDataTables();
     if ($this->isLinkEnabled()) {
         $idSite = Common::getRequestVar('idSite', null, 'int');
         $periodLabel = reset($dataTables)->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLabel();
         $axisXOnClick = array();
         $queryStringAsHash = $this->getQueryStringAsHash();
         foreach ($dataTable->getDataTables() as $idDataTable => $metadataDataTable) {
             $dateInUrl = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart();
             $parameters = array('idSite' => $idSite, 'period' => $periodLabel, 'date' => $dateInUrl->toString(), 'segment' => \Piwik\API\Request::getRawSegmentFromRequest());
             $hash = '';
             if (!empty($queryStringAsHash)) {
                 $hash = '#' . Url::getQueryStringFromParameters($queryStringAsHash + $parameters);
             }
             $link = 'index.php?' . Url::getQueryStringFromParameters(array('module' => 'CoreHome', 'action' => 'index') + $parameters) . $hash;
             $axisXOnClick[] = $link;
         }
         $visualization->setAxisXOnClick($axisXOnClick);
     }
 }
예제 #28
0
 public function render()
 {
     $lastMinutes = Config::getInstance()->General[Controller::SIMPLE_VISIT_COUNT_WIDGET_LAST_MINUTES_CONFIG_KEY];
     $lastNData = Request::processRequest('Live.getCounters', array('lastMinutes' => $lastMinutes));
     $view = new View('@Live/getSimpleLastVisitCount');
     $view->lastMinutes = $lastMinutes;
     $view->visitors = MetricsFormatter::getPrettyNumber($lastNData[0]['visitors']);
     $view->visits = MetricsFormatter::getPrettyNumber($lastNData[0]['visits']);
     $view->actions = MetricsFormatter::getPrettyNumber($lastNData[0]['actions']);
     $view->refreshAfterXSecs = Config::getInstance()->General['live_widget_refresh_after_seconds'];
     $view->translations = array('one_visitor' => Piwik::translate('Live_NbVisitor'), 'visitors' => Piwik::translate('Live_NbVisitors'), 'one_visit' => Piwik::translate('General_OneVisit'), 'visits' => Piwik::translate('General_NVisits'), 'one_action' => Piwik::translate('General_OneAction'), 'actions' => Piwik::translate('VisitsSummary_NbActionsDescription'), 'one_minute' => Piwik::translate('General_OneMinute'), 'minutes' => Piwik::translate('General_NMinutes'));
     return $view->render();
 }
예제 #29
0
 public function configureView(ViewDataTable $view)
 {
     // link to the page, not just the report, but only if not a widget
     $widget = Common::getRequestVar('widget', false);
     $view->config->self_url = Request::getCurrentUrlWithoutGenericFilters(array('module' => 'Actions', 'action' => $widget === false ? 'indexExitPageUrls' : 'getExitPageUrls'));
     $view->config->addTranslations(array('label' => $this->dimension->getName()));
     $view->config->title = $this->name;
     $view->config->columns_to_display = array('label', 'exit_nb_visits', 'nb_visits', 'exit_rate');
     $view->requestConfig->filter_sort_column = 'exit_nb_visits';
     $view->requestConfig->filter_sort_order = 'desc';
     $this->addPageDisplayProperties($view);
     $this->addBaseDisplayProperties($view);
 }
 /**
  * We send this data via server to not expose eg PHP version to users
  * @return array
  */
 public function getServerVisitCustomVariables()
 {
     $users = Request::processRequest('UsersManager.getUsers', array('filter_limit' => '-1'));
     $websites = Request::processRequest('SitesManager.getAllSites', array('filter_limit' => '-1'));
     $customVars = array(array('id' => 1, 'name' => 'Piwik Version', 'value' => StaticContainer::get('AnonymousPiwikUsageMeasurement.piwikVersion')), array('id' => 2, 'name' => 'PHP Version', 'value' => StaticContainer::get('AnonymousPiwikUsageMeasurement.phpVersion')), array('id' => 3, 'name' => 'Num Users', 'value' => count($users)), array('id' => 4, 'name' => 'Num Websites', 'value' => count($websites)));
     $segmentClass = 'Piwik\\Plugins\\SegmentEditor\\Services\\StoredSegmentService';
     if (class_exists($segmentClass)) {
         $service = StaticContainer::get($segmentClass);
         $segments = $service->getAllSegmentsAndIgnoreVisibility();
         $customVars[] = array('id' => 5, 'name' => 'Num Segments', 'value' => count($segments));
     }
     return $customVars;
 }