3
* @version $Id: jce.php 9526 2007-12-08 23:29:19Z robs $
5
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
6
* @license GNU/GPL, see LICENSE.php
7
* Joomla! is free software. This version may have been modified pursuant
8
* to the GNU General Public License, and as distributed it includes or
9
* is derivative of works licensed under the GNU General Public License or
10
* other free or open source software licenses.
11
* See COPYRIGHT.php for copyright notices and details.
14
// Do not allow direct access
15
defined( '_JEXEC' ) or die( 'Restricted access' );
17
jimport( 'joomla.plugin.plugin' );
20
* JCE WYSIWYG Editor Plugin
22
* @author Louis Landry <louis.landry@joomla.org>
26
class plgEditorJCE extends JPlugin
31
* For php4 compatability we must not use the __constructor as a constructor for plugins
32
* because func_get_args ( void ) returns a copy of all passed arguments NOT references.
33
* This causes problems with cross-referencing necessary for the observer design pattern.
35
* @param object $subject The object to observe
36
* @param array $config An array that holds the plugin configuration
39
function plgEditorJCE(& $subject, $config){
40
parent::__construct($subject, $config);
44
* Method to handle the onInit event.
45
* - Initializes the TinyMCE WYSIWYG Editor
48
* @return string JavaScript Initialization string
54
// Editor gets loaded twice in Legacy mode???
55
if( defined( '_JCE_ISLOADED' ) ){
58
define( '_JCE_ISLOADED', 1 );
60
if( !is_dir( JPATH_SITE .DS. 'components' .DS. 'com_jce' ) || !is_dir( JPATH_ADMINISTRATOR .DS. 'components' .DS. 'com_jce' ) ){
61
JError::raiseWarning( '404', 'The JCE Administration Component is not installed! The Editor cannot function without it!' );
64
JLoader::import( 'editors.jce.libraries.classes.editor', JPATH_PLUGINS );
66
$jce =& JContentEditor::getInstance();
67
$url = $jce->getSite();
69
$load = "\t<script type=\"text/javascript\" src=\"". $url ."plugins/editors/jce/tiny_mce/tiny_mce.js?version=". $jce->getVersion() ."\"></script>\n";
70
$load .= "<script type=\"text/javascript\" src=\"". $url ."plugins/editors/jce/libraries/js/editor.js?version=". $jce->getVersion() ."\"></script>\n";
72
$params = $jce->getEditorParams();
76
if( $jce->checkUser() ){
80
$param['document_base_url'] = $url;
81
$param['site_url'] = $mainframe->isAdmin() ? $url . 'administrator/' : $url;
84
$param['theme_advanced_toolbar_location'] = $jce->getParam( $params, 'editor_theme_advanced_toolbar_location', 'top', 'bottom' );
85
$param['theme_advanced_toolbar_align'] = $jce->getParam( $params, 'editor_theme_advanced_toolbar_align', 'left', 'center' );
86
$param['theme_advanced_path'] = '1';
87
$param['theme_advanced_statusbar_location'] = $jce->getParam( $params, 'editor_theme_advanced_statusbar_location', 'bottom', 'none' );
89
$param['theme_advanced_resizing'] = $jce->getParam( $params, 'editor_theme_advanced_resizing', '1', '0' );
90
$param['theme_advanced_resize_horizontal'] = $jce->getParam( $params, 'editor_theme_advanced_resize_horizontal', '1', '0' );
91
$param['theme_advanced_resizing_use_cookie'] = $jce->getParam( $params, 'editor_theme_advanced_resizing_use_cookie', '1', '0' );
93
$param['theme_advanced_source_editor_width'] = $jce->getParam( $params, 'editor_theme_advanced_source_editor_width', '750', '500' );
94
$param['theme_advanced_source_editor_height'] = $jce->getParam( $params, 'editor_theme_advanced_source_editor_height', '550', '400' );
95
$param['theme_advanced_source_editor_php'] = $jce->getParam( $params, 'editor_allow_php', '0' );
96
$param['theme_advanced_source_editor_script'] = $jce->getParam( $params, 'editor_allow_script', '0' );
97
$param['theme_advanced_source_editor_highlight']= $jce->getParam( $params, 'editor_theme_advanced_source_editor_highlight', '1' );
99
$param['theme_advanced_disable'] = $jce->getRemovePlugins();
100
$param['theme_advanced_blockformats'] = $jce->getParam( $params, 'editor_theme_advanced_blockformats', 'p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd,code,samp,pre', 'p,address,pre,h1,h2,h3,h4,h5,h6' );
102
$param['theme_advanced_fonts'] = $jce->getEditorFonts( $jce->getParam( $params, 'editor_theme_advanced_fonts_add', '' ), $jce->getParam( $params, 'editor_theme_advanced_fonts_remove', '' ) );
104
//$param['font_size_classes'] = $jce->getParam( $params, 'editor_font_size_classes', '' );
105
$param['font_size_style_values'] = $jce->getParam( $params, 'editor_font_size_style_values', '8pt,10pt,12pt,14pt,18pt,24pt,36pt' );
108
$param['theme_advanced_buttons1'] = '';
109
$param['theme_advanced_buttons2'] = '';
110
$param['theme_advanced_buttons3'] = '';
112
$rows = $jce->getRows();
113
for( $i=1; $i<=count( $rows ); $i++ ){
114
$param['theme_advanced_buttons'. $i] = $rows[$i];
117
$param['verify_html'] = $jce->getParam( $params, 'editor_verify_html', '0', '1' );
118
$param['event_elements'] = $jce->getParam( $params, 'editor_event_elements', 'a,img', 'a,img' );
120
$param['width'] = $jce->getParam( $params, 'editor_width', '' );
121
$param['height'] = $jce->getParam( $params, 'editor_height', '' );
123
$param['plugin_preview_width'] = $jce->getParam( $params, 'preview_width', '750', '550' );
124
$param['plugin_preview_height'] = $jce->getParam( $params, 'preview_height', '550', '600' );
127
$param['custom_colors'] = $jce->getParam( $params, 'custom_colors', '', '' );
129
$param['table_inline_editing'] = $jce->getParam( $params, 'editor_table_inline_editing', '0', '0' );
130
$param['fix_list_elements'] = $jce->getParam( $params, 'editor_fix_list_elements', '1', '0' );
131
$param['fix_table_elements'] = $jce->getParam( $params, 'editor_fix_table_elements', '1', '0' );
133
//Default template url
134
$param['content_css'] = $url . "templates/" . $jce->getSiteTemplate() . "/css/template.css";
136
//Custom template url
137
if( $params->get( 'editor_content_css', '1' ) == '0' ){
138
$custom = $params->get( 'editor_content_css_custom', '' );
139
$param['content_css'] = $url . str_replace( '$template', $jce->getSiteTemplate(), $custom );
145
$invalid_elements[] = $jce->getParam( $params, 'editor_invalid_elements', '', '' );
146
$elements = $jce->getElements();
148
if( $jce->getParam( $params, 'allow_script', '0' ) ){
149
$invalid_elements[] = 'script';
151
$jce->removeKey( $invalid_elements, 'script' );
154
if( $jce->isLoaded( 'paste' ) ){
155
$paste_params = $jce->getPluginParams( 'paste' );
157
$param['paste_create_paragraphs'] = $jce->getParam( $paste_params, 'paste_create_paragraphs', '1', '1' );
158
$param['paste_create_linebreaks'] = $jce->getParam( $paste_params, 'paste_create_linebreaks', '1', '1' );
159
$param['paste_use_dialog'] = $jce->getParam( $paste_params, 'paste_use_dialog', '0', '0' );
160
$param['paste_auto_cleanup_on_paste'] = $jce->getParam( $paste_params, 'paste_auto_cleanup_on_paste', '0', '0' );
161
$param['paste_strip_class_attributes'] = $jce->getParam( $paste_params, 'paste_strip_class_attributes', 'all', 'all' );
162
$param['paste_remove_spans'] = $jce->getParam( $paste_params, 'paste_remove_spans', '1', '1' );
163
$param['paste_remove_styles'] = $jce->getParam( $paste_params, 'paste_remove_styles', '1', '1' );
165
if( $jce->isLoaded( 'media' ) || $jce->isLoaded( 'mediamanager' ) ){
166
$media_params = $jce->getPluginParams( 'media' );
168
$param['media_use_script'] = $jce->getParam( $media_params, 'media_use_script', '0', '0' );
169
if( $param['media_use_script'] && $jce->getParam( $params, 'editor_allow_script', '0' ) ){
170
$jce->removeKey( $invalid_elements, 'script' );
172
$media_codebase_flash = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0';
173
$media_codebase_shockwave = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,0,0,458';
174
$media_codebase_mplayer = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
175
$media_codebase_quicktime = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
176
$media_codebase_real = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0';
177
$media_codebase_divx = 'http://go.divx.com/plugin/DivXBrowserPlugin.cab';
179
$param['media_codebase_flash'] = $jce->getParam( $media_params, 'media_codebase_flash', $media_codebase_flash, $media_codebase_flash );
180
$param['media_codebase_shockwave'] = $jce->getParam( $media_params, 'media_codebase_shockwave', $media_codebase_shockwave, $media_codebase_shockwave );
181
$param['media_codebase_mplayer'] = $jce->getParam( $media_params, 'media_codebase_mplayer', $media_codebase_mplayer, $media_codebase_mplayer );
182
$param['media_codebase_quicktime'] = $jce->getParam( $media_params, 'media_codebase_quicktime', $media_codebase_quicktime, $media_codebase_quicktime );
183
$param['media_codebase_real'] = $jce->getParam( $media_params, 'media_codebase_real', $media_codebase_real, $media_codebase_real );
184
$param['media_codebase_divx'] = $jce->getParam( $media_params, 'media_codebase_divx', $media_codebase_divx, $media_codebase_divx );
188
if( $jce->isLoaded( 'mediamanager' ) && !$jce->isLoaded( 'media' ) ){
189
$plugins[] = 'media';
193
if( $jce->isLoaded( 'templatemanager' ) ){
194
$tpl_params = $jce->getPluginParams( 'templatemanager' );
195
$rv = $jce->getParam( $tpl_params, 'template_replace_values', '', '' );
196
if( strpos( $rv, ',' ) == strlen( $rv ) ){
197
$rv = substr( $rv, 0, -1 );
199
$rv = str_replace( array( '$username', '$usertype', '$name', '$email' ), array( $jce->getUser('username'), $jce->getUser('usertype'), $jce->getUser('name'), $jce->getUser('email') ), $rv );
200
$param['template_replace_values'] = "{" . $rv . "}";
201
$param['template_selected_content_classes'] = $jce->getParam( $tpl_params, 'template_selected_content_classes', '' );
202
$param['template_cdate_classes'] = $jce->getParam( $tpl_params, 'template_cdate_classes', 'cdate creationdate' );
203
$param['template_mdate_classes'] = $jce->getParam( $tpl_params, 'template_mdate_classes', 'mdate modifieddate' );
204
$param['template_cdate_format'] = $jce->getParam( $tpl_params, 'template_cdate_format', '%m/%d/%Y : %H:%M:%S' );
205
$param['template_mdate_format'] = $jce->getParam( $tpl_params, 'template_mdate_format', '%m/%d/%Y : %H:%M:%S' );
209
$spell_params = $jce->getPluginParams( 'spellchecker' );
210
$param['spellchecker_languages'] = '+' . $jce->getParam( $spell_params, 'spellchecker_languages', 'English=en', '' );
213
$param['language'] = $jce->getLanguage();
214
$param['directionality'] = $jce->getLanguageDir();
216
// Paragraph handling
217
$param['forced_root_block'] = $jce->getParam( $params, 'editor_forced_root_block', '0', 'p' );
219
if( $params->get( 'editor_newlines', '0' ) == '1' ){
220
$param['force_br_newlines'] = '1';
221
$param['force_p_newlines'] = '0';
223
$param['force_br_newlines'] = '0';
224
$param['force_p_newlines'] = '1';
228
$param['invalid_elements'] = implode( ',', $invalid_elements );
229
$param['extended_valid_elements'] = $elements;
230
$param['plugins'] = $jce->getPlugins();
233
$param['skin'] = $jce->getParam( $params, 'editor_skin', 'default', 'default' );
234
$param['skin_variant'] = $jce->getParam( $params, 'editor_skin_variant', 'default', 'default' );
235
$param['inlinepopups_skin'] = $jce->getParam( $params, 'editor_inlinepopups_skin', 'clearlooks2' );
236
$param['body_class'] = $jce->getParam( $params, 'editor_body_class_type', 'custom' ) == 'contrast' ? 'mceForceColors' : $jce->getParam( $params, 'body_class_custom', '' );
238
//Other - user specified
239
$userParams = $params->get( 'editor_custom_config', '' );
245
'file_browser_callback',
250
$userParams = explode( ';', $userParams );
251
foreach( $userParams as $userParam ){
252
$keys = explode( ':', $userParam );
253
if( !in_array( trim( $keys[0] ), $baseParams ) ){
254
$param[trim( $keys[0] )] = trim( $keys[1] );
258
$callbackFile = $params->get( 'editor_callback_file', '' );
261
$param['relative_urls'] = $jce->getParam( $params, 'editor_relative_urls', '1', '1' );
262
if( $param['relative_urls'] == '0' ){
263
$param['remove_script_host'] = '0';
265
foreach( $param as $k => $v ){
267
// objects or arrays or functions
268
if( preg_match('/(\[[^\]*]\]|\{[^\}]*\}|function\([^\}]*\})/', $v ) ){
270
// anything that is not solely an integer
271
}else if( !is_numeric( $v ) ){
273
// 1 or 0 become true/false
274
}else if( $v == '1' || $v == '0' ){
275
$v = intval( $v ) ? 'true' : 'false';
277
$init .= "\t\t\t". $k .": ". $v .",\n";
279
if( preg_match('/theme_advanced_buttons([1-3])/', $k ) && $v == '' ){
280
$init .= "\t\t\t". $k .": \"\",\n";
285
$params->set( 'editor_toggle', '0' );
286
$params->set( 'editor_allow_php', '0' );
287
$params->set( 'editor_allow_script', '0' );
291
"<script type=\"text/javascript\">
294
theme: '". $theme ."',
295
entity_encoding: 'raw',
296
editor_selector: 'mceEditor',\n";
298
$return .= "\t\t\tonpageload: 'jceOnLoad',
299
cleanup_callback: 'jceCleanup',
300
save_callback: 'jceSave',
301
file_browser_callback: 'jceBrowser'
304
pluginmode : ". $params->get( 'editor_pluginmode', '0' ) .",
305
state : '". $params->get( 'editor_state', 'mceEditor' ) ."',
306
allowToggle : ". $params->get( 'editor_toggle', '1' ) .",
307
php : ". $params->get( 'editor_allow_php', '0' ) .",
308
javascript : ". $params->get( 'editor_allow_script', '0' ) .",
309
toggleText : '". $jce->xmlEncode( $params->get( 'editor_toggle_text', '[show/hide]' ) ) ."'
311
function jceSave(id, html, body){
312
return JContentEditor.save(html);
314
function jceCleanup(type, value){
315
return JContentEditor.cleanup(type, value);
317
function jceBrowser(name, url, type, win){
318
return JContentEditor.browser(name, url, type, win);
321
if( $params->get( 'callback_file' ) ){
322
$return .= "\n<script type=\"text/javascript\" src=\"". $mainframe->getSiteURL() . $callbackFile ."\"></script>\n";
328
* TinyMCE WYSIWYG Editor - get the editor content
330
* @param string The name of the editor
332
function onGetContent( $editor ) {
333
return "JContentEditor.getContent('".$editor."');";
337
* TinyMCE WYSIWYG Editor - set the editor content
339
* @param string The name of the editor
341
function onSetContent( $editor, $html ) {
342
return "tinyMCE.activeEditor.setContent(".$html.");";
346
* TinyMCE WYSIWYG Editor - copy editor content to form field
348
* @param string The name of the editor
350
function onSave( $editor ) {
351
return "tinyMCE.triggerSave();";
355
* TinyMCE WYSIWYG Editor - display the editor
357
* @param string The name of the editor area
358
* @param string The content of the field
359
* @param string The width of the editor area
360
* @param string The height of the editor area
361
* @param int The number of columns for the editor area
362
* @param int The number of rows for the editor area
363
* @param mixed Can be boolean or array.
365
function onDisplay( $name, $content, $width, $height, $col, $row, $buttons = true)
367
// Only add "px" to width and height if they are not given as a percentage
368
if (is_numeric( $width )) {
371
if (is_numeric( $height )) {
375
$buttons = $this->_displayButtons($name, $buttons);
376
$editor = "<div id=\"jce_editor_".$name."_toggle\"></div>";
377
$editor .= "<textarea id=\"$name\" name=\"$name\" cols=\"$col\" rows=\"$row\" style=\"width:{$width}; height:{$height};\" class=\"mceEditor\">$content</textarea>\n" . $buttons;
378
$editor .= "<script type=\"text/javascript\">function jceOnLoad(){JContentEditor.initEditorMode('$name');}</script>";
383
function onGetInsertMethod($name)
385
$doc = & JFactory::getDocument();
387
$js= "function jInsertEditorText( text, editor ) {
388
tinyMCE.execInstanceCommand(editor, 'mceInsertContent',false,text);
390
$doc->addScriptDeclaration($js);
395
function _displayButtons($name, $buttons)
397
// Load modal popup behavior
398
JHTML::_('behavior.modal', 'a.modal-button');
400
$args['name'] = $name;
401
$args['event'] = 'onGetInsertMethod';
404
$results[] = $this->update($args);
405
foreach ($results as $result) {
406
if (is_string($result) && trim($result)) {
413
$results = $this->_subject->getButtons($name, $buttons);
416
* This will allow plugins to attach buttons or change the behavior on the fly using AJAX
418
$return .= "\n<div id=\"editor-xtd-buttons\">\n";
419
foreach ($results as $button)
422
* Results should be an object
424
if ( $button->get('name') )
426
$modal = ($button->get('modal')) ? 'class="modal-button"' : null;
427
$href = ($button->get('link')) ? 'href="'.JURI::base().$button->get('link').'"' : null;
428
$onclick = ($button->get('onclick')) ? 'onclick="'.$button->get('onclick').'"' : null;
429
$return .= "<div class=\"button2-left\"><div class=\"".$button->get('name')."\"><a ".$modal." title=\"".$button->get('text')."\" ".$href." ".$onclick." rel=\"".$button->get('options')."\">".$button->get('text')."</a></div></div>\n";
432
$return .= "</div>\n";
b'\\ No newline at end of file'