[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 13 | |
---|
| 14 | require dirname(__FILE__).'/class.themeEditor.php'; |
---|
| 15 | |
---|
| 16 | $file_default = $file = array('c'=>null, 'w'=>false, 'type'=>null, 'f'=>null, 'default_file'=>false); |
---|
| 17 | |
---|
[948] | 18 | # Get interface setting |
---|
| 19 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
| 20 | $user_ui_colorsyntax = $core->auth->user_prefs->interface->colorsyntax; |
---|
[3251] | 21 | $user_ui_colorsyntax_theme = $core->auth->user_prefs->interface->colorsyntax_theme; |
---|
[948] | 22 | |
---|
[0] | 23 | # Loading themes |
---|
| 24 | $core->themes = new dcThemes($core); |
---|
| 25 | $core->themes->loadModules($core->blog->themes_path,null); |
---|
| 26 | $T = $core->themes->getModules($core->blog->settings->system->theme); |
---|
| 27 | $o = new dcThemeEditor($core); |
---|
| 28 | |
---|
| 29 | try |
---|
| 30 | { |
---|
| 31 | try |
---|
| 32 | { |
---|
| 33 | if (!empty($_REQUEST['tpl'])) { |
---|
| 34 | $file = $o->getFileContent('tpl',$_REQUEST['tpl']); |
---|
| 35 | } elseif (!empty($_REQUEST['css'])) { |
---|
| 36 | $file = $o->getFileContent('css',$_REQUEST['css']); |
---|
| 37 | } elseif (!empty($_REQUEST['js'])) { |
---|
| 38 | $file = $o->getFileContent('js',$_REQUEST['js']); |
---|
[1036] | 39 | } elseif (!empty($_REQUEST['po'])) { |
---|
| 40 | $file = $o->getFileContent('po',$_REQUEST['po']); |
---|
[0] | 41 | } |
---|
| 42 | } |
---|
| 43 | catch (Exception $e) |
---|
| 44 | { |
---|
| 45 | $file = $file_default; |
---|
| 46 | throw $e; |
---|
| 47 | } |
---|
[2566] | 48 | |
---|
[0] | 49 | # Write file |
---|
| 50 | if (!empty($_POST['write'])) |
---|
| 51 | { |
---|
| 52 | $file['c'] = $_POST['file_content']; |
---|
| 53 | $o->writeFile($file['type'],$file['f'],$file['c']); |
---|
| 54 | } |
---|
[2663] | 55 | |
---|
| 56 | # Delete file |
---|
| 57 | if (!empty($_POST['delete'])) |
---|
| 58 | { |
---|
| 59 | $o->deleteFile($file['type'],$file['f']); |
---|
[2744] | 60 | dcPage::addSuccessNotice(__('The file has been reset.')); |
---|
[2663] | 61 | http::redirect($p_url.'&'.$file['type'].'='.$file['f']); |
---|
| 62 | } |
---|
[0] | 63 | } |
---|
| 64 | catch (Exception $e) |
---|
| 65 | { |
---|
| 66 | $core->error->add($e->getMessage()); |
---|
| 67 | } |
---|
| 68 | ?> |
---|
| 69 | |
---|
| 70 | <html> |
---|
| 71 | <head> |
---|
[1382] | 72 | <title><?php echo __('Edit theme files'); ?></title> |
---|
[3021] | 73 | <?php echo dcPage::cssLoad(dcPage::getPF('themeEditor/style.css'));?> |
---|
[0] | 74 | <script type="text/javascript"> |
---|
| 75 | //<![CDATA[ |
---|
| 76 | <?php echo dcPage::jsVar('dotclear.msg.saving_document',__("Saving document...")); ?> |
---|
| 77 | <?php echo dcPage::jsVar('dotclear.msg.document_saved',__("Document saved")); ?> |
---|
| 78 | <?php echo dcPage::jsVar('dotclear.msg.error_occurred',__("An error occurred:")); ?> |
---|
[2663] | 79 | <?php echo dcPage::jsVar('dotclear.msg.confirm_reset_file',__("Are you sure you want to reset this file?")); ?> |
---|
[948] | 80 | <?php echo dcPage::jsVar('dotclear.colorsyntax',$user_ui_colorsyntax); ?> |
---|
[0] | 81 | //]]> |
---|
| 82 | </script> |
---|
[2805] | 83 | <?php echo dcPage::jsConfirmClose('file-form'); ?> |
---|
[2849] | 84 | <script type="text/javascript" src="<?php echo dcPage::getPF('themeEditor/script.js'); ?>"></script> |
---|
[948] | 85 | <?php if ($user_ui_colorsyntax) { ?> |
---|
[3251] | 86 | <?php echo dcPage::jsCodeMirror($user_ui_colorsyntax_theme); ?> |
---|
[948] | 87 | <?php } ?> |
---|
[0] | 88 | </head> |
---|
| 89 | |
---|
| 90 | <body> |
---|
[1339] | 91 | <?php |
---|
[1358] | 92 | echo dcPage::breadcrumb( |
---|
[1339] | 93 | array( |
---|
| 94 | html::escapeHTML($core->blog->name) => '', |
---|
[2815] | 95 | __('Blog appearance') => $core->adminurl->get('admin.blog.theme'), |
---|
[2166] | 96 | __('Edit theme files') => '' |
---|
[2256] | 97 | )). |
---|
| 98 | dcPage::notices(); |
---|
[1339] | 99 | ?> |
---|
[0] | 100 | |
---|
| 101 | <p><strong><?php echo sprintf(__('Your current theme on this blog is "%s".'),html::escapeHTML($T['name'])); ?></strong></p> |
---|
| 102 | |
---|
| 103 | <?php if ($core->blog->settings->system->theme == 'default') { ?> |
---|
| 104 | <div class="error"><p><?php echo __("You can't edit default theme."); ?></p></div> |
---|
| 105 | </body></html> |
---|
| 106 | <?php } ?> |
---|
| 107 | |
---|
| 108 | <div id="file-box"> |
---|
| 109 | <div id="file-editor"> |
---|
| 110 | <?php |
---|
| 111 | if ($file['c'] === null) |
---|
| 112 | { |
---|
| 113 | echo '<p>'.__('Please select a file to edit.').'</p>'; |
---|
| 114 | } |
---|
| 115 | else |
---|
| 116 | { |
---|
| 117 | echo |
---|
| 118 | '<form id="file-form" action="'.$p_url.'" method="post">'. |
---|
[2955] | 119 | '<div class="fieldset"><h4>'.__('File editor').'</h4>'. |
---|
[100] | 120 | '<p><label for="file_content">'.sprintf(__('Editing file %s'),'<strong>'.$file['f']).'</strong></label></p>'. |
---|
[0] | 121 | '<p>'.form::textarea('file_content',72,25,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>'; |
---|
[2566] | 122 | |
---|
[0] | 123 | if ($file['w']) |
---|
| 124 | { |
---|
| 125 | echo |
---|
[219] | 126 | '<p><input type="submit" name="write" value="'.__('Save').' (s)" accesskey="s" /> '. |
---|
[2663] | 127 | ($o->deletableFile($file['type'],$file['f']) ? '<input type="submit" name="delete" class="delete" value="'.__('Reset').'" />' : ''). |
---|
[0] | 128 | $core->formNonce(). |
---|
| 129 | ($file['type'] ? form::hidden(array($file['type']),$file['f']) : ''). |
---|
| 130 | '</p>'; |
---|
| 131 | } |
---|
| 132 | else |
---|
| 133 | { |
---|
| 134 | echo '<p>'.__('This file is not writable. Please check your theme files permissions.').'</p>'; |
---|
| 135 | } |
---|
[2566] | 136 | |
---|
[0] | 137 | echo |
---|
[2955] | 138 | '</div></form>'; |
---|
[948] | 139 | |
---|
| 140 | if ($user_ui_colorsyntax) { |
---|
[2566] | 141 | $editorMode = |
---|
[1036] | 142 | (!empty($_REQUEST['css']) ? "css" : |
---|
| 143 | (!empty($_REQUEST['js']) ? "javascript" : |
---|
| 144 | (!empty($_REQUEST['po']) ? "text/plain" : "text/html"))); |
---|
[2566] | 145 | echo |
---|
[948] | 146 | '<script> |
---|
[997] | 147 | window.CodeMirror.defineMode("dotclear", function(config) { |
---|
| 148 | return CodeMirror.multiplexingMode( |
---|
| 149 | CodeMirror.getMode(config, "'.$editorMode.'"), |
---|
| 150 | {open: "{{tpl:", close: "}}", |
---|
| 151 | mode: CodeMirror.getMode(config, "text/plain"), |
---|
| 152 | delimStyle: "delimit"}, |
---|
| 153 | {open: "<tpl:", close: ">", |
---|
| 154 | mode: CodeMirror.getMode(config, "text/plain"), |
---|
| 155 | delimStyle: "delimit"}, |
---|
| 156 | {open: "</tpl:", close: ">", |
---|
| 157 | mode: CodeMirror.getMode(config, "text/plain"), |
---|
| 158 | delimStyle: "delimit"} |
---|
| 159 | ); |
---|
| 160 | }); |
---|
[948] | 161 | var editor = CodeMirror.fromTextArea(document.getElementById("file_content"), { |
---|
[997] | 162 | mode: "dotclear", |
---|
[948] | 163 | tabMode: "indent", |
---|
| 164 | lineWrapping: "true", |
---|
| 165 | lineNumbers: "true", |
---|
[3251] | 166 | matchBrackets: "true", |
---|
| 167 | autoCloseBrackets: "true"'. |
---|
| 168 | ($user_ui_colorsyntax_theme != '' ? ',theme: "'.$user_ui_colorsyntax_theme.'"' : '').' |
---|
[948] | 169 | }); |
---|
| 170 | </script>'; |
---|
| 171 | } |
---|
[0] | 172 | } |
---|
| 173 | ?> |
---|
| 174 | </div> |
---|
| 175 | </div> |
---|
| 176 | |
---|
| 177 | <div id="file-chooser"> |
---|
| 178 | <h3><?php echo __('Templates files'); ?></h3> |
---|
| 179 | <?php echo $o->filesList('tpl','<a href="'.$p_url.'&tpl=%2$s" class="tpl-link">%1$s</a>'); ?> |
---|
| 180 | |
---|
| 181 | <h3><?php echo __('CSS files'); ?></h3> |
---|
| 182 | <?php echo $o->filesList('css','<a href="'.$p_url.'&css=%2$s" class="css-link">%1$s</a>'); ?> |
---|
| 183 | |
---|
| 184 | <h3><?php echo __('JavaScript files'); ?></h3> |
---|
| 185 | <?php echo $o->filesList('js','<a href="'.$p_url.'&js=%2$s" class="js-link">%1$s</a>'); ?> |
---|
[1036] | 186 | |
---|
| 187 | <h3><?php echo __('Locales files'); ?></h3> |
---|
| 188 | <?php echo $o->filesList('po','<a href="'.$p_url.'&po=%2$s" class="po-link">%1$s</a>'); ?> |
---|
[0] | 189 | </div> |
---|
| 190 | |
---|
| 191 | <?php dcPage::helpBlock('themeEditor'); ?> |
---|
| 192 | </body> |
---|
[2566] | 193 | </html> |
---|