Completed
Push — master ( b3fce7...c570af )
by Michael
02:32
created
class/MetaGen.php 2 patches
Indentation   +387 added lines, -387 removed lines patch added patch discarded remove patch
@@ -22,357 +22,357 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class MetaGen
24 24
 {
25
-    public $_myts;
26
-
27
-    public $_title;
28
-    public $_original_title;
29
-    public $_keywords;
30
-    public $_meta_description;
31
-    public $_categoryPath;
32
-    public $_description;
33
-    public $_minChar = 4;
34
-
35
-    /**
36
-     * SmartMetaGen constructor.
37
-     * @param      $title
38
-     * @param bool $keywords
39
-     * @param bool $description
40
-     * @param bool $categoryPath
41
-     */
42
-    public function __construct($title, $keywords = false, $description = false, $categoryPath = false)
43
-    {
44
-        $this->_myts = \MyTextSanitizer::getInstance();
45
-        $this->setCategoryPath($categoryPath);
46
-        $this->setTitle($title);
47
-        $this->setDescription($description);
48
-
49
-        if (!$keywords) {
50
-            $keywords = $this->createMetaKeywords();
51
-        }
52
-
53
-        /*      $myts = \MyTextSanitizer::getInstance();
25
+	public $_myts;
26
+
27
+	public $_title;
28
+	public $_original_title;
29
+	public $_keywords;
30
+	public $_meta_description;
31
+	public $_categoryPath;
32
+	public $_description;
33
+	public $_minChar = 4;
34
+
35
+	/**
36
+	 * SmartMetaGen constructor.
37
+	 * @param      $title
38
+	 * @param bool $keywords
39
+	 * @param bool $description
40
+	 * @param bool $categoryPath
41
+	 */
42
+	public function __construct($title, $keywords = false, $description = false, $categoryPath = false)
43
+	{
44
+		$this->_myts = \MyTextSanitizer::getInstance();
45
+		$this->setCategoryPath($categoryPath);
46
+		$this->setTitle($title);
47
+		$this->setDescription($description);
48
+
49
+		if (!$keywords) {
50
+			$keywords = $this->createMetaKeywords();
51
+		}
52
+
53
+		/*      $myts = \MyTextSanitizer::getInstance();
54 54
          if (method_exists($myts, 'formatForML')) {
55 55
          $keywords = $myts->formatForML($keywords);
56 56
          $description = $myts->formatForML($description);
57 57
          }
58 58
          */
59
-        $this->setKeywords($keywords);
60
-    }
61
-
62
-    /**
63
-     * Return true if the string is length > 0
64
-     *
65
-     * @credit psylove
66
-     *
67
-     * @var    string $string Chaine de caract�re
68
-     * @return boolean
69
-     */
70
-    public function emptyString($var)
71
-    {
72
-        return (strlen($var) > 0);
73
-    }
74
-
75
-    /**
76
-     * Create a title for the short_url field of an article
77
-     *
78
-     * @credit psylove
79
-     *
80
-     * @var    string      $title title of the article
81
-     * @param  bool|string $withExt
82
-     * @return string      sort_url for the article
83
-     */
84
-    public function generateSeoTitle($title = '', $withExt = true)
85
-    {
86
-        // Transformation de la chaine en minuscule
87
-        // Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus
88
-        $title = rawurlencode(strtolower($title));
89
-
90
-        // Transformation des ponctuations
91
-        $pattern = [
92
-            '/%09/', // Tab
93
-            '/%20/', // Space
94
-            '/%21/', // !
95
-            '/%22/', // "
96
-            '/%23/', // #
97
-            '/%25/', // %
98
-            '/%26/', // &
99
-            '/%27/', // '
100
-            '/%28/', // (
101
-            '/%29/', // )
102
-            '/%2C/', // ,
103
-            '/%2F/', // /
104
-            '/%3A/', // :
105
-            '/%3B/', // ;
106
-            '/%3C/', // <
107
-            '/%3D/', // =
108
-            '/%3E/', // >
109
-            '/%3F/', // ?
110
-            '/%40/', // @
111
-            '/%5B/', // [
112
-            '/%5C/', // \
113
-            '/%5D/', // ]
114
-            '/%5E/', // ^
115
-            '/%7B/', // {
116
-            '/%7C/', // |
117
-            '/%7D/', // }
118
-            '/%7E/', // ~
119
-            "/\./" // .
120
-        ];
121
-        $rep_pat = [
122
-            '-',
123
-            '-',
124
-            '-',
125
-            '-',
126
-            '-',
127
-            '-100',
128
-            '-',
129
-            '-',
130
-            '-',
131
-            '-',
132
-            '-',
133
-            '-',
134
-            '-',
135
-            '-',
136
-            '-',
137
-            '-',
138
-            '-',
139
-            '-',
140
-            '-at-',
141
-            '-',
142
-            '-',
143
-            '-',
144
-            '-',
145
-            '-',
146
-            '-',
147
-            '-',
148
-            '-',
149
-            '-'
150
-        ];
151
-        $title   = preg_replace($pattern, $rep_pat, $title);
152
-
153
-        // Transformation des caractères accentués
154
-        $pattern = [
155
-            '/%B0/', // °
156
-            '/%E8/', // è
157
-            '/%E9/', // é
158
-            '/%EA/', // ê
159
-            '/%EB/', // ë
160
-            '/%E7/', // ç
161
-            '/%E0/', // à
162
-            '/%E2/', // â
163
-            '/%E4/', // ä
164
-            '/%EE/', // î
165
-            '/%EF/', // ï
166
-            '/%F9/', // ù
167
-            '/%FC/', // ü
168
-            '/%FB/', // û
169
-            '/%F4/', // ô
170
-            '/%F6/', // ö
171
-        ];
172
-        $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'];
173
-        $title   = preg_replace($pattern, $rep_pat, $title);
174
-
175
-        $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
176
-        $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau
177
-        $title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
178
-
179
-        if (count($title) > 0) {
180
-            if ($withExt) {
181
-                $title .= '.html';
182
-            }
183
-
184
-            return $title;
185
-        } else {
186
-            return '';
187
-        }
188
-    }
189
-
190
-    /**
191
-     * @param $document
192
-     * @return mixed
193
-     */
194
-    public function html2text($document)
195
-    {
196
-        return Smartobject\Utility::getHtml2text($document);
197
-    }
198
-
199
-    /**
200
-     * @param $title
201
-     */
202
-    public function setTitle($title)
203
-    {
204
-        global $xoopsModule;
205
-        /** @var Smartobject\Helper $helper */
206
-        $helper = Smartobject\Helper::getInstance();
207
-
208
-        $this->_title          = $this->html2text($title);
209
-        $this->_title          = $this->purifyText($this->_title);
210
-        $this->_original_title = $this->_title;
211
-
212
-        $moduleName = $xoopsModule->getVar('name');
213
-
214
-        $titleTag = [];
215
-
216
-        $show_mod_name_breadcrumb = null !==($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true;
217
-
218
-        if ($moduleName && $show_mod_name_breadcrumb) {
219
-            $titleTag['module'] = $moduleName;
220
-        }
221
-
222
-        if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) {
223
-            $titleTag['title'] = $this->_title;
224
-        }
225
-
226
-        if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) {
227
-            $titleTag['category'] = $this->_categoryPath;
228
-        }
229
-
230
-        $ret = isset($titleTag['title']) ? $titleTag['title'] : '';
231
-
232
-        if (isset($titleTag['category']) && '' !== $titleTag['category']) {
233
-            if ('' !== $ret) {
234
-                $ret .= ' - ';
235
-            }
236
-            $ret .= $titleTag['category'];
237
-        }
238
-        if (isset($titleTag['module']) && '' !== $titleTag['module']) {
239
-            if ('' !== $ret) {
240
-                $ret .= ' - ';
241
-            }
242
-            $ret .= $titleTag['module'];
243
-        }
244
-        $this->_title = $ret;
245
-    }
246
-
247
-    /**
248
-     * @param $keywords
249
-     */
250
-    public function setKeywords($keywords)
251
-    {
252
-        $this->_keywords = $keywords;
253
-    }
254
-
255
-    /**
256
-     * @param $categoryPath
257
-     */
258
-    public function setCategoryPath($categoryPath)
259
-    {
260
-        $categoryPath        = $this->html2text($categoryPath);
261
-        $this->_categoryPath = $categoryPath;
262
-    }
263
-
264
-    /**
265
-     * @param $description
266
-     */
267
-    public function setDescription($description)
268
-    {
269
-        if (!$description) {
270
-            /** @var Smartobject\Helper $helper */
271
-            $helper = Smartobject\Helper::getInstance();
272
-
273
-            if  (null !== ($helper->getConfig('module_meta_description'))) {
274
-                $description = $helper->getConfig('module_meta_description');
275
-            }
276
-        }
277
-
278
-        $description = $this->html2text($description);
279
-        $description = $this->purifyText($description);
280
-
281
-        $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description);
282
-        $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description);
283
-        $description = preg_replace('/[ ]* [ ]*/', ' ', $description);
284
-        $description = stripslashes($description);
285
-
286
-        $this->_description      = $description;
287
-        $this->_meta_description = $this->createMetaDescription();
288
-    }
289
-
290
-    public function createTitleTag()
291
-    {
292
-    }
293
-
294
-    /**
295
-     * @param               $text
296
-     * @param  bool         $keyword
297
-     * @return mixed|string
298
-     */
299
-    public function purifyText($text, $keyword = false)
300
-    {
301
-        return Smartobject\Utility::purifyText($text, $keyword);
302
-    }
303
-
304
-    /**
305
-     * @param  int $maxWords
306
-     * @return string
307
-     */
308
-    public function createMetaDescription($maxWords = 100)
309
-    {
310
-        $words = [];
311
-        $words = explode(' ', $this->_description);
312
-
313
-        // Only keep $maxWords words
314
-        $newWords = [];
315
-        $i        = 0;
316
-
317
-        while ($i < $maxWords - 1 && $i < count($words)) {
318
-            $newWords[] = $words[$i];
319
-            ++$i;
320
-        }
321
-        $ret = implode(' ', $newWords);
322
-
323
-        return $ret;
324
-    }
325
-
326
-    /**
327
-     * @param $text
328
-     * @param $minChar
329
-     * @return array
330
-     */
331
-    public function findMetaKeywords($text, $minChar)
332
-    {
333
-        $keywords = [];
334
-
335
-        $text = $this->purifyText($text);
336
-        $text = $this->html2text($text);
337
-
338
-        $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text);
339
-        $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text);
340
-        $text = preg_replace('/[ ]* [ ]*/', ' ', $text);
341
-        $text = stripslashes($text);
342
-        $text =
343
-
344
-        $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY);
345
-
346
-        foreach ($originalKeywords as $originalKeyword) {
347
-            $secondRoundKeywords = explode("'", $originalKeyword);
348
-            foreach ($secondRoundKeywords as $secondRoundKeyword) {
349
-                if (strlen($secondRoundKeyword) >= $minChar) {
350
-                    if (!in_array($secondRoundKeyword, $keywords)) {
351
-                        $keywords[] = trim($secondRoundKeyword);
352
-                    }
353
-                }
354
-            }
355
-        }
356
-
357
-        return $keywords;
358
-    }
359
-
360
-    /**
361
-     * @return string
362
-     */
363
-    public function createMetaKeywords()
364
-    {
365
-        /** @var Smartobject\Helper $helper */
366
-        $helper = Smartobject\Helper::getInstance();
367
-
368
-        $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
369
-        if (null !== ($helper->getModule()) && null !== ($helper->getConfig('moduleMetaKeywords'))
370
-            && '' !== $helper->getConfig('moduleMetaKeywords')) {
371
-            $moduleKeywords = explode(',', $helper->getConfig('moduleMetaKeywords'));
372
-            $keywords       = array_merge($keywords, $moduleKeywords);
373
-        }
374
-
375
-        /* Commenting this out as it may cause problem on XOOPS ML websites
59
+		$this->setKeywords($keywords);
60
+	}
61
+
62
+	/**
63
+	 * Return true if the string is length > 0
64
+	 *
65
+	 * @credit psylove
66
+	 *
67
+	 * @var    string $string Chaine de caract�re
68
+	 * @return boolean
69
+	 */
70
+	public function emptyString($var)
71
+	{
72
+		return (strlen($var) > 0);
73
+	}
74
+
75
+	/**
76
+	 * Create a title for the short_url field of an article
77
+	 *
78
+	 * @credit psylove
79
+	 *
80
+	 * @var    string      $title title of the article
81
+	 * @param  bool|string $withExt
82
+	 * @return string      sort_url for the article
83
+	 */
84
+	public function generateSeoTitle($title = '', $withExt = true)
85
+	{
86
+		// Transformation de la chaine en minuscule
87
+		// Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus
88
+		$title = rawurlencode(strtolower($title));
89
+
90
+		// Transformation des ponctuations
91
+		$pattern = [
92
+			'/%09/', // Tab
93
+			'/%20/', // Space
94
+			'/%21/', // !
95
+			'/%22/', // "
96
+			'/%23/', // #
97
+			'/%25/', // %
98
+			'/%26/', // &
99
+			'/%27/', // '
100
+			'/%28/', // (
101
+			'/%29/', // )
102
+			'/%2C/', // ,
103
+			'/%2F/', // /
104
+			'/%3A/', // :
105
+			'/%3B/', // ;
106
+			'/%3C/', // <
107
+			'/%3D/', // =
108
+			'/%3E/', // >
109
+			'/%3F/', // ?
110
+			'/%40/', // @
111
+			'/%5B/', // [
112
+			'/%5C/', // \
113
+			'/%5D/', // ]
114
+			'/%5E/', // ^
115
+			'/%7B/', // {
116
+			'/%7C/', // |
117
+			'/%7D/', // }
118
+			'/%7E/', // ~
119
+			"/\./" // .
120
+		];
121
+		$rep_pat = [
122
+			'-',
123
+			'-',
124
+			'-',
125
+			'-',
126
+			'-',
127
+			'-100',
128
+			'-',
129
+			'-',
130
+			'-',
131
+			'-',
132
+			'-',
133
+			'-',
134
+			'-',
135
+			'-',
136
+			'-',
137
+			'-',
138
+			'-',
139
+			'-',
140
+			'-at-',
141
+			'-',
142
+			'-',
143
+			'-',
144
+			'-',
145
+			'-',
146
+			'-',
147
+			'-',
148
+			'-',
149
+			'-'
150
+		];
151
+		$title   = preg_replace($pattern, $rep_pat, $title);
152
+
153
+		// Transformation des caractères accentués
154
+		$pattern = [
155
+			'/%B0/', // °
156
+			'/%E8/', // è
157
+			'/%E9/', // é
158
+			'/%EA/', // ê
159
+			'/%EB/', // ë
160
+			'/%E7/', // ç
161
+			'/%E0/', // à
162
+			'/%E2/', // â
163
+			'/%E4/', // ä
164
+			'/%EE/', // î
165
+			'/%EF/', // ï
166
+			'/%F9/', // ù
167
+			'/%FC/', // ü
168
+			'/%FB/', // û
169
+			'/%F4/', // ô
170
+			'/%F6/', // ö
171
+		];
172
+		$rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'];
173
+		$title   = preg_replace($pattern, $rep_pat, $title);
174
+
175
+		$tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
176
+		$tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau
177
+		$title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
178
+
179
+		if (count($title) > 0) {
180
+			if ($withExt) {
181
+				$title .= '.html';
182
+			}
183
+
184
+			return $title;
185
+		} else {
186
+			return '';
187
+		}
188
+	}
189
+
190
+	/**
191
+	 * @param $document
192
+	 * @return mixed
193
+	 */
194
+	public function html2text($document)
195
+	{
196
+		return Smartobject\Utility::getHtml2text($document);
197
+	}
198
+
199
+	/**
200
+	 * @param $title
201
+	 */
202
+	public function setTitle($title)
203
+	{
204
+		global $xoopsModule;
205
+		/** @var Smartobject\Helper $helper */
206
+		$helper = Smartobject\Helper::getInstance();
207
+
208
+		$this->_title          = $this->html2text($title);
209
+		$this->_title          = $this->purifyText($this->_title);
210
+		$this->_original_title = $this->_title;
211
+
212
+		$moduleName = $xoopsModule->getVar('name');
213
+
214
+		$titleTag = [];
215
+
216
+		$show_mod_name_breadcrumb = null !==($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true;
217
+
218
+		if ($moduleName && $show_mod_name_breadcrumb) {
219
+			$titleTag['module'] = $moduleName;
220
+		}
221
+
222
+		if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) {
223
+			$titleTag['title'] = $this->_title;
224
+		}
225
+
226
+		if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) {
227
+			$titleTag['category'] = $this->_categoryPath;
228
+		}
229
+
230
+		$ret = isset($titleTag['title']) ? $titleTag['title'] : '';
231
+
232
+		if (isset($titleTag['category']) && '' !== $titleTag['category']) {
233
+			if ('' !== $ret) {
234
+				$ret .= ' - ';
235
+			}
236
+			$ret .= $titleTag['category'];
237
+		}
238
+		if (isset($titleTag['module']) && '' !== $titleTag['module']) {
239
+			if ('' !== $ret) {
240
+				$ret .= ' - ';
241
+			}
242
+			$ret .= $titleTag['module'];
243
+		}
244
+		$this->_title = $ret;
245
+	}
246
+
247
+	/**
248
+	 * @param $keywords
249
+	 */
250
+	public function setKeywords($keywords)
251
+	{
252
+		$this->_keywords = $keywords;
253
+	}
254
+
255
+	/**
256
+	 * @param $categoryPath
257
+	 */
258
+	public function setCategoryPath($categoryPath)
259
+	{
260
+		$categoryPath        = $this->html2text($categoryPath);
261
+		$this->_categoryPath = $categoryPath;
262
+	}
263
+
264
+	/**
265
+	 * @param $description
266
+	 */
267
+	public function setDescription($description)
268
+	{
269
+		if (!$description) {
270
+			/** @var Smartobject\Helper $helper */
271
+			$helper = Smartobject\Helper::getInstance();
272
+
273
+			if  (null !== ($helper->getConfig('module_meta_description'))) {
274
+				$description = $helper->getConfig('module_meta_description');
275
+			}
276
+		}
277
+
278
+		$description = $this->html2text($description);
279
+		$description = $this->purifyText($description);
280
+
281
+		$description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description);
282
+		$description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description);
283
+		$description = preg_replace('/[ ]* [ ]*/', ' ', $description);
284
+		$description = stripslashes($description);
285
+
286
+		$this->_description      = $description;
287
+		$this->_meta_description = $this->createMetaDescription();
288
+	}
289
+
290
+	public function createTitleTag()
291
+	{
292
+	}
293
+
294
+	/**
295
+	 * @param               $text
296
+	 * @param  bool         $keyword
297
+	 * @return mixed|string
298
+	 */
299
+	public function purifyText($text, $keyword = false)
300
+	{
301
+		return Smartobject\Utility::purifyText($text, $keyword);
302
+	}
303
+
304
+	/**
305
+	 * @param  int $maxWords
306
+	 * @return string
307
+	 */
308
+	public function createMetaDescription($maxWords = 100)
309
+	{
310
+		$words = [];
311
+		$words = explode(' ', $this->_description);
312
+
313
+		// Only keep $maxWords words
314
+		$newWords = [];
315
+		$i        = 0;
316
+
317
+		while ($i < $maxWords - 1 && $i < count($words)) {
318
+			$newWords[] = $words[$i];
319
+			++$i;
320
+		}
321
+		$ret = implode(' ', $newWords);
322
+
323
+		return $ret;
324
+	}
325
+
326
+	/**
327
+	 * @param $text
328
+	 * @param $minChar
329
+	 * @return array
330
+	 */
331
+	public function findMetaKeywords($text, $minChar)
332
+	{
333
+		$keywords = [];
334
+
335
+		$text = $this->purifyText($text);
336
+		$text = $this->html2text($text);
337
+
338
+		$text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text);
339
+		$text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text);
340
+		$text = preg_replace('/[ ]* [ ]*/', ' ', $text);
341
+		$text = stripslashes($text);
342
+		$text =
343
+
344
+		$originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY);
345
+
346
+		foreach ($originalKeywords as $originalKeyword) {
347
+			$secondRoundKeywords = explode("'", $originalKeyword);
348
+			foreach ($secondRoundKeywords as $secondRoundKeyword) {
349
+				if (strlen($secondRoundKeyword) >= $minChar) {
350
+					if (!in_array($secondRoundKeyword, $keywords)) {
351
+						$keywords[] = trim($secondRoundKeyword);
352
+					}
353
+				}
354
+			}
355
+		}
356
+
357
+		return $keywords;
358
+	}
359
+
360
+	/**
361
+	 * @return string
362
+	 */
363
+	public function createMetaKeywords()
364
+	{
365
+		/** @var Smartobject\Helper $helper */
366
+		$helper = Smartobject\Helper::getInstance();
367
+
368
+		$keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
369
+		if (null !== ($helper->getModule()) && null !== ($helper->getConfig('moduleMetaKeywords'))
370
+			&& '' !== $helper->getConfig('moduleMetaKeywords')) {
371
+			$moduleKeywords = explode(',', $helper->getConfig('moduleMetaKeywords'));
372
+			$keywords       = array_merge($keywords, $moduleKeywords);
373
+		}
374
+
375
+		/* Commenting this out as it may cause problem on XOOPS ML websites
376 376
          $return_keywords = array();
377 377
 
378 378
          // Cleaning for duplicate keywords
@@ -382,45 +382,45 @@  discard block
 block discarded – undo
382 382
          }
383 383
          }*/
384 384
 
385
-        // Only take the first 90 keywords
386
-        $newKeywords = [];
387
-        $i           = 0;
388
-        while ($i < 90 - 1 && isset($keywords[$i])) {
389
-            $newKeywords[] = $keywords[$i];
390
-            ++$i;
391
-        }
392
-        $ret = implode(', ', $newKeywords);
393
-
394
-        return $ret;
395
-    }
396
-
397
-    public function autoBuildMeta_keywords()
398
-    {
399
-    }
400
-
401
-    public function buildAutoMetaTags()
402
-    {
403
-        global $xoopsModule;
404
-        /** @var Smartobject\Helper $helper */
405
-        $helper = Smartobject\Helper::getInstance();
406
-
407
-        $this->_keywords         = $this->createMetaKeywords();
408
-        $this->_meta_description = $this->createMetaDescription();
409
-        $this->_title            = $this->createTitleTag();
410
-    }
411
-
412
-    public function createMetaTags()
413
-    {
414
-        global $xoopsTpl, $xoTheme;
415
-
416
-        if (is_object($xoTheme)) {
417
-            $xoTheme->addMeta('meta', 'keywords', $this->_keywords);
418
-            $xoTheme->addMeta('meta', 'description', $this->_description);
419
-            $xoTheme->addMeta('meta', 'title', $this->_title);
420
-        } else {
421
-            $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords);
422
-            $xoopsTpl->assign('xoops_meta_description', $this->_description);
423
-        }
424
-        $xoopsTpl->assign('xoops_pagetitle', $this->_title);
425
-    }
385
+		// Only take the first 90 keywords
386
+		$newKeywords = [];
387
+		$i           = 0;
388
+		while ($i < 90 - 1 && isset($keywords[$i])) {
389
+			$newKeywords[] = $keywords[$i];
390
+			++$i;
391
+		}
392
+		$ret = implode(', ', $newKeywords);
393
+
394
+		return $ret;
395
+	}
396
+
397
+	public function autoBuildMeta_keywords()
398
+	{
399
+	}
400
+
401
+	public function buildAutoMetaTags()
402
+	{
403
+		global $xoopsModule;
404
+		/** @var Smartobject\Helper $helper */
405
+		$helper = Smartobject\Helper::getInstance();
406
+
407
+		$this->_keywords         = $this->createMetaKeywords();
408
+		$this->_meta_description = $this->createMetaDescription();
409
+		$this->_title            = $this->createTitleTag();
410
+	}
411
+
412
+	public function createMetaTags()
413
+	{
414
+		global $xoopsTpl, $xoTheme;
415
+
416
+		if (is_object($xoTheme)) {
417
+			$xoTheme->addMeta('meta', 'keywords', $this->_keywords);
418
+			$xoTheme->addMeta('meta', 'description', $this->_description);
419
+			$xoTheme->addMeta('meta', 'title', $this->_title);
420
+		} else {
421
+			$xoopsTpl->assign('xoops_meta_keywords', $this->_keywords);
422
+			$xoopsTpl->assign('xoops_meta_description', $this->_description);
423
+		}
424
+		$xoopsTpl->assign('xoops_pagetitle', $this->_title);
425
+	}
426 426
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
         $titleTag = [];
215 215
 
216
-        $show_mod_name_breadcrumb = null !==($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true;
216
+        $show_mod_name_breadcrumb = null !== ($helper->getConfig('show_mod_name_breadcrumb')) ? $helper->getConfig('show_mod_name_breadcrumb') : true;
217 217
 
218 218
         if ($moduleName && $show_mod_name_breadcrumb) {
219 219
             $titleTag['module'] = $moduleName;
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
             /** @var Smartobject\Helper $helper */
271 271
             $helper = Smartobject\Helper::getInstance();
272 272
 
273
-            if  (null !== ($helper->getConfig('module_meta_description'))) {
273
+            if (null !== ($helper->getConfig('module_meta_description'))) {
274 274
                 $description = $helper->getConfig('module_meta_description');
275 275
             }
276 276
         }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
         /** @var Smartobject\Helper $helper */
366 366
         $helper = Smartobject\Helper::getInstance();
367 367
 
368
-        $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
368
+        $keywords = $this->findMetaKeywords($this->_original_title.' '.$this->_description, $this->_minChar);
369 369
         if (null !== ($helper->getModule()) && null !== ($helper->getConfig('moduleMetaKeywords'))
370 370
             && '' !== $helper->getConfig('moduleMetaKeywords')) {
371 371
             $moduleKeywords = explode(',', $helper->getConfig('moduleMetaKeywords'));
Please login to merge, or discard this patch.
class/BaseSmartObject.php 2 patches
Indentation   +1404 added lines, -1404 removed lines patch added patch discarded remove patch
@@ -20,31 +20,31 @@  discard block
 block discarded – undo
20 20
 require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
21 21
 
22 22
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
23
-    define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
23
+	define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
24 24
 }
25 25
 if (!defined('XOBJ_DTYPE_CURRENCY')) {
26
-    define('XOBJ_DTYPE_CURRENCY', 200);
26
+	define('XOBJ_DTYPE_CURRENCY', 200);
27 27
 }
28 28
 if (!defined('XOBJ_DTYPE_FLOAT')) {
29
-    define('XOBJ_DTYPE_FLOAT', 201);
29
+	define('XOBJ_DTYPE_FLOAT', 201);
30 30
 }
31 31
 if (!defined('XOBJ_DTYPE_TIME_ONLY')) {
32
-    define('XOBJ_DTYPE_TIME_ONLY', 202);
32
+	define('XOBJ_DTYPE_TIME_ONLY', 202);
33 33
 }
34 34
 if (!defined('XOBJ_DTYPE_URLLINK')) {
35
-    define('XOBJ_DTYPE_URLLINK', 203);
35
+	define('XOBJ_DTYPE_URLLINK', 203);
36 36
 }
37 37
 if (!defined('XOBJ_DTYPE_FILE')) {
38
-    define('XOBJ_DTYPE_FILE', 204);
38
+	define('XOBJ_DTYPE_FILE', 204);
39 39
 }
40 40
 if (!defined('XOBJ_DTYPE_IMAGE')) {
41
-    define('XOBJ_DTYPE_IMAGE', 205);
41
+	define('XOBJ_DTYPE_IMAGE', 205);
42 42
 }
43 43
 if (!defined('XOBJ_DTYPE_FORM_SECTION')) {
44
-    define('XOBJ_DTYPE_FORM_SECTION', 210);
44
+	define('XOBJ_DTYPE_FORM_SECTION', 210);
45 45
 }
46 46
 if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) {
47
-    define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
47
+	define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
48 48
 }
49 49
 
50 50
 /**
@@ -58,1402 +58,1402 @@  discard block
 block discarded – undo
58 58
  */
59 59
 class BaseSmartObject extends \XoopsObject
60 60
 {
61
-    public $_image_path;
62
-    public $_image_url;
63
-
64
-    public $seoEnabled   = false;
65
-    public $titleField;
66
-    public $summaryField = false;
67
-
68
-    /**
69
-     * Reference to the handler managing this object
70
-     *
71
-     * @var PersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
72
-     */
73
-    public $handler;
74
-
75
-    /**
76
-     * References to control objects, managing the form fields of this object
77
-     */
78
-    public $controls = [];
79
-
80
-    /**
81
-     * SmartObject constructor.
82
-     * @param $handler
83
-     */
84
-    public function __construct($handler)
85
-    {
86
-        $this->handler = $handler;
87
-    }
88
-
89
-    /**
90
-     * Checks if the user has a specific access on this object
91
-     *
92
-     * @param $perm_name
93
-     * @return bool: TRUE if user has access, false if not
94
-     * @internal param string $gperm_name name of the permission to test
95
-     */
96
-    public function accessGranted($perm_name)
97
-    {
98
-        $smartPermissionsHandler = new PermissionHandler($this->handler);
99
-
100
-        return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
101
-    }
102
-
103
-    /**
104
-     * @param      $section_name
105
-     * @param bool $value
106
-     * @param bool $hide
107
-     */
108
-    public function addFormSection($section_name, $value = false, $hide = false)
109
-    {
110
-        $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
111
-        $this->vars[$section_name]['hide'] = $hide;
112
-    }
113
-
114
-    /**
115
-     * @param $section_name
116
-     */
117
-    public function closeSection($section_name)
118
-    {
119
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
120
-    }
121
-
122
-    /**
123
-     *
124
-     * @param string $key          key of this field. This needs to be the name of the field in the related database table
125
-     * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
126
-     * @param mixed  $value        default value of this variable
127
-     * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
128
-     * @param int    $maxlength    maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
129
-     * @param string $options      does this data have any select options?
130
-     * @param bool   $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
131
-     * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
132
-     * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
133
-     * @param bool   $sortby       set to TRUE to make this field used to sort objects in SmartObjectTable
134
-     * @param bool   $persistent   set to FALSE if this field is not to be saved in the database
135
-     * @param bool   $displayOnForm
136
-     */
137
-    public function initVar(
138
-        $key,
139
-        $data_type,
140
-        $value = null,
141
-        $required = false,
142
-        $maxlength = null,
143
-        $options = '',
144
-        $multilingual = false,
145
-        $form_caption = '',
146
-        $form_dsc = '',
147
-        $sortby = false,
148
-        $persistent = true,
149
-        $displayOnForm = true
150
-    ) {
151
-        //url_ is reserved for files.
152
-        if (0 === strpos($key, 'url_')) {
153
-            trigger_error("Cannot use variable starting with 'url_'.");
154
-        }
155
-        parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
156
-        if ($this->handler && (!$form_caption || '' === $form_caption)) {
157
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
158
-            if (defined($dyn_form_caption)) {
159
-                $form_caption = constant($dyn_form_caption);
160
-            }
161
-        }
162
-        if ($this->handler && (!$form_dsc || '' === $form_dsc)) {
163
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
164
-            if (defined($dyn_form_dsc)) {
165
-                $form_dsc = constant($dyn_form_dsc);
166
-            }
167
-        }
168
-
169
-        $this->vars[$key] = array_merge($this->vars[$key], [
170
-            'multilingual'        => $multilingual,
171
-            'form_caption'        => $form_caption,
172
-            'form_dsc'            => $form_dsc,
173
-            'sortby'              => $sortby,
174
-            'persistent'          => $persistent,
175
-            'displayOnForm'       => $displayOnForm,
176
-            'displayOnSingleView' => true,
177
-            'readonly'            => false
178
-        ]);
179
-    }
180
-
181
-    /**
182
-     * @param        $key
183
-     * @param        $data_type
184
-     * @param bool   $itemName
185
-     * @param string $form_caption
186
-     * @param bool   $sortby
187
-     * @param string $value
188
-     * @param bool   $displayOnForm
189
-     * @param bool   $required
190
-     */
191
-    public function initNonPersistableVar(
192
-        $key,
193
-        $data_type,
194
-        $itemName = false,
195
-        $form_caption = '',
196
-        $sortby = false,
197
-        $value = '',
198
-        $displayOnForm = false,
199
-        $required = false
200
-    ) {
201
-        $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
202
-        $this->vars[$key]['itemName'] = $itemName;
203
-    }
204
-
205
-    /**
206
-     * Quickly initiate a var
207
-     *
208
-     * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
209
-     *
210
-     * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
211
-     * - all other vars are NULL or '' depending of the parameter
212
-     *
213
-     * @param string $key          key of this field. This needs to be the name of the field in the related database table
214
-     * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
215
-     * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
216
-     * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
217
-     * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
218
-     * @param mixed  $value        default value of this variable
219
-     */
220
-    public function quickInitVar(
221
-        $key,
222
-        $data_type,
223
-        $required = false,
224
-        $form_caption = '',
225
-        $form_dsc = '',
226
-        $value = null
227
-    ) {
228
-        $maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null;
229
-        $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
230
-    }
231
-
232
-    /**
233
-     * @param        $varname
234
-     * @param bool   $displayOnForm
235
-     * @param string $default
236
-     */
237
-    public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
238
-    {
239
-        switch ($varname) {
240
-            case 'dohtml':
241
-                $value = 'notdefined' !== $default ? $default : true;
242
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
243
-                $this->setControl($varname, 'yesno');
244
-                break;
245
-
246
-            case 'dobr':
247
-                $value = ('notdefined' === $default) ? true : $default;
248
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
249
-                $this->setControl($varname, 'yesno');
250
-                break;
251
-
252
-            case 'doimage':
253
-                $value = 'notdefined' !== $default ? $default : true;
254
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
255
-                $this->setControl($varname, 'yesno');
256
-                break;
257
-
258
-            case 'dosmiley':
259
-                $value = 'notdefined' !== $default ? $default : true;
260
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
261
-                $this->setControl($varname, 'yesno');
262
-                break;
263
-
264
-            case 'doxcode':
265
-                $value = 'notdefined' !== $default ? $default : true;
266
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
267
-                $this->setControl($varname, 'yesno');
268
-                break;
269
-
270
-            case 'meta_keywords':
271
-                $value = 'notdefined' !== $default ? $default : '';
272
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
273
-                $this->setControl('meta_keywords', [
274
-                    'name'        => 'textarea',
275
-                    'form_editor' => 'textarea'
276
-                ]);
277
-                break;
278
-
279
-            case 'meta_description':
280
-                $value = 'notdefined' !== $default ? $default : '';
281
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
282
-                $this->setControl('meta_description', [
283
-                    'name'        => 'textarea',
284
-                    'form_editor' => 'textarea'
285
-                ]);
286
-                break;
287
-
288
-            case 'short_url':
289
-                $value = 'notdefined' !== $default ? $default : '';
290
-                $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
291
-                break;
292
-
293
-            case 'hierarchy_path':
294
-                $value = 'notdefined' !== $default ? $default : '';
295
-                $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
296
-                break;
297
-
298
-            case 'counter':
299
-                $value = 'notdefined' !== $default ? $default : 0;
300
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
301
-                break;
302
-
303
-            case 'weight':
304
-                $value = 'notdefined' !== $default ? $default : 0;
305
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
306
-                break;
307
-            case 'custom_css':
308
-                $value = 'notdefined' !== $default ? $default : '';
309
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
310
-                $this->setControl('custom_css', [
311
-                    'name'        => 'textarea',
312
-                    'form_editor' => 'textarea'
313
-                ]);
314
-                break;
315
-        }
316
-        $this->hideFieldFromSingleView($varname);
317
-    }
318
-
319
-    /**
320
-     * Set control information for an instance variable
321
-     *
322
-     * The $options parameter can be a string or an array. Using a string
323
-     * is the quickest way:
324
-     *
325
-     * $this->setControl('date', 'date_time');
326
-     *
327
-     * This will create a date and time selectbox for the 'date' var on the
328
-     * form to edit or create this item.
329
-     *
330
-     * Here are the currently supported controls:
331
-     *
332
-     *      - color
333
-     *      - country
334
-     *      - date_time
335
-     *      - date
336
-     *      - email
337
-     *      - group
338
-     *      - group_multi
339
-     *      - image
340
-     *      - imageupload
341
-     *      - label
342
-     *      - language
343
-     *      - parentcategory
344
-     *      - password
345
-     *      - select_multi
346
-     *      - select
347
-     *      - text
348
-     *      - textarea
349
-     *      - theme
350
-     *      - theme_multi
351
-     *      - timezone
352
-     *      - user
353
-     *      - user_multi
354
-     *      - yesno
355
-     *
356
-     * Now, using an array as $options, you can customize what information to
357
-     * use in the control. For example, if one needs to display a select box for
358
-     * the user to choose the status of an item. We only need to tell SmartObject
359
-     * what method to execute within what handler to retreive the options of the
360
-     * selectbox.
361
-     *
362
-     * $this->setControl('status', array('name' => false,
363
-     *                                   'itemHandler' => 'item',
364
-     *                                   'method' => 'getStatus',
365
-     *                                   'module' => 'smartshop'));
366
-     *
367
-     * In this example, the array elements are the following:
368
-     *      - name: false, as we don't need to set a special control here.
369
-     *               we will use the default control related to the object type (defined in initVar)
370
-     *      - itemHandler: name of the object for which we will use the handler
371
-     *      - method: name of the method of this handler that we will execute
372
-     *      - module: name of the module from wich the handler is
373
-     *
374
-     * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
375
-     * populate this selectbox with the result from SmartshopItemHandler::getStatus()
376
-     *
377
-     * Another example of the use of $options as an array is for TextArea:
378
-     *
379
-     * $this->setControl('body', array('name' => 'textarea',
380
-     *                                   'form_editor' => 'default'));
381
-     *
382
-     * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
383
-     * the 'default' editor, providing it is defined in the module
384
-     * preferences: $helper->getConfig('default_editor')
385
-     *
386
-     * Of course, you can force the use of a specific editor:
387
-     *
388
-     * $this->setControl('body', array('name' => 'textarea',
389
-     *                                   'form_editor' => 'koivi'));
390
-     *
391
-     * Here is a list of supported editor:
392
-     *      - tiny: TinyEditor
393
-     *      - dhtmltextarea: XOOPS DHTML Area
394
-     *      - fckeditor: FCKEditor
395
-     *      - inbetween: InBetween
396
-     *      - koivi: Koivi
397
-     *      - spaw: Spaw WYSIWYG Editor
398
-     *      - htmlarea: HTMLArea
399
-     *      - textarea: basic textarea with no options
400
-     *
401
-     * @param string $var name of the variable for which we want to set a control
402
-     * @param array  $options
403
-     */
404
-    public function setControl($var, $options = [])
405
-    {
406
-        if (isset($this->controls[$var])) {
407
-            unset($this->controls[$var]);
408
-        }
409
-        if (is_string($options)) {
410
-            $options = ['name' => $options];
411
-        }
412
-        $this->controls[$var] = $options;
413
-    }
414
-
415
-    /**
416
-     * Get control information for an instance variable
417
-     *
418
-     * @param  string $var
419
-     * @return bool|mixed
420
-     */
421
-    public function getControl($var)
422
-    {
423
-        return isset($this->controls[$var]) ? $this->controls[$var] : false;
424
-    }
425
-
426
-    /**
427
-     * Create the form for this object
428
-     *
429
-     * @param         $form_caption
430
-     * @param         $form_name
431
-     * @param  bool   $form_action
432
-     * @param  string $submit_button_caption
433
-     * @param  bool   $cancel_js_action
434
-     * @param  bool   $captcha
435
-     * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
436
-     *                                      object for this object
437
-     * @see SmartObjectForm::SmartObjectForm()
438
-     */
439
-    public function getForm(
440
-        $form_caption,
441
-        $form_name,
442
-        $form_action = false,
443
-        $submit_button_caption = _CO_SOBJECT_SUBMIT,
444
-        $cancel_js_action = false,
445
-        $captcha = false
446
-    ) {
61
+	public $_image_path;
62
+	public $_image_url;
63
+
64
+	public $seoEnabled   = false;
65
+	public $titleField;
66
+	public $summaryField = false;
67
+
68
+	/**
69
+	 * Reference to the handler managing this object
70
+	 *
71
+	 * @var PersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
72
+	 */
73
+	public $handler;
74
+
75
+	/**
76
+	 * References to control objects, managing the form fields of this object
77
+	 */
78
+	public $controls = [];
79
+
80
+	/**
81
+	 * SmartObject constructor.
82
+	 * @param $handler
83
+	 */
84
+	public function __construct($handler)
85
+	{
86
+		$this->handler = $handler;
87
+	}
88
+
89
+	/**
90
+	 * Checks if the user has a specific access on this object
91
+	 *
92
+	 * @param $perm_name
93
+	 * @return bool: TRUE if user has access, false if not
94
+	 * @internal param string $gperm_name name of the permission to test
95
+	 */
96
+	public function accessGranted($perm_name)
97
+	{
98
+		$smartPermissionsHandler = new PermissionHandler($this->handler);
99
+
100
+		return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
101
+	}
102
+
103
+	/**
104
+	 * @param      $section_name
105
+	 * @param bool $value
106
+	 * @param bool $hide
107
+	 */
108
+	public function addFormSection($section_name, $value = false, $hide = false)
109
+	{
110
+		$this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
111
+		$this->vars[$section_name]['hide'] = $hide;
112
+	}
113
+
114
+	/**
115
+	 * @param $section_name
116
+	 */
117
+	public function closeSection($section_name)
118
+	{
119
+		$this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
120
+	}
121
+
122
+	/**
123
+	 *
124
+	 * @param string $key          key of this field. This needs to be the name of the field in the related database table
125
+	 * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
126
+	 * @param mixed  $value        default value of this variable
127
+	 * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
128
+	 * @param int    $maxlength    maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
129
+	 * @param string $options      does this data have any select options?
130
+	 * @param bool   $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
131
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
132
+	 * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
133
+	 * @param bool   $sortby       set to TRUE to make this field used to sort objects in SmartObjectTable
134
+	 * @param bool   $persistent   set to FALSE if this field is not to be saved in the database
135
+	 * @param bool   $displayOnForm
136
+	 */
137
+	public function initVar(
138
+		$key,
139
+		$data_type,
140
+		$value = null,
141
+		$required = false,
142
+		$maxlength = null,
143
+		$options = '',
144
+		$multilingual = false,
145
+		$form_caption = '',
146
+		$form_dsc = '',
147
+		$sortby = false,
148
+		$persistent = true,
149
+		$displayOnForm = true
150
+	) {
151
+		//url_ is reserved for files.
152
+		if (0 === strpos($key, 'url_')) {
153
+			trigger_error("Cannot use variable starting with 'url_'.");
154
+		}
155
+		parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
156
+		if ($this->handler && (!$form_caption || '' === $form_caption)) {
157
+			$dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
158
+			if (defined($dyn_form_caption)) {
159
+				$form_caption = constant($dyn_form_caption);
160
+			}
161
+		}
162
+		if ($this->handler && (!$form_dsc || '' === $form_dsc)) {
163
+			$dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
164
+			if (defined($dyn_form_dsc)) {
165
+				$form_dsc = constant($dyn_form_dsc);
166
+			}
167
+		}
168
+
169
+		$this->vars[$key] = array_merge($this->vars[$key], [
170
+			'multilingual'        => $multilingual,
171
+			'form_caption'        => $form_caption,
172
+			'form_dsc'            => $form_dsc,
173
+			'sortby'              => $sortby,
174
+			'persistent'          => $persistent,
175
+			'displayOnForm'       => $displayOnForm,
176
+			'displayOnSingleView' => true,
177
+			'readonly'            => false
178
+		]);
179
+	}
180
+
181
+	/**
182
+	 * @param        $key
183
+	 * @param        $data_type
184
+	 * @param bool   $itemName
185
+	 * @param string $form_caption
186
+	 * @param bool   $sortby
187
+	 * @param string $value
188
+	 * @param bool   $displayOnForm
189
+	 * @param bool   $required
190
+	 */
191
+	public function initNonPersistableVar(
192
+		$key,
193
+		$data_type,
194
+		$itemName = false,
195
+		$form_caption = '',
196
+		$sortby = false,
197
+		$value = '',
198
+		$displayOnForm = false,
199
+		$required = false
200
+	) {
201
+		$this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
202
+		$this->vars[$key]['itemName'] = $itemName;
203
+	}
204
+
205
+	/**
206
+	 * Quickly initiate a var
207
+	 *
208
+	 * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
209
+	 *
210
+	 * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
211
+	 * - all other vars are NULL or '' depending of the parameter
212
+	 *
213
+	 * @param string $key          key of this field. This needs to be the name of the field in the related database table
214
+	 * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
215
+	 * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
216
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
217
+	 * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
218
+	 * @param mixed  $value        default value of this variable
219
+	 */
220
+	public function quickInitVar(
221
+		$key,
222
+		$data_type,
223
+		$required = false,
224
+		$form_caption = '',
225
+		$form_dsc = '',
226
+		$value = null
227
+	) {
228
+		$maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null;
229
+		$this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
230
+	}
231
+
232
+	/**
233
+	 * @param        $varname
234
+	 * @param bool   $displayOnForm
235
+	 * @param string $default
236
+	 */
237
+	public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
238
+	{
239
+		switch ($varname) {
240
+			case 'dohtml':
241
+				$value = 'notdefined' !== $default ? $default : true;
242
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
243
+				$this->setControl($varname, 'yesno');
244
+				break;
245
+
246
+			case 'dobr':
247
+				$value = ('notdefined' === $default) ? true : $default;
248
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
249
+				$this->setControl($varname, 'yesno');
250
+				break;
251
+
252
+			case 'doimage':
253
+				$value = 'notdefined' !== $default ? $default : true;
254
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
255
+				$this->setControl($varname, 'yesno');
256
+				break;
257
+
258
+			case 'dosmiley':
259
+				$value = 'notdefined' !== $default ? $default : true;
260
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
261
+				$this->setControl($varname, 'yesno');
262
+				break;
263
+
264
+			case 'doxcode':
265
+				$value = 'notdefined' !== $default ? $default : true;
266
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
267
+				$this->setControl($varname, 'yesno');
268
+				break;
269
+
270
+			case 'meta_keywords':
271
+				$value = 'notdefined' !== $default ? $default : '';
272
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
273
+				$this->setControl('meta_keywords', [
274
+					'name'        => 'textarea',
275
+					'form_editor' => 'textarea'
276
+				]);
277
+				break;
278
+
279
+			case 'meta_description':
280
+				$value = 'notdefined' !== $default ? $default : '';
281
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
282
+				$this->setControl('meta_description', [
283
+					'name'        => 'textarea',
284
+					'form_editor' => 'textarea'
285
+				]);
286
+				break;
287
+
288
+			case 'short_url':
289
+				$value = 'notdefined' !== $default ? $default : '';
290
+				$this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
291
+				break;
292
+
293
+			case 'hierarchy_path':
294
+				$value = 'notdefined' !== $default ? $default : '';
295
+				$this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
296
+				break;
297
+
298
+			case 'counter':
299
+				$value = 'notdefined' !== $default ? $default : 0;
300
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
301
+				break;
302
+
303
+			case 'weight':
304
+				$value = 'notdefined' !== $default ? $default : 0;
305
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
306
+				break;
307
+			case 'custom_css':
308
+				$value = 'notdefined' !== $default ? $default : '';
309
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
310
+				$this->setControl('custom_css', [
311
+					'name'        => 'textarea',
312
+					'form_editor' => 'textarea'
313
+				]);
314
+				break;
315
+		}
316
+		$this->hideFieldFromSingleView($varname);
317
+	}
318
+
319
+	/**
320
+	 * Set control information for an instance variable
321
+	 *
322
+	 * The $options parameter can be a string or an array. Using a string
323
+	 * is the quickest way:
324
+	 *
325
+	 * $this->setControl('date', 'date_time');
326
+	 *
327
+	 * This will create a date and time selectbox for the 'date' var on the
328
+	 * form to edit or create this item.
329
+	 *
330
+	 * Here are the currently supported controls:
331
+	 *
332
+	 *      - color
333
+	 *      - country
334
+	 *      - date_time
335
+	 *      - date
336
+	 *      - email
337
+	 *      - group
338
+	 *      - group_multi
339
+	 *      - image
340
+	 *      - imageupload
341
+	 *      - label
342
+	 *      - language
343
+	 *      - parentcategory
344
+	 *      - password
345
+	 *      - select_multi
346
+	 *      - select
347
+	 *      - text
348
+	 *      - textarea
349
+	 *      - theme
350
+	 *      - theme_multi
351
+	 *      - timezone
352
+	 *      - user
353
+	 *      - user_multi
354
+	 *      - yesno
355
+	 *
356
+	 * Now, using an array as $options, you can customize what information to
357
+	 * use in the control. For example, if one needs to display a select box for
358
+	 * the user to choose the status of an item. We only need to tell SmartObject
359
+	 * what method to execute within what handler to retreive the options of the
360
+	 * selectbox.
361
+	 *
362
+	 * $this->setControl('status', array('name' => false,
363
+	 *                                   'itemHandler' => 'item',
364
+	 *                                   'method' => 'getStatus',
365
+	 *                                   'module' => 'smartshop'));
366
+	 *
367
+	 * In this example, the array elements are the following:
368
+	 *      - name: false, as we don't need to set a special control here.
369
+	 *               we will use the default control related to the object type (defined in initVar)
370
+	 *      - itemHandler: name of the object for which we will use the handler
371
+	 *      - method: name of the method of this handler that we will execute
372
+	 *      - module: name of the module from wich the handler is
373
+	 *
374
+	 * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
375
+	 * populate this selectbox with the result from SmartshopItemHandler::getStatus()
376
+	 *
377
+	 * Another example of the use of $options as an array is for TextArea:
378
+	 *
379
+	 * $this->setControl('body', array('name' => 'textarea',
380
+	 *                                   'form_editor' => 'default'));
381
+	 *
382
+	 * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
383
+	 * the 'default' editor, providing it is defined in the module
384
+	 * preferences: $helper->getConfig('default_editor')
385
+	 *
386
+	 * Of course, you can force the use of a specific editor:
387
+	 *
388
+	 * $this->setControl('body', array('name' => 'textarea',
389
+	 *                                   'form_editor' => 'koivi'));
390
+	 *
391
+	 * Here is a list of supported editor:
392
+	 *      - tiny: TinyEditor
393
+	 *      - dhtmltextarea: XOOPS DHTML Area
394
+	 *      - fckeditor: FCKEditor
395
+	 *      - inbetween: InBetween
396
+	 *      - koivi: Koivi
397
+	 *      - spaw: Spaw WYSIWYG Editor
398
+	 *      - htmlarea: HTMLArea
399
+	 *      - textarea: basic textarea with no options
400
+	 *
401
+	 * @param string $var name of the variable for which we want to set a control
402
+	 * @param array  $options
403
+	 */
404
+	public function setControl($var, $options = [])
405
+	{
406
+		if (isset($this->controls[$var])) {
407
+			unset($this->controls[$var]);
408
+		}
409
+		if (is_string($options)) {
410
+			$options = ['name' => $options];
411
+		}
412
+		$this->controls[$var] = $options;
413
+	}
414
+
415
+	/**
416
+	 * Get control information for an instance variable
417
+	 *
418
+	 * @param  string $var
419
+	 * @return bool|mixed
420
+	 */
421
+	public function getControl($var)
422
+	{
423
+		return isset($this->controls[$var]) ? $this->controls[$var] : false;
424
+	}
425
+
426
+	/**
427
+	 * Create the form for this object
428
+	 *
429
+	 * @param         $form_caption
430
+	 * @param         $form_name
431
+	 * @param  bool   $form_action
432
+	 * @param  string $submit_button_caption
433
+	 * @param  bool   $cancel_js_action
434
+	 * @param  bool   $captcha
435
+	 * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
436
+	 *                                      object for this object
437
+	 * @see SmartObjectForm::SmartObjectForm()
438
+	 */
439
+	public function getForm(
440
+		$form_caption,
441
+		$form_name,
442
+		$form_action = false,
443
+		$submit_button_caption = _CO_SOBJECT_SUBMIT,
444
+		$cancel_js_action = false,
445
+		$captcha = false
446
+	) {
447 447
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
448
-        $form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
449
-
450
-        return $form;
451
-    }
452
-
453
-    /**
454
-     * @return array
455
-     */
456
-    public function toArray()
457
-    {
458
-        $ret  = [];
459
-        $vars =& $this->getVars();
460
-        foreach ($vars as $key => $var) {
461
-            $value     = $this->getVar($key);
462
-            $ret[$key] = $value;
463
-        }
464
-        if ('' !== $this->handler->identifierName) {
465
-            $controller = new ObjectController($this->handler);
466
-            /**
467
-             * Addition of some automatic value
468
-             */
469
-            $ret['itemLink']         = $controller->getItemLink($this);
470
-            $ret['itemUrl']          = $controller->getItemLink($this, true);
471
-            $ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
472
-            $ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
473
-            $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
474
-        }
475
-
476
-        // Hightlighting searched words
448
+		$form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
449
+
450
+		return $form;
451
+	}
452
+
453
+	/**
454
+	 * @return array
455
+	 */
456
+	public function toArray()
457
+	{
458
+		$ret  = [];
459
+		$vars =& $this->getVars();
460
+		foreach ($vars as $key => $var) {
461
+			$value     = $this->getVar($key);
462
+			$ret[$key] = $value;
463
+		}
464
+		if ('' !== $this->handler->identifierName) {
465
+			$controller = new ObjectController($this->handler);
466
+			/**
467
+			 * Addition of some automatic value
468
+			 */
469
+			$ret['itemLink']         = $controller->getItemLink($this);
470
+			$ret['itemUrl']          = $controller->getItemLink($this, true);
471
+			$ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
472
+			$ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
473
+			$ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
474
+		}
475
+
476
+		// Hightlighting searched words
477 477
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php';
478
-        $highlight = Smartobject\Utility::getConfig('module_search_highlighter', false, true);
479
-
480
-        if ($highlight && isset($_GET['keywords'])) {
481
-            $myts     = \MyTextSanitizer::getInstance();
482
-            $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
483
-            $h        = new Highlighter($keywords, true, 'smart_highlighter');
484
-            foreach ($this->handler->highlightFields as $field) {
485
-                $ret[$field] = $h->highlight($ret[$field]);
486
-            }
487
-        }
488
-
489
-        return $ret;
490
-    }
491
-
492
-    /**
493
-     * add an error
494
-     *
495
-     * @param      $err_str
496
-     * @param bool $prefix
497
-     * @internal param string $value error to add
498
-     * @access   public
499
-     */
500
-    public function setErrors($err_str, $prefix = false)
501
-    {
502
-        if (is_array($err_str)) {
503
-            foreach ($err_str as $str) {
504
-                $this->setErrors($str, $prefix);
505
-            }
506
-        } else {
507
-            if ($prefix) {
508
-                $err_str = '[' . $prefix . '] ' . $err_str;
509
-            }
510
-            parent::setErrors($err_str);
511
-        }
512
-    }
513
-
514
-    /**
515
-     * @param      $field
516
-     * @param bool $required
517
-     */
518
-    public function setFieldAsRequired($field, $required = true)
519
-    {
520
-        if (is_array($field)) {
521
-            foreach ($field as $v) {
522
-                $this->doSetFieldAsRequired($v, $required);
523
-            }
524
-        } else {
525
-            $this->doSetFieldAsRequired($field, $required);
526
-        }
527
-    }
528
-
529
-    /**
530
-     * @param $field
531
-     */
532
-    public function setFieldForSorting($field)
533
-    {
534
-        if (is_array($field)) {
535
-            foreach ($field as $v) {
536
-                $this->doSetFieldForSorting($v);
537
-            }
538
-        } else {
539
-            $this->doSetFieldForSorting($field);
540
-        }
541
-    }
542
-
543
-    /**
544
-     * @return bool
545
-     */
546
-    public function hasError()
547
-    {
548
-        return count($this->_errors) > 0;
549
-    }
550
-
551
-    /**
552
-     * @param $url
553
-     * @param $path
554
-     */
555
-    public function setImageDir($url, $path)
556
-    {
557
-        $this->_image_url  = $url;
558
-        $this->_image_path = $path;
559
-    }
560
-
561
-    /**
562
-     * Retreive the group that have been granted access to a specific permission for this object
563
-     *
564
-     * @param $group_perm
565
-     * @return string $group_perm name of the permission
566
-     */
567
-    public function getGroupPerm($group_perm)
568
-    {
569
-        if (!$this->handler->getPermissions()) {
570
-            $this->setError("Trying to access a permission that does not exists for thisobject's handler");
571
-
572
-            return false;
573
-        }
574
-
575
-        $smartPermissionsHandler = new PermissionHandler($this->handler);
576
-        $ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
577
-
578
-        if (0 == count($ret)) {
579
-            return false;
580
-        } else {
581
-            return $ret;
582
-        }
583
-    }
584
-
585
-    /**
586
-     * @param  bool $path
587
-     * @return mixed
588
-     */
589
-    public function getImageDir($path = false)
590
-    {
591
-        if ($path) {
592
-            return $this->_image_path;
593
-        } else {
594
-            return $this->_image_url;
595
-        }
596
-    }
597
-
598
-    /**
599
-     * @param  bool $path
600
-     * @return mixed
601
-     */
602
-    public function getUploadDir($path = false)
603
-    {
604
-        if ($path) {
605
-            return $this->_image_path;
606
-        } else {
607
-            return $this->_image_url;
608
-        }
609
-    }
610
-
611
-    /**
612
-     * @param  string $key
613
-     * @param  string $info
614
-     * @return array
615
-     */
616
-    public function getVarInfo($key = '', $info = '')
617
-    {
618
-        if (isset($this->vars[$key][$info])) {
619
-            return $this->vars[$key][$info];
620
-        } elseif ('' === $info && isset($this->vars[$key])) {
621
-            return $this->vars[$key];
622
-        } else {
623
-            return $this->vars;
624
-        }
625
-    }
626
-
627
-    /**
628
-     * Get the id of the object
629
-     *
630
-     * @return int id of this object
631
-     */
632
-    public function id()
633
-    {
634
-        return $this->getVar($this->handler->keyName, 'e');
635
-    }
636
-
637
-    /**
638
-     * Return the value of the title field of this object
639
-     *
640
-     * @param  string $format
641
-     * @return string
642
-     */
643
-    public function title($format = 's')
644
-    {
645
-        return $this->getVar($this->handler->identifierName, $format);
646
-    }
647
-
648
-    /**
649
-     * Return the value of the title field of this object
650
-     *
651
-     * @return string
652
-     */
653
-    public function summary()
654
-    {
655
-        if ($this->handler->summaryName) {
656
-            return $this->getVar($this->handler->summaryName);
657
-        } else {
658
-            return false;
659
-        }
660
-    }
661
-
662
-    /**
663
-     * Retreive the object admin side link, displayijng a SingleView page
664
-     *
665
-     * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
666
-     * @return string user side link to the object
667
-     */
668
-    public function getAdminViewItemLink($onlyUrl = false)
669
-    {
670
-        $controller = new ObjectController($this->handler);
671
-
672
-        return $controller->getAdminViewItemLink($this, $onlyUrl);
673
-    }
674
-
675
-    /**
676
-     * Retreive the object user side link
677
-     *
678
-     * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
679
-     * @return string user side link to the object
680
-     */
681
-    public function getItemLink($onlyUrl = false)
682
-    {
683
-        $controller = new ObjectController($this->handler);
684
-
685
-        return $controller->getItemLink($this, $onlyUrl);
686
-    }
687
-
688
-    /**
689
-     * @param  bool $onlyUrl
690
-     * @param  bool $withimage
691
-     * @param  bool $userSide
692
-     * @return string
693
-     */
694
-    public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
695
-    {
696
-        $controller = new ObjectController($this->handler);
697
-
698
-        return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
699
-    }
700
-
701
-    /**
702
-     * @param  bool $onlyUrl
703
-     * @param  bool $withimage
704
-     * @param  bool $userSide
705
-     * @return string
706
-     */
707
-    public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
708
-    {
709
-        $controller = new ObjectController($this->handler);
710
-
711
-        return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
712
-    }
713
-
714
-    /**
715
-     * @return string
716
-     */
717
-    public function getPrintAndMailLink()
718
-    {
719
-        $controller = new ObjectController($this->handler);
720
-
721
-        return $controller->getPrintAndMailLink($this);
722
-    }
723
-
724
-    /**
725
-     * @param $sortsel
726
-     * @return array|bool
727
-     */
728
-    public function getFieldsForSorting($sortsel)
729
-    {
730
-        $ret = [];
731
-
732
-        foreach ($this->vars as $key => $field_info) {
733
-            if ($field_info['sortby']) {
734
-                $ret[$key]['caption']  = $field_info['form_caption'];
735
-                $ret[$key]['selected'] = $key == $sortsel ? 'selected' : '';
736
-            }
737
-        }
738
-
739
-        if (count($ret) > 0) {
740
-            return $ret;
741
-        } else {
742
-            return false;
743
-        }
744
-    }
745
-
746
-    /**
747
-     * @param $key
748
-     * @param $newType
749
-     */
750
-    public function setType($key, $newType)
751
-    {
752
-        $this->vars[$key]['data_type'] = $newType;
753
-    }
754
-
755
-    /**
756
-     * @param $key
757
-     * @param $info
758
-     * @param $value
759
-     */
760
-    public function setVarInfo($key, $info, $value)
761
-    {
762
-        $this->vars[$key][$info] = $value;
763
-    }
764
-
765
-    /**
766
-     * @param         $key
767
-     * @param  bool   $editor
768
-     * @return string
769
-     */
770
-    public function getValueFor($key, $editor = true)
771
-    {
772
-        /** @var Smartmedia\Helper $helper */
773
-        $helper = Smartmedia\Helper::getInstance();
774
-
775
-        $ret  = $this->getVar($key, 'n');
776
-        $myts = \MyTextSanitizer::getInstance();
777
-
778
-        $control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
779
-        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
780
-
781
-        $html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
782
-        $smiley   = true;
783
-        $xcode    = true;
784
-        $image    = true;
785
-        $br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
786
-        $formatML = true;
787
-
788
-        if ('default' === $form_editor) {
789
-            /** @var Smartmedia\Helper $helper */
790
-            $helper = Smartmedia\Helper::getInstance();
791
-
792
-            $form_editor = null !==($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea';
793
-        }
794
-
795
-        if ($editor) {
796
-            if (defined('XOOPS_EDITOR_IS_HTML')
797
-                && !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) {
798
-                $br       = false;
799
-                $formatML = !$editor;
800
-            } else {
801
-                return htmlspecialchars($ret, ENT_QUOTES);
802
-            }
803
-        }
804
-
805
-        if (method_exists($myts, 'formatForML')) {
806
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
807
-        } else {
808
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
809
-        }
810
-    }
811
-
812
-    /**
813
-     * clean values of all variables of the object for storage.
814
-     * also add slashes whereever needed
815
-     *
816
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
817
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
818
-     * as a string separated by |
819
-     *
820
-     * @return bool true if successful
821
-     * @access public
822
-     */
823
-    public function cleanVars()
824
-    {
825
-        $ts              = \MyTextSanitizer::getInstance();
826
-        $existing_errors = $this->getErrors();
827
-        $this->_errors   = [];
828
-        foreach ($this->vars as $k => $v) {
829
-            $cleanv = $v['value'];
830
-            if (!$v['changed']) {
831
-            } else {
832
-                $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
833
-                switch ($v['data_type']) {
834
-                    case XOBJ_DTYPE_TXTBOX:
835
-                        if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
836
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
837
-                            continue 2;
838
-                        }
839
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
840
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
841
-                            continue 2;
842
-                        }
843
-                        if (!$v['not_gpc']) {
844
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
845
-                        } else {
846
-                            $cleanv = $ts->censorString($cleanv);
847
-                        }
848
-                        break;
849
-                    case XOBJ_DTYPE_TXTAREA:
850
-                        if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
851
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
852
-                            continue 2;
853
-                        }
854
-                        if (!$v['not_gpc']) {
855
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
856
-                        } else {
857
-                            $cleanv = $ts->censorString($cleanv);
858
-                        }
859
-                        break;
860
-                    case XOBJ_DTYPE_SOURCE:
861
-                        if (!$v['not_gpc']) {
862
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
863
-                        } else {
864
-                            $cleanv = $cleanv;
865
-                        }
866
-                        break;
867
-                    case XOBJ_DTYPE_INT:
868
-                    case XOBJ_DTYPE_TIME_ONLY:
869
-                        $cleanv = (int)$cleanv;
870
-                        break;
871
-
872
-                    case XOBJ_DTYPE_CURRENCY:
873
-                        $cleanv = Smartobject\Utility::getCurrency($cleanv);
874
-                        break;
875
-
876
-                    case XOBJ_DTYPE_FLOAT:
877
-                        $cleanv = Smartobject\Utility::float($cleanv);
878
-                        break;
879
-
880
-                    case XOBJ_DTYPE_EMAIL:
881
-                        if ($v['required'] && '' === $cleanv) {
882
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
883
-                            continue 2;
884
-                        }
885
-                        if ('' !== $cleanv
886
-                            && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
887
-                            $this->setErrors('Invalid Email');
888
-                            continue 2;
889
-                        }
890
-                        if (!$v['not_gpc']) {
891
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
892
-                        }
893
-                        break;
894
-                    case XOBJ_DTYPE_URL:
895
-                        if ($v['required'] && '' === $cleanv) {
896
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
897
-                            continue 2;
898
-                        }
899
-                        if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
900
-                            $cleanv = 'http://' . $cleanv;
901
-                        }
902
-                        if (!$v['not_gpc']) {
903
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
904
-                        }
905
-                        break;
906
-                    case XOBJ_DTYPE_SIMPLE_ARRAY:
907
-                        $cleanv = implode('|', $cleanv);
908
-                        break;
909
-                    case XOBJ_DTYPE_ARRAY:
910
-                        $cleanv = serialize($cleanv);
911
-                        break;
912
-                    case XOBJ_DTYPE_STIME:
913
-                    case XOBJ_DTYPE_MTIME:
914
-                    case XOBJ_DTYPE_LTIME:
915
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
916
-                        if (!($cleanv > 0)) {
917
-                            $cleanv = strtotime($cleanv);
918
-                        }
919
-                        break;
920
-                    default:
921
-                        break;
922
-                }
923
-            }
924
-            $this->cleanVars[$k] =& $cleanv;
925
-            unset($cleanv);
926
-        }
927
-        if (count($this->_errors) > 0) {
928
-            $this->_errors = array_merge($existing_errors, $this->_errors);
929
-
930
-            return false;
931
-        }
932
-        $this->_errors = array_merge($existing_errors, $this->_errors);
933
-        $this->unsetDirty();
934
-
935
-        return true;
936
-    }
937
-
938
-    /**
939
-     * returns a specific variable for the object in a proper format
940
-     *
941
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
942
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
943
-     * as a string separated by |
944
-     *
945
-     * @access public
946
-     * @param  string $key    key of the object's variable to be returned
947
-     * @param  string $format format to use for the output
948
-     * @return mixed  formatted value of the variable
949
-     */
950
-    public function getVar($key, $format = 's')
951
-    {
952
-        global $myts;
953
-
954
-        $ret = $this->vars[$key]['value'];
955
-
956
-        switch ($this->vars[$key]['data_type']) {
957
-
958
-            case XOBJ_DTYPE_TXTBOX:
959
-                switch (strtolower($format)) {
960
-                    case 's':
961
-                    case 'show':
962
-                        // ML Hack by marcan
963
-                        $ts  = \MyTextSanitizer::getInstance();
964
-                        $ret = $ts->htmlSpecialChars($ret);
965
-
966
-                        if (method_exists($myts, 'formatForML')) {
967
-                            return $ts->formatForML($ret);
968
-                        } else {
969
-                            return $ret;
970
-                        }
971
-                        break 1;
972
-                    // End of ML Hack by marcan
973
-
974
-                    case 'clean':
975
-                        $ts = \MyTextSanitizer::getInstance();
976
-
977
-                        $ret = Smartobject\Utility::getHtml2text($ret);
978
-                        $ret = Smartobject\Utility::purifyText($ret);
979
-
980
-                        if (method_exists($myts, 'formatForML')) {
981
-                            return $ts->formatForML($ret);
982
-                        } else {
983
-                            return $ret;
984
-                        }
985
-                        break 1;
986
-                    // End of ML Hack by marcan
987
-
988
-                    case 'e':
989
-                    case 'edit':
990
-                        $ts = \MyTextSanitizer::getInstance();
991
-
992
-                        return $ts->htmlSpecialChars($ret);
993
-                        break 1;
994
-                    case 'p':
995
-                    case 'preview':
996
-                    case 'f':
997
-                    case 'formpreview':
998
-                        $ts = \MyTextSanitizer::getInstance();
999
-
1000
-                        return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
1001
-                        break 1;
1002
-                    case 'n':
1003
-                    case 'none':
1004
-                    default:
1005
-                        break 1;
1006
-                }
1007
-                break;
1008
-            case XOBJ_DTYPE_LTIME:
1009
-                switch (strtolower($format)) {
1010
-                    case 's':
1011
-                    case 'show':
1012
-                    case 'p':
1013
-                    case 'preview':
1014
-                    case 'f':
1015
-                    case 'formpreview':
1016
-                        $ret = formatTimestamp($ret, _DATESTRING);
1017
-
1018
-                        return $ret;
1019
-                        break 1;
1020
-                    case 'n':
1021
-                    case 'none':
1022
-                    case 'e':
1023
-                    case 'edit':
1024
-                        break 1;
1025
-                    default:
1026
-                        break 1;
1027
-                }
1028
-                break;
1029
-            case XOBJ_DTYPE_STIME:
1030
-                switch (strtolower($format)) {
1031
-                    case 's':
1032
-                    case 'show':
1033
-                    case 'p':
1034
-                    case 'preview':
1035
-                    case 'f':
1036
-                    case 'formpreview':
1037
-                        $ret = formatTimestamp($ret, _SHORTDATESTRING);
1038
-
1039
-                        return $ret;
1040
-                        break 1;
1041
-                    case 'n':
1042
-                    case 'none':
1043
-                    case 'e':
1044
-                    case 'edit':
1045
-                        break 1;
1046
-                    default:
1047
-                        break 1;
1048
-                }
1049
-                break;
1050
-            case XOBJ_DTYPE_TIME_ONLY:
1051
-                switch (strtolower($format)) {
1052
-                    case 's':
1053
-                    case 'show':
1054
-                    case 'p':
1055
-                    case 'preview':
1056
-                    case 'f':
1057
-                    case 'formpreview':
1058
-                        $ret = formatTimestamp($ret, 'G:i');
1059
-
1060
-                        return $ret;
1061
-                        break 1;
1062
-                    case 'n':
1063
-                    case 'none':
1064
-                    case 'e':
1065
-                    case 'edit':
1066
-                        break 1;
1067
-                    default:
1068
-                        break 1;
1069
-                }
1070
-                break;
1071
-
1072
-            case XOBJ_DTYPE_CURRENCY:
1073
-                $decimal_section_original = strstr($ret, '.');
1074
-                $decimal_section          = $decimal_section_original;
1075
-                if ($decimal_section) {
1076
-                    if (1 == strlen($decimal_section)) {
1077
-                        $decimal_section = '.00';
1078
-                    } elseif (2 == strlen($decimal_section)) {
1079
-                        $decimal_section .= '0';
1080
-                    }
1081
-                    $ret = str_replace($decimal_section_original, $decimal_section, $ret);
1082
-                } else {
1083
-                    $ret .= '.00';
1084
-                }
1085
-                break;
1086
-
1087
-            case XOBJ_DTYPE_TXTAREA:
1088
-                switch (strtolower($format)) {
1089
-                    case 's':
1090
-                    case 'show':
1091
-                        $ts   = \MyTextSanitizer::getInstance();
1092
-                        $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1093
-
1094
-                        $xcode = (!isset($this->vars['doxcode']['value'])
1095
-                                  || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1096
-
1097
-                        $smiley = (!isset($this->vars['dosmiley']['value'])
1098
-                                   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1099
-                        $image  = (!isset($this->vars['doimage']['value'])
1100
-                                   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1101
-                        $br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1102
-
1103
-                        /**
1104
-                         * Hack by marcan <INBOX> for SCSPRO
1105
-                         * Setting mastop as the main editor
1106
-                         */
1107
-                        if (defined('XOOPS_EDITOR_IS_HTML')) {
1108
-                            $br = false;
1109
-                        }
1110
-
1111
-                        /**
1112
-                         * Hack by marcan <INBOX> for SCSPRO
1113
-                         * Setting mastop as the main editor
1114
-                         */
1115
-
1116
-                        return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1117
-                        break 1;
1118
-                    case 'e':
1119
-                    case 'edit':
1120
-                        return htmlspecialchars($ret, ENT_QUOTES);
1121
-                        break 1;
1122
-                    case 'p':
1123
-                    case 'preview':
1124
-                        $ts     = \MyTextSanitizer::getInstance();
1125
-                        $html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1126
-                        $xcode  = (!isset($this->vars['doxcode']['value'])
1127
-                                   || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1128
-                        $smiley = (!isset($this->vars['dosmiley']['value'])
1129
-                                   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1130
-                        $image  = (!isset($this->vars['doimage']['value'])
1131
-                                   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1132
-                        $br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1133
-
1134
-                        return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1135
-                        break 1;
1136
-                    case 'f':
1137
-                    case 'formpreview':
1138
-                        $ts = \MyTextSanitizer::getInstance();
1139
-
1140
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1141
-                        break 1;
1142
-                    case 'n':
1143
-                    case 'none':
1144
-                    default:
1145
-                        break 1;
1146
-                }
1147
-                break;
1148
-            case XOBJ_DTYPE_SIMPLE_ARRAY:
1149
-                $ret =& explode('|', $ret);
1150
-                break;
1151
-            case XOBJ_DTYPE_ARRAY:
1152
-                $ret =& unserialize($ret);
1153
-                break;
1154
-            case XOBJ_DTYPE_SOURCE:
1155
-                switch (strtolower($format)) {
1156
-                    case 's':
1157
-                    case 'show':
1158
-                        break 1;
1159
-                    case 'e':
1160
-                    case 'edit':
1161
-                        return htmlspecialchars($ret, ENT_QUOTES);
1162
-                        break 1;
1163
-                    case 'p':
1164
-                    case 'preview':
1165
-                        $ts = \MyTextSanitizer::getInstance();
1166
-
1167
-                        return $ts->stripSlashesGPC($ret);
1168
-                        break 1;
1169
-                    case 'f':
1170
-                    case 'formpreview':
1171
-                        $ts = \MyTextSanitizer::getInstance();
1172
-
1173
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1174
-                        break 1;
1175
-                    case 'n':
1176
-                    case 'none':
1177
-                    default:
1178
-                        break 1;
1179
-                }
1180
-                break;
1181
-            default:
1182
-                if ('' !== $this->vars[$key]['options'] && '' != $ret) {
1183
-                    switch (strtolower($format)) {
1184
-                        case 's':
1185
-                        case 'show':
1186
-                            $selected = explode('|', $ret);
1187
-                            $options  = explode('|', $this->vars[$key]['options']);
1188
-                            $i        = 1;
1189
-                            $ret      = [];
1190
-                            foreach ($options as $op) {
1191
-                                if (in_array($i, $selected)) {
1192
-                                    $ret[] = $op;
1193
-                                }
1194
-                                ++$i;
1195
-                            }
1196
-
1197
-                            return implode(', ', $ret);
1198
-                        case 'e':
1199
-                        case 'edit':
1200
-                            $ret = explode('|', $ret);
1201
-                            break 1;
1202
-                        default:
1203
-                            break 1;
1204
-                    }
1205
-                }
1206
-                break;
1207
-        }
1208
-
1209
-        return $ret;
1210
-    }
1211
-
1212
-    /**
1213
-     * @param $key
1214
-     */
1215
-    public function doMakeFieldreadOnly($key)
1216
-    {
1217
-        if (isset($this->vars[$key])) {
1218
-            $this->vars[$key]['readonly']      = true;
1219
-            $this->vars[$key]['displayOnForm'] = true;
1220
-        }
1221
-    }
1222
-
1223
-    /**
1224
-     * @param $key
1225
-     */
1226
-    public function makeFieldReadOnly($key)
1227
-    {
1228
-        if (is_array($key)) {
1229
-            foreach ($key as $v) {
1230
-                $this->doMakeFieldreadOnly($v);
1231
-            }
1232
-        } else {
1233
-            $this->doMakeFieldreadOnly($key);
1234
-        }
1235
-    }
1236
-
1237
-    /**
1238
-     * @param $key
1239
-     */
1240
-    public function doHideFieldFromForm($key)
1241
-    {
1242
-        if (isset($this->vars[$key])) {
1243
-            $this->vars[$key]['displayOnForm'] = false;
1244
-        }
1245
-    }
1246
-
1247
-    /**
1248
-     * @param $key
1249
-     */
1250
-    public function doHideFieldFromSingleView($key)
1251
-    {
1252
-        if (isset($this->vars[$key])) {
1253
-            $this->vars[$key]['displayOnSingleView'] = false;
1254
-        }
1255
-    }
1256
-
1257
-    /**
1258
-     * @param $key
1259
-     */
1260
-    public function hideFieldFromForm($key)
1261
-    {
1262
-        if (is_array($key)) {
1263
-            foreach ($key as $v) {
1264
-                $this->doHideFieldFromForm($v);
1265
-            }
1266
-        } else {
1267
-            $this->doHideFieldFromForm($key);
1268
-        }
1269
-    }
1270
-
1271
-    /**
1272
-     * @param $key
1273
-     */
1274
-    public function hideFieldFromSingleView($key)
1275
-    {
1276
-        if (is_array($key)) {
1277
-            foreach ($key as $v) {
1278
-                $this->doHideFieldFromSingleView($v);
1279
-            }
1280
-        } else {
1281
-            $this->doHideFieldFromSingleView($key);
1282
-        }
1283
-    }
1284
-
1285
-    /**
1286
-     * @param $key
1287
-     */
1288
-    public function doShowFieldOnForm($key)
1289
-    {
1290
-        if (isset($this->vars[$key])) {
1291
-            $this->vars[$key]['displayOnForm'] = true;
1292
-        }
1293
-    }
1294
-
1295
-    /**
1296
-     * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1297
-     *
1298
-     * @param  bool  $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1299
-     * @param  bool  $userSide  for futur use, to do something different on the user side
1300
-     * @param  array $actions
1301
-     * @param  bool  $headerAsRow
1302
-     * @return string content of the template if $fetchOnly or nothing if !$fetchOnly
1303
-     */
1304
-    public function displaySingleObject(
1305
-        $fetchOnly = false,
1306
-        $userSide = false,
1307
-        $actions = [],
1308
-        $headerAsRow = true
1309
-    ) {
478
+		$highlight = Smartobject\Utility::getConfig('module_search_highlighter', false, true);
479
+
480
+		if ($highlight && isset($_GET['keywords'])) {
481
+			$myts     = \MyTextSanitizer::getInstance();
482
+			$keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
483
+			$h        = new Highlighter($keywords, true, 'smart_highlighter');
484
+			foreach ($this->handler->highlightFields as $field) {
485
+				$ret[$field] = $h->highlight($ret[$field]);
486
+			}
487
+		}
488
+
489
+		return $ret;
490
+	}
491
+
492
+	/**
493
+	 * add an error
494
+	 *
495
+	 * @param      $err_str
496
+	 * @param bool $prefix
497
+	 * @internal param string $value error to add
498
+	 * @access   public
499
+	 */
500
+	public function setErrors($err_str, $prefix = false)
501
+	{
502
+		if (is_array($err_str)) {
503
+			foreach ($err_str as $str) {
504
+				$this->setErrors($str, $prefix);
505
+			}
506
+		} else {
507
+			if ($prefix) {
508
+				$err_str = '[' . $prefix . '] ' . $err_str;
509
+			}
510
+			parent::setErrors($err_str);
511
+		}
512
+	}
513
+
514
+	/**
515
+	 * @param      $field
516
+	 * @param bool $required
517
+	 */
518
+	public function setFieldAsRequired($field, $required = true)
519
+	{
520
+		if (is_array($field)) {
521
+			foreach ($field as $v) {
522
+				$this->doSetFieldAsRequired($v, $required);
523
+			}
524
+		} else {
525
+			$this->doSetFieldAsRequired($field, $required);
526
+		}
527
+	}
528
+
529
+	/**
530
+	 * @param $field
531
+	 */
532
+	public function setFieldForSorting($field)
533
+	{
534
+		if (is_array($field)) {
535
+			foreach ($field as $v) {
536
+				$this->doSetFieldForSorting($v);
537
+			}
538
+		} else {
539
+			$this->doSetFieldForSorting($field);
540
+		}
541
+	}
542
+
543
+	/**
544
+	 * @return bool
545
+	 */
546
+	public function hasError()
547
+	{
548
+		return count($this->_errors) > 0;
549
+	}
550
+
551
+	/**
552
+	 * @param $url
553
+	 * @param $path
554
+	 */
555
+	public function setImageDir($url, $path)
556
+	{
557
+		$this->_image_url  = $url;
558
+		$this->_image_path = $path;
559
+	}
560
+
561
+	/**
562
+	 * Retreive the group that have been granted access to a specific permission for this object
563
+	 *
564
+	 * @param $group_perm
565
+	 * @return string $group_perm name of the permission
566
+	 */
567
+	public function getGroupPerm($group_perm)
568
+	{
569
+		if (!$this->handler->getPermissions()) {
570
+			$this->setError("Trying to access a permission that does not exists for thisobject's handler");
571
+
572
+			return false;
573
+		}
574
+
575
+		$smartPermissionsHandler = new PermissionHandler($this->handler);
576
+		$ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
577
+
578
+		if (0 == count($ret)) {
579
+			return false;
580
+		} else {
581
+			return $ret;
582
+		}
583
+	}
584
+
585
+	/**
586
+	 * @param  bool $path
587
+	 * @return mixed
588
+	 */
589
+	public function getImageDir($path = false)
590
+	{
591
+		if ($path) {
592
+			return $this->_image_path;
593
+		} else {
594
+			return $this->_image_url;
595
+		}
596
+	}
597
+
598
+	/**
599
+	 * @param  bool $path
600
+	 * @return mixed
601
+	 */
602
+	public function getUploadDir($path = false)
603
+	{
604
+		if ($path) {
605
+			return $this->_image_path;
606
+		} else {
607
+			return $this->_image_url;
608
+		}
609
+	}
610
+
611
+	/**
612
+	 * @param  string $key
613
+	 * @param  string $info
614
+	 * @return array
615
+	 */
616
+	public function getVarInfo($key = '', $info = '')
617
+	{
618
+		if (isset($this->vars[$key][$info])) {
619
+			return $this->vars[$key][$info];
620
+		} elseif ('' === $info && isset($this->vars[$key])) {
621
+			return $this->vars[$key];
622
+		} else {
623
+			return $this->vars;
624
+		}
625
+	}
626
+
627
+	/**
628
+	 * Get the id of the object
629
+	 *
630
+	 * @return int id of this object
631
+	 */
632
+	public function id()
633
+	{
634
+		return $this->getVar($this->handler->keyName, 'e');
635
+	}
636
+
637
+	/**
638
+	 * Return the value of the title field of this object
639
+	 *
640
+	 * @param  string $format
641
+	 * @return string
642
+	 */
643
+	public function title($format = 's')
644
+	{
645
+		return $this->getVar($this->handler->identifierName, $format);
646
+	}
647
+
648
+	/**
649
+	 * Return the value of the title field of this object
650
+	 *
651
+	 * @return string
652
+	 */
653
+	public function summary()
654
+	{
655
+		if ($this->handler->summaryName) {
656
+			return $this->getVar($this->handler->summaryName);
657
+		} else {
658
+			return false;
659
+		}
660
+	}
661
+
662
+	/**
663
+	 * Retreive the object admin side link, displayijng a SingleView page
664
+	 *
665
+	 * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
666
+	 * @return string user side link to the object
667
+	 */
668
+	public function getAdminViewItemLink($onlyUrl = false)
669
+	{
670
+		$controller = new ObjectController($this->handler);
671
+
672
+		return $controller->getAdminViewItemLink($this, $onlyUrl);
673
+	}
674
+
675
+	/**
676
+	 * Retreive the object user side link
677
+	 *
678
+	 * @param  bool $onlyUrl wether or not to return a simple URL or a full <a> link
679
+	 * @return string user side link to the object
680
+	 */
681
+	public function getItemLink($onlyUrl = false)
682
+	{
683
+		$controller = new ObjectController($this->handler);
684
+
685
+		return $controller->getItemLink($this, $onlyUrl);
686
+	}
687
+
688
+	/**
689
+	 * @param  bool $onlyUrl
690
+	 * @param  bool $withimage
691
+	 * @param  bool $userSide
692
+	 * @return string
693
+	 */
694
+	public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
695
+	{
696
+		$controller = new ObjectController($this->handler);
697
+
698
+		return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
699
+	}
700
+
701
+	/**
702
+	 * @param  bool $onlyUrl
703
+	 * @param  bool $withimage
704
+	 * @param  bool $userSide
705
+	 * @return string
706
+	 */
707
+	public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
708
+	{
709
+		$controller = new ObjectController($this->handler);
710
+
711
+		return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
712
+	}
713
+
714
+	/**
715
+	 * @return string
716
+	 */
717
+	public function getPrintAndMailLink()
718
+	{
719
+		$controller = new ObjectController($this->handler);
720
+
721
+		return $controller->getPrintAndMailLink($this);
722
+	}
723
+
724
+	/**
725
+	 * @param $sortsel
726
+	 * @return array|bool
727
+	 */
728
+	public function getFieldsForSorting($sortsel)
729
+	{
730
+		$ret = [];
731
+
732
+		foreach ($this->vars as $key => $field_info) {
733
+			if ($field_info['sortby']) {
734
+				$ret[$key]['caption']  = $field_info['form_caption'];
735
+				$ret[$key]['selected'] = $key == $sortsel ? 'selected' : '';
736
+			}
737
+		}
738
+
739
+		if (count($ret) > 0) {
740
+			return $ret;
741
+		} else {
742
+			return false;
743
+		}
744
+	}
745
+
746
+	/**
747
+	 * @param $key
748
+	 * @param $newType
749
+	 */
750
+	public function setType($key, $newType)
751
+	{
752
+		$this->vars[$key]['data_type'] = $newType;
753
+	}
754
+
755
+	/**
756
+	 * @param $key
757
+	 * @param $info
758
+	 * @param $value
759
+	 */
760
+	public function setVarInfo($key, $info, $value)
761
+	{
762
+		$this->vars[$key][$info] = $value;
763
+	}
764
+
765
+	/**
766
+	 * @param         $key
767
+	 * @param  bool   $editor
768
+	 * @return string
769
+	 */
770
+	public function getValueFor($key, $editor = true)
771
+	{
772
+		/** @var Smartmedia\Helper $helper */
773
+		$helper = Smartmedia\Helper::getInstance();
774
+
775
+		$ret  = $this->getVar($key, 'n');
776
+		$myts = \MyTextSanitizer::getInstance();
777
+
778
+		$control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
779
+		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
780
+
781
+		$html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
782
+		$smiley   = true;
783
+		$xcode    = true;
784
+		$image    = true;
785
+		$br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
786
+		$formatML = true;
787
+
788
+		if ('default' === $form_editor) {
789
+			/** @var Smartmedia\Helper $helper */
790
+			$helper = Smartmedia\Helper::getInstance();
791
+
792
+			$form_editor = null !==($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea';
793
+		}
794
+
795
+		if ($editor) {
796
+			if (defined('XOOPS_EDITOR_IS_HTML')
797
+				&& !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) {
798
+				$br       = false;
799
+				$formatML = !$editor;
800
+			} else {
801
+				return htmlspecialchars($ret, ENT_QUOTES);
802
+			}
803
+		}
804
+
805
+		if (method_exists($myts, 'formatForML')) {
806
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
807
+		} else {
808
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
809
+		}
810
+	}
811
+
812
+	/**
813
+	 * clean values of all variables of the object for storage.
814
+	 * also add slashes whereever needed
815
+	 *
816
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
817
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
818
+	 * as a string separated by |
819
+	 *
820
+	 * @return bool true if successful
821
+	 * @access public
822
+	 */
823
+	public function cleanVars()
824
+	{
825
+		$ts              = \MyTextSanitizer::getInstance();
826
+		$existing_errors = $this->getErrors();
827
+		$this->_errors   = [];
828
+		foreach ($this->vars as $k => $v) {
829
+			$cleanv = $v['value'];
830
+			if (!$v['changed']) {
831
+			} else {
832
+				$cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
833
+				switch ($v['data_type']) {
834
+					case XOBJ_DTYPE_TXTBOX:
835
+						if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
836
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
837
+							continue 2;
838
+						}
839
+						if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
840
+							$this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
841
+							continue 2;
842
+						}
843
+						if (!$v['not_gpc']) {
844
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
845
+						} else {
846
+							$cleanv = $ts->censorString($cleanv);
847
+						}
848
+						break;
849
+					case XOBJ_DTYPE_TXTAREA:
850
+						if ($v['required'] && '0' != $cleanv && '' == $cleanv) {
851
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
852
+							continue 2;
853
+						}
854
+						if (!$v['not_gpc']) {
855
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
856
+						} else {
857
+							$cleanv = $ts->censorString($cleanv);
858
+						}
859
+						break;
860
+					case XOBJ_DTYPE_SOURCE:
861
+						if (!$v['not_gpc']) {
862
+							$cleanv = $ts->stripSlashesGPC($cleanv);
863
+						} else {
864
+							$cleanv = $cleanv;
865
+						}
866
+						break;
867
+					case XOBJ_DTYPE_INT:
868
+					case XOBJ_DTYPE_TIME_ONLY:
869
+						$cleanv = (int)$cleanv;
870
+						break;
871
+
872
+					case XOBJ_DTYPE_CURRENCY:
873
+						$cleanv = Smartobject\Utility::getCurrency($cleanv);
874
+						break;
875
+
876
+					case XOBJ_DTYPE_FLOAT:
877
+						$cleanv = Smartobject\Utility::float($cleanv);
878
+						break;
879
+
880
+					case XOBJ_DTYPE_EMAIL:
881
+						if ($v['required'] && '' === $cleanv) {
882
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
883
+							continue 2;
884
+						}
885
+						if ('' !== $cleanv
886
+							&& !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
887
+							$this->setErrors('Invalid Email');
888
+							continue 2;
889
+						}
890
+						if (!$v['not_gpc']) {
891
+							$cleanv = $ts->stripSlashesGPC($cleanv);
892
+						}
893
+						break;
894
+					case XOBJ_DTYPE_URL:
895
+						if ($v['required'] && '' === $cleanv) {
896
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
897
+							continue 2;
898
+						}
899
+						if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
900
+							$cleanv = 'http://' . $cleanv;
901
+						}
902
+						if (!$v['not_gpc']) {
903
+							$cleanv =& $ts->stripSlashesGPC($cleanv);
904
+						}
905
+						break;
906
+					case XOBJ_DTYPE_SIMPLE_ARRAY:
907
+						$cleanv = implode('|', $cleanv);
908
+						break;
909
+					case XOBJ_DTYPE_ARRAY:
910
+						$cleanv = serialize($cleanv);
911
+						break;
912
+					case XOBJ_DTYPE_STIME:
913
+					case XOBJ_DTYPE_MTIME:
914
+					case XOBJ_DTYPE_LTIME:
915
+						$cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
916
+						if (!($cleanv > 0)) {
917
+							$cleanv = strtotime($cleanv);
918
+						}
919
+						break;
920
+					default:
921
+						break;
922
+				}
923
+			}
924
+			$this->cleanVars[$k] =& $cleanv;
925
+			unset($cleanv);
926
+		}
927
+		if (count($this->_errors) > 0) {
928
+			$this->_errors = array_merge($existing_errors, $this->_errors);
929
+
930
+			return false;
931
+		}
932
+		$this->_errors = array_merge($existing_errors, $this->_errors);
933
+		$this->unsetDirty();
934
+
935
+		return true;
936
+	}
937
+
938
+	/**
939
+	 * returns a specific variable for the object in a proper format
940
+	 *
941
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
942
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
943
+	 * as a string separated by |
944
+	 *
945
+	 * @access public
946
+	 * @param  string $key    key of the object's variable to be returned
947
+	 * @param  string $format format to use for the output
948
+	 * @return mixed  formatted value of the variable
949
+	 */
950
+	public function getVar($key, $format = 's')
951
+	{
952
+		global $myts;
953
+
954
+		$ret = $this->vars[$key]['value'];
955
+
956
+		switch ($this->vars[$key]['data_type']) {
957
+
958
+			case XOBJ_DTYPE_TXTBOX:
959
+				switch (strtolower($format)) {
960
+					case 's':
961
+					case 'show':
962
+						// ML Hack by marcan
963
+						$ts  = \MyTextSanitizer::getInstance();
964
+						$ret = $ts->htmlSpecialChars($ret);
965
+
966
+						if (method_exists($myts, 'formatForML')) {
967
+							return $ts->formatForML($ret);
968
+						} else {
969
+							return $ret;
970
+						}
971
+						break 1;
972
+					// End of ML Hack by marcan
973
+
974
+					case 'clean':
975
+						$ts = \MyTextSanitizer::getInstance();
976
+
977
+						$ret = Smartobject\Utility::getHtml2text($ret);
978
+						$ret = Smartobject\Utility::purifyText($ret);
979
+
980
+						if (method_exists($myts, 'formatForML')) {
981
+							return $ts->formatForML($ret);
982
+						} else {
983
+							return $ret;
984
+						}
985
+						break 1;
986
+					// End of ML Hack by marcan
987
+
988
+					case 'e':
989
+					case 'edit':
990
+						$ts = \MyTextSanitizer::getInstance();
991
+
992
+						return $ts->htmlSpecialChars($ret);
993
+						break 1;
994
+					case 'p':
995
+					case 'preview':
996
+					case 'f':
997
+					case 'formpreview':
998
+						$ts = \MyTextSanitizer::getInstance();
999
+
1000
+						return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
1001
+						break 1;
1002
+					case 'n':
1003
+					case 'none':
1004
+					default:
1005
+						break 1;
1006
+				}
1007
+				break;
1008
+			case XOBJ_DTYPE_LTIME:
1009
+				switch (strtolower($format)) {
1010
+					case 's':
1011
+					case 'show':
1012
+					case 'p':
1013
+					case 'preview':
1014
+					case 'f':
1015
+					case 'formpreview':
1016
+						$ret = formatTimestamp($ret, _DATESTRING);
1017
+
1018
+						return $ret;
1019
+						break 1;
1020
+					case 'n':
1021
+					case 'none':
1022
+					case 'e':
1023
+					case 'edit':
1024
+						break 1;
1025
+					default:
1026
+						break 1;
1027
+				}
1028
+				break;
1029
+			case XOBJ_DTYPE_STIME:
1030
+				switch (strtolower($format)) {
1031
+					case 's':
1032
+					case 'show':
1033
+					case 'p':
1034
+					case 'preview':
1035
+					case 'f':
1036
+					case 'formpreview':
1037
+						$ret = formatTimestamp($ret, _SHORTDATESTRING);
1038
+
1039
+						return $ret;
1040
+						break 1;
1041
+					case 'n':
1042
+					case 'none':
1043
+					case 'e':
1044
+					case 'edit':
1045
+						break 1;
1046
+					default:
1047
+						break 1;
1048
+				}
1049
+				break;
1050
+			case XOBJ_DTYPE_TIME_ONLY:
1051
+				switch (strtolower($format)) {
1052
+					case 's':
1053
+					case 'show':
1054
+					case 'p':
1055
+					case 'preview':
1056
+					case 'f':
1057
+					case 'formpreview':
1058
+						$ret = formatTimestamp($ret, 'G:i');
1059
+
1060
+						return $ret;
1061
+						break 1;
1062
+					case 'n':
1063
+					case 'none':
1064
+					case 'e':
1065
+					case 'edit':
1066
+						break 1;
1067
+					default:
1068
+						break 1;
1069
+				}
1070
+				break;
1071
+
1072
+			case XOBJ_DTYPE_CURRENCY:
1073
+				$decimal_section_original = strstr($ret, '.');
1074
+				$decimal_section          = $decimal_section_original;
1075
+				if ($decimal_section) {
1076
+					if (1 == strlen($decimal_section)) {
1077
+						$decimal_section = '.00';
1078
+					} elseif (2 == strlen($decimal_section)) {
1079
+						$decimal_section .= '0';
1080
+					}
1081
+					$ret = str_replace($decimal_section_original, $decimal_section, $ret);
1082
+				} else {
1083
+					$ret .= '.00';
1084
+				}
1085
+				break;
1086
+
1087
+			case XOBJ_DTYPE_TXTAREA:
1088
+				switch (strtolower($format)) {
1089
+					case 's':
1090
+					case 'show':
1091
+						$ts   = \MyTextSanitizer::getInstance();
1092
+						$html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1093
+
1094
+						$xcode = (!isset($this->vars['doxcode']['value'])
1095
+								  || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1096
+
1097
+						$smiley = (!isset($this->vars['dosmiley']['value'])
1098
+								   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1099
+						$image  = (!isset($this->vars['doimage']['value'])
1100
+								   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1101
+						$br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1102
+
1103
+						/**
1104
+						 * Hack by marcan <INBOX> for SCSPRO
1105
+						 * Setting mastop as the main editor
1106
+						 */
1107
+						if (defined('XOOPS_EDITOR_IS_HTML')) {
1108
+							$br = false;
1109
+						}
1110
+
1111
+						/**
1112
+						 * Hack by marcan <INBOX> for SCSPRO
1113
+						 * Setting mastop as the main editor
1114
+						 */
1115
+
1116
+						return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1117
+						break 1;
1118
+					case 'e':
1119
+					case 'edit':
1120
+						return htmlspecialchars($ret, ENT_QUOTES);
1121
+						break 1;
1122
+					case 'p':
1123
+					case 'preview':
1124
+						$ts     = \MyTextSanitizer::getInstance();
1125
+						$html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1126
+						$xcode  = (!isset($this->vars['doxcode']['value'])
1127
+								   || 1 == $this->vars['doxcode']['value']) ? 1 : 0;
1128
+						$smiley = (!isset($this->vars['dosmiley']['value'])
1129
+								   || 1 == $this->vars['dosmiley']['value']) ? 1 : 0;
1130
+						$image  = (!isset($this->vars['doimage']['value'])
1131
+								   || 1 == $this->vars['doimage']['value']) ? 1 : 0;
1132
+						$br     = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0;
1133
+
1134
+						return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1135
+						break 1;
1136
+					case 'f':
1137
+					case 'formpreview':
1138
+						$ts = \MyTextSanitizer::getInstance();
1139
+
1140
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1141
+						break 1;
1142
+					case 'n':
1143
+					case 'none':
1144
+					default:
1145
+						break 1;
1146
+				}
1147
+				break;
1148
+			case XOBJ_DTYPE_SIMPLE_ARRAY:
1149
+				$ret =& explode('|', $ret);
1150
+				break;
1151
+			case XOBJ_DTYPE_ARRAY:
1152
+				$ret =& unserialize($ret);
1153
+				break;
1154
+			case XOBJ_DTYPE_SOURCE:
1155
+				switch (strtolower($format)) {
1156
+					case 's':
1157
+					case 'show':
1158
+						break 1;
1159
+					case 'e':
1160
+					case 'edit':
1161
+						return htmlspecialchars($ret, ENT_QUOTES);
1162
+						break 1;
1163
+					case 'p':
1164
+					case 'preview':
1165
+						$ts = \MyTextSanitizer::getInstance();
1166
+
1167
+						return $ts->stripSlashesGPC($ret);
1168
+						break 1;
1169
+					case 'f':
1170
+					case 'formpreview':
1171
+						$ts = \MyTextSanitizer::getInstance();
1172
+
1173
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1174
+						break 1;
1175
+					case 'n':
1176
+					case 'none':
1177
+					default:
1178
+						break 1;
1179
+				}
1180
+				break;
1181
+			default:
1182
+				if ('' !== $this->vars[$key]['options'] && '' != $ret) {
1183
+					switch (strtolower($format)) {
1184
+						case 's':
1185
+						case 'show':
1186
+							$selected = explode('|', $ret);
1187
+							$options  = explode('|', $this->vars[$key]['options']);
1188
+							$i        = 1;
1189
+							$ret      = [];
1190
+							foreach ($options as $op) {
1191
+								if (in_array($i, $selected)) {
1192
+									$ret[] = $op;
1193
+								}
1194
+								++$i;
1195
+							}
1196
+
1197
+							return implode(', ', $ret);
1198
+						case 'e':
1199
+						case 'edit':
1200
+							$ret = explode('|', $ret);
1201
+							break 1;
1202
+						default:
1203
+							break 1;
1204
+					}
1205
+				}
1206
+				break;
1207
+		}
1208
+
1209
+		return $ret;
1210
+	}
1211
+
1212
+	/**
1213
+	 * @param $key
1214
+	 */
1215
+	public function doMakeFieldreadOnly($key)
1216
+	{
1217
+		if (isset($this->vars[$key])) {
1218
+			$this->vars[$key]['readonly']      = true;
1219
+			$this->vars[$key]['displayOnForm'] = true;
1220
+		}
1221
+	}
1222
+
1223
+	/**
1224
+	 * @param $key
1225
+	 */
1226
+	public function makeFieldReadOnly($key)
1227
+	{
1228
+		if (is_array($key)) {
1229
+			foreach ($key as $v) {
1230
+				$this->doMakeFieldreadOnly($v);
1231
+			}
1232
+		} else {
1233
+			$this->doMakeFieldreadOnly($key);
1234
+		}
1235
+	}
1236
+
1237
+	/**
1238
+	 * @param $key
1239
+	 */
1240
+	public function doHideFieldFromForm($key)
1241
+	{
1242
+		if (isset($this->vars[$key])) {
1243
+			$this->vars[$key]['displayOnForm'] = false;
1244
+		}
1245
+	}
1246
+
1247
+	/**
1248
+	 * @param $key
1249
+	 */
1250
+	public function doHideFieldFromSingleView($key)
1251
+	{
1252
+		if (isset($this->vars[$key])) {
1253
+			$this->vars[$key]['displayOnSingleView'] = false;
1254
+		}
1255
+	}
1256
+
1257
+	/**
1258
+	 * @param $key
1259
+	 */
1260
+	public function hideFieldFromForm($key)
1261
+	{
1262
+		if (is_array($key)) {
1263
+			foreach ($key as $v) {
1264
+				$this->doHideFieldFromForm($v);
1265
+			}
1266
+		} else {
1267
+			$this->doHideFieldFromForm($key);
1268
+		}
1269
+	}
1270
+
1271
+	/**
1272
+	 * @param $key
1273
+	 */
1274
+	public function hideFieldFromSingleView($key)
1275
+	{
1276
+		if (is_array($key)) {
1277
+			foreach ($key as $v) {
1278
+				$this->doHideFieldFromSingleView($v);
1279
+			}
1280
+		} else {
1281
+			$this->doHideFieldFromSingleView($key);
1282
+		}
1283
+	}
1284
+
1285
+	/**
1286
+	 * @param $key
1287
+	 */
1288
+	public function doShowFieldOnForm($key)
1289
+	{
1290
+		if (isset($this->vars[$key])) {
1291
+			$this->vars[$key]['displayOnForm'] = true;
1292
+		}
1293
+	}
1294
+
1295
+	/**
1296
+	 * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1297
+	 *
1298
+	 * @param  bool  $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1299
+	 * @param  bool  $userSide  for futur use, to do something different on the user side
1300
+	 * @param  array $actions
1301
+	 * @param  bool  $headerAsRow
1302
+	 * @return string content of the template if $fetchOnly or nothing if !$fetchOnly
1303
+	 */
1304
+	public function displaySingleObject(
1305
+		$fetchOnly = false,
1306
+		$userSide = false,
1307
+		$actions = [],
1308
+		$headerAsRow = true
1309
+	) {
1310 1310
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1311
-        $singleview = new SingleView($this, $userSide, $actions, $headerAsRow);
1312
-        // add all fields mark as displayOnSingleView except the keyid
1313
-        foreach ($this->vars as $key => $var) {
1314
-            if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1315
-                $is_header = ($key == $this->handler->identifierName);
1316
-                $singleview->addRow(new ObjectRow($key, false, $is_header));
1317
-            }
1318
-        }
1319
-
1320
-        if ($fetchOnly) {
1321
-            $ret = $singleview->render($fetchOnly);
1322
-
1323
-            return $ret;
1324
-        } else {
1325
-            $singleview->render($fetchOnly);
1326
-        }
1327
-    }
1328
-
1329
-    /**
1330
-     * @param $key
1331
-     */
1332
-    public function doDisplayFieldOnSingleView($key)
1333
-    {
1334
-        if (isset($this->vars[$key])) {
1335
-            $this->vars[$key]['displayOnSingleView'] = true;
1336
-        }
1337
-    }
1338
-
1339
-    /**
1340
-     * @param      $field
1341
-     * @param bool $required
1342
-     */
1343
-    public function doSetFieldAsRequired($field, $required = true)
1344
-    {
1345
-        $this->setVarInfo($field, 'required', $required);
1346
-    }
1347
-
1348
-    /**
1349
-     * @param $field
1350
-     */
1351
-    public function doSetFieldForSorting($field)
1352
-    {
1353
-        $this->setVarInfo($field, 'sortby', true);
1354
-    }
1355
-
1356
-    /**
1357
-     * @param $key
1358
-     */
1359
-    public function showFieldOnForm($key)
1360
-    {
1361
-        if (is_array($key)) {
1362
-            foreach ($key as $v) {
1363
-                $this->doShowFieldOnForm($v);
1364
-            }
1365
-        } else {
1366
-            $this->doShowFieldOnForm($key);
1367
-        }
1368
-    }
1369
-
1370
-    /**
1371
-     * @param $key
1372
-     */
1373
-    public function displayFieldOnSingleView($key)
1374
-    {
1375
-        if (is_array($key)) {
1376
-            foreach ($key as $v) {
1377
-                $this->doDisplayFieldOnSingleView($v);
1378
-            }
1379
-        } else {
1380
-            $this->doDisplayFieldOnSingleView($key);
1381
-        }
1382
-    }
1383
-
1384
-    /**
1385
-     * @param $key
1386
-     */
1387
-    public function doSetAdvancedFormFields($key)
1388
-    {
1389
-        if (isset($this->vars[$key])) {
1390
-            $this->vars[$key]['advancedform'] = true;
1391
-        }
1392
-    }
1393
-
1394
-    /**
1395
-     * @param $key
1396
-     */
1397
-    public function setAdvancedFormFields($key)
1398
-    {
1399
-        if (is_array($key)) {
1400
-            foreach ($key as $v) {
1401
-                $this->doSetAdvancedFormFields($v);
1402
-            }
1403
-        } else {
1404
-            $this->doSetAdvancedFormFields($key);
1405
-        }
1406
-    }
1407
-
1408
-    /**
1409
-     * @param $key
1410
-     * @return mixed
1411
-     */
1412
-    public function getUrlLinkObj($key)
1413
-    {
1414
-        $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1415
-        $urllinkid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1416
-        if (0 != $urllinkid) {
1417
-            return $smartobjectLinkurlHandler->get($urllinkid);
1418
-        } else {
1419
-            return $smartobjectLinkurlHandler->create();
1420
-        }
1421
-    }
1422
-
1423
-    /**
1424
-     * @param $urlLinkObj
1425
-     * @return mixed
1426
-     */
1427
-    public function &storeUrlLinkObj($urlLinkObj)
1428
-    {
1429
-        $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1430
-
1431
-        return $smartobjectLinkurlHandler->insert($urlLinkObj);
1432
-    }
1433
-
1434
-    /**
1435
-     * @param $key
1436
-     * @return mixed
1437
-     */
1438
-    public function getFileObj($key)
1439
-    {
1440
-        $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1441
-        $fileid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1442
-        if (0 != $fileid) {
1443
-            return $smartobjectFileHandler->get($fileid);
1444
-        } else {
1445
-            return $smartobjectFileHandler->create();
1446
-        }
1447
-    }
1448
-
1449
-    /**
1450
-     * @param $fileObj
1451
-     * @return mixed
1452
-     */
1453
-    public function &storeFileObj($fileObj)
1454
-    {
1455
-        $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1456
-
1457
-        return $smartobjectFileHandler->insert($fileObj);
1458
-    }
1311
+		$singleview = new SingleView($this, $userSide, $actions, $headerAsRow);
1312
+		// add all fields mark as displayOnSingleView except the keyid
1313
+		foreach ($this->vars as $key => $var) {
1314
+			if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1315
+				$is_header = ($key == $this->handler->identifierName);
1316
+				$singleview->addRow(new ObjectRow($key, false, $is_header));
1317
+			}
1318
+		}
1319
+
1320
+		if ($fetchOnly) {
1321
+			$ret = $singleview->render($fetchOnly);
1322
+
1323
+			return $ret;
1324
+		} else {
1325
+			$singleview->render($fetchOnly);
1326
+		}
1327
+	}
1328
+
1329
+	/**
1330
+	 * @param $key
1331
+	 */
1332
+	public function doDisplayFieldOnSingleView($key)
1333
+	{
1334
+		if (isset($this->vars[$key])) {
1335
+			$this->vars[$key]['displayOnSingleView'] = true;
1336
+		}
1337
+	}
1338
+
1339
+	/**
1340
+	 * @param      $field
1341
+	 * @param bool $required
1342
+	 */
1343
+	public function doSetFieldAsRequired($field, $required = true)
1344
+	{
1345
+		$this->setVarInfo($field, 'required', $required);
1346
+	}
1347
+
1348
+	/**
1349
+	 * @param $field
1350
+	 */
1351
+	public function doSetFieldForSorting($field)
1352
+	{
1353
+		$this->setVarInfo($field, 'sortby', true);
1354
+	}
1355
+
1356
+	/**
1357
+	 * @param $key
1358
+	 */
1359
+	public function showFieldOnForm($key)
1360
+	{
1361
+		if (is_array($key)) {
1362
+			foreach ($key as $v) {
1363
+				$this->doShowFieldOnForm($v);
1364
+			}
1365
+		} else {
1366
+			$this->doShowFieldOnForm($key);
1367
+		}
1368
+	}
1369
+
1370
+	/**
1371
+	 * @param $key
1372
+	 */
1373
+	public function displayFieldOnSingleView($key)
1374
+	{
1375
+		if (is_array($key)) {
1376
+			foreach ($key as $v) {
1377
+				$this->doDisplayFieldOnSingleView($v);
1378
+			}
1379
+		} else {
1380
+			$this->doDisplayFieldOnSingleView($key);
1381
+		}
1382
+	}
1383
+
1384
+	/**
1385
+	 * @param $key
1386
+	 */
1387
+	public function doSetAdvancedFormFields($key)
1388
+	{
1389
+		if (isset($this->vars[$key])) {
1390
+			$this->vars[$key]['advancedform'] = true;
1391
+		}
1392
+	}
1393
+
1394
+	/**
1395
+	 * @param $key
1396
+	 */
1397
+	public function setAdvancedFormFields($key)
1398
+	{
1399
+		if (is_array($key)) {
1400
+			foreach ($key as $v) {
1401
+				$this->doSetAdvancedFormFields($v);
1402
+			}
1403
+		} else {
1404
+			$this->doSetAdvancedFormFields($key);
1405
+		}
1406
+	}
1407
+
1408
+	/**
1409
+	 * @param $key
1410
+	 * @return mixed
1411
+	 */
1412
+	public function getUrlLinkObj($key)
1413
+	{
1414
+		$smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1415
+		$urllinkid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1416
+		if (0 != $urllinkid) {
1417
+			return $smartobjectLinkurlHandler->get($urllinkid);
1418
+		} else {
1419
+			return $smartobjectLinkurlHandler->create();
1420
+		}
1421
+	}
1422
+
1423
+	/**
1424
+	 * @param $urlLinkObj
1425
+	 * @return mixed
1426
+	 */
1427
+	public function &storeUrlLinkObj($urlLinkObj)
1428
+	{
1429
+		$smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink');
1430
+
1431
+		return $smartobjectLinkurlHandler->insert($urlLinkObj);
1432
+	}
1433
+
1434
+	/**
1435
+	 * @param $key
1436
+	 * @return mixed
1437
+	 */
1438
+	public function getFileObj($key)
1439
+	{
1440
+		$smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1441
+		$fileid                 = null !== $this->getVar($key) ? $this->getVar($key) : 0;
1442
+		if (0 != $fileid) {
1443
+			return $smartobjectFileHandler->get($fileid);
1444
+		} else {
1445
+			return $smartobjectFileHandler->create();
1446
+		}
1447
+	}
1448
+
1449
+	/**
1450
+	 * @param $fileObj
1451
+	 * @return mixed
1452
+	 */
1453
+	public function &storeFileObj($fileObj)
1454
+	{
1455
+		$smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File');
1456
+
1457
+		return $smartobjectFileHandler->insert($fileObj);
1458
+	}
1459 1459
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 
18 18
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
19 19
 
20
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
20
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
21 21
 
22 22
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
23 23
     define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function closeSection($section_name)
118 118
     {
119
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
119
+        $this->initVar('close_section_'.$section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
120 120
     }
121 121
 
122 122
     /**
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
         }
155 155
         parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
156 156
         if ($this->handler && (!$form_caption || '' === $form_caption)) {
157
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
157
+            $dyn_form_caption = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key);
158 158
             if (defined($dyn_form_caption)) {
159 159
                 $form_caption = constant($dyn_form_caption);
160 160
             }
161 161
         }
162 162
         if ($this->handler && (!$form_dsc || '' === $form_dsc)) {
163
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
163
+            $dyn_form_dsc = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key.'_DSC');
164 164
             if (defined($dyn_form_dsc)) {
165 165
                 $form_dsc = constant($dyn_form_dsc);
166 166
             }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     public function toArray()
457 457
     {
458 458
         $ret  = [];
459
-        $vars =& $this->getVars();
459
+        $vars = & $this->getVars();
460 460
         foreach ($vars as $key => $var) {
461 461
             $value     = $this->getVar($key);
462 462
             $ret[$key] = $value;
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             }
506 506
         } else {
507 507
             if ($prefix) {
508
-                $err_str = '[' . $prefix . '] ' . $err_str;
508
+                $err_str = '['.$prefix.'] '.$err_str;
509 509
             }
510 510
             parent::setErrors($err_str);
511 511
         }
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             /** @var Smartmedia\Helper $helper */
790 790
             $helper = Smartmedia\Helper::getInstance();
791 791
 
792
-            $form_editor = null !==($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea';
792
+            $form_editor = null !== ($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea';
793 793
         }
794 794
 
795 795
         if ($editor) {
@@ -836,8 +836,8 @@  discard block
 block discarded – undo
836 836
                             $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
837 837
                             continue 2;
838 838
                         }
839
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
840
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
839
+                        if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) {
840
+                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength']));
841 841
                             continue 2;
842 842
                         }
843 843
                         if (!$v['not_gpc']) {
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
                         break;
867 867
                     case XOBJ_DTYPE_INT:
868 868
                     case XOBJ_DTYPE_TIME_ONLY:
869
-                        $cleanv = (int)$cleanv;
869
+                        $cleanv = (int) $cleanv;
870 870
                         break;
871 871
 
872 872
                     case XOBJ_DTYPE_CURRENCY:
@@ -897,10 +897,10 @@  discard block
 block discarded – undo
897 897
                             continue 2;
898 898
                         }
899 899
                         if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
900
-                            $cleanv = 'http://' . $cleanv;
900
+                            $cleanv = 'http://'.$cleanv;
901 901
                         }
902 902
                         if (!$v['not_gpc']) {
903
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
903
+                            $cleanv = & $ts->stripSlashesGPC($cleanv);
904 904
                         }
905 905
                         break;
906 906
                     case XOBJ_DTYPE_SIMPLE_ARRAY:
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
                     case XOBJ_DTYPE_STIME:
913 913
                     case XOBJ_DTYPE_MTIME:
914 914
                     case XOBJ_DTYPE_LTIME:
915
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
915
+                        $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv);
916 916
                         if (!($cleanv > 0)) {
917 917
                             $cleanv = strtotime($cleanv);
918 918
                         }
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
                         break;
922 922
                 }
923 923
             }
924
-            $this->cleanVars[$k] =& $cleanv;
924
+            $this->cleanVars[$k] = & $cleanv;
925 925
             unset($cleanv);
926 926
         }
927 927
         if (count($this->_errors) > 0) {
@@ -1146,10 +1146,10 @@  discard block
 block discarded – undo
1146 1146
                 }
1147 1147
                 break;
1148 1148
             case XOBJ_DTYPE_SIMPLE_ARRAY:
1149
-                $ret =& explode('|', $ret);
1149
+                $ret = & explode('|', $ret);
1150 1150
                 break;
1151 1151
             case XOBJ_DTYPE_ARRAY:
1152
-                $ret =& unserialize($ret);
1152
+                $ret = & unserialize($ret);
1153 1153
                 break;
1154 1154
             case XOBJ_DTYPE_SOURCE:
1155 1155
                 switch (strtolower($format)) {
Please login to merge, or discard this patch.
class/ObjectController.php 2 patches
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.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
         foreach (array_keys($smartObj->vars) as $key) {
53 53
             switch ($smartObj->vars[$key]['data_type']) {
54 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]);
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 58
                         if (file_exists($oldFile)) {
59 59
                             unlink($oldFile);
60 60
                         }
61 61
                     }
62
-                    if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) {
63
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
62
+                    if (isset($_POST['delete_'.$key]) && '1' == $_POST['delete_'.$key]) {
63
+                        $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e');
64 64
                         $smartObj->setVar($key, '');
65 65
                         if (file_exists($oldFile)) {
66 66
                             unlink($oldFile);
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 
71 71
                 case XOBJ_DTYPE_URLLINK:
72 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]);
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 77
                     if ('' !== $linkObj->getVar('url')) {
78 78
                         $smartObj->storeUrlLinkObj($linkObj);
79 79
                     }
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
                     break;
83 83
 
84 84
                 case XOBJ_DTYPE_FILE:
85
-                    if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) {
85
+                    if (!isset($_FILES['upload_'.$key]['name']) || '' === $_FILES['upload_'.$key]['name']) {
86 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]);
87
+                        $fileObj->setVar('caption', $_POST['caption_'.$key]);
88
+                        $fileObj->setVar('description', $_POST['desc_'.$key]);
89
+                        $fileObj->setVar('url', $_POST['url_'.$key]);
90 90
                         if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url')
91 91
                               && '' === $fileObj->getVar('url'))) {
92 92
                             $res = $smartObj->storeFileObj($fileObj);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
                         $value = strtotime($_POST[$key]);
111 111
                         //if strtotime returns false, the value is already a time stamp
112 112
                         if (!$value) {
113
-                            $value = (int)$_POST[$key];
113
+                            $value = (int) $_POST[$key];
114 114
                         }
115 115
                     }
116 116
                     $smartObj->setVar($key, $value);
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                 if (isset($file_array['name']) && '' !== $file_array['name']
160 160
                     && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
161 161
                     if ($uploaderObj->fetchMedia($name)) {
162
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
162
+                        $uploaderObj->setTargetFileName(time().'_'.$uploaderObj->getMediaName());
163 163
                         if ($uploaderObj->upload()) {
164 164
                             // Find the related field in the SmartObject
165 165
                             $related_field   = str_replace('upload_', '', $name);
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
                             if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) {
169 169
                                 $object_fileurl = $smartObj->getUploadDir();
170 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]);
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 174
                                 $smartObj->storeFileObj($fileObj);
175 175
                                 //todo: catch errors
176 176
                                 $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
177 177
                             } else {
178
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
178
+                                $old_file = $smartObj->getUploadDir(true).$smartObj->getVar($related_field);
179 179
                                 unlink($old_file);
180 180
                                 $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
181 181
                             }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             return $smartObj;
207 207
         } else {
208 208
             if (!$storeResult) {
209
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
209
+                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR.$smartObj->getHtmlErrors());
210 210
             }
211 211
 
212 212
             $redirect_page = $redirect_page ?: Smartobject\Utility::getPageBeforeForm();
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         $debug = false,
236 236
         $x_param = false
237 237
     ) {
238
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
238
+        $objectid = isset($_POST[$this->handler->keyName]) ? (int) $_POST[$this->handler->keyName] : 0;
239 239
         if ($debug) {
240 240
             if ($x_param) {
241 241
                 $smartObj = $this->handler->getD($objectid, true, $x_param);
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     {
312 312
         global $smart_previous_page;
313 313
 
314
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
314
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
315 315
         $smartObj = $this->handler->get($objectid);
316 316
 
317 317
         if ($smartObj->isNew()) {
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
         $confirm = \Xmf\Request::getInt('confirm', 0, POST);
322 322
         if ($confirm) {
323 323
             if (!$this->handler->delete($smartObj)) {
324
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
324
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
325 325
             }
326 326
 
327 327
             redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
     {
355 355
         global $smart_previous_page, $xoopsTpl;
356 356
 
357
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
357
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
358 358
         $smartObj = $this->handler->get($objectid);
359 359
 
360 360
         if ($smartObj->isNew()) {
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
         $confirm = \Xmf\Request::getInt('confirm', 0, POST);
365 365
         if ($confirm) {
366 366
             if (!$this->handler->delete($smartObj)) {
367
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
367
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
368 368
             }
369 369
 
370 370
             redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
@@ -396,14 +396,14 @@  discard block
 block discarded – undo
396 396
      */
397 397
     public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
398 398
     {
399
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
399
+        $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=view&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
400 400
         if ($onlyUrl) {
401 401
             return $ret;
402 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>";
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 404
         }
405 405
 
406
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
406
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
407 407
     }
408 408
 
409 409
     /**
@@ -425,15 +425,15 @@  discard block
 block discarded – undo
425 425
         $seoIncludeId = true;
426 426
 
427 427
         if ('rewrite' === $seoMode) {
428
-            $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
428
+            $ret = XOOPS_URL.'/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html';
429 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';
430
+            $ret = SMARTOBJECT_URL.'seo.php/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html';
431 431
         } else {
432
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
432
+            $ret = $this->handler->_moduleUrl.$this->handler->_page.'?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
433 433
         }
434 434
 
435 435
         if (!$onlyUrl) {
436
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
436
+            $ret = "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
437 437
         }
438 438
 
439 439
         return $ret;
@@ -447,14 +447,14 @@  discard block
 block discarded – undo
447 447
      */
448 448
     public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
449 449
     {
450
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
450
+        $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName).'&language='.$smartObj->getVar('language');
451 451
         if ($onlyUrl) {
452 452
             return $ret;
453 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>";
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 455
         }
456 456
 
457
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
457
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
458 458
     }
459 459
 
460 460
     /**
@@ -467,14 +467,14 @@  discard block
 block discarded – undo
467 467
     public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
468 468
     {
469 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);
470
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
471 471
         if ($onlyUrl) {
472 472
             return $ret;
473 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>";
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 475
         }
476 476
 
477
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
477
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
478 478
     }
479 479
 
480 480
     /**
@@ -487,14 +487,14 @@  discard block
 block discarded – undo
487 487
     public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
488 488
     {
489 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);
490
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=del&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
491 491
         if ($onlyUrl) {
492 492
             return $ret;
493 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>";
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 495
         }
496 496
 
497
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
497
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
498 498
     }
499 499
 
500 500
     /**
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
     {
506 506
         global $xoopsConfig;
507 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>';
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 511
 
512 512
         $smartModule = Smartobject\Utility::getModuleInfo($smartObj->handler->_moduleName);
513 513
         $link        = Smartobject\Utility::getCurrentPage();
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
                        . _CO_SOBJECT_EMAIL
527 527
                        . '" style="vertical-align: middle;"></a>';
528 528
 
529
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
529
+        $ret = '<span id="smartobject_print_button">'.$printlink.'&nbsp;</span>'.'<span id="smartobject_mail_button">'.$friendlink.'</span>';
530 530
 
531 531
         return $ret;
532 532
     }
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
      */
537 537
     public function getModuleItemString()
538 538
     {
539
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
539
+        $ret = $this->handler->_moduleName.'_'.$this->handler->_itemname;
540 540
 
541 541
         return $ret;
542 542
     }
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/Helper.php 2 patches
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.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     protected function __construct($debug = false)
35 35
     {
36
-        $this->debug   = $debug;
36
+        $this->debug = $debug;
37 37
        $moduleDirName = basename(dirname(__DIR__));
38 38
        parent::__construct($moduleDirName);
39 39
     }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $ret   = false;
74 74
         $db    = \XoopsDatabaseFactory::getDatabaseConnection();
75
-        $class = '\\XoopsModules\\' . ucfirst(strtolower(basename(dirname(__DIR__)))) . '\\' . $name . 'Handler';
75
+        $class = '\\XoopsModules\\'.ucfirst(strtolower(basename(dirname(__DIR__)))).'\\'.$name.'Handler';
76 76
         $ret   = new $class($db);
77 77
         return $ret;
78 78
     }
Please login to merge, or discard this patch.
include/common.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 use XoopsModules\Smartobject;
11 11
 
12
-require_once __DIR__ . '/../preloads/autoloader.php';
12
+require_once __DIR__.'/../preloads/autoloader.php';
13 13
 
14 14
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
15 15
 
@@ -19,30 +19,30 @@  discard block
 block discarded – undo
19 19
  * SmartObject library path
20 20
  */
21 21
 if (!defined('SMARTOBJECT_URL')) {
22
-    define('SMARTOBJECT_URL', XOOPS_URL . '/modules/smartobject/');
22
+    define('SMARTOBJECT_URL', XOOPS_URL.'/modules/smartobject/');
23 23
 }
24 24
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
25
-    define('SMARTOBJECT_ROOT_PATH', XOOPS_ROOT_PATH . '/modules/smartobject/');
25
+    define('SMARTOBJECT_ROOT_PATH', XOOPS_ROOT_PATH.'/modules/smartobject/');
26 26
 }
27 27
 if (!defined('SMARTOBJECT_IMAGES_URL')) {
28
-    define('SMARTOBJECT_IMAGES_URL', SMARTOBJECT_URL . 'assets/images/');
28
+    define('SMARTOBJECT_IMAGES_URL', SMARTOBJECT_URL.'assets/images/');
29 29
 }
30 30
 if (!defined('SMARTOBJECT_IMAGES_ROOT_PATH')) {
31
-    define('SMARTOBJECT_IMAGES_ROOT_PATH', SMARTOBJECT_ROOT_PATH . 'assets/images/');
31
+    define('SMARTOBJECT_IMAGES_ROOT_PATH', SMARTOBJECT_ROOT_PATH.'assets/images/');
32 32
 }
33 33
 if (!defined('SMARTOBJECT_IMAGES_ACTIONS_URL')) {
34
-    define('SMARTOBJECT_IMAGES_ACTIONS_URL', SMARTOBJECT_URL . 'assets/images/actions/');
34
+    define('SMARTOBJECT_IMAGES_ACTIONS_URL', SMARTOBJECT_URL.'assets/images/actions/');
35 35
 }
36 36
 if (!defined('SMARTOBJECT_IMAGES_ACTIONS_ROOT_PATH')) {
37
-    define('SMARTOBJECT_IMAGES_ACTIONS_ROOT_PATH', SMARTOBJECT_ROOT_PATH . 'assets/images/actions/');
37
+    define('SMARTOBJECT_IMAGES_ACTIONS_ROOT_PATH', SMARTOBJECT_ROOT_PATH.'assets/images/actions/');
38 38
 }
39 39
 
40 40
 /**
41 41
  * Version of the SmartObject Framework
42 42
  */
43
-require_once SMARTOBJECT_ROOT_PATH . 'include/version.php';
43
+require_once SMARTOBJECT_ROOT_PATH.'include/version.php';
44 44
 //require_once SMARTOBJECT_ROOT_PATH . 'include/functions.php';
45
-require_once SMARTOBJECT_ROOT_PATH . 'include/xoops_core_common_functions.php';
45
+require_once SMARTOBJECT_ROOT_PATH.'include/xoops_core_common_functions.php';
46 46
 
47 47
 /**
48 48
  * Some constants used by the SmartObjects
Please login to merge, or discard this patch.