CoreFiles by mySites.guru
tinymce.php1,097 lines, 26,631 bytes, from Joomla_3.5.0-beta-Beta-Full_Package.zip
Raw History Compare with 3.4.0-beta3
md5
315e262056b67960ce3ad8f65cfb1434
sha1
55a0b81713e133e70763eeab8c84796f74d69e44
sha256
d1b6590409cefcba9bd027200f2194962caf2f2df1203c483271c571dfdd56c9
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  Editors.tinymce
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * TinyMCE Editor Plugin
 *
 * @since  1.5
 */
class PlgEditorTinymce extends JPlugin
{
	/**
	 * Base path for editor files
	 */
	protected $_basePath = 'media/editors/tinymce';

	/**
	 * Load the language file on instantiation.
	 *
	 * @var    boolean
	 * @since  3.1
	 */
	protected $autoloadLanguage = true;

	/**
	 * Loads the application object
	 *
	 * @var    JApplicationCms
	 * @since  3.2
	 */
	protected $app = null;

	/**
	 * Initialises the Editor.
	 *
	 * @return  string  JavaScript Initialization string
	 *
	 * @since   1.5
	 */
	public function onInit()
	{
		$app      = JFactory::getApplication();
		$language = JFactory::getLanguage();
		$mode     = (int) $this->params->get('mode', 1);
		$theme    = 'modern';

		// List the skins
		$skindirs = glob(JPATH_ROOT . '/media/editors/tinymce/skins' . '/*', GLOB_ONLYDIR);

		// Set the selected skin
		if ($app->isSite())
		{
			if ((int) $this->params->get('skin', 0) < count($skindirs))
			{
				$skin = 'skin : "' . basename($skindirs[(int) $this->params->get('skin', 0)]) . '",';
			}
			else
			{
				$skin = 'skin : "lightgray",';
			}
		}

		// Set the selected administrator skin
		elseif ($app->isAdmin())
		{
			if ((int) $this->params->get('skin_admin', 0) < count($skindirs))
			{
				$skin = 'skin : "' . basename($skindirs[(int) $this->params->get('skin_admin', 0)]) . '",';
			}
			else
			{
				$skin = 'skin : "lightgray",';
			}
		}

		$entity_encoding = $this->params->get('entity_encoding', 'raw');
		$langMode        = $this->params->get('lang_mode', 0);
		$langPrefix      = $this->params->get('lang_code', 'en');

		if ($langMode)
		{
			if (file_exists(JPATH_ROOT . "/media/editors/tinymce/langs/" . $language->getTag() . ".js"))
			{
				$langPrefix = $language->getTag();
			}
			elseif (file_exists(JPATH_ROOT . "/media/editors/tinymce/langs/" . substr($language->getTag(), 0, strpos($language->getTag(), '-')) . ".js"))
			{
				$langPrefix = substr($language->getTag(), 0, strpos($language->getTag(), '-'));
			}
			else
			{
				$langPrefix = "en";
			}
		}

		$text_direction = 'ltr';

		if ($language->isRtl())
		{
			$text_direction = 'rtl';
		}

		$use_content_css    = $this->params->get('content_css', 1);
		$content_css_custom = $this->params->get('content_css_custom', '');

		/*
		 * Lets get the default template for the site application
		 */
		$db    = JFactory::getDbo();
		$query = $db->getQuery(true)
			->select('template')
			->from('#__template_styles')
			->where('client_id=0 AND home=' . $db->quote('1'));

		$db->setQuery($query);
		try
		{
			$template = $db->loadResult();
		}
		catch (RuntimeException $e)
		{
			JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');

			return;
		}

		$content_css    = '';
		$templates_path = JPATH_SITE . '/templates';

		// Loading of css file for 'styles' dropdown
		if ($content_css_custom)
		{
			// If URL, just pass it to $content_css
			if (strpos($content_css_custom, 'http') !== false)
			{
				$content_css = 'content_css : "' . $content_css_custom . '",';
			}

			// If it is not a URL, assume it is a file name in the current template folder
			else
			{
				$content_css = 'content_css : "' . JUri::root() . 'templates/' . $template . '/css/' . $content_css_custom . '",';

				// Issue warning notice if the file is not found (but pass name to $content_css anyway to avoid TinyMCE error
				if (!file_exists($templates_path . '/' . $template . '/css/' . $content_css_custom))
				{
					$msg = sprintf(JText::_('PLG_TINY_ERR_CUSTOMCSSFILENOTPRESENT'), $content_css_custom);
					JLog::add($msg, JLog::WARNING, 'jerror');
				}
			}
		}
		else
		{
			// Process when use_content_css is Yes and no custom file given
			if ($use_content_css)
			{
				// First check templates folder for default template
				// if no editor.css file in templates folder, check system template folder
				if (!file_exists($templates_path . '/' . $template . '/css/editor.css'))
				{
					// If no editor.css file in system folder, show alert
					if (!file_exists($templates_path . '/system/css/editor.css'))
					{
						JLog::add(JText::_('PLG_TINY_ERR_EDITORCSSFILENOTPRESENT'), JLog::WARNING, 'jerror');
					}
					else
					{
						$content_css = 'content_css : "' . JUri::root() . 'templates/system/css/editor.css",';
					}
				}
				else
				{
					$content_css = 'content_css : "' . JUri::root() . 'templates/' . $template . '/css/editor.css",';
				}
			}
		}

		$relative_urls = $this->params->get('relative_urls', '1');

		if ($relative_urls)
		{
			// Relative
			$relative_urls = "true";
		}
		else
		{
			// Absolute
			$relative_urls = "false";
		}

		$newlines = $this->params->get('newlines', 0);

		if ($newlines)
		{
			// Break
			$forcenewline = "force_br_newlines : true, force_p_newlines : false, forced_root_block : '',";
		}
		else
		{
			// Paragraph
			$forcenewline = "force_br_newlines : false, force_p_newlines : true, forced_root_block : 'p',";
		}

		$invalid_elements  = $this->params->get('invalid_elements', 'script,applet,iframe');
		$extended_elements = $this->params->get('extended_elements', '');
		$valid_elements    = $this->params->get('valid_elements', '');

		// Advanced Options
		$access = JFactory::getUser()->getAuthorisedViewLevels();

		// Flip for performance, so we can direct check for the key isset($access[$key])
		$access = array_flip($access);

		$html_height = $this->params->get('html_height', '550');
		$html_width  = $this->params->get('html_width', '');

		if ($html_width == 750)
		{
			$html_width = '';
		}

		// Image advanced options
		$image_advtab = $this->params->get('image_advtab', 1);

		if (isset($access[$image_advtab]))
		{
			$image_advtab = "true";
		}
		else
		{
			$image_advtab = "false";
		}

		// The param is true for vertical resizing only, false or both
		$resizing = $this->params->get('resizing', '1');
		$resize_horizontal = $this->params->get('resize_horizontal', '1');

		if ($resizing || $resizing == 'true')
		{
			if ($resize_horizontal || $resize_horizontal == 'true')
			{
				$resizing = 'resize: "both",';
			}
			else
			{
				$resizing = 'resize: true,';
			}
		}
		else
		{
			$resizing = 'resize: false,';
		}

		$toolbar1_add   = array();
		$toolbar2_add   = array();
		$toolbar3_add   = array();
		$toolbar4_add   = array();
		$elements       = array();
		$plugins        = array(
			'autolink',
			'lists',
			'image',
			'charmap',
			'print',
			'preview',
			'anchor',
			'pagebreak',
			'code',
			'save',
			'textcolor',
			'colorpicker',
			'importcss');
		$toolbar1_add[] = 'bold';
		$toolbar1_add[] = 'italic';
		$toolbar1_add[] = 'underline';
		$toolbar1_add[] = 'strikethrough';

		// Alignment buttons
		$alignment = $this->params->get('alignment', 1);

		if (isset($access[$alignment]))
		{
			$toolbar1_add[] = '|';
			$toolbar1_add[] = 'alignleft';
			$toolbar1_add[] = 'aligncenter';
			$toolbar1_add[] = 'alignright';
			$toolbar1_add[] = 'alignjustify';
		}

		$toolbar1_add[] = '|';
		$toolbar1_add[] = 'styleselect';
		$toolbar1_add[] = '|';
		$toolbar1_add[] = 'formatselect';

		// Fonts
		$fonts = $this->params->get('fonts', 1);

		if (isset($access[$fonts]))
		{
			$toolbar1_add[] = 'fontselect';
			$toolbar1_add[] = 'fontsizeselect';
		}

		// Search & replace
		$searchreplace = $this->params->get('searchreplace', 1);

		if (isset($access[$searchreplace]))
		{
			$plugins[]      = 'searchreplace';
			$toolbar2_add[] = 'searchreplace';
		}

		$toolbar2_add[] = '|';
		$toolbar2_add[] = 'bullist';
		$toolbar2_add[] = 'numlist';
		$toolbar2_add[] = '|';
		$toolbar2_add[] = 'outdent';
		$toolbar2_add[] = 'indent';
		$toolbar2_add[] = '|';
		$toolbar2_add[] = 'undo';
		$toolbar2_add[] = 'redo';
		$toolbar2_add[] = '|';

		// Insert date and/or time plugin
		$insertdate = $this->params->get('insertdate', 1);

		if (isset($access[$insertdate]))
		{
			$plugins[]      = 'insertdatetime';
			$toolbar4_add[] = 'inserttime';
		}

		// Link plugin
		$link = $this->params->get('link', 1);

		if (isset($access[$link]))
		{
			$plugins[]      = 'link';
			$toolbar2_add[] = 'link';
			$toolbar2_add[] = 'unlink';
		}

		$toolbar2_add[] = 'anchor';
		$toolbar2_add[] = 'image';
		$toolbar2_add[] = '|';
		$toolbar2_add[] = 'code';

		// Colors
		$colors = $this->params->get('colors', 1);

		if (isset($access[$colors]))
		{
			$toolbar2_add[] = '|';
			$toolbar2_add[] = 'forecolor,backcolor';
		}

		// Fullscreen
		$fullscreen = $this->params->get('fullscreen', 1);

		if (isset($access[$fullscreen]))
		{
			$plugins[]      = 'fullscreen';
			$toolbar2_add[] = '|';
			$toolbar2_add[] = 'fullscreen';
		}

		// Table
		$table = $this->params->get('table', 1);

		if (isset($access[$table]))
		{
			$plugins[]      = 'table';
			$toolbar3_add[] = 'table';
			$toolbar3_add[] = '|';
		}

		$toolbar3_add[] = 'subscript';
		$toolbar3_add[] = 'superscript';
		$toolbar3_add[] = '|';
		$toolbar3_add[] = 'charmap';

		// Emotions
		$smilies = $this->params->get('smilies', 1);

		if (isset($access[$smilies]))
		{
			$plugins[]      = 'emoticons';
			$toolbar3_add[] = 'emoticons';
		}

		// Media plugin
		$media = $this->params->get('media', 1);

		if (isset($access[$media]))
		{
			$plugins[]      = 'media';
			$toolbar3_add[] = 'media';
		}

		// Horizontal line
		$hr = $this->params->get('hr', 1);

		if (isset($access[$hr]))
		{
			$plugins[]      = 'hr';
			$elements[]     = 'hr[id|title|alt|class|width|size|noshade]';
			$toolbar3_add[] = 'hr';
		}
		else
		{
			$elements[] = 'hr[id|class|title|alt]';
		}

		// RTL/LTR buttons
		$directionality = $this->params->get('directionality', 1);

		if (isset($access[$directionality]))
		{
			$plugins[] = 'directionality';
			$toolbar3_add[] = 'ltr rtl';
		}

		if ($extended_elements != "")
		{
			$elements = explode(',', $extended_elements);
		}

		$toolbar4_add[] = 'cut';
		$toolbar4_add[] = 'copy';

		// Paste
		$paste = $this->params->get('paste', 1);

		if (isset($access[$paste]))
		{
			$plugins[]      = 'paste';
			$toolbar4_add[] = 'paste';
		}

		$toolbar4_add[] = '|';

		// Visualchars
		$visualchars = $this->params->get('visualchars', 1);

		if (isset($access[$visualchars]))
		{
			$plugins[]      = 'visualchars';
			$toolbar4_add[] = 'visualchars';
		}

		// Visualblocks
		$visualblocks = $this->params->get('visualblocks', 1);

		if (isset($access[$visualblocks]))
		{
			$plugins[]      = 'visualblocks';
			$toolbar4_add[] = 'visualblocks';
		}

		// Non-breaking
		$nonbreaking = $this->params->get('nonbreaking', 1);

		if (isset($access[$nonbreaking]))
		{
			$plugins[]      = 'nonbreaking';
			$toolbar4_add[] = 'nonbreaking';
		}

		// Blockquote
		$blockquote = $this->params->get('blockquote', 1);

		if (isset($access[$blockquote]))
		{
			$toolbar4_add[] = 'blockquote';
		}

		// Template
		$template = $this->params->get('template', 1);

		if (isset($access[$template]))
		{
			$plugins[]      = 'template';
			$toolbar4_add[] = 'template';

			// Note this check for the template_list.js file will be removed in Joomla 4.0
			if (is_file(JPATH_ROOT . "/media/editors/tinymce/templates/template_list.js"))
			{
				// If using the legacy file we need to include and input the files the new way
				$str = file_get_contents(JPATH_ROOT . "/media/editors/tinymce/templates/template_list.js");

				// Find from one [ to the last ]
				preg_match_all('/\[.*\]/', $str, $matches);

				$templates = "templates: [";

				// Set variables
				foreach ($matches['0'] as $match)
				{
					preg_match_all('/\".*\"/', $match, $values);
					$result = trim($values["0"]["0"], '"');
					$final_result = explode(',', $result);
					$templates .= "{title: '" . trim($final_result['0'], ' " ') . "', description: '"
						. trim($final_result['2'], ' " ') . "', url: '" . JUri::root() . trim($final_result['1'], ' " ') . "'},";
				}

				$templates .= "],";
			}
			else
			{
				$templates = 'templates: [';

				foreach (glob(JPATH_ROOT . '/media/editors/tinymce/templates/*.html') as $filename)
				{
					$filename = basename($filename, '.html');

					if ($filename !== 'index')
					{
						$lang = JFactory::getLanguage();
						$title = $filename;
						$description = ' ';

						if ($lang->hasKey('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_TITLE'))
						{
							$title = JText::_('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_TITLE');
						}

						if ($lang->hasKey('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_DESC'))
						{
							$description = JText::_('PLG_TINY_TEMPLATE_' . strtoupper($filename) . '_DESC');
						}

						$templates .= '{title: \'' . $title . '\', description: \'' . $description . '\', url:\''
							. JUri::root() . 'media/editors/tinymce/templates/' . $filename . '.html\'},';
					}
				}

				$templates .= '],';
			}
		}
		else
		{
			$templates = '';
		}

		// Print
		$print = $this->params->get('print', 1);

		if (isset($access[$print]))
		{
			$plugins[] = 'print';
			$toolbar4_add[] = '|';
			$toolbar4_add[] = 'print';
			$toolbar4_add[] = 'preview';
		}

		// Spellchecker
		$spell = $this->params->get('spell', 0);

		if (isset($access[$spell]))
		{
			$plugins[]      = 'spellchecker';
			$toolbar4_add[] = '|';
			$toolbar4_add[] = 'spellchecker';
		}

		// Wordcount
		$wordcount = $this->params->get('wordcount', 1);

		if (isset($access[$wordcount]))
		{
			$plugins[] = 'wordcount';
		}

		// Advlist
		$advlist = $this->params->get('advlist', 1);

		if (isset($access[$advlist]))
		{
			$plugins[] = 'advlist';
		}

		// Autosave
		$autosave = $this->params->get('autosave', 1);

		if (isset($access[$autosave]))
		{
			$plugins[] = 'autosave';
		}

		// Context menu
		$contextmenu = $this->params->get('contextmenu', 1);

		if (isset($access[$contextmenu]))
		{
			$plugins[] = 'contextmenu';
		}

		$custom_plugin = $this->params->get('custom_plugin', '');

		if ($custom_plugin != "")
		{
			$plugins[] = $custom_plugin;
		}

		$custom_button = $this->params->get('custom_button', '');

		if ($custom_button != "")
		{
			$toolbar4_add[] = $custom_button;
		}

		// We shall put the XTD button inside tinymce
		$buttons = $this->tinyButtons();
		$btnsNames = $buttons['names'];
		$tinyBtns  = $buttons['script'];

		// Drag and drop Images
		$allowImgPaste = "false";
		$dragDropPlg   = '';
		$dragdrop      = $this->params->get('drag_drop', 1);
		$user          = JFactory::getUser();

		if ($dragdrop && $user->authorise('core.create', 'com_media'))
		{
			$allowImgPaste = "true";
			$isSubDir      = '';
			$session       = JFactory::getSession();
			$uploadUrl     = JUri::base() . 'index.php?option=com_media&task=file.upload&tmpl=component&'
				. $session->getName() . '=' . $session->getId()
				. '&' . JSession::getFormToken() . '=1'
				. '&asset=image&format=json';

			if (JFactory::getApplication()->isSite())
			{
				$uploadUrl = htmlentities($uploadUrl, null, 'UTF-8', null);
			}

			// Is Joomla installed in subdirectory
			if (JUri::root(true) != '/')
			{
				$isSubDir = JUri::root(true);
			}

			// Get specific path
			$tempPath = $this->params->get('path', '');

			if (!empty($tempPath))
			{
				$tempPath = rtrim($tempPath, '/');
				$tempPath = ltrim($tempPath, '/');
			}

			$dragDropPlg = 'jdragdrop';

			JText::script('PLG_TINY_ERR_UNSUPPORTEDBROWSER');
			JFactory::getDocument()->addScriptDeclaration(
				"
		var setCustomDir    = '" . $isSubDir . "';
		var mediaUploadPath = '" . $tempPath . "';
		var uploadUri       = '" . $uploadUrl . "';
				"
			);
		}

		// Prepare config variables
		$plugins  = implode(',', $plugins);
		$elements = implode(',', $elements);

		// Prepare config variables
		$toolbar1 = implode(' ', $toolbar1_add) . ' | '
			. implode(' ', $toolbar2_add) . ' | '
			. implode(' ', $toolbar3_add) . ' | '
			. implode(' ', $toolbar4_add) . ' | '
			. implode(" | ", $btnsNames);
		$toolbar5 = implode(" | ", $btnsNames);

		// The buttons script
		$tinyBtns = implode("; ", $tinyBtns);

		// See if mobileVersion is activated
		$mobileVersion = $this->params->get('mobile', 0);

		JHtml::script($this->_basePath . '/tinymce.min.js', false, false, false, false, false);

		/**
		 * Shrink the buttons if not on a mobile or if mobile view is off.
		 * If mobile view is on force into simple mode and enlarge the buttons
		 **/
		if (!$this->app->client->mobile)
		{
			$smallButtons = 'toolbar_items_size: "small",';
		}
		elseif ($mobileVersion == false)
		{
			$smallButtons = '';
		}
		else
		{
			$smallButtons = '';
			$mode         = 0;
		}

		switch ($mode)
		{
			case 0: /* Simple mode*/
				JFactory::getDocument()->addScriptDeclaration(
					"
		tinymce.init({
			// General
			directionality: \"$text_direction\",
			selector: \"textarea.mce_editable\",
			language : \"$langPrefix\",
			mode : \"specific_textareas\",
			autosave_restore_when_empty: false,
			$skin
			theme : \"$theme\",
			schema: \"html5\",
			menubar: false,
			toolbar1: \"bold italics underline strikethrough | undo redo | bullist numlist | $toolbar5 | code\",
			plugins: \"$dragDropPlg code\",
			// Cleanup/Output
			inline_styles : true,
			gecko_spellcheck : true,
			entity_encoding : \"$entity_encoding\",
			$forcenewline
			$smallButtons
			// URL
			relative_urls : $relative_urls,
			remove_script_host : false,
			// Layout
			$content_css
			document_base_url : \"" . JUri::root() . "\",
			setup: function (editor) {
				$tinyBtns
			},
			paste_data_images: $allowImgPaste
		});
		"
				);
				break;

			case 1:
			default: /* Advanced mode*/
			$toolbar1 = "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | formatselect | bullist numlist "
				. "| outdent indent | undo redo | link unlink anchor image | hr table | subscript superscript | charmap";
				JFactory::getDocument()->addScriptDeclaration(
					"
		tinyMCE.init({
			// General
			directionality: \"$text_direction\",
			language : \"$langPrefix\",
			mode : \"specific_textareas\",
			autosave_restore_when_empty: false,
			$skin
			theme : \"$theme\",
			schema: \"html5\",
			selector: \"textarea.mce_editable\",
			// Cleanup/Output
			inline_styles : true,
			gecko_spellcheck : true,
			entity_encoding : \"$entity_encoding\",
			valid_elements : \"$valid_elements\",
			extended_valid_elements : \"$elements\",
			$forcenewline
			$smallButtons
			invalid_elements : \"$invalid_elements\",
			// Plugins
			plugins : \"table link image code hr charmap autolink lists importcss $dragDropPlg\",
			// Toolbar
			toolbar1: \"$toolbar1 | $toolbar5 | code\",
			removed_menuitems: \"newdocument\",
			// URL
			relative_urls : $relative_urls,
			remove_script_host : false,
			document_base_url : \"" . JUri::root() . "\",
			// Layout
			$content_css
			importcss_append: true,
			// Advanced Options
			$resizing
			height : \"$html_height\",
			width : \"$html_width\",
			setup: function (editor) {
				$tinyBtns
			},
			paste_data_images: $allowImgPaste
		});
			"
				);
				break;

			case 2: /* Extended mode*/
				JFactory::getDocument()->addScriptDeclaration(
					"
		tinyMCE.init({
			// General
			directionality: \"$text_direction\",
			language : \"$langPrefix\",
			mode : \"specific_textareas\",
			autosave_restore_when_empty: false,
			$skin
			theme : \"$theme\",
			schema: \"html5\",
			selector: \"textarea.mce_editable\",
			// Cleanup/Output
			inline_styles : true,
			gecko_spellcheck : true,
			entity_encoding : \"$entity_encoding\",
			valid_elements : \"$valid_elements\",
			extended_valid_elements : \"$elements\",
			$forcenewline
			$smallButtons
			invalid_elements : \"$invalid_elements\",
			// Plugins
			plugins : \"$plugins $dragDropPlg\",
			// Toolbar
			toolbar1: \"$toolbar1 | code\",
			removed_menuitems: \"newdocument\",
			// URL
			relative_urls : $relative_urls,
			remove_script_host : false,
			document_base_url : \"" . JUri::root() . "\",
			rel_list : [
				{title: 'Alternate', value: 'alternate'},
				{title: 'Author', value: 'author'},
				{title: 'Bookmark', value: 'bookmark'},
				{title: 'Help', value: 'help'},
				{title: 'License', value: 'license'},
				{title: 'Lightbox', value: 'lightbox'},
				{title: 'Next', value: 'next'},
				{title: 'No Follow', value: 'nofollow'},
				{title: 'No Referrer', value: 'noreferrer'},
				{title: 'Prefetch', value: 'prefetch'},
				{title: 'Prev', value: 'prev'},
				{title: 'Search', value: 'search'},
				{title: 'Tag', value: 'tag'}
			],
			//Templates
			" . $templates . "
			// Layout
			$content_css
			importcss_append: true,
			// Advanced Options
			$resizing
			image_advtab: $image_advtab,
			height : \"$html_height\",
			width : \"$html_width\",
			setup: function (editor) {
				$tinyBtns
			},
			paste_data_images: $allowImgPaste
		});
		"
				);
				break;
		}

		if (!empty($btnsNames))
		{
			JFactory::getDocument()->addScriptDeclaration(
				"
		function jInsertEditorText( text, editor )
		{
			tinyMCE.activeEditor.execCommand('mceInsertContent', false, text);
		}
			"
			);
		}

		return;
	}

	/**
	 * TinyMCE WYSIWYG Editor - get the editor content
	 *
	 * @param   string  $editor  The name of the editor
	 *
	 * @return  string
	 */
	public function onGetContent($editor)
	{
		return 'tinyMCE.activeEditor.getContent();';
	}

	/**
	 * TinyMCE WYSIWYG Editor - set the editor content
	 *
	 * @param   string  $editor  The name of the editor
	 * @param   string  $html    The html to place in the editor
	 *
	 * @return  string
	 */
	public function onSetContent($editor, $html)
	{
		return 'tinyMCE.activeEditor.setContent(' . $html . ');';
	}

	/**
	 * TinyMCE WYSIWYG Editor - copy editor content to form field
	 *
	 * @param   string  $editor  The name of the editor
	 *
	 * @return  string
	 */
	public function onSave($editor)
	{
		return 'if (tinyMCE.get("' . $editor . '").isHidden()) {tinyMCE.get("' . $editor . '").show()};';
	}

	/**
	 * Inserts html code into the editor
	 *
	 * @param   string  $name  The name of the editor
	 *
	 * @return  void
	 *
	 * @deprecated 3.5 tinyMCE (API v4) will get the content automatically from the text area
	 */
	public function onGetInsertMethod($name)
	{
		return;
	}

	/**
	 * Display the editor area.
	 *
	 * @param   string   $name     The name of the editor area.
	 * @param   string   $content  The content of the field.
	 * @param   string   $width    The width of the editor area.
	 * @param   string   $height   The height of the editor area.
	 * @param   int      $col      The number of columns for the editor area.
	 * @param   int      $row      The number of rows for the editor area.
	 * @param   boolean  $buttons  True and the editor buttons will be displayed.
	 * @param   string   $id       An optional ID for the textarea. If not supplied the name is used.
	 * @param   string   $asset    The object asset
	 * @param   object   $author   The author.
	 *
	 * @return  string
	 */
	public function onDisplay($name, $content, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null)
	{
		if (empty($id))
		{
			$id = $name;
		}

		// 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';
		}

		// Data object for the layout
		$textarea = new stdClass;
		$textarea->name    = $name;
		$textarea->id      = $id;
		$textarea->cols    = $col;
		$textarea->rows    = $row;
		$textarea->width   = $width;
		$textarea->height  = $height;
		$textarea->content = $content;

		$editor = '<div class="editor">';
		$editor .= JLayoutHelper::render('joomla.tinymce.textarea', $textarea);
		$editor .= $this->_toogleButton($id);
		$editor .= '</div>';

		return $editor;
	}

	/**
	 * Get the toggle editor button
	 *
	 * @param   string  $name  Editor name
	 *
	 * @return  string
	 */
	private function _toogleButton($name)
	{
		return JLayoutHelper::render('joomla.tinymce.togglebutton', $name);
	}

	/**
	 * Get the XTD buttons and render them inside tinyMCE
	 *
	 * @return array
	 */
	private function tinyButtons()
	{
		// Get the available buttons
		$buttons = $this->_subject->getButtons($this->_name, true);

		// Init the arrays for the buttons
		$tinyBtns  = array();
		$btnsNames = array();

		// Build the script
		foreach ($buttons as $button)
		{
			if ($button->get('name'))
			{
				// Set some vars
				$name    = str_replace(" ", "", $button->get('text'));
				$title   = $button->get('text');
				$onclick = ($button->get('onclick')) ? $button->get('onclick') : null;
				$options = $button->get('options');
				$icon    = $button->get('name');

				if ($button->get('link') != "#")
				{
					$href = JUri::base() . $button->get('link');
				}
				else
				{
					$href = null;
				}

				// We do some hack here to set the correct icon for 3PD buttons
				$icon = 'none icon-' . $icon;

				// Get the modal width/height
				if ($options)
				{
					preg_match('/x:\s*+\d{2,4}/', $options, $modalWidth);
					preg_match('/y:\s*+\d{2,4}/', $options, $modalHeight);
					$modalWidth  = filter_var(implode("", $modalWidth), FILTER_SANITIZE_NUMBER_INT);
					$modalHeight = filter_var(implode("", $modalHeight), FILTER_SANITIZE_NUMBER_INT);
				}

				// Now we can built the script
				$tempConstructor = "
				editor.addButton(\"" . $name . "\", {
					text: \"" . $title . "\",
					title: \"" . $title . "\",
					icon: \"" . $icon . "\",
					onclick: function () {";
				if ($button->get('modal') || $href)
				{
					$tempConstructor .= "
							editor.windowManager.open({
								title  : \"" . $title . "\",
								url : '" . $href . "',";
					if (!empty($modalHeight) && !empty($modalWidth))
					{
						$tempConstructor .= "
								width  : $modalWidth,
								height : $modalHeight,";
					}
					$tempConstructor .= "
								buttons: [{
									text   : \"Close\",
									onclick: \"close\"
								}]
							});";
					if ($onclick && ($button->get('modal') || $href))
					{
						$tempConstructor .= ",
						" . $onclick . "
							";
					}
				}
				else
				{
					$tempConstructor .= "
						" . $onclick . "
							";
				}
				$tempConstructor .= "
					}
				})";

				// The array with the toolbar buttons
				$btnsNames[] = $name;

				// The array with code for each button
				$tinyBtns[] = $tempConstructor;
			}
		}

		return array(
			'names'  => $btnsNames,
			'script' => $tinyBtns
		);
	}
}

No other release has this exact content. See every version of this file.