php Piwik-API-Request类(方法)实例源码

下面列出了php Piwik-API-Request 类(方法)源码代码实例,从而了解它的用法。

作者:a4tunad    项目:piwi   
/**
  * @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);
 }

作者:bossrabbi    项目:piwi   
/** 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();
 }

作者:diosmosi    项目:piwi   
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);
 }

作者:a4tunad    项目:piwi   
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();
 }

作者:a4tunad    项目:piwi   
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);
 }

作者:ahdinosau    项目:analytics.dinosaur.i   
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());
 }

作者:dorelljame    项目:piwi   
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;
 }

作者:CaptainShar    项目:SSAD_Projec   
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;
 }

作者:igorclar    项目:piwi   
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);
     }
 }

作者:piwi    项目:plugin-AnonymousPiwikUsageMeasuremen   
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");
             }
         };
     });
 }

作者:bossrabbi    项目:piwi   
/**
  * @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;
 }

作者:Ratu    项目:VPSCashPiwikBannerPlugi   
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));
 }

作者:bossrabbi    项目:piwi   
/**
  * 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();
 }

作者:FluentDevelopmen    项目:piwi   
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'));
 }

作者:carriercom    项目:piwi   
/**
  * @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'];
     }
 }

作者:dorelljame    项目:piwi   
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;
         }
     }
 }

作者:carriercom    项目:piwi   
/**
  * @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;
 }

作者:piwi    项目:piwi   
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);
 }

作者:piwi    项目:piwi   
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()));
 }

作者:piwi    项目:plugin-AnonymousPiwikUsageMeasuremen   
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'));
 }


问题


面经


文章

微信
公众号

扫码关注公众号