Changeset 2566:9bf417837888 for inc/core/class.dc.modules.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.modules.php
r2492 r2566 16 16 @brief Modules handler 17 17 18 Provides an object to handle modules (themes or plugins). 18 Provides an object to handle modules (themes or plugins). 19 19 */ 20 20 class dcModules … … 26 26 protected $errors = array(); 27 27 protected $modules_names = array(); 28 28 29 29 protected $id; 30 30 protected $mroot; 31 31 32 32 # Inclusion variables 33 33 protected static $superglobals = array('GLOBALS','_SERVER','_GET','_POST','_COOKIE','_FILES','_ENV','_REQUEST','_SESSION'); … … 36 36 37 37 protected static $type = null; 38 38 39 39 public $core; ///< <b>dcCore</b> dcCore instance 40 40 41 41 /** 42 42 Object constructor. 43 43 44 44 @param core <b>dcCore</b> dcCore instance 45 45 */ … … 48 48 $this->core =& $core; 49 49 } 50 50 51 51 /** 52 52 Loads modules. <var>$path</var> could be a separated list of paths 53 53 (path separator depends on your OS). 54 54 55 55 <var>$ns</var> indicates if an additionnal file needs to be loaded on plugin 56 56 load, value could be: … … 58 58 - public (loads module's _public.php) 59 59 - xmlrpc (loads module's _xmlrpc.php) 60 60 61 61 <var>$lang</var> indicates if we need to load a lang file on plugin 62 62 loading. … … 66 66 $this->path = explode(PATH_SEPARATOR,$path); 67 67 $this->ns = $ns; 68 68 69 69 $disabled = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode']; 70 70 $disabled = $disabled && !get_parent_class($this) ? true : false; 71 71 72 72 foreach ($this->path as $root) 73 73 { … … 75 75 continue; 76 76 } 77 77 78 78 if (substr($root,-1) != '/') { 79 79 $root .= '/'; 80 80 } 81 81 82 82 if (($d = @dir($root)) === false) { 83 83 continue; 84 84 } 85 85 86 86 while (($entry = $d->read()) !== false) 87 87 { 88 88 $full_entry = $root.$entry; 89 89 90 90 if ($entry != '.' && $entry != '..' && is_dir($full_entry) 91 91 && file_exists($full_entry.'/_define.php')) … … 110 110 $d->close(); 111 111 } 112 112 113 113 # Sort plugins 114 114 uasort($this->modules,array($this,'sortModules')); 115 115 116 116 # Load translation, _prepend and ns_file 117 117 foreach ($this->modules as $id => $m) … … 120 120 { 121 121 $r = $this->loadModuleFile($m['root'].'/_prepend.php'); 122 122 123 123 # If _prepend.php file returns null (ie. it has a void return statement) 124 124 if (is_null($r)) { … … 127 127 unset($r); 128 128 } 129 129 130 130 $this->loadModuleL10N($id,$lang,'main'); 131 131 if ($ns == 'admin') { … … 135 135 } 136 136 } 137 137 138 138 public function requireDefine($dir,$id) 139 139 { … … 143 143 $this->id = null; 144 144 } 145 } 146 145 } 146 147 147 /** 148 148 This method registers a module in modules list. You should use this to 149 149 register a new module. 150 150 151 151 <var>$permissions</var> is a comma separated list of permissions for your 152 152 module. If <var>$permissions</var> is null, only super admin has access to 153 153 this module. 154 154 155 155 <var>$priority</var> is an integer. Modules are sorted by priority and name. 156 156 Lowest priority comes first. 157 157 158 158 @param name <b>string</b> Module name 159 159 @param desc <b>string</b> Module description 160 160 @param author <b>string</b> Module author name 161 161 @param version <b>string</b> Module version 162 @param properties <b>array</b> extra properties 162 @param properties <b>array</b> extra properties 163 163 (currently available keys : permissions, priority, type) 164 164 */ … … 207 207 } 208 208 } 209 209 210 210 # Check module install on multiple path 211 211 if ($this->id) { … … 238 238 } 239 239 } 240 240 241 241 public function resetModulesList() 242 242 { … … 244 244 $this->modules_names = array(); 245 245 $this->errors = array(); 246 } 247 246 } 247 248 248 public static function installPackage($zip_file,dcModules &$modules) 249 249 { 250 250 $zip = new fileUnzip($zip_file); 251 251 $zip->getList(false,'#(^|/)(__MACOSX|\.svn|\.hg|\.git|\.DS_Store|\.directory|Thumbs\.db)(/|$)#'); 252 252 253 253 $zip_root_dir = $zip->getRootDir(); 254 254 $define = ''; … … 264 264 $has_define = $zip->hasFile($define); 265 265 } 266 266 267 267 if ($zip->isEmpty()) { 268 268 $zip->close(); … … 270 270 throw new Exception(__('Empty module zip file.')); 271 271 } 272 272 273 273 if (!$has_define) { 274 274 $zip->close(); … … 276 276 throw new Exception(__('The zip file does not appear to be a valid Dotclear module.')); 277 277 } 278 278 279 279 $ret_code = 1; 280 280 281 281 if (!is_dir($destination)) 282 282 { 283 283 try { 284 284 files::makeDir($destination,true); 285 285 286 286 $sandbox = clone $modules; 287 287 $zip->unzip($define, $target.'/_define.php'); 288 288 289 289 $sandbox->resetModulesList(); 290 290 $sandbox->requireDefine($target,basename($destination)); 291 291 unlink($target.'/_define.php'); 292 292 293 293 $new_errors = $sandbox->getErrors(); 294 294 if (!empty($new_errors)) { … … 296 296 throw new Exception($new_errors); 297 297 } 298 298 299 299 files::deltree($destination); 300 300 } … … 304 304 unlink($zip_file); 305 305 files::deltree($destination); 306 throw new Exception($e->getMessage()); 306 throw new Exception($e->getMessage()); 307 307 } 308 308 } … … 312 312 $sandbox = clone $modules; 313 313 $zip->unzip($define, $target.'/_define.php'); 314 314 315 315 $sandbox->resetModulesList(); 316 316 $sandbox->requireDefine($target,basename($destination)); 317 317 unlink($target.'/_define.php'); 318 318 $new_modules = $sandbox->getModules(); 319 319 320 320 if (!empty($new_modules)) 321 321 { … … 335 335 $zip->close(); 336 336 unlink($zip_file); 337 throw new Exception(sprintf(__('Unable to upgrade "%s". (older or same version)'),basename($destination))); 337 throw new Exception(sprintf(__('Unable to upgrade "%s". (older or same version)'),basename($destination))); 338 338 } 339 339 } … … 342 342 $zip->close(); 343 343 unlink($zip_file); 344 throw new Exception(sprintf(__('Unable to read new _define.php file'))); 344 throw new Exception(sprintf(__('Unable to read new _define.php file'))); 345 345 } 346 346 } … … 350 350 return $ret_code; 351 351 } 352 352 353 353 /** 354 354 This method installs all modules having a _install file. 355 355 356 356 @see dcModules::installModule 357 357 */ … … 368 368 } 369 369 } 370 370 371 371 return $res; 372 372 } 373 373 374 374 /** 375 375 This method installs module with ID <var>$id</var> and having a _install 376 376 file. This file should throw exception on failure or true if it installs 377 377 successfully. 378 378 379 379 <var>$msg</var> is an out parameter that handle installer message. 380 380 381 381 @param id <b>string</b> Module ID 382 382 @param msg <b>string</b> Module installer message … … 394 394 return false; 395 395 } 396 396 397 397 return null; 398 398 } 399 399 400 400 public function deleteModule($id,$disabled=false) 401 401 { … … 405 405 $p =& $this->modules; 406 406 } 407 407 408 408 if (!isset($p[$id])) { 409 409 throw new Exception(__('No such module.')); 410 410 } 411 411 412 412 if (!files::deltree($p[$id]['root'])) { 413 413 throw new Exception(__('Cannot remove module files')); 414 414 } 415 415 } 416 416 417 417 public function deactivateModule($id) 418 418 { … … 420 420 throw new Exception(__('No such module.')); 421 421 } 422 422 423 423 if (!$this->modules[$id]['root_writable']) { 424 424 throw new Exception(__('Cannot deactivate plugin.')); 425 425 } 426 426 427 427 if (@file_put_contents($this->modules[$id]['root'].'/_disabled','')) { 428 428 throw new Exception(__('Cannot deactivate plugin.')); 429 429 } 430 430 } 431 431 432 432 public function activateModule($id) 433 433 { … … 435 435 throw new Exception(__('No such module.')); 436 436 } 437 437 438 438 if (!$this->disabled[$id]['root_writable']) { 439 439 throw new Exception(__('Cannot activate plugin.')); 440 440 } 441 441 442 442 if (@unlink($this->disabled[$id]['root'].'/_disabled') === false) { 443 443 throw new Exception(__('Cannot activate plugin.')); 444 444 } 445 445 } 446 446 447 447 /** 448 448 This method will search for file <var>$file</var> in language 449 449 <var>$lang</var> for module <var>$id</var>. 450 450 451 451 <var>$file</var> should not have any extension. 452 452 453 453 @param id <b>string</b> Module ID 454 454 @param lang <b>string</b> Language code … … 460 460 return; 461 461 } 462 462 463 463 $lfile = $this->modules[$id]['root'].'/locales/%s/%s'; 464 464 if (l10n::set(sprintf($lfile,$lang,$file)) === false && $lang != 'en') { … … 466 466 } 467 467 } 468 468 469 469 public function loadModuleL10Nresources($id,$lang) 470 470 { … … 472 472 return; 473 473 } 474 474 475 475 $f = l10n::getFilePath($this->modules[$id]['root'].'/locales','resources.php',$lang); 476 476 if ($f) { … … 478 478 } 479 479 } 480 480 481 481 /** 482 482 Returns all modules associative array or only one module if <var>$id</var> 483 483 is present. 484 484 485 485 @param id <b>string</b> Optionnal module ID 486 486 @return <b>array</b> … … 493 493 return $this->modules; 494 494 } 495 495 496 496 /** 497 497 Returns true if the module with ID <var>$id</var> exists. 498 498 499 499 @param id <b>string</b> Module ID 500 500 @return <b>boolean</b> … … 504 504 return isset($this->modules[$id]); 505 505 } 506 506 507 507 /** 508 508 Returns all disabled modules in an array 509 509 510 510 @return <b>array</b> 511 511 */ … … 514 514 return $this->disabled; 515 515 } 516 516 517 517 /** 518 518 Returns root path for module with ID <var>$id</var>. 519 519 520 520 @param id <b>string</b> Module ID 521 521 @return <b>string</b> … … 525 525 return $this->moduleInfo($id,'root'); 526 526 } 527 527 528 528 /** 529 529 Returns a module information that could be: … … 535 535 - permissions 536 536 - priority 537 537 538 538 @param id <b>string</b> Module ID 539 539 @param info <b>string</b> Information to retrieve … … 544 544 return isset($this->modules[$id][$info]) ? $this->modules[$id][$info] : null; 545 545 } 546 546 547 547 /** 548 548 Loads namespace <var>$ns</var> specific files for all modules. 549 549 550 550 @param ns <b>string</b> Namespace name 551 551 */ … … 556 556 } 557 557 } 558 558 559 559 /** 560 560 Loads namespace <var>$ns</var> specific file for module with ID 561 561 <var>$id</var> 562 562 563 563 @param id <b>string</b> Module ID 564 564 @param ns <b>string</b> Namespace name … … 578 578 } 579 579 } 580 580 581 581 public function getErrors() 582 582 { 583 583 return $this->errors; 584 584 } 585 585 586 586 protected function loadModuleFile($________) 587 587 { … … 589 589 return; 590 590 } 591 591 592 592 self::$_k = array_keys($GLOBALS); 593 593 594 594 foreach (self::$_k as self::$_n) { 595 595 if (!in_array(self::$_n,self::$superglobals)) { … … 597 597 } 598 598 } 599 599 600 600 return require $________; 601 601 } 602 602 603 603 private function sortModules($a,$b) 604 604 { … … 606 606 return strcasecmp($a['name'],$b['name']); 607 607 } 608 608 609 609 return ($a['priority'] < $b['priority']) ? -1 : 1; 610 610 } 611 611 } 612 ?>
Note: See TracChangeset
for help on using the changeset viewer.