Changeset 25406 for trunk/admin
- Timestamp:
- Nov 9, 2013, 12:29:38 AM (10 years ago)
- Location:
- trunk/admin/include
- Files:
-
- 2 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');
Note: See TracChangeset
for help on using the changeset viewer.