Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

Location:
plugins/themeEditor
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • plugins/themeEditor/_define.php

    r3333 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414$this->registerModule( 
    15      /* Name */               "themeEditor", 
    16      /* Description*/         "Theme Editor", 
    17      /* Author */             "Olivier Meunier", 
    18      /* Version */            '1.3', 
    19      array( 
    20           'type'         =>        'plugin', 
    21           'settings'     =>        array( 
    22                                         'pref' => '#user-options.themeEditor_prefs' 
    23                                    ) 
    24      ) 
     15    "themeEditor",     // Name 
     16    "Theme Editor",    // Description 
     17    "Olivier Meunier", // Author 
     18    '1.3',             // Version 
     19    array( 
     20        'type'     => 'plugin', 
     21        'settings' => array( 
     22            'pref' => '#user-options.themeEditor_prefs' 
     23        ) 
     24    ) 
    2525); 
  • plugins/themeEditor/class.themeEditor.php

    r2981 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcThemeEditor 
    1515{ 
    16      protected $core; 
    17  
    18      protected $user_theme; 
    19      protected $parent_theme; 
    20      protected $tplset_theme; 
    21  
    22      protected $parent_name; 
    23      protected $tplset_name; 
    24  
    25      public $tpl = array(); 
    26      public $css = array(); 
    27      public $js  = array(); 
    28      public $po  = array(); 
    29  
    30      public function __construct($core) 
    31      { 
    32           $this->core =& $core; 
    33           $this->default_theme = path::real($this->core->blog->themes_path.'/default'); 
    34           $this->user_theme = path::real($this->core->blog->themes_path.'/'.$this->core->blog->settings->system->theme); 
    35           $this->tplset_theme = DC_ROOT.'/inc/public/default-templates/'.DC_DEFAULT_TPLSET; 
    36           $this->tplset_name = DC_DEFAULT_TPLSET; 
    37           if (null !== $this->core->themes) { 
    38                $parent_theme = $this->core->themes->moduleInfo($this->core->blog->settings->system->theme,'parent'); 
    39                if ($parent_theme) { 
    40                     $this->parent_theme = path::real($this->core->blog->themes_path.'/'.$parent_theme); 
    41                     $this->parent_name = $parent_theme; 
    42                } 
    43                $tplset = $this->core->themes->moduleInfo($this->core->blog->settings->system->theme,'tplset'); 
    44                if ($tplset) { 
    45                     $this->tplset_theme = DC_ROOT.'/inc/public/default-templates/'.$tplset; 
    46                     $this->tplset_name = $tplset; 
    47                } 
    48           } 
    49           $this->findTemplates(); 
    50           $this->findStyles(); 
    51           $this->findScripts(); 
    52           $this->findLocales(); 
    53      } 
    54  
    55      public function filesList($type,$item='%1$s',$split=true) 
    56      { 
    57           $files = $this->getFilesFromType($type); 
    58  
    59           if (empty($files)) { 
    60                return '<p>'.__('No file').'</p>'; 
    61           } 
    62  
    63           $list = ''; 
    64           if ($split) { 
    65                $list_theme = '';   // Files from current theme 
    66                $list_parent = '';  // Files from parent of current theme 
    67                $list_tpl = '';          // Files from template set used by current theme 
    68                foreach ($files as $k => $v) 
    69                { 
    70                     if (strpos($v,$this->user_theme) === 0) { 
    71                          $li = sprintf('<li class="default-file">%s</li>',$item); 
    72                          $list_theme .= sprintf($li,$k,html::escapeHTML($k)); 
    73                     } elseif ($this->parent_theme && strpos($v,$this->parent_theme) === 0) { 
    74                          $li = sprintf('<li class="parent-file">%s</li>',$item); 
    75                          $list_parent .= sprintf($li,$k,html::escapeHTML($k)); 
    76                     } else { 
    77                          $li = sprintf('<li>%s</li>',$item); 
    78                          $list_tpl .= sprintf($li,$k,html::escapeHTML($k)); 
    79                     } 
    80                } 
    81                $list .= ($list_theme != '' ? sprintf('<li class="group-file">'.__('From theme:').'<ul>%s</ul></li>',$list_theme) : ''); 
    82                $list .= ($list_parent != '' ? sprintf('<li class="group-file">'.__('From parent:').' %s<ul>%s</ul></li>', 
    83                     $this->parent_name,$list_parent) : ''); 
    84                $list .= ($list_tpl != '' ? sprintf('<li class="group-file">'.__('From template set:').' %s<ul>%s</ul></li>', 
    85                     $this->tplset_name,$list_tpl) : ''); 
    86           } else { 
    87                foreach ($files as $k => $v) 
    88                { 
    89                     if (strpos($v,$this->user_theme) === 0) { 
    90                          $li = sprintf('<li class="default-file">%s</li>',$item); 
    91                     } elseif ($this->parent_theme && strpos($v,$this->parent_theme) === 0) { 
    92                          $li = sprintf('<li class="parent-file">%s</li>',$item); 
    93                     } else { 
    94                          $li = sprintf('<li>%s</li>',$item); 
    95                     } 
    96                     $list .= sprintf($li,$k,html::escapeHTML($k)); 
    97                } 
    98           } 
    99  
    100           return sprintf('<ul>%s</ul>',$list); 
    101      } 
    102  
    103      public function getFileContent($type,$f) 
    104      { 
    105           $files = $this->getFilesFromType($type); 
    106  
    107           if (!isset($files[$f])) { 
    108                throw new Exception(__('File does not exist.')); 
    109           } 
    110  
    111           $F = $files[$f]; 
    112           if (!is_readable($F)) { 
    113                throw new Exception(sprintf(__('File %s is not readable'),$f)); 
    114           } 
    115  
    116           return array( 
    117                'c' => file_get_contents($F), 
    118                'w' => $this->getDestinationFile($type,$f) !== false, 
    119                'type' => $type, 
    120                'f' => $f 
    121           ); 
    122      } 
    123  
    124      public function writeFile($type,$f,$content) 
    125      { 
    126           $files = $this->getFilesFromType($type); 
    127  
    128           if (!isset($files[$f])) { 
    129                throw new Exception(__('File does not exist.')); 
    130           } 
    131  
    132           try 
    133           { 
    134                $dest = $this->getDestinationFile($type,$f); 
    135  
    136                if ($dest == false) { 
    137                     throw new Exception(); 
    138                } 
    139  
    140                if ($type == 'tpl' && !is_dir(dirname($dest))) { 
    141                     files::makeDir(dirname($dest)); 
    142                } 
    143  
    144                if ($type == 'po' && !is_dir(dirname($dest))) { 
    145                     files::makeDir(dirname($dest)); 
    146                } 
    147  
    148                $fp = @fopen($dest,'wb'); 
    149                if (!$fp) { 
    150                     throw new Exception('tocatch'); 
    151                } 
    152  
    153                $content = preg_replace('/(\r?\n)/m',"\n",$content); 
    154                $content = preg_replace('/\r/m',"\n",$content); 
    155  
    156                fwrite($fp,$content); 
    157                fclose($fp); 
    158  
    159                # Updating inner files list 
    160                $this->updateFileInList($type,$f,$dest); 
    161           } 
    162           catch (Exception $e) 
    163           { 
    164                throw new Exception(sprintf(__('Unable to write file %s. Please check your theme files and folders permissions.'),$f)); 
    165           } 
    166      } 
    167  
    168      public function deletableFile($type,$f) 
    169      { 
    170           if ($type != 'tpl') { 
    171                // Only tpl files may be deleted 
    172                return false; 
    173           } 
    174  
    175           $files = $this->getFilesFromType($type); 
    176           if (isset($files[$f])) { 
    177                $dest = $this->getDestinationFile($type,$f); 
    178                if ($dest) { 
    179                     if (file_exists($dest) && is_writable($dest)) { 
    180                          // Is there a model (parent theme or template set) ? 
    181                          if (isset($this->tpl_model[$f])) { 
    182                               return true; 
    183                          } 
    184                     } 
    185                } 
    186           } 
    187           return false; 
    188      } 
    189  
    190      public function deleteFile($type,$f) 
    191      { 
    192           if ($type != 'tpl') { 
    193                // Only tpl files may be deleted 
    194                return; 
    195           } 
    196  
    197           $files = $this->getFilesFromType($type); 
    198           if (!isset($files[$f])) { 
    199                throw new Exception(__('File does not exist.')); 
    200           } 
    201  
    202           try 
    203           { 
    204                $dest = $this->getDestinationFile($type,$f); 
    205                if ($dest) { 
    206                     // File exists and may be deleted 
    207                     unlink($dest); 
    208  
    209                     // Updating template files list 
    210                     $this->findTemplates(); 
    211                } 
    212           } 
    213           catch (Exception $e) 
    214           { 
    215                throw new Exception(sprintf(__('Unable to delete file %s. Please check your theme files and folders permissions.'),$f)); 
    216           } 
    217      } 
    218  
    219      protected function getDestinationFile($type,$f) 
    220      { 
    221           if ($type == 'tpl') { 
    222                $dest = $this->user_theme.'/tpl/'.$f; 
    223           } elseif ($type == 'po') { 
    224                $dest = $this->user_theme.'/locales/'.$f; 
    225           } else { 
    226                $dest = $this->user_theme.'/'.$f; 
    227           } 
    228  
    229           if (file_exists($dest) && is_writable($dest)) { 
    230                return $dest; 
    231           } 
    232  
    233           if ($type == 'tpl' && !is_dir(dirname($dest))) { 
    234                if (is_writable($this->user_theme)) { 
    235                     return $dest; 
    236                } 
    237           } 
    238  
    239           if ($type == 'po' && !is_dir(dirname($dest))) { 
    240                if (is_writable($this->user_theme)) { 
    241                     return $dest; 
    242                } 
    243           } 
    244  
    245           if (is_writable(dirname($dest))) { 
    246                return $dest; 
    247           } 
    248  
    249           return false; 
    250      } 
    251  
    252      protected function getFilesFromType($type) 
    253      { 
    254           switch ($type) 
    255           { 
    256                case 'tpl': 
    257                     return $this->tpl; 
    258                case 'css': 
    259                     return $this->css; 
    260                case 'js': 
    261                     return $this->js; 
    262                case 'po': 
    263                     return $this->po; 
    264                default: 
    265                     return array(); 
    266           } 
    267      } 
    268  
    269      protected function updateFileInList($type,$f,$file) 
    270      { 
    271           switch ($type) 
    272           { 
    273                case 'tpl': 
    274                     $list =& $this->tpl; 
    275                     break; 
    276                case 'css': 
    277                     $list =& $this->css; 
    278                     break; 
    279                case 'js': 
    280                     $list =& $this->js; 
    281                     break; 
    282                case 'po': 
    283                     $list =& $this->po; 
    284                     break; 
    285                default: 
    286                     return; 
    287           } 
    288  
    289           $list[$f] = $file; 
    290      } 
    291  
    292      protected function findTemplates() 
    293      { 
    294           $this->tpl = array_merge( 
    295                $this->getFilesInDir($this->tplset_theme), 
    296                $this->getFilesInDir($this->parent_theme.'/tpl') 
    297                ); 
    298           $this->tpl_model = $this->tpl; 
    299  
    300           $this->tpl = array_merge($this->tpl,$this->getFilesInDir($this->user_theme.'/tpl')); 
    301  
    302           # Then we look in 'default-templates' plugins directory 
    303           $plugins = $this->core->plugins->getModules(); 
    304           foreach ($plugins as $p) { 
    305                // Looking in default-templates directory 
    306                $this->tpl = array_merge($this->getFilesInDir($p['root'].'/default-templates'),$this->tpl); 
    307                $this->tpl_model = array_merge($this->getFilesInDir($p['root'].'/default-templates'),$this->tpl_model); 
    308                // Looking in default-templates/tplset directory 
    309                $this->tpl = array_merge($this->getFilesInDir($p['root'].'/default-templates/'.$this->tplset_name),$this->tpl); 
    310                $this->tpl_model = array_merge($this->getFilesInDir($p['root'].'/default-templates/'.$this->tplset_name),$this->tpl_model); 
    311           } 
    312  
    313           uksort($this->tpl,array($this,'sortFilesHelper')); 
    314      } 
    315  
    316      protected function findStyles() 
    317      { 
    318           $this->css = $this->getFilesInDir($this->user_theme,'css'); 
    319           $this->css= array_merge($this->css,$this->getFilesInDir($this->user_theme.'/style','css','style/')); 
    320           $this->css= array_merge($this->css,$this->getFilesInDir($this->user_theme.'/css','css','css/')); 
    321      } 
    322  
    323      protected function findScripts() 
    324      { 
    325           $this->js = $this->getFilesInDir($this->user_theme,'js'); 
    326           $this->js = array_merge($this->js,$this->getFilesInDir($this->user_theme.'/js','js','js/')); 
    327      } 
    328  
    329      protected function findLocales() 
    330      { 
    331           $langs = l10n::getISOcodes(1,1); 
    332           foreach ($langs as $k => $v) { 
    333                if ($this->parent_theme) { 
    334                     $this->po = array_merge($this->po,$this->getFilesInDir($this->parent_theme.'/locales/'.$v,'po',$v.'/')); 
    335                } 
    336                $this->po = array_merge($this->po,$this->getFilesInDir($this->user_theme.'/locales/'.$v,'po',$v.'/')); 
    337           } 
    338      } 
    339  
    340      protected function getFilesInDir($dir,$ext=null,$prefix='',$model=null) 
    341      { 
    342           $dir = path::real($dir); 
    343           if (!$dir || !is_dir($dir) || !is_readable($dir)) { 
    344                return array(); 
    345           } 
    346  
    347           $d = dir($dir); 
    348           $res = array(); 
    349           while (($f = $d->read()) !== false) 
    350           { 
    351                if (is_file($dir.'/'.$f) && !preg_match('/^\./',$f) && (!$ext || preg_match('/\.'.preg_quote($ext).'$/i',$f))) { 
    352                     if (!$model || preg_match('/^'.preg_quote($model).'$/i', $f)) { 
    353                          $res[$prefix.$f] = $dir.'/'.$f; 
    354                     } 
    355                } 
    356           } 
    357  
    358           return $res; 
    359      } 
    360  
    361      protected function sortFilesHelper($a,$b) 
    362      { 
    363           if ($a == $b) { 
    364                return 0; 
    365           } 
    366  
    367           $ext_a = files::getExtension($a); 
    368           $ext_b = files::getExtension($b); 
    369  
    370           return strcmp($ext_a.'.'.$a,$ext_b.'.'.$b); 
    371      } 
     16    protected $core; 
     17 
     18    protected $user_theme; 
     19    protected $parent_theme; 
     20    protected $tplset_theme; 
     21 
     22    protected $parent_name; 
     23    protected $tplset_name; 
     24 
     25    public $tpl = array(); 
     26    public $css = array(); 
     27    public $js  = array(); 
     28    public $po  = array(); 
     29 
     30    public function __construct($core) 
     31    { 
     32        $this->core          = &$core; 
     33        $this->default_theme = path::real($this->core->blog->themes_path . '/default'); 
     34        $this->user_theme    = path::real($this->core->blog->themes_path . '/' . $this->core->blog->settings->system->theme); 
     35        $this->tplset_theme  = DC_ROOT . '/inc/public/default-templates/' . DC_DEFAULT_TPLSET; 
     36        $this->tplset_name   = DC_DEFAULT_TPLSET; 
     37        if (null !== $this->core->themes) { 
     38            $parent_theme = $this->core->themes->moduleInfo($this->core->blog->settings->system->theme, 'parent'); 
     39            if ($parent_theme) { 
     40                $this->parent_theme = path::real($this->core->blog->themes_path . '/' . $parent_theme); 
     41                $this->parent_name  = $parent_theme; 
     42            } 
     43            $tplset = $this->core->themes->moduleInfo($this->core->blog->settings->system->theme, 'tplset'); 
     44            if ($tplset) { 
     45                $this->tplset_theme = DC_ROOT . '/inc/public/default-templates/' . $tplset; 
     46                $this->tplset_name  = $tplset; 
     47            } 
     48        } 
     49        $this->findTemplates(); 
     50        $this->findStyles(); 
     51        $this->findScripts(); 
     52        $this->findLocales(); 
     53    } 
     54 
     55    public function filesList($type, $item = '%1$s', $split = true) 
     56    { 
     57        $files = $this->getFilesFromType($type); 
     58 
     59        if (empty($files)) { 
     60            return '<p>' . __('No file') . '</p>'; 
     61        } 
     62 
     63        $list = ''; 
     64        if ($split) { 
     65            $list_theme  = ''; // Files from current theme 
     66            $list_parent = ''; // Files from parent of current theme 
     67            $list_tpl    = ''; // Files from template set used by current theme 
     68            foreach ($files as $k => $v) { 
     69                if (strpos($v, $this->user_theme) === 0) { 
     70                    $li = sprintf('<li class="default-file">%s</li>', $item); 
     71                    $list_theme .= sprintf($li, $k, html::escapeHTML($k)); 
     72                } elseif ($this->parent_theme && strpos($v, $this->parent_theme) === 0) { 
     73                    $li = sprintf('<li class="parent-file">%s</li>', $item); 
     74                    $list_parent .= sprintf($li, $k, html::escapeHTML($k)); 
     75                } else { 
     76                    $li = sprintf('<li>%s</li>', $item); 
     77                    $list_tpl .= sprintf($li, $k, html::escapeHTML($k)); 
     78                } 
     79            } 
     80            $list .= ($list_theme != '' ? sprintf('<li class="group-file">' . __('From theme:') . '<ul>%s</ul></li>', $list_theme) : ''); 
     81            $list .= ($list_parent != '' ? sprintf('<li class="group-file">' . __('From parent:') . ' %s<ul>%s</ul></li>', 
     82                $this->parent_name, $list_parent) : ''); 
     83            $list .= ($list_tpl != '' ? sprintf('<li class="group-file">' . __('From template set:') . ' %s<ul>%s</ul></li>', 
     84                $this->tplset_name, $list_tpl) : ''); 
     85        } else { 
     86            foreach ($files as $k => $v) { 
     87                if (strpos($v, $this->user_theme) === 0) { 
     88                    $li = sprintf('<li class="default-file">%s</li>', $item); 
     89                } elseif ($this->parent_theme && strpos($v, $this->parent_theme) === 0) { 
     90                    $li = sprintf('<li class="parent-file">%s</li>', $item); 
     91                } else { 
     92                    $li = sprintf('<li>%s</li>', $item); 
     93                } 
     94                $list .= sprintf($li, $k, html::escapeHTML($k)); 
     95            } 
     96        } 
     97 
     98        return sprintf('<ul>%s</ul>', $list); 
     99    } 
     100 
     101    public function getFileContent($type, $f) 
     102    { 
     103        $files = $this->getFilesFromType($type); 
     104 
     105        if (!isset($files[$f])) { 
     106            throw new Exception(__('File does not exist.')); 
     107        } 
     108 
     109        $F = $files[$f]; 
     110        if (!is_readable($F)) { 
     111            throw new Exception(sprintf(__('File %s is not readable'), $f)); 
     112        } 
     113 
     114        return array( 
     115            'c'    => file_get_contents($F), 
     116            'w'    => $this->getDestinationFile($type, $f) !== false, 
     117            'type' => $type, 
     118            'f'    => $f 
     119        ); 
     120    } 
     121 
     122    public function writeFile($type, $f, $content) 
     123    { 
     124        $files = $this->getFilesFromType($type); 
     125 
     126        if (!isset($files[$f])) { 
     127            throw new Exception(__('File does not exist.')); 
     128        } 
     129 
     130        try 
     131        { 
     132            $dest = $this->getDestinationFile($type, $f); 
     133 
     134            if ($dest == false) { 
     135                throw new Exception(); 
     136            } 
     137 
     138            if ($type == 'tpl' && !is_dir(dirname($dest))) { 
     139                files::makeDir(dirname($dest)); 
     140            } 
     141 
     142            if ($type == 'po' && !is_dir(dirname($dest))) { 
     143                files::makeDir(dirname($dest)); 
     144            } 
     145 
     146            $fp = @fopen($dest, 'wb'); 
     147            if (!$fp) { 
     148                throw new Exception('tocatch'); 
     149            } 
     150 
     151            $content = preg_replace('/(\r?\n)/m', "\n", $content); 
     152            $content = preg_replace('/\r/m', "\n", $content); 
     153 
     154            fwrite($fp, $content); 
     155            fclose($fp); 
     156 
     157            # Updating inner files list 
     158            $this->updateFileInList($type, $f, $dest); 
     159        } catch (Exception $e) { 
     160            throw new Exception(sprintf(__('Unable to write file %s. Please check your theme files and folders permissions.'), $f)); 
     161        } 
     162    } 
     163 
     164    public function deletableFile($type, $f) 
     165    { 
     166        if ($type != 'tpl') { 
     167            // Only tpl files may be deleted 
     168            return false; 
     169        } 
     170 
     171        $files = $this->getFilesFromType($type); 
     172        if (isset($files[$f])) { 
     173            $dest = $this->getDestinationFile($type, $f); 
     174            if ($dest) { 
     175                if (file_exists($dest) && is_writable($dest)) { 
     176                    // Is there a model (parent theme or template set) ? 
     177                    if (isset($this->tpl_model[$f])) { 
     178                        return true; 
     179                    } 
     180                } 
     181            } 
     182        } 
     183        return false; 
     184    } 
     185 
     186    public function deleteFile($type, $f) 
     187    { 
     188        if ($type != 'tpl') { 
     189            // Only tpl files may be deleted 
     190            return; 
     191        } 
     192 
     193        $files = $this->getFilesFromType($type); 
     194        if (!isset($files[$f])) { 
     195            throw new Exception(__('File does not exist.')); 
     196        } 
     197 
     198        try 
     199        { 
     200            $dest = $this->getDestinationFile($type, $f); 
     201            if ($dest) { 
     202                // File exists and may be deleted 
     203                unlink($dest); 
     204 
     205                // Updating template files list 
     206                $this->findTemplates(); 
     207            } 
     208        } catch (Exception $e) { 
     209            throw new Exception(sprintf(__('Unable to delete file %s. Please check your theme files and folders permissions.'), $f)); 
     210        } 
     211    } 
     212 
     213    protected function getDestinationFile($type, $f) 
     214    { 
     215        if ($type == 'tpl') { 
     216            $dest = $this->user_theme . '/tpl/' . $f; 
     217        } elseif ($type == 'po') { 
     218            $dest = $this->user_theme . '/locales/' . $f; 
     219        } else { 
     220            $dest = $this->user_theme . '/' . $f; 
     221        } 
     222 
     223        if (file_exists($dest) && is_writable($dest)) { 
     224            return $dest; 
     225        } 
     226 
     227        if ($type == 'tpl' && !is_dir(dirname($dest))) { 
     228            if (is_writable($this->user_theme)) { 
     229                return $dest; 
     230            } 
     231        } 
     232 
     233        if ($type == 'po' && !is_dir(dirname($dest))) { 
     234            if (is_writable($this->user_theme)) { 
     235                return $dest; 
     236            } 
     237        } 
     238 
     239        if (is_writable(dirname($dest))) { 
     240            return $dest; 
     241        } 
     242 
     243        return false; 
     244    } 
     245 
     246    protected function getFilesFromType($type) 
     247    { 
     248        switch ($type) { 
     249            case 'tpl': 
     250                return $this->tpl; 
     251            case 'css': 
     252                return $this->css; 
     253            case 'js': 
     254                return $this->js; 
     255            case 'po': 
     256                return $this->po; 
     257            default: 
     258                return array(); 
     259        } 
     260    } 
     261 
     262    protected function updateFileInList($type, $f, $file) 
     263    { 
     264        switch ($type) { 
     265            case 'tpl': 
     266                $list = &$this->tpl; 
     267                break; 
     268            case 'css': 
     269                $list = &$this->css; 
     270                break; 
     271            case 'js': 
     272                $list = &$this->js; 
     273                break; 
     274            case 'po': 
     275                $list = &$this->po; 
     276                break; 
     277            default: 
     278                return; 
     279        } 
     280 
     281        $list[$f] = $file; 
     282    } 
     283 
     284    protected function findTemplates() 
     285    { 
     286        $this->tpl = array_merge( 
     287            $this->getFilesInDir($this->tplset_theme), 
     288            $this->getFilesInDir($this->parent_theme . '/tpl') 
     289        ); 
     290        $this->tpl_model = $this->tpl; 
     291 
     292        $this->tpl = array_merge($this->tpl, $this->getFilesInDir($this->user_theme . '/tpl')); 
     293 
     294        # Then we look in 'default-templates' plugins directory 
     295        $plugins = $this->core->plugins->getModules(); 
     296        foreach ($plugins as $p) { 
     297            // Looking in default-templates directory 
     298            $this->tpl       = array_merge($this->getFilesInDir($p['root'] . '/default-templates'), $this->tpl); 
     299            $this->tpl_model = array_merge($this->getFilesInDir($p['root'] . '/default-templates'), $this->tpl_model); 
     300            // Looking in default-templates/tplset directory 
     301            $this->tpl       = array_merge($this->getFilesInDir($p['root'] . '/default-templates/' . $this->tplset_name), $this->tpl); 
     302            $this->tpl_model = array_merge($this->getFilesInDir($p['root'] . '/default-templates/' . $this->tplset_name), $this->tpl_model); 
     303        } 
     304 
     305        uksort($this->tpl, array($this, 'sortFilesHelper')); 
     306    } 
     307 
     308    protected function findStyles() 
     309    { 
     310        $this->css = $this->getFilesInDir($this->user_theme, 'css'); 
     311        $this->css = array_merge($this->css, $this->getFilesInDir($this->user_theme . '/style', 'css', 'style/')); 
     312        $this->css = array_merge($this->css, $this->getFilesInDir($this->user_theme . '/css', 'css', 'css/')); 
     313    } 
     314 
     315    protected function findScripts() 
     316    { 
     317        $this->js = $this->getFilesInDir($this->user_theme, 'js'); 
     318        $this->js = array_merge($this->js, $this->getFilesInDir($this->user_theme . '/js', 'js', 'js/')); 
     319    } 
     320 
     321    protected function findLocales() 
     322    { 
     323        $langs = l10n::getISOcodes(1, 1); 
     324        foreach ($langs as $k => $v) { 
     325            if ($this->parent_theme) { 
     326                $this->po = array_merge($this->po, $this->getFilesInDir($this->parent_theme . '/locales/' . $v, 'po', $v . '/')); 
     327            } 
     328            $this->po = array_merge($this->po, $this->getFilesInDir($this->user_theme . '/locales/' . $v, 'po', $v . '/')); 
     329        } 
     330    } 
     331 
     332    protected function getFilesInDir($dir, $ext = null, $prefix = '', $model = null) 
     333    { 
     334        $dir = path::real($dir); 
     335        if (!$dir || !is_dir($dir) || !is_readable($dir)) { 
     336            return array(); 
     337        } 
     338 
     339        $d   = dir($dir); 
     340        $res = array(); 
     341        while (($f = $d->read()) !== false) { 
     342            if (is_file($dir . '/' . $f) && !preg_match('/^\./', $f) && (!$ext || preg_match('/\.' . preg_quote($ext) . '$/i', $f))) { 
     343                if (!$model || preg_match('/^' . preg_quote($model) . '$/i', $f)) { 
     344                    $res[$prefix . $f] = $dir . '/' . $f; 
     345                } 
     346            } 
     347        } 
     348 
     349        return $res; 
     350    } 
     351 
     352    protected function sortFilesHelper($a, $b) 
     353    { 
     354        if ($a == $b) { 
     355            return 0; 
     356        } 
     357 
     358        $ext_a = files::getExtension($a); 
     359        $ext_b = files::getExtension($b); 
     360 
     361        return strcmp($ext_a . '.' . $a, $ext_b . '.' . $b); 
     362    } 
    372363} 
  • plugins/themeEditor/style.css

    r3365 r3730  
    11#file-box { 
    2      width: 100%; 
    3      float: left; 
    4      margin-right: -15em; /* was -180px; */ 
     2  width: 100%; 
     3  float: left; 
     4  margin-right: -15em; 
     5  /* was -180px; */ 
    56} 
    6  
    77#file-editor { 
    8      margin-right: 15em; /* was 180px; */ 
     8  margin-right: 15em; 
     9  /* was 180px; */ 
    910} 
    10  
    1111#file-chooser { 
    12      float: right; 
    13      width: 14em; /* was 170px; */ 
     12  float: right; 
     13  width: 14em; 
     14  /* was 170px; */ 
    1415} 
    1516#file-chooser ul { 
    16      padding-left: 0; 
     17  padding-left: 0; 
    1718} 
    1819#file-chooser li { 
    19      list-style: square inside; 
     20  list-style: square inside; 
    2021} 
    2122#file-chooser li.default-file { 
    22      color: #f90; 
    23      font-weight: bold; 
     23  color: #f90; 
     24  font-weight: bold; 
    2425} 
    2526#file-chooser li.parent-file { 
    26      color:#c00; 
     27  color: #c00; 
    2728} 
    2829#file-chooser li.group-file { 
    29      list-style: none; 
    30      margin-bottom: 1em; 
     30  list-style: none; 
     31  margin-bottom: 1em; 
    3132} 
    3233#file-chooser li.group-file ul { 
    33      margin-top: .5em; 
     34  margin-top: .5em; 
    3435} 
    3536textarea { 
    36      font: 1em Monaco,"Courier New",Courier,monospace; 
     37  font: 1em Monaco, "Courier New", Courier, monospace; 
    3738} 
    3839.CodeMirror { 
    39      height: 30em; 
     40  height: 30em; 
    4041} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map