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 | return |
---|
29 | self::jsToolBar() . |
---|
30 | dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/_post_editor.js')) . |
---|
31 | '<script type="text/javascript">' . "\n" . |
---|
32 | dcPage::jsVar('dotclear.legacy_editor_context', $context) . |
---|
33 | dcPage::jsVar('dotclear.legacy_editor_syntax', $syntax) . |
---|
34 | 'dotclear.legacy_editor_tags_context = ' . sprintf('{%s:["%s"]};' . "\n", $context, implode('","', $tags)) . "\n" . |
---|
35 | "</script>\n"; |
---|
36 | } |
---|
37 | |
---|
38 | public static function adminPopupMedia($editor = '') |
---|
39 | { |
---|
40 | if (empty($editor) || $editor != 'dcLegacyEditor') {return;} |
---|
41 | |
---|
42 | return dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/popup_media.js')); |
---|
43 | } |
---|
44 | |
---|
45 | public static function adminPopupLink($editor = '') |
---|
46 | { |
---|
47 | if (empty($editor) || $editor != 'dcLegacyEditor') {return;} |
---|
48 | |
---|
49 | return dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/popup_link.js')); |
---|
50 | } |
---|
51 | |
---|
52 | public static function adminPopupPosts($editor = '') |
---|
53 | { |
---|
54 | if (empty($editor) || $editor != 'dcLegacyEditor') {return;} |
---|
55 | |
---|
56 | return dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/popup_posts.js')); |
---|
57 | } |
---|
58 | |
---|
59 | protected static function jsToolBar() |
---|
60 | { |
---|
61 | $res = |
---|
62 | dcPage::cssLoad(dcPage::getPF('dcLegacyEditor/css/jsToolBar/jsToolBar.css')) . |
---|
63 | dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.js')); |
---|
64 | |
---|
65 | if (isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('enable_wysiwyg')) { |
---|
66 | $res .= dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.wysiwyg.js')); |
---|
67 | } |
---|
68 | |
---|
69 | $res .= |
---|
70 | dcPage::jsLoad(dcPage::getPF('dcLegacyEditor/js/jsToolBar/jsToolBar.dotclear.js')) . |
---|
71 | '<script type="text/javascript">' . "\n" . |
---|
72 | "jsToolBar.prototype.dialog_url = 'popup.php'; " . "\n" . |
---|
73 | "jsToolBar.prototype.iframe_css = '" . |
---|
74 | 'body {' . |
---|
75 | ' color: #000;' . |
---|
76 | ' background: #f9f9f9;' . |
---|
77 | ' margin: 0;' . |
---|
78 | ' padding: 2px;' . |
---|
79 | ' border: none;' . |
---|
80 | (l10n::getTextDirection($GLOBALS['_lang']) == 'rtl' ? ' direction: rtl;' : '') . |
---|
81 | '}' . |
---|
82 | 'code {' . |
---|
83 | ' color: #666;' . |
---|
84 | ' font-weight: bold;' . |
---|
85 | '}' . |
---|
86 | 'body > p:first-child {' . |
---|
87 | ' margin-top: 0;' . |
---|
88 | '}' . |
---|
89 | "'; " . "\n" . |
---|
90 | "jsToolBar.prototype.base_url = '" . html::escapeJS($GLOBALS['core']->blog->host) . "'; " . "\n" . |
---|
91 | "jsToolBar.prototype.switcher_visual_title = '" . html::escapeJS(__('visual')) . "'; " . "\n" . |
---|
92 | "jsToolBar.prototype.switcher_source_title = '" . html::escapeJS(__('source')) . "'; " . "\n" . |
---|
93 | "jsToolBar.prototype.legend_msg = '" . |
---|
94 | html::escapeJS(__('You can use the following shortcuts to format your text.')) . "'; " . "\n" . |
---|
95 | "jsToolBar.prototype.elements.blocks.options.none = '" . html::escapeJS(__('-- none --')) . "'; " . "\n" . |
---|
96 | "jsToolBar.prototype.elements.blocks.options.nonebis = '" . html::escapeJS(__('-- block format --')) . "'; " . "\n" . |
---|
97 | "jsToolBar.prototype.elements.blocks.options.p = '" . html::escapeJS(__('Paragraph')) . "'; " . "\n" . |
---|
98 | "jsToolBar.prototype.elements.blocks.options.h1 = '" . html::escapeJS(__('Level 1 header')) . "'; " . "\n" . |
---|
99 | "jsToolBar.prototype.elements.blocks.options.h2 = '" . html::escapeJS(__('Level 2 header')) . "'; " . "\n" . |
---|
100 | "jsToolBar.prototype.elements.blocks.options.h3 = '" . html::escapeJS(__('Level 3 header')) . "'; " . "\n" . |
---|
101 | "jsToolBar.prototype.elements.blocks.options.h4 = '" . html::escapeJS(__('Level 4 header')) . "'; " . "\n" . |
---|
102 | "jsToolBar.prototype.elements.blocks.options.h5 = '" . html::escapeJS(__('Level 5 header')) . "'; " . "\n" . |
---|
103 | "jsToolBar.prototype.elements.blocks.options.h6 = '" . html::escapeJS(__('Level 6 header')) . "'; " . "\n" . |
---|
104 | "jsToolBar.prototype.elements.strong.title = '" . html::escapeJS(__('Strong emphasis')) . "'; " . "\n" . |
---|
105 | "jsToolBar.prototype.elements.em.title = '" . html::escapeJS(__('Emphasis')) . "'; " . "\n" . |
---|
106 | "jsToolBar.prototype.elements.ins.title = '" . html::escapeJS(__('Inserted')) . "'; " . "\n" . |
---|
107 | "jsToolBar.prototype.elements.del.title = '" . html::escapeJS(__('Deleted')) . "'; " . "\n" . |
---|
108 | "jsToolBar.prototype.elements.quote.title = '" . html::escapeJS(__('Inline quote')) . "'; " . "\n" . |
---|
109 | "jsToolBar.prototype.elements.code.title = '" . html::escapeJS(__('Code')) . "'; " . "\n" . |
---|
110 | "jsToolBar.prototype.elements.mark.title = '" . html::escapeJS(__('Mark')) . "'; " . "\n" . |
---|
111 | "jsToolBar.prototype.elements.br.title = '" . html::escapeJS(__('Line break')) . "'; " . "\n" . |
---|
112 | "jsToolBar.prototype.elements.blockquote.title = '" . html::escapeJS(__('Blockquote')) . "'; " . "\n" . |
---|
113 | "jsToolBar.prototype.elements.pre.title = '" . html::escapeJS(__('Preformated text')) . "'; " . "\n" . |
---|
114 | "jsToolBar.prototype.elements.ul.title = '" . html::escapeJS(__('Unordered list')) . "'; " . "\n" . |
---|
115 | "jsToolBar.prototype.elements.ol.title = '" . html::escapeJS(__('Ordered list')) . "'; " . "\n" . |
---|
116 | |
---|
117 | "jsToolBar.prototype.elements.link.title = '" . html::escapeJS(__('Link')) . "'; " . "\n" . |
---|
118 | "jsToolBar.prototype.elements.link.accesskey = '" . html::escapeJS(__('l')) . "'; " . "\n" . |
---|
119 | "jsToolBar.prototype.elements.link.href_prompt = '" . html::escapeJS(__('URL?')) . "'; " . "\n" . |
---|
120 | "jsToolBar.prototype.elements.link.hreflang_prompt = '" . html::escapeJS(__('Language?')) . "'; " . "\n" . |
---|
121 | |
---|
122 | "jsToolBar.prototype.elements.img.title = '" . html::escapeJS(__('External image')) . "'; " . "\n" . |
---|
123 | "jsToolBar.prototype.elements.img.src_prompt = '" . html::escapeJS(__('URL?')) . "'; " . "\n" . |
---|
124 | |
---|
125 | "jsToolBar.prototype.elements.img_select.title = '" . html::escapeJS(__('Media chooser')) . "'; " . "\n" . |
---|
126 | "jsToolBar.prototype.elements.img_select.accesskey = '" . html::escapeJS(__('m')) . "'; " . "\n" . |
---|
127 | "jsToolBar.prototype.elements.post_link.title = '" . html::escapeJS(__('Link to an entry')) . "'; " . "\n" . |
---|
128 | "jsToolBar.prototype.elements.removeFormat = jsToolBar.prototype.elements.removeFormat || {}; " . "\n" . |
---|
129 | "jsToolBar.prototype.elements.removeFormat.title = '" . html::escapeJS(__('Remove text formating')) . "'; " . "\n"; |
---|
130 | |
---|
131 | if (!$GLOBALS['core']->auth->check('media,media_admin', $GLOBALS['core']->blog->id)) { |
---|
132 | $res .= "jsToolBar.prototype.elements.img_select.disabled = true;\n"; |
---|
133 | } |
---|
134 | |
---|
135 | $res .= "jsToolBar.prototype.toolbar_bottom = " . |
---|
136 | (isset($GLOBALS['core']->auth) && $GLOBALS['core']->auth->getOption('toolbar_bottom') ? 'true' : 'false') . ";\n"; |
---|
137 | |
---|
138 | $res .= |
---|
139 | "</script>\n"; |
---|
140 | |
---|
141 | return $res; |
---|
142 | } |
---|
143 | } |
---|