Newer
Older
mattpiwik
a validé
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
mattpiwik
a validé
*
mattpiwik
a validé
* @package Piwik
*/
/**
* Parent class of all plugins Controllers (located in /plugins/PluginName/Controller.php
* It defines some helper functions controllers can use.
*
* @package Piwik
*/
abstract class Piwik_Controller
{
/**
* Plugin name, eg. Referers
* @var string
*/
protected $pluginName;
/**
* Date string
*
* @var string
*/
protected $strDate;
/**
* Piwik_Date object or null if the requested date is a range
*
* @var Piwik_Date|null
*/
protected $date;
/**
* @var int
*/
/**
* @var Piwik_Site
*/
mattpiwik
a validé
/**
* Builds the controller object, reads the date from the request, extracts plugin name from
*/
function __construct()
mattpiwik
a validé
{
$aPluginName = explode('_', get_class($this));
$this->pluginName = $aPluginName[1];
$date = Piwik_Common::getRequestVar('date', 'yesterday', 'string');
try {
$this->idSite = Piwik_Common::getRequestVar('idSite', false, 'int');
$this->site = new Piwik_Site($this->idSite);
$date = $this->getDateParameterInTimezone($date, $this->site->getTimezone());
$this->setDate($date);
mattpiwik
a validé
} catch(Exception $e){
// the date looks like YYYY-MM-DD,YYYY-MM-DD or other format
$this->date = null;
}
}
/**
* Helper method to convert "today" or "yesterday" to the default timezone specified.
* If the date is absolute, ie. YYYY-MM-DD, it will not be converted to the timezone
*
* @param string $date today, yesterday, YYYY-MM-DD
* @param string $defaultTimezone default timezone to use
* @return Piwik_Date
*/
protected function getDateParameterInTimezone($date, $defaultTimezone )
{
$timezone = null;
// if the requested date is not YYYY-MM-DD, we need to ensure
// it is relative to the website's timezone
if(in_array($date, array('today', 'yesterday')))
{
// today is at midnight; we really want to get the time now, so that
// * if the website is UTC+12 and it is 5PM now in UTC, the calendar will allow to select the UTC "tomorrow"
// * if the website is UTC-12 and it is 5AM now in UTC, the calendar will allow to select the UTC "yesterday"
if($date == 'today')
{
$date = 'now';
}
elseif($date == 'yesterday')
{
$date = 'yesterdaySameTime';
}
$timezone = $defaultTimezone;
}
return Piwik_Date::factory($date, $timezone);
}
/**
* Sets the date to be used by all other methods in the controller.
* If the date has to be modified, it should be called just after the controller construct
*
* @param Piwik_Date $date
* @return void
*/
protected function setDate(Piwik_Date $date)
{
$this->date = $date;
$strDate = $this->date->toString();
$this->strDate = $strDate;
mattpiwik
a validé
/**
* Returns the name of the default method that will be called
* when visiting: index.php?module=PluginName without the action parameter
*
* @return string
*/
function getDefaultAction()
{
return 'index';
}
mattpiwik
a validé
/**
* Given an Object implementing Piwik_View_Interface, we either:
mattpiwik
a validé
* - echo the output of the rendering if fetch = false
* - returns the output of the rendering if fetch = true
*
* @param Piwik_ViewDataTable $view view object to use
* @param bool $fetch indicates whether to output or return the content
mattpiwik
a validé
* @return string|void
*/
protected function renderView( Piwik_ViewDataTable $view, $fetch = false)
mattpiwik
a validé
{
Piwik_PostEvent( 'Controller.renderView',
$this,
array( 'view' => $view,
'controllerName' => $view->getCurrentControllerName(),
'controllerAction' => $view->getCurrentControllerAction(),
'apiMethodToRequestDataTable' => $view->getApiMethodToRequestDataTable(),
'controllerActionCalledWhenRequestSubTable' => $view->getControllerActionCalledWhenRequestSubTable(),
)
);
mattpiwik
a validé
$view->main();
$rendered = $view->getView()->render();
if($fetch)
{
return $rendered;
}
echo $rendered;
}
/**
* Returns a ViewDataTable object of an Evolution graph
* for the last30 days/weeks/etc. of the current period, relative to the current date.
*
* @param string $currentModuleName
* @param string $currentControllerAction
* @param string $apiMethod
mattpiwik
a validé
* @return Piwik_ViewDataTable_GenerateGraphHTML_ChartEvolution
*/
protected function getLastUnitGraph($currentModuleName, $currentControllerAction, $apiMethod)
{
$view = Piwik_ViewDataTable::factory('graphEvolution');
$view->init( $currentModuleName, $currentControllerAction, $apiMethod );
return $view;
}
BeezyT
a validé
/**
* This method is similar to self::getLastUnitGraph. It works with API.get to combine metrics
* of different *.get reports. The returned ViewDataTable is configured with column
* translations and selectable metrics.
* @param string $currentModuleName
* @param string $currentControllerAction
* @param array $columnsToDisplay
* @param array $selectableColumns
* @param bool|string $reportDocumentation
* @param string $apiMethod The method to request the report from
* (by default, this is API.get but it can be changed for custom stuff)
BeezyT
a validé
* @return Piwik_ViewDataTable_GenerateGraphHTML_ChartEvolution
*/
protected function getLastUnitGraphAcrossPlugins($currentModuleName, $currentControllerAction,
$columnsToDisplay, $selectableColumns=array(), $reportDocumentation=false, $apiMethod='API.get')
BeezyT
a validé
{
// back up and manipulate the columns parameter
$backupColumns = false;
if (isset($_GET['columns']))
{
$backupColumns = $_GET['columns'];
}
$_GET['columns'] = implode(',', $columnsToDisplay);
// load translations from meta data
BeezyT
a validé
$idSite = Piwik_Common::getRequestVar('idSite');
$period = Piwik_Common::getRequestVar('period');
$date = Piwik_Common::getRequestVar('date');
$meta = Piwik_API_API::getInstance()->getReportMetadata($idSite, $period, $date);
BeezyT
a validé
$columns = array_merge($columnsToDisplay, $selectableColumns);
$translations = array();
foreach ($meta as $reportMeta)
BeezyT
a validé
{
if ($reportMeta['action'] == 'get' && !isset($reportMeta['parameters']))
BeezyT
a validé
{
foreach ($columns as $column)
BeezyT
a validé
{
if (isset($reportMeta['metrics'][$column]))
{
$translations[$column] = $reportMeta['metrics'][$column];
}
BeezyT
a validé
}
}
}
// initialize the graph and load the data
$view = $this->getLastUnitGraph($currentModuleName, $currentControllerAction, $apiMethod);
BeezyT
a validé
$view->setColumnsToDisplay($columnsToDisplay);
$view->setSelectableColumns($selectableColumns);
$view->setColumnsTranslations($translations);
if ($reportDocumentation)
{
$view->setReportDocumentation($reportDocumentation);
}
$view->main();
// restore the columns parameter
if ($backupColumns !== false)
{
$_GET['columns'] = $backupColumns;
}
else
{
unset($_GET['columns']);
}
return $view;
}
mattpiwik
a validé
/**
* Returns the array of new processed parameters once the parameters are applied.
* For example: if you set range=last30 and date=2008-03-10,
mattpiwik
a validé
* the date element of the returned array will be "2008-02-10,2008-03-10"
mattpiwik
a validé
* Parameters you can set:
* - range: last30, previous10, etc.
* - date: YYYY-MM-DD, today, yesterday
* - period: day, week, month, year
* @param array $paramsToSet array( 'date' => 'last50', 'viewDataTable' =>'sparkline' )
* @throws Piwik_Access_NoAccessException
* @return array
mattpiwik
a validé
*/
protected function getGraphParamsModified($paramsToSet = array())
{
if(!isset($paramsToSet['period']))
{
$period = Piwik_Common::getRequestVar('period');
}
else
{
$period = $paramsToSet['period'];
}
if($period == 'range')
{
return $paramsToSet;
}
mattpiwik
a validé
if(!isset($paramsToSet['range']))
{
$range = 'last30';
}
else
{
$range = $paramsToSet['range'];
}
if(!isset($paramsToSet['date']))
{
$endDate = $this->strDate;
}
else
{
$endDate = $paramsToSet['date'];
}
if(is_null($this->site))
{
throw new Piwik_Access_NoAccessException("Website not initialized, check that you are logged in and/or using the correct token_auth.");
}
$paramDate = self::getDateRangeRelativeToEndDate($period, $range, $endDate, $this->site);
mattpiwik
a validé
$params = array_merge($paramsToSet , array( 'date' => $paramDate ) );
return $params;
}
/**
* Given for example, $period = month, $lastN = 'last6', $endDate = '2011-07-01',
* It will return the $date = '2011-01-01,2011-07-01' which is useful to draw graphs for the last N periods
*
* @param string $period
* @param string $lastN
* @param string $endDate
* @param Piwik_Site $site
*/
static public function getDateRangeRelativeToEndDate($period, $lastN, $endDate, $site )
{
$last30Relative = new Piwik_Period_Range($period, $lastN, $site->getTimezone() );
$last30Relative->setDefaultEndDate(Piwik_Date::factory($endDate));
$date = $last30Relative->getDateStart()->toString() . "," . $last30Relative->getDateEnd()->toString();
return $date;
}
mattpiwik
a validé
/**
* Returns a numeric value from the API.
* Works only for API methods that originally returns numeric values (there is no cast here)
*
* @param string $methodToCall Name of method to call, eg. Referers.getNumberOfDistinctSearchEngines
mattpiwik
a validé
* @return int|float
*/
protected function getNumericValue( $methodToCall )
{
$requestString = 'method='.$methodToCall.'&format=original';
$request = new Piwik_API_Request($requestString);
return $request->process();
}
/**
* Returns the current URL to use in a img src=X to display a sparkline.
mattpiwik
a validé
* $action must be the name of a Controller method that requests data using the Piwik_ViewDataTable::factory
* It will automatically build a sparkline by setting the viewDataTable=sparkline parameter in the URL.
* It will also computes automatically the 'date' for the 'last30' days/weeks/etc.
*
* @param string $action Method name of the controller to call in the img src
* @param array $customParameters Array of name => value of parameters to set in the generated GET url
mattpiwik
a validé
*/
protected function getUrlSparkline( $action, $customParameters = array() )
mattpiwik
a validé
{
$params = $this->getGraphParamsModified(
array( 'viewDataTable' => 'sparkline',
'action' => $action,
'module' => $this->pluginName)
+ $customParameters
mattpiwik
a validé
);
// convert array values to comma separated
foreach($params as &$value)
{
if(is_array($value))
{
$value = implode(',', $value);
}
}
mattpiwik
a validé
$url = Piwik_Url::getCurrentQueryStringWithParametersModified($params);
return $url;
}
*
* @param Piwik_Date $minDate
* @param Piwik_View $view
protected function setMinDateView(Piwik_Date $minDate, $view)
{
$view->minDateYear = $minDate->toString('Y');
$view->minDateMonth = $minDate->toString('m');
$view->minDateDay = $minDate->toString('d');
}
/**
* Sets "today" in the calendar. Today does not always mean "UTC" today, eg. for websites in UTC+12.
*
* @param Piwik_Date $maxDate
* @param Piwik_View $view
* @return void
*/
protected function setMaxDateView(Piwik_Date $maxDate, $view)
{
$view->maxDateYear = $maxDate->toString('Y');
$view->maxDateMonth = $maxDate->toString('m');
$view->maxDateDay = $maxDate->toString('d');
}
* Sets general variables to the view that are used by
* various templates and Javascript.
* If any error happens, displays the login screen
*
* @param Piwik_View $view
* @throws Exception
mattpiwik
a validé
protected function setGeneralVariablesView($view)
{
$view->date = $this->strDate;
try {
$view->idSite = $this->idSite;
if(empty($this->site) || empty($this->idSite))
{
throw new Exception("The requested website idSite is not found in the request, or is invalid.
Please check that you are logged in Piwik and have permission to access the specified website.");
$this->setPeriodVariablesView($view);
$rawDate = Piwik_Common::getRequestVar('date');
if($periodStr != 'range')
{
$date = Piwik_Date::factory($this->strDate);
$period = Piwik_Period::factory($periodStr, $date);
}
else
{
$period = new Piwik_Period_Range($periodStr, $rawDate, $this->site->getTimezone());
$view->rawDate = $rawDate;
$view->prettyDate = self::getCalendarPrettyDate($period);
benakamoorthi
a validé
$view->siteName = $this->site->getName();
$view->siteMainUrl = $this->site->getMainUrl();
$datetimeMinDate = $this->site->getCreationDate()->getDatetime();
$minDate = Piwik_Date::factory($datetimeMinDate, $this->site->getTimezone());
robocoder
a validé
$maxDate = Piwik_Date::factory('now', $this->site->getTimezone());
$this->setMaxDateView($maxDate, $view);
// Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected
$dateStart = $period->getDateStart();
if($dateStart->isEarlier($minDate)) { $dateStart = $minDate; }
$dateEnd = $period->getDateEnd();
if($dateEnd->isLater($maxDate)) { $dateEnd = $maxDate; }
$view->startDate = $dateStart;
$view->endDate = $dateEnd;
$language = Piwik_LanguagesManager::getLanguageForSession();
$view->language = !empty($language) ? $language : Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
$view->config_action_url_category_delimiter = Piwik_Config::getInstance()->General['action_url_category_delimiter'];
mattpiwik
a validé
} catch(Exception $e) {
Piwik_ExitWithMessage($e->getMessage());
mattpiwik
a validé
}
* Set the minimal variables in the view object
* @param Piwik_View $view
$view->debugTrackVisitsInsidePiwikUI = Piwik_Config::getInstance()->Debug['track_visits_inside_piwik_ui'];
$view->isSuperUser = Zend_Registry::get('access')->isSuperUser();
$view->isCustomLogo = Piwik_Config::getInstance()->branding['use_custom_logo'];
$view->logoHeader = Piwik_API_API::getInstance()->getHeaderLogoUrl();
$view->logoLarge = Piwik_API_API::getInstance()->getLogoUrl();
$view->enableFrames = Piwik_Config::getInstance()->General['enable_framed_pages']
|| @Piwik_Config::getInstance()->General['enable_framed_logins'];
if(!$view->enableFrames)
{
$view->setXFrameOptions('sameorigin');
}
benakamoorthi
a validé
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
self::setHostValidationVariablesView($view);
}
/**
* Checks if the current host is valid and sets variables on the given view, including:
*
* isValidHost - true if host is valid, false if otherwise
* invalidHostMessage - message to display if host is invalid (only set if host is invalid)
* invalidHost - the invalid hostname (only set if host is invalid)
* mailLinkStart - the open tag of a link to email the super user of this problem (only set
* if host is invalid)
*/
public static function setHostValidationVariablesView( $view )
{
// check if host is valid
$view->isValidHost = Piwik_Url::isValidHost();
if (!$view->isValidHost)
{
// invalid host, so display warning to user
$validHost = Piwik_Config::getInstance()->General['trusted_hosts'][0];
$invalidHost = $_SERVER['HTTP_HOST'];
$emailSubject = rawurlencode(Piwik_Translate('CoreHome_InjectedHostEmailSubject', $invalidHost));
$emailBody = rawurlencode(Piwik_Translate('CoreHome_InjectedHostEmailBody'));
$superUserEmail = Piwik::getSuperUserEmail();
$mailToUrl = "mailto:$superUserEmail?subject=$emailSubject&body=$emailBody";
$mailLinkStart = "<a href=\"$mailToUrl\">";
$invalidUrl = Piwik_Url::getCurrentUrlWithoutQueryString($checkIfTrusted = false);
$validUrl = Piwik_Url::getCurrentScheme() . '://' . $validHost
. Piwik_Url::getCurrentScriptName();
$validLink = "<a href=\"$validUrl\">$validUrl</a>";
$changeTrustedHostsUrl = "index.php"
. Piwik_Url::getCurrentQueryStringWithParametersModified(array(
'module' => 'CoreAdminHome',
'action' => 'generalSettings'
))
. "#trustedHostsSection";
$warningStart = Piwik_Translate('CoreHome_InjectedHostWarningIntro', array(
'<strong>'.$invalidUrl.'</strong>',
'<strong>'.$validUrl.'</strong>'
));
if (Piwik::isUserIsSuperUser())
{
$view->invalidHostMessage = $warningStart . ' '
. Piwik_Translate('CoreHome_InjectedHostSuperUserWarning', array(
"<a href=\"$changeTrustedHostsUrl\">",
$invalidHost,
'</a>',
"<a href=\"$validUrl\">",
$validHost,
'</a>'
));
}
else
{
$view->invalidHostMessage = $warningStart . ' '
. Piwik_Translate('CoreHome_InjectedHostNonSuperUserWarning', array(
"<a href=\"$validUrl\">",
'</a>',
$mailLinkStart,
'</a>'
));
}
$view->invalidHost = $invalidHost; // for UserSettings warning
$view->invalidHostMailLinkStart = $mailLinkStart;
}
* Sets general period variables (available periods, current period, period labels) used by templates
*
* @param Piwik_View $view
* @throws Exception
public static function setPeriodVariablesView($view)
if(isset($view->period))
{
return;
}
$currentPeriod = Piwik_Common::getRequestVar('period');
$view->displayUniqueVisitors = Piwik::isUniqueVisitorsEnabled($currentPeriod);
$availablePeriods = array('day', 'week', 'month', 'year', 'range');
if(!in_array($currentPeriod,$availablePeriods))
{
throw new Exception("Period must be one of: ".implode(",",$availablePeriods));
}
$periodNames = array(
'day' => array('singular' => Piwik_Translate('CoreHome_PeriodDay'), 'plural' => Piwik_Translate('CoreHome_PeriodDays')),
'week' => array('singular' => Piwik_Translate('CoreHome_PeriodWeek'), 'plural' => Piwik_Translate('CoreHome_PeriodWeeks')),
'month' => array('singular' => Piwik_Translate('CoreHome_PeriodMonth'), 'plural' => Piwik_Translate('CoreHome_PeriodMonths')),
'year' => array('singular' => Piwik_Translate('CoreHome_PeriodYear'), 'plural' => Piwik_Translate('CoreHome_PeriodYears')),
'range' => array('singular' => Piwik_Translate('General_DateRangeInPeriodList'), 'plural' => Piwik_Translate('General_DateRangeInPeriodList') ),
mattpiwik
a validé
$found = array_search($currentPeriod,$availablePeriods);
mattpiwik
a validé
if($found !== false)
{
unset($availablePeriods[$found]);
mattpiwik
a validé
}
$view->period = $currentPeriod;
$view->otherPeriods = $availablePeriods;
$view->periodsNames = $periodNames;
mattpiwik
a validé
}
/**
* Set metrics variables (displayed metrics, available metrics) used by template
* Handles the server-side of the metrics picker
*
* @param Piwik_View|Piwik_ViewDataTable $view
* @param string $defaultMetricDay name of the default metric for period=day
* @param string $defaultMetric name of the default metric for other periods
* @param array $metricsForDay metrics that are only available for period=day
* @param array $metricsForAllPeriods metrics that are available for all periods
* @param bool $labelDisplayed add 'label' to columns to display?
* @return void
*/
protected function setMetricsVariablesView(Piwik_ViewDataTable $view, $defaultMetricDay='nb_uniq_visitors',
$defaultMetric='nb_visits', $metricsForDay=array('nb_uniq_visitors'),
$metricsForAllPeriods=array('nb_visits', 'nb_actions'), $labelDisplayed=true)
{
// columns is set in the request if metrics picker has been used
$columns = Piwik_Common::getRequestVar('columns', false);
if ($columns !== false)
{
$columns = Piwik::getArrayFromApiParameter($columns);
$firstColumn = $columns[0];
}
else
{
// default columns
$firstColumn = isset($view->period) && $view->period == 'day' ? $defaultMetricDay : $defaultMetric;
$columns = array($firstColumn);
}
// displayed columns
if ($labelDisplayed
&& !($view instanceof Piwik_ViewDataTable_GenerateGraphData))
{
array_unshift($columns, 'label');
}
$view->setColumnsToDisplay($columns);
// Continue only for graphs
if(!($view instanceof Piwik_ViewDataTable_GenerateGraphData))
{
return;
}
// do not sort if sorted column was initially "label" or eg. it would make "Visits by Server time" not pretty
if($view->getSortedColumn() != 'label')
{
$view->setSortedColumn($firstColumn);
}
// selectable columns
if (isset($view->period) && $view->period == 'day')
{
$selectableColumns = array_merge($metricsForDay, $metricsForAllPeriods);
}
else
{
$selectableColumns = $metricsForAllPeriods;
}
$view->setSelectableColumns($selectableColumns);
}
/**
* Helper method used to redirect the current http request to another module/action
* If specified, will also redirect to a given website, period and /or date
* @param string $moduleToRedirect Module, eg. "MultiSites"
* @param string $actionToRedirect Action, eg. "index"
* @param string $websiteId Website ID, eg. 1
* @param string $defaultPeriod Default period, eg. "day"
* @param string $defaultDate Default date, eg. "today"
* @param array $parameters Parameters to append to url
function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId = null, $defaultPeriod = null, $defaultDate = null, $parameters = array())
mattpiwik
a validé
{
if(is_null($websiteId))
{
$websiteId = $this->getDefaultWebsiteId();
}
if(is_null($defaultDate))
{
$defaultDate = $this->getDefaultDate();
}
if(is_null($defaultPeriod))
{
$defaultPeriod = $this->getDefaultPeriod();
}
$parametersString = '';
if(!empty($parameters))
{
$parametersString = '&' . Piwik_Url::getQueryStringFromParameters($parameters);
}
$url = "Location: index.php?module=".$moduleToRedirect
."&action=".$actionToRedirect
."&idSite=".$websiteId
."&period=".$defaultPeriod
Piwik_ExitWithMessage("Error: no website was found in this Piwik installation.
<br />Check the table '". Piwik_Common::prefixTable('site') ."' in your database, it should contain your Piwik websites.", false, true);
}
$currentLogin = Piwik::getCurrentUserLogin();
if(!empty($currentLogin)
&& $currentLogin != 'anonymous')
{
$errorMessage = sprintf(Piwik_Translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:".Piwik::getSuperUserEmail()."?subject=Access to Piwik for user $currentLogin'>", "</a>");
$errorMessage .= "<br /><br /> <b><a href='index.php?module=". Zend_Registry::get('auth')->getName() ."&action=logout'>› ". Piwik_Translate('General_Logout'). "</a></b><br />";
Piwik_ExitWithMessage($errorMessage, false, true);
}
robocoder
a validé
Piwik_FrontController::getInstance()->dispatch(Piwik::getLoginPluginName(), false);
* Returns default website that Piwik should load
*
* @return Piwik_Site
*/
protected function getDefaultWebsiteId()
{
$defaultWebsiteId = false;
// User preference: default website ID to load
$defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT);
if(is_numeric($defaultReport))
{
$defaultWebsiteId = $defaultReport;
}
Piwik_PostEvent( 'Controller.getDefaultWebsiteId', $defaultWebsiteId );
if($defaultWebsiteId)
{
return $defaultWebsiteId;
}
$sitesId = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess();
mattpiwik
a validé
if(!empty($sitesId))
{
mattpiwik
a validé
}
*
* @return string today, 2010-01-01, etc.
// NOTE: a change in this function might mean a change in plugins/UsersManager/templates/userSettings.js as well
$userSettingsDate = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE);
if($userSettingsDate === false)
{
return Piwik_Config::getInstance()->General['default_day'];
}
if($userSettingsDate == 'yesterday')
{
return $userSettingsDate;
}
if(strpos($userSettingsDate, 'last') === 0
|| strpos($userSettingsDate, 'previous') === 0)
return 'today';
* Returns default date for Piwik reports
*
* @return string today, 2010-01-01, etc.
$userSettingsDate = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT_DATE);
if($userSettingsDate === false)
{
return Piwik_Config::getInstance()->General['default_period'];
}
if(in_array($userSettingsDate, array('today','yesterday')))
{
return 'day';
}
if(strpos($userSettingsDate, 'last') === 0
|| strpos($userSettingsDate, 'previous') === 0)
return $userSettingsDate;
mattpiwik
a validé
}
* Checks that the specified token matches the current logged in user token.
* Note: this protection against CSRF should be limited to controller
* actions that are either invoked via AJAX or redirect to a page
* within the site. The token should never appear in the browser's
* address bar.
*
* @throws Piwik_Access_NoAccessException if token doesn't match
* @return void
*/
protected function checkTokenInUrl()
{
if(Piwik_Common::getRequestVar('token_auth', false) != Piwik::getCurrentUserTokenAuth()) {
throw new Piwik_Access_NoAccessException(Piwik_TranslateException('General_ExceptionInvalidToken'));
/**
* Returns pretty date for use in period selector widget.
*
* @param Piwik_Period $period
* @return string
*/
public static function getCalendarPrettyDate($period)
{
if ($period instanceof Piwik_Period_Month) // show month name when period is for a month
{
return $period->getLocalizedLongString();
}
else
{
return $period->getPrettyString();
}
}