| 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 | |
|---|
| 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 | * @param syntax <b>string</b> wanted syntax (xhtml) |
|---|
| 25 | */ |
|---|
| 26 | public static function adminPostEditor($editor='',$context='',array $tags=array(),$syntax='xhtml') { |
|---|
| 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 | return |
|---|
| 35 | '<script type="text/javascript">'."\n". |
|---|
| 36 | "//<![CDATA[\n". |
|---|
| 37 | dcPage::jsVar('dotclear.ckeditor_context', $context). |
|---|
| 38 | 'dotclear.ckeditor_tags_context = '.sprintf('{%s:["%s"]};'."\n", $context, implode('","', $tags)). |
|---|
| 39 | 'var CKEDITOR_BASEPATH = "'.DC_ADMIN_URL.self::$p_url.'/js/ckeditor/";'."\n". |
|---|
| 40 | dcPage::jsVar('dotclear.admin_base_url', DC_ADMIN_URL). |
|---|
| 41 | dcPage::jsVar('dotclear.base_url', $GLOBALS['core']->blog->host). |
|---|
| 42 | dcPage::jsVar('dotclear.dcckeditor_plugin_url',DC_ADMIN_URL.self::$p_url). |
|---|
| 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 | };'. |
|---|
| 50 | "dotclear.msg.img_select_title = '".html::escapeJS(__('Media chooser'))."'; ". |
|---|
| 51 | "dotclear.msg.img_select_accesskey = '".html::escapeJS(__('m'))."'; ". |
|---|
| 52 | "dotclear.msg.post_link_title = '".html::escapeJS(__('Link to an entry'))."'; ". |
|---|
| 53 | "dotclear.msg.link_title = '".html::escapeJS(__('Link'))."'; ". |
|---|
| 54 | "dotclear.msg.link_accesskey = '".html::escapeJS(__('l'))."'; ". |
|---|
| 55 | "dotclear.msg.img_title = '".html::escapeJS(__('External image'))."'; ". |
|---|
| 56 | "dotclear.msg.url_cannot_be_empty = '".html::escapeJS(__('URL field cannot be empty.'))."';". |
|---|
| 57 | "\n//]]>\n". |
|---|
| 58 | "</script>\n". |
|---|
| 59 | dcPage::jsLoad(self::$p_url.'/js/ckeditor/ckeditor.js'). |
|---|
| 60 | dcPage::jsLoad(self::$p_url.'/js/ckeditor/adapters/jquery.js'). |
|---|
| 61 | dcPage::jsLoad($config_js); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | public static function adminPopupMedia($editor='') { |
|---|
| 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 | if (empty($editor) || $editor!='dcCKEditor') { return;} |
|---|
| 72 | |
|---|
| 73 | return dcPage::jsLoad(self::$p_url.'/js/popup_link.js'); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public static function adminPopupPosts($editor='') { |
|---|
| 77 | if (empty($editor) || $editor!='dcCKEditor') { return;} |
|---|
| 78 | |
|---|
| 79 | return dcPage::jsLoad(self::$p_url.'/js/popup_posts.js'); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | public static function adminMediaURLParams($p) { |
|---|
| 83 | if (!empty($_GET['editor'])) { |
|---|
| 84 | $p['editor'] = html::sanitizeURL($_GET['editor']); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | public static function getTagsContext() { |
|---|
| 89 | return self::$tagsContext; |
|---|
| 90 | } |
|---|
| 91 | } |
|---|