[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/html/ -> editor.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: editor.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla.Framework
   5   * @subpackage    HTML
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  jimport('joomla.event.dispatcher');
  19  
  20  /**
  21   * JEditor class to handle WYSIWYG editors
  22   *
  23   * @package        Joomla.Framework
  24   * @subpackage    HTML
  25   * @since        1.5
  26   */
  27  class JEditor extends JObservable
  28  {
  29      /**
  30       * Editor Plugin object
  31       *
  32       * @var    object
  33       */
  34      var $_editor = null;
  35  
  36      /**
  37       * Editor Plugin name
  38       *
  39       * @var string
  40       */
  41      var $_name = null;
  42      
  43      /**
  44       * Editor start and end tag
  45       * Used to tell SEF plugin not to process editor contents
  46       * @var array
  47       */
  48      var $_tagForSEF = array('start' => '<!-- Start Editor -->', 'end' => '<!-- End Editor -->'); 
  49  
  50      /**
  51       * constructor
  52       *
  53       * @access    protected
  54       * @param    string    The editor name
  55       */
  56  	function __construct($editor = 'none')
  57      {
  58          $this->_name = $editor;
  59      }
  60  
  61      /**
  62       * Returns a reference to a global Editor object, only creating it
  63       * if it doesn't already exist.
  64       *
  65       * This method must be invoked as:
  66       *         <pre>  $editor = &JEditor::getInstance([$editor);</pre>
  67       *
  68       * @access    public
  69       * @param    string    $editor  The editor to use.
  70       * @return    JEditor    The Editor object.
  71       */
  72      function &getInstance($editor = 'none')
  73      {
  74          static $instances;
  75  
  76          if (!isset ($instances)) {
  77              $instances = array ();
  78          }
  79  
  80          $signature = serialize($editor);
  81  
  82          if (empty ($instances[$signature])) {
  83              $instances[$signature] = new JEditor($editor);
  84          }
  85  
  86          return $instances[$signature];
  87      }
  88  
  89      /**
  90       * Initialize the editor
  91       */
  92  	function initialise()
  93      {
  94          //check if editor is already loaded
  95          if(is_null(($this->_editor))) {
  96              return;
  97          }
  98  
  99          $args['event'] = 'onInit';
 100  
 101          $return = '';
 102          $results[] = $this->_editor->update($args);
 103          foreach ($results as $result) {
 104              if (trim($result)) {
 105                  //$return .= $result;
 106                  $return = $result;
 107              }
 108          }
 109  
 110          $document =& JFactory::getDocument();
 111          $document->addCustomTag($return);
 112      }
 113  
 114      /**
 115       * Present a text area
 116       *
 117       * @param    string    The control name
 118       * @param    string    The contents of the text area
 119       * @param    string    The width of the text area (px or %)
 120       * @param    string    The height of the text area (px or %)
 121       * @param    int        The number of columns for the textarea
 122       * @param    int        The number of rows for the textarea
 123       * @param    boolean    True and the editor buttons will be displayed
 124       * @param    array    Associative array of editor parameters
 125       */
 126  	function display($name, $html, $width, $height, $col, $row, $buttons = true, $params = array())
 127      {
 128          $this->_loadEditor($params);
 129  
 130          //check if editor is already loaded
 131          if(is_null(($this->_editor))) {
 132              return;
 133          }
 134  
 135          // Backwards compatibility. Width and height should be passed without a semicolon from now on.
 136          // If editor plugins need a unit like "px" for CSS styling, they need to take care of that
 137          $width    = str_replace( ';', '', $width );
 138          $height    = str_replace( ';', '', $height );
 139  
 140          // Initialize variables
 141          $return = null;
 142  
 143          $args['name']          = $name;
 144          $args['content']     = $html;
 145          $args['width']          = $width;
 146          $args['height']      = $height;
 147          $args['col']          = $col;
 148          $args['row']          = $row;
 149          $args['buttons']     = $buttons;
 150          $args['event']          = 'onDisplay';
 151  
 152          $results[] = $this->_editor->update($args);
 153  
 154          foreach ($results as $result)
 155          {
 156              if (trim($result)) {
 157                  $return .= $result;
 158              }
 159          }
 160          return $this->_tagForSEF['start'] . $return . $this->_tagForSEF['end'];
 161      }
 162  
 163      /**
 164       * Save the editor content
 165       *
 166       * @param    string    The name of the editor control
 167       */
 168  	function save( $editor )
 169      {
 170          $this->_loadEditor();
 171  
 172          //check if editor is already loaded
 173          if(is_null(($this->_editor))) {
 174              return;
 175          }
 176  
 177          $args[] = $editor;
 178          $args['event'] = 'onSave';
 179  
 180          $return = '';
 181          $results[] = $this->_editor->update($args);
 182          foreach ($results as $result) {
 183              if (trim($result)) {
 184                  $return .= $result;
 185              }
 186          }
 187          return $return;
 188      }
 189  
 190      /**
 191       * Get the editor contents
 192       *
 193       * @param    string    The name of the editor control
 194       */
 195  	function getContent( $editor )
 196      {
 197          $this->_loadEditor();
 198  
 199          $args['name'] = $editor;
 200          $args['event'] = 'onGetContent';
 201  
 202          $return = '';
 203          $results[] = $this->_editor->update($args);
 204          foreach ($results as $result) {
 205              if (trim($result)) {
 206                  $return .= $result;
 207              }
 208          }
 209          return $return;
 210      }
 211  
 212      /**
 213       * Set the editor contents
 214       *
 215       * @param    string    The name of the editor control
 216       * @param    string    The contents of the text area
 217       */
 218  	function setContent( $editor, $html )
 219      {
 220          $this->_loadEditor();
 221  
 222          $args['name'] = $editor;
 223          $args['html'] = $html;
 224          $args['event'] = 'onSetContent';
 225  
 226          $return = '';
 227          $results[] = $this->_editor->update($args);
 228          foreach ($results as $result) {
 229              if (trim($result)) {
 230                  $return .= $result;
 231              }
 232          }
 233          return $return;
 234      }
 235  
 236      /**
 237       * Get the editor buttons
 238       *
 239       * @param    mixed    $buttons Can be boolean or array, if boolean defines if the buttons are displayed, if array defines a list of buttons not to show.
 240       * @access public
 241       * @since 1.5
 242       */
 243  	 function getButtons($editor, $buttons = true)
 244       {
 245          $result = array();
 246  
 247          if(is_bool($buttons) && !$buttons) {
 248              return $result;
 249          }
 250  
 251          // Get plugins
 252          $plugins = JPluginHelper::getPlugin('editors-xtd');
 253  
 254          foreach($plugins as $plugin)
 255          {
 256              if(is_array($buttons) &&  in_array($plugin->name, $buttons)) {
 257                  continue;
 258              }
 259  
 260              $isLoaded = JPluginHelper::importPlugin('editors-xtd', $plugin->name, false);
 261  
 262              $className = 'plgButton'.$plugin->name;
 263              if(class_exists($className)) {
 264                  $plugin = new $className($this, (array)$plugin);
 265              }
 266  
 267              // Try to authenticate -- only add to array if authentication is successful
 268              $resultTest = $plugin->onDisplay($editor);
 269              if ($resultTest) $result[] =  $resultTest;
 270          }
 271  
 272          return $result;
 273       }
 274  
 275      /**
 276       * Load the editor
 277       *
 278       * @access    private
 279       * @param    array    Associative array of editor config paramaters
 280       * @since    1.5
 281       */
 282  	function _loadEditor($config = array())
 283      {
 284          //check if editor is already loaded
 285          if(!is_null(($this->_editor))) {
 286              return;
 287          }
 288  
 289          jimport('joomla.filesystem.file');
 290  
 291          // Build the path to the needed editor plugin
 292          $name = JFilterInput::clean($this->_name, 'cmd');
 293          $path = JPATH_SITE.DS.'plugins'.DS.'editors'.DS.$name.'.php';
 294  
 295          if ( ! JFile::exists($path) )
 296          {
 297              $message = JText::_('Cannot load the editor');
 298              JError::raiseWarning( 500, $message );
 299              return false;
 300          }
 301  
 302          // Require plugin file
 303          require_once $path;
 304  
 305          // Get the plugin
 306          $plugin   =& JPluginHelper::getPlugin('editors', $this->_name);
 307          $params   = new JParameter($plugin->params);
 308          $params->loadArray($config);
 309          $plugin->params = $params;
 310  
 311          // Build editor plugin classname
 312          $name = 'plgEditor'.$this->_name;
 313          if($this->_editor = new $name ($this, (array)$plugin))
 314          {
 315              // load plugin parameters
 316              $this->initialise();
 317              JPluginHelper::importPlugin('editors-xtd');
 318          }
 319      }
 320  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1