Issues (3083)

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