Dotclear

source: plugins/dcCKEditor/inc/dc.ckeditor.behaviors.php @ 3915:a57821ba9ef1

Revision 3915:a57821ba9ef1, 3.7 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Switching from inline JS variables to JSON script. A step ahead…

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 ids into 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        '<script type="text/javascript">' . "\n" .
36        dcPage::jsVar('dotclear.ckeditor_context', $context) .
37        'dotclear.ckeditor_tags_context = ' . sprintf('{%s:["%s"]};' . "\n", $context, implode('","', $tags)) .
38        'var CKEDITOR_BASEPATH = "' . DC_ADMIN_URL . self::$p_url . '/js/ckeditor/";' . "\n" .
39        dcPage::jsVar('dotclear.admin_base_url', DC_ADMIN_URL) .
40        dcPage::jsVar('dotclear.base_url', $GLOBALS['core']->blog->host) .
41        dcPage::jsVar('dotclear.dcckeditor_plugin_url', DC_ADMIN_URL . self::$p_url) .
42        dcPage::jsVar('dotclear.user_language', $GLOBALS['core']->auth->getInfo('user_lang')) .
43        'CKEDITOR_GETURL = function(resource) {
44                // If this is not a full or absolute path.
45                if ( resource.indexOf(":/") == -1 && resource.indexOf("/") !== 0 ) {
46                    resource = this.basePath + resource;
47                }
48                return resource;
49             };' . "\n" .
50        "dotclear.msg.img_select_title = '" . html::escapeJS(__('Media chooser')) . "'; " . "\n" .
51        "dotclear.msg.img_select_accesskey = '" . html::escapeJS(__('m')) . "'; " . "\n" .
52        "dotclear.msg.post_link_title = '" . html::escapeJS(__('Link to an entry')) . "'; " . "\n" .
53        "dotclear.msg.link_title = '" . html::escapeJS(__('Link')) . "'; " . "\n" .
54        "dotclear.msg.link_accesskey = '" . html::escapeJS(__('l')) . "'; " . "\n" .
55        "dotclear.msg.img_title = '" . html::escapeJS(__('External image')) . "'; " . "\n" .
56        "dotclear.msg.url_cannot_be_empty = '" . html::escapeJS(__('URL field cannot be empty.')) . "';" . "\n" .
57        "</script>\n" .
58        dcPage::jsLoad(self::$p_url . '/js/ckeditor/ckeditor.js') .
59        dcPage::jsLoad(self::$p_url . '/js/ckeditor/adapters/jquery.js') .
60        dcPage::jsLoad($config_js);
61
62        return $res;
63    }
64
65    public static function adminPopupMedia($editor = '')
66    {
67        if (empty($editor) || $editor != 'dcCKEditor') {return;}
68
69        return dcPage::jsLoad(self::$p_url . '/js/popup_media.js');
70    }
71
72    public static function adminPopupLink($editor = '')
73    {
74        if (empty($editor) || $editor != 'dcCKEditor') {return;}
75
76        return dcPage::jsLoad(self::$p_url . '/js/popup_link.js');
77    }
78
79    public static function adminPopupPosts($editor = '')
80    {
81        if (empty($editor) || $editor != 'dcCKEditor') {return;}
82
83        return dcPage::jsLoad(self::$p_url . '/js/popup_posts.js');
84    }
85
86    public static function adminMediaURLParams($p)
87    {
88        if (!empty($_GET['editor'])) {
89            $p['editor'] = html::sanitizeURL($_GET['editor']);
90        }
91    }
92
93    public static function getTagsContext()
94    {
95        return self::$tagsContext;
96    }
97}
Note: See TracBrowser for help on using the repository browser.

Sites map