Piwik
Piwik\
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.
Methods
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()— Returnstrueif 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()— Returnstrueif the user has admin access to the requested sites,falseif otherwise.checkUserHasAdminAccess()— Checks that the current user has admin access to the requested list of sites.isUserHasSomeAdminAccess()— Returnstrueif 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()— Returnstrueif the current user has write access to at least one site.isUserHasCapability()— Returnstrueif 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()— Returnstrueif the user has view access to the requested list of sites.isUserHasWriteAccess()— Returnstrueif 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()— Returnstrueif 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()— Returnstrueif 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.
Signature
- It returns a
stringvalue.
getCurrentUserLastSeen()
Returns the current user's Last Seen.
Signature
- It returns a
stringvalue.
getCurrentUserLogin()
Returns the current user's username.
Signature
- It returns a
stringvalue.
getCurrentUserTokenAuth()
Returns the current user's token auth.
Signature
- It returns a
stringvalue.
hasUserSuperUserAccessOrIsTheUser()
Returns true if the current user is either the Super User or the user specified by
$theUser.
Signature
- It accepts the following parameter(s):
$theUser(string) — A username.
- It returns a
boolvalue.
checkUserHasSuperUserAccessOrIsTheUser()
Check that the current user is either the specified user or the superuser.
Signature
- It accepts the following parameter(s):
$theUser(string) — A username.
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
Piwik\NoAccessException— If the user is neither the Super User nor the user$theUser.
hasTheUserSuperUserAccess()
Check whether the given user has superuser access.
Signature
- It accepts the following parameter(s):
$theUser(string) — A username.
- It returns a
boolvalue.
hasUserSuperUserAccess()
Returns true if the current user has Super User access.
Signature
- It returns a
boolvalue.
isUserIsAnonymous()
Returns true if the current user is the special anonymous user or not.
Signature
- It returns a
boolvalue.
checkUserIsNotAnonymous()
Checks that the user is not the anonymous user.
Signature
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
Piwik\NoAccessException— if the current user is the anonymous user.
checkUserHasSuperUserAccess()
Check that the current user has superuser access.
Signature
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
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.
Signature
- It accepts the following parameter(s):
$idSites(int|array) — The list of site IDs to check access for.
- It returns a
boolvalue.
checkUserHasAdminAccess()
Checks that the current user has admin access to the requested list of sites.
Signature
- It accepts the following parameter(s):
$idSites(int|array) — One or more site IDs to check access for.
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
Exception— If user doesn't have admin access.
isUserHasSomeAdminAccess()
Returns true if the current user has admin access to at least one site.
Signature
- It returns a
boolvalue.
checkUserHasSomeWriteAccess()
Checks that the current user has write access to at least one site.
Signature
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
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.
Signature
- It returns a
boolvalue.
isUserHasCapability()
Returns true if the current user has the given capability for the given sites.
Signature
It accepts the following parameter(s):
$idSites$capability
It returns a
boolvalue.
checkUserHasSomeAdminAccess()
Checks that the current user has admin access to at least one site.
Signature
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
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.
Signature
- It accepts the following parameter(s):
$idSites(int|array) — One or more site IDs to check access for.
- It returns a
boolvalue.
isUserHasWriteAccess()
Returns true if the user has write access to the requested list of sites.
Signature
- It accepts the following parameter(s):
$idSites(int|array) — One or more site IDs to check access for.
- It returns a
boolvalue.
checkUserHasViewAccess()
Checks that the current user has view access to the requested list of sites
Signature
- It accepts the following parameter(s):
$idSites(int|array|string) — The list of site IDs to check access for.
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
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
Signature
- It accepts the following parameter(s):
$idSites(int|array) — The list of site IDs to check access for.
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
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.
Signature
- It returns a
boolvalue.
checkUserHasSomeViewAccess()
Checks that the current user has view access to at least one site.
Signature
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
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.
Signature
- It returns a
stringvalue.
redirectToModule()
Redirects the current request to a new module and action.
Signature
- It accepts the following parameter(s):
$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.
- It does not return anything or a mixed result.
isValidEmailString()
Returns true if supplied the email address is a valid.
Signature
It accepts the following parameter(s):
$emailAddress(string) —
It returns a
boolvalue.
postEvent()
Post an event to Matomo's event dispatcher which will execute the event's observers.
Signature
- It accepts the following parameter(s):
$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.
- It does not return anything or a mixed result.
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.
Signature
- It accepts the following parameter(s):
$eventName(string) — The event name.$function(callable|array) — The observer.
- It does not return anything or a mixed result.
translate()
Returns an internationalized string using a translation token. If a translation cannot be found for the token, the token is returned.
Signature
It accepts the following parameter(s):
$translationId(string) — Translation ID, eg,'General_Date'.$args(array|string|int) —sprintfarguments 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
Signature
- It accepts the following parameter(s):
$default(string|null) — default value to use
- It returns a
stringvalue. - It throws one of the following exceptions:
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
Signature
- It accepts the following parameter(s):
$default(string|null) — default value to use
- It returns a
stringvalue. - It throws one of the following exceptions: