| [2738] | 1 | <?php |
|---|
| [3731] | 2 | /** |
|---|
| 3 | * @brief dcCKEditor, a plugin for Dotclear 2 |
|---|
| 4 | * |
|---|
| 5 | * @package Dotclear |
|---|
| 6 | * @subpackage Plugins |
|---|
| 7 | * |
|---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 9 | * @copyright GPL-2.0-only |
|---|
| 10 | */ |
|---|
| [2738] | 11 | |
|---|
| 12 | class dcCKEditorBehaviors |
|---|
| 13 | { |
|---|
| [3730] | 14 | protected static $p_url = 'index.php?pf=dcCKEditor'; |
|---|
| [2738] | 15 | protected static $config_url = 'plugin.php?p=dcCKEditor&config=1'; |
|---|
| 16 | |
|---|
| [2854] | 17 | /** |
|---|
| 18 | * adminPostEditor add javascript to the DOM to load ckeditor depending on context |
|---|
| 19 | * |
|---|
| 20 | * @param editor <b>string</b> wanted editor |
|---|
| 21 | * @param context <b>string</b> page context (post,page,comment,event,...) |
|---|
| 22 | * @param tags <b>array</b> array of ids into inject editor |
|---|
| [3024] | 23 | * @param syntax <b>string</b> wanted syntax (xhtml) |
|---|
| [2854] | 24 | */ |
|---|
| [3730] | 25 | public static function adminPostEditor($editor = '', $context = '', array $tags = array(), $syntax = 'xhtml') |
|---|
| 26 | { |
|---|
| 27 | if (empty($editor) || $editor != 'dcCKEditor' || $syntax != 'xhtml') {return;} |
|---|
| [2738] | 28 | |
|---|
| [2761] | 29 | $config_js = self::$config_url; |
|---|
| 30 | if (!empty($context)) { |
|---|
| [3730] | 31 | $config_js .= '&context=' . $context; |
|---|
| [2761] | 32 | } |
|---|
| 33 | |
|---|
| [3669] | 34 | $res = |
|---|
| [3730] | 35 | '<script type="text/javascript">' . "\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 | };' . "\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" . |
|---|
| 56 | "</script>\n" . |
|---|
| 57 | dcPage::jsLoad(self::$p_url . '/js/ckeditor/ckeditor.js') . |
|---|
| 58 | dcPage::jsLoad(self::$p_url . '/js/ckeditor/adapters/jquery.js') . |
|---|
| 59 | dcPage::jsLoad($config_js); |
|---|
| [3669] | 60 | |
|---|
| [3730] | 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 | } |
|---|
| [3669] | 67 | |
|---|
| [3730] | 68 | return $res; |
|---|
| [2738] | 69 | } |
|---|
| 70 | |
|---|
| [3730] | 71 | public static function adminPopupMedia($editor = '') |
|---|
| 72 | { |
|---|
| 73 | if (empty($editor) || $editor != 'dcCKEditor') {return;} |
|---|
| [2749] | 74 | |
|---|
| [3730] | 75 | return dcPage::jsLoad(self::$p_url . '/js/popup_media.js'); |
|---|
| [2738] | 76 | } |
|---|
| 77 | |
|---|
| [3730] | 78 | public static function adminPopupLink($editor = '') |
|---|
| 79 | { |
|---|
| 80 | if (empty($editor) || $editor != 'dcCKEditor') {return;} |
|---|
| [2749] | 81 | |
|---|
| [3730] | 82 | return dcPage::jsLoad(self::$p_url . '/js/popup_link.js'); |
|---|
| [2738] | 83 | } |
|---|
| 84 | |
|---|
| [3730] | 85 | public static function adminPopupPosts($editor = '') |
|---|
| 86 | { |
|---|
| 87 | if (empty($editor) || $editor != 'dcCKEditor') {return;} |
|---|
| 88 | |
|---|
| 89 | return dcPage::jsLoad(self::$p_url . '/js/popup_posts.js'); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | public static function adminMediaURLParams($p) |
|---|
| 93 | { |
|---|
| [2738] | 94 | if (!empty($_GET['editor'])) { |
|---|
| [2893] | 95 | $p['editor'] = html::sanitizeURL($_GET['editor']); |
|---|
| [2738] | 96 | } |
|---|
| 97 | } |
|---|
| [2854] | 98 | |
|---|
| [3730] | 99 | public static function getTagsContext() |
|---|
| 100 | { |
|---|
| [2854] | 101 | return self::$tagsContext; |
|---|
| 102 | } |
|---|
| [2738] | 103 | } |
|---|