|
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
|
|
|
namespace Xoops\Form\Renderer; |
|
11
|
|
|
|
|
12
|
|
|
use Xoops\Form\RendererInterface; |
|
13
|
|
|
/** |
|
14
|
|
|
* Bootstrap3Renderer style form renderer |
|
15
|
|
|
* |
|
16
|
|
|
* @author Grégory Mage |
|
17
|
|
|
* @copyright 2019 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 Bootstrap3Renderer implements RendererInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public function render(\Xoops\Form\Element $element):string |
|
24
|
|
|
{ |
|
25
|
|
|
$methodName = 'render' . str_replace('\\' , '', get_class($element)); |
|
26
|
|
|
if (true === method_exists($this, $methodName)) { |
|
27
|
|
|
return $this->$methodName($element); |
|
28
|
|
|
} |
|
29
|
|
|
return $element->defaultRender(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Example of an override render method for a specific element class. |
|
34
|
|
|
* Each method will be specific to a concrete implementation of Xoops\Form\Element |
|
35
|
|
|
* |
|
36
|
|
|
* @param \Xoops\Form\Button $element Provides access to the element we are rendering. |
|
37
|
|
|
* The strong type makes sure we get what we expect. |
|
38
|
|
|
* |
|
39
|
|
|
* @return string the rendering of $element |
|
40
|
|
|
* |
|
41
|
|
|
protected function renderXoopsFormButton(\Xoops\Form\Button $element):string |
|
42
|
|
|
{ |
|
43
|
|
|
// do the rendering and return a string |
|
44
|
|
|
return ''; |
|
45
|
|
|
}*/ |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Render support for XoopsFormButton |
|
49
|
|
|
* |
|
50
|
|
|
* @param XoopsFormButton $element form element |
|
|
|
|
|
|
51
|
|
|
* |
|
52
|
|
|
* @return string rendered form element |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function renderXoopsFormButton(\Xoops\Form\Button $element):string |
|
55
|
|
|
{ |
|
56
|
|
|
if (false == $element->hasClassLike('btn')) { |
|
|
|
|
|
|
57
|
|
|
$element->add('class', 'btn btn-default'); |
|
58
|
|
|
} |
|
59
|
|
|
$attributes = $element->renderAttributeString(); |
|
60
|
|
|
return '<input ' . $attributes . $element->getExtra() .' >'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Render support for XoopsFormButtonTray |
|
65
|
|
|
* |
|
66
|
|
|
* @param XoopsFormButtonTray $element form element |
|
|
|
|
|
|
67
|
|
|
* |
|
68
|
|
|
* @return string rendered form element |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function renderXoopsFormButtonTray(\Xoops\Form\ButtonTray $element):string |
|
71
|
|
|
{ |
|
72
|
|
|
$ret = ''; |
|
73
|
|
|
$element->add('class', 'btn'); |
|
74
|
|
|
$class = 'class="' . $element->getClass() . '"'; |
|
75
|
|
|
|
|
76
|
|
|
$attributes = $element->renderAttributeString(); |
|
77
|
|
|
|
|
78
|
|
|
if ((bool) $element->get(':showdelete', false)) { |
|
79
|
|
|
$ret .= '<input type="submit"' . $class . ' name="delete" id="delete" value="' |
|
80
|
|
|
. \XoopsLocale::A_DELETE . '" onclick="this.form.elements.op.value=\'delete\'">'; |
|
81
|
|
|
} |
|
82
|
|
|
$ret .= ' <input type="button" ' . $class . ' value="' . \XoopsLocale::A_CANCEL |
|
83
|
|
|
. '" onclick="history.go(-1);return true;" />' |
|
84
|
|
|
. ' <input type="reset"' . $class . ' name="reset" id="reset" value="' . \XoopsLocale::A_RESET . '" />' |
|
85
|
|
|
. ' <input ' . $attributes . $element->getExtra() . ' />'; |
|
86
|
|
|
return $ret; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Render support for XoopsFormColorPicker |
|
91
|
|
|
* |
|
92
|
|
|
* @param XoopsFormColorPicker $element form element |
|
|
|
|
|
|
93
|
|
|
* |
|
94
|
|
|
* @return string rendered form element |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function renderXoopsFormColorPicker(\Xoops\Form\ColorPicker $element):string |
|
97
|
|
|
{ |
|
98
|
|
|
$xoops = \Xoops::getInstance(); |
|
99
|
|
|
if ($xoops->theme()) { |
|
100
|
|
|
$xoops->theme()->addScript('include/color-picker.js'); |
|
101
|
|
|
} else { |
|
102
|
|
|
echo '<script type="text/javascript" src="' . $xoops->url('/include/color-picker.js') . '"></script>'; |
|
103
|
|
|
} |
|
104
|
|
|
$temp = $element->get('value', ''); |
|
105
|
|
|
if (!empty($temp)) { |
|
106
|
|
|
$element->set('style', 'background-color:' . $temp . ';'); |
|
107
|
|
|
} |
|
108
|
|
|
$element->set('class', 'form-control'); |
|
109
|
|
|
$ret = '<div class="input-group">'; |
|
110
|
|
|
$attributes = $element->renderAttributeString(); |
|
111
|
|
|
$ret .= '<input ' . $attributes . ' ' . $element->getExtra() .' >'; |
|
112
|
|
|
$ret .= '<span class="input-group-btn">'; |
|
113
|
|
|
$ret .= '<button class="btn btn-default" type="button" '; |
|
114
|
|
|
$ret .= 'data-toggle="tooltip" data-placement="left" title="' . \XoopsLocale::A_SELECT . '" '; |
|
115
|
|
|
$ret .= 'onclick="return TCP.popup(\''; |
|
116
|
|
|
$ret .= $xoops->url('/include/') . '\',document.getElementById(\'' . $element->getName() . '\'));">'; |
|
117
|
|
|
$ret .= '<span class="glyphicon glyphicon-option-horizontal" aria-hidden="true"></span></button>'; |
|
118
|
|
|
$ret .= '</span></div>'; |
|
119
|
|
|
|
|
120
|
|
|
return $ret; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Render support for XoopsFormDateSelect |
|
125
|
|
|
* |
|
126
|
|
|
* @param XoopsFormDateSelect $element form element |
|
|
|
|
|
|
127
|
|
|
* |
|
128
|
|
|
* @return string rendered form element |
|
129
|
|
|
*/ |
|
130
|
|
|
protected function renderXoopsFormDateSelect(\Xoops\Form\DateSelect $element):string |
|
131
|
|
|
{ |
|
132
|
|
|
$xoops = \Xoops::getInstance(); |
|
133
|
|
|
|
|
134
|
|
|
$display_value = \Xoops\Core\Locale\Time::formatDate($element->getValue(false)); |
|
135
|
|
|
|
|
136
|
|
|
$dataList = $element->isDatalist(); |
|
137
|
|
|
if (!empty($dataList)) { |
|
138
|
|
|
$element->add('list', 'list_' . $element->getName()); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$element->add('class', 'form-control'); |
|
142
|
|
|
$element->suppressRender(['value']); |
|
143
|
|
|
$attributes = $element->renderAttributeString(); |
|
144
|
|
|
|
|
145
|
|
|
$xoops->theme()->addBaseStylesheetAssets('@jqueryuicss'); |
|
|
|
|
|
|
146
|
|
|
$xoops->theme()->addBaseScriptAssets('@jqueryui'); |
|
|
|
|
|
|
147
|
|
|
\Xoops\Core\Locale\Time::localizeDatePicker(); |
|
148
|
|
|
|
|
149
|
|
|
$xoops->theme()->addScript( |
|
150
|
|
|
'', |
|
151
|
|
|
'', |
|
|
|
|
|
|
152
|
|
|
' $(function() { $( "#' . $element->get('id') . '" ).datepicker({' . |
|
|
|
|
|
|
153
|
|
|
'showOn: "focus", changeYear: true, constrainInput: false ' . |
|
154
|
|
|
' }); }); ' |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
$ret = '<div class="input-group">'; |
|
158
|
|
|
$ret .= '<input ' . $attributes . ' value="' . $display_value . '" ' . $element->getExtra() .' >'; |
|
159
|
|
|
$ret .= '<span class="input-group-btn">'; |
|
160
|
|
|
$ret .= '<button class="btn btn-default" type="button" '; |
|
161
|
|
|
$ret .= 'data-toggle="tooltip" data-placement="left" title="' . \XoopsLocale::A_SELECT . '" '; |
|
162
|
|
|
$ret .= 'onclick="$( \'#' . $element->get('id') . '\' ).datepicker( \'show\' );"> '; |
|
163
|
|
|
$ret .= '<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span></button>'; |
|
164
|
|
|
$ret .= '</span></div>'; |
|
165
|
|
|
|
|
166
|
|
|
return $ret; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Render support for XoopsFormDhtmlTextArea |
|
171
|
|
|
* |
|
172
|
|
|
* @param XoopsFormDhtmlTextArea $element form element |
|
|
|
|
|
|
173
|
|
|
* |
|
174
|
|
|
* @return string rendered form element |
|
175
|
|
|
*/ |
|
176
|
|
|
protected function renderXoopsFormDhtmlTextArea(\Xoops\Form\DhtmlTextArea $element):string |
|
177
|
|
|
{ |
|
178
|
|
|
if ($element->htmlEditor && is_object($element->htmlEditor)) { |
|
179
|
|
|
if (!isset($element->htmlEditor->isEnabled) || $element->htmlEditor->isEnabled) { |
|
180
|
|
|
return $element->htmlEditor->render(); |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
static $js_loaded; |
|
184
|
|
|
|
|
185
|
|
|
$xoops = \Xoops::getInstance(); |
|
186
|
|
|
|
|
187
|
|
|
$extra = ($element->getExtra() != '' ? " " . $element->getExtra() : ''); |
|
188
|
|
|
$ret = ""; |
|
189
|
|
|
// actions |
|
190
|
|
|
$ret .= $element->codeIcon() . "<br />\n"; |
|
191
|
|
|
// fonts |
|
192
|
|
|
$ret .= $element->fontArray(); |
|
193
|
|
|
// length checker |
|
194
|
|
|
$ret .= '<button type="button" class="btn btn-xs btn-default" onclick="XoopsCheckLength(\'' |
|
195
|
|
|
. $element->getName() . '\', \'' . @$element->configs['maxlength'] . '\', \'' |
|
196
|
|
|
. \XoopsLocale::F_CURRENT_TEXT_LENGTH . '\', \'' . \XoopsLocale::MAXIMUM_LENGTH . '\');"' |
|
197
|
|
|
. ' title="' . \XoopsLocale::CHECK_TEXT_LENGTH . '">' |
|
198
|
|
|
. '<span class="glyphicon glyphicon-check"></span></button>'; |
|
199
|
|
|
$ret .= "\n"; |
|
200
|
|
|
// the textarea box |
|
201
|
|
|
$element->add('class', 'form-control'); |
|
202
|
|
|
$element->suppressRender(['value']); |
|
203
|
|
|
$attributes = $element->renderAttributeString(); |
|
204
|
|
|
|
|
205
|
|
|
$ret .= '<textarea ' . $attributes . $extra . '>' . $element->getValue() . "</textarea>\n"; |
|
206
|
|
|
|
|
207
|
|
|
if (empty($element->skipPreview)) { |
|
208
|
|
|
if (!$xoops->theme()) { |
|
209
|
|
|
$element->js .= implode("", file($xoops->path('media/xoops/image.js'))); |
|
|
|
|
|
|
210
|
|
|
} else { |
|
211
|
|
|
$xoops->theme()->addScript('media/xoops/image.js', array('type' => 'text/javascript')); |
|
212
|
|
|
} |
|
213
|
|
|
$button = "<input id='" . $element->getName() . "_preview_button' " . "type='button' " . "class='btn btn-sm btn-default' value='" . \XoopsLocale::A_PREVIEW . "' " . "onclick=\"form_instantPreview('" . XOOPS_URL . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)($element->doHtml) . ", '" . $xoops->security()->createToken() . "')\"" . " />"; |
|
214
|
|
|
$ret .= "<br />" . "<div id='" . $element->getName() . "_hidden' style='display: block;'> " . "<fieldset>" . "<legend>" . $button . "</legend>" . "<div id='" . $element->getName() . "_hidden_data'>" . \XoopsLocale::CLICK_PREVIEW_TO_SEE_CONTENT . "</div>" . "</fieldset>" . "</div>"; |
|
215
|
|
|
} |
|
216
|
|
|
// Load javascript |
|
217
|
|
|
if (empty($js_loaded)) { |
|
218
|
|
|
$javascript = (($element->js) |
|
219
|
|
|
? '<script type="text/javascript">' . $element->js . '</script>' |
|
220
|
|
|
: '') . '<script type="text/javascript" src="' . \XoopsBaseConfig::get('url') . '/include/formdhtmltextarea.js"></script>'; |
|
221
|
|
|
$ret = $javascript . $ret; |
|
222
|
|
|
$js_loaded = true; |
|
223
|
|
|
} |
|
224
|
|
|
return $ret; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Render support for XoopsFormPassword |
|
229
|
|
|
* |
|
230
|
|
|
* @param XoopsFormPassword $element form element |
|
|
|
|
|
|
231
|
|
|
* |
|
232
|
|
|
* @return string rendered form element |
|
233
|
|
|
*/ |
|
234
|
|
|
protected function renderXoopsFormPassword(\Xoops\Form\Password $element):string |
|
235
|
|
|
{ |
|
236
|
|
|
$element->add('class', 'form-control'); |
|
237
|
|
|
$attributes = $element->renderAttributeString(); |
|
238
|
|
|
return '<input ' . $attributes . $element->getExtra() .' >'; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Render support for XoopsFormSelect |
|
243
|
|
|
* |
|
244
|
|
|
* @param XoopsFormSelect $element form element |
|
|
|
|
|
|
245
|
|
|
* |
|
246
|
|
|
* @return string rendered form element |
|
247
|
|
|
*/ |
|
248
|
|
|
protected function renderXoopsFormSelect(\Xoops\Form\Select $element):string |
|
249
|
|
|
{ |
|
250
|
|
|
$selected = (array) $element->getValue(); |
|
251
|
|
|
|
|
252
|
|
|
$ele_options = $element->getOptions(); |
|
253
|
|
|
|
|
254
|
|
|
$extra = ($element->getExtra() != '' ? " " . $element->getExtra() : ''); |
|
255
|
|
|
$element->add('class', 'form-control'); |
|
256
|
|
|
$attributes = $element->renderAttributeString(); |
|
257
|
|
|
$ret = '<select ' . $attributes . $extra .' >' . "\n"; |
|
258
|
|
|
|
|
259
|
|
|
if (empty($ele_optgroup)) { |
|
|
|
|
|
|
260
|
|
|
foreach ($ele_options as $value => $display) { |
|
261
|
|
|
if (is_array($display)) { |
|
262
|
|
|
$ret .= '<optgroup label="' . $value . '">' . "\n"; |
|
263
|
|
|
foreach ($display as $optvalue => $optdisplay) { |
|
264
|
|
|
$ret .= $element->renderOption($optvalue, $optdisplay, $selected); |
|
265
|
|
|
} |
|
266
|
|
|
} else { |
|
267
|
|
|
$ret .= $element->renderOption($value, $display, $selected); |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
$ret .= '</select>' . "\n"; |
|
272
|
|
|
|
|
273
|
|
|
return $ret; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Render support for XoopsFormText |
|
278
|
|
|
* |
|
279
|
|
|
* @param XoopsFormText $element form element |
|
|
|
|
|
|
280
|
|
|
* |
|
281
|
|
|
* @return string rendered form element |
|
282
|
|
|
*/ |
|
283
|
|
|
protected function renderXoopsFormText(\Xoops\Form\Text $element):string |
|
284
|
|
|
{ |
|
285
|
|
|
$element->add('class', 'form-control'); |
|
286
|
|
|
$dataList = $element->isDatalist(); |
|
287
|
|
|
if (!empty($dataList)) { |
|
288
|
|
|
$element->add('list', 'list_' . $element->getName()); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
$attributes = $element->renderAttributeString(); |
|
292
|
|
|
return '<input ' . $attributes . ' ' . $element->getExtra() .' >'; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* Render support for XoopsFormTextArea |
|
297
|
|
|
* |
|
298
|
|
|
* @param XoopsFormTextArea $element form element |
|
|
|
|
|
|
299
|
|
|
* |
|
300
|
|
|
* @return string rendered form element |
|
301
|
|
|
*/ |
|
302
|
|
|
protected function renderXoopsFormTextArea(\Xoops\Form\TextArea $element):string |
|
303
|
|
|
{ |
|
304
|
|
|
$element->suppressRender(['value']); |
|
305
|
|
|
$element->add('class', 'form-control'); |
|
306
|
|
|
$attributes = $element->renderAttributeString(); |
|
307
|
|
|
return '<textarea ' . $attributes . ' ' . $element->getExtra() .' >' |
|
308
|
|
|
. $element->getValue() . '</textarea>'; |
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
|