Dotclear

source: plugins/dcCKEditor/inc/dc.ckeditor.behaviors.php @ 3990:b0ad980ed2ea

Revision 3990:b0ad980ed2ea, 3.5 KB checked in by franck <carnet.franck.paul@…>, 6 years ago (diff)

Oups :-)

Line 
1<?php
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 */
11
12class dcCKEditorBehaviors
13{
14    protected static $p_url      = 'index.php?pf=dcCKEditor';
15    protected static $config_url = 'plugin.php?p=dcCKEditor&config=1';
16
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,...)
22     * @param tags     <b>array</b>  array of elt ids (textarea) where inject editor
23     * @param syntax   <b>string</b> wanted syntax (xhtml)
24     */
25    public static function adminPostEditor($editor = '', $context = '', array $tags = [], $syntax = 'xhtml')
26    {
27        if (empty($editor) || $editor != 'dcCKEditor' || $syntax != 'xhtml') {return;}
28
29        $config_js = self::$config_url;
30        if (!empty($context)) {
31            $config_js .= '&context=' . $context;
32        }
33
34        $res =
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') .
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);
59
60        return $res;
61    }
62
63    public static function adminPopupMedia($editor = '')
64    {
65        if (empty($editor) || $editor != 'dcCKEditor') {return;}
66
67        return dcPage::jsLoad(self::$p_url . '/js/popup_media.js');
68    }
69
70    public static function adminPopupLink($editor = '')
71    {
72        if (empty($editor) || $editor != 'dcCKEditor') {return;}
73
74        return dcPage::jsLoad(self::$p_url . '/js/popup_link.js');
75    }
76
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    {
86        if (!empty($_GET['editor'])) {
87            $p['editor'] = html::sanitizeURL($_GET['editor']);
88        }
89    }
90
91    public static function getTagsContext()
92    {
93        return self::$tagsContext;
94    }
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    }
102}
Note: See TracBrowser for help on using the repository browser.

Sites map