html_editor.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * A html editor field to use with QuickForm
  6. */
  7. class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea
  8. {
  9. /** @var \Chamilo\CoreBundle\Component\Editor\Editor */
  10. public $editor;
  11. /**
  12. * Class constructor
  13. * @param string HTML editor name/id
  14. * @param string HTML editor label
  15. * @param array Attributes for the textarea
  16. * @param array $config Optional configuration settings for the online editor.
  17. * @return bool
  18. */
  19. public function HTML_QuickForm_html_editor($name = null, $label = null, $attributes = null, $config = null)
  20. {
  21. if (empty($name)) {
  22. return false;
  23. }
  24. HTML_QuickForm_element::HTML_QuickForm_element($name, $label, $attributes);
  25. $this->_persistantFreeze = true;
  26. $this->_type = 'html_editor';
  27. global $fck_attribute;
  28. $editor = Container::getHtmlEditor();
  29. if ($editor) {
  30. $this->editor = $editor;
  31. $this->editor->setName($name);
  32. $this->editor->processConfig($fck_attribute);
  33. $this->editor->processConfig($config);
  34. }
  35. }
  36. /**
  37. * Return the HTML editor in HTML
  38. * @return string
  39. */
  40. public function toHtml()
  41. {
  42. $value = $this->getValue();
  43. if ($this->editor) {
  44. if ($this->editor->getConfigAttribute('fullPage')) {
  45. if (strlen(trim($value)) == 0) {
  46. // TODO: To be considered whether here to be added DOCTYPE, language and character set declarations.
  47. $value = '<html><head><title></title></head><body></body></html>';
  48. $this->setValue($value);
  49. }
  50. }
  51. }
  52. if ($this->isFrozen()) {
  53. return $this->getFrozenHtml();
  54. } else {
  55. return $this->buildEditor();
  56. }
  57. }
  58. /**
  59. * Returns the html area content in HTML
  60. * @return string
  61. */
  62. public function getFrozenHtml()
  63. {
  64. return $this->getValue();
  65. }
  66. /**
  67. * @return string
  68. */
  69. public function buildEditor()
  70. {
  71. $result = '';
  72. if ($this->editor) {
  73. $this->editor->value = $this->getValue();
  74. $this->editor->setName($this->getName());
  75. $result = $this->editor->createHtml();
  76. }
  77. return $result;
  78. }
  79. }