diff options
Diffstat (limited to 'plugins/UserCountry/LocationProvider.php')
-rwxr-xr-x | plugins/UserCountry/LocationProvider.php | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/plugins/UserCountry/LocationProvider.php b/plugins/UserCountry/LocationProvider.php index 771984dbd4..75e34fbe84 100755 --- a/plugins/UserCountry/LocationProvider.php +++ b/plugins/UserCountry/LocationProvider.php @@ -118,6 +118,19 @@ abstract class LocationProvider abstract public function isWorking(); /** + * Returns information about this location provider. Contains an id, title & description: + * + * array( + * 'id' => 'geoip2php', + * 'title' => '...', + * 'description' => '...' + * ); + * + * @return array + */ + abstract public function getInfo(); + + /** * Returns an array mapping location result keys w/ bool values indicating whether * that information is supported by this provider. If it is not supported, that means * this provider either cannot get this information, or is not configured to get it. @@ -131,6 +144,21 @@ abstract class LocationProvider abstract public function getSupportedLocationInfo(); /** + * Method called when a provider gets activated. + */ + public function activate() + { + } + + /** + * Returns if location provider should be shown. + */ + public function isVisible() + { + return true; + } + + /** * Returns every available provider instance. * * @return LocationProvider[] @@ -142,7 +170,9 @@ abstract class LocationProvider $plugins = PluginManager::getInstance()->getPluginsLoadedAndActivated(); foreach ($plugins as $plugin) { foreach (self::getLocationProviders($plugin) as $instance) { - self::$providers[] = $instance; + if ($instance->isVisible()) { + self::$providers[] = $instance; + } } } } @@ -200,10 +230,10 @@ abstract class LocationProvider * * An example result: * array( - * 'geoip_php' => array('id' => 'geoip_php', + * 'geoip2php' => array('id' => 'geoip2php', * 'title' => '...', * 'desc' => '...', - * 'status' => GeoIp::BROKEN, + * 'status' => GeoIp2::BROKEN, * 'statusMessage' => '...', * 'location' => '...') * 'geoip_serverbased' => array(...) @@ -217,6 +247,7 @@ abstract class LocationProvider { $allInfo = array(); foreach (self::getAllProviders() as $provider) { + $info = $provider->getInfo(); $status = self::INSTALLED; @@ -273,7 +304,11 @@ abstract class LocationProvider */ public static function getCurrentProviderId() { - $optionValue = Option::get(self::CURRENT_PROVIDER_OPTION_NAME); + try { + $optionValue = Option::get(self::CURRENT_PROVIDER_OPTION_NAME); + } catch (\Exception $e) { + $optionValue = false; + } return $optionValue === false ? DefaultProvider::ID : $optionValue; } @@ -303,6 +338,9 @@ abstract class LocationProvider throw new Exception( "Invalid provider ID '$providerId'. The provider either does not exist or is not available"); } + + $provider->activate(); + Option::set(self::CURRENT_PROVIDER_OPTION_NAME, $providerId); Cache::clearCacheGeneral(); return $provider; @@ -470,4 +508,3 @@ abstract class LocationProvider } } } - |