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