1 | <?php |
---|
2 | /** |
---|
3 | * @brief themeEditor, a plugin for Dotclear 2 |
---|
4 | * |
---|
5 | * @package Dotclear |
---|
6 | * @subpackage Plugins |
---|
7 | * |
---|
8 | * @copyright Olivier Meunier & Association Dotclear |
---|
9 | * @copyright GPL-2.0-only |
---|
10 | */ |
---|
11 | |
---|
12 | if (!defined('DC_CONTEXT_ADMIN')) {return;} |
---|
13 | |
---|
14 | require dirname(__FILE__) . '/class.themeEditor.php'; |
---|
15 | |
---|
16 | $file_default = $file = ['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 | } catch (Exception $e) { |
---|
43 | $file = $file_default; |
---|
44 | throw $e; |
---|
45 | } |
---|
46 | |
---|
47 | # Write file |
---|
48 | if (!empty($_POST['write'])) { |
---|
49 | $file['c'] = $_POST['file_content']; |
---|
50 | $o->writeFile($file['type'], $file['f'], $file['c']); |
---|
51 | } |
---|
52 | |
---|
53 | # Delete file |
---|
54 | if (!empty($_POST['delete'])) { |
---|
55 | $o->deleteFile($file['type'], $file['f']); |
---|
56 | dcPage::addSuccessNotice(__('The file has been reset.')); |
---|
57 | http::redirect($p_url . '&' . $file['type'] . '=' . $file['f']); |
---|
58 | } |
---|
59 | } catch (Exception $e) { |
---|
60 | $core->error->add($e->getMessage()); |
---|
61 | } |
---|
62 | ?> |
---|
63 | |
---|
64 | <html> |
---|
65 | <head> |
---|
66 | <title><?php echo __('Edit theme files'); ?></title> |
---|
67 | <?php |
---|
68 | if ($user_ui_colorsyntax) { |
---|
69 | echo dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => $user_ui_colorsyntax]); |
---|
70 | } |
---|
71 | echo dcPage::jsJson('theme_editor_msg', [ |
---|
72 | 'saving_document' => __("Saving document..."), |
---|
73 | 'document_saved' => __("Document saved"), |
---|
74 | 'error_occurred' => __("An error occurred:"), |
---|
75 | 'confirm_reset_file' => __("Are you sure you want to reset this file?") |
---|
76 | ]) . |
---|
77 | dcPage::jsLoad(dcPage::getPF('themeEditor/js/script.js')) . |
---|
78 | dcPage::jsConfirmClose('file-form') ; |
---|
79 | if ($user_ui_colorsyntax) { |
---|
80 | echo dcPage::jsLoadCodeMirror($user_ui_colorsyntax_theme); |
---|
81 | } |
---|
82 | echo dcPage::cssLoad(dcPage::getPF('themeEditor/style.css')); |
---|
83 | ?> |
---|
84 | </head> |
---|
85 | |
---|
86 | <body> |
---|
87 | <?php |
---|
88 | echo dcPage::breadcrumb( |
---|
89 | [ |
---|
90 | html::escapeHTML($core->blog->name) => '', |
---|
91 | __('Blog appearance') => $core->adminurl->get('admin.blog.theme'), |
---|
92 | __('Edit theme files') => '' |
---|
93 | ]) . |
---|
94 | dcPage::notices(); |
---|
95 | ?> |
---|
96 | |
---|
97 | <p><strong><?php echo sprintf(__('Your current theme on this blog is "%s".'), html::escapeHTML($T['name'])); ?></strong></p> |
---|
98 | |
---|
99 | <?php if ($core->blog->settings->system->theme == 'default') {?> |
---|
100 | <div class="error"><p><?php echo __("You can't edit default theme."); ?></p></div> |
---|
101 | </body></html> |
---|
102 | <?php }?> |
---|
103 | |
---|
104 | <div id="file-box"> |
---|
105 | <div id="file-editor"> |
---|
106 | <?php |
---|
107 | if ($file['c'] === null) { |
---|
108 | echo '<p>' . __('Please select a file to edit.') . '</p>'; |
---|
109 | } else { |
---|
110 | echo |
---|
111 | '<form id="file-form" action="' . $p_url . '" method="post">' . |
---|
112 | '<div class="fieldset"><h3>' . __('File editor') . '</h3>' . |
---|
113 | '<p><label for="file_content">' . sprintf(__('Editing file %s'), '<strong>' . $file['f']) . '</strong></label></p>' . |
---|
114 | '<p>' . form::textarea('file_content', 72, 25, [ |
---|
115 | 'default' => html::escapeHTML($file['c']), |
---|
116 | 'class' => 'maximal', |
---|
117 | 'disabled' => !$file['w'] |
---|
118 | ]) . '</p>'; |
---|
119 | |
---|
120 | if ($file['w']) { |
---|
121 | echo |
---|
122 | '<p><input type="submit" name="write" value="' . __('Save') . ' (s)" accesskey="s" /> ' . |
---|
123 | ($o->deletableFile($file['type'], $file['f']) ? '<input type="submit" name="delete" class="delete" value="' . __('Reset') . '" />' : '') . |
---|
124 | $core->formNonce() . |
---|
125 | ($file['type'] ? form::hidden([$file['type']], $file['f']) : '') . |
---|
126 | '</p>'; |
---|
127 | } else { |
---|
128 | echo '<p>' . __('This file is not writable. Please check your theme files permissions.') . '</p>'; |
---|
129 | } |
---|
130 | |
---|
131 | echo |
---|
132 | '</div></form>'; |
---|
133 | |
---|
134 | if ($user_ui_colorsyntax) { |
---|
135 | $editorMode = |
---|
136 | (!empty($_REQUEST['css']) ? "css" : |
---|
137 | (!empty($_REQUEST['js']) ? "javascript" : |
---|
138 | (!empty($_REQUEST['po']) ? "text/plain" : "text/html"))); |
---|
139 | echo dcPage::jsJson('theme_editor_mode', ['mode' => $editorMode]); |
---|
140 | echo dcPage::jsLoad(dcPage::getPF('themeEditor/js/mode.js')); |
---|
141 | echo dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', $user_ui_colorsyntax_theme); |
---|
142 | } |
---|
143 | } |
---|
144 | ?> |
---|
145 | </div> |
---|
146 | </div> |
---|
147 | |
---|
148 | <div id="file-chooser"> |
---|
149 | <h3><?php echo __('Templates files'); ?></h3> |
---|
150 | <?php echo $o->filesList('tpl', '<a href="' . $p_url . '&tpl=%2$s" class="tpl-link">%1$s</a>'); ?> |
---|
151 | |
---|
152 | <h3><?php echo __('CSS files'); ?></h3> |
---|
153 | <?php echo $o->filesList('css', '<a href="' . $p_url . '&css=%2$s" class="css-link">%1$s</a>'); ?> |
---|
154 | |
---|
155 | <h3><?php echo __('JavaScript files'); ?></h3> |
---|
156 | <?php echo $o->filesList('js', '<a href="' . $p_url . '&js=%2$s" class="js-link">%1$s</a>'); ?> |
---|
157 | |
---|
158 | <h3><?php echo __('Locales files'); ?></h3> |
---|
159 | <?php echo $o->filesList('po', '<a href="' . $p_url . '&po=%2$s" class="po-link">%1$s</a>'); ?> |
---|
160 | </div> |
---|
161 | |
---|
162 | <?php dcPage::helpBlock('themeEditor');?> |
---|
163 | </body> |
---|
164 | </html> |
---|