| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
|---|
| 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 | |
|---|
| 18 | # Get interface setting |
|---|
| 19 | $core->auth->user_prefs->addWorkspace('interface'); |
|---|
| 20 | $user_ui_colorsyntax = $core->auth->user_prefs->interface->colorsyntax; |
|---|
| 21 | $user_ui_colorsyntax_theme = $core->auth->user_prefs->interface->colorsyntax_theme; |
|---|
| 22 | |
|---|
| 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']); |
|---|
| 39 | } elseif (!empty($_REQUEST['po'])) { |
|---|
| 40 | $file = $o->getFileContent('po',$_REQUEST['po']); |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | catch (Exception $e) |
|---|
| 44 | { |
|---|
| 45 | $file = $file_default; |
|---|
| 46 | throw $e; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 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 | } |
|---|
| 55 | |
|---|
| 56 | # Delete file |
|---|
| 57 | if (!empty($_POST['delete'])) |
|---|
| 58 | { |
|---|
| 59 | $o->deleteFile($file['type'],$file['f']); |
|---|
| 60 | dcPage::addSuccessNotice(__('The file has been reset.')); |
|---|
| 61 | http::redirect($p_url.'&'.$file['type'].'='.$file['f']); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | catch (Exception $e) |
|---|
| 65 | { |
|---|
| 66 | $core->error->add($e->getMessage()); |
|---|
| 67 | } |
|---|
| 68 | ?> |
|---|
| 69 | |
|---|
| 70 | <html> |
|---|
| 71 | <head> |
|---|
| 72 | <title><?php echo __('Edit theme files'); ?></title> |
|---|
| 73 | <script type="text/javascript"> |
|---|
| 74 | <?php echo dcPage::jsVar('dotclear.msg.saving_document',__("Saving document...")); ?> |
|---|
| 75 | <?php echo dcPage::jsVar('dotclear.msg.document_saved',__("Document saved")); ?> |
|---|
| 76 | <?php echo dcPage::jsVar('dotclear.msg.error_occurred',__("An error occurred:")); ?> |
|---|
| 77 | <?php echo dcPage::jsVar('dotclear.msg.confirm_reset_file',__("Are you sure you want to reset this file?")); ?> |
|---|
| 78 | <?php echo dcPage::jsVar('dotclear.colorsyntax',$user_ui_colorsyntax); ?> |
|---|
| 79 | </script> |
|---|
| 80 | <?php echo dcPage::jsConfirmClose('file-form'); ?> |
|---|
| 81 | <script type="text/javascript" src="<?php echo dcPage::getPF('themeEditor/script.js'); ?>"></script> |
|---|
| 82 | <?php if ($user_ui_colorsyntax) { ?> |
|---|
| 83 | <?php echo dcPage::jsLoadCodeMirror($user_ui_colorsyntax_theme); ?> |
|---|
| 84 | <?php } ?> |
|---|
| 85 | <?php echo dcPage::cssLoad(dcPage::getPF('themeEditor/style.css'));?> |
|---|
| 86 | </head> |
|---|
| 87 | |
|---|
| 88 | <body> |
|---|
| 89 | <?php |
|---|
| 90 | echo dcPage::breadcrumb( |
|---|
| 91 | array( |
|---|
| 92 | html::escapeHTML($core->blog->name) => '', |
|---|
| 93 | __('Blog appearance') => $core->adminurl->get('admin.blog.theme'), |
|---|
| 94 | __('Edit theme files') => '' |
|---|
| 95 | )). |
|---|
| 96 | dcPage::notices(); |
|---|
| 97 | ?> |
|---|
| 98 | |
|---|
| 99 | <p><strong><?php echo sprintf(__('Your current theme on this blog is "%s".'),html::escapeHTML($T['name'])); ?></strong></p> |
|---|
| 100 | |
|---|
| 101 | <?php if ($core->blog->settings->system->theme == 'default') { ?> |
|---|
| 102 | <div class="error"><p><?php echo __("You can't edit default theme."); ?></p></div> |
|---|
| 103 | </body></html> |
|---|
| 104 | <?php } ?> |
|---|
| 105 | |
|---|
| 106 | <div id="file-box"> |
|---|
| 107 | <div id="file-editor"> |
|---|
| 108 | <?php |
|---|
| 109 | if ($file['c'] === null) |
|---|
| 110 | { |
|---|
| 111 | echo '<p>'.__('Please select a file to edit.').'</p>'; |
|---|
| 112 | } |
|---|
| 113 | else |
|---|
| 114 | { |
|---|
| 115 | echo |
|---|
| 116 | '<form id="file-form" action="'.$p_url.'" method="post">'. |
|---|
| 117 | '<div class="fieldset"><h3>'.__('File editor').'</h3>'. |
|---|
| 118 | '<p><label for="file_content">'.sprintf(__('Editing file %s'),'<strong>'.$file['f']).'</strong></label></p>'. |
|---|
| 119 | '<p>'.form::textarea('file_content',72,25,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>'; |
|---|
| 120 | |
|---|
| 121 | if ($file['w']) |
|---|
| 122 | { |
|---|
| 123 | echo |
|---|
| 124 | '<p><input type="submit" name="write" value="'.__('Save').' (s)" accesskey="s" /> '. |
|---|
| 125 | ($o->deletableFile($file['type'],$file['f']) ? '<input type="submit" name="delete" class="delete" value="'.__('Reset').'" />' : ''). |
|---|
| 126 | $core->formNonce(). |
|---|
| 127 | ($file['type'] ? form::hidden(array($file['type']),$file['f']) : ''). |
|---|
| 128 | '</p>'; |
|---|
| 129 | } |
|---|
| 130 | else |
|---|
| 131 | { |
|---|
| 132 | echo '<p>'.__('This file is not writable. Please check your theme files permissions.').'</p>'; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | echo |
|---|
| 136 | '</div></form>'; |
|---|
| 137 | |
|---|
| 138 | if ($user_ui_colorsyntax) { |
|---|
| 139 | $editorMode = |
|---|
| 140 | (!empty($_REQUEST['css']) ? "css" : |
|---|
| 141 | (!empty($_REQUEST['js']) ? "javascript" : |
|---|
| 142 | (!empty($_REQUEST['po']) ? "text/plain" : "text/html"))); |
|---|
| 143 | echo |
|---|
| 144 | '<script type="text/javascript"> |
|---|
| 145 | window.CodeMirror.defineMode("dotclear", function(config) { |
|---|
| 146 | return CodeMirror.multiplexingMode( |
|---|
| 147 | CodeMirror.getMode(config, "'.$editorMode.'"), |
|---|
| 148 | {open: "{{tpl:", close: "}}", |
|---|
| 149 | mode: CodeMirror.getMode(config, "text/plain"), |
|---|
| 150 | delimStyle: "delimit"}, |
|---|
| 151 | {open: "<tpl:", close: ">", |
|---|
| 152 | mode: CodeMirror.getMode(config, "text/plain"), |
|---|
| 153 | delimStyle: "delimit"}, |
|---|
| 154 | {open: "</tpl:", close: ">", |
|---|
| 155 | mode: CodeMirror.getMode(config, "text/plain"), |
|---|
| 156 | delimStyle: "delimit"} |
|---|
| 157 | ); |
|---|
| 158 | }); |
|---|
| 159 | </script>'; |
|---|
| 160 | echo dcPage::jsRunCodeMirror('editor','file_content','dotclear',$user_ui_colorsyntax_theme); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | ?> |
|---|
| 164 | </div> |
|---|
| 165 | </div> |
|---|
| 166 | |
|---|
| 167 | <div id="file-chooser"> |
|---|
| 168 | <h3><?php echo __('Templates files'); ?></h3> |
|---|
| 169 | <?php echo $o->filesList('tpl','<a href="'.$p_url.'&tpl=%2$s" class="tpl-link">%1$s</a>'); ?> |
|---|
| 170 | |
|---|
| 171 | <h3><?php echo __('CSS files'); ?></h3> |
|---|
| 172 | <?php echo $o->filesList('css','<a href="'.$p_url.'&css=%2$s" class="css-link">%1$s</a>'); ?> |
|---|
| 173 | |
|---|
| 174 | <h3><?php echo __('JavaScript files'); ?></h3> |
|---|
| 175 | <?php echo $o->filesList('js','<a href="'.$p_url.'&js=%2$s" class="js-link">%1$s</a>'); ?> |
|---|
| 176 | |
|---|
| 177 | <h3><?php echo __('Locales files'); ?></h3> |
|---|
| 178 | <?php echo $o->filesList('po','<a href="'.$p_url.'&po=%2$s" class="po-link">%1$s</a>'); ?> |
|---|
| 179 | </div> |
|---|
| 180 | |
|---|
| 181 | <?php dcPage::helpBlock('themeEditor'); ?> |
|---|
| 182 | </body> |
|---|
| 183 | </html> |
|---|