Test Failed
Push — master ( e4be3a...b73711 )
by Michael
10:46 queued 11s
created

XoopsFormRendererBootstrap4::renderFormSelect()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 24
rs 9.3554
c 1
b 0
f 0
cc 5
nc 6
nop 1
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
 * This program is distributed in the hope that it will be useful,
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
 */
10
11
/**
12
 * Bootstrap4 style form renderer
13
 *
14
 * @category  XoopsForm
15
 * @package   XoopsFormRendererBootstrap4
16
 * @author    Richard Griffith <[email protected]>
17
 * @copyright 2018 XOOPS Project (http://xoops.org)
18
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
19
 * @link      http://xoops.org
20
 */
21
class XoopsFormRendererBootstrap4 implements XoopsFormRendererInterface
22
{
23
24
    /**
25
     * Render support for XoopsFormButton
26
     *
27
     * @param XoopsFormButton $element form element
28
     *
29
     * @return string rendered form element
30
     */
31
    public function renderFormButton(XoopsFormButton $element)
32
    {
33
        return "<button type='" . $element->getType() . "' class='btn btn-primary' name='"
34
            . $element->getName() . "'  id='" . $element->getName() . "' title='" . $element->getValue() . "'" . $element->getExtra() . '>' . $element->getValue() . '</button>';
35
    }
36
37
    /**
38
     * Render support for XoopsFormButtonTray
39
     *
40
     * @param XoopsFormButtonTray $element form element
41
     *
42
     * @return string rendered form element
43
     */
44
    public function renderFormButtonTray(XoopsFormButtonTray $element)
45
    {
46
        $ret = '';
47
        if ($element->_showDelete) {
48
            $ret .= '<button type="submit" class="btn btn-danger mr-1" name="delete" id="delete" onclick="this.form.elements.op.value=\'delete\'">' . _DELETE
49
            . '</button>';
50
        }
51
        $ret .= '<button class="btn btn-danger mr-1" onClick="history.go(-1);return true;">'
52
            . _CANCEL . '</button>'
53
            . '<button type="reset" class="btn btn-warning mr-1" name="reset" id="reset">' . _RESET . '</button>'
54
            . '<button type="' . $element->getType() . '" class="btn btn-success" name="' . $element->getName()
55
            . '"  id="' . $element->getName() . '" ' . $element->getExtra()
56
            . '>' . $element->getValue() . '</button>';
57
58
        return $ret;
59
    }
60
61
    /**
62
     * Render support for XoopsFormCheckBox
63
     *
64
     * @param XoopsFormCheckBox $element form element
65
     *
66
     * @return string rendered form element
67
     */
68
    public function renderFormCheckBox(XoopsFormCheckBox $element)
69
    {
70
        $elementName = $element->getName();
71
        $elementId = $elementName;
72
        $elementOptions = $element->getOptions();
73
        if (count($elementOptions) > 1 && substr($elementName, -2, 2) !== '[]') {
74
            $elementName .= '[]';
75
            $element->setName($elementName);
76
        }
77
78
        switch ((int) ($element->columns)) {
79
            case 0:
80
                return $this->renderCheckedInline($element, 'checkbox', $elementId, $elementName);
81
            case 1:
82
                return $this->renderCheckedOneColumn($element, 'checkbox', $elementId, $elementName);
83
            default:
84
                return $this->renderCheckedColumnar($element, 'checkbox', $elementId, $elementName);
85
        }
86
    }
87
88
    /**
89
     * Render a inline checkbox or radio element
90
     *
91
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
92
     * @param string                           $type    'checkbox' or 'radio;
93
     * @param string                           $elementId   input 'id' attribute of element
94
     * @param string                           $elementName input 'name' attribute of element
95
     * @return string
96
     */
97
    protected function renderCheckedInline($element, $type, $elementId, $elementName)
98
    {
99
        $class = $type . '-inline';
0 ignored issues
show
Unused Code introduced by
The assignment to $class is dead and can be removed.
Loading history...
100
        $ret = '';
101
102
        $idSuffix = 0;
103
        $elementValue = $element->getValue();
104
        $elementOptions = $element->getOptions();
105
        foreach ($elementOptions as $value => $name) {
106
            ++$idSuffix;
107
108
            $ret .= '<div class="form-check form-check-inline  m-2">';
109
            $ret .= "<input class='form-check-input' type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
110
                . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
111
                . htmlspecialchars($value, ENT_QUOTES) . "'";
112
113
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
114
                $ret .= ' checked';
115
            }
116
            $ret .= $element->getExtra() . '>';
117
            $ret .= '<label class="form-check-label" for="'.$elementId.$idSuffix.'">' . $name . $element->getDelimeter().'</label>';
118
            $ret .= '</div>';
119
        }
120
121
        return $ret;
122
    }
123
124
    /**
125
     * Render a single column checkbox or radio element
126
     *
127
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
128
     * @param string                           $type    'checkbox' or 'radio;
129
     * @param string                           $elementId   input 'id' attribute of element
130
     * @param string                           $elementName input 'name' attribute of element
131
     * @return string
132
     */
133
    protected function renderCheckedOneColumn($element, $type, $elementId, $elementName)
134
    {
135
        $class = $type;
136
        $ret = '';
137
138
        $idSuffix = 0;
139
        $elementValue = $element->getValue();
140
        $elementOptions = $element->getOptions();
141
        foreach ($elementOptions as $value => $name) {
142
            ++$idSuffix;
143
            $ret .= '<div class="' . $class . '">';
144
            $ret .= '<label>';
145
            $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
146
                . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
147
                . htmlspecialchars($value, ENT_QUOTES) . "'";
148
149
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
150
                $ret .= ' checked';
151
            }
152
            $ret .= $element->getExtra() . '>' . $name . $element->getDelimeter();
153
            $ret .= '</label>';
154
            $ret .= '</div>';
155
        }
156
157
        return $ret;
158
    }
159
160
    /**
161
     * Render a multicolumn checkbox or radio element
162
     *
163
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
164
     * @param string                           $type    'checkbox' or 'radio;
165
     * @param string                           $elementId   input 'id' attribute of element
166
     * @param string                           $elementName input 'name' attribute of element
167
     * @return string
168
     */
169
    protected function renderCheckedColumnar($element, $type, $elementId, $elementName)
170
    {
171
        $class = $type;
0 ignored issues
show
Unused Code introduced by
The assignment to $class is dead and can be removed.
Loading history...
172
        $ret = '';
173
174
        $idSuffix = 0;
175
        $elementValue = $element->getValue();
176
        $elementOptions = $element->getOptions();
177
        foreach ($elementOptions as $value => $name) {
178
            ++$idSuffix;
179
180
            $ret .= '<div class="form-check m-2">';
181
            $ret .= "<input class='form-check-input' type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
182
                . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
183
                . htmlspecialchars($value, ENT_QUOTES) . "'";
184
185
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
186
                $ret .= ' checked';
187
            }
188
            $ret .= $element->getExtra() . '>';
189
            $ret .= '<label class="form-check-label" for="'.$elementId.$idSuffix.'">'. $name . $element->getDelimeter().'</label>';
190
            $ret .= '</div>';
191
        }
192
193
        return $ret;
194
    }
195
    /**
196
     * Render support for XoopsFormColorPicker
197
     *
198
     * @param XoopsFormColorPicker $element form element
199
     *
200
     * @return string rendered form element
201
     */
202
    public function renderFormColorPicker(XoopsFormColorPicker $element)
203
    {
204
        if (isset($GLOBALS['xoTheme'])) {
205
            $GLOBALS['xoTheme']->addScript('include/spectrum.js');
206
            $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css');
207
        } else {
208
            echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>';
209
            echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">';
210
        }
211
        return '<input class="form-control" style="width: 25%;" type="color" name="' . $element->getName()
212
            . "' title='" . $element->getTitle() . "' id='" . $element->getName()
213
            . '" size="7" maxlength="7" value="' . $element->getValue() . '"' . $element->getExtra() . '>';
214
    }
215
216
    /**
217
     * Render support for XoopsFormDhtmlTextArea
218
     *
219
     * @param XoopsFormDhtmlTextArea $element form element
220
     *
221
     * @return string rendered form element
222
     */
223
    public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element)
224
    {
225
        static $js_loaded;
226
227
        xoops_loadLanguage('formdhtmltextarea');
228
        $ret = '';
229
        // actions
230
        $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n";
231
        // fonts
232
        $ret .= $this->renderFormDhtmlTATypography($element);
233
        // length checker
234
235
        $ret .= "<br>\n";
236
        // the textarea box
237
        $ret .= "<textarea class='form-control' id='" . $element->getName() . "' name='" . $element->getName()
238
            . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName()
239
            . "');\" onclick=\"xoopsSavePosition('" . $element->getName()
240
            . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='"
241
            . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra()
242
            . '>' . $element->getValue() . "</textarea>\n";
243
244
        if (empty($element->skipPreview)) {
245
            if (empty($GLOBALS['xoTheme'])) {
246
                $element->js .= implode('', file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
0 ignored issues
show
Bug introduced by
It seems like file(XOOPS_ROOT_PATH . '...itizer/image/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

246
                $element->js .= implode('', /** @scrutinizer ignore-type */ file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
Loading history...
247
            } else {
248
                $GLOBALS['xoTheme']->addScript(
249
                    '/class/textsanitizer/image/image.js',
250
                    array('type' => 'text/javascript')
251
                );
252
            }
253
            $button = "<button type='button' class='btn btn-primary' onclick=\"form_instantPreview('" . XOOPS_URL
254
                . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)$element->doHtml . ", '"
255
                . $GLOBALS['xoopsSecurity']->createToken() . "')\" title='" . _PREVIEW . "'>" . _PREVIEW . "</button>";
256
257
            $ret .= '<br>' . "<div id='" . $element->getName() . "_hidden' style='display: block;'> "
258
                . '   <fieldset>' . '       <legend>' . $button . '</legend>'
259
                . "       <div id='" . $element->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT
260
                . '</div>' . '   </fieldset>' . '</div>';
261
        }
262
        // Load javascript
263
        if (empty($js_loaded)) {
264
            $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '')
265
                . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
266
            $ret        = $javascript . $ret;
267
            $js_loaded  = true;
268
        }
269
270
        return $ret;
271
    }
272
273
    /**
274
     * Render xoopscode buttons for editor, include calling text sanitizer extensions
275
     *
276
     * @param XoopsFormDhtmlTextArea $element form element
277
     *
278
     * @return string rendered buttons for xoopscode assistance
279
     */
280
    protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element)
281
    {
282
        $textarea_id = $element->getName();
283
        $code = '';
284
        $code .= "<div class='row'><div class='col-lg-12'>";
285
        $code .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsCodeUrl(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_URL . "'><span class='fa fa-fw fa-link' aria-hidden='true'></span></button>";
286
        $code .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsCodeEmail(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_EMAIL . "'><span class='fa fa-fw fa-envelope-o' aria-hidden='true'></span></button>";
287
        $code .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsCodeImg(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_IMG . "'><span class='fa fa-fw fa-file-image-o' aria-hidden='true'></span></button>";
288
        $code .= "<button type='button' class='btn btn-secondary btn-sm' onclick='openWithSelfMain(\"" . XOOPS_URL . "/imagemanager.php?target={$textarea_id}\",\"imgmanager\",400,430);' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_IMAGE . "'><span class='fa fa-file-image-o' aria-hidden='true'></span><small> Manager</small></button>";
289
        $code .= "<button type='button' class='btn btn-secondary btn-sm' onclick='openWithSelfMain(\"" . XOOPS_URL . "/misc.php?action=showpopups&amp;type=smilies&amp;target={$textarea_id}\",\"smilies\",300,475);' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_SMILEY . "'><span class='fa fa-fw fa-smile-o' aria-hidden='true'></span></button>";
290
291
        $myts = MyTextSanitizer::getInstance();
292
293
        $extensions = array_filter($myts->config['extensions']);
294
        foreach (array_keys($extensions) as $key) {
295
            $extension = $myts->loadExtension($key);
296
            @list($encode, $js) = $extension->encode($textarea_id);
297
            if (empty($encode)) {
298
                continue;
299
            }
300
            $code .= $encode;
301
            if (!empty($js)) {
302
                $element->js .= $js;
303
            }
304
        }
305
        $code .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsCodeCode(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERCODE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_CODE . "'><span class='fa fa-fw fa-code' aria-hidden='true'></span></button>";
306
        $code .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsCodeQuote(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_QUOTE . "'><span class='fa fa-fw fa-quote-right' aria-hidden='true'></span></button>";
307
        $code .= "</div></div>";
308
309
        $xoopsPreload = XoopsPreload::getInstance();
310
        $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
311
312
        return $code;
313
    }
314
315
    /**
316
     * Render typography controls for editor (font, size, color)
317
     *
318
     * @param XoopsFormDhtmlTextArea $element form element
319
     *
320
     * @return string rendered typography controls
321
     */
322
    protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element)
323
    {
324
        $textarea_id = $element->getName();
325
        $hiddentext  = $element->_hiddenText;
326
327
        $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array(
328
            'Arial',
329
            'Courier',
330
            'Georgia',
331
            'Helvetica',
332
            'Impact',
333
            'Verdana',
334
            'Haettenschweiler');
335
336
        $colorArray = array(
337
            'Black'  => '000000',
338
            'Blue'   => '38AAFF',
339
            'Brown'  => '987857',
340
            'Green'  => '79D271',
341
            'Grey'   => '888888',
342
            'Orange' => 'FFA700',
343
            'Paper'  => 'E0E0E0',
344
            'Purple' => '363E98',
345
            'Red'    => 'FF211E',
346
            'White'  => 'FEFEFE',
347
            'Yellow' => 'FFD628',
348
        );
349
350
        $fontStr = '<div class="row"><div class="col-lg-12"><div class="btn-group" role="toolbar">';
351
        $fontStr .= '<div class="btn-group">'
352
            . '<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" title="'. _SIZE .'"'
353
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
354
            . '<span class = "glyphicon glyphicon-text-height"></span><span class="caret"></span></button>'
355
            . '<ul class="dropdown-menu">';
356
            //. _SIZE . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
357
        foreach ($GLOBALS['formtextdhtml_sizes'] as $value => $name) {
358
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'size\', \'' . $value . '\', \''
359
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $name . '</a></li>';
360
        }
361
        $fontStr .= '</ul></div>';
362
363
        $fontStr .= '<div class="btn-group">'
364
            . '<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" title="'. _FONT .'"'
365
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
366
            . '<span class = "glyphicon glyphicon-font"></span><span class="caret"></span></button>'
367
            . '<ul class="dropdown-menu">';
368
            //. _FONT . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
369
        foreach ($fontarray as $font) {
370
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'font\', \'' . $font . '\', \''
371
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $font . '</a></li>';
372
        }
373
        $fontStr .= '</ul></div>';
374
375
        $fontStr .= '<div class="btn-group">'
376
            . '<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" title="'. _COLOR .'"'
377
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
378
            . '<span class = "glyphicon glyphicon-text-color"></span><span class="caret"></span></button>'
379
            . '<ul class="dropdown-menu">';
380
            //. _COLOR . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
381
        foreach ($colorArray as $color => $hex) {
382
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'color\', \'' . $hex . '\', \''
383
                . $textarea_id . '\', \'' . $hiddentext . '\');">'
384
                . '<span style="color:#' . $hex . ';">' . $color .'</span></a></li>';
385
        }
386
        $fontStr .= '</ul></div>';
387
        $fontStr .= '</div>';
388
389
        //$styleStr = "<div class='row'><div class='col-lg-12'>";
390
        $styleStr  = "<div class='btn-group' role='group'>";
391
        $styleStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsMakeBold(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_BOLD . "' aria-label='Left Align'><span class='fa fa-bold' aria-hidden='true'></span></button>";
392
        $styleStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsMakeItalic(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_ITALIC . "' aria-label='Left Align'><span class='fa fa-italic' aria-hidden='true'></span></button>";
393
        $styleStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_UNDERLINE . "' aria-label='Left Align'>" . '<span class="fa fa-underline"></span></button>';
394
        $styleStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LINETHROUGH . "' aria-label='Left Align'>" . '<span class="fa fa-strikethrough"></span></button>';
395
        $styleStr .= "</div>";
396
397
        $alignStr = "<div class='btn-group' role='group'>";
398
        $alignStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsMakeLeft(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LEFT . "' aria-label='Left Align'><span class='fa fa-align-left' aria-hidden='true'></span></button>";
399
        $alignStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsMakeCenter(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_CENTER . "' aria-label='Left Align'><span class='fa fa-align-center' aria-hidden='true'></span></button>";
400
        $alignStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick='xoopsMakeRight(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_RIGHT . "' aria-label='Left Align'><span class='fa fa-align-right' aria-hidden='true'></span></button>";
401
        $alignStr .= "</div>";
402
403
        $fontStr .= "&nbsp;{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
404
405
        $fontStr .= "<button type='button' class='btn btn-secondary btn-sm' onclick=\"XoopsCheckLength('"
406
            . $element->getName() . "', '" . @$element->configs['maxlength'] . "', '"
0 ignored issues
show
Bug introduced by
The property configs does not seem to exist on XoopsFormDhtmlTextArea.
Loading history...
407
            . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='"
408
            . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>";
409
        $fontStr .= "</div></div>";
410
411
        return $fontStr;
412
    }
413
414
    /**
415
     * Render support for XoopsFormElementTray
416
     *
417
     * @param XoopsFormElementTray $element form element
418
     *
419
     * @return string rendered form element
420
     */
421
    public function renderFormElementTray(XoopsFormElementTray $element)
422
    {
423
        $count = 0;
424
        $ret = '<span class="form-inline">';
425
        foreach ($element->getElements() as $ele) {
426
            if ($count > 0) {
427
                $ret .= $element->getDelimeter();
428
            }
429
            if ($ele->getCaption() != '') {
430
                $ret .= $ele->getCaption() . '&nbsp;';
431
            }
432
            $ret .= $ele->render() . NWLINE;
0 ignored issues
show
Bug introduced by
Are you sure the usage of $ele->render() targeting XoopsFormElement::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
433
            if (!$ele->isHidden()) {
434
                ++$count;
435
            }
436
        }
437
        /*
438
        if (substr_count($ret, '<div class="form-group form-inline">') > 0) {
439
            $ret = str_replace('<div class="form-group form-inline">', '', $ret);
440
            $ret = str_replace('</div>', '', $ret);
441
        }
442
        if (substr_count($ret, '<div class="checkbox-inline">') > 0) {
443
            $ret = str_replace('<div class="checkbox-inline">', '', $ret);
444
        }
445
        */
446
        $ret .= '</span>';
447
        return $ret;
448
    }
449
450
    /**
451
     * Render support for XoopsFormFile
452
     *
453
     * @param XoopsFormFile $element form element
454
     *
455
     * @return string rendered form element
456
     */
457
    public function renderFormFile(XoopsFormFile $element)
458
    {
459
460
        return '<input type="file" class="form-control"  name="' . $element->getName()
461
        . '" id="' . $element->getName()
462
        . '" title="' . $element->getTitle() . '" ' . $element->getExtra() . '>'
463
            . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '">'
464
            . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="'
465
            . $element->getName() . '">';
466
    }
467
468
    /**
469
     * Render support for XoopsFormLabel
470
     *
471
     * @param XoopsFormLabel $element form element
472
     *
473
     * @return string rendered form element
474
     */
475
    public function renderFormLabel(XoopsFormLabel $element)
476
    {
477
        return '<div class="form-control-static">' . $element->getValue() . '</div>';
478
    }
479
480
    /**
481
     * Render support for XoopsFormPassword
482
     *
483
     * @param XoopsFormPassword $element form element
484
     *
485
     * @return string rendered form element
486
     */
487
    public function renderFormPassword(XoopsFormPassword $element)
488
    {
489
        return '<input class="form-control" type="password" name="'
490
            . $element->getName() . '" id="' . $element->getName() . '" size="' . $element->getSize()
491
            . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue() . '"'
492
            . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>';
493
    }
494
495
    /**
496
     * Render support for XoopsFormRadio
497
     *
498
     * @param XoopsFormRadio $element form element
499
     *
500
     * @return string rendered form element
501
     */
502
    public function renderFormRadio(XoopsFormRadio $element)
503
    {
504
505
        $elementName = $element->getName();
506
        $elementId = $elementName;
507
508
        switch ((int) ($element->columns)) {
509
            case 0:
510
                return $this->renderCheckedInline($element, 'radio', $elementId, $elementName);
511
            case 1:
512
                return $this->renderCheckedOneColumn($element, 'radio', $elementId, $elementName);
513
            default:
514
                return $this->renderCheckedColumnar($element, 'radio', $elementId, $elementName);
515
        }
516
    }
517
518
    /**
519
     * Render support for XoopsFormSelect
520
     *
521
     * @param XoopsFormSelect $element form element
522
     *
523
     * @return string rendered form element
524
     */
525
    public function renderFormSelect(XoopsFormSelect $element)
526
    {
527
        $ele_name    = $element->getName();
528
        $ele_title   = $element->getTitle();
529
        $ele_value   = $element->getValue();
530
        $ele_options = $element->getOptions();
531
        $ret = '<select class="form-control" size="'
532
            . $element->getSize() . '"' . $element->getExtra();
533
        if ($element->isMultiple() != false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
534
            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title
535
                . '" multiple="multiple">';
536
        } else {
537
            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
538
        }
539
        foreach ($ele_options as $value => $name) {
540
            $ret .= '<option value="' . htmlspecialchars($value, ENT_QUOTES) . '"';
541
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
542
                $ret .= ' selected';
543
            }
544
            $ret .= '>' . $name . '</option>';
545
        }
546
        $ret .= '</select>';
547
548
        return $ret;
549
    }
550
    /**
551
     * Render support for XoopsFormText
552
     *
553
     * @param XoopsFormText $element form element
554
     *
555
     * @return string rendered form element
556
     */
557
    public function renderFormText(XoopsFormText $element)
558
    {
559
        return "<input class='form-control' type='text' name='"
560
            . $element->getName() . "' title='" . $element->getTitle() . "' id='" . $element->getName()
561
            . "' size='" . $element->getSize() . "' maxlength='" . $element->getMaxlength()
562
            . "' value='" . $element->getValue() . "'" . $element->getExtra() . '>';
563
    }
564
565
    /**
566
     * Render support for XoopsFormTextArea
567
     *
568
     * @param XoopsFormTextArea $element form element
569
     *
570
     * @return string rendered form element
571
     */
572
    public function renderFormTextArea(XoopsFormTextArea $element)
573
    {
574
        return "<textarea class='form-control' name='"
575
            . $element->getName() . "' id='" . $element->getName() . "'  title='" . $element->getTitle()
576
            . "' rows='" . $element->getRows() . "' cols='" . $element->getCols() . "'"
577
            . $element->getExtra() . '>' . $element->getValue() . '</textarea>';
578
    }
579
580
    /**
581
     * Render support for XoopsFormTextDateSelect
582
     *
583
     * @param XoopsFormTextDateSelect $element form element
584
     *
585
     * @return string rendered form element
586
     */
587
    public function renderFormTextDateSelect(XoopsFormTextDateSelect $element)
588
    {
589
        static $included = false;
590
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) {
591
            include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php';
592
        } else {
593
            include_once XOOPS_ROOT_PATH . '/language/english/calendar.php';
594
        }
595
596
        $ele_name  = $element->getName();
597
        $ele_value = $element->getValue(false);
598
        if (is_string($ele_value)) {
0 ignored issues
show
introduced by
The condition is_string($ele_value) is always true.
Loading history...
599
            $display_value = $ele_value;
600
            $ele_value     = time();
601
        } else {
602
            $display_value = date(_SHORTDATESTRING, $ele_value);
603
        }
604
605
        $jstime = formatTimestamp($ele_value, _SHORTDATESTRING);
606
        if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) {
607
            $GLOBALS['xoTheme']->addScript('include/calendar.js');
608
            $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css');
609
            if (!$included) {
610
                $included = true;
611
                $GLOBALS['xoTheme']->addScript('', '', '
612
                    var calendar = null;
613
614
                    function selected(cal, date)
615
                    {
616
                    cal.sel.value = date;
617
                    }
618
619
                    function closeHandler(cal)
620
                    {
621
                    cal.hide();
622
                    Calendar.removeEvent(document, "mousedown", checkCalendar);
623
                    }
624
625
                    function checkCalendar(ev)
626
                    {
627
                    var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
628
                    for (; el != null; el = el.parentNode)
629
                    if (el == calendar.element || el.tagName == "A") break;
630
                    if (el == null) {
631
                    calendar.callCloseHandler(); Calendar.stopEvent(ev);
632
                    }
633
                    }
634
                    function showCalendar(id)
635
                    {
636
                    var el = xoopsGetElementById(id);
637
                    if (calendar != null) {
638
                    calendar.hide();
639
                    } else {
640
                    var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler);
641
                    calendar = cal;
642
                    cal.setRange(1900, 2100);
643
                    calendar.create();
644
                    }
645
                    calendar.sel = el;
646
                    calendar.parseDate(el.value);
647
                    calendar.showAtElement(el);
648
                    Calendar.addEvent(document, "mousedown", checkCalendar);
649
650
                    return false;
651
                    }
652
653
                    Calendar._DN = new Array
654
                    ("' . _CAL_SUNDAY . '",
655
                    "' . _CAL_MONDAY . '",
656
                    "' . _CAL_TUESDAY . '",
657
                    "' . _CAL_WEDNESDAY . '",
658
                    "' . _CAL_THURSDAY . '",
659
                    "' . _CAL_FRIDAY . '",
660
                    "' . _CAL_SATURDAY . '",
661
                    "' . _CAL_SUNDAY . '");
662
                    Calendar._MN = new Array
663
                    ("' . _CAL_JANUARY . '",
664
                    "' . _CAL_FEBRUARY . '",
665
                    "' . _CAL_MARCH . '",
666
                    "' . _CAL_APRIL . '",
667
                    "' . _CAL_MAY . '",
668
                    "' . _CAL_JUNE . '",
669
                    "' . _CAL_JULY . '",
670
                    "' . _CAL_AUGUST . '",
671
                    "' . _CAL_SEPTEMBER . '",
672
                    "' . _CAL_OCTOBER . '",
673
                    "' . _CAL_NOVEMBER . '",
674
                    "' . _CAL_DECEMBER . '");
675
676
                    Calendar._TT = {};
677
                    Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '";
678
                    Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '";
679
                    Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '";
680
                    Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '";
681
                    Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '";
682
                    Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '";
683
                    Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '";
684
                    Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '";
685
                    Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')";
686
                    Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '";
687
                    Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '";
688
                    Calendar._TT["CLOSE"] = "' . _CLOSE . '";
689
                    Calendar._TT["TODAY"] = "' . _CAL_TODAY . '";
690
691
                    // date formats
692
                    Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
693
                    Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
694
695
                    Calendar._TT["WK"] = "";
696
                ');
697
            }
698
        }
699
        return '<div class="input-group">'
700
            . '<input class="form-control" type="text" name="' . $ele_name . '" id="' . $ele_name
701
            . '" size="' . $element->getSize() . '" maxlength="' . $element->getMaxlength()
702
            . '" value="' . $display_value . '"' . $element->getExtra() . '>'
703
            . '<span class="input-group-btn"><button class="btn btn-secondary" type="button"'
704
            . ' onclick="return showCalendar(\'' . $ele_name . '\');">'
705
            . '<span class="fa fa-calendar" aria-hidden="true"></span></button>'
706
            . '</span>'
707
            . '</div>';
708
    }
709
710
    /**
711
     * Render support for XoopsThemeForm
712
     *
713
     * @param XoopsThemeForm $form form to render
714
     *
715
     * @return string rendered form
716
     */
717
    public function renderThemeForm(XoopsThemeForm $form)
718
    {
719
        $ele_name = $form->getName();
720
721
        $ret = '<div>';
722
        $ret .= '<form name="' . $ele_name . '" id="' . $ele_name . '" action="'
723
            . $form->getAction() . '" method="' . $form->getMethod()
724
            . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>'
725
            . '<h3>' . $form->getTitle() . '</h3>';
726
        $hidden   = '';
727
728
        foreach ($form->getElements() as $element) {
729
            if (!is_object($element)) { // see $form->addBreak()
730
                $ret .= $element;
731
                continue;
732
            }
733
            if ($element->isHidden()) {
734
                $hidden .= $element->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $element->render() targeting XoopsFormElement::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
735
                continue;
736
            }
737
738
            $ret .= '<div class="form-group row">';
739
            if (($caption = $element->getCaption()) != '') {
0 ignored issues
show
Unused Code introduced by
The assignment to $caption is dead and can be removed.
Loading history...
740
                $ret .= '<label for="' . $element->getName() . '" class="col-lg-2 col-form-label text-sm-right">'
741
                    . $element->getCaption()
742
                    . ($element->isRequired() ? '<span class="caption-required">*</span>' : '')
743
                    . '</label>';
744
            } else {
745
                $ret .= '<div class="col-lg-2"> </div>';
746
            }
747
            $ret .= '<div class="col-lg-10">';
748
            $ret .= $element->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $element->render() targeting XoopsFormElement::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
749
            if (($desc = $element->getDescription()) != '') {
750
                $ret .= '<p class="form-text text-muted">' . $desc . '</p>';
751
            }
752
            $ret .= '</div>';
753
            $ret .= '</div>';
754
        }
755
        $ret .= $hidden;
756
        $ret .= '</form></div>';
757
        $ret .= $form->renderValidationJS(true);
758
759
        return $ret;
760
    }
761
762
    /**
763
     * Support for themed addBreak
764
     *
765
     * @param XoopsThemeForm $form
766
     * @param string         $extra pre-rendered content for break row
767
     * @param string         $class class for row
768
     *
769
     * @return void
770
     */
771
    public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class)
772
    {
773
        $class = ($class != '') ? preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) : '';
774
        $form->addElement('<div class="col-md-12 ' . $class .'">'. $extra . '</div>');
775
    }
776
}
777