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

XoopsFormRendererLegacy::renderFormCheckBox()   D

Complexity

Conditions 14
Paths 456

Size

Total Lines 57
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 57
rs 4.5861
c 1
b 0
f 0
cc 14
eloc 36
nc 456
nop 1

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 * 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   XoopsFormRendererLegacy
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 XoopsFormRendererLegacy 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='formButton' name='" . $element->getName()
34
            . "'  id='" . $element->getName() . "' value='" . $element->getValue() . "' title='"
35
            . $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="formbutton" name="delete" id="delete" value="' . _DELETE
50
                . '" onclick="this.form.elements.op.value=\'delete\'">&nbsp;';
51
        }
52
        $ret .= '<input type="button" value="' . _CANCEL . '" onClick="history.go(-1);return true;" />&nbsp;'
53
            . '<input type="reset" class="formbutton"  name="reset"  id="reset" value="' . _RESET . '" />&nbsp;'
54
            . '<input type="' . $element->getType() . '" class="formbutton"  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
        $ele_name      = $element->getName();
71
        $ele_title     = $element->getTitle();
72
        $ele_id        = $ele_name;
73
        $ele_value     = $element->getValue();
74
        $ele_options   = $element->getOptions();
75
        $ele_extra     = $element->getExtra();
76
        $ele_delimiter = empty($element->columns) ? $element->getDelimeter() : '';
77
78
        if (count($ele_options) > 1 && substr($ele_name, -2, 2) !== '[]') {
79
            $ele_name .= '[]';
80
            $element->setName($ele_name);
81
        }
82
        $ret = '';
83
        /*<label class="checkbox-inline">
84
          <input type="checkbox" id="inlineCheckbox1" value="option1"> 1
85
        </label>*/
86
        if (!empty($element->columns)) {
87
            $ret .= '<table><tr>';
88
        }
89
        $i      = 0;
90
        $id_ele = 0;
91
        foreach ($ele_options as $value => $name) {
92
            ++$id_ele;
93
            if (!empty($element->columns)) {
94
                if ($i % $element->columns == 0) {
95
                    $ret .= '<tr>';
96
                }
97
                $ret .= '<td>';
98
            }
99
            // $name may be a link, should we use $name in the title tag?
100
            $ret .= '<input type="checkbox" name="' . $ele_name . '" id="' . $ele_id .$id_ele . '" '
101
                . ' title="' . $ele_title . '" value="' . htmlspecialchars($value, ENT_QUOTES) . '"';
102
103
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
104
                $ret .= ' checked';
105
            }
106
            $ret .= $ele_extra . ' />' . '<label name="xolb_' . $ele_name . '" for="'
107
            . $ele_id . $id_ele . '" >' . $name . '</label>' . $ele_delimiter;
108
109
110
            if (!empty($element->columns)) {
111
                $ret .= '</td>';
112
                if (++$i % $element->columns == 0) {
113
                    $ret .= '</tr>';
114
                }
115
            }
116
        }
117
        if (!empty($element->columns)) {
118
            if ($span = $i % $element->columns) {
119
                $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>';
120
            }
121
            $ret .= '</table>';
122
        }
123
124
        return $ret;
125
    }
126
127
    /**
128
     * Render support for XoopsFormColorPicker
129
     *
130
     * @param XoopsFormColorPicker $element form element
131
     *
132
     * @return string rendered form element
133
     */
134
    public function renderFormColorPicker(XoopsFormColorPicker $element)
135
    {
136
        if (isset($GLOBALS['xoTheme'])) {
137
            $GLOBALS['xoTheme']->addScript("browse.php?Frameworks/jquery/jquery.js");
138
            $GLOBALS['xoTheme']->addScript('include/spectrum.js');
139
            $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css');
140
        } else {
141
            echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>';
142
            echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">';
143
        }
144
        return "<input type='color' name='" . $element->getName() . "' title='" . $element->getTitle()
145
            . "' id='" . $element->getName() . "' size='" . $element->getSize() . "' maxlength='"
146
            . $element->getMaxlength() . "' value='" . $element->getValue() . "'" . $element->getExtra()
147
            . ' />';
148
    }
149
150
    /**
151
     * Render support for XoopsFormDhtmlTextArea
152
     *
153
     * @param XoopsFormDhtmlTextArea $element form element
154
     *
155
     * @return string rendered form element
156
     */
157
    public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element)
158
    {
159
        static $js_loaded;
160
161
        xoops_loadLanguage('formdhtmltextarea');
162
        $ret = '';
163
        // actions
164
        $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n";
165
        // fonts
166
        $ret .= $this->renderFormDhtmlTATypography($element);
167
        // length checker
168
        $ret .= "<button type='button' class='btn btn-default' onclick=\"XoopsCheckLength('" . $element->getName() . "', '" . @$element->configs['maxlength'] . "', '" . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='" . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>&nbsp;";
0 ignored issues
show
Bug introduced by
The property configs does not seem to exist on XoopsFormDhtmlTextArea.
Loading history...
169
        $ret .= "<br>\n";
170
        // the textarea box
171
        $ret .= "<textarea id='" . $element->getName() . "' name='" . $element->getName() . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName() . "');\" onclick=\"xoopsSavePosition('" . $element->getName() . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='" . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra() . '>' . $element->getValue() . "</textarea><br>\n";
172
173
        if (empty($element->skipPreview)) {
174
            if (empty($GLOBALS['xoTheme'])) {
175
                $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

175
                $element->js .= implode('', /** @scrutinizer ignore-type */ file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
Loading history...
176
            } else {
177
                $GLOBALS['xoTheme']->addScript('/class/textsanitizer/image/image.js', array('type' => 'text/javascript'));
178
            }
179
            $button = "<button type='button' class='btn btn-primary' onclick=\"form_instantPreview('" . XOOPS_URL . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)$element->doHtml . ", '" . $GLOBALS['xoopsSecurity']->createToken() . "')\" title='" . _PREVIEW . "'>" . _PREVIEW . "</button>";
180
181
            $ret .= '<br>' . "<div id='" . $element->getName() . "_hidden' style='display: block;'> " . '   <fieldset>' . '       <legend>' . $button . '</legend>' . "       <div id='" . $element->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT . '</div>' . '   </fieldset>' . '</div>';
182
        }
183
        // Load javascript
184
        if (empty($js_loaded)) {
185
            $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '') . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
186
            $ret        = $javascript . $ret;
187
            $js_loaded  = true;
188
        }
189
190
        return $ret;
191
    }
192
193
    /**
194
     * Render xoopscode buttons for editor, include calling text sanitizer extensions
195
     *
196
     * @param XoopsFormDhtmlTextArea $element form element
197
     *
198
     * @return string rendered buttons for xoopscode assistance
199
     */
200
    protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element)
201
    {
202
        $textarea_id = $element->getName();
203
        $code = '';
204
        $code .= '<a name="moresmiley"></a>';
205
        $code .= "<button type='button' class='btn btn-default' 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>";
206
        $code .= "<button type='button' class='btn btn-default' 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>";
207
        $code .= "<button type='button' class='btn btn-default' 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>";
208
        $code .= "<button type='button' class='btn btn-default' 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><span style='font-size:75%;'> Manager</span></button>";
209
        $code .= "<button type='button' class='btn btn-default' 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>";
210
211
        $myts        = MyTextSanitizer::getInstance();
212
213
        $extensions = array_filter($myts->config['extensions']);
214
        foreach (array_keys($extensions) as $key) {
215
            $extension = $myts->loadExtension($key);
216
            @list($encode, $js) = $extension->encode($textarea_id);
217
            if (empty($encode)) {
218
                continue;
219
            }
220
            $code .= $encode;
221
            if (!empty($js)) {
222
                $element->js .= $js;
223
            }
224
        }
225
        $code .= "<button type='button' class='btn btn-default' 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>";
226
        $code .= "<button type='button' class='btn btn-default' 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>";
227
228
        $xoopsPreload = XoopsPreload::getInstance();
229
        $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
230
231
        return $code;
232
    }
233
234
    /**
235
     * Render typography controls for editor (font, size, color)
236
     *
237
     * @param XoopsFormDhtmlTextArea $element form element
238
     *
239
     * @return string rendered typography controls
240
     */
241
    protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element)
242
    {
243
        $textarea_id = $element->getName();
244
        $hiddentext  = $element->_hiddenText;
245
        $fontStr = "<script type=\"text/javascript\">" . "var _editor_dialog = ''" . "+ '<select class=\"input-sm form-control\" id=\'{$textarea_id}Size\' onchange=\'xoopsSetElementAttribute(\"size\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'SIZE\'>" . _SIZE . "</option>'";
246
247
        foreach ($GLOBALS['formtextdhtml_sizes'] as $_val => $_name) {
248
            $fontStr .= " + '<option value=\'{$_val}\'>{$_name}</option>'";
249
        }
250
        $fontStr .= " + '</select> '";
251
        $fontStr .= "+ '<select class=\"input-sm form-control\" id=\'{$textarea_id}Font\' onchange=\'xoopsSetElementAttribute(\"font\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'FONT\'>" . _FONT . "</option>'";
252
        $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array(
253
            'Arial',
254
            'Courier',
255
            'Georgia',
256
            'Helvetica',
257
            'Impact',
258
            'Verdana',
259
            'Haettenschweiler');
260
        foreach ($fontarray as $font) {
261
            $fontStr .= " + '<option value=\'{$font}\'>{$font}</option>'";
262
        }
263
        $fontStr .= " + '</select> '";
264
        $fontStr .= "+ '<select class=\"input-sm form-control\" id=\'{$textarea_id}Color\' onchange=\'xoopsSetElementAttribute(\"color\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\'>'" . "+ '<option value=\'COLOR\'>" . _COLOR . "</option>';" . "var _color_array = new Array('00', '33', '66', '99', 'CC', 'FF');
265
                for (var i = 0; i < _color_array.length; i ++) {
266
                    for (var j = 0; j < _color_array.length; j ++) {
267
                        for (var k = 0; k < _color_array.length; k ++) {
268
                            var _color_ele = _color_array[i] + _color_array[j] + _color_array[k];
269
                            _editor_dialog += '<option value=\''+_color_ele+'\' style=\'background-color:#'+_color_ele+';color:#'+_color_ele+';\'>#'+_color_ele+'</option>';
270
                        }
271
                    }
272
                }
273
                _editor_dialog += '</select>'";
274
        $fontStr .= ";";
275
        $fontStr .= 'document.write(_editor_dialog); </script>';
276
277
        $styleStr  = "<button type='button' class='btn btn-default' onclick='xoopsMakeBold(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_BOLD . "' aria-label='Left Align'><span class='fa fa-bold' aria-hidden='true'></span></button>";
278
        $styleStr .= "<button type='button' class='btn btn-default' onclick='xoopsMakeItalic(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_ITALIC . "' aria-label='Left Align'><span class='fa fa-italic' aria-hidden='true'></span></button>";
279
        $styleStr .= "<button type='button' class='btn btn-default' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_UNDERLINE . "' aria-label='Left Align'>" . '<span class="fa fa-underline"></span></button>';
280
        $styleStr .= "<button type='button' class='btn btn-default' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LINETHROUGH . "' aria-label='Left Align'>" . '<span class="fa fa-strikethrough"></span></button>';
281
282
        $alignStr  = "<button type='button' class='btn btn-default' 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>";
283
        $alignStr .= "<button type='button' class='btn btn-default' 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>";
284
        $alignStr .= "<button type='button' class='btn btn-default' 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>";
285
286
        $fontStr .= "<br>\n{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
287
        return $fontStr;
288
    }
289
290
    /**
291
     * Render support for XoopsFormElementTray
292
     *
293
     * @param XoopsFormElementTray $element form element
294
     *
295
     * @return string rendered form element
296
     */
297
    public function renderFormElementTray(XoopsFormElementTray $element)
298
    {
299
        $count = 0;
300
        $ret   = '';
301
        foreach ($element->getElements() as $ele) {
302
            if ($count > 0) {
303
                $ret .= $element->getDelimeter();
304
            }
305
            if ($ele->getCaption() != '') {
306
                $ret .= $ele->getCaption() . '&nbsp;';
307
            }
308
            $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...
309
            if (!$ele->isHidden()) {
310
                ++$count;
311
            }
312
        }
313
        return $ret;
314
    }
315
316
    /**
317
     * Render support for XoopsFormFile
318
     *
319
     * @param XoopsFormFile $element form element
320
     *
321
     * @return string rendered form element
322
     */
323
    public function renderFormFile(XoopsFormFile $element)
324
    {
325
        return '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '" />'
326
            . '<input type="file" name="' . $element->getName() . '" id="' . $element->getName() . '" title="'
327
            . $element->getTitle() . '" ' . $element->getExtra() . ' />'
328
            . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="' . $element->getName()
329
            . '" />';
330
331
    }
332
333
    /**
334
     * Render support for XoopsFormLabel
335
     *
336
     * @param XoopsFormLabel $element form element
337
     *
338
     * @return string rendered form element
339
     */
340
    public function renderFormLabel(XoopsFormLabel $element)
341
    {
342
        return $element->getValue();
343
    }
344
345
    /**
346
     * Render support for XoopsFormPassword
347
     *
348
     * @param XoopsFormPassword $element form element
349
     *
350
     * @return string rendered form element
351
     */
352
    public function renderFormPassword(XoopsFormPassword $element)
353
    {
354
        return '<input type="password" name="' . $element->getName() . '" id="' . $element->getName() . '" size="'
355
            . $element->getSize() . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue()
356
            . '"' . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>';
357
    }
358
359
    /**
360
     * Render support for XoopsFormRadio
361
     *
362
     * @param XoopsFormRadio $element form element
363
     *
364
     * @return string rendered form element
365
     */
366
    public function renderFormRadio(XoopsFormRadio $element)
367
    {
368
        $ret           = '';
369
        $ele_name      = $element->getName();
370
        $ele_title     = $element->getTitle();
371
        $ele_value     = $element->getValue();
372
        $ele_options   = $element->getOptions();
373
        $ele_extra     = $element->getExtra();
374
        $ele_delimiter = empty($element->columns) ? $element->getDelimeter() : '';
375
        if (!empty($element->columns)) {
376
            $ret .= '<table><tr>';
377
        }
378
        $i      = 0;
379
        $id_ele = 0;
380
        foreach ($ele_options as $value => $name) {
381
            ++$id_ele;
382
            if (!empty($element->columns)) {
383
                if ($i % $element->columns == 0) {
384
                    $ret .= '<tr>';
385
                }
386
                $ret .= '<td>';
387
            }
388
389
            $ret .= '<input type="radio" name="' . $ele_name . '" id="' . $ele_name . $id_ele
390
                . '" title = "' . htmlspecialchars($ele_title, ENT_QUOTES) . '" value="'
391
                . htmlspecialchars($value, ENT_QUOTES) . '"';
392
            if (isset($ele_value) && $value == $ele_value) {
393
                $ret .= ' checked';
394
            }
395
            $ret .= $ele_extra . ' />' . "<label name='xolb_{$ele_name}' for='" . $ele_name . $id_ele
396
                . "'>" . $name . '</label>' . $ele_delimiter;
397
            if (!empty($element->columns)) {
398
                $ret .= '</td>';
399
                if (++$i % $element->columns == 0) {
400
                    $ret .= '</tr>';
401
                }
402
            }
403
        }
404
        if (!empty($element->columns)) {
405
            if ($span = $i % $element->columns) {
406
                $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>';
407
            }
408
            $ret .= '</table>';
409
        }
410
411
        return $ret;
412
    }
413
414
    /**
415
     * Render support for XoopsFormSelect
416
     *
417
     * @param XoopsFormSelect $element form element
418
     *
419
     * @return string rendered form element
420
     */
421
    public function renderFormSelect(XoopsFormSelect $element)
422
    {
423
        $ele_name    = $element->getName();
424
        $ele_title   = $element->getTitle();
425
        $ele_value   = $element->getValue();
426
        $ele_options = $element->getOptions();
427
        $ret = '<select size="' . $element->getSize() . '"' . $element->getExtra();
428
        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...
429
            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title
430
                . '" multiple="multiple">';
431
        } else {
432
            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
433
        }
434
        foreach ($ele_options as $value => $name) {
435
            $ret .= '<option value="' . htmlspecialchars($value, ENT_QUOTES) . '"';
436
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
437
                $ret .= ' selected';
438
            }
439
            $ret .= '>' . $name . '</option>';
440
        }
441
        $ret .= '</select>';
442
443
        return $ret;
444
    }
445
446
    /**
447
     * Render support for XoopsFormText
448
     *
449
     * @param XoopsFormText $element form element
450
     *
451
     * @return string rendered form element
452
     */
453
    public function renderFormText(XoopsFormText $element)
454
    {
455
        return "<input type='text' name='" . $element->getName() . "' title='" . $element->getTitle()
456
            . "' id='" . $element->getName() . "' size='" . $element->getSize() . "' maxlength='"
457
            . $element->getMaxlength() . "' value='" . $element->getValue() . "'" . $element->getExtra()
458
            . ' />';
459
    }
460
461
    /**
462
     * Render support for XoopsFormTextArea
463
     *
464
     * @param XoopsFormTextArea $element form element
465
     *
466
     * @return string rendered form element
467
     */
468
    public function renderFormTextArea(XoopsFormTextArea $element)
469
    {
470
        return "<textarea name='" . $element->getName() . "' id='" . $element->getName() . "'  title='"
471
            . $element->getTitle() . "' rows='" . $element->getRows() . "' cols='" . $element->getCols()
472
            . "'" . $element->getExtra() . '>' . $element->getValue() . '</textarea>';
473
    }
474
475
    /**
476
     * Render support for XoopsFormTextDateSelect
477
     *
478
     * @param XoopsFormTextDateSelect $element form element
479
     *
480
     * @return string rendered form element
481
     */
482
    public function renderFormTextDateSelect(XoopsFormTextDateSelect $element)
483
    {
484
        static $included = false;
485
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) {
486
            include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php';
487
        } else {
488
            include_once XOOPS_ROOT_PATH . '/language/english/calendar.php';
489
        }
490
491
        $ele_name  = $element->getName();
492
        $ele_value = $element->getValue(false);
493
        if (is_string($ele_value)) {
0 ignored issues
show
introduced by
The condition is_string($ele_value) is always true.
Loading history...
494
            $display_value = $ele_value;
495
            $ele_value     = time();
496
        } else {
497
            $display_value = date(_SHORTDATESTRING, $ele_value);
498
        }
499
500
        $jstime = formatTimestamp($ele_value, _SHORTDATESTRING);
501
        if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) {
502
            $GLOBALS['xoTheme']->addScript('include/calendar.js');
503
            $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css');
504
            if (!$included) {
505
                $included = true;
506
                $GLOBALS['xoTheme']->addScript('', '', '
507
                    var calendar = null;
508
509
                    function selected(cal, date)
510
                    {
511
                    cal.sel.value = date;
512
                    }
513
514
                    function closeHandler(cal)
515
                    {
516
                    cal.hide();
517
                    Calendar.removeEvent(document, "mousedown", checkCalendar);
518
                    }
519
520
                    function checkCalendar(ev)
521
                    {
522
                    var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
523
                    for (; el != null; el = el.parentNode)
524
                    if (el == calendar.element || el.tagName == "A") break;
525
                    if (el == null) {
526
                    calendar.callCloseHandler(); Calendar.stopEvent(ev);
527
                    }
528
                    }
529
                    function showCalendar(id)
530
                    {
531
                    var el = xoopsGetElementById(id);
532
                    if (calendar != null) {
533
                    calendar.hide();
534
                    } else {
535
                    var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler);
536
                    calendar = cal;
537
                    cal.setRange(1900, 2100);
538
                    calendar.create();
539
                    }
540
                    calendar.sel = el;
541
                    calendar.parseDate(el.value);
542
                    calendar.showAtElement(el);
543
                    Calendar.addEvent(document, "mousedown", checkCalendar);
544
545
                    return false;
546
                    }
547
548
                    Calendar._DN = new Array
549
                    ("' . _CAL_SUNDAY . '",
550
                    "' . _CAL_MONDAY . '",
551
                    "' . _CAL_TUESDAY . '",
552
                    "' . _CAL_WEDNESDAY . '",
553
                    "' . _CAL_THURSDAY . '",
554
                    "' . _CAL_FRIDAY . '",
555
                    "' . _CAL_SATURDAY . '",
556
                    "' . _CAL_SUNDAY . '");
557
                    Calendar._MN = new Array
558
                    ("' . _CAL_JANUARY . '",
559
                    "' . _CAL_FEBRUARY . '",
560
                    "' . _CAL_MARCH . '",
561
                    "' . _CAL_APRIL . '",
562
                    "' . _CAL_MAY . '",
563
                    "' . _CAL_JUNE . '",
564
                    "' . _CAL_JULY . '",
565
                    "' . _CAL_AUGUST . '",
566
                    "' . _CAL_SEPTEMBER . '",
567
                    "' . _CAL_OCTOBER . '",
568
                    "' . _CAL_NOVEMBER . '",
569
                    "' . _CAL_DECEMBER . '");
570
571
                    Calendar._TT = {};
572
                    Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '";
573
                    Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '";
574
                    Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '";
575
                    Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '";
576
                    Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '";
577
                    Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '";
578
                    Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '";
579
                    Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '";
580
                    Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')";
581
                    Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '";
582
                    Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '";
583
                    Calendar._TT["CLOSE"] = "' . _CLOSE . '";
584
                    Calendar._TT["TODAY"] = "' . _CAL_TODAY . '";
585
586
                    // date formats
587
                    Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
588
                    Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
589
590
                    Calendar._TT["WK"] = "";
591
                ');
592
            }
593
        }
594
        return '<input type="text" name="' . $ele_name . '" id="' . $ele_name . '" size="'
595
            . $element->getSize() . '" maxlength="' . $element->getMaxlength() . '" value="'
596
            . $display_value . '"' . $element->getExtra()
597
            . ' /><input type="reset" value=" ... " onclick="return showCalendar(\'' . $ele_name
598
            . '\');">';
599
        /*
600
        return "<input type='text' name='" . $ele_name . "' id='" . $ele_name . "' size='"
601
            . $element->getSize() . "' maxlength='" . $element->getMaxlength() . "' value='"
602
            . $display_value . "'" . $element->getExtra()
603
            . " /><input type='reset' value=' ... ' onclick='return showCalendar(\"" . $ele_name
604
            . "\");'>";
605
        */
606
    }
607
608
    /**
609
     * Render support for XoopsThemeForm
610
     *
611
     * @param XoopsThemeForm $form form to render
612
     *
613
     * @return string rendered form
614
     */
615
    public function renderThemeForm(XoopsThemeForm $form)
616
    {
617
        $ele_name = $form->getName();
618
        $ret      = '<form name="' . $ele_name . '" id="' . $ele_name . '" action="' . $form->getAction() . '" method="' . $form->getMethod() . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>
619
            <table width="100%" class="outer" cellspacing="1">
620
            <tr><th colspan="2">' . $form->getTitle() . '</th></tr>
621
        ';
622
        $hidden   = '';
623
        $class    = 'even';
624
        foreach ($form->getElements() as $ele) {
625
            if (!is_object($ele)) {
626
                $ret .= $ele;
627
            } elseif (!$ele->isHidden()) {
628
                if (!$ele->getNocolspan()) {
0 ignored issues
show
Deprecated Code introduced by
The function XoopsFormElement::getNocolspan() has been deprecated: PLEASE AVOID USING THIS METHOD ( Ignorable by Annotation )

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

628
                if (!/** @scrutinizer ignore-deprecated */ $ele->getNocolspan()) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
629
                    $ret .= '<tr valign="top" align="left"><td class="head">';
630
                    if (($caption = $ele->getCaption()) != '') {
631
                        $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">';
632
                        $ret .= '<span class="caption-text">' . $caption . '</span>';
633
                        $ret .= '<span class="caption-marker">*</span>';
634
                        $ret .= '</div>';
635
                    }
636
                    if (($desc = $ele->getDescription()) != '') {
637
                        $ret .= '<div class="xoops-form-element-help">' . $desc . '</div>';
638
                    }
639
                    $ret .= '</td><td class="' . $class . '">' . $ele->render() . '</td></tr>' . 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...
640
                } else {
641
                    $ret .= '<tr valign="top" align="left"><td class="head" colspan="2">';
642
                    if (($caption = $ele->getCaption()) != '') {
643
                        $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">';
644
                        $ret .= '<span class="caption-text">' . $caption . '</span>';
645
                        $ret .= '<span class="caption-marker">*</span>';
646
                        $ret .= '</div>';
647
                    }
648
                    $ret .= '</td></tr><tr valign="top" align="left"><td class="' . $class . '" colspan="2">' . $ele->render() . '</td></tr>';
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...
649
                }
650
            } else {
651
                $hidden .= $ele->render();
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...
652
            }
653
        }
654
        $ret .= '</table>' . NWLINE . ' ' . $hidden . '</form>' . NWLINE;
655
        $ret .= $form->renderValidationJS(true);
656
657
        return $ret;
658
    }
659
660
    /**
661
     * Support for themed addBreak
662
     *
663
     * @param XoopsThemeForm $form
664
     * @param string         $extra pre-rendered content for break row
665
     * @param string         $class class for row
666
     *
667
     * @return void
668
     */
669
    public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class)
670
    {
671
        $class = ($class != '') ? " class='" . preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) . "'" : '';
672
        // Fix for $extra tag not showing
673
        if ($extra) {
674
            $extra = '<tr><td colspan="2" ' . $class . '>' . $extra . '</td></tr>';
675
            $form->addElement($extra);
676
        } else {
677
            $extra = '<tr><td colspan="2" ' . $class . '>&nbsp;</td></tr>';
678
            $form->addElement($extra);
679
        }
680
    }
681
}
682