diff options
-rw-r--r-- | core/Common.php | 17 | ||||
-rw-r--r-- | core/UrlHelper.php | 7 | ||||
-rw-r--r-- | plugins/LanguagesManager/TranslationWriter/Validate/CoreTranslations.php | 7 | ||||
-rw-r--r-- | plugins/MobileMessaging/Controller.php | 34 | ||||
-rw-r--r-- | plugins/UserCountry/Columns/Country.php | 7 | ||||
-rw-r--r-- | plugins/UserCountry/UserCountry.php | 7 | ||||
-rw-r--r-- | plugins/UserSettings/Archiver.php | 8 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/CommonTest.php | 6 |
8 files changed, 68 insertions, 25 deletions
diff --git a/core/Common.php b/core/Common.php index dcadaa2d49..6088f83be9 100644 --- a/core/Common.php +++ b/core/Common.php @@ -959,7 +959,11 @@ class Common return self::LANGUAGE_CODE_INVALID; } - $validCountries = self::getCountriesList(); + /** @var RegionDataProvider $dataProvider */ + $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); + + $validCountries = $dataProvider->getCountryList(); + return self::extractCountryCodeFromBrowserLanguage($lang, $validCountries, $enableLanguageToCountryGuess); } @@ -1070,11 +1074,12 @@ class Common */ public static function getContinent($country) { - $countryList = self::getCountriesList(); - if (isset($countryList[$country])) { - return $countryList[$country]; - } - return 'unk'; + /** @var RegionDataProvider $dataProvider */ + $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); + + $countryList = $dataProvider->getCountryList(); + + return isset($countryList[$country]) ? $countryList[$country] : 'unk'; } /* diff --git a/core/UrlHelper.php b/core/UrlHelper.php index 5efba99996..4eedce07a9 100644 --- a/core/UrlHelper.php +++ b/core/UrlHelper.php @@ -8,6 +8,9 @@ */ namespace Piwik; +use Piwik\Container\StaticContainer; +use Piwik\Intl\Data\Provider\RegionDataProvider; + /** * Contains less commonly needed URL helper methods. * @@ -72,7 +75,9 @@ class UrlHelper { static $countries; if (!isset($countries)) { - $countries = implode('|', array_keys(Common::getCountriesList(true))); + /** @var RegionDataProvider $regionDataProvider */ + $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); + $countries = implode('|', array_keys($regionDataProvider->getCountryList(true))); } return preg_replace( diff --git a/plugins/LanguagesManager/TranslationWriter/Validate/CoreTranslations.php b/plugins/LanguagesManager/TranslationWriter/Validate/CoreTranslations.php index eb888bf434..8499f57850 100644 --- a/plugins/LanguagesManager/TranslationWriter/Validate/CoreTranslations.php +++ b/plugins/LanguagesManager/TranslationWriter/Validate/CoreTranslations.php @@ -10,6 +10,8 @@ namespace Piwik\Plugins\LanguagesManager\TranslationWriter\Validate; use Piwik\Common; +use Piwik\Container\StaticContainer; +use Piwik\Intl\Data\Provider\RegionDataProvider; class CoreTranslations extends ValidateAbstract { @@ -73,8 +75,11 @@ class CoreTranslations extends ValidateAbstract return false; } + /** @var RegionDataProvider $regionDataProvider */ + $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); + $allLanguages = Common::getLanguagesList(); - $allCountries = Common::getCountriesList(); + $allCountries = $regionDataProvider->getCountryList(); if (!preg_match('/^([a-z]{2})_([A-Z]{2})\.UTF-8$/', $translations['General']['Locale'], $matches)) { $this->message = self::ERRORSTATE_LOCALEINVALID; diff --git a/plugins/MobileMessaging/Controller.php b/plugins/MobileMessaging/Controller.php index 92661ed87d..cb3ec59238 100644 --- a/plugins/MobileMessaging/Controller.php +++ b/plugins/MobileMessaging/Controller.php @@ -10,20 +10,31 @@ namespace Piwik\Plugins\MobileMessaging; use Piwik\Common; +use Piwik\Intl\Data\Provider\RegionDataProvider; use Piwik\IP; use Piwik\Piwik; +use Piwik\Plugin\ControllerAdmin; use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\MobileMessaging\SMSProvider; use Piwik\View; require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php'; -/** - * - */ -class Controller extends \Piwik\Plugin\ControllerAdmin +class Controller extends ControllerAdmin { - /* + /** + * @var RegionDataProvider + */ + private $regionDataProvider; + + public function __construct(RegionDataProvider $regionDataProvider) + { + $this->regionDataProvider = $regionDataProvider; + + parent::__construct(); + } + + /** * Mobile Messaging Settings tab : * - set delegated management * - provide & validate SMS API credential @@ -40,7 +51,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin return $view->render(); } - /* + /** * Mobile Messaging Settings tab : * - set delegated management * - provide & validate SMS API credential @@ -77,13 +88,12 @@ class Controller extends \Piwik\Plugin\ControllerAdmin // construct the list of countries from the lang files $countries = array(); - foreach (Common::getCountriesList() as $countryCode => $continentCode) { + foreach ($this->regionDataProvider->getCountryList() as $countryCode => $continentCode) { if (isset(CountryCallingCodes::$countryCallingCodes[$countryCode])) { - $countries[$countryCode] = - array( - 'countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), - 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode], - ); + $countries[$countryCode] = array( + 'countryName' => \Piwik\Plugins\UserCountry\countryTranslate($countryCode), + 'countryCallingCode' => CountryCallingCodes::$countryCallingCodes[$countryCode], + ); } } $view->countries = $countries; diff --git a/plugins/UserCountry/Columns/Country.php b/plugins/UserCountry/Columns/Country.php index 31e2839a54..db8026ba6b 100644 --- a/plugins/UserCountry/Columns/Country.php +++ b/plugins/UserCountry/Columns/Country.php @@ -10,6 +10,8 @@ namespace Piwik\Plugins\UserCountry\Columns; use Piwik\Common; use Piwik\Config; +use Piwik\Container\StaticContainer; +use Piwik\Intl\Data\Provider\RegionDataProvider; use Piwik\IP; use Piwik\Piwik; use Piwik\Plugin\Manager; @@ -92,7 +94,10 @@ class Country extends Base $hostnameDomain = 'gb'; } - if (array_key_exists($hostnameDomain, Common::getCountriesList())) { + /** @var RegionDataProvider $regionDataProvider */ + $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); + + if (array_key_exists($hostnameDomain, $regionDataProvider->getCountryList())) { return $hostnameDomain; } diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index 960e966093..d28e6ce601 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -11,6 +11,8 @@ namespace Piwik\Plugins\UserCountry; use Piwik\ArchiveProcessor; use Piwik\Common; use Piwik\Config; +use Piwik\Container\StaticContainer; +use Piwik\Intl\Data\Provider\RegionDataProvider; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; use Piwik\Plugins\UserCountry\LocationProvider; use Piwik\Url; @@ -85,9 +87,12 @@ class UserCountry extends \Piwik\Plugin */ public static function getCountriesForContinent($continent) { + /** @var RegionDataProvider $regionDataProvider */ + $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); + $result = array(); $continent = strtolower($continent); - foreach (Common::getCountriesList() as $countryCode => $continentCode) { + foreach ($regionDataProvider->getCountryList() as $countryCode => $continentCode) { if ($continent == $continentCode) { $result[] = $countryCode; } diff --git a/plugins/UserSettings/Archiver.php b/plugins/UserSettings/Archiver.php index 54f0034c41..28f405adf3 100644 --- a/plugins/UserSettings/Archiver.php +++ b/plugins/UserSettings/Archiver.php @@ -10,9 +10,10 @@ namespace Piwik\Plugins\UserSettings; use Piwik\Common; -use Piwik\DataAccess\LogAggregator; +use Piwik\Container\StaticContainer; use Piwik\DataArray; use Piwik\DataTable; +use Piwik\Intl\Data\Provider\RegionDataProvider; use Piwik\Metrics; require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php'; @@ -50,8 +51,11 @@ class Archiver extends \Piwik\Plugin\Archiver protected function aggregateByLanguage() { + /** @var RegionDataProvider $regionDataProvider */ + $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); + $query = $this->getLogAggregator()->queryVisitsByDimension(array("label" => self::LANGUAGE_DIMENSION)); - $countryCodes = Common::getCountriesList($includeInternalCodes = true); + $countryCodes = $regionDataProvider->getCountryList($includeInternalCodes = true); $metricsByLanguage = new DataArray(); while ($row = $query->fetch()) { diff --git a/tests/PHPUnit/Unit/CommonTest.php b/tests/PHPUnit/Unit/CommonTest.php index 503ce0dc12..8aa85ed550 100644 --- a/tests/PHPUnit/Unit/CommonTest.php +++ b/tests/PHPUnit/Unit/CommonTest.php @@ -11,7 +11,9 @@ namespace Piwik\Tests\Unit; use Exception; use PHPUnit_Framework_TestCase; use Piwik\Common; +use Piwik\Container\StaticContainer; use Piwik\Filesystem; +use Piwik\Intl\Data\Provider\RegionDataProvider; /** * @backupGlobals enabled @@ -336,6 +338,8 @@ class CommonTest extends PHPUnit_Framework_TestCase */ public function getCountryCodeTestData() { + /** @var RegionDataProvider $regionDataProvider */ + $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); return array( // browser language, valid countries, expected result array("", array(), "xx"), @@ -347,7 +351,7 @@ class CommonTest extends PHPUnit_Framework_TestCase 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", Common::getCountriesList(), "us"), + array("en-us,en;q=0.5", $regionDataProvider->getCountryList(), "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") ); |