Dotclear

source: plugins/themeEditor/index.php @ 948:206fd3d17d64

Revision 948:206fd3d17d64, 5.2 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Add syntax color option to theme editor plugin, using CodeMirror? ( http://codemirror.net/), fixes #628

Line 
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 -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) { return; }
13
14require 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
28try
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}
53catch (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/xml.js"></script>
77  <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/javascript.js"></script>
78  <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/css.js"></script>
79  <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/php.js"></script>
80  <script type="text/JavaScript" src="index.php?pf=themeEditor/codemirror/htmlmixed.js"></script>
81<?php } ?>
82</head>
83
84<body>
85<?php echo '<h2>'.html::escapeHTML($core->blog->name).
86' &rsaquo; <a href="blog_theme.php">'.__('Blog appearance').'</a> &rsaquo; <span class="page-title">'.__('Theme Editor').'</span></h2>'; ?>
87
88<p><strong><?php echo sprintf(__('Your current theme on this blog is "%s".'),html::escapeHTML($T['name'])); ?></strong></p>
89
90<?php if ($core->blog->settings->system->theme == 'default') { ?>
91     <div class="error"><p><?php echo __("You can't edit default theme."); ?></p></div>
92     </body></html>
93<?php } ?>
94
95<div id="file-box">
96<div id="file-editor">
97<?php
98if ($file['c'] === null)
99{
100     echo '<p>'.__('Please select a file to edit.').'</p>';
101}
102else
103{
104     echo
105     '<form id="file-form" action="'.$p_url.'" method="post">'.
106     '<fieldset><legend>'.__('File editor').'</legend>'.
107     '<p><label for="file_content">'.sprintf(__('Editing file %s'),'<strong>'.$file['f']).'</strong></label></p>'.
108     '<p>'.form::textarea('file_content',72,25,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>';
109     
110     if ($file['w'])
111     {
112          echo
113          '<p><input type="submit" name="write" value="'.__('Save').' (s)" accesskey="s" /> '.
114          $core->formNonce().
115          ($file['type'] ? form::hidden(array($file['type']),$file['f']) : '').
116          '</p>';
117     }
118     else
119     {
120          echo '<p>'.__('This file is not writable. Please check your theme files permissions.').'</p>';
121     }
122     
123     echo
124     '</fieldset></form>';
125
126     if ($user_ui_colorsyntax) {
127          $editorMode = (!empty($_REQUEST['css']) ? "css" : (!empty($_REQUEST['js']) ? "javascript" : "text/html"));
128          echo 
129          '<script>
130          var editor = CodeMirror.fromTextArea(document.getElementById("file_content"), {
131               mode: "'.$editorMode.'",
132                    tabMode: "indent",
133                    lineWrapping: "true",
134                    lineNumbers: "true",
135                    matchBrackets: "true"
136               });
137         </script>';
138     }
139}
140?>
141</div>
142</div>
143
144<div id="file-chooser">
145<h3><?php echo __('Templates files'); ?></h3>
146<?php echo $o->filesList('tpl','<a href="'.$p_url.'&amp;tpl=%2$s" class="tpl-link">%1$s</a>'); ?>
147
148<h3><?php echo __('CSS files'); ?></h3>
149<?php echo $o->filesList('css','<a href="'.$p_url.'&amp;css=%2$s" class="css-link">%1$s</a>'); ?>
150
151<h3><?php echo __('JavaScript files'); ?></h3>
152<?php echo $o->filesList('js','<a href="'.$p_url.'&amp;js=%2$s" class="js-link">%1$s</a>'); ?>
153</div>
154
155<?php dcPage::helpBlock('themeEditor'); ?>
156</body>
157</html>
Note: See TracBrowser for help on using the repository browser.

Sites map