Piwik\
Main piwik helper class.
Contains helper methods for a variety of common tasks. Plugin developers are encouraged to reuse these methods as much as possible.
The class defines the following methods:
getCurrentUserEmail() — Returns the current user's email address.getCurrentUserLastSeen() — Returns the current user's Last Seen.getCurrentUserLogin() — Returns the current user's username.getCurrentUserTokenAuth() — Returns the current user's token auth.hasUserSuperUserAccessOrIsTheUser() — Returns true if the current user is either the Super User or the user specified by $theUser.checkUserHasSuperUserAccessOrIsTheUser() — Check that the current user is either the specified user or the superuser.hasTheUserSuperUserAccess() — Check whether the given user has superuser access.hasUserSuperUserAccess() — Returns true if the current user has Super User access.isUserIsAnonymous() — Returns true if the current user is the special anonymous user or not.checkUserIsNotAnonymous() — Checks that the user is not the anonymous user.checkUserHasSuperUserAccess() — Check that the current user has superuser access.isUserHasAdminAccess() — Returns true if the user has admin access to the requested sites, false if otherwise.checkUserHasAdminAccess() — Checks that the current user has admin access to the requested list of sites.isUserHasSomeAdminAccess() — Returns true if the current user has admin access to at least one site.checkUserHasSomeWriteAccess() — Checks that the current user has write access to at least one site.isUserHasSomeWriteAccess() — Returns true if the current user has write access to at least one site.isUserHasCapability() — Returns true if the current user has the given capability for the given sites.checkUserHasSomeAdminAccess() — Checks that the current user has admin access to at least one site.isUserHasViewAccess() — Returns true if the user has view access to the requested list of sites.isUserHasWriteAccess() — Returns true if the user has write access to the requested list of sites.checkUserHasViewAccess() — Checks that the current user has view access to the requested list of sitescheckUserHasWriteAccess() — Checks that the current user has write access to the requested list of sitesisUserHasSomeViewAccess() — Returns true if the current user has view access to at least one site.checkUserHasSomeViewAccess() — Checks that the current user has view access to at least one site.getLoginPluginName() — Returns the name of the Login plugin currently being used.redirectToModule() — Redirects the current request to a new module and action.isValidEmailString() — Returns true if supplied the email address is a valid.postEvent() — Post an event to Matomo (formerly Piwik)'s event dispatcher which will execute the event's observers.addAction() — Register an observer to an event.translate() — Returns an internationalized string using a translation token.getPeriod() — Returns the period provided in the current request.getDate() — Returns the date provided in the current request.getCurrentUserEmail()Returns the current user's email address.
string value.getCurrentUserLastSeen()Returns the current user's Last Seen.
string value.getCurrentUserLogin()Returns the current user's username.
string value.getCurrentUserTokenAuth()Returns the current user's token auth.
string value.hasUserSuperUserAccessOrIsTheUser()Returns true if the current user is either the Super User or the user specified by
$theUser.
$theUser (string) —
A username.bool value.checkUserHasSuperUserAccessOrIsTheUser()Check that the current user is either the specified user or the superuser.
$theUser (string) —
A username.Piwik\NoAccessException — If the user is neither the Super User nor the user $theUser.hasTheUserSuperUserAccess()Check whether the given user has superuser access.
$theUser (string) —
A username.bool value.hasUserSuperUserAccess()Returns true if the current user has Super User access.
bool value.isUserIsAnonymous()Returns true if the current user is the special anonymous user or not.
bool value.checkUserIsNotAnonymous()Checks that the user is not the anonymous user.
Piwik\NoAccessException — if the current user is the anonymous user.checkUserHasSuperUserAccess()Check that the current user has superuser access.
Exception — if the current user is not the superuser.isUserHasAdminAccess()Returns true if the user has admin access to the requested sites, false if otherwise.
$idSites (int|array) —
The list of site IDs to check access for.bool value.checkUserHasAdminAccess()Checks that the current user has admin access to the requested list of sites.
$idSites (int|array) —
One or more site IDs to check access for.Exception — If user doesn't have admin access.isUserHasSomeAdminAccess()Returns true if the current user has admin access to at least one site.
bool value.checkUserHasSomeWriteAccess()Checks that the current user has write access to at least one site.
Exception — if user doesn't have write access to any site.isUserHasSomeWriteAccess()Returns true if the current user has write access to at least one site.
bool value.isUserHasCapability()Returns true if the current user has the given capability for the given sites.
It accepts the following parameter(s):
$idSites
$capability
It returns a bool value.
checkUserHasSomeAdminAccess()Checks that the current user has admin access to at least one site.
Exception — if user doesn't have admin access to any site.isUserHasViewAccess()Returns true if the user has view access to the requested list of sites.
$idSites (int|array) —
One or more site IDs to check access for.bool value.isUserHasWriteAccess()Returns true if the user has write access to the requested list of sites.
$idSites (int|array) —
One or more site IDs to check access for.bool value.checkUserHasViewAccess()Checks that the current user has view access to the requested list of sites
$idSites (int|array|string) —
The list of site IDs to check access for.Exception — if the current user does not have view access to every site in the list.checkUserHasWriteAccess()Checks that the current user has write access to the requested list of sites
$idSites (int|array) —
The list of site IDs to check access for.Exception — if the current user does not have write access to every site in the list.isUserHasSomeViewAccess()Returns true if the current user has view access to at least one site.
bool value.checkUserHasSomeViewAccess()Checks that the current user has view access to at least one site.
Exception — if user doesn't have view access to any site.getLoginPluginName()Returns the name of the Login plugin currently being used.
Must be used since it is not allowed to hardcode 'Login' in URLs in case another Login plugin is being used.
string value.redirectToModule()Redirects the current request to a new module and action.
$newModule (string) —
The target module, eg, 'UserCountry'.$newAction (string) —
The target controller action, eg, 'index'.$parameters (array) —
The query parameter values to modify before redirecting.isValidEmailString()Returns true if supplied the email address is a valid.
It accepts the following parameter(s):
$emailAddress (string) —It returns a bool value.
postEvent()Post an event to Matomo's event dispatcher which will execute the event's observers.
$eventName (string) —
The event name.$params (array) —
The parameter array to forward to observer callbacks.$pending (bool) —
If true, plugins that are loaded after this event is fired will have their observers for this event executed.$plugins (array|null) —
The list of plugins to execute observers for. If null, all plugin observers will be executed.addAction()Register an observer to an event.
Note: Observers should normally be defined in plugin objects. It is unlikely that you will need to use this function.
$eventName (string) —
The event name.$function (callable|array) —
The observer.translate()Returns an internationalized string using a translation token. If a translation cannot be found for the token, the token is returned.
It accepts the following parameter(s):
$translationId (string) —
Translation ID, eg, 'General_Date'.$args (array|string|int) —
sprintf arguments to be applied to the internationalized string.$language (string|null) —
Optionally force the language.Returns: string —
The translated string or $translationId.
getPeriod()Returns the period provided in the current request.
If no $default is provided, this method will throw an Exception if period can't be found in the request
$default (string|null) —
default value to usestring value.getDate()Returns the date provided in the current request.
If no $default is provided, this method will throw an Exception if date can't be found in the request
$default (string|null) —
default value to usestring value.