public static function getGoalDefinitions($idSite) { $websiteAttributes = Cache::getCacheWebsiteAttributes($idSite); if (isset($websiteAttributes['goals'])) { return $websiteAttributes['goals']; } return array(); }
private function getSiteCreatedTime($idSite) { $attributes = Cache::getCacheWebsiteAttributes($idSite); if (!isset($attributes['ts_created'])) { return null; } return Date::factory($attributes['ts_created']); }
/** * We have previously tried to detect the campaign variables in the URL * so at this stage, if the referrer host is the current host, * or if the referrer host is any of the registered URL for this website, * it is considered a direct entry * @return bool */ protected function detectReferrerDirectEntry() { if (empty($this->referrerHost)) { return false; } $urlsByHost = $this->getCachedUrlsByHostAndIdSite(); $directEntry = new SiteUrls(); $matchingSites = $directEntry->getIdSitesMatchingUrl($this->referrerUrlParse, $urlsByHost); if (isset($matchingSites) && is_array($matchingSites) && in_array($this->idsite, $matchingSites)) { $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY; return true; } elseif (isset($matchingSites)) { return false; } $site = Cache::getCacheWebsiteAttributes($this->idsite); $excludeUnknowns = $site['exclude_unknown_urls']; // fallback logic if the referrer domain is not known to any site to not break BC if (!$excludeUnknowns && isset($this->currentUrlParse['host'])) { // this might be actually buggy if first thing tracked is eg an outlink and referrer is from that site $currentHost = Common::mb_strtolower($this->currentUrlParse['host']); if ($currentHost == Common::mb_strtolower($this->referrerHost)) { $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY; return true; } } return false; }
/** * Returns true if the specified user agent should be excluded for the current site or not. * * Visits whose user agent string contains one of the excluded_user_agents strings for the * site being tracked (or one of the global strings) will be excluded. * * @internal param string $this ->userAgent The user agent string. * @return bool */ protected function isUserAgentExcluded() { $websiteAttributes = Cache::getCacheWebsiteAttributes($this->idSite); if (!empty($websiteAttributes['excluded_user_agents'])) { foreach ($websiteAttributes['excluded_user_agents'] as $excludedUserAgent) { // if the excluded user agent string part is in this visit's user agent, this visit should be excluded if (stripos($this->userAgent, $excludedUserAgent) !== false) { return true; } } } return false; }
public static function authenticateSuperUserOrAdmin($tokenAuth, $idSite) { if (empty($tokenAuth)) { return false; } $superUserLogin = Config::getInstance()->superuser['login']; $superUserPassword = Config::getInstance()->superuser['password']; if (md5($superUserLogin . $superUserPassword) === $tokenAuth) { return true; } // Now checking the list of admin token_auth cached in the Tracker config file if (!empty($idSite) && $idSite > 0) { $website = Cache::getCacheWebsiteAttributes($idSite); if (array_key_exists('admin_token_auth', $website) && in_array($tokenAuth, $website['admin_token_auth'])) { return true; } } Common::printDebug("WARNING! token_auth = {$tokenAuth} is not valid, Super User / Admin was NOT authenticated"); return false; }
private function getTimezoneForSite($idSite) { try { $site = Cache::getCacheWebsiteAttributes($idSite); } catch (UnexpectedWebsiteFoundException $e) { return null; } if (!empty($site['timezone'])) { return $site['timezone']; } }
public static function authenticateSuperUserOrAdmin($tokenAuth, $idSite) { if (empty($tokenAuth)) { return false; } Piwik::postEvent('Request.initAuthenticationObject'); /** @var \Piwik\Auth $auth */ $auth = StaticContainer::get('Piwik\\Auth'); $auth->setTokenAuth($tokenAuth); $auth->setLogin(null); $auth->setPassword(null); $auth->setPasswordHash(null); $access = $auth->authenticate(); if (!empty($access) && $access->hasSuperUserAccess()) { return true; } // Now checking the list of admin token_auth cached in the Tracker config file if (!empty($idSite) && $idSite > 0) { $website = Cache::getCacheWebsiteAttributes($idSite); if (array_key_exists('admin_token_auth', $website) && in_array((string) $tokenAuth, $website['admin_token_auth'])) { return true; } } Common::printDebug("WARNING! token_auth = {$tokenAuth} is not valid, Super User / Admin was NOT authenticated"); return false; }
/** * Returns true if URL fragments should be removed for a specific site, * false if otherwise. * * This function uses the Tracker cache and not the MySQL database. * * @param $idSite int The ID of the site to check for. * @return bool */ public static function shouldRemoveURLFragmentFor($idSite) { $websiteAttributes = Cache::getCacheWebsiteAttributes($idSite); return empty($websiteAttributes['keep_url_fragment']); }
protected function detectSiteSearch($originalUrl) { $website = Cache::getCacheWebsiteAttributes($this->request->getIdSite()); if (empty($website['sitesearch'])) { Common::printDebug("Internal 'Site Search' tracking is not enabled for this site. "); return false; } $actionName = $url = $categoryName = $count = false; $originalUrl = PageUrl::cleanupUrl($originalUrl); // Detect Site search from Tracking API parameters rather than URL $searchKwd = $this->request->getParam('search'); if (!empty($searchKwd)) { $actionName = $searchKwd; $isCategoryName = $this->request->getParam('search_cat'); if (!empty($isCategoryName)) { $categoryName = $isCategoryName; } $isCount = $this->request->getParam('search_count'); if ($this->isValidSearchCount($isCount)) { $count = $isCount; } } if (empty($actionName)) { $parsedUrl = @parse_url($originalUrl); // Detect Site Search from URL query parameters if (!empty($parsedUrl['query']) || !empty($parsedUrl['fragment'])) { // array($url, $actionName, $categoryName, $count); $searchInfo = $this->detectSiteSearchFromUrl($website, $parsedUrl); if (!empty($searchInfo)) { list($url, $actionName, $categoryName, $count) = $searchInfo; } } } $actionName = trim($actionName); $categoryName = trim($categoryName); if (empty($actionName)) { Common::printDebug("(this is not a Site Search request)"); return false; } Common::printDebug("Detected Site Search keyword '{$actionName}'. "); if (!empty($categoryName)) { Common::printDebug("- Detected Site Search Category '{$categoryName}'. "); } if ($count !== false) { Common::printDebug("- Search Results Count was '{$count}'. "); } if ($url != $originalUrl) { Common::printDebug("NOTE: The Page URL was changed / removed, during the Site Search detection, was '{$originalUrl}', now is '{$url}'"); } return array($actionName, $url, $categoryName, $count); }
public static function isHostKnownAliasHost($urlHost, $idSite) { $websiteData = Cache::getCacheWebsiteAttributes($idSite); if (isset($websiteData['hosts'])) { $canonicalHosts = array(); foreach ($websiteData['hosts'] as $host) { $canonicalHosts[] = self::toCanonicalHost($host); } $canonicalHost = self::toCanonicalHost($urlHost); if (in_array($canonicalHost, $canonicalHosts)) { return true; } } return false; }
public static function isHostKnownAliasHost($urlHost, $idSite) { $websiteData = Cache::getCacheWebsiteAttributes($idSite); if (isset($websiteData['hosts'])) { $canonicalHosts = array(); foreach ($websiteData['hosts'] as $host) { $canonicalHosts[] = str_replace('www.', '', mb_strtolower($host, 'UTF-8')); } $canonicalHost = str_replace('www.', '', mb_strtolower($urlHost, 'UTF-8')); if (in_array($canonicalHost, $canonicalHosts)) { return true; } } return false; }
public function test_shouldCacheDimensinsViaWebsiteAttributes_ButOnlyActiveOnes() { $this->configureSomeDimensions(); $cache = Cache::getCacheWebsiteAttributes($idSite = 1); $this->assertCount(4, $cache['custom_dimensions']); foreach ($cache['custom_dimensions'] as $dimension) { $this->assertTrue($dimension['active']); } $cache = Cache::getCacheWebsiteAttributes($idSite = 2); $this->assertCount(1, $cache['custom_dimensions']); foreach ($cache['custom_dimensions'] as $dimension) { $this->assertTrue($dimension['active']); } }
/** * Get Cached Custom Dimensions during tracking. Returns only active custom dimensions. * * @param Request $request * @return array * @throws \Piwik\Exception\UnexpectedWebsiteFoundException */ public static function getCachedCustomDimensions(Request $request) { $idSite = $request->getIdSite(); $cache = Cache::getCacheWebsiteAttributes($idSite); if (empty($cache['custom_dimensions'])) { // no custom dimensions set return array(); } return $cache['custom_dimensions']; }