html_editor.php 2.2 KB

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