Dotclear

source: plugins/dcCKEditor/_post_config.php @ 2761:6b76144ca48b

Revision 2761:6b76144ca48b, 5.1 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

CKEditor can now load external plugins such as tags, series,...
Closes #1992

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

Sites map