[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/form/fields/ -> editor.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  Form
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 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  jimport('joomla.html.editor');
  13  
  14  /**
  15   * Form Field class for the Joomla Platform.
  16   * An editarea field for content creation
  17   *
  18   * @package     Joomla.Platform
  19   * @subpackage  Form
  20   * @see         JFormfieldEditors
  21   * @see         JEditor
  22   * @since       11.1
  23   */
  24  class JFormFieldEditor extends JFormField
  25  {
  26      /**
  27       * The form field type.
  28       *
  29       * @var    string
  30       * @since  11.1
  31       */
  32      public $type = 'Editor';
  33  
  34      /**
  35       * The JEditor object.
  36       *
  37       * @var    object
  38       * @since  11.1
  39       */
  40      protected $editor;
  41  
  42      /**
  43       * Method to get the field input markup for the editor area
  44       *
  45       * @return  string  The field input markup.
  46       *
  47       * @since   11.1
  48       */
  49  	protected function getInput()
  50      {
  51          // Initialize some field attributes.
  52          $rows = (int) $this->element['rows'];
  53          $cols = (int) $this->element['cols'];
  54          $height = ((string) $this->element['height']) ? (string) $this->element['height'] : '250';
  55          $width = ((string) $this->element['width']) ? (string) $this->element['width'] : '100%';
  56          $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
  57          $authorField = $this->element['created_by_field'] ? (string) $this->element['created_by_field'] : 'created_by';
  58          $asset = $this->form->getValue($assetField) ? $this->form->getValue($assetField) : (string) $this->element['asset_id'];
  59  
  60          // Build the buttons array.
  61          $buttons = (string) $this->element['buttons'];
  62  
  63          if ($buttons == 'true' || $buttons == 'yes' || $buttons == '1')
  64          {
  65              $buttons = true;
  66          }
  67          elseif ($buttons == 'false' || $buttons == 'no' || $buttons == '0')
  68          {
  69              $buttons = false;
  70          }
  71          else
  72          {
  73              $buttons = explode(',', $buttons);
  74          }
  75  
  76          $hide = ((string) $this->element['hide']) ? explode(',', (string) $this->element['hide']) : array();
  77  
  78          // Get an editor object.
  79          $editor = $this->getEditor();
  80  
  81          return $editor
  82              ->display(
  83              $this->name, htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'), $width, $height, $cols, $rows,
  84              $buttons ? (is_array($buttons) ? array_merge($buttons, $hide) : $hide) : false, $this->id, $asset,
  85              $this->form->getValue($authorField)
  86          );
  87      }
  88  
  89      /**
  90       * Method to get a JEditor object based on the form field.
  91       *
  92       * @return  JEditor  The JEditor object.
  93       *
  94       * @since   11.1
  95       */
  96      protected function &getEditor()
  97      {
  98          // Only create the editor if it is not already created.
  99          if (empty($this->editor))
 100          {
 101              // Initialize variables.
 102              $editor = null;
 103  
 104              // Get the editor type attribute. Can be in the form of: editor="desired|alternative".
 105              $type = trim((string) $this->element['editor']);
 106  
 107              if ($type)
 108              {
 109                  // Get the list of editor types.
 110                  $types = explode('|', $type);
 111  
 112                  // Get the database object.
 113                  $db = JFactory::getDBO();
 114  
 115                  // Iterate over teh types looking for an existing editor.
 116                  foreach ($types as $element)
 117                  {
 118                      // Build the query.
 119                      $query = $db->getQuery(true);
 120                      $query->select('element');
 121                      $query->from('#__extensions');
 122                      $query->where('element = ' . $db->quote($element));
 123                      $query->where('folder = ' . $db->quote('editors'));
 124                      $query->where('enabled = 1');
 125  
 126                      // Check of the editor exists.
 127                      $db->setQuery($query, 0, 1);
 128                      $editor = $db->loadResult();
 129  
 130                      // If an editor was found stop looking.
 131                      if ($editor)
 132                      {
 133                          break;
 134                      }
 135                  }
 136              }
 137  
 138              // Create the JEditor instance based on the given editor.
 139              $this->editor = JFactory::getEditor($editor ? $editor : null);
 140          }
 141  
 142          return $this->editor;
 143      }
 144  
 145      /**
 146       * Method to get the JEditor output for an onSave event.
 147       *
 148       * @return  string  The JEditor object output.
 149       *
 150       * @since   11.1
 151       */
 152  	public function save()
 153      {
 154          return $this->getEditor()->save($this->id);
 155      }
 156  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1