[2738] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @brief dcCKEditor, 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 | */ |
---|
[2738] | 11 | |
---|
| 12 | class dcCKEditorBehaviors |
---|
| 13 | { |
---|
[3730] | 14 | protected static $p_url = 'index.php?pf=dcCKEditor'; |
---|
[2738] | 15 | protected static $config_url = 'plugin.php?p=dcCKEditor&config=1'; |
---|
| 16 | |
---|
[2854] | 17 | /** |
---|
| 18 | * adminPostEditor add javascript to the DOM to load ckeditor depending on context |
---|
| 19 | * |
---|
| 20 | * @param editor <b>string</b> wanted editor |
---|
| 21 | * @param context <b>string</b> page context (post,page,comment,event,...) |
---|
[3977] | 22 | * @param tags <b>array</b> array of elt ids (textarea) where inject editor |
---|
[3024] | 23 | * @param syntax <b>string</b> wanted syntax (xhtml) |
---|
[2854] | 24 | */ |
---|
[3874] | 25 | public static function adminPostEditor($editor = '', $context = '', array $tags = [], $syntax = 'xhtml') |
---|
[3730] | 26 | { |
---|
| 27 | if (empty($editor) || $editor != 'dcCKEditor' || $syntax != 'xhtml') {return;} |
---|
[2738] | 28 | |
---|
[2761] | 29 | $config_js = self::$config_url; |
---|
| 30 | if (!empty($context)) { |
---|
[3730] | 31 | $config_js .= '&context=' . $context; |
---|
[2761] | 32 | } |
---|
| 33 | |
---|
[3669] | 34 | $res = |
---|
[3977] | 35 | dcPage::jsJson('ck_editor_ctx', [ |
---|
| 36 | 'ckeditor_context' => $context, |
---|
| 37 | 'ckeditor_tags_context' => [$context => $tags], |
---|
| 38 | 'admin_base_url' => DC_ADMIN_URL, |
---|
| 39 | 'base_url' => $GLOBALS['core']->blog->host, |
---|
| 40 | 'dcckeditor_plugin_url' => DC_ADMIN_URL . self::$p_url, |
---|
| 41 | 'user_language' => $GLOBALS['core']->auth->getInfo('user_lang') |
---|
| 42 | ]) . |
---|
| 43 | dcPage::jsJson('ck_editor_var', [ |
---|
| 44 | 'CKEDITOR_BASEPATH' => DC_ADMIN_URL . self::$p_url . '/js/ckeditor/' |
---|
| 45 | ]) . |
---|
| 46 | dcPage::jsJson('ck_editor_msg', [ |
---|
| 47 | 'img_select_title' => __('Media chooser'), |
---|
| 48 | 'img_select_accesskey' => __('m'), |
---|
| 49 | 'post_link_title' => __('Link to an entry'), |
---|
| 50 | 'link_title' => __('Link'), |
---|
| 51 | 'link_accesskey' => __('l'), |
---|
| 52 | 'img_title' => __('External image'), |
---|
| 53 | 'url_cannot_be_empty' => __('URL field cannot be empty.') |
---|
| 54 | ]) . |
---|
| 55 | dcPage::jsLoad(self::$p_url . '/js/_post_editor.js') . |
---|
[3730] | 56 | dcPage::jsLoad(self::$p_url . '/js/ckeditor/ckeditor.js') . |
---|
| 57 | dcPage::jsLoad(self::$p_url . '/js/ckeditor/adapters/jquery.js') . |
---|
| 58 | dcPage::jsLoad($config_js); |
---|
[3669] | 59 | |
---|
[3730] | 60 | return $res; |
---|
[2738] | 61 | } |
---|
| 62 | |
---|
[3730] | 63 | public static function adminPopupMedia($editor = '') |
---|
| 64 | { |
---|
| 65 | if (empty($editor) || $editor != 'dcCKEditor') {return;} |
---|
[2749] | 66 | |
---|
[3730] | 67 | return dcPage::jsLoad(self::$p_url . '/js/popup_media.js'); |
---|
[2738] | 68 | } |
---|
| 69 | |
---|
[3730] | 70 | public static function adminPopupLink($editor = '') |
---|
| 71 | { |
---|
| 72 | if (empty($editor) || $editor != 'dcCKEditor') {return;} |
---|
[2749] | 73 | |
---|
[3730] | 74 | return dcPage::jsLoad(self::$p_url . '/js/popup_link.js'); |
---|
[2738] | 75 | } |
---|
| 76 | |
---|
[3730] | 77 | public static function adminPopupPosts($editor = '') |
---|
| 78 | { |
---|
| 79 | if (empty($editor) || $editor != 'dcCKEditor') {return;} |
---|
| 80 | |
---|
| 81 | return dcPage::jsLoad(self::$p_url . '/js/popup_posts.js'); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | public static function adminMediaURLParams($p) |
---|
| 85 | { |
---|
[2738] | 86 | if (!empty($_GET['editor'])) { |
---|
[2893] | 87 | $p['editor'] = html::sanitizeURL($_GET['editor']); |
---|
[2738] | 88 | } |
---|
| 89 | } |
---|
[2854] | 90 | |
---|
[3730] | 91 | public static function getTagsContext() |
---|
| 92 | { |
---|
[2854] | 93 | return self::$tagsContext; |
---|
| 94 | } |
---|
[3988] | 95 | |
---|
| 96 | public static function adminPageHTTPHeaderCSP($csp) |
---|
| 97 | { |
---|
| 98 | // add 'unsafe-inline' for CSS, add 'unsafe-eval' for scripts as far as CKEditor 4.x is used |
---|
| 99 | $csp['style-src'] .= " 'unsafe-inline'"; |
---|
| 100 | $csp['script-src'] .= " 'unsafe-inline' 'unsafe-eval'"; |
---|
| 101 | } |
---|
[2738] | 102 | } |
---|