Dotclear

source: plugins/themeEditor/index.php @ 3980:df625feec28c

Revision 3980:df625feec28c, 5.4 KB checked in by franck <carnet.franck.paul@…>, 6 years ago (diff)

Switching from inline JS variables to JSON script, theme editor plugin

RevLine 
[0]1<?php
[3731]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
[3709]12if (!defined('DC_CONTEXT_ADMIN')) {return;}
[0]13
[3709]14require dirname(__FILE__) . '/class.themeEditor.php';
[0]15
[3874]16$file_default = $file = ['c' => null, 'w' => false, 'type' => null, 'f' => null, 'default_file' => false];
[0]17
[948]18# Get interface setting
19$core->auth->user_prefs->addWorkspace('interface');
[3709]20$user_ui_colorsyntax       = $core->auth->user_prefs->interface->colorsyntax;
[3251]21$user_ui_colorsyntax_theme = $core->auth->user_prefs->interface->colorsyntax_theme;
[948]22
[0]23# Loading themes
24$core->themes = new dcThemes($core);
[3709]25$core->themes->loadModules($core->blog->themes_path, null);
[0]26$T = $core->themes->getModules($core->blog->settings->system->theme);
27$o = new dcThemeEditor($core);
28
29try
30{
[3709]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    }
[2566]46
[3709]47    # Write file
48    if (!empty($_POST['write'])) {
49        $file['c'] = $_POST['file_content'];
50        $o->writeFile($file['type'], $file['f'], $file['c']);
51    }
[2663]52
[3709]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());
[0]61}
62?>
63
64<html>
65<head>
[3709]66    <title><?php echo __('Edit theme files'); ?></title>
67    <?php
[3980]68if ($user_ui_colorsyntax) {
69    echo dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => $user_ui_colorsyntax]);
70}
71echo 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?")
[3874]76]) .
[3980]77dcPage::jsLoad(dcPage::getPF('themeEditor/js/script.js')) .
78dcPage::jsConfirmClose('file-form') ;
[3709]79if ($user_ui_colorsyntax) {
80    echo dcPage::jsLoadCodeMirror($user_ui_colorsyntax_theme);
81}
82echo dcPage::cssLoad(dcPage::getPF('themeEditor/style.css'));
83?>
[0]84</head>
85
86<body>
[1339]87<?php
[1358]88echo dcPage::breadcrumb(
[3874]89    [
[3709]90        html::escapeHTML($core->blog->name) => '',
91        __('Blog appearance')               => $core->adminurl->get('admin.blog.theme'),
92        __('Edit theme files')              => ''
[3874]93    ]) .
[3709]94dcPage::notices();
[1339]95?>
[0]96
[3709]97<p><strong><?php echo sprintf(__('Your current theme on this blog is "%s".'), html::escapeHTML($T['name'])); ?></strong></p>
[0]98
[3709]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 }?>
[0]103
104<div id="file-box">
105<div id="file-editor">
106<?php
[3709]107if ($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>' .
[3874]114    '<p>' . form::textarea('file_content', 72, 25, [
[3710]115        'default'  => html::escapeHTML($file['c']),
116        'class'    => 'maximal',
117        'disabled' => !$file['w']
[3874]118    ]) . '</p>';
[2566]119
[3709]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() .
[3874]125            ($file['type'] ? form::hidden([$file['type']], $file['f']) : '') .
[3709]126            '</p>';
127    } else {
128        echo '<p>' . __('This file is not writable. Please check your theme files permissions.') . '</p>';
129    }
[2566]130
[3709]131    echo
132        '</div></form>';
[948]133
[3709]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")));
[3980]139        echo dcPage::jsJson('theme_editor_mode', ['mode' => $editorMode]);
140        echo dcPage::jsLoad(dcPage::getPF('themeEditor/js/mode.js'));
[3709]141        echo dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', $user_ui_colorsyntax_theme);
142    }
[0]143}
144?>
145</div>
146</div>
147
148<div id="file-chooser">
149<h3><?php echo __('Templates files'); ?></h3>
[3709]150<?php echo $o->filesList('tpl', '<a href="' . $p_url . '&amp;tpl=%2$s" class="tpl-link">%1$s</a>'); ?>
[0]151
152<h3><?php echo __('CSS files'); ?></h3>
[3709]153<?php echo $o->filesList('css', '<a href="' . $p_url . '&amp;css=%2$s" class="css-link">%1$s</a>'); ?>
[0]154
155<h3><?php echo __('JavaScript files'); ?></h3>
[3709]156<?php echo $o->filesList('js', '<a href="' . $p_url . '&amp;js=%2$s" class="js-link">%1$s</a>'); ?>
[1036]157
158<h3><?php echo __('Locales files'); ?></h3>
[3709]159<?php echo $o->filesList('po', '<a href="' . $p_url . '&amp;po=%2$s" class="po-link">%1$s</a>'); ?>
[0]160</div>
161
[3709]162<?php dcPage::helpBlock('themeEditor');?>
[0]163</body>
[2566]164</html>
Note: See TracBrowser for help on using the repository browser.

Sites map