本文整理汇总了PHP中Piwik_Common::getCountriesList方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik_Common::getCountriesList方法的具体用法?PHP Piwik_Common::getCountriesList怎么用?PHP Piwik_Common::getCountriesList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik_Common
的用法示例。
在下文中一共展示了Piwik_Common::getCountriesList方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
Piwik::checkUserIsNotAnonymous();
$view = Piwik_View::factory('Settings');
$view->isSuperUser = Piwik::isUserIsSuperUser();
$mobileMessagingAPI = Piwik_MobileMessaging_API::getInstance();
$view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement();
$view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided();
$view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement;
$view->strHelpAddPhone = Piwik_Translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array(Piwik_Translate('UserSettings_SubmenuSettings'), Piwik_Translate('MobileMessaging_SettingsMenu')));
if ($view->credentialSupplied && $view->accountManagedByCurrentUser) {
$view->provider = $mobileMessagingAPI->getSMSProvider();
$view->creditLeft = $mobileMessagingAPI->getCreditLeft();
}
$view->smsProviders = Piwik_MobileMessaging_SMSProvider::$availableSMSProviders;
// construct the list of countries from the lang files
$countries = array();
foreach (Piwik_Common::getCountriesList() as $countryCode => $continentCode) {
if (isset(Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode])) {
$countries[$countryCode] = array('countryName' => Piwik_CountryTranslate($countryCode), 'countryCallingCode' => Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode]);
}
}
$view->countries = $countries;
$view->defaultCountry = Piwik_Common::getCountry(Piwik_LanguagesManager::getLanguageCodeForCurrentUser(), true, Piwik_IP::getIpFromHeader());
$view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers();
$this->setBasicVariablesView($view);
$view->menu = Piwik_GetAdminMenu();
echo $view->render();
}
示例2: logProviderInfo
/**
* Logs the provider in the log_visit table
*/
public function logProviderInfo($notification)
{
$visitorInfo =& $notification->getNotificationObject();
$ip = Piwik_IP::N2P($visitorInfo['location_ip']);
// In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking
if (substr($ip, -2, 2) == '.0') {
printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup...");
return;
}
$hostname = $this->getHost($ip);
$hostnameExtension = $this->getCleanHostname($hostname);
// add the provider value in the table log_visit
$visitorInfo['location_provider'] = $hostnameExtension;
$visitorInfo['location_provider'] = substr($visitorInfo['location_provider'], 0, 100);
// improve the country using the provider extension if valid
$hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.'));
if ($hostnameDomain == 'uk') {
$hostnameDomain = 'gb';
}
if (array_key_exists($hostnameDomain, Piwik_Common::getCountriesList())) {
$visitorInfo['location_country'] = $hostnameDomain;
}
}
示例3: logProviderInfo
/**
* Logs the provider in the log_visit table
*/
public function logProviderInfo($notification)
{
$visitorInfo =& $notification->getNotificationObject();
$hostname = $this->getHost($visitorInfo['location_ip']);
$hostnameExtension = $this->getCleanHostname($hostname);
// add the provider value in the table log_visit
$visitorInfo['location_provider'] = $hostnameExtension;
$visitorInfo['location_provider'] = substr($visitorInfo['location_provider'], 0, 100);
// improve the country using the provider extension if valid
$hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.'));
if($hostnameDomain == 'uk')
{
$hostnameDomain = 'gb';
}
if(array_key_exists($hostnameDomain, Piwik_Common::getCountriesList()))
{
$visitorInfo['location_country'] = $hostnameDomain;
}
}
示例4: test_extractCountryCodeFromBrowserLanguage
/**
* Data driven tests of extractCountryCodeFromBrowserLanguage
*/
public function test_extractCountryCodeFromBrowserLanguage()
{
$a1 = array(array("", array(), "xx"), array("", array("us" => 'amn'), "xx"), array("en", array("us" => 'amn'), "xx"), array("en-us", array("us" => 'amn'), "us"), array("en-ca", array("us" => 'amn'), "xx"), array("en-ca", array("us" => 'amn', "ca" => 'amn'), "ca"), array("fr-fr,fr-ca", array("us" => 'amn', "ca" => 'amn'), "ca"), array("fr-fr;q=1.0,fr-ca;q=0.9", array("us" => 'amn', "ca" => 'amn'), "ca"), array("fr-ca,fr;q=0.1", array("us" => 'amn', "ca" => 'amn'), "ca"), array("en-us,en;q=0.5", Piwik_Common::getCountriesList(), "us"), array("fr-ca,fr;q=0.1", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "ca"), array("fr-fr,fr-ca", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr"));
foreach ($a1 as $testdata) {
$this->assertEqual($testdata[2], Piwik_Common::extractCountryCodeFromBrowserLanguage($testdata[0], $testdata[1], true));
$this->assertEqual($testdata[2], Piwik_Common::extractCountryCodeFromBrowserLanguage($testdata[0], $testdata[1], false));
}
}
示例5: test_getTranslationsForLanguages
function test_getTranslationsForLanguages()
{
$allLanguages = Piwik_Common::getLanguagesList();
$allCountries = Piwik_Common::getCountriesList();
$englishStrings = Piwik_LanguagesManager_API::getInstance()->getTranslationsForLanguage('en');
$englishStringsWithParameters = array();
$expectedLanguageKeys = array();
foreach ($englishStrings as $englishString) {
$stringLabel = $englishString['label'];
$stringValue = $englishString['value'];
$count = $this->getCountParametersToReplace($stringValue);
if ($count > 0) {
$englishStringsWithParameters[$stringLabel] = $count;
}
$englishStringsIndexed[$stringLabel] = $stringValue;
$expectedLanguageKeys[] = $stringLabel;
}
// we also test that none of the language php files outputs any character on the screen (eg. space before the <?php)
$languages = Piwik_LanguagesManager_API::getInstance()->getAvailableLanguages();
foreach ($languages as $language) {
ob_start();
$writeCleanedFile = false;
$strings = Piwik_LanguagesManager_API::getInstance()->getTranslationsForLanguage($language);
$content = ob_get_flush();
$serializedStrings = serialize($strings);
$invalids = array("<script", 'document.', 'javascript:', 'src=', 'BACKGROUND=', 'onload=');
foreach ($invalids as $invalid) {
$this->assertTrue(stripos($serializedStrings, $invalid) === false, "{$language}: language file containing javascript");
}
$this->assertTrue(count($strings) > 100, "{$language}: expecting at least 100 translations in the language file");
$this->assertTrue(strlen($content) == 0, "{$language}: buffer was " . strlen($content) . " long but should be zero. Translation file for '{$language}' must be buggy.");
$cleanedStrings = array();
foreach ($strings as $string) {
$stringLabel = $string['label'];
$stringValue = $string['value'];
$plugin = substr($stringLabel, 0, strpos($stringLabel, '_'));
$plugins[$plugin] = true;
// Testing that the translated string is not empty => '',
if (empty($stringValue) || trim($stringValue) === '') {
$writeCleanedFile = true;
echo "{$language}: The string {$stringLabel} is empty in the translation file, removing the line. <br/>\n";
$cleanedStrings[$stringLabel] = false;
} elseif (!in_array($stringLabel, $expectedLanguageKeys) && !in_array($plugin, array('GeoIP', 'Forecast', 'EntryPage', 'UserLanguage'))) {
$writeCleanedFile = true;
echo "{$language}: The string {$stringLabel} was not found in the English language file, removing the line. <br/>\n";
$cleanedStrings[$stringLabel] = false;
} else {
// checking that translated strings have the same number of %s as the english source strings
if (isset($englishStringsWithParameters[$stringLabel])) {
$englishParametersCount = $englishStringsWithParameters[$stringLabel];
$countTranslation = $this->getCountParametersToReplace($stringValue);
if ($englishParametersCount != $countTranslation) {
// Write fixed file in given location
// Will trigger a ->fail()
$writeCleanedFile = true;
echo "{$language}: The string {$stringLabel} has {$englishParametersCount} parameters in English, but {$countTranslation} in this translation. <br/>\n";
} else {
$cleanedStrings[$stringLabel] = $stringValue;
}
} else {
$cleanedStrings[$stringLabel] = $stringValue;
}
}
// If the translation is the same as in English, we remove it from the translation file (as it might have been copied by
// the translator but this would skew translation stats
if (isset($englishStringsIndexed[$stringLabel]) && $englishStringsIndexed[$stringLabel] == $stringValue && $language == 'fa') {
$writeCleanedFile = true;
echo "{$language}: The string {$stringLabel} is the same as in English, removing... <br/>\n";
$cleanedStrings[$stringLabel] = false;
}
// remove excessive line breaks (and leading/trailing whitespace) from translations
if (!empty($cleanedStrings[$stringLabel])) {
$stringNoLineBreak = trim($cleanedStrings[$stringLabel]);
if ($stringLabel != 'Login_MailPasswordRecoveryBody') {
$stringNoLineBreak = str_replace(array("\n", "\r"), " ", $stringNoLineBreak);
}
if ($cleanedStrings[$stringLabel] !== $stringNoLineBreak) {
echo "{$language}: found unnecessary whitespace in some strings in {$stringLabel} <br/>\n";
$writeCleanedFile = true;
$cleanedStrings[$stringLabel] = $stringNoLineBreak;
}
}
// Test locale
if ($stringLabel == 'General_Locale' && !empty($cleanedStrings[$stringLabel])) {
if (!preg_match('/^([a-z]{2})_([A-Z]{2})\\.UTF-8$/', $cleanedStrings[$stringLabel], $matches)) {
$this->fail("{$language}: invalid locale in {$stringLabel}");
} else {
if (!array_key_exists($matches[1], $allLanguages)) {
$this->fail("{$language}: invalid language code in {$stringLabel}");
} else {
if (!array_key_exists(strtolower($matches[2]), $allCountries)) {
$this->fail("{$language}: invalid region (country code) in {$stringLabel}");
}
}
}
}
if (isset($cleanedStrings[$stringLabel])) {
$currentString = $cleanedStrings[$stringLabel];
$decoded = Piwik_TranslationWriter::clean($currentString);
if ($currentString != $decoded) {
//.........这里部分代码省略.........
示例6: getCountriesForContinent
/**
* Returns a list of country codes for a given continent code.
*
* @param string $continent The continent code.
* @return array
*/
public static function getCountriesForContinent($continent)
{
$continent = strtolower($continent);
$result = array();
foreach (Piwik_Common::getCountriesList() as $countryCode => $continentCode) {
if ($continent == $continentCode) {
$result[] = $countryCode;
}
}
return array('SQL' => "'" . implode("', '", $result) . "', ?", 'bind' => '-');
// HACK: SegmentExpression requires a $bind, even if there's nothing to bind
}
示例7: getCountryCodeTestData
/**
* Dataprovider for testExtractCountryCodeFromBrowserLanguage
*/
public function getCountryCodeTestData()
{
return array(array("", array(), "xx"), array("", array("us" => 'amn'), "xx"), array("en", array("us" => 'amn'), "xx"), array("en-us", array("us" => 'amn'), "us"), array("en-ca", array("us" => 'amn'), "xx"), array("en-ca", array("us" => 'amn', "ca" => 'amn'), "ca"), array("fr-fr,fr-ca", array("us" => 'amn', "ca" => 'amn'), "ca"), array("fr-fr;q=1.0,fr-ca;q=0.9", array("us" => 'amn', "ca" => 'amn'), "ca"), array("fr-ca,fr;q=0.1", array("us" => 'amn', "ca" => 'amn'), "ca"), array("en-us,en;q=0.5", Piwik_Common::getCountriesList(), "us"), array("fr-ca,fr;q=0.1", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "ca"), array("fr-fr,fr-ca", array("fr" => 'eur', "us" => 'amn', "ca" => 'amn'), "fr"));
}