Issues (3083)

xoopsform/renderer/XoopsFormRendererLegacy.php (5 issues)

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-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 XoopsFormRendererLegacy 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='formButton' name='" . $element->getName()
33
            . "'  id='" . $element->getName() . "' value='" . $element->getValue() . "' title='"
34
            . $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="formbutton" name="delete" id="delete" value="' . _DELETE
49
                . '" onclick="this.form.elements.op.value=\'delete\'">&nbsp;';
50
        }
51
        $ret .= '<input type="button" value="' . _CANCEL . '" onClick="history.go(-1);return true;" />&nbsp;'
52
            . '<input type="reset" class="formbutton"  name="reset"  id="reset" value="' . _RESET . '" />&nbsp;'
53
            . '<input type="' . $element->getType() . '" class="formbutton"  name="' . $element->getName()
54
            . '" id="' . $element->getName() . '" value="' . $element->getValue() . '"' . $element->getExtra()
55
            . ' />';
56
57
        return $ret;
58
    }
59
60
    /**
61
     * Render support for XoopsFormCheckBox
62
     *
63
     * @param XoopsFormCheckBox $element form element
64
     *
65
     * @return string rendered form element
66
     */
67
    public function renderFormCheckBox(XoopsFormCheckBox $element)
68
    {
69
        $ele_name      = $element->getName();
70
        $ele_title     = $element->getTitle();
71
        $ele_id        = $ele_name;
72
        $ele_value     = $element->getValue();
73
        $ele_options   = $element->getOptions();
74
        $ele_extra     = $element->getExtra();
75
        $ele_delimiter = empty($element->columns) ? $element->getDelimeter() : '';
76
77
        if (count($ele_options) > 1 && substr($ele_name, -2, 2) !== '[]') {
78
            $ele_name .= '[]';
79
            $element->setName($ele_name);
80
        }
81
        $ret = '';
82
        /*<label class="checkbox-inline">
83
          <input type="checkbox" id="inlineCheckbox1" value="option1"> 1
84
        </label>*/
85
        if (!empty($element->columns)) {
86
            $ret .= '<table><tr>';
87
        }
88
        $i      = 0;
89
        $id_ele = 0;
90
        foreach ($ele_options as $value => $name) {
91
            ++$id_ele;
92
            if (!empty($element->columns)) {
93
                if ($i % $element->columns == 0) {
94
                    $ret .= '<tr>';
95
                }
96
                $ret .= '<td>';
97
            }
98
            // $name may be a link, should we use $name in the title tag?
99
            $ret .= '<input type="checkbox" name="' . $ele_name . '" id="' . $ele_id .$id_ele . '" '
100
                . ' title="' . $ele_title . '" value="' . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . '"';
101
102
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
103
                $ret .= ' checked';
104
            }
105
            $ret .= $ele_extra . ' />' . '<label name="xolb_' . $ele_name . '" for="'
106
            . $ele_id . $id_ele . '" >' . $name . '</label>' . $ele_delimiter;
107
108
109
            if (!empty($element->columns)) {
110
                $ret .= '</td>';
111
                if (++$i % $element->columns == 0) {
112
                    $ret .= '</tr>';
113
                }
114
            }
115
        }
116
        if (!empty($element->columns)) {
117
            if ($span = $i % $element->columns) {
118
                $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>';
119
            }
120
            $ret .= '</table>';
121
        }
122
123
        return $ret;
124
    }
125
126
    /**
127
     * Render support for XoopsFormColorPicker
128
     *
129
     * @param XoopsFormColorPicker $element form element
130
     *
131
     * @return string rendered form element
132
     */
133
    public function renderFormColorPicker(XoopsFormColorPicker $element)
134
    {
135
        if (isset($GLOBALS['xoTheme'])) {
136
            $GLOBALS['xoTheme']->addScript("browse.php?Frameworks/jquery/jquery.js");
137
            $GLOBALS['xoTheme']->addScript('include/spectrum.js');
138
            $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css');
139
        } else {
140
            echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>';
141
            echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">';
142
        }
143
        return "<input type='color' name='" . $element->getName() . "' title='" . $element->getTitle()
144
            . "' id='" . $element->getName() . "' size='" . $element->getSize() . "' maxlength='"
145
            . $element->getMaxlength() . "' value='" . $element->getValue() . "'" . $element->getExtra()
146
            . ' />';
147
    }
148
149
    /**
150
     * Render support for XoopsFormDhtmlTextArea
151
     *
152
     * @param XoopsFormDhtmlTextArea $element form element
153
     *
154
     * @return string rendered form element
155
     */
156
    public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element)
157
    {
158
        xoops_loadLanguage('formdhtmltextarea');
159
        $ret = '';
160
        // actions
161
        $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n";
162
        // fonts
163
        $ret .= $this->renderFormDhtmlTATypography($element);
164
        // length checker
165
        $maxlength = isset($element->configs['maxlength']) ? $element->configs['maxlength'] : 0;
0 ignored issues
show
The property configs does not seem to exist on XoopsFormDhtmlTextArea.
Loading history...
166
        $ret .= "<button type='button' class='btn btn-default' onclick=\"XoopsCheckLength('" . $element->getName() . "', '" . $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;";
167
        $ret .= "<br>\n";
168
        // the textarea box
169
        $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";
170
171
        if (empty($element->skipPreview)) {
172
            if (empty($GLOBALS['xoTheme'])) {
173
                $element->js .= implode('', file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
174
            } else {
175
                $GLOBALS['xoTheme']->addScript('/class/textsanitizer/image/image.js', array('type' => 'text/javascript'));
176
            }
177
            $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>";
178
179
            $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>';
180
        }
181
        // Load javascript
182
        $javascript_file = XOOPS_URL . '/include/formdhtmltextarea.js';
183
        $javascript_file_element = 'include_formdhtmltextarea_js';
184
        $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '');
185
        $javascript .= <<<EOJS
186
<script>
187
    var el = document.getElementById('{$javascript_file_element}');
188
    if (el === null) {
189
        var xformtag = document.createElement('script');
190
        xformtag.id = '{$javascript_file_element}';
191
        xformtag.type = 'text/javascript';
192
        xformtag.src = '{$javascript_file}';
193
        document.body.appendChild(xformtag);
194
    }
195
</script>
196
EOJS;
197
198
        return $javascript . $ret;
199
    }
200
201
    /**
202
     * Render xoopscode buttons for editor, include calling text sanitizer extensions
203
     *
204
     * @param XoopsFormDhtmlTextArea $element form element
205
     *
206
     * @return string rendered buttons for xoopscode assistance
207
     */
208
    protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element)
209
    {
210
        $textarea_id = $element->getName();
211
        $code = '';
212
        $code .= '<a name="moresmiley"></a>';
213
        $code .= "<button type='button' class='btn btn-default' 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>";
214
        $code .= "<button type='button' class='btn btn-default' 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>";
215
        $code .= "<button type='button' class='btn btn-default' 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>";
216
        $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>";
217
        $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>";
218
219
        $myts        = \MyTextSanitizer::getInstance();
220
221
        $extensions = array_filter($myts->config['extensions']);
222
        foreach (array_keys($extensions) as $key) {
223
            $extension = $myts->loadExtension($key);
224
            @list($encode, $js) = $extension->encode($textarea_id);
225
            if (empty($encode)) {
226
                continue;
227
            }
228
            $code .= $encode;
229
            if (!empty($js)) {
230
                $element->js .= $js;
231
            }
232
        }
233
        $code .= "<button type='button' class='btn btn-default' 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>";
234
        $code .= "<button type='button' class='btn btn-default' 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>";
235
236
        $xoopsPreload = XoopsPreload::getInstance();
237
        $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
238
239
        return $code;
240
    }
241
242
    /**
243
     * Render typography controls for editor (font, size, color)
244
     *
245
     * @param XoopsFormDhtmlTextArea $element form element
246
     *
247
     * @return string rendered typography controls
248
     */
249
    protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element)
250
    {
251
        $textarea_id = $element->getName();
252
        $hiddentext  = $element->_hiddenText;
253
        $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}\");\' onfocusout=\'this.selectedIndex=0;\'>'" . "+ '<option value=\'SIZE\'>" . _SIZE . "</option>'";
254
255
        foreach ($GLOBALS['formtextdhtml_sizes'] as $_val => $_name) {
256
            $fontStr .= " + '<option value=\'{$_val}\'>{$_name}</option>'";
257
        }
258
        $fontStr .= " + '</select> '";
259
        $fontStr .= "+ '<select class=\"input-sm form-control\" id=\'{$textarea_id}Font\' onchange=\'xoopsSetElementAttribute(\"font\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\' onfocusout=\'this.selectedIndex=0;\'>'" . "+ '<option value=\'FONT\'>" . _FONT . "</option>'";
260
        $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array(
261
            'Arial',
262
            'Courier',
263
            'Georgia',
264
            'Helvetica',
265
            'Impact',
266
            'Verdana',
267
            'Haettenschweiler');
268
        foreach ($fontarray as $font) {
269
            $fontStr .= " + '<option value=\'{$font}\'>{$font}</option>'";
270
        }
271
        $fontStr .= " + '</select> '";
272
        $fontStr .= "+ '<select class=\"input-sm form-control\" id=\'{$textarea_id}Color\' onchange=\'xoopsSetElementAttribute(\"color\", this.options[this.selectedIndex].value, \"{$textarea_id}\", \"{$hiddentext}\");\' onfocusout=\'this.selectedIndex=0;\'>'" . "+ '<option value=\'COLOR\'>" . _COLOR . "</option>';" . "var _color_array = new Array('00', '33', '66', '99', 'CC', 'FF');
273
                for (var i = 0; i < _color_array.length; i ++) {
274
                    for (var j = 0; j < _color_array.length; j ++) {
275
                        for (var k = 0; k < _color_array.length; k ++) {
276
                            var _color_ele = _color_array[i] + _color_array[j] + _color_array[k];
277
                            _editor_dialog += '<option value=\''+_color_ele+'\' style=\'background-color:#'+_color_ele+';color:#'+_color_ele+';\'>#'+_color_ele+'</option>';
278
                        }
279
                    }
280
                }
281
                _editor_dialog += '</select>'";
282
        $fontStr .= ";";
283
        $fontStr .= 'document.write(_editor_dialog); </script>';
284
285
        $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>";
286
        $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>";
287
        $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>';
288
        $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>';
289
290
        $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>";
291
        $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>";
292
        $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>";
293
294
        $fontStr .= "<br>\n{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
295
        return $fontStr;
296
    }
297
298
    /**
299
     * Render support for XoopsFormElementTray
300
     *
301
     * @param XoopsFormElementTray $element form element
302
     *
303
     * @return string rendered form element
304
     */
305
    public function renderFormElementTray(XoopsFormElementTray $element)
306
    {
307
        $count = 0;
308
        $isVertical = (\XoopsFormElementTray::ORIENTATION_VERTICAL === $element->getOrientation());
309
        $ret   = '';
310
        foreach ($element->getElements() as $ele) {
311
            if ($count > 0) {
312
                $ret .= $element->getDelimeter();
313
                if ($isVertical) {
314
                    $ret .= '<br>';
315
                }
316
            }
317
            if ($ele->getCaption() != '') {
318
                $ret .= $ele->getCaption() . '&nbsp;';
319
            }
320
            $ret .= $ele->render() . NWLINE;
0 ignored issues
show
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...
321
            if (!$ele->isHidden()) {
322
                ++$count;
323
            }
324
        }
325
        return $ret;
326
    }
327
328
    /**
329
     * Render support for XoopsFormFile
330
     *
331
     * @param XoopsFormFile $element form element
332
     *
333
     * @return string rendered form element
334
     */
335
    public function renderFormFile(XoopsFormFile $element)
336
    {
337
        return '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '" />'
338
            . '<input type="file" name="' . $element->getName() . '" id="' . $element->getName() . '" title="'
339
            . $element->getTitle() . '" ' . $element->getExtra() . ' />'
340
            . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="' . $element->getName()
341
            . '" />';
342
343
    }
344
345
    /**
346
     * Render support for XoopsFormLabel
347
     *
348
     * @param XoopsFormLabel $element form element
349
     *
350
     * @return string rendered form element
351
     */
352
    public function renderFormLabel(XoopsFormLabel $element)
353
    {
354
        return $element->getValue();
355
    }
356
357
    /**
358
     * Render support for XoopsFormPassword
359
     *
360
     * @param XoopsFormPassword $element form element
361
     *
362
     * @return string rendered form element
363
     */
364
    public function renderFormPassword(XoopsFormPassword $element)
365
    {
366
        return '<input type="password" name="' . $element->getName() . '" id="' . $element->getName() . '" size="'
367
            . $element->getSize() . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue()
368
            . '"' . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>';
369
    }
370
371
    /**
372
     * Render support for XoopsFormRadio
373
     *
374
     * @param XoopsFormRadio $element form element
375
     *
376
     * @return string rendered form element
377
     */
378
    public function renderFormRadio(XoopsFormRadio $element)
379
    {
380
        $ret           = '';
381
        $ele_name      = $element->getName();
382
        $ele_title     = $element->getTitle();
383
        $ele_value     = $element->getValue();
384
        $ele_options   = $element->getOptions();
385
        $ele_extra     = $element->getExtra();
386
        $ele_delimiter = empty($element->columns) ? $element->getDelimeter() : '';
387
        if (!empty($element->columns)) {
388
            $ret .= '<table><tr>';
389
        }
390
        $i      = 0;
391
        $id_ele = 0;
392
        foreach ($ele_options as $value => $name) {
393
            ++$id_ele;
394
            if (!empty($element->columns)) {
395
                if ($i % $element->columns == 0) {
396
                    $ret .= '<tr>';
397
                }
398
                $ret .= '<td>';
399
            }
400
401
            $ret .= '<input type="radio" name="' . $ele_name . '" id="' . $ele_name . $id_ele
402
                . '" title = "' . htmlspecialchars($ele_title, ENT_QUOTES | ENT_HTML5) . '" value="'
403
                . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . '"';
404
            if (isset($ele_value) && $value == $ele_value) {
405
                $ret .= ' checked';
406
            }
407
            $ret .= $ele_extra . ' />' . "<label name='xolb_{$ele_name}' for='" . $ele_name . $id_ele
408
                . "'>" . $name . '</label>' . $ele_delimiter;
409
            if (!empty($element->columns)) {
410
                $ret .= '</td>';
411
                if (++$i % $element->columns == 0) {
412
                    $ret .= '</tr>';
413
                }
414
            }
415
        }
416
        if (!empty($element->columns)) {
417
            if ($span = $i % $element->columns) {
418
                $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>';
419
            }
420
            $ret .= '</table>';
421
        }
422
423
        return $ret;
424
    }
425
426
    /**
427
     * Render support for XoopsFormSelect
428
     *
429
     * @param XoopsFormSelect $element form element
430
     *
431
     * @return string rendered form element
432
     */
433
    public function renderFormSelect(XoopsFormSelect $element)
434
    {
435
        $ele_name    = $element->getName();
436
        $ele_title   = $element->getTitle();
437
        $ele_value   = $element->getValue();
438
        $ele_options = $element->getOptions();
439
        $ret = '<select size="' . $element->getSize() . '"' . $element->getExtra();
440
        if ($element->isMultiple() != false) {
441
            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title
442
                . '" multiple="multiple">';
443
        } else {
444
            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
445
        }
446
        foreach ($ele_options as $value => $name) {
447
            $ret .= '<option value="' . htmlspecialchars($value, ENT_QUOTES | ENT_HTML5) . '"';
448
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
449
                $ret .= ' selected';
450
            }
451
            $ret .= '>' . $name . '</option>';
452
        }
453
        $ret .= '</select>';
454
455
        return $ret;
456
    }
457
458
    /**
459
     * Render support for XoopsFormText
460
     *
461
     * @param XoopsFormText $element form element
462
     *
463
     * @return string rendered form element
464
     */
465
    public function renderFormText(XoopsFormText $element)
466
    {
467
        return "<input type='text' name='" . $element->getName() . "' title='" . $element->getTitle()
468
            . "' id='" . $element->getName() . "' size='" . $element->getSize() . "' maxlength='"
469
            . $element->getMaxlength() . "' value='" . $element->getValue() . "'" . $element->getExtra()
470
            . ' />';
471
    }
472
473
    /**
474
     * Render support for XoopsFormTextArea
475
     *
476
     * @param XoopsFormTextArea $element form element
477
     *
478
     * @return string rendered form element
479
     */
480
    public function renderFormTextArea(XoopsFormTextArea $element)
481
    {
482
        return "<textarea name='" . $element->getName() . "' id='" . $element->getName() . "'  title='"
483
            . $element->getTitle() . "' rows='" . $element->getRows() . "' cols='" . $element->getCols()
484
            . "'" . $element->getExtra() . '>' . $element->getValue() . '</textarea>';
485
    }
486
487
    /**
488
     * Render support for XoopsFormTextDateSelect
489
     *
490
     * @param XoopsFormTextDateSelect $element form element
491
     *
492
     * @return string rendered form element
493
     */
494
    public function renderFormTextDateSelect(XoopsFormTextDateSelect $element)
495
    {
496
        static $included = false;
497
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) {
498
            include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php';
499
        } else {
500
            include_once XOOPS_ROOT_PATH . '/language/english/calendar.php';
501
        }
502
503
        $ele_name  = $element->getName();
504
        $ele_value = $element->getValue(false);
505
        if (is_string($ele_value)) {
506
            $display_value = $ele_value;
507
            $ele_value     = time();
508
        } else {
509
            $display_value = date(_SHORTDATESTRING, $ele_value);
510
        }
511
512
        $jstime = formatTimestamp($ele_value, 'm/d/Y');
513
        if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) {
514
            $GLOBALS['xoTheme']->addScript('include/calendar.js');
515
            $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css');
516
            if (!$included) {
517
                $included = true;
518
                $GLOBALS['xoTheme']->addScript('', '', '
519
                    var calendar = null;
520
521
                    function selected(cal, date)
522
                    {
523
                    cal.sel.value = date;
524
                    }
525
526
                    function closeHandler(cal)
527
                    {
528
                    cal.hide();
529
                    Calendar.removeEvent(document, "mousedown", checkCalendar);
530
                    }
531
532
                    function checkCalendar(ev)
533
                    {
534
                    var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
535
                    for (; el != null; el = el.parentNode)
536
                    if (el == calendar.element || el.tagName == "A") break;
537
                    if (el == null) {
538
                    calendar.callCloseHandler(); Calendar.stopEvent(ev);
539
                    }
540
                    }
541
                    function showCalendar(id)
542
                    {
543
                    var el = xoopsGetElementById(id);
544
                    if (calendar != null) {
545
                    calendar.hide();
546
                    } else {
547
                    var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler);
548
                    calendar = cal;
549
                    cal.setRange(1900, 2100);
550
                    calendar.create();
551
                    }
552
                    calendar.sel = el;
553
                    calendar.parseDate(el.value);
554
                    calendar.showAtElement(el);
555
                    Calendar.addEvent(document, "mousedown", checkCalendar);
556
557
                    return false;
558
                    }
559
560
                    Calendar._DN = new Array
561
                    ("' . _CAL_SUNDAY . '",
562
                    "' . _CAL_MONDAY . '",
563
                    "' . _CAL_TUESDAY . '",
564
                    "' . _CAL_WEDNESDAY . '",
565
                    "' . _CAL_THURSDAY . '",
566
                    "' . _CAL_FRIDAY . '",
567
                    "' . _CAL_SATURDAY . '",
568
                    "' . _CAL_SUNDAY . '");
569
                    Calendar._MN = new Array
570
                    ("' . _CAL_JANUARY . '",
571
                    "' . _CAL_FEBRUARY . '",
572
                    "' . _CAL_MARCH . '",
573
                    "' . _CAL_APRIL . '",
574
                    "' . _CAL_MAY . '",
575
                    "' . _CAL_JUNE . '",
576
                    "' . _CAL_JULY . '",
577
                    "' . _CAL_AUGUST . '",
578
                    "' . _CAL_SEPTEMBER . '",
579
                    "' . _CAL_OCTOBER . '",
580
                    "' . _CAL_NOVEMBER . '",
581
                    "' . _CAL_DECEMBER . '");
582
583
                    Calendar._TT = {};
584
                    Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '";
585
                    Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '";
586
                    Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '";
587
                    Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '";
588
                    Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '";
589
                    Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '";
590
                    Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '";
591
                    Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '";
592
                    Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')";
593
                    Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '";
594
                    Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '";
595
                    Calendar._TT["CLOSE"] = "' . _CLOSE . '";
596
                    Calendar._TT["TODAY"] = "' . _CAL_TODAY . '";
597
598
                    // date formats
599
                    Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
600
                    Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
601
602
                    Calendar._TT["WK"] = "";
603
                ');
604
            }
605
        }
606
        return '<input type="text" name="' . $ele_name . '" id="' . $ele_name . '" size="'
607
            . $element->getSize() . '" maxlength="' . $element->getMaxlength() . '" value="'
608
            . $display_value . '"' . $element->getExtra()
609
            . ' /><input type="reset" value=" ... " onclick="return showCalendar(\'' . $ele_name
610
            . '\');">';
611
        /*
612
        return "<input type='text' name='" . $ele_name . "' id='" . $ele_name . "' size='"
613
            . $element->getSize() . "' maxlength='" . $element->getMaxlength() . "' value='"
614
            . $display_value . "'" . $element->getExtra()
615
            . " /><input type='reset' value=' ... ' onclick='return showCalendar(\"" . $ele_name
616
            . "\");'>";
617
        */
618
    }
619
620
    /**
621
     * Render support for XoopsThemeForm
622
     *
623
     * @param XoopsThemeForm $form form to render
624
     *
625
     * @return string rendered form
626
     */
627
    public function renderThemeForm(XoopsThemeForm $form)
628
    {
629
        $ele_name = $form->getName();
630
        $ret      = '<form name="' . $ele_name . '" id="' . $ele_name . '" action="' . $form->getAction() . '" method="' . $form->getMethod() . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>
631
            <table width="100%" class="outer" cellspacing="1">
632
            <tr><th colspan="2">' . $form->getTitle() . '</th></tr>
633
        ';
634
        $hidden   = '';
635
        $class    = 'even';
636
        foreach ($form->getElements() as $ele) {
637
            if (!is_object($ele)) {
638
                $ret .= $ele;
639
            } elseif (!$ele->isHidden()) {
640
                if (!$ele->getNocolspan()) {
641
                    $ret .= '<tr valign="top" align="left"><td class="head">';
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
                    if (($desc = $ele->getDescription()) != '') {
649
                        $ret .= '<div class="xoops-form-element-help">' . $desc . '</div>';
650
                    }
651
                    $ret .= '</td><td class="' . $class . '">' . $ele->render() . '</td></tr>' . NWLINE;
0 ignored issues
show
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
                } else {
653
                    $ret .= '<tr valign="top" align="left"><td class="head" colspan="2">';
654
                    if (($caption = $ele->getCaption()) != '') {
655
                        $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">';
656
                        $ret .= '<span class="caption-text">' . $caption . '</span>';
657
                        $ret .= '<span class="caption-marker">*</span>';
658
                        $ret .= '</div>';
659
                    }
660
                    $ret .= '</td></tr><tr valign="top" align="left"><td class="' . $class . '" colspan="2">' . $ele->render() . '</td></tr>';
0 ignored issues
show
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...
661
                }
662
            } else {
663
                $hidden .= $ele->render();
0 ignored issues
show
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...
664
            }
665
        }
666
        if (count($form->getRequired()) > 0) {
667
            $ret .= "<tr class='foot'><td colspan='2'>* = " . _REQUIRED . '</td></tr>';
668
        }
669
        $ret .= '</table>' . NWLINE . ' ' . $hidden . '</form>' . NWLINE;
670
        $ret .= $form->renderValidationJS(true);
671
672
        return $ret;
673
    }
674
675
    /**
676
     * Support for themed addBreak
677
     *
678
     * @param XoopsThemeForm $form
679
     * @param string         $extra pre-rendered content for break row
680
     * @param string         $class class for row
681
     *
682
     * @return void
683
     */
684
    public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class)
685
    {
686
        $class = ($class != '') ? " class='" . preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) . "'" : '';
687
        // Fix for $extra tag not showing
688
        if ($extra) {
689
            $extra = '<tr><td colspan="2" ' . $class . '>' . $extra . '</td></tr>';
690
            $form->addElement($extra);
691
        } else {
692
            $extra = '<tr><td colspan="2" ' . $class . '>&nbsp;</td></tr>';
693
            $form->addElement($extra);
694
        }
695
    }
696
}
697