コード例 #1
0
ファイル: Controller.php プロジェクト: nnnnathann/piwik
 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
0
ファイル: Provider.php プロジェクト: neolf/PIWIK4MOBILE
 /**
  * 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
0
ファイル: Provider.php プロジェクト: BackupTheBerlios/oos-svn
	/**
	 * 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
0
ファイル: Common.test.php プロジェクト: nnnnathann/piwik
 /**
  * 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
0
 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) {
                     echo "{$language}: found encoded entities in {$stringLabel}, converting entities to characters <br/>\n";
                     $writeCleanedFile = true;
                     $cleanedStrings[$stringLabel] = $decoded;
                 }
             }
         }
         $this->assertTrue(!empty($cleanedStrings['General_TranslatorName']), "{$language}: translator info not specified");
         $this->assertTrue(!empty($cleanedStrings['General_TranslatorEmail']), "{$language}: translator info not specified");
         if (!empty($cleanedStrings['General_LayoutDirection']) && !in_array($cleanedStrings['General_LayoutDirection'], array('rtl', 'ltr'))) {
             $writeCleanedFile = true;
             $cleanedStrings['General_LayoutDirection'] = false;
             echo "{$language}: General_LayoutDirection must be rtl or ltr";
         }
         if ($writeCleanedFile) {
             $this->writeCleanedTranslationFile($cleanedStrings, $language);
         }
     }
     //		var_dump('Unique plugins found: ' . var_export($plugins, 1));
     $this->pass();
 }
コード例 #6
0
ファイル: UserCountry.php プロジェクト: nomoto-ubicast/piwik
 /**
  * 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
0
ファイル: CommonTest.php プロジェクト: nnnnathann/piwik
 /**
  * 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"));
 }