本文整理汇总了PHP中Piwik\Common::getBrowserLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP Common::getBrowserLanguage方法的具体用法?PHP Common::getBrowserLanguage怎么用?PHP Common::getBrowserLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Common
的用法示例。
在下文中一共展示了Common::getBrowserLanguage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLocation
/**
* Guesses a visitor's location using a visitor's browser language.
*
* @param array $info Contains 'ip' & 'lang' keys.
* @return array Contains the guessed country code mapped to LocationProvider::COUNTRY_CODE_KEY.
*/
public function getLocation($info)
{
$enableLanguageToCountryGuess = Config::getInstance()->Tracker['enable_language_to_country_guess'];
if (empty($info['lang'])) {
$info['lang'] = Common::getBrowserLanguage();
}
$country = Common::getCountry($info['lang'], $enableLanguageToCountryGuess, $info['ip']);
$location = array(parent::COUNTRY_CODE_KEY => $country);
$this->completeLocationResult($location);
return $location;
}
示例2: getBrowserLanguage
/**
* Returns the language the visitor is viewing.
*
* @return string browser language code, eg. "en-gb,en;q=0.5"
*/
public function getBrowserLanguage()
{
return Common::getRequestVar('lang', Common::getBrowserLanguage(), 'string', $this->params);
}
示例3: getAllProviderInfo
/**
* Returns an array mapping provider IDs w/ information about the provider,
* for each location provider.
*
* The following information is provided for each provider:
* 'id' - The provider's unique string ID.
* 'title' - The provider's title.
* 'description' - A description of how the location provider works.
* 'status' - Either self::NOT_INSTALLED, self::INSTALLED or self::BROKEN.
* 'statusMessage' - If the status is self::BROKEN, then the message describes why.
* 'location' - A pretty formatted location of the current IP address
* (IP::getIpFromHeader()).
*
* An example result:
* array(
* 'geoip_php' => array('id' => 'geoip_php',
* 'title' => '...',
* 'desc' => '...',
* 'status' => GeoIp::BROKEN,
* 'statusMessage' => '...',
* 'location' => '...')
* 'geoip_serverbased' => array(...)
* )
*
* @param string $newline What to separate lines with in the pretty locations.
* @param bool $includeExtra Whether to include ISP/Org info in formatted location.
* @return array
*/
public static function getAllProviderInfo($newline = "\n", $includeExtra = false)
{
$allInfo = array();
foreach (self::getAllProviders() as $provider) {
$info = $provider->getInfo();
$status = self::INSTALLED;
$location = false;
$statusMessage = false;
$availableOrMessage = $provider->isAvailable();
if ($availableOrMessage !== true) {
$status = self::NOT_INSTALLED;
if (is_string($availableOrMessage)) {
$statusMessage = $availableOrMessage;
}
} else {
$workingOrError = $provider->isWorking();
if ($workingOrError === true) {
$locInfo = array('ip' => IP::getIpFromHeader(), 'lang' => Common::getBrowserLanguage(), 'disable_fallbacks' => true);
$location = $provider->getLocation($locInfo);
$location = self::prettyFormatLocation($location, $newline, $includeExtra);
} else {
$status = self::BROKEN;
$statusMessage = $workingOrError;
}
}
$info['status'] = $status;
$info['statusMessage'] = $statusMessage;
$info['location'] = $location;
$allInfo[$info['order']] = $info;
}
ksort($allInfo);
$result = array();
foreach ($allInfo as $info) {
$result[$info['id']] = $info;
}
return $result;
}
示例4: testGetBrowserLanguage
/**
* @dataProvider getBrowserLanguageData
* @group Core
*/
public function testGetBrowserLanguage($useragent, $browserLanguage)
{
$res = Common::getBrowserLanguage($useragent);
$this->assertEquals($browserLanguage, $res);
}
示例5: getLanguageCodeForCurrentUser
/**
* @return string Two letters language code, eg. "fr"
*/
public static function getLanguageCodeForCurrentUser()
{
$languageCode = self::getLanguageFromPreferences();
if (!API::getInstance()->isLanguageAvailable($languageCode)) {
$languageCode = Common::extractLanguageCodeFromBrowserLanguage(Common::getBrowserLanguage(), API::getInstance()->getAvailableLanguages());
}
if (!API::getInstance()->isLanguageAvailable($languageCode)) {
$languageCode = Translate::getLanguageDefault();
}
return $languageCode;
}
示例6: getLocationUsingProvider
/**
* Echo's a pretty formatted location using a specific LocationProvider.
*
* Input:
* The 'id' query parameter must be set to the ID of the LocationProvider to use.
*
* Output:
* The pretty formatted location that was obtained. Will be HTML.
*/
public function getLocationUsingProvider()
{
$providerId = Common::getRequestVar('id');
$provider = LocationProvider::getProviderById($providerId);
if (empty($provider)) {
throw new Exception("Invalid provider ID: '{$providerId}'.");
}
$location = $provider->getLocation(array('ip' => IP::getIpFromHeader(), 'lang' => Common::getBrowserLanguage(), 'disable_fallbacks' => true));
$location = LocationProvider::prettyFormatLocation($location, $newline = '<br/>', $includeExtra = true);
return $location;
}