Dotclear

source: plugins/themeEditor/index.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 6.1 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

Line 
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
12if (!defined('DC_CONTEXT_ADMIN')) {return;}
13
14require 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
29try
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
68echo dcPage::jsVars([
69    'dotclear.msg.saving_document'    => __("Saving document..."),
70    'dotclear.msg.document_saved'     => __("Document saved"),
71    'dotclear.msg.error_occurred'     => __("An error occurred:"),
72    'dotclear.msg.confirm_reset_file' => __("Are you sure you want to reset this file?")
73]) .
74dcPage::jsConfirmClose('file-form') .
75dcPage::jsLoad(dcPage::getPF('themeEditor/js/script.js'));
76if ($user_ui_colorsyntax) {
77    echo dcPage::jsVars(['dotclear.colorsyntax' => $user_ui_colorsyntax]);
78    echo dcPage::jsLoadCodeMirror($user_ui_colorsyntax_theme);
79}
80echo dcPage::cssLoad(dcPage::getPF('themeEditor/style.css'));
81?>
82</head>
83
84<body>
85<?php
86echo dcPage::breadcrumb(
87    [
88        html::escapeHTML($core->blog->name) => '',
89        __('Blog appearance')               => $core->adminurl->get('admin.blog.theme'),
90        __('Edit theme files')              => ''
91    ]) .
92dcPage::notices();
93?>
94
95<p><strong><?php echo sprintf(__('Your current theme on this blog is "%s".'), html::escapeHTML($T['name'])); ?></strong></p>
96
97<?php if ($core->blog->settings->system->theme == 'default') {?>
98    <div class="error"><p><?php echo __("You can't edit default theme."); ?></p></div>
99    </body></html>
100<?php }?>
101
102<div id="file-box">
103<div id="file-editor">
104<?php
105if ($file['c'] === null) {
106    echo '<p>' . __('Please select a file to edit.') . '</p>';
107} else {
108    echo
109    '<form id="file-form" action="' . $p_url . '" method="post">' .
110    '<div class="fieldset"><h3>' . __('File editor') . '</h3>' .
111    '<p><label for="file_content">' . sprintf(__('Editing file %s'), '<strong>' . $file['f']) . '</strong></label></p>' .
112    '<p>' . form::textarea('file_content', 72, 25, [
113        'default'  => html::escapeHTML($file['c']),
114        'class'    => 'maximal',
115        'disabled' => !$file['w']
116    ]) . '</p>';
117
118    if ($file['w']) {
119        echo
120        '<p><input type="submit" name="write" value="' . __('Save') . ' (s)" accesskey="s" /> ' .
121        ($o->deletableFile($file['type'], $file['f']) ? '<input type="submit" name="delete" class="delete" value="' . __('Reset') . '" />' : '') .
122        $core->formNonce() .
123            ($file['type'] ? form::hidden([$file['type']], $file['f']) : '') .
124            '</p>';
125    } else {
126        echo '<p>' . __('This file is not writable. Please check your theme files permissions.') . '</p>';
127    }
128
129    echo
130        '</div></form>';
131
132    if ($user_ui_colorsyntax) {
133        $editorMode =
134            (!empty($_REQUEST['css']) ? "css" :
135            (!empty($_REQUEST['js']) ? "javascript" :
136                (!empty($_REQUEST['po']) ? "text/plain" : "text/html")));
137        echo
138            '<script type="text/javascript">
139            window.CodeMirror.defineMode("dotclear", function(config) {
140                return CodeMirror.multiplexingMode(
141                    CodeMirror.getMode(config, "' . $editorMode . '"),
142                    {open: "{{tpl:", close: "}}",
143                     mode: CodeMirror.getMode(config, "text/plain"),
144                     delimStyle: "delimit"},
145                    {open: "<tpl:", close: ">",
146                     mode: CodeMirror.getMode(config, "text/plain"),
147                     delimStyle: "delimit"},
148                    {open: "</tpl:", close: ">",
149                     mode: CodeMirror.getMode(config, "text/plain"),
150                     delimStyle: "delimit"}
151                    );
152            });
153        </script>';
154        echo dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', $user_ui_colorsyntax_theme);
155    }
156}
157?>
158</div>
159</div>
160
161<div id="file-chooser">
162<h3><?php echo __('Templates files'); ?></h3>
163<?php echo $o->filesList('tpl', '<a href="' . $p_url . '&amp;tpl=%2$s" class="tpl-link">%1$s</a>'); ?>
164
165<h3><?php echo __('CSS files'); ?></h3>
166<?php echo $o->filesList('css', '<a href="' . $p_url . '&amp;css=%2$s" class="css-link">%1$s</a>'); ?>
167
168<h3><?php echo __('JavaScript files'); ?></h3>
169<?php echo $o->filesList('js', '<a href="' . $p_url . '&amp;js=%2$s" class="js-link">%1$s</a>'); ?>
170
171<h3><?php echo __('Locales files'); ?></h3>
172<?php echo $o->filesList('po', '<a href="' . $p_url . '&amp;po=%2$s" class="po-link">%1$s</a>'); ?>
173</div>
174
175<?php dcPage::helpBlock('themeEditor');?>
176</body>
177</html>
Note: See TracBrowser for help on using the repository browser.

Sites map