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