Changeset 25406
- Timestamp:
- Nov 9, 2013, 12:29:38 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/plugins.class.php
r25133 r25406 22 22 // +-----------------------------------------------------------------------+ 23 23 24 /** 25 * class DummyPlugin_maintain 26 * used when a plugin uses the old procedural declaration of maintenance methods 27 */ 28 class DummyPlugin_maintain extends PluginMaintain 29 { 30 function install($plugin_version, &$errors=array()) 31 { 32 return $this->__call(__FUNCTION__, func_get_args()); 33 } 34 function activate($plugin_version, &$errors=array()) 35 { 36 return $this->__call(__FUNCTION__, func_get_args()); 37 } 38 function deactivate() 39 { 40 return $this->__call(__FUNCTION__, func_get_args()); 41 } 42 function uninstall() 43 { 44 return $this->__call(__FUNCTION__, func_get_args()); 45 } 46 47 function __call($name, $arguments) 48 { 49 if (is_callable('plugin_'.$name)) 50 { 51 array_unshift($arguments, $this->plugin_id); 52 return call_user_func_array('plugin_'.$name, $arguments); 53 } 54 return null; 55 } 56 } 57 58 24 59 class plugins 25 60 { … … 31 66 /** 32 67 * Initialize $fs_plugins and $db_plugins_by_id 33 */68 */ 34 69 function plugins() 35 70 { … … 42 77 } 43 78 44 /** 79 /** 80 * Returns the maintain class of a plugin 81 * or build a new class with the procedural methods 82 * @param string $plugin_id 83 */ 84 private static function build_maintain_class($plugin_id) 85 { 86 $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php'; 87 $classname = $plugin_id.'_maintain'; 88 89 if (file_exists($file_to_include)) 90 { 91 include_once($file_to_include); 92 93 if (class_exists($classname)) 94 { 95 $plugin_maintain = new $classname($plugin_id); 96 } 97 else 98 { 99 $plugin_maintain = new DummyPlugin_maintain($plugin_id); 100 } 101 } 102 else 103 { 104 $plugin_maintain = new DummyPlugin_maintain($plugin_id); 105 } 106 107 return $plugin_maintain; 108 } 109 110 /** 45 111 * Perform requested actions 46 *@param string - action47 * @param string - plugin id48 * @param array - errors49 */112 * @param string - action 113 * @param string - plugin id 114 * @param array - errors 115 */ 50 116 function perform_action($action, $plugin_id) 51 117 { … … 54 120 $crt_db_plugin = $this->db_plugins_by_id[$plugin_id]; 55 121 } 56 $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php'; 122 123 $plugin_maintain = self::build_maintain_class($plugin_id); 57 124 58 125 $errors = array(); … … 65 132 break; 66 133 } 67 if (file_exists($file_to_include)) 68 { 69 include_once($file_to_include); 70 if (function_exists('plugin_install')) 71 { 72 plugin_install($plugin_id, $this->fs_plugins[$plugin_id]['version'], $errors); 73 } 74 } 134 135 $plugin_maintain->install($this->fs_plugins[$plugin_id]['version'], $errors); 136 75 137 if (empty($errors)) 76 138 { 77 139 $query = ' 78 INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES (\''79 . $plugin_id . '\',\'' . $this->fs_plugins[$plugin_id]['version'] . '\' 80 )';140 INSERT INTO '. PLUGINS_TABLE .' (id,version) 141 VALUES (\''. $plugin_id .'\', \''. $this->fs_plugins[$plugin_id]['version'] .'\') 142 ;'; 81 143 pwg_query($query); 82 144 } … … 94 156 break; 95 157 } 96 if (empty($errors) and file_exists($file_to_include)) 97 { 98 include_once($file_to_include); 99 if (function_exists('plugin_activate')) 100 { 101 plugin_activate($plugin_id, $crt_db_plugin['version'], $errors); 102 } 103 } 158 104 159 if (empty($errors)) 105 160 { 161 $plugin_maintain->activate($crt_db_plugin['version'], $errors); 162 } 163 164 if (empty($errors)) 165 { 106 166 $query = ' 107 UPDATE ' . PLUGINS_TABLE . ' 108 SET state=\'active\', version=\''.$this->fs_plugins[$plugin_id]['version'].'\' 109 WHERE id=\'' . $plugin_id . '\''; 167 UPDATE '. PLUGINS_TABLE .' 168 SET state=\'active\', 169 version=\''. $this->fs_plugins[$plugin_id]['version'] .'\' 170 WHERE id=\''. $plugin_id .'\' 171 ;'; 110 172 pwg_query($query); 111 173 } … … 117 179 break; 118 180 } 181 119 182 $query = ' 120 UPDATE ' . PLUGINS_TABLE . ' SET state=\'inactive\' WHERE id=\'' . $plugin_id . '\''; 183 UPDATE '. PLUGINS_TABLE .' 184 SET state=\'inactive\' 185 WHERE id=\''. $plugin_id .'\' 186 ;'; 121 187 pwg_query($query); 122 if (file_exists($file_to_include)) 123 { 124 include_once($file_to_include); 125 if (function_exists('plugin_deactivate')) 126 { 127 plugin_deactivate($plugin_id); 128 } 129 } 188 189 $plugin_maintain->deactivate(); 130 190 break; 131 191 … … 139 199 $this->perform_action('deactivate', $plugin_id); 140 200 } 201 141 202 $query = ' 142 DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; 203 DELETE FROM '. PLUGINS_TABLE .' 204 WHERE id=\''. $plugin_id .'\' 205 ;'; 143 206 pwg_query($query); 144 if (file_exists($file_to_include)) 145 { 146 include_once($file_to_include); 147 if (function_exists('plugin_uninstall')) 148 { 149 plugin_uninstall($plugin_id); 150 } 151 } 207 208 $plugin_maintain->uninstall(); 152 209 break; 153 210 … … 167 224 break; 168 225 } 226 169 227 deltree(PHPWG_PLUGINS_PATH . $plugin_id, PHPWG_PLUGINS_PATH . 'trash'); 170 228 break; 171 229 } 230 172 231 return $errors; 173 232 } 174 233 175 234 /** 176 *Get plugins defined in the plugin directory177 */235 * Get plugins defined in the plugin directory 236 */ 178 237 function get_fs_plugins() 179 238 { -
trunk/admin/include/themes.class.php
r25018 r25406 22 22 // +-----------------------------------------------------------------------+ 23 23 24 /** 25 * class DummyTheme_maintain 26 * used when a theme uses the old procedural declaration of maintenance methods 27 */ 28 class DummyTheme_maintain extends ThemeMaintain 29 { 30 function activate($theme_version, &$errors=array()) 31 { 32 return $this->__call(__FUNCTION__, func_get_args()); 33 } 34 function deactivate() 35 { 36 return $this->__call(__FUNCTION__, func_get_args()); 37 } 38 function delete() 39 { 40 return $this->__call(__FUNCTION__, func_get_args()); 41 } 42 43 function __call($name, $arguments) 44 { 45 if (is_callable('theme_'.$name)) 46 { 47 array_unshift($arguments, $this->theme_id); 48 return call_user_func_array('theme_'.$name, $arguments); 49 } 50 return null; 51 } 52 } 53 54 24 55 class themes 25 56 { … … 39 70 $this->db_themes_by_id[$db_theme['id']] = $db_theme; 40 71 } 72 } 73 74 /** 75 * Returns the maintain class of a theme 76 * or build a new class with the procedural methods 77 * @param string $theme_id 78 */ 79 private static function build_maintain_class($theme_id) 80 { 81 $file_to_include = PHPWG_THEMES_PATH.'/'.$theme_id.'/admin/maintain.inc.php'; 82 $classname = $theme_id.'_maintain'; 83 84 if (file_exists($file_to_include)) 85 { 86 include_once($file_to_include); 87 88 if (class_exists($classname)) 89 { 90 $theme_maintain = new $classname($theme_id); 91 } 92 else 93 { 94 $theme_maintain = new DummyTheme_maintain($theme_id); 95 } 96 } 97 else 98 { 99 $theme_maintain = new DummyTheme_maintain($theme_id); 100 } 101 102 return $theme_maintain; 41 103 } 42 104 … … 56 118 } 57 119 58 $ file_to_include = PHPWG_THEMES_PATH.'/'.$theme_id.'/admin/maintain.inc.php';120 $theme_maintain = self::build_maintain_class($theme_id); 59 121 60 122 $errors = array(); … … 86 148 } 87 149 88 89 150 if ($this->fs_themes[$theme_id]['mobile'] 90 151 and !empty($conf['mobile_theme']) … … 95 156 } 96 157 97 if (file_exists($file_to_include)) 98 { 99 include($file_to_include); 100 if (function_exists('theme_activate')) 101 { 102 theme_activate($theme_id, $this->fs_themes[$theme_id]['version'], $errors); 103 } 104 } 158 $theme_maintain->activate($this->fs_themes[$theme_id]['version'], $errors); 105 159 106 160 if (empty($errors)) … … 142 196 143 197 $query = ' 144 SELECT 145 id 198 SELECT id 146 199 FROM '.THEMES_TABLE.' 147 200 WHERE id != \''.$theme_id.'\' … … 160 213 } 161 214 162 if (file_exists($file_to_include)) 163 { 164 include($file_to_include); 165 if (function_exists('theme_deactivate')) 166 { 167 theme_deactivate($theme_id); 168 } 169 } 215 $theme_maintain->deactivate(); 170 216 171 217 $query = ' … … 204 250 } 205 251 206 if (file_exists($file_to_include)) 207 { 208 include($file_to_include); 209 if (function_exists('theme_delete')) 210 { 211 theme_delete($theme_id); 212 } 213 } 252 $theme_maintain->delete(); 214 253 215 254 deltree(PHPWG_THEMES_PATH.$theme_id, PHPWG_THEMES_PATH . 'trash'); -
trunk/include/functions_plugins.inc.php
r25018 r25406 32 32 33 33 define('PHPWG_PLUGINS_PATH', PHPWG_ROOT_PATH.'plugins/'); 34 35 34 define('EVENT_HANDLER_PRIORITY_NEUTRAL', 50); 35 36 37 /** 38 * class PluginMaintain 39 * used to declare maintenance methods of a plugin 40 */ 41 abstract class PluginMaintain 42 { 43 protected $plugin_id; 44 45 function __construct($id) 46 { 47 $this->plugin_id = $id; 48 } 49 50 abstract function install($plugin_version, &$errors=array()); 51 abstract function activate($plugin_version, &$errors=array()); 52 abstract function deactivate(); 53 abstract function uninstall(); 54 55 /* 56 * test if a plugin needs to be updated and call a update function 57 * @param: string $version, version exposed by the plugin 58 * @param: string $on_update, name of a method to call when an update is needed 59 * it receives the previous version as first parameter 60 */ 61 function autoUpdate($version, $on_update=null) 62 { 63 global $pwg_loaded_plugins; 64 65 $current_version = $pwg_loaded_plugins[$this->plugin_id]['version']; 66 67 if ( $version == 'auto' or $current_version == 'auto' 68 or version_compare($current_version, $version, '<') 69 ) 70 { 71 if (!empty($on_update)) 72 { 73 call_user_func(array(&$this, $on_update), $current_version); 74 } 75 76 if ($version != 'auto') 77 { 78 $query = ' 79 UPDATE '. PLUGINS_TABLE .' 80 SET version = "'. $version .'" 81 WHERE id = "'. $this->plugin_id .'" 82 ;'; 83 pwg_query($query); 84 85 $pwg_loaded_plugins[$this->plugin_id]['version'] = $version; 86 } 87 } 88 } 89 } 90 91 /** 92 * class ThemeMaintain 93 * used to declare maintenance methods of a theme 94 */ 95 abstract class ThemeMaintain 96 { 97 protected $theme_id; 98 99 function __construct($id) 100 { 101 $this->theme_id = $id; 102 } 103 104 abstract function activate($theme_version, &$errors=array()); 105 abstract function deactivate(); 106 abstract function delete(); 107 108 /* 109 * test if a theme needs to be updated and call a update function 110 * @param: string $version, version exposed by the theme 111 * @param: string $on_update, name of a method to call when an update is needed 112 * it receives the previous version as first parameter 113 */ 114 function autoUpdate($version, $on_update=null) 115 { 116 $query = ' 117 SELECT version 118 FROM '. THEMES_TABLE .' 119 WHERE id = "'. $this->theme_id .'" 120 ;'; 121 list($current_version) = pwg_db_fetch_row(pwg_query($query)); 122 123 if ( $version == 'auto' or $current_version == 'auto' 124 or version_compare($current_version, $version, '<') 125 ) 126 { 127 if (!empty($on_update)) 128 { 129 call_user_func(array(&$this, $on_update), $current_version); 130 } 131 132 if ($version != 'auto') 133 { 134 $query = ' 135 UPDATE '. THEMES_TABLE .' 136 SET version = "'. $version .'" 137 WHERE id = "'. $this->theme_id .'" 138 ;'; 139 pwg_query($query); 140 } 141 } 142 } 143 } 144 36 145 37 146 /* Register a event handler. … … 254 363 } 255 364 256 /*257 * test if a plugin needs to be updated and call a update function258 * @param: string $plugin_id, id of the plugin as seen in PLUGINS_TABLE and $pwg_loaded_plugins259 * @param: string $version, version exposed by the plugin260 * @param: callable $on_update, function to call when and update is needed261 * it receives the previous version as first parameter262 */263 function request_plugin_update($plugin_id, $version, $on_update)264 {265 global $pwg_loaded_plugins;266 267 if (268 $version == 'auto' or269 $pwg_loaded_plugins[$plugin_id]['version'] == 'auto' or270 version_compare($pwg_loaded_plugins[$plugin_id]['version'], $version, '<')271 )272 {273 // call update function274 if (!empty($on_update))275 {276 call_user_func($on_update, $pwg_loaded_plugins[$plugin_id]['version']);277 }278 279 // update plugin version in database280 if ($version != 'auto')281 {282 $query = '283 UPDATE '. PLUGINS_TABLE .'284 SET version = "'. $version .'"285 WHERE id = "'. $plugin_id .'"';286 pwg_query($query);287 288 $pwg_loaded_plugins[$plugin_id]['version'] = $version;289 }290 }291 }292 293 365 ?>
Note: See TracChangeset
for help on using the changeset viewer.