XoopsFormRendererBootstrap3::renderFormCheckBox()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 17
rs 9.5222
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
 * Bootstrap3 style form renderer
13
 *
14
 * @category  XoopsForm
15
 * @package   XoopsFormRendererBootstrap3
16
 * @author    Richard Griffith <[email protected]>
17
 * @copyright 2017-2021 XOOPS Project (https://xoops.org)
18
 * @license   GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 */
20
class XoopsFormRendererBootstrap3 implements XoopsFormRendererInterface
21
{
22
23
    /**
24
     * Render support for XoopsFormButton
25
     *
26
     * @param XoopsFormButton $element form element
27
     *
28
     * @return string rendered form element
29
     */
30
    public function renderFormButton(XoopsFormButton $element)
31
    {
32
        return "<input type='" . $element->getType() . "' class='btn btn-default' name='"
33
            . $element->getName() . "'  id='" . $element->getName() . "' value='" . $element->getValue()
34
            . "' title='" . $element->getValue() . "'" . $element->getExtra() . ' />';
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 .= '<input type="submit" class="btn btn-danger" name="delete" id="delete" value="' . _DELETE
49
                . '" onclick="this.form.elements.op.value=\'delete\'">&nbsp;';
50
        }
51
        $ret .= '<input type="button" class="btn btn-danger" value="' . _CANCEL
52
             . '" onClick="history.go(-1);return true;" />&nbsp;'
53
             . '<input type="reset" class="btn btn-warning"  name="reset"  id="reset" value="' . _RESET . '" />&nbsp;'
54
             . '<input type="' . $element->getType() . '" class="btn btn-success"  name="' . $element->getName()
55
             . '"  id="' . $element->getName() . '" value="' . $element->getValue() . '"' . $element->getExtra()
56
             . '  />';
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';
100
        $ret = '';
101
102
        $idSuffix = 0;
103
        $elementValue = $element->getValue();
104
        $elementOptions = $element->getOptions();
105
        foreach ($elementOptions as $value => $name) {
106
            ++$idSuffix;
107
            $ret .= '<label class="' . $class . '">';
108
            $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
109
                . htmlspecialchars(strip_tags($name), ENT_QUOTES | ENT_HTML5) . "' value='"
110
                . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . "'";
111
112
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
113
                $ret .= ' checked';
114
            }
115
            $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
116
            $ret .= '</label>';
117
        }
118
119
        return $ret;
120
    }
121
122
    /**
123
     * Render a single column checkbox or radio element
124
     *
125
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
126
     * @param string                           $type    'checkbox' or 'radio;
127
     * @param string                           $elementId   input 'id' attribute of element
128
     * @param string                           $elementName input 'name' attribute of element
129
     * @return string
130
     */
131
    protected function renderCheckedOneColumn($element, $type, $elementId, $elementName)
132
    {
133
        $class = $type;
134
        $ret = '';
135
136
        $idSuffix = 0;
137
        $elementValue = $element->getValue();
138
        $elementOptions = $element->getOptions();
139
        foreach ($elementOptions as $value => $name) {
140
            ++$idSuffix;
141
            $ret .= '<div class="' . $class . '">';
142
            $ret .= '<label>';
143
            $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
144
                . htmlspecialchars(strip_tags($name), ENT_QUOTES | ENT_HTML5) . "' value='"
145
                . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . "'";
146
147
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
148
                $ret .= ' checked';
149
            }
150
            $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
151
            $ret .= '</label>';
152
            $ret .= '</div>';
153
        }
154
155
        return $ret;
156
    }
157
158
    /**
159
     * Render a multicolumn checkbox or radio element
160
     *
161
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
162
     * @param string                           $type    'checkbox' or 'radio;
163
     * @param string                           $elementId   input 'id' attribute of element
164
     * @param string                           $elementName input 'name' attribute of element
165
     * @return string
166
     */
167
    protected function renderCheckedColumnar($element, $type, $elementId, $elementName)
168
    {
169
        $class = $type;
170
        $ret = '';
171
172
        $idSuffix = 0;
173
        $elementValue = $element->getValue();
174
        $elementOptions = $element->getOptions();
175
        foreach ($elementOptions as $value => $name) {
176
            ++$idSuffix;
177
            $ret .= '<div class="' . $class . ' col-md-2">';
178
            $ret .= '<label>';
179
            $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
180
                . htmlspecialchars(strip_tags($name), ENT_QUOTES | ENT_HTML5) . "' value='"
181
                . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . "'";
182
183
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
184
                $ret .= ' checked';
185
            }
186
            $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
187
            $ret .= '</label>';
188
            $ret .= '</div>';
189
        }
190
191
        return $ret;
192
    }
193
    /**
194
     * Render support for XoopsFormColorPicker
195
     *
196
     * @param XoopsFormColorPicker $element form element
197
     *
198
     * @return string rendered form element
199
     */
200
    public function renderFormColorPicker(XoopsFormColorPicker $element)
201
    {
202
        if (isset($GLOBALS['xoTheme'])) {
203
            $GLOBALS['xoTheme']->addScript('include/spectrum.js');
204
            $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css');
205
        } else {
206
            echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>';
207
            echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">';
208
        }
209
        return '<input class="form-control" style="width: 25%;" type="color" name="' . $element->getName()
210
            . "' title='" . $element->getTitle() . "' id='" . $element->getName()
211
            . '" size="7" maxlength="7" value="' . $element->getValue() . '"' . $element->getExtra() . ' />';
212
    }
213
214
    /**
215
     * Render support for XoopsFormDhtmlTextArea
216
     *
217
     * @param XoopsFormDhtmlTextArea $element form element
218
     *
219
     * @return string rendered form element
220
     */
221
    public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element)
222
    {
223
        xoops_loadLanguage('formdhtmltextarea');
224
        $ret = '';
225
        // actions
226
        $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n";
227
        // fonts
228
        $ret .= $this->renderFormDhtmlTATypography($element);
229
        // length checker
230
231
        $ret .= "<br>\n";
232
        // the textarea box
233
        $ret .= "<textarea class='form-control' id='" . $element->getName() . "' name='" . $element->getName()
234
            . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName()
235
            . "');\" onclick=\"xoopsSavePosition('" . $element->getName()
236
            . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='"
237
            . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra()
238
            . '>' . $element->getValue() . "</textarea>\n";
239
240
        if (empty($element->skipPreview)) {
241
            if (empty($GLOBALS['xoTheme'])) {
242
                $element->js .= implode('', file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
243
            } else {
244
                $GLOBALS['xoTheme']->addScript(
245
                    '/class/textsanitizer/image/image.js',
246
                    array('type' => 'text/javascript')
247
                );
248
            }
249
            $button = "<button type='button' class='btn btn-primary' onclick=\"form_instantPreview('" . XOOPS_URL
250
                . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)$element->doHtml . ", '"
251
                . $GLOBALS['xoopsSecurity']->createToken() . "')\" title='" . _PREVIEW . "'>" . _PREVIEW . "</button>";
252
253
            $ret .= '<br>' . "<div id='" . $element->getName() . "_hidden' style='display: block;'> "
254
                . '   <fieldset>' . '       <legend>' . $button . '</legend>'
255
                . "       <div id='" . $element->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT
256
                . '</div>' . '   </fieldset>' . '</div>';
257
        }
258
        // Load javascript
259
        $javascript_file = XOOPS_URL . '/include/formdhtmltextarea.js';
260
        $javascript_file_element = 'include_formdhtmltextarea_js';
261
        $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '');
262
        $javascript .= <<<EOJS
263
<script>
264
    var el = document.getElementById('{$javascript_file_element}');
265
    if (el === null) {
266
        var xformtag = document.createElement('script');
267
        xformtag.id = '{$javascript_file_element}';
268
        xformtag.type = 'text/javascript';
269
        xformtag.src = '{$javascript_file}';
270
        document.body.appendChild(xformtag);
271
    }
272
</script>
273
EOJS;
274
275
        return $javascript . $ret;
276
    }
277
278
    /**
279
     * Render xoopscode buttons for editor, include calling text sanitizer extensions
280
     *
281
     * @param XoopsFormDhtmlTextArea $element form element
282
     *
283
     * @return string rendered buttons for xoopscode assistance
284
     */
285
    protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element)
286
    {
287
        $textarea_id = $element->getName();
288
        $code = '';
289
        $code .= "<div class='row'><div class='col-md-12'>";
290
        $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeUrl(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERURL, ENT_QUOTES | ENT_HTML5) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES | ENT_HTML5) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_URL . "'><span class='fa fa-fw fa-link' aria-hidden='true'></span></button>";
291
        $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeEmail(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES | ENT_HTML5) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES | ENT_HTML5) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_EMAIL . "'><span class='fa fa-fw fa-envelope-o' aria-hidden='true'></span></button>";
292
        $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeImg(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES | ENT_HTML5) . "\", \"" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES | ENT_HTML5) . "\", \"" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES | ENT_HTML5) . "\", \"" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES | ENT_HTML5) . "\", \"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES | ENT_HTML5) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_IMG . "'><span class='fa fa-fw fa-file-image-o' aria-hidden='true'></span></button>";
293
        $code .= "<button type='button' class='btn btn-default 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>";
294
        $code .= "<button type='button' class='btn btn-default 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>";
295
296
        $myts = \MyTextSanitizer::getInstance();
297
298
        $extensions = array_filter($myts->config['extensions']);
299
        foreach (array_keys($extensions) as $key) {
300
            $extension = $myts->loadExtension($key);
301
            @list($encode, $js) = $extension->encode($textarea_id);
302
            if (empty($encode)) {
303
                continue;
304
            }
305
            $code .= $encode;
306
            if (!empty($js)) {
307
                $element->js .= $js;
308
            }
309
        }
310
        $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeCode(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERCODE, ENT_QUOTES | ENT_HTML5) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_CODE . "'><span class='fa fa-fw fa-code' aria-hidden='true'></span></button>";
311
        $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeQuote(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES | ENT_HTML5) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_QUOTE . "'><span class='fa fa-fw fa-quote-right' aria-hidden='true'></span></button>";
312
        $code .= "</div></div>";
313
314
        $xoopsPreload = XoopsPreload::getInstance();
315
        $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
316
317
        return $code;
318
    }
319
320
    /**
321
     * Render typography controls for editor (font, size, color)
322
     *
323
     * @param XoopsFormDhtmlTextArea $element form element
324
     *
325
     * @return string rendered typography controls
326
     */
327
    protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element)
328
    {
329
        $textarea_id = $element->getName();
330
        $hiddentext  = $element->_hiddenText;
331
332
        $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array(
333
            'Arial',
334
            'Courier',
335
            'Georgia',
336
            'Helvetica',
337
            'Impact',
338
            'Verdana',
339
            'Haettenschweiler');
340
341
        $colorArray = array(
342
            'Black'  => '000000',
343
            'Blue'   => '38AAFF',
344
            'Brown'  => '987857',
345
            'Green'  => '79D271',
346
            'Grey'   => '888888',
347
            'Orange' => 'FFA700',
348
            'Paper'  => 'E0E0E0',
349
            'Purple' => '363E98',
350
            'Red'    => 'FF211E',
351
            'White'  => 'FEFEFE',
352
            'Yellow' => 'FFD628',
353
        );
354
355
        $fontStr = '<div class="row"><div class="col-md-12"><div class="btn-group" role="toolbar">';
356
        $fontStr .= '<div class="btn-group">'
357
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _SIZE .'"'
358
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
359
            . '<span class = "fa fa-text-height"></span><span class="caret"></span></button>'
360
            . '<ul class="dropdown-menu">';
361
            //. _SIZE . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
362
        foreach ($GLOBALS['formtextdhtml_sizes'] as $value => $name) {
363
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'size\', \'' . $value . '\', \''
364
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $name . '</a></li>';
365
        }
366
        $fontStr .= '</ul></div>';
367
368
        $fontStr .= '<div class="btn-group">'
369
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _FONT .'"'
370
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
371
            . '<span class = "fa fa-font"></span><span class="caret"></span></button>'
372
            . '<ul class="dropdown-menu">';
373
            //. _FONT . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
374
        foreach ($fontarray as $font) {
375
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'font\', \'' . $font . '\', \''
376
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $font . '</a></li>';
377
        }
378
        $fontStr .= '</ul></div>';
379
380
        $fontStr .= '<div class="btn-group">'
381
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _COLOR .'"'
382
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
383
            . '<span class = "fa fa-tint"></span><span class="caret"></span></button>'
384
            . '<ul class="dropdown-menu">';
385
            //. _COLOR . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
386
        foreach ($colorArray as $color => $hex) {
387
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'color\', \'' . $hex . '\', \''
388
                . $textarea_id . '\', \'' . $hiddentext . '\');">'
389
                . '<span style="color:#' . $hex . ';">' . $color .'</span></a></li>';
390
        }
391
        $fontStr .= '</ul></div>';
392
        $fontStr .= '</div>';
393
394
        //$styleStr = "<div class='row'><div class='col-md-12'>";
395
        $styleStr  = "<div class='btn-group' role='group'>";
396
        $styleStr .= "<button type='button' class='btn btn-default 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>";
397
        $styleStr .= "<button type='button' class='btn btn-default 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>";
398
        $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_UNDERLINE . "' aria-label='Left Align'>" . '<span class="fa fa-underline"></span></button>';
399
        $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LINETHROUGH . "' aria-label='Left Align'>" . '<span class="fa fa-strikethrough"></span></button>';
400
        $styleStr .= "</div>";
401
402
        $alignStr = "<div class='btn-group' role='group'>";
403
        $alignStr .= "<button type='button' class='btn btn-default 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>";
404
        $alignStr .= "<button type='button' class='btn btn-default 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>";
405
        $alignStr .= "<button type='button' class='btn btn-default 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>";
406
        $alignStr .= "</div>";
407
408
        $fontStr .= "&nbsp;{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
409
410
        $maxlength = isset($element->configs['maxlength']) ? $element->configs['maxlength'] : 0;
0 ignored issues
show
Bug introduced by
The property configs does not seem to exist on XoopsFormDhtmlTextArea.
Loading history...
411
        $fontStr .= "<button type='button' class='btn btn-default btn-sm' onclick=\"XoopsCheckLength('"
412
                    . $element->getName() . "', '" . $maxlength . "', '"
413
            . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='"
414
            . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>";
415
        $fontStr .= "</div></div>";
416
417
        return $fontStr;
418
    }
419
420
    /**
421
     * Render support for XoopsFormElementTray
422
     *
423
     * @param XoopsFormElementTray $element form element
424
     *
425
     * @return string rendered form element
426
     */
427
    public function renderFormElementTray(XoopsFormElementTray $element)
428
    {
429
        $count = 0;
430
        $isVertical = (\XoopsFormElementTray::ORIENTATION_VERTICAL === $element->getOrientation());
431
        $ret = '<span class="form-inline">';
432
        foreach ($element->getElements() as $ele) {
433
            if ($count > 0) {
434
                $ret .= $element->getDelimeter();
435
                if ($isVertical) {
436
                    $ret .= '<br>';
437
                }
438
            }
439
            if ($ele->getCaption() != '') {
440
                $ret .= $ele->getCaption() . '&nbsp;';
441
            }
442
            $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...
443
            if (!$ele->isHidden()) {
444
                ++$count;
445
            }
446
        }
447
        /*
448
        if (substr_count($ret, '<div class="form-group form-inline">') > 0) {
449
            $ret = str_replace('<div class="form-group form-inline">', '', $ret);
450
            $ret = str_replace('</div>', '', $ret);
451
        }
452
        if (substr_count($ret, '<div class="checkbox-inline">') > 0) {
453
            $ret = str_replace('<div class="checkbox-inline">', '', $ret);
454
        }
455
        */
456
        $ret .= '</span>';
457
        return $ret;
458
    }
459
460
    /**
461
     * Render support for XoopsFormFile
462
     *
463
     * @param XoopsFormFile $element form element
464
     *
465
     * @return string rendered form element
466
     */
467
    public function renderFormFile(XoopsFormFile $element)
468
    {
469
        return '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '" />'
470
            . '<input class="form-control-static" type="file" name="' . $element->getName()
471
            . '" id="' . $element->getName()
472
            . '" title="' . $element->getTitle() . '" ' . $element->getExtra() . ' />'
473
            . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="'
474
            . $element->getName() . '" />';
475
    }
476
477
    /**
478
     * Render support for XoopsFormLabel
479
     *
480
     * @param XoopsFormLabel $element form element
481
     *
482
     * @return string rendered form element
483
     */
484
    public function renderFormLabel(XoopsFormLabel $element)
485
    {
486
        return '<div class="form-control-static">' . $element->getValue() . '</div>';
487
    }
488
489
    /**
490
     * Render support for XoopsFormPassword
491
     *
492
     * @param XoopsFormPassword $element form element
493
     *
494
     * @return string rendered form element
495
     */
496
    public function renderFormPassword(XoopsFormPassword $element)
497
    {
498
        return '<input class="form-control" type="password" name="'
499
            . $element->getName() . '" id="' . $element->getName() . '" size="' . $element->getSize()
500
            . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue() . '"'
501
            . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>';
502
    }
503
504
    /**
505
     * Render support for XoopsFormRadio
506
     *
507
     * @param XoopsFormRadio $element form element
508
     *
509
     * @return string rendered form element
510
     */
511
    public function renderFormRadio(XoopsFormRadio $element)
512
    {
513
514
        $elementName = $element->getName();
515
        $elementId = $elementName;
516
517
        switch ((int) ($element->columns)) {
518
            case 0:
519
                return $this->renderCheckedInline($element, 'radio', $elementId, $elementName);
520
            case 1:
521
                return $this->renderCheckedOneColumn($element, 'radio', $elementId, $elementName);
522
            default:
523
                return $this->renderCheckedColumnar($element, 'radio', $elementId, $elementName);
524
        }
525
    }
526
527
    /**
528
     * Render support for XoopsFormSelect
529
     *
530
     * @param XoopsFormSelect $element form element
531
     *
532
     * @return string rendered form element
533
     */
534
    public function renderFormSelect(XoopsFormSelect $element)
535
    {
536
        $ele_name    = $element->getName();
537
        $ele_title   = $element->getTitle();
538
        $ele_value   = $element->getValue();
539
        $ele_options = $element->getOptions();
540
        $ret = '<select class="form-control" size="'
541
            . $element->getSize() . '"' . $element->getExtra();
542
        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...
543
            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title
544
                . '" multiple="multiple">';
545
        } else {
546
            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
547
        }
548
        foreach ($ele_options as $value => $name) {
549
            $ret .= '<option value="' . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . '"';
550
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
551
                $ret .= ' selected';
552
            }
553
            $ret .= '>' . $name . '</option>';
554
        }
555
        $ret .= '</select>';
556
557
        return $ret;
558
    }
559
    /**
560
     * Render support for XoopsFormText
561
     *
562
     * @param XoopsFormText $element form element
563
     *
564
     * @return string rendered form element
565
     */
566
    public function renderFormText(XoopsFormText $element)
567
    {
568
        return "<input class='form-control' type='text' name='"
569
            . $element->getName() . "' title='" . $element->getTitle() . "' id='" . $element->getName()
570
            . "' size='" . $element->getSize() . "' maxlength='" . $element->getMaxlength()
571
            . "' value='" . $element->getValue() . "'" . $element->getExtra() . ' />';
572
    }
573
574
    /**
575
     * Render support for XoopsFormTextArea
576
     *
577
     * @param XoopsFormTextArea $element form element
578
     *
579
     * @return string rendered form element
580
     */
581
    public function renderFormTextArea(XoopsFormTextArea $element)
582
    {
583
        return "<textarea class='form-control' name='"
584
            . $element->getName() . "' id='" . $element->getName() . "'  title='" . $element->getTitle()
585
            . "' rows='" . $element->getRows() . "' cols='" . $element->getCols() . "'"
586
            . $element->getExtra() . '>' . $element->getValue() . '</textarea>';
587
    }
588
589
    /**
590
     * Render support for XoopsFormTextDateSelect
591
     *
592
     * @param XoopsFormTextDateSelect $element form element
593
     *
594
     * @return string rendered form element
595
     */
596
    public function renderFormTextDateSelect(XoopsFormTextDateSelect $element)
597
    {
598
        static $included = false;
599
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) {
600
            include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php';
601
        } else {
602
            include_once XOOPS_ROOT_PATH . '/language/english/calendar.php';
603
        }
604
605
        $ele_name  = $element->getName();
606
        $ele_value = $element->getValue(false);
607
        if (is_string($ele_value)) {
0 ignored issues
show
introduced by
The condition is_string($ele_value) is always true.
Loading history...
608
            $display_value = $ele_value;
609
            $ele_value     = time();
610
        } else {
611
            $display_value = date(_SHORTDATESTRING, $ele_value);
612
        }
613
614
        $jstime = formatTimestamp($ele_value, 'm/d/Y');
615
        if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) {
616
            $GLOBALS['xoTheme']->addScript('include/calendar.js');
617
            $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css');
618
            if (!$included) {
619
                $included = true;
620
                $GLOBALS['xoTheme']->addScript('', '', '
621
                    var calendar = null;
622
623
                    function selected(cal, date)
624
                    {
625
                    cal.sel.value = date;
626
                    }
627
628
                    function closeHandler(cal)
629
                    {
630
                    cal.hide();
631
                    Calendar.removeEvent(document, "mousedown", checkCalendar);
632
                    }
633
634
                    function checkCalendar(ev)
635
                    {
636
                    var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
637
                    for (; el != null; el = el.parentNode)
638
                    if (el == calendar.element || el.tagName == "A") break;
639
                    if (el == null) {
640
                    calendar.callCloseHandler(); Calendar.stopEvent(ev);
641
                    }
642
                    }
643
                    function showCalendar(id)
644
                    {
645
                    var el = xoopsGetElementById(id);
646
                    if (calendar != null) {
647
                    calendar.hide();
648
                    } else {
649
                    var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler);
650
                    calendar = cal;
651
                    cal.setRange(1900, 2100);
652
                    calendar.create();
653
                    }
654
                    calendar.sel = el;
655
                    calendar.parseDate(el.value);
656
                    calendar.showAtElement(el);
657
                    Calendar.addEvent(document, "mousedown", checkCalendar);
658
659
                    return false;
660
                    }
661
662
                    Calendar._DN = new Array
663
                    ("' . _CAL_SUNDAY . '",
664
                    "' . _CAL_MONDAY . '",
665
                    "' . _CAL_TUESDAY . '",
666
                    "' . _CAL_WEDNESDAY . '",
667
                    "' . _CAL_THURSDAY . '",
668
                    "' . _CAL_FRIDAY . '",
669
                    "' . _CAL_SATURDAY . '",
670
                    "' . _CAL_SUNDAY . '");
671
                    Calendar._MN = new Array
672
                    ("' . _CAL_JANUARY . '",
673
                    "' . _CAL_FEBRUARY . '",
674
                    "' . _CAL_MARCH . '",
675
                    "' . _CAL_APRIL . '",
676
                    "' . _CAL_MAY . '",
677
                    "' . _CAL_JUNE . '",
678
                    "' . _CAL_JULY . '",
679
                    "' . _CAL_AUGUST . '",
680
                    "' . _CAL_SEPTEMBER . '",
681
                    "' . _CAL_OCTOBER . '",
682
                    "' . _CAL_NOVEMBER . '",
683
                    "' . _CAL_DECEMBER . '");
684
685
                    Calendar._TT = {};
686
                    Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '";
687
                    Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '";
688
                    Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '";
689
                    Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '";
690
                    Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '";
691
                    Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '";
692
                    Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '";
693
                    Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '";
694
                    Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')";
695
                    Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '";
696
                    Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '";
697
                    Calendar._TT["CLOSE"] = "' . _CLOSE . '";
698
                    Calendar._TT["TODAY"] = "' . _CAL_TODAY . '";
699
700
                    // date formats
701
                    Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
702
                    Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
703
704
                    Calendar._TT["WK"] = "";
705
                ');
706
            }
707
        }
708
        return '<div class="input-group">'
709
            . '<input class="form-control" type="text" name="' . $ele_name . '" id="' . $ele_name
710
            . '" size="' . $element->getSize() . '" maxlength="' . $element->getMaxlength()
711
            . '" value="' . $display_value . '"' . $element->getExtra() . ' />'
712
            . '<span class="input-group-btn"><button class="btn btn-default" type="button"'
713
            . ' onclick="return showCalendar(\'' . $ele_name . '\');">'
714
            . '<span class="fa fa-calendar" aria-hidden="true"></span>&nbsp;</button>'
715
            . '</span>'
716
            . '</div>';
717
    }
718
719
    /**
720
     * Render support for XoopsThemeForm
721
     *
722
     * @param XoopsThemeForm $form form to render
723
     *
724
     * @return string rendered form
725
     */
726
    public function renderThemeForm(XoopsThemeForm $form)
727
    {
728
        $ele_name = $form->getName();
729
730
        $ret = '<div>';
731
        $ret .= '<form class="form-horizontal" name="' . $ele_name . '" id="' . $ele_name . '" action="'
732
            . $form->getAction() . '" method="' . $form->getMethod()
733
            . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>'
734
            . '<h3>' . $form->getTitle() . '</h3>';
735
        $hidden   = '';
736
737
        foreach ($form->getElements() as $element) {
738
            if (!is_object($element)) { // see $form->addBreak()
739
                $ret .= $element;
740
                continue;
741
            }
742
            if ($element->isHidden()) {
743
                $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...
744
                continue;
745
            }
746
747
            $ret .= '<div class="form-group">';
748
            if (($caption = $element->getCaption()) != '') {
0 ignored issues
show
Unused Code introduced by
The assignment to $caption is dead and can be removed.
Loading history...
749
                $ret .= '<label for="' . $element->getName() . '" class="col-md-2 control-label">'
750
                    . $element->getCaption()
751
                    . ($element->isRequired() ? '<span class="xo-caption-required">*</span>' : '')
752
                    . '</label>';
753
            } else {
754
                $ret .= '<div class="col-md-2"> </div>';
755
            }
756
            $ret .= '<div class="col-md-10">';
757
            $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...
758
            if (($desc = $element->getDescription()) != '') {
759
                $ret .= '<p class="help-block">' . $desc . '</p>';
760
            }
761
            $ret .= '</div>';
762
            $ret .= '</div>';
763
        }
764
        if (count($form->getRequired()) > 0) {
765
            //  Add caption marker constructed using renderer's formatting
766
            $ret .= NWLINE . '<div class="col-12"> <span class="xo-caption-required">*</span> = ' . _REQUIRED . '<br></div>' . NWLINE;
767
        }
768
        $ret .= $hidden;
769
        $ret .= '</form></div>';
770
        $ret .= $form->renderValidationJS(true);
771
772
        return $ret;
773
    }
774
775
    /**
776
     * Support for themed addBreak
777
     *
778
     * @param XoopsThemeForm $form
779
     * @param string         $extra pre-rendered content for break row
780
     * @param string         $class class for row
781
     *
782
     * @return void
783
     */
784
    public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class)
785
    {
786
        $class = ($class != '') ? preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) : '';
787
        $form->addElement('<div class="col-sm-12 ' . $class .'">'. $extra . '</div>');
788
    }
789
}
790