<?php
/**
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * THIS IS PURELY A TEST AND IF IT WORKS AGAIN ONLY SHOULD BE USED
 * UNTIL JOOMLA USES MOOTOOLS 1.2
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 *  
 * @version		$Id: editor.php 10381 2008-06-01 03:35:53Z pasamio $
 * @package		Joomla.Framework
 * @subpackage	HTML
 * @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.
 */

// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();

jimport('joomla.event.dispatcher');

/**
 * FEditor class to handle WYSIWYG editors
 *
 * @author		Louis Landry <louis.landry@joomla.org>
 * @author		Johan Janssens <johan.janssens@joomla.org>
 * @package		Joomla.Framework
 * @subpackage	HTML
 * @since		1.5
 */
class FEditor extends JEditor
{
	/**
	 * Editor Plugin object
	 *
	 * @var	object
	 */
	var $_editor = null;

	/**
	 * Editor Plugin name
	 *
	 * @var string
	 */
	var $_name = null;

	/**
	 * Load the editor
	 *
	 * @param	array	Associative array of editor config paramaters
	 * @since	1.5
	 */
	function _loadEditor($config = array())
	{
		//check if editor is already loaded
		if (!is_null(($this->_editor))) {
			return;
		}

		jimport('joomla.filesystem.file');

		// Build the path to the needed editor plugin
		$name = JFilterInput::clean($this->_name, 'cmd');
		//$path = JPATH_SITE.DS.'plugins'.DS.'editors'.DS.$name.'.php';
		
		//$$$rob - redirect to our own editor classes!
		$path = JPATH_SITE.DS.'components'.DS.'com_fabrik'.DS.'helpers'.DS.'editors'.DS.$name.'.php';

		if (! JFile::exists($path) )
		{
			$path = JPATH_SITE.DS.'plugins'.DS.'editors'.DS.$name.'.php';
		}
		
		if (! JFile::exists($path) )
		{
			$path = JPATH_SITE.DS.'components'.DS.'com_fabrik'.DS.'helpers'.DS.'editors'.DS.'tinymce'.'.php';
		}

		// Require plugin file
		require_once $path;

		// Get the plugin
		$plugin   =& JPluginHelper::getPlugin('editors', $this->_name);
		$params   = new JParameter($plugin->params);
		$params->loadArray($config);
		$plugin->params = $params;

		// Build editor plugin classname
		$name = 'FplgEditor'.$this->_name;
		if (!class_exists($name)) {
			$name = 'plgEditor'.$this->_name;
		}
		if ($this->_editor = new $name ($this, (array)$plugin)) {
			// load plugin parameters
			$this->initialise();
			JPluginHelper::importPlugin('editors-xtd');
		}
	}
}