PHP Класс Piwik\Common

This is the only non-Tracker class loaded by the **\/piwik.php** file.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$isCliMode

Открытые методы

Метод Описание
convertUserIdToVisitorIdBin ( $userId ) : string Converts a User ID string to the Visitor ID Binary representation.
convertVisitorIdToBin ( string $id ) : string This function will convert the input string to the binary representation of the ID but it will throw an Exception if the specified input ID is not correct
destroy ( mixed &$var ) Marks an orphaned object for garbage collection.
extractCountryCodeFromBrowserLanguage ( string $browserLanguage, array $validCountries, boolean $enableLanguageToCountryGuess ) : array Returns list of valid country codes
extractLanguageAndRegionCodeFromBrowserLanguage ( string $browserLanguage, array $validLanguages = [] ) : string Returns the language and region string, based only on the Browser 'accepted language' information.
extractLanguageCodeFromBrowserLanguage ( string $browserLanguage, array $validLanguages = [] ) : string Returns the language and region string, based only on the Browser 'accepted language' information.
forceDotAsSeparatorForDecimalPoint ( float | string $value ) : string Force the separator for decimal point to be a dot. See https://github.com/piwik/piwik/issues/6435 If for instance a German locale is used it would be a comma otherwise.
generateUniqId ( ) : string Returns a 32 characters long uniq ID
getBrowserLanguage ( string | null $browserLang = null ) : string Returns the browser language code, eg. "en-gb,en;q=0.5"
getCampaignParameters ( ) : array Returns the list of Campaign parameter names that will be read to classify a visit as coming from a Campaign
getClassLineage ( string $class ) : string[] Returns the list of parent classes for the given class.
getContinent ( string $country ) : string Returns the continent of a given country
getContinentsList ( ) : array Returns list of continent codes
getCountriesList ( boolean $includeInternalCodes = false ) : array Returns list of valid country codes
getCountry ( string $lang, boolean $enableLanguageToCountryGuess, string $ip ) : string Returns the visitor country based on the Browser 'accepted language' information, but provides a hook for geolocation via IP address.
getCurrentLocationProviderId ( ) Returns the ID of the current LocationProvider (see UserCountry plugin code) from the Tracker cache.
getLanguageToCountryList ( ) : array Returns a list of language to country mappings.
getLanguagesList ( ) : array Returns the list of valid language codes.
getLastJsonError ( ) : string Returns a human readable error message in case an error occcurred during the last json encode/decode.
getProviderNames ( ) : array Returns list of provider names
getRandomString ( integer $length = 16, string $alphabet = "abcdefghijklmnoprstuvwxyz0123456789" ) : string Generate random string.
getRequestVar ( string $varName, string | null $varDefault = null, string | null $varType = null, array | null $requestArrayToUse = null ) : mixed Gets a sanitized request parameter by name from the $_GET and $_POST superglobals.
getSqlStringFieldsArray ( array | string $fields ) : string Returns a string with a comma separated list of placeholders for use in an SQL query. Used mainly to fill the `IN (.
hasJsonErrorOccurred ( ) : boolean Detects whether an error occurred during the last json encode/decode.
hash ( string $str, boolean $raw_output = false ) : string Configurable hash() algorithm (defaults to md5)
hashStringToInt ( string $string ) : integer Hashes a string into an integer which should be very low collision risks
hex2bin ( string $str ) : string Convert hexadecimal representation into binary data.
isActionsPluginEnabled ( )
isGoalPluginEnabled ( ) * Tracker
isPhpCgiType ( ) : boolean Returns true if PHP is executed as CGI type.
isPhpCliMode ( ) : boolean Returns true if PHP was invoked from command-line interface (shell)
isRunningConsoleCommand ( ) : boolean Returns true if the current request is a console command, eg.
isXmlHttpRequest ( ) : boolean Returns true if the request is an AJAX request.
json_decode ( string $json, boolean $assoc = false ) : mixed JSON decode wrapper - missing or broken in some php 5.x versions
json_encode ( mixed $value ) : string JSON encode wrapper - missing or broken in some php 5.x versions
mb_strlen ( string $string ) : integer Multi-byte strlen() - works with UTF-8
mb_strtolower ( string $string ) : string Multi-byte strtolower() - works with UTF-8.
mb_substr ( string $string, integer $start ) : string Multi-byte substr() - works with UTF-8.
prefixTable ( string $table ) : string Returns a prefixed table name.
prefixTables ( ) : array Returns an array containing the prefixed table names of every passed argument.
printDebug ( $info = '' )
sanitizeInputValue ( string $value ) : string Sanitize a single input value and removes line breaks, tabs and null characters.
sanitizeInputValues ( mixed $value, boolean $alreadyStripslashed = false ) : mixed Sanitizes a string to help avoid XSS vulnerabilities.
sanitizeLineBreaks ( string $value ) : string
sanitizeNullBytes ( string $value ) : string
sendHeader ( string $header, boolean $replace = true ) Sets outgoing header.
sendResponseCode ( integer $code ) Sends the given response code if supported.
stringEndsWith ( $haystack, $needle )
unprefixTable ( string $table ) : string Removes the prefix from a table name and returns the result.
unsanitizeInputValue ( string $value ) : string Unsanitizes a single input value and returns the result.
unsanitizeInputValues ( string | array $value ) : string | array Unsanitizes one or more values and returns the result.

Защищенные методы

Метод Описание
checkValidLanguagesIsSet ( $validLanguages ) : array

Приватные методы

Метод Описание
sanitizeString ( $value ) : string Sanitize a single input value

Описание методов

checkValidLanguagesIsSet() защищенный статический Метод

protected static checkValidLanguagesIsSet ( $validLanguages ) : array
$validLanguages
Результат array

convertUserIdToVisitorIdBin() публичный статический Метод

Converts a User ID string to the Visitor ID Binary representation.
public static convertUserIdToVisitorIdBin ( $userId ) : string
$userId
Результат string

convertVisitorIdToBin() публичный статический Метод

This is used when building segments containing visitorId which could be an invalid string therefore throwing Unexpected PHP error [pack(): Type H: illegal hex digit i] severity [E_WARNING] It would be simply to silent fail the pack() call above but in all other cases, we don't expect an error, so better be safe and get the php error when something unexpected is happening
public static convertVisitorIdToBin ( string $id ) : string
$id string
Результат string binary string

destroy() публичный статический Метод

For more information: {@link https://github.com/piwik/piwik/issues/374}
public static destroy ( mixed &$var )
$var mixed The object to destroy.

extractCountryCodeFromBrowserLanguage() публичный статический Метод

Returns list of valid country codes
public static extractCountryCodeFromBrowserLanguage ( string $browserLanguage, array $validCountries, boolean $enableLanguageToCountryGuess ) : array
$browserLanguage string
$validCountries array Array of valid countries
$enableLanguageToCountryGuess boolean (if true, will guess country based on language that lacks region information)
Результат array Array of 2 letter ISO codes

extractLanguageAndRegionCodeFromBrowserLanguage() публичный статический Метод

* The language tag is defined by ISO 639-1 * The region tag is defined by ISO 3166-1
public static extractLanguageAndRegionCodeFromBrowserLanguage ( string $browserLanguage, array $validLanguages = [] ) : string
$browserLanguage string Browser's accepted langauge header
$validLanguages array array of valid language codes. Note that if the array includes "fr" then it will consider all regional variants of this language valid, such as "fr-ca" etc.
Результат string 2 letter ISO 639 code 'es' (Spanish) or if found, includes the region as well: 'es-ar'

extractLanguageCodeFromBrowserLanguage() публичный статический Метод

* The language tag is defined by ISO 639-1
public static extractLanguageCodeFromBrowserLanguage ( string $browserLanguage, array $validLanguages = [] ) : string
$browserLanguage string Browser's accepted langauge header
$validLanguages array array of valid language codes
Результат string 2 letter ISO 639 code 'es' (Spanish)

forceDotAsSeparatorForDecimalPoint() публичный статический Метод

Force the separator for decimal point to be a dot. See https://github.com/piwik/piwik/issues/6435 If for instance a German locale is used it would be a comma otherwise.
public static forceDotAsSeparatorForDecimalPoint ( float | string $value ) : string
$value float | string
Результат string

generateUniqId() публичный статический Метод

Returns a 32 characters long uniq ID
public static generateUniqId ( ) : string
Результат string 32 chars

getBrowserLanguage() публичный статический Метод

Returns the browser language code, eg. "en-gb,en;q=0.5"
public static getBrowserLanguage ( string | null $browserLang = null ) : string
$browserLang string | null Optional browser language, otherwise taken from the request header
Результат string

getCampaignParameters() публичный статический Метод

Returns the list of Campaign parameter names that will be read to classify a visit as coming from a Campaign
public static getCampaignParameters ( ) : array
Результат array array( 0 => array( ... ) // campaign names parameters 1 => array( ... ) // campaign keyword parameters );

getClassLineage() публичный статический Метод

Returns the list of parent classes for the given class.
public static getClassLineage ( string $class ) : string[]
$class string A class name.
Результат string[] The list of parent classes in order from highest ancestor to the descended class.

getContinent() публичный статический Метод

Returns the continent of a given country
public static getContinent ( string $country ) : string
$country string 2 letters iso code
Результат string Continent (3 letters code : afr, asi, eur, amn, ams, oce)

getContinentsList() публичный статический Метод

Returns list of continent codes
См. также: Piwik\Intl\Data\Provider\RegionDataProvider::getContinentList()
Устаревший: Use Piwik\Intl\Data\Provider\RegionDataProvider instead.
public static getContinentsList ( ) : array
Результат array Array of 3 letter continent codes

getCountriesList() публичный статический Метод

Returns list of valid country codes
См. также: Piwik\Intl\Data\Provider\RegionDataProvider::getCountryList()
Устаревший: Use Piwik\Intl\Data\Provider\RegionDataProvider instead.
public static getCountriesList ( boolean $includeInternalCodes = false ) : array
$includeInternalCodes boolean
Результат array Array of (2 letter ISO codes => 3 letter continent code)

getCountry() публичный статический Метод

Returns the visitor country based on the Browser 'accepted language' information, but provides a hook for geolocation via IP address.
public static getCountry ( string $lang, boolean $enableLanguageToCountryGuess, string $ip ) : string
$lang string browser lang
$enableLanguageToCountryGuess boolean If set to true, some assumption will be made and detection guessed more often, but accuracy could be affected
$ip string
Результат string 2 letter ISO code

getCurrentLocationProviderId() публичный статический Метод

Returns the ID of the current LocationProvider (see UserCountry plugin code) from the Tracker cache.
public static getCurrentLocationProviderId ( )

getLanguageToCountryList() публичный статический Метод

См. также: Piwik\Intl\Data\Provider\LanguageDataProvider::getLanguageToCountryList()
Устаревший: Use Piwik\Intl\Data\Provider\LanguageDataProvider instead.
public static getLanguageToCountryList ( ) : array
Результат array Array of two letter ISO language codes mapped with two letter ISO country codes: `array('fr' => 'fr') // French => France`

getLanguagesList() публичный статический Метод

См. также: Piwik\Intl\Data\Provider\LanguageDataProvider::getLanguageList()
Устаревший: Use Piwik\Intl\Data\Provider\LanguageDataProvider instead.
public static getLanguagesList ( ) : array
Результат array Array of two letter ISO codes mapped with their associated language names (in English). E.g. `array('en' => 'English', 'ja' => 'Japanese')`.

getLastJsonError() публичный статический Метод

Returns an empty string in case there was no error.
public static getLastJsonError ( ) : string
Результат string

getProviderNames() публичный статический Метод

Returns list of provider names
public static getProviderNames ( ) : array
Результат array Array of ( dnsName => providerName )

getRandomString() публичный статический Метод

Do not use for security related purposes (the string is not truly random).
public static getRandomString ( integer $length = 16, string $alphabet = "abcdefghijklmnoprstuvwxyz0123456789" ) : string
$length integer string length
$alphabet string characters allowed in random string
Результат string random string with given length

getRequestVar() публичный статический Метод

Use this function to get request parameter values. **_NEVER use $_GET and $_POST directly._** If the variable cannot be found, and a default value was not provided, an exception is raised. _See {@link sanitizeInputValues()} to learn more about sanitization._
public static getRequestVar ( string $varName, string | null $varDefault = null, string | null $varType = null, array | null $requestArrayToUse = null ) : mixed
$varName string Name of the request parameter to get. By default, we look in `$_GET[$varName]` and `$_POST[$varName]` for the value.
$varDefault string | null The value to return if the request parameter cannot be found or has an empty value.
$varType string | null Expected type of the request variable. This parameters value must be one of the following: `'array'`, `'int'`, `'integer'`, `'string'`, `'json'`. If `'json'`, the string value will be `json_decode`-d and then sanitized.
$requestArrayToUse array | null The array to use instead of `$_GET` and `$_POST`.
Результат mixed The sanitized request parameter.

getSqlStringFieldsArray() публичный статический Метод

..)` part of a query.
public static getSqlStringFieldsArray ( array | string $fields ) : string
$fields array | string The names of the mysql table fields to bind, e.g. `array(fieldName1, fieldName2, fieldName3)`. _Note: The content of the array isn't important, just its length._
Результат string The placeholder string, e.g. `"?, ?, ?"`.

hasJsonErrorOccurred() публичный статический Метод

Detects whether an error occurred during the last json encode/decode.
public static hasJsonErrorOccurred ( ) : boolean
Результат boolean

hash() публичный статический Метод

Configurable hash() algorithm (defaults to md5)
public static hash ( string $str, boolean $raw_output = false ) : string
$str string String to be hashed
$raw_output boolean
Результат string Hash string

hashStringToInt() публичный статический Метод

Hashes a string into an integer which should be very low collision risks
public static hashStringToInt ( string $string ) : integer
$string string String to hash
Результат integer Resulting int hash

hex2bin() публичный статический Метод

!! Will emit warning if input string is not hex!!
См. также: http://php.net/bin2hex
public static hex2bin ( string $str ) : string
$str string Hexadecimal representation
Результат string

isActionsPluginEnabled() публичный статический Метод

public static isActionsPluginEnabled ( )

isGoalPluginEnabled() публичный статический Метод

* Tracker
public static isGoalPluginEnabled ( )

isPhpCgiType() публичный статический Метод

Returns true if PHP is executed as CGI type.
public static isPhpCgiType ( ) : boolean
Результат boolean true if PHP invoked as a CGI

isPhpCliMode() публичный статический Метод

Returns true if PHP was invoked from command-line interface (shell)
public static isPhpCliMode ( ) : boolean
Результат boolean true if PHP invoked as a CGI or from CLI

isRunningConsoleCommand() публичный статический Метод

./console xx:yy or php console xx:yy
public static isRunningConsoleCommand ( ) : boolean
Результат boolean

isXmlHttpRequest() публичный статический Метод

Returns true if the request is an AJAX request.
public static isXmlHttpRequest ( ) : boolean
Результат boolean

json_decode() публичный статический Метод

JSON decode wrapper - missing or broken in some php 5.x versions
Устаревший:
public static json_decode ( string $json, boolean $assoc = false ) : mixed
$json string
$assoc boolean
Результат mixed

json_encode() публичный статический Метод

JSON encode wrapper - missing or broken in some php 5.x versions
Устаревший:
public static json_encode ( mixed $value ) : string
$value mixed
Результат string

mb_strlen() публичный статический Метод

Calls mb_substr if available and falls back to substr if not.
public static mb_strlen ( string $string ) : integer
$string string
Результат integer

mb_strtolower() публичный статический Метод

Calls mb_strtolower if available and falls back to strtolower if not.
public static mb_strtolower ( string $string ) : string
$string string
Результат string

mb_substr() публичный статический Метод

Calls mb_substr if available and falls back to substr if it's not.
public static mb_substr ( string $string, integer $start ) : string
$string string
$start integer
Результат string

prefixTable() публичный статический Метод

The table prefix is determined by the [database] tables_prefix INI config option.
public static prefixTable ( string $table ) : string
$table string The table name to prefix, ie "log_visit"
Результат string The prefixed name, ie "piwik-production_log_visit".

prefixTables() публичный статический Метод

Returns an array containing the prefixed table names of every passed argument.
public static prefixTables ( ) : array
Результат array The prefixed names in an array.

printDebug() публичный статический Метод

public static printDebug ( $info = '' )

sanitizeInputValue() публичный статический Метод

Sanitize a single input value and removes line breaks, tabs and null characters.
public static sanitizeInputValue ( string $value ) : string
$value string
Результат string sanitized input

sanitizeInputValues() публичный статический Метод

This function is automatically called when {@link getRequestVar()} is called, so you should not normally have to use it. This function should be used when outputting data that isn't escaped and was obtained from the user (for example when using the |raw twig filter on goal names). _NOTE: Sanitized input should not be used directly in an SQL query; SQL placeholders should still be used._ **Implementation Details** - htmlspecialchars is used to escape text. - Single quotes are not escaped so **Piwik's amazing community** will still be **Piwik's amazing community**. - Use of the magic_quotes setting will not break this method. - Boolean, numeric and null values are not modified.
public static sanitizeInputValues ( mixed $value, boolean $alreadyStripslashed = false ) : mixed
$value mixed The variable to be sanitized. If an array is supplied, the contents of the array will be sanitized recursively. The keys of the array will also be sanitized.
$alreadyStripslashed boolean Implementation detail, ignore.
Результат mixed The sanitized value.

sanitizeLineBreaks() публичный статический Метод

public static sanitizeLineBreaks ( string $value ) : string
$value string
Результат string Line breaks and line carriage removed

sanitizeNullBytes() публичный статический Метод

public static sanitizeNullBytes ( string $value ) : string
$value string
Результат string Null bytes removed

sendHeader() публичный статический Метод

Sets outgoing header.
public static sendHeader ( string $header, boolean $replace = true )
$header string The header.
$replace boolean Whether to replace existing or not.

sendResponseCode() публичный статический Метод

Sends the given response code if supported.
public static sendResponseCode ( integer $code )
$code integer Eg 204

stringEndsWith() публичный статический Метод

public static stringEndsWith ( $haystack, $needle )

unprefixTable() публичный статический Метод

The table prefix is determined by the [database] tables_prefix INI config option.
public static unprefixTable ( string $table ) : string
$table string The prefixed table name, eg "piwik-production_log_visit".
Результат string The unprefixed table name, eg "log_visit".

unsanitizeInputValue() публичный статический Метод

Unsanitizes a single input value and returns the result.
public static unsanitizeInputValue ( string $value ) : string
$value string
Результат string unsanitized input

unsanitizeInputValues() публичный статический Метод

This method should be used when you need to unescape data that was obtained from the user. Some data in Piwik is stored sanitized (such as site name). In this case you may have to use this method to unsanitize it in order to, for example, output it in JSON.
public static unsanitizeInputValues ( string | array $value ) : string | array
$value string | array The data to unsanitize. If an array is passed, the array is sanitized recursively. Key values are not unsanitized.
Результат string | array The unsanitized data.

Описание свойств

$isCliMode публичное статическое свойство

public static $isCliMode