Dotclear

Changeset 2239:cd7100fa57db


Ignore:
Timestamp:
10/04/13 00:53:07 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
default
Children:
2240:2553775ae2fe, 2242:f31162da2395
Message:

Prevent install theme as plugin and vice versa by adding property "type" to modules definition, fixes #1713

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • admin/index.php

    r2229 r2239  
    258258if ($core->auth->isSuperAdmin()) 
    259259{ 
    260      $list = array(); 
    261      foreach ($core->plugins->getErrors() as $k => $error) { 
    262           $list[] = '<li>'.$error.'</li>'; 
    263      } 
    264       
    265      if (count($list) > 0) { 
     260     $list = $core->plugins->getErrors(); 
     261     if (!empty($list)) { 
    266262          echo  
    267           '<div class="error" id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '. 
    268           '<ul>'.implode("\n",$list).'</ul></div>'; 
     263          '<div class="error" id="module-errors" class="error"><p>'.__('Errors have occured with following plugins:').'</p> '. 
     264          '<ul><li>'.implode("</li>\n<li>", $list).'</li></ul></div>'; 
    269265     } 
    270266} 
  • inc/core/class.dc.modules.php

    r2095 r2239  
    3535     protected static $_k; 
    3636     protected static $_n; 
     37 
     38     protected static $type = 'plugin'; 
    3739      
    3840     public $core;  ///< <b>dcCore</b>  dcCore instance 
     
    177179               array( 
    178180                    'permissions' => null, 
    179                     'priority' => 1000 
     181                    'priority' => 1000, 
     182                    'standalone_config' => false, 
     183                    'type' => null 
    180184               ), $properties 
    181185          ); 
     186 
     187          if ($properties['type'] !== null && $properties['type'] != self::$type) { 
     188               $this->errors[] = sprintf( 
     189                    __('Module "%s" has type "%s" that mismatch required module type "%s".'), 
     190                    '<strong>'.html::escapeHTML($name).'</strong>', 
     191                    '<em>'.html::escapeHTML($properties['type']).'</em>', 
     192                    '<em>'.html::escapeHTML(self::$type).'</em>' 
     193               ); 
     194               return; 
     195          } 
     196 
    182197          $permissions = $properties['permissions']; 
    183198          if ($this->ns == 'admin') { 
     
    210225                    $path2 = path::real($this->mroot); 
    211226                    $this->errors[] = sprintf( 
    212                          __('%s: in [%s] and [%s]'), 
     227                         __('Module "%s" is installed twice in "%s" and "%s".'), 
    213228                         '<strong>'.$name.'</strong>', 
    214229                         '<em>'.$path1.'</em>', 
     
    223238          $this->modules = array(); 
    224239          $this->modules_names = array(); 
     240          $this->errors = array(); 
    225241     }     
    226242      
     
    258274          $ret_code = 1; 
    259275           
    260           if (is_dir($destination)) 
     276          if (!is_dir($destination)) 
     277          { 
     278               try { 
     279                    files::makeDir($destination,true); 
     280                     
     281                    $sandbox = clone $modules; 
     282                    $zip->unzip($define, $target.'/_define.php'); 
     283                     
     284                    $sandbox->resetModulesList(); 
     285                    $sandbox->requireDefine($target,basename($destination)); 
     286                    unlink($target.'/_define.php'); 
     287                     
     288                    $new_errors = $sandbox->getErrors(); 
     289                    if (!empty($new_errors)) { 
     290                         $new_errors = is_array($new_errors) ? implode(" \n",$new_errors) : $new_errors; 
     291                         throw new Exception($new_errors); 
     292                    } 
     293                     
     294                    files::deltree($destination); 
     295               } 
     296               catch(Exception $e) 
     297               { 
     298                    $zip->close(); 
     299                    unlink($zip_file); 
     300                    files::deltree($destination); 
     301                    throw new Exception($e->getMessage());        
     302               } 
     303          } 
     304          else 
    261305          { 
    262306               # test for update 
  • inc/core/class.dc.themes.php

    r1179 r2239  
    2323class dcThemes extends dcModules 
    2424{     
     25     protected static $type = 'theme'; 
     26 
    2527     /** 
    2628     This method registers a theme in modules list. You should use this to 
     
    5860                    'parent' => null, 
    5961                    'priority' => 1000, 
    60                     'standalone_config' => false 
     62                    'standalone_config' => false, 
     63                    'type' => null 
    6164               ), $properties 
    6265          ); 
     66 
     67          if ($properties['type'] !== null && $properties['type'] != self::$type) { 
     68               $this->errors[] = sprintf( 
     69                    __('Module "%s" has type "%s" that mismatch required module type "%s".'), 
     70                    '<strong>'.html::escapeHTML($name).'</strong>', 
     71                    '<em>'.html::escapeHTML($properties['type']).'</em>', 
     72                    '<em>'.html::escapeHTML(self::$type).'</em>' 
     73               ); 
     74               return; 
     75          } 
     76 
    6377          if ($this->id) { 
    6478               $this->modules[$this->id] = array_merge( 
Note: See TracChangeset for help on using the changeset viewer.

Sites map