Dotclear

source: plugins/dcCKEditor/inc/dc.ckeditor.behaviors.php @ 2854:2d4e6314b899

Revision 2854:2d4e6314b899, 3.2 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Add tags into inject ckeditor for adminPostEditor behavior
Addresses #2011

@TODO : need to find a way to add multiple context: for example comment tab on admin/post.php page

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2014 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13class dcCKEditorBehaviors
14{
15    protected static $p_url = 'index.php?pf=dcCKEditor';
16    protected static $config_url = 'plugin.php?p=dcCKEditor&config=1';
17
18    /**
19     * adminPostEditor add javascript to the DOM to load ckeditor depending on context
20     *
21     * @param editor   <b>string</b> wanted editor
22     * @param context  <b>string</b> page context (post,page,comment,event,...)
23     * @param tags     <b>array</b>  array of ids into inject editor
24     */
25    public static function adminPostEditor($editor='',$context='',array $tags=array()) {
26        if (empty($editor) || $editor!='dcCKEditor') { return;}
27
28        $config_js = self::$config_url;
29        if (!empty($context)) {
30            $config_js .= '&context='.$context;
31        }
32
33        return
34            '<script type="text/javascript">'."\n".
35            "//<![CDATA[\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.base_url', $GLOBALS['core']->blog->host).
40            dcPage::jsVar('dotclear.dcckeditor_plugin_url',DC_ADMIN_URL.self::$p_url).
41            'CKEDITOR_GETURL = function(resource) {
42                 // If this is not a full or absolute path.
43                 if ( resource.indexOf(":/") == -1 && resource.indexOf("/") !== 0 ) {
44                      resource = this.basePath + resource;
45                 }
46                 return resource;
47             };'.
48            "dotclear.msg.img_select_title = '".html::escapeJS(__('Media chooser'))."'; ".
49            "dotclear.msg.post_link_title = '".html::escapeJS(__('Link to an entry'))."'; ".
50            "dotclear.msg.link_title = '".html::escapeJS(__('Link'))."'; ".
51            "\n//]]>\n".
52            "</script>\n".
53            dcPage::jsLoad(self::$p_url.'/js/ckeditor/ckeditor.js').
54            dcPage::jsLoad(self::$p_url.'/js/ckeditor/adapters/jquery.js').
55            dcPage::jsLoad($config_js);
56     }
57
58    public static function adminPopupMedia($editor='') {
59        if (empty($editor) || $editor!='dcCKEditor') { return;}
60
61     return dcPage::jsLoad(self::$p_url.'/js/popup_media.js');
62    }
63
64    public static function adminPopupLink($editor='') {
65        if (empty($editor) || $editor!='dcCKEditor') { return;}
66
67     return dcPage::jsLoad(self::$p_url.'/js/popup_link.js');
68    }
69
70    public static function adminPopupPosts($editor='') {
71        if (empty($editor) || $editor!='dcCKEditor') { return;}
72
73     return dcPage::jsLoad(self::$p_url.'/js/popup_posts.js');
74    }
75
76    public static function adminMediaURLParams($p) {
77        if (!empty($_GET['editor'])) {
78            $p['editor']=html::sanitiseURL($_GET['editor']);
79        }
80    }
81
82    public static function getTagsContext() {
83        return self::$tagsContext;
84    }
85}
Note: See TracBrowser for help on using the repository browser.

Sites map