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 | <?php echo dcPage::cssLoad(dcPage::getPF('themeEditor/style.css'));?> |
---|
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:")); ?> |
---|
79 | <?php echo dcPage::jsVar('dotclear.msg.confirm_reset_file',__("Are you sure you want to reset this file?")); ?> |
---|
80 | <?php echo dcPage::jsVar('dotclear.colorsyntax',$user_ui_colorsyntax); ?> |
---|
81 | //]]> |
---|
82 | </script> |
---|
83 | <?php echo dcPage::jsConfirmClose('file-form'); ?> |
---|
84 | <script type="text/javascript" src="<?php echo dcPage::getPF('themeEditor/script.js'); ?>"></script> |
---|
85 | <?php if ($user_ui_colorsyntax) { ?> |
---|
86 | <?php echo dcPage::jsCodeMirror($user_ui_colorsyntax_theme); ?> |
---|
87 | <?php } ?> |
---|
88 | </head> |
---|
89 | |
---|
90 | <body> |
---|
91 | <?php |
---|
92 | echo dcPage::breadcrumb( |
---|
93 | array( |
---|
94 | html::escapeHTML($core->blog->name) => '', |
---|
95 | __('Blog appearance') => $core->adminurl->get('admin.blog.theme'), |
---|
96 | __('Edit theme files') => '' |
---|
97 | )). |
---|
98 | dcPage::notices(); |
---|
99 | ?> |
---|
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">'. |
---|
119 | '<div class="fieldset"><h4>'.__('File editor').'</h4>'. |
---|
120 | '<p><label for="file_content">'.sprintf(__('Editing file %s'),'<strong>'.$file['f']).'</strong></label></p>'. |
---|
121 | '<p>'.form::textarea('file_content',72,25,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>'; |
---|
122 | |
---|
123 | if ($file['w']) |
---|
124 | { |
---|
125 | echo |
---|
126 | '<p><input type="submit" name="write" value="'.__('Save').' (s)" accesskey="s" /> '. |
---|
127 | ($o->deletableFile($file['type'],$file['f']) ? '<input type="submit" name="delete" class="delete" value="'.__('Reset').'" />' : ''). |
---|
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 | } |
---|
136 | |
---|
137 | echo |
---|
138 | '</div></form>'; |
---|
139 | |
---|
140 | if ($user_ui_colorsyntax) { |
---|
141 | $editorMode = |
---|
142 | (!empty($_REQUEST['css']) ? "css" : |
---|
143 | (!empty($_REQUEST['js']) ? "javascript" : |
---|
144 | (!empty($_REQUEST['po']) ? "text/plain" : "text/html"))); |
---|
145 | echo |
---|
146 | '<script> |
---|
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 | }); |
---|
161 | var editor = CodeMirror.fromTextArea(document.getElementById("file_content"), { |
---|
162 | mode: "dotclear", |
---|
163 | tabMode: "indent", |
---|
164 | lineWrapping: "true", |
---|
165 | lineNumbers: "true", |
---|
166 | matchBrackets: "true", |
---|
167 | autoCloseBrackets: "true"'. |
---|
168 | ($user_ui_colorsyntax_theme != '' ? ',theme: "'.$user_ui_colorsyntax_theme.'"' : '').' |
---|
169 | }); |
---|
170 | </script>'; |
---|
171 | } |
---|
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>'); ?> |
---|
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>'); ?> |
---|
189 | </div> |
---|
190 | |
---|
191 | <?php dcPage::helpBlock('themeEditor'); ?> |
---|
192 | </body> |
---|
193 | </html> |
---|