Completed
Push — master ( 8d9a9b...cd572c )
by Richard
11s
created

XoopsFormRendererBootstrap3::renderFormFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
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 View Code Duplication
    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
        $ele_name      = $element->getName();
72
        $ele_title     = $element->getTitle();
73
        $ele_id        = $ele_name;
74
        $ele_value     = $element->getValue();
75
        $ele_options   = $element->getOptions();
76
        $ele_extra     = $element->getExtra();
77
        $ele_delimeter= empty($element->columns) ? $element->getDelimeter() : '';
78
79 View Code Duplication
        if (count($ele_options) > 1 && substr($ele_name, -2, 2) !== '[]') {
80
            $ele_name .= '[]';
81
            $element->setName($ele_name);
82
        }
83
        $ret = '';
84
        /*<label class="checkbox-inline">
85
          <input type="checkbox" id="inlineCheckbox1" value="option1"> 1
86
        </label>*/
87
        if (!empty($element->columns)) {
88
            $ret .= '<table><tr>';
89
        }
90
        $i      = 0;
91
        $id_ele = 0;
92
        foreach ($ele_options as $value => $name) {
93
            ++$id_ele;
94 View Code Duplication
            if (!empty($element->columns)) {
95
                if ($i % $element->columns == 0) {
96
                    $ret .= '<tr>';
97
                }
98
                $ret .= '<td>';
99
            }
100
            $ret .= '<div class="checkbox-inline"><label>';
101
            // $name may be a link, should we use $name in the title tag?
102
            $ret .= "<input type='checkbox' name='{$ele_name}' id='{$ele_id}{$id_ele}' title='"
103
                 . $ele_title . "' value='" . htmlspecialchars($value, ENT_QUOTES) . "'";
104
105
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
106
                $ret .= ' checked';
107
            }
108
            $ret .= $ele_extra . ' />' . $name . $ele_delimeter;
109
            $ret .= '<label></div>';
110
111 View Code Duplication
            if (!empty($element->columns)) {
112
                $ret .= '</td>';
113
                if (++$i % $element->columns == 0) {
114
                    $ret .= '</tr>';
115
                }
116
            }
117
        }
118 View Code Duplication
        if (!empty($element->columns)) {
119
            if ($span = $i % $element->columns) {
120
                $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>';
121
            }
122
            $ret .= '</table>';
123
        }
124
125
        return $ret;
126
    }
127
128
    /**
129
     * Render support for XoopsFormColorPicker
130
     *
131
     * @param XoopsFormColorPicker $element form element
132
     *
133
     * @return string rendered form element
134
     */
135
    public function renderFormColorPicker(XoopsFormColorPicker $element)
136
    {
137 View Code Duplication
        if (isset($GLOBALS['xoTheme'])) {
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 class="form-control" style="width: 25%;" type="color" name="' . $element->getName()
145
            . "' title='" . $element->getTitle() . "' id='" . $element->getName()
146
            . '" size="7" maxlength="7" value="' . $element->getValue() . '"' . $element->getExtra() . ' />';
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
        static $js_loaded;
159
160
        xoops_loadLanguage('formdhtmltextarea');
161
        $ret = '';
162
        // actions
163
        $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n";
164
        // fonts
165
        $ret .= $this->renderFormDhtmlTATypography($element);
166
        // length checker
167
168
        $ret .= "<br>\n";
169
        // the textarea box
170
        $ret .= "<textarea class='form-control' id='" . $element->getName() . "' name='" . $element->getName()
171
            . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName()
172
            . "');\" onclick=\"xoopsSavePosition('" . $element->getName()
173
            . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='"
174
            . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra()
175
            . '>' . $element->getValue() . "</textarea>\n";
176
177 View Code Duplication
        if (empty($element->skipPreview)) {
178
            if (empty($GLOBALS['xoTheme'])) {
179
                $element->js .= implode('', file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js'));
180
            } else {
181
                $GLOBALS['xoTheme']->addScript('/class/textsanitizer/image/image.js', array('type' => 'text/javascript'));
182
            }
183
            $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>";
184
185
            $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>';
186
        }
187
        // Load javascript
188 View Code Duplication
        if (empty($js_loaded)) {
189
            $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '') . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>';
190
            $ret        = $javascript . $ret;
191
            $js_loaded  = true;
192
        }
193
194
        return $ret;
195
    }
196
197
    /**
198
     * Render xoopscode buttons for editor, include calling text sanitizer extensions
199
     *
200
     * @param XoopsFormDhtmlTextArea $element form element
201
     *
202
     * @return string rendered buttons for xoopscode assistance
203
     */
204 View Code Duplication
    protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element)
205
    {
206
        $textarea_id = $element->getName();
207
        $code = '';
208
        $code .= "<div class='row'><div class='col-md-12'>";
209
        $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>";
210
        $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>";
211
        $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>";
212
        $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> Manager</button>";
213
        $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>";
214
215
        $myts        = MyTextSanitizer::getInstance();
216
217
        $extensions = array_filter($myts->config['extensions']);
218
        foreach (array_keys($extensions) as $key) {
219
            $extension = $myts->loadExtension($key);
220
            @list($encode, $js) = $extension->encode($textarea_id);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
221
            if (empty($encode)) {
222
                continue;
223
            }
224
            $code .= $encode;
225
            if (!empty($js)) {
226
                $element->js .= $js;
227
            }
228
        }
229
        $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>";
230
        $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>";
231
        $code .= "</div></div>";
232
233
        $xoopsPreload = XoopsPreload::getInstance();
234
        $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
235
236
        return $code;
237
    }
238
239
    /**
240
     * Render typography controls for editor (font, size, color)
241
     *
242
     * @param XoopsFormDhtmlTextArea $element form element
243
     *
244
     * @return string rendered typography controls
245
     */
246
    protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element)
247
    {
248
        $textarea_id = $element->getName();
249
        $hiddentext  = $element->_hiddenText;
250
251
        $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array(
252
            'Arial',
253
            'Courier',
254
            'Georgia',
255
            'Helvetica',
256
            'Impact',
257
            'Verdana',
258
            'Haettenschweiler');
259
260
        $colorArray = array(
261
            'Black'  => '000000',
262
            'Blue'   => '38AAFF',
263
            'Brown'  => '987857',
264
            'Green'  => '79D271',
265
            'Grey'   => '888888',
266
            'Orange' => 'FFA700',
267
            'Paper'  => 'E0E0E0',
268
            'Purple' => '363E98',
269
            'Red'    => 'FF211E',
270
            'White'  => 'FEFEFE',
271
            'Yellow' => 'FFD628',
272
        );
273
274
        $fontStr = '<div class="row"><div class="col-md-12"><div class="btn-group" role="toolbar">';
275
        $fontStr .= '<div class="btn-group">'
276
            . '<button type="button" class="btn btn-default dropdown-toggle" title="'. _SIZE .'"'
277
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
278
            . '<span class = "glyphicon glyphicon-text-height"></span><span class="caret"></span></button>'
279
            . '<ul class="dropdown-menu">';
280
            //. _SIZE . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
281 View Code Duplication
        foreach ($GLOBALS['formtextdhtml_sizes'] as $value => $name) {
282
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'size\', \'' . $value . '\', \''
283
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $name . '</a></li>';
284
        }
285
        $fontStr .= '</ul></div>';
286
287
        $fontStr .= '<div class="btn-group">'
288
            . '<button type="button" class="btn btn-default dropdown-toggle" title="'. _FONT .'"'
289
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
290
            . '<span class = "glyphicon glyphicon-font"></span><span class="caret"></span></button>'
291
            . '<ul class="dropdown-menu">';
292
            //. _FONT . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
293 View Code Duplication
        foreach ($fontarray as $font) {
294
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'font\', \'' . $font . '\', \''
295
                . $textarea_id . '\', \'' . $hiddentext . '\');">' . $font . '</a></li>';
296
        }
297
        $fontStr .= '</ul></div>';
298
299
        $fontStr .= '<div class="btn-group">'
300
            . '<button type="button" class="btn btn-default dropdown-toggle" title="'. _COLOR .'"'
301
            . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
302
            . '<span class = "glyphicon glyphicon-text-color"></span><span class="caret"></span></button>'
303
            . '<ul class="dropdown-menu">';
304
            //. _COLOR . '&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
305
        foreach ($colorArray as $color => $hex) {
306
            $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'color\', \'' . $hex . '\', \''
307
                . $textarea_id . '\', \'' . $hiddentext . '\');">'
308
                . '<span style="color:#' . $hex . ';">' . $color .'</span></a></li>';
309
        }
310
        $fontStr .= '</ul></div>';
311
        $fontStr .= '</div>';
312
313
        //$styleStr = "<div class='row'><div class='col-md-12'>";
314
        $styleStr  = "<div class='btn-group' role='group'>";
315
        $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>";
316
        $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>";
317
        $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>';
318
        $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>';
319
        $styleStr .= "</div>";
320
321
        $alignStr = "<div class='btn-group' role='group'>";
322
        $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>";
323
        $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>";
324
        $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>";
325
        $alignStr .= "</div>";
326
327
        $fontStr .= "&nbsp;{$styleStr}&nbsp;{$alignStr}&nbsp;\n";
328
329
        $fontStr .= "<button type='button' class='btn btn-default' onclick=\"XoopsCheckLength('"
330
            . $element->getName() . "', '" . @$element->configs['maxlength'] . "', '"
0 ignored issues
show
Bug introduced by
The property configs does not seem to exist in XoopsFormDhtmlTextArea.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
331
            . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='"
332
            . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>";
333
        $fontStr .= "</div></div>";
334
335
        return $fontStr;
336
    }
337
338
    /**
339
     * Render support for XoopsFormElementTray
340
     *
341
     * @param XoopsFormElementTray $element form element
342
     *
343
     * @return string rendered form element
344
     */
345 View Code Duplication
    public function renderFormElementTray(XoopsFormElementTray $element)
346
    {
347
        $count = 0;
348
        $ret = '<div class="form-inline">';
349
        foreach ($element->getElements() as $ele) {
350
            if ($count > 0) {
351
                $ret .= $element->getDelimeter();
352
            }
353
            if ($ele->getCaption() != '') {
354
                $ret .= $ele->getCaption() . '&nbsp;';
355
            }
356
            $ret .= $ele->render() . NWLINE;
357
            if (!$ele->isHidden()) {
358
                ++$count;
359
            }
360
        }
361
        /*
362
        if (substr_count($ret, '<div class="form-group form-inline">') > 0) {
363
            $ret = str_replace('<div class="form-group form-inline">', '', $ret);
364
            $ret = str_replace('</div>', '', $ret);
365
        }
366
        if (substr_count($ret, '<div class="checkbox-inline">') > 0) {
367
            $ret = str_replace('<div class="checkbox-inline">', '', $ret);
368
        }
369
        */
370
        $ret .= '</div>';
371
        return $ret;
372
    }
373
374
    /**
375
     * Render support for XoopsFormFile
376
     *
377
     * @param XoopsFormFile $element form element
378
     *
379
     * @return string rendered form element
380
     */
381 View Code Duplication
    public function renderFormFile(XoopsFormFile $element)
382
    {
383
        return '<input class="form-control" type="file" name="' . $element->getName()
384
            . '" id="' . $element->getName()
385
            . '" title="' . $element->getTitle() . '" ' . $element->getExtra() . ' />'
386
            . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '" />'
387
            . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="'
388
            . $element->getName() . '" />';
389
390
    }
391
392
    /**
393
     * Render support for XoopsFormLabel
394
     *
395
     * @param XoopsFormLabel $element form element
396
     *
397
     * @return string rendered form element
398
     */
399
    public function renderFormLabel(XoopsFormLabel $element)
400
    {
401
        return $element->getValue();
402
    }
403
404
    /**
405
     * Render support for XoopsFormPassword
406
     *
407
     * @param XoopsFormPassword $element form element
408
     *
409
     * @return string rendered form element
410
     */
411
    public function renderFormPassword(XoopsFormPassword $element)
412
    {
413
        return '<input class="form-control" type="password" name="'
414
            . $element->getName() . '" id="' . $element->getName() . '" size="' . $element->getSize()
415
            . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue() . '"'
416
            . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>';
417
    }
418
419
    /**
420
     * Render support for XoopsFormRadio
421
     *
422
     * @param XoopsFormRadio $element form element
423
     *
424
     * @return string rendered form element
425
     */
426
    public function renderFormRadio(XoopsFormRadio $element)
427
    {
428
        $ret           = '';
429
        $ele_name      = $element->getName();
430
        $ele_title     = $element->getTitle();
431
        $ele_value     = $element->getValue();
432
        $ele_options   = $element->getOptions();
433
        $ele_extra     = $element->getExtra();
434
        $ele_delimeter = empty($element->columns) ? $element->getDelimeter() : '';
435
        if (!empty($element->columns)) {
436
            $ret .= '<table><tr>';
437
        }
438
        $i      = 0;
439
        $id_ele = 0;
440
        foreach ($ele_options as $value => $name) {
441
            ++$id_ele;
442 View Code Duplication
            if (!empty($element->columns)) {
443
                if ($i % $element->columns == 0) {
444
                    $ret .= '<tr>';
445
                }
446
                $ret .= '<td>';
447
            }
448
449
            $ret .= '<div class="checkbox-inline"><label>';
450
451
            $ret .= '<input type="radio" name="' . $ele_name . '" id="' . $ele_name . $id_ele
452
                . '" title = "' . htmlspecialchars($ele_title, ENT_QUOTES) . '" value="'
453
                . htmlspecialchars($value, ENT_QUOTES) . '"';
454
            if (isset($ele_value) && $value == $ele_value) {
455
                $ret .= ' checked';
456
            }
457
458
            $ret .= $ele_extra . ' /> ' . $name . $ele_delimeter;
459
            $ret .= '<label></div>';
460
461 View Code Duplication
            if (!empty($element->columns)) {
462
                $ret .= '</td>';
463
                if (++$i % $element->columns == 0) {
464
                    $ret .= '</tr>';
465
                }
466
            }
467
        }
468 View Code Duplication
        if (!empty($element->columns)) {
469
            if ($span = $i % $element->columns) {
470
                $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>';
471
            }
472
            $ret .= '</table>';
473
        }
474
475
        return $ret;
476
    }
477
478
    /**
479
     * Render support for XoopsFormSelect
480
     *
481
     * @param XoopsFormSelect $element form element
482
     *
483
     * @return string rendered form element
484
     */
485 View Code Duplication
    public function renderFormSelect(XoopsFormSelect $element)
486
    {
487
        $ele_name    = $element->getName();
488
        $ele_title   = $element->getTitle();
489
        $ele_value   = $element->getValue();
490
        $ele_options = $element->getOptions();
491
        $ret = '<select class="form-control" size="'
492
            . $element->getSize() . '"' . $element->getExtra();
493
        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...
494
            $ret .= ' name="' . $ele_name . '[]" id="' . $ele_name . '" title="' . $ele_title
495
                . '" multiple="multiple">';
496
        } else {
497
            $ret .= ' name="' . $ele_name . '" id="' . $ele_name . '" title="' . $ele_title . '">';
498
        }
499
        foreach ($ele_options as $value => $name) {
500
            $ret .= '<option value="' . htmlspecialchars($value, ENT_QUOTES) . '"';
501
            if (count($ele_value) > 0 && in_array($value, $ele_value)) {
502
                $ret .= ' selected';
503
            }
504
            $ret .= '>' . $name . '</option>';
505
        }
506
        $ret .= '</select>';
507
508
        return $ret;
509
    }
510
    /**
511
     * Render support for XoopsFormText
512
     *
513
     * @param XoopsFormText $element form element
514
     *
515
     * @return string rendered form element
516
     */
517 View Code Duplication
    public function renderFormText(XoopsFormText $element)
518
    {
519
        return "<input class='form-control' type='text' name='"
520
            . $element->getName() . "' title='" . $element->getTitle() . "' id='" . $element->getName()
521
            . "' size='" . $element->getSize() . "' maxlength='" . $element->getMaxlength()
522
            . "' value='" . $element->getValue() . "'" . $element->getExtra() . ' />';
523
    }
524
525
    /**
526
     * Render support for XoopsFormTextArea
527
     *
528
     * @param XoopsFormTextArea $element form element
529
     *
530
     * @return string rendered form element
531
     */
532 View Code Duplication
    public function renderFormTextArea(XoopsFormTextArea $element)
533
    {
534
        return "<textarea class='form-control' name='"
535
            . $element->getName() . "' id='" . $element->getName() . "'  title='" . $element->getTitle()
536
            . "' rows='" . $element->getRows() . "' cols='" . $element->getCols() . "'"
537
            . $element->getExtra() . '>' . $element->getValue() . '</textarea>';
538
    }
539
540
    /**
541
     * Render support for XoopsFormTextDateSelect
542
     *
543
     * @param XoopsFormTextDateSelect $element form element
544
     *
545
     * @return string rendered form element
546
     */
547 View Code Duplication
    public function renderFormTextDateSelect(XoopsFormTextDateSelect $element)
548
    {
549
        static $included = false;
550
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) {
551
            include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php';
552
        } else {
553
            include_once XOOPS_ROOT_PATH . '/language/english/calendar.php';
554
        }
555
556
        $ele_name  = $element->getName();
557
        $ele_value = $element->getValue(false);
558
        if (is_string($ele_value)) {
559
            $display_value = $ele_value;
560
            $ele_value     = time();
561
        } else {
562
            $display_value = date(_SHORTDATESTRING, $ele_value);
563
        }
564
565
        $jstime = formatTimestamp($ele_value, _SHORTDATESTRING);
566
        if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) {
567
            $GLOBALS['xoTheme']->addScript('include/calendar.js');
568
            $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css');
569
            if (!$included) {
570
                $included = true;
571
                $GLOBALS['xoTheme']->addScript('', '', '
572
                    var calendar = null;
573
574
                    function selected(cal, date)
575
                    {
576
                    cal.sel.value = date;
577
                    }
578
579
                    function closeHandler(cal)
580
                    {
581
                    cal.hide();
582
                    Calendar.removeEvent(document, "mousedown", checkCalendar);
583
                    }
584
585
                    function checkCalendar(ev)
586
                    {
587
                    var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
588
                    for (; el != null; el = el.parentNode)
589
                    if (el == calendar.element || el.tagName == "A") break;
590
                    if (el == null) {
591
                    calendar.callCloseHandler(); Calendar.stopEvent(ev);
592
                    }
593
                    }
594
                    function showCalendar(id)
595
                    {
596
                    var el = xoopsGetElementById(id);
597
                    if (calendar != null) {
598
                    calendar.hide();
599
                    } else {
600
                    var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler);
601
                    calendar = cal;
602
                    cal.setRange(1900, 2100);
603
                    calendar.create();
604
                    }
605
                    calendar.sel = el;
606
                    calendar.parseDate(el.value);
607
                    calendar.showAtElement(el);
608
                    Calendar.addEvent(document, "mousedown", checkCalendar);
609
610
                    return false;
611
                    }
612
613
                    Calendar._DN = new Array
614
                    ("' . _CAL_SUNDAY . '",
615
                    "' . _CAL_MONDAY . '",
616
                    "' . _CAL_TUESDAY . '",
617
                    "' . _CAL_WEDNESDAY . '",
618
                    "' . _CAL_THURSDAY . '",
619
                    "' . _CAL_FRIDAY . '",
620
                    "' . _CAL_SATURDAY . '",
621
                    "' . _CAL_SUNDAY . '");
622
                    Calendar._MN = new Array
623
                    ("' . _CAL_JANUARY . '",
624
                    "' . _CAL_FEBRUARY . '",
625
                    "' . _CAL_MARCH . '",
626
                    "' . _CAL_APRIL . '",
627
                    "' . _CAL_MAY . '",
628
                    "' . _CAL_JUNE . '",
629
                    "' . _CAL_JULY . '",
630
                    "' . _CAL_AUGUST . '",
631
                    "' . _CAL_SEPTEMBER . '",
632
                    "' . _CAL_OCTOBER . '",
633
                    "' . _CAL_NOVEMBER . '",
634
                    "' . _CAL_DECEMBER . '");
635
636
                    Calendar._TT = {};
637
                    Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '";
638
                    Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '";
639
                    Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '";
640
                    Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '";
641
                    Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '";
642
                    Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '";
643
                    Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '";
644
                    Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '";
645
                    Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')";
646
                    Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '";
647
                    Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '";
648
                    Calendar._TT["CLOSE"] = "' . _CLOSE . '";
649
                    Calendar._TT["TODAY"] = "' . _CAL_TODAY . '";
650
651
                    // date formats
652
                    Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
653
                    Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '";
654
655
                    Calendar._TT["WK"] = "";
656
                ');
657
            }
658
        }
659
        return '<div class="form-inline"><input class="form-control" type="text" name="' . $ele_name
660
            . '" id="' . $ele_name . '" size="' . $element->getSize() . '" maxlength="'
661
            . $element->getMaxlength() . '" value="' . $display_value . '"' . $element->getExtra()
662
            . ' /><input class="form-control" type="reset" value=" ... " onclick="return showCalendar(\''
663
            . $ele_name . '\');"></div>';
664
    }
665
666
    /**
667
     * Render support for XoopsThemeForm
668
     *
669
     * @param XoopsThemeForm $form form to render
670
     *
671
     * @return string rendered form
672
     */
673
    public function renderThemeForm(XoopsThemeForm $form)
674
    {
675
        $ele_name = $form->getName();
676
677
        $ret = '<div>';
678
        $ret .= '<form class="form-horizontal" name="' . $ele_name . '" id="' . $ele_name . '" action="'
679
            . $form->getAction() . '" method="' . $form->getMethod()
680
            . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>';
681
682
        $hidden   = '';
683
        $class    = 'even';
0 ignored issues
show
Unused Code introduced by
$class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
684
        foreach ($form->getElements() as $ele) {
685
            if (!is_object($ele)) { // see $form->addBreak()
686
                $ret .= $ele;
687
                continue;
688
            }
689
            if ($ele->isHidden()) {
690
                $hidden .= $ele->render();
691
                continue;
692
            }
693
694
            $ret .= '<div class="form-group">';
695
            if (($caption = $ele->getCaption()) != '') {
696
                $ret .= '<label for="' . $ele->getName() . '" class="col-sm-2 control-label">'
697
                    . $ele->getCaption()
698
                    . ($ele->isRequired() ? '<span class="caption-required">*</span>' : '')
699
                    . '</label>';
700
            } else {
701
                $ret .= '<div class="col-sm-2"> </div>';
702
            }
703
            $ret .= '<div class="col-sm-10">';
704
            $ret .= $ele->render();
705
            if (($desc = $ele->getDescription()) != '') {
706
                $ret .= '<p class="text-muted">' . $desc . '</p>';
707
            }
708
            $ret .= '</div>';
709
            $ret .= '</div>';
710
        }
711
        $ret .= '</form></div>';
712
        $ret .= $form->renderValidationJS(true);
713
714
        return $ret;
715
    }
716
717
    /**
718
     * Support for themed addBreak
719
     *
720
     * @param XoopsThemeForm $form
721
     * @param string         $extra pre-rendered content for break row
722
     * @param string         $class class for row
723
     *
724
     * @return void
725
     */
726
    public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class)
727
    {
728
        $class = ($class != '') ? preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) : '';
729
        $form->addElement('<div class="col-sm-12 ' . $class .'">'. $extra . '</div>');
730
    }
731
}
732