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