本文整理汇总了PHP中Piwik\Plugins\SitesManager\API::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP API::getInstance方法的具体用法?PHP API::getInstance怎么用?PHP API::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Plugins\SitesManager\API
的用法示例。
在下文中一共展示了API::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpWebsitesAndGoals
private function setUpWebsitesAndGoals()
{
$ecommerce = $this->allowConversions ? 1 : 0;
// tests run in UTC, the Tracker in UTC
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime, $ecommerce, "Site 1");
}
if (!self::siteCreated($idSite = 2)) {
self::createWebsite($this->dateTime, 0, "Site 2");
}
if ($this->allowConversions) {
if (!self::goalExists($idSite = 1, $idGoal = 1)) {
APIGoals::getInstance()->addGoal($this->idSite1, 'all', 'url', 'http', 'contains', false, 5);
}
if (!self::goalExists($idSite = 1, $idGoal = 2)) {
APIGoals::getInstance()->addGoal($this->idSite2, 'all', 'url', 'http', 'contains');
}
if (!self::goalExists($idSite = 1, $idGoal = 3)) {
APIGoals::getInstance()->addGoal($this->idSite1, 'matching URL with campaign parameter', 'url', self::URL_IS_GOAL_WITH_CAMPAIGN_PARAMETERS, 'contains');
}
}
APISitesManager::getInstance()->updateSite($this->idSite1, "Site 1", $urls = null, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 2);
// KEEP_URL_FRAGMENT_NO No for idSite 1
APISitesManager::getInstance()->updateSite($this->idSite2, "Site 2", $urls = null, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
// KEEP_URL_FRAGMENT_YES Yes for idSite 2
}
示例2: update
static function update($schema = 'Myisam')
{
// force regeneration of cache files following #648
Piwik::setUserIsSuperUser();
$allSiteIds = API::getInstance()->getAllSitesId();
Cache::regenerateCacheWebsiteAttributes($allSiteIds);
}
示例3: setUpWebsites
/**
* One site with custom search parameters,
* One site using default search parameters,
* One site with disabled site search
*/
private function setUpWebsites()
{
API::getInstance()->setGlobalSearchParameters($searchKeywordParameters = 'gkwd', $searchCategoryParameters = 'gcat');
if (!self::siteCreated($idSite = 1)) {
self::createWebsite(Date::factory($this->dateTime)->getDatetime(), 0, "Site 1 - Site search", $siteurl = false, $search = 1, $searchKwd = 'q,mykwd,p', $searchCat = 'cats');
}
}
示例4: setUp
public function setUp()
{
parent::setUp();
$this->siteUrls = new SiteUrls();
$this->api = API::getInstance();
SiteUrls::clearSitesCache();
}
示例5: check
/**
* Check for a newer version
*
* @param bool $force Force check
* @param int $interval Interval used for update checks
*/
public static function check($force = false, $interval = null)
{
if (!self::isAutoUpdateEnabled()) {
return;
}
if ($interval === null) {
$interval = self::CHECK_INTERVAL;
}
$lastTimeChecked = Option::get(self::LAST_TIME_CHECKED);
if ($force || $lastTimeChecked === false || time() - $interval > $lastTimeChecked) {
// set the time checked first, so that parallel Piwik requests don't all trigger the http requests
Option::set(self::LAST_TIME_CHECKED, time(), $autoLoad = 1);
$parameters = array('piwik_version' => Version::VERSION, 'php_version' => PHP_VERSION, 'url' => Url::getCurrentUrlWithoutQueryString(), 'trigger' => Common::getRequestVar('module', '', 'string'), 'timezone' => API::getInstance()->getDefaultTimezone());
$url = Config::getInstance()->General['api_service_url'] . '/1.0/getLatestVersion/' . '?' . http_build_query($parameters, '', '&');
$timeout = self::SOCKET_TIMEOUT;
if (@Config::getInstance()->Debug['allow_upgrades_to_beta']) {
$url = 'http://builds.piwik.org/LATEST_BETA';
}
try {
$latestVersion = Http::sendHttpRequest($url, $timeout);
if (!preg_match('~^[0-9][0-9a-zA-Z_.-]*$~D', $latestVersion)) {
$latestVersion = '';
}
} catch (Exception $e) {
// e.g., disable_functions = fsockopen; allow_url_open = Off
$latestVersion = '';
}
Option::set(self::LATEST_VERSION, $latestVersion);
}
}
示例6: setGlobalSettings
/**
* Records Global settings when user submit changes
*/
public function setGlobalSettings()
{
$response = new ResponseBuilder(Common::getRequestVar('format'));
try {
$this->checkTokenInUrl();
$timezone = Common::getRequestVar('timezone', false);
$excludedIps = Common::getRequestVar('excludedIps', false);
$excludedQueryParameters = Common::getRequestVar('excludedQueryParameters', false);
$excludedUserAgents = Common::getRequestVar('excludedUserAgents', false);
$currency = Common::getRequestVar('currency', false);
$searchKeywordParameters = Common::getRequestVar('searchKeywordParameters', $default = "");
$searchCategoryParameters = Common::getRequestVar('searchCategoryParameters', $default = "");
$enableSiteUserAgentExclude = Common::getRequestVar('enableSiteUserAgentExclude', $default = 0);
$keepURLFragments = Common::getRequestVar('keepURLFragments', $default = 0);
$api = API::getInstance();
$api->setDefaultTimezone($timezone);
$api->setDefaultCurrency($currency);
$api->setGlobalExcludedQueryParameters($excludedQueryParameters);
$api->setGlobalExcludedIps($excludedIps);
$api->setGlobalExcludedUserAgents($excludedUserAgents);
$api->setGlobalSearchParameters($searchKeywordParameters, $searchCategoryParameters);
$api->setSiteSpecificUserAgentExcludeEnabled($enableSiteUserAgentExclude == 1);
$api->setKeepURLFragmentsGlobal($keepURLFragments);
$toReturn = $response->getResponse();
} catch (Exception $e) {
$toReturn = $response->getResponseException($e);
}
return $toReturn;
}
示例7: setUp
public function setUp()
{
parent::setUp();
$access = Access::getInstance();
$access->setSuperUserAccess(true);
$this->idSiteAccess = APISitesManager::getInstance()->addSite("test", "http://test");
\Piwik\Plugin\Manager::getInstance()->loadPlugins(array('MultiSites', 'VisitsSummary', 'Actions'));
\Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
}
示例8: setUp
public function setUp()
{
parent::setUp();
// setup the access layer
FakeAccess::$superUser = true;
$this->idSiteAccess = APISitesManager::getInstance()->addSite("test", "http://test");
\Piwik\Plugin\Manager::getInstance()->loadPlugins(array('ScheduledReports', 'MobileMessaging', 'MultiSites'));
\Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
}
示例9: trackVisits
private function trackVisits()
{
if (!$this->trackInvalidRequests) {
return;
}
$dateTime = $this->dateTime;
$idSite = $this->idSite;
API::getInstance()->setSiteSpecificUserAgentExcludeEnabled(true);
API::getInstance()->setGlobalExcludedUserAgents('globalexcludeduseragent');
// Trigger empty request
$trackerUrl = self::getTrackerUrl();
$response = Http::fetchRemoteFile($trackerUrl);
self::assertTrue(strpos($response, 'is a free open source web') !== false, 'Piwik empty request response not correct: ' . $response);
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
// test GoogleBot UA visitor
$t->setUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
self::checkResponse($t->doTrackPageView('bot visit, please do not record'));
// Test IP Exclusion works with or without IP exclusion
foreach (array(false, true) as $enable) {
$excludedIp = '154.1.12.34';
API::getInstance()->updateSite($idSite, 'new site name', $url = array('http://site.com'), $ecommerce = 0, $ss = 1, $ss_kwd = '', $ss_cat = '', $excludedIp . ',1.2.3.4', $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = 'excludeduseragentstring');
// Enable IP Anonymization
$t->DEBUG_APPEND_URL = '&forceIpAnonymization=' . (int) $enable;
// test with excluded User Agent
$t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729) (excludeduseragentstring)');
$t->setIp('211.1.2.3');
self::checkResponse($t->doTrackPageView('visit from excluded User Agent'));
$t->setUserAgent('Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0 Google (+https://developers.google.com/+/web/snippet/)');
self::checkResponse($t->doTrackPageView('visit from excluded User Agent'));
// test w/ global excluded User Agent
$t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729) (globalexcludeduseragent)');
$t->setIp('211.1.2.3');
self::checkResponse($t->doTrackPageView('visit from global excluded User Agent'));
// test with excluded IP
$t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)');
// restore normal user agent
$t->setIp($excludedIp);
self::checkResponse($t->doTrackPageView('visit from IP excluded'));
// test with global list of excluded IPs
$excludedIpBis = '145.5.3.4';
API::getInstance()->setGlobalExcludedIps($excludedIpBis);
$t->setIp($excludedIpBis);
self::checkResponse($t->doTrackPageView('visit from IP globally excluded'));
}
try {
@$t->setAttributionInfo(array());
self::fail();
} catch (Exception $e) {
}
try {
$t->setAttributionInfo(json_encode('test'));
self::fail();
} catch (Exception $e) {
}
$t->setAttributionInfo(json_encode(array()));
}
示例10: index
public function index()
{
$view = new View('@ScheduledReports/index');
$this->setGeneralVariablesView($view);
$view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess());
// get report types
$reportTypes = API::getReportTypes();
$view->reportTypes = $reportTypes;
$view->defaultReportType = self::DEFAULT_REPORT_TYPE;
$view->defaultReportFormat = ScheduledReports::DEFAULT_REPORT_FORMAT;
$view->displayFormats = ScheduledReports::getDisplayFormats();
$reportsByCategoryByType = array();
$reportFormatsByReportType = array();
$allowMultipleReportsByReportType = array();
foreach ($reportTypes as $reportType => $reportTypeIcon) {
// get report formats
$reportFormatsByReportType[$reportType] = API::getReportFormats($reportType);
$allowMultipleReportsByReportType[$reportType] = API::allowMultipleReports($reportType);
// get report metadata
$reportsByCategory = array();
$availableReportMetadata = API::getReportMetadata($this->idSite, $reportType);
foreach ($availableReportMetadata as $reportMetadata) {
$reportsByCategory[$reportMetadata['category']][] = $reportMetadata;
}
$reportsByCategoryByType[$reportType] = $reportsByCategory;
}
$view->reportsByCategoryByReportType = $reportsByCategoryByType;
$view->reportFormatsByReportType = $reportFormatsByReportType;
$view->allowMultipleReportsByReportType = $allowMultipleReportsByReportType;
$reports = array();
$reportsById = array();
if (!Piwik::isUserIsAnonymous()) {
$reports = API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true);
foreach ($reports as &$report) {
$report['recipients'] = API::getReportRecipients($report);
$reportsById[$report['idreport']] = $report;
}
}
$view->reports = $reports;
$view->reportsJSON = Common::json_encode($reportsById);
$view->downloadOutputType = API::OUTPUT_INLINE;
$view->periods = ScheduledReports::getPeriodToFrequency();
$view->defaultPeriod = ScheduledReports::DEFAULT_PERIOD;
$view->defaultHour = ScheduledReports::DEFAULT_HOUR;
$view->language = LanguagesManager::getLanguageCodeForCurrentUser();
$view->segmentEditorActivated = false;
if (API::isSegmentEditorActivated()) {
$savedSegmentsById = array();
foreach (APISegmentEditor::getInstance()->getAll($this->idSite) as $savedSegment) {
$savedSegmentsById[$savedSegment['idsegment']] = $savedSegment['name'];
}
$view->savedSegmentsById = $savedSegmentsById;
$view->segmentEditorActivated = true;
}
return $view->render();
}
示例11: makeVisitorAndAction
private function makeVisitorAndAction($lastActionTimestamp, $currentActionTime, $isVisitorKnown = false)
{
$idsite = API::getInstance()->addSite("name", "http://piwik.net/");
/** @var Request $request */
list($visit, $request) = $this->prepareVisitWithRequest(array('idsite' => $idsite), $currentActionTime);
$visitProperties = new VisitProperties();
$visitProperties->setProperty('visit_last_action_time', Date::factory($lastActionTimestamp)->getTimestamp());
$request->setMetadata('CoreHome', 'isVisitorKnown', $isVisitorKnown);
return array($visit, $visitProperties, $request);
}
示例12: setUp
public function setUp()
{
parent::setUp();
// setup the access layer
$pseudoMockAccess = new FakeAccess();
FakeAccess::$superUser = true;
//finally we set the user as a Super User by default
Access::setSingletonInstance($pseudoMockAccess);
$this->idSiteAccess = APISitesManager::getInstance()->addSite("test", "http://test");
\Piwik\Plugin\Manager::getInstance()->loadPlugins(array('ScheduledReports', 'MobileMessaging', 'MultiSites'));
\Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
}
示例13: getDefaultWebsiteId
/**
* Returns default site ID that Piwik should load.
*
* _Note: This value is a Piwik setting set by each user._
*
* @return bool|int
* @api
*/
public function getDefaultWebsiteId()
{
$defaultReport = $this->getDefaultReport();
if (is_numeric($defaultReport) && Piwik::isUserHasViewAccess($defaultReport)) {
return $defaultReport;
}
$sitesId = APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess();
if (!empty($sitesId)) {
return $sitesId[0];
}
return false;
}
示例14: setUp
public function setUp()
{
parent::setUp();
self::updateDatabase();
// make sure site has an early enough creation date (for period selector tests)
Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1");
$this->addOverlayVisits();
$this->addNewSitesForSiteSelector();
DbHelper::createAnonymousUser();
UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true);
SitesManagerAPI::getInstance()->updateSite(1, null, null, true);
}
示例15: add
/**
* Adds a new entry to the menu.
*
* @param string $menuName The menu's category name. Can be a translation token.
* @param string $subMenuName The menu item's name. Can be a translation token.
* @param string|array $url The URL the admin menu entry should link to, or an array of query parameters
* that can be used to build the URL.
* @param boolean $displayedForCurrentUser Whether this menu entry should be displayed for the
* current user. If false, the entry will not be added.
* @param int $order The order hint.
* @param bool|string $tooltip An optional tooltip to display or false to display the tooltip.
* @api
*/
public function add($menuName, $subMenuName, $url, $displayedForCurrentUser = true, $order = 50, $tooltip = false)
{
if (!$displayedForCurrentUser) {
return;
}
// make sure the idSite value used is numeric (hack-y fix for #3426)
if (!is_numeric(Common::getRequestVar('idSite', false))) {
$idSites = API::getInstance()->getSitesIdWithAtLeastViewAccess();
$url['idSite'] = reset($idSites);
}
$this->menuEntries[] = array($menuName, $subMenuName, $url, $order, $tooltip);
}