/
HtmlEditor.php
112 lines (100 loc) · 2.85 KB
/
HtmlEditor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\Editor\CkEditor\CkEditor;
/**
* A html editor field to use with QuickForm.
*/
class HtmlEditor extends HTML_QuickForm_textarea
{
/** @var \Chamilo\CoreBundle\Component\Editor\Editor */
public $editor;
/**
* Full page.
*/
public $fullPage;
/**
* Class Constructor.
*
* @param string $name
* @param string $elementLabel HTML editor label
* @param array $attributes Attributes for the textarea
* @param array $config optional configuration settings for the online editor
*/
public function __construct(
$name = null,
$elementLabel = null,
$attributes = [],
$config = []
) {
if (empty($name)) {
throw new \Exception('Name is required');
}
parent::__construct($name, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'html_editor';
//$editor = Container::getHtmlEditor();
$editor = new CkEditor();
if ($editor) {
$this->editor = $editor;
$this->editor->setName($name);
$this->editor->processConfig($config);
}
}
/**
* Return the HTML editor in HTML.
*
* @return string
*/
public function toHtml()
{
if ($this->editor) {
if ($this->editor->getConfigAttribute('fullPage')) {
$value = $this->getValue();
if (strlen(trim($value)) == 0) {
// TODO: To be considered whether here to add
// language and character set declarations.
$value = '<!DOCTYPE html><html><head><title></title></head><body></body></html>';
$this->setValue($value);
}
}
}
if ($this->isFrozen()) {
return $this->getFrozenHtml();
} else {
$styleCss = $this->editor->getConfigAttribute('style');
$style = false;
if ($styleCss) {
$style = true;
}
return $this->buildEditor($style);
}
}
/**
* Returns the html area content in HTML.
*
* @return string
*/
public function getFrozenHtml()
{
return $this->getCleanValue();
}
/**
* @param bool $style
*
* @return string
*/
public function buildEditor($style = false)
{
$result = '';
if ($this->editor) {
$this->editor->value = $this->getCleanValue();
$this->editor->setName($this->getName());
if ($style === true) {
$result = $this->editor->createHtmlStyle();
} else {
$result = $this->editor->createHtml();
}
}
return $result;
}
}