PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/contentmanager/code/trunk/administrator/components/com_contentmanager/libraries/jxtended/form/fields/editor.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 96 lines | 53 code | 7 blank | 36 comment | 8 complexity | 0fda02795e8676923b5053260dc180e0 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: editor.php 160 2009-07-09 00:06:09Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage Form
  6. * @copyright Copyright (C) 2008 - 2009 JXtended, LLC. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://jxtended.com
  9. */
  10. defined('JPATH_BASE') or die;
  11. jimport('joomla.html.editor');
  12. jximport2('jxtended.form.field');
  13. /**
  14. * JXtended Form Field Type Class for an Editor.
  15. *
  16. * @package JXtended.Libraries
  17. * @subpackage Form
  18. * @version 1.0
  19. */
  20. class JXFieldTypeEditor extends JXFieldType
  21. {
  22. /**
  23. * Field type
  24. *
  25. * @access protected
  26. * @var string
  27. */
  28. var $_name = 'Editor';
  29. /**
  30. * Method to generate the form field markup.
  31. *
  32. * @access public
  33. * @param string The form field name.
  34. * @param string The form field value.
  35. * @param object The JXFormField object.
  36. * @param string The form field control name.
  37. * @return string Form field markup.
  38. * @since 1.0
  39. */
  40. function fetchField($name, $value, &$node, $controlName)
  41. {
  42. // editor attribute can be in the form of:
  43. // editor="desired|alternative"
  44. if ($editorName = trim($node->attributes('editor')))
  45. {
  46. $parts = explode('|', $editorName);
  47. $db = &JFactory::getDBO();
  48. $query = 'SELECT element' .
  49. ' FROM #__plugins' .
  50. ' WHERE element = '.$db->Quote($parts[0]) .
  51. ' AND folder = '.$db->Quote('editors') .
  52. ' AND published = 1';
  53. $db->setQuery($query);
  54. if ($db->loadResult()) {
  55. $editorName = $parts[0];
  56. }
  57. else if (isset($parts[1])) {
  58. $editorName = $parts[1];
  59. }
  60. else {
  61. $editorName = '';
  62. }
  63. $node->addAttribute('editor', $editorName);
  64. }
  65. $editor = &JFactory::getEditor($editorName ? $editorName : null);
  66. $rows = $node->attributes('rows');
  67. $cols = $node->attributes('cols');
  68. $height = ($node->attributes('height')) ? $node->attributes('height') : '200';
  69. $width = ($node->attributes('width')) ? $node->attributes('width') : '100%';
  70. $class = ($node->attributes('class') ? 'class="'.$node->attributes('class').'"' : 'class="text_area"');
  71. $buttons = $node->attributes('buttons');
  72. $editor->set('TemplateXML', $node->attributes('templatexml'));
  73. if ($buttons == 'true') {
  74. $buttons = true;
  75. } else {
  76. $buttons = explode(',', $buttons);
  77. }
  78. // convert <br /> tags so they are not visible when editing
  79. //$value = str_replace('<br />', "\n", $value);
  80. return $editor->display($controlName.'['.$name.']', htmlspecialchars($value), $width, $height, $cols, $rows, $buttons) ;
  81. }
  82. function render(&$xmlElement, $value, $controlName = 'jxform')
  83. {
  84. $result = &parent::render($xmlElement, $value, $controlName);
  85. $editorName = trim($xmlElement->attributes('editor'));
  86. $result->editor = &JFactory::getEditor($editorName ? $editorName : null);
  87. return $result;
  88. }
  89. }