Test Failed
Push — master ( 398493...d4ef72 )
by Michael
11:04
created

XoopsFormRendererBootstrap3::renderFormLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
eloc 1
nc 1
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
 * Legacy style form renderer
13
 *
14
 * @category  XoopsForm
15
 * @package   XoopsFormRendererBootstrap3
16
 * @author    Richard Griffith <[email protected]>
17
 * @copyright 2017 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 XoopsFormRendererBootstrap3 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 "<input type='" . $element->getType() . "' class='btn btn-default' name='"
34
            . $element->getName() . "'  id='" . $element->getName() . "' value='" . $element->getValue()
35
            . "' title='" . $element->getValue() . "'" . $element->getExtra() . ' />';
36
    }
37
38
    /**
39
     * Render support for XoopsFormButtonTray
40
     *
41
     * @param XoopsFormButtonTray $element form element
42
     *
43
     * @return string rendered form element
44
     */
45
    public function renderFormButtonTray(XoopsFormButtonTray $element)
46
    {
47
        $ret = '';
48
        if ($element->_showDelete) {
49
            $ret .= '<input type="submit" class="btn btn-danger" name="delete" id="delete" value="' . _DELETE
50
                . '" onclick="this.form.elements.op.value=\'delete\'">&nbsp;';
51
        }
52
        $ret .= '<input type="button" class="btn btn-danger" value="' . _CANCEL
53
             . '" onClick="history.go(-1);return true;" />&nbsp;'
54
             . '<input type="reset" class="btn btn-warning"  name="reset"  id="reset" value="' . _RESET . '" />&nbsp;'
55
             . '<input type="' . $element->getType() . '" class="btn btn-success"  name="' . $element->getName()
56
             . '"  id="' . $element->getName() . '" value="' . $element->getValue() . '"' . $element->getExtra()
57
             . '  />';
58
59
        return $ret;
60
    }
61
62
    /**
63
     * Render support for XoopsFormCheckBox
64
     *
65
     * @param XoopsFormCheckBox $element form element
66
     *
67
     * @return string rendered form element
68
     */
69
    public function renderFormCheckBox(XoopsFormCheckBox $element)
70
    {
71
        $elementName = $element->getName();
72
        $elementId = $elementName;
73
        $elementOptions = $element->getOptions();
74
        if (count($elementOptions) > 1 && substr($elementName, -2, 2) !== '[]') {
75
            $elementName .= '[]';
76
            $element->setName($elementName);
77
        }
78
79
        switch ((int) ($element->columns)) {
80
            case 0:
81
                return $this->renderCheckedInline($element, 'checkbox', $elementId, $elementName);
82
            case 1:
83
                return $this->renderCheckedOneColumn($element, 'checkbox', $elementId, $elementName);
84
            default:
85
                return $this->renderCheckedColumnar($element, 'checkbox', $elementId, $elementName);
86
        }
87
    }
88
89
    /**
90
     * Render a inline checkbox or radio element
91
     *
92
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
93
     * @param string                           $type    'checkbox' or 'radio;
94
     * @param string                           $elementId   input 'id' attribute of element
95
     * @param string                           $elementName input 'name' attribute of element
96
     * @return string
97
     */
98
    protected function renderCheckedInline($element, $type, $elementId, $elementName)
99
    {
100
        $class = $type . '-inline';
101
        $ret = '';
102
103
        $idSuffix = 0;
104
        $elementValue = $element->getValue();
105
        $elementOptions = $element->getOptions();
106
        foreach ($elementOptions as $value => $name) {
107
            ++$idSuffix;
108
            $ret .= '<label class="' . $class . '">';
109
            $ret .= "<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() . ' />' . $name . $element->getDelimeter();
117
            $ret .= '</label>';
118
        }
119
120
        return $ret;
121
    }
122
123
    /**
124
     * Render a single column checkbox or radio element
125
     *
126
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
127
     * @param string                           $type    'checkbox' or 'radio;
128
     * @param string                           $elementId   input 'id' attribute of element
129
     * @param string                           $elementName input 'name' attribute of element
130
     * @return string
131
     */
132
    protected function renderCheckedOneColumn($element, $type, $elementId, $elementName)
133
    {
134
        $class = $type;
135
        $ret = '';
136
137
        $idSuffix = 0;
138
        $elementValue = $element->getValue();
139
        $elementOptions = $element->getOptions();
140
        foreach ($elementOptions as $value => $name) {
141
            ++$idSuffix;
142
            $ret .= '<div class="' . $class . '">';
143
            $ret .= '<label>';
144
            $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
145
                . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
146
                . htmlspecialchars($value, ENT_QUOTES) . "'";
147
148
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
149
                $ret .= ' checked';
150
            }
151
            $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
152
            $ret .= '</label>';
153
            $ret .= '</div>';
154
        }
155
156
        return $ret;
157
    }
158
159
    /**
160
     * Render a multicolumn checkbox or radio element
161
     *
162
     * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered
163
     * @param string                           $type    'checkbox' or 'radio;
164
     * @param string                           $elementId   input 'id' attribute of element
165
     * @param string                           $elementName input 'name' attribute of element
166
     * @return string
167
     */
168
    protected function renderCheckedColumnar($element, $type, $elementId, $elementName)
169
    {
170
        $class = $type;
171
        $ret = '';
172
173
        $idSuffix = 0;
174
        $elementValue = $element->getValue();
175
        $elementOptions = $element->getOptions();
176
        foreach ($elementOptions as $value => $name) {
177
            ++$idSuffix;
178
            $ret .= '<div class="' . $class . ' col-md-2">';
179
            $ret .= '<label>';
180
            $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='"
181
                . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='"
182
                . htmlspecialchars($value, ENT_QUOTES) . "'";
183
184
            if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) {
185
                $ret .= ' checked';
186
            }
187
            $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter();
188
            $ret .= '</label>';
189
            $ret .= '</div>';
190
        }
191
192
        return $ret;
193
    }
194
    /**
195
     * Render support for XoopsFormColorPicker
196
     *
197
     * @param XoopsFormColorPicker $element form element
198
     *
199
     * @return string rendered form element
200
     */
201
    public function renderFormColorPicker(XoopsFormColorPicker $element)
202
    {
203
        if (isset($GLOBALS['xoTheme'])) {
204
            $GLOBALS['xoTheme']->addScript('include/spectrum.js');
205
            $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css');
206
        } else {
207
            echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>';
208
            echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">';
209
        }
210
        return '<input class="form-control" style="width: 25%;" type="color" name="' . $element->getName()
211
            . "' title='" . $element->getTitle() . "' id='" . $element->getName()
212
            . '" size="7" maxlength="7" value="' . $element->getValue() . '"' . $element->getExtra() . ' />';
213
    }
214
215
    /**
216
     * Render support for XoopsFormDhtmlTextArea
217
     *
218
     * @param XoopsFormDhtmlTextArea $element form element
219
     *
220
     * @return string rendered form element
221
     */
222
    public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element)
223
    {
224
        static $js_loaded;
225
226
        xoops_loadLanguage('formdhtmltextarea');
227
        $ret = '';
228
        // actions
229
        $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n";
230
        // fonts
231
        $ret .= $this->renderFormDhtmlTATypography($element);
232
        // length checker
233
234
        $ret .= "<br>\n";
235
        // the textarea box
236
        $ret .= "<textarea class='form-control' id='" . $element->getName() . "' name='" . $element->getName()
237
            . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName()
238
            . "');\" onclick=\"xoopsSavePosition('" . $element->getName()
239
            . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='"
240
            . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra()
241
            . '>' . $element->getValue() . "</textarea>\n";
242
243
        if (empty($element->skipPreview)) {
244
            if (empty($GLOBALS['xoTheme'])) {
245
                $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

245
                $element->js .= implode('', /** @scrutinizer ignore-type */ file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
Loading history...
246
            } else {
247
                $GLOBALS['xoTheme']->addScript(
248
                    '/class/textsanitizer/image/image.js',
249
                    array('type' => 'text/javascript')
250
                );
251
            }
252
            $button = "<button type='button' class='btn btn-primary' onclick=\"form_instantPreview('" . XOOPS_URL
253
                . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)$element->doHtml . ", '"
254
                . $GLOBALS['xoopsSecurity']->createToken() . "')\" title='" . _PREVIEW . "'>" . _PREVIEW . "</button>";
255
256
            $ret .= '<br>' . "<div id='" . $element->getName() . "_hidden' style='display: block;'> "
257
                . '   <fieldset>' . '       <legend>' . $button . '</legend>'
258
                . "       <div id='" . $element->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT
259
                . '</div>' . '   </fieldset>' . '</div>';
260
        }
261
        // Load javascript
262
        if (empty($js_loaded)) {
263
            $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '')
264
                . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
265
            $ret        = $javascript . $ret;
266
            $js_loaded  = true;
267
        }
268
269
        return $ret;
270
    }
271
272
    /**
273
     * Render xoopscode buttons for editor, include calling text sanitizer extensions
274
     *
275
     * @param XoopsFormDhtmlTextArea $element form element
276
     *
277
     * @return string rendered buttons for xoopscode assistance
278
     */
279
    protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element)
280
    {
281
        $textarea_id = $element->getName();
282
        $code = '';
283
        $code .= "<div class='row'><div class='col-md-12'>";
284
        $code .= "<button type='button' class='btn btn-default 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>";
285
        $code .= "<button type='button' class='btn btn-default 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>";
286
        $code .= "<button type='button' class='btn btn-default 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>";
287
        $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>";
288
        $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>";
289
290
        $myts = MyTextSanitizer::getInstance();
291
292
        $extensions = array_filter($myts->config['extensions']);
293
        foreach (array_keys($extensions) as $key) {
294
            $extension = $myts->loadExtension($key);
295
            @list($encode, $js) = $extension->encode($textarea_id);
296
            if (empty($encode)) {
297
                continue;
298
            }
299
            $code .= $encode;
300
            if (!empty($js)) {
301
                $element->js .= $js;
302
            }
303
        }
304
        $code .= "<button type='button' class='btn btn-default 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>";
305
        $code .= "<button type='button' class='btn btn-default 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>";
306
        $code .= "</div></div>";
307
308
        $xoopsPreload = XoopsPreload::getInstance();
309
        $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
310
311
        return $code;
312
    }
313
314
    /**
315
     * Render typography controls for editor (font, size, color)
316
     *
317
     * @param XoopsFormDhtmlTextArea $element form element
318
     *
319
     * @return string rendered typography controls
320
     */
321
    protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element)
322
    {
323
        $textarea_id = $element->getName();
324
        $hiddentext  = $element->_hiddenText;
325
326
        $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array(
327
            'Arial',
328
            'Courier',
329
            'Georgia',
330
            'Helvetica',
331
            'Impact',
332
            'Verdana',
333
            'Haettenschweiler');
334
335
        $colorArray = array(
336
            'Black'  => '000000',
337
            'Blue'   => '38AAFF',
338
            'Brown'  => '987857',
339
            'Green'  => '79D271',
340
            'Grey'   => '888888',
341
            'Orange' => 'FFA700',
342
            'Paper'  => 'E0E0E0',
343
            'Purple' => '363E98',
344
            'Red'    => 'FF211E',
345
            'White'  => 'FEFEFE',
346
            'Yellow' => 'FFD628',
347
        );
348
349
        $fontStr = '<div class="row"><div class="col-md-12"><div class="btn-group" role="toolbar">';
350
        $fontStr .= '<div class="btn-group">'
351
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _SIZE .'"'
352
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
353
            . '<span class = "glyphicon glyphicon-text-height"></span><span class="caret"></span></button>'
354
            . '<ul class="dropdown-menu">';
355
            //. _SIZE . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
356
        foreach ($GLOBALS['formtextdhtml_sizes'] as $value => $name) {
357
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'size\', \'' . $value . '\', \''
358
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $name . '</a></li>';
359
        }
360
        $fontStr .= '</ul></div>';
361
362
        $fontStr .= '<div class="btn-group">'
363
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _FONT .'"'
364
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
365
            . '<span class = "glyphicon glyphicon-font"></span><span class="caret"></span></button>'
366
            . '<ul class="dropdown-menu">';
367
            //. _FONT . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
368
        foreach ($fontarray as $font) {
369
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'font\', \'' . $font . '\', \''
370
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $font . '</a></li>';
371
        }
372
        $fontStr .= '</ul></div>';
373
374
        $fontStr .= '<div class="btn-group">'
375
            . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _COLOR .'"'
376
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
377
            . '<span class = "glyphicon glyphicon-text-color"></span><span class="caret"></span></button>'
378
            . '<ul class="dropdown-menu">';
379
            //. _COLOR . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
380
        foreach ($colorArray as $color => $hex) {
381
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'color\', \'' . $hex . '\', \''
382
                . $textarea_id . '\', \'' . $hiddentext . '\');">'
383
                . '<span style="color:#' . $hex . ';">' . $color .'</span></a></li>';
384
        }
385
        $fontStr .= '</ul></div>';
386
        $fontStr .= '</div>';
387
388
        //$styleStr = "<div class='row'><div class='col-md-12'>";
389
        $styleStr  = "<div class='btn-group' role='group'>";
390
        $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>";
391
        $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>";
392
        $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>';
393
        $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>';
394
        $styleStr .= "</div>";
395
396
        $alignStr = "<div class='btn-group' role='group'>";
397
        $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>";
398
        $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>";
399
        $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>";
400
        $alignStr .= "</div>";
401
402
        $fontStr .= "&nbsp;{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
403
404
        $fontStr .= "<button type='button' class='btn btn-default btn-sm' onclick=\"XoopsCheckLength('"
405
            . $element->getName() . "', '" . @$element->configs['maxlength'] . "', '"
0 ignored issues
show
Bug introduced by
The property configs does not seem to exist on XoopsFormDhtmlTextArea.
Loading history...
406
            . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='"
407
            . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>";
408
        $fontStr .= "</div></div>";
409
410
        return $fontStr;
411
    }
412
413
    /**
414
     * Render support for XoopsFormElementTray
415
     *
416
     * @param XoopsFormElementTray $element form element
417
     *
418
     * @return string rendered form element
419
     */
420
    public function renderFormElementTray(XoopsFormElementTray $element)
421
    {
422
        $count = 0;
423
        $ret = '<span class="form-inline">';
424
        foreach ($element->getElements() as $ele) {
425
            if ($count > 0) {
426
                $ret .= $element->getDelimeter();
427
            }
428
            if ($ele->getCaption() != '') {
429
                $ret .= $ele->getCaption() . '&nbsp;';
430
            }
431
            $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...
432
            if (!$ele->isHidden()) {
433
                ++$count;
434
            }
435
        }
436
        /*
437
        if (substr_count($ret, '<div class="form-group form-inline">') > 0) {
438
            $ret = str_replace('<div class="form-group form-inline">', '', $ret);
439
            $ret = str_replace('</div>', '', $ret);
440
        }
441
        if (substr_count($ret, '<div class="checkbox-inline">') > 0) {
442
            $ret = str_replace('<div class="checkbox-inline">', '', $ret);
443
        }
444
        */
445
        $ret .= '</span>';
446
        return $ret;
447
    }
448
449
    /**
450
     * Render support for XoopsFormFile
451
     *
452
     * @param XoopsFormFile $element form element
453
     *
454
     * @return string rendered form element
455
     */
456
    public function renderFormFile(XoopsFormFile $element)
457
    {
458
        return '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '" />'
459
            . '<input class="form-control-static" type="file" name="' . $element->getName()
460
            . '" id="' . $element->getName()
461
            . '" title="' . $element->getTitle() . '" ' . $element->getExtra() . ' />'
462
            . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="'
463
            . $element->getName() . '" />';
464
    }
465
466
    /**
467
     * Render support for XoopsFormLabel
468
     *
469
     * @param XoopsFormLabel $element form element
470
     *
471
     * @return string rendered form element
472
     */
473
    public function renderFormLabel(XoopsFormLabel $element)
474
    {
475
        return '<div class="form-control-static">' . $element->getValue() . '</div>';
476
    }
477
478
    /**
479
     * Render support for XoopsFormPassword
480
     *
481
     * @param XoopsFormPassword $element form element
482
     *
483
     * @return string rendered form element
484
     */
485
    public function renderFormPassword(XoopsFormPassword $element)
486
    {
487
        return '<input class="form-control" type="password" name="'
488
            . $element->getName() . '" id="' . $element->getName() . '" size="' . $element->getSize()
489
            . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue() . '"'
490
            . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>';
491
    }
492
493
    /**
494
     * Render support for XoopsFormRadio
495
     *
496
     * @param XoopsFormRadio $element form element
497
     *
498
     * @return string rendered form element
499
     */
500
    public function renderFormRadio(XoopsFormRadio $element)
501
    {
502
503
        $elementName = $element->getName();
504
        $elementId = $elementName;
505
506
        switch ((int) ($element->columns)) {
507
            case 0:
508
                return $this->renderCheckedInline($element, 'radio', $elementId, $elementName);
509
            case 1:
510
                return $this->renderCheckedOneColumn($element, 'radio', $elementId, $elementName);
511
            default:
512
                return $this->renderCheckedColumnar($element, 'radio', $elementId, $elementName);
513
        }
514
    }
515
516
    /**
517
     * Render support for XoopsFormSelect
518
     *
519
     * @param XoopsFormSelect $element form element
520
     *
521
     * @return string rendered form element
522
     */
523
    public function renderFormSelect(XoopsFormSelect $element)
524
    {
525
        $ele_name    = $element->getName();
526
        $ele_title   = $element->getTitle();
527
        $ele_value   = $element->getValue();
528
        $ele_options = $element->getOptions();
529
        $ret = '<select class="form-control" size="'
530
            . $element->getSize() . '"' . $element->getExtra();
531
        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...
532
            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title
533
                . '" multiple="multiple">';
534
        } else {
535
            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
536
        }
537
        foreach ($ele_options as $value => $name) {
538
            $ret .= '<option value="' . htmlspecialchars($value, ENT_QUOTES) . '"';
539
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
540
                $ret .= ' selected';
541
            }
542
            $ret .= '>' . $name . '</option>';
543
        }
544
        $ret .= '</select>';
545
546
        return $ret;
547
    }
548
    /**
549
     * Render support for XoopsFormText
550
     *
551
     * @param XoopsFormText $element form element
552
     *
553
     * @return string rendered form element
554
     */
555
    public function renderFormText(XoopsFormText $element)
556
    {
557
        return "<input class='form-control' type='text' name='"
558
            . $element->getName() . "' title='" . $element->getTitle() . "' id='" . $element->getName()
559
            . "' size='" . $element->getSize() . "' maxlength='" . $element->getMaxlength()
560
            . "' value='" . $element->getValue() . "'" . $element->getExtra() . ' />';
561
    }
562
563
    /**
564
     * Render support for XoopsFormTextArea
565
     *
566
     * @param XoopsFormTextArea $element form element
567
     *
568
     * @return string rendered form element
569
     */
570
    public function renderFormTextArea(XoopsFormTextArea $element)
571
    {
572
        return "<textarea class='form-control' name='"
573
            . $element->getName() . "' id='" . $element->getName() . "'  title='" . $element->getTitle()
574
            . "' rows='" . $element->getRows() . "' cols='" . $element->getCols() . "'"
575
            . $element->getExtra() . '>' . $element->getValue() . '</textarea>';
576
    }
577
578
    /**
579
     * Render support for XoopsFormTextDateSelect
580
     *
581
     * @param XoopsFormTextDateSelect $element form element
582
     *
583
     * @return string rendered form element
584
     */
585
    public function renderFormTextDateSelect(XoopsFormTextDateSelect $element)
586
    {
587
        static $included = false;
588
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) {
589
            include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php';
590
        } else {
591
            include_once XOOPS_ROOT_PATH . '/language/english/calendar.php';
592
        }
593
594
        $ele_name  = $element->getName();
595
        $ele_value = $element->getValue(false);
596
        if (is_string($ele_value)) {
0 ignored issues
show
introduced by
The condition is_string($ele_value) is always true.
Loading history...
597
            $display_value = $ele_value;
598
            $ele_value     = time();
599
        } else {
600
            $display_value = date(_SHORTDATESTRING, $ele_value);
601
        }
602
603
        $jstime = formatTimestamp($ele_value, _SHORTDATESTRING);
604
        if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) {
605
            $GLOBALS['xoTheme']->addScript('include/calendar.js');
606
            $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css');
607
            if (!$included) {
608
                $included = true;
609
                $GLOBALS['xoTheme']->addScript('', '', '
610
                    var calendar = null;
611
612
                    function selected(cal, date)
613
                    {
614
                    cal.sel.value = date;
615
                    }
616
617
                    function closeHandler(cal)
618
                    {
619
                    cal.hide();
620
                    Calendar.removeEvent(document, "mousedown", checkCalendar);
621
                    }
622
623
                    function checkCalendar(ev)
624
                    {
625
                    var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
626
                    for (; el != null; el = el.parentNode)
627
                    if (el == calendar.element || el.tagName == "A") break;
628
                    if (el == null) {
629
                    calendar.callCloseHandler(); Calendar.stopEvent(ev);
630
                    }
631
                    }
632
                    function showCalendar(id)
633
                    {
634
                    var el = xoopsGetElementById(id);
635
                    if (calendar != null) {
636
                    calendar.hide();
637
                    } else {
638
                    var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler);
639
                    calendar = cal;
640
                    cal.setRange(1900, 2100);
641
                    calendar.create();
642
                    }
643
                    calendar.sel = el;
644
                    calendar.parseDate(el.value);
645
                    calendar.showAtElement(el);
646
                    Calendar.addEvent(document, "mousedown", checkCalendar);
647
648
                    return false;
649
                    }
650
651
                    Calendar._DN = new Array
652
                    ("' . _CAL_SUNDAY . '",
653
                    "' . _CAL_MONDAY . '",
654
                    "' . _CAL_TUESDAY . '",
655
                    "' . _CAL_WEDNESDAY . '",
656
                    "' . _CAL_THURSDAY . '",
657
                    "' . _CAL_FRIDAY . '",
658
                    "' . _CAL_SATURDAY . '",
659
                    "' . _CAL_SUNDAY . '");
660
                    Calendar._MN = new Array
661
                    ("' . _CAL_JANUARY . '",
662
                    "' . _CAL_FEBRUARY . '",
663
                    "' . _CAL_MARCH . '",
664
                    "' . _CAL_APRIL . '",
665
                    "' . _CAL_MAY . '",
666
                    "' . _CAL_JUNE . '",
667
                    "' . _CAL_JULY . '",
668
                    "' . _CAL_AUGUST . '",
669
                    "' . _CAL_SEPTEMBER . '",
670
                    "' . _CAL_OCTOBER . '",
671
                    "' . _CAL_NOVEMBER . '",
672
                    "' . _CAL_DECEMBER . '");
673
674
                    Calendar._TT = {};
675
                    Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '";
676
                    Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '";
677
                    Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '";
678
                    Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '";
679
                    Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '";
680
                    Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '";
681
                    Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '";
682
                    Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '";
683
                    Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')";
684
                    Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '";
685
                    Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '";
686
                    Calendar._TT["CLOSE"] = "' . _CLOSE . '";
687
                    Calendar._TT["TODAY"] = "' . _CAL_TODAY . '";
688
689
                    // date formats
690
                    Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
691
                    Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
692
693
                    Calendar._TT["WK"] = "";
694
                ');
695
            }
696
        }
697
        return '<div class="input-group">'
698
            . '<input class="form-control" type="text" name="' . $ele_name . '" id="' . $ele_name
699
            . '" size="' . $element->getSize() . '" maxlength="' . $element->getMaxlength()
700
            . '" value="' . $display_value . '"' . $element->getExtra() . ' />'
701
            . '<span class="input-group-btn"><button class="btn btn-default" type="button"'
702
            . ' onclick="return showCalendar(\'' . $ele_name . '\');">'
703
            . '<span class="fa fa-calendar" aria-hidden="true"></span></button>'
704
            . '</span>'
705
            . '</div>';
706
    }
707
708
    /**
709
     * Render support for XoopsThemeForm
710
     *
711
     * @param XoopsThemeForm $form form to render
712
     *
713
     * @return string rendered form
714
     */
715
    public function renderThemeForm(XoopsThemeForm $form)
716
    {
717
        $ele_name = $form->getName();
718
719
        $ret = '<div>';
720
        $ret .= '<form class="form-horizontal" name="' . $ele_name . '" id="' . $ele_name . '" action="'
721
            . $form->getAction() . '" method="' . $form->getMethod()
722
            . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>'
723
            . '<h3>' . $form->getTitle() . '</h3>';
724
        $hidden   = '';
725
726
        foreach ($form->getElements() as $element) {
727
            if (!is_object($element)) { // see $form->addBreak()
728
                $ret .= $element;
729
                continue;
730
            }
731
            if ($element->isHidden()) {
732
                $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...
733
                continue;
734
            }
735
736
            $ret .= '<div class="form-group">';
737
            if (($caption = $element->getCaption()) != '') {
0 ignored issues
show
Unused Code introduced by
The assignment to $caption is dead and can be removed.
Loading history...
738
                $ret .= '<label for="' . $element->getName() . '" class="col-md-2 control-label">'
739
                    . $element->getCaption()
740
                    . ($element->isRequired() ? '<span class="caption-required">*</span>' : '')
741
                    . '</label>';
742
            } else {
743
                $ret .= '<div class="col-md-2"> </div>';
744
            }
745
            $ret .= '<div class="col-md-10">';
746
            $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...
747
            if (($desc = $element->getDescription()) != '') {
748
                $ret .= '<p class="help-block">' . $desc . '</p>';
749
            }
750
            $ret .= '</div>';
751
            $ret .= '</div>';
752
        }
753
        $ret .= $hidden;
754
        $ret .= '</form></div>';
755
        $ret .= $form->renderValidationJS(true);
756
757
        return $ret;
758
    }
759
760
    /**
761
     * Support for themed addBreak
762
     *
763
     * @param XoopsThemeForm $form
764
     * @param string         $extra pre-rendered content for break row
765
     * @param string         $class class for row
766
     *
767
     * @return void
768
     */
769
    public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class)
770
    {
771
        $class = ($class != '') ? preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) : '';
772
        $form->addElement('<div class="col-sm-12 ' . $class .'">'. $extra . '</div>');
773
    }
774
}
775