本文整理汇总了PHP中Piwik\Site::getSites方法的典型用法代码示例。如果您正苦于以下问题:PHP Site::getSites方法的具体用法?PHP Site::getSites怎么用?PHP Site::getSites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Site
的用法示例。
在下文中一共展示了Site::getSites方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Main Plugin Index
*
* @return mixed
* @throws \Exception
*/
public function index()
{
Piwik::checkUserHasSomeAdminAccess();
if (isset($_SERVER['REQUEST_METHOD']) && 'POST' == $_SERVER['REQUEST_METHOD']) {
// Cannot use Common::getRequestVar, because the function remove whitespaces and newline breaks
$postedSiteData = isset($_POST['site']) ? $_POST['site'] : null;
if (is_array($postedSiteData) && count($postedSiteData) > 0) {
foreach ($postedSiteData as $id => $site) {
if (!isset($site['css'], $site['file'])) {
continue;
}
// Check URL
if (!UrlHelper::isLookLikeUrl($site['file'])) {
$site['file'] = null;
}
API::getInstance()->saveSite($id, $site['css'], $site['file']);
}
// Redirect to, clear POST vars
$this->redirectToIndex('CustomOptOut', 'index');
return;
}
}
$view = new View('@CustomOptOut/index.twig');
Site::clearCache();
if (Piwik::hasUserSuperUserAccess()) {
$sitesRaw = APISiteManager::getInstance()->getAllSites();
} else {
$sitesRaw = APISiteManager::getInstance()->getSitesWithAdminAccess();
}
// Gets sites after Site.setSite hook was called
$sites = array_values(Site::getSites());
if (count($sites) != count($sitesRaw)) {
throw new \Exception("One or more website are missing or invalid.");
}
foreach ($sites as &$site) {
$site['alias_urls'] = APISiteManager::getInstance()->getSiteUrlsFromId($site['idsite']);
}
$view->adminSites = $sites;
$view->adminSitesCount = count($sites);
$view->language = LanguagesManager::getLanguageCodeForCurrentUser();
$view->isEditorEnabled = API::getInstance()->isCssEditorEnabled();
$view->editorTheme = API::getInstance()->getEditorTheme();
$view->showOldLinks = false;
$this->setBasicVariablesView($view);
return $view->render();
}
示例2: index
/**
* Main view showing listing of websites and settings
*/
public function index()
{
$view = new View('@SitesManager/index');
Site::clearCache();
if (Piwik::isUserIsSuperUser()) {
$sitesRaw = API::getInstance()->getAllSites();
} else {
$sitesRaw = API::getInstance()->getSitesWithAdminAccess();
}
// Gets sites after Site.setSite hook was called
$sites = array_values(Site::getSites());
if (count($sites) != count($sitesRaw)) {
throw new Exception("One or more website are missing or invalid.");
}
foreach ($sites as &$site) {
$site['alias_urls'] = API::getInstance()->getSiteUrlsFromId($site['idsite']);
$site['excluded_ips'] = explode(',', $site['excluded_ips']);
$site['excluded_parameters'] = explode(',', $site['excluded_parameters']);
$site['excluded_user_agents'] = explode(',', $site['excluded_user_agents']);
}
$view->adminSites = $sites;
$view->adminSitesCount = count($sites);
$timezones = API::getInstance()->getTimezonesList();
$view->timezoneSupported = SettingsServer::isTimezoneSupportEnabled();
$view->timezones = Common::json_encode($timezones);
$view->defaultTimezone = API::getInstance()->getDefaultTimezone();
$view->currencies = Common::json_encode(API::getInstance()->getCurrencyList());
$view->defaultCurrency = API::getInstance()->getDefaultCurrency();
$view->utcTime = Date::now()->getDatetime();
$excludedIpsGlobal = API::getInstance()->getExcludedIpsGlobal();
$view->globalExcludedIps = str_replace(',', "\n", $excludedIpsGlobal);
$excludedQueryParametersGlobal = API::getInstance()->getExcludedQueryParametersGlobal();
$view->globalExcludedQueryParameters = str_replace(',', "\n", $excludedQueryParametersGlobal);
$globalExcludedUserAgents = API::getInstance()->getExcludedUserAgentsGlobal();
$view->globalExcludedUserAgents = str_replace(',', "\n", $globalExcludedUserAgents);
$view->globalSearchKeywordParameters = API::getInstance()->getSearchKeywordParametersGlobal();
$view->globalSearchCategoryParameters = API::getInstance()->getSearchCategoryParametersGlobal();
$view->isSearchCategoryTrackingEnabled = \Piwik\Plugin\Manager::getInstance()->isPluginActivated('CustomVariables');
$view->allowSiteSpecificUserAgentExclude = API::getInstance()->isSiteSpecificUserAgentExcludeEnabled();
$view->globalKeepURLFragments = API::getInstance()->getKeepURLFragmentsGlobal();
$view->currentIpAddress = IP::getIpFromHeader();
$view->showAddSite = (bool) Common::getRequestVar('showaddsite', false);
$this->setBasicVariablesView($view);
return $view->render();
}
示例3: getSitesIdFromPattern
/**
* Fetches the list of sites which names match the string pattern
*
* @param string $pattern
* @param bool $_restrictSitesToLogin
* @return array|string
*/
private function getSitesIdFromPattern($pattern, $_restrictSitesToLogin)
{
// First clear cache
Site::clearCache();
if (empty($pattern)) {
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\\Scheduler\\Scheduler');
// Then, warm the cache with only the data we should have access to
if (Piwik::hasUserSuperUserAccess() && !$scheduler->isRunningTask()) {
APISitesManager::getInstance()->getAllSites();
} else {
APISitesManager::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin);
}
} else {
$sites = Request::processRequest('SitesManager.getPatternMatchSites', array('pattern' => $pattern, 'showColumns' => '', 'hideColumns' => '', 'serialize' => 0, 'format' => 'original'));
if (!empty($sites)) {
$idSites = array();
foreach ($sites as $site) {
$idSites[] = $site['idsite'];
}
$model = new ModelSitesManager();
$sites = $model->getSitesFromIds($idSites);
// getPatternMatchSites does not return all sites information...
Site::setSitesFromArray($sites);
}
}
// Both calls above have called Site::setSitesFromArray. We now get these sites:
$sitesToProblablyAdd = Site::getSites();
return $sitesToProblablyAdd;
}
示例4: buildDataTable
private function buildDataTable($idSitesOrIdSite, $period, $date, $segment, $_restrictSitesToLogin, $enhanced, $multipleWebsitesRequested)
{
$allWebsitesRequested = $idSitesOrIdSite == 'all';
if ($allWebsitesRequested) {
// First clear cache
Site::clearCache();
// Then, warm the cache with only the data we should have access to
if (Piwik::isUserIsSuperUser() && !TaskScheduler::isTaskBeingExecuted()) {
$sites = APISitesManager::getInstance()->getAllSites();
} else {
$sites = APISitesManager::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin);
}
// Both calls above have called Site::setSitesFromArray. We now get these sites:
$sitesToProblablyAdd = Site::getSites();
} else {
$sitesToProblablyAdd = array(APISitesManager::getInstance()->getSiteFromId($idSitesOrIdSite));
}
// build the archive type used to query archive data
$archive = Archive::build($idSitesOrIdSite, $period, $date, $segment, $_restrictSitesToLogin);
// determine what data will be displayed
$fieldsToGet = array();
$columnNameRewrites = array();
$apiECommerceMetrics = array();
$apiMetrics = API::getApiMetrics($enhanced);
foreach ($apiMetrics as $metricName => $metricSettings) {
$fieldsToGet[] = $metricSettings[self::METRIC_RECORD_NAME_KEY];
$columnNameRewrites[$metricSettings[self::METRIC_RECORD_NAME_KEY]] = $metricName;
if ($metricSettings[self::METRIC_IS_ECOMMERCE_KEY]) {
$apiECommerceMetrics[$metricName] = $metricSettings;
}
}
// get the data
// $dataTable instanceOf Set
$dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
$dataTable = $this->mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWebsitesRequested, $dataTable);
if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $table) {
$this->addMissingWebsites($table, $fieldsToGet, $sitesToProblablyAdd);
}
} else {
$this->addMissingWebsites($dataTable, $fieldsToGet, $sitesToProblablyAdd);
}
// calculate total visits/actions/revenue
$this->setMetricsTotalsMetadata($dataTable, $apiMetrics);
// 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
list($strLastDate, $lastPeriod) = Range::getLastDate($date, $period);
if ($strLastDate !== false) {
if ($lastPeriod !== false) {
// NOTE: no easy way to set last period date metadata when range of dates is requested.
// will be easier if DataTable\Map::metadata is removed, and metadata that is
// put there is put directly in DataTable::metadata.
$dataTable->setMetadata(self::getLastPeriodMetadataName('date'), $lastPeriod);
}
$pastArchive = Archive::build($idSitesOrIdSite, $period, $strLastDate, $segment, $_restrictSitesToLogin);
$pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
$pastData = $this->mergeDataTableMapAndPopulateLabel($idSitesOrIdSite, $multipleWebsitesRequested, $pastData);
// use past data to calculate evolution percentages
$this->calculateEvolutionPercentages($dataTable, $pastData, $apiMetrics);
$this->setPastDataMetadata($dataTable, $pastData, $apiMetrics);
}
// remove eCommerce related metrics on non eCommerce Piwik sites
// note: this is not optimal in terms of performance: those metrics should not be retrieved in the first place
if ($enhanced) {
if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $table) {
$this->removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($table, $apiECommerceMetrics);
}
} else {
$this->removeEcommerceRelatedMetricsOnNonEcommercePiwikSites($dataTable, $apiECommerceMetrics);
}
}
// move the site id to a metadata column
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'idsite'));
// set the label of each row to the site name
if ($multipleWebsitesRequested) {
$dataTable->filter('ColumnCallbackReplace', array('label', '\\Piwik\\Site::getNameFor'));
} else {
$dataTable->filter('ColumnDelete', array('label'));
}
// replace record names with user friendly metric names
$dataTable->filter('ReplaceColumnNames', array($columnNameRewrites));
// Ensures data set sorted, for Metadata output
$dataTable->filter('Sort', array(self::NB_VISITS_METRIC, 'desc', $naturalSort = false));
// filter rows without visits
// note: if only one website is queried and there are no visits, we can not remove the row otherwise
// ResponseBuilder throws 'Call to a member function getColumns() on a non-object'
if ($multipleWebsitesRequested && !$enhanced) {
$dataTable->filter('ColumnCallbackDeleteRow', array(self::NB_VISITS_METRIC, function ($value) {
return $value == 0;
}));
}
return $dataTable;
}