| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @brief dcLegacyEditor, 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 | |
|---|
| 12 | class dcLegacyEditorBehaviors |
|---|
| 13 | { |
|---|
| 14 | protected static $p_url = 'index.php?pf=dcLegacyEditor'; |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * adminPostEditor add javascript to the DOM to load ckeditor depending on context |
|---|
| 18 | * |
|---|
| 19 | * @param editor <b>string</b> wanted editor |
|---|
| 20 | * @param context <b>string</b> page context (post,page,comment,event,...) |
|---|
| 21 | * @param tags <b>array</b> array of ids to inject editor |
|---|
| 22 | * @param syntax <b>string</b> wanted syntax (wiki,markdown,...) |
|---|
| 23 | */ |
|---|
| 24 | public static function adminPostEditor($editor = '', $context = '', array $tags = [], $syntax = '') |
|---|
| 25 | { |
|---|
| 26 | if (empty($editor) || $editor != 'dcLegacyEditor') {return;} |
|---|
| 27 | |
|---|
| 28 | $js = [ |
|---|
| 29 | 'legacy_editor_context' => $context, |
|---|
| 30 | 'legacy_editor_syntax' => $syntax, |
|---|
| 31 | 'legacy_editor_tags_context' => [$context => $tags] |
|---|
| 32 | ]; |
|---|
| 33 | |
|---|
| 34 | return |
|---|
| 35 | self::jsToolBar() . |
|---|
| 36 | dcPage::jsJson('legacy_editor_ctx', $js) . |
|---|
| 37 | dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/_post_editor.js')); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | public static function adminPopupMedia($editor = '') |
|---|
| 41 | { |
|---|
| 42 | if (empty($editor) || $editor != 'dcLegacyEditor') {return;} |
|---|
| 43 | |
|---|
| 44 | return dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/popup_media.js')); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | public static function adminPopupLink($editor = '') |
|---|
| 48 | { |
|---|
| 49 | if (empty($editor) || $editor != 'dcLegacyEditor') {return;} |
|---|
| 50 | |
|---|
| 51 | return dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/popup_link.js')); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | public static function adminPopupPosts($editor = '') |
|---|
| 55 | { |
|---|
| 56 | if (empty($editor) || $editor != 'dcLegacyEditor') {return;} |
|---|
| 57 | |
|---|
| 58 | return dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/popup_posts.js')); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | protected static function jsToolBar() |
|---|
| 62 | { |
|---|
| 63 | $rtl = l10n::getTextDirection($GLOBALS['_lang']) == 'rtl' ? 'direction: rtl;' : ''; |
|---|
| 64 | $css = <<<EOT |
|---|
| 65 | body { |
|---|
| 66 | color: #000; |
|---|
| 67 | background: #f9f9f9; |
|---|
| 68 | margin: 0; |
|---|
| 69 | padding: 2px; |
|---|
| 70 | border: none; |
|---|
| 71 | $rtl |
|---|
| 72 | } |
|---|
| 73 | code { |
|---|
| 74 | color: #666; |
|---|
| 75 | font-weight: bold; |
|---|
| 76 | } |
|---|
| 77 | body > p:first-child { |
|---|
| 78 | margin-top: 0; |
|---|
| 79 | } |
|---|
| 80 | EOT; |
|---|
| 81 | $js = [ |
|---|
| 82 | 'dialog_url' => 'popup.php', |
|---|
| 83 | 'iframe_css' => $css, |
|---|
| 84 | 'base_url' => $GLOBALS['core']->blog->host, |
|---|
| 85 | 'switcher_visual_title' => __('visual'), |
|---|
| 86 | 'switcher_source_title' => __('source'), |
|---|
| 87 | 'legend_msg' => __('You can use the following shortcuts to format your text.'), |
|---|
| 88 | 'elements' => [ |
|---|
| 89 | 'blocks' => ['options' => [ |
|---|
| 90 | 'none' => __('-- none --'), |
|---|
| 91 | 'nonebis' => __('-- block format --'), |
|---|
| 92 | 'p' => __('Paragraph'), |
|---|
| 93 | 'h1' => __('Level 1 header'), |
|---|
| 94 | 'h2' => __('Level 2 header'), |
|---|
| 95 | 'h3' => __('Level 3 header'), |
|---|
| 96 | 'h4' => __('Level 4 header'), |
|---|
| 97 | 'h5' => __('Level 5 header'), |
|---|
| 98 | 'h6' => __('Level 6 header'), |
|---|
| 99 | ]], |
|---|
| 100 | |
|---|
| 101 | 'strong' => ['title' => __('Strong emphasis')], |
|---|
| 102 | 'em' => ['title' => __('Emphasis')], |
|---|
| 103 | 'ins' => ['title' => __('Inserted')], |
|---|
| 104 | 'del' => ['title' => __('Deleted')], |
|---|
| 105 | 'quote' => ['title' => __('Inline quote')], |
|---|
| 106 | 'code' => ['title' => __('Code')], |
|---|
| 107 | 'mark' => ['title' => __('Mark')], |
|---|
| 108 | 'br' => ['title' => __('Line break')], |
|---|
| 109 | 'blockquote' => ['title' => __('Blockquote')], |
|---|
| 110 | 'pre' => ['title' => __('Preformated text')], |
|---|
| 111 | 'ul' => ['title' => __('Unordered list')], |
|---|
| 112 | 'ol' => ['title' => __('Ordered list')], |
|---|
| 113 | |
|---|
| 114 | 'link' => [ |
|---|
| 115 | 'title' => __('Link'), |
|---|
| 116 | 'accesskey' => __('l'), |
|---|
| 117 | 'href_prompt' => __('URL?'), |
|---|
| 118 | 'hreflang_prompt' => __('Language?') |
|---|
| 119 | ], |
|---|
| 120 | |
|---|
| 121 | 'img' => [ |
|---|
| 122 | 'title' => __('External image'), |
|---|
| 123 | 'src_prompt' => __('URL?') |
|---|
| 124 | ], |
|---|
| 125 | |
|---|
| 126 | 'img_select' => [ |
|---|
| 127 | 'title' => __('Media chooser'), |
|---|
| 128 | 'accesskey' => __('m') |
|---|
| 129 | ], |
|---|
| 130 | |
|---|
| 131 | 'post_link' => ['title' => __('Link to an entry')], |
|---|
| 132 | 'removeFormat' => ['title' => __('Remove text formating')] |
|---|
| 133 | ], |
|---|
| 134 | 'toolbar_bottom' => (boolean) isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('toolbar_bottom') |
|---|
| 135 | ]; |
|---|
| 136 | if (!$GLOBALS['core']->auth->check('media,media_admin', $GLOBALS['core']->blog->id)) { |
|---|
| 137 | $js['elements']['img_select']['disabled'] = true; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | $res = |
|---|
| 141 | dcPage::jsJson('legacy_editor', $js) . |
|---|
| 142 | dcPage::cssLoad(dcPage::getPF('dcLegacyEditor/css/jsToolBar/jsToolBar.css')) . |
|---|
| 143 | dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.js')); |
|---|
| 144 | |
|---|
| 145 | if (isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('enable_wysiwyg')) { |
|---|
| 146 | $res .= dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.wysiwyg.js')); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | $res .= |
|---|
| 150 | dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js')) . |
|---|
| 151 | dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.config.js')); |
|---|
| 152 | |
|---|
| 153 | return $res; |
|---|
| 154 | } |
|---|
| 155 | } |
|---|