示例#1
0
 function index()
 {
     $view = Piwik_View::factory('SitesManager');
     if (Piwik::isUserIsSuperUser()) {
         $sites = Piwik_SitesManager_API::getInstance()->getAllSites();
         Piwik_Site::setSites($sites);
         $sites = array_values($sites);
     } else {
         $sites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess();
         Piwik_Site::setSitesFromArray($sites);
     }
     foreach ($sites as &$site) {
         $site['alias_urls'] = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($site['idsite']);
         $site['excluded_ips'] = str_replace(',', '<br/>', $site['excluded_ips']);
         $site['excluded_parameters'] = str_replace(',', '<br/>', $site['excluded_parameters']);
     }
     $view->adminSites = $sites;
     $view->adminSitesCount = count($sites);
     $timezones = Piwik_SitesManager_API::getInstance()->getTimezonesList();
     $view->timezoneSupported = Piwik::isTimezoneSupportEnabled();
     $view->timezones = Piwik_Common::json_encode($timezones);
     $view->defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
     $view->currencies = Piwik_Common::json_encode(Piwik_SitesManager_API::getInstance()->getCurrencyList());
     $view->defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency();
     $view->utcTime = Piwik_Date::now()->getDatetime();
     $excludedIpsGlobal = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal();
     $view->globalExcludedIps = str_replace(',', "\n", $excludedIpsGlobal);
     $excludedQueryParametersGlobal = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal();
     $view->globalExcludedQueryParameters = str_replace(',', "\n", $excludedQueryParametersGlobal);
     $view->currentIpAddress = Piwik_IP::getIpFromHeader();
     $view->showAddSite = (bool) Piwik_Common::getRequestVar('showaddsite', false);
     $this->setBasicVariablesView($view);
     $view->menu = Piwik_GetAdminMenu();
     echo $view->render();
 }
示例#2
0
 function index()
 {
     $view = Piwik_View::factory('SitesManager');
     $sites = Piwik_SitesManager_API::getInstance()->getSitesWithAdminAccess();
     foreach ($sites as $site) {
         $sitesIndexedById[$site['idsite']] = $site;
     }
     Piwik_Site::setSites($sitesIndexedById);
     foreach ($sites as &$site) {
         $site['alias_urls'] = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($site['idsite']);
         $site['excluded_ips'] = str_replace(',', '<br/>', $site['excluded_ips']);
         $site['excluded_parameters'] = str_replace(',', '<br/>', $site['excluded_parameters']);
     }
     $view->adminSites = $sites;
     $view->adminSitesCount = count($sites);
     $timezones = Piwik_SitesManager_API::getInstance()->getTimezonesList();
     $view->timezoneSupported = Piwik::isTimezoneSupportEnabled();
     $view->timezones = json_encode($timezones);
     $view->defaultTimezone = Piwik_SitesManager_API::getInstance()->getDefaultTimezone();
     $view->currencies = json_encode(Piwik_SitesManager_API::getInstance()->getCurrencyList());
     $view->defaultCurrency = Piwik_SitesManager_API::getInstance()->getDefaultCurrency();
     $view->utcTime = Piwik_Date::now()->getDatetime();
     $excludedIpsGlobal = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal();
     $view->globalExcludedIps = str_replace(',', "\n", $excludedIpsGlobal);
     $excludedQueryParametersGlobal = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal();
     $view->globalExcludedQueryParameters = str_replace(',', "\n", $excludedQueryParametersGlobal);
     $view->currentIpAddress = Piwik_Common::getIpString();
     $this->setBasicVariablesView($view);
     $view->menu = Piwik_GetAdminMenu();
     echo $view->render();
 }
示例#3
0
 /**
  * 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;
 }
示例#4
0
文件: API.php 项目: nnnnathann/piwik
 private function buildDataTable($sites, $period, $date, $segment, $_restrictSitesToLogin, $enhanced)
 {
     $allWebsitesRequested = $sites == 'all';
     if ($allWebsitesRequested) {
         if (Piwik::isUserIsSuperUser() && !Piwik_TaskScheduler::isTaskBeingExecuted()) {
             Piwik_Site::setSites(Piwik_SitesManager_API::getInstance()->getAllSites());
         } else {
             Piwik_Site::setSitesFromArray(Piwik_SitesManager_API::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin));
         }
     }
     // build the archive type used to query archive data
     $archive = Piwik_Archive::build($sites, $period, $date, $segment, $_restrictSitesToLogin);
     // determine what data will be displayed
     $fieldsToGet = array();
     $columnNameRewrites = array();
     $apiECommerceMetrics = array();
     $apiMetrics = Piwik_MultiSites_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 Piwik_DataTable_Array
     $dataTable = $archive->getDataTableFromNumeric($fieldsToGet);
     // get rid of the DataTable_Array that is created by the IndexedBySite archive type
     if ($dataTable instanceof Piwik_DataTable_Array && $allWebsitesRequested) {
         $dataTable = $dataTable->mergeChildren();
     } else {
         if (!$dataTable instanceof Piwik_DataTable_Array) {
             $firstDataTableRow = $dataTable->getFirstRow();
             $firstDataTableRow->setColumn('label', $sites);
         }
     }
     // 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, $_restrictSitesToLogin);
         $pastData = $pastArchive->getDataTableFromNumeric($fieldsToGet);
         $pastData = $pastData->mergeChildren();
         // use past data to calculate evolution percentages
         $this->calculateEvolutionPercentages($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) {
         // $dataTableRows instanceOf Piwik_DataTable_Row[]
         $dataTableRows = $dataTable->getRows();
         foreach ($dataTableRows as $dataTableRow) {
             $siteId = $dataTableRow->getColumn('label');
             if (!Piwik_Site::isEcommerceEnabledFor($siteId)) {
                 foreach ($apiECommerceMetrics as $metricSettings) {
                     $dataTableRow->deleteColumn($metricSettings[self::METRIC_RECORD_NAME_KEY]);
                     $dataTableRow->deleteColumn($metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY]);
                 }
             }
         }
     }
     // 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 ($allWebsitesRequested) {
         $getNameFor = array('Piwik_Site', 'getNameFor');
         $dataTable->filter('ColumnCallbackReplace', array('label', $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 Piwik_API_ResponseBuilder throws 'Call to a member function getColumns() on a non-object'
     if ($allWebsitesRequested) {
         $dataTable->filter('ColumnCallbackDeleteRow', array(self::NB_VISITS_METRIC, create_function('$value', 'return $value != 0;')));
     }
     return $dataTable;
 }