1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2011 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 | |
---|
22 | # Loading themes |
---|
23 | $core->themes = new dcThemes($core); |
---|
24 | $core->themes->loadModules($core->blog->themes_path,null); |
---|
25 | $T = $core->themes->getModules($core->blog->settings->system->theme); |
---|
26 | $o = new dcThemeEditor($core); |
---|
27 | |
---|
28 | try |
---|
29 | { |
---|
30 | try |
---|
31 | { |
---|
32 | if (!empty($_REQUEST['tpl'])) { |
---|
33 | $file = $o->getFileContent('tpl',$_REQUEST['tpl']); |
---|
34 | } elseif (!empty($_REQUEST['css'])) { |
---|
35 | $file = $o->getFileContent('css',$_REQUEST['css']); |
---|
36 | } elseif (!empty($_REQUEST['js'])) { |
---|
37 | $file = $o->getFileContent('js',$_REQUEST['js']); |
---|
38 | } |
---|
39 | } |
---|
40 | catch (Exception $e) |
---|
41 | { |
---|
42 | $file = $file_default; |
---|
43 | throw $e; |
---|
44 | } |
---|
45 | |
---|
46 | # Write file |
---|
47 | if (!empty($_POST['write'])) |
---|
48 | { |
---|
49 | $file['c'] = $_POST['file_content']; |
---|
50 | $o->writeFile($file['type'],$file['f'],$file['c']); |
---|
51 | } |
---|
52 | } |
---|
53 | catch (Exception $e) |
---|
54 | { |
---|
55 | $core->error->add($e->getMessage()); |
---|
56 | } |
---|
57 | ?> |
---|
58 | |
---|
59 | <html> |
---|
60 | <head> |
---|
61 | <title><?php echo __('Theme Editor'); ?></title> |
---|
62 | <link rel="stylesheet" type="text/css" href="index.php?pf=themeEditor/style.css" /> |
---|
63 | <script type="text/javascript"> |
---|
64 | //<![CDATA[ |
---|
65 | <?php echo dcPage::jsVar('dotclear.msg.saving_document',__("Saving document...")); ?> |
---|
66 | <?php echo dcPage::jsVar('dotclear.msg.document_saved',__("Document saved")); ?> |
---|
67 | <?php echo dcPage::jsVar('dotclear.msg.error_occurred',__("An error occurred:")); ?> |
---|
68 | <?php echo dcPage::jsVar('dotclear.colorsyntax',$user_ui_colorsyntax); ?> |
---|
69 | //]]> |
---|
70 | </script> |
---|
71 | <script type="text/javascript" src="index.php?pf=themeEditor/script.js"></script> |
---|
72 | <?php if ($user_ui_colorsyntax) { ?> |
---|
73 | <link rel="stylesheet" type="text/css" href="index.php?pf=themeEditor/codemirror/codemirror.css" /> |
---|
74 | <link rel="stylesheet" type="text/css" href="index.php?pf=themeEditor/codemirror.css" /> |
---|
75 | <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/codemirror.js"></script> |
---|
76 | <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/multiplex.js"></script> |
---|
77 | <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/xml.js"></script> |
---|
78 | <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/javascript.js"></script> |
---|
79 | <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/css.js"></script> |
---|
80 | <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/php.js"></script> |
---|
81 | <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/htmlmixed.js"></script> |
---|
82 | <?php } ?> |
---|
83 | </head> |
---|
84 | |
---|
85 | <body> |
---|
86 | <?php echo '<h2>'.html::escapeHTML($core->blog->name). |
---|
87 | ' › <a href="blog_theme.php">'.__('Blog appearance').'</a> › <span class="page-title">'.__('Theme Editor').'</span></h2>'; ?> |
---|
88 | |
---|
89 | <p><strong><?php echo sprintf(__('Your current theme on this blog is "%s".'),html::escapeHTML($T['name'])); ?></strong></p> |
---|
90 | |
---|
91 | <?php if ($core->blog->settings->system->theme == 'default') { ?> |
---|
92 | <div class="error"><p><?php echo __("You can't edit default theme."); ?></p></div> |
---|
93 | </body></html> |
---|
94 | <?php } ?> |
---|
95 | |
---|
96 | <div id="file-box"> |
---|
97 | <div id="file-editor"> |
---|
98 | <?php |
---|
99 | if ($file['c'] === null) |
---|
100 | { |
---|
101 | echo '<p>'.__('Please select a file to edit.').'</p>'; |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | echo |
---|
106 | '<form id="file-form" action="'.$p_url.'" method="post">'. |
---|
107 | '<fieldset><legend>'.__('File editor').'</legend>'. |
---|
108 | '<p><label for="file_content">'.sprintf(__('Editing file %s'),'<strong>'.$file['f']).'</strong></label></p>'. |
---|
109 | '<p>'.form::textarea('file_content',72,25,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>'; |
---|
110 | |
---|
111 | if ($file['w']) |
---|
112 | { |
---|
113 | echo |
---|
114 | '<p><input type="submit" name="write" value="'.__('Save').' (s)" accesskey="s" /> '. |
---|
115 | $core->formNonce(). |
---|
116 | ($file['type'] ? form::hidden(array($file['type']),$file['f']) : ''). |
---|
117 | '</p>'; |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | echo '<p>'.__('This file is not writable. Please check your theme files permissions.').'</p>'; |
---|
122 | } |
---|
123 | |
---|
124 | echo |
---|
125 | '</fieldset></form>'; |
---|
126 | |
---|
127 | if ($user_ui_colorsyntax) { |
---|
128 | $editorMode = (!empty($_REQUEST['css']) ? "css" : (!empty($_REQUEST['js']) ? "javascript" : "text/html")); |
---|
129 | echo |
---|
130 | '<script> |
---|
131 | window.CodeMirror.defineMode("dotclear", function(config) { |
---|
132 | return CodeMirror.multiplexingMode( |
---|
133 | CodeMirror.getMode(config, "'.$editorMode.'"), |
---|
134 | {open: "{{tpl:", close: "}}", |
---|
135 | mode: CodeMirror.getMode(config, "text/plain"), |
---|
136 | delimStyle: "delimit"}, |
---|
137 | {open: "<tpl:", close: ">", |
---|
138 | mode: CodeMirror.getMode(config, "text/plain"), |
---|
139 | delimStyle: "delimit"}, |
---|
140 | {open: "</tpl:", close: ">", |
---|
141 | mode: CodeMirror.getMode(config, "text/plain"), |
---|
142 | delimStyle: "delimit"} |
---|
143 | ); |
---|
144 | }); |
---|
145 | var editor = CodeMirror.fromTextArea(document.getElementById("file_content"), { |
---|
146 | mode: "dotclear", |
---|
147 | tabMode: "indent", |
---|
148 | lineWrapping: "true", |
---|
149 | lineNumbers: "true", |
---|
150 | matchBrackets: "true" |
---|
151 | }); |
---|
152 | </script>'; |
---|
153 | } |
---|
154 | } |
---|
155 | ?> |
---|
156 | </div> |
---|
157 | </div> |
---|
158 | |
---|
159 | <div id="file-chooser"> |
---|
160 | <h3><?php echo __('Templates files'); ?></h3> |
---|
161 | <?php echo $o->filesList('tpl','<a href="'.$p_url.'&tpl=%2$s" class="tpl-link">%1$s</a>'); ?> |
---|
162 | |
---|
163 | <h3><?php echo __('CSS files'); ?></h3> |
---|
164 | <?php echo $o->filesList('css','<a href="'.$p_url.'&css=%2$s" class="css-link">%1$s</a>'); ?> |
---|
165 | |
---|
166 | <h3><?php echo __('JavaScript files'); ?></h3> |
---|
167 | <?php echo $o->filesList('js','<a href="'.$p_url.'&js=%2$s" class="js-link">%1$s</a>'); ?> |
---|
168 | </div> |
---|
169 | |
---|
170 | <?php dcPage::helpBlock('themeEditor'); ?> |
---|
171 | </body> |
---|
172 | </html> |
---|