作者:KiwiJuice
项目:handball-dacha
public static function getArchiveIdAndVisits(Site $site, Period $period, Segment $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin)
{
$dateStart = $period->getDateStart();
$bindSQL = array($site->getId(), $dateStart->toString('Y-m-d'), $period->getDateEnd()->toString('Y-m-d'), $period->getId());
$timeStampWhere = '';
if ($minDatetimeArchiveProcessedUTC) {
$timeStampWhere = " AND ts_archived >= ? ";
$bindSQL[] = Date::factory($minDatetimeArchiveProcessedUTC)->getDatetime();
}
$pluginOrVisitsSummary = array("VisitsSummary", $requestedPlugin);
$pluginOrVisitsSummary = array_unique($pluginOrVisitsSummary);
$sqlWhereArchiveName = self::getNameCondition($pluginOrVisitsSummary, $segment);
$sqlQuery = "\tSELECT idarchive, value, name, date1 as startDate\n\t\t\t\t\t\tFROM " . ArchiveTableCreator::getNumericTable($dateStart) . "``\n\t\t\t\t\t\tWHERE idsite = ?\n\t\t\t\t\t\t\tAND date1 = ?\n\t\t\t\t\t\t\tAND date2 = ?\n\t\t\t\t\t\t\tAND period = ?\n\t\t\t\t\t\t\tAND ( ({$sqlWhereArchiveName})\n\t\t\t\t\t\t\t\t OR name = '" . self::NB_VISITS_RECORD_LOOKED_UP . "'\n\t\t\t\t\t\t\t\t OR name = '" . self::NB_VISITS_CONVERTED_RECORD_LOOKED_UP . "')\n\t\t\t\t\t\t\t{$timeStampWhere}\n\t\t\t\t\t\tORDER BY idarchive DESC";
$results = Db::fetchAll($sqlQuery, $bindSQL);
if (empty($results)) {
return false;
}
$idArchive = self::getMostRecentIdArchiveFromResults($segment, $requestedPlugin, $results);
$idArchiveVisitsSummary = self::getMostRecentIdArchiveFromResults($segment, "VisitsSummary", $results);
list($visits, $visitsConverted) = self::getVisitsMetricsFromResults($idArchive, $idArchiveVisitsSummary, $results);
if ($visits === false && $idArchive === false) {
return false;
}
return array($idArchive, $visits, $visitsConverted);
}
作者:brienomatt
项目:elmsl
/**
* Returns true if it is likely that the data for this report has been purged and if the
* user should be told about that.
*
* In order for this function to return true, the following must also be true:
* - The data table for this report must either be empty or not have been fetched.
* - The period of this report is not a multiple period.
* - The date of this report must be older than the delete_reports_older_than config option.
* @param DataTableInterface $dataTable
* @return bool
*/
public static function hasReportBeenPurged($dataTable)
{
$strPeriod = Common::getRequestVar('period', false);
$strDate = Common::getRequestVar('date', false);
if (false !== $strPeriod && false !== $strDate && (is_null($dataTable) || !empty($dataTable) && $dataTable->getRowsCount() == 0)) {
// if range, only look at the first date
if ($strPeriod == 'range') {
$idSite = Common::getRequestVar('idSite', '');
if (intval($idSite) != 0) {
$site = new Site($idSite);
$timezone = $site->getTimezone();
} else {
$timezone = 'UTC';
}
$period = new Range('range', $strDate, $timezone);
$reportDate = $period->getDateStart();
} elseif (Period::isMultiplePeriod($strDate, $strPeriod)) {
// if a multiple period, this function is irrelevant
return false;
} else {
// otherwise, use the date as given
$reportDate = Date::factory($strDate);
}
$reportYear = $reportDate->toString('Y');
$reportMonth = $reportDate->toString('m');
if (static::shouldReportBePurged($reportYear, $reportMonth)) {
return true;
}
}
return false;
}
作者:Abin
项目:piwi
/**
* @param bool $standalone When set to true, the Top controls will be hidden to provide better full screen view
* @param bool $fetch
* @param bool|string $segmentOverride
*
* @return string
*/
public function realtimeMap($standalone = false, $fetch = false, $segmentOverride = false)
{
$this->checkUserCountryPluginEnabled();
$idSite = Common::getRequestVar('idSite', 1, 'int');
Piwik::checkUserHasViewAccess($idSite);
$token_auth = Piwik::getCurrentUserTokenAuth();
$view = new View('@UserCountryMap/realtimeMap');
$view->mapIsStandaloneNotWidget = $standalone;
$view->metrics = $this->getMetrics($idSite, 'range', self::REAL_TIME_WINDOW, $token_auth);
$view->defaultMetric = 'nb_visits';
$liveRefreshAfterMs = (int) Config::getInstance()->General['live_widget_refresh_after_seconds'] * 1000;
$goals = APIGoals::getInstance()->getGoals($idSite);
$site = new Site($idSite);
$hasGoals = !empty($goals) || $site->isEcommerceEnabled();
// maximum number of visits to be displayed in the map
$maxVisits = Common::getRequestVar('filter_limit', 100, 'int');
// some translations
$locale = array('nb_actions' => Piwik::translate('VisitsSummary_NbActionsDescription'), 'local_time' => Piwik::translate('VisitTime_ColumnLocalTime'), 'from' => Piwik::translate('General_FromReferrer'), 'seconds' => Piwik::translate('UserCountryMap_Seconds'), 'seconds_ago' => Piwik::translate('UserCountryMap_SecondsAgo'), 'minutes' => Piwik::translate('UserCountryMap_Minutes'), 'minutes_ago' => Piwik::translate('UserCountryMap_MinutesAgo'), 'hours' => Piwik::translate('UserCountryMap_Hours'), 'hours_ago' => Piwik::translate('UserCountryMap_HoursAgo'), 'days_ago' => Piwik::translate('UserCountryMap_DaysAgo'), 'actions' => Piwik::translate('VisitsSummary_NbPageviewsDescription'), 'searches' => Piwik::translate('UserCountryMap_Searches'), 'goal_conversions' => Piwik::translate('UserCountryMap_GoalConversions'));
$segment = $segmentOverride ?: Request::getRawSegmentFromRequest() ?: '';
$params = array('period' => 'range', 'idSite' => $idSite, 'segment' => $segment, 'token_auth' => $token_auth);
$realtimeWindow = Common::getRequestVar('realtimeWindow', self::REAL_TIME_WINDOW, 'string');
if ($realtimeWindow != 'false') {
// handle special value
$params['date'] = $realtimeWindow;
}
$reqParams = $this->getEnrichedRequest($params, $encode = false);
$view->config = array('metrics' => array(), 'svgBasePath' => $view->piwikUrl . 'plugins/UserCountryMap/svg/', 'liveRefreshAfterMs' => $liveRefreshAfterMs, '_' => $locale, 'reqParams' => $reqParams, 'siteHasGoals' => $hasGoals, 'maxVisits' => $maxVisits, 'changeVisitAlpha' => Common::getRequestVar('changeVisitAlpha', true, 'int'), 'removeOldVisits' => Common::getRequestVar('removeOldVisits', true, 'int'), 'showFooterMessage' => Common::getRequestVar('showFooterMessage', true, 'int'), 'showDateTime' => Common::getRequestVar('showDateTime', true, 'int'), 'doNotRefreshVisits' => Common::getRequestVar('doNotRefreshVisits', false, 'int'), 'enableAnimation' => Common::getRequestVar('enableAnimation', true, 'int'), 'forceNowValue' => Common::getRequestVar('forceNowValue', false, 'int'));
return $view->render();
}
作者:FluentDevelopmen
项目:piwi
protected function init()
{
$idSite = $this->getIdSite();
$site = new Site($idSite);
if ($site->isEcommerceEnabled()) {
$this->addWidget('General_Overview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER));
$this->addWidget('Goals_EcommerceLog', 'getEcommerceLog');
}
}
作者:brienomatt
项目:elmsl
public function configure(WidgetsList $widgetsList)
{
$idSite = Common::getRequestVar('idSite', null, 'int');
$site = new Site($idSite);
if ($site->isEcommerceEnabled()) {
$this->addEcommerceWidgets($widgetsList);
}
$this->addGoalsWidgets($widgetsList, $idSite);
}
作者:piwi
项目:piwi
public function isEnabled()
{
$idSite = Common::getRequestVar('idSite', false, 'int');
if (empty($idSite)) {
return false;
}
$site = new Site($idSite);
return $site->isEcommerceEnabled();
}
作者:cem
项目:piwi
public function configureReportingMenu(MenuReporting $menu)
{
$idSite = Common::getRequestVar('idSite', null, 'int');
$site = new Site($idSite);
if ($site->isEcommerceEnabled()) {
$ecommerceParams = array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER);
$menu->addItem('Goals_Ecommerce', '', array(), 24);
$menu->addItem('Goals_Ecommerce', 'General_Overview', $this->urlForAction('ecommerceReport', $ecommerceParams), 1);
$menu->addItem('Goals_Ecommerce', 'Goals_EcommerceLog', $this->urlForAction('ecommerceLogReport'), 2);
$menu->addItem('Goals_Ecommerce', 'Goals_Products', $this->urlForAction('products', $ecommerceParams), 3);
$menu->addItem('Goals_Ecommerce', 'Ecommerce_Sales', $this->urlForAction('sales', $ecommerceParams), 4);
}
}
作者:piwi
项目:piwi
public static function configure(WidgetConfig $config)
{
$config->setCategoryId('Goals_Ecommerce');
$config->setSubcategoryId('Goals_EcommerceLog');
$config->setName('Goals_EcommerceLog');
$idSite = Common::getRequestVar('idSite', 0, 'int');
if (empty($idSite)) {
$config->disable();
return;
}
$site = new Site($idSite);
$config->setIsEnabled($site->isEcommerceEnabled());
}
作者:dorelljame
项目:piwi
public function setUp()
{
parent::setUp();
$idSite = 1;
if (!Fixture::siteCreated($idSite)) {
Fixture::createWebsite('2014-01-01 00:00:00');
}
$site = new Site($idSite);
$date = Date::factory('2012-01-01');
$period = Period\Factory::build('month', $date);
$segment = new Segment('', array($site->getId()));
$params = new Parameters($site, $period, $segment);
$this->logAggregator = new LogAggregator($params);
}
作者:mgou-ne
项目:piwi
/**
* @dataProvider getUnitColumns
* @group Core
*/
public function testGetUnit($column, $expected)
{
Site::setSites(array(1 => array('name' => 'TestSite', 'currency' => 'EUR')));
FakeAccess::$superUser = true;
$actual = Metrics::getUnit($column, 1);
$this->assertEquals($expected, $actual);
}
作者:brienomatt
项目:elmsl
public function configureTopMenu(MenuTop $menu)
{
$userPreferences = new UserPreferences();
$idSite = $userPreferences->getDefaultWebsiteId();
$tooltip = Piwik::translate('Dashboard_TopLinkTooltip', Site::getNameFor($idSite));
$urlParams = array('module' => 'CoreHome', 'action' => 'index', 'idSite' => $idSite);
$menu->add('Dashboard_Dashboard', null, $urlParams, true, 1, $tooltip);
}
作者:piwi
项目:piwi
public function render()
{
$idSite = Common::getRequestVar('idSite');
$site = new Site($idSite);
$url = urldecode(Common::getRequestVar('url', '', 'string'));
if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
$url = 'http://' . $url;
}
if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
$url = $site->getMainUrl();
}
$dataTable = API::getInstance()->getRank($url);
/** @var \Piwik\DataTable\Renderer\Php $renderer */
$renderer = Renderer::factory('php');
$renderer->setSerialize(false);
return $this->renderTemplate('getRank', array('urlToRank' => Url::getHostFromUrl($url), 'ranks' => $renderer->render($dataTable)));
}
作者:normimu
项目:piwi
public function configureTopMenu(MenuTop $menu)
{
$userPreferences = new UserPreferences();
$idSite = $userPreferences->getDefaultWebsiteId();
$tooltip = Piwik::translate('Dashboard_TopLinkTooltip', Site::getNameFor($idSite));
$urlParams = $this->urlForModuleActionWithDefaultUserParams('CoreHome', 'index');
$menu->addItem('Dashboard_Dashboard', null, $urlParams, 1, $tooltip);
}
作者:a4tunad
项目:piwi
/**
* @dataProvider getUnitColumns
* @group Core
*/
public function testGetUnit($column, $expected)
{
\Piwik\Site::setSites(array(1 => array('name' => 'TestSite', 'currency' => 'EUR')));
$pseudoMockAccess = new FakeAccess();
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
$actual = Metrics::getUnit($column, 1);
$this->assertEquals($expected, $actual);
}
作者:KiwiJuice
项目:handball-dacha
/**
* This method takes the websites timezone into consideration when scheduling a task.
* @param int $idSite
* @param string $period Eg 'day', 'week', 'month'
* @return Daily|Monthly|Weekly
* @throws \Exception
* @ignore
*/
public static function getScheduledTimeForSite($idSite, $period)
{
$arbitraryDateInUTC = Date::factory('2011-01-01');
$midnightInSiteTimezone = date('H', Date::factory($arbitraryDateInUTC, Site::getTimezoneFor($idSite))->getTimestamp());
$hourInUTC = (24 - $midnightInSiteTimezone) % 24;
$schedule = self::getScheduledTimeForPeriod($period);
$schedule->setHour($hourInUTC);
return $schedule;
}
作者:a4tunad
项目:piwi
protected function init()
{
$this->addWidget('Goals_GoalsOverview', 'widgetGoalsOverview');
$idSite = $this->getIdSite();
$goals = API::getInstance()->getGoals($idSite);
if (count($goals) > 0) {
foreach ($goals as $goal) {
$name = Common::sanitizeInputValue($goal['name']);
$params = array('idGoal' => $goal['idgoal']);
$this->addWidget($name, 'widgetGoalReport', $params);
}
}
$site = new Site($idSite);
if ($site->isEcommerceEnabled()) {
$this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceOverview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER));
$this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceLog', 'getEcommerceLog');
}
}
作者:PiwikPR
项目:plugin-InterSite
/**
* Return the number of visitors that visited every site in the given list for the
* given date range. Includes the number of visitors that visited at least one site
* and the number that visited every site.
*
* This data is calculated on demand, and for very large tables can take a long time
* to run.
*
* See {@link Model\DistinctMetricsAggregator} for more information.
*
* @param string $idSite comma separated list of site IDs, ie, `"1,2,3"`
* @param string $period
* @param string $date
* @return array Metrics **nb_total_visitors** and **nb_shared_visitors**.
* @throws Exception if $idSite references zero sites or just one site.
*/
public function getCommonVisitors($idSite, $period, $date, $segment = false)
{
if (empty($idSite)) {
throw new Exception("No sites to get common visitors for.");
}
$idSites = Site::getIdSitesFromIdSitesString($idSite);
Piwik::checkUserHasViewAccess($idSites);
$segment = new Segment($segment, $idSites);
$period = PeriodFactory::build($period, $date);
return $this->distinctMetricsAggregator->getCommonVisitorCount($idSites, $period->getDateStart(), $period->getDateEnd(), $segment);
}
作者:a4tunad
项目:piwi
protected function setSparklinesAndNumbers($view)
{
$view->urlSparklineNbVisits = $this->getUrlSparkline('getEvolutionGraph', array('columns' => $view->displayUniqueVisitors ? array('nb_visits', 'nb_uniq_visitors') : array('nb_visits')));
$view->urlSparklineNbUsers = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_users')));
$view->urlSparklineNbPageviews = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_pageviews', 'nb_uniq_pageviews')));
$view->urlSparklineNbDownloads = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_downloads', 'nb_uniq_downloads')));
$view->urlSparklineNbOutlinks = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_outlinks', 'nb_uniq_outlinks')));
$view->urlSparklineAvgVisitDuration = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('avg_time_on_site')));
$view->urlSparklineMaxActions = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('max_actions')));
$view->urlSparklineActionsPerVisit = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_actions_per_visit')));
$view->urlSparklineBounceRate = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('bounce_rate')));
$view->urlSparklineAvgGenerationTime = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('avg_time_generation')));
$idSite = Common::getRequestVar('idSite');
$displaySiteSearch = Site::isSiteSearchEnabledFor($idSite);
if ($displaySiteSearch) {
$view->urlSparklineNbSearches = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_searches', 'nb_keywords')));
}
$view->displaySiteSearch = $displaySiteSearch;
$dataTableVisit = self::getVisitsSummary();
$dataRow = $dataTableVisit->getRowsCount() == 0 ? new Row() : $dataTableVisit->getFirstRow();
$view->nbUniqVisitors = (int) $dataRow->getColumn('nb_uniq_visitors');
$view->nbUsers = (int) $dataRow->getColumn('nb_users');
$nbVisits = (int) $dataRow->getColumn('nb_visits');
$view->nbVisits = $nbVisits;
$view->averageVisitDuration = $dataRow->getColumn('avg_time_on_site');
$nbBouncedVisits = $dataRow->getColumn('bounce_count');
$view->bounceRate = Piwik::getPercentageSafe($nbBouncedVisits, $nbVisits);
$view->maxActions = (int) $dataRow->getColumn('max_actions');
$view->nbActionsPerVisit = $dataRow->getColumn('nb_actions_per_visit');
if (Common::isActionsPluginEnabled()) {
$view->showActionsPluginReports = true;
$dataTableActions = APIActions::getInstance()->get($idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), \Piwik\API\Request::getRawSegmentFromRequest());
$dataActionsRow = $dataTableActions->getRowsCount() == 0 ? new Row() : $dataTableActions->getFirstRow();
$view->nbPageviews = (int) $dataActionsRow->getColumn('nb_pageviews');
$view->nbUniquePageviews = (int) $dataActionsRow->getColumn('nb_uniq_pageviews');
$view->nbDownloads = (int) $dataActionsRow->getColumn('nb_downloads');
$view->nbUniqueDownloads = (int) $dataActionsRow->getColumn('nb_uniq_downloads');
$view->nbOutlinks = (int) $dataActionsRow->getColumn('nb_outlinks');
$view->nbUniqueOutlinks = (int) $dataActionsRow->getColumn('nb_uniq_outlinks');
$view->averageGenerationTime = $dataActionsRow->getColumn('avg_time_generation');
if ($displaySiteSearch) {
$view->nbSearches = (int) $dataActionsRow->getColumn('nb_searches');
$view->nbKeywords = (int) $dataActionsRow->getColumn('nb_keywords');
}
// backward compatibility:
// show actions if the finer metrics are not archived
$view->showOnlyActions = false;
if ($dataActionsRow->getColumn('nb_pageviews') + $dataActionsRow->getColumn('nb_downloads') + $dataActionsRow->getColumn('nb_outlinks') == 0 && $dataRow->getColumn('nb_actions') > 0) {
$view->showOnlyActions = true;
$view->nbActions = $dataRow->getColumn('nb_actions');
$view->urlSparklineNbActions = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array('nb_actions')));
}
}
}
作者:kreyne
项目:elmsl
function getRank()
{
$idSite = Common::getRequestVar('idSite');
$site = new Site($idSite);
$url = urldecode(Common::getRequestVar('url', '', 'string'));
if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
$url = 'http://' . $url;
}
if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
$url = $site->getMainUrl();
}
$dataTable = API::getInstance()->getRank($url);
$view = new View('@SEO/getRank');
$view->urlToRank = RankChecker::extractDomainFromUrl($url);
/** @var \Piwik\DataTable\Renderer\Php $renderer */
$renderer = Renderer::factory('php');
$renderer->setSerialize(false);
$view->ranks = $renderer->render($dataTable);
return $view->render();
}
作者:a4tunad
项目:piwi
public function schedule()
{
foreach (API::getInstance()->getReports() as $report) {
if (!$report['deleted'] && $report['period'] != ScheduledTime::PERIOD_NEVER) {
$timezone = Site::getTimezoneFor($report['idsite']);
$schedule = ScheduledTime::getScheduledTimeForPeriod($report['period']);
$schedule->setHour($report['hour']);
$schedule->setTimezone($timezone);
$this->custom(API::getInstance(), 'sendReport', $report['idreport'], $schedule);
}
}
}