Dotclear


Ignore:
Timestamp:
11/17/13 20:25:53 (12 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
2.6
Children:
2567:6c11245cbf04, 2568:61c67a7d17fa
Message:

Add some people in CREDITS, remove trailing spaces and tabs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.modules.php

    r2492 r2566  
    1616@brief Modules handler 
    1717 
    18 Provides an object to handle modules (themes or plugins).  
     18Provides an object to handle modules (themes or plugins). 
    1919*/ 
    2020class dcModules 
     
    2626     protected $errors = array(); 
    2727     protected $modules_names = array(); 
    28       
     28 
    2929     protected $id; 
    3030     protected $mroot; 
    31       
     31 
    3232     # Inclusion variables 
    3333     protected static $superglobals = array('GLOBALS','_SERVER','_GET','_POST','_COOKIE','_FILES','_ENV','_REQUEST','_SESSION'); 
     
    3636 
    3737     protected static $type = null; 
    38       
     38 
    3939     public $core;  ///< <b>dcCore</b>  dcCore instance 
    40       
     40 
    4141     /** 
    4242     Object constructor. 
    43       
     43 
    4444     @param    core      <b>dcCore</b>  dcCore instance 
    4545     */ 
     
    4848          $this->core =& $core; 
    4949     } 
    50       
     50 
    5151     /** 
    5252     Loads modules. <var>$path</var> could be a separated list of paths 
    5353     (path separator depends on your OS). 
    54       
     54 
    5555     <var>$ns</var> indicates if an additionnal file needs to be loaded on plugin 
    5656     load, value could be: 
     
    5858     - public (loads module's _public.php) 
    5959     - xmlrpc (loads module's _xmlrpc.php) 
    60       
     60 
    6161     <var>$lang</var> indicates if we need to load a lang file on plugin 
    6262     loading. 
     
    6666          $this->path = explode(PATH_SEPARATOR,$path); 
    6767          $this->ns = $ns; 
    68            
     68 
    6969          $disabled = isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode']; 
    7070          $disabled = $disabled && !get_parent_class($this) ? true : false; 
    71            
     71 
    7272          foreach ($this->path as $root) 
    7373          { 
     
    7575                    continue; 
    7676               } 
    77                 
     77 
    7878               if (substr($root,-1) != '/') { 
    7979                    $root .= '/'; 
    8080               } 
    81                 
     81 
    8282               if (($d = @dir($root)) === false) { 
    8383                    continue; 
    8484               } 
    85                 
     85 
    8686               while (($entry = $d->read()) !== false) 
    8787               { 
    8888                    $full_entry = $root.$entry; 
    89                      
     89 
    9090                    if ($entry != '.' && $entry != '..' && is_dir($full_entry) 
    9191                    && file_exists($full_entry.'/_define.php')) 
     
    110110               $d->close(); 
    111111          } 
    112            
     112 
    113113          # Sort plugins 
    114114          uasort($this->modules,array($this,'sortModules')); 
    115            
     115 
    116116          # Load translation, _prepend and ns_file 
    117117          foreach ($this->modules as $id => $m) 
     
    120120               { 
    121121                    $r = $this->loadModuleFile($m['root'].'/_prepend.php'); 
    122                      
     122 
    123123                    # If _prepend.php file returns null (ie. it has a void return statement) 
    124124                    if (is_null($r)) { 
     
    127127                    unset($r); 
    128128               } 
    129                 
     129 
    130130               $this->loadModuleL10N($id,$lang,'main'); 
    131131               if ($ns == 'admin') { 
     
    135135          } 
    136136     } 
    137       
     137 
    138138     public function requireDefine($dir,$id) 
    139139     { 
     
    143143               $this->id = null; 
    144144          } 
    145      }     
    146       
     145     } 
     146 
    147147     /** 
    148148     This method registers a module in modules list. You should use this to 
    149149     register a new module. 
    150       
     150 
    151151     <var>$permissions</var> is a comma separated list of permissions for your 
    152152     module. If <var>$permissions</var> is null, only super admin has access to 
    153153     this module. 
    154       
     154 
    155155     <var>$priority</var> is an integer. Modules are sorted by priority and name. 
    156156     Lowest priority comes first. 
    157       
     157 
    158158     @param    name           <b>string</b>       Module name 
    159159     @param    desc           <b>string</b>       Module description 
    160160     @param    author         <b>string</b>       Module author name 
    161161     @param    version        <b>string</b>       Module version 
    162      @param    properties     <b>array</b>        extra properties  
     162     @param    properties     <b>array</b>        extra properties 
    163163     (currently available keys : permissions, priority, type) 
    164164     */ 
     
    207207               } 
    208208          } 
    209            
     209 
    210210          # Check module install on multiple path 
    211211          if ($this->id) { 
     
    238238          } 
    239239     } 
    240       
     240 
    241241     public function resetModulesList() 
    242242     { 
     
    244244          $this->modules_names = array(); 
    245245          $this->errors = array(); 
    246      }     
    247       
     246     } 
     247 
    248248     public static function installPackage($zip_file,dcModules &$modules) 
    249249     { 
    250250          $zip = new fileUnzip($zip_file); 
    251251          $zip->getList(false,'#(^|/)(__MACOSX|\.svn|\.hg|\.git|\.DS_Store|\.directory|Thumbs\.db)(/|$)#'); 
    252            
     252 
    253253          $zip_root_dir = $zip->getRootDir(); 
    254254          $define = ''; 
     
    264264               $has_define = $zip->hasFile($define); 
    265265          } 
    266            
     266 
    267267          if ($zip->isEmpty()) { 
    268268               $zip->close(); 
     
    270270               throw new Exception(__('Empty module zip file.')); 
    271271          } 
    272            
     272 
    273273          if (!$has_define) { 
    274274               $zip->close(); 
     
    276276               throw new Exception(__('The zip file does not appear to be a valid Dotclear module.')); 
    277277          } 
    278            
     278 
    279279          $ret_code = 1; 
    280            
     280 
    281281          if (!is_dir($destination)) 
    282282          { 
    283283               try { 
    284284                    files::makeDir($destination,true); 
    285                      
     285 
    286286                    $sandbox = clone $modules; 
    287287                    $zip->unzip($define, $target.'/_define.php'); 
    288                      
     288 
    289289                    $sandbox->resetModulesList(); 
    290290                    $sandbox->requireDefine($target,basename($destination)); 
    291291                    unlink($target.'/_define.php'); 
    292                      
     292 
    293293                    $new_errors = $sandbox->getErrors(); 
    294294                    if (!empty($new_errors)) { 
     
    296296                         throw new Exception($new_errors); 
    297297                    } 
    298                      
     298 
    299299                    files::deltree($destination); 
    300300               } 
     
    304304                    unlink($zip_file); 
    305305                    files::deltree($destination); 
    306                     throw new Exception($e->getMessage());        
     306                    throw new Exception($e->getMessage()); 
    307307               } 
    308308          } 
     
    312312               $sandbox = clone $modules; 
    313313               $zip->unzip($define, $target.'/_define.php'); 
    314                 
     314 
    315315               $sandbox->resetModulesList(); 
    316316               $sandbox->requireDefine($target,basename($destination)); 
    317317               unlink($target.'/_define.php'); 
    318318               $new_modules = $sandbox->getModules(); 
    319                 
     319 
    320320               if (!empty($new_modules)) 
    321321               { 
     
    335335                         $zip->close(); 
    336336                         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))); 
    338338                    } 
    339339               } 
     
    342342                    $zip->close(); 
    343343                    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'))); 
    345345               } 
    346346          } 
     
    350350          return $ret_code; 
    351351     } 
    352       
     352 
    353353     /** 
    354354     This method installs all modules having a _install file. 
    355       
     355 
    356356     @see dcModules::installModule 
    357357     */ 
     
    368368               } 
    369369          } 
    370            
     370 
    371371          return $res; 
    372372     } 
    373       
     373 
    374374     /** 
    375375     This method installs module with ID <var>$id</var> and having a _install 
    376376     file. This file should throw exception on failure or true if it installs 
    377377     successfully. 
    378       
     378 
    379379     <var>$msg</var> is an out parameter that handle installer message. 
    380       
     380 
    381381     @param    id        <b>string</b>       Module ID 
    382382     @param    msg       <b>string</b>       Module installer message 
     
    394394               return false; 
    395395          } 
    396            
     396 
    397397          return null; 
    398398     } 
    399       
     399 
    400400     public function deleteModule($id,$disabled=false) 
    401401     { 
     
    405405               $p =& $this->modules; 
    406406          } 
    407            
     407 
    408408          if (!isset($p[$id])) { 
    409409               throw new Exception(__('No such module.')); 
    410410          } 
    411            
     411 
    412412          if (!files::deltree($p[$id]['root'])) { 
    413413               throw new Exception(__('Cannot remove module files')); 
    414414          } 
    415415     } 
    416       
     416 
    417417     public function deactivateModule($id) 
    418418     { 
     
    420420               throw new Exception(__('No such module.')); 
    421421          } 
    422            
     422 
    423423          if (!$this->modules[$id]['root_writable']) { 
    424424               throw new Exception(__('Cannot deactivate plugin.')); 
    425425          } 
    426            
     426 
    427427          if (@file_put_contents($this->modules[$id]['root'].'/_disabled','')) { 
    428428               throw new Exception(__('Cannot deactivate plugin.')); 
    429429          } 
    430430     } 
    431       
     431 
    432432     public function activateModule($id) 
    433433     { 
     
    435435               throw new Exception(__('No such module.')); 
    436436          } 
    437            
     437 
    438438          if (!$this->disabled[$id]['root_writable']) { 
    439439               throw new Exception(__('Cannot activate plugin.')); 
    440440          } 
    441            
     441 
    442442          if (@unlink($this->disabled[$id]['root'].'/_disabled') === false) { 
    443443               throw new Exception(__('Cannot activate plugin.')); 
    444444          } 
    445445     } 
    446       
     446 
    447447     /** 
    448448     This method will search for file <var>$file</var> in language 
    449449     <var>$lang</var> for module <var>$id</var>. 
    450       
     450 
    451451     <var>$file</var> should not have any extension. 
    452       
     452 
    453453     @param    id        <b>string</b>       Module ID 
    454454     @param    lang      <b>string</b>       Language code 
     
    460460               return; 
    461461          } 
    462            
     462 
    463463          $lfile = $this->modules[$id]['root'].'/locales/%s/%s'; 
    464464          if (l10n::set(sprintf($lfile,$lang,$file)) === false && $lang != 'en') { 
     
    466466          } 
    467467     } 
    468       
     468 
    469469     public function loadModuleL10Nresources($id,$lang) 
    470470     { 
     
    472472               return; 
    473473          } 
    474            
     474 
    475475          $f = l10n::getFilePath($this->modules[$id]['root'].'/locales','resources.php',$lang); 
    476476          if ($f) { 
     
    478478          } 
    479479     } 
    480       
     480 
    481481     /** 
    482482     Returns all modules associative array or only one module if <var>$id</var> 
    483483     is present. 
    484       
     484 
    485485     @param    id        <b>string</b>       Optionnal module ID 
    486486     @return   <b>array</b> 
     
    493493          return $this->modules; 
    494494     } 
    495       
     495 
    496496     /** 
    497497     Returns true if the module with ID <var>$id</var> exists. 
    498       
     498 
    499499     @param    id        <b>string</b>       Module ID 
    500500     @return   <b>boolean</b> 
     
    504504          return isset($this->modules[$id]); 
    505505     } 
    506       
     506 
    507507     /** 
    508508     Returns all disabled modules in an array 
    509       
     509 
    510510     @return   <b>array</b> 
    511511     */ 
     
    514514          return $this->disabled; 
    515515     } 
    516       
     516 
    517517     /** 
    518518     Returns root path for module with ID <var>$id</var>. 
    519       
     519 
    520520     @param    id        <b>string</b>       Module ID 
    521521     @return   <b>string</b> 
     
    525525          return $this->moduleInfo($id,'root'); 
    526526     } 
    527       
     527 
    528528     /** 
    529529     Returns a module information that could be: 
     
    535535     - permissions 
    536536     - priority 
    537       
     537 
    538538     @param    id        <b>string</b>       Module ID 
    539539     @param    info      <b>string</b>       Information to retrieve 
     
    544544          return isset($this->modules[$id][$info]) ? $this->modules[$id][$info] : null; 
    545545     } 
    546       
     546 
    547547     /** 
    548548     Loads namespace <var>$ns</var> specific files for all modules. 
    549       
     549 
    550550     @param    ns        <b>string</b>       Namespace name 
    551551     */ 
     
    556556          } 
    557557     } 
    558       
     558 
    559559     /** 
    560560     Loads namespace <var>$ns</var> specific file for module with ID 
    561561     <var>$id</var> 
    562       
     562 
    563563     @param    id        <b>string</b>       Module ID 
    564564     @param    ns        <b>string</b>       Namespace name 
     
    578578          } 
    579579     } 
    580       
     580 
    581581     public function getErrors() 
    582582     { 
    583583          return $this->errors; 
    584584     } 
    585       
     585 
    586586     protected function loadModuleFile($________) 
    587587     { 
     
    589589               return; 
    590590          } 
    591            
     591 
    592592          self::$_k = array_keys($GLOBALS); 
    593            
     593 
    594594          foreach (self::$_k as self::$_n) { 
    595595               if (!in_array(self::$_n,self::$superglobals)) { 
     
    597597               } 
    598598          } 
    599            
     599 
    600600          return require $________; 
    601601     } 
    602       
     602 
    603603     private function sortModules($a,$b) 
    604604     { 
     
    606606               return strcasecmp($a['name'],$b['name']); 
    607607          } 
    608            
     608 
    609609          return ($a['priority'] < $b['priority']) ? -1 : 1; 
    610610     } 
    611611} 
    612 ?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map