Source for file editor.php

Documentation is available at editor.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12.  
  13. /**
  14.  * Form Field class for the Joomla CMS.
  15.  * A textarea field for content creation
  16.  *
  17.  * @package     Joomla.Libraries
  18.  * @subpackage  Form
  19.  * @see         JEditor
  20.  * @since       1.6
  21.  */
  22. {
  23.     /**
  24.      * The form field type.
  25.      *
  26.      * @var    string 
  27.      * @since  1.6
  28.      */
  29.     public $type = 'Editor';
  30.  
  31.     /**
  32.      * The JEditor object.
  33.      *
  34.      * @var    JEditor 
  35.      * @since  1.6
  36.      */
  37.     protected $editor;
  38.  
  39.     /**
  40.      * The height of the editor.
  41.      *
  42.      * @var    string 
  43.      * @since  3.2
  44.      */
  45.     protected $height;
  46.  
  47.     /**
  48.      * The width of the editor.
  49.      *
  50.      * @var    string 
  51.      * @since  3.2
  52.      */
  53.     protected $width;
  54.  
  55.     /**
  56.      * The assetField of the editor.
  57.      *
  58.      * @var    string 
  59.      * @since  3.2
  60.      */
  61.     protected $assetField;
  62.  
  63.     /**
  64.      * The authorField of the editor.
  65.      *
  66.      * @var    string 
  67.      * @since  3.2
  68.      */
  69.     protected $authorField;
  70.  
  71.     /**
  72.      * The asset of the editor.
  73.      *
  74.      * @var    string 
  75.      * @since  3.2
  76.      */
  77.     protected $asset;
  78.  
  79.     /**
  80.      * The buttons of the editor.
  81.      *
  82.      * @var    mixed 
  83.      * @since  3.2
  84.      */
  85.     protected $buttons;
  86.  
  87.     /**
  88.      * The hide of the editor.
  89.      *
  90.      * @var    array 
  91.      * @since  3.2
  92.      */
  93.     protected $hide;
  94.  
  95.     /**
  96.      * The editorType of the editor.
  97.      *
  98.      * @var    array 
  99.      * @since  3.2
  100.      */
  101.     protected $editorType;
  102.  
  103.     /**
  104.      * Method to get certain otherwise inaccessible properties from the form field object.
  105.      *
  106.      * @param   string  $name  The property name for which to the the value.
  107.      *
  108.      * @return  mixed  The property value or null.
  109.      *
  110.      * @since   3.2
  111.      */
  112.     public function __get($name)
  113.     {
  114.         switch ($name)
  115.         {
  116.             case 'height':
  117.             case 'width':
  118.             case 'assetField':
  119.             case 'authorField':
  120.             case 'asset':
  121.             case 'buttons':
  122.             case 'hide':
  123.             case 'editorType':
  124.                 return $this->$name;
  125.         }
  126.  
  127.         return parent::__get($name);
  128.     }
  129.  
  130.     /**
  131.      * Method to set certain otherwise inaccessible properties of the form field object.
  132.      *
  133.      * @param   string  $name   The property name for which to the the value.
  134.      * @param   mixed   $value  The value of the property.
  135.      *
  136.      * @return  void 
  137.      *
  138.      * @since   3.2
  139.      */
  140.     public function __set($name$value)
  141.     {
  142.         switch ($name)
  143.         {
  144.             case 'height':
  145.             case 'width':
  146.             case 'assetField':
  147.             case 'authorField':
  148.             case 'asset':
  149.                 $this->$name = (string) $value;
  150.                 break;
  151.  
  152.             case 'buttons':
  153.                 $value = (string) $value;
  154.  
  155.                 if ($value == 'true' || $value == 'yes' || $value == '1')
  156.                 {
  157.                     $this->buttons = true;
  158.                 }
  159.                 elseif ($value == 'false' || $value == 'no' || $value == '0')
  160.                 {
  161.                     $this->buttons = false;
  162.                 }
  163.                 else
  164.                 {
  165.                     $this->buttons = explode(','$value);
  166.                 }
  167.                 break;
  168.  
  169.             case 'hide':
  170.                 $value = (string) $value;
  171.                 $this->hide = $value explode(','$valuearray();
  172.                 break;
  173.  
  174.             case 'editorType':
  175.                 // Can be in the form of: editor="desired|alternative".
  176.                 $this->editorType  = explode('|'trim((string) $value));
  177.                 break;
  178.  
  179.             default:
  180.                 parent::__set($name$value);
  181.         }
  182.     }
  183.  
  184.     /**
  185.      * Method to attach a JForm object to the field.
  186.      *
  187.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  188.      * @param   mixed             $value    The form field value to validate.
  189.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  190.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  191.      *                                       full field name would end up being "bar[foo]".
  192.      *
  193.      * @return  boolean  True on success.
  194.      *
  195.      * @see     JFormField::setup()
  196.      * @since   3.2
  197.      */
  198.     public function setup(SimpleXMLElement $element$value$group null)
  199.     {
  200.         $result parent::setup($element$value$group);
  201.  
  202.         if ($result == true)
  203.         {
  204.             $this->height      = $this->element['height'? (string) $this->element['height''500';
  205.             $this->width       = $this->element['width'? (string) $this->element['width''100%';
  206.             $this->assetField  = $this->element['asset_field'? (string) $this->element['asset_field''asset_id';
  207.             $this->authorField = $this->element['created_by_field'? (string) $this->element['created_by_field''created_by';
  208.             $this->asset       = $this->form->getValue($this->assetField$this->form->getValue($this->assetField: (string) $this->element['asset_id'];
  209.  
  210.             $buttons    = (string) $this->element['buttons'];
  211.             $hide       = (string) $this->element['hide'];
  212.             $editorType = (string) $this->element['editor'];
  213.  
  214.             if ($buttons == 'true' || $buttons == 'yes' || $buttons == '1')
  215.             {
  216.                 $this->buttons = true;
  217.             }
  218.             elseif ($buttons == 'false' || $buttons == 'no' || $buttons == '0')
  219.             {
  220.                 $this->buttons = false;
  221.             }
  222.             else
  223.             {
  224.                 $this->buttons = !empty($hideexplode(','$buttonsarray();
  225.             }
  226.  
  227.             $this->hide        = !empty($hideexplode(','(string) $this->element['hide']array();
  228.             $this->editorType  = !empty($editorTypeexplode('|'trim($editorType)) array();
  229.         }
  230.  
  231.         return $result;
  232.     }
  233.  
  234.     /**
  235.      * Method to get the field input markup for the editor area
  236.      *
  237.      * @return  string  The field input markup.
  238.      *
  239.      * @since   1.6
  240.      */
  241.     protected function getInput()
  242.     {
  243.         // Get an editor object.
  244.         $editor $this->getEditor();
  245.  
  246.         return $editor->display(
  247.             $this->namehtmlspecialchars($this->valueENT_COMPAT'UTF-8')$this->width$this->height$this->cols$this->rows,
  248.             $this->buttons ? (is_array($this->buttonsarray_merge($this->buttons$this->hide$this->hidefalse$this->id$this->asset,
  249.             $this->form->getValue($this->authorField)array('syntax' => (string) $this->element['syntax'])
  250.         );
  251.     }
  252.  
  253.     /**
  254.      * Method to get a JEditor object based on the form field.
  255.      *
  256.      * @return  JEditor  The JEditor object.
  257.      *
  258.      * @since   1.6
  259.      */
  260.     protected function getEditor()
  261.     {
  262.         // Only create the editor if it is not already created.
  263.         if (empty($this->editor))
  264.         {
  265.             $editor null;
  266.  
  267.             if ($this->editorType)
  268.             {
  269.                 // Get the list of editor types.
  270.                 $types $this->editorType;
  271.  
  272.                 // Get the database object.
  273.                 $db JFactory::getDbo();
  274.  
  275.                 // Iterate over teh types looking for an existing editor.
  276.                 foreach ($types as $element)
  277.                 {
  278.                     // Build the query.
  279.                     $query $db->getQuery(true)
  280.                         ->select('element')
  281.                         ->from('#__extensions')
  282.                         ->where('element = ' $db->quote($element))
  283.                         ->where('folder = ' $db->quote('editors'))
  284.                         ->where('enabled = 1');
  285.  
  286.                     // Check of the editor exists.
  287.                     $db->setQuery($query01);
  288.                     $editor $db->loadResult();
  289.  
  290.                     // If an editor was found stop looking.
  291.                     if ($editor)
  292.                     {
  293.                         break;
  294.                     }
  295.                 }
  296.             }
  297.  
  298.             // Create the JEditor instance based on the given editor.
  299.             if (is_null($editor))
  300.             {
  301.                 $conf JFactory::getConfig();
  302.                 $editor $conf->get('editor');
  303.             }
  304.  
  305.             $this->editor = JEditor::getInstance($editor);
  306.         }
  307.  
  308.         return $this->editor;
  309.     }
  310.  
  311.     /**
  312.      * Method to get the JEditor output for an onSave event.
  313.      *
  314.      * @return  string  The JEditor object output.
  315.      *
  316.      * @since   1.6
  317.      */
  318.     public function save()
  319.     {
  320.         return $this->getEditor()->save($this->id);
  321.     }
  322. }

Documentation generated on Tue, 19 Nov 2013 15:02:15 +0100 by phpDocumentor 1.4.3