[2738] | 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 | |
---|
| 13 | class dcCKEditorBehaviors |
---|
| 14 | { |
---|
| 15 | protected static $p_url = 'index.php?pf=dcCKEditor'; |
---|
| 16 | protected static $config_url = 'plugin.php?p=dcCKEditor&config=1'; |
---|
| 17 | |
---|
[2854] | 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 |
---|
[3024] | 24 | * @param syntax <b>string</b> wanted syntax (xhtml) |
---|
[2854] | 25 | */ |
---|
[3024] | 26 | public static function adminPostEditor($editor='',$context='',array $tags=array(),$syntax='xhtml') { |
---|
| 27 | if (empty($editor) || $editor != 'dcCKEditor' || $syntax != 'xhtml') { return;} |
---|
[2738] | 28 | |
---|
[2761] | 29 | $config_js = self::$config_url; |
---|
| 30 | if (!empty($context)) { |
---|
| 31 | $config_js .= '&context='.$context; |
---|
| 32 | } |
---|
| 33 | |
---|
[3669] | 34 | $res = |
---|
[2738] | 35 | '<script type="text/javascript">'."\n". |
---|
[2854] | 36 | dcPage::jsVar('dotclear.ckeditor_context', $context). |
---|
| 37 | 'dotclear.ckeditor_tags_context = '.sprintf('{%s:["%s"]};'."\n", $context, implode('","', $tags)). |
---|
[2738] | 38 | 'var CKEDITOR_BASEPATH = "'.DC_ADMIN_URL.self::$p_url.'/js/ckeditor/";'."\n". |
---|
[2962] | 39 | dcPage::jsVar('dotclear.admin_base_url', DC_ADMIN_URL). |
---|
[2738] | 40 | dcPage::jsVar('dotclear.base_url', $GLOBALS['core']->blog->host). |
---|
| 41 | dcPage::jsVar('dotclear.dcckeditor_plugin_url',DC_ADMIN_URL.self::$p_url). |
---|
| 42 | 'CKEDITOR_GETURL = function(resource) { |
---|
| 43 | // If this is not a full or absolute path. |
---|
| 44 | if ( resource.indexOf(":/") == -1 && resource.indexOf("/") !== 0 ) { |
---|
| 45 | resource = this.basePath + resource; |
---|
| 46 | } |
---|
| 47 | return resource; |
---|
[3421] | 48 | };'."\n". |
---|
| 49 | "dotclear.msg.img_select_title = '".html::escapeJS(__('Media chooser'))."'; "."\n". |
---|
| 50 | "dotclear.msg.img_select_accesskey = '".html::escapeJS(__('m'))."'; "."\n". |
---|
| 51 | "dotclear.msg.post_link_title = '".html::escapeJS(__('Link to an entry'))."'; "."\n". |
---|
| 52 | "dotclear.msg.link_title = '".html::escapeJS(__('Link'))."'; "."\n". |
---|
| 53 | "dotclear.msg.link_accesskey = '".html::escapeJS(__('l'))."'; "."\n". |
---|
| 54 | "dotclear.msg.img_title = '".html::escapeJS(__('External image'))."'; "."\n". |
---|
| 55 | "dotclear.msg.url_cannot_be_empty = '".html::escapeJS(__('URL field cannot be empty.'))."';"."\n". |
---|
[2738] | 56 | "</script>\n". |
---|
| 57 | dcPage::jsLoad(self::$p_url.'/js/ckeditor/ckeditor.js'). |
---|
| 58 | dcPage::jsLoad(self::$p_url.'/js/ckeditor/adapters/jquery.js'). |
---|
[2761] | 59 | dcPage::jsLoad($config_js); |
---|
[3669] | 60 | |
---|
| 61 | if ($GLOBALS['core']->auth->user_prefs->interface->htmlfontsize) { |
---|
| 62 | $res .= |
---|
| 63 | '<script type="text/javascript">'."\n". |
---|
| 64 | dcPage::jsVar('dotclear_htmlFontSize',$GLOBALS['core']->auth->user_prefs->interface->htmlfontsize)."\n". |
---|
| 65 | "</script>\n"; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | return $res; |
---|
[2738] | 69 | } |
---|
| 70 | |
---|
[2749] | 71 | public static function adminPopupMedia($editor='') { |
---|
| 72 | if (empty($editor) || $editor!='dcCKEditor') { return;} |
---|
| 73 | |
---|
[2738] | 74 | return dcPage::jsLoad(self::$p_url.'/js/popup_media.js'); |
---|
| 75 | } |
---|
| 76 | |
---|
[2749] | 77 | public static function adminPopupLink($editor='') { |
---|
| 78 | if (empty($editor) || $editor!='dcCKEditor') { return;} |
---|
| 79 | |
---|
[2738] | 80 | return dcPage::jsLoad(self::$p_url.'/js/popup_link.js'); |
---|
| 81 | } |
---|
| 82 | |
---|
[2749] | 83 | public static function adminPopupPosts($editor='') { |
---|
| 84 | if (empty($editor) || $editor!='dcCKEditor') { return;} |
---|
| 85 | |
---|
[2738] | 86 | return dcPage::jsLoad(self::$p_url.'/js/popup_posts.js'); |
---|
| 87 | } |
---|
| 88 | |
---|
[2852] | 89 | public static function adminMediaURLParams($p) { |
---|
[2738] | 90 | if (!empty($_GET['editor'])) { |
---|
[2893] | 91 | $p['editor'] = html::sanitizeURL($_GET['editor']); |
---|
[2738] | 92 | } |
---|
| 93 | } |
---|
[2854] | 94 | |
---|
| 95 | public static function getTagsContext() { |
---|
| 96 | return self::$tagsContext; |
---|
| 97 | } |
---|
[2738] | 98 | } |
---|