Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/plugins/editors/tinymce.php
c7d7e38b2269
12.6 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | <?php
/**
* @version $Id: tinymce.php 10709 2008-08-21 09:58:52Z eddieajau $
* @package Joomla
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Do not allow direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
/**
* TinyMCE WYSIWYG Editor Plugin
*
* @package Editors
* @since 1.5
*/
class plgEditorTinymce extends JPlugin
{
/**
* Constructor
*
* For php4 compatability we must not use the __constructor as a constructor for plugins
* because func_get_args ( void ) returns a copy of all passed arguments NOT references.
* This causes problems with cross-referencing necessary for the observer design pattern.
*
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.5
*/
function plgEditorTinymce(& $subject, $config)
{
parent::__construct($subject, $config);
}
/**
* Method to handle the onInit event.
* - Initializes the TinyMCE WYSIWYG Editor
*
* @access public
* @return string JavaScript Initialization string
* @since 1.5
*/
function onInit()
{
global $mainframe;
$db =& JFactory::getDBO();
$language =& JFactory::getLanguage();
$theme = $this->params->get( 'theme', 'advanced' );
// handling for former default option
if ($theme == 'default' ) {
$theme = 'advanced';
}
$toolbar = $this->params->def( 'toolbar', 'top' );
$html_height = $this->params->def( 'html_height', '550' );
$html_width = $this->params->def( 'html_width', '750' );
$content_css = $this->params->def( 'content_css', 1 );
$content_css_custom = $this->params->def( 'content_css_custom', '' );
$invalid_elements = $this->params->def( 'invalid_elements', 'script,applet,iframe' );
$newlines = $this->params->def( 'newlines', 0 );
$cleanup_startup = $this->params->def( 'cleanup_startup', 0 );
$cleanup_save = $this->params->def( 'cleanup_save', 2 );
$compressed = $this->params->def( 'compressed', 0 );
$langPrefix = $this->params->def( 'lang_code', 'en' );
$langMode = $this->params->def( 'lang_mode', 0 );
$relative_urls = $this->params->def( 'relative_urls', 0 );
$clear_entities = $this->params->def( 'clear_entities', 0 );
$extended_elements = $this->params->def( 'extended_elements', '' );
$plugins = array();
$buttons2 = array();
$buttons3 = array();
$elements = explode( ',', $extended_elements );
// search & replace
$searchreplace = $this->params->def( 'searchreplace', 1 );
if ( $searchreplace ) {
$plugins[] = 'searchreplace';
$buttons2[] = 'search,replace';
}
$plugins[] = 'insertdatetime';
// insert date
$insertdate = $this->params->def( 'insertdate', 1 );
$format_date = $this->params->def( 'format_date', '%Y-%m-%d' );
if ( $insertdate ) {
$buttons2[] = 'insertdate';
}
// insert time
$inserttime = $this->params->def( 'inserttime', 1 );
$format_time = $this->params->def( 'format_time', '%H:%M:%S' );
if ( $inserttime ) {
$buttons2[] = 'inserttime';
}
// emotions
$smilies = $this->params->def( 'smilies', 0 );
if ( $smilies ) {
$plugins[] = 'emotions';
$buttons2[] = 'emotions';
}
//media plugin
$plugins[] = 'media';
$buttons2[] = 'media';
// horizontal line
$hr = $this->params->def( 'hr', 1 );
if ( $hr ) {
$plugins[] = 'advhr';
$elements[] = 'hr[id|title|alt|class|width|size|noshade]';
$buttons3[] = 'advhr';
} else {
$elements[] = 'hr[id|class|title|alt]';
}
// table
$table = $this->params->def( 'table', 1 );
if ( $table ) {
$plugins[] = 'table';
$buttons3[] = 'tablecontrols';
}
// fullscreen
$fullscreen = $this->params->def( 'fullscreen', 1 );
if ( $fullscreen ) {
$plugins[] = 'fullscreen';
$buttons3[] = 'fullscreen';
}
// rtl/ltr buttons
$directionality = $this->params->def( 'directionality', 1 );
if ( $directionality ) {
$plugins[] = 'directionality';
$buttons2[] = 'ltr,rtl';
}
// autosave
$autosave = $this->params->def( 'autosave', 0 );
if ( $autosave ) {
$plugins[] = 'autosave';
}
// layer
$layer = $this->params->def( 'layer', 1 );
if ( $layer ) {
$plugins[] = 'layer';
$buttons2[] = 'insertlayer';
$buttons2[] = 'moveforward';
$buttons2[] = 'movebackward';
$buttons2[] = 'absolute';
}
// style
$style = $this->params->def( 'style', 1 );
if ( $style ) {
$plugins[] = 'style';
$buttons3[] = 'styleprops';
}
// XHTMLxtras
$xhtmlxtras = $this->params->def( 'xhtmlxtras', 0 );
if ( $xhtmlxtras ) {
$plugins[] = 'xhtmlxtras';
$buttons3[] = 'cite';
$buttons3[] = 'abbr';
$buttons3[] = 'acronym';
$buttons3[] = 'ins';
$buttons3[] = 'del';
$buttons3[] = 'attribs';
}
// template
$template = $this->params->def( 'template', 0 );
if ( $template ) {
$plugins[] = 'template';
$buttons3[] = 'template';
}
// text color
$buttons2[] = 'forecolor';
if ($language->isRTL()) {
$text_direction = 'rtl';
} else {
$text_direction = 'ltr';
}
$entities = '';
if ($clear_entities) {
$entities = 'entities : "160,nbsp,38,amp,34,quot,162,cent,8364,euro,163,pound,165,yen,169,copy,174,reg,8482,trade,8240,permil,60,lt,62,gt,8804,le,8805,ge,176,deg,8722,minus",';
}
$element_path = '';
if($this->params->get('element_path', 0)) {
$element_path = "theme_advanced_statusbar_location : \"bottom\", theme_advanced_path : true,";
}
if ( $langMode ) {
$langPrefix = substr( $language->getTag(), 0, strpos( $language->getTag(), '-' ) );
}
// loading of css file for `styles` dropdown
if ( $content_css_custom ) {
$content_css = 'content_css : "'. $content_css_custom .'", ';
}
else
{
/*
* Lets get the default template for the site application
*/
$query = 'SELECT template'
. ' FROM #__templates_menu'
. ' WHERE client_id = 0'
. ' AND menuid = 0'
;
$db->setQuery( $query );
$template = $db->loadResult();
if($content_css)
{
$file_path = JPATH_SITE .'/templates/'. $template .'/css/';
if ( !file_exists( $file_path .DS. 'editor.css' ) ) {
$template = 'system';
}
$content_css = 'content_css : "' . JURI::root() .'templates/'. $template . '/css/editor.css",';
} else {
$content_css = '';
}
}
if ( $cleanup_startup ) {
$cleanup_startup = 'true';
} else {
$cleanup_startup = 'false';
}
switch ( $cleanup_save ) {
case '0': /* Never clean up on save */
$cleanup = 'false';
break;
case '1': /* Clean up front end edits only */
if ($mainframe->isadmin())
$cleanup = 'false';
else
$cleanup = 'true';
break;
default: /* Always clean up on save */
$cleanup = 'true';
}
if ( $newlines ) {
$br_newlines = 'true';
$p_newlines = 'false';
} else {
$br_newlines = 'false';
$p_newlines = 'true';
}
// Tiny Compressed mode
if ( $compressed ) {
$load = "\t<script type=\"text/javascript\" src=\"".JURI::root()."plugins/editors/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php\"></script>\n";
} else {
$load = "\t<script type=\"text/javascript\" src=\"".JURI::root()."plugins/editors/tinymce/jscripts/tiny_mce/tiny_mce.js\"></script>\n";
}
$buttons2 = implode( ',', $buttons2 );
$buttons3 = implode( ',', $buttons3 );
$plugins = implode( ',', $plugins );
$elements = implode( ',', $elements );
$return = $load .
"\t<script type=\"text/javascript\">
tinyMCE.init({
theme : \"$theme\",
language : \"". $langPrefix . "\",
mode : \"textareas\",
gecko_spellcheck : \"true\",
editor_selector : \"mce_editable\",
document_base_url : \"". JURI::root() ."\",
entities : \"60,lt,62,gt\",
relative_urls : $relative_urls,
remove_script_host : false,
save_callback : \"TinyMCE_Save\",
invalid_elements : \"$invalid_elements\",
extended_valid_elements : \"a[class|name|href|target|title|onclick|rel],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],$elements\",
theme_advanced_toolbar_location : \"$toolbar\",
theme_advanced_source_editor_height : \"$html_height\",
theme_advanced_source_editor_width : \"$html_width\",
directionality: \"$text_direction\",
force_br_newlines : \"$br_newlines\",
force_p_newlines : \"$p_newlines\",
$content_css
debug : false,
cleanup : $cleanup,
cleanup_on_startup : $cleanup_startup,
safari_warning : false,
plugins : \"advlink, advimage, $plugins\",
theme_advanced_buttons1_add : \"fontselect\",
theme_advanced_buttons2_add : \"$buttons2\",
theme_advanced_buttons3_add : \"$buttons3\",
theme_advanced_disable : \"help\",
plugin_insertdate_dateFormat : \"$format_date\",
plugin_insertdate_timeFormat : \"$format_time\",
$entities
$element_path
fullscreen_settings : {
theme_advanced_path_location : \"top\"
}
});
function TinyMCE_Save(editor_id, content, node)
{
base_url = tinyMCE.settings['document_base_url'];
var vHTML = content;
if (true == true){
vHTML = tinyMCE.regexpReplace(vHTML, 'href\s*=\s*\"?'+base_url+'', 'href=\"', 'gi');
vHTML = tinyMCE.regexpReplace(vHTML, 'src\s*=\s*\"?'+base_url+'', 'src=\"', 'gi');
vHTML = tinyMCE.regexpReplace(vHTML, 'mce_real_src\s*=\s*\"?', '', 'gi');
vHTML = tinyMCE.regexpReplace(vHTML, 'mce_real_href\s*=\s*\"?', '', 'gi');
}
return vHTML;
}
</script>";
return $return;
}
/**
* TinyMCE WYSIWYG Editor - get the editor content
*
* @param string The name of the editor
*/
function onGetContent( $editor ) {
return "tinyMCE.getContent();";
}
/**
* TinyMCE WYSIWYG Editor - set the editor content
*
* @param string The name of the editor
*/
function onSetContent( $editor, $html ) {
return "tinyMCE.setContent(".$html.");";
}
/**
* TinyMCE WYSIWYG Editor - copy editor content to form field
*
* @param string The name of the editor
*/
function onSave( $editor ) {
return "tinyMCE.triggerSave();";
}
/**
* TinyMCE WYSIWYG Editor - display the editor
*
* @param string The name of the editor area
* @param string The content of the field
* @param string The width of the editor area
* @param string The height of the editor area
* @param int The number of columns for the editor area
* @param int The number of rows for the editor area
* @param mixed Can be boolean or array.
*/
function onDisplay( $name, $content, $width, $height, $col, $row, $buttons = true)
{
// Only add "px" to width and height if they are not given as a percentage
if (is_numeric( $width )) {
$width .= 'px';
}
if (is_numeric( $height )) {
$height .= 'px';
}
$buttons = $this->_displayButtons($name, $buttons);
$editor = "<textarea id=\"$name\" name=\"$name\" cols=\"$col\" rows=\"$row\" style=\"width:{$width}; height:{$height};\" class=\"mce_editable=\">$content</textarea>\n" . $buttons;
return $editor;
}
function onGetInsertMethod($name)
{
$doc = & JFactory::getDocument();
$js= "function jInsertEditorText( text, editor ) {
tinyMCE.execInstanceCommand(editor, 'mceInsertContent',false,text);
}";
$doc->addScriptDeclaration($js);
return true;
}
function _displayButtons($name, $buttons)
{
// Load modal popup behavior
JHTML::_('behavior.modal', 'a.modal-button');
$args['name'] = $name;
$args['event'] = 'onGetInsertMethod';
$return = '';
$results[] = $this->update($args);
foreach ($results as $result) {
if (is_string($result) && trim($result)) {
$return .= $result;
}
}
if(!empty($buttons))
{
$results = $this->_subject->getButtons($name, $buttons);
/*
* This will allow plugins to attach buttons or change the behavior on the fly using AJAX
*/
$return .= "\n<div id=\"editor-xtd-buttons\">\n";
foreach ($results as $button)
{
/*
* Results should be an object
*/
if ( $button->get('name') )
{
$modal = ($button->get('modal')) ? 'class="modal-button"' : null;
$href = ($button->get('link')) ? 'href="'.JURI::base().$button->get('link').'"' : null;
$onclick = ($button->get('onclick')) ? 'onclick="'.$button->get('onclick').'"' : null;
$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";
}
}
$return .= "</div>\n";
}
return $return;
}
}
|