Passed
Push — 1.11.x ( 106594...56cdc0 )
by Angel Fernando Quiroz
08:52
created

main/inc/lib/formvalidator/Element/HtmlEditor.php (1 issue)

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
                /** @scrutinizer ignore-call */ 
106
                $result = $this->editor->createHtmlStyle($value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
            } else {
107
                $result = $this->editor->createHtml($value);
108
            }
109
        }
110
111
        return $result;
112
    }
113
}
114