AgmPluginInstaller

Handles plugin installation.

Defined (1)

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

/lib/class_agm_plugin_installer.php  
  1. class AgmPluginInstaller { 
  2. var $wpdb; 
  3.  
  4. var $defaults = array ( 
  5. 'height' => 300,  
  6. 'width' => 300,  
  7. 'map_type' => 'ROADMAP',  
  8. 'image_size' => 'small',  
  9. 'image_limit' => 10,  
  10. 'map_alignment' => 'left',  
  11. 'zoom' => 1,  
  12. 'units' => 'METRIC',  
  13. ); 
  14.  
  15. /** 
  16. * PHP4 compatibility constructor. 
  17. */ 
  18. function AgmPluginInstaller () { 
  19. $this->__construct(); 
  20.  
  21. function __construct() { 
  22. global $wpdb; 
  23. $this->wpdb = $wpdb; 
  24. $this->model = new AgmMapModel(); 
  25.  
  26. /** 
  27. * Entry method. 
  28. * Handles Plugin installation. 
  29. * @access public 
  30. * @static 
  31. */ 
  32. function install () { 
  33. $me = new AgmPluginInstaller(); 
  34. if (!$me->has_database_table()) { 
  35. $me->create_database_table(); 
  36. $me->set_default_options(); 
  37.  
  38. /** 
  39. * Performs a quick check for plugin install state. 
  40. * Also updates plugin options as needed. This handles minor updates 
  41. * (i.e. no database changes). 
  42. * @access public 
  43. * @static 
  44. */ 
  45. function check () { 
  46. $is_installed = get_option('agm_google_maps', false); 
  47. if ($is_installed) return AgmPluginInstaller::check_and_update_options($is_installed); 
  48. else AgmPluginInstaller::install(); 
  49.  
  50. /** 
  51. * Checks to see if we already have a table. 
  52. * @access private 
  53. * @return bool True if we do, false if we need to create it. 
  54. */ 
  55. function has_database_table () { 
  56. $table = $this->model->get_table_name(); 
  57. return ($this->wpdb->get_var("show tables like '{$table}'") == $table); 
  58.  
  59. /** 
  60. * Actually creates the database table. 
  61. * @access private 
  62. */ 
  63. function create_database_table () { 
  64. $table = $this->model->get_table_name(); 
  65. $sql = "CREATE TABLE {$table} ( 
  66. id INT(10) NOT NULL AUTO_INCREMENT,  
  67. title VARCHAR(50) NOT NULL,  
  68. post_ids TEXT NOT NULL,  
  69. markers TEXT NOT NULL,  
  70. options TEXT NOT NULL,  
  71. UNIQUE KEY id (id) 
  72. )"; 
  73. // Setup charset and collation 
  74. if (!empty($this->wpdb->charset)) { 
  75. $sql .= " DEFAULT CHARACTER SET {$this->wpdb->charset}"; 
  76. if (!empty($this->wpdb->collate)) { 
  77. $sql .= " COLLATE {$this->wpdb->collate}"; 
  78. require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
  79. dbDelta($sql); 
  80.  
  81. /** 
  82. * (Re)sets Plugin options to defaults. 
  83. * @access private 
  84. */ 
  85. function set_default_options () { 
  86. update_option('agm_google_maps', $this->defaults); 
  87.  
  88. /** 
  89. * Checks for new plugin options and adds them as needed. 
  90. * @access private 
  91. * @static 
  92. */ 
  93. function check_and_update_options ($opts) { 
  94. $me = new AgmPluginInstaller; 
  95. $res = array_merge($me->defaults, $opts); 
  96. update_option('agm_google_maps', $res); 
  97.