Changeset 2566:9bf417837888 for plugins/themeEditor
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- Location:
- plugins/themeEditor
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/themeEditor/_admin.php
r2370 r2566 38 38 try { 39 39 $core->auth->user_prefs->interface->put('colorsyntax',!empty($_POST['colorsyntax']),'boolean'); 40 } 40 } 41 41 catch (Exception $e) 42 42 { … … 44 44 } 45 45 } 46 46 47 47 public static function adminPreferencesForm($core) 48 48 { … … 50 50 $core->auth->user_prefs->addWorkspace('interface'); 51 51 52 echo 52 echo 53 53 '<p><label for="colorsyntax" class="classic">'. 54 54 form::checkbox('colorsyntax',1,$core->auth->user_prefs->interface->colorsyntax).'</label>'. … … 57 57 } 58 58 } 59 ?> -
plugins/themeEditor/_define.php
r2257 r2566 21 21 ) 22 22 ); 23 ?> -
plugins/themeEditor/class.themeEditor.php
r1179 r2566 15 15 { 16 16 protected $core; 17 17 18 18 protected $default_theme; 19 19 protected $user_theme; 20 20 protected $parent_theme; 21 21 22 22 protected $default_tpl = array(); 23 23 public $tpl = array(); … … 25 25 public $js = array(); 26 26 public $po = array(); 27 27 28 28 public function __construct($core) 29 29 { … … 42 42 $this->findLocales(); 43 43 } 44 44 45 45 public function filesList($type,$item='%1$s') 46 46 { 47 47 $files = $this->getFilesFromType($type); 48 48 49 49 if (empty($files)) { 50 50 return '<p>'.__('No file').'</p>'; 51 51 } 52 52 53 53 $list = ''; 54 54 foreach ($files as $k => $v) … … 63 63 $list .= sprintf($li,$k,html::escapeHTML($k)); 64 64 } 65 65 66 66 return sprintf('<ul>%s</ul>',$list); 67 67 } 68 68 69 69 public function getFileContent($type,$f) 70 70 { 71 71 $files = $this->getFilesFromType($type); 72 72 73 73 if (!isset($files[$f])) { 74 74 throw new Exception(__('File does not exist.')); 75 75 } 76 76 77 77 $F = $files[$f]; 78 78 if (!is_readable($F)) { 79 79 throw new Exception(sprintf(__('File %s is not readable'),$f)); 80 80 } 81 81 82 82 return array( 83 83 'c' => file_get_contents($F), … … 87 87 ); 88 88 } 89 89 90 90 public function writeFile($type,$f,$content) 91 91 { 92 92 $files = $this->getFilesFromType($type); 93 93 94 94 if (!isset($files[$f])) { 95 95 throw new Exception(__('File does not exist.')); 96 96 } 97 97 98 98 try 99 99 { 100 100 $dest = $this->getDestinationFile($type,$f); 101 101 102 102 if ($dest == false) { 103 103 throw new Exception(); 104 104 } 105 105 106 106 if ($type == 'tpl' && !is_dir(dirname($dest))) { 107 107 files::makeDir(dirname($dest)); 108 108 } 109 109 110 110 if ($type == 'po' && !is_dir(dirname($dest))) { 111 111 files::makeDir(dirname($dest)); 112 112 } 113 113 114 114 $fp = @fopen($dest,'wb'); 115 115 if (!$fp) { 116 116 throw new Exception('tocatch'); 117 117 } 118 118 119 119 $content = preg_replace('/(\r?\n)/m',"\n",$content); 120 120 $content = preg_replace('/\r/m',"\n",$content); 121 121 122 122 fwrite($fp,$content); 123 123 fclose($fp); 124 124 125 125 # Updating inner files list 126 126 $this->updateFileInList($type,$f,$dest); … … 131 131 } 132 132 } 133 133 134 134 protected function getDestinationFile($type,$f) 135 135 { … … 141 141 $dest = $this->user_theme.'/'.$f; 142 142 } 143 143 144 144 if (file_exists($dest) && is_writable($dest)) { 145 145 return $dest; 146 146 } 147 147 148 148 if ($type == 'tpl' && !is_dir(dirname($dest))) { 149 149 if (is_writable($this->user_theme)) { … … 161 161 return $dest; 162 162 } 163 163 164 164 return false; 165 165 } 166 166 167 167 protected function getFilesFromType($type) 168 168 { … … 181 181 } 182 182 } 183 183 184 184 protected function updateFileInList($type,$f,$file) 185 185 { … … 201 201 return; 202 202 } 203 203 204 204 $list[$f] = $file; 205 205 } 206 206 207 207 protected function findTemplates() 208 208 { 209 209 # First, we look in template paths 210 210 $this->default_tpl = $this->getFilesInDir($this->default_theme.'/tpl'); 211 211 212 212 $this->tpl = array_merge( 213 213 $this->default_tpl, … … 216 216 ); 217 217 $this->tpl = array_merge($this->getFilesInDir(DC_ROOT.'/inc/public/default-templates'),$this->tpl); 218 218 219 219 # Then we look in 'default-templates' plugins directory 220 220 $plugins = $this->core->plugins->getModules(); … … 222 222 $this->tpl = array_merge($this->getFilesInDir($p['root'].'/default-templates'),$this->tpl); 223 223 } 224 224 225 225 uksort($this->tpl,array($this,'sortFilesHelper')); 226 226 } 227 227 228 228 protected function findStyles() 229 229 { … … 231 231 $this->css= array_merge($this->css,$this->getFilesInDir($this->user_theme.'/style','css','style/')); 232 232 } 233 233 234 234 protected function findScripts() 235 235 { … … 237 237 $this->js = array_merge($this->js,$this->getFilesInDir($this->user_theme.'/js','js','js/')); 238 238 } 239 239 240 240 protected function findLocales() 241 241 { … … 248 248 } 249 249 } 250 250 251 251 protected function getFilesInDir($dir,$ext=null,$prefix='',$model=null) 252 252 { … … 255 255 return array(); 256 256 } 257 257 258 258 $d = dir($dir); 259 259 $res = array(); … … 266 266 } 267 267 } 268 268 269 269 return $res; 270 270 } 271 271 272 272 protected function sortFilesHelper($a,$b) 273 273 { … … 275 275 return 0; 276 276 } 277 277 278 278 $ext_a = files::getExtension($a); 279 279 $ext_b = files::getExtension($b); 280 280 281 281 return strcmp($ext_a.'.'.$a,$ext_b.'.'.$b); 282 282 } 283 283 } 284 ?> -
plugins/themeEditor/index.php
r2256 r2566 45 45 throw $e; 46 46 } 47 47 48 48 # Write file 49 49 if (!empty($_POST['write'])) … … 117 117 '<p><label for="file_content">'.sprintf(__('Editing file %s'),'<strong>'.$file['f']).'</strong></label></p>'. 118 118 '<p>'.form::textarea('file_content',72,25,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>'; 119 119 120 120 if ($file['w']) 121 121 { … … 130 130 echo '<p>'.__('This file is not writable. Please check your theme files permissions.').'</p>'; 131 131 } 132 132 133 133 echo 134 134 '</fieldset></form>'; 135 135 136 136 if ($user_ui_colorsyntax) { 137 $editorMode = 137 $editorMode = 138 138 (!empty($_REQUEST['css']) ? "css" : 139 139 (!empty($_REQUEST['js']) ? "javascript" : 140 140 (!empty($_REQUEST['po']) ? "text/plain" : "text/html"))); 141 echo 141 echo 142 142 '<script> 143 143 window.CodeMirror.defineMode("dotclear", function(config) { -
plugins/themeEditor/script.js
r948 r2566 3 3 $('#file-form input[name="write"]').click(function() { 4 4 var f = this.form; 5 5 6 6 var data = { 7 7 file_content: (!dotclear.colorsyntax ? $(f).find('#file_content').get(0).value : editor.getValue()), … … 9 9 write: 1 10 10 }; 11 11 12 12 if (msg == false) { 13 13 msg = $('<p style="font-weight:bold; color:red;"></p>'); 14 14 $('#file_content').parent().after(msg); 15 15 } 16 16 17 17 msg.text(dotclear.msg.saving_document); 18 18 19 19 $.post(document.location.href,data,function(res,status) { 20 20 var err = $(res).find('div.error li:first'); … … 28 28 } 29 29 }); 30 30 31 31 return false; 32 32 });
Note: See TracChangeset
for help on using the changeset viewer.