Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/html/editor.php

Documentation is available at editor.php

  1. <?php
  2. /**
  3. @version        $Id: editor.php 6762 2007-03-03 08:37:41Z tcp $
  4. @package        Joomla.Framework
  5. @subpackage    HTML
  6. @copyright    Copyright (C) 2005 - 2007 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.application.event');
  19.  
  20. /**
  21.  * JEditor class to handle WYSIWYG editors
  22.  *
  23.  * @author        Louis Landry <[email protected]>
  24.  * @package        Joomla.Framework
  25.  * @subpackage    HTML
  26.  * @since        1.5
  27.  */
  28. class JEditor extends JObservable
  29. {
  30.     /**
  31.      * Editor Plugin object
  32.      *
  33.      *
  34.      */
  35.     var $_editor = null;
  36.  
  37.  
  38.     /**
  39.      * Editor Plugin name
  40.      *
  41.      *
  42.      */
  43.     var $_name = null;
  44.  
  45.     /**
  46.     * constructor
  47.     *
  48.     * @access protected
  49.     * @param string The editor name
  50.     */
  51.  
  52.     function __construct($editor 'none'{
  53.         $this->_name = $editor;
  54.     }
  55.  
  56.     /**
  57.      * Returns a reference to a global Editor object, only creating it
  58.      * if it doesn't already exist.
  59.      *
  60.      * This method must be invoked as:
  61.      *         <pre>  $editor = &JEditor::getInstance([$editor);</pre>
  62.      *
  63.      * @access public
  64.      * @param string $editor  The editor to use.
  65.      * @return JEditor  The Editor object.
  66.      */
  67.     function &getInstance($editor 'none')
  68.     {
  69.         static $instances;
  70.  
  71.         if (!isset ($instances)) {
  72.             $instances array ();
  73.         }
  74.  
  75.         $signature serialize($editor);
  76.  
  77.         if (empty ($instances[$signature])) {
  78.             $instances[$signaturenew JEditor($editor);
  79.         }
  80.  
  81.         return $instances[$signature];
  82.     }
  83.  
  84.     /**
  85.      * Initialize the editor
  86.      *
  87.      */
  88.     function initialise()
  89.     {
  90.         //check if editor is already loaded
  91.         if(is_null(($this->_editor))) {
  92.             return;
  93.         }
  94.  
  95.         $args['event''onInit';
  96.  
  97.         $return '';
  98.         $results[$this->_editor->update($args);
  99.         foreach ($results as $result{
  100.             if (trim($result)) {
  101.                 //$return .= $result;
  102.                 $return $result;
  103.             }
  104.         }
  105.  
  106.         $document =JFactory::getDocument();
  107.         $document->addCustomTag($return);
  108.     }
  109.  
  110.     /**
  111.      * Present a text area
  112.      *
  113.      *
  114.      */
  115.     function display($name$html$width$height$col$row$buttons true)
  116.     {
  117.         $this->_loadEditor();
  118.  
  119.         //check if editor is already loaded
  120.         if(is_null(($this->_editor))) {
  121.             return;
  122.         }
  123.         
  124.         /*
  125.          * Backwards compatibility. Width and height should be passed without a semicolon from now on.
  126.          * If editor plugins need a unit like "px" for CSS styling, they need to take care of that
  127.          */
  128.         $width    str_replace';'''$width );
  129.         $height    str_replace';'''$height );
  130.  
  131.         /*
  132.          * Initialize variables
  133.          */
  134.         $return null;
  135.  
  136.         $args['name']          $name;
  137.         $args['content']     $html;
  138.         $args['width']          $width;
  139.         $args['height']      $height;
  140.         $args['col']          $col;
  141.         $args['row']          $row;
  142.         $args['buttons']     $buttons;
  143.         $args['event']          'onDisplay';
  144.  
  145.         $results[$this->_editor->update($args);
  146.  
  147.         foreach ($results as $result{
  148.             if (trim($result)) {
  149.                 $return .= $result;
  150.             }
  151.         }
  152.         return $return;
  153.     }
  154.  
  155.     /**
  156.      * Save the editor content
  157.      *
  158.      *
  159.      */
  160.     function save$editor )
  161.     {
  162.         $this->_loadEditor();
  163.  
  164.         //check if editor is already loaded
  165.         if(is_null(($this->_editor))) {
  166.             return;
  167.         }
  168.         
  169.         $args[$editor;
  170.         $args['event''onSave';
  171.  
  172.         $return '';
  173.         $results[$this->_editor->update($args);
  174.         foreach ($results as $result{
  175.             if (trim($result)) {
  176.                 $return .= $result;
  177.             }
  178.         }
  179.         return $return;
  180.     }
  181.  
  182.     /**
  183.      * Get the editor contents
  184.      *
  185.      *
  186.      */
  187.     function getContent$editor )
  188.     {
  189.         $this->_loadEditor();
  190.  
  191.         $args['name'$editor;
  192.         $args['event''onGetContent';
  193.  
  194.         $return '';
  195.         $results[$this->_editor->update($args);
  196.         foreach ($results as $result{
  197.             if (trim($result)) {
  198.                 $return .= $result;
  199.             }
  200.         }
  201.         return $return;
  202.     }
  203.  
  204.     /**
  205.      * Set the editor contents
  206.      *
  207.      *
  208.      */
  209.     function setContent$editor$html )
  210.     {
  211.         $this->_loadEditor();
  212.  
  213.         $args['name'$editor;
  214.         $args['html'$html;
  215.         $args['event''onSetContent';
  216.  
  217.         $return '';
  218.         $results[$this->_editor->update($args);
  219.         foreach ($results as $result{
  220.             if (trim($result)) {
  221.                 $return .= $result;
  222.             }
  223.         }
  224.         return $return;
  225.     }
  226.  
  227.     /**
  228.      * Load the editor
  229.      *
  230.      * @access private
  231.      * @since 1.5
  232.      */
  233.     function _loadEditor()
  234.     {
  235.         //check if editor is already loaded
  236.         if(!is_null(($this->_editor))) {
  237.             return;
  238.         }
  239.         
  240.         jimport('joomla.filesystem.file');
  241.  
  242.         // Build the path to the needed editor plugin
  243.         $path JPATH_SITE.DS.'plugins'.DS.'editors'.DS.$this->_name.'.php';
  244.  
  245.         if JFile::exists($path) )
  246.         {
  247.             $message    JText::_('Cannot load the editor');
  248.             JError::raiseWarning500$message );
  249.             return false;
  250.         }
  251.         
  252.         // Require plugin file
  253.         require_once ($path);
  254.  
  255.         // Build editor plugin classname
  256.         $name 'plgEditor'.$this->_name;
  257.         if($this->_editor = new $name ($this))
  258.         {
  259.             $this->initialise();
  260.             JPluginHelper::importPlugin('editors-xtd');
  261.         }
  262.     }
  263. }
  264. ?>

Documentation generated on Mon, 05 Mar 2007 20:57:16 +0000 by phpDocumentor 1.3.1