1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 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 | if (!isset($__resources['help']['themeEditor'])) { |
---|
15 | $__resources['help']['themeEditor'] = dirname(__FILE__).'/help.html'; |
---|
16 | } |
---|
17 | |
---|
18 | $core->addBehavior('adminCurrentThemeDetails', array('themeEditorBehaviors','theme_editor_details')); |
---|
19 | |
---|
20 | $core->addBehavior('adminBeforeUserOptionsUpdate',array('themeEditorBehaviors','adminBeforeUserUpdate')); |
---|
21 | $core->addBehavior('adminPreferencesForm',array('themeEditorBehaviors','adminPreferencesForm')); |
---|
22 | |
---|
23 | class themeEditorBehaviors |
---|
24 | { |
---|
25 | public static function theme_editor_details($core,$id) |
---|
26 | { |
---|
27 | if ($id != 'default' && $core->auth->isSuperAdmin()) { |
---|
28 | return '<p><a href="'.$core->adminurl->get('admin.plugin.themeEditor').'" class="button">'.__('Edit theme files').'</a></p>'; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | public static function adminBeforeUserUpdate($cur,$userID) |
---|
33 | { |
---|
34 | global $core; |
---|
35 | |
---|
36 | // Get and store user's prefs for plugin options |
---|
37 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
38 | try { |
---|
39 | $core->auth->user_prefs->interface->put('colorsyntax',!empty($_POST['colorsyntax']),'boolean'); |
---|
40 | $core->auth->user_prefs->interface->put('colorsyntax_theme', |
---|
41 | (!empty($_POST['colorsyntax_theme']) ? $_POST['colorsyntax_theme'] : '')); |
---|
42 | } |
---|
43 | catch (Exception $e) |
---|
44 | { |
---|
45 | $core->error->add($e->getMessage()); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | public static function adminPreferencesForm($core) |
---|
50 | { |
---|
51 | // Add fieldset for plugin options |
---|
52 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
53 | |
---|
54 | $themes_list = dcPage::getCodeMirrorThemes(); |
---|
55 | $themes_combo = array(__('Default') => ''); |
---|
56 | foreach ($themes_list as $theme) { |
---|
57 | $themes_combo[$theme] = $theme; |
---|
58 | } |
---|
59 | |
---|
60 | echo |
---|
61 | '<div class="fieldset two-cols clearfix">'. |
---|
62 | '<h5>'.__('Syntax highlighting').'</h5>'; |
---|
63 | echo |
---|
64 | '<div class="col">'. |
---|
65 | '<p><label for="colorsyntax" class="classic">'. |
---|
66 | form::checkbox('colorsyntax',1,$core->auth->user_prefs->interface->colorsyntax).'</label>'. |
---|
67 | __('Syntax highlighting in theme editor'). |
---|
68 | '</p>'; |
---|
69 | if (count($themes_combo) > 1) { |
---|
70 | echo |
---|
71 | '<p><label for="colorsyntax_theme" class="classic">'.__('Theme:').'</label> '. |
---|
72 | form::combo('colorsyntax_theme',$themes_combo,$core->auth->user_prefs->interface->colorsyntax_theme, |
---|
73 | '','',false,'onchange="selectTheme()"'). |
---|
74 | '</p>'; |
---|
75 | } else { |
---|
76 | echo form::hidden('colorsyntax_theme',''); |
---|
77 | } |
---|
78 | echo '</div>'; |
---|
79 | echo '<div class="col">'; |
---|
80 | echo dcPage::jsCodeMirror('',false,array('javascript')); |
---|
81 | foreach ($themes_list as $theme) { |
---|
82 | echo dcPage::cssLoad('js/codemirror/theme/'.$theme.'.css'); |
---|
83 | } |
---|
84 | echo ' |
---|
85 | <textarea id="codemirror" name="codemirror"> |
---|
86 | function findSequence(goal) { |
---|
87 | function find(start, history) { |
---|
88 | if (start == goal) |
---|
89 | return history; |
---|
90 | else if (start > goal) |
---|
91 | return null; |
---|
92 | else |
---|
93 | return find(start + 5, "(" + history + " + 5)") || |
---|
94 | find(start * 3, "(" + history + " * 3)"); |
---|
95 | } |
---|
96 | return find(1, "1"); |
---|
97 | }</textarea>'; |
---|
98 | echo |
---|
99 | '<script> |
---|
100 | var input = document.getElementById("colorsyntax_theme"); |
---|
101 | var theme = input.options[input.selectedIndex].textContent; |
---|
102 | var editor = CodeMirror.fromTextArea(document.getElementById("codemirror"), { |
---|
103 | mode: "javascript", |
---|
104 | tabMode: "indent", |
---|
105 | lineWrapping: "true", |
---|
106 | lineNumbers: "true", |
---|
107 | matchBrackets: "true", |
---|
108 | autoCloseBrackets: "true", |
---|
109 | theme: "'.($core->auth->user_prefs->interface->colorsyntax_theme != '' ? $core->auth->user_prefs->interface->colorsyntax_theme : 'default').'" |
---|
110 | }); |
---|
111 | function selectTheme() { |
---|
112 | var input = document.getElementById("colorsyntax_theme"); |
---|
113 | var theme = input.options[input.selectedIndex].value; |
---|
114 | if (theme == "") theme = "default"; |
---|
115 | editor.setOption("theme", theme); |
---|
116 | editor.refresh(); |
---|
117 | } |
---|
118 | </script>'; |
---|
119 | echo '</div>'; |
---|
120 | echo '</div>'; |
---|
121 | } |
---|
122 | } |
---|