本文整理汇总了PHP中Piwik_API_Request::process方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_API_Request::process方法的具体用法?PHP Piwik_API_Request::process怎么用?PHP Piwik_API_Request::process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_API_Request
的用法示例。
在下文中一共展示了Piwik_API_Request::process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addMainPageMetricsToReport
/**
* Add the main metrics (pageviews, exits, bounces) to the full report.
* Data is loaded from Actions.getPageUrls using the label filter.
*/
private function addMainPageMetricsToReport(&$report, $pageUrl, $idSite, $period, $date, $segment)
{
$label = Piwik_Actions::getActionExplodedNames($pageUrl, Piwik_Tracker_Action::TYPE_ACTION_URL);
if (count($label) == 1) {
$label = $label[0];
} else {
$label = array_map('urlencode', $label);
$label = implode('>', $label);
}
$parameters = array('method' => 'Actions.getPageUrls', 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'label' => $label, 'format' => 'original', 'serialize' => '0', 'expanded' => '0');
if (!empty($segment)) {
$parameters['segment'] = $segment;
}
$url = Piwik_Url::getQueryStringFromParameters($parameters);
$request = new Piwik_API_Request($url);
try {
/** @var $dataTable Piwik_DataTable */
$dataTable = $request->process();
} catch (Exception $e) {
throw new Exception("Actions.getPageUrls returned an error: " . $e->getMessage() . "\n");
}
if ($dataTable->getRowsCount() == 0) {
throw new Exception("The label '{$label}' could not be found in Actions.getPageUrls\n");
}
$row = $dataTable->getFirstRow();
if ($row !== false) {
$report['pageMetrics'] = array('pageviews' => intval($row->getColumn('nb_hits')), 'exits' => intval($row->getColumn('exit_nb_visits')), 'bounces' => intval($row->getColumn('entry_bounce_count')));
} else {
$report['pageMetrics'] = array('pageviews' => 0, 'exits' => 0, 'bounces' => 0);
}
}
示例2: worldMap
function worldMap()
{
if (!Piwik_PluginsManager::getInstance()->isPluginActivated('UserCountry')) {
return '';
}
$idSite = Piwik_Common::getRequestVar('idSite', 1, 'int');
Piwik::checkUserHasViewAccess($idSite);
$period = Piwik_Common::getRequestVar('period');
$date = Piwik_Common::getRequestVar('date');
$token_auth = Piwik::getCurrentUserTokenAuth();
$view = Piwik_View::factory('worldmap');
$view->dataUrl = "?module=API" . "&method=API.getProcessedReport&format=XML" . "&apiModule=UserCountry&apiAction=getCountry" . "&idSite=" . $idSite . "&period=" . $period . "&date=" . $date . "&token_auth=" . $token_auth . "&segment=" . Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('segment', '')) . "&filter_limit=-1";
// definition of the color scale
$view->hueMin = 218;
$view->hueMax = 216;
$view->satMin = "0.285";
$view->satMax = "0.9";
$view->lgtMin = ".97";
$view->lgtMax = ".44";
$request = new Piwik_API_Request('method=API.getMetadata&format=PHP' . '&apiModule=UserCountry&apiAction=getCountry' . '&idSite=' . $idSite . '&period=' . $period . '&date=' . $date . '&token_auth=' . $token_auth . '&filter_limit=-1');
$metaData = $request->process();
$metrics = array();
foreach ($metaData[0]['metrics'] as $id => $val) {
if (Piwik_Common::getRequestVar('period') == 'day' || $id != 'nb_uniq_visitors') {
$metrics[] = array($id, $val);
}
}
foreach ($metaData[0]['processedMetrics'] as $id => $val) {
$metrics[] = array($id, $val);
}
$view->metrics = $metrics;
$view->defaultMetric = 'nb_visits';
echo $view->render();
}
示例3: foreach
function test_callableApiMethods_doNotFail()
{
Piwik::createConfigObject();
Piwik_Config::getInstance()->setTestEnvironment();
Piwik::createLogObject();
Piwik::createAccessObject();
Piwik::createDatabaseObject();
Piwik::setUserIsSuperUser();
Piwik_Translate::getInstance()->loadEnglishTranslation();
$pluginsManager = Piwik_PluginsManager::getInstance();
$pluginsManager->loadPlugins(Piwik_Config::getInstance()->Plugins['Plugins']);
Piwik_SitesManager_API::getInstance()->addSite("name", "http://example.org");
$apiGenerator = new Piwik_API_DocumentationGenerator_CallAllMethods();
$requestUrls = $apiGenerator->getAllRequestsWithParameters();
$this->assertTrue(count($requestUrls) > 20);
foreach ($requestUrls as $url) {
$call = new Piwik_API_Request($url);
$output = $call->process();
// var_dump($url);
// var_dump($output);
$this->assertTrue(!empty($output));
}
Piwik_Translate::getInstance()->unloadEnglishTranslation();
$this->pass();
}
示例4: index
function index()
{
$view = new Piwik_View('Goals/templates/overview.tpl');
$view->currency = Piwik::getCurrency();
$view->title = 'All goals - evolution';
$view->graphEvolution = $this->getEvolutionGraph(true, array(Piwik_Goals::getRecordName('nb_conversions')));
$view->nameGraphEvolution = 'GoalsgetEvolutionGraph';
// sparkline for the historical data of the above values
$view->urlSparklineConversions = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('nb_conversions'))));
$view->urlSparklineConversionRate = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('conversion_rate'))));
$view->urlSparklineRevenue = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('revenue'))));
$request = new Piwik_API_Request("method=Goals.get&format=original");
$datatable = $request->process();
$dataRow = $datatable->getFirstRow();
$view->nb_conversions = $dataRow->getColumn('Goal_nb_conversions');
$view->conversion_rate = $dataRow->getColumn('Goal_conversion_rate');
$view->revenue = $dataRow->getColumn('Goal_revenue');
$goalMetrics = array();
foreach ($this->goals as $idGoal => $goal) {
$goalMetrics[$idGoal] = $this->getMetricsForGoal($idGoal);
$goalMetrics[$idGoal]['name'] = $goal['name'];
}
$view->goalMetrics = $goalMetrics;
$view->goals = $this->goals;
$view->goalsJSON = json_encode($this->goals);
$view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
echo $view->render();
}
示例5: unserialize
function _processRequest($request)
{
$token_auth = self::_getToken();
$request = new Piwik_API_Request($request . "&format=php&token_auth=" . $token_auth);
$result = $request->process();
$content = unserialize($result);
return $content;
}
示例6: getVisits
static public function getVisits()
{
$requestString = "method=VisitsSummary.getVisits".
"&format=original".
"&disable_generic_filters=1";
$request = new Piwik_API_Request($requestString);
return $request->process();
}
示例7: index
function index()
{
// when calling the API through http, we limit the number of returned results
if (!isset($_GET['filter_limit'])) {
$_GET['filter_limit'] = Zend_Registry::get('config')->General->API_datatable_default_limit;
}
$request = new Piwik_API_Request('token_auth=' . Piwik_Common::getRequestVar('token_auth', 'anonymous', 'string'));
echo $request->process();
}
示例8: getLastVisitsStart
public function getLastVisitsStart($fetch = false)
{
// hack, ensure we load today's visits by default
$_GET['date'] = 'today';
$_GET['period'] = 'day';
$view = Piwik_View::factory('lastVisits');
$view->idSite = $this->idSite;
$api = new Piwik_API_Request("method=Live.getLastVisitsDetails&idSite={$this->idSite}&filter_limit=10&format=php&serialize=0&disable_generic_filters=1");
$visitors = $api->process();
$view->visitors = $visitors;
return $this->render($view, $fetch);
}
示例9: renderSidebar
/** 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();
}
示例10: getLastVisits
function getLastVisits($fetch = false)
{
$idSite = Piwik_Common::getRequestVar('idSite', null, 'int');
$minIdVisit = Piwik_Common::getRequestVar('minIdVisit', 0, 'int');
$limit = 10;
$api = new Piwik_API_Request("method=Live.getLastVisits&idSite={$idSite}&limit={$limit}&minIdVisit={$minIdVisit}&format=php&serialize=0&disable_generic_filters=1");
$view = new Piwik_View('Live/templates/lastVisits.tpl');
$visitors = $api->process();
if ($minIdVisit == 0) {
$visitors = array_slice($visitors, 3);
}
$view->visitors = $visitors;
$rendered = $view->render($fetch);
if ($fetch) {
return $rendered;
}
echo $rendered;
}
示例11: testAnotherApi
/**
* @depends testApi
* @dataProvider getAnotherApiForTesting
* @group Integration
* @group VisitsInPast_InvalidateOldReports
*/
public function testAnotherApi($api, $params)
{
// 1) Invalidate old reports for the 2 websites
// Test invalidate 1 date only
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=4,5,6,55,-1,s',1&dates=2010-01-03");
$r->process();
// Test invalidate comma separated dates
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . self::$idSite . "," . self::$idSite2 . "&dates=2010-01-06,2009-10-30");
$r->process();
// test invalidate date in the past
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . self::$idSite2 . "&dates=2009-06-29");
$r->process();
// invalidate a date more recent to check the date is only updated when it's earlier than current
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . self::$idSite2 . "&dates=2010-03-03");
$r->process();
// 2) Call API again, with an older date, which should now return data
$this->runApiTests($api, $params);
}
示例12: foreach
function test_callableApiMethods_doNotFail()
{
Piwik::createConfigObject();
Piwik::createLogObject();
Piwik::createAccessObject();
Piwik::createDatabaseObject();
Piwik::setUserIsSuperUser();
$pluginsManager = Piwik_PluginsManager::getInstance();
$pluginsManager->setPluginsToLoad(Zend_Registry::get('config')->Plugins->Plugins->toArray());
$apiGenerator = new Piwik_API_DocumentationGenerator_CallAllMethods();
$requestUrls = $apiGenerator->getAllRequestsWithParameters();
$this->assertTrue(count($requestUrls) > 20);
foreach ($requestUrls as $url) {
$call = new Piwik_API_Request($url);
$output = $call->process();
// var_dump($url);
// var_dump($output);
$this->assertTrue(!empty($output));
}
$this->pass();
}
示例13: getAnotherApiToTest
/**
* This is called after getApiToTest()
* WE invalidate old reports and check that data is now returned for old dates
*/
public function getAnotherApiToTest()
{
// 1) Invalidate old reports for the 2 websites
// Test invalidate 1 date only
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports\n\t\t\t&idSites=4,5,6,55,-1,s',1&dates=2010-01-03");
$r->process();
// Test invalidate comma separated dates
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports\n\t\t\t&idSites=" . $this->idSite . "," . $this->idSite2 . "&dates=2010-01-06,2009-10-30");
$r->process();
// test invalidate date in the past
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports\n\t\t\t&idSites=" . $this->idSite2 . "&dates=2009-06-29");
$r->process();
// invalidate a date more recent to check the date is only updated when it's earlier than current
$r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports\n\t\t\t&idSites=" . $this->idSite2 . "&dates=2010-03-03");
$r->process();
// 2) Call API again, with an older date, which should now return data
// website 1
$this->tests[0][1]['testSuffix'] = 'Website' . $this->idSite . '_OldReportsShouldAppear';
// website2
$this->tests[1][1]['testSuffix'] = 'Website' . $this->idSite2 . '_OldReportsShouldAppear';
return $this->tests;
}
示例14: loadRowEvolutionData
/** @return Piwik_DataTable_Array */
private function loadRowEvolutionData($idSite, $period, $date, $apiModule, $apiAction, $label, $segment)
{
if ($period == 'range') {
// load days in the range
$period = 'day';
}
$parameters = array('method' => $apiModule . '.' . $apiAction, 'label' => $label, 'idSite' => $idSite, 'period' => $period, 'date' => $date, 'format' => 'original', 'serialize' => '0', 'segment' => $segment);
// add "processed metrics" like actions per visit or bounce rate
if ($apiModule != 'Actions') {
$parameters['filter_add_columns_when_show_all_columns'] = '1';
}
$url = Piwik_Url::getQueryStringFromParameters($parameters);
$request = new Piwik_API_Request($url);
try {
$dataTable = $request->process();
} catch (Exception $e) {
throw new Exception("API returned an error: " . $e->getMessage() . "\n");
}
if (!$dataTable instanceof Piwik_DataTable_Array) {
throw new Exception("API didn't return a DataTable array. Maybe you used " . "a single date (i.e. not YYYY-MM-DD,YYYY-MM-DD)");
}
return $dataTable;
}
示例15: firstWebsiteSetup
/**
* Installation Step 7: Configure first web-site
*/
public function firstWebsiteSetup()
{
$this->checkPreviousStepIsValid( __FUNCTION__ );
$view = new Piwik_Installation_View(
$this->pathView . 'firstWebsiteSetup.tpl',
$this->getInstallationSteps(),
__FUNCTION__
);
$this->skipThisStep( __FUNCTION__ );
$form = new Piwik_Installation_FormFirstWebsiteSetup();
if( !isset($this->session->generalSetupSuccessMessage))
{
$view->displayGeneralSetupSuccess = true;
$this->session->generalSetupSuccessMessage = true;
}
$this->initObjectsToCallAPI();
if($form->validate())
{
$name = urlencode($form->getSubmitValue('siteName'));
$url = urlencode($form->getSubmitValue('url'));
$ecommerce = (int)$form->getSubmitValue('ecommerce');
$request = new Piwik_API_Request("
method=SitesManager.addSite
&siteName=$name
&urls=$url
&ecommerce=$ecommerce
&format=original
");
try {
$result = $request->process();
$this->session->site_idSite = $result;
$this->session->site_name = $name;
$this->session->site_url = $url;
$this->redirectToNextStep( __FUNCTION__ );
} catch(Exception $e) {
$view->errorMessage = $e->getMessage();
}
}
$view->addForm($form);
echo $view->render();
}