Changeset 29792 for branches/2.7
- Timestamp:
- Sep 25, 2014, 9:23:52 PM (10 years ago)
- Location:
- branches/2.7
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.7/admin/include/plugins.class.php
r28969 r29792 90 90 $classname = $plugin_id.'_maintain'; 91 91 92 // 2.7 pattern (OO only) 92 93 if (file_exists($file_to_include.'.class.php')) 93 94 { … … 96 97 } 97 98 99 // before 2.7 pattern (OO or procedural) 98 100 if (file_exists($file_to_include.'.inc.php')) 99 101 { … … 115 117 * @param array - errors 116 118 */ 117 function perform_action($action, $plugin_id )119 function perform_action($action, $plugin_id, $options=array()) 118 120 { 119 121 if (isset($this->db_plugins_by_id[$plugin_id])) … … 122 124 } 123 125 124 $plugin_maintain = self::build_maintain_class($plugin_id); 126 if ($action !== 'update') 127 { // wait for files to be updated 128 $plugin_maintain = self::build_maintain_class($plugin_id); 129 } 125 130 126 131 $errors = array(); … … 146 151 break; 147 152 153 case 'update': 154 $previous_version = $this->fs_plugins[$plugin_id]['version']; 155 $errors[0] = $this->extract_plugin_files('upgrade', $options['revision'], $plugin_id); 156 157 if ($errors[0] === 'ok') 158 { 159 $this->get_fs_plugin($plugin_id); // refresh plugins list 160 $new_version = $this->fs_plugins[$plugin_id]['version']; 161 162 $plugin_maintain = self::build_maintain_class($plugin_id); 163 $plugin_maintain->update($previous_version, $new_version, $errors); 164 165 if ($new_version != 'auto') 166 { 167 $query = ' 168 UPDATE '. PLUGINS_TABLE .' 169 SET version=\''. $new_version .'\' 170 WHERE id=\''. $plugin_id .'\' 171 ;'; 172 pwg_query($query); 173 } 174 } 175 176 break; 177 148 178 case 'activate': 149 179 if (!isset($crt_db_plugin)) … … 167 197 $query = ' 168 198 UPDATE '. PLUGINS_TABLE .' 169 SET state=\'active\', 170 version=\''. $this->fs_plugins[$plugin_id]['version'] .'\' 199 SET state=\'active\' 171 200 WHERE id=\''. $plugin_id .'\' 172 201 ;'; … … 243 272 if ($file!='.' and $file!='..') 244 273 { 245 $path = PHPWG_PLUGINS_PATH.$file; 246 if (is_dir($path) and !is_link($path) 247 and preg_match('/^[a-zA-Z0-9-_]+$/', $file ) 248 and file_exists($path.'/main.inc.php') 249 ) 250 { 251 $plugin = array( 252 'name'=>$file, 253 'version'=>'0', 254 'uri'=>'', 255 'description'=>'', 256 'author'=>'', 257 ); 258 $plg_data = file_get_contents($path.'/main.inc.php', null, null, 0, 2048); 259 260 if (preg_match("|Plugin Name:\\s*(.+)|", $plg_data, $val)) 261 { 262 $plugin['name'] = trim( $val[1] ); 263 } 264 if (preg_match("|Version:\\s*([\\w.-]+)|", $plg_data, $val)) 265 { 266 $plugin['version'] = trim($val[1]); 267 } 268 if (preg_match("|Plugin URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val)) 269 { 270 $plugin['uri'] = trim($val[1]); 271 } 272 if ($desc = load_language('description.txt', $path.'/', array('return' => true))) 273 { 274 $plugin['description'] = trim($desc); 275 } 276 elseif (preg_match("|Description:\\s*(.+)|", $plg_data, $val)) 277 { 278 $plugin['description'] = trim($val[1]); 279 } 280 if (preg_match("|Author:\\s*(.+)|", $plg_data, $val)) 281 { 282 $plugin['author'] = trim($val[1]); 283 } 284 if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val)) 285 { 286 $plugin['author uri'] = trim($val[1]); 287 } 288 if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) 289 { 290 list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); 291 if (is_numeric($extension)) $plugin['extension'] = $extension; 292 } 293 294 // IMPORTANT SECURITY ! 295 $plugin = array_map('htmlspecialchars', $plugin); 296 $this->fs_plugins[$file] = $plugin; 274 if (preg_match('/^[a-zA-Z0-9-_]+$/', $file)) 275 { 276 $this->get_fs_plugin($file); 297 277 } 298 278 } 299 279 } 300 280 closedir($dir); 281 } 282 283 /** 284 * Load metadata of a plugin in `fs_plugins` array 285 * @from 2.7 286 * @param $plugin_id 287 * @return false|array 288 */ 289 function get_fs_plugin($plugin_id) 290 { 291 $path = PHPWG_PLUGINS_PATH.$plugin_id; 292 293 if (is_dir($path) and !is_link($path) 294 and file_exists($path.'/main.inc.php') 295 ) 296 { 297 $plugin = array( 298 'name'=>$plugin_id, 299 'version'=>'0', 300 'uri'=>'', 301 'description'=>'', 302 'author'=>'', 303 ); 304 $plg_data = file_get_contents($path.'/main.inc.php', null, null, 0, 2048); 305 306 if (preg_match("|Plugin Name:\\s*(.+)|", $plg_data, $val)) 307 { 308 $plugin['name'] = trim( $val[1] ); 309 } 310 if (preg_match("|Version:\\s*([\\w.-]+)|", $plg_data, $val)) 311 { 312 $plugin['version'] = trim($val[1]); 313 } 314 if (preg_match("|Plugin URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val)) 315 { 316 $plugin['uri'] = trim($val[1]); 317 } 318 if ($desc = load_language('description.txt', $path.'/', array('return' => true))) 319 { 320 $plugin['description'] = trim($desc); 321 } 322 elseif (preg_match("|Description:\\s*(.+)|", $plg_data, $val)) 323 { 324 $plugin['description'] = trim($val[1]); 325 } 326 if (preg_match("|Author:\\s*(.+)|", $plg_data, $val)) 327 { 328 $plugin['author'] = trim($val[1]); 329 } 330 if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val)) 331 { 332 $plugin['author uri'] = trim($val[1]); 333 } 334 if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) 335 { 336 list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); 337 if (is_numeric($extension)) $plugin['extension'] = $extension; 338 } 339 340 // IMPORTANT SECURITY ! 341 $plugin = array_map('htmlspecialchars', $plugin); 342 $this->fs_plugins[$plugin_id] = $plugin; 343 344 return $plugin; 345 } 346 347 return false; 301 348 } 302 349 -
branches/2.7/include/functions_plugins.inc.php
r29316 r29792 377 377 function autoupdate_plugin(&$plugin) 378 378 { 379 $maintain_file = PHPWG_PLUGINS_PATH.$plugin['id'].'/maintain.class.php'; 380 381 // autoupdate is applicable only to plugins with 2.7 architecture 382 if (file_exists($maintain_file)) 383 { 384 // try to find the filesystem version in lines 2 to 10 of main.inc.php 385 $fh = fopen(PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php', 'r'); 386 $fs_version = null; 387 $i = -1; 388 389 while (($line = fgets($fh))!==false && $fs_version==null && $i<10) 390 { 391 $i++; 392 if ($i < 2) continue; // first lines are typically "<?php" and "/*" 393 394 if (preg_match('/Version:\\s*([\\w.-]+)/', $line, $matches)) 395 { 396 $fs_version = $matches[1]; 397 } 398 } 399 400 fclose($fh); 401 402 if ($fs_version != null) 403 { 404 global $pwg_loaded_plugins, $page; 405 406 // if version is auto (dev) or superior 407 if ( 408 $fs_version == 'auto' or $plugin['version'] == 'auto' 409 or safe_version_compare($plugin['version'], $fs_version, '<') 410 ) 411 { 412 // call update method 413 include_once($maintain_file); 414 415 $classname = $plugin['id'].'_maintain'; 416 $plugin_maintain = new $classname($plugin['id']); 417 $plugin_maintain->update($plugin['version'], $fs_version, $page['errors']); 418 419 $plugin['version'] = $fs_version; 420 421 // update database (only on production) 422 if ($plugin['version'] != 'auto') 423 { 424 $query = ' 379 // try to find the filesystem version in lines 2 to 10 of main.inc.php 380 $fh = fopen(PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php', 'r'); 381 $fs_version = null; 382 $i = -1; 383 384 while (($line = fgets($fh))!==false && $fs_version==null && $i<10) 385 { 386 $i++; 387 if ($i < 2) continue; // first lines are typically "<?php" and "/*" 388 389 if (preg_match('/Version:\\s*([\\w.-]+)/', $line, $matches)) 390 { 391 $fs_version = $matches[1]; 392 } 393 } 394 395 fclose($fh); 396 397 // if version is auto (dev) or superior 398 if ($fs_version != null && ( 399 $fs_version == 'auto' || $plugin['version'] == 'auto' || 400 safe_version_compare($plugin['version'], $fs_version, '<') 401 ) 402 ) { 403 $plugin['version'] = $fs_version; 404 405 $maintain_file = PHPWG_PLUGINS_PATH.$plugin['id'].'/maintain.class.php'; 406 407 // autoupdate is applicable only to plugins with 2.7 architecture 408 if (file_exists($maintain_file)) 409 { 410 global $page; 411 412 // call update method 413 include_once($maintain_file); 414 415 $classname = $plugin['id'].'_maintain'; 416 $plugin_maintain = new $classname($plugin['id']); 417 $plugin_maintain->update($plugin['version'], $fs_version, $page['errors']); 418 } 419 420 // update database (only on production) 421 if ($plugin['version'] != 'auto') 422 { 423 $query = ' 425 424 UPDATE '. PLUGINS_TABLE .' 426 425 SET version = "'. $plugin['version'] .'" 427 426 WHERE id = "'. $plugin['id'] .'" 428 427 ;'; 429 pwg_query($query); 430 } 431 } 428 pwg_query($query); 432 429 } 433 430 } -
branches/2.7/include/ws_functions/pwg.extensions.php
r27694 r29792 189 189 } 190 190 191 $upgrade_status = $extension->extract_plugin_files('upgrade', $revision, $extension_id);191 list($upgrade_status) = $extension->perform_action('update', $extension_id, array('revision'=>$revision)); 192 192 $extension_name = $extension->fs_plugins[$extension_id]['name']; 193 193
Note: See TracChangeset
for help on using the changeset viewer.