Dotclear

source: plugins/dcCKEditor/_post_config.php @ 2868:2f77d528185b

Revision 2868:2f77d528185b, 6.1 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Add external media for CKEditor
Allow link around external media

Line 
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
13if (!defined('DC_CONTEXT_ADMIN')) { return; }
14header('Content-type: text/javascript');
15if (!empty($_GET['context'])) {
16     $context = $_GET['context'];
17} else {
18     $context = '';
19}
20$__extraPlugins = new ArrayObject();
21$core->callBehavior('ckeditorExtraPlugins',$__extraPlugins,$context);
22$extraPlugins = $__extraPlugins->getArrayCopy();
23?>
24(function($) {
25     $.toolbarPopup = function toolbarPopup(url) {
26          var args = Array.prototype.slice.call(arguments);
27          var width = 520, height = 420;
28          if (args[1]!==undefined) {
29               width = args[1].width || width;
30               height = args[1].height || height;
31          }
32
33          var popup_params = 'alwaysRaised=yes,dependent=yes,toolbar=yes,';
34          popup_params += 'height='+height+',width='+width+',menubar=no,resizable=yes,scrollbars=yes,status=no';
35          var popup_link = window.open(url,'dc_popup', popup_params);
36     };
37
38     $.stripBaseURL = function stripBaseURL(url) {
39          if (dotclear.base_url != '') {
40               var pos = url.indexOf(dotclear.base_url);
41               if (pos == 0) {
42                    url = url.substr(dotclear.base_url.length);
43               }
44          }
45
46          return url;
47     };
48
49     /* Retrieve editor from popup */
50     $.active_editor = null;
51     $.getEditorName = function getEditorName() {
52          return $.active_editor;
53     }
54     chainHandler(window, 'onbeforeunload', function(e) {
55          if (e == undefined && window.event) {
56               e = window.event;
57          }
58
59          var editor = CKEDITOR.instances[$.getEditorName()];
60          if (editor!==undefined && !confirmClosePage.formSubmit && editor.checkDirty()) {
61               e.returnValue = confirmClosePage.prompt;
62               return confirmClosePage.prompt;
63          }
64          return false;
65     });
66})(jQuery);
67
68$(function() {
69     /* By default ckeditor load related resources with a timestamp to avoid cache problem when upgrading itself
70      * load_plugin_file.php does not allow other param that file to load (pf param), so remove timestamp
71      */
72
73     CKEDITOR.timestamp = '';
74     CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/';
75    CKEDITOR.config.baseHref = dotclear.base_url;
76
77<?php if (!empty($dcckeditor_cancollapse_button)):?>
78     CKEDITOR.config.toolbarCanCollapse = true;
79<?php endif;?>
80
81     CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/');
82     CKEDITOR.plugins.addExternal('dclink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/dclink/');
83     CKEDITOR.plugins.addExternal('media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/media/');
84     CKEDITOR.plugins.addExternal('external-media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/external-media/');
85
86<?php if (!empty($extraPlugins) && count($extraPlugins)>0) {
87     foreach ($extraPlugins as $plugin) {
88          printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']);
89     }
90}
91?>
92    if (dotclear.ckeditor_context===undefined || dotclear.ckeditor_tags_context[dotclear.ckeditor_context]===undefined) {
93        return;
94    }
95     $(dotclear.ckeditor_tags_context[dotclear.ckeditor_context].join(',')).ckeditor({
96<?php
97$defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format,external-media';
98if (!empty($extraPlugins) && count($extraPlugins)>0) {
99     foreach ($extraPlugins as $plugin) {
100          $defautExtraPlugins .= ','. $plugin['name'];
101     }
102}
103?>
104          extraPlugins: '<?php echo $defautExtraPlugins;?>',
105
106          <?php if (!empty($dcckeditor_format_select)):?>
107          // format tags
108          format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address',
109
110          // following definition are needed to be specialized
111          format_p: { element: 'p' },
112          format_h1: { element: 'h1' },
113          format_h2: { element: 'h2' },
114          format_h3: { element: 'h3' },
115          format_h4: { element: 'h4' },
116          format_h5: { element: 'h5' },
117          format_h6: { element: 'h6' },
118          format_pre: { element: 'pre' },
119          format_address: { element: 'address' },
120          <?php endif;?>
121
122          entities: false,
123          removeButtons: '',
124          allowedContent: true,
125          toolbar: [
126               {
127                    name: 'basicstyles',
128                    items: [
129<?php if (!empty($dcckeditor_format_select)):?>
130                         'Format',
131<?php endif;?>
132                         'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote',
133
134<?php if (!empty($dcckeditor_list_buttons)):?>
135                         'NumberedList', 'BulletedList',
136<?php endif;?>
137                         'RemoveFormat'
138                    ]
139               },
140<?php if (!empty($dcckeditor_clipboard_buttons)):?>
141               {
142                    name: 'clipoard',
143                    items: ['Cut','Copy','Paste','PasteText','PasteFromWord']
144               },
145<?php endif;?>
146<?php if (!empty($dcckeditor_alignment_buttons)):?>
147               {
148                    name: 'paragraph',
149                    items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
150               },
151<?php endif;?>
152<?php if (!empty($dcckeditor_table_button)):?>
153               {
154                    name: 'table',
155                    items: ['Table']
156               },
157<?php endif;?>
158               {
159                    name: 'custom',
160                    items: [
161                         'EntryLink','dcLink','Media','dcExternalMedia','-',
162                         'Source'
163<?php if (!empty($dcckeditor_textcolor_button)):?>
164                ,'TextColor'
165<?php endif;?>
166                    ]
167               },
168            {
169                name: 'special',
170                items: [
171                    'Maximize'
172                ]
173            },
174               <?php // add extra buttons comming from dotclear plugins
175               if (!empty($extraPlugins) && count($extraPlugins)>0) {
176                    $extraPlugins_str = "{name: 'extra', items: [%s]},\n";
177                    $extra_icons = '';
178                    foreach ($extraPlugins as $plugin) {
179                         $extra_icons .= sprintf("'%s',", $plugin['button']);
180                    }
181                    printf($extraPlugins_str, $extra_icons);
182               }
183               ?>
184          ]
185     });
186
187     CKEDITOR.on('instanceReady', function(e) {
188          if ($('label[for="post_excerpt"] a img').attr('src')==dotclear.img_minus_src) {
189               $('#cke_post_excerpt').removeClass('hide');
190          } else {
191               $('#cke_post_excerpt').addClass('hide');
192          }
193
194          $('#excerpt-area label').click(function() {
195               $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
196          });
197     });
198
199     // @TODO: find a better way to retrieve active editor
200     for (var id in CKEDITOR.instances) {
201          CKEDITOR.instances[id].on('focus', function(e) {
202               $.active_editor = e.editor.name;
203          });
204     }
205});
Note: See TracBrowser for help on using the repository browser.

Sites map