/** * @param Piwik_Event_Notification $notification notification object */ function addUniqueVisitorsColumnToGivenReport($notification) { $view = $notification->getNotificationInfo(); $view = $view['view']; if ($view->getCurrentControllerName() == 'Referers' && $view->getCurrentControllerAction() == 'getWebsites') { $view->addColumnToDisplay('nb_uniq_visitors'); } }
/** * Hooks when a website tracker cache is flushed (website updated, cache deleted, or empty cache) * Will record in the tracker config file all data needed for this website in Tracker. * * @param Piwik_Event_Notification $notification * @return void */ function recordWebsiteDataInCache($notification) { $idSite = $notification->getNotificationInfo(); // add the 'hosts' entry in the website array $array =& $notification->getNotificationObject(); $array['hosts'] = $this->getTrackerHosts($idSite); $array['excluded_ips'] = $this->getTrackerExcludedIps($idSite); $array['excluded_parameters'] = $this->getTrackerExcludedQueryParameters($idSite); }
/** * Hooks when a website tracker cache is flushed (website/user updated, cache deleted, or empty cache) * Will record in the tracker config file the list of Admin token_auth for this website. This * will be used when the Tracking API is used with setIp(), setForceDateTime(), setVisitorId(), etc. * * @param Piwik_Event_Notification $notification * @return void */ function recordAdminUsersInCache($notification) { $idSite = $notification->getNotificationInfo(); // add the 'hosts' entry in the website array $users = Piwik_UsersManager_API::getInstance()->getUsersWithSiteAccess($idSite, 'admin'); $tokens = array(); foreach ($users as $user) { $tokens[] = $user['token_auth']; } $array =& $notification->getNotificationObject(); $array['admin_token_auth'] = $tokens; }
/** * Hooks when a website tracker cache is flushed (website updated, cache deleted, or empty cache) * Will record in the tracker config file all data needed for this website in Tracker. * * @param Piwik_Event_Notification $notification notification object * @return void */ function recordWebsiteDataInCache($notification) { $idSite = $notification->getNotificationInfo(); // add the 'hosts' entry in the website array $array =& $notification->getNotificationObject(); $array['hosts'] = $this->getTrackerHosts($idSite); $website = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); $array['excluded_ips'] = $this->getTrackerExcludedIps($website); $array['excluded_parameters'] = self::getTrackerExcludedQueryParameters($website); $array['sitesearch'] = $website['sitesearch']; $array['sitesearch_keyword_parameters'] = $this->getTrackerSearchKeywordParameters($website); $array['sitesearch_category_parameters'] = $this->getTrackerSearchCategoryParameters($website); }
/** * Initializes the authentication object. * Listens to FrontController.initAuthenticationObject hook. * * @param Piwik_Event_Notification $notification notification object */ function initAuthenticationObject($notification) { $auth = new Piwik_Login_Auth(); Zend_Registry::set('auth', $auth); $allowCookieAuthentication = $notification->getNotificationInfo(); $action = Piwik::getAction(); if (Piwik::getModule() === 'API' && (empty($action) || $action == 'index') && $allowCookieAuthentication !== true) { return; } $authCookieName = Piwik_Config::getInstance()->General['login_cookie_name']; $authCookieExpiry = 0; $authCookiePath = Piwik_Config::getInstance()->General['login_cookie_path']; $authCookie = new Piwik_Cookie($authCookieName, $authCookieExpiry, $authCookiePath); $defaultLogin = '******'; $defaultTokenAuth = 'anonymous'; if ($authCookie->isCookieFound()) { $defaultLogin = $authCookie->get('login'); $defaultTokenAuth = $authCookie->get('token_auth'); } $auth->setLogin($defaultLogin); $auth->setTokenAuth($defaultTokenAuth); }
/** * @param Piwik_Event_Notification $notification notification object */ public function getVisitorLocation($notification) { require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; $location =& $notification->getNotificationObject(); $visitorInfo = $notification->getNotificationInfo(); $id = Piwik_Common::getCurrentLocationProviderId(); $provider = Piwik_UserCountry_LocationProvider::getProviderById($id); if ($provider === false) { $id = Piwik_UserCountry_LocationProvider_Default::ID; $provider = Piwik_UserCountry_LocationProvider::getProviderById($id); printDebug("GEO: no current location provider sent, falling back to default '{$id}' one."); } $location = $provider->getLocation($visitorInfo); // if we can't find a location, use default provider if ($location === false) { $defaultId = Piwik_UserCountry_LocationProvider_Default::ID; $provider = Piwik_UserCountry_LocationProvider::getProviderById($defaultId); $location = $provider->getLocation($visitorInfo); printDebug("GEO: couldn't find a location with Geo Module '{$id}', using Default '{$defaultId}' provider as fallback..."); $id = $defaultId; } printDebug("GEO: Found IP location (provider '" . $id . "'): " . var_export($location, true)); }
/** * @param Piwik_Event_Notification $notification notification object */ function fetchGoalsFromDb($notification) { $idsite = $notification->getNotificationInfo(); // add the 'goal' entry in the website array $array =& $notification->getNotificationObject(); $array['goals'] = Piwik_Goals_API::getInstance()->getGoals($idsite); }
/** * @param Piwik_Event_Notification $notification notification object * @return mixed */ public function getReportMetadata($notification) { $info = $notification->getNotificationInfo(); $reports =& $notification->getNotificationObject(); $idSites = $info['idSites']; // If only one website is selected, we add the Graph URL if (count($idSites) != 1) { return; } $idSite = reset($idSites); // in case API.getReportMetadata was not called with date/period we use sane defaults if (empty($info['period'])) { $info['period'] = 'day'; } if (empty($info['date'])) { $info['date'] = 'today'; } // need two sets of period & date, one for single period graphs, one for multiple periods graphs if (Piwik_Archive::isMultiplePeriod($info['date'], $info['period'])) { $periodForMultiplePeriodGraph = $info['period']; $dateForMultiplePeriodGraph = $info['date']; $periodForSinglePeriodGraph = 'range'; $dateForSinglePeriodGraph = $info['date']; } else { $periodForSinglePeriodGraph = $info['period']; $dateForSinglePeriodGraph = $info['date']; $piwikSite = new Piwik_Site($idSite); if ($periodForSinglePeriodGraph == 'range') { $periodForMultiplePeriodGraph = Piwik_Config::getInstance()->General['graphs_default_period_to_plot_when_period_range']; $dateForMultiplePeriodGraph = $dateForSinglePeriodGraph; } else { $periodForMultiplePeriodGraph = $periodForSinglePeriodGraph; $dateForMultiplePeriodGraph = Piwik_Controller::getDateRangeRelativeToEndDate($periodForSinglePeriodGraph, 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, $dateForSinglePeriodGraph, $piwikSite); } } $token_auth = Piwik_Common::getRequestVar('token_auth', false); $urlPrefix = "index.php?"; foreach ($reports as &$report) { $reportModule = $report['module']; $reportAction = $report['action']; $reportUniqueId = $reportModule . '_' . $reportAction; $parameters = array(); $parameters['module'] = 'API'; $parameters['method'] = 'ImageGraph.get'; $parameters['idSite'] = $idSite; $parameters['apiModule'] = $reportModule; $parameters['apiAction'] = $reportAction; if (!empty($token_auth)) { $parameters['token_auth'] = $token_auth; } // Forward custom Report parameters to the graph URL if (!empty($report['parameters'])) { $parameters = array_merge($parameters, $report['parameters']); } if (empty($report['dimension'])) { $parameters['period'] = $periodForMultiplePeriodGraph; $parameters['date'] = $dateForMultiplePeriodGraph; } else { $parameters['period'] = $periodForSinglePeriodGraph; $parameters['date'] = $dateForSinglePeriodGraph; } // add the idSubtable if it exists $idSubtable = Piwik_Common::getRequestVar('idSubtable', false); if ($idSubtable !== false) { $parameters['idSubtable'] = $idSubtable; } $report['imageGraphUrl'] = $urlPrefix . Piwik_Url::getQueryStringFromParameters($parameters); // thanks to API.getRowEvolution, reports with dimensions can now be plotted using an evolution graph // however, most reports with a fixed set of dimension values are excluded // this is done so Piwik Mobile and Scheduled Reports do not display them if (empty($report['constantRowsCount']) || in_array($reportUniqueId, self::$CONSTANT_ROW_COUNT_REPORT_EXCEPTIONS)) { $parameters['period'] = $periodForMultiplePeriodGraph; $parameters['date'] = $dateForMultiplePeriodGraph; $report['imageGraphEvolutionUrl'] = $urlPrefix . Piwik_Url::getQueryStringFromParameters($parameters); } } }
/** * @param Piwik_Event_Notification $notification notification object * @return mixed */ public function getReportMetadata($notification) { $info = $notification->getNotificationInfo(); $reports =& $notification->getNotificationObject(); $idSites = $info['idSites']; // If only one website is selected, we add the Graph URL if (count($idSites) != 1) { return; } $idSite = reset($idSites); // in case API.getReportMetadata was not called with date/period we use sane defaults if (empty($info['period'])) { $info['period'] = 'day'; } if (empty($info['date'])) { $info['date'] = 'today'; } // need two sets of period & date, one for single period graphs, one for multiple periods graphs if (Piwik_Archive::isMultiplePeriod($info['date'], $info['period'])) { $periodForMultiplePeriodGraph = $info['period']; $dateForMultiplePeriodGraph = $info['date']; $periodForSinglePeriodGraph = 'range'; $dateForSinglePeriodGraph = $info['date']; } else { $periodForSinglePeriodGraph = $info['period']; $dateForSinglePeriodGraph = $info['date']; $piwikSite = new Piwik_Site($idSite); if ($periodForSinglePeriodGraph == 'range') { $periodForMultiplePeriodGraph = Piwik_Config::getInstance()->General['graphs_default_period_to_plot_when_period_range']; $dateForMultiplePeriodGraph = $dateForSinglePeriodGraph; } else { $periodForMultiplePeriodGraph = $periodForSinglePeriodGraph; $dateForMultiplePeriodGraph = Piwik_Controller::getDateRangeRelativeToEndDate($periodForSinglePeriodGraph, 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, $dateForSinglePeriodGraph, $piwikSite); } } $token_auth = Piwik_Common::getRequestVar('token_auth', false); $urlPrefix = "index.php?"; foreach ($reports as &$report) { $parameters = array(); $parameters['module'] = 'API'; $parameters['method'] = 'ImageGraph.get'; $parameters['idSite'] = $idSite; $parameters['apiModule'] = $report['module']; $parameters['apiAction'] = $report['action']; if (!empty($token_auth)) { $parameters['token_auth'] = $token_auth; } // Forward custom Report parameters to the graph URL if (!empty($report['parameters'])) { $parameters = array_merge($parameters, $report['parameters']); } if (empty($report['dimension'])) { $parameters['period'] = $periodForMultiplePeriodGraph; $parameters['date'] = $dateForMultiplePeriodGraph; } else { $parameters['period'] = $periodForSinglePeriodGraph; $parameters['date'] = $dateForSinglePeriodGraph; } // add the idSubtable if it exists $idSubtable = Piwik_Common::getRequestVar('idSubtable', false); if ($idSubtable !== false) { $parameters['idSubtable'] = $idSubtable; } $report['imageGraphUrl'] = $urlPrefix . Piwik_Url::getQueryStringFromParameters($parameters); } }