| 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 | */ | 
|---|
| 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 | "dotclear.msg.img_title = '".html::escapeJS(__('External image'))."'; ". | 
|---|
| 52 | "dotclear.msg.url_cannot_be_empty = '".html::escapeJS(__('URL field cannot be empty.'))."';". | 
|---|
| 53 | "\n//]]>\n". | 
|---|
| 54 | "</script>\n". | 
|---|
| 55 | dcPage::jsLoad(self::$p_url.'/js/ckeditor/ckeditor.js'). | 
|---|
| 56 | dcPage::jsLoad(self::$p_url.'/js/ckeditor/adapters/jquery.js'). | 
|---|
| 57 | dcPage::jsLoad($config_js); | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | public static function adminPopupMedia($editor='') { | 
|---|
| 61 | if (empty($editor) || $editor!='dcCKEditor') { return;} | 
|---|
| 62 |  | 
|---|
| 63 | return dcPage::jsLoad(self::$p_url.'/js/popup_media.js'); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | public static function adminPopupLink($editor='') { | 
|---|
| 67 | if (empty($editor) || $editor!='dcCKEditor') { return;} | 
|---|
| 68 |  | 
|---|
| 69 | return dcPage::jsLoad(self::$p_url.'/js/popup_link.js'); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | public static function adminPopupPosts($editor='') { | 
|---|
| 73 | if (empty($editor) || $editor!='dcCKEditor') { return;} | 
|---|
| 74 |  | 
|---|
| 75 | return dcPage::jsLoad(self::$p_url.'/js/popup_posts.js'); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | public static function adminMediaURLParams($p) { | 
|---|
| 79 | if (!empty($_GET['editor'])) { | 
|---|
| 80 | $p['editor'] = html::sanitizeURL($_GET['editor']); | 
|---|
| 81 | } | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | public static function getTagsContext() { | 
|---|
| 85 | return self::$tagsContext; | 
|---|
| 86 | } | 
|---|
| 87 | } | 
|---|