[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 | |
---|
[3703] | 12 | if (!defined('DC_CONTEXT_ADMIN')) {return;} |
---|
[0] | 13 | |
---|
| 14 | if (!isset($__resources['help']['themeEditor'])) { |
---|
[3703] | 15 | $__resources['help']['themeEditor'] = dirname(__FILE__) . '/help.html'; |
---|
[0] | 16 | } |
---|
| 17 | |
---|
[3874] | 18 | $core->addBehavior('adminCurrentThemeDetails', ['themeEditorBehaviors', 'theme_editor_details']); |
---|
[0] | 19 | |
---|
[3874] | 20 | $core->addBehavior('adminBeforeUserOptionsUpdate', ['themeEditorBehaviors', 'adminBeforeUserUpdate']); |
---|
| 21 | $core->addBehavior('adminPreferencesForm', ['themeEditorBehaviors', 'adminPreferencesForm']); |
---|
[948] | 22 | |
---|
| 23 | class themeEditorBehaviors |
---|
[0] | 24 | { |
---|
[3703] | 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 | } |
---|
[948] | 31 | |
---|
[3703] | 32 | public static function adminBeforeUserUpdate($cur, $userID) |
---|
| 33 | { |
---|
| 34 | global $core; |
---|
[948] | 35 | |
---|
[3703] | 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 | } catch (Exception $e) { |
---|
| 43 | $core->error->add($e->getMessage()); |
---|
| 44 | } |
---|
| 45 | } |
---|
[2566] | 46 | |
---|
[3703] | 47 | public static function adminPreferencesForm($core) |
---|
| 48 | { |
---|
| 49 | // Add fieldset for plugin options |
---|
| 50 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
[948] | 51 | |
---|
[3703] | 52 | $themes_list = dcPage::getCodeMirrorThemes(); |
---|
[3874] | 53 | $themes_combo = [__('Default') => '']; |
---|
[3703] | 54 | foreach ($themes_list as $theme) { |
---|
| 55 | $themes_combo[$theme] = $theme; |
---|
| 56 | } |
---|
[3251] | 57 | |
---|
[3703] | 58 | echo |
---|
| 59 | '<div class="fieldset two-cols clearfix">' . |
---|
| 60 | '<h5 id="themeEditor_prefs">' . __('Syntax highlighting') . '</h5>'; |
---|
| 61 | echo |
---|
| 62 | '<div class="col">' . |
---|
| 63 | '<p><label for="colorsyntax" class="classic">' . |
---|
| 64 | form::checkbox('colorsyntax', 1, $core->auth->user_prefs->interface->colorsyntax) . '</label>' . |
---|
| 65 | __('Syntax highlighting in theme editor') . |
---|
| 66 | '</p>'; |
---|
| 67 | if (count($themes_combo) > 1) { |
---|
| 68 | echo |
---|
| 69 | '<p><label for="colorsyntax_theme" class="classic">' . __('Theme:') . '</label> ' . |
---|
| 70 | form::combo('colorsyntax_theme', $themes_combo, |
---|
[3874] | 71 | [ |
---|
[3980] | 72 | 'default' => $core->auth->user_prefs->interface->colorsyntax_theme |
---|
| 73 | ]) . |
---|
[3703] | 74 | '</p>'; |
---|
| 75 | } else { |
---|
| 76 | echo form::hidden('colorsyntax_theme', ''); |
---|
| 77 | } |
---|
| 78 | echo '</div>'; |
---|
| 79 | echo '<div class="col">'; |
---|
[3874] | 80 | echo dcPage::jsLoadCodeMirror('', false, ['javascript']); |
---|
[3703] | 81 | foreach ($themes_list as $theme) { |
---|
| 82 | echo dcPage::cssLoad('js/codemirror/theme/' . $theme . '.css'); |
---|
| 83 | } |
---|
| 84 | echo ' |
---|
[3251] | 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>'; |
---|
[3703] | 98 | echo |
---|
[3980] | 99 | dcPage::jsJson('theme_editor_current', ['theme' => $core->auth->user_prefs->interface->colorsyntax_theme != '' ? $core->auth->user_prefs->interface->colorsyntax_theme : 'default']) . |
---|
| 100 | dcPage::jsLoad(dcPage::getPF('themeEditor/js/theme.js')); |
---|
[3703] | 101 | echo '</div>'; |
---|
| 102 | echo '</div>'; |
---|
| 103 | } |
---|
[0] | 104 | } |
---|