本文整理汇总了PHP中Piwik_SitesManager_API类的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_SitesManager_API类的具体用法?PHP Piwik_SitesManager_API怎么用?PHP Piwik_SitesManager_API使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Piwik_SitesManager_API类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getScheduledTasks
function getScheduledTasks($notification)
{
// Reports have to be sent when the period ends for all websites
$maxHourOffset = 0;
$uniqueTimezones = Piwik_SitesManager_API::getInstance()->getUniqueSiteTimezones();
$baseDate = Piwik_Date::factory("1971-01-01");
foreach ($uniqueTimezones as &$timezone) {
$offsetDate = Piwik_Date::factory($baseDate->toString(), $timezone);
// Earlier means a negative timezone
if ($offsetDate->isEarlier($baseDate)) {
// Gets the timezone offset
$hourOffset = 24 - date('H', $offsetDate->getTimestamp());
if ($hourOffset > $maxHourOffset) {
$maxHourOffset = $hourOffset;
}
}
}
$tasks =& $notification->getNotificationObject();
$dailySchedule = new Piwik_ScheduledTime_Daily();
$dailySchedule->setHour($maxHourOffset);
$tasks[] = new Piwik_ScheduledTask($this, 'dailySchedule', $dailySchedule);
$weeklySchedule = new Piwik_ScheduledTime_Weekly();
$weeklySchedule->setHour($maxHourOffset);
$tasks[] = new Piwik_ScheduledTask($this, 'weeklySchedule', $weeklySchedule);
$monthlySchedule = new Piwik_ScheduledTime_Monthly();
$monthlySchedule->setHour($maxHourOffset);
$tasks[] = new Piwik_ScheduledTask($this, 'monthlySchedule', $monthlySchedule);
}
示例2: __construct
function __construct($idsite)
{
$this->id = $idsite;
if (!isset(self::$infoSites[$this->id])) {
self::$infoSites[$this->id] = Piwik_SitesManager_API::getSiteFromId($idsite);
}
}
示例3: setUpWebsites
/**
* One site with custom search parameters,
* One site using default search parameters,
* One site with disabled site search
*/
protected static function setUpWebsites()
{
Piwik_SitesManager_API::getInstance()->setGlobalSearchParameters($searchKeywordParameters = 'gkwd', $searchCategoryParameters = 'gcat');
self::createWebsite(Piwik_Date::factory(self::$dateTime)->subHour(200)->getDatetime(), 0, "Site 1 - Site search", $siteurl = false, $search = 1, $searchKwd = 'q,mykwd,p', $searchCat = 'cats');
self::createWebsite(Piwik_Date::factory(self::$dateTime)->subHour(400)->getDatetime(), 0, "Site 2 - Site search use default", $siteurl = false, $search = 1, $searchKwd = '', $searchCat = '');
self::createWebsite(Piwik_Date::factory(self::$dateTime)->subHour(600)->getDatetime(), 0, "Site 3 - No site search", $siteurl = false, $search = 0);
}
示例4: update
static function update()
{
$obsoleteFiles = array(
PIWIK_INCLUDE_PATH . '/core/Db/Mysqli.php',
);
foreach($obsoleteFiles as $obsoleteFile)
{
if(file_exists($obsoleteFile))
{
@unlink($obsoleteFile);
}
}
$obsoleteDirectories = array(
PIWIK_INCLUDE_PATH . '/core/Db/Pdo',
);
foreach($obsoleteDirectories as $dir)
{
if(file_exists($dir))
{
Piwik::unlinkRecursive($dir, true);
}
}
// force regeneration of cache files
Piwik::setUserIsSuperUser();
$allSiteIds = Piwik_SitesManager_API::getInstance()->getAllSitesId();
Piwik_Common::regenerateCacheWebsiteAttributes($allSiteIds);
}
示例5: index
public function index()
{
Piwik::checkUserIsNotAnonymous();
$view = Piwik_View::factory('index');
$this->setGeneralVariablesView($view);
$view->currentUserEmail = Piwik::getCurrentUserEmail();
$allSites = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess();
$view->countWebsites = count($allSites);
$availableReports = Piwik_API_API::getInstance()->getReportMetadata($this->idSite);
$reportsByCategory = array();
foreach ($availableReports as $report) {
$reportsByCategory[$report['category']][] = $report;
}
unset($reportsByCategory['API']);
$reports = Piwik_PDFReports_API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true);
$reportsById = array();
foreach ($reports as &$report) {
$report['additional_emails'] = str_replace(',', "\n", $report['additional_emails']);
$report['reports'] = explode(',', str_replace('.', '_', $report['reports']));
$reportsById[$report['idreport']] = $report;
}
$view->downloadOutputType = Piwik_PDFReports_API::OUTPUT_DOWNLOAD;
$columnsCount = 2;
$view->newColumnAfter = ceil(count($reportsByCategory) / $columnsCount);
$view->reportsByCategory = $reportsByCategory;
$view->reportsJSON = Piwik_Common::json_encode($reportsById);
$view->periods = array_merge(array('never' => Piwik_Translate('General_Never')), Piwik_PDFReports_API::getPeriodToFrequency());
$view->defaultFormat = Piwik_PDFReports::DEFAULT_FORMAT;
$view->formats = Piwik_ReportRenderer::$availableReportRenderers;
$view->aggregateReportsFormats = Piwik_PDFReports_API::getAggregateReportsFormats();
$view->reports = $reports;
$view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
echo $view->render();
}
示例6: test_callableApiMethods_doNotFail
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();
}
示例7: check
/**
* Check for a newer version
*
* @param bool $force Force check
*/
public static function check($force = false)
{
$lastTimeChecked = Piwik_GetOption(self::LAST_TIME_CHECKED);
if($force || $lastTimeChecked === false
|| time() - self::CHECK_INTERVAL > $lastTimeChecked )
{
// set the time checked first, so that parallel Piwik requests don't all trigger the http requests
Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1);
$parameters = array(
'piwik_version' => Piwik_Version::VERSION,
'php_version' => PHP_VERSION,
'url' => Piwik_Url::getCurrentUrlWithoutQueryString(),
'trigger' => Piwik_Common::getRequestVar('module','','string'),
'timezone' => Piwik_SitesManager_API::getInstance()->getDefaultTimezone(),
);
$url = Zend_Registry::get('config')->General->api_service_url;
$url .= '/1.0/getLatestVersion/';
$url .= '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
try {
$latestVersion = Piwik_Http::sendHttpRequest($url, $timeout);
Piwik_SetOption(self::LATEST_VERSION, $latestVersion);
} catch(Exception $e) {
// e.g., disable_functions = fsockopen; allow_url_open = Off
Piwik_SetOption(self::LATEST_VERSION, '');
}
}
}
示例8: update
static function update()
{
// force regeneration of cache files following #648
Piwik::setUserIsSuperUser();
$allSiteIds = Piwik_SitesManager_API::getAllSitesId();
Piwik_Common::regenerateCacheWebsiteAttributes($allSiteIds);
}
示例9: render
public function render()
{
try {
$this->currentModule = Piwik::getModule();
$this->currentPluginName = Piwik::getCurrentPlugin()->getName();
$this->userLogin = Piwik::getCurrentUserLogin();
$showWebsiteSelectorInUserInterface = Zend_Registry::get('config')->General->show_website_selector_in_user_interface;
if ($showWebsiteSelectorInUserInterface) {
$sites = Piwik_SitesManager_API::getSitesWithAtLeastViewAccess();
usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);'));
$this->sites = $sites;
}
$this->showWebsiteSelectorInUserInterface = $showWebsiteSelectorInUserInterface;
$this->url = Piwik_Url::getCurrentUrl();
$this->token_auth = Piwik::getCurrentUserTokenAuth();
$this->userHasSomeAdminAccess = Piwik::isUserHasSomeAdminAccess();
$this->userIsSuperUser = Piwik::isUserIsSuperUser();
$this->piwik_version = Piwik_Version::VERSION;
$this->latest_version_available = Piwik_UpdateCheck::isNewestVersionAvailable();
$this->loginModule = Zend_Registry::get('auth')->getName();
} catch (Exception $e) {
// can fail, for example at installation (no plugin loaded yet)
}
$this->totalTimeGeneration = Zend_Registry::get('timer')->getTime();
try {
$this->totalNumberOfQueries = Piwik::getQueryCount();
} catch (Exception $e) {
$this->totalNumberOfQueries = 0;
}
header('Content-Type: text/html; charset=utf-8');
header("Pragma: ");
header("Cache-Control: no-store, must-revalidate");
return $this->smarty->fetch($this->template);
}
示例10: setGeneralVariablesView
protected function setGeneralVariablesView($view)
{
// date
$view->date = $this->strDate;
$oDate = new Piwik_Date($this->strDate);
$view->prettyDate = $oDate->getLocalized(Piwik_Translate('Home_LocalizedDateFormat'));
// period
$currentPeriod = Piwik_Common::getRequestVar('period');
$otherPeriodsAvailable = array('day', 'week', 'month', 'year');
$otherPeriodsNames = array('day' => Piwik_Translate('Home_PeriodDay'), 'week' => Piwik_Translate('Home_PeriodWeek'), 'month' => Piwik_Translate('Home_PeriodMonth'), 'year' => Piwik_Translate('Home_PeriodYear'));
$found = array_search($currentPeriod, $otherPeriodsAvailable);
if ($found !== false) {
unset($otherPeriodsAvailable[$found]);
}
$view->period = $currentPeriod;
$view->otherPeriods = $otherPeriodsAvailable;
$view->periodsNames = $otherPeriodsNames;
// other
$view->idSite = Piwik_Common::getRequestVar('idSite');
$view->userLogin = Piwik::getCurrentUserLogin();
$view->sites = Piwik_SitesManager_API::getSitesWithAtLeastViewAccess();
$view->url = Piwik_Url::getCurrentUrl();
$view->menu = Piwik_GetMenu();
$view->menuJson = json_encode($view->menu);
//var_dump($view->menuJson);
}
示例11: trackVisitsImpl
protected function trackVisitsImpl($t)
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
$t->disableCookieSupport();
$t->setUrlReferrer('http://referer.com/page.htm?param=valuewith some spaces');
// testing URL excluded parameters
$parameterToExclude = 'excluded_parameter';
Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new name', $url = array('http://site.com'), $ecommerce = 0, $excludedIps = null, $parameterToExclude . ',anotherParameter');
// Record 1st page view
$urlPage1 = 'http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY¶meter=Should display';
$t->setUrl($urlPage1);
$this->checkResponse($t->doTrackPageView('incredible title!'));
// testing that / and index.htm above record with different URLs
// Recording the 2nd page after 3 minutes
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.05)->getDatetime());
$urlPage2 = 'http://example.org/';
$t->setUrl($urlPage2);
// $t->setUrlReferrer($urlPage1);
$this->checkResponse($t->doTrackPageView('Second page view - should be registered as URL /'));
// $t->setUrlReferrer($urlPage2);
// Click on external link after 6 minutes (3rd action)
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime());
$this->checkResponse($t->doTrackAction('http://dev.piwik.org/svn', 'link'));
// Click on file download after 12 minutes (4th action)
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
$this->checkResponse($t->doTrackAction('http://piwik.org/path/again/latest.zip', 'download'));
// Create Goal 1: Triggered by JS, after 18 minutes
$idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
// Change to Thai browser to ensure the conversion is credited to FR instead (the visitor initial country)
$t->setBrowserLanguage('th');
$this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42));
// Track same Goal twice (after 24 minutes), should only be tracked once
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
$this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42));
$t->setBrowserLanguage('fr');
// Final page view (after 27 min)
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime());
$t->setUrl('http://example.org/index.htm');
$this->checkResponse($t->doTrackPageView('Looking at homepage (again)...'));
// -
// End of first visit: 24min
// Create Goal 2: Matching on URL
Piwik_Goals_API::getInstance()->addGoal($idSite, 'matching purchase.htm', 'url', '(.*)store\\/purchase\\.(.*)', 'regex', false, $revenue = 1);
// -
// Start of returning visit, 1 hour after first page view
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
$t->setUrl('http://example.org/store/purchase.htm');
$t->setUrlReferrer('http://search.yahoo.com/search?p=purchase');
// Temporary, until we implement 1st party cookies in PiwikTracker
$t->DEBUG_APPEND_URL = '&_idvc=2';
// Goal Tracking URL matching, testing custom referer including keyword
$this->checkResponse($t->doTrackPageView('Checkout/Purchasing...'));
// -
// End of second visit
}
示例12: setUp
public function setUp()
{
parent::setUp();
$access = new Piwik_Access();
Zend_Registry::set('access', $access);
$access->setSuperUser(true);
$this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("test", "http://test");
Piwik_PluginsManager::getInstance()->loadPlugins(array('MultiSites', 'VisitsSummary', 'Actions'));
Piwik_PluginsManager::getInstance()->installLoadedPlugins();
}
示例13: testExcludeQueryParametersSiteAndGlobalExcluded
/**
* Testing with some website specific and some global excluded query parameters
* @group Core
* @group Tracker
* @group Tracker_Action
* @dataProvider getTestUrls
*/
public function testExcludeQueryParametersSiteAndGlobalExcluded($url, $filteredUrl)
{
// testing also that query parameters are case insensitive
$excludedQueryParameters = 'P2,var[value][date]';
$excludedGlobalParameters = 'blabla, P4';
$this->setUpRootAccess();
$idSite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0, $excludedIps = '', $excludedQueryParameters);
Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedGlobalParameters);
$this->assertEquals($filteredUrl[1], Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite));
}
示例14: getAll
/**
* Returns a report displaying the total visits, actions and revenue, as
* well as the evolution of these values, of all existing sites over a
* specified period of time.
*
* If the specified period is not a 'range', this function will calculcate
* evolution metrics. Evolution metrics are metrics that display the
* percent increase/decrease of another metric since the last period.
*
* This function will merge the result of the archive query so each
* row in the result DataTable will correspond to the metrics of a single
* site. If a date range is specified, the result will be a
* DataTable_Array, but it will still be merged.
*
* @param string $period The period type to get data for.
* @param string $date The date(s) to get data for.
* @param string $segment The segments to get data for.
*/
public function getAll($period, $date, $segment = false)
{
Piwik::checkUserHasSomeViewAccess();
$isGoalPluginEnabled = Piwik_Common::isGoalPluginEnabled();
// get site data for every viewable site and cache them
if (Piwik::isUserIsSuperUser()) {
$sites = Piwik_SitesManager_API::getInstance()->getAllSites();
Piwik_Site::setSites($sites);
} else {
$sites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
Piwik_Site::setSitesFromArray($sites);
}
// build the archive type used to query archive data
$archive = Piwik_Archive::build('all', $period, $date, $segment);
// determine what data will be displayed
$fieldsToGet = array('nb_visits', 'nb_actions');
if ($isGoalPluginEnabled) {
$revenueMetric = Piwik_Goals::getRecordName('revenue');
$fieldsToGet[] = $revenueMetric;
}
// get the data
$dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
// get rid of the DataTable_Array that is created by the IndexedBySite archive type
$dataTable = $dataTable->mergeChildren();
// if the period isn't a range & a lastN/previousN date isn't used, we get the same
// data for the last period to show the evolution of visits/actions/revenue
if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
if (strpos($date, ',')) {
$rangePeriod = new Piwik_Period_Range($period, $date);
$lastStartDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateStart(), $n = 1);
$lastEndDate = Piwik_Period_Range::removePeriod($period, $rangePeriod->getDateEnd(), $n = 1);
$strLastDate = "{$lastStartDate},{$lastEndDate}";
} else {
$strLastDate = Piwik_Period_Range::removePeriod($period, Piwik_Date::factory($date), $n = 1)->toString();
}
$pastArchive = Piwik_Archive::build('all', $period, $strLastDate, $segment);
$pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
$pastData = $pastData->mergeChildren();
// use past data to calculate evolution percentages
$this->calculateEvolutionPercentages($dataTable, $pastData, $fieldsToGet);
}
// move the site id to a metadata column
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'idsite'));
// set the label of each row to the site name
$getNameFor = array('Piwik_Site', 'getNameFor');
$dataTable->filter('ColumnCallbackReplace', array('label', $getNameFor));
// rename the revenue column from the metric name to 'revenue'
if ($isGoalPluginEnabled) {
$mapping = array($revenueMetric => 'revenue');
$dataTable->filter('ReplaceColumnNames', array($mapping));
}
// Ensures data set sorted, for Metadata output
$dataTable->filter('Sort', array('nb_visits', 'desc', $naturalSort = false));
return $dataTable;
}
示例15: getSitesInfo
public function getSitesInfo()
{
$view = new Piwik_View("MultiSites/templates/index.tpl");
$mySites = Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess();
$params = $this->getGraphParamsModified();
$this->dateToStr = $params['date'];
$ids = 'all';
$this->period = Piwik_Common::getRequestVar('period', 'day');
$this->date = Piwik_Common::getRequestVar('date', 'today');
$lastDate = date('Y-m-d', strtotime("-1 " . $this->period, strtotime($this->date)));
$visits = Piwik_VisitsSummary_API::getInstance()->getVisits($ids, $this->period, $this->date);
$lastVisits = Piwik_VisitsSummary_API::getInstance()->getVisits($ids, $this->period, $lastDate);
$actions = Piwik_VisitsSummary_API::getInstance()->getActions($ids, $this->period, $this->date);
$lastActions = Piwik_VisitsSummary_API::getInstance()->getActions($ids, $this->period, $lastDate);
$uniqueUsers = Piwik_VisitsSummary_API::getInstance()->getUniqueVisitors($ids, $this->period, $this->date);
$lastUniqueUsers = Piwik_VisitsSummary_API::getInstance()->getUniqueVisitors($ids, $this->period, $lastDate);
$visitsSummary = $this->getSummary($lastVisits, $visits, $mySites, "visits");
$actionsSummary = $this->getSummary($lastActions, $actions, $mySites, "actions");
$uniqueSummary = $this->getSummary($lastUniqueUsers, $uniqueUsers, $mySites, "unique");
$visitsArray = $visits->getArray();
$actionsArray = $actions->getArray();
$uniqueUsersArray = $uniqueUsers->getArray();
$lastVisitsArray = $lastVisits->getArray();
$lastActionsArray = $lastActions->getArray();
$lastUniqueUsersArray = $lastUniqueUsers->getArray();
foreach ($mySites as &$site) {
$idSite = $site['idsite'];
$site['visits'] = array_shift($visitsArray[$idSite]->getColumn(0));
$site['actions'] = array_shift($actionsArray[$idSite]->getColumn(0));
$site['unique'] = array_shift($uniqueUsersArray[$idSite]->getColumn(0));
$site['lastVisits'] = array_shift($lastVisitsArray[$idSite]->getColumn(0));
$site['lastActions'] = array_shift($lastActionsArray[$idSite]->getColumn(0));
$site['lastUnique'] = array_shift($lastUniqueUsersArray[$idSite]->getColumn(0));
$site['visitsSummaryValue'] = $visitsSummary[$idSite];
$site['actionsSummaryValue'] = $actionsSummary[$idSite];
$site['uniqueSummaryValue'] = $uniqueSummary[$idSite];
}
$view->mySites = $mySites;
$view->evolutionBy = $this->evolutionBy;
$view->period = $this->period;
$view->date = $this->date;
$view->page = $this->page;
$view->limit = $this->limit;
$view->orderBy = $this->orderBy;
$view->order = $this->order;
$view->dateToStr = $this->dateToStr;
$this->setGeneralVariablesView($view);
$minTimestamp = Zend_Registry::get('access')->getSitesMinDate();
if (!empty($minTimestamp)) {
$minDate = Piwik_Date::factory($minTimestamp);
$this->setMinDateView($minDate, $view);
}
echo $view->render();
}