Completed
Push — master ( 88111b...b3fce7 )
by Michael
05:58
created
plugins/xcgal.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@
 block discarded – undo
9 9
 
10 10
 function smartobject_plugin_xcgal()
11 11
 {
12
-    global $xoopsConfig;
12
+	global $xoopsConfig;
13 13
 
14
-    $pluginInfo                              = [];
15
-    $pluginInfo['items']['album']['caption'] = 'Album';
16
-    $pluginInfo['items']['item']['url']      = 'thumbnails.php?album=%u';
17
-    $pluginInfo['items']['item']['request']  = 'album';
14
+	$pluginInfo                              = [];
15
+	$pluginInfo['items']['album']['caption'] = 'Album';
16
+	$pluginInfo['items']['item']['url']      = 'thumbnails.php?album=%u';
17
+	$pluginInfo['items']['item']['request']  = 'album';
18 18
 
19
-    return $pluginInfo;
19
+	return $pluginInfo;
20 20
 }
Please login to merge, or discard this patch.
plugins/smartsection.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@
 block discarded – undo
9 9
 
10 10
 function smartobject_plugin_smartsection()
11 11
 {
12
-    $pluginInfo = [];
12
+	$pluginInfo = [];
13 13
 
14
-    $pluginInfo['items']['item']['caption'] = 'Article';
15
-    $pluginInfo['items']['item']['url']     = 'item.php?itemid=%u';
16
-    $pluginInfo['items']['item']['request'] = 'itemid';
14
+	$pluginInfo['items']['item']['caption'] = 'Article';
15
+	$pluginInfo['items']['item']['url']     = 'item.php?itemid=%u';
16
+	$pluginInfo['items']['item']['request'] = 'itemid';
17 17
 
18
-    $pluginInfo['items']['category']['caption'] = 'Category';
19
-    $pluginInfo['items']['category']['url']     = 'category.php?categoryid=%u';
20
-    $pluginInfo['items']['category']['request'] = 'categoryid';
18
+	$pluginInfo['items']['category']['caption'] = 'Category';
19
+	$pluginInfo['items']['category']['url']     = 'category.php?categoryid=%u';
20
+	$pluginInfo['items']['category']['request'] = 'categoryid';
21 21
 
22
-    return $pluginInfo;
22
+	return $pluginInfo;
23 23
 }
Please login to merge, or discard this patch.
class/BaseSmartObject.php 3 patches
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     }
177 177
 
178 178
     /**
179
-     * @param        $key
179
+     * @param        string $key
180 180
      * @param        $data_type
181 181
      * @param bool   $itemName
182 182
      * @param string $form_caption
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
213 213
      * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
214 214
      * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
215
-     * @param mixed  $value        default value of this variable
215
+     * @param string|false  $value        default value of this variable
216 216
      */
217 217
     public function quickInitVar(
218 218
         $key,
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     }
228 228
 
229 229
     /**
230
-     * @param        $varname
230
+     * @param        string $varname
231 231
      * @param bool   $displayOnForm
232 232
      * @param string $default
233 233
      */
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
     /**
490 490
      * add an error
491 491
      *
492
-     * @param      $err_str
492
+     * @param      string $err_str
493 493
      * @param bool $prefix
494 494
      * @internal param string $value error to add
495 495
      * @access   public
@@ -751,8 +751,8 @@  discard block
 block discarded – undo
751 751
 
752 752
     /**
753 753
      * @param $key
754
-     * @param $info
755
-     * @param $value
754
+     * @param string $info
755
+     * @param boolean $value
756 756
      */
757 757
     public function setVarInfo($key, $info, $value)
758 758
     {
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
     }
761 761
 
762 762
     /**
763
-     * @param         $key
763
+     * @param         string $key
764 764
      * @param  bool   $editor
765 765
      * @return string
766 766
      */
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
      * @access public
940 940
      * @param  string $key    key of the object's variable to be returned
941 941
      * @param  string $format format to use for the output
942
-     * @return mixed  formatted value of the variable
942
+     * @return string  formatted value of the variable
943 943
      */
944 944
     public function getVar($key, $format = 's')
945 945
     {
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
     }
1250 1250
 
1251 1251
     /**
1252
-     * @param $key
1252
+     * @param string $key
1253 1253
      */
1254 1254
     public function hideFieldFromForm($key)
1255 1255
     {
Please login to merge, or discard this patch.
Indentation   +1401 added lines, -1401 removed lines patch added patch discarded remove patch
@@ -18,31 +18,31 @@  discard block
 block discarded – undo
18 18
 require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
19 19
 
20 20
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
21
-    define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
21
+	define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
22 22
 }
23 23
 if (!defined('XOBJ_DTYPE_CURRENCY')) {
24
-    define('XOBJ_DTYPE_CURRENCY', 200);
24
+	define('XOBJ_DTYPE_CURRENCY', 200);
25 25
 }
26 26
 if (!defined('XOBJ_DTYPE_FLOAT')) {
27
-    define('XOBJ_DTYPE_FLOAT', 201);
27
+	define('XOBJ_DTYPE_FLOAT', 201);
28 28
 }
29 29
 if (!defined('XOBJ_DTYPE_TIME_ONLY')) {
30
-    define('XOBJ_DTYPE_TIME_ONLY', 202);
30
+	define('XOBJ_DTYPE_TIME_ONLY', 202);
31 31
 }
32 32
 if (!defined('XOBJ_DTYPE_URLLINK')) {
33
-    define('XOBJ_DTYPE_URLLINK', 203);
33
+	define('XOBJ_DTYPE_URLLINK', 203);
34 34
 }
35 35
 if (!defined('XOBJ_DTYPE_FILE')) {
36
-    define('XOBJ_DTYPE_FILE', 204);
36
+	define('XOBJ_DTYPE_FILE', 204);
37 37
 }
38 38
 if (!defined('XOBJ_DTYPE_IMAGE')) {
39
-    define('XOBJ_DTYPE_IMAGE', 205);
39
+	define('XOBJ_DTYPE_IMAGE', 205);
40 40
 }
41 41
 if (!defined('XOBJ_DTYPE_FORM_SECTION')) {
42
-    define('XOBJ_DTYPE_FORM_SECTION', 210);
42
+	define('XOBJ_DTYPE_FORM_SECTION', 210);
43 43
 }
44 44
 if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) {
45
-    define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
45
+	define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
46 46
 }
47 47
 
48 48
 /**
@@ -56,1399 +56,1399 @@  discard block
 block discarded – undo
56 56
  */
57 57
 class BaseSmartObject extends \XoopsObject
58 58
 {
59
-    public $_image_path;
60
-    public $_image_url;
61
-
62
-    public $seoEnabled   = false;
63
-    public $titleField;
64
-    public $summaryField = false;
65
-
66
-    /**
67
-     * Reference to the handler managing this object
68
-     *
69
-     * @var PersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
70
-     */
71
-    public $handler;
72
-
73
-    /**
74
-     * References to control objects, managing the form fields of this object
75
-     */
76
-    public $controls = [];
77
-
78
-    /**
79
-     * SmartObject constructor.
80
-     * @param $handler
81
-     */
82
-    public function __construct($handler)
83
-    {
84
-        $this->handler = $handler;
85
-    }
86
-
87
-    /**
88
-     * Checks if the user has a specific access on this object
89
-     *
90
-     * @param $perm_name
91
-     * @return bool: TRUE if user has access, false if not
92
-     * @internal param string $gperm_name name of the permission to test
93
-     */
94
-    public function accessGranted($perm_name)
95
-    {
96
-        $smartPermissionsHandler = new PermissionHandler($this->handler);
97
-
98
-        return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
99
-    }
100
-
101
-    /**
102
-     * @param      $section_name
103
-     * @param bool $value
104
-     * @param bool $hide
105
-     */
106
-    public function addFormSection($section_name, $value = false, $hide = false)
107
-    {
108
-        $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
109
-        $this->vars[$section_name]['hide'] = $hide;
110
-    }
111
-
112
-    /**
113
-     * @param $section_name
114
-     */
115
-    public function closeSection($section_name)
116
-    {
117
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
118
-    }
119
-
120
-    /**
121
-     *
122
-     * @param string $key          key of this field. This needs to be the name of the field in the related database table
123
-     * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
124
-     * @param mixed  $value        default value of this variable
125
-     * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
126
-     * @param int    $maxlength    maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
127
-     * @param string $options      does this data have any select options?
128
-     * @param bool   $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
129
-     * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
130
-     * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
131
-     * @param bool   $sortby       set to TRUE to make this field used to sort objects in SmartObjectTable
132
-     * @param bool   $persistent   set to FALSE if this field is not to be saved in the database
133
-     * @param bool   $displayOnForm
134
-     */
135
-    public function initVar(
136
-        $key,
137
-        $data_type,
138
-        $value = null,
139
-        $required = false,
140
-        $maxlength = null,
141
-        $options = '',
142
-        $multilingual = false,
143
-        $form_caption = '',
144
-        $form_dsc = '',
145
-        $sortby = false,
146
-        $persistent = true,
147
-        $displayOnForm = true
148
-    ) {
149
-        //url_ is reserved for files.
150
-        if (0 === strpos($key, 'url_')) {
151
-            trigger_error("Cannot use variable starting with 'url_'.");
152
-        }
153
-        parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
154
-        if ($this->handler && (!$form_caption || '' === $form_caption)) {
155
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
156
-            if (defined($dyn_form_caption)) {
157
-                $form_caption = constant($dyn_form_caption);
158
-            }
159
-        }
160
-        if ($this->handler && (!$form_dsc || '' === $form_dsc)) {
161
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
162
-            if (defined($dyn_form_dsc)) {
163
-                $form_dsc = constant($dyn_form_dsc);
164
-            }
165
-        }
166
-
167
-        $this->vars[$key] = array_merge($this->vars[$key], [
168
-            'multilingual'        => $multilingual,
169
-            'form_caption'        => $form_caption,
170
-            'form_dsc'            => $form_dsc,
171
-            'sortby'              => $sortby,
172
-            'persistent'          => $persistent,
173
-            'displayOnForm'       => $displayOnForm,
174
-            'displayOnSingleView' => true,
175
-            'readonly'            => false
176
-        ]);
177
-    }
178
-
179
-    /**
180
-     * @param        $key
181
-     * @param        $data_type
182
-     * @param bool   $itemName
183
-     * @param string $form_caption
184
-     * @param bool   $sortby
185
-     * @param string $value
186
-     * @param bool   $displayOnForm
187
-     * @param bool   $required
188
-     */
189
-    public function initNonPersistableVar(
190
-        $key,
191
-        $data_type,
192
-        $itemName = false,
193
-        $form_caption = '',
194
-        $sortby = false,
195
-        $value = '',
196
-        $displayOnForm = false,
197
-        $required = false
198
-    ) {
199
-        $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
200
-        $this->vars[$key]['itemName'] = $itemName;
201
-    }
202
-
203
-    /**
204
-     * Quickly initiate a var
205
-     *
206
-     * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
207
-     *
208
-     * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
209
-     * - all other vars are NULL or '' depending of the parameter
210
-     *
211
-     * @param string $key          key of this field. This needs to be the name of the field in the related database table
212
-     * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
213
-     * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
214
-     * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
215
-     * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
216
-     * @param mixed  $value        default value of this variable
217
-     */
218
-    public function quickInitVar(
219
-        $key,
220
-        $data_type,
221
-        $required = false,
222
-        $form_caption = '',
223
-        $form_dsc = '',
224
-        $value = null
225
-    ) {
226
-        $maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null;
227
-        $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
228
-    }
229
-
230
-    /**
231
-     * @param        $varname
232
-     * @param bool   $displayOnForm
233
-     * @param string $default
234
-     */
235
-    public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
236
-    {
237
-        switch ($varname) {
238
-            case 'dohtml':
239
-                $value = 'notdefined' !== $default ? $default : true;
240
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
241
-                $this->setControl($varname, 'yesno');
242
-                break;
243
-
244
-            case 'dobr':
245
-                $value = ('notdefined' === $default) ? true : $default;
246
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
247
-                $this->setControl($varname, 'yesno');
248
-                break;
249
-
250
-            case 'doimage':
251
-                $value = 'notdefined' !== $default ? $default : true;
252
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
253
-                $this->setControl($varname, 'yesno');
254
-                break;
255
-
256
-            case 'dosmiley':
257
-                $value = 'notdefined' !== $default ? $default : true;
258
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
259
-                $this->setControl($varname, 'yesno');
260
-                break;
261
-
262
-            case 'doxcode':
263
-                $value = 'notdefined' !== $default ? $default : true;
264
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
265
-                $this->setControl($varname, 'yesno');
266
-                break;
267
-
268
-            case 'meta_keywords':
269
-                $value = 'notdefined' !== $default ? $default : '';
270
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
271
-                $this->setControl('meta_keywords', [
272
-                    'name'        => 'textarea',
273
-                    'form_editor' => 'textarea'
274
-                ]);
275
-                break;
276
-
277
-            case 'meta_description':
278
-                $value = 'notdefined' !== $default ? $default : '';
279
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
280
-                $this->setControl('meta_description', [
281
-                    'name'        => 'textarea',
282
-                    'form_editor' => 'textarea'
283
-                ]);
284
-                break;
285
-
286
-            case 'short_url':
287
-                $value = 'notdefined' !== $default ? $default : '';
288
-                $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
289
-                break;
290
-
291
-            case 'hierarchy_path':
292
-                $value = 'notdefined' !== $default ? $default : '';
293
-                $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
294
-                break;
295
-
296
-            case 'counter':
297
-                $value = 'notdefined' !== $default ? $default : 0;
298
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
299
-                break;
300
-
301
-            case 'weight':
302
-                $value = 'notdefined' !== $default ? $default : 0;
303
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
304
-                break;
305
-            case 'custom_css':
306
-                $value = 'notdefined' !== $default ? $default : '';
307
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
308
-                $this->setControl('custom_css', [
309
-                    'name'        => 'textarea',
310
-                    'form_editor' => 'textarea'
311
-                ]);
312
-                break;
313
-        }
314
-        $this->hideFieldFromSingleView($varname);
315
-    }
316
-
317
-    /**
318
-     * Set control information for an instance variable
319
-     *
320
-     * The $options parameter can be a string or an array. Using a string
321
-     * is the quickest way:
322
-     *
323
-     * $this->setControl('date', 'date_time');
324
-     *
325
-     * This will create a date and time selectbox for the 'date' var on the
326
-     * form to edit or create this item.
327
-     *
328
-     * Here are the currently supported controls:
329
-     *
330
-     *      - color
331
-     *      - country
332
-     *      - date_time
333
-     *      - date
334
-     *      - email
335
-     *      - group
336
-     *      - group_multi
337
-     *      - image
338
-     *      - imageupload
339
-     *      - label
340
-     *      - language
341
-     *      - parentcategory
342
-     *      - password
343
-     *      - select_multi
344
-     *      - select
345
-     *      - text
346
-     *      - textarea
347
-     *      - theme
348
-     *      - theme_multi
349
-     *      - timezone
350
-     *      - user
351
-     *      - user_multi
352
-     *      - yesno
353
-     *
354
-     * Now, using an array as $options, you can customize what information to
355
-     * use in the control. For example, if one needs to display a select box for
356
-     * the user to choose the status of an item. We only need to tell SmartObject
357
-     * what method to execute within what handler to retreive the options of the
358
-     * selectbox.
359
-     *
360
-     * $this->setControl('status', array('name' => false,
361
-     *                                   'itemHandler' => 'item',
362
-     *                                   'method' => 'getStatus',
363
-     *                                   'module' => 'smartshop'));
364
-     *
365
-     * In this example, the array elements are the following:
366
-     *      - name: false, as we don't need to set a special control here.
367
-     *               we will use the default control related to the object type (defined in initVar)
368
-     *      - itemHandler: name of the object for which we will use the handler
369
-     *      - method: name of the method of this handler that we will execute
370
-     *      - module: name of the module from wich the handler is
371
-     *
372
-     * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
373
-     * populate this selectbox with the result from SmartshopItemHandler::getStatus()
374
-     *
375
-     * Another example of the use of $options as an array is for TextArea:
376
-     *
377
-     * $this->setControl('body', array('name' => 'textarea',
378
-     *                                   'form_editor' => 'default'));
379
-     *
380
-     * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
381
-     * the 'default' editor, providing it is defined in the module
382
-     * preferences: $xoopsModuleConfig['default_editor']
383
-     *
384
-     * Of course, you can force the use of a specific editor:
385
-     *
386
-     * $this->setControl('body', array('name' => 'textarea',
387
-     *                                   'form_editor' => 'koivi'));
388
-     *
389
-     * Here is a list of supported editor:
390
-     *      - tiny: TinyEditor
391
-     *      - dhtmltextarea: XOOPS DHTML Area
392
-     *      - fckeditor: FCKEditor
393
-     *      - inbetween: InBetween
394
-     *      - koivi: Koivi
395
-     *      - spaw: Spaw WYSIWYG Editor
396
-     *      - htmlarea: HTMLArea
397
-     *      - textarea: basic textarea with no options
398
-     *
399
-     * @param string $var name of the variable for which we want to set a control
400
-     * @param array  $options
401
-     */
402
-    public function setControl($var, $options = [])
403
-    {
404
-        if (isset($this->controls[$var])) {
405
-            unset($this->controls[$var]);
406
-        }
407
-        if (is_string($options)) {
408
-            $options = ['name' => $options];
409
-        }
410
-        $this->controls[$var] = $options;
411
-    }
412
-
413
-    /**
414
-     * Get control information for an instance variable
415
-     *
416
-     * @param  string $var
417
-     * @return bool|mixed
418
-     */
419
-    public function getControl($var)
420
-    {
421
-        return isset($this->controls[$var]) ? $this->controls[$var] : false;
422
-    }
423
-
424
-    /**
425
-     * Create the form for this object
426
-     *
427
-     * @param         $form_caption
428
-     * @param         $form_name
429
-     * @param  bool   $form_action
430
-     * @param  string $submit_button_caption
431
-     * @param  bool   $cancel_js_action
432
-     * @param  bool   $captcha
433
-     * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
434
-     *                                      object for this object
435
-     * @see SmartObjectForm::SmartObjectForm()
436
-     */
437
-    public function getForm(
438
-        $form_caption,
439
-        $form_name,
440
-        $form_action = false,
441
-        $submit_button_caption = _CO_SOBJECT_SUBMIT,
442
-        $cancel_js_action = false,
443
-        $captcha = false
444
-    ) {
59
+	public $_image_path;
60
+	public $_image_url;
61
+
62
+	public $seoEnabled   = false;
63
+	public $titleField;
64
+	public $summaryField = false;
65
+
66
+	/**
67
+	 * Reference to the handler managing this object
68
+	 *
69
+	 * @var PersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
70
+	 */
71
+	public $handler;
72
+
73
+	/**
74
+	 * References to control objects, managing the form fields of this object
75
+	 */
76
+	public $controls = [];
77
+
78
+	/**
79
+	 * SmartObject constructor.
80
+	 * @param $handler
81
+	 */
82
+	public function __construct($handler)
83
+	{
84
+		$this->handler = $handler;
85
+	}
86
+
87
+	/**
88
+	 * Checks if the user has a specific access on this object
89
+	 *
90
+	 * @param $perm_name
91
+	 * @return bool: TRUE if user has access, false if not
92
+	 * @internal param string $gperm_name name of the permission to test
93
+	 */
94
+	public function accessGranted($perm_name)
95
+	{
96
+		$smartPermissionsHandler = new PermissionHandler($this->handler);
97
+
98
+		return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
99
+	}
100
+
101
+	/**
102
+	 * @param      $section_name
103
+	 * @param bool $value
104
+	 * @param bool $hide
105
+	 */
106
+	public function addFormSection($section_name, $value = false, $hide = false)
107
+	{
108
+		$this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
109
+		$this->vars[$section_name]['hide'] = $hide;
110
+	}
111
+
112
+	/**
113
+	 * @param $section_name
114
+	 */
115
+	public function closeSection($section_name)
116
+	{
117
+		$this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
118
+	}
119
+
120
+	/**
121
+	 *
122
+	 * @param string $key          key of this field. This needs to be the name of the field in the related database table
123
+	 * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
124
+	 * @param mixed  $value        default value of this variable
125
+	 * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
126
+	 * @param int    $maxlength    maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
127
+	 * @param string $options      does this data have any select options?
128
+	 * @param bool   $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
129
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
130
+	 * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
131
+	 * @param bool   $sortby       set to TRUE to make this field used to sort objects in SmartObjectTable
132
+	 * @param bool   $persistent   set to FALSE if this field is not to be saved in the database
133
+	 * @param bool   $displayOnForm
134
+	 */
135
+	public function initVar(
136
+		$key,
137
+		$data_type,
138
+		$value = null,
139
+		$required = false,
140
+		$maxlength = null,
141
+		$options = '',
142
+		$multilingual = false,
143
+		$form_caption = '',
144
+		$form_dsc = '',
145
+		$sortby = false,
146
+		$persistent = true,
147
+		$displayOnForm = true
148
+	) {
149
+		//url_ is reserved for files.
150
+		if (0 === strpos($key, 'url_')) {
151
+			trigger_error("Cannot use variable starting with 'url_'.");
152
+		}
153
+		parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
154
+		if ($this->handler && (!$form_caption || '' === $form_caption)) {
155
+			$dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
156
+			if (defined($dyn_form_caption)) {
157
+				$form_caption = constant($dyn_form_caption);
158
+			}
159
+		}
160
+		if ($this->handler && (!$form_dsc || '' === $form_dsc)) {
161
+			$dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
162
+			if (defined($dyn_form_dsc)) {
163
+				$form_dsc = constant($dyn_form_dsc);
164
+			}
165
+		}
166
+
167
+		$this->vars[$key] = array_merge($this->vars[$key], [
168
+			'multilingual'        => $multilingual,
169
+			'form_caption'        => $form_caption,
170
+			'form_dsc'            => $form_dsc,
171
+			'sortby'              => $sortby,
172
+			'persistent'          => $persistent,
173
+			'displayOnForm'       => $displayOnForm,
174
+			'displayOnSingleView' => true,
175
+			'readonly'            => false
176
+		]);
177
+	}
178
+
179
+	/**
180
+	 * @param        $key
181
+	 * @param        $data_type
182
+	 * @param bool   $itemName
183
+	 * @param string $form_caption
184
+	 * @param bool   $sortby
185
+	 * @param string $value
186
+	 * @param bool   $displayOnForm
187
+	 * @param bool   $required
188
+	 */
189
+	public function initNonPersistableVar(
190
+		$key,
191
+		$data_type,
192
+		$itemName = false,
193
+		$form_caption = '',
194
+		$sortby = false,
195
+		$value = '',
196
+		$displayOnForm = false,
197
+		$required = false
198
+	) {
199
+		$this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
200
+		$this->vars[$key]['itemName'] = $itemName;
201
+	}
202
+
203
+	/**
204
+	 * Quickly initiate a var
205
+	 *
206
+	 * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
207
+	 *
208
+	 * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
209
+	 * - all other vars are NULL or '' depending of the parameter
210
+	 *
211
+	 * @param string $key          key of this field. This needs to be the name of the field in the related database table
212
+	 * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
213
+	 * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
214
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
215
+	 * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
216
+	 * @param mixed  $value        default value of this variable
217
+	 */
218
+	public function quickInitVar(
219
+		$key,
220
+		$data_type,
221
+		$required = false,
222
+		$form_caption = '',
223
+		$form_dsc = '',
224
+		$value = null
225
+	) {
226
+		$maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null;
227
+		$this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
228
+	}
229
+
230
+	/**
231
+	 * @param        $varname
232
+	 * @param bool   $displayOnForm
233
+	 * @param string $default
234
+	 */
235
+	public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
236
+	{
237
+		switch ($varname) {
238
+			case 'dohtml':
239
+				$value = 'notdefined' !== $default ? $default : true;
240
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
241
+				$this->setControl($varname, 'yesno');
242
+				break;
243
+
244
+			case 'dobr':
245
+				$value = ('notdefined' === $default) ? true : $default;
246
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
247
+				$this->setControl($varname, 'yesno');
248
+				break;
249
+
250
+			case 'doimage':
251
+				$value = 'notdefined' !== $default ? $default : true;
252
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
253
+				$this->setControl($varname, 'yesno');
254
+				break;
255
+
256
+			case 'dosmiley':
257
+				$value = 'notdefined' !== $default ? $default : true;
258
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
259
+				$this->setControl($varname, 'yesno');
260
+				break;
261
+
262
+			case 'doxcode':
263
+				$value = 'notdefined' !== $default ? $default : true;
264
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
265
+				$this->setControl($varname, 'yesno');
266
+				break;
267
+
268
+			case 'meta_keywords':
269
+				$value = 'notdefined' !== $default ? $default : '';
270
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
271
+				$this->setControl('meta_keywords', [
272
+					'name'        => 'textarea',
273
+					'form_editor' => 'textarea'
274
+				]);
275
+				break;
276
+
277
+			case 'meta_description':
278
+				$value = 'notdefined' !== $default ? $default : '';
279
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
280
+				$this->setControl('meta_description', [
281
+					'name'        => 'textarea',
282
+					'form_editor' => 'textarea'
283
+				]);
284
+				break;
285
+
286
+			case 'short_url':
287
+				$value = 'notdefined' !== $default ? $default : '';
288
+				$this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
289
+				break;
290
+
291
+			case 'hierarchy_path':
292
+				$value = 'notdefined' !== $default ? $default : '';
293
+				$this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
294
+				break;
295
+
296
+			case 'counter':
297
+				$value = 'notdefined' !== $default ? $default : 0;
298
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
299
+				break;
300
+
301
+			case 'weight':
302
+				$value = 'notdefined' !== $default ? $default : 0;
303
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
304
+				break;
305
+			case 'custom_css':
306
+				$value = 'notdefined' !== $default ? $default : '';
307
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
308
+				$this->setControl('custom_css', [
309
+					'name'        => 'textarea',
310
+					'form_editor' => 'textarea'
311
+				]);
312
+				break;
313
+		}
314
+		$this->hideFieldFromSingleView($varname);
315
+	}
316
+
317
+	/**
318
+	 * Set control information for an instance variable
319
+	 *
320
+	 * The $options parameter can be a string or an array. Using a string
321
+	 * is the quickest way:
322
+	 *
323
+	 * $this->setControl('date', 'date_time');
324
+	 *
325
+	 * This will create a date and time selectbox for the 'date' var on the
326
+	 * form to edit or create this item.
327
+	 *
328
+	 * Here are the currently supported controls:
329
+	 *
330
+	 *      - color
331
+	 *      - country
332
+	 *      - date_time
333
+	 *      - date
334
+	 *      - email
335
+	 *      - group
336
+	 *      - group_multi
337
+	 *      - image
338
+	 *      - imageupload
339
+	 *      - label
340
+	 *      - language
341
+	 *      - parentcategory
342
+	 *      - password
343
+	 *      - select_multi
344
+	 *      - select
345
+	 *      - text
346
+	 *      - textarea
347
+	 *      - theme
348
+	 *      - theme_multi
349
+	 *      - timezone
350
+	 *      - user
351
+	 *      - user_multi
352
+	 *      - yesno
353
+	 *
354
+	 * Now, using an array as $options, you can customize what information to
355
+	 * use in the control. For example, if one needs to display a select box for
356
+	 * the user to choose the status of an item. We only need to tell SmartObject
357
+	 * what method to execute within what handler to retreive the options of the
358
+	 * selectbox.
359
+	 *
360
+	 * $this->setControl('status', array('name' => false,
361
+	 *                                   'itemHandler' => 'item',
362
+	 *                                   'method' => 'getStatus',
363
+	 *                                   'module' => 'smartshop'));
364
+	 *
365
+	 * In this example, the array elements are the following:
366
+	 *      - name: false, as we don't need to set a special control here.
367
+	 *               we will use the default control related to the object type (defined in initVar)
368
+	 *      - itemHandler: name of the object for which we will use the handler
369
+	 *      - method: name of the method of this handler that we will execute
370
+	 *      - module: name of the module from wich the handler is
371
+	 *
372
+	 * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
373
+	 * populate this selectbox with the result from SmartshopItemHandler::getStatus()
374
+	 *
375
+	 * Another example of the use of $options as an array is for TextArea:
376
+	 *
377
+	 * $this->setControl('body', array('name' => 'textarea',
378
+	 *                                   'form_editor' => 'default'));
379
+	 *
380
+	 * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
381
+	 * the 'default' editor, providing it is defined in the module
382
+	 * preferences: $xoopsModuleConfig['default_editor']
383
+	 *
384
+	 * Of course, you can force the use of a specific editor:
385
+	 *
386
+	 * $this->setControl('body', array('name' => 'textarea',
387
+	 *                                   'form_editor' => 'koivi'));
388
+	 *
389
+	 * Here is a list of supported editor:
390
+	 *      - tiny: TinyEditor
391
+	 *      - dhtmltextarea: XOOPS DHTML Area
392
+	 *      - fckeditor: FCKEditor
393
+	 *      - inbetween: InBetween
394
+	 *      - koivi: Koivi
395
+	 *      - spaw: Spaw WYSIWYG Editor
396
+	 *      - htmlarea: HTMLArea
397
+	 *      - textarea: basic textarea with no options
398
+	 *
399
+	 * @param string $var name of the variable for which we want to set a control
400
+	 * @param array  $options
401
+	 */
402
+	public function setControl($var, $options = [])
403
+	{
404
+		if (isset($this->controls[$var])) {
405
+			unset($this->controls[$var]);
406
+		}
407
+		if (is_string($options)) {
408
+			$options = ['name' => $options];
409
+		}
410
+		$this->controls[$var] = $options;
411
+	}
412
+
413
+	/**
414
+	 * Get control information for an instance variable
415
+	 *
416
+	 * @param  string $var
417
+	 * @return bool|mixed
418
+	 */
419
+	public function getControl($var)
420
+	{
421
+		return isset($this->controls[$var]) ? $this->controls[$var] : false;
422
+	}
423
+
424
+	/**
425
+	 * Create the form for this object
426
+	 *
427
+	 * @param         $form_caption
428
+	 * @param         $form_name
429
+	 * @param  bool   $form_action
430
+	 * @param  string $submit_button_caption
431
+	 * @param  bool   $cancel_js_action
432
+	 * @param  bool   $captcha
433
+	 * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
434
+	 *                                      object for this object
435
+	 * @see SmartObjectForm::SmartObjectForm()
436
+	 */
437
+	public function getForm(
438
+		$form_caption,
439
+		$form_name,
440
+		$form_action = false,
441
+		$submit_button_caption = _CO_SOBJECT_SUBMIT,
442
+		$cancel_js_action = false,
443
+		$captcha = false
444
+	) {
445 445
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
446
-        $form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
447
-
448
-        return $form;
449
-    }
450
-
451
-    /**
452
-     * @return array
453
-     */
454
-    public function toArray()
455
-    {
456
-        $ret  = [];
457
-        $vars =& $this->getVars();
458
-        foreach ($vars as $key => $var) {
459
-            $value     = $this->getVar($key);
460
-            $ret[$key] = $value;
461
-        }
462
-        if ('' !== $this->handler->identifierName) {
463
-            $controller = new ObjectController($this->handler);
464
-            /**
465
-             * Addition of some automatic value
466
-             */
467
-            $ret['itemLink']         = $controller->getItemLink($this);
468
-            $ret['itemUrl']          = $controller->getItemLink($this, true);
469
-            $ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
470
-            $ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
471
-            $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
472
-        }
473
-
474
-        // Hightlighting searched words
446
+		$form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
447
+
448
+		return $form;
449
+	}
450
+
451
+	/**
452
+	 * @return array
453
+	 */
454
+	public function toArray()
455
+	{
456
+		$ret  = [];
457
+		$vars =& $this->getVars();
458
+		foreach ($vars as $key => $var) {
459
+			$value     = $this->getVar($key);
460
+			$ret[$key] = $value;
461
+		}
462
+		if ('' !== $this->handler->identifierName) {
463
+			$controller = new ObjectController($this->handler);
464
+			/**
465
+			 * Addition of some automatic value
466
+			 */
467
+			$ret['itemLink']         = $controller->getItemLink($this);
468
+			$ret['itemUrl']          = $controller->getItemLink($this, true);
469
+			$ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
470
+			$ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
471
+			$ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
472
+		}
473
+
474
+		// Hightlighting searched words
475 475
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php';
476
-        $highlight = Smartobject\Utility::getConfig('module_search_highlighter', false, true);
477
-
478
-        if ($highlight && isset($_GET['keywords'])) {
479
-            $myts     = \MyTextSanitizer::getInstance();
480
-            $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
481
-            $h        = new Highlighter($keywords, true, 'smart_highlighter');
482
-            foreach ($this->handler->highlightFields as $field) {
483
-                $ret[$field] = $h->highlight($ret[$field]);
484
-            }
485
-        }
486
-
487
-        return $ret;
488
-    }
489
-
490
-    /**
491
-     * add an error
492
-     *
493
-     * @param      $err_str
494
-     * @param bool $prefix
495
-     * @internal param string $value error to add
496
-     * @access   public
497
-     */
498
-    public function setErrors($err_str, $prefix = false)
499
-    {
500
-        if (is_array($err_str)) {
501
-            foreach ($err_str as $str) {
502
-                $this->setErrors($str, $prefix);
503
-            }
504
-        } else {
505
-            if ($prefix) {
506
-                $err_str = '[' . $prefix . '] ' . $err_str;
507
-            }
508
-            parent::setErrors($err_str);
509
-        }
510
-    }
511
-
512
-    /**
513
-     * @param      $field
514
-     * @param bool $required
515
-     */
516
-    public function setFieldAsRequired($field, $required = true)
517
-    {
518
-        if (is_array($field)) {
519
-            foreach ($field as $v) {
520
-                $this->doSetFieldAsRequired($v, $required);
521
-            }
522
-        } else {
523
-            $this->doSetFieldAsRequired($field, $required);
524
-        }
525
-    }
526
-
527
-    /**
528
-     * @param $field
529
-     */
530
-    public function setFieldForSorting($field)
531
-    {
532
-        if (is_array($field)) {
533
-            foreach ($field as $v) {
534
-                $this->doSetFieldForSorting($v);
535
-            }
536
-        } else {
537
-            $this->doSetFieldForSorting($field);
538
-        }
539
-    }
540
-
541
-    /**
542
-     * @return bool
543
-     */
544
-    public function hasError()
545
-    {
546
-        return count($this->_errors) > 0;
547
-    }
548
-
549
-    /**
550
-     * @param $url
551
-     * @param $path
552
-     */
553
-    public function setImageDir($url, $path)
554
-    {
555
-        $this->_image_url  = $url;
556
-        $this->_image_path = $path;
557
-    }
558
-
559
-    /**
560
-     * Retreive the group that have been granted access to a specific permission for this object
561
-     *
562
-     * @param $group_perm
563
-     * @return string $group_perm name of the permission
564
-     */
565
-    public function getGroupPerm($group_perm)
566
-    {
567
-        if (!$this->handler->getPermissions()) {
568
-            $this->setError("Trying to access a permission that does not exists for thisobject's handler");
569
-
570
-            return false;
571
-        }
572
-
573
-        $smartPermissionsHandler = new PermissionHandler($this->handler);
574
-        $ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
575
-
576
-        if (0 == count($ret)) {
577
-            return false;
578
-        } else {
579
-            return $ret;
580
-        }
581
-    }
582
-
583
-    /**
584
-     * @param  bool $path
585
-     * @return mixed
586
-     */
587
-    public function getImageDir($path = false)
588
-    {
589
-        if ($path) {
590
-            return $this->_image_path;
591
-        } else {
592
-            return $this->_image_url;
593
-        }
594
-    }
595
-
596
-    /**
597
-     * @param  bool $path
598
-     * @return mixed
599
-     */
600
-    public function getUploadDir($path = false)
601
-    {
602
-        if ($path) {
603
-            return $this->_image_path;
604
-        } else {
605
-            return $this->_image_url;
606
-        }
607
-    }
608
-
609
-    /**
610
-     * @param  string $key
611
-     * @param  string $info
612
-     * @return array
613
-     */
614
-    public function getVarInfo($key = '', $info = '')
615
-    {
616
-        if (isset($this->vars[$key][$info])) {
617
-            return $this->vars[$key][$info];
618
-        } elseif ('' === $info && isset($this->vars[$key])) {
619
-            return $this->vars[$key];
620
-        } else {
621
-            return $this->vars;
622
-        }
623
-    }
624
-
625
-    /**
626
-     * Get the id of the object
627
-     *
628
-     * @return int id of this object
629
-     */
630
-    public function id()
631
-    {
632
-        return $this->getVar($this->handler->keyName, 'e');
633
-    }
634
-
635
-    /**
636
-     * Return the value of the title field of this object
637
-     *
638
-     * @param  string $format
639
-     * @return string
640
-     */
641
-    public function title($format = 's')
642
-    {
643
-        return $this->getVar($this->handler->identifierName, $format);
644
-    }
645
-
646
-    /**
647
-     * Return the value of the title field of this object
648
-     *
649
-     * @return string
650
-     */
651
-    public function summary()
652
-    {
653
-        if ($this->handler->summaryName) {
654
-            return $this->getVar($this->handler->summaryName);
655
-        } else {
656
-            return false;
657
-        }
658
-    }
659
-
660
-    /**
661
-     * Retreive the object admin side link, displayijng a SingleView page
662
-     *
663
-     * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
664
-     * @return string user side link to the object
665
-     */
666
-    public function getAdminViewItemLink($onlyUrl = false)
667
-    {
668
-        $controller = new ObjectController($this->handler);
669
-
670
-        return $controller->getAdminViewItemLink($this, $onlyUrl);
671
-    }
672
-
673
-    /**
674
-     * Retreive the object user side link
675
-     *
676
-     * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
677
-     * @return string user side link to the object
678
-     */
679
-    public function getItemLink($onlyUrl = false)
680
-    {
681
-        $controller = new ObjectController($this->handler);
682
-
683
-        return $controller->getItemLink($this, $onlyUrl);
684
-    }
685
-
686
-    /**
687
-     * @param  bool $onlyUrl
688
-     * @param  bool $withimage
689
-     * @param  bool $userSide
690
-     * @return string
691
-     */
692
-    public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
693
-    {
694
-        $controller = new ObjectController($this->handler);
695
-
696
-        return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
697
-    }
698
-
699
-    /**
700
-     * @param  bool $onlyUrl
701
-     * @param  bool $withimage
702
-     * @param  bool $userSide
703
-     * @return string
704
-     */
705
-    public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
706
-    {
707
-        $controller = new ObjectController($this->handler);
708
-
709
-        return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
710
-    }
711
-
712
-    /**
713
-     * @return string
714
-     */
715
-    public function getPrintAndMailLink()
716
-    {
717
-        $controller = new ObjectController($this->handler);
718
-
719
-        return $controller->getPrintAndMailLink($this);
720
-    }
721
-
722
-    /**
723
-     * @param $sortsel
724
-     * @return array|bool
725
-     */
726
-    public function getFieldsForSorting($sortsel)
727
-    {
728
-        $ret = [];
729
-
730
-        foreach ($this->vars as $key => $field_info) {
731
-            if ($field_info['sortby']) {
732
-                $ret[$key]['caption']  = $field_info['form_caption'];
733
-                $ret[$key]['selected'] = $key == $sortsel ? 'selected' : '';
734
-            }
735
-        }
736
-
737
-        if (count($ret) > 0) {
738
-            return $ret;
739
-        } else {
740
-            return false;
741
-        }
742
-    }
743
-
744
-    /**
745
-     * @param $key
746
-     * @param $newType
747
-     */
748
-    public function setType($key, $newType)
749
-    {
750
-        $this->vars[$key]['data_type'] = $newType;
751
-    }
752
-
753
-    /**
754
-     * @param $key
755
-     * @param $info
756
-     * @param $value
757
-     */
758
-    public function setVarInfo($key, $info, $value)
759
-    {
760
-        $this->vars[$key][$info] = $value;
761
-    }
762
-
763
-    /**
764
-     * @param         $key
765
-     * @param  bool   $editor
766
-     * @return string
767
-     */
768
-    public function getValueFor($key, $editor = true)
769
-    {
770
-        global $xoopsModuleConfig;
771
-
772
-        $ret  = $this->getVar($key, 'n');
773
-        $myts = \MyTextSanitizer::getInstance();
774
-
775
-        $control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
776
-        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
777
-
778
-        $html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
779
-        $smiley   = true;
780
-        $xcode    = true;
781
-        $image    = true;
782
-        $br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
783
-        $formatML = true;
784
-
785
-        if ('default' === $form_editor) {
786
-            global $xoopsModuleConfig;
787
-            $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
788
-        }
789
-
790
-        if ($editor) {
791
-            if (defined('XOOPS_EDITOR_IS_HTML')
792
-                && !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) {
793
-                $br       = false;
794
-                $formatML = !$editor;
795
-            } else {
796
-                return htmlspecialchars($ret, ENT_QUOTES);
797
-            }
798
-        }
799
-
800
-        if (method_exists($myts, 'formatForML')) {
801
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
802
-        } else {
803
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
804
-        }
805
-    }
806
-
807
-    /**
808
-     * clean values of all variables of the object for storage.
809
-     * also add slashes whereever needed
810
-     *
811
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
812
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
813
-     * as a string separated by |
814
-     *
815
-     * @return bool true if successful
816
-     * @access public
817
-     */
818
-    public function cleanVars()
819
-    {
820
-        $ts              = \MyTextSanitizer::getInstance();
821
-        $existing_errors = $this->getErrors();
822
-        $this->_errors   = [];
823
-        foreach ($this->vars as $k => $v) {
824
-            $cleanv = $v['value'];
825
-            if (!$v['changed']) {
826
-            } else {
827
-                $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
828
-                switch ($v['data_type']) {
829
-                    case XOBJ_DTYPE_TXTBOX:
830
-                        if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
831
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
832
-                            continue 2;
833
-                        }
834
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
835
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
836
-                            continue 2;
837
-                        }
838
-                        if (!$v['not_gpc']) {
839
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
840
-                        } else {
841
-                            $cleanv = $ts->censorString($cleanv);
842
-                        }
843
-                        break;
844
-                    case XOBJ_DTYPE_TXTAREA:
845
-                        if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
846
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
847
-                            continue 2;
848
-                        }
849
-                        if (!$v['not_gpc']) {
850
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
851
-                        } else {
852
-                            $cleanv = $ts->censorString($cleanv);
853
-                        }
854
-                        break;
855
-                    case XOBJ_DTYPE_SOURCE:
856
-                        if (!$v['not_gpc']) {
857
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
858
-                        } else {
859
-                            $cleanv = $cleanv;
860
-                        }
861
-                        break;
862
-                    case XOBJ_DTYPE_INT:
863
-                    case XOBJ_DTYPE_TIME_ONLY:
864
-                        $cleanv = (int)$cleanv;
865
-                        break;
866
-
867
-                    case XOBJ_DTYPE_CURRENCY:
868
-                        $cleanv = Smartobject\Utility::getCurrency($cleanv);
869
-                        break;
870
-
871
-                    case XOBJ_DTYPE_FLOAT:
872
-                        $cleanv = Smartobject\Utility::float($cleanv);
873
-                        break;
874
-
875
-                    case XOBJ_DTYPE_EMAIL:
876
-                        if ($v['required'] && '' === $cleanv) {
877
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
878
-                            continue 2;
879
-                        }
880
-                        if ('' !== $cleanv
881
-                            && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
882
-                            $this->setErrors('Invalid Email');
883
-                            continue 2;
884
-                        }
885
-                        if (!$v['not_gpc']) {
886
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
887
-                        }
888
-                        break;
889
-                    case XOBJ_DTYPE_URL:
890
-                        if ($v['required'] && '' === $cleanv) {
891
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
892
-                            continue 2;
893
-                        }
894
-                        if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
895
-                            $cleanv = 'http://' . $cleanv;
896
-                        }
897
-                        if (!$v['not_gpc']) {
898
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
899
-                        }
900
-                        break;
901
-                    case XOBJ_DTYPE_SIMPLE_ARRAY:
902
-                        $cleanv = implode('|', $cleanv);
903
-                        break;
904
-                    case XOBJ_DTYPE_ARRAY:
905
-                        $cleanv = serialize($cleanv);
906
-                        break;
907
-                    case XOBJ_DTYPE_STIME:
908
-                    case XOBJ_DTYPE_MTIME:
909
-                    case XOBJ_DTYPE_LTIME:
910
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
911
-                        if (!($cleanv > 0)) {
912
-                            $cleanv = strtotime($cleanv);
913
-                        }
914
-                        break;
915
-                    default:
916
-                        break;
917
-                }
918
-            }
919
-            $this->cleanVars[$k] =& $cleanv;
920
-            unset($cleanv);
921
-        }
922
-        if (count($this->_errors) > 0) {
923
-            $this->_errors = array_merge($existing_errors, $this->_errors);
924
-
925
-            return false;
926
-        }
927
-        $this->_errors = array_merge($existing_errors, $this->_errors);
928
-        $this->unsetDirty();
929
-
930
-        return true;
931
-    }
932
-
933
-    /**
934
-     * returns a specific variable for the object in a proper format
935
-     *
936
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
937
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
938
-     * as a string separated by |
939
-     *
940
-     * @access public
941
-     * @param  string $key    key of the object's variable to be returned
942
-     * @param  string $format format to use for the output
943
-     * @return mixed  formatted value of the variable
944
-     */
945
-    public function getVar($key, $format = 's')
946
-    {
947
-        global $myts;
948
-
949
-        $ret = $this->vars[$key]['value'];
950
-
951
-        switch ($this->vars[$key]['data_type']) {
952
-
953
-            case XOBJ_DTYPE_TXTBOX:
954
-                switch (strtolower($format)) {
955
-                    case 's':
956
-                    case 'show':
957
-                        // ML Hack by marcan
958
-                        $ts  = \MyTextSanitizer::getInstance();
959
-                        $ret = $ts->htmlSpecialChars($ret);
960
-
961
-                        if (method_exists($myts, 'formatForML')) {
962
-                            return $ts->formatForML($ret);
963
-                        } else {
964
-                            return $ret;
965
-                        }
966
-                        break 1;
967
-                    // End of ML Hack by marcan
968
-
969
-                    case 'clean':
970
-                        $ts = \MyTextSanitizer::getInstance();
971
-
972
-                        $ret = Smartobject\Utility::getHtml2text($ret);
973
-                        $ret = Smartobject\Utility::purifyText($ret);
974
-
975
-                        if (method_exists($myts, 'formatForML')) {
976
-                            return $ts->formatForML($ret);
977
-                        } else {
978
-                            return $ret;
979
-                        }
980
-                        break 1;
981
-                    // End of ML Hack by marcan
982
-
983
-                    case 'e':
984
-                    case 'edit':
985
-                        $ts = \MyTextSanitizer::getInstance();
986
-
987
-                        return $ts->htmlSpecialChars($ret);
988
-                        break 1;
989
-                    case 'p':
990
-                    case 'preview':
991
-                    case 'f':
992
-                    case 'formpreview':
993
-                        $ts = \MyTextSanitizer::getInstance();
994
-
995
-                        return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
996
-                        break 1;
997
-                    case 'n':
998
-                    case 'none':
999
-                    default:
1000
-                        break 1;
1001
-                }
1002
-                break;
1003
-            case XOBJ_DTYPE_LTIME:
1004
-                switch (strtolower($format)) {
1005
-                    case 's':
1006
-                    case 'show':
1007
-                    case 'p':
1008
-                    case 'preview':
1009
-                    case 'f':
1010
-                    case 'formpreview':
1011
-                        $ret = formatTimestamp($ret, _DATESTRING);
1012
-
1013
-                        return $ret;
1014
-                        break 1;
1015
-                    case 'n':
1016
-                    case 'none':
1017
-                    case 'e':
1018
-                    case 'edit':
1019
-                        break 1;
1020
-                    default:
1021
-                        break 1;
1022
-                }
1023
-                break;
1024
-            case XOBJ_DTYPE_STIME:
1025
-                switch (strtolower($format)) {
1026
-                    case 's':
1027
-                    case 'show':
1028
-                    case 'p':
1029
-                    case 'preview':
1030
-                    case 'f':
1031
-                    case 'formpreview':
1032
-                        $ret = formatTimestamp($ret, _SHORTDATESTRING);
1033
-
1034
-                        return $ret;
1035
-                        break 1;
1036
-                    case 'n':
1037
-                    case 'none':
1038
-                    case 'e':
1039
-                    case 'edit':
1040
-                        break 1;
1041
-                    default:
1042
-                        break 1;
1043
-                }
1044
-                break;
1045
-            case XOBJ_DTYPE_TIME_ONLY:
1046
-                switch (strtolower($format)) {
1047
-                    case 's':
1048
-                    case 'show':
1049
-                    case 'p':
1050
-                    case 'preview':
1051
-                    case 'f':
1052
-                    case 'formpreview':
1053
-                        $ret = formatTimestamp($ret, 'G:i');
1054
-
1055
-                        return $ret;
1056
-                        break 1;
1057
-                    case 'n':
1058
-                    case 'none':
1059
-                    case 'e':
1060
-                    case 'edit':
1061
-                        break 1;
1062
-                    default:
1063
-                        break 1;
1064
-                }
1065
-                break;
1066
-
1067
-            case XOBJ_DTYPE_CURRENCY:
1068
-                $decimal_section_original = strstr($ret, '.');
1069
-                $decimal_section          = $decimal_section_original;
1070
-                if ($decimal_section) {
1071
-                    if (1 == strlen($decimal_section)) {
1072
-                        $decimal_section = '.00';
1073
-                    } elseif (2 == strlen($decimal_section)) {
1074
-                        $decimal_section .= '0';
1075
-                    }
1076
-                    $ret = str_replace($decimal_section_original, $decimal_section, $ret);
1077
-                } else {
1078
-                    $ret .= '.00';
1079
-                }
1080
-                break;
1081
-
1082
-            case XOBJ_DTYPE_TXTAREA:
1083
-                switch (strtolower($format)) {
1084
-                    case 's':
1085
-                    case 'show':
1086
-                        $ts   = \MyTextSanitizer::getInstance();
1087
-                        $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1088
-
1089
-                        $xcode = (!isset($this->vars['doxcode']['value'])
1090
-                                  || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1091
-
1092
-                        $smiley = (!isset($this->vars['dosmiley']['value'])
1093
-                                   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1094
-                        $image  = (!isset($this->vars['doimage']['value'])
1095
-                                   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1096
-                        $br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1097
-
1098
-                        /**
1099
-                         * Hack by marcan <INBOX> for SCSPRO
1100
-                         * Setting mastop as the main editor
1101
-                         */
1102
-                        if (defined('XOOPS_EDITOR_IS_HTML')) {
1103
-                            $br = false;
1104
-                        }
1105
-
1106
-                        /**
1107
-                         * Hack by marcan <INBOX> for SCSPRO
1108
-                         * Setting mastop as the main editor
1109
-                         */
1110
-
1111
-                        return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1112
-                        break 1;
1113
-                    case 'e':
1114
-                    case 'edit':
1115
-                        return htmlspecialchars($ret, ENT_QUOTES);
1116
-                        break 1;
1117
-                    case 'p':
1118
-                    case 'preview':
1119
-                        $ts     = \MyTextSanitizer::getInstance();
1120
-                        $html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1121
-                        $xcode  = (!isset($this->vars['doxcode']['value'])
1122
-                                   || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1123
-                        $smiley = (!isset($this->vars['dosmiley']['value'])
1124
-                                   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1125
-                        $image  = (!isset($this->vars['doimage']['value'])
1126
-                                   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1127
-                        $br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1128
-
1129
-                        return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1130
-                        break 1;
1131
-                    case 'f':
1132
-                    case 'formpreview':
1133
-                        $ts = \MyTextSanitizer::getInstance();
1134
-
1135
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1136
-                        break 1;
1137
-                    case 'n':
1138
-                    case 'none':
1139
-                    default:
1140
-                        break 1;
1141
-                }
1142
-                break;
1143
-            case XOBJ_DTYPE_SIMPLE_ARRAY:
1144
-                $ret =& explode('|', $ret);
1145
-                break;
1146
-            case XOBJ_DTYPE_ARRAY:
1147
-                $ret =& unserialize($ret);
1148
-                break;
1149
-            case XOBJ_DTYPE_SOURCE:
1150
-                switch (strtolower($format)) {
1151
-                    case 's':
1152
-                    case 'show':
1153
-                        break 1;
1154
-                    case 'e':
1155
-                    case 'edit':
1156
-                        return htmlspecialchars($ret, ENT_QUOTES);
1157
-                        break 1;
1158
-                    case 'p':
1159
-                    case 'preview':
1160
-                        $ts = \MyTextSanitizer::getInstance();
1161
-
1162
-                        return $ts->stripSlashesGPC($ret);
1163
-                        break 1;
1164
-                    case 'f':
1165
-                    case 'formpreview':
1166
-                        $ts = \MyTextSanitizer::getInstance();
1167
-
1168
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1169
-                        break 1;
1170
-                    case 'n':
1171
-                    case 'none':
1172
-                    default:
1173
-                        break 1;
1174
-                }
1175
-                break;
1176
-            default:
1177
-                if ('' !== $this->vars[$key]['options'] && '' != $ret) {
1178
-                    switch (strtolower($format)) {
1179
-                        case 's':
1180
-                        case 'show':
1181
-                            $selected = explode('|', $ret);
1182
-                            $options  = explode('|', $this->vars[$key]['options']);
1183
-                            $i        = 1;
1184
-                            $ret      = [];
1185
-                            foreach ($options as $op) {
1186
-                                if (in_array($i, $selected)) {
1187
-                                    $ret[] = $op;
1188
-                                }
1189
-                                ++$i;
1190
-                            }
1191
-
1192
-                            return implode(', ', $ret);
1193
-                        case 'e':
1194
-                        case 'edit':
1195
-                            $ret = explode('|', $ret);
1196
-                            break 1;
1197
-                        default:
1198
-                            break 1;
1199
-                    }
1200
-                }
1201
-                break;
1202
-        }
1203
-
1204
-        return $ret;
1205
-    }
1206
-
1207
-    /**
1208
-     * @param $key
1209
-     */
1210
-    public function doMakeFieldreadOnly($key)
1211
-    {
1212
-        if (isset($this->vars[$key])) {
1213
-            $this->vars[$key]['readonly']      = true;
1214
-            $this->vars[$key]['displayOnForm'] = true;
1215
-        }
1216
-    }
1217
-
1218
-    /**
1219
-     * @param $key
1220
-     */
1221
-    public function makeFieldReadOnly($key)
1222
-    {
1223
-        if (is_array($key)) {
1224
-            foreach ($key as $v) {
1225
-                $this->doMakeFieldreadOnly($v);
1226
-            }
1227
-        } else {
1228
-            $this->doMakeFieldreadOnly($key);
1229
-        }
1230
-    }
1231
-
1232
-    /**
1233
-     * @param $key
1234
-     */
1235
-    public function doHideFieldFromForm($key)
1236
-    {
1237
-        if (isset($this->vars[$key])) {
1238
-            $this->vars[$key]['displayOnForm'] = false;
1239
-        }
1240
-    }
1241
-
1242
-    /**
1243
-     * @param $key
1244
-     */
1245
-    public function doHideFieldFromSingleView($key)
1246
-    {
1247
-        if (isset($this->vars[$key])) {
1248
-            $this->vars[$key]['displayOnSingleView'] = false;
1249
-        }
1250
-    }
1251
-
1252
-    /**
1253
-     * @param $key
1254
-     */
1255
-    public function hideFieldFromForm($key)
1256
-    {
1257
-        if (is_array($key)) {
1258
-            foreach ($key as $v) {
1259
-                $this->doHideFieldFromForm($v);
1260
-            }
1261
-        } else {
1262
-            $this->doHideFieldFromForm($key);
1263
-        }
1264
-    }
1265
-
1266
-    /**
1267
-     * @param $key
1268
-     */
1269
-    public function hideFieldFromSingleView($key)
1270
-    {
1271
-        if (is_array($key)) {
1272
-            foreach ($key as $v) {
1273
-                $this->doHideFieldFromSingleView($v);
1274
-            }
1275
-        } else {
1276
-            $this->doHideFieldFromSingleView($key);
1277
-        }
1278
-    }
1279
-
1280
-    /**
1281
-     * @param $key
1282
-     */
1283
-    public function doShowFieldOnForm($key)
1284
-    {
1285
-        if (isset($this->vars[$key])) {
1286
-            $this->vars[$key]['displayOnForm'] = true;
1287
-        }
1288
-    }
1289
-
1290
-    /**
1291
-     * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1292
-     *
1293
-     * @param  bool  $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1294
-     * @param  bool  $userSide  for futur use, to do something different on the user side
1295
-     * @param  array $actions
1296
-     * @param  bool  $headerAsRow
1297
-     * @return string content of the template if $fetchOnly or nothing if !$fetchOnly
1298
-     */
1299
-    public function displaySingleObject(
1300
-        $fetchOnly = false,
1301
-        $userSide = false,
1302
-        $actions = [],
1303
-        $headerAsRow = true
1304
-    ) {
476
+		$highlight = Smartobject\Utility::getConfig('module_search_highlighter', false, true);
477
+
478
+		if ($highlight && isset($_GET['keywords'])) {
479
+			$myts     = \MyTextSanitizer::getInstance();
480
+			$keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
481
+			$h        = new Highlighter($keywords, true, 'smart_highlighter');
482
+			foreach ($this->handler->highlightFields as $field) {
483
+				$ret[$field] = $h->highlight($ret[$field]);
484
+			}
485
+		}
486
+
487
+		return $ret;
488
+	}
489
+
490
+	/**
491
+	 * add an error
492
+	 *
493
+	 * @param      $err_str
494
+	 * @param bool $prefix
495
+	 * @internal param string $value error to add
496
+	 * @access   public
497
+	 */
498
+	public function setErrors($err_str, $prefix = false)
499
+	{
500
+		if (is_array($err_str)) {
501
+			foreach ($err_str as $str) {
502
+				$this->setErrors($str, $prefix);
503
+			}
504
+		} else {
505
+			if ($prefix) {
506
+				$err_str = '[' . $prefix . '] ' . $err_str;
507
+			}
508
+			parent::setErrors($err_str);
509
+		}
510
+	}
511
+
512
+	/**
513
+	 * @param      $field
514
+	 * @param bool $required
515
+	 */
516
+	public function setFieldAsRequired($field, $required = true)
517
+	{
518
+		if (is_array($field)) {
519
+			foreach ($field as $v) {
520
+				$this->doSetFieldAsRequired($v, $required);
521
+			}
522
+		} else {
523
+			$this->doSetFieldAsRequired($field, $required);
524
+		}
525
+	}
526
+
527
+	/**
528
+	 * @param $field
529
+	 */
530
+	public function setFieldForSorting($field)
531
+	{
532
+		if (is_array($field)) {
533
+			foreach ($field as $v) {
534
+				$this->doSetFieldForSorting($v);
535
+			}
536
+		} else {
537
+			$this->doSetFieldForSorting($field);
538
+		}
539
+	}
540
+
541
+	/**
542
+	 * @return bool
543
+	 */
544
+	public function hasError()
545
+	{
546
+		return count($this->_errors) > 0;
547
+	}
548
+
549
+	/**
550
+	 * @param $url
551
+	 * @param $path
552
+	 */
553
+	public function setImageDir($url, $path)
554
+	{
555
+		$this->_image_url  = $url;
556
+		$this->_image_path = $path;
557
+	}
558
+
559
+	/**
560
+	 * Retreive the group that have been granted access to a specific permission for this object
561
+	 *
562
+	 * @param $group_perm
563
+	 * @return string $group_perm name of the permission
564
+	 */
565
+	public function getGroupPerm($group_perm)
566
+	{
567
+		if (!$this->handler->getPermissions()) {
568
+			$this->setError("Trying to access a permission that does not exists for thisobject's handler");
569
+
570
+			return false;
571
+		}
572
+
573
+		$smartPermissionsHandler = new PermissionHandler($this->handler);
574
+		$ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
575
+
576
+		if (0 == count($ret)) {
577
+			return false;
578
+		} else {
579
+			return $ret;
580
+		}
581
+	}
582
+
583
+	/**
584
+	 * @param  bool $path
585
+	 * @return mixed
586
+	 */
587
+	public function getImageDir($path = false)
588
+	{
589
+		if ($path) {
590
+			return $this->_image_path;
591
+		} else {
592
+			return $this->_image_url;
593
+		}
594
+	}
595
+
596
+	/**
597
+	 * @param  bool $path
598
+	 * @return mixed
599
+	 */
600
+	public function getUploadDir($path = false)
601
+	{
602
+		if ($path) {
603
+			return $this->_image_path;
604
+		} else {
605
+			return $this->_image_url;
606
+		}
607
+	}
608
+
609
+	/**
610
+	 * @param  string $key
611
+	 * @param  string $info
612
+	 * @return array
613
+	 */
614
+	public function getVarInfo($key = '', $info = '')
615
+	{
616
+		if (isset($this->vars[$key][$info])) {
617
+			return $this->vars[$key][$info];
618
+		} elseif ('' === $info && isset($this->vars[$key])) {
619
+			return $this->vars[$key];
620
+		} else {
621
+			return $this->vars;
622
+		}
623
+	}
624
+
625
+	/**
626
+	 * Get the id of the object
627
+	 *
628
+	 * @return int id of this object
629
+	 */
630
+	public function id()
631
+	{
632
+		return $this->getVar($this->handler->keyName, 'e');
633
+	}
634
+
635
+	/**
636
+	 * Return the value of the title field of this object
637
+	 *
638
+	 * @param  string $format
639
+	 * @return string
640
+	 */
641
+	public function title($format = 's')
642
+	{
643
+		return $this->getVar($this->handler->identifierName, $format);
644
+	}
645
+
646
+	/**
647
+	 * Return the value of the title field of this object
648
+	 *
649
+	 * @return string
650
+	 */
651
+	public function summary()
652
+	{
653
+		if ($this->handler->summaryName) {
654
+			return $this->getVar($this->handler->summaryName);
655
+		} else {
656
+			return false;
657
+		}
658
+	}
659
+
660
+	/**
661
+	 * Retreive the object admin side link, displayijng a SingleView page
662
+	 *
663
+	 * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
664
+	 * @return string user side link to the object
665
+	 */
666
+	public function getAdminViewItemLink($onlyUrl = false)
667
+	{
668
+		$controller = new ObjectController($this->handler);
669
+
670
+		return $controller->getAdminViewItemLink($this, $onlyUrl);
671
+	}
672
+
673
+	/**
674
+	 * Retreive the object user side link
675
+	 *
676
+	 * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
677
+	 * @return string user side link to the object
678
+	 */
679
+	public function getItemLink($onlyUrl = false)
680
+	{
681
+		$controller = new ObjectController($this->handler);
682
+
683
+		return $controller->getItemLink($this, $onlyUrl);
684
+	}
685
+
686
+	/**
687
+	 * @param  bool $onlyUrl
688
+	 * @param  bool $withimage
689
+	 * @param  bool $userSide
690
+	 * @return string
691
+	 */
692
+	public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
693
+	{
694
+		$controller = new ObjectController($this->handler);
695
+
696
+		return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
697
+	}
698
+
699
+	/**
700
+	 * @param  bool $onlyUrl
701
+	 * @param  bool $withimage
702
+	 * @param  bool $userSide
703
+	 * @return string
704
+	 */
705
+	public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
706
+	{
707
+		$controller = new ObjectController($this->handler);
708
+
709
+		return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
710
+	}
711
+
712
+	/**
713
+	 * @return string
714
+	 */
715
+	public function getPrintAndMailLink()
716
+	{
717
+		$controller = new ObjectController($this->handler);
718
+
719
+		return $controller->getPrintAndMailLink($this);
720
+	}
721
+
722
+	/**
723
+	 * @param $sortsel
724
+	 * @return array|bool
725
+	 */
726
+	public function getFieldsForSorting($sortsel)
727
+	{
728
+		$ret = [];
729
+
730
+		foreach ($this->vars as $key => $field_info) {
731
+			if ($field_info['sortby']) {
732
+				$ret[$key]['caption']  = $field_info['form_caption'];
733
+				$ret[$key]['selected'] = $key == $sortsel ? 'selected' : '';
734
+			}
735
+		}
736
+
737
+		if (count($ret) > 0) {
738
+			return $ret;
739
+		} else {
740
+			return false;
741
+		}
742
+	}
743
+
744
+	/**
745
+	 * @param $key
746
+	 * @param $newType
747
+	 */
748
+	public function setType($key, $newType)
749
+	{
750
+		$this->vars[$key]['data_type'] = $newType;
751
+	}
752
+
753
+	/**
754
+	 * @param $key
755
+	 * @param $info
756
+	 * @param $value
757
+	 */
758
+	public function setVarInfo($key, $info, $value)
759
+	{
760
+		$this->vars[$key][$info] = $value;
761
+	}
762
+
763
+	/**
764
+	 * @param         $key
765
+	 * @param  bool   $editor
766
+	 * @return string
767
+	 */
768
+	public function getValueFor($key, $editor = true)
769
+	{
770
+		global $xoopsModuleConfig;
771
+
772
+		$ret  = $this->getVar($key, 'n');
773
+		$myts = \MyTextSanitizer::getInstance();
774
+
775
+		$control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
776
+		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
777
+
778
+		$html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
779
+		$smiley   = true;
780
+		$xcode    = true;
781
+		$image    = true;
782
+		$br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
783
+		$formatML = true;
784
+
785
+		if ('default' === $form_editor) {
786
+			global $xoopsModuleConfig;
787
+			$form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
788
+		}
789
+
790
+		if ($editor) {
791
+			if (defined('XOOPS_EDITOR_IS_HTML')
792
+				&& !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) {
793
+				$br       = false;
794
+				$formatML = !$editor;
795
+			} else {
796
+				return htmlspecialchars($ret, ENT_QUOTES);
797
+			}
798
+		}
799
+
800
+		if (method_exists($myts, 'formatForML')) {
801
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
802
+		} else {
803
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
804
+		}
805
+	}
806
+
807
+	/**
808
+	 * clean values of all variables of the object for storage.
809
+	 * also add slashes whereever needed
810
+	 *
811
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
812
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
813
+	 * as a string separated by |
814
+	 *
815
+	 * @return bool true if successful
816
+	 * @access public
817
+	 */
818
+	public function cleanVars()
819
+	{
820
+		$ts              = \MyTextSanitizer::getInstance();
821
+		$existing_errors = $this->getErrors();
822
+		$this->_errors   = [];
823
+		foreach ($this->vars as $k => $v) {
824
+			$cleanv = $v['value'];
825
+			if (!$v['changed']) {
826
+			} else {
827
+				$cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
828
+				switch ($v['data_type']) {
829
+					case XOBJ_DTYPE_TXTBOX:
830
+						if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
831
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
832
+							continue 2;
833
+						}
834
+						if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
835
+							$this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
836
+							continue 2;
837
+						}
838
+						if (!$v['not_gpc']) {
839
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
840
+						} else {
841
+							$cleanv = $ts->censorString($cleanv);
842
+						}
843
+						break;
844
+					case XOBJ_DTYPE_TXTAREA:
845
+						if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
846
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
847
+							continue 2;
848
+						}
849
+						if (!$v['not_gpc']) {
850
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
851
+						} else {
852
+							$cleanv = $ts->censorString($cleanv);
853
+						}
854
+						break;
855
+					case XOBJ_DTYPE_SOURCE:
856
+						if (!$v['not_gpc']) {
857
+							$cleanv = $ts->stripSlashesGPC($cleanv);
858
+						} else {
859
+							$cleanv = $cleanv;
860
+						}
861
+						break;
862
+					case XOBJ_DTYPE_INT:
863
+					case XOBJ_DTYPE_TIME_ONLY:
864
+						$cleanv = (int)$cleanv;
865
+						break;
866
+
867
+					case XOBJ_DTYPE_CURRENCY:
868
+						$cleanv = Smartobject\Utility::getCurrency($cleanv);
869
+						break;
870
+
871
+					case XOBJ_DTYPE_FLOAT:
872
+						$cleanv = Smartobject\Utility::float($cleanv);
873
+						break;
874
+
875
+					case XOBJ_DTYPE_EMAIL:
876
+						if ($v['required'] && '' === $cleanv) {
877
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
878
+							continue 2;
879
+						}
880
+						if ('' !== $cleanv
881
+							&& !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
882
+							$this->setErrors('Invalid Email');
883
+							continue 2;
884
+						}
885
+						if (!$v['not_gpc']) {
886
+							$cleanv = $ts->stripSlashesGPC($cleanv);
887
+						}
888
+						break;
889
+					case XOBJ_DTYPE_URL:
890
+						if ($v['required'] && '' === $cleanv) {
891
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
892
+							continue 2;
893
+						}
894
+						if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
895
+							$cleanv = 'http://' . $cleanv;
896
+						}
897
+						if (!$v['not_gpc']) {
898
+							$cleanv =& $ts->stripSlashesGPC($cleanv);
899
+						}
900
+						break;
901
+					case XOBJ_DTYPE_SIMPLE_ARRAY:
902
+						$cleanv = implode('|', $cleanv);
903
+						break;
904
+					case XOBJ_DTYPE_ARRAY:
905
+						$cleanv = serialize($cleanv);
906
+						break;
907
+					case XOBJ_DTYPE_STIME:
908
+					case XOBJ_DTYPE_MTIME:
909
+					case XOBJ_DTYPE_LTIME:
910
+						$cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
911
+						if (!($cleanv > 0)) {
912
+							$cleanv = strtotime($cleanv);
913
+						}
914
+						break;
915
+					default:
916
+						break;
917
+				}
918
+			}
919
+			$this->cleanVars[$k] =& $cleanv;
920
+			unset($cleanv);
921
+		}
922
+		if (count($this->_errors) > 0) {
923
+			$this->_errors = array_merge($existing_errors, $this->_errors);
924
+
925
+			return false;
926
+		}
927
+		$this->_errors = array_merge($existing_errors, $this->_errors);
928
+		$this->unsetDirty();
929
+
930
+		return true;
931
+	}
932
+
933
+	/**
934
+	 * returns a specific variable for the object in a proper format
935
+	 *
936
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
937
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
938
+	 * as a string separated by |
939
+	 *
940
+	 * @access public
941
+	 * @param  string $key    key of the object's variable to be returned
942
+	 * @param  string $format format to use for the output
943
+	 * @return mixed  formatted value of the variable
944
+	 */
945
+	public function getVar($key, $format = 's')
946
+	{
947
+		global $myts;
948
+
949
+		$ret = $this->vars[$key]['value'];
950
+
951
+		switch ($this->vars[$key]['data_type']) {
952
+
953
+			case XOBJ_DTYPE_TXTBOX:
954
+				switch (strtolower($format)) {
955
+					case 's':
956
+					case 'show':
957
+						// ML Hack by marcan
958
+						$ts  = \MyTextSanitizer::getInstance();
959
+						$ret = $ts->htmlSpecialChars($ret);
960
+
961
+						if (method_exists($myts, 'formatForML')) {
962
+							return $ts->formatForML($ret);
963
+						} else {
964
+							return $ret;
965
+						}
966
+						break 1;
967
+					// End of ML Hack by marcan
968
+
969
+					case 'clean':
970
+						$ts = \MyTextSanitizer::getInstance();
971
+
972
+						$ret = Smartobject\Utility::getHtml2text($ret);
973
+						$ret = Smartobject\Utility::purifyText($ret);
974
+
975
+						if (method_exists($myts, 'formatForML')) {
976
+							return $ts->formatForML($ret);
977
+						} else {
978
+							return $ret;
979
+						}
980
+						break 1;
981
+					// End of ML Hack by marcan
982
+
983
+					case 'e':
984
+					case 'edit':
985
+						$ts = \MyTextSanitizer::getInstance();
986
+
987
+						return $ts->htmlSpecialChars($ret);
988
+						break 1;
989
+					case 'p':
990
+					case 'preview':
991
+					case 'f':
992
+					case 'formpreview':
993
+						$ts = \MyTextSanitizer::getInstance();
994
+
995
+						return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
996
+						break 1;
997
+					case 'n':
998
+					case 'none':
999
+					default:
1000
+						break 1;
1001
+				}
1002
+				break;
1003
+			case XOBJ_DTYPE_LTIME:
1004
+				switch (strtolower($format)) {
1005
+					case 's':
1006
+					case 'show':
1007
+					case 'p':
1008
+					case 'preview':
1009
+					case 'f':
1010
+					case 'formpreview':
1011
+						$ret = formatTimestamp($ret, _DATESTRING);
1012
+
1013
+						return $ret;
1014
+						break 1;
1015
+					case 'n':
1016
+					case 'none':
1017
+					case 'e':
1018
+					case 'edit':
1019
+						break 1;
1020
+					default:
1021
+						break 1;
1022
+				}
1023
+				break;
1024
+			case XOBJ_DTYPE_STIME:
1025
+				switch (strtolower($format)) {
1026
+					case 's':
1027
+					case 'show':
1028
+					case 'p':
1029
+					case 'preview':
1030
+					case 'f':
1031
+					case 'formpreview':
1032
+						$ret = formatTimestamp($ret, _SHORTDATESTRING);
1033
+
1034
+						return $ret;
1035
+						break 1;
1036
+					case 'n':
1037
+					case 'none':
1038
+					case 'e':
1039
+					case 'edit':
1040
+						break 1;
1041
+					default:
1042
+						break 1;
1043
+				}
1044
+				break;
1045
+			case XOBJ_DTYPE_TIME_ONLY:
1046
+				switch (strtolower($format)) {
1047
+					case 's':
1048
+					case 'show':
1049
+					case 'p':
1050
+					case 'preview':
1051
+					case 'f':
1052
+					case 'formpreview':
1053
+						$ret = formatTimestamp($ret, 'G:i');
1054
+
1055
+						return $ret;
1056
+						break 1;
1057
+					case 'n':
1058
+					case 'none':
1059
+					case 'e':
1060
+					case 'edit':
1061
+						break 1;
1062
+					default:
1063
+						break 1;
1064
+				}
1065
+				break;
1066
+
1067
+			case XOBJ_DTYPE_CURRENCY:
1068
+				$decimal_section_original = strstr($ret, '.');
1069
+				$decimal_section          = $decimal_section_original;
1070
+				if ($decimal_section) {
1071
+					if (1 == strlen($decimal_section)) {
1072
+						$decimal_section = '.00';
1073
+					} elseif (2 == strlen($decimal_section)) {
1074
+						$decimal_section .= '0';
1075
+					}
1076
+					$ret = str_replace($decimal_section_original, $decimal_section, $ret);
1077
+				} else {
1078
+					$ret .= '.00';
1079
+				}
1080
+				break;
1081
+
1082
+			case XOBJ_DTYPE_TXTAREA:
1083
+				switch (strtolower($format)) {
1084
+					case 's':
1085
+					case 'show':
1086
+						$ts   = \MyTextSanitizer::getInstance();
1087
+						$html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1088
+
1089
+						$xcode = (!isset($this->vars['doxcode']['value'])
1090
+								  || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1091
+
1092
+						$smiley = (!isset($this->vars['dosmiley']['value'])
1093
+								   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1094
+						$image  = (!isset($this->vars['doimage']['value'])
1095
+								   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1096
+						$br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1097
+
1098
+						/**
1099
+						 * Hack by marcan <INBOX> for SCSPRO
1100
+						 * Setting mastop as the main editor
1101
+						 */
1102
+						if (defined('XOOPS_EDITOR_IS_HTML')) {
1103
+							$br = false;
1104
+						}
1105
+
1106
+						/**
1107
+						 * Hack by marcan <INBOX> for SCSPRO
1108
+						 * Setting mastop as the main editor
1109
+						 */
1110
+
1111
+						return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1112
+						break 1;
1113
+					case 'e':
1114
+					case 'edit':
1115
+						return htmlspecialchars($ret, ENT_QUOTES);
1116
+						break 1;
1117
+					case 'p':
1118
+					case 'preview':
1119
+						$ts     = \MyTextSanitizer::getInstance();
1120
+						$html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1121
+						$xcode  = (!isset($this->vars['doxcode']['value'])
1122
+								   || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1123
+						$smiley = (!isset($this->vars['dosmiley']['value'])
1124
+								   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1125
+						$image  = (!isset($this->vars['doimage']['value'])
1126
+								   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1127
+						$br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1128
+
1129
+						return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1130
+						break 1;
1131
+					case 'f':
1132
+					case 'formpreview':
1133
+						$ts = \MyTextSanitizer::getInstance();
1134
+
1135
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1136
+						break 1;
1137
+					case 'n':
1138
+					case 'none':
1139
+					default:
1140
+						break 1;
1141
+				}
1142
+				break;
1143
+			case XOBJ_DTYPE_SIMPLE_ARRAY:
1144
+				$ret =& explode('|', $ret);
1145
+				break;
1146
+			case XOBJ_DTYPE_ARRAY:
1147
+				$ret =& unserialize($ret);
1148
+				break;
1149
+			case XOBJ_DTYPE_SOURCE:
1150
+				switch (strtolower($format)) {
1151
+					case 's':
1152
+					case 'show':
1153
+						break 1;
1154
+					case 'e':
1155
+					case 'edit':
1156
+						return htmlspecialchars($ret, ENT_QUOTES);
1157
+						break 1;
1158
+					case 'p':
1159
+					case 'preview':
1160
+						$ts = \MyTextSanitizer::getInstance();
1161
+
1162
+						return $ts->stripSlashesGPC($ret);
1163
+						break 1;
1164
+					case 'f':
1165
+					case 'formpreview':
1166
+						$ts = \MyTextSanitizer::getInstance();
1167
+
1168
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1169
+						break 1;
1170
+					case 'n':
1171
+					case 'none':
1172
+					default:
1173
+						break 1;
1174
+				}
1175
+				break;
1176
+			default:
1177
+				if ('' !== $this->vars[$key]['options'] && '' != $ret) {
1178
+					switch (strtolower($format)) {
1179
+						case 's':
1180
+						case 'show':
1181
+							$selected = explode('|', $ret);
1182
+							$options  = explode('|', $this->vars[$key]['options']);
1183
+							$i        = 1;
1184
+							$ret      = [];
1185
+							foreach ($options as $op) {
1186
+								if (in_array($i, $selected)) {
1187
+									$ret[] = $op;
1188
+								}
1189
+								++$i;
1190
+							}
1191
+
1192
+							return implode(', ', $ret);
1193
+						case 'e':
1194
+						case 'edit':
1195
+							$ret = explode('|', $ret);
1196
+							break 1;
1197
+						default:
1198
+							break 1;
1199
+					}
1200
+				}
1201
+				break;
1202
+		}
1203
+
1204
+		return $ret;
1205
+	}
1206
+
1207
+	/**
1208
+	 * @param $key
1209
+	 */
1210
+	public function doMakeFieldreadOnly($key)
1211
+	{
1212
+		if (isset($this->vars[$key])) {
1213
+			$this->vars[$key]['readonly']      = true;
1214
+			$this->vars[$key]['displayOnForm'] = true;
1215
+		}
1216
+	}
1217
+
1218
+	/**
1219
+	 * @param $key
1220
+	 */
1221
+	public function makeFieldReadOnly($key)
1222
+	{
1223
+		if (is_array($key)) {
1224
+			foreach ($key as $v) {
1225
+				$this->doMakeFieldreadOnly($v);
1226
+			}
1227
+		} else {
1228
+			$this->doMakeFieldreadOnly($key);
1229
+		}
1230
+	}
1231
+
1232
+	/**
1233
+	 * @param $key
1234
+	 */
1235
+	public function doHideFieldFromForm($key)
1236
+	{
1237
+		if (isset($this->vars[$key])) {
1238
+			$this->vars[$key]['displayOnForm'] = false;
1239
+		}
1240
+	}
1241
+
1242
+	/**
1243
+	 * @param $key
1244
+	 */
1245
+	public function doHideFieldFromSingleView($key)
1246
+	{
1247
+		if (isset($this->vars[$key])) {
1248
+			$this->vars[$key]['displayOnSingleView'] = false;
1249
+		}
1250
+	}
1251
+
1252
+	/**
1253
+	 * @param $key
1254
+	 */
1255
+	public function hideFieldFromForm($key)
1256
+	{
1257
+		if (is_array($key)) {
1258
+			foreach ($key as $v) {
1259
+				$this->doHideFieldFromForm($v);
1260
+			}
1261
+		} else {
1262
+			$this->doHideFieldFromForm($key);
1263
+		}
1264
+	}
1265
+
1266
+	/**
1267
+	 * @param $key
1268
+	 */
1269
+	public function hideFieldFromSingleView($key)
1270
+	{
1271
+		if (is_array($key)) {
1272
+			foreach ($key as $v) {
1273
+				$this->doHideFieldFromSingleView($v);
1274
+			}
1275
+		} else {
1276
+			$this->doHideFieldFromSingleView($key);
1277
+		}
1278
+	}
1279
+
1280
+	/**
1281
+	 * @param $key
1282
+	 */
1283
+	public function doShowFieldOnForm($key)
1284
+	{
1285
+		if (isset($this->vars[$key])) {
1286
+			$this->vars[$key]['displayOnForm'] = true;
1287
+		}
1288
+	}
1289
+
1290
+	/**
1291
+	 * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1292
+	 *
1293
+	 * @param  bool  $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1294
+	 * @param  bool  $userSide  for futur use, to do something different on the user side
1295
+	 * @param  array $actions
1296
+	 * @param  bool  $headerAsRow
1297
+	 * @return string content of the template if $fetchOnly or nothing if !$fetchOnly
1298
+	 */
1299
+	public function displaySingleObject(
1300
+		$fetchOnly = false,
1301
+		$userSide = false,
1302
+		$actions = [],
1303
+		$headerAsRow = true
1304
+	) {
1305 1305
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1306
-        $singleview = new SingleView($this, $userSide, $actions, $headerAsRow);
1307
-        // add all fields mark as displayOnSingleView except the keyid
1308
-        foreach ($this->vars as $key => $var) {
1309
-            if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1310
-                $is_header = ($key == $this->handler->identifierName);
1311
-                $singleview->addRow(new ObjectRow($key, false, $is_header));
1312
-            }
1313
-        }
1314
-
1315
-        if ($fetchOnly) {
1316
-            $ret = $singleview->render($fetchOnly);
1317
-
1318
-            return $ret;
1319
-        } else {
1320
-            $singleview->render($fetchOnly);
1321
-        }
1322
-    }
1323
-
1324
-    /**
1325
-     * @param $key
1326
-     */
1327
-    public function doDisplayFieldOnSingleView($key)
1328
-    {
1329
-        if (isset($this->vars[$key])) {
1330
-            $this->vars[$key]['displayOnSingleView'] = true;
1331
-        }
1332
-    }
1333
-
1334
-    /**
1335
-     * @param      $field
1336
-     * @param bool $required
1337
-     */
1338
-    public function doSetFieldAsRequired($field, $required = true)
1339
-    {
1340
-        $this->setVarInfo($field, 'required', $required);
1341
-    }
1342
-
1343
-    /**
1344
-     * @param $field
1345
-     */
1346
-    public function doSetFieldForSorting($field)
1347
-    {
1348
-        $this->setVarInfo($field, 'sortby', true);
1349
-    }
1350
-
1351
-    /**
1352
-     * @param $key
1353
-     */
1354
-    public function showFieldOnForm($key)
1355
-    {
1356
-        if (is_array($key)) {
1357
-            foreach ($key as $v) {
1358
-                $this->doShowFieldOnForm($v);
1359
-            }
1360
-        } else {
1361
-            $this->doShowFieldOnForm($key);
1362
-        }
1363
-    }
1364
-
1365
-    /**
1366
-     * @param $key
1367
-     */
1368
-    public function displayFieldOnSingleView($key)
1369
-    {
1370
-        if (is_array($key)) {
1371
-            foreach ($key as $v) {
1372
-                $this->doDisplayFieldOnSingleView($v);
1373
-            }
1374
-        } else {
1375
-            $this->doDisplayFieldOnSingleView($key);
1376
-        }
1377
-    }
1378
-
1379
-    /**
1380
-     * @param $key
1381
-     */
1382
-    public function doSetAdvancedFormFields($key)
1383
-    {
1384
-        if (isset($this->vars[$key])) {
1385
-            $this->vars[$key]['advancedform'] = true;
1386
-        }
1387
-    }
1388
-
1389
-    /**
1390
-     * @param $key
1391
-     */
1392
-    public function setAdvancedFormFields($key)
1393
-    {
1394
-        if (is_array($key)) {
1395
-            foreach ($key as $v) {
1396
-                $this->doSetAdvancedFormFields($v);
1397
-            }
1398
-        } else {
1399
-            $this->doSetAdvancedFormFields($key);
1400
-        }
1401
-    }
1402
-
1403
-    /**
1404
-     * @param $key
1405
-     * @return mixed
1406
-     */
1407
-    public function getUrlLinkObj($key)
1408
-    {
1409
-        $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1410
-        $urllinkid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1411
-        if (0 != $urllinkid) {
1412
-            return $smartobjectLinkurlHandler->get($urllinkid);
1413
-        } else {
1414
-            return $smartobjectLinkurlHandler->create();
1415
-        }
1416
-    }
1417
-
1418
-    /**
1419
-     * @param $urlLinkObj
1420
-     * @return mixed
1421
-     */
1422
-    public function &storeUrlLinkObj($urlLinkObj)
1423
-    {
1424
-        $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1425
-
1426
-        return $smartobjectLinkurlHandler->insert($urlLinkObj);
1427
-    }
1428
-
1429
-    /**
1430
-     * @param $key
1431
-     * @return mixed
1432
-     */
1433
-    public function getFileObj($key)
1434
-    {
1435
-        $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1436
-        $fileid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1437
-        if (0 != $fileid) {
1438
-            return $smartobjectFileHandler->get($fileid);
1439
-        } else {
1440
-            return $smartobjectFileHandler->create();
1441
-        }
1442
-    }
1443
-
1444
-    /**
1445
-     * @param $fileObj
1446
-     * @return mixed
1447
-     */
1448
-    public function &storeFileObj($fileObj)
1449
-    {
1450
-        $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1451
-
1452
-        return $smartobjectFileHandler->insert($fileObj);
1453
-    }
1306
+		$singleview = new SingleView($this, $userSide, $actions, $headerAsRow);
1307
+		// add all fields mark as displayOnSingleView except the keyid
1308
+		foreach ($this->vars as $key => $var) {
1309
+			if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1310
+				$is_header = ($key == $this->handler->identifierName);
1311
+				$singleview->addRow(new ObjectRow($key, false, $is_header));
1312
+			}
1313
+		}
1314
+
1315
+		if ($fetchOnly) {
1316
+			$ret = $singleview->render($fetchOnly);
1317
+
1318
+			return $ret;
1319
+		} else {
1320
+			$singleview->render($fetchOnly);
1321
+		}
1322
+	}
1323
+
1324
+	/**
1325
+	 * @param $key
1326
+	 */
1327
+	public function doDisplayFieldOnSingleView($key)
1328
+	{
1329
+		if (isset($this->vars[$key])) {
1330
+			$this->vars[$key]['displayOnSingleView'] = true;
1331
+		}
1332
+	}
1333
+
1334
+	/**
1335
+	 * @param      $field
1336
+	 * @param bool $required
1337
+	 */
1338
+	public function doSetFieldAsRequired($field, $required = true)
1339
+	{
1340
+		$this->setVarInfo($field, 'required', $required);
1341
+	}
1342
+
1343
+	/**
1344
+	 * @param $field
1345
+	 */
1346
+	public function doSetFieldForSorting($field)
1347
+	{
1348
+		$this->setVarInfo($field, 'sortby', true);
1349
+	}
1350
+
1351
+	/**
1352
+	 * @param $key
1353
+	 */
1354
+	public function showFieldOnForm($key)
1355
+	{
1356
+		if (is_array($key)) {
1357
+			foreach ($key as $v) {
1358
+				$this->doShowFieldOnForm($v);
1359
+			}
1360
+		} else {
1361
+			$this->doShowFieldOnForm($key);
1362
+		}
1363
+	}
1364
+
1365
+	/**
1366
+	 * @param $key
1367
+	 */
1368
+	public function displayFieldOnSingleView($key)
1369
+	{
1370
+		if (is_array($key)) {
1371
+			foreach ($key as $v) {
1372
+				$this->doDisplayFieldOnSingleView($v);
1373
+			}
1374
+		} else {
1375
+			$this->doDisplayFieldOnSingleView($key);
1376
+		}
1377
+	}
1378
+
1379
+	/**
1380
+	 * @param $key
1381
+	 */
1382
+	public function doSetAdvancedFormFields($key)
1383
+	{
1384
+		if (isset($this->vars[$key])) {
1385
+			$this->vars[$key]['advancedform'] = true;
1386
+		}
1387
+	}
1388
+
1389
+	/**
1390
+	 * @param $key
1391
+	 */
1392
+	public function setAdvancedFormFields($key)
1393
+	{
1394
+		if (is_array($key)) {
1395
+			foreach ($key as $v) {
1396
+				$this->doSetAdvancedFormFields($v);
1397
+			}
1398
+		} else {
1399
+			$this->doSetAdvancedFormFields($key);
1400
+		}
1401
+	}
1402
+
1403
+	/**
1404
+	 * @param $key
1405
+	 * @return mixed
1406
+	 */
1407
+	public function getUrlLinkObj($key)
1408
+	{
1409
+		$smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1410
+		$urllinkid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1411
+		if (0 != $urllinkid) {
1412
+			return $smartobjectLinkurlHandler->get($urllinkid);
1413
+		} else {
1414
+			return $smartobjectLinkurlHandler->create();
1415
+		}
1416
+	}
1417
+
1418
+	/**
1419
+	 * @param $urlLinkObj
1420
+	 * @return mixed
1421
+	 */
1422
+	public function &storeUrlLinkObj($urlLinkObj)
1423
+	{
1424
+		$smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1425
+
1426
+		return $smartobjectLinkurlHandler->insert($urlLinkObj);
1427
+	}
1428
+
1429
+	/**
1430
+	 * @param $key
1431
+	 * @return mixed
1432
+	 */
1433
+	public function getFileObj($key)
1434
+	{
1435
+		$smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1436
+		$fileid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1437
+		if (0 != $fileid) {
1438
+			return $smartobjectFileHandler->get($fileid);
1439
+		} else {
1440
+			return $smartobjectFileHandler->create();
1441
+		}
1442
+	}
1443
+
1444
+	/**
1445
+	 * @param $fileObj
1446
+	 * @return mixed
1447
+	 */
1448
+	public function &storeFileObj($fileObj)
1449
+	{
1450
+		$smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1451
+
1452
+		return $smartobjectFileHandler->insert($fileObj);
1453
+	}
1454 1454
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
17 17
 
18
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
18
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
19 19
 
20 20
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
21 21
     define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function closeSection($section_name)
116 116
     {
117
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
117
+        $this->initVar('close_section_'.$section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
118 118
     }
119 119
 
120 120
     /**
@@ -152,13 +152,13 @@  discard block
 block discarded – undo
152 152
         }
153 153
         parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
154 154
         if ($this->handler && (!$form_caption || '' === $form_caption)) {
155
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
155
+            $dyn_form_caption = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key);
156 156
             if (defined($dyn_form_caption)) {
157 157
                 $form_caption = constant($dyn_form_caption);
158 158
             }
159 159
         }
160 160
         if ($this->handler && (!$form_dsc || '' === $form_dsc)) {
161
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
161
+            $dyn_form_dsc = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key.'_DSC');
162 162
             if (defined($dyn_form_dsc)) {
163 163
                 $form_dsc = constant($dyn_form_dsc);
164 164
             }
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     public function toArray()
455 455
     {
456 456
         $ret  = [];
457
-        $vars =& $this->getVars();
457
+        $vars = & $this->getVars();
458 458
         foreach ($vars as $key => $var) {
459 459
             $value     = $this->getVar($key);
460 460
             $ret[$key] = $value;
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
             }
504 504
         } else {
505 505
             if ($prefix) {
506
-                $err_str = '[' . $prefix . '] ' . $err_str;
506
+                $err_str = '['.$prefix.'] '.$err_str;
507 507
             }
508 508
             parent::setErrors($err_str);
509 509
         }
@@ -831,8 +831,8 @@  discard block
 block discarded – undo
831 831
                             $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
832 832
                             continue 2;
833 833
                         }
834
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
835
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
834
+                        if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) {
835
+                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength']));
836 836
                             continue 2;
837 837
                         }
838 838
                         if (!$v['not_gpc']) {
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
                         break;
862 862
                     case XOBJ_DTYPE_INT:
863 863
                     case XOBJ_DTYPE_TIME_ONLY:
864
-                        $cleanv = (int)$cleanv;
864
+                        $cleanv = (int) $cleanv;
865 865
                         break;
866 866
 
867 867
                     case XOBJ_DTYPE_CURRENCY:
@@ -892,10 +892,10 @@  discard block
 block discarded – undo
892 892
                             continue 2;
893 893
                         }
894 894
                         if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
895
-                            $cleanv = 'http://' . $cleanv;
895
+                            $cleanv = 'http://'.$cleanv;
896 896
                         }
897 897
                         if (!$v['not_gpc']) {
898
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
898
+                            $cleanv = & $ts->stripSlashesGPC($cleanv);
899 899
                         }
900 900
                         break;
901 901
                     case XOBJ_DTYPE_SIMPLE_ARRAY:
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
                     case XOBJ_DTYPE_STIME:
908 908
                     case XOBJ_DTYPE_MTIME:
909 909
                     case XOBJ_DTYPE_LTIME:
910
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
910
+                        $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv);
911 911
                         if (!($cleanv > 0)) {
912 912
                             $cleanv = strtotime($cleanv);
913 913
                         }
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
                         break;
917 917
                 }
918 918
             }
919
-            $this->cleanVars[$k] =& $cleanv;
919
+            $this->cleanVars[$k] = & $cleanv;
920 920
             unset($cleanv);
921 921
         }
922 922
         if (count($this->_errors) > 0) {
@@ -1141,10 +1141,10 @@  discard block
 block discarded – undo
1141 1141
                 }
1142 1142
                 break;
1143 1143
             case XOBJ_DTYPE_SIMPLE_ARRAY:
1144
-                $ret =& explode('|', $ret);
1144
+                $ret = & explode('|', $ret);
1145 1145
                 break;
1146 1146
             case XOBJ_DTYPE_ARRAY:
1147
-                $ret =& unserialize($ret);
1147
+                $ret = & unserialize($ret);
1148 1148
                 break;
1149 1149
             case XOBJ_DTYPE_SOURCE:
1150 1150
                 switch (strtolower($format)) {
Please login to merge, or discard this patch.
class/Form/Elements/SmartFormUploadElement.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
 class SmartFormUploadElement extends \XoopsFormFile
20 20
 {
21 21
     /**
22
-     * @param $object
23
-     * @param $key
22
+     * @param string $object
23
+     * @param string $key
24 24
      */
25 25
     public function SmartFormFileElement($object, $key)
26 26
     {
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -18,25 +18,25 @@
 block discarded – undo
18 18
  */
19 19
 class SmartFormUploadElement extends \XoopsFormFile
20 20
 {
21
-    /**
22
-     * @param $object
23
-     * @param $key
24
-     */
25
-    public function SmartFormFileElement($object, $key)
26
-    {
27
-        parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0);
28
-        $this->setExtra(' size=50');
29
-    }
21
+	/**
22
+	 * @param $object
23
+	 * @param $key
24
+	 */
25
+	public function SmartFormFileElement($object, $key)
26
+	{
27
+		parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0);
28
+		$this->setExtra(' size=50');
29
+	}
30 30
 
31
-    /**
32
-     * prepare HTML for output
33
-     *
34
-     * @return string HTML
35
-     */
36
-    public function render()
37
-    {
38
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
31
+	/**
32
+	 * prepare HTML for output
33
+	 *
34
+	 * @return string HTML
35
+	 */
36
+	public function render()
37
+	{
38
+		return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
39 39
                 <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . ">
40 40
                 <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>";
41
-    }
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@
 block discarded – undo
28 28
      */
29 29
     public function render()
30 30
     {
31
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
32
-                <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . ">
33
-                <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>";
31
+        return "<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."'>
32
+                <input type='file' name='" . $this->getName()."' id='".$this->getName()."'".$this->getExtra().">
33
+                <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName()."'>";
34 34
     }
35 35
 }
Please login to merge, or discard this patch.
class/Form/SmartObjectForm.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -306,8 +306,8 @@
 block discarded – undo
306 306
     }
307 307
 
308 308
     /**
309
-     * @param      $form_name
310
-     * @param      $form_caption
309
+     * @param      string $form_name
310
+     * @param      string $form_caption
311 311
      * @param bool $submit_button_caption
312 312
      */
313 313
     public function createButtons($form_name, $form_caption, $submit_button_caption = false)
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 use XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose;
26 26
 use XoopsModules\Smartobject\Form\Elements\SmartFormUrlLinkElement;
27 27
 
28
-require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
28
+require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
29 29
 //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php';
30 30
 //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php';
31 31
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
         $cancel_js_action = false,
71 71
         $captcha = false
72 72
     ) {
73
-        $this->targetObject           =& $target;
73
+        $this->targetObject           = & $target;
74 74
         $this->form_fields            = $form_fields;
75 75
         $this->_cancel_js_action      = $cancel_js_action;
76 76
         $this->_captcha               = $captcha;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
     public function addCaptcha()
100 100
     {
101
-        require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php';
101
+        require_once SMARTOBJECT_ROOT_PATH.'include/captcha/formcaptcha.php';
102 102
         $this->addElement(new \XoopsFormCaptcha(), true);
103 103
     }
104 104
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function addCustomButton($name, $caption, $onclick = false)
111 111
     {
112
-        $custom_button_array    = [
112
+        $custom_button_array = [
113 113
             'name'    => $name,
114 114
             'caption' => $caption,
115 115
             'onclick' => $onclick
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         if ($key) {
131 131
             if ($this->targetObject->vars[$key]['readonly']) {
132 132
                 $formElement->setExtra('disabled="disabled"');
133
-                $formElement->setName($key . '-readonly');
133
+                $formElement->setName($key.'-readonly');
134 134
                 // Since this element is disable, we still want to pass it's value in the form
135 135
                 $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
136 136
                 $this->addElement($hidden);
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                 $this->addElement($hidden);
142 142
                 $otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
143 143
                 $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
144
-                $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
144
+                $formElement->setExtra('onchange="'.$onchangedString.'"'.' '.$otherExtra);
145 145
             } else {
146 146
                 if (isset($var['form_extra'])) {
147 147
                     $formElement->setExtra($var['form_extra']);
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
             asort($group_list);
309 309
             foreach ($permissions as $permission) {
310 310
                 if ($this->targetObject->isNew()) {
311
-                    if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
312
-                        $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
311
+                    if (isset($smartModuleConfig['def_perm_'.$permission['perm_name']])) {
312
+                        $groups_value = $smartModuleConfig['def_perm_'.$permission['perm_name']];
313 313
                     }
314 314
                 } else {
315 315
                     $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
         } else {
342 342
             $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
343 343
         }
344
-        $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
344
+        $butt_create->setExtra('onclick="this.form.elements.op.value=\''.$form_name.'\'"');
345 345
         $button_tray->addElement($butt_create);
346 346
 
347 347
         //creating custom buttons
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
             foreach ($this->_custom_button as $custom_button) {
350 350
                 $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
351 351
                 if ($custom_button['onclick']) {
352
-                    $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
352
+                    $butt_custom->setExtra('onclick="'.$custom_button['onclick'].'"');
353 353
                 }
354 354
                 $button_tray->addElement($butt_custom);
355 355
                 unset($butt_custom);
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
         // creating the "cancel" button
360 360
         $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
361 361
         if ($this->_cancel_js_action) {
362
-            $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
362
+            $butt_cancel->setExtra('onclick="'.$this->_cancel_js_action.'"');
363 363
         } else {
364 364
             $butt_cancel->setExtra('onclick="history.go(-1)"');
365 365
         }
@@ -461,21 +461,21 @@  discard block
 block discarded – undo
461 461
                 break;
462 462
 
463 463
             default:
464
-                $classname = 'SmartForm' . ucfirst($controlName) . 'Element';
464
+                $classname = 'SmartForm'.ucfirst($controlName).'Element';
465 465
                 if (!class_exists($classname)) {
466
-                    if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
466
+                    if (file_exists(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php')) {
467 467
 //                        require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php';
468 468
                     } else {
469 469
                         // perhaps this is a control created by the module
470 470
                         $moduleName             = $this->targetObject->handler->_moduleName;
471
-                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
472
-                        $classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
473
-                        $classFileName          = strtolower($classname) . '.php';
471
+                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath.'class/form/elements/';
472
+                        $classname              = ucfirst($moduleName).ucfirst($controlName).'Element';
473
+                        $classFileName          = strtolower($classname).'.php';
474 474
 
475
-                        if (file_exists($moduleFormElementsPath . $classFileName)) {
475
+                        if (file_exists($moduleFormElementsPath.$classFileName)) {
476 476
 //                            require_once $moduleFormElementsPath . $classFileName;
477 477
                         } else {
478
-                            trigger_error($classname . ' Not found', E_USER_WARNING);
478
+                            trigger_error($classname.' Not found', E_USER_WARNING);
479 479
 
480 480
                             return new \XoopsFormLabel(); //Empty object
481 481
                         }
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
         $editor_configs['height'] = '400px';
545 545
 
546 546
         $dhtml            = true;
547
-        $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
547
+        $xoopseditorclass = XOOPS_ROOT_PATH.'/class/xoopsform/formeditor.php';
548 548
 
549 549
         if (file_exists($xoopseditorclass)) {
550 550
             require_once $xoopseditorclass;
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 
555 555
                 case 'tiny':
556 556
                     if (!$xoops22) {
557
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
558
-                            require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php';
557
+                        if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
558
+                            require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php';
559 559
                             $editor = new \XoopsFormTinymce([
560 560
                                                                     'caption' => $caption,
561 561
                                                                     'name'    => $name,
@@ -662,10 +662,10 @@  discard block
 block discarded – undo
662 662
         $size         = $multiple ? 5 : 1;
663 663
         $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
664 664
 
665
-        $handle  = opendir(XOOPS_THEME_PATH . '/');
665
+        $handle  = opendir(XOOPS_THEME_PATH.'/');
666 666
         $dirlist = [];
667 667
         while (false !== ($file = readdir($handle))) {
668
-            if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file)
668
+            if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match('/^[.]{1,2}$/', $file)
669 669
                 && 'cvs' !== strtolower($file)) {
670 670
                 $dirlist[$file] = $file;
671 671
             }
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
     {
688 688
         foreach ($this->_elements as $eleObj) {
689 689
             if ($eleObj->getName() == $keyname) {
690
-                $ret =& $eleObj;
690
+                $ret = & $eleObj;
691 691
                 break;
692 692
             }
693 693
         }
@@ -704,9 +704,9 @@  discard block
 block discarded – undo
704 704
     {
705 705
         $required = $this->getRequired();
706 706
         $ret      = "
707
-            <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . ">
707
+            <form name='" . $this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra().">
708 708
             <table width='100%' class='outer' cellspacing='1'>
709
-            <tr><th colspan='2'>" . $this->getTitle() . '</th></tr>
709
+            <tr><th colspan='2'>" . $this->getTitle().'</th></tr>
710 710
         ';
711 711
         $hidden   = '';
712 712
         $class    = 'even';
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
                 $ret .= $ele;
716 716
             } elseif (!$ele->isHidden()) {
717 717
                 //$class = ( $class == 'even' ) ? 'odd': 'even';
718
-                $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
718
+                $ret .= "<tr id='".$ele->getName()."' valign='top' align='left'><td class='head'>".$ele->getCaption();
719 719
                 if ('' !== $ele->getDescription()) {
720
-                    $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
720
+                    $ret .= '<br><br><span style="font-weight: normal;">'.$ele->getDescription().'</span>';
721 721
                 }
722
-                $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
722
+                $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n";
723 723
             } else {
724 724
                 $hidden .= $ele->render();
725 725
             }
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
             'name'       => $this->getName(),
768 768
             'action'     => $this->getAction(),
769 769
             'method'     => $this->getMethod(),
770
-            'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
770
+            'extra'      => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(),
771 771
             'javascript' => $js,
772 772
             'elements'   => $elements
773 773
         ]);
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
         }
786 786
         $myts     = \MyTextSanitizer::getInstance();
787 787
         $formname = $this->getName();
788
-        $js       .= "function xoopsFormValidate_{$formname}(myform) {";
788
+        $js .= "function xoopsFormValidate_{$formname}(myform) {";
789 789
         // First, output code to check required elements
790 790
         $elements = $this->getRequired();
791 791
         foreach ($elements as $elt) {
@@ -836,15 +836,15 @@  discard block
 block discarded – undo
836 836
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
837 837
                 }
838 838
             } else {
839
-                $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
839
+                $js .= "if ( myform.{$eltname}.value == \"\" ) "."{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
840 840
             }
841 841
         }
842 842
         // Now, handle custom validation code
843
-        $elements =& $this->getElements(true);
843
+        $elements = & $this->getElements(true);
844 844
         foreach ($elements as $elt) {
845 845
             if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) {
846 846
                 if ($eltjs = $elt->renderValidationJS()) {
847
-                    $js .= $eltjs . "\n";
847
+                    $js .= $eltjs."\n";
848 848
                 }
849 849
             }
850 850
         }
Please login to merge, or discard this patch.
Indentation   +698 added lines, -698 removed lines patch added patch discarded remove patch
@@ -40,548 +40,548 @@  discard block
 block discarded – undo
40 40
  */
41 41
 class SmartObjectForm extends \XoopsThemeForm
42 42
 {
43
-    public $targetObject           = null;
44
-    public $form_fields            = null;
45
-    public $_cancel_js_action      = false;
46
-    public $_custom_button         = false;
47
-    public $_captcha               = false;
48
-    public $_form_name             = false;
49
-    public $_form_caption          = false;
50
-    public $_submit_button_caption = false;
51
-
52
-    /**
53
-     * SmartobjectForm constructor.
54
-     * @param string $target
55
-     * @param string $form_name
56
-     * @param string $form_caption
57
-     * @param string $form_action
58
-     * @param null   $form_fields
59
-     * @param bool   $submit_button_caption
60
-     * @param bool   $cancel_js_action
61
-     * @param bool   $captcha
62
-     */
63
-    public function __construct(
64
-        &$target,
65
-        $form_name,
66
-        $form_caption,
67
-        $form_action,
68
-        $form_fields = null,
69
-        $submit_button_caption = false,
70
-        $cancel_js_action = false,
71
-        $captcha = false
72
-    ) {
73
-        $this->targetObject           =& $target;
74
-        $this->form_fields            = $form_fields;
75
-        $this->_cancel_js_action      = $cancel_js_action;
76
-        $this->_captcha               = $captcha;
77
-        $this->_form_name             = $form_name;
78
-        $this->_form_caption          = $form_caption;
79
-        $this->_submit_button_caption = $submit_button_caption;
80
-
81
-        if (!isset($form_action)) {
82
-            $form_action = xoops_getenv('PHP_SELF');
83
-        }
84
-
85
-        parent::__construct($form_caption, $form_name, $form_action, 'post', true);
86
-        $this->setExtra('enctype="multipart/form-data"');
87
-
88
-        $this->createElements();
89
-
90
-        if ($captcha) {
91
-            $this->addCaptcha();
92
-        }
93
-
94
-        $this->createPermissionControls();
95
-
96
-        $this->createButtons($form_name, $form_caption, $submit_button_caption);
97
-    }
98
-
99
-    public function addCaptcha()
100
-    {
101
-        require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php';
102
-        $this->addElement(new \XoopsFormCaptcha(), true);
103
-    }
104
-
105
-    /**
106
-     * @param      $name
107
-     * @param      $caption
108
-     * @param bool $onclick
109
-     */
110
-    public function addCustomButton($name, $caption, $onclick = false)
111
-    {
112
-        $custom_button_array    = [
113
-            'name'    => $name,
114
-            'caption' => $caption,
115
-            'onclick' => $onclick
116
-        ];
117
-        $this->_custom_button[] = $custom_button_array;
118
-    }
119
-
120
-    /**
121
-     * Add an element to the form
122
-     *
123
-     * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement}
124
-     * @param bool                    $key
125
-     * @param bool                    $var
126
-     * @param bool|string             $required     is this a "required" element?
127
-     */
128
-    public function addElement($formElement, $key = false, $var = false, $required = 'notset')
129
-    {
130
-        if ($key) {
131
-            if ($this->targetObject->vars[$key]['readonly']) {
132
-                $formElement->setExtra('disabled="disabled"');
133
-                $formElement->setName($key . '-readonly');
134
-                // Since this element is disable, we still want to pass it's value in the form
135
-                $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
136
-                $this->addElement($hidden);
137
-            }
138
-            $formElement->setDescription($var['form_dsc']);
139
-            if (isset($this->targetObject->controls[$key]['onSelect'])) {
140
-                $hidden = new \XoopsFormHidden('changedField', false);
141
-                $this->addElement($hidden);
142
-                $otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
143
-                $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
144
-                $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
145
-            } else {
146
-                if (isset($var['form_extra'])) {
147
-                    $formElement->setExtra($var['form_extra']);
148
-                }
149
-            }
150
-            $controls = $this->targetObject->controls;
151
-            if (isset($controls[$key]['js'])) {
152
-                $formElement->customValidationCode[] = $controls[$key]['js'];
153
-            }
154
-            parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required);
155
-        } else {
156
-            parent::addElement($formElement, 'notset' === $required ? false : true);
157
-        }
158
-        unset($formElement);
159
-    }
160
-
161
-    public function createElements()
162
-    {
163
-        $controls = $this->targetObject->controls;
164
-        $vars     = $this->targetObject->vars;
165
-        foreach ($vars as $key => $var) {
166
-
167
-            // If $displayOnForm is false OR this is the primary key, it doesn't
168
-            // need to be displayed, then we only create an hidden field
169
-            if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
170
-                $elementToAdd = new \XoopsFormHidden($key, $var['value']);
171
-                $this->addElement($elementToAdd, $key, $var, false);
172
-                unset($elementToAdd);
173
-            // If not, the we need to create the proper form control for this fields
174
-            } else {
175
-                // If this field has a specific control, we will use it
176
-
177
-                if ('parentid' === $key) {
178
-                    /**
179
-                     * Why this ?
180
-                     */
181
-                }
182
-                if (isset($controls[$key])) {
183
-                    /* If the control has name, it's because it's an object already present in the script
43
+	public $targetObject           = null;
44
+	public $form_fields            = null;
45
+	public $_cancel_js_action      = false;
46
+	public $_custom_button         = false;
47
+	public $_captcha               = false;
48
+	public $_form_name             = false;
49
+	public $_form_caption          = false;
50
+	public $_submit_button_caption = false;
51
+
52
+	/**
53
+	 * SmartobjectForm constructor.
54
+	 * @param string $target
55
+	 * @param string $form_name
56
+	 * @param string $form_caption
57
+	 * @param string $form_action
58
+	 * @param null   $form_fields
59
+	 * @param bool   $submit_button_caption
60
+	 * @param bool   $cancel_js_action
61
+	 * @param bool   $captcha
62
+	 */
63
+	public function __construct(
64
+		&$target,
65
+		$form_name,
66
+		$form_caption,
67
+		$form_action,
68
+		$form_fields = null,
69
+		$submit_button_caption = false,
70
+		$cancel_js_action = false,
71
+		$captcha = false
72
+	) {
73
+		$this->targetObject           =& $target;
74
+		$this->form_fields            = $form_fields;
75
+		$this->_cancel_js_action      = $cancel_js_action;
76
+		$this->_captcha               = $captcha;
77
+		$this->_form_name             = $form_name;
78
+		$this->_form_caption          = $form_caption;
79
+		$this->_submit_button_caption = $submit_button_caption;
80
+
81
+		if (!isset($form_action)) {
82
+			$form_action = xoops_getenv('PHP_SELF');
83
+		}
84
+
85
+		parent::__construct($form_caption, $form_name, $form_action, 'post', true);
86
+		$this->setExtra('enctype="multipart/form-data"');
87
+
88
+		$this->createElements();
89
+
90
+		if ($captcha) {
91
+			$this->addCaptcha();
92
+		}
93
+
94
+		$this->createPermissionControls();
95
+
96
+		$this->createButtons($form_name, $form_caption, $submit_button_caption);
97
+	}
98
+
99
+	public function addCaptcha()
100
+	{
101
+		require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php';
102
+		$this->addElement(new \XoopsFormCaptcha(), true);
103
+	}
104
+
105
+	/**
106
+	 * @param      $name
107
+	 * @param      $caption
108
+	 * @param bool $onclick
109
+	 */
110
+	public function addCustomButton($name, $caption, $onclick = false)
111
+	{
112
+		$custom_button_array    = [
113
+			'name'    => $name,
114
+			'caption' => $caption,
115
+			'onclick' => $onclick
116
+		];
117
+		$this->_custom_button[] = $custom_button_array;
118
+	}
119
+
120
+	/**
121
+	 * Add an element to the form
122
+	 *
123
+	 * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement}
124
+	 * @param bool                    $key
125
+	 * @param bool                    $var
126
+	 * @param bool|string             $required     is this a "required" element?
127
+	 */
128
+	public function addElement($formElement, $key = false, $var = false, $required = 'notset')
129
+	{
130
+		if ($key) {
131
+			if ($this->targetObject->vars[$key]['readonly']) {
132
+				$formElement->setExtra('disabled="disabled"');
133
+				$formElement->setName($key . '-readonly');
134
+				// Since this element is disable, we still want to pass it's value in the form
135
+				$hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
136
+				$this->addElement($hidden);
137
+			}
138
+			$formElement->setDescription($var['form_dsc']);
139
+			if (isset($this->targetObject->controls[$key]['onSelect'])) {
140
+				$hidden = new \XoopsFormHidden('changedField', false);
141
+				$this->addElement($hidden);
142
+				$otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
143
+				$onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
144
+				$formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
145
+			} else {
146
+				if (isset($var['form_extra'])) {
147
+					$formElement->setExtra($var['form_extra']);
148
+				}
149
+			}
150
+			$controls = $this->targetObject->controls;
151
+			if (isset($controls[$key]['js'])) {
152
+				$formElement->customValidationCode[] = $controls[$key]['js'];
153
+			}
154
+			parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required);
155
+		} else {
156
+			parent::addElement($formElement, 'notset' === $required ? false : true);
157
+		}
158
+		unset($formElement);
159
+	}
160
+
161
+	public function createElements()
162
+	{
163
+		$controls = $this->targetObject->controls;
164
+		$vars     = $this->targetObject->vars;
165
+		foreach ($vars as $key => $var) {
166
+
167
+			// If $displayOnForm is false OR this is the primary key, it doesn't
168
+			// need to be displayed, then we only create an hidden field
169
+			if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
170
+				$elementToAdd = new \XoopsFormHidden($key, $var['value']);
171
+				$this->addElement($elementToAdd, $key, $var, false);
172
+				unset($elementToAdd);
173
+			// If not, the we need to create the proper form control for this fields
174
+			} else {
175
+				// If this field has a specific control, we will use it
176
+
177
+				if ('parentid' === $key) {
178
+					/**
179
+					 * Why this ?
180
+					 */
181
+				}
182
+				if (isset($controls[$key])) {
183
+					/* If the control has name, it's because it's an object already present in the script
184 184
                      * for example, "user"
185 185
                      * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect)
186 186
                      */
187
-                    if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
188
-                        $controls[$key]['name'] = 'select';
189
-                    }
190
-
191
-                    $form_select = $this->getControl($controls[$key]['name'], $key);
192
-
193
-                    // Adding on the form, the control for this field
194
-                    $this->addElement($form_select, $key, $var);
195
-                    unset($form_select);
196
-
197
-                // If this field don't have a specific control, we will use the standard one, depending on its data type
198
-                } else {
199
-                    switch ($var['data_type']) {
200
-
201
-                        case XOBJ_DTYPE_TXTBOX:
202
-
203
-                            $form_text = $this->getControl('text', $key);
204
-                            $this->addElement($form_text, $key, $var);
205
-                            unset($form_text);
206
-                            break;
207
-
208
-                        case XOBJ_DTYPE_INT:
209
-                            $this->targetObject->setControl($key, [
210
-                                'name' => 'text',
211
-                                'size' => '5'
212
-                            ]);
213
-                            $form_text = $this->getControl('text', $key);
214
-                            $this->addElement($form_text, $key, $var);
215
-                            unset($form_text);
216
-                            break;
217
-
218
-                        case XOBJ_DTYPE_FLOAT:
219
-                            $this->targetObject->setControl($key, [
220
-                                'name' => 'text',
221
-                                'size' => '5'
222
-                            ]);
223
-                            $form_text = $this->getControl('text', $key);
224
-                            $this->addElement($form_text, $key, $var);
225
-                            unset($form_text);
226
-                            break;
227
-
228
-                        case XOBJ_DTYPE_LTIME:
229
-                            $form_date_time = $this->getControl('date_time', $key);
230
-                            $this->addElement($form_date_time, $key, $var);
231
-                            unset($form_date_time);
232
-                            break;
233
-
234
-                        case XOBJ_DTYPE_STIME:
235
-                            $form_date_time = $this->getControl('date', $key);
236
-                            $this->addElement($form_date_time, $key, $var);
237
-                            unset($form_date_time);
238
-                            break;
239
-
240
-                        case XOBJ_DTYPE_TIME_ONLY:
241
-                            $form_time = $this->getControl('time', $key);
242
-                            $this->addElement($form_time, $key, $var);
243
-                            unset($form_time);
244
-                            break;
245
-
246
-                        case XOBJ_DTYPE_CURRENCY:
247
-                            $this->targetObject->setControl($key, [
248
-                                'name' => 'text',
249
-                                'size' => '15'
250
-                            ]);
251
-                            $form_currency = $this->getControl('text', $key);
252
-                            $this->addElement($form_currency, $key, $var);
253
-                            unset($form_currency);
254
-                            break;
255
-
256
-                        case XOBJ_DTYPE_URLLINK:
257
-                            $form_urllink = $this->getControl('urllink', $key);
258
-                            $this->addElement($form_urllink, $key, $var);
259
-                            unset($form_urllink);
260
-                            break;
261
-
262
-                        case XOBJ_DTYPE_FILE:
263
-                            $form_file = $this->getControl('richfile', $key);
264
-                            $this->addElement($form_file, $key, $var);
265
-                            unset($form_file);
266
-                            break;
267
-
268
-                        case XOBJ_DTYPE_TXTAREA:
269
-
270
-                            $form_text_area = $this->getTextArea($key, $var);
271
-                            $this->addElement($form_text_area, $key, $var);
272
-                            unset($form_text_area);
273
-                            break;
274
-
275
-                        case XOBJ_DTYPE_ARRAY:
276
-                            // TODO: To come...
277
-                            break;
278
-                        case XOBJ_DTYPE_SOURCE:
279
-                            // TODO: To come...
280
-                            break;
281
-                        case XOBJ_DTYPE_FORM_SECTION:
282
-                            $section_control = new SmartFormSection($key, $var['value']);
283
-                            $this->addElement($section_control, $key, $var);
284
-                            unset($section_control);
285
-                            break;
286
-                        case XOBJ_DTYPE_FORM_SECTION_CLOSE:
287
-                            $section_control = new SmartFormSectionClose($key, $var['value']);
288
-                            $this->addElement($section_control, $key, $var);
289
-                            unset($section_control);
290
-                            break;
291
-                    }
292
-                }
293
-            }
294
-        }
295
-        // Add an hidden field to store the URL of the page before this form
296
-        $this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm()));
297
-    }
298
-
299
-    public function createPermissionControls()
300
-    {
301
-        $smartModuleConfig = $this->targetObject->handler->getModuleConfig();
302
-
303
-        $permissions = $this->targetObject->handler->getPermissions();
304
-
305
-        if ($permissions) {
306
-            $memberHandler = xoops_getHandler('member');
307
-            $group_list    = $memberHandler->getGroupList();
308
-            asort($group_list);
309
-            foreach ($permissions as $permission) {
310
-                if ($this->targetObject->isNew()) {
311
-                    if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
312
-                        $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
313
-                    }
314
-                } else {
315
-                    $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
316
-                }
317
-                $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true);
318
-                $groups_select->setDescription($permission['description']);
319
-                $groups_select->addOptionArray($group_list);
320
-                $this->addElement($groups_select);
321
-                unset($groups_select);
322
-            }
323
-        }
324
-    }
325
-
326
-    /**
327
-     * @param      $form_name
328
-     * @param      $form_caption
329
-     * @param bool $submit_button_caption
330
-     */
331
-    public function createButtons($form_name, $form_caption, $submit_button_caption = false)
332
-    {
333
-        $button_tray = new \XoopsFormElementTray('', '');
334
-        $button_tray->addElement(new \XoopsFormHidden('op', $form_name));
335
-        if (!$submit_button_caption) {
336
-            if ($this->targetObject->isNew()) {
337
-                $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit');
338
-            } else {
339
-                $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit');
340
-            }
341
-        } else {
342
-            $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
343
-        }
344
-        $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
345
-        $button_tray->addElement($butt_create);
346
-
347
-        //creating custom buttons
348
-        if ($this->_custom_button) {
349
-            foreach ($this->_custom_button as $custom_button) {
350
-                $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
351
-                if ($custom_button['onclick']) {
352
-                    $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
353
-                }
354
-                $button_tray->addElement($butt_custom);
355
-                unset($butt_custom);
356
-            }
357
-        }
358
-
359
-        // creating the "cancel" button
360
-        $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
361
-        if ($this->_cancel_js_action) {
362
-            $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
363
-        } else {
364
-            $butt_cancel->setExtra('onclick="history.go(-1)"');
365
-        }
366
-        $button_tray->addElement($butt_cancel);
367
-
368
-        $this->addElement($button_tray);
369
-    }
370
-
371
-    /**
372
-     * @param $controlName
373
-     * @param $key
374
-     * @return \XoopsFormLabel
375
-     */
376
-    public function getControl($controlName, $key)
377
-    {
378
-        switch ($controlName) {
379
-            case 'check':
187
+					if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
188
+						$controls[$key]['name'] = 'select';
189
+					}
190
+
191
+					$form_select = $this->getControl($controls[$key]['name'], $key);
192
+
193
+					// Adding on the form, the control for this field
194
+					$this->addElement($form_select, $key, $var);
195
+					unset($form_select);
196
+
197
+				// If this field don't have a specific control, we will use the standard one, depending on its data type
198
+				} else {
199
+					switch ($var['data_type']) {
200
+
201
+						case XOBJ_DTYPE_TXTBOX:
202
+
203
+							$form_text = $this->getControl('text', $key);
204
+							$this->addElement($form_text, $key, $var);
205
+							unset($form_text);
206
+							break;
207
+
208
+						case XOBJ_DTYPE_INT:
209
+							$this->targetObject->setControl($key, [
210
+								'name' => 'text',
211
+								'size' => '5'
212
+							]);
213
+							$form_text = $this->getControl('text', $key);
214
+							$this->addElement($form_text, $key, $var);
215
+							unset($form_text);
216
+							break;
217
+
218
+						case XOBJ_DTYPE_FLOAT:
219
+							$this->targetObject->setControl($key, [
220
+								'name' => 'text',
221
+								'size' => '5'
222
+							]);
223
+							$form_text = $this->getControl('text', $key);
224
+							$this->addElement($form_text, $key, $var);
225
+							unset($form_text);
226
+							break;
227
+
228
+						case XOBJ_DTYPE_LTIME:
229
+							$form_date_time = $this->getControl('date_time', $key);
230
+							$this->addElement($form_date_time, $key, $var);
231
+							unset($form_date_time);
232
+							break;
233
+
234
+						case XOBJ_DTYPE_STIME:
235
+							$form_date_time = $this->getControl('date', $key);
236
+							$this->addElement($form_date_time, $key, $var);
237
+							unset($form_date_time);
238
+							break;
239
+
240
+						case XOBJ_DTYPE_TIME_ONLY:
241
+							$form_time = $this->getControl('time', $key);
242
+							$this->addElement($form_time, $key, $var);
243
+							unset($form_time);
244
+							break;
245
+
246
+						case XOBJ_DTYPE_CURRENCY:
247
+							$this->targetObject->setControl($key, [
248
+								'name' => 'text',
249
+								'size' => '15'
250
+							]);
251
+							$form_currency = $this->getControl('text', $key);
252
+							$this->addElement($form_currency, $key, $var);
253
+							unset($form_currency);
254
+							break;
255
+
256
+						case XOBJ_DTYPE_URLLINK:
257
+							$form_urllink = $this->getControl('urllink', $key);
258
+							$this->addElement($form_urllink, $key, $var);
259
+							unset($form_urllink);
260
+							break;
261
+
262
+						case XOBJ_DTYPE_FILE:
263
+							$form_file = $this->getControl('richfile', $key);
264
+							$this->addElement($form_file, $key, $var);
265
+							unset($form_file);
266
+							break;
267
+
268
+						case XOBJ_DTYPE_TXTAREA:
269
+
270
+							$form_text_area = $this->getTextArea($key, $var);
271
+							$this->addElement($form_text_area, $key, $var);
272
+							unset($form_text_area);
273
+							break;
274
+
275
+						case XOBJ_DTYPE_ARRAY:
276
+							// TODO: To come...
277
+							break;
278
+						case XOBJ_DTYPE_SOURCE:
279
+							// TODO: To come...
280
+							break;
281
+						case XOBJ_DTYPE_FORM_SECTION:
282
+							$section_control = new SmartFormSection($key, $var['value']);
283
+							$this->addElement($section_control, $key, $var);
284
+							unset($section_control);
285
+							break;
286
+						case XOBJ_DTYPE_FORM_SECTION_CLOSE:
287
+							$section_control = new SmartFormSectionClose($key, $var['value']);
288
+							$this->addElement($section_control, $key, $var);
289
+							unset($section_control);
290
+							break;
291
+					}
292
+				}
293
+			}
294
+		}
295
+		// Add an hidden field to store the URL of the page before this form
296
+		$this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm()));
297
+	}
298
+
299
+	public function createPermissionControls()
300
+	{
301
+		$smartModuleConfig = $this->targetObject->handler->getModuleConfig();
302
+
303
+		$permissions = $this->targetObject->handler->getPermissions();
304
+
305
+		if ($permissions) {
306
+			$memberHandler = xoops_getHandler('member');
307
+			$group_list    = $memberHandler->getGroupList();
308
+			asort($group_list);
309
+			foreach ($permissions as $permission) {
310
+				if ($this->targetObject->isNew()) {
311
+					if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
312
+						$groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
313
+					}
314
+				} else {
315
+					$groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
316
+				}
317
+				$groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true);
318
+				$groups_select->setDescription($permission['description']);
319
+				$groups_select->addOptionArray($group_list);
320
+				$this->addElement($groups_select);
321
+				unset($groups_select);
322
+			}
323
+		}
324
+	}
325
+
326
+	/**
327
+	 * @param      $form_name
328
+	 * @param      $form_caption
329
+	 * @param bool $submit_button_caption
330
+	 */
331
+	public function createButtons($form_name, $form_caption, $submit_button_caption = false)
332
+	{
333
+		$button_tray = new \XoopsFormElementTray('', '');
334
+		$button_tray->addElement(new \XoopsFormHidden('op', $form_name));
335
+		if (!$submit_button_caption) {
336
+			if ($this->targetObject->isNew()) {
337
+				$butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit');
338
+			} else {
339
+				$butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit');
340
+			}
341
+		} else {
342
+			$butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
343
+		}
344
+		$butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
345
+		$button_tray->addElement($butt_create);
346
+
347
+		//creating custom buttons
348
+		if ($this->_custom_button) {
349
+			foreach ($this->_custom_button as $custom_button) {
350
+				$butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
351
+				if ($custom_button['onclick']) {
352
+					$butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
353
+				}
354
+				$button_tray->addElement($butt_custom);
355
+				unset($butt_custom);
356
+			}
357
+		}
358
+
359
+		// creating the "cancel" button
360
+		$butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
361
+		if ($this->_cancel_js_action) {
362
+			$butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
363
+		} else {
364
+			$butt_cancel->setExtra('onclick="history.go(-1)"');
365
+		}
366
+		$button_tray->addElement($butt_cancel);
367
+
368
+		$this->addElement($button_tray);
369
+	}
370
+
371
+	/**
372
+	 * @param $controlName
373
+	 * @param $key
374
+	 * @return \XoopsFormLabel
375
+	 */
376
+	public function getControl($controlName, $key)
377
+	{
378
+		switch ($controlName) {
379
+			case 'check':
380 380
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php';
381
-                $control    = $this->targetObject->getControl($key);
382
-                $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
383
-                $controlObj->addOptionArray($control['options']);
381
+				$control    = $this->targetObject->getControl($key);
382
+				$controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
383
+				$controlObj->addOptionArray($control['options']);
384 384
 
385
-                return $controlObj;
386
-                break;
385
+				return $controlObj;
386
+				break;
387 387
 
388
-            case 'color':
389
-                $control    = $this->targetObject->getControl($key);
390
-                $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
388
+			case 'color':
389
+				$control    = $this->targetObject->getControl($key);
390
+				$controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
391 391
 
392
-                return $controlObj;
393
-                break;
392
+				return $controlObj;
393
+				break;
394 394
 
395
-            case 'radio':
396
-                $control = $this->targetObject->getControl($key);
395
+			case 'radio':
396
+				$control = $this->targetObject->getControl($key);
397 397
 
398
-                $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
399
-                $controlObj->addOptionArray($control['options']);
398
+				$controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
399
+				$controlObj->addOptionArray($control['options']);
400 400
 
401
-                return $controlObj;
402
-                break;
401
+				return $controlObj;
402
+				break;
403 403
 
404
-            case 'label':
405
-                return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
406
-                break;
404
+			case 'label':
405
+				return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
406
+				break;
407 407
 
408
-            case 'textarea':
409
-                return $this->getTextArea($key);
408
+			case 'textarea':
409
+				return $this->getTextArea($key);
410 410
 
411
-            case 'theme':
412
-                return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
411
+			case 'theme':
412
+				return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
413 413
 
414
-            case 'theme_multi':
415
-                return $this->getThemeSelect($key, $this->targetObject->vars[$key], true);
416
-                break;
414
+			case 'theme_multi':
415
+				return $this->getThemeSelect($key, $this->targetObject->vars[$key], true);
416
+				break;
417 417
 
418
-            case 'timezone':
419
-                return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
420
-                break;
418
+			case 'timezone':
419
+				return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
420
+				break;
421 421
 
422
-            case 'group':
423
-                return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
424
-                break;
422
+			case 'group':
423
+				return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
424
+				break;
425 425
 
426
-            case 'group_multi':
427
-                return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
428
-                break;
426
+			case 'group_multi':
427
+				return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
428
+				break;
429 429
 
430
-            /*case 'user':
430
+			/*case 'user':
431 431
              return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
432 432
              break;*/
433 433
 
434
-            case 'user_multi':
435
-                return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
436
-                break;
434
+			case 'user_multi':
435
+				return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
436
+				break;
437 437
 
438
-            case 'password':
439
-                return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
440
-                break;
438
+			case 'password':
439
+				return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
440
+				break;
441 441
 
442
-            case 'country':
443
-                return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
444
-                break;
442
+			case 'country':
443
+				return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
444
+				break;
445 445
 
446
-            case 'urllink':
446
+			case 'urllink':
447 447
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php';
448 448
 
449
-                return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
450
-                break;
449
+				return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
450
+				break;
451 451
 
452
-            case 'richfile':
452
+			case 'richfile':
453 453
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php';
454 454
 
455
-                return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
456
-                break;
457
-            case 'section':
455
+				return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
456
+				break;
457
+			case 'section':
458 458
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php';
459 459
 
460
-                return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
461
-                break;
460
+				return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
461
+				break;
462 462
 
463
-            default:
464
-                $classname = 'SmartForm' . ucfirst($controlName) . 'Element';
465
-                if (!class_exists($classname)) {
466
-                    if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
463
+			default:
464
+				$classname = 'SmartForm' . ucfirst($controlName) . 'Element';
465
+				if (!class_exists($classname)) {
466
+					if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
467 467
 //                        require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php';
468
-                    } else {
469
-                        // perhaps this is a control created by the module
470
-                        $moduleName             = $this->targetObject->handler->_moduleName;
471
-                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
472
-                        $classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
473
-                        $classFileName          = strtolower($classname) . '.php';
474
-
475
-                        if (file_exists($moduleFormElementsPath . $classFileName)) {
468
+					} else {
469
+						// perhaps this is a control created by the module
470
+						$moduleName             = $this->targetObject->handler->_moduleName;
471
+						$moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
472
+						$classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
473
+						$classFileName          = strtolower($classname) . '.php';
474
+
475
+						if (file_exists($moduleFormElementsPath . $classFileName)) {
476 476
 //                            require_once $moduleFormElementsPath . $classFileName;
477
-                        } else {
478
-                            trigger_error($classname . ' Not found', E_USER_WARNING);
479
-
480
-                            return new \XoopsFormLabel(); //Empty object
481
-                        }
482
-                    }
483
-                }
484
-
485
-                return new $classname($this->targetObject, $key);
486
-                break;
487
-        }
488
-    }
489
-
490
-    /**
491
-     * @param $key
492
-     * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4
493
-     */
494
-    public function getTextArea($key)
495
-    {
496
-        $var = $this->targetObject->vars[$key];
497
-
498
-        // if no control has been created, let's create a default one
499
-        if (!isset($this->targetObject->controls[$key])) {
500
-            $control = [
501
-                'name'        => 'textarea',
502
-                'itemHandler' => false,
503
-                'method'      => false,
504
-                'module'      => false,
505
-                'form_editor' => 'default'
506
-            ];
507
-        } else {
508
-            $control = $this->targetObject->controls[$key];
509
-        }
510
-        $xoops22 = Smartobject\Utility::isXoops22();
511
-
512
-        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
513
-        /**
514
-         * If the editor is 'default', retreive the default editor of this module
515
-         */
516
-        if ('default' === $form_editor) {
517
-            global $xoopsModuleConfig;
518
-            $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
519
-        }
520
-
521
-        $caption = $var['form_caption'];
522
-        $name    = $key;
523
-
524
-        $value = $this->targetObject->getVar($key);
525
-
526
-        $value = $this->targetObject->getValueFor($key, true);
527
-
528
-        $editor_configs          = [];
529
-        $editor_configs['name']  = $name;
530
-        $editor_configs['value'] = $value;
531
-        if ('textarea' !== $form_editor) {
532
-            $editor_configs['rows'] = 35;
533
-            $editor_configs['cols'] = 60;
534
-        }
535
-
536
-        if (isset($control['rows'])) {
537
-            $editor_configs['rows'] = $control['rows'];
538
-        }
539
-        if (isset($control['cols'])) {
540
-            $editor_configs['cols'] = $control['cols'];
541
-        }
542
-
543
-        $editor_configs['width']  = '100%';
544
-        $editor_configs['height'] = '400px';
545
-
546
-        $dhtml            = true;
547
-        $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
548
-
549
-        if (file_exists($xoopseditorclass)) {
550
-            require_once $xoopseditorclass;
551
-            $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea');
552
-        } else {
553
-            switch ($form_editor) {
554
-
555
-                case 'tiny':
556
-                    if (!$xoops22) {
557
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
558
-                            require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php';
559
-                            $editor = new \XoopsFormTinymce([
560
-                                                                    'caption' => $caption,
561
-                                                                    'name'    => $name,
562
-                                                                    'value'   => $value,
563
-                                                                    'width'   => '100%',
564
-                                                                    'height'  => '300px'
565
-                                                                ], true);
566
-                        } else {
567
-                            if ($dhtml) {
568
-                                $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
569
-                            } else {
570
-                                $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60);
571
-                            }
572
-                        }
573
-                    } else {
574
-                        $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
575
-                    }
576
-                    break;
577
-
578
-                case 'dhtmltextarea':
579
-                case 'dhtmltext':
580
-                    $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60);
581
-                    if ($var['form_dsc']) {
582
-                        $editor->setDescription($var['form_dsc']);
583
-                    }
584
-                    break;
477
+						} else {
478
+							trigger_error($classname . ' Not found', E_USER_WARNING);
479
+
480
+							return new \XoopsFormLabel(); //Empty object
481
+						}
482
+					}
483
+				}
484
+
485
+				return new $classname($this->targetObject, $key);
486
+				break;
487
+		}
488
+	}
489
+
490
+	/**
491
+	 * @param $key
492
+	 * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4
493
+	 */
494
+	public function getTextArea($key)
495
+	{
496
+		$var = $this->targetObject->vars[$key];
497
+
498
+		// if no control has been created, let's create a default one
499
+		if (!isset($this->targetObject->controls[$key])) {
500
+			$control = [
501
+				'name'        => 'textarea',
502
+				'itemHandler' => false,
503
+				'method'      => false,
504
+				'module'      => false,
505
+				'form_editor' => 'default'
506
+			];
507
+		} else {
508
+			$control = $this->targetObject->controls[$key];
509
+		}
510
+		$xoops22 = Smartobject\Utility::isXoops22();
511
+
512
+		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
513
+		/**
514
+		 * If the editor is 'default', retreive the default editor of this module
515
+		 */
516
+		if ('default' === $form_editor) {
517
+			global $xoopsModuleConfig;
518
+			$form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
519
+		}
520
+
521
+		$caption = $var['form_caption'];
522
+		$name    = $key;
523
+
524
+		$value = $this->targetObject->getVar($key);
525
+
526
+		$value = $this->targetObject->getValueFor($key, true);
527
+
528
+		$editor_configs          = [];
529
+		$editor_configs['name']  = $name;
530
+		$editor_configs['value'] = $value;
531
+		if ('textarea' !== $form_editor) {
532
+			$editor_configs['rows'] = 35;
533
+			$editor_configs['cols'] = 60;
534
+		}
535
+
536
+		if (isset($control['rows'])) {
537
+			$editor_configs['rows'] = $control['rows'];
538
+		}
539
+		if (isset($control['cols'])) {
540
+			$editor_configs['cols'] = $control['cols'];
541
+		}
542
+
543
+		$editor_configs['width']  = '100%';
544
+		$editor_configs['height'] = '400px';
545
+
546
+		$dhtml            = true;
547
+		$xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
548
+
549
+		if (file_exists($xoopseditorclass)) {
550
+			require_once $xoopseditorclass;
551
+			$editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea');
552
+		} else {
553
+			switch ($form_editor) {
554
+
555
+				case 'tiny':
556
+					if (!$xoops22) {
557
+						if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
558
+							require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php';
559
+							$editor = new \XoopsFormTinymce([
560
+																	'caption' => $caption,
561
+																	'name'    => $name,
562
+																	'value'   => $value,
563
+																	'width'   => '100%',
564
+																	'height'  => '300px'
565
+																], true);
566
+						} else {
567
+							if ($dhtml) {
568
+								$editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
569
+							} else {
570
+								$editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60);
571
+							}
572
+						}
573
+					} else {
574
+						$editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
575
+					}
576
+					break;
577
+
578
+				case 'dhtmltextarea':
579
+				case 'dhtmltext':
580
+					$editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60);
581
+					if ($var['form_dsc']) {
582
+						$editor->setDescription($var['form_dsc']);
583
+					}
584
+					break;
585 585
 
586 586
 //                case 'inbetween':
587 587
 //                    if (!$xoops22) {
@@ -634,177 +634,177 @@  discard block
 block discarded – undo
634 634
 //                    }
635 635
 //                    break;
636 636
 
637
-                default:
638
-                case 'textarea':
639
-                    $form_rows = isset($control['rows']) ? $control['rows'] : 5;
640
-                    $form_cols = isset($control['cols']) ? $control['cols'] : 60;
641
-
642
-                    $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
643
-                    if ($var['form_dsc']) {
644
-                        $editor->setDescription($var['form_dsc']);
645
-                    }
646
-                    break;
647
-
648
-            }
649
-        }
650
-
651
-        return $editor;
652
-    }
653
-
654
-    /**
655
-     * @param                  $key
656
-     * @param                  $var
657
-     * @param  bool            $multiple
658
-     * @return \XoopsFormSelect
659
-     */
660
-    public function getThemeSelect($key, $var, $multiple = false)
661
-    {
662
-        $size         = $multiple ? 5 : 1;
663
-        $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
664
-
665
-        $handle  = opendir(XOOPS_THEME_PATH . '/');
666
-        $dirlist = [];
667
-        while (false !== ($file = readdir($handle))) {
668
-            if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file)
669
-                && 'cvs' !== strtolower($file)) {
670
-                $dirlist[$file] = $file;
671
-            }
672
-        }
673
-        closedir($handle);
674
-        if (!empty($dirlist)) {
675
-            asort($dirlist);
676
-            $theme_select->addOptionArray($dirlist);
677
-        }
678
-
679
-        return $theme_select;
680
-    }
681
-
682
-    /**
683
-     * @param $keyname
684
-     * @return bool
685
-     */
686
-    public function &getElementById($keyname)
687
-    {
688
-        foreach ($this->_elements as $eleObj) {
689
-            if ($eleObj->getName() == $keyname) {
690
-                $ret =& $eleObj;
691
-                break;
692
-            }
693
-        }
694
-
695
-        return isset($ret) ? $ret : false;
696
-    }
697
-
698
-    /**
699
-     * create HTML to output the form as a theme-enabled table with validation.
700
-     *
701
-     * @return string
702
-     */
703
-    public function render()
704
-    {
705
-        $required = $this->getRequired();
706
-        $ret      = "
637
+				default:
638
+				case 'textarea':
639
+					$form_rows = isset($control['rows']) ? $control['rows'] : 5;
640
+					$form_cols = isset($control['cols']) ? $control['cols'] : 60;
641
+
642
+					$editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
643
+					if ($var['form_dsc']) {
644
+						$editor->setDescription($var['form_dsc']);
645
+					}
646
+					break;
647
+
648
+			}
649
+		}
650
+
651
+		return $editor;
652
+	}
653
+
654
+	/**
655
+	 * @param                  $key
656
+	 * @param                  $var
657
+	 * @param  bool            $multiple
658
+	 * @return \XoopsFormSelect
659
+	 */
660
+	public function getThemeSelect($key, $var, $multiple = false)
661
+	{
662
+		$size         = $multiple ? 5 : 1;
663
+		$theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
664
+
665
+		$handle  = opendir(XOOPS_THEME_PATH . '/');
666
+		$dirlist = [];
667
+		while (false !== ($file = readdir($handle))) {
668
+			if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file)
669
+				&& 'cvs' !== strtolower($file)) {
670
+				$dirlist[$file] = $file;
671
+			}
672
+		}
673
+		closedir($handle);
674
+		if (!empty($dirlist)) {
675
+			asort($dirlist);
676
+			$theme_select->addOptionArray($dirlist);
677
+		}
678
+
679
+		return $theme_select;
680
+	}
681
+
682
+	/**
683
+	 * @param $keyname
684
+	 * @return bool
685
+	 */
686
+	public function &getElementById($keyname)
687
+	{
688
+		foreach ($this->_elements as $eleObj) {
689
+			if ($eleObj->getName() == $keyname) {
690
+				$ret =& $eleObj;
691
+				break;
692
+			}
693
+		}
694
+
695
+		return isset($ret) ? $ret : false;
696
+	}
697
+
698
+	/**
699
+	 * create HTML to output the form as a theme-enabled table with validation.
700
+	 *
701
+	 * @return string
702
+	 */
703
+	public function render()
704
+	{
705
+		$required = $this->getRequired();
706
+		$ret      = "
707 707
             <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . ">
708 708
             <table width='100%' class='outer' cellspacing='1'>
709 709
             <tr><th colspan='2'>" . $this->getTitle() . '</th></tr>
710 710
         ';
711
-        $hidden   = '';
712
-        $class    = 'even';
713
-        foreach ($this->getElements() as $ele) {
714
-            if (!is_object($ele)) {
715
-                $ret .= $ele;
716
-            } elseif (!$ele->isHidden()) {
717
-                //$class = ( $class == 'even' ) ? 'odd': 'even';
718
-                $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
719
-                if ('' !== $ele->getDescription()) {
720
-                    $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
721
-                }
722
-                $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
723
-            } else {
724
-                $hidden .= $ele->render();
725
-            }
726
-        }
727
-        $ret .= "</table>\n$hidden\n</form>\n";
728
-        $ret .= $this->renderValidationJS(true);
729
-
730
-        return $ret;
731
-    }
732
-
733
-    /**
734
-     * assign to smarty form template instead of displaying directly
735
-     *
736
-     * @param \XoopsTpl $tpl
737
-     *
738
-     * object
739
-     * @param bool      $smartyName
740
-     * @see     Smarty
741
-     */
742
-    public function assign(\XoopsTpl $tpl, $smartyName = false)
743
-    {
744
-        $i        = 0;
745
-        $elements = [];
746
-        foreach ($this->getElements() as $ele) {
747
-            $n                             = ('' !== $ele->getName()) ? $ele->getName() : $i;
748
-            $elements[$n]['name']          = $ele->getName();
749
-            $elements[$n]['caption']       = $ele->getCaption();
750
-            $elements[$n]['body']          = $ele->render();
751
-            $elements[$n]['hidden']        = $ele->isHidden();
752
-            $elements[$n]['section']       = strtolower(get_class($ele)) == strtolower('SmartFormSection');
753
-            $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose;
754
-            $elements[$n]['hide']          = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false;
755
-            if ('' !== $ele->getDescription()) {
756
-                $elements[$n]['description'] = $ele->getDescription();
757
-            }
758
-            ++$i;
759
-        }
760
-        $js = $this->renderValidationJS();
761
-        if (!$smartyName) {
762
-            $smartyName = $this->getName();
763
-        }
764
-
765
-        $tpl->assign($smartyName, [
766
-            'title'      => $this->getTitle(),
767
-            'name'       => $this->getName(),
768
-            'action'     => $this->getAction(),
769
-            'method'     => $this->getMethod(),
770
-            'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
771
-            'javascript' => $js,
772
-            'elements'   => $elements
773
-        ]);
774
-    }
775
-
776
-    /**
777
-     * @param  bool $withtags
778
-     * @return string
779
-     */
780
-    public function renderValidationJS($withtags = true)
781
-    {
782
-        $js = '';
783
-        if ($withtags) {
784
-            $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
785
-        }
786
-        $myts     = \MyTextSanitizer::getInstance();
787
-        $formname = $this->getName();
788
-        $js       .= "function xoopsFormValidate_{$formname}(myform) {";
789
-        // First, output code to check required elements
790
-        $elements = $this->getRequired();
791
-        foreach ($elements as $elt) {
792
-            $eltname    = $elt->getName();
793
-            $eltcaption = trim($elt->getCaption());
794
-            $eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
795
-            $eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
796
-            if ('xoopsformradio' === strtolower(get_class($elt))) {
797
-                $js .= 'var myOption = -1;';
798
-                $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
711
+		$hidden   = '';
712
+		$class    = 'even';
713
+		foreach ($this->getElements() as $ele) {
714
+			if (!is_object($ele)) {
715
+				$ret .= $ele;
716
+			} elseif (!$ele->isHidden()) {
717
+				//$class = ( $class == 'even' ) ? 'odd': 'even';
718
+				$ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
719
+				if ('' !== $ele->getDescription()) {
720
+					$ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
721
+				}
722
+				$ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
723
+			} else {
724
+				$hidden .= $ele->render();
725
+			}
726
+		}
727
+		$ret .= "</table>\n$hidden\n</form>\n";
728
+		$ret .= $this->renderValidationJS(true);
729
+
730
+		return $ret;
731
+	}
732
+
733
+	/**
734
+	 * assign to smarty form template instead of displaying directly
735
+	 *
736
+	 * @param \XoopsTpl $tpl
737
+	 *
738
+	 * object
739
+	 * @param bool      $smartyName
740
+	 * @see     Smarty
741
+	 */
742
+	public function assign(\XoopsTpl $tpl, $smartyName = false)
743
+	{
744
+		$i        = 0;
745
+		$elements = [];
746
+		foreach ($this->getElements() as $ele) {
747
+			$n                             = ('' !== $ele->getName()) ? $ele->getName() : $i;
748
+			$elements[$n]['name']          = $ele->getName();
749
+			$elements[$n]['caption']       = $ele->getCaption();
750
+			$elements[$n]['body']          = $ele->render();
751
+			$elements[$n]['hidden']        = $ele->isHidden();
752
+			$elements[$n]['section']       = strtolower(get_class($ele)) == strtolower('SmartFormSection');
753
+			$elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose;
754
+			$elements[$n]['hide']          = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false;
755
+			if ('' !== $ele->getDescription()) {
756
+				$elements[$n]['description'] = $ele->getDescription();
757
+			}
758
+			++$i;
759
+		}
760
+		$js = $this->renderValidationJS();
761
+		if (!$smartyName) {
762
+			$smartyName = $this->getName();
763
+		}
764
+
765
+		$tpl->assign($smartyName, [
766
+			'title'      => $this->getTitle(),
767
+			'name'       => $this->getName(),
768
+			'action'     => $this->getAction(),
769
+			'method'     => $this->getMethod(),
770
+			'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
771
+			'javascript' => $js,
772
+			'elements'   => $elements
773
+		]);
774
+	}
775
+
776
+	/**
777
+	 * @param  bool $withtags
778
+	 * @return string
779
+	 */
780
+	public function renderValidationJS($withtags = true)
781
+	{
782
+		$js = '';
783
+		if ($withtags) {
784
+			$js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
785
+		}
786
+		$myts     = \MyTextSanitizer::getInstance();
787
+		$formname = $this->getName();
788
+		$js       .= "function xoopsFormValidate_{$formname}(myform) {";
789
+		// First, output code to check required elements
790
+		$elements = $this->getRequired();
791
+		foreach ($elements as $elt) {
792
+			$eltname    = $elt->getName();
793
+			$eltcaption = trim($elt->getCaption());
794
+			$eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
795
+			$eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
796
+			if ('xoopsformradio' === strtolower(get_class($elt))) {
797
+				$js .= 'var myOption = -1;';
798
+				$js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
799 799
                     if (myform.{$eltname}[i].checked) {
800 800
                         myOption = i; i = -1;
801 801
                     }
802 802
                 }
803 803
                 if (myOption == -1) {
804 804
                     window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n";
805
-            } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) {
806
-                $js .= 'var hasSelections = false;';
807
-                $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
805
+			} elseif ('smartformselect_multielement' === strtolower(get_class($elt))) {
806
+				$js .= 'var hasSelections = false;';
807
+				$js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
808 808
                     if (myform['{$eltname}[]'].options[i].selected) {
809 809
                         hasSelections = true;
810 810
                     }
@@ -812,12 +812,12 @@  discard block
 block discarded – undo
812 812
                 }
813 813
                 if (hasSelections === false) {
814 814
                     window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n";
815
-            } elseif ('xoopsformcheckbox' === strtolower(get_class($elt))
816
-                      || 'smartformcheckelement' === strtolower(get_class($elt))) {
817
-                $js .= 'var hasSelections = false;';
818
-                //sometimes, there is an implicit '[]', sometimes not
819
-                if (false === strpos($eltname, '[')) {
820
-                    $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
815
+			} elseif ('xoopsformcheckbox' === strtolower(get_class($elt))
816
+					  || 'smartformcheckelement' === strtolower(get_class($elt))) {
817
+				$js .= 'var hasSelections = false;';
818
+				//sometimes, there is an implicit '[]', sometimes not
819
+				if (false === strpos($eltname, '[')) {
820
+					$js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
821 821
                         if (myform['{$eltname}[]'][i].checked) {
822 822
                             hasSelections = true;
823 823
                         }
@@ -825,8 +825,8 @@  discard block
 block discarded – undo
825 825
                     }
826 826
                     if (hasSelections === false) {
827 827
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n";
828
-                } else {
829
-                    $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
828
+				} else {
829
+					$js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
830 830
                         if (myform['{$eltname}'][i].checked) {
831 831
                             hasSelections = true;
832 832
                         }
@@ -834,25 +834,25 @@  discard block
 block discarded – undo
834 834
                     }
835 835
                     if (hasSelections === false) {
836 836
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
837
-                }
838
-            } else {
839
-                $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
840
-            }
841
-        }
842
-        // Now, handle custom validation code
843
-        $elements =& $this->getElements(true);
844
-        foreach ($elements as $elt) {
845
-            if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) {
846
-                if ($eltjs = $elt->renderValidationJS()) {
847
-                    $js .= $eltjs . "\n";
848
-                }
849
-            }
850
-        }
851
-        $js .= "return true;\n}\n";
852
-        if ($withtags) {
853
-            $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n";
854
-        }
855
-
856
-        return $js;
857
-    }
837
+				}
838
+			} else {
839
+				$js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
840
+			}
841
+		}
842
+		// Now, handle custom validation code
843
+		$elements =& $this->getElements(true);
844
+		foreach ($elements as $elt) {
845
+			if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) {
846
+				if ($eltjs = $elt->renderValidationJS()) {
847
+					$js .= $eltjs . "\n";
848
+				}
849
+			}
850
+		}
851
+		$js .= "return true;\n}\n";
852
+		if ($withtags) {
853
+			$js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n";
854
+		}
855
+
856
+		return $js;
857
+	}
858 858
 }
Please login to merge, or discard this patch.
include/captcha/scripts/img.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -196,7 +196,7 @@
 block discarded – undo
196 196
     }
197 197
 
198 198
     /**
199
-     * @param         $name
199
+     * @param         string $name
200 200
      * @param  string $extension
201 201
      * @return array
202 202
      */
Please login to merge, or discard this patch.
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $xoopsLogger->activated = false;
11 11
 
12 12
 if (empty(Request::getString('HTTP_REFERER', '', 'SERVER')) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', Request::getString('HTTP_REFERER', '', 'SERVER'))) {
13
-    exit();
13
+	exit();
14 14
 }
15 15
 
16 16
 /**
@@ -18,192 +18,192 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class XoopsCaptchaImageHandler
20 20
 {
21
-    public $config = [];
22
-    //var $mode = "gd"; // GD or bmp
23
-    public $code;
24
-    public $invalid = false;
25
-
26
-    public $font;
27
-    public $spacing;
28
-    public $width;
29
-    public $height;
30
-
31
-    /**
32
-     * XoopsCaptchaImageHandler constructor.
33
-     */
34
-    public function __construct()
35
-    {
36
-        if (empty($_SESSION['XoopsCaptcha_name'])) {
37
-            $this->invalid = true;
38
-        }
39
-
40
-        if (!extension_loaded('gd')) {
41
-            $this->mode = 'bmp';
42
-        } else {
43
-            $required_functions = [
44
-                'imagecreatetruecolor',
45
-                'imagecolorallocate',
46
-                'imagefilledrectangle',
47
-                'imagejpeg',
48
-                'imagedestroy',
49
-                'imageftbbox'
50
-            ];
51
-            foreach ($required_functions as $func) {
52
-                if (!function_exists($func)) {
53
-                    $this->mode = 'bmp';
54
-                    break;
55
-                }
56
-            }
57
-        }
58
-    }
59
-
60
-    /**
61
-     * Loading configs from CAPTCHA class
62
-     * @param array $config
63
-     */
64
-    public function setConfig($config = [])
65
-    {
66
-        // Loading default preferences
67
-        $this->config = $config;
68
-    }
69
-
70
-    public function loadImage()
71
-    {
72
-        $this->createCode();
73
-        $this->setCode();
74
-        $this->createImage();
75
-    }
76
-
77
-    /**
78
-     * Create Code
79
-     */
80
-    public function createCode()
81
-    {
82
-        if ($this->invalid) {
83
-            return;
84
-        }
85
-
86
-        if ('bmp' === $this->mode) {
87
-            $this->config['num_chars'] = 4;
88
-            $this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9'));
89
-        } else {
90
-            $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']);
91
-            if (!$this->config['casesensitive']) {
92
-                $this->code = strtoupper($this->code);
93
-            }
94
-        }
95
-    }
96
-
97
-    public function setCode()
98
-    {
99
-        if ($this->invalid) {
100
-            return;
101
-        }
102
-
103
-        $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code;
104
-        $maxAttempts                          = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
105
-
106
-        // Increase the attempt records on refresh
107
-        if (!empty($maxAttempts)) {
108
-            $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++;
109
-            if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
110
-                $this->invalid = true;
111
-            }
112
-        }
113
-    }
114
-
115
-    /**
116
-     * @param  string $file
117
-     * @return string|void
118
-     */
119
-    public function createImage($file = '')
120
-    {
121
-        if ($this->invalid) {
122
-            header('Content-type: image/gif');
123
-            readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif');
124
-
125
-            return;
126
-        }
127
-
128
-        if ('bmp' === $this->mode) {
129
-            return $this->createImageBmp();
130
-        } else {
131
-            return $this->createImageGd();
132
-        }
133
-    }
134
-
135
-    /**
136
-     *  Create CAPTCHA iamge with GD
137
-     *  Originated from DuGris' SecurityImage
138
-     * @param string $file
139
-     */
140
-    //  --------------------------------------------------------------------------- //
141
-    // Class: SecurityImage 1.5                                                    //
142
-    // Author: DuGris aka L. Jen <http://www.dugris.info>                           //
143
-    // Email: [email protected]                                                    //
144
-    // Licence: GNU                                                                 //
145
-    // Project: XOOPS Project                                                   //
146
-    //  --------------------------------------------------------------------------- //
147
-    public function createImageGd($file = '')
148
-    {
149
-        $this->loadFont();
150
-        $this->setImageSize();
151
-
152
-        $this->oImage = imagecreatetruecolor($this->width, $this->height);
153
-        $background   = imagecolorallocate($this->oImage, 255, 255, 255);
154
-        imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background);
155
-
156
-        switch ($this->config['background_type']) {
157
-            default:
158
-            case 0:
159
-                $this->drawBars();
160
-                break;
161
-
162
-            case 1:
163
-                $this->drawCircles();
164
-                break;
165
-
166
-            case 2:
167
-                $this->drawLines();
168
-                break;
169
-
170
-            case 3:
171
-                $this->drawRectangles();
172
-                break;
173
-
174
-            case 4:
175
-                $this->drawEllipses();
176
-                break;
177
-
178
-            case 5:
179
-                $this->drawPolygons();
180
-                break;
181
-
182
-            case 100:
183
-                $this->createFromFile();
184
-                break;
185
-        }
186
-        $this->drawBorder();
187
-        $this->drawCode();
188
-
189
-        if (empty($file)) {
190
-            header('Content-type: image/jpeg');
191
-            imagejpeg($this->oImage);
192
-        } else {
193
-            imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg');
194
-        }
195
-        imagedestroy($this->oImage);
196
-    }
197
-
198
-    /**
199
-     * @param         $name
200
-     * @param  string $extension
201
-     * @return array
202
-     */
203
-    public function _getList($name, $extension = '')
204
-    {
205
-        $items = [];
206
-        /*
21
+	public $config = [];
22
+	//var $mode = "gd"; // GD or bmp
23
+	public $code;
24
+	public $invalid = false;
25
+
26
+	public $font;
27
+	public $spacing;
28
+	public $width;
29
+	public $height;
30
+
31
+	/**
32
+	 * XoopsCaptchaImageHandler constructor.
33
+	 */
34
+	public function __construct()
35
+	{
36
+		if (empty($_SESSION['XoopsCaptcha_name'])) {
37
+			$this->invalid = true;
38
+		}
39
+
40
+		if (!extension_loaded('gd')) {
41
+			$this->mode = 'bmp';
42
+		} else {
43
+			$required_functions = [
44
+				'imagecreatetruecolor',
45
+				'imagecolorallocate',
46
+				'imagefilledrectangle',
47
+				'imagejpeg',
48
+				'imagedestroy',
49
+				'imageftbbox'
50
+			];
51
+			foreach ($required_functions as $func) {
52
+				if (!function_exists($func)) {
53
+					$this->mode = 'bmp';
54
+					break;
55
+				}
56
+			}
57
+		}
58
+	}
59
+
60
+	/**
61
+	 * Loading configs from CAPTCHA class
62
+	 * @param array $config
63
+	 */
64
+	public function setConfig($config = [])
65
+	{
66
+		// Loading default preferences
67
+		$this->config = $config;
68
+	}
69
+
70
+	public function loadImage()
71
+	{
72
+		$this->createCode();
73
+		$this->setCode();
74
+		$this->createImage();
75
+	}
76
+
77
+	/**
78
+	 * Create Code
79
+	 */
80
+	public function createCode()
81
+	{
82
+		if ($this->invalid) {
83
+			return;
84
+		}
85
+
86
+		if ('bmp' === $this->mode) {
87
+			$this->config['num_chars'] = 4;
88
+			$this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9'));
89
+		} else {
90
+			$this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']);
91
+			if (!$this->config['casesensitive']) {
92
+				$this->code = strtoupper($this->code);
93
+			}
94
+		}
95
+	}
96
+
97
+	public function setCode()
98
+	{
99
+		if ($this->invalid) {
100
+			return;
101
+		}
102
+
103
+		$_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code;
104
+		$maxAttempts                          = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
105
+
106
+		// Increase the attempt records on refresh
107
+		if (!empty($maxAttempts)) {
108
+			$_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++;
109
+			if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
110
+				$this->invalid = true;
111
+			}
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * @param  string $file
117
+	 * @return string|void
118
+	 */
119
+	public function createImage($file = '')
120
+	{
121
+		if ($this->invalid) {
122
+			header('Content-type: image/gif');
123
+			readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif');
124
+
125
+			return;
126
+		}
127
+
128
+		if ('bmp' === $this->mode) {
129
+			return $this->createImageBmp();
130
+		} else {
131
+			return $this->createImageGd();
132
+		}
133
+	}
134
+
135
+	/**
136
+	 *  Create CAPTCHA iamge with GD
137
+	 *  Originated from DuGris' SecurityImage
138
+	 * @param string $file
139
+	 */
140
+	//  --------------------------------------------------------------------------- //
141
+	// Class: SecurityImage 1.5                                                    //
142
+	// Author: DuGris aka L. Jen <http://www.dugris.info>                           //
143
+	// Email: [email protected]                                                    //
144
+	// Licence: GNU                                                                 //
145
+	// Project: XOOPS Project                                                   //
146
+	//  --------------------------------------------------------------------------- //
147
+	public function createImageGd($file = '')
148
+	{
149
+		$this->loadFont();
150
+		$this->setImageSize();
151
+
152
+		$this->oImage = imagecreatetruecolor($this->width, $this->height);
153
+		$background   = imagecolorallocate($this->oImage, 255, 255, 255);
154
+		imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background);
155
+
156
+		switch ($this->config['background_type']) {
157
+			default:
158
+			case 0:
159
+				$this->drawBars();
160
+				break;
161
+
162
+			case 1:
163
+				$this->drawCircles();
164
+				break;
165
+
166
+			case 2:
167
+				$this->drawLines();
168
+				break;
169
+
170
+			case 3:
171
+				$this->drawRectangles();
172
+				break;
173
+
174
+			case 4:
175
+				$this->drawEllipses();
176
+				break;
177
+
178
+			case 5:
179
+				$this->drawPolygons();
180
+				break;
181
+
182
+			case 100:
183
+				$this->createFromFile();
184
+				break;
185
+		}
186
+		$this->drawBorder();
187
+		$this->drawCode();
188
+
189
+		if (empty($file)) {
190
+			header('Content-type: image/jpeg');
191
+			imagejpeg($this->oImage);
192
+		} else {
193
+			imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg');
194
+		}
195
+		imagedestroy($this->oImage);
196
+	}
197
+
198
+	/**
199
+	 * @param         $name
200
+	 * @param  string $extension
201
+	 * @return array
202
+	 */
203
+	public function _getList($name, $extension = '')
204
+	{
205
+		$items = [];
206
+		/*
207 207
          if (@ require_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") {
208 208
          load_functions("cache");
209 209
          if ($items = mod_loadCacheFile("captcha_{$name}", "captcha")) {
@@ -211,231 +211,231 @@  discard block
 block discarded – undo
211 211
          }
212 212
          }
213 213
          */
214
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
215
-        $file_path = $this->config['rootpath'] . "/{$name}";
216
-        $files     = XoopsLists::getFileListAsArray($file_path);
217
-        foreach ($files as $item) {
218
-            if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) {
219
-                $items[] = $item;
220
-            }
221
-        }
222
-        if (function_exists('mod_createCacheFile')) {
223
-            mod_createCacheFile($items, "captcha_{$name}", 'captcha');
224
-        }
225
-
226
-        return $items;
227
-    }
228
-
229
-    public function loadFont()
230
-    {
231
-        $fonts      = $this->_getList('fonts', 'ttf');
232
-        $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)];
233
-    }
234
-
235
-    public function setImageSize()
236
-    {
237
-        $MaxCharWidth  = 0;
238
-        $MaxCharHeight = 0;
239
-        $oImage        = imagecreatetruecolor(100, 100);
240
-        $text_color    = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
241
-        $FontSize      = $this->config['fontsize_max'];
242
-        for ($Angle = -30; $Angle <= 30; ++$Angle) {
243
-            for ($i = 65; $i <= 90; ++$i) {
244
-                $CharDetails   = imageftbbox($FontSize, $Angle, $this->font, chr($i), []);
245
-                $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]);
246
-                if ($_MaxCharWidth > $MaxCharWidth) {
247
-                    $MaxCharWidth = $_MaxCharWidth;
248
-                }
249
-                $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]);
250
-                if ($_MaxCharHeight > $MaxCharHeight) {
251
-                    $MaxCharHeight = $_MaxCharHeight;
252
-                }
253
-            }
254
-        }
255
-        imagedestroy($oImage);
256
-
257
-        $this->height  = $MaxCharHeight + 2;
258
-        $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
259
-        $this->width   = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2);
260
-    }
261
-
262
-    /**
263
-     * Return random background
264
-     *
265
-     * @return null|string
266
-     */
267
-    public function loadBackground()
268
-    {
269
-        $RandBackground = null;
270
-        if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) {
271
-            $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)];
272
-        }
273
-
274
-        return $RandBackground;
275
-    }
276
-
277
-    /**
278
-     * Draw Image background
279
-     */
280
-    public function createFromFile()
281
-    {
282
-        if ($RandImage = $this->loadBackground()) {
283
-            $ImageType = @getimagesize($RandImage);
284
-            switch (@$ImageType[2]) {
285
-                case 1:
286
-                    $BackgroundImage = imagecreatefromgif($RandImage);
287
-                    break;
288
-
289
-                case 2:
290
-                    $BackgroundImage = imagecreatefromjpeg($RandImage);
291
-                    break;
292
-
293
-                case 3:
294
-                    $BackgroundImage = imagecreatefrompng($RandImage);
295
-                    break;
296
-            }
297
-        }
298
-        if (!empty($BackgroundImage)) {
299
-            imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage));
300
-            imagedestroy($BackgroundImage);
301
-        } else {
302
-            $this->drawBars();
303
-        }
304
-    }
305
-
306
-    /**
307
-     * Draw Code
308
-     */
309
-    public function drawCode()
310
-    {
311
-        for ($i = 0; $i < $this->config['num_chars']; ++$i) {
312
-            // select random greyscale colour
313
-            $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
314
-
315
-            // write text to image
316
-            $Angle = mt_rand(10, 30);
317
-            if ($i % 2) {
318
-                $Angle = mt_rand(-10, -30);
319
-            }
320
-
321
-            // select random font size
322
-            $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']);
323
-
324
-            $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []);
325
-            $CharHeight  = abs($CharDetails[1] + $CharDetails[5]);
326
-
327
-            // calculate character starting coordinates
328
-            $posX = ($this->spacing / 2) + ($i * $this->spacing);
329
-            $posY = 2 + ($this->height / 2) + ($CharHeight / 4);
330
-
331
-            imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []);
332
-        }
333
-    }
334
-
335
-    /**
336
-     * Draw Border
337
-     */
338
-    public function drawBorder()
339
-    {
340
-        $rgb          = mt_rand(50, 150);
341
-        $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb);
342
-        imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color);
343
-    }
344
-
345
-    /**
346
-     * Draw Circles background
347
-     */
348
-    public function drawCircles()
349
-    {
350
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
351
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
352
-            imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor);
353
-        }
354
-    }
355
-
356
-    /**
357
-     * Draw Lines background
358
-     */
359
-    public function drawLines()
360
-    {
361
-        for ($i = 0; $i < $this->config['background_num']; ++$i) {
362
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
363
-            imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
364
-        }
365
-    }
366
-
367
-    /**
368
-     * Draw Rectangles background
369
-     */
370
-    public function drawRectangles()
371
-    {
372
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
373
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
374
-            imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
375
-        }
376
-    }
377
-
378
-    /**
379
-     * Draw Bars background
380
-     */
381
-    public function drawBars()
382
-    {
383
-        for ($i = 0; $i <= $this->height;) {
384
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
385
-            imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor);
386
-            $i += 2.5;
387
-        }
388
-        for ($i = 0; $i <= $this->width;) {
389
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
390
-            imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor);
391
-            $i += 2.5;
392
-        }
393
-    }
394
-
395
-    /**
396
-     * Draw Ellipses background
397
-     */
398
-    public function drawEllipses()
399
-    {
400
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
401
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
402
-            imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
403
-        }
404
-    }
405
-
406
-    /**
407
-     * Draw polygons background
408
-     */
409
-    public function drawPolygons()
410
-    {
411
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
412
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
413
-            $coords      = [];
414
-            for ($j = 1; $j <= $this->config['polygon_point']; ++$j) {
415
-                $coords[] = mt_rand(0, $this->width);
416
-                $coords[] = mt_rand(0, $this->height);
417
-            }
418
-            imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor);
419
-        }
420
-    }
421
-
422
-    /**
423
-     *  Create CAPTCHA iamge with BMP
424
-     *  TODO
425
-     * @param  string $file
426
-     * @return string
427
-     */
428
-    public function createImageBmp($file = '')
429
-    {
430
-        $image = '';
431
-
432
-        if (empty($file)) {
433
-            header('Content-type: image/bmp');
434
-            echo $image;
435
-        } else {
436
-            return $image;
437
-        }
438
-    }
214
+		require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
215
+		$file_path = $this->config['rootpath'] . "/{$name}";
216
+		$files     = XoopsLists::getFileListAsArray($file_path);
217
+		foreach ($files as $item) {
218
+			if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) {
219
+				$items[] = $item;
220
+			}
221
+		}
222
+		if (function_exists('mod_createCacheFile')) {
223
+			mod_createCacheFile($items, "captcha_{$name}", 'captcha');
224
+		}
225
+
226
+		return $items;
227
+	}
228
+
229
+	public function loadFont()
230
+	{
231
+		$fonts      = $this->_getList('fonts', 'ttf');
232
+		$this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)];
233
+	}
234
+
235
+	public function setImageSize()
236
+	{
237
+		$MaxCharWidth  = 0;
238
+		$MaxCharHeight = 0;
239
+		$oImage        = imagecreatetruecolor(100, 100);
240
+		$text_color    = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
241
+		$FontSize      = $this->config['fontsize_max'];
242
+		for ($Angle = -30; $Angle <= 30; ++$Angle) {
243
+			for ($i = 65; $i <= 90; ++$i) {
244
+				$CharDetails   = imageftbbox($FontSize, $Angle, $this->font, chr($i), []);
245
+				$_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]);
246
+				if ($_MaxCharWidth > $MaxCharWidth) {
247
+					$MaxCharWidth = $_MaxCharWidth;
248
+				}
249
+				$_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]);
250
+				if ($_MaxCharHeight > $MaxCharHeight) {
251
+					$MaxCharHeight = $_MaxCharHeight;
252
+				}
253
+			}
254
+		}
255
+		imagedestroy($oImage);
256
+
257
+		$this->height  = $MaxCharHeight + 2;
258
+		$this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
259
+		$this->width   = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2);
260
+	}
261
+
262
+	/**
263
+	 * Return random background
264
+	 *
265
+	 * @return null|string
266
+	 */
267
+	public function loadBackground()
268
+	{
269
+		$RandBackground = null;
270
+		if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) {
271
+			$RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)];
272
+		}
273
+
274
+		return $RandBackground;
275
+	}
276
+
277
+	/**
278
+	 * Draw Image background
279
+	 */
280
+	public function createFromFile()
281
+	{
282
+		if ($RandImage = $this->loadBackground()) {
283
+			$ImageType = @getimagesize($RandImage);
284
+			switch (@$ImageType[2]) {
285
+				case 1:
286
+					$BackgroundImage = imagecreatefromgif($RandImage);
287
+					break;
288
+
289
+				case 2:
290
+					$BackgroundImage = imagecreatefromjpeg($RandImage);
291
+					break;
292
+
293
+				case 3:
294
+					$BackgroundImage = imagecreatefrompng($RandImage);
295
+					break;
296
+			}
297
+		}
298
+		if (!empty($BackgroundImage)) {
299
+			imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage));
300
+			imagedestroy($BackgroundImage);
301
+		} else {
302
+			$this->drawBars();
303
+		}
304
+	}
305
+
306
+	/**
307
+	 * Draw Code
308
+	 */
309
+	public function drawCode()
310
+	{
311
+		for ($i = 0; $i < $this->config['num_chars']; ++$i) {
312
+			// select random greyscale colour
313
+			$text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
314
+
315
+			// write text to image
316
+			$Angle = mt_rand(10, 30);
317
+			if ($i % 2) {
318
+				$Angle = mt_rand(-10, -30);
319
+			}
320
+
321
+			// select random font size
322
+			$FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']);
323
+
324
+			$CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []);
325
+			$CharHeight  = abs($CharDetails[1] + $CharDetails[5]);
326
+
327
+			// calculate character starting coordinates
328
+			$posX = ($this->spacing / 2) + ($i * $this->spacing);
329
+			$posY = 2 + ($this->height / 2) + ($CharHeight / 4);
330
+
331
+			imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []);
332
+		}
333
+	}
334
+
335
+	/**
336
+	 * Draw Border
337
+	 */
338
+	public function drawBorder()
339
+	{
340
+		$rgb          = mt_rand(50, 150);
341
+		$border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb);
342
+		imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color);
343
+	}
344
+
345
+	/**
346
+	 * Draw Circles background
347
+	 */
348
+	public function drawCircles()
349
+	{
350
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
351
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
352
+			imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor);
353
+		}
354
+	}
355
+
356
+	/**
357
+	 * Draw Lines background
358
+	 */
359
+	public function drawLines()
360
+	{
361
+		for ($i = 0; $i < $this->config['background_num']; ++$i) {
362
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
363
+			imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
364
+		}
365
+	}
366
+
367
+	/**
368
+	 * Draw Rectangles background
369
+	 */
370
+	public function drawRectangles()
371
+	{
372
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
373
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
374
+			imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
375
+		}
376
+	}
377
+
378
+	/**
379
+	 * Draw Bars background
380
+	 */
381
+	public function drawBars()
382
+	{
383
+		for ($i = 0; $i <= $this->height;) {
384
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
385
+			imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor);
386
+			$i += 2.5;
387
+		}
388
+		for ($i = 0; $i <= $this->width;) {
389
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
390
+			imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor);
391
+			$i += 2.5;
392
+		}
393
+	}
394
+
395
+	/**
396
+	 * Draw Ellipses background
397
+	 */
398
+	public function drawEllipses()
399
+	{
400
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
401
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
402
+			imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
403
+		}
404
+	}
405
+
406
+	/**
407
+	 * Draw polygons background
408
+	 */
409
+	public function drawPolygons()
410
+	{
411
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
412
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
413
+			$coords      = [];
414
+			for ($j = 1; $j <= $this->config['polygon_point']; ++$j) {
415
+				$coords[] = mt_rand(0, $this->width);
416
+				$coords[] = mt_rand(0, $this->height);
417
+			}
418
+			imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor);
419
+		}
420
+	}
421
+
422
+	/**
423
+	 *  Create CAPTCHA iamge with BMP
424
+	 *  TODO
425
+	 * @param  string $file
426
+	 * @return string
427
+	 */
428
+	public function createImageBmp($file = '')
429
+	{
430
+		$image = '';
431
+
432
+		if (empty($file)) {
433
+			header('Content-type: image/bmp');
434
+			echo $image;
435
+		} else {
436
+			return $image;
437
+		}
438
+	}
439 439
 }
440 440
 
441 441
 $config       = @include __DIR__ . '/../config.php';
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@  discard block
 block discarded – undo
5 5
  * D.J.
6 6
  */
7 7
 
8
-include dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/mainfile.php';
8
+include dirname(dirname(dirname(dirname(dirname(__DIR__))))).'/mainfile.php';
9 9
 error_reporting(0);
10 10
 $xoopsLogger->activated = false;
11 11
 
12
-if (empty(Request::getString('HTTP_REFERER', '', 'SERVER')) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', Request::getString('HTTP_REFERER', '', 'SERVER'))) {
12
+if (empty(Request::getString('HTTP_REFERER', '', 'SERVER')) || !preg_match('/^'.preg_quote(XOOPS_URL, '/').'/', Request::getString('HTTP_REFERER', '', 'SERVER'))) {
13 13
     exit();
14 14
 }
15 15
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
         if ('bmp' === $this->mode) {
87 87
             $this->config['num_chars'] = 4;
88
-            $this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9'));
88
+            $this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int) str_pad('9', $this->config['num_chars'], '9'));
89 89
         } else {
90 90
             $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']);
91 91
             if (!$this->config['casesensitive']) {
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
             return;
101 101
         }
102 102
 
103
-        $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code;
104
-        $maxAttempts                          = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
103
+        $_SESSION['XoopsCaptcha_sessioncode'] = (string) $this->code;
104
+        $maxAttempts                          = (int) (@$_SESSION['XoopsCaptcha_maxattempts']);
105 105
 
106 106
         // Increase the attempt records on refresh
107 107
         if (!empty($maxAttempts)) {
108
-            $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++;
109
-            if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
108
+            $_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']]++;
109
+            if ($_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
110 110
                 $this->invalid = true;
111 111
             }
112 112
         }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     {
121 121
         if ($this->invalid) {
122 122
             header('Content-type: image/gif');
123
-            readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif');
123
+            readfile(XOOPS_ROOT_PATH.'/images/subject/icon2.gif');
124 124
 
125 125
             return;
126 126
         }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             header('Content-type: image/jpeg');
191 191
             imagejpeg($this->oImage);
192 192
         } else {
193
-            imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg');
193
+            imagejpeg($this->oImage, XOOPS_ROOT_PATH.'/'.$this->config['imagepath'].'/'.$file.'.jpg');
194 194
         }
195 195
         imagedestroy($this->oImage);
196 196
     }
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
          }
212 212
          }
213 213
          */
214
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
215
-        $file_path = $this->config['rootpath'] . "/{$name}";
214
+        require_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
215
+        $file_path = $this->config['rootpath']."/{$name}";
216 216
         $files     = XoopsLists::getFileListAsArray($file_path);
217 217
         foreach ($files as $item) {
218 218
             if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) {
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
     public function loadFont()
230 230
     {
231 231
         $fonts      = $this->_getList('fonts', 'ttf');
232
-        $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)];
232
+        $this->font = $this->config['rootpath'].'/fonts/'.$fonts[array_rand($fonts)];
233 233
     }
234 234
 
235 235
     public function setImageSize()
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         imagedestroy($oImage);
256 256
 
257 257
         $this->height  = $MaxCharHeight + 2;
258
-        $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
258
+        $this->spacing = (int) (($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
259 259
         $this->width   = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2);
260 260
     }
261 261
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     {
269 269
         $RandBackground = null;
270 270
         if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) {
271
-            $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)];
271
+            $RandBackground = $this->config['rootpath'].'/backgrounds/'.$backgrounds[array_rand($backgrounds)];
272 272
         }
273 273
 
274 274
         return $RandBackground;
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
     }
439 439
 }
440 440
 
441
-$config       = @include __DIR__ . '/../config.php';
441
+$config       = @include __DIR__.'/../config.php';
442 442
 $imageHandler = new \XoopsCaptchaImageHandler();
443 443
 $imageHandler->setConfig($config);
444 444
 $imageHandler->loadImage();
Please login to merge, or discard this patch.
admin/admin_header.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,6 +41,6 @@
 block discarded – undo
41 41
 $myts = \MyTextSanitizer::getInstance();
42 42
 
43 43
 if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) {
44
-    require_once $GLOBALS['xoops']->path('class/template.php');
45
-    $xoopsTpl = new \XoopsTpl();
44
+	require_once $GLOBALS['xoops']->path('class/template.php');
45
+	$xoopsTpl = new \XoopsTpl();
46 46
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@
 block discarded – undo
19 19
 
20 20
 use XoopsModules\Smartobject;
21 21
 
22
-require_once __DIR__ . '/../../../include/cp_header.php';
22
+require_once __DIR__.'/../../../include/cp_header.php';
23 23
 //require_once $GLOBALS['xoops']->path('www/class/xoopsformloader.php');
24 24
 
25 25
 // require_once __DIR__ . '/../class/Utility.php';
26
-require_once __DIR__ . '/../include/common.php';
26
+require_once __DIR__.'/../include/common.php';
27 27
 
28 28
 $moduleDirName = basename(dirname(__DIR__));
29 29
 $helper = Smartobject\Helper::getInstance();
Please login to merge, or discard this patch.
admin/about.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@
 block discarded – undo
17 17
  * @author       XOOPS Development Team
18 18
  */
19 19
 
20
-require_once __DIR__ . '/admin_header.php';
20
+require_once __DIR__.'/admin_header.php';
21 21
 xoops_cp_header();
22 22
 
23 23
 $adminObject->displayNavigation(basename(__FILE__));
24 24
 $adminObject::setPaypal('[email protected]');
25 25
 $adminObject->displayAbout(false);
26 26
 
27
-require_once __DIR__ . '/admin_footer.php';
27
+require_once __DIR__.'/admin_footer.php';
Please login to merge, or discard this patch.
preloads/autoloader.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,29 +4,29 @@
 block discarded – undo
4 4
  * @see http://www.php-fig.org/psr/psr-4/examples/
5 5
  */
6 6
 spl_autoload_register(function ($class) {
7
-    // project-specific namespace prefix
8
-    $prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__)));
7
+	// project-specific namespace prefix
8
+	$prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__)));
9 9
 
10
-    // base directory for the namespace prefix
11
-    $base_dir = __DIR__ . '/../class/';
10
+	// base directory for the namespace prefix
11
+	$base_dir = __DIR__ . '/../class/';
12 12
 
13
-    // does the class use the namespace prefix?
14
-    $len      = strlen($prefix);
13
+	// does the class use the namespace prefix?
14
+	$len      = strlen($prefix);
15 15
 
16
-    if (0 !== strncmp($prefix, $class, $len)) {
17
-        return;
18
-    }
16
+	if (0 !== strncmp($prefix, $class, $len)) {
17
+		return;
18
+	}
19 19
 
20
-    // get the relative class name
21
-    $relative_class = substr($class, $len);
20
+	// get the relative class name
21
+	$relative_class = substr($class, $len);
22 22
 
23
-    // replace the namespace prefix with the base directory, replace namespace
24
-    // separators with directory separators in the relative class name, append
25
-    // with .php
26
-    $file           = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
23
+	// replace the namespace prefix with the base directory, replace namespace
24
+	// separators with directory separators in the relative class name, append
25
+	// with .php
26
+	$file           = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
27 27
 
28
-    // if the file exists, require it
29
-    if (file_exists($file)) {
30
-        require $file;
31
-    }
28
+	// if the file exists, require it
29
+	if (file_exists($file)) {
30
+		require $file;
31
+	}
32 32
 });
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * @see http://www.php-fig.org/psr/psr-4/examples/
5 5
  */
6
-spl_autoload_register(function ($class) {
6
+spl_autoload_register(function($class) {
7 7
     // project-specific namespace prefix
8
-    $prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__)));
8
+    $prefix = 'XoopsModules\\'.ucfirst(basename(dirname(__DIR__)));
9 9
 
10 10
     // base directory for the namespace prefix
11
-    $base_dir = __DIR__ . '/../class/';
11
+    $base_dir = __DIR__.'/../class/';
12 12
 
13 13
     // does the class use the namespace prefix?
14 14
     $len      = strlen($prefix);
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     // replace the namespace prefix with the base directory, replace namespace
24 24
     // separators with directory separators in the relative class name, append
25 25
     // with .php
26
-    $file           = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
26
+    $file = $base_dir.str_replace('\\', '/', $relative_class).'.php';
27 27
 
28 28
     // if the file exists, require it
29 29
     if (file_exists($file)) {
Please login to merge, or discard this patch.