Completed
Pull Request — master (#591)
by Richard
17:41
created

DhtmlTextArea::xoopsCodeControls()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 89
Code Lines 73

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 72
CRAP Score 5.0004

Importance

Changes 0
Metric Value
cc 5
eloc 73
nc 10
nop 0
dl 0
loc 89
ccs 72
cts 74
cp 0.973
crap 5.0004
rs 8.2779
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Form;
13
14
use Xoops\Html\Button;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Xoops\Form\Button. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
16
/**
17
 * DhtmlTextArea - A textarea with xoopsish formatting and smilie buttons
18
 *
19
 * @category  Xoops\Form\DhtmlTextArea
20
 * @package   Xoops\Form
21
 * @author    Kazumi Ono <[email protected]>
22
 * @author    Taiwen Jiang <[email protected]>
23
 * @author    Vinod <[email protected]>
24
 * @copyright 2001-2016 XOOPS Project (https://xoops.org)
25
 * @license   GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
26
 */
27
class DhtmlTextArea extends \XoopsEditor
28
{
29
    /**
30
     * Extended HTML editor
31
     *
32
     * <p>If an extended HTML editor is set, the renderer will be replaced by the specified editor,
33
     * usually a visual or WYSIWYG editor.</p>
34
     *
35
     * <ul>Developer and user guide:
36
     *      <li>
37
     *          <ul>For run-time settings per call
38
     *              <li>To use an editor pre-configured by {@link XoopsEditor}, e.g. 'fckeditor': <code>$options['editor'] = 'fckeditor';</code></li>
39
     *              <li>To use a custom editor, e.g. 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>$options['editor'] = array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li>
40
     *          </ul>
41
     *      </li>
42
     *      <li>
43
     *          <ul>For pre-configured settings, which will force to use a editor if no specific editor is set for call
44
     *              <li>
45
     *                  <ul>Set up custom configs: in XOOPS_VAR_PATH . '/configs/xoopsconfig.php' set a editor as default, e.g.
46
     *                      <li>a pre-configured editor 'fckeditor': <code>return array('editor' => 'fckeditor');</code></li>
47
     *                      <li>a custom editor 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>return array('editor' => array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li>
48
     *                  </ul>
49
     *              </li>
50
     *              <li>To disable the default editor, in XOOPS_VAR_PATH . '/configs/xoopsconfig.php': <code>return array();</code></li>
51
     *              <li>To disable the default editor for a specific call: <code>$options['editor'] = 'dhtmltextarea';</code></li>
52
     *          </ul>
53
     *      </li>
54
     * </ul>
55
     */
56
    /**
57
     * @var \XoopsEditor
58
     */
59
    public $htmlEditor;
60
61
    /**
62
     * Hidden text
63
     *
64
     * @var string
65
     */
66
    private $hiddenText;
67
68
    /**
69
     * @var bool
70
     */
71
    public $skipPreview = false;
72
73
    /**
74
     * @var bool
75
     */
76
    public $doHtml = false;
77
78
    /**
79
     * @var string
80
     */
81
    public $js = '';
82
83
    /**
84
     * @var array
85
     */
86
    public $configs = array();
87
88
    /**
89
     * Constructor
90
     *
91
     * @param string  $caption    Caption
92
     * @param string  $name       name attribute
93
     * @param string  $value      Initial text
94
     * @param integer $rows       Number of rows
95
     * @param integer $cols       Number of columns
96
     * @param string  $hiddentext Identifier for hidden Text
97
     * @param array   $options    Extra options
98
     */
99 6
    public function __construct(
100
        $caption,
101
        $name,
102
        $value = "",
103
        $rows = 5,
104
        $cols = 50,
105
        $hiddentext = "xoopsHiddenText",
106
        $options = array()
107
    ) {
108 6
        static $inLoop = 0;
109
110 6
        ++$inLoop;
111
        // Second loop, invalid, return directly
112 6
        if ($inLoop > 2) {
113
            return;
114
        }
115
116
        // Else, initialize
117 6
        parent::__construct($caption, $name, $value, $rows, $cols);
118 6
        $this->hiddenText = $hiddentext;
119
120 6
        if ($inLoop > 1) {
121
            return;
122
        }
123
124 6
        $xoops = \Xoops::getInstance();
125 6
        if (!isset($options['editor'])) {
126 6
            if ($editor = $xoops->getConfig('editor')) {
127
                $options['editor'] = $editor;
128
            }
129
        }
130
131 6
        if (!empty($this->htmlEditor) || !empty($options['editor'])) {
132
            $options['name'] = $this->getName();
133
            $options['value'] = $this->getValue();
134
            if (!empty($options['editor'])) {
135
                $this->htmlEditor = is_array($options['editor']) ? $options['editor'] : array($options['editor']);
0 ignored issues
show
Documentation Bug introduced by
It seems like is_array($options['edito...ray($options['editor']) of type array or array is incompatible with the declared type XoopsEditor of property $htmlEditor.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
136
            }
137
138
            if (count($this->htmlEditor) == 1) {
139
                $editor_handler = \XoopsEditorHandler::getInstance();
140
                $this->htmlEditor = $editor_handler->get($this->htmlEditor[0], $options);
141
                if ($inLoop > 1) {
142
                    $this->htmlEditor = null;
143
                }
144
            } else {
145
                list ($class, $path) = $this->htmlEditor;
146
                include_once \XoopsBaseConfig::get('root-path') . $path;
147
                if (class_exists($class)) {
148
                    $this->htmlEditor = new $class($options);
149
                }
150
                if ($inLoop > 1) {
151
                    $this->htmlEditor = null;
152
                }
153
            }
154
        }
155
156 6
        $inLoop = 0;
157 6
    }
158
159
    /**
160
     * defaultRender
161
     *
162
     * @return string rendered form element
163
     */
164 1
    public function defaultRender()
165
    {
166 1
        if ($this->htmlEditor && is_object($this->htmlEditor)) {
167
            if (!isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) {
168
                return $this->htmlEditor->render();
169
            }
170
        }
171 1
        static $js_loaded;
172
173 1
        $xoops = \Xoops::getInstance();
174
175 1
        $extra = ($this->getExtra() != '' ? " " . $this->getExtra() : '');
176 1
        $ret = "";
177
        // actions
178 1
        $ret .= $this->xoopsCodeControls() . "<br />\n";
179
        // fonts
180 1
        $ret .= $this->typographyControls();
181
182
        // the textarea box
183
184 1
        $this->suppressRender(['value']);
185 1
        $attributes = $this->renderAttributeString();
186
187 1
        $ret .= '<textarea ' . $attributes . $extra . '>' . $this->getValue() . "</textarea>\n";
188
189 1
        if (empty($this->skipPreview)) {
190 1
            if (!$xoops->theme()) {
191
                $this->js .= implode("", file($xoops->path('media/xoops/image.js')));
0 ignored issues
show
Bug introduced by
It seems like file($xoops->path('media/xoops/image.js')) can also be of type false; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

191
                $this->js .= implode("", /** @scrutinizer ignore-type */ file($xoops->path('media/xoops/image.js')));
Loading history...
192
            } else {
193 1
                $xoops->theme()->addScript('media/xoops/image.js', array('type' => 'text/javascript'));
194
            }
195 1
            $button = "<input id='" . $this->getName() . "_preview_button' " . "type='button' " . "class='btn btn-sm btn-default' value='" . \XoopsLocale::A_PREVIEW . "' " . "onclick=\"form_instantPreview('" . XOOPS_URL . "', '" . $this->getName() . "','" . XOOPS_URL . "/images', " . (int)($this->doHtml) . ", '" . $xoops->security()->createToken() . "')\"" . " />";
196 1
            $ret .= "<br />" . "<div id='" . $this->getName() . "_hidden' style='display: block;'> " . "<fieldset>" . "<legend>" . $button . "</legend>" . "<div id='" . $this->getName() . "_hidden_data'>" . \XoopsLocale::CLICK_PREVIEW_TO_SEE_CONTENT . "</div>" . "</fieldset>" . "</div>";
197
        }
198
        // Load javascript
199 1
        if (empty($js_loaded)) {
200 1
            $javascript = (($this->js)
201 1
                ? '<script type="text/javascript">' . $this->js . '</script>'
202 1
                : '') . '<script type="text/javascript" src="' . \XoopsBaseConfig::get('url') . '/include/formdhtmltextarea.js"></script>';
203 1
            $ret = $javascript . $ret;
204 1
            $js_loaded = true;
205
        }
206 1
        return $ret;
207
    }
208
209
    /**
210
     * xoopsCodeControls
211
     *
212
     * @return string
213
     */
214 2
    public function xoopsCodeControls()
215
    {
216 2
        $textarea_id = $this->getName();
217 2
        $xoops = \Xoops::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $xoops is dead and can be removed.
Loading history...
218 2
        $myts = \Xoops\Core\Text\Sanitizer::getInstance();
219
220 2
        $code = '';
221 2
        $code .= '<div class="row"><div class="col-md-12">';
222
223 2
        $urlText = htmlspecialchars(\XoopsLocale::ENTER_LINK_URL, ENT_COMPAT);
224 2
        $titleText = htmlspecialchars(\XoopsLocale::ENTER_WEBSITE_TITLE, ENT_COMPAT);
225 2
        $urlButton = new Button();
226 2
        $urlButton->set('type', 'button')
227 2
            ->set('class', 'btn btn-default btn-sm')
228 2
            ->set('alt', \XoopsLocale::URL)
229 2
            ->set('title', \XoopsLocale::URL)
230 2
            ->set('onclick', "xoopsCodeUrl(\"{$textarea_id}\", \"{$urlText}\", \"{$titleText}\")")
231 2
            ->set('onmouseover', "style.cursor='hand'")
232 2
            ->set('value', '<span class="fa fa-fw fa-link" aria-hidden="true"></span>');
233 2
        $code .= $urlButton->render();
234
235 2
        $emailText = htmlspecialchars(\XoopsLocale::ENTER_EMAIL, ENT_COMPAT);
236 2
        $emailButton = new Button();
237 2
        $emailButton->set('type', 'button')
238 2
            ->set('class', 'btn btn-default btn-sm')
239 2
            ->set('alt', \XoopsLocale::EMAIL)
240 2
            ->set('title', \XoopsLocale::EMAIL)
241 2
            ->set('onclick', "xoopsCodeEmail(\"{$textarea_id}\", \"{$emailText}\")")
242 2
            ->set('onmouseover', "style.cursor='hand'")
243 2
            ->set('value', '<span class="fa fa-fw fa-envelope-o" aria-hidden="true"></span>');
244 2
        $code .= $emailButton->render();
245
246 2
        $imgUrlText      = htmlspecialchars(\XoopsLocale::ENTER_IMAGE_URL, ENT_COMPAT);
247 2
        $imgPosText      = htmlspecialchars(\XoopsLocale::ENTER_IMAGE_POSITION, ENT_COMPAT);
248 2
        $imgPosDescText  = htmlspecialchars(\XoopsLocale::IMAGE_POSITION_DESCRIPTION, ENT_COMPAT);
249 2
        $imgEPosText     = htmlspecialchars(\XoopsLocale::E_ENTER_IMAGE_POSITION, ENT_COMPAT);
250 2
        $imgWidthText    = htmlspecialchars(\XoopsLocale::WIDTH, ENT_COMPAT);
251 2
        $imageButton = new Button();
252 2
        $imageButton->set('type', 'button')
253 2
            ->set('class', 'btn btn-default btn-sm')
254 2
            ->set('alt', \XoopsLocale::IMAGES)
255 2
            ->set('title', \XoopsLocale::IMAGES)
256 2
            ->set('onclick', "xoopsCodeImg(\"{$textarea_id}\", \"{$imgUrlText}\", \"{$imgPosText}\", \"{$imgPosDescText}\", \"{$imgEPosText}\", \"{$imgWidthText}\")")
257 2
            ->set('onmouseover', "style.cursor='hand'")
258 2
            ->set('value', '<span class="fa fa-fw fa-file-image-o" aria-hidden="true"></span>');
259 2
        $code .= $imageButton->render();
260
261 2
        $extensions = array_filter($myts->listExtensions());
262 2
        foreach ($extensions as $extension) {
263 2
            list ($button, $js) = $myts->getDhtmlEditorSupport($extension, $textarea_id);
264 2
            if (!empty($button)) {
265 2
                $code .= $button;
266
            }
267 2
            if (!empty($js)) {
268 2
                $this->js .= $js;
269
            }
270
        }
271
272 2
        $codeText = htmlspecialchars(\XoopsLocale::ENTER_CODE, ENT_COMPAT);
273 2
        $codeButton = new Button();
274 2
        $codeButton->set('type', 'button')
275 2
            ->set('class', 'btn btn-default btn-sm')
276 2
            ->set('alt', \XoopsLocale::SOURCE_CODE)
277 2
            ->set('title', \XoopsLocale::SOURCE_CODE)
278 2
            ->set('onclick', "xoopsCodeCode(\"{$textarea_id}\", \"{$codeText}\")")
279 2
            ->set('onmouseover', "style.cursor='hand'")
280 2
            ->set('value', '<span class="fa fa-fw fa-code" aria-hidden="true"></span>');
281 2
        $code .= $codeButton->render();
282
283 2
        $quoteText = htmlspecialchars(\XoopsLocale::ENTER_QUOTE, ENT_COMPAT);
0 ignored issues
show
Unused Code introduced by
The assignment to $quoteText is dead and can be removed.
Loading history...
284 2
        $quoteButton = new Button();
285 2
        $quoteButton->set('type', 'button')
286 2
            ->set('class', 'btn btn-default btn-sm')
287 2
            ->set('alt', \XoopsLocale::QUOTE)
288 2
            ->set('title', \XoopsLocale::QUOTE)
289 2
            ->set('onclick', "xoopsCodeQuote(\"{$textarea_id}\", \"{$codeText}\")")
290 2
            ->set('onmouseover', "style.cursor='hand'")
291 2
            ->set('value', '<span class="fa fa-fw fa-quote-right" aria-hidden="true"></span>');
292 2
        $code .= $quoteButton->render();
293
294 2
        $response = \Xoops::getInstance()->service('emoji')->renderEmojiSelector($this->getName());
295 2
        if ($response->isSuccess()) {
296
            $emojiSelector = $response->getValue();
297
            $code .= $emojiSelector;
298
        }
299
300 2
        $code .= "</div></div>";
301
302 2
        return $code;
303
    }
304
305
    /**
306
     * Render typography controls for editor (font, size, color)
307
     *
308
     * @param XoopsFormDhtmlTextArea $element form element
0 ignored issues
show
Bug introduced by
The type Xoops\Form\XoopsFormDhtmlTextArea was not found. Did you mean XoopsFormDhtmlTextArea? If so, make sure to prefix the type with \.
Loading history...
309
     *
310
     * @return string rendered typography controls
311
     */
312 1
    public function typographyControls()
313
    {
314 1
        $textarea_id = $this->getName();
315 1
        $hiddentext = $this->hiddenText;
316
317 1
        $fontarray = \XoopsLocale::getFonts();
318
319
        $colorArray = array(
320 1
            'Black'  => '000000',
321
            'Blue'   => '38AAFF',
322
            'Brown'  => '987857',
323
            'Green'  => '79D271',
324
            'Grey'   => '888888',
325
            'Orange' => 'FFA700',
326
            'Paper'  => 'E0E0E0',
327
            'Purple' => '363E98',
328
            'Red'    => 'FF211E',
329
            'White'  => 'FEFEFE',
330
            'Yellow' => 'FFD628',
331
        );
332
333 1
        $fontStr = '<div class="row"><div class="col-md-12"><div class="btn-group" role="toolbar">';
334
        $fontStr .= '<div class="btn-group">'
335 1
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. \XoopsLocale::SIZE .'"'
336 1
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
337 1
            . '<span class = "glyphicon glyphicon-text-height"></span><span class="caret"></span></button>'
338 1
            . '<ul class="dropdown-menu">';
339 1
        $localeFontSizes = \XoopsLocale::getFontSizes();
340 1
        foreach ($localeFontSizes as $value => $name) {
341 1
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'size\', \'' . $value . '\', \''
342 1
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $name . '</a></li>';
343
        }
344 1
        $fontStr .= '</ul></div>';
345
346
        $fontStr .= '<div class="btn-group">'
347 1
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. \XoopsLocale::FONT .'"'
348 1
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
349 1
            . '<span class = "glyphicon glyphicon-font"></span><span class="caret"></span></button>'
350 1
            . '<ul class="dropdown-menu">';
351
        //. _FONT . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
352 1
        foreach ($fontarray as $font) {
353 1
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'font\', \'' . $font . '\', \''
354 1
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $font . '</a></li>';
355
        }
356 1
        $fontStr .= '</ul></div>';
357
358
        $fontStr .= '<div class="btn-group">'
359 1
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. \XoopsLocale::COLOR .'"'
360 1
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
361 1
            . '<span class = "glyphicon glyphicon-text-color"></span><span class="caret"></span></button>'
362 1
            . '<ul class="dropdown-menu">';
363
        //. _COLOR . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
364 1
        foreach ($colorArray as $color => $hex) {
365 1
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'color\', \'' . $hex . '\', \''
366 1
                . $textarea_id . '\', \'' . $hiddentext . '\');">'
367 1
                . '<span style="color:#' . $hex . ';">' . $color .'</span></a></li>';
368
        }
369 1
        $fontStr .= '</ul></div>';
370 1
        $fontStr .= '</div>';
371
372
        //$styleStr = "<div class='row'><div class='col-md-12'>";
373 1
        $styleStr  = "<div class='btn-group' role='group'>";
374 1
        $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeBold(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . \XoopsLocale::BOLD . "' aria-label='Left Align'><span class='fa fa-bold' aria-hidden='true'></span></button>";
375 1
        $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeItalic(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . \XoopsLocale::ITALIC . "' aria-label='Left Align'><span class='fa fa-italic' aria-hidden='true'></span></button>";
376 1
        $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . \XoopsLocale::UNDERLINE . "' aria-label='Left Align'>" . '<span class="fa fa-underline"></span></button>';
377 1
        $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . \XoopsLocale::LINE_THROUGH . "' aria-label='Left Align'>" . '<span class="fa fa-strikethrough"></span></button>';
378 1
        $styleStr .= "</div>";
379
380 1
        $alignStr = "<div class='btn-group' role='group'>";
381 1
        $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeLeft(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . \XoopsLocale::LEFT . "' aria-label='Left Align'><span class='fa fa-align-left' aria-hidden='true'></span></button>";
382 1
        $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeCenter(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . \XoopsLocale::CENTER . "' aria-label='Left Align'><span class='fa fa-align-center' aria-hidden='true'></span></button>";
383 1
        $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeRight(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . \XoopsLocale::RIGHT . "' aria-label='Left Align'><span class='fa fa-align-right' aria-hidden='true'></span></button>";
384 1
        $alignStr .= "</div>";
385
386 1
        $fontStr .= "&nbsp;{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
387
388
        $fontStr .= "<button type='button' class='btn btn-default btn-sm' onclick=\"XoopsCheckLength('"
389 1
            . $this->getName() . "', '" . @$this->configs['maxlength'] . "', '"
390 1
            . \XoopsLocale::F_CURRENT_TEXT_LENGTH . "', '" . \XoopsLocale::MAXIMUM_LENGTH . "');\" title='"
391 1
            . \XoopsLocale::CHECK_TEXT_LENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>";
392 1
        $fontStr .= "</div></div>";
393
394 1
        return $fontStr;
395
    }
396
397
    /**
398
     * fontArray
399
     *
400
     * @return string
401
     */
402 1
    public function fontArray()
403
    {
404 1
        $textarea_id = $this->getName();
405 1
        $hiddentext = $this->hiddenText;
406
407 1
        $fontStr = "<script type=\"text/javascript\" language=\"JavaScript\">";
408 1
        $fontStr .= "var _editor_dialog = ''" . "+ '<select class=\"span2\" id=\'{$textarea_id}Size\' onchange=\'xoopsSetElementAttribute(\"size\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'";
409 1
        $fontStr .= "+ '<option value=\'SIZE\'>" . \XoopsLocale::SIZE . "</option>'";
410 1
        $localeFontSizes = \XoopsLocale::getFontSizes();
411 1
        foreach ($localeFontSizes as $_val => $_name) {
412 1
            $fontStr .= " + '<option value=\'{$_val}\'>{$_name}</option>'";
413
        }
414 1
        $fontStr .= " + '</select> '";
415 1
        $fontStr .= "+ '<select class=\"span2\" id=\'{$textarea_id}Font\' onchange=\'xoopsSetElementAttribute(\"font\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'";
416 1
        $fontStr .= "+ '<option value=\'FONT\'>" . \XoopsLocale::FONT . "</option>'";
417 1
        $localeFonts = \XoopsLocale::getFonts();
418 1
        $fontarray = !empty($localeFonts) ? $localeFonts :
419 1
            array("Arial", "Courier", "Georgia", "Helvetica", "Impact", "Verdana", "Haettenschweiler");
420 1
        foreach ($fontarray as $font) {
421 1
            $fontStr .= " + '<option value=\'{$font}\'>{$font}</option>'";
422
        }
423 1
        $fontStr .= " + '</select> '";
424 1
        $fontStr .= "+ '<select class=\"span2\" id=\'{$textarea_id}Color\' onchange=\'xoopsSetElementAttribute(\"color\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'";
425 1
        $fontStr .= "+ '<option value=\'COLOR\'>" . \XoopsLocale::COLOR . "</option>';";
426 1
        $fontStr .= "var _color_array = new Array('00', '33', '66', '99', 'CC', 'FF');
427
            for(var i = 0; i < _color_array.length; i ++) {
428
                for(var j = 0; j < _color_array.length; j ++) {
429
                    for(var k = 0; k < _color_array.length; k ++) {
430
                        var _color_ele = _color_array[i] + _color_array[j] + _color_array[k];
431
                        _editor_dialog += '<option value=\''+_color_ele+'\' style=\'background-color:#'+_color_ele+';color:#'+_color_ele+';\'>#'+_color_ele+'</option>';
432
                    }
433
                }
434
            }
435
            _editor_dialog += '</select>';";
436
437 1
        $fontStr .= "document.write(_editor_dialog); </script>";
438
439 1
        $styleStr = "<img src='" . \XoopsBaseConfig::get('url') . "/images/bold.gif' alt='" . \XoopsLocale::BOLD . "' title='" . \XoopsLocale::BOLD . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeBold(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
440 1
        $styleStr .= "<img src='" . \XoopsBaseConfig::get('url') . "/images/italic.gif' alt='" . \XoopsLocale::ITALIC . "' title='" . \XoopsLocale::ITALIC . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeItalic(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
441 1
        $styleStr .= "<img src='" . \XoopsBaseConfig::get('url') . "/images/underline.gif' alt='" . \XoopsLocale::UNDERLINE . "' title='" . \XoopsLocale::UNDERLINE . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");'/>&nbsp;";
442 1
        $styleStr .= "<img src='" . \XoopsBaseConfig::get('url') . "/images/linethrough.gif' alt='" . \XoopsLocale::LINE_THROUGH . "' title='" . \XoopsLocale::LINE_THROUGH . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
443
444 1
        $alignStr = "<img src='" . \XoopsBaseConfig::get('url') . "/images/alignleft.gif' alt='" . \XoopsLocale::LEFT . "' title='" . \XoopsLocale::LEFT . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeLeft(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
445 1
        $alignStr .= "<img src='" . \XoopsBaseConfig::get('url') . "/images/aligncenter.gif' alt='" . \XoopsLocale::CENTER . "' title='" . \XoopsLocale::CENTER . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeCenter(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
446 1
        $alignStr .= "<img src='" . \XoopsBaseConfig::get('url') . "/images/alignright.gif' alt='" . \XoopsLocale::RIGHT . "' title='" . \XoopsLocale::RIGHT . "' onmouseover='style.cursor=\"hand\"' onclick='xoopsMakeRight(\"{$hiddentext}\", \"{$textarea_id}\");' />&nbsp;";
447 1
        $fontStr = $fontStr . "<br />\n{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
448 1
        return $fontStr;
449
    }
450
451
    /**
452
     * renderValidationJS
453
     *
454
     * @return bool|string
455
     */
456 1
    public function renderValidationJS()
457
    {
458 1
        if ($this->htmlEditor && is_object($this->htmlEditor) && method_exists($this->htmlEditor, 'renderValidationJS')) {
459
            if (!isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) {
460
                return $this->htmlEditor->renderValidationJS();
461
            }
462
        }
463 1
        return parent::renderValidationJS();
464
    }
465
}
466