PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/redirect/code/trunk/administrator/components/com_redirect/libraries/jxtended/form/fields/editor.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 114 lines | 62 code | 10 blank | 42 comment | 20 complexity | 8bcefca8c670e1c68bf13c26fbe53cd2 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: editor.php 390 2010-11-05 11:35:33Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage Form
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License
  8. * @link http://www.theartofjoomla.com
  9. */
  10. defined('JPATH_BASE') or die;
  11. jimport('joomla.html.editor');
  12. juimport('jxtended.form.formfield');
  13. /**
  14. * Form Field class for JXtended Libraries.
  15. *
  16. * @package JXtended.Libraries
  17. * @subpackage Form
  18. * @since 1.1
  19. */
  20. class JFormFieldEditor extends JFormField
  21. {
  22. /**
  23. * The field type.
  24. *
  25. * @var string
  26. */
  27. public $type = 'Editor';
  28. /**
  29. * A refenence to the editor object.
  30. *
  31. * @var object.
  32. */
  33. protected $_editor = null;
  34. /**
  35. * Method to get the field input.
  36. *
  37. * @return string The field input.
  38. */
  39. protected function _getInput()
  40. {
  41. $rows = $this->_element->attributes('rows');
  42. $cols = $this->_element->attributes('cols');
  43. $height = ($this->_element->attributes('height')) ? $this->_element->attributes('height') : '250';
  44. $width = ($this->_element->attributes('width')) ? $this->_element->attributes('width') : '100%';
  45. $class = ($this->_element->attributes('class') ? 'class="'.$this->_element->attributes('class').'"' : 'class="text_area"');
  46. $buttons = $this->_element->attributes('buttons');
  47. if ($buttons == 'true' || $buttons == 'yes' || $buttons == 1) {
  48. $buttons = true;
  49. }
  50. else if ($buttons == 'false' || $buttons == 'no' || $buttons == 0) {
  51. $buttons = false;
  52. }
  53. else {
  54. $buttons = explode(',', $buttons);
  55. }
  56. $editor = $this->_getEditor();
  57. return $editor->display($this->inputName, htmlspecialchars($this->value), $width, $height, $cols, $rows, $buttons, $this->inputId);
  58. }
  59. /**
  60. * Get the editor object.
  61. *
  62. * @return object
  63. */
  64. protected function &_getEditor()
  65. {
  66. if (empty($this->_editor))
  67. {
  68. // editor attribute can be in the form of:
  69. // editor="desired|alternative"
  70. if ($editorName = trim($this->_element->attributes('editor')))
  71. {
  72. $parts = explode('|', $editorName);
  73. $db = &JFactory::getDbo();
  74. $query = 'SELECT element' .
  75. ' FROM #__plugins' .
  76. ' WHERE element = '.$db->Quote($parts[0]) .
  77. ' AND folder = '.$db->Quote('editors') .
  78. ' AND published = 1';
  79. $db->setQuery($query);
  80. if ($db->loadResult()) {
  81. $editorName = trim($parts[0]);
  82. }
  83. else if (isset($parts[1])) {
  84. $editorName = trim($parts[1]);
  85. }
  86. else {
  87. $editorName = '';
  88. }
  89. $this->_element->addAttribute('editor', $editorName);
  90. }
  91. $this->_editor = JFactory::getEditor($editorName ? $editorName : null);
  92. }
  93. return $this->_editor;
  94. }
  95. /**
  96. * Get the internal reference to the editor.
  97. *
  98. * @return string
  99. */
  100. public function save()
  101. {
  102. return $this->_editor->save($this->inputId);
  103. }
  104. }