AgmPluginsHandler

Handles all Google Maps plugins.

Defined (1)

The class is defined in the following location(s).

/lib/class_agm_plugins_handler.php  
  1. class AgmPluginsHandler { 
  2.  
  3. public static function init () { 
  4. define('AGM_PLUGIN_PLUGINS_DIR', AGM_PLUGIN_BASE_DIR . '/lib/plugins', true); 
  5. self::load_active_plugins(); 
  6.  
  7. public static function get_active_plugins () { 
  8. $active = get_option('agm_activated_plugins'); 
  9. $active = $active ? $active : array(); 
  10.  
  11. return $active; 
  12.  
  13. public static function load_active_plugins () { 
  14. $active = self::get_active_plugins(); 
  15.  
  16. foreach ($active as $plugin) { 
  17. $path = self::plugin_to_path($plugin); 
  18. if (!file_exists($path)) continue; 
  19. else @require_once($path); 
  20.  
  21. public static function get_all_plugins () { 
  22. $all = glob(AGM_PLUGIN_PLUGINS_DIR . '/*.php'); 
  23. $all = $all ? $all : array(); 
  24. $ret = array(); 
  25. foreach ($all as $path) { 
  26. $ret[] = pathinfo($path, PATHINFO_FILENAME); 
  27. return $ret; 
  28.  
  29. public static function plugin_to_path ($plugin) { 
  30. $plugin = str_replace('/', '_', $plugin); 
  31. return AGM_PLUGIN_PLUGINS_DIR . '/' . "{$plugin}.php"; 
  32.  
  33. public static function get_plugin_info ($plugin) { 
  34. $path = self::plugin_to_path($plugin); 
  35. $default_headers = array( 
  36. 'Name' => 'Plugin Name',  
  37. 'Author' => 'Author',  
  38. 'Description' => 'Description',  
  39. 'Plugin URI' => 'Plugin URI',  
  40. 'Version' => 'Version',  
  41. ); 
  42. return get_file_data($path, $default_headers, 'plugin'); 
  43.  
  44. public static function activate_plugin ($plugin) { 
  45. $active = self::get_active_plugins(); 
  46. if (in_array($plugin, $active)) return true; // Already active 
  47.  
  48. $active[] = $plugin; 
  49. return update_option('agm_activated_plugins', $active); 
  50.  
  51. public static function deactivate_plugin ($plugin) { 
  52. $active = self::get_active_plugins(); 
  53. if (!in_array($plugin, $active)) return true; // Already deactivated 
  54.  
  55. $key = array_search($plugin, $active); 
  56. if ($key === false) return false; // Haven't found it 
  57.  
  58. unset($active[$key]); 
  59. return update_option('agm_activated_plugins', $active);