Completed
Push — master ( b3fce7...c570af )
by Michael
02:32
created
class/ObjectController.php 1 patch
Indentation   +506 added lines, -506 removed lines patch added patch discarded remove patch
@@ -33,511 +33,511 @@
 block discarded – undo
33 33
  */
34 34
 class ObjectController
35 35
 {
36
-    public $handler;
37
-
38
-    /**
39
-     * SmartObjectController constructor.
40
-     * @param $handler
41
-     */
42
-    public function __construct($handler)
43
-    {
44
-        $this->handler = $handler;
45
-    }
46
-
47
-    /**
48
-     * @param $smartObj
49
-     */
50
-    public function postDataToObject(&$smartObj)
51
-    {
52
-        foreach (array_keys($smartObj->vars) as $key) {
53
-            switch ($smartObj->vars[$key]['data_type']) {
54
-                case XOBJ_DTYPE_IMAGE:
55
-                    if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) {
56
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
57
-                        $smartObj->setVar($key, $_POST['url_' . $key]);
58
-                        if (file_exists($oldFile)) {
59
-                            unlink($oldFile);
60
-                        }
61
-                    }
62
-                    if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) {
63
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
64
-                        $smartObj->setVar($key, '');
65
-                        if (file_exists($oldFile)) {
66
-                            unlink($oldFile);
67
-                        }
68
-                    }
69
-                    break;
70
-
71
-                case XOBJ_DTYPE_URLLINK:
72
-                    $linkObj = $smartObj->getUrlLinkObj($key);
73
-                    $linkObj->setVar('caption', $_POST['caption_' . $key]);
74
-                    $linkObj->setVar('description', $_POST['desc_' . $key]);
75
-                    $linkObj->setVar('target', $_POST['target_' . $key]);
76
-                    $linkObj->setVar('url', $_POST['url_' . $key]);
77
-                    if ('' !== $linkObj->getVar('url')) {
78
-                        $smartObj->storeUrlLinkObj($linkObj);
79
-                    }
80
-                    //todo: catch errors
81
-                    $smartObj->setVar($key, $linkObj->getVar('urllinkid'));
82
-                    break;
83
-
84
-                case XOBJ_DTYPE_FILE:
85
-                    if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) {
86
-                        $fileObj = $smartObj->getFileObj($key);
87
-                        $fileObj->setVar('caption', $_POST['caption_' . $key]);
88
-                        $fileObj->setVar('description', $_POST['desc_' . $key]);
89
-                        $fileObj->setVar('url', $_POST['url_' . $key]);
90
-                        if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url')
91
-                              && '' === $fileObj->getVar('url'))) {
92
-                            $res = $smartObj->storeFileObj($fileObj);
93
-                            if ($res) {
94
-                                $smartObj->setVar($key, $fileObj->getVar('fileid'));
95
-                            } else {
96
-                                //error setted, but no error message (to be improved)
97
-                                $smartObj->setErrors($fileObj->getErrors());
98
-                            }
99
-                        }
100
-                    }
101
-                    break;
102
-
103
-                case XOBJ_DTYPE_STIME:
104
-                case XOBJ_DTYPE_MTIME:
105
-                case XOBJ_DTYPE_LTIME:
106
-                    // check if this field's value is available in the POST array
107
-                    if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
108
-                        $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
109
-                    } else {
110
-                        $value = strtotime($_POST[$key]);
111
-                        //if strtotime returns false, the value is already a time stamp
112
-                        if (!$value) {
113
-                            $value = (int)$_POST[$key];
114
-                        }
115
-                    }
116
-                    $smartObj->setVar($key, $value);
117
-
118
-                    break;
119
-
120
-                default:
121
-                    $smartObj->setVar($key, $_POST[$key]);
122
-                    break;
123
-            }
124
-        }
125
-    }
126
-
127
-    /**
128
-     * @param        $smartObj
129
-     * @param        $objectid
130
-     * @param        $created_success_msg
131
-     * @param        $modified_success_msg
132
-     * @param  bool  $redirect_page
133
-     * @param  bool  $debug
134
-     * @return mixed
135
-     */
136
-    public function doStoreFromDefaultForm(
137
-        &$smartObj,
138
-        $objectid,
139
-        $created_success_msg,
140
-        $modified_success_msg,
141
-        $redirect_page = false,
142
-        $debug = false
143
-    ) {
144
-        global $smart_previous_page;
145
-
146
-        $this->postDataToObject($smartObj);
147
-
148
-        if ($smartObj->isNew()) {
149
-            $redirect_msg = $created_success_msg;
150
-        } else {
151
-            $redirect_msg = $modified_success_msg;
152
-        }
153
-
154
-        // Check if there were uploaded files
155
-        if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
36
+	public $handler;
37
+
38
+	/**
39
+	 * SmartObjectController constructor.
40
+	 * @param $handler
41
+	 */
42
+	public function __construct($handler)
43
+	{
44
+		$this->handler = $handler;
45
+	}
46
+
47
+	/**
48
+	 * @param $smartObj
49
+	 */
50
+	public function postDataToObject(&$smartObj)
51
+	{
52
+		foreach (array_keys($smartObj->vars) as $key) {
53
+			switch ($smartObj->vars[$key]['data_type']) {
54
+				case XOBJ_DTYPE_IMAGE:
55
+					if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) {
56
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
57
+						$smartObj->setVar($key, $_POST['url_' . $key]);
58
+						if (file_exists($oldFile)) {
59
+							unlink($oldFile);
60
+						}
61
+					}
62
+					if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) {
63
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
64
+						$smartObj->setVar($key, '');
65
+						if (file_exists($oldFile)) {
66
+							unlink($oldFile);
67
+						}
68
+					}
69
+					break;
70
+
71
+				case XOBJ_DTYPE_URLLINK:
72
+					$linkObj = $smartObj->getUrlLinkObj($key);
73
+					$linkObj->setVar('caption', $_POST['caption_' . $key]);
74
+					$linkObj->setVar('description', $_POST['desc_' . $key]);
75
+					$linkObj->setVar('target', $_POST['target_' . $key]);
76
+					$linkObj->setVar('url', $_POST['url_' . $key]);
77
+					if ('' !== $linkObj->getVar('url')) {
78
+						$smartObj->storeUrlLinkObj($linkObj);
79
+					}
80
+					//todo: catch errors
81
+					$smartObj->setVar($key, $linkObj->getVar('urllinkid'));
82
+					break;
83
+
84
+				case XOBJ_DTYPE_FILE:
85
+					if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) {
86
+						$fileObj = $smartObj->getFileObj($key);
87
+						$fileObj->setVar('caption', $_POST['caption_' . $key]);
88
+						$fileObj->setVar('description', $_POST['desc_' . $key]);
89
+						$fileObj->setVar('url', $_POST['url_' . $key]);
90
+						if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url')
91
+							  && '' === $fileObj->getVar('url'))) {
92
+							$res = $smartObj->storeFileObj($fileObj);
93
+							if ($res) {
94
+								$smartObj->setVar($key, $fileObj->getVar('fileid'));
95
+							} else {
96
+								//error setted, but no error message (to be improved)
97
+								$smartObj->setErrors($fileObj->getErrors());
98
+							}
99
+						}
100
+					}
101
+					break;
102
+
103
+				case XOBJ_DTYPE_STIME:
104
+				case XOBJ_DTYPE_MTIME:
105
+				case XOBJ_DTYPE_LTIME:
106
+					// check if this field's value is available in the POST array
107
+					if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
108
+						$value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
109
+					} else {
110
+						$value = strtotime($_POST[$key]);
111
+						//if strtotime returns false, the value is already a time stamp
112
+						if (!$value) {
113
+							$value = (int)$_POST[$key];
114
+						}
115
+					}
116
+					$smartObj->setVar($key, $value);
117
+
118
+					break;
119
+
120
+				default:
121
+					$smartObj->setVar($key, $_POST[$key]);
122
+					break;
123
+			}
124
+		}
125
+	}
126
+
127
+	/**
128
+	 * @param        $smartObj
129
+	 * @param        $objectid
130
+	 * @param        $created_success_msg
131
+	 * @param        $modified_success_msg
132
+	 * @param  bool  $redirect_page
133
+	 * @param  bool  $debug
134
+	 * @return mixed
135
+	 */
136
+	public function doStoreFromDefaultForm(
137
+		&$smartObj,
138
+		$objectid,
139
+		$created_success_msg,
140
+		$modified_success_msg,
141
+		$redirect_page = false,
142
+		$debug = false
143
+	) {
144
+		global $smart_previous_page;
145
+
146
+		$this->postDataToObject($smartObj);
147
+
148
+		if ($smartObj->isNew()) {
149
+			$redirect_msg = $created_success_msg;
150
+		} else {
151
+			$redirect_msg = $modified_success_msg;
152
+		}
153
+
154
+		// Check if there were uploaded files
155
+		if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
156 156
 //            require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
157
-            $uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
158
-            foreach ($_FILES as $name => $file_array) {
159
-                if (isset($file_array['name']) && '' !== $file_array['name']
160
-                    && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
161
-                    if ($uploaderObj->fetchMedia($name)) {
162
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
163
-                        if ($uploaderObj->upload()) {
164
-                            // Find the related field in the SmartObject
165
-                            $related_field   = str_replace('upload_', '', $name);
166
-                            $uploadedArray[] = $related_field;
167
-                            //si c'est un fichier Rich
168
-                            if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) {
169
-                                $object_fileurl = $smartObj->getUploadDir();
170
-                                $fileObj        = $smartObj->getFileObj($related_field);
171
-                                $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
172
-                                $fileObj->setVar('caption', $_POST['caption_' . $related_field]);
173
-                                $fileObj->setVar('description', $_POST['desc_' . $related_field]);
174
-                                $smartObj->storeFileObj($fileObj);
175
-                                //todo: catch errors
176
-                                $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
177
-                            } else {
178
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
179
-                                unlink($old_file);
180
-                                $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
181
-                            }
182
-                        } else {
183
-                            $smartObj->setErrors($uploaderObj->getErrors(false));
184
-                        }
185
-                    } else {
186
-                        $smartObj->setErrors($uploaderObj->getErrors(false));
187
-                    }
188
-                }
189
-            }
190
-        }
191
-
192
-        if ($debug) {
193
-            $storeResult = $this->handler->insertD($smartObj);
194
-        } else {
195
-            $storeResult = $this->handler->insert($smartObj);
196
-        }
197
-
198
-        if ($storeResult) {
199
-            if ($this->handler->getPermissions()) {
200
-                $smartPermissionsHandler = new PermissionHandler($this->handler);
201
-                $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
202
-            }
203
-        }
204
-
205
-        if (null === $redirect_page) {
206
-            return $smartObj;
207
-        } else {
208
-            if (!$storeResult) {
209
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
210
-            }
211
-
212
-            $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm();
213
-
214
-            redirect_header($redirect_page, 2, $redirect_msg);
215
-        }
216
-    }
217
-
218
-    /**
219
-     * Store the object in the database autmatically from a form sending POST data
220
-     *
221
-     * @param  string      $created_success_msg  message to display if new object was created
222
-     * @param  string      $modified_success_msg message to display if object was successfully edited
223
-     * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
224
-     * @param  bool        $debug
225
-     * @param  bool        $x_param
226
-     * @return bool
227
-     * @internal param string $created_redir_page redirect page after creating the object
228
-     * @internal param string $modified_redir_page redirect page after editing the object
229
-     * @internal param bool $exit if set to TRUE then the script ends
230
-     */
231
-    public function storeFromDefaultForm(
232
-        $created_success_msg,
233
-        $modified_success_msg,
234
-        $redirect_page = false,
235
-        $debug = false,
236
-        $x_param = false
237
-    ) {
238
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
239
-        if ($debug) {
240
-            if ($x_param) {
241
-                $smartObj = $this->handler->getD($objectid, true, $x_param);
242
-            } else {
243
-                $smartObj = $this->handler->getD($objectid);
244
-            }
245
-        } else {
246
-            if ($x_param) {
247
-                $smartObj = $this->handler->get($objectid, true, false, false, $x_param);
248
-            } else {
249
-                $smartObj = $this->handler->get($objectid);
250
-            }
251
-        }
252
-
253
-        // if handler is the Multilanguage handler, we will need to treat this for multilanguage
254
-        if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
255
-            if ($smartObj->isNew()) {
256
-                // This is a new object. We need to store the meta data and then the language data
257
-                // First, we will get rid of the multilanguage data to only store the meta data
258
-                $smartObj->stripMultilanguageFields();
259
-                $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
260
-                /**
261
-                 * @todo we need to trap potential errors here
262
-                 */
263
-
264
-                // ok, the meta daa is stored. Let's recreate the object and then
265
-                // get rid of anything not multilanguage
266
-                unset($smartObj);
267
-                $smartObj = $this->handler->get($objectid);
268
-                $smartObj->stripNonMultilanguageFields();
269
-
270
-                $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
271
-                $this->handler->changeTableNameForML();
272
-                $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
273
-
274
-                return $ret;
275
-            }
276
-        } else {
277
-            return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
278
-        }
279
-    }
280
-
281
-    /**
282
-     * @return bool
283
-     */
284
-    public function storeSmartObjectD()
285
-    {
286
-        return $this->storeSmartObject(true);
287
-    }
288
-
289
-    /**
290
-     * @param  bool $debug
291
-     * @param  bool $xparam
292
-     * @return bool
293
-     */
294
-    public function storeSmartObject($debug = false, $xparam = false)
295
-    {
296
-        $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
297
-
298
-        return $ret;
299
-    }
300
-
301
-    /**
302
-     * Handles deletion of an object which keyid is passed as a GET param
303
-     *
304
-     * @param  bool   $confirm_msg
305
-     * @param  string $op
306
-     * @param  bool   $userSide
307
-     * @return void
308
-     * @internal param string $redir_page redirect page after deleting the object
309
-     */
310
-    public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
311
-    {
312
-        global $smart_previous_page;
313
-
314
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
315
-        $smartObj = $this->handler->get($objectid);
316
-
317
-        if ($smartObj->isNew()) {
318
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
319
-        }
320
-
321
-        $confirm = \Xmf\Request::getInt('confirm', 0, POST);
322
-        if ($confirm) {
323
-            if (!$this->handler->delete($smartObj)) {
324
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
325
-            }
326
-
327
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
328
-        } else {
329
-            // no confirm: show deletion condition
330
-
331
-            xoops_cp_header();
332
-
333
-            if (!$confirm_msg) {
334
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
335
-            }
336
-
337
-            xoops_confirm([
338
-                              'op'                    => $op,
339
-                              $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
340
-                              'confirm'               => 1,
341
-                              'redirect_page'         => $smart_previous_page
342
-                          ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
343
-
344
-            xoops_cp_footer();
345
-        }
346
-        exit();
347
-    }
348
-
349
-    /**
350
-     * @param bool   $confirm_msg
351
-     * @param string $op
352
-     */
353
-    public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
354
-    {
355
-        global $smart_previous_page, $xoopsTpl;
356
-
357
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
358
-        $smartObj = $this->handler->get($objectid);
359
-
360
-        if ($smartObj->isNew()) {
361
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
362
-        }
363
-
364
-        $confirm = \Xmf\Request::getInt('confirm', 0, POST);
365
-        if ($confirm) {
366
-            if (!$this->handler->delete($smartObj)) {
367
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
368
-            }
369
-
370
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
371
-        } else {
372
-            // no confirm: show deletion condition
373
-            if (!$confirm_msg) {
374
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
375
-            }
376
-
377
-            ob_start();
378
-            xoops_confirm([
379
-                              'op'                    => $op,
380
-                              $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
381
-                              'confirm'               => 1,
382
-                              'redirect_page'         => $smart_previous_page
383
-                          ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
384
-            $smartobjectDeleteConfirm = ob_get_clean();
385
-            $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
386
-        }
387
-    }
388
-
389
-    /**
390
-     * Retreive the object admin side link for a {@link SmartObjectSingleView} page
391
-     *
392
-     * @param  SmartObject $smartObj reference to the object from which we want the user side link
393
-     * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
394
-     * @param  bool        $withimage
395
-     * @return string      admin side link to the object
396
-     */
397
-    public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
398
-    {
399
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
400
-        if ($onlyUrl) {
401
-            return $ret;
402
-        } elseif ($withimage) {
403
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "'  title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>";
404
-        }
405
-
406
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
407
-    }
408
-
409
-    /**
410
-     * Retreive the object user side link
411
-     *
412
-     * @param  SmartObject $smartObj reference to the object from which we want the user side link
413
-     * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
414
-     * @return string      user side link to the object
415
-     */
416
-    public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
417
-    {
418
-        $seoMode       = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName);
419
-        $seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName);
420
-
421
-        /**
422
-         * $seoIncludeId feature is not finished yet, so let's put it always to true
423
-         */
424
-        //$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName);
425
-        $seoIncludeId = true;
426
-
427
-        if ('rewrite' === $seoMode) {
428
-            $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
429
-        } elseif ('pathinfo' === $seoMode) {
430
-            $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
431
-        } else {
432
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
433
-        }
434
-
435
-        if (!$onlyUrl) {
436
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
437
-        }
438
-
439
-        return $ret;
440
-    }
441
-
442
-    /**
443
-     * @param         $smartObj
444
-     * @param  bool   $onlyUrl
445
-     * @param  bool   $withimage
446
-     * @return string
447
-     */
448
-    public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
449
-    {
450
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
451
-        if ($onlyUrl) {
452
-            return $ret;
453
-        } elseif ($withimage) {
454
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'  title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>";
455
-        }
456
-
457
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
458
-    }
459
-
460
-    /**
461
-     * @param         $smartObj
462
-     * @param  bool   $onlyUrl
463
-     * @param  bool   $withimage
464
-     * @param  bool   $userSide
465
-     * @return string
466
-     */
467
-    public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
468
-    {
469
-        $admin_side = $userSide ? '' : 'admin/';
470
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
471
-        if ($onlyUrl) {
472
-            return $ret;
473
-        } elseif ($withimage) {
474
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "'  title='" . _CO_SOBJECT_MODIFY . "'></a>";
475
-        }
476
-
477
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
478
-    }
479
-
480
-    /**
481
-     * @param         $smartObj
482
-     * @param  bool   $onlyUrl
483
-     * @param  bool   $withimage
484
-     * @param  bool   $userSide
485
-     * @return string
486
-     */
487
-    public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
488
-    {
489
-        $admin_side = $userSide ? '' : 'admin/';
490
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
491
-        if ($onlyUrl) {
492
-            return $ret;
493
-        } elseif ($withimage) {
494
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "'  title='" . _CO_SOBJECT_DELETE . "'></a>";
495
-        }
496
-
497
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
498
-    }
499
-
500
-    /**
501
-     * @param $smartObj
502
-     * @return string
503
-     */
504
-    public function getPrintAndMailLink($smartObj)
505
-    {
506
-        global $xoopsConfig;
507
-
508
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
509
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
510
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>';
511
-
512
-        $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName);
513
-        $link        = Smartobject\Utility::getCurrentPage();
514
-        $mid         = $smartModule->getVar('mid');
515
-        $friendlink  = "<a href=\"javascript:openWithSelfMain('"
516
-                       . SMARTOBJECT_URL
517
-                       . 'sendlink.php?link='
518
-                       . $link
519
-                       . '&amp;mid='
520
-                       . $mid
521
-                       . "', ',',',',',','sendmessage', 674, 500);\"><img src=\""
522
-                       . SMARTOBJECT_IMAGES_ACTIONS_URL
523
-                       . 'mail_send.png"  alt="'
524
-                       . _CO_SOBJECT_EMAIL
525
-                       . '" title="'
526
-                       . _CO_SOBJECT_EMAIL
527
-                       . '" style="vertical-align: middle;"></a>';
528
-
529
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
530
-
531
-        return $ret;
532
-    }
533
-
534
-    /**
535
-     * @return string
536
-     */
537
-    public function getModuleItemString()
538
-    {
539
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
540
-
541
-        return $ret;
542
-    }
157
+			$uploaderObj = new Uploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
158
+			foreach ($_FILES as $name => $file_array) {
159
+				if (isset($file_array['name']) && '' !== $file_array['name']
160
+					&& in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
161
+					if ($uploaderObj->fetchMedia($name)) {
162
+						$uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
163
+						if ($uploaderObj->upload()) {
164
+							// Find the related field in the SmartObject
165
+							$related_field   = str_replace('upload_', '', $name);
166
+							$uploadedArray[] = $related_field;
167
+							//si c'est un fichier Rich
168
+							if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) {
169
+								$object_fileurl = $smartObj->getUploadDir();
170
+								$fileObj        = $smartObj->getFileObj($related_field);
171
+								$fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
172
+								$fileObj->setVar('caption', $_POST['caption_' . $related_field]);
173
+								$fileObj->setVar('description', $_POST['desc_' . $related_field]);
174
+								$smartObj->storeFileObj($fileObj);
175
+								//todo: catch errors
176
+								$smartObj->setVar($related_field, $fileObj->getVar('fileid'));
177
+							} else {
178
+								$old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
179
+								unlink($old_file);
180
+								$smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
181
+							}
182
+						} else {
183
+							$smartObj->setErrors($uploaderObj->getErrors(false));
184
+						}
185
+					} else {
186
+						$smartObj->setErrors($uploaderObj->getErrors(false));
187
+					}
188
+				}
189
+			}
190
+		}
191
+
192
+		if ($debug) {
193
+			$storeResult = $this->handler->insertD($smartObj);
194
+		} else {
195
+			$storeResult = $this->handler->insert($smartObj);
196
+		}
197
+
198
+		if ($storeResult) {
199
+			if ($this->handler->getPermissions()) {
200
+				$smartPermissionsHandler = new PermissionHandler($this->handler);
201
+				$smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
202
+			}
203
+		}
204
+
205
+		if (null === $redirect_page) {
206
+			return $smartObj;
207
+		} else {
208
+			if (!$storeResult) {
209
+				redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
210
+			}
211
+
212
+			$redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm();
213
+
214
+			redirect_header($redirect_page, 2, $redirect_msg);
215
+		}
216
+	}
217
+
218
+	/**
219
+	 * Store the object in the database autmatically from a form sending POST data
220
+	 *
221
+	 * @param  string      $created_success_msg  message to display if new object was created
222
+	 * @param  string      $modified_success_msg message to display if object was successfully edited
223
+	 * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
224
+	 * @param  bool        $debug
225
+	 * @param  bool        $x_param
226
+	 * @return bool
227
+	 * @internal param string $created_redir_page redirect page after creating the object
228
+	 * @internal param string $modified_redir_page redirect page after editing the object
229
+	 * @internal param bool $exit if set to TRUE then the script ends
230
+	 */
231
+	public function storeFromDefaultForm(
232
+		$created_success_msg,
233
+		$modified_success_msg,
234
+		$redirect_page = false,
235
+		$debug = false,
236
+		$x_param = false
237
+	) {
238
+		$objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
239
+		if ($debug) {
240
+			if ($x_param) {
241
+				$smartObj = $this->handler->getD($objectid, true, $x_param);
242
+			} else {
243
+				$smartObj = $this->handler->getD($objectid);
244
+			}
245
+		} else {
246
+			if ($x_param) {
247
+				$smartObj = $this->handler->get($objectid, true, false, false, $x_param);
248
+			} else {
249
+				$smartObj = $this->handler->get($objectid);
250
+			}
251
+		}
252
+
253
+		// if handler is the Multilanguage handler, we will need to treat this for multilanguage
254
+		if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
255
+			if ($smartObj->isNew()) {
256
+				// This is a new object. We need to store the meta data and then the language data
257
+				// First, we will get rid of the multilanguage data to only store the meta data
258
+				$smartObj->stripMultilanguageFields();
259
+				$newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
260
+				/**
261
+				 * @todo we need to trap potential errors here
262
+				 */
263
+
264
+				// ok, the meta daa is stored. Let's recreate the object and then
265
+				// get rid of anything not multilanguage
266
+				unset($smartObj);
267
+				$smartObj = $this->handler->get($objectid);
268
+				$smartObj->stripNonMultilanguageFields();
269
+
270
+				$smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
271
+				$this->handler->changeTableNameForML();
272
+				$ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
273
+
274
+				return $ret;
275
+			}
276
+		} else {
277
+			return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
278
+		}
279
+	}
280
+
281
+	/**
282
+	 * @return bool
283
+	 */
284
+	public function storeSmartObjectD()
285
+	{
286
+		return $this->storeSmartObject(true);
287
+	}
288
+
289
+	/**
290
+	 * @param  bool $debug
291
+	 * @param  bool $xparam
292
+	 * @return bool
293
+	 */
294
+	public function storeSmartObject($debug = false, $xparam = false)
295
+	{
296
+		$ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
297
+
298
+		return $ret;
299
+	}
300
+
301
+	/**
302
+	 * Handles deletion of an object which keyid is passed as a GET param
303
+	 *
304
+	 * @param  bool   $confirm_msg
305
+	 * @param  string $op
306
+	 * @param  bool   $userSide
307
+	 * @return void
308
+	 * @internal param string $redir_page redirect page after deleting the object
309
+	 */
310
+	public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
311
+	{
312
+		global $smart_previous_page;
313
+
314
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
315
+		$smartObj = $this->handler->get($objectid);
316
+
317
+		if ($smartObj->isNew()) {
318
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
319
+		}
320
+
321
+		$confirm = \Xmf\Request::getInt('confirm', 0, POST);
322
+		if ($confirm) {
323
+			if (!$this->handler->delete($smartObj)) {
324
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
325
+			}
326
+
327
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
328
+		} else {
329
+			// no confirm: show deletion condition
330
+
331
+			xoops_cp_header();
332
+
333
+			if (!$confirm_msg) {
334
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
335
+			}
336
+
337
+			xoops_confirm([
338
+							  'op'                    => $op,
339
+							  $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
340
+							  'confirm'               => 1,
341
+							  'redirect_page'         => $smart_previous_page
342
+						  ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
343
+
344
+			xoops_cp_footer();
345
+		}
346
+		exit();
347
+	}
348
+
349
+	/**
350
+	 * @param bool   $confirm_msg
351
+	 * @param string $op
352
+	 */
353
+	public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
354
+	{
355
+		global $smart_previous_page, $xoopsTpl;
356
+
357
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
358
+		$smartObj = $this->handler->get($objectid);
359
+
360
+		if ($smartObj->isNew()) {
361
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
362
+		}
363
+
364
+		$confirm = \Xmf\Request::getInt('confirm', 0, POST);
365
+		if ($confirm) {
366
+			if (!$this->handler->delete($smartObj)) {
367
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
368
+			}
369
+
370
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
371
+		} else {
372
+			// no confirm: show deletion condition
373
+			if (!$confirm_msg) {
374
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
375
+			}
376
+
377
+			ob_start();
378
+			xoops_confirm([
379
+							  'op'                    => $op,
380
+							  $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
381
+							  'confirm'               => 1,
382
+							  'redirect_page'         => $smart_previous_page
383
+						  ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
384
+			$smartobjectDeleteConfirm = ob_get_clean();
385
+			$xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
386
+		}
387
+	}
388
+
389
+	/**
390
+	 * Retreive the object admin side link for a {@link SmartObjectSingleView} page
391
+	 *
392
+	 * @param  SmartObject $smartObj reference to the object from which we want the user side link
393
+	 * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
394
+	 * @param  bool        $withimage
395
+	 * @return string      admin side link to the object
396
+	 */
397
+	public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
398
+	{
399
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
400
+		if ($onlyUrl) {
401
+			return $ret;
402
+		} elseif ($withimage) {
403
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "'  title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>";
404
+		}
405
+
406
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
407
+	}
408
+
409
+	/**
410
+	 * Retreive the object user side link
411
+	 *
412
+	 * @param  SmartObject $smartObj reference to the object from which we want the user side link
413
+	 * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
414
+	 * @return string      user side link to the object
415
+	 */
416
+	public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
417
+	{
418
+		$seoMode       = Smartobject\Utility::getModuleModeSEO($this->handler->_moduleName);
419
+		$seoModuleName = Smartobject\Utility::getModuleNameForSEO($this->handler->_moduleName);
420
+
421
+		/**
422
+		 * $seoIncludeId feature is not finished yet, so let's put it always to true
423
+		 */
424
+		//$seoIncludeId = Smartobject\Utility::getModuleIncludeIdSEO($this->handler->_moduleName);
425
+		$seoIncludeId = true;
426
+
427
+		if ('rewrite' === $seoMode) {
428
+			$ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
429
+		} elseif ('pathinfo' === $seoMode) {
430
+			$ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
431
+		} else {
432
+			$ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
433
+		}
434
+
435
+		if (!$onlyUrl) {
436
+			$ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
437
+		}
438
+
439
+		return $ret;
440
+	}
441
+
442
+	/**
443
+	 * @param         $smartObj
444
+	 * @param  bool   $onlyUrl
445
+	 * @param  bool   $withimage
446
+	 * @return string
447
+	 */
448
+	public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
449
+	{
450
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
451
+		if ($onlyUrl) {
452
+			return $ret;
453
+		} elseif ($withimage) {
454
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'  title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>";
455
+		}
456
+
457
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
458
+	}
459
+
460
+	/**
461
+	 * @param         $smartObj
462
+	 * @param  bool   $onlyUrl
463
+	 * @param  bool   $withimage
464
+	 * @param  bool   $userSide
465
+	 * @return string
466
+	 */
467
+	public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
468
+	{
469
+		$admin_side = $userSide ? '' : 'admin/';
470
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
471
+		if ($onlyUrl) {
472
+			return $ret;
473
+		} elseif ($withimage) {
474
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "'  title='" . _CO_SOBJECT_MODIFY . "'></a>";
475
+		}
476
+
477
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
478
+	}
479
+
480
+	/**
481
+	 * @param         $smartObj
482
+	 * @param  bool   $onlyUrl
483
+	 * @param  bool   $withimage
484
+	 * @param  bool   $userSide
485
+	 * @return string
486
+	 */
487
+	public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
488
+	{
489
+		$admin_side = $userSide ? '' : 'admin/';
490
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
491
+		if ($onlyUrl) {
492
+			return $ret;
493
+		} elseif ($withimage) {
494
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "'  title='" . _CO_SOBJECT_DELETE . "'></a>";
495
+		}
496
+
497
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
498
+	}
499
+
500
+	/**
501
+	 * @param $smartObj
502
+	 * @return string
503
+	 */
504
+	public function getPrintAndMailLink($smartObj)
505
+	{
506
+		global $xoopsConfig;
507
+
508
+		$printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
509
+		$js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
510
+		$printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>';
511
+
512
+		$smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName);
513
+		$link        = Smartobject\Utility::getCurrentPage();
514
+		$mid         = $smartModule->getVar('mid');
515
+		$friendlink  = "<a href=\"javascript:openWithSelfMain('"
516
+					   . SMARTOBJECT_URL
517
+					   . 'sendlink.php?link='
518
+					   . $link
519
+					   . '&amp;mid='
520
+					   . $mid
521
+					   . "', ',',',',',','sendmessage', 674, 500);\"><img src=\""
522
+					   . SMARTOBJECT_IMAGES_ACTIONS_URL
523
+					   . 'mail_send.png"  alt="'
524
+					   . _CO_SOBJECT_EMAIL
525
+					   . '" title="'
526
+					   . _CO_SOBJECT_EMAIL
527
+					   . '" style="vertical-align: middle;"></a>';
528
+
529
+		$ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
530
+
531
+		return $ret;
532
+	}
533
+
534
+	/**
535
+	 * @return string
536
+	 */
537
+	public function getModuleItemString()
538
+	{
539
+		$ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
540
+
541
+		return $ret;
542
+	}
543 543
 }
Please login to merge, or discard this patch.
class/Form/SmartObjectForm.php 1 patch
Indentation   +699 added lines, -699 removed lines patch added patch discarded remove patch
@@ -44,549 +44,549 @@  discard block
 block discarded – undo
44 44
  */
45 45
 class SmartObjectForm extends \XoopsThemeForm
46 46
 {
47
-    public $targetObject           = null;
48
-    public $form_fields            = null;
49
-    public $_cancel_js_action      = false;
50
-    public $_custom_button         = false;
51
-    public $_captcha               = false;
52
-    public $_form_name             = false;
53
-    public $_form_caption          = false;
54
-    public $_submit_button_caption = false;
55
-
56
-    /**
57
-     * SmartobjectForm constructor.
58
-     * @param string $target
59
-     * @param string $form_name
60
-     * @param string $form_caption
61
-     * @param string $form_action
62
-     * @param null   $form_fields
63
-     * @param bool   $submit_button_caption
64
-     * @param bool   $cancel_js_action
65
-     * @param bool   $captcha
66
-     */
67
-    public function __construct(
68
-        &$target,
69
-        $form_name,
70
-        $form_caption,
71
-        $form_action,
72
-        $form_fields = null,
73
-        $submit_button_caption = false,
74
-        $cancel_js_action = false,
75
-        $captcha = false
76
-    ) {
77
-        $this->targetObject           =& $target;
78
-        $this->form_fields            = $form_fields;
79
-        $this->_cancel_js_action      = $cancel_js_action;
80
-        $this->_captcha               = $captcha;
81
-        $this->_form_name             = $form_name;
82
-        $this->_form_caption          = $form_caption;
83
-        $this->_submit_button_caption = $submit_button_caption;
84
-
85
-        if (!isset($form_action)) {
86
-            $form_action = xoops_getenv('PHP_SELF');
87
-        }
88
-
89
-        parent::__construct($form_caption, $form_name, $form_action, 'post', true);
90
-        $this->setExtra('enctype="multipart/form-data"');
91
-
92
-        $this->createElements();
93
-
94
-        if ($captcha) {
95
-            $this->addCaptcha();
96
-        }
97
-
98
-        $this->createPermissionControls();
99
-
100
-        $this->createButtons($form_name, $form_caption, $submit_button_caption);
101
-    }
102
-
103
-    public function addCaptcha()
104
-    {
105
-        require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php';
106
-        $this->addElement(new \XoopsFormCaptcha(), true);
107
-    }
108
-
109
-    /**
110
-     * @param      $name
111
-     * @param      $caption
112
-     * @param bool $onclick
113
-     */
114
-    public function addCustomButton($name, $caption, $onclick = false)
115
-    {
116
-        $custom_button_array    = [
117
-            'name'    => $name,
118
-            'caption' => $caption,
119
-            'onclick' => $onclick
120
-        ];
121
-        $this->_custom_button[] = $custom_button_array;
122
-    }
123
-
124
-    /**
125
-     * Add an element to the form
126
-     *
127
-     * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement}
128
-     * @param bool                    $key
129
-     * @param bool                    $var
130
-     * @param bool|string             $required     is this a "required" element?
131
-     */
132
-    public function addElement($formElement, $key = false, $var = false, $required = 'notset')
133
-    {
134
-        if ($key) {
135
-            if ($this->targetObject->vars[$key]['readonly']) {
136
-                $formElement->setExtra('disabled="disabled"');
137
-                $formElement->setName($key . '-readonly');
138
-                // Since this element is disable, we still want to pass it's value in the form
139
-                $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
140
-                $this->addElement($hidden);
141
-            }
142
-            $formElement->setDescription($var['form_dsc']);
143
-            if (isset($this->targetObject->controls[$key]['onSelect'])) {
144
-                $hidden = new \XoopsFormHidden('changedField', false);
145
-                $this->addElement($hidden);
146
-                $otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
147
-                $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
148
-                $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
149
-            } else {
150
-                if (isset($var['form_extra'])) {
151
-                    $formElement->setExtra($var['form_extra']);
152
-                }
153
-            }
154
-            $controls = $this->targetObject->controls;
155
-            if (isset($controls[$key]['js'])) {
156
-                $formElement->customValidationCode[] = $controls[$key]['js'];
157
-            }
158
-            parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required);
159
-        } else {
160
-            parent::addElement($formElement, 'notset' === $required ? false : true);
161
-        }
162
-        unset($formElement);
163
-    }
164
-
165
-    public function createElements()
166
-    {
167
-        $controls = $this->targetObject->controls;
168
-        $vars     = $this->targetObject->vars;
169
-        foreach ($vars as $key => $var) {
170
-
171
-            // If $displayOnForm is false OR this is the primary key, it doesn't
172
-            // need to be displayed, then we only create an hidden field
173
-            if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
174
-                $elementToAdd = new \XoopsFormHidden($key, $var['value']);
175
-                $this->addElement($elementToAdd, $key, $var, false);
176
-                unset($elementToAdd);
177
-            // If not, the we need to create the proper form control for this fields
178
-            } else {
179
-                // If this field has a specific control, we will use it
180
-
181
-                if ('parentid' === $key) {
182
-                    /**
183
-                     * Why this ?
184
-                     */
185
-                }
186
-                if (isset($controls[$key])) {
187
-                    /* If the control has name, it's because it's an object already present in the script
47
+	public $targetObject           = null;
48
+	public $form_fields            = null;
49
+	public $_cancel_js_action      = false;
50
+	public $_custom_button         = false;
51
+	public $_captcha               = false;
52
+	public $_form_name             = false;
53
+	public $_form_caption          = false;
54
+	public $_submit_button_caption = false;
55
+
56
+	/**
57
+	 * SmartobjectForm constructor.
58
+	 * @param string $target
59
+	 * @param string $form_name
60
+	 * @param string $form_caption
61
+	 * @param string $form_action
62
+	 * @param null   $form_fields
63
+	 * @param bool   $submit_button_caption
64
+	 * @param bool   $cancel_js_action
65
+	 * @param bool   $captcha
66
+	 */
67
+	public function __construct(
68
+		&$target,
69
+		$form_name,
70
+		$form_caption,
71
+		$form_action,
72
+		$form_fields = null,
73
+		$submit_button_caption = false,
74
+		$cancel_js_action = false,
75
+		$captcha = false
76
+	) {
77
+		$this->targetObject           =& $target;
78
+		$this->form_fields            = $form_fields;
79
+		$this->_cancel_js_action      = $cancel_js_action;
80
+		$this->_captcha               = $captcha;
81
+		$this->_form_name             = $form_name;
82
+		$this->_form_caption          = $form_caption;
83
+		$this->_submit_button_caption = $submit_button_caption;
84
+
85
+		if (!isset($form_action)) {
86
+			$form_action = xoops_getenv('PHP_SELF');
87
+		}
88
+
89
+		parent::__construct($form_caption, $form_name, $form_action, 'post', true);
90
+		$this->setExtra('enctype="multipart/form-data"');
91
+
92
+		$this->createElements();
93
+
94
+		if ($captcha) {
95
+			$this->addCaptcha();
96
+		}
97
+
98
+		$this->createPermissionControls();
99
+
100
+		$this->createButtons($form_name, $form_caption, $submit_button_caption);
101
+	}
102
+
103
+	public function addCaptcha()
104
+	{
105
+		require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php';
106
+		$this->addElement(new \XoopsFormCaptcha(), true);
107
+	}
108
+
109
+	/**
110
+	 * @param      $name
111
+	 * @param      $caption
112
+	 * @param bool $onclick
113
+	 */
114
+	public function addCustomButton($name, $caption, $onclick = false)
115
+	{
116
+		$custom_button_array    = [
117
+			'name'    => $name,
118
+			'caption' => $caption,
119
+			'onclick' => $onclick
120
+		];
121
+		$this->_custom_button[] = $custom_button_array;
122
+	}
123
+
124
+	/**
125
+	 * Add an element to the form
126
+	 *
127
+	 * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement}
128
+	 * @param bool                    $key
129
+	 * @param bool                    $var
130
+	 * @param bool|string             $required     is this a "required" element?
131
+	 */
132
+	public function addElement($formElement, $key = false, $var = false, $required = 'notset')
133
+	{
134
+		if ($key) {
135
+			if ($this->targetObject->vars[$key]['readonly']) {
136
+				$formElement->setExtra('disabled="disabled"');
137
+				$formElement->setName($key . '-readonly');
138
+				// Since this element is disable, we still want to pass it's value in the form
139
+				$hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
140
+				$this->addElement($hidden);
141
+			}
142
+			$formElement->setDescription($var['form_dsc']);
143
+			if (isset($this->targetObject->controls[$key]['onSelect'])) {
144
+				$hidden = new \XoopsFormHidden('changedField', false);
145
+				$this->addElement($hidden);
146
+				$otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
147
+				$onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
148
+				$formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
149
+			} else {
150
+				if (isset($var['form_extra'])) {
151
+					$formElement->setExtra($var['form_extra']);
152
+				}
153
+			}
154
+			$controls = $this->targetObject->controls;
155
+			if (isset($controls[$key]['js'])) {
156
+				$formElement->customValidationCode[] = $controls[$key]['js'];
157
+			}
158
+			parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required);
159
+		} else {
160
+			parent::addElement($formElement, 'notset' === $required ? false : true);
161
+		}
162
+		unset($formElement);
163
+	}
164
+
165
+	public function createElements()
166
+	{
167
+		$controls = $this->targetObject->controls;
168
+		$vars     = $this->targetObject->vars;
169
+		foreach ($vars as $key => $var) {
170
+
171
+			// If $displayOnForm is false OR this is the primary key, it doesn't
172
+			// need to be displayed, then we only create an hidden field
173
+			if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
174
+				$elementToAdd = new \XoopsFormHidden($key, $var['value']);
175
+				$this->addElement($elementToAdd, $key, $var, false);
176
+				unset($elementToAdd);
177
+			// If not, the we need to create the proper form control for this fields
178
+			} else {
179
+				// If this field has a specific control, we will use it
180
+
181
+				if ('parentid' === $key) {
182
+					/**
183
+					 * Why this ?
184
+					 */
185
+				}
186
+				if (isset($controls[$key])) {
187
+					/* If the control has name, it's because it's an object already present in the script
188 188
                      * for example, "user"
189 189
                      * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect)
190 190
                      */
191
-                    if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
192
-                        $controls[$key]['name'] = 'select';
193
-                    }
194
-
195
-                    $form_select = $this->getControl($controls[$key]['name'], $key);
196
-
197
-                    // Adding on the form, the control for this field
198
-                    $this->addElement($form_select, $key, $var);
199
-                    unset($form_select);
200
-
201
-                // If this field don't have a specific control, we will use the standard one, depending on its data type
202
-                } else {
203
-                    switch ($var['data_type']) {
204
-
205
-                        case XOBJ_DTYPE_TXTBOX:
206
-
207
-                            $form_text = $this->getControl('text', $key);
208
-                            $this->addElement($form_text, $key, $var);
209
-                            unset($form_text);
210
-                            break;
211
-
212
-                        case XOBJ_DTYPE_INT:
213
-                            $this->targetObject->setControl($key, [
214
-                                'name' => 'text',
215
-                                'size' => '5'
216
-                            ]);
217
-                            $form_text = $this->getControl('text', $key);
218
-                            $this->addElement($form_text, $key, $var);
219
-                            unset($form_text);
220
-                            break;
221
-
222
-                        case XOBJ_DTYPE_FLOAT:
223
-                            $this->targetObject->setControl($key, [
224
-                                'name' => 'text',
225
-                                'size' => '5'
226
-                            ]);
227
-                            $form_text = $this->getControl('text', $key);
228
-                            $this->addElement($form_text, $key, $var);
229
-                            unset($form_text);
230
-                            break;
231
-
232
-                        case XOBJ_DTYPE_LTIME:
233
-                            $form_date_time = $this->getControl('date_time', $key);
234
-                            $this->addElement($form_date_time, $key, $var);
235
-                            unset($form_date_time);
236
-                            break;
237
-
238
-                        case XOBJ_DTYPE_STIME:
239
-                            $form_date_time = $this->getControl('date', $key);
240
-                            $this->addElement($form_date_time, $key, $var);
241
-                            unset($form_date_time);
242
-                            break;
243
-
244
-                        case XOBJ_DTYPE_TIME_ONLY:
245
-                            $form_time = $this->getControl('time', $key);
246
-                            $this->addElement($form_time, $key, $var);
247
-                            unset($form_time);
248
-                            break;
249
-
250
-                        case XOBJ_DTYPE_CURRENCY:
251
-                            $this->targetObject->setControl($key, [
252
-                                'name' => 'text',
253
-                                'size' => '15'
254
-                            ]);
255
-                            $form_currency = $this->getControl('text', $key);
256
-                            $this->addElement($form_currency, $key, $var);
257
-                            unset($form_currency);
258
-                            break;
259
-
260
-                        case XOBJ_DTYPE_URLLINK:
261
-                            $form_urllink = $this->getControl('urllink', $key);
262
-                            $this->addElement($form_urllink, $key, $var);
263
-                            unset($form_urllink);
264
-                            break;
265
-
266
-                        case XOBJ_DTYPE_FILE:
267
-                            $form_file = $this->getControl('richfile', $key);
268
-                            $this->addElement($form_file, $key, $var);
269
-                            unset($form_file);
270
-                            break;
271
-
272
-                        case XOBJ_DTYPE_TXTAREA:
273
-
274
-                            $form_text_area = $this->getTextArea($key, $var);
275
-                            $this->addElement($form_text_area, $key, $var);
276
-                            unset($form_text_area);
277
-                            break;
278
-
279
-                        case XOBJ_DTYPE_ARRAY:
280
-                            // TODO: To come...
281
-                            break;
282
-                        case XOBJ_DTYPE_SOURCE:
283
-                            // TODO: To come...
284
-                            break;
285
-                        case XOBJ_DTYPE_FORM_SECTION:
286
-                            $section_control = new SmartFormSection($key, $var['value']);
287
-                            $this->addElement($section_control, $key, $var);
288
-                            unset($section_control);
289
-                            break;
290
-                        case XOBJ_DTYPE_FORM_SECTION_CLOSE:
291
-                            $section_control = new SmartFormSectionClose($key, $var['value']);
292
-                            $this->addElement($section_control, $key, $var);
293
-                            unset($section_control);
294
-                            break;
295
-                    }
296
-                }
297
-            }
298
-        }
299
-        // Add an hidden field to store the URL of the page before this form
300
-        $this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm()));
301
-    }
302
-
303
-    public function createPermissionControls()
304
-    {
305
-        $smartModuleConfig = $this->targetObject->handler->getModuleConfig();
306
-
307
-        $permissions = $this->targetObject->handler->getPermissions();
308
-
309
-        if ($permissions) {
310
-            $memberHandler = xoops_getHandler('member');
311
-            $group_list    = $memberHandler->getGroupList();
312
-            asort($group_list);
313
-            foreach ($permissions as $permission) {
314
-                if ($this->targetObject->isNew()) {
315
-                    if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
316
-                        $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
317
-                    }
318
-                } else {
319
-                    $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
320
-                }
321
-                $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true);
322
-                $groups_select->setDescription($permission['description']);
323
-                $groups_select->addOptionArray($group_list);
324
-                $this->addElement($groups_select);
325
-                unset($groups_select);
326
-            }
327
-        }
328
-    }
329
-
330
-    /**
331
-     * @param      $form_name
332
-     * @param      $form_caption
333
-     * @param bool $submit_button_caption
334
-     */
335
-    public function createButtons($form_name, $form_caption, $submit_button_caption = false)
336
-    {
337
-        $button_tray = new \XoopsFormElementTray('', '');
338
-        $button_tray->addElement(new \XoopsFormHidden('op', $form_name));
339
-        if (!$submit_button_caption) {
340
-            if ($this->targetObject->isNew()) {
341
-                $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit');
342
-            } else {
343
-                $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit');
344
-            }
345
-        } else {
346
-            $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
347
-        }
348
-        $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
349
-        $button_tray->addElement($butt_create);
350
-
351
-        //creating custom buttons
352
-        if ($this->_custom_button) {
353
-            foreach ($this->_custom_button as $custom_button) {
354
-                $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
355
-                if ($custom_button['onclick']) {
356
-                    $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
357
-                }
358
-                $button_tray->addElement($butt_custom);
359
-                unset($butt_custom);
360
-            }
361
-        }
362
-
363
-        // creating the "cancel" button
364
-        $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
365
-        if ($this->_cancel_js_action) {
366
-            $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
367
-        } else {
368
-            $butt_cancel->setExtra('onclick="history.go(-1)"');
369
-        }
370
-        $button_tray->addElement($butt_cancel);
371
-
372
-        $this->addElement($button_tray);
373
-    }
374
-
375
-    /**
376
-     * @param $controlName
377
-     * @param $key
378
-     * @return \XoopsFormLabel
379
-     */
380
-    public function getControl($controlName, $key)
381
-    {
382
-        switch ($controlName) {
383
-            case 'check':
191
+					if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
192
+						$controls[$key]['name'] = 'select';
193
+					}
194
+
195
+					$form_select = $this->getControl($controls[$key]['name'], $key);
196
+
197
+					// Adding on the form, the control for this field
198
+					$this->addElement($form_select, $key, $var);
199
+					unset($form_select);
200
+
201
+				// If this field don't have a specific control, we will use the standard one, depending on its data type
202
+				} else {
203
+					switch ($var['data_type']) {
204
+
205
+						case XOBJ_DTYPE_TXTBOX:
206
+
207
+							$form_text = $this->getControl('text', $key);
208
+							$this->addElement($form_text, $key, $var);
209
+							unset($form_text);
210
+							break;
211
+
212
+						case XOBJ_DTYPE_INT:
213
+							$this->targetObject->setControl($key, [
214
+								'name' => 'text',
215
+								'size' => '5'
216
+							]);
217
+							$form_text = $this->getControl('text', $key);
218
+							$this->addElement($form_text, $key, $var);
219
+							unset($form_text);
220
+							break;
221
+
222
+						case XOBJ_DTYPE_FLOAT:
223
+							$this->targetObject->setControl($key, [
224
+								'name' => 'text',
225
+								'size' => '5'
226
+							]);
227
+							$form_text = $this->getControl('text', $key);
228
+							$this->addElement($form_text, $key, $var);
229
+							unset($form_text);
230
+							break;
231
+
232
+						case XOBJ_DTYPE_LTIME:
233
+							$form_date_time = $this->getControl('date_time', $key);
234
+							$this->addElement($form_date_time, $key, $var);
235
+							unset($form_date_time);
236
+							break;
237
+
238
+						case XOBJ_DTYPE_STIME:
239
+							$form_date_time = $this->getControl('date', $key);
240
+							$this->addElement($form_date_time, $key, $var);
241
+							unset($form_date_time);
242
+							break;
243
+
244
+						case XOBJ_DTYPE_TIME_ONLY:
245
+							$form_time = $this->getControl('time', $key);
246
+							$this->addElement($form_time, $key, $var);
247
+							unset($form_time);
248
+							break;
249
+
250
+						case XOBJ_DTYPE_CURRENCY:
251
+							$this->targetObject->setControl($key, [
252
+								'name' => 'text',
253
+								'size' => '15'
254
+							]);
255
+							$form_currency = $this->getControl('text', $key);
256
+							$this->addElement($form_currency, $key, $var);
257
+							unset($form_currency);
258
+							break;
259
+
260
+						case XOBJ_DTYPE_URLLINK:
261
+							$form_urllink = $this->getControl('urllink', $key);
262
+							$this->addElement($form_urllink, $key, $var);
263
+							unset($form_urllink);
264
+							break;
265
+
266
+						case XOBJ_DTYPE_FILE:
267
+							$form_file = $this->getControl('richfile', $key);
268
+							$this->addElement($form_file, $key, $var);
269
+							unset($form_file);
270
+							break;
271
+
272
+						case XOBJ_DTYPE_TXTAREA:
273
+
274
+							$form_text_area = $this->getTextArea($key, $var);
275
+							$this->addElement($form_text_area, $key, $var);
276
+							unset($form_text_area);
277
+							break;
278
+
279
+						case XOBJ_DTYPE_ARRAY:
280
+							// TODO: To come...
281
+							break;
282
+						case XOBJ_DTYPE_SOURCE:
283
+							// TODO: To come...
284
+							break;
285
+						case XOBJ_DTYPE_FORM_SECTION:
286
+							$section_control = new SmartFormSection($key, $var['value']);
287
+							$this->addElement($section_control, $key, $var);
288
+							unset($section_control);
289
+							break;
290
+						case XOBJ_DTYPE_FORM_SECTION_CLOSE:
291
+							$section_control = new SmartFormSectionClose($key, $var['value']);
292
+							$this->addElement($section_control, $key, $var);
293
+							unset($section_control);
294
+							break;
295
+					}
296
+				}
297
+			}
298
+		}
299
+		// Add an hidden field to store the URL of the page before this form
300
+		$this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm()));
301
+	}
302
+
303
+	public function createPermissionControls()
304
+	{
305
+		$smartModuleConfig = $this->targetObject->handler->getModuleConfig();
306
+
307
+		$permissions = $this->targetObject->handler->getPermissions();
308
+
309
+		if ($permissions) {
310
+			$memberHandler = xoops_getHandler('member');
311
+			$group_list    = $memberHandler->getGroupList();
312
+			asort($group_list);
313
+			foreach ($permissions as $permission) {
314
+				if ($this->targetObject->isNew()) {
315
+					if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
316
+						$groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
317
+					}
318
+				} else {
319
+					$groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
320
+				}
321
+				$groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true);
322
+				$groups_select->setDescription($permission['description']);
323
+				$groups_select->addOptionArray($group_list);
324
+				$this->addElement($groups_select);
325
+				unset($groups_select);
326
+			}
327
+		}
328
+	}
329
+
330
+	/**
331
+	 * @param      $form_name
332
+	 * @param      $form_caption
333
+	 * @param bool $submit_button_caption
334
+	 */
335
+	public function createButtons($form_name, $form_caption, $submit_button_caption = false)
336
+	{
337
+		$button_tray = new \XoopsFormElementTray('', '');
338
+		$button_tray->addElement(new \XoopsFormHidden('op', $form_name));
339
+		if (!$submit_button_caption) {
340
+			if ($this->targetObject->isNew()) {
341
+				$butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit');
342
+			} else {
343
+				$butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit');
344
+			}
345
+		} else {
346
+			$butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
347
+		}
348
+		$butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
349
+		$button_tray->addElement($butt_create);
350
+
351
+		//creating custom buttons
352
+		if ($this->_custom_button) {
353
+			foreach ($this->_custom_button as $custom_button) {
354
+				$butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
355
+				if ($custom_button['onclick']) {
356
+					$butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
357
+				}
358
+				$button_tray->addElement($butt_custom);
359
+				unset($butt_custom);
360
+			}
361
+		}
362
+
363
+		// creating the "cancel" button
364
+		$butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
365
+		if ($this->_cancel_js_action) {
366
+			$butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
367
+		} else {
368
+			$butt_cancel->setExtra('onclick="history.go(-1)"');
369
+		}
370
+		$button_tray->addElement($butt_cancel);
371
+
372
+		$this->addElement($button_tray);
373
+	}
374
+
375
+	/**
376
+	 * @param $controlName
377
+	 * @param $key
378
+	 * @return \XoopsFormLabel
379
+	 */
380
+	public function getControl($controlName, $key)
381
+	{
382
+		switch ($controlName) {
383
+			case 'check':
384 384
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php';
385
-                $control    = $this->targetObject->getControl($key);
386
-                $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
387
-                $controlObj->addOptionArray($control['options']);
385
+				$control    = $this->targetObject->getControl($key);
386
+				$controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
387
+				$controlObj->addOptionArray($control['options']);
388 388
 
389
-                return $controlObj;
390
-                break;
389
+				return $controlObj;
390
+				break;
391 391
 
392
-            case 'color':
393
-                $control    = $this->targetObject->getControl($key);
394
-                $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
392
+			case 'color':
393
+				$control    = $this->targetObject->getControl($key);
394
+				$controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
395 395
 
396
-                return $controlObj;
397
-                break;
396
+				return $controlObj;
397
+				break;
398 398
 
399
-            case 'radio':
400
-                $control = $this->targetObject->getControl($key);
399
+			case 'radio':
400
+				$control = $this->targetObject->getControl($key);
401 401
 
402
-                $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
403
-                $controlObj->addOptionArray($control['options']);
402
+				$controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
403
+				$controlObj->addOptionArray($control['options']);
404 404
 
405
-                return $controlObj;
406
-                break;
405
+				return $controlObj;
406
+				break;
407 407
 
408
-            case 'label':
409
-                return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
410
-                break;
408
+			case 'label':
409
+				return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
410
+				break;
411 411
 
412
-            case 'textarea':
413
-                return $this->getTextArea($key);
412
+			case 'textarea':
413
+				return $this->getTextArea($key);
414 414
 
415
-            case 'theme':
416
-                return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
415
+			case 'theme':
416
+				return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
417 417
 
418
-            case 'theme_multi':
419
-                return $this->getThemeSelect($key, $this->targetObject->vars[$key], true);
420
-                break;
418
+			case 'theme_multi':
419
+				return $this->getThemeSelect($key, $this->targetObject->vars[$key], true);
420
+				break;
421 421
 
422
-            case 'timezone':
423
-                return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
424
-                break;
422
+			case 'timezone':
423
+				return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
424
+				break;
425 425
 
426
-            case 'group':
427
-                return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
428
-                break;
426
+			case 'group':
427
+				return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
428
+				break;
429 429
 
430
-            case 'group_multi':
431
-                return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
432
-                break;
430
+			case 'group_multi':
431
+				return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
432
+				break;
433 433
 
434
-            /*case 'user':
434
+			/*case 'user':
435 435
              return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
436 436
              break;*/
437 437
 
438
-            case 'user_multi':
439
-                return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
440
-                break;
438
+			case 'user_multi':
439
+				return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
440
+				break;
441 441
 
442
-            case 'password':
443
-                return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
444
-                break;
442
+			case 'password':
443
+				return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
444
+				break;
445 445
 
446
-            case 'country':
447
-                return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
448
-                break;
446
+			case 'country':
447
+				return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
448
+				break;
449 449
 
450
-            case 'urllink':
450
+			case 'urllink':
451 451
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php';
452 452
 
453
-                return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
454
-                break;
453
+				return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
454
+				break;
455 455
 
456
-            case 'richfile':
456
+			case 'richfile':
457 457
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php';
458 458
 
459
-                return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
460
-                break;
461
-            case 'section':
459
+				return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
460
+				break;
461
+			case 'section':
462 462
 //                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php';
463 463
 
464
-                return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
465
-                break;
464
+				return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
465
+				break;
466 466
 
467
-            default:
468
-                $classname = 'SmartForm' . ucfirst($controlName) . 'Element';
469
-                if (!class_exists($classname)) {
470
-                    if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
467
+			default:
468
+				$classname = 'SmartForm' . ucfirst($controlName) . 'Element';
469
+				if (!class_exists($classname)) {
470
+					if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
471 471
 //                        require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php';
472
-                    } else {
473
-                        // perhaps this is a control created by the module
474
-                        $moduleName             = $this->targetObject->handler->_moduleName;
475
-                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
476
-                        $classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
477
-                        $classFileName          = strtolower($classname) . '.php';
478
-
479
-                        if (file_exists($moduleFormElementsPath . $classFileName)) {
472
+					} else {
473
+						// perhaps this is a control created by the module
474
+						$moduleName             = $this->targetObject->handler->_moduleName;
475
+						$moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
476
+						$classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
477
+						$classFileName          = strtolower($classname) . '.php';
478
+
479
+						if (file_exists($moduleFormElementsPath . $classFileName)) {
480 480
 //                            require_once $moduleFormElementsPath . $classFileName;
481
-                        } else {
482
-                            trigger_error($classname . ' Not found', E_USER_WARNING);
483
-
484
-                            return new \XoopsFormLabel(); //Empty object
485
-                        }
486
-                    }
487
-                }
488
-
489
-                return new $classname($this->targetObject, $key);
490
-                break;
491
-        }
492
-    }
493
-
494
-    /**
495
-     * @param $key
496
-     * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4
497
-     */
498
-    public function getTextArea($key)
499
-    {
500
-        $var = $this->targetObject->vars[$key];
501
-
502
-        // if no control has been created, let's create a default one
503
-        if (!isset($this->targetObject->controls[$key])) {
504
-            $control = [
505
-                'name'        => 'textarea',
506
-                'itemHandler' => false,
507
-                'method'      => false,
508
-                'module'      => false,
509
-                'form_editor' => 'default'
510
-            ];
511
-        } else {
512
-            $control = $this->targetObject->controls[$key];
513
-        }
514
-        $xoops22 = Smartobject\Utility::isXoops22();
515
-
516
-        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
517
-        /**
518
-         * If the editor is 'default', retreive the default editor of this module
519
-         */
520
-        if ('default' === $form_editor) {
521
-               /** @var Smartobject\Helper $helper */
522
-            $helper = Smartobject\Helper::getInstance();
523
-            $form_editor = null !== ($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea';
524
-        }
525
-
526
-        $caption = $var['form_caption'];
527
-        $name    = $key;
528
-
529
-        $value = $this->targetObject->getVar($key);
530
-
531
-        $value = $this->targetObject->getValueFor($key, true);
532
-
533
-        $editor_configs          = [];
534
-        $editor_configs['name']  = $name;
535
-        $editor_configs['value'] = $value;
536
-        if ('textarea' !== $form_editor) {
537
-            $editor_configs['rows'] = 35;
538
-            $editor_configs['cols'] = 60;
539
-        }
540
-
541
-        if (isset($control['rows'])) {
542
-            $editor_configs['rows'] = $control['rows'];
543
-        }
544
-        if (isset($control['cols'])) {
545
-            $editor_configs['cols'] = $control['cols'];
546
-        }
547
-
548
-        $editor_configs['width']  = '100%';
549
-        $editor_configs['height'] = '400px';
550
-
551
-        $dhtml            = true;
552
-        $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
553
-
554
-        if (file_exists($xoopseditorclass)) {
555
-            require_once $xoopseditorclass;
556
-            $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea');
557
-        } else {
558
-            switch ($form_editor) {
559
-
560
-                case 'tiny':
561
-                    if (!$xoops22) {
562
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
563
-                            require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php';
564
-                            $editor = new \XoopsFormTinymce([
565
-                                                                    'caption' => $caption,
566
-                                                                    'name'    => $name,
567
-                                                                    'value'   => $value,
568
-                                                                    'width'   => '100%',
569
-                                                                    'height'  => '300px'
570
-                                                                ], true);
571
-                        } else {
572
-                            if ($dhtml) {
573
-                                $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
574
-                            } else {
575
-                                $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60);
576
-                            }
577
-                        }
578
-                    } else {
579
-                        $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
580
-                    }
581
-                    break;
582
-
583
-                case 'dhtmltextarea':
584
-                case 'dhtmltext':
585
-                    $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60);
586
-                    if ($var['form_dsc']) {
587
-                        $editor->setDescription($var['form_dsc']);
588
-                    }
589
-                    break;
481
+						} else {
482
+							trigger_error($classname . ' Not found', E_USER_WARNING);
483
+
484
+							return new \XoopsFormLabel(); //Empty object
485
+						}
486
+					}
487
+				}
488
+
489
+				return new $classname($this->targetObject, $key);
490
+				break;
491
+		}
492
+	}
493
+
494
+	/**
495
+	 * @param $key
496
+	 * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4
497
+	 */
498
+	public function getTextArea($key)
499
+	{
500
+		$var = $this->targetObject->vars[$key];
501
+
502
+		// if no control has been created, let's create a default one
503
+		if (!isset($this->targetObject->controls[$key])) {
504
+			$control = [
505
+				'name'        => 'textarea',
506
+				'itemHandler' => false,
507
+				'method'      => false,
508
+				'module'      => false,
509
+				'form_editor' => 'default'
510
+			];
511
+		} else {
512
+			$control = $this->targetObject->controls[$key];
513
+		}
514
+		$xoops22 = Smartobject\Utility::isXoops22();
515
+
516
+		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
517
+		/**
518
+		 * If the editor is 'default', retreive the default editor of this module
519
+		 */
520
+		if ('default' === $form_editor) {
521
+			   /** @var Smartobject\Helper $helper */
522
+			$helper = Smartobject\Helper::getInstance();
523
+			$form_editor = null !== ($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea';
524
+		}
525
+
526
+		$caption = $var['form_caption'];
527
+		$name    = $key;
528
+
529
+		$value = $this->targetObject->getVar($key);
530
+
531
+		$value = $this->targetObject->getValueFor($key, true);
532
+
533
+		$editor_configs          = [];
534
+		$editor_configs['name']  = $name;
535
+		$editor_configs['value'] = $value;
536
+		if ('textarea' !== $form_editor) {
537
+			$editor_configs['rows'] = 35;
538
+			$editor_configs['cols'] = 60;
539
+		}
540
+
541
+		if (isset($control['rows'])) {
542
+			$editor_configs['rows'] = $control['rows'];
543
+		}
544
+		if (isset($control['cols'])) {
545
+			$editor_configs['cols'] = $control['cols'];
546
+		}
547
+
548
+		$editor_configs['width']  = '100%';
549
+		$editor_configs['height'] = '400px';
550
+
551
+		$dhtml            = true;
552
+		$xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
553
+
554
+		if (file_exists($xoopseditorclass)) {
555
+			require_once $xoopseditorclass;
556
+			$editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea');
557
+		} else {
558
+			switch ($form_editor) {
559
+
560
+				case 'tiny':
561
+					if (!$xoops22) {
562
+						if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
563
+							require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php';
564
+							$editor = new \XoopsFormTinymce([
565
+																	'caption' => $caption,
566
+																	'name'    => $name,
567
+																	'value'   => $value,
568
+																	'width'   => '100%',
569
+																	'height'  => '300px'
570
+																], true);
571
+						} else {
572
+							if ($dhtml) {
573
+								$editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
574
+							} else {
575
+								$editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60);
576
+							}
577
+						}
578
+					} else {
579
+						$editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
580
+					}
581
+					break;
582
+
583
+				case 'dhtmltextarea':
584
+				case 'dhtmltext':
585
+					$editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60);
586
+					if ($var['form_dsc']) {
587
+						$editor->setDescription($var['form_dsc']);
588
+					}
589
+					break;
590 590
 
591 591
 //                case 'inbetween':
592 592
 //                    if (!$xoops22) {
@@ -639,177 +639,177 @@  discard block
 block discarded – undo
639 639
 //                    }
640 640
 //                    break;
641 641
 
642
-                default:
643
-                case 'textarea':
644
-                    $form_rows = isset($control['rows']) ? $control['rows'] : 5;
645
-                    $form_cols = isset($control['cols']) ? $control['cols'] : 60;
646
-
647
-                    $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
648
-                    if ($var['form_dsc']) {
649
-                        $editor->setDescription($var['form_dsc']);
650
-                    }
651
-                    break;
652
-
653
-            }
654
-        }
655
-
656
-        return $editor;
657
-    }
658
-
659
-    /**
660
-     * @param                  $key
661
-     * @param                  $var
662
-     * @param  bool            $multiple
663
-     * @return \XoopsFormSelect
664
-     */
665
-    public function getThemeSelect($key, $var, $multiple = false)
666
-    {
667
-        $size         = $multiple ? 5 : 1;
668
-        $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
669
-
670
-        $handle  = opendir(XOOPS_THEME_PATH . '/');
671
-        $dirlist = [];
672
-        while (false !== ($file = readdir($handle))) {
673
-            if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file)
674
-                && 'cvs' !== strtolower($file)) {
675
-                $dirlist[$file] = $file;
676
-            }
677
-        }
678
-        closedir($handle);
679
-        if (!empty($dirlist)) {
680
-            asort($dirlist);
681
-            $theme_select->addOptionArray($dirlist);
682
-        }
683
-
684
-        return $theme_select;
685
-    }
686
-
687
-    /**
688
-     * @param $keyname
689
-     * @return bool
690
-     */
691
-    public function &getElementById($keyname)
692
-    {
693
-        foreach ($this->_elements as $eleObj) {
694
-            if ($eleObj->getName() == $keyname) {
695
-                $ret =& $eleObj;
696
-                break;
697
-            }
698
-        }
699
-
700
-        return isset($ret) ? $ret : false;
701
-    }
702
-
703
-    /**
704
-     * create HTML to output the form as a theme-enabled table with validation.
705
-     *
706
-     * @return string
707
-     */
708
-    public function render()
709
-    {
710
-        $required = $this->getRequired();
711
-        $ret      = "
642
+				default:
643
+				case 'textarea':
644
+					$form_rows = isset($control['rows']) ? $control['rows'] : 5;
645
+					$form_cols = isset($control['cols']) ? $control['cols'] : 60;
646
+
647
+					$editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
648
+					if ($var['form_dsc']) {
649
+						$editor->setDescription($var['form_dsc']);
650
+					}
651
+					break;
652
+
653
+			}
654
+		}
655
+
656
+		return $editor;
657
+	}
658
+
659
+	/**
660
+	 * @param                  $key
661
+	 * @param                  $var
662
+	 * @param  bool            $multiple
663
+	 * @return \XoopsFormSelect
664
+	 */
665
+	public function getThemeSelect($key, $var, $multiple = false)
666
+	{
667
+		$size         = $multiple ? 5 : 1;
668
+		$theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
669
+
670
+		$handle  = opendir(XOOPS_THEME_PATH . '/');
671
+		$dirlist = [];
672
+		while (false !== ($file = readdir($handle))) {
673
+			if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file)
674
+				&& 'cvs' !== strtolower($file)) {
675
+				$dirlist[$file] = $file;
676
+			}
677
+		}
678
+		closedir($handle);
679
+		if (!empty($dirlist)) {
680
+			asort($dirlist);
681
+			$theme_select->addOptionArray($dirlist);
682
+		}
683
+
684
+		return $theme_select;
685
+	}
686
+
687
+	/**
688
+	 * @param $keyname
689
+	 * @return bool
690
+	 */
691
+	public function &getElementById($keyname)
692
+	{
693
+		foreach ($this->_elements as $eleObj) {
694
+			if ($eleObj->getName() == $keyname) {
695
+				$ret =& $eleObj;
696
+				break;
697
+			}
698
+		}
699
+
700
+		return isset($ret) ? $ret : false;
701
+	}
702
+
703
+	/**
704
+	 * create HTML to output the form as a theme-enabled table with validation.
705
+	 *
706
+	 * @return string
707
+	 */
708
+	public function render()
709
+	{
710
+		$required = $this->getRequired();
711
+		$ret      = "
712 712
             <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . ">
713 713
             <table width='100%' class='outer' cellspacing='1'>
714 714
             <tr><th colspan='2'>" . $this->getTitle() . '</th></tr>
715 715
         ';
716
-        $hidden   = '';
717
-        $class    = 'even';
718
-        foreach ($this->getElements() as $ele) {
719
-            if (!is_object($ele)) {
720
-                $ret .= $ele;
721
-            } elseif (!$ele->isHidden()) {
722
-                //$class = ( $class == 'even' ) ? 'odd': 'even';
723
-                $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
724
-                if ('' !== $ele->getDescription()) {
725
-                    $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
726
-                }
727
-                $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
728
-            } else {
729
-                $hidden .= $ele->render();
730
-            }
731
-        }
732
-        $ret .= "</table>\n$hidden\n</form>\n";
733
-        $ret .= $this->renderValidationJS(true);
734
-
735
-        return $ret;
736
-    }
737
-
738
-    /**
739
-     * assign to smarty form template instead of displaying directly
740
-     *
741
-     * @param \XoopsTpl $tpl
742
-     *
743
-     * object
744
-     * @param bool      $smartyName
745
-     * @see     Smarty
746
-     */
747
-    public function assign(\XoopsTpl $tpl, $smartyName = false)
748
-    {
749
-        $i        = 0;
750
-        $elements = [];
751
-        foreach ($this->getElements() as $ele) {
752
-            $n                             = ('' !== $ele->getName()) ? $ele->getName() : $i;
753
-            $elements[$n]['name']          = $ele->getName();
754
-            $elements[$n]['caption']       = $ele->getCaption();
755
-            $elements[$n]['body']          = $ele->render();
756
-            $elements[$n]['hidden']        = $ele->isHidden();
757
-            $elements[$n]['section']       = strtolower(get_class($ele)) == strtolower('SmartFormSection');
758
-            $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose;
759
-            $elements[$n]['hide']          = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false;
760
-            if ('' !== $ele->getDescription()) {
761
-                $elements[$n]['description'] = $ele->getDescription();
762
-            }
763
-            ++$i;
764
-        }
765
-        $js = $this->renderValidationJS();
766
-        if (!$smartyName) {
767
-            $smartyName = $this->getName();
768
-        }
769
-
770
-        $tpl->assign($smartyName, [
771
-            'title'      => $this->getTitle(),
772
-            'name'       => $this->getName(),
773
-            'action'     => $this->getAction(),
774
-            'method'     => $this->getMethod(),
775
-            'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
776
-            'javascript' => $js,
777
-            'elements'   => $elements
778
-        ]);
779
-    }
780
-
781
-    /**
782
-     * @param  bool $withtags
783
-     * @return string
784
-     */
785
-    public function renderValidationJS($withtags = true)
786
-    {
787
-        $js = '';
788
-        if ($withtags) {
789
-            $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
790
-        }
791
-        $myts     = \MyTextSanitizer::getInstance();
792
-        $formname = $this->getName();
793
-        $js       .= "function xoopsFormValidate_{$formname}(myform) {";
794
-        // First, output code to check required elements
795
-        $elements = $this->getRequired();
796
-        foreach ($elements as $elt) {
797
-            $eltname    = $elt->getName();
798
-            $eltcaption = trim($elt->getCaption());
799
-            $eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
800
-            $eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
801
-            if ('xoopsformradio' === strtolower(get_class($elt))) {
802
-                $js .= 'var myOption = -1;';
803
-                $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
716
+		$hidden   = '';
717
+		$class    = 'even';
718
+		foreach ($this->getElements() as $ele) {
719
+			if (!is_object($ele)) {
720
+				$ret .= $ele;
721
+			} elseif (!$ele->isHidden()) {
722
+				//$class = ( $class == 'even' ) ? 'odd': 'even';
723
+				$ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
724
+				if ('' !== $ele->getDescription()) {
725
+					$ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
726
+				}
727
+				$ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
728
+			} else {
729
+				$hidden .= $ele->render();
730
+			}
731
+		}
732
+		$ret .= "</table>\n$hidden\n</form>\n";
733
+		$ret .= $this->renderValidationJS(true);
734
+
735
+		return $ret;
736
+	}
737
+
738
+	/**
739
+	 * assign to smarty form template instead of displaying directly
740
+	 *
741
+	 * @param \XoopsTpl $tpl
742
+	 *
743
+	 * object
744
+	 * @param bool      $smartyName
745
+	 * @see     Smarty
746
+	 */
747
+	public function assign(\XoopsTpl $tpl, $smartyName = false)
748
+	{
749
+		$i        = 0;
750
+		$elements = [];
751
+		foreach ($this->getElements() as $ele) {
752
+			$n                             = ('' !== $ele->getName()) ? $ele->getName() : $i;
753
+			$elements[$n]['name']          = $ele->getName();
754
+			$elements[$n]['caption']       = $ele->getCaption();
755
+			$elements[$n]['body']          = $ele->render();
756
+			$elements[$n]['hidden']        = $ele->isHidden();
757
+			$elements[$n]['section']       = strtolower(get_class($ele)) == strtolower('SmartFormSection');
758
+			$elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose;
759
+			$elements[$n]['hide']          = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false;
760
+			if ('' !== $ele->getDescription()) {
761
+				$elements[$n]['description'] = $ele->getDescription();
762
+			}
763
+			++$i;
764
+		}
765
+		$js = $this->renderValidationJS();
766
+		if (!$smartyName) {
767
+			$smartyName = $this->getName();
768
+		}
769
+
770
+		$tpl->assign($smartyName, [
771
+			'title'      => $this->getTitle(),
772
+			'name'       => $this->getName(),
773
+			'action'     => $this->getAction(),
774
+			'method'     => $this->getMethod(),
775
+			'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
776
+			'javascript' => $js,
777
+			'elements'   => $elements
778
+		]);
779
+	}
780
+
781
+	/**
782
+	 * @param  bool $withtags
783
+	 * @return string
784
+	 */
785
+	public function renderValidationJS($withtags = true)
786
+	{
787
+		$js = '';
788
+		if ($withtags) {
789
+			$js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
790
+		}
791
+		$myts     = \MyTextSanitizer::getInstance();
792
+		$formname = $this->getName();
793
+		$js       .= "function xoopsFormValidate_{$formname}(myform) {";
794
+		// First, output code to check required elements
795
+		$elements = $this->getRequired();
796
+		foreach ($elements as $elt) {
797
+			$eltname    = $elt->getName();
798
+			$eltcaption = trim($elt->getCaption());
799
+			$eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
800
+			$eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
801
+			if ('xoopsformradio' === strtolower(get_class($elt))) {
802
+				$js .= 'var myOption = -1;';
803
+				$js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
804 804
                     if (myform.{$eltname}[i].checked) {
805 805
                         myOption = i; i = -1;
806 806
                     }
807 807
                 }
808 808
                 if (myOption == -1) {
809 809
                     window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n";
810
-            } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) {
811
-                $js .= 'var hasSelections = false;';
812
-                $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
810
+			} elseif ('smartformselect_multielement' === strtolower(get_class($elt))) {
811
+				$js .= 'var hasSelections = false;';
812
+				$js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
813 813
                     if (myform['{$eltname}[]'].options[i].selected) {
814 814
                         hasSelections = true;
815 815
                     }
@@ -817,12 +817,12 @@  discard block
 block discarded – undo
817 817
                 }
818 818
                 if (hasSelections === false) {
819 819
                     window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n";
820
-            } elseif ('xoopsformcheckbox' === strtolower(get_class($elt))
821
-                      || 'smartformcheckelement' === strtolower(get_class($elt))) {
822
-                $js .= 'var hasSelections = false;';
823
-                //sometimes, there is an implicit '[]', sometimes not
824
-                if (false === strpos($eltname, '[')) {
825
-                    $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
820
+			} elseif ('xoopsformcheckbox' === strtolower(get_class($elt))
821
+					  || 'smartformcheckelement' === strtolower(get_class($elt))) {
822
+				$js .= 'var hasSelections = false;';
823
+				//sometimes, there is an implicit '[]', sometimes not
824
+				if (false === strpos($eltname, '[')) {
825
+					$js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
826 826
                         if (myform['{$eltname}[]'][i].checked) {
827 827
                             hasSelections = true;
828 828
                         }
@@ -830,8 +830,8 @@  discard block
 block discarded – undo
830 830
                     }
831 831
                     if (hasSelections === false) {
832 832
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n";
833
-                } else {
834
-                    $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
833
+				} else {
834
+					$js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
835 835
                         if (myform['{$eltname}'][i].checked) {
836 836
                             hasSelections = true;
837 837
                         }
@@ -839,25 +839,25 @@  discard block
 block discarded – undo
839 839
                     }
840 840
                     if (hasSelections === false) {
841 841
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
842
-                }
843
-            } else {
844
-                $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
845
-            }
846
-        }
847
-        // Now, handle custom validation code
848
-        $elements =& $this->getElements(true);
849
-        foreach ($elements as $elt) {
850
-            if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) {
851
-                if ($eltjs = $elt->renderValidationJS()) {
852
-                    $js .= $eltjs . "\n";
853
-                }
854
-            }
855
-        }
856
-        $js .= "return true;\n}\n";
857
-        if ($withtags) {
858
-            $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n";
859
-        }
860
-
861
-        return $js;
862
-    }
842
+				}
843
+			} else {
844
+				$js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
845
+			}
846
+		}
847
+		// Now, handle custom validation code
848
+		$elements =& $this->getElements(true);
849
+		foreach ($elements as $elt) {
850
+			if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) {
851
+				if ($eltjs = $elt->renderValidationJS()) {
852
+					$js .= $eltjs . "\n";
853
+				}
854
+			}
855
+		}
856
+		$js .= "return true;\n}\n";
857
+		if ($withtags) {
858
+			$js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n";
859
+		}
860
+
861
+		return $js;
862
+	}
863 863
 }
Please login to merge, or discard this patch.
class/Utility.php 1 patch
Indentation   +1241 added lines, -1241 removed lines patch added patch discarded remove patch
@@ -9,186 +9,186 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class Utility
11 11
 {
12
-    use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits
13
-
14
-    use Common\ServerStats; // getServerStats Trait
15
-
16
-    use Common\FilesManagement; // Files Management Trait
17
-
18
-    //--------------- Custom module methods -----------------------------
19
-
20
-
21
-
22
-    /**
23
-     * @param $cssfile
24
-     * @return string
25
-     */
26
-    public static function getCssLink($cssfile)
27
-    {
28
-        $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">';
29
-
30
-        return $ret;
31
-    }
32
-
33
-    /**
34
-     * @return string
35
-     */
36
-    public static function getPageBeforeForm()
37
-    {
38
-        global $smart_previous_page;
39
-
40
-        return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page;
41
-    }
42
-
43
-    /**
44
-     * Checks if a user is admin of $module
45
-     *
46
-     * @param  bool $module
47
-     * @return bool: true if user is admin
48
-     */
49
-    public static function userIsAdmin($module = false)
50
-    {
51
-        global $xoopsUser;
52
-        static $smart_isAdmin;
53
-        if (!$module) {
54
-            global $xoopsModule;
55
-            $module = $xoopsModule->getVar('dirname');
56
-        }
57
-        if (isset($smart_isAdmin[$module])) {
58
-            return $smart_isAdmin[$module];
59
-        }
60
-        if (!$xoopsUser) {
61
-            $smart_isAdmin[$module] = false;
62
-
63
-            return $smart_isAdmin[$module];
64
-        }
65
-        $smart_isAdmin[$module] = false;
66
-        $smartModule            = static::getModuleInfo($module);
67
-        if (!is_object($smartModule)) {
68
-            return false;
69
-        }
70
-        $module_id              = $smartModule->getVar('mid');
71
-        $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id);
72
-
73
-        return $smart_isAdmin[$module];
74
-    }
75
-
76
-    /**
77
-     * @return bool
78
-     */
79
-    public static function isXoops22()
80
-    {
81
-        $xoops22 = false;
82
-        $xv      = str_replace('XOOPS ', '', XOOPS_VERSION);
83
-        if ('2' == substr($xv, 2, 1)) {
84
-            $xoops22 = true;
85
-        }
86
-
87
-        return $xoops22;
88
-    }
89
-
90
-    /**
91
-     * @param  bool $withLink
92
-     * @param  bool $forBreadCrumb
93
-     * @param  bool $moduleName
94
-     * @return string
95
-     */
96
-    public static function getModuleName($withLink = true, $forBreadCrumb = false, $moduleName = false)
97
-    {
98
-        if (!$moduleName) {
99
-            global $xoopsModule;
100
-            $moduleName = $xoopsModule->getVar('dirname');
101
-        }
102
-        $smartModule       = static::getModuleInfo($moduleName);
103
-        $smartModuleConfig = static::getModuleConfig($moduleName);
104
-        if (!isset($smartModule)) {
105
-            return '';
106
-        }
107
-
108
-        if ($forBreadCrumb
109
-            && (isset($smartModuleConfig['show_mod_name_breadcrumb'])
110
-                && !$smartModuleConfig['show_mod_name_breadcrumb'])) {
111
-            return '';
112
-        }
113
-        if (!$withLink) {
114
-            return $smartModule->getVar('name');
115
-        } else {
116
-            $seoMode = static::getModuleModeSEO($moduleName);
117
-            if ('rewrite' === $seoMode) {
118
-                $seoModuleName = static::getModuleNameForSEO($moduleName);
119
-                $ret           = XOOPS_URL . '/' . $seoModuleName . '/';
120
-            } elseif ('pathinfo' === $seoMode) {
121
-                $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
122
-            } else {
123
-                $ret = XOOPS_URL . '/modules/' . $moduleName . '/';
124
-            }
125
-
126
-            return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
127
-        }
128
-    }
129
-
130
-    /**
131
-     * @param  bool $moduleName
132
-     * @return string
133
-     */
134
-    public static function getModuleNameForSEO($moduleName = false)
135
-    {
136
-        $smartModule       = static::getModuleInfo($moduleName);
137
-        $smartModuleConfig = static::getModuleConfig($moduleName);
138
-        if (isset($smartModuleConfig['seo_module_name'])) {
139
-            return $smartModuleConfig['seo_module_name'];
140
-        }
141
-        $ret = static::getModuleName(false, false, $moduleName);
142
-
143
-        return strtolower($ret);
144
-    }
145
-
146
-    /**
147
-     * @param  bool $moduleName
148
-     * @return bool
149
-     */
150
-    public static function getModuleModeSEO($moduleName = false)
151
-    {
152
-        $smartModule       = static::getModuleInfo($moduleName);
153
-        $smartModuleConfig = static::getModuleConfig($moduleName);
154
-
155
-        return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false;
156
-    }
157
-
158
-    /**
159
-     * @param  bool $moduleName
160
-     * @return bool
161
-     */
162
-    public static function getModuleIncludeIdSEO($moduleName = false)
163
-    {
164
-        $smartModule       = static::getModuleInfo($moduleName);
165
-        $smartModuleConfig = static::getModuleConfig($moduleName);
166
-
167
-        return !empty($smartModuleConfig['seo_inc_id']);
168
-    }
169
-
170
-    /**
171
-     * @param $key
172
-     * @return string
173
-     */
174
-    public static function getEnv($key)
175
-    {
176
-        $ret = '';
177
-        $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : '');
178
-
179
-        return $ret;
180
-    }
181
-
182
-    public static function getXoopsCpHeader()
183
-    {
184
-        xoops_cp_header();
185
-        global $xoopsModule, $xoopsConfig;
186
-        /**
187
-         * include SmartObject admin language file
188
-         */
189
-        /** @var Smartobject\Helper $helper */
190
-        $helper = Smartobject\Helper::getInstance();
191
-        $helper->loadLanguage('admin'); ?>
12
+	use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits
13
+
14
+	use Common\ServerStats; // getServerStats Trait
15
+
16
+	use Common\FilesManagement; // Files Management Trait
17
+
18
+	//--------------- Custom module methods -----------------------------
19
+
20
+
21
+
22
+	/**
23
+	 * @param $cssfile
24
+	 * @return string
25
+	 */
26
+	public static function getCssLink($cssfile)
27
+	{
28
+		$ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">';
29
+
30
+		return $ret;
31
+	}
32
+
33
+	/**
34
+	 * @return string
35
+	 */
36
+	public static function getPageBeforeForm()
37
+	{
38
+		global $smart_previous_page;
39
+
40
+		return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page;
41
+	}
42
+
43
+	/**
44
+	 * Checks if a user is admin of $module
45
+	 *
46
+	 * @param  bool $module
47
+	 * @return bool: true if user is admin
48
+	 */
49
+	public static function userIsAdmin($module = false)
50
+	{
51
+		global $xoopsUser;
52
+		static $smart_isAdmin;
53
+		if (!$module) {
54
+			global $xoopsModule;
55
+			$module = $xoopsModule->getVar('dirname');
56
+		}
57
+		if (isset($smart_isAdmin[$module])) {
58
+			return $smart_isAdmin[$module];
59
+		}
60
+		if (!$xoopsUser) {
61
+			$smart_isAdmin[$module] = false;
62
+
63
+			return $smart_isAdmin[$module];
64
+		}
65
+		$smart_isAdmin[$module] = false;
66
+		$smartModule            = static::getModuleInfo($module);
67
+		if (!is_object($smartModule)) {
68
+			return false;
69
+		}
70
+		$module_id              = $smartModule->getVar('mid');
71
+		$smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id);
72
+
73
+		return $smart_isAdmin[$module];
74
+	}
75
+
76
+	/**
77
+	 * @return bool
78
+	 */
79
+	public static function isXoops22()
80
+	{
81
+		$xoops22 = false;
82
+		$xv      = str_replace('XOOPS ', '', XOOPS_VERSION);
83
+		if ('2' == substr($xv, 2, 1)) {
84
+			$xoops22 = true;
85
+		}
86
+
87
+		return $xoops22;
88
+	}
89
+
90
+	/**
91
+	 * @param  bool $withLink
92
+	 * @param  bool $forBreadCrumb
93
+	 * @param  bool $moduleName
94
+	 * @return string
95
+	 */
96
+	public static function getModuleName($withLink = true, $forBreadCrumb = false, $moduleName = false)
97
+	{
98
+		if (!$moduleName) {
99
+			global $xoopsModule;
100
+			$moduleName = $xoopsModule->getVar('dirname');
101
+		}
102
+		$smartModule       = static::getModuleInfo($moduleName);
103
+		$smartModuleConfig = static::getModuleConfig($moduleName);
104
+		if (!isset($smartModule)) {
105
+			return '';
106
+		}
107
+
108
+		if ($forBreadCrumb
109
+			&& (isset($smartModuleConfig['show_mod_name_breadcrumb'])
110
+				&& !$smartModuleConfig['show_mod_name_breadcrumb'])) {
111
+			return '';
112
+		}
113
+		if (!$withLink) {
114
+			return $smartModule->getVar('name');
115
+		} else {
116
+			$seoMode = static::getModuleModeSEO($moduleName);
117
+			if ('rewrite' === $seoMode) {
118
+				$seoModuleName = static::getModuleNameForSEO($moduleName);
119
+				$ret           = XOOPS_URL . '/' . $seoModuleName . '/';
120
+			} elseif ('pathinfo' === $seoMode) {
121
+				$ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
122
+			} else {
123
+				$ret = XOOPS_URL . '/modules/' . $moduleName . '/';
124
+			}
125
+
126
+			return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
127
+		}
128
+	}
129
+
130
+	/**
131
+	 * @param  bool $moduleName
132
+	 * @return string
133
+	 */
134
+	public static function getModuleNameForSEO($moduleName = false)
135
+	{
136
+		$smartModule       = static::getModuleInfo($moduleName);
137
+		$smartModuleConfig = static::getModuleConfig($moduleName);
138
+		if (isset($smartModuleConfig['seo_module_name'])) {
139
+			return $smartModuleConfig['seo_module_name'];
140
+		}
141
+		$ret = static::getModuleName(false, false, $moduleName);
142
+
143
+		return strtolower($ret);
144
+	}
145
+
146
+	/**
147
+	 * @param  bool $moduleName
148
+	 * @return bool
149
+	 */
150
+	public static function getModuleModeSEO($moduleName = false)
151
+	{
152
+		$smartModule       = static::getModuleInfo($moduleName);
153
+		$smartModuleConfig = static::getModuleConfig($moduleName);
154
+
155
+		return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false;
156
+	}
157
+
158
+	/**
159
+	 * @param  bool $moduleName
160
+	 * @return bool
161
+	 */
162
+	public static function getModuleIncludeIdSEO($moduleName = false)
163
+	{
164
+		$smartModule       = static::getModuleInfo($moduleName);
165
+		$smartModuleConfig = static::getModuleConfig($moduleName);
166
+
167
+		return !empty($smartModuleConfig['seo_inc_id']);
168
+	}
169
+
170
+	/**
171
+	 * @param $key
172
+	 * @return string
173
+	 */
174
+	public static function getEnv($key)
175
+	{
176
+		$ret = '';
177
+		$ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : '');
178
+
179
+		return $ret;
180
+	}
181
+
182
+	public static function getXoopsCpHeader()
183
+	{
184
+		xoops_cp_header();
185
+		global $xoopsModule, $xoopsConfig;
186
+		/**
187
+		 * include SmartObject admin language file
188
+		 */
189
+		/** @var Smartobject\Helper $helper */
190
+		$helper = Smartobject\Helper::getInstance();
191
+		$helper->loadLanguage('admin'); ?>
192 192
 
193 193
         <script type='text/javascript'>
194 194
             <!--
@@ -202,504 +202,504 @@  discard block
 block discarded – undo
202 202
             src='<?php echo SMARTOBJECT_URL ?>include/smart.js'></script>
203 203
         <?php
204 204
 
205
-        /**
206
-         * Include the admin language constants for the SmartObject Framework
207
-         */
208
-        /** @var Smartobject\Helper $helper */
209
-        $helper = Smartobject\Helper::getInstance();
210
-        $helper->loadLanguage('admin');
211
-    }
212
-
213
-    /**
214
-     * Detemines if a table exists in the current db
215
-     *
216
-     * @param  string $table the table name (without XOOPS prefix)
217
-     * @return bool   True if table exists, false if not
218
-     *
219
-     * @access public
220
-     * @author xhelp development team
221
-     */
222
-    public static function isTable($table)
223
-    {
224
-        $bRetVal = false;
225
-        //Verifies that a MySQL table exists
226
-        $xoopsDB  = \XoopsDatabaseFactory::getDatabaseConnection();
227
-        $realname = $xoopsDB->prefix($table);
228
-        $sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
229
-        $ret      = $xoopsDB->queryF($sql);
230
-        while (false !== (list($m_table) = $xoopsDB->fetchRow($ret))) {
231
-            if ($m_table == $realname) {
232
-                $bRetVal = true;
233
-                break;
234
-            }
235
-        }
236
-        $xoopsDB->freeRecordSet($ret);
237
-
238
-        return $bRetVal;
239
-    }
240
-
241
-    /**
242
-     * Gets a value from a key in the xhelp_meta table
243
-     *
244
-     * @param  string $key
245
-     * @param  bool   $moduleName
246
-     * @return string $value
247
-     *
248
-     * @access public
249
-     * @author xhelp development team
250
-     */
251
-    public static function getMeta($key, $moduleName = false)
252
-    {
253
-        if (!$moduleName) {
254
-            $moduleName = static::getCurrentModuleName();
255
-        }
256
-        $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
257
-        $sql     = sprintf('SELECT metavalue FROM `%s` WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
258
-        $ret     = $xoopsDB->query($sql);
259
-        if (!$ret) {
260
-            $value = false;
261
-        } else {
262
-            list($value) = $xoopsDB->fetchRow($ret);
263
-        }
264
-
265
-        return $value;
266
-    }
267
-
268
-    /**
269
-     * @return bool
270
-     */
271
-    public static function getCurrentModuleName()
272
-    {
273
-        global $xoopsModule;
274
-        if (is_object($xoopsModule)) {
275
-            return $xoopsModule->getVar('dirname');
276
-        } else {
277
-            return false;
278
-        }
279
-    }
280
-
281
-    /**
282
-     * Sets a value for a key in the xhelp_meta table
283
-     *
284
-     * @param  string $key
285
-     * @param  string $value
286
-     * @param  bool   $moduleName
287
-     * @return bool   TRUE if success, FALSE if failure
288
-     *
289
-     * @access public
290
-     * @author xhelp development team
291
-     */
292
-    public static function setMeta($key, $value, $moduleName = false)
293
-    {
294
-        if (!$moduleName) {
295
-            $moduleName = static::getCurrentModuleName();
296
-        }
297
-        $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
298
-        $ret     = static::getMeta($key, $moduleName);
299
-        if ('0' === $ret || $ret > 0) {
300
-            $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
301
-        } else {
302
-            $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
303
-        }
304
-        $ret = $xoopsDB->queryF($sql);
305
-        if (!$ret) {
306
-            return false;
307
-        }
308
-
309
-        return true;
310
-    }
311
-
312
-    // Thanks to Mithrandir:-)
313
-    /**
314
-     * @param         $str
315
-     * @param         $start
316
-     * @param         $length
317
-     * @param  string $trimmarker
318
-     * @return string
319
-     */
320
-    public static function getSubstr($str, $start, $length, $trimmarker = '...')
321
-    {
322
-        // if the string is empty, let's get out ;-)
323
-        if ('' === $str) {
324
-            return $str;
325
-        }
326
-        // reverse a string that is shortened with '' as trimmarker
327
-        $reversed_string = strrev(xoops_substr($str, $start, $length, ''));
328
-        // find first space in reversed string
329
-        $position_of_space = strpos($reversed_string, ' ', 0);
330
-        // truncate the original string to a length of $length
331
-        // minus the position of the last space
332
-        // plus the length of the $trimmarker
333
-        $truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker);
334
-
335
-        return $truncated_string;
336
-    }
337
-
338
-    /**
339
-     * @param              $key
340
-     * @param  bool        $moduleName
341
-     * @param  string      $default
342
-     * @return null|string
343
-     */
344
-    public static function getConfig($key, $moduleName = false, $default = 'default_is_undefined')
345
-    {
346
-        if (!$moduleName) {
347
-            $moduleName = static::getCurrentModuleName();
348
-        }
349
-        $configs = static::getModuleConfig($moduleName);
350
-        if (isset($configs[$key])) {
351
-            return $configs[$key];
352
-        } else {
353
-            if ('default_is_undefined' === $default) {
354
-                return null;
355
-            } else {
356
-                return $default;
357
-            }
358
-        }
359
-    }
360
-
361
-    /**
362
-     * Copy a file, or a folder and its contents
363
-     *
364
-     * @author      Aidan Lister <[email protected]>
365
-     * @param  string $source The source
366
-     * @param  string $dest   The destination
367
-     * @return bool   Returns true on success, false on failure
368
-     */
369
-    public static function copyr($source, $dest)
370
-    {
371
-        // Simple copy for a file
372
-        if (is_file($source)) {
373
-            return copy($source, $dest);
374
-        }
375
-        // Make destination directory
376
-        if (!is_dir($dest)) {
377
-            mkdir($dest);
378
-        }
379
-        // Loop through the folder
380
-        $dir = dir($source);
381
-        while (false !== $entry = $dir->read()) {
382
-            // Skip pointers
383
-            if ('.' === $entry || '..' === $entry) {
384
-                continue;
385
-            }
386
-            // Deep copy directories
387
-            if (is_dir("$source/$entry") && ("$source/$entry" !== $dest)) {
388
-                static::copyr("$source/$entry", "$dest/$entry");
389
-            } else {
390
-                copy("$source/$entry", "$dest/$entry");
391
-            }
392
-        }
393
-        // Clean up
394
-        $dir->close();
395
-
396
-        return true;
397
-    }
398
-
399
-    /**
400
-     * Thanks to the NewBB2 Development Team
401
-     * @param $target
402
-     * @return bool
403
-     */
404
-    public static function mkdirAsAdmin($target)
405
-    {
406
-        // http://www.php.net/manual/en/function.mkdir.php
407
-        // saint at corenova.com
408
-        // bart at cdasites dot com
409
-        if (is_dir($target) || empty($target)) {
410
-            return true; // best case check first
411
-        }
412
-        if (file_exists($target) && !is_dir($target)) {
413
-            return false;
414
-        }
415
-        if (static::mkdirAsAdmin(substr($target, 0, strrpos($target, '/')))) {
416
-            if (!file_exists($target)) {
417
-                $res = mkdir($target, 0777); // crawl back up & create dir tree
418
-                static::chmodAsAdmin($target);
419
-
420
-                return $res;
421
-            }
422
-        }
423
-        $res = is_dir($target);
424
-
425
-        return $res;
426
-    }
427
-
428
-    /**
429
-     * Thanks to the NewBB2 Development Team
430
-     * @param       $target
431
-     * @param  int  $mode
432
-     * @return bool
433
-     */
434
-    public static function chmodAsAdmin($target, $mode = 0777)
435
-    {
436
-        return @ chmod($target, $mode);
437
-    }
438
-
439
-    /**
440
-     * @param $src
441
-     * @param $maxWidth
442
-     * @param $maxHeight
443
-     * @return array
444
-     */
445
-    public static function imageResize($src, $maxWidth, $maxHeight)
446
-    {
447
-        $width  = '';
448
-        $height = '';
449
-        $type   = '';
450
-        $attr   = '';
451
-        if (file_exists($src)) {
452
-            list($width, $height, $type, $attr) = getimagesize($src);
453
-            if ($width > $maxWidth) {
454
-                $originalWidth = $width;
455
-                $width         = $maxWidth;
456
-                $height        = $width * $height / $originalWidth;
457
-            }
458
-            if ($height > $maxHeight) {
459
-                $originalHeight = $height;
460
-                $height         = $maxHeight;
461
-                $width          = $height * $width / $originalHeight;
462
-            }
463
-            $attr = " width='$width' height='$height'";
464
-        }
465
-
466
-        return [
467
-            $width,
468
-            $height,
469
-            $type,
470
-            $attr
471
-        ];
472
-    }
473
-
474
-    /**
475
-     * @param  bool $moduleName
476
-     * @return mixed
477
-     */
478
-    public static function getModuleInfo($moduleName = false)
479
-    {
480
-        static $smartModules;
481
-        if (isset($smartModules[$moduleName])) {
482
-            $ret =& $smartModules[$moduleName];
483
-
484
-            return $ret;
485
-        }
486
-        global $xoopsModule;
487
-        if (!$moduleName) {
488
-            if (isset($xoopsModule) && is_object($xoopsModule)) {
489
-                $smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule;
490
-
491
-                return $smartModules[$xoopsModule->getVar('dirname')];
492
-            }
493
-        }
494
-        if (!isset($smartModules[$moduleName])) {
495
-            if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
496
-                $smartModules[$moduleName] = $xoopsModule;
497
-            } else {
498
-                $hModule = xoops_getHandler('module');
499
-                if ('xoops' !== $moduleName) {
500
-                    $smartModules[$moduleName] = $hModule->getByDirname($moduleName);
501
-                } else {
502
-                    $smartModules[$moduleName] = $hModule->getByDirname('system');
503
-                }
504
-            }
505
-        }
506
-
507
-        return $smartModules[$moduleName];
508
-    }
509
-
510
-    /**
511
-     * @param  bool $moduleName
512
-     * @return bool
513
-     */
514
-    public static function getModuleConfig($moduleName = false)
515
-    {
516
-        static $smartConfigs;
517
-        if (isset($smartConfigs[$moduleName])) {
518
-            $ret =& $smartConfigs[$moduleName];
519
-
520
-            return $ret;
521
-        }
522
-        global $xoopsModule, $xoopsModuleConfig;
523
-        if (!$moduleName) {
524
-            if (isset($xoopsModule) && is_object($xoopsModule)) {
525
-                $smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig;
526
-
527
-                return $smartConfigs[$xoopsModule->getVar('dirname')];
528
-            }
529
-        }
530
-        // if we still did not found the xoopsModule, this is because there is none
531
-        if (!$moduleName) {
532
-            $ret = false;
533
-
534
-            return $ret;
535
-        }
536
-        if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
537
-            $smartConfigs[$moduleName] = $xoopsModuleConfig;
538
-        } else {
539
-            $module = static::getModuleInfo($moduleName);
540
-            if (!is_object($module)) {
541
-                $ret = false;
542
-
543
-                return $ret;
544
-            }
545
-            $hModConfig                = xoops_getHandler('config');
546
-            $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
547
-        }
548
-
549
-        return $smartConfigs[$moduleName];
550
-    }
551
-
552
-    /**
553
-     * @param $dirname
554
-     * @return bool
555
-     */
556
-    public static function deleteFile($dirname)
557
-    {
558
-        // Simple delete for a file
559
-        if (is_file($dirname)) {
560
-            return unlink($dirname);
561
-        }
562
-    }
563
-
564
-    /**
565
-     * @param  array $errors
566
-     * @return string
567
-     */
568
-    public static function formatErrors($errors = [])
569
-    {
570
-        $ret = '';
571
-        foreach ($errors as $key => $value) {
572
-            $ret .= '<br> - ' . $value;
573
-        }
574
-
575
-        return $ret;
576
-    }
577
-
578
-    /**
579
-     * getLinkedUnameFromId()
580
-     *
581
-     * @param  integer $userid Userid of poster etc
582
-     * @param  integer $name   :  0 Use Usenamer 1 Use realname
583
-     * @param  array   $users
584
-     * @param  bool    $withContact
585
-     * @return string
586
-     */
587
-    public static function getLinkedUnameFromId($userid = 0, $name = 0, $users = [], $withContact = false)
588
-    {
589
-        if (!is_numeric($userid)) {
590
-            return $userid;
591
-        }
592
-        $userid = (int)$userid;
593
-        if ($userid > 0) {
594
-            if ($users == []) {
595
-                //fetching users
596
-                $memberHandler = xoops_getHandler('member');
597
-                $user          =& $memberHandler->getUser($userid);
598
-            } else {
599
-                if (!isset($users[$userid])) {
600
-                    return $GLOBALS['xoopsConfig']['anonymous'];
601
-                }
602
-                $user =& $users[$userid];
603
-            }
604
-            if (is_object($user)) {
605
-                $ts        = \MyTextSanitizer:: getInstance();
606
-                $username  = $user->getVar('uname');
607
-                $fullname  = '';
608
-                $fullname2 = $user->getVar('name');
609
-                if ($name && !empty($fullname2)) {
610
-                    $fullname = $user->getVar('name');
611
-                }
612
-                if (!empty($fullname)) {
613
-                    $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
614
-                } else {
615
-                    $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
616
-                }
617
-                // add contact info: email + PM
618
-                if ($withContact) {
619
-                    $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>';
620
-                    $js         = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
621
-                    $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>';
622
-                }
623
-
624
-                return $linkeduser;
625
-            }
626
-        }
627
-
628
-        return $GLOBALS['xoopsConfig']['anonymous'];
629
-    }
630
-
631
-    /**
632
-     * @param int    $currentoption
633
-     * @param string $breadcrumb
634
-     * @param bool   $submenus
635
-     * @param int    $currentsub
636
-     */
637
-    public static function getAdminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1)
638
-    {
639
-        global $xoopsModule, $xoopsConfig;
640
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
641
-
642
-
643
-        /** @var Smartobject\Helper $helper */
644
-        $helper = Smartobject\Helper::getInstance();
645
-        $helper->loadLanguage('admin');
646
-        $helper->loadLanguage('modinfo');
647
-        $headermenu  = [];
648
-        $adminObject = [];
649
-        include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
650
-        $tpl = new \XoopsTpl();
651
-        $tpl->assign([
652
-                         'headermenu'      => $headermenu,
653
-                         'adminmenu'       => $adminObject,
654
-                         'current'         => $currentoption,
655
-                         'breadcrumb'      => $breadcrumb,
656
-                         'headermenucount' => count($headermenu),
657
-                         'submenus'        => $submenus,
658
-                         'currentsub'      => $currentsub,
659
-                         'submenuscount'   => count($submenus)
660
-                     ]);
661
-        $tpl->display('db:smartobject_admin_menu.tpl');
662
-    }
663
-
664
-    /**
665
-     * @param string $id
666
-     * @param string $title
667
-     * @param string $dsc
668
-     */
669
-    public static function getCollapsableBar($id = '', $title = '', $dsc = '')
670
-    {
671
-        global $xoopsModule;
672
-        echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>";
673
-        echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
674
-        echo "<div id='" . $id . "'>";
675
-        if ('' !== $dsc) {
676
-            echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>';
677
-        }
678
-    }
679
-
680
-    /**
681
-     * @param string $id
682
-     * @param string $title
683
-     * @param string $dsc
684
-     */
685
-    public static function getAjaxCollapsableBar($id = '', $title = '', $dsc = '')
686
-    {
687
-        global $xoopsModule;
688
-        $onClick = "ajaxtogglecollapse('$id')";
689
-        //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
690
-        echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
691
-        echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
692
-        echo "<div id='" . $id . "'>";
693
-        if ('' !== $dsc) {
694
-            echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>';
695
-        }
696
-    }
697
-
698
-    /**
699
-     * Ajax testing......
700
-     * @param $name
701
-     */
702
-    /*
205
+		/**
206
+		 * Include the admin language constants for the SmartObject Framework
207
+		 */
208
+		/** @var Smartobject\Helper $helper */
209
+		$helper = Smartobject\Helper::getInstance();
210
+		$helper->loadLanguage('admin');
211
+	}
212
+
213
+	/**
214
+	 * Detemines if a table exists in the current db
215
+	 *
216
+	 * @param  string $table the table name (without XOOPS prefix)
217
+	 * @return bool   True if table exists, false if not
218
+	 *
219
+	 * @access public
220
+	 * @author xhelp development team
221
+	 */
222
+	public static function isTable($table)
223
+	{
224
+		$bRetVal = false;
225
+		//Verifies that a MySQL table exists
226
+		$xoopsDB  = \XoopsDatabaseFactory::getDatabaseConnection();
227
+		$realname = $xoopsDB->prefix($table);
228
+		$sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
229
+		$ret      = $xoopsDB->queryF($sql);
230
+		while (false !== (list($m_table) = $xoopsDB->fetchRow($ret))) {
231
+			if ($m_table == $realname) {
232
+				$bRetVal = true;
233
+				break;
234
+			}
235
+		}
236
+		$xoopsDB->freeRecordSet($ret);
237
+
238
+		return $bRetVal;
239
+	}
240
+
241
+	/**
242
+	 * Gets a value from a key in the xhelp_meta table
243
+	 *
244
+	 * @param  string $key
245
+	 * @param  bool   $moduleName
246
+	 * @return string $value
247
+	 *
248
+	 * @access public
249
+	 * @author xhelp development team
250
+	 */
251
+	public static function getMeta($key, $moduleName = false)
252
+	{
253
+		if (!$moduleName) {
254
+			$moduleName = static::getCurrentModuleName();
255
+		}
256
+		$xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
257
+		$sql     = sprintf('SELECT metavalue FROM `%s` WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
258
+		$ret     = $xoopsDB->query($sql);
259
+		if (!$ret) {
260
+			$value = false;
261
+		} else {
262
+			list($value) = $xoopsDB->fetchRow($ret);
263
+		}
264
+
265
+		return $value;
266
+	}
267
+
268
+	/**
269
+	 * @return bool
270
+	 */
271
+	public static function getCurrentModuleName()
272
+	{
273
+		global $xoopsModule;
274
+		if (is_object($xoopsModule)) {
275
+			return $xoopsModule->getVar('dirname');
276
+		} else {
277
+			return false;
278
+		}
279
+	}
280
+
281
+	/**
282
+	 * Sets a value for a key in the xhelp_meta table
283
+	 *
284
+	 * @param  string $key
285
+	 * @param  string $value
286
+	 * @param  bool   $moduleName
287
+	 * @return bool   TRUE if success, FALSE if failure
288
+	 *
289
+	 * @access public
290
+	 * @author xhelp development team
291
+	 */
292
+	public static function setMeta($key, $value, $moduleName = false)
293
+	{
294
+		if (!$moduleName) {
295
+			$moduleName = static::getCurrentModuleName();
296
+		}
297
+		$xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
298
+		$ret     = static::getMeta($key, $moduleName);
299
+		if ('0' === $ret || $ret > 0) {
300
+			$sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
301
+		} else {
302
+			$sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
303
+		}
304
+		$ret = $xoopsDB->queryF($sql);
305
+		if (!$ret) {
306
+			return false;
307
+		}
308
+
309
+		return true;
310
+	}
311
+
312
+	// Thanks to Mithrandir:-)
313
+	/**
314
+	 * @param         $str
315
+	 * @param         $start
316
+	 * @param         $length
317
+	 * @param  string $trimmarker
318
+	 * @return string
319
+	 */
320
+	public static function getSubstr($str, $start, $length, $trimmarker = '...')
321
+	{
322
+		// if the string is empty, let's get out ;-)
323
+		if ('' === $str) {
324
+			return $str;
325
+		}
326
+		// reverse a string that is shortened with '' as trimmarker
327
+		$reversed_string = strrev(xoops_substr($str, $start, $length, ''));
328
+		// find first space in reversed string
329
+		$position_of_space = strpos($reversed_string, ' ', 0);
330
+		// truncate the original string to a length of $length
331
+		// minus the position of the last space
332
+		// plus the length of the $trimmarker
333
+		$truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker);
334
+
335
+		return $truncated_string;
336
+	}
337
+
338
+	/**
339
+	 * @param              $key
340
+	 * @param  bool        $moduleName
341
+	 * @param  string      $default
342
+	 * @return null|string
343
+	 */
344
+	public static function getConfig($key, $moduleName = false, $default = 'default_is_undefined')
345
+	{
346
+		if (!$moduleName) {
347
+			$moduleName = static::getCurrentModuleName();
348
+		}
349
+		$configs = static::getModuleConfig($moduleName);
350
+		if (isset($configs[$key])) {
351
+			return $configs[$key];
352
+		} else {
353
+			if ('default_is_undefined' === $default) {
354
+				return null;
355
+			} else {
356
+				return $default;
357
+			}
358
+		}
359
+	}
360
+
361
+	/**
362
+	 * Copy a file, or a folder and its contents
363
+	 *
364
+	 * @author      Aidan Lister <[email protected]>
365
+	 * @param  string $source The source
366
+	 * @param  string $dest   The destination
367
+	 * @return bool   Returns true on success, false on failure
368
+	 */
369
+	public static function copyr($source, $dest)
370
+	{
371
+		// Simple copy for a file
372
+		if (is_file($source)) {
373
+			return copy($source, $dest);
374
+		}
375
+		// Make destination directory
376
+		if (!is_dir($dest)) {
377
+			mkdir($dest);
378
+		}
379
+		// Loop through the folder
380
+		$dir = dir($source);
381
+		while (false !== $entry = $dir->read()) {
382
+			// Skip pointers
383
+			if ('.' === $entry || '..' === $entry) {
384
+				continue;
385
+			}
386
+			// Deep copy directories
387
+			if (is_dir("$source/$entry") && ("$source/$entry" !== $dest)) {
388
+				static::copyr("$source/$entry", "$dest/$entry");
389
+			} else {
390
+				copy("$source/$entry", "$dest/$entry");
391
+			}
392
+		}
393
+		// Clean up
394
+		$dir->close();
395
+
396
+		return true;
397
+	}
398
+
399
+	/**
400
+	 * Thanks to the NewBB2 Development Team
401
+	 * @param $target
402
+	 * @return bool
403
+	 */
404
+	public static function mkdirAsAdmin($target)
405
+	{
406
+		// http://www.php.net/manual/en/function.mkdir.php
407
+		// saint at corenova.com
408
+		// bart at cdasites dot com
409
+		if (is_dir($target) || empty($target)) {
410
+			return true; // best case check first
411
+		}
412
+		if (file_exists($target) && !is_dir($target)) {
413
+			return false;
414
+		}
415
+		if (static::mkdirAsAdmin(substr($target, 0, strrpos($target, '/')))) {
416
+			if (!file_exists($target)) {
417
+				$res = mkdir($target, 0777); // crawl back up & create dir tree
418
+				static::chmodAsAdmin($target);
419
+
420
+				return $res;
421
+			}
422
+		}
423
+		$res = is_dir($target);
424
+
425
+		return $res;
426
+	}
427
+
428
+	/**
429
+	 * Thanks to the NewBB2 Development Team
430
+	 * @param       $target
431
+	 * @param  int  $mode
432
+	 * @return bool
433
+	 */
434
+	public static function chmodAsAdmin($target, $mode = 0777)
435
+	{
436
+		return @ chmod($target, $mode);
437
+	}
438
+
439
+	/**
440
+	 * @param $src
441
+	 * @param $maxWidth
442
+	 * @param $maxHeight
443
+	 * @return array
444
+	 */
445
+	public static function imageResize($src, $maxWidth, $maxHeight)
446
+	{
447
+		$width  = '';
448
+		$height = '';
449
+		$type   = '';
450
+		$attr   = '';
451
+		if (file_exists($src)) {
452
+			list($width, $height, $type, $attr) = getimagesize($src);
453
+			if ($width > $maxWidth) {
454
+				$originalWidth = $width;
455
+				$width         = $maxWidth;
456
+				$height        = $width * $height / $originalWidth;
457
+			}
458
+			if ($height > $maxHeight) {
459
+				$originalHeight = $height;
460
+				$height         = $maxHeight;
461
+				$width          = $height * $width / $originalHeight;
462
+			}
463
+			$attr = " width='$width' height='$height'";
464
+		}
465
+
466
+		return [
467
+			$width,
468
+			$height,
469
+			$type,
470
+			$attr
471
+		];
472
+	}
473
+
474
+	/**
475
+	 * @param  bool $moduleName
476
+	 * @return mixed
477
+	 */
478
+	public static function getModuleInfo($moduleName = false)
479
+	{
480
+		static $smartModules;
481
+		if (isset($smartModules[$moduleName])) {
482
+			$ret =& $smartModules[$moduleName];
483
+
484
+			return $ret;
485
+		}
486
+		global $xoopsModule;
487
+		if (!$moduleName) {
488
+			if (isset($xoopsModule) && is_object($xoopsModule)) {
489
+				$smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule;
490
+
491
+				return $smartModules[$xoopsModule->getVar('dirname')];
492
+			}
493
+		}
494
+		if (!isset($smartModules[$moduleName])) {
495
+			if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
496
+				$smartModules[$moduleName] = $xoopsModule;
497
+			} else {
498
+				$hModule = xoops_getHandler('module');
499
+				if ('xoops' !== $moduleName) {
500
+					$smartModules[$moduleName] = $hModule->getByDirname($moduleName);
501
+				} else {
502
+					$smartModules[$moduleName] = $hModule->getByDirname('system');
503
+				}
504
+			}
505
+		}
506
+
507
+		return $smartModules[$moduleName];
508
+	}
509
+
510
+	/**
511
+	 * @param  bool $moduleName
512
+	 * @return bool
513
+	 */
514
+	public static function getModuleConfig($moduleName = false)
515
+	{
516
+		static $smartConfigs;
517
+		if (isset($smartConfigs[$moduleName])) {
518
+			$ret =& $smartConfigs[$moduleName];
519
+
520
+			return $ret;
521
+		}
522
+		global $xoopsModule, $xoopsModuleConfig;
523
+		if (!$moduleName) {
524
+			if (isset($xoopsModule) && is_object($xoopsModule)) {
525
+				$smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig;
526
+
527
+				return $smartConfigs[$xoopsModule->getVar('dirname')];
528
+			}
529
+		}
530
+		// if we still did not found the xoopsModule, this is because there is none
531
+		if (!$moduleName) {
532
+			$ret = false;
533
+
534
+			return $ret;
535
+		}
536
+		if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
537
+			$smartConfigs[$moduleName] = $xoopsModuleConfig;
538
+		} else {
539
+			$module = static::getModuleInfo($moduleName);
540
+			if (!is_object($module)) {
541
+				$ret = false;
542
+
543
+				return $ret;
544
+			}
545
+			$hModConfig                = xoops_getHandler('config');
546
+			$smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
547
+		}
548
+
549
+		return $smartConfigs[$moduleName];
550
+	}
551
+
552
+	/**
553
+	 * @param $dirname
554
+	 * @return bool
555
+	 */
556
+	public static function deleteFile($dirname)
557
+	{
558
+		// Simple delete for a file
559
+		if (is_file($dirname)) {
560
+			return unlink($dirname);
561
+		}
562
+	}
563
+
564
+	/**
565
+	 * @param  array $errors
566
+	 * @return string
567
+	 */
568
+	public static function formatErrors($errors = [])
569
+	{
570
+		$ret = '';
571
+		foreach ($errors as $key => $value) {
572
+			$ret .= '<br> - ' . $value;
573
+		}
574
+
575
+		return $ret;
576
+	}
577
+
578
+	/**
579
+	 * getLinkedUnameFromId()
580
+	 *
581
+	 * @param  integer $userid Userid of poster etc
582
+	 * @param  integer $name   :  0 Use Usenamer 1 Use realname
583
+	 * @param  array   $users
584
+	 * @param  bool    $withContact
585
+	 * @return string
586
+	 */
587
+	public static function getLinkedUnameFromId($userid = 0, $name = 0, $users = [], $withContact = false)
588
+	{
589
+		if (!is_numeric($userid)) {
590
+			return $userid;
591
+		}
592
+		$userid = (int)$userid;
593
+		if ($userid > 0) {
594
+			if ($users == []) {
595
+				//fetching users
596
+				$memberHandler = xoops_getHandler('member');
597
+				$user          =& $memberHandler->getUser($userid);
598
+			} else {
599
+				if (!isset($users[$userid])) {
600
+					return $GLOBALS['xoopsConfig']['anonymous'];
601
+				}
602
+				$user =& $users[$userid];
603
+			}
604
+			if (is_object($user)) {
605
+				$ts        = \MyTextSanitizer:: getInstance();
606
+				$username  = $user->getVar('uname');
607
+				$fullname  = '';
608
+				$fullname2 = $user->getVar('name');
609
+				if ($name && !empty($fullname2)) {
610
+					$fullname = $user->getVar('name');
611
+				}
612
+				if (!empty($fullname)) {
613
+					$linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
614
+				} else {
615
+					$linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
616
+				}
617
+				// add contact info: email + PM
618
+				if ($withContact) {
619
+					$linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>';
620
+					$js         = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
621
+					$linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>';
622
+				}
623
+
624
+				return $linkeduser;
625
+			}
626
+		}
627
+
628
+		return $GLOBALS['xoopsConfig']['anonymous'];
629
+	}
630
+
631
+	/**
632
+	 * @param int    $currentoption
633
+	 * @param string $breadcrumb
634
+	 * @param bool   $submenus
635
+	 * @param int    $currentsub
636
+	 */
637
+	public static function getAdminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1)
638
+	{
639
+		global $xoopsModule, $xoopsConfig;
640
+		require_once XOOPS_ROOT_PATH . '/class/template.php';
641
+
642
+
643
+		/** @var Smartobject\Helper $helper */
644
+		$helper = Smartobject\Helper::getInstance();
645
+		$helper->loadLanguage('admin');
646
+		$helper->loadLanguage('modinfo');
647
+		$headermenu  = [];
648
+		$adminObject = [];
649
+		include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
650
+		$tpl = new \XoopsTpl();
651
+		$tpl->assign([
652
+						 'headermenu'      => $headermenu,
653
+						 'adminmenu'       => $adminObject,
654
+						 'current'         => $currentoption,
655
+						 'breadcrumb'      => $breadcrumb,
656
+						 'headermenucount' => count($headermenu),
657
+						 'submenus'        => $submenus,
658
+						 'currentsub'      => $currentsub,
659
+						 'submenuscount'   => count($submenus)
660
+					 ]);
661
+		$tpl->display('db:smartobject_admin_menu.tpl');
662
+	}
663
+
664
+	/**
665
+	 * @param string $id
666
+	 * @param string $title
667
+	 * @param string $dsc
668
+	 */
669
+	public static function getCollapsableBar($id = '', $title = '', $dsc = '')
670
+	{
671
+		global $xoopsModule;
672
+		echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>";
673
+		echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
674
+		echo "<div id='" . $id . "'>";
675
+		if ('' !== $dsc) {
676
+			echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>';
677
+		}
678
+	}
679
+
680
+	/**
681
+	 * @param string $id
682
+	 * @param string $title
683
+	 * @param string $dsc
684
+	 */
685
+	public static function getAjaxCollapsableBar($id = '', $title = '', $dsc = '')
686
+	{
687
+		global $xoopsModule;
688
+		$onClick = "ajaxtogglecollapse('$id')";
689
+		//$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
690
+		echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
691
+		echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
692
+		echo "<div id='" . $id . "'>";
693
+		if ('' !== $dsc) {
694
+			echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $dsc . '</span>';
695
+		}
696
+	}
697
+
698
+	/**
699
+	 * Ajax testing......
700
+	 * @param $name
701
+	 */
702
+	/*
703 703
      public static function getCollapsableBar($id = '', $title = '', $dsc='')
704 704
      {
705 705
     
@@ -717,22 +717,22 @@  discard block
 block discarded – undo
717 717
      }
718 718
      }
719 719
      */
720
-    public static function opencloseCollapsable($name)
721
-    {
722
-        $urls        = static::getCurrentUrls();
723
-        $path        = $urls['phpself'];
724
-        $cookie_name = $path . '_smart_collaps_' . $name;
725
-        $cookie_name = str_replace('.', '_', $cookie_name);
726
-        $cookie      = static::getCookieVar($cookie_name, '');
727
-        if ('none' === $cookie) {
728
-            echo '
720
+	public static function opencloseCollapsable($name)
721
+	{
722
+		$urls        = static::getCurrentUrls();
723
+		$path        = $urls['phpself'];
724
+		$cookie_name = $path . '_smart_collaps_' . $name;
725
+		$cookie_name = str_replace('.', '_', $cookie_name);
726
+		$cookie      = static::getCookieVar($cookie_name, '');
727
+		if ('none' === $cookie) {
728
+			echo '
729 729
                 <script type="text/javascript"><!--
730 730
                 togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon");
731 731
                     //-->
732 732
                 </script>
733 733
                 ';
734
-        }
735
-        /*  if ($cookie == 'none') {
734
+		}
735
+		/*  if ($cookie == 'none') {
736 736
          echo '
737 737
          <script type="text/javascript"><!--
738 738
          hideElement("' . $name . '");
@@ -741,96 +741,96 @@  discard block
 block discarded – undo
741 741
          ';
742 742
          }
743 743
          */
744
-    }
745
-
746
-    /**
747
-     * @param $name
748
-     */
749
-    public static function closeCollapsable($name)
750
-    {
751
-        echo '</div>';
752
-        static::opencloseCollapsable($name);
753
-        echo '<br>';
754
-    }
755
-
756
-    /**
757
-     * @param     $name
758
-     * @param     $value
759
-     * @param int $time
760
-     */
761
-    public static function setCookieVar($name, $value, $time = 0)
762
-    {
763
-        if (0 == $time) {
764
-            $time = time() + 3600 * 24 * 365;
765
-            //$time = '';
766
-        }
767
-        setcookie($name, $value, $time, '/');
768
-    }
769
-
770
-    /**
771
-     * @param         $name
772
-     * @param  string $default
773
-     * @return string
774
-     */
775
-    public static function getCookieVar($name, $default = '')
776
-    {
777
-        $name = str_replace('.', '_', $name);
778
-        if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
779
-            return $_COOKIE[$name];
780
-        } else {
781
-            return $default;
782
-        }
783
-    }
784
-
785
-    /**
786
-     * @return array
787
-     */
788
-    public static function getCurrentUrls()
789
-    {
790
-        $urls        = [];
791
-        $http        = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://';
792
-        $phpself     = $_SERVER['PHP_SELF'];
793
-        $httphost    = $_SERVER['HTTP_HOST'];
794
-        $querystring = $_SERVER['QUERY_STRING'];
795
-        if ('' !== $querystring) {
796
-            $querystring = '?' . $querystring;
797
-        }
798
-        $currenturl           = $http . $httphost . $phpself . $querystring;
799
-        $urls                 = [];
800
-        $urls['http']         = $http;
801
-        $urls['httphost']     = $httphost;
802
-        $urls['phpself']      = $phpself;
803
-        $urls['querystring']  = $querystring;
804
-        $urls['full_phpself'] = $http . $httphost . $phpself;
805
-        $urls['full']         = $currenturl;
806
-        $urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
807
-
808
-        return $urls;
809
-    }
810
-
811
-    /**
812
-     * @return mixed
813
-     */
814
-    public static function getCurrentPage()
815
-    {
816
-        $urls = static::getCurrentUrls();
817
-
818
-        return $urls['full'];
819
-    }
820
-
821
-    /**
822
-     * Create a title for the short_url field of an article
823
-     *
824
-     * @credit psylove
825
-     *
826
-     * @var    string $title   title of the article
827
-     * @var    string $withExt do we add an html extension or not
828
-     * @return string sort_url for the article
829
-     */
830
-    /**
831
-     * Moved in SmartMetaGenClass
832
-     */
833
-    /*
744
+	}
745
+
746
+	/**
747
+	 * @param $name
748
+	 */
749
+	public static function closeCollapsable($name)
750
+	{
751
+		echo '</div>';
752
+		static::opencloseCollapsable($name);
753
+		echo '<br>';
754
+	}
755
+
756
+	/**
757
+	 * @param     $name
758
+	 * @param     $value
759
+	 * @param int $time
760
+	 */
761
+	public static function setCookieVar($name, $value, $time = 0)
762
+	{
763
+		if (0 == $time) {
764
+			$time = time() + 3600 * 24 * 365;
765
+			//$time = '';
766
+		}
767
+		setcookie($name, $value, $time, '/');
768
+	}
769
+
770
+	/**
771
+	 * @param         $name
772
+	 * @param  string $default
773
+	 * @return string
774
+	 */
775
+	public static function getCookieVar($name, $default = '')
776
+	{
777
+		$name = str_replace('.', '_', $name);
778
+		if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
779
+			return $_COOKIE[$name];
780
+		} else {
781
+			return $default;
782
+		}
783
+	}
784
+
785
+	/**
786
+	 * @return array
787
+	 */
788
+	public static function getCurrentUrls()
789
+	{
790
+		$urls        = [];
791
+		$http        = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://';
792
+		$phpself     = $_SERVER['PHP_SELF'];
793
+		$httphost    = $_SERVER['HTTP_HOST'];
794
+		$querystring = $_SERVER['QUERY_STRING'];
795
+		if ('' !== $querystring) {
796
+			$querystring = '?' . $querystring;
797
+		}
798
+		$currenturl           = $http . $httphost . $phpself . $querystring;
799
+		$urls                 = [];
800
+		$urls['http']         = $http;
801
+		$urls['httphost']     = $httphost;
802
+		$urls['phpself']      = $phpself;
803
+		$urls['querystring']  = $querystring;
804
+		$urls['full_phpself'] = $http . $httphost . $phpself;
805
+		$urls['full']         = $currenturl;
806
+		$urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
807
+
808
+		return $urls;
809
+	}
810
+
811
+	/**
812
+	 * @return mixed
813
+	 */
814
+	public static function getCurrentPage()
815
+	{
816
+		$urls = static::getCurrentUrls();
817
+
818
+		return $urls['full'];
819
+	}
820
+
821
+	/**
822
+	 * Create a title for the short_url field of an article
823
+	 *
824
+	 * @credit psylove
825
+	 *
826
+	 * @var    string $title   title of the article
827
+	 * @var    string $withExt do we add an html extension or not
828
+	 * @return string sort_url for the article
829
+	 */
830
+	/**
831
+	 * Moved in SmartMetaGenClass
832
+	 */
833
+	/*
834 834
      public static function smart_seo_title($title='', $withExt=true)
835 835
      {
836 836
      // Transformation de la chaine en minuscule
@@ -876,468 +876,468 @@  discard block
 block discarded – undo
876 876
      return '';
877 877
      }
878 878
      */
879
-    public static function getModFooter()
880
-    {
881
-        global $xoopsConfig, $xoopsModule;
882
-
883
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
884
-        $tpl = new \XoopsTpl();
885
-
886
-        $hModule      = xoops_getHandler('module');
887
-        $versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
888
-        $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
889
-        $modfooter    = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>";
890
-        $tpl->assign('modfooter', $modfooter);
891
-
892
-        if (!defined('_AM_SOBJECT_XOOPS_PRO')) {
893
-            define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?');
894
-        }
895
-        $smartobjectConfig = static::getModuleConfig('smartobject');
896
-        $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
897
-        $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl');
898
-    }
899
-
900
-    public static function getXoopsCpFooter()
901
-    {
902
-        static::getModFooter();
903
-        xoops_cp_footer();
904
-    }
905
-
906
-    /**
907
-     * @param $text
908
-     * @return mixed
909
-     */
910
-    public static function sanitizeForCommonTags($text)
911
-    {
912
-        global $xoopsConfig;
913
-        $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text);
914
-        $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text);
915
-
916
-        return $text;
917
-    }
918
-
919
-    /**
920
-     * @param $src
921
-     */
922
-    public static function addScript($src)
923
-    {
924
-        echo '<script src="' . $src . '" type="text/javascript"></script>';
925
-    }
926
-
927
-    /**
928
-     * @param $src
929
-     */
930
-    public static function addStyle($src)
931
-    {
932
-        if ('smartobject' === $src) {
933
-            $src = SMARTOBJECT_URL . 'assets/css/module.css';
934
-        }
935
-        echo static::getCssLink($src);
936
-    }
937
-
938
-    public static function addAdminAjaxSupport()
939
-    {
940
-        static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
941
-        static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
942
-        static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
943
-    }
944
-
945
-    /**
946
-     * @param $text
947
-     * @return mixed
948
-     */
949
-    public static function sanitizeForSmartpopupLink($text)
950
-    {
951
-        $patterns[]     = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU";
952
-        $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>";
953
-        $ret            = preg_replace($patterns, $replacements, $text);
954
-
955
-        return $ret;
956
-    }
957
-
958
-    /**
959
-     * Finds the width and height of an image (can also be a flash file)
960
-     *
961
-     * @credit phppp
962
-     *
963
-     * @var    string $url    path of the image file
964
-     * @var    string $width  reference to the width
965
-     * @var    string $height reference to the height
966
-     * @return bool   false if impossible to find dimension
967
-     */
968
-    public static function getImageSize($url, & $width, & $height)
969
-    {
970
-        if (empty($width) || empty($height)) {
971
-            if (!$dimension = @ getimagesize($url)) {
972
-                return false;
973
-            }
974
-            if (!empty($width)) {
975
-                $height = $dimension[1] * $width / $dimension[0];
976
-            } elseif (!empty($height)) {
977
-                $width = $dimension[0] * $height / $dimension[1];
978
-            } else {
979
-                list($width, $height) = [
980
-                    $dimension[0],
981
-                    $dimension[1]
982
-                ];
983
-            }
984
-
985
-            return true;
986
-        } else {
987
-            return true;
988
-        }
989
-    }
990
-
991
-    /**
992
-     * Convert characters to decimal values
993
-     *
994
-     * @author eric.wallet at yahoo.fr
995
-     * @link   http://ca.php.net/manual/en/function.htmlentities.php#69913
996
-     * @param $str
997
-     * @return mixed
998
-     */
999
-    public static function getHtmlnumericentities($str)
1000
-    {
1001
-        //    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
1002
-        return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) {
1003
-            return '&#' . ord($m[0]) . chr(59);
1004
-        }, $str);
1005
-    }
1006
-
1007
-    /**
1008
-     * @param        $name
1009
-     * @param  bool  $optional
1010
-     * @return mixed
1011
-     */
1012
-    public static function getCoreHandler($name, $optional = false)
1013
-    {
1014
-        static $handlers;
1015
-        $name = strtolower(trim($name));
1016
-        if (!isset($handlers[$name])) {
1017
-            if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1018
-                require_once $hnd_file;
1019
-            }
1020
-            $class = 'Xoops' . ucfirst($name) . 'Handler';
1021
-            if (class_exists($class)) {
1022
-                $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops');
1023
-            }
1024
-        }
1025
-        if (!isset($handlers[$name]) && !$optional) {
1026
-            trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1027
-        }
1028
-        if (isset($handlers[$name])) {
1029
-            return $handlers[$name];
1030
-        }
1031
-        $inst = false;
1032
-    }
1033
-
1034
-    /**
1035
-     * @param $matches
1036
-     * @return string
1037
-     */
1038
-    public static function sanitizeAdsenses_callback($matches)
1039
-    {
1040
-        global $smartobjectAdsenseHandler;
1041
-        if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) {
1042
-            $adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]];
1043
-            $ret        = $adsenseObj->render();
1044
-
1045
-            return $ret;
1046
-        } else {
1047
-            return '';
1048
-        }
1049
-    }
1050
-
1051
-    /**
1052
-     * @param $text
1053
-     * @return mixed
1054
-     */
1055
-    public static function sanitizeAdsenses($text)
1056
-    {
1057
-        $patterns     = [];
1058
-        $replacements = [];
1059
-
1060
-        $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU";
1061
-        $text       = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeAdsenses_callback', $text);
1062
-
1063
-        return $text;
1064
-    }
1065
-
1066
-    /**
1067
-     * @param $matches
1068
-     * @return string
1069
-     */
1070
-    public static function sanitizeCustomtags_callback($matches)
1071
-    {
1072
-        global $smartobjectCustomtagHandler;
1073
-        if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) {
1074
-            $customObj = $smartobjectCustomtagHandler->objects[$matches[1]];
1075
-            $ret       = $customObj->renderWithPhp();
1076
-
1077
-            return $ret;
1078
-        } else {
1079
-            return '';
1080
-        }
1081
-    }
1082
-
1083
-    /**
1084
-     * @param $text
1085
-     * @return mixed
1086
-     */
1087
-    public static function sanitizeCustomtags($text)
1088
-    {
1089
-        $patterns     = [];
1090
-        $replacements = [];
1091
-
1092
-        $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU";
1093
-        $text       = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeCustomtags_callback', $text);
1094
-
1095
-        return $text;
1096
-    }
1097
-
1098
-    /**
1099
-     * @param $module
1100
-     * @param $file
1101
-     */
1102
-    public static function loadLanguageFile($module, $file)
1103
-    {
1104
-        global $xoopsConfig;
1105
-
1106
-        $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1107
-        if (!file_exists($filename)) {
1108
-            $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1109
-        }
1110
-        if (file_exists($filename)) {
1111
-            require_once $filename;
1112
-        }
1113
-    }
1114
-
1115
-    public static function loadCommonLanguageFile()
1116
-    {
1117
-        static::loadLanguageFile('smartobject', 'common');
1118
-    }
1119
-
1120
-    /**
1121
-     * @param               $text
1122
-     * @param  bool         $keyword
1123
-     * @return mixed|string
1124
-     */
1125
-    public static function purifyText($text, $keyword = false)
1126
-    {
1127
-        global $myts;
1128
-        $text = str_replace('&nbsp;', ' ', $text);
1129
-        $text = str_replace('<br>', ' ', $text);
1130
-        $text = str_replace('<br>', ' ', $text);
1131
-        $text = str_replace('<br', ' ', $text);
1132
-        $text = strip_tags($text);
1133
-        $text = html_entity_decode($text);
1134
-        $text = $myts->undoHtmlSpecialChars($text);
1135
-        $text = str_replace(')', ' ', $text);
1136
-        $text = str_replace('(', ' ', $text);
1137
-        $text = str_replace(':', ' ', $text);
1138
-        $text = str_replace('&euro', ' euro ', $text);
1139
-        $text = str_replace('&hellip', '...', $text);
1140
-        $text = str_replace('&rsquo', ' ', $text);
1141
-        $text = str_replace('!', ' ', $text);
1142
-        $text = str_replace('?', ' ', $text);
1143
-        $text = str_replace('"', ' ', $text);
1144
-        $text = str_replace('-', ' ', $text);
1145
-        $text = str_replace('\n', ' ', $text);
1146
-        $text = str_replace('&#8213;', ' ', $text);
1147
-
1148
-        if ($keyword) {
1149
-            $text = str_replace('.', ' ', $text);
1150
-            $text = str_replace(',', ' ', $text);
1151
-            $text = str_replace('\'', ' ', $text);
1152
-        }
1153
-        $text = str_replace(';', ' ', $text);
1154
-
1155
-        return $text;
1156
-    }
1157
-
1158
-    /**
1159
-     * @param $document
1160
-     * @return mixed
1161
-     */
1162
-    public static function getHtml2text($document)
1163
-    {
1164
-        // PHP Manual:: function preg_replace
1165
-        // $document should contain an HTML document.
1166
-        // This will remove HTML tags, javascript sections
1167
-        // and white space. It will also convert some
1168
-        // common HTML entities to their text equivalent.
1169
-        // Credits: newbb2
1170
-        $search = [
1171
-            "'<script[^>]*?>.*?</script>'si", // Strip out javascript
1172
-            "'<img.*?>'si", // Strip out img tags
1173
-            "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
1174
-            "'([\r\n])[\s]+'", // Strip out white space
1175
-            "'&(quot|#34);'i", // Replace HTML entities
1176
-            "'&(amp|#38);'i",
1177
-            "'&(lt|#60);'i",
1178
-            "'&(gt|#62);'i",
1179
-            "'&(nbsp|#160);'i",
1180
-            "'&(iexcl|#161);'i",
1181
-            "'&(cent|#162);'i",
1182
-            "'&(pound|#163);'i",
1183
-            "'&(copy|#169);'i"
1184
-        ]; // evaluate as php
1185
-
1186
-        $replace = [
1187
-            '',
1188
-            '',
1189
-            '',
1190
-            "\\1",
1191
-            '"',
1192
-            '&',
1193
-            '<',
1194
-            '>',
1195
-            ' ',
1196
-            chr(161),
1197
-            chr(162),
1198
-            chr(163),
1199
-            chr(169),
1200
-        ];
1201
-
1202
-        $text = preg_replace($search, $replace, $document);
1203
-
1204
-        preg_replace_callback('/&#(\d+);/', function ($matches) {
1205
-            return chr($matches[1]);
1206
-        }, $document);
1207
-
1208
-        return $text;
1209
-    }
1210
-
1211
-    /**
1212
-     * @author pillepop2003 at yahoo dot de
1213
-     *
1214
-     * Use this snippet to extract any float out of a string. You can choose how a single dot is treated with the (bool) 'single_dot_as_decimal' directive.
1215
-     * This function should be able to cover almost all floats that appear in an european environment.
1216
-     * @param            $str
1217
-     * @param  bool      $set
1218
-     * @return float|int
1219
-     */
1220
-    public static function getFloat($str, $set = false)
1221
-    {
1222
-        if (preg_match("/([0-9\.,-]+)/", $str, $match)) {
1223
-            // Found number in $str, so set $str that number
1224
-            $str = $match[0];
1225
-            if (false !== strpos($str, ',')) {
1226
-                // A comma exists, that makes it easy, cos we assume it separates the decimal part.
1227
-                $str = str_replace('.', '', $str);    // Erase thousand seps
1228
-                $str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1229
-
1230
-                return (float)$str;
1231
-            } else {
1232
-                // No comma exists, so we have to decide, how a single dot shall be treated
1233
-                if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) {
1234
-                    // Treat single dot as decimal separator
1235
-                    return (float)$str;
1236
-                } else {
1237
-                    //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1238
-                    // Else, treat all dots as thousand seps
1239
-                    $str = str_replace('.', '', $str);    // Erase thousand seps
1240
-
1241
-                    return (float)$str;
1242
-                }
1243
-            }
1244
-        } else {
1245
-            // No number found, return zero
1246
-            return 0;
1247
-        }
1248
-    }
1249
-
1250
-    /**
1251
-     * @param                         $var
1252
-     * @param  bool                   $currencyObj
1253
-     * @return float|int|mixed|string
1254
-     */
1255
-    public static function getCurrency($var, $currencyObj = false)
1256
-    {
1257
-        $ret = static::getFloat($var, ['single_dot_as_decimal' => true]);
1258
-        $ret = round($ret, 2);
1259
-        // make sur we have at least .00 in the $var
1260
-        $decimal_section_original = strstr($ret, '.');
1261
-        $decimal_section          = $decimal_section_original;
1262
-        if ($decimal_section) {
1263
-            if (1 == strlen($decimal_section)) {
1264
-                $decimal_section = '.00';
1265
-            } elseif (2 == strlen($decimal_section)) {
1266
-                $decimal_section .= '0';
1267
-            }
1268
-            $ret = str_replace($decimal_section_original, $decimal_section, $ret);
1269
-        } else {
1270
-            $ret .= '.00';
1271
-        }
1272
-        if ($currencyObj) {
1273
-            $ret = $ret . ' ' . $currencyObj->getCode();
1274
-        }
1275
-
1276
-        return $ret;
1277
-    }
1278
-
1279
-    /**
1280
-     * @param $var
1281
-     * @return float|int|mixed|string
1282
-     */
1283
-    public static function float($var)
1284
-    {
1285
-        return static::getCurrency($var);
1286
-    }
1287
-
1288
-    /**
1289
-     * @param  bool $moduleName
1290
-     * @return string
1291
-     */
1292
-    public static function getModuleAdminLink($moduleName = false)
1293
-    {
1294
-        global $xoopsModule;
1295
-        if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) {
1296
-            $moduleName = $xoopsModule->getVar('dirname');
1297
-        }
1298
-        $ret = '';
1299
-        if ($moduleName) {
1300
-            $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1301
-        }
1302
-
1303
-        return $ret;
1304
-    }
1305
-
1306
-    /**
1307
-     * @return array|bool
1308
-     */
1309
-    public static function getEditors()
1310
-    {
1311
-        $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1312
-        if (!file_exists($filename)) {
1313
-            return false;
1314
-        }
1315
-        require_once $filename;
1316
-        $xoopseditorHandler = \XoopsEditorHandler::getInstance();
1317
-        $aList              = $xoopseditorHandler->getList();
1318
-        $ret                = [];
1319
-        foreach ($aList as $k => $v) {
1320
-            $ret[$v] = $k;
1321
-        }
1322
-
1323
-        return $ret;
1324
-    }
1325
-
1326
-    /**
1327
-     * @param $moduleName
1328
-     * @param $items
1329
-     * @return array
1330
-     */
1331
-    public static function getTablesArray($moduleName, $items)
1332
-    {
1333
-        $ret = [];
1334
-        foreach ($items as $item) {
1335
-            $ret[] = $moduleName . '_' . $item;
1336
-        }
1337
-        $ret[] = $moduleName . '_meta';
1338
-
1339
-        return $ret;
1340
-    }
879
+	public static function getModFooter()
880
+	{
881
+		global $xoopsConfig, $xoopsModule;
882
+
883
+		require_once XOOPS_ROOT_PATH . '/class/template.php';
884
+		$tpl = new \XoopsTpl();
885
+
886
+		$hModule      = xoops_getHandler('module');
887
+		$versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
888
+		$modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
889
+		$modfooter    = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>";
890
+		$tpl->assign('modfooter', $modfooter);
891
+
892
+		if (!defined('_AM_SOBJECT_XOOPS_PRO')) {
893
+			define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?');
894
+		}
895
+		$smartobjectConfig = static::getModuleConfig('smartobject');
896
+		$tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
897
+		$tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl');
898
+	}
899
+
900
+	public static function getXoopsCpFooter()
901
+	{
902
+		static::getModFooter();
903
+		xoops_cp_footer();
904
+	}
905
+
906
+	/**
907
+	 * @param $text
908
+	 * @return mixed
909
+	 */
910
+	public static function sanitizeForCommonTags($text)
911
+	{
912
+		global $xoopsConfig;
913
+		$text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text);
914
+		$text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text);
915
+
916
+		return $text;
917
+	}
918
+
919
+	/**
920
+	 * @param $src
921
+	 */
922
+	public static function addScript($src)
923
+	{
924
+		echo '<script src="' . $src . '" type="text/javascript"></script>';
925
+	}
926
+
927
+	/**
928
+	 * @param $src
929
+	 */
930
+	public static function addStyle($src)
931
+	{
932
+		if ('smartobject' === $src) {
933
+			$src = SMARTOBJECT_URL . 'assets/css/module.css';
934
+		}
935
+		echo static::getCssLink($src);
936
+	}
937
+
938
+	public static function addAdminAjaxSupport()
939
+	{
940
+		static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
941
+		static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
942
+		static::addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
943
+	}
944
+
945
+	/**
946
+	 * @param $text
947
+	 * @return mixed
948
+	 */
949
+	public static function sanitizeForSmartpopupLink($text)
950
+	{
951
+		$patterns[]     = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU";
952
+		$replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>";
953
+		$ret            = preg_replace($patterns, $replacements, $text);
954
+
955
+		return $ret;
956
+	}
957
+
958
+	/**
959
+	 * Finds the width and height of an image (can also be a flash file)
960
+	 *
961
+	 * @credit phppp
962
+	 *
963
+	 * @var    string $url    path of the image file
964
+	 * @var    string $width  reference to the width
965
+	 * @var    string $height reference to the height
966
+	 * @return bool   false if impossible to find dimension
967
+	 */
968
+	public static function getImageSize($url, & $width, & $height)
969
+	{
970
+		if (empty($width) || empty($height)) {
971
+			if (!$dimension = @ getimagesize($url)) {
972
+				return false;
973
+			}
974
+			if (!empty($width)) {
975
+				$height = $dimension[1] * $width / $dimension[0];
976
+			} elseif (!empty($height)) {
977
+				$width = $dimension[0] * $height / $dimension[1];
978
+			} else {
979
+				list($width, $height) = [
980
+					$dimension[0],
981
+					$dimension[1]
982
+				];
983
+			}
984
+
985
+			return true;
986
+		} else {
987
+			return true;
988
+		}
989
+	}
990
+
991
+	/**
992
+	 * Convert characters to decimal values
993
+	 *
994
+	 * @author eric.wallet at yahoo.fr
995
+	 * @link   http://ca.php.net/manual/en/function.htmlentities.php#69913
996
+	 * @param $str
997
+	 * @return mixed
998
+	 */
999
+	public static function getHtmlnumericentities($str)
1000
+	{
1001
+		//    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
1002
+		return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) {
1003
+			return '&#' . ord($m[0]) . chr(59);
1004
+		}, $str);
1005
+	}
1006
+
1007
+	/**
1008
+	 * @param        $name
1009
+	 * @param  bool  $optional
1010
+	 * @return mixed
1011
+	 */
1012
+	public static function getCoreHandler($name, $optional = false)
1013
+	{
1014
+		static $handlers;
1015
+		$name = strtolower(trim($name));
1016
+		if (!isset($handlers[$name])) {
1017
+			if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1018
+				require_once $hnd_file;
1019
+			}
1020
+			$class = 'Xoops' . ucfirst($name) . 'Handler';
1021
+			if (class_exists($class)) {
1022
+				$handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops');
1023
+			}
1024
+		}
1025
+		if (!isset($handlers[$name]) && !$optional) {
1026
+			trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1027
+		}
1028
+		if (isset($handlers[$name])) {
1029
+			return $handlers[$name];
1030
+		}
1031
+		$inst = false;
1032
+	}
1033
+
1034
+	/**
1035
+	 * @param $matches
1036
+	 * @return string
1037
+	 */
1038
+	public static function sanitizeAdsenses_callback($matches)
1039
+	{
1040
+		global $smartobjectAdsenseHandler;
1041
+		if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) {
1042
+			$adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]];
1043
+			$ret        = $adsenseObj->render();
1044
+
1045
+			return $ret;
1046
+		} else {
1047
+			return '';
1048
+		}
1049
+	}
1050
+
1051
+	/**
1052
+	 * @param $text
1053
+	 * @return mixed
1054
+	 */
1055
+	public static function sanitizeAdsenses($text)
1056
+	{
1057
+		$patterns     = [];
1058
+		$replacements = [];
1059
+
1060
+		$patterns[] = "/\[adsense](.*)\[\/adsense\]/sU";
1061
+		$text       = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeAdsenses_callback', $text);
1062
+
1063
+		return $text;
1064
+	}
1065
+
1066
+	/**
1067
+	 * @param $matches
1068
+	 * @return string
1069
+	 */
1070
+	public static function sanitizeCustomtags_callback($matches)
1071
+	{
1072
+		global $smartobjectCustomtagHandler;
1073
+		if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) {
1074
+			$customObj = $smartobjectCustomtagHandler->objects[$matches[1]];
1075
+			$ret       = $customObj->renderWithPhp();
1076
+
1077
+			return $ret;
1078
+		} else {
1079
+			return '';
1080
+		}
1081
+	}
1082
+
1083
+	/**
1084
+	 * @param $text
1085
+	 * @return mixed
1086
+	 */
1087
+	public static function sanitizeCustomtags($text)
1088
+	{
1089
+		$patterns     = [];
1090
+		$replacements = [];
1091
+
1092
+		$patterns[] = "/\[customtag](.*)\[\/customtag\]/sU";
1093
+		$text       = preg_replace_callback($patterns, 'Smartobject\Utility::sanitizeCustomtags_callback', $text);
1094
+
1095
+		return $text;
1096
+	}
1097
+
1098
+	/**
1099
+	 * @param $module
1100
+	 * @param $file
1101
+	 */
1102
+	public static function loadLanguageFile($module, $file)
1103
+	{
1104
+		global $xoopsConfig;
1105
+
1106
+		$filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1107
+		if (!file_exists($filename)) {
1108
+			$filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1109
+		}
1110
+		if (file_exists($filename)) {
1111
+			require_once $filename;
1112
+		}
1113
+	}
1114
+
1115
+	public static function loadCommonLanguageFile()
1116
+	{
1117
+		static::loadLanguageFile('smartobject', 'common');
1118
+	}
1119
+
1120
+	/**
1121
+	 * @param               $text
1122
+	 * @param  bool         $keyword
1123
+	 * @return mixed|string
1124
+	 */
1125
+	public static function purifyText($text, $keyword = false)
1126
+	{
1127
+		global $myts;
1128
+		$text = str_replace('&nbsp;', ' ', $text);
1129
+		$text = str_replace('<br>', ' ', $text);
1130
+		$text = str_replace('<br>', ' ', $text);
1131
+		$text = str_replace('<br', ' ', $text);
1132
+		$text = strip_tags($text);
1133
+		$text = html_entity_decode($text);
1134
+		$text = $myts->undoHtmlSpecialChars($text);
1135
+		$text = str_replace(')', ' ', $text);
1136
+		$text = str_replace('(', ' ', $text);
1137
+		$text = str_replace(':', ' ', $text);
1138
+		$text = str_replace('&euro', ' euro ', $text);
1139
+		$text = str_replace('&hellip', '...', $text);
1140
+		$text = str_replace('&rsquo', ' ', $text);
1141
+		$text = str_replace('!', ' ', $text);
1142
+		$text = str_replace('?', ' ', $text);
1143
+		$text = str_replace('"', ' ', $text);
1144
+		$text = str_replace('-', ' ', $text);
1145
+		$text = str_replace('\n', ' ', $text);
1146
+		$text = str_replace('&#8213;', ' ', $text);
1147
+
1148
+		if ($keyword) {
1149
+			$text = str_replace('.', ' ', $text);
1150
+			$text = str_replace(',', ' ', $text);
1151
+			$text = str_replace('\'', ' ', $text);
1152
+		}
1153
+		$text = str_replace(';', ' ', $text);
1154
+
1155
+		return $text;
1156
+	}
1157
+
1158
+	/**
1159
+	 * @param $document
1160
+	 * @return mixed
1161
+	 */
1162
+	public static function getHtml2text($document)
1163
+	{
1164
+		// PHP Manual:: function preg_replace
1165
+		// $document should contain an HTML document.
1166
+		// This will remove HTML tags, javascript sections
1167
+		// and white space. It will also convert some
1168
+		// common HTML entities to their text equivalent.
1169
+		// Credits: newbb2
1170
+		$search = [
1171
+			"'<script[^>]*?>.*?</script>'si", // Strip out javascript
1172
+			"'<img.*?>'si", // Strip out img tags
1173
+			"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
1174
+			"'([\r\n])[\s]+'", // Strip out white space
1175
+			"'&(quot|#34);'i", // Replace HTML entities
1176
+			"'&(amp|#38);'i",
1177
+			"'&(lt|#60);'i",
1178
+			"'&(gt|#62);'i",
1179
+			"'&(nbsp|#160);'i",
1180
+			"'&(iexcl|#161);'i",
1181
+			"'&(cent|#162);'i",
1182
+			"'&(pound|#163);'i",
1183
+			"'&(copy|#169);'i"
1184
+		]; // evaluate as php
1185
+
1186
+		$replace = [
1187
+			'',
1188
+			'',
1189
+			'',
1190
+			"\\1",
1191
+			'"',
1192
+			'&',
1193
+			'<',
1194
+			'>',
1195
+			' ',
1196
+			chr(161),
1197
+			chr(162),
1198
+			chr(163),
1199
+			chr(169),
1200
+		];
1201
+
1202
+		$text = preg_replace($search, $replace, $document);
1203
+
1204
+		preg_replace_callback('/&#(\d+);/', function ($matches) {
1205
+			return chr($matches[1]);
1206
+		}, $document);
1207
+
1208
+		return $text;
1209
+	}
1210
+
1211
+	/**
1212
+	 * @author pillepop2003 at yahoo dot de
1213
+	 *
1214
+	 * Use this snippet to extract any float out of a string. You can choose how a single dot is treated with the (bool) 'single_dot_as_decimal' directive.
1215
+	 * This function should be able to cover almost all floats that appear in an european environment.
1216
+	 * @param            $str
1217
+	 * @param  bool      $set
1218
+	 * @return float|int
1219
+	 */
1220
+	public static function getFloat($str, $set = false)
1221
+	{
1222
+		if (preg_match("/([0-9\.,-]+)/", $str, $match)) {
1223
+			// Found number in $str, so set $str that number
1224
+			$str = $match[0];
1225
+			if (false !== strpos($str, ',')) {
1226
+				// A comma exists, that makes it easy, cos we assume it separates the decimal part.
1227
+				$str = str_replace('.', '', $str);    // Erase thousand seps
1228
+				$str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1229
+
1230
+				return (float)$str;
1231
+			} else {
1232
+				// No comma exists, so we have to decide, how a single dot shall be treated
1233
+				if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) {
1234
+					// Treat single dot as decimal separator
1235
+					return (float)$str;
1236
+				} else {
1237
+					//echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1238
+					// Else, treat all dots as thousand seps
1239
+					$str = str_replace('.', '', $str);    // Erase thousand seps
1240
+
1241
+					return (float)$str;
1242
+				}
1243
+			}
1244
+		} else {
1245
+			// No number found, return zero
1246
+			return 0;
1247
+		}
1248
+	}
1249
+
1250
+	/**
1251
+	 * @param                         $var
1252
+	 * @param  bool                   $currencyObj
1253
+	 * @return float|int|mixed|string
1254
+	 */
1255
+	public static function getCurrency($var, $currencyObj = false)
1256
+	{
1257
+		$ret = static::getFloat($var, ['single_dot_as_decimal' => true]);
1258
+		$ret = round($ret, 2);
1259
+		// make sur we have at least .00 in the $var
1260
+		$decimal_section_original = strstr($ret, '.');
1261
+		$decimal_section          = $decimal_section_original;
1262
+		if ($decimal_section) {
1263
+			if (1 == strlen($decimal_section)) {
1264
+				$decimal_section = '.00';
1265
+			} elseif (2 == strlen($decimal_section)) {
1266
+				$decimal_section .= '0';
1267
+			}
1268
+			$ret = str_replace($decimal_section_original, $decimal_section, $ret);
1269
+		} else {
1270
+			$ret .= '.00';
1271
+		}
1272
+		if ($currencyObj) {
1273
+			$ret = $ret . ' ' . $currencyObj->getCode();
1274
+		}
1275
+
1276
+		return $ret;
1277
+	}
1278
+
1279
+	/**
1280
+	 * @param $var
1281
+	 * @return float|int|mixed|string
1282
+	 */
1283
+	public static function float($var)
1284
+	{
1285
+		return static::getCurrency($var);
1286
+	}
1287
+
1288
+	/**
1289
+	 * @param  bool $moduleName
1290
+	 * @return string
1291
+	 */
1292
+	public static function getModuleAdminLink($moduleName = false)
1293
+	{
1294
+		global $xoopsModule;
1295
+		if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) {
1296
+			$moduleName = $xoopsModule->getVar('dirname');
1297
+		}
1298
+		$ret = '';
1299
+		if ($moduleName) {
1300
+			$ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1301
+		}
1302
+
1303
+		return $ret;
1304
+	}
1305
+
1306
+	/**
1307
+	 * @return array|bool
1308
+	 */
1309
+	public static function getEditors()
1310
+	{
1311
+		$filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1312
+		if (!file_exists($filename)) {
1313
+			return false;
1314
+		}
1315
+		require_once $filename;
1316
+		$xoopseditorHandler = \XoopsEditorHandler::getInstance();
1317
+		$aList              = $xoopseditorHandler->getList();
1318
+		$ret                = [];
1319
+		foreach ($aList as $k => $v) {
1320
+			$ret[$v] = $k;
1321
+		}
1322
+
1323
+		return $ret;
1324
+	}
1325
+
1326
+	/**
1327
+	 * @param $moduleName
1328
+	 * @param $items
1329
+	 * @return array
1330
+	 */
1331
+	public static function getTablesArray($moduleName, $items)
1332
+	{
1333
+		$ret = [];
1334
+		foreach ($items as $item) {
1335
+			$ret[] = $moduleName . '_' . $item;
1336
+		}
1337
+		$ret[] = $moduleName . '_meta';
1338
+
1339
+		return $ret;
1340
+	}
1341 1341
     
1342 1342
     
1343 1343
 }
Please login to merge, or discard this patch.
class/Helper.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -25,55 +25,55 @@
 block discarded – undo
25 25
  */
26 26
 class Helper extends \Xmf\Module\Helper
27 27
 {
28
-    public $debug;
28
+	public $debug;
29 29
 
30
-    /**
31
-     *
32
-     * @param bool $debug
33
-     */
34
-    protected function __construct($debug = false)
35
-    {
36
-        $this->debug   = $debug;
37
-       $moduleDirName = basename(dirname(__DIR__));
38
-       parent::__construct($moduleDirName);
39
-    }
30
+	/**
31
+	 *
32
+	 * @param bool $debug
33
+	 */
34
+	protected function __construct($debug = false)
35
+	{
36
+		$this->debug   = $debug;
37
+	   $moduleDirName = basename(dirname(__DIR__));
38
+	   parent::__construct($moduleDirName);
39
+	}
40 40
 
41
-    /**
42
-     * @param bool $debug
43
-     *
44
-     * @return \Xmf\Module\Helper
45
-     */
46
-    public static function getInstance($debug = false)
47
-    {
48
-        static $instance;
49
-        if (null === $instance) {
50
-            $instance = new static($debug);
51
-        }
41
+	/**
42
+	 * @param bool $debug
43
+	 *
44
+	 * @return \Xmf\Module\Helper
45
+	 */
46
+	public static function getInstance($debug = false)
47
+	{
48
+		static $instance;
49
+		if (null === $instance) {
50
+			$instance = new static($debug);
51
+		}
52 52
 
53
-        return $instance;
54
-    }
53
+		return $instance;
54
+	}
55 55
 
56
-    /**
57
-     * @return string
58
-     */
59
-    public function getDirname()
60
-    {
61
-        return $this->dirname;
62
-    }
56
+	/**
57
+	 * @return string
58
+	 */
59
+	public function getDirname()
60
+	{
61
+		return $this->dirname;
62
+	}
63 63
 
64
-    /**
65
-     * Get an Object Handler
66
-     *
67
-     * @param string $name name of handler to load
68
-     *
69
-     * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler
70
-     */
71
-    public function getHandler($name)
72
-    {
73
-        $ret   = false;
74
-        $db    = \XoopsDatabaseFactory::getDatabaseConnection();
75
-        $class = '\\XoopsModules\\' . ucfirst(strtolower(basename(dirname(__DIR__)))) . '\\' . $name . 'Handler';
76
-        $ret   = new $class($db);
77
-        return $ret;
78
-    }
64
+	/**
65
+	 * Get an Object Handler
66
+	 *
67
+	 * @param string $name name of handler to load
68
+	 *
69
+	 * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler
70
+	 */
71
+	public function getHandler($name)
72
+	{
73
+		$ret   = false;
74
+		$db    = \XoopsDatabaseFactory::getDatabaseConnection();
75
+		$class = '\\XoopsModules\\' . ucfirst(strtolower(basename(dirname(__DIR__)))) . '\\' . $name . 'Handler';
76
+		$ret   = new $class($db);
77
+		return $ret;
78
+	}
79 79
 }
Please login to merge, or discard this patch.