Completed
Push — master ( 01b1a5...81f493 )
by Michael
04:03
created
class/adsense.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     /**
93 93
      * @param  string $key
94 94
      * @param  string $format
95
-     * @return mixed
95
+     * @return string
96 96
      */
97 97
     public function getVar($key, $format = 's')
98 98
     {
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     }
158 158
 
159 159
     /**
160
-     * @return mixed|string
160
+     * @return string
161 161
      */
162 162
     public function generateTag()
163 163
     {
Please login to merge, or discard this patch.
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -36,87 +36,87 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class SmartobjectAdsense extends SmartObject
38 38
 {
39
-    /**
40
-     * SmartobjectAdsense constructor.
41
-     */
42
-    public function __construct()
43
-    {
44
-        $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true);
45
-        $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC);
46
-        $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC);
47
-        $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC);
48
-        $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC);
49
-        $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC);
50
-        $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC);
51
-        $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC);
52
-        $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC);
53
-        $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC);
54
-        $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC);
55
-
56
-        $this->setControl('format', array(
57
-            'handler' => 'adsense',
58
-            'method'  => 'getFormats'
59
-        ));
60
-
61
-        $this->setControl('border_color', array(
62
-            'name'      => 'text',
63
-            'size'      => 6,
64
-            'maxlength' => 6
65
-        ));
66
-
67
-        $this->setControl('background_color', array(
68
-            'name'      => 'text',
69
-            'size'      => 6,
70
-            'maxlength' => 6
71
-        ));
72
-
73
-        $this->setControl('link_color', array(
74
-            'name'      => 'text',
75
-            'size'      => 6,
76
-            'maxlength' => 6
77
-        ));
78
-
79
-        $this->setControl('url_color', array(
80
-            'name'      => 'text',
81
-            'size'      => 6,
82
-            'maxlength' => 6
83
-        ));
84
-
85
-        $this->setControl('text_color', array(
86
-            'name'      => 'text',
87
-            'size'      => 6,
88
-            'maxlength' => 6
89
-        ));
90
-    }
91
-
92
-    /**
93
-     * @param  string $key
94
-     * @param  string $format
95
-     * @return mixed
96
-     */
97
-    public function getVar($key, $format = 's')
98
-    {
99
-        if ($format === 's' && in_array($key, array())) {
100
-            //            return call_user_func(array($this, $key));
101
-            return $this->{$key}();
102
-        }
103
-
104
-        return parent::getVar($key, $format);
105
-    }
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function render()
111
-    {
112
-        global $smartobjectAdsenseHandler;
113
-        if ($this->getVar('style', 'n') !== '') {
114
-            $ret = '<div style="' . $this->getVar('style', 'n') . '">';
115
-        } else {
116
-            $ret = '<div>';
117
-        }
118
-
119
-        $ret .= '<script type="text/javascript"><!--
39
+	/**
40
+	 * SmartobjectAdsense constructor.
41
+	 */
42
+	public function __construct()
43
+	{
44
+		$this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true);
45
+		$this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC);
46
+		$this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC);
47
+		$this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC);
48
+		$this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC);
49
+		$this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC);
50
+		$this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC);
51
+		$this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC);
52
+		$this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC);
53
+		$this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC);
54
+		$this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC);
55
+
56
+		$this->setControl('format', array(
57
+			'handler' => 'adsense',
58
+			'method'  => 'getFormats'
59
+		));
60
+
61
+		$this->setControl('border_color', array(
62
+			'name'      => 'text',
63
+			'size'      => 6,
64
+			'maxlength' => 6
65
+		));
66
+
67
+		$this->setControl('background_color', array(
68
+			'name'      => 'text',
69
+			'size'      => 6,
70
+			'maxlength' => 6
71
+		));
72
+
73
+		$this->setControl('link_color', array(
74
+			'name'      => 'text',
75
+			'size'      => 6,
76
+			'maxlength' => 6
77
+		));
78
+
79
+		$this->setControl('url_color', array(
80
+			'name'      => 'text',
81
+			'size'      => 6,
82
+			'maxlength' => 6
83
+		));
84
+
85
+		$this->setControl('text_color', array(
86
+			'name'      => 'text',
87
+			'size'      => 6,
88
+			'maxlength' => 6
89
+		));
90
+	}
91
+
92
+	/**
93
+	 * @param  string $key
94
+	 * @param  string $format
95
+	 * @return mixed
96
+	 */
97
+	public function getVar($key, $format = 's')
98
+	{
99
+		if ($format === 's' && in_array($key, array())) {
100
+			//            return call_user_func(array($this, $key));
101
+			return $this->{$key}();
102
+		}
103
+
104
+		return parent::getVar($key, $format);
105
+	}
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function render()
111
+	{
112
+		global $smartobjectAdsenseHandler;
113
+		if ($this->getVar('style', 'n') !== '') {
114
+			$ret = '<div style="' . $this->getVar('style', 'n') . '">';
115
+		} else {
116
+			$ret = '<div>';
117
+		}
118
+
119
+		$ret .= '<script type="text/javascript"><!--
120 120
 google_ad_client = "' . $this->getVar('client_id', 'n') . '";
121 121
 google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . ';
122 122
 google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . ';
@@ -134,120 +134,120 @@  discard block
 block discarded – undo
134 134
 </script>
135 135
 </div>';
136 136
 
137
-        return $ret;
138
-    }
139
-
140
-    /**
141
-     * @return string
142
-     */
143
-    public function getXoopsCode()
144
-    {
145
-        $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]';
146
-
147
-        return $ret;
148
-    }
149
-
150
-    /**
151
-     * @param $var
152
-     * @return bool
153
-     */
154
-    public function emptyString($var)
155
-    {
156
-        return (strlen($var) > 0);
157
-    }
158
-
159
-    /**
160
-     * @return mixed|string
161
-     */
162
-    public function generateTag()
163
-    {
164
-        $title = rawurlencode(strtolower($this->getVar('description', 'e')));
165
-        $title = xoops_substr($title, 0, 10, '');
166
-        // Transformation des ponctuations
167
-        $pattern = array(
168
-            '/%09/', // Tab
169
-            '/%20/', // Space
170
-            '/%21/', // !
171
-            '/%22/', // "
172
-            '/%23/', // #
173
-            '/%25/', // %
174
-            '/%26/', // &
175
-            '/%27/', // '
176
-            '/%28/', // (
177
-            '/%29/', // )
178
-            '/%2C/', // ,
179
-            '/%2F/', // /
180
-            '/%3A/', // :
181
-            '/%3B/', // ;
182
-            '/%3C/', // <
183
-            '/%3D/', // =
184
-            '/%3E/', // >
185
-            '/%3F/', // ?
186
-            '/%40/', // @
187
-            '/%5B/', // [
188
-            '/%5C/', // \
189
-            '/%5D/', // ]
190
-            '/%5E/', // ^
191
-            '/%7B/', // {
192
-            '/%7C/', // |
193
-            '/%7D/', // }
194
-            '/%7E/', // ~
195
-            "/\./" // .
196
-        );
197
-        $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
198
-        $title   = preg_replace($pattern, $rep_pat, $title);
199
-
200
-        // Transformation des caract�res accentu�s
201
-        $pattern = array(
202
-            '/%B0/', // °
203
-            '/%E8/', // è
204
-            '/%E9/', // é
205
-            '/%EA/', // ê
206
-            '/%EB/', // ë
207
-            '/%E7/', // ç
208
-            '/%E0/', // à
209
-            '/%E2/', // â
210
-            '/%E4/', // ä
211
-            '/%EE/', // î
212
-            '/%EF/', // ï
213
-            '/%F9/', // ù
214
-            '/%FC/', // ü
215
-            '/%FB/', // û
216
-            '/%F4/', // ô
217
-            '/%F6/', // ö
218
-        );
219
-        $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o');
220
-        $title   = preg_replace($pattern, $rep_pat, $title);
221
-
222
-        $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
223
-        $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau
224
-        $title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
225
-
226
-        $title .= time();
227
-        $title = md5($title);
228
-
229
-        return $title;
230
-    }
231
-
232
-    /**
233
-     * @return string
234
-     */
235
-    public function getCloneLink()
236
-    {
237
-        $ret = '<a href="' .
238
-               SMARTOBJECT_URL .
239
-               'admin/adsense.php?op=clone&adsenseid=' .
240
-               $this->getVar('adsenseid') .
241
-               '"><img src="' .
242
-               SMARTOBJECT_IMAGES_ACTIONS_URL .
243
-               'editcopy.png" alt="' .
244
-               _CO_SOBJECT_ADSENSE_CLONE .
245
-               '" title="' .
246
-               _CO_SOBJECT_ADSENSE_CLONE .
247
-               '" /></a>';
248
-
249
-        return $ret;
250
-    }
137
+		return $ret;
138
+	}
139
+
140
+	/**
141
+	 * @return string
142
+	 */
143
+	public function getXoopsCode()
144
+	{
145
+		$ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]';
146
+
147
+		return $ret;
148
+	}
149
+
150
+	/**
151
+	 * @param $var
152
+	 * @return bool
153
+	 */
154
+	public function emptyString($var)
155
+	{
156
+		return (strlen($var) > 0);
157
+	}
158
+
159
+	/**
160
+	 * @return mixed|string
161
+	 */
162
+	public function generateTag()
163
+	{
164
+		$title = rawurlencode(strtolower($this->getVar('description', 'e')));
165
+		$title = xoops_substr($title, 0, 10, '');
166
+		// Transformation des ponctuations
167
+		$pattern = array(
168
+			'/%09/', // Tab
169
+			'/%20/', // Space
170
+			'/%21/', // !
171
+			'/%22/', // "
172
+			'/%23/', // #
173
+			'/%25/', // %
174
+			'/%26/', // &
175
+			'/%27/', // '
176
+			'/%28/', // (
177
+			'/%29/', // )
178
+			'/%2C/', // ,
179
+			'/%2F/', // /
180
+			'/%3A/', // :
181
+			'/%3B/', // ;
182
+			'/%3C/', // <
183
+			'/%3D/', // =
184
+			'/%3E/', // >
185
+			'/%3F/', // ?
186
+			'/%40/', // @
187
+			'/%5B/', // [
188
+			'/%5C/', // \
189
+			'/%5D/', // ]
190
+			'/%5E/', // ^
191
+			'/%7B/', // {
192
+			'/%7C/', // |
193
+			'/%7D/', // }
194
+			'/%7E/', // ~
195
+			"/\./" // .
196
+		);
197
+		$rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
198
+		$title   = preg_replace($pattern, $rep_pat, $title);
199
+
200
+		// Transformation des caract�res accentu�s
201
+		$pattern = array(
202
+			'/%B0/', // °
203
+			'/%E8/', // è
204
+			'/%E9/', // é
205
+			'/%EA/', // ê
206
+			'/%EB/', // ë
207
+			'/%E7/', // ç
208
+			'/%E0/', // à
209
+			'/%E2/', // â
210
+			'/%E4/', // ä
211
+			'/%EE/', // î
212
+			'/%EF/', // ï
213
+			'/%F9/', // ù
214
+			'/%FC/', // ü
215
+			'/%FB/', // û
216
+			'/%F4/', // ô
217
+			'/%F6/', // ö
218
+		);
219
+		$rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o');
220
+		$title   = preg_replace($pattern, $rep_pat, $title);
221
+
222
+		$tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
223
+		$tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau
224
+		$title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
225
+
226
+		$title .= time();
227
+		$title = md5($title);
228
+
229
+		return $title;
230
+	}
231
+
232
+	/**
233
+	 * @return string
234
+	 */
235
+	public function getCloneLink()
236
+	{
237
+		$ret = '<a href="' .
238
+			   SMARTOBJECT_URL .
239
+			   'admin/adsense.php?op=clone&adsenseid=' .
240
+			   $this->getVar('adsenseid') .
241
+			   '"><img src="' .
242
+			   SMARTOBJECT_IMAGES_ACTIONS_URL .
243
+			   'editcopy.png" alt="' .
244
+			   _CO_SOBJECT_ADSENSE_CLONE .
245
+			   '" title="' .
246
+			   _CO_SOBJECT_ADSENSE_CLONE .
247
+			   '" /></a>';
248
+
249
+		return $ret;
250
+	}
251 251
 }
252 252
 
253 253
 /**
@@ -255,116 +255,116 @@  discard block
 block discarded – undo
255 255
  */
256 256
 class SmartobjectAdsenseHandler extends SmartPersistableObjectHandler
257 257
 {
258
-    public $adFormats;
259
-    public $adFormatsList;
260
-    public $objects = false;
261
-
262
-    /**
263
-     * SmartobjectAdsenseHandler constructor.
264
-     * @param XoopsDatabase $db
265
-     */
266
-    public function __construct(XoopsDatabase $db)
267
-    {
268
-        parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject');
269
-        $this->adFormats     = array();
270
-        $this->adFormatsList = array();
271
-
272
-        $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard';
273
-        $this->adFormats['728x90_as']['width']   = 728;
274
-        $this->adFormats['728x90_as']['height']  = 90;
275
-        $this->adFormatsList['728x90_as']        = $this->adFormats['728x90_as']['caption'];
276
-
277
-        $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner';
278
-        $this->adFormats['468x60_as']['width']   = 468;
279
-        $this->adFormats['468x60_as']['height']  = 60;
280
-        $this->adFormatsList['468x60_as']        = $this->adFormats['468x60_as']['caption'];
281
-
282
-        $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner';
283
-        $this->adFormats['234x60_as']['width']   = 234;
284
-        $this->adFormats['234x60_as']['height']  = 60;
285
-        $this->adFormatsList['234x60_as']        = $this->adFormats['234x60_as']['caption'];
286
-
287
-        $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper';
288
-        $this->adFormats['120x600_as']['width']   = 120;
289
-        $this->adFormats['120x600_as']['height']  = 600;
290
-        $this->adFormatsList['120x600_as']        = $this->adFormats['120x600_as']['caption'];
291
-
292
-        $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper';
293
-        $this->adFormats['160x600_as']['width']   = 160;
294
-        $this->adFormats['160x600_as']['height']  = 600;
295
-        $this->adFormatsList['160x600_as']        = $this->adFormats['160x600_as']['caption'];
296
-
297
-        $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner';
298
-        $this->adFormats['120x240_as']['width']   = 120;
299
-        $this->adFormats['120x240_as']['height']  = 240;
300
-        $this->adFormatsList['120x240_as']        = $this->adFormats['120x240_as']['caption'];
301
-
302
-        $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle';
303
-        $this->adFormats['336x280_as']['width']   = 136;
304
-        $this->adFormats['336x280_as']['height']  = 280;
305
-        $this->adFormatsList['336x280_as']        = $this->adFormats['336x280_as']['caption'];
306
-
307
-        $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle';
308
-        $this->adFormats['300x250_as']['width']   = 300;
309
-        $this->adFormats['300x250_as']['height']  = 250;
310
-        $this->adFormatsList['300x250_as']        = $this->adFormats['300x250_as']['caption'];
311
-
312
-        $this->adFormats['250x250_as']['caption'] = '250 X 250 Square';
313
-        $this->adFormats['250x250_as']['width']   = 250;
314
-        $this->adFormats['250x250_as']['height']  = 250;
315
-        $this->adFormatsList['250x250_as']        = $this->adFormats['250x250_as']['caption'];
316
-
317
-        $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square';
318
-        $this->adFormats['200x200_as']['width']   = 200;
319
-        $this->adFormats['200x200_as']['height']  = 200;
320
-        $this->adFormatsList['200x200_as']        = $this->adFormats['200x200_as']['caption'];
321
-
322
-        $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle';
323
-        $this->adFormats['180x150_as']['width']   = 180;
324
-        $this->adFormats['180x150_as']['height']  = 150;
325
-        $this->adFormatsList['180x150_as']        = $this->adFormats['180x150_as']['caption'];
326
-
327
-        $this->adFormats['125x125_as']['caption'] = '125 X 125 Button';
328
-        $this->adFormats['125x125_as']['width']   = 125;
329
-        $this->adFormats['125x125_as']['height']  = 125;
330
-        $this->adFormatsList['125x125_as']        = $this->adFormats['125x125_as']['caption'];
331
-    }
332
-
333
-    /**
334
-     * @return array
335
-     */
336
-    public function getFormats()
337
-    {
338
-        return $this->adFormatsList;
339
-    }
340
-
341
-    /**
342
-     * @param $obj
343
-     * @return bool
344
-     */
345
-    public function beforeSave($obj)
346
-    {
347
-        if ($obj->getVar('tag') === '') {
348
-            $obj->setVar('tag', $title = $obj->generateTag());
349
-        }
350
-
351
-        return true;
352
-    }
353
-
354
-    /**
355
-     * @return array|bool
356
-     */
357
-    public function getAdsensesByTag()
358
-    {
359
-        if (!$this->objects) {
360
-            $adsensesObj = $this->getObjects(null, true);
361
-            $ret         = array();
362
-            foreach ($adsensesObj as $adsenseObj) {
363
-                $ret[$adsenseObj->getVar('tag')] = $adsenseObj;
364
-            }
365
-            $this->objects = $ret;
366
-        }
367
-
368
-        return $this->objects;
369
-    }
258
+	public $adFormats;
259
+	public $adFormatsList;
260
+	public $objects = false;
261
+
262
+	/**
263
+	 * SmartobjectAdsenseHandler constructor.
264
+	 * @param XoopsDatabase $db
265
+	 */
266
+	public function __construct(XoopsDatabase $db)
267
+	{
268
+		parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject');
269
+		$this->adFormats     = array();
270
+		$this->adFormatsList = array();
271
+
272
+		$this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard';
273
+		$this->adFormats['728x90_as']['width']   = 728;
274
+		$this->adFormats['728x90_as']['height']  = 90;
275
+		$this->adFormatsList['728x90_as']        = $this->adFormats['728x90_as']['caption'];
276
+
277
+		$this->adFormats['468x60_as']['caption'] = '468 X 60 Banner';
278
+		$this->adFormats['468x60_as']['width']   = 468;
279
+		$this->adFormats['468x60_as']['height']  = 60;
280
+		$this->adFormatsList['468x60_as']        = $this->adFormats['468x60_as']['caption'];
281
+
282
+		$this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner';
283
+		$this->adFormats['234x60_as']['width']   = 234;
284
+		$this->adFormats['234x60_as']['height']  = 60;
285
+		$this->adFormatsList['234x60_as']        = $this->adFormats['234x60_as']['caption'];
286
+
287
+		$this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper';
288
+		$this->adFormats['120x600_as']['width']   = 120;
289
+		$this->adFormats['120x600_as']['height']  = 600;
290
+		$this->adFormatsList['120x600_as']        = $this->adFormats['120x600_as']['caption'];
291
+
292
+		$this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper';
293
+		$this->adFormats['160x600_as']['width']   = 160;
294
+		$this->adFormats['160x600_as']['height']  = 600;
295
+		$this->adFormatsList['160x600_as']        = $this->adFormats['160x600_as']['caption'];
296
+
297
+		$this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner';
298
+		$this->adFormats['120x240_as']['width']   = 120;
299
+		$this->adFormats['120x240_as']['height']  = 240;
300
+		$this->adFormatsList['120x240_as']        = $this->adFormats['120x240_as']['caption'];
301
+
302
+		$this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle';
303
+		$this->adFormats['336x280_as']['width']   = 136;
304
+		$this->adFormats['336x280_as']['height']  = 280;
305
+		$this->adFormatsList['336x280_as']        = $this->adFormats['336x280_as']['caption'];
306
+
307
+		$this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle';
308
+		$this->adFormats['300x250_as']['width']   = 300;
309
+		$this->adFormats['300x250_as']['height']  = 250;
310
+		$this->adFormatsList['300x250_as']        = $this->adFormats['300x250_as']['caption'];
311
+
312
+		$this->adFormats['250x250_as']['caption'] = '250 X 250 Square';
313
+		$this->adFormats['250x250_as']['width']   = 250;
314
+		$this->adFormats['250x250_as']['height']  = 250;
315
+		$this->adFormatsList['250x250_as']        = $this->adFormats['250x250_as']['caption'];
316
+
317
+		$this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square';
318
+		$this->adFormats['200x200_as']['width']   = 200;
319
+		$this->adFormats['200x200_as']['height']  = 200;
320
+		$this->adFormatsList['200x200_as']        = $this->adFormats['200x200_as']['caption'];
321
+
322
+		$this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle';
323
+		$this->adFormats['180x150_as']['width']   = 180;
324
+		$this->adFormats['180x150_as']['height']  = 150;
325
+		$this->adFormatsList['180x150_as']        = $this->adFormats['180x150_as']['caption'];
326
+
327
+		$this->adFormats['125x125_as']['caption'] = '125 X 125 Button';
328
+		$this->adFormats['125x125_as']['width']   = 125;
329
+		$this->adFormats['125x125_as']['height']  = 125;
330
+		$this->adFormatsList['125x125_as']        = $this->adFormats['125x125_as']['caption'];
331
+	}
332
+
333
+	/**
334
+	 * @return array
335
+	 */
336
+	public function getFormats()
337
+	{
338
+		return $this->adFormatsList;
339
+	}
340
+
341
+	/**
342
+	 * @param $obj
343
+	 * @return bool
344
+	 */
345
+	public function beforeSave($obj)
346
+	{
347
+		if ($obj->getVar('tag') === '') {
348
+			$obj->setVar('tag', $title = $obj->generateTag());
349
+		}
350
+
351
+		return true;
352
+	}
353
+
354
+	/**
355
+	 * @return array|bool
356
+	 */
357
+	public function getAdsensesByTag()
358
+	{
359
+		if (!$this->objects) {
360
+			$adsensesObj = $this->getObjects(null, true);
361
+			$ret         = array();
362
+			foreach ($adsensesObj as $adsenseObj) {
363
+				$ret[$adsenseObj->getVar('tag')] = $adsenseObj;
364
+			}
365
+			$this->objects = $ret;
366
+		}
367
+
368
+		return $this->objects;
369
+	}
370 370
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
31 31
 
32
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
32
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
33 33
 
34 34
 /**
35 35
  * Class SmartobjectAdsense
@@ -111,23 +111,23 @@  discard block
 block discarded – undo
111 111
     {
112 112
         global $smartobjectAdsenseHandler;
113 113
         if ($this->getVar('style', 'n') !== '') {
114
-            $ret = '<div style="' . $this->getVar('style', 'n') . '">';
114
+            $ret = '<div style="'.$this->getVar('style', 'n').'">';
115 115
         } else {
116 116
             $ret = '<div>';
117 117
         }
118 118
 
119 119
         $ret .= '<script type="text/javascript"><!--
120
-google_ad_client = "' . $this->getVar('client_id', 'n') . '";
121
-google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . ';
122
-google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . ';
123
-google_ad_format = "' . $this->getVar('format', 'n') . '";
120
+google_ad_client = "' . $this->getVar('client_id', 'n').'";
121
+google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'].';
122
+google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'].';
123
+google_ad_format = "' . $this->getVar('format', 'n').'";
124 124
 google_ad_type = "text";
125 125
 google_ad_channel ="";
126
-google_color_border = "' . $this->getVar('border_color', 'n') . '";
127
-google_color_bg = "' . $this->getVar('background_color', 'n') . '";
128
-google_color_link = "' . $this->getVar('link_color', 'n') . '";
129
-google_color_url = "' . $this->getVar('url_color', 'n') . '";
130
-google_color_text = "' . $this->getVar('text_color', 'n') . '";
126
+google_color_border = "' . $this->getVar('border_color', 'n').'";
127
+google_color_bg = "' . $this->getVar('background_color', 'n').'";
128
+google_color_link = "' . $this->getVar('link_color', 'n').'";
129
+google_color_url = "' . $this->getVar('url_color', 'n').'";
130
+google_color_text = "' . $this->getVar('text_color', 'n').'";
131 131
 //--></script>
132 132
 <script type="text/javascript"
133 133
   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function getXoopsCode()
144 144
     {
145
-        $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]';
145
+        $ret = '[adsense]'.$this->getVar('tag', 'n').'[/adsense]';
146 146
 
147 147
         return $ret;
148 148
     }
@@ -234,16 +234,16 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function getCloneLink()
236 236
     {
237
-        $ret = '<a href="' .
238
-               SMARTOBJECT_URL .
239
-               'admin/adsense.php?op=clone&adsenseid=' .
240
-               $this->getVar('adsenseid') .
241
-               '"><img src="' .
242
-               SMARTOBJECT_IMAGES_ACTIONS_URL .
243
-               'editcopy.png" alt="' .
244
-               _CO_SOBJECT_ADSENSE_CLONE .
245
-               '" title="' .
246
-               _CO_SOBJECT_ADSENSE_CLONE .
237
+        $ret = '<a href="'.
238
+               SMARTOBJECT_URL.
239
+               'admin/adsense.php?op=clone&adsenseid='.
240
+               $this->getVar('adsenseid').
241
+               '"><img src="'.
242
+               SMARTOBJECT_IMAGES_ACTIONS_URL.
243
+               'editcopy.png" alt="'.
244
+               _CO_SOBJECT_ADSENSE_CLONE.
245
+               '" title="'.
246
+               _CO_SOBJECT_ADSENSE_CLONE.
247 247
                '" /></a>';
248 248
 
249 249
         return $ret;
Please login to merge, or discard this patch.
class/customtag.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@
 block discarded – undo
147 147
     }
148 148
 
149 149
     /**
150
-     * @return mixed|string
150
+     * @return string
151 151
      */
152 152
     public function generateTag()
153 153
     {
Please login to merge, or discard this patch.
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -36,208 +36,208 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class SmartobjectCustomtag extends SmartObject
38 38
 {
39
-    public $content = false;
40
-
41
-    /**
42
-     * SmartobjectCustomtag constructor.
43
-     */
44
-    public function __construct()
45
-    {
46
-        $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true);
47
-        $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC);
48
-        $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC);
49
-        $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC);
50
-        $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC);
51
-
52
-        $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true);
53
-        $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true);
54
-        $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true);
55
-        $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true);
56
-
57
-        $this->setControl('content', array(
58
-            'name'        => 'textarea',
59
-            'form_editor' => 'textarea',
60
-            'form_rows'   => 25
61
-        ));
62
-        $this->setControl('language', array(
63
-            'name' => 'language',
64
-            'all'  => true
65
-        ));
66
-    }
67
-
68
-    /**
69
-     * @param  string $key
70
-     * @param  string $format
71
-     * @return mixed
72
-     */
73
-    public function getVar($key, $format = 's')
74
-    {
75
-        if ($format === 's' && in_array($key, array())) {
76
-            //            return call_user_func(array($this, $key));
77
-            return $this->{$key}();
78
-        }
79
-
80
-        return parent::getVar($key, $format);
81
-    }
82
-
83
-    /**
84
-     * @return bool|mixed
85
-     */
86
-    public function render()
87
-    {
88
-        if (!$this->content) {
89
-            $ret           = $this->getVar('content');
90
-            $this->content = $ret;
91
-        }
92
-
93
-        return $this->content;
94
-    }
95
-
96
-    /**
97
-     * @return bool|mixed|string
98
-     */
99
-    public function renderWithPhp()
100
-    {
101
-        if (!$this->content) {
102
-            $ret           = $this->getVar('content');
103
-            $this->content = $ret;
104
-        } else {
105
-            $ret = $this->content;
106
-        }
107
-
108
-        // check for PHP if we are not on admin side
109
-        if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) {
110
-            $ret = str_replace('[php]', '', $ret);
111
-            // we have PHP code, let's evaluate
112
-            eval($ret);
113
-
114
-            return '';
115
-        }
116
-
117
-        return $this->content;
118
-    }
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    public function getXoopsCode()
124
-    {
125
-        $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]';
126
-
127
-        return $ret;
128
-    }
129
-
130
-    /**
131
-     * @return string
132
-     */
133
-    public function getCloneLink()
134
-    {
135
-        $ret = '<a href="' .
136
-               SMARTOBJECT_URL .
137
-               'admin/customtag.php?op=clone&customtagid=' .
138
-               $this->id() .
139
-               '"><img src="' .
140
-               SMARTOBJECT_IMAGES_ACTIONS_URL .
141
-               'editcopy.png" style="vertical-align: middle;" alt="' .
142
-               _CO_SOBJECT_CUSTOMTAG_CLONE .
143
-               '" title="' .
144
-               _CO_SOBJECT_CUSTOMTAG_CLONE .
145
-               '" /></a>';
146
-
147
-        return $ret;
148
-    }
149
-
150
-    /**
151
-     * @param $var
152
-     * @return bool
153
-     */
154
-    public function emptyString($var)
155
-    {
156
-        return (strlen($var) > 0);
157
-    }
158
-
159
-    /**
160
-     * @return mixed|string
161
-     */
162
-    public function generateTag()
163
-    {
164
-        $title = rawurlencode(strtolower($this->getVar('description', 'e')));
165
-        $title = xoops_substr($title, 0, 10, '');
166
-        // Transformation des ponctuations
167
-        $pattern = array(
168
-            '/%09/', // Tab
169
-            '/%20/', // Space
170
-            '/%21/', // !
171
-            '/%22/', // "
172
-            '/%23/', // #
173
-            '/%25/', // %
174
-            '/%26/', // &
175
-            '/%27/', // '
176
-            '/%28/', // (
177
-            '/%29/', // )
178
-            '/%2C/', // ,
179
-            '/%2F/', // /
180
-            '/%3A/', // :
181
-            '/%3B/', // ;
182
-            '/%3C/', // <
183
-            '/%3D/', // =
184
-            '/%3E/', // >
185
-            '/%3F/', // ?
186
-            '/%40/', // @
187
-            '/%5B/', // [
188
-            '/%5C/', // \
189
-            '/%5D/', // ]
190
-            '/%5E/', // ^
191
-            '/%7B/', // {
192
-            '/%7C/', // |
193
-            '/%7D/', // }
194
-            '/%7E/', // ~
195
-            "/\./" // .
196
-        );
197
-        $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
198
-        $title   = preg_replace($pattern, $rep_pat, $title);
199
-
200
-        // Transformation des caract�res accentu�s
201
-        $pattern = array(
202
-            '/%B0/', // °
203
-            '/%E8/', // è
204
-            '/%E9/', // é
205
-            '/%EA/', // ê
206
-            '/%EB/', // ë
207
-            '/%E7/', // ç
208
-            '/%E0/', // à
209
-            '/%E2/', // â
210
-            '/%E4/', // ä
211
-            '/%EE/', // î
212
-            '/%EF/', // ï
213
-            '/%F9/', // ù
214
-            '/%FC/', // ü
215
-            '/%FB/', // û
216
-            '/%F4/', // ô
217
-            '/%F6/', // ö
218
-        );
219
-        $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o');
220
-        $title   = preg_replace($pattern, $rep_pat, $title);
221
-
222
-        $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
223
-        $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau
224
-        $title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
225
-
226
-        $title .= time();
227
-        $title = md5($title);
228
-
229
-        return $title;
230
-    }
231
-
232
-    /**
233
-     * @return mixed
234
-     */
235
-    public function getCustomtagName()
236
-    {
237
-        $ret = $this->getVar('name');
238
-
239
-        return $ret;
240
-    }
39
+	public $content = false;
40
+
41
+	/**
42
+	 * SmartobjectCustomtag constructor.
43
+	 */
44
+	public function __construct()
45
+	{
46
+		$this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true);
47
+		$this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC);
48
+		$this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC);
49
+		$this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC);
50
+		$this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC);
51
+
52
+		$this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true);
53
+		$this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true);
54
+		$this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true);
55
+		$this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true);
56
+
57
+		$this->setControl('content', array(
58
+			'name'        => 'textarea',
59
+			'form_editor' => 'textarea',
60
+			'form_rows'   => 25
61
+		));
62
+		$this->setControl('language', array(
63
+			'name' => 'language',
64
+			'all'  => true
65
+		));
66
+	}
67
+
68
+	/**
69
+	 * @param  string $key
70
+	 * @param  string $format
71
+	 * @return mixed
72
+	 */
73
+	public function getVar($key, $format = 's')
74
+	{
75
+		if ($format === 's' && in_array($key, array())) {
76
+			//            return call_user_func(array($this, $key));
77
+			return $this->{$key}();
78
+		}
79
+
80
+		return parent::getVar($key, $format);
81
+	}
82
+
83
+	/**
84
+	 * @return bool|mixed
85
+	 */
86
+	public function render()
87
+	{
88
+		if (!$this->content) {
89
+			$ret           = $this->getVar('content');
90
+			$this->content = $ret;
91
+		}
92
+
93
+		return $this->content;
94
+	}
95
+
96
+	/**
97
+	 * @return bool|mixed|string
98
+	 */
99
+	public function renderWithPhp()
100
+	{
101
+		if (!$this->content) {
102
+			$ret           = $this->getVar('content');
103
+			$this->content = $ret;
104
+		} else {
105
+			$ret = $this->content;
106
+		}
107
+
108
+		// check for PHP if we are not on admin side
109
+		if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) {
110
+			$ret = str_replace('[php]', '', $ret);
111
+			// we have PHP code, let's evaluate
112
+			eval($ret);
113
+
114
+			return '';
115
+		}
116
+
117
+		return $this->content;
118
+	}
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	public function getXoopsCode()
124
+	{
125
+		$ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]';
126
+
127
+		return $ret;
128
+	}
129
+
130
+	/**
131
+	 * @return string
132
+	 */
133
+	public function getCloneLink()
134
+	{
135
+		$ret = '<a href="' .
136
+			   SMARTOBJECT_URL .
137
+			   'admin/customtag.php?op=clone&customtagid=' .
138
+			   $this->id() .
139
+			   '"><img src="' .
140
+			   SMARTOBJECT_IMAGES_ACTIONS_URL .
141
+			   'editcopy.png" style="vertical-align: middle;" alt="' .
142
+			   _CO_SOBJECT_CUSTOMTAG_CLONE .
143
+			   '" title="' .
144
+			   _CO_SOBJECT_CUSTOMTAG_CLONE .
145
+			   '" /></a>';
146
+
147
+		return $ret;
148
+	}
149
+
150
+	/**
151
+	 * @param $var
152
+	 * @return bool
153
+	 */
154
+	public function emptyString($var)
155
+	{
156
+		return (strlen($var) > 0);
157
+	}
158
+
159
+	/**
160
+	 * @return mixed|string
161
+	 */
162
+	public function generateTag()
163
+	{
164
+		$title = rawurlencode(strtolower($this->getVar('description', 'e')));
165
+		$title = xoops_substr($title, 0, 10, '');
166
+		// Transformation des ponctuations
167
+		$pattern = array(
168
+			'/%09/', // Tab
169
+			'/%20/', // Space
170
+			'/%21/', // !
171
+			'/%22/', // "
172
+			'/%23/', // #
173
+			'/%25/', // %
174
+			'/%26/', // &
175
+			'/%27/', // '
176
+			'/%28/', // (
177
+			'/%29/', // )
178
+			'/%2C/', // ,
179
+			'/%2F/', // /
180
+			'/%3A/', // :
181
+			'/%3B/', // ;
182
+			'/%3C/', // <
183
+			'/%3D/', // =
184
+			'/%3E/', // >
185
+			'/%3F/', // ?
186
+			'/%40/', // @
187
+			'/%5B/', // [
188
+			'/%5C/', // \
189
+			'/%5D/', // ]
190
+			'/%5E/', // ^
191
+			'/%7B/', // {
192
+			'/%7C/', // |
193
+			'/%7D/', // }
194
+			'/%7E/', // ~
195
+			"/\./" // .
196
+		);
197
+		$rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
198
+		$title   = preg_replace($pattern, $rep_pat, $title);
199
+
200
+		// Transformation des caract�res accentu�s
201
+		$pattern = array(
202
+			'/%B0/', // °
203
+			'/%E8/', // è
204
+			'/%E9/', // é
205
+			'/%EA/', // ê
206
+			'/%EB/', // ë
207
+			'/%E7/', // ç
208
+			'/%E0/', // à
209
+			'/%E2/', // â
210
+			'/%E4/', // ä
211
+			'/%EE/', // î
212
+			'/%EF/', // ï
213
+			'/%F9/', // ù
214
+			'/%FC/', // ü
215
+			'/%FB/', // û
216
+			'/%F4/', // ô
217
+			'/%F6/', // ö
218
+		);
219
+		$rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o');
220
+		$title   = preg_replace($pattern, $rep_pat, $title);
221
+
222
+		$tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
223
+		$tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau
224
+		$title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
225
+
226
+		$title .= time();
227
+		$title = md5($title);
228
+
229
+		return $title;
230
+	}
231
+
232
+	/**
233
+	 * @return mixed
234
+	 */
235
+	public function getCustomtagName()
236
+	{
237
+		$ret = $this->getVar('name');
238
+
239
+		return $ret;
240
+	}
241 241
 }
242 242
 
243 243
 /**
@@ -245,48 +245,48 @@  discard block
 block discarded – undo
245 245
  */
246 246
 class SmartobjectCustomtagHandler extends SmartPersistableObjectHandler
247 247
 {
248
-    public $objects = false;
249
-
250
-    /**
251
-     * SmartobjectCustomtagHandler constructor.
252
-     * @param XoopsDatabase $db
253
-     */
254
-    public function __construct(XoopsDatabase $db)
255
-    {
256
-        parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject');
257
-        $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC);
258
-    }
259
-
260
-    /**
261
-     * @return array|bool
262
-     */
263
-    public function getCustomtagsByName()
264
-    {
265
-        if (!$this->objects) {
266
-            global $xoopsConfig;
267
-
268
-            $ret = array();
269
-
270
-            $criteria = new CriteriaCompo();
271
-
272
-            $criteria_language = new CriteriaCompo();
273
-            $criteria_language->add(new Criteria('language', $xoopsConfig['language']));
274
-            $criteria_language->add(new Criteria('language', 'all'), 'OR');
275
-            $criteria->add($criteria_language);
276
-
277
-            $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this);
278
-            $granted_ids                   = $smartobjectPermissionsHandler->getGrantedItems('view');
279
-
280
-            if ($granted_ids && count($granted_ids) > 0) {
281
-                $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN'));
282
-                $customtagsObj = $this->getObjects($criteria, true);
283
-                foreach ($customtagsObj as $customtagObj) {
284
-                    $ret[$customtagObj->getVar('name')] = $customtagObj;
285
-                }
286
-            }
287
-            $this->objects = $ret;
288
-        }
289
-
290
-        return $this->objects;
291
-    }
248
+	public $objects = false;
249
+
250
+	/**
251
+	 * SmartobjectCustomtagHandler constructor.
252
+	 * @param XoopsDatabase $db
253
+	 */
254
+	public function __construct(XoopsDatabase $db)
255
+	{
256
+		parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject');
257
+		$this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC);
258
+	}
259
+
260
+	/**
261
+	 * @return array|bool
262
+	 */
263
+	public function getCustomtagsByName()
264
+	{
265
+		if (!$this->objects) {
266
+			global $xoopsConfig;
267
+
268
+			$ret = array();
269
+
270
+			$criteria = new CriteriaCompo();
271
+
272
+			$criteria_language = new CriteriaCompo();
273
+			$criteria_language->add(new Criteria('language', $xoopsConfig['language']));
274
+			$criteria_language->add(new Criteria('language', 'all'), 'OR');
275
+			$criteria->add($criteria_language);
276
+
277
+			$smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this);
278
+			$granted_ids                   = $smartobjectPermissionsHandler->getGrantedItems('view');
279
+
280
+			if ($granted_ids && count($granted_ids) > 0) {
281
+				$criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN'));
282
+				$customtagsObj = $this->getObjects($criteria, true);
283
+				foreach ($customtagsObj as $customtagObj) {
284
+					$ret[$customtagObj->getVar('name')] = $customtagObj;
285
+				}
286
+			}
287
+			$this->objects = $ret;
288
+		}
289
+
290
+		return $this->objects;
291
+	}
292 292
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
31 31
 
32
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
32
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
33 33
 
34 34
 /**
35 35
  * Class SmartobjectCustomtag
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function getXoopsCode()
124 124
     {
125
-        $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]';
125
+        $ret = '[customtag]'.$this->getVar('tag', 'n').'[/customtag]';
126 126
 
127 127
         return $ret;
128 128
     }
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function getCloneLink()
134 134
     {
135
-        $ret = '<a href="' .
136
-               SMARTOBJECT_URL .
137
-               'admin/customtag.php?op=clone&customtagid=' .
138
-               $this->id() .
139
-               '"><img src="' .
140
-               SMARTOBJECT_IMAGES_ACTIONS_URL .
141
-               'editcopy.png" style="vertical-align: middle;" alt="' .
142
-               _CO_SOBJECT_CUSTOMTAG_CLONE .
143
-               '" title="' .
144
-               _CO_SOBJECT_CUSTOMTAG_CLONE .
135
+        $ret = '<a href="'.
136
+               SMARTOBJECT_URL.
137
+               'admin/customtag.php?op=clone&customtagid='.
138
+               $this->id().
139
+               '"><img src="'.
140
+               SMARTOBJECT_IMAGES_ACTIONS_URL.
141
+               'editcopy.png" style="vertical-align: middle;" alt="'.
142
+               _CO_SOBJECT_CUSTOMTAG_CLONE.
143
+               '" title="'.
144
+               _CO_SOBJECT_CUSTOMTAG_CLONE.
145 145
                '" /></a>';
146 146
 
147 147
         return $ret;
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             $granted_ids                   = $smartobjectPermissionsHandler->getGrantedItems('view');
279 279
 
280 280
             if ($granted_ids && count($granted_ids) > 0) {
281
-                $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN'));
281
+                $criteria->add(new Criteria('customtagid', '('.implode(', ', $granted_ids).')', 'IN'));
282 282
                 $customtagsObj = $this->getObjects($criteria, true);
283 283
                 foreach ($customtagsObj as $customtagObj) {
284 284
                     $ret[$customtagObj->getVar('name')] = $customtagObj;
Please login to merge, or discard this patch.
class/form/elements/smartformuploadelement.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@
 block discarded – undo
12 12
 class SmartFormUploadElement extends XoopsFormFile
13 13
 {
14 14
     /**
15
-     * @param $object
16
-     * @param $key
15
+     * @param string $object
16
+     * @param string $key
17 17
      */
18 18
     public function SmartFormFileElement($object, $key)
19 19
     {
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -11,25 +11,25 @@
 block discarded – undo
11 11
  */
12 12
 class SmartFormUploadElement extends XoopsFormFile
13 13
 {
14
-    /**
15
-     * @param $object
16
-     * @param $key
17
-     */
18
-    public function SmartFormFileElement($object, $key)
19
-    {
20
-        parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0);
21
-        $this->setExtra(' size=50');
22
-    }
14
+	/**
15
+	 * @param $object
16
+	 * @param $key
17
+	 */
18
+	public function SmartFormFileElement($object, $key)
19
+	{
20
+		parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0);
21
+		$this->setExtra(' size=50');
22
+	}
23 23
 
24
-    /**
25
-     * prepare HTML for output
26
-     *
27
-     * @return string HTML
28
-     */
29
-    public function render()
30
-    {
31
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "' />
24
+	/**
25
+	 * prepare HTML for output
26
+	 *
27
+	 * @return string HTML
28
+	 */
29
+	public function render()
30
+	{
31
+		return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "' />
32 32
                 <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . " />
33 33
                 <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "' />";
34
-    }
34
+	}
35 35
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@
 block discarded – undo
28 28
      */
29 29
     public function render()
30 30
     {
31
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "' />
32
-                <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . " />
33
-                <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "' />";
31
+        return "<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."' />
32
+                <input type='file' name='" . $this->getName()."' id='".$this->getName()."'".$this->getExtra()." />
33
+                <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName()."' />";
34 34
     }
35 35
 }
Please login to merge, or discard this patch.
class/form/smartobjectform.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -306,8 +306,8 @@
 block discarded – undo
306 306
     }
307 307
 
308 308
     /**
309
-     * @param      $form_name
310
-     * @param      $form_caption
309
+     * @param      string $form_name
310
+     * @param      string $form_caption
311 311
      * @param bool $submit_button_caption
312 312
      */
313 313
     public function createButtons($form_name, $form_caption, $submit_button_caption = false)
Please login to merge, or discard this patch.
Indentation   +796 added lines, -796 removed lines patch added patch discarded remove patch
@@ -30,790 +30,790 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class SmartObjectForm extends XoopsThemeForm
32 32
 {
33
-    public $targetObject           = null;
34
-    public $form_fields            = null;
35
-    public $_cancel_js_action      = false;
36
-    public $_custom_button         = false;
37
-    public $_captcha               = false;
38
-    public $_form_name             = false;
39
-    public $_form_caption          = false;
40
-    public $_submit_button_caption = false;
41
-
42
-    /**
43
-     * SmartobjectForm constructor.
44
-     * @param string $target
45
-     * @param string $form_name
46
-     * @param string $form_caption
47
-     * @param string $form_action
48
-     * @param null   $form_fields
49
-     * @param bool   $submit_button_caption
50
-     * @param bool   $cancel_js_action
51
-     * @param bool   $captcha
52
-     */
53
-    public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false)
54
-    {
55
-        $this->targetObject           =& $target;
56
-        $this->form_fields            = $form_fields;
57
-        $this->_cancel_js_action      = $cancel_js_action;
58
-        $this->_captcha               = $captcha;
59
-        $this->_form_name             = $form_name;
60
-        $this->_form_caption          = $form_caption;
61
-        $this->_submit_button_caption = $submit_button_caption;
62
-
63
-        if (!isset($form_action)) {
64
-            $form_action = xoops_getenv('PHP_SELF');
65
-        }
66
-
67
-        parent::__construct($form_caption, $form_name, $form_action);
68
-        $this->setExtra('enctype="multipart/form-data"');
69
-
70
-        $this->createElements();
71
-
72
-        if ($captcha) {
73
-            $this->addCaptcha();
74
-        }
75
-
76
-        $this->createPermissionControls();
77
-
78
-        $this->createButtons($form_name, $form_caption, $submit_button_caption);
79
-    }
80
-
81
-    public function addCaptcha()
82
-    {
83
-        include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php');
84
-        $this->addElement(new XoopsFormCaptcha(), true);
85
-    }
86
-
87
-    /**
88
-     * @param      $name
89
-     * @param      $caption
90
-     * @param bool $onclick
91
-     */
92
-    public function addCustomButton($name, $caption, $onclick = false)
93
-    {
94
-        $custom_button_array    = array(
95
-            'name'    => $name,
96
-            'caption' => $caption,
97
-            'onclick' => $onclick
98
-        );
99
-        $this->_custom_button[] = $custom_button_array;
100
-    }
101
-
102
-    /**
103
-     * Add an element to the form
104
-     *
105
-     * @param string|XoopsFormElement      &$formElement reference to a {@link XoopsFormElement}
106
-     * @param bool        $key
107
-     * @param bool        $var
108
-     * @param bool|string $required     is this a "required" element?
109
-     */
110
-    public function addElement($formElement, $key = false, $var = false, $required = 'notset')
111
-    {
112
-        if ($key) {
113
-            if ($this->targetObject->vars[$key]['readonly']) {
114
-                $formElement->setExtra('disabled="disabled"');
115
-                $formElement->setName($key . '-readonly');
116
-                // Since this element is disable, we still want to pass it's value in the form
117
-                $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
118
-                $this->addElement($hidden);
119
-            }
120
-            $formElement->setDescription($var['form_dsc']);
121
-            if (isset($this->targetObject->controls[$key]['onSelect'])) {
122
-                $hidden = new XoopsFormHidden('changedField', false);
123
-                $this->addElement($hidden);
124
-                $otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
125
-                $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
126
-                $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
127
-            } else {
128
-                if (isset($var['form_extra'])) {
129
-                    $formElement->setExtra($var['form_extra']);
130
-                }
131
-            }
132
-            $controls = $this->targetObject->controls;
133
-            if (isset($controls[$key]['js'])) {
134
-                $formElement->customValidationCode[] = $controls[$key]['js'];
135
-            }
136
-            parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required);
137
-        } else {
138
-            parent::addElement($formElement, $required === 'notset' ? false : true);
139
-        }
140
-        unset($formElement);
141
-    }
142
-
143
-    public function createElements()
144
-    {
145
-        $controls = $this->targetObject->controls;
146
-        $vars     = $this->targetObject->vars;
147
-        foreach ($vars as $key => $var) {
148
-
149
-            // If $displayOnForm is false OR this is the primary key, it doesn't
150
-            // need to be displayed, then we only create an hidden field
151
-            if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
152
-                $elementToAdd = new XoopsFormHidden($key, $var['value']);
153
-                $this->addElement($elementToAdd, $key, $var, false);
154
-                unset($elementToAdd);
155
-                // If not, the we need to create the proper form control for this fields
156
-            } else {
157
-                // If this field has a specific control, we will use it
158
-
159
-                if ($key === 'parentid') {
160
-                    /**
161
-                     * Why this ?
162
-                     */
163
-                }
164
-                if (isset($controls[$key])) {
165
-                    /* If the control has name, it's because it's an object already present in the script
33
+	public $targetObject           = null;
34
+	public $form_fields            = null;
35
+	public $_cancel_js_action      = false;
36
+	public $_custom_button         = false;
37
+	public $_captcha               = false;
38
+	public $_form_name             = false;
39
+	public $_form_caption          = false;
40
+	public $_submit_button_caption = false;
41
+
42
+	/**
43
+	 * SmartobjectForm constructor.
44
+	 * @param string $target
45
+	 * @param string $form_name
46
+	 * @param string $form_caption
47
+	 * @param string $form_action
48
+	 * @param null   $form_fields
49
+	 * @param bool   $submit_button_caption
50
+	 * @param bool   $cancel_js_action
51
+	 * @param bool   $captcha
52
+	 */
53
+	public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false)
54
+	{
55
+		$this->targetObject           =& $target;
56
+		$this->form_fields            = $form_fields;
57
+		$this->_cancel_js_action      = $cancel_js_action;
58
+		$this->_captcha               = $captcha;
59
+		$this->_form_name             = $form_name;
60
+		$this->_form_caption          = $form_caption;
61
+		$this->_submit_button_caption = $submit_button_caption;
62
+
63
+		if (!isset($form_action)) {
64
+			$form_action = xoops_getenv('PHP_SELF');
65
+		}
66
+
67
+		parent::__construct($form_caption, $form_name, $form_action);
68
+		$this->setExtra('enctype="multipart/form-data"');
69
+
70
+		$this->createElements();
71
+
72
+		if ($captcha) {
73
+			$this->addCaptcha();
74
+		}
75
+
76
+		$this->createPermissionControls();
77
+
78
+		$this->createButtons($form_name, $form_caption, $submit_button_caption);
79
+	}
80
+
81
+	public function addCaptcha()
82
+	{
83
+		include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php');
84
+		$this->addElement(new XoopsFormCaptcha(), true);
85
+	}
86
+
87
+	/**
88
+	 * @param      $name
89
+	 * @param      $caption
90
+	 * @param bool $onclick
91
+	 */
92
+	public function addCustomButton($name, $caption, $onclick = false)
93
+	{
94
+		$custom_button_array    = array(
95
+			'name'    => $name,
96
+			'caption' => $caption,
97
+			'onclick' => $onclick
98
+		);
99
+		$this->_custom_button[] = $custom_button_array;
100
+	}
101
+
102
+	/**
103
+	 * Add an element to the form
104
+	 *
105
+	 * @param string|XoopsFormElement      &$formElement reference to a {@link XoopsFormElement}
106
+	 * @param bool        $key
107
+	 * @param bool        $var
108
+	 * @param bool|string $required     is this a "required" element?
109
+	 */
110
+	public function addElement($formElement, $key = false, $var = false, $required = 'notset')
111
+	{
112
+		if ($key) {
113
+			if ($this->targetObject->vars[$key]['readonly']) {
114
+				$formElement->setExtra('disabled="disabled"');
115
+				$formElement->setName($key . '-readonly');
116
+				// Since this element is disable, we still want to pass it's value in the form
117
+				$hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
118
+				$this->addElement($hidden);
119
+			}
120
+			$formElement->setDescription($var['form_dsc']);
121
+			if (isset($this->targetObject->controls[$key]['onSelect'])) {
122
+				$hidden = new XoopsFormHidden('changedField', false);
123
+				$this->addElement($hidden);
124
+				$otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
125
+				$onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
126
+				$formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
127
+			} else {
128
+				if (isset($var['form_extra'])) {
129
+					$formElement->setExtra($var['form_extra']);
130
+				}
131
+			}
132
+			$controls = $this->targetObject->controls;
133
+			if (isset($controls[$key]['js'])) {
134
+				$formElement->customValidationCode[] = $controls[$key]['js'];
135
+			}
136
+			parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required);
137
+		} else {
138
+			parent::addElement($formElement, $required === 'notset' ? false : true);
139
+		}
140
+		unset($formElement);
141
+	}
142
+
143
+	public function createElements()
144
+	{
145
+		$controls = $this->targetObject->controls;
146
+		$vars     = $this->targetObject->vars;
147
+		foreach ($vars as $key => $var) {
148
+
149
+			// If $displayOnForm is false OR this is the primary key, it doesn't
150
+			// need to be displayed, then we only create an hidden field
151
+			if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
152
+				$elementToAdd = new XoopsFormHidden($key, $var['value']);
153
+				$this->addElement($elementToAdd, $key, $var, false);
154
+				unset($elementToAdd);
155
+				// If not, the we need to create the proper form control for this fields
156
+			} else {
157
+				// If this field has a specific control, we will use it
158
+
159
+				if ($key === 'parentid') {
160
+					/**
161
+					 * Why this ?
162
+					 */
163
+				}
164
+				if (isset($controls[$key])) {
165
+					/* If the control has name, it's because it's an object already present in the script
166 166
                      * for example, "user"
167 167
                      * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect)
168 168
                      */
169
-                    if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
170
-                        $controls[$key]['name'] = 'select';
171
-                    }
172
-
173
-                    $form_select = $this->getControl($controls[$key]['name'], $key);
174
-
175
-                    // Adding on the form, the control for this field
176
-                    $this->addElement($form_select, $key, $var);
177
-                    unset($form_select);
178
-
179
-                    // If this field don't have a specific control, we will use the standard one, depending on its data type
180
-                } else {
181
-                    switch ($var['data_type']) {
182
-
183
-                        case XOBJ_DTYPE_TXTBOX:
184
-
185
-                            $form_text = $this->getControl('text', $key);
186
-                            $this->addElement($form_text, $key, $var);
187
-                            unset($form_text);
188
-                            break;
189
-
190
-                        case XOBJ_DTYPE_INT:
191
-                            $this->targetObject->setControl($key, array(
192
-                                'name' => 'text',
193
-                                'size' => '5'
194
-                            ));
195
-                            $form_text = $this->getControl('text', $key);
196
-                            $this->addElement($form_text, $key, $var);
197
-                            unset($form_text);
198
-                            break;
199
-
200
-                        case XOBJ_DTYPE_FLOAT:
201
-                            $this->targetObject->setControl($key, array(
202
-                                'name' => 'text',
203
-                                'size' => '5'
204
-                            ));
205
-                            $form_text = $this->getControl('text', $key);
206
-                            $this->addElement($form_text, $key, $var);
207
-                            unset($form_text);
208
-                            break;
209
-
210
-                        case XOBJ_DTYPE_LTIME:
211
-                            $form_date_time = $this->getControl('date_time', $key);
212
-                            $this->addElement($form_date_time, $key, $var);
213
-                            unset($form_date_time);
214
-                            break;
215
-
216
-                        case XOBJ_DTYPE_STIME:
217
-                            $form_date_time = $this->getControl('date', $key);
218
-                            $this->addElement($form_date_time, $key, $var);
219
-                            unset($form_date_time);
220
-                            break;
221
-
222
-                        case XOBJ_DTYPE_TIME_ONLY:
223
-                            $form_time = $this->getControl('time', $key);
224
-                            $this->addElement($form_time, $key, $var);
225
-                            unset($form_time);
226
-                            break;
227
-
228
-                        case XOBJ_DTYPE_CURRENCY:
229
-                            $this->targetObject->setControl($key, array(
230
-                                'name' => 'text',
231
-                                'size' => '15'
232
-                            ));
233
-                            $form_currency = $this->getControl('text', $key);
234
-                            $this->addElement($form_currency, $key, $var);
235
-                            unset($form_currency);
236
-                            break;
237
-
238
-                        case XOBJ_DTYPE_URLLINK:
239
-                            $form_urllink = $this->getControl('urllink', $key);
240
-                            $this->addElement($form_urllink, $key, $var);
241
-                            unset($form_urllink);
242
-                            break;
243
-
244
-                        case XOBJ_DTYPE_FILE:
245
-                            $form_file = $this->getControl('richfile', $key);
246
-                            $this->addElement($form_file, $key, $var);
247
-                            unset($form_file);
248
-                            break;
249
-
250
-                        case XOBJ_DTYPE_TXTAREA:
251
-
252
-                            $form_text_area = $this->getTextArea($key, $var);
253
-                            $this->addElement($form_text_area, $key, $var);
254
-                            unset($form_text_area);
255
-                            break;
256
-
257
-                        case XOBJ_DTYPE_ARRAY:
258
-                            // TODO: To come...
259
-                            break;
260
-                        case XOBJ_DTYPE_SOURCE:
261
-                            // TODO: To come...
262
-                            break;
263
-                        case XOBJ_DTYPE_FORM_SECTION:
264
-                            $section_control = new SmartFormSection($key, $var['value']);
265
-                            $this->addElement($section_control, $key, $var);
266
-                            unset($section_control);
267
-                            break;
268
-                        case XOBJ_DTYPE_FORM_SECTION_CLOSE:
269
-                            $section_control = new SmartFormSectionClose($key, $var['value']);
270
-                            $this->addElement($section_control, $key, $var);
271
-                            unset($section_control);
272
-                            break;
273
-                    }
274
-                }
275
-            }
276
-        }
277
-        // Add an hidden field to store the URL of the page before this form
278
-        $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form()));
279
-    }
280
-
281
-    public function createPermissionControls()
282
-    {
283
-        $smartModuleConfig = $this->targetObject->handler->getModuleConfig();
284
-
285
-        $permissions = $this->targetObject->handler->getPermissions();
286
-
287
-        if ($permissions) {
288
-            $memberHandler = xoops_getHandler('member');
289
-            $group_list    = $memberHandler->getGroupList();
290
-            asort($group_list);
291
-            foreach ($permissions as $permission) {
292
-                if ($this->targetObject->isNew()) {
293
-                    if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
294
-                        $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
295
-                    }
296
-                } else {
297
-                    $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
298
-                }
299
-                $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true);
300
-                $groups_select->setDescription($permission['description']);
301
-                $groups_select->addOptionArray($group_list);
302
-                $this->addElement($groups_select);
303
-                unset($groups_select);
304
-            }
305
-        }
306
-    }
307
-
308
-    /**
309
-     * @param      $form_name
310
-     * @param      $form_caption
311
-     * @param bool $submit_button_caption
312
-     */
313
-    public function createButtons($form_name, $form_caption, $submit_button_caption = false)
314
-    {
315
-        $button_tray = new XoopsFormElementTray('', '');
316
-        $button_tray->addElement(new XoopsFormHidden('op', $form_name));
317
-        if (!$submit_button_caption) {
318
-            if ($this->targetObject->isNew()) {
319
-                $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit');
320
-            } else {
321
-                $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit');
322
-            }
323
-        } else {
324
-            $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
325
-        }
326
-        $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
327
-        $button_tray->addElement($butt_create);
328
-
329
-        //creating custom buttons
330
-        if ($this->_custom_button) {
331
-            foreach ($this->_custom_button as $custom_button) {
332
-                $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
333
-                if ($custom_button['onclick']) {
334
-                    $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
335
-                }
336
-                $button_tray->addElement($butt_custom);
337
-                unset($butt_custom);
338
-            }
339
-        }
340
-
341
-        // creating the "cancel" button
342
-        $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
343
-        if ($this->_cancel_js_action) {
344
-            $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
345
-        } else {
346
-            $butt_cancel->setExtra('onclick="history.go(-1)"');
347
-        }
348
-        $button_tray->addElement($butt_cancel);
349
-
350
-        $this->addElement($button_tray);
351
-    }
352
-
353
-    /**
354
-     * @param $controlName
355
-     * @param $key
356
-     * @return XoopsFormLabel
357
-     */
358
-    public function getControl($controlName, $key)
359
-    {
360
-        switch ($controlName) {
361
-            case 'check':
362
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php');
363
-                $control    = $this->targetObject->getControl($key);
364
-                $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
365
-                $controlObj->addOptionArray($control['options']);
366
-
367
-                return $controlObj;
368
-                break;
369
-
370
-            case 'color':
371
-                $control    = $this->targetObject->getControl($key);
372
-                $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
373
-
374
-                return $controlObj;
375
-                break;
376
-
377
-            case 'radio':
378
-                $control = $this->targetObject->getControl($key);
379
-
380
-                $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
381
-                $controlObj->addOptionArray($control['options']);
382
-
383
-                return $controlObj;
384
-                break;
385
-
386
-            case 'label':
387
-                return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
388
-                break;
389
-
390
-            case 'textarea':
391
-                return $this->getTextArea($key);
392
-
393
-            case 'theme':
394
-                return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
395
-
396
-            case 'theme_multi':
397
-                return $this->getThemeSelect($key, $this->targetObject->vars[$key], true);
398
-                break;
399
-
400
-            case 'timezone':
401
-                return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
402
-                break;
403
-
404
-            case 'group':
405
-                return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
406
-                break;
407
-
408
-            case 'group_multi':
409
-                return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
410
-                break;
411
-
412
-            /*case 'user':
169
+					if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
170
+						$controls[$key]['name'] = 'select';
171
+					}
172
+
173
+					$form_select = $this->getControl($controls[$key]['name'], $key);
174
+
175
+					// Adding on the form, the control for this field
176
+					$this->addElement($form_select, $key, $var);
177
+					unset($form_select);
178
+
179
+					// If this field don't have a specific control, we will use the standard one, depending on its data type
180
+				} else {
181
+					switch ($var['data_type']) {
182
+
183
+						case XOBJ_DTYPE_TXTBOX:
184
+
185
+							$form_text = $this->getControl('text', $key);
186
+							$this->addElement($form_text, $key, $var);
187
+							unset($form_text);
188
+							break;
189
+
190
+						case XOBJ_DTYPE_INT:
191
+							$this->targetObject->setControl($key, array(
192
+								'name' => 'text',
193
+								'size' => '5'
194
+							));
195
+							$form_text = $this->getControl('text', $key);
196
+							$this->addElement($form_text, $key, $var);
197
+							unset($form_text);
198
+							break;
199
+
200
+						case XOBJ_DTYPE_FLOAT:
201
+							$this->targetObject->setControl($key, array(
202
+								'name' => 'text',
203
+								'size' => '5'
204
+							));
205
+							$form_text = $this->getControl('text', $key);
206
+							$this->addElement($form_text, $key, $var);
207
+							unset($form_text);
208
+							break;
209
+
210
+						case XOBJ_DTYPE_LTIME:
211
+							$form_date_time = $this->getControl('date_time', $key);
212
+							$this->addElement($form_date_time, $key, $var);
213
+							unset($form_date_time);
214
+							break;
215
+
216
+						case XOBJ_DTYPE_STIME:
217
+							$form_date_time = $this->getControl('date', $key);
218
+							$this->addElement($form_date_time, $key, $var);
219
+							unset($form_date_time);
220
+							break;
221
+
222
+						case XOBJ_DTYPE_TIME_ONLY:
223
+							$form_time = $this->getControl('time', $key);
224
+							$this->addElement($form_time, $key, $var);
225
+							unset($form_time);
226
+							break;
227
+
228
+						case XOBJ_DTYPE_CURRENCY:
229
+							$this->targetObject->setControl($key, array(
230
+								'name' => 'text',
231
+								'size' => '15'
232
+							));
233
+							$form_currency = $this->getControl('text', $key);
234
+							$this->addElement($form_currency, $key, $var);
235
+							unset($form_currency);
236
+							break;
237
+
238
+						case XOBJ_DTYPE_URLLINK:
239
+							$form_urllink = $this->getControl('urllink', $key);
240
+							$this->addElement($form_urllink, $key, $var);
241
+							unset($form_urllink);
242
+							break;
243
+
244
+						case XOBJ_DTYPE_FILE:
245
+							$form_file = $this->getControl('richfile', $key);
246
+							$this->addElement($form_file, $key, $var);
247
+							unset($form_file);
248
+							break;
249
+
250
+						case XOBJ_DTYPE_TXTAREA:
251
+
252
+							$form_text_area = $this->getTextArea($key, $var);
253
+							$this->addElement($form_text_area, $key, $var);
254
+							unset($form_text_area);
255
+							break;
256
+
257
+						case XOBJ_DTYPE_ARRAY:
258
+							// TODO: To come...
259
+							break;
260
+						case XOBJ_DTYPE_SOURCE:
261
+							// TODO: To come...
262
+							break;
263
+						case XOBJ_DTYPE_FORM_SECTION:
264
+							$section_control = new SmartFormSection($key, $var['value']);
265
+							$this->addElement($section_control, $key, $var);
266
+							unset($section_control);
267
+							break;
268
+						case XOBJ_DTYPE_FORM_SECTION_CLOSE:
269
+							$section_control = new SmartFormSectionClose($key, $var['value']);
270
+							$this->addElement($section_control, $key, $var);
271
+							unset($section_control);
272
+							break;
273
+					}
274
+				}
275
+			}
276
+		}
277
+		// Add an hidden field to store the URL of the page before this form
278
+		$this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form()));
279
+	}
280
+
281
+	public function createPermissionControls()
282
+	{
283
+		$smartModuleConfig = $this->targetObject->handler->getModuleConfig();
284
+
285
+		$permissions = $this->targetObject->handler->getPermissions();
286
+
287
+		if ($permissions) {
288
+			$memberHandler = xoops_getHandler('member');
289
+			$group_list    = $memberHandler->getGroupList();
290
+			asort($group_list);
291
+			foreach ($permissions as $permission) {
292
+				if ($this->targetObject->isNew()) {
293
+					if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
294
+						$groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
295
+					}
296
+				} else {
297
+					$groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
298
+				}
299
+				$groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true);
300
+				$groups_select->setDescription($permission['description']);
301
+				$groups_select->addOptionArray($group_list);
302
+				$this->addElement($groups_select);
303
+				unset($groups_select);
304
+			}
305
+		}
306
+	}
307
+
308
+	/**
309
+	 * @param      $form_name
310
+	 * @param      $form_caption
311
+	 * @param bool $submit_button_caption
312
+	 */
313
+	public function createButtons($form_name, $form_caption, $submit_button_caption = false)
314
+	{
315
+		$button_tray = new XoopsFormElementTray('', '');
316
+		$button_tray->addElement(new XoopsFormHidden('op', $form_name));
317
+		if (!$submit_button_caption) {
318
+			if ($this->targetObject->isNew()) {
319
+				$butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit');
320
+			} else {
321
+				$butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit');
322
+			}
323
+		} else {
324
+			$butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
325
+		}
326
+		$butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
327
+		$button_tray->addElement($butt_create);
328
+
329
+		//creating custom buttons
330
+		if ($this->_custom_button) {
331
+			foreach ($this->_custom_button as $custom_button) {
332
+				$butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
333
+				if ($custom_button['onclick']) {
334
+					$butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
335
+				}
336
+				$button_tray->addElement($butt_custom);
337
+				unset($butt_custom);
338
+			}
339
+		}
340
+
341
+		// creating the "cancel" button
342
+		$butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
343
+		if ($this->_cancel_js_action) {
344
+			$butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
345
+		} else {
346
+			$butt_cancel->setExtra('onclick="history.go(-1)"');
347
+		}
348
+		$button_tray->addElement($butt_cancel);
349
+
350
+		$this->addElement($button_tray);
351
+	}
352
+
353
+	/**
354
+	 * @param $controlName
355
+	 * @param $key
356
+	 * @return XoopsFormLabel
357
+	 */
358
+	public function getControl($controlName, $key)
359
+	{
360
+		switch ($controlName) {
361
+			case 'check':
362
+				include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php');
363
+				$control    = $this->targetObject->getControl($key);
364
+				$controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
365
+				$controlObj->addOptionArray($control['options']);
366
+
367
+				return $controlObj;
368
+				break;
369
+
370
+			case 'color':
371
+				$control    = $this->targetObject->getControl($key);
372
+				$controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
373
+
374
+				return $controlObj;
375
+				break;
376
+
377
+			case 'radio':
378
+				$control = $this->targetObject->getControl($key);
379
+
380
+				$controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
381
+				$controlObj->addOptionArray($control['options']);
382
+
383
+				return $controlObj;
384
+				break;
385
+
386
+			case 'label':
387
+				return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
388
+				break;
389
+
390
+			case 'textarea':
391
+				return $this->getTextArea($key);
392
+
393
+			case 'theme':
394
+				return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
395
+
396
+			case 'theme_multi':
397
+				return $this->getThemeSelect($key, $this->targetObject->vars[$key], true);
398
+				break;
399
+
400
+			case 'timezone':
401
+				return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
402
+				break;
403
+
404
+			case 'group':
405
+				return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
406
+				break;
407
+
408
+			case 'group_multi':
409
+				return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
410
+				break;
411
+
412
+			/*case 'user':
413 413
              return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
414 414
              break;*/
415 415
 
416
-            case 'user_multi':
417
-                return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
418
-                break;
419
-
420
-            case 'password':
421
-                return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
422
-                break;
423
-
424
-            case 'country':
425
-                return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
426
-                break;
427
-
428
-            case 'urllink':
429
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php');
430
-
431
-                return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
432
-                break;
433
-
434
-            case 'richfile':
435
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php');
436
-
437
-                return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
438
-                break;
439
-            case 'section':
440
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php');
441
-
442
-                return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
443
-                break;
444
-
445
-            default:
446
-                $classname = 'SmartForm' . ucfirst($controlName) . 'Element';
447
-                if (!class_exists($classname)) {
448
-                    if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
449
-                        include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php');
450
-                    } else {
451
-                        // perhaps this is a control created by the module
452
-                        $moduleName             = $this->targetObject->handler->_moduleName;
453
-                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
454
-                        $classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
455
-                        $classFileName          = strtolower($classname) . '.php';
456
-
457
-                        if (file_exists($moduleFormElementsPath . $classFileName)) {
458
-                            include_once($moduleFormElementsPath . $classFileName);
459
-                        } else {
460
-                            trigger_error($classname . ' Not found', E_USER_WARNING);
461
-
462
-                            return new XoopsFormLabel(); //Empty object
463
-                        }
464
-                    }
465
-                }
466
-
467
-                return new $classname($this->targetObject, $key);
468
-                break;
469
-        }
470
-    }
471
-
472
-    /**
473
-     * @param $key
474
-     * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea
475
-     */
476
-    public function getTextArea($key)
477
-    {
478
-        $var = $this->targetObject->vars[$key];
479
-
480
-        // if no control has been created, let's create a default one
481
-        if (!isset($this->targetObject->controls[$key])) {
482
-            $control = array(
483
-                'name'        => 'textarea',
484
-                'itemHandler' => false,
485
-                'method'      => false,
486
-                'module'      => false,
487
-                'form_editor' => 'default'
488
-            );
489
-        } else {
490
-            $control = $this->targetObject->controls[$key];
491
-        }
492
-        $xoops22 = smart_isXoops22();
493
-
494
-        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
495
-        /**
496
-         * If the editor is 'default', retreive the default editor of this module
497
-         */
498
-        if ($form_editor === 'default') {
499
-            global $xoopsModuleConfig;
500
-            $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
501
-        }
502
-
503
-        $caption = $var['form_caption'];
504
-        $name    = $key;
505
-
506
-        $value = $this->targetObject->getVar($key);
507
-
508
-        $value = $this->targetObject->getValueFor($key, true);
509
-
510
-        $editor_configs          = array();
511
-        $editor_configs['name']  = $name;
512
-        $editor_configs['value'] = $value;
513
-        if ($form_editor !== 'textarea') {
514
-            $editor_configs['rows'] = 35;
515
-            $editor_configs['cols'] = 60;
516
-        }
517
-
518
-        if (isset($control['rows'])) {
519
-            $editor_configs['rows'] = $control['rows'];
520
-        }
521
-        if (isset($control['cols'])) {
522
-            $editor_configs['cols'] = $control['cols'];
523
-        }
524
-
525
-        $editor_configs['width']  = '100%';
526
-        $editor_configs['height'] = '400px';
527
-
528
-        $dhtml            = true;
529
-        $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
530
-
531
-        if (file_exists($xoopseditorclass)) {
532
-            include_once($xoopseditorclass);
533
-            $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea');
534
-        } else {
535
-            switch ($form_editor) {
536
-
537
-                case 'tiny':
538
-                    if (!$xoops22) {
539
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
540
-                            include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php');
541
-                            $editor = new XoopsFormTinyTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
542
-                        } else {
543
-                            if ($dhtml) {
544
-                                $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
545
-                            } else {
546
-                                $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
547
-                            }
548
-                        }
549
-                    } else {
550
-                        $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
551
-                    }
552
-                    break;
553
-
554
-                case 'dhtmltextarea':
555
-                case 'dhtmltext':
556
-                    $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60);
557
-                    if ($var['form_dsc']) {
558
-                        $editor->setDescription($var['form_dsc']);
559
-                    }
560
-                    break;
561
-
562
-                case 'fckeditor':
563
-                    if (!$xoops22) {
564
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) {
565
-                            include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php');
566
-                            $editor = new XoopsFormFckeditor(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
567
-                        } else {
568
-                            if ($dhtml) {
569
-                                $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
570
-                            } else {
571
-                                $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
572
-                            }
573
-                        }
574
-                    } else {
575
-                        $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs);
576
-                    }
577
-                    break;
578
-
579
-                case 'inbetween':
580
-                    if (!$xoops22) {
581
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) {
582
-                            include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php');
583
-                            $editor = new XoopsFormInbetweenTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
584
-                        } else {
585
-                            if ($dhtml) {
586
-                                $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
587
-                            } else {
588
-                                $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
589
-                            }
590
-                        }
591
-                    } else {
592
-                        $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs);
593
-                    }
594
-                    break;
595
-
596
-                case 'koivi':
597
-                    if (!$xoops22) {
598
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) {
599
-                            include_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php');
600
-                            $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px');
601
-                        } else {
602
-                            if ($dhtml) {
603
-                                $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
604
-                            } else {
605
-                                $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
606
-                            }
607
-                        }
608
-                    } else {
609
-                        $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs);
610
-                    }
611
-                    break;
612
-
613
-                case 'spaw':
614
-                    if (!$xoops22) {
615
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) {
616
-                            include_once(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php');
617
-                            $editor = new XoopsFormSpaw($caption, $name, $value);
618
-                        }
619
-                    } else {
620
-                        $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs);
621
-                    }
622
-                    break;
623
-
624
-                case 'htmlarea':
625
-                    if (!$xoops22) {
626
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) {
627
-                            include_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php');
628
-                            $editor = new XoopsFormHtmlarea($caption, $name, $value);
629
-                        }
630
-                    } else {
631
-                        $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs);
632
-                    }
633
-                    break;
634
-
635
-                default:
636
-                case 'textarea':
637
-                    $form_rows = isset($control['rows']) ? $control['rows'] : 5;
638
-                    $form_cols = isset($control['cols']) ? $control['cols'] : 60;
639
-
640
-                    $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
641
-                    if ($var['form_dsc']) {
642
-                        $editor->setDescription($var['form_dsc']);
643
-                    }
644
-                    break;
645
-
646
-            }
647
-        }
648
-
649
-        return $editor;
650
-    }
651
-
652
-    /**
653
-     * @param                  $key
654
-     * @param                  $var
655
-     * @param  bool            $multiple
656
-     * @return XoopsFormSelect
657
-     */
658
-    public function getThemeSelect($key, $var, $multiple = false)
659
-    {
660
-        $size         = $multiple ? 5 : 1;
661
-        $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
662
-
663
-        $handle  = opendir(XOOPS_THEME_PATH . '/');
664
-        $dirlist = array();
665
-        while (false !== ($file = readdir($handle))) {
666
-            if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') {
667
-                $dirlist[$file] = $file;
668
-            }
669
-        }
670
-        closedir($handle);
671
-        if (!empty($dirlist)) {
672
-            asort($dirlist);
673
-            $theme_select->addOptionArray($dirlist);
674
-        }
675
-
676
-        return $theme_select;
677
-    }
678
-
679
-    /**
680
-     * @param $keyname
681
-     * @return bool
682
-     */
683
-    public function &getElementById($keyname)
684
-    {
685
-        foreach ($this->_elements as $eleObj) {
686
-            if ($eleObj->getName() == $keyname) {
687
-                $ret =& $eleObj;
688
-                break;
689
-            }
690
-        }
691
-
692
-        return isset($ret) ? $ret : false;
693
-    }
694
-
695
-    /**
696
-     * create HTML to output the form as a theme-enabled table with validation.
697
-     *
698
-     * @return string
699
-     */
700
-    public function render()
701
-    {
702
-        $required = $this->getRequired();
703
-        $ret      = "
416
+			case 'user_multi':
417
+				return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
418
+				break;
419
+
420
+			case 'password':
421
+				return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
422
+				break;
423
+
424
+			case 'country':
425
+				return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
426
+				break;
427
+
428
+			case 'urllink':
429
+				include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php');
430
+
431
+				return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
432
+				break;
433
+
434
+			case 'richfile':
435
+				include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php');
436
+
437
+				return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
438
+				break;
439
+			case 'section':
440
+				include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php');
441
+
442
+				return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
443
+				break;
444
+
445
+			default:
446
+				$classname = 'SmartForm' . ucfirst($controlName) . 'Element';
447
+				if (!class_exists($classname)) {
448
+					if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
449
+						include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php');
450
+					} else {
451
+						// perhaps this is a control created by the module
452
+						$moduleName             = $this->targetObject->handler->_moduleName;
453
+						$moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
454
+						$classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
455
+						$classFileName          = strtolower($classname) . '.php';
456
+
457
+						if (file_exists($moduleFormElementsPath . $classFileName)) {
458
+							include_once($moduleFormElementsPath . $classFileName);
459
+						} else {
460
+							trigger_error($classname . ' Not found', E_USER_WARNING);
461
+
462
+							return new XoopsFormLabel(); //Empty object
463
+						}
464
+					}
465
+				}
466
+
467
+				return new $classname($this->targetObject, $key);
468
+				break;
469
+		}
470
+	}
471
+
472
+	/**
473
+	 * @param $key
474
+	 * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea
475
+	 */
476
+	public function getTextArea($key)
477
+	{
478
+		$var = $this->targetObject->vars[$key];
479
+
480
+		// if no control has been created, let's create a default one
481
+		if (!isset($this->targetObject->controls[$key])) {
482
+			$control = array(
483
+				'name'        => 'textarea',
484
+				'itemHandler' => false,
485
+				'method'      => false,
486
+				'module'      => false,
487
+				'form_editor' => 'default'
488
+			);
489
+		} else {
490
+			$control = $this->targetObject->controls[$key];
491
+		}
492
+		$xoops22 = smart_isXoops22();
493
+
494
+		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
495
+		/**
496
+		 * If the editor is 'default', retreive the default editor of this module
497
+		 */
498
+		if ($form_editor === 'default') {
499
+			global $xoopsModuleConfig;
500
+			$form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
501
+		}
502
+
503
+		$caption = $var['form_caption'];
504
+		$name    = $key;
505
+
506
+		$value = $this->targetObject->getVar($key);
507
+
508
+		$value = $this->targetObject->getValueFor($key, true);
509
+
510
+		$editor_configs          = array();
511
+		$editor_configs['name']  = $name;
512
+		$editor_configs['value'] = $value;
513
+		if ($form_editor !== 'textarea') {
514
+			$editor_configs['rows'] = 35;
515
+			$editor_configs['cols'] = 60;
516
+		}
517
+
518
+		if (isset($control['rows'])) {
519
+			$editor_configs['rows'] = $control['rows'];
520
+		}
521
+		if (isset($control['cols'])) {
522
+			$editor_configs['cols'] = $control['cols'];
523
+		}
524
+
525
+		$editor_configs['width']  = '100%';
526
+		$editor_configs['height'] = '400px';
527
+
528
+		$dhtml            = true;
529
+		$xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
530
+
531
+		if (file_exists($xoopseditorclass)) {
532
+			include_once($xoopseditorclass);
533
+			$editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea');
534
+		} else {
535
+			switch ($form_editor) {
536
+
537
+				case 'tiny':
538
+					if (!$xoops22) {
539
+						if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
540
+							include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php');
541
+							$editor = new XoopsFormTinyTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
542
+						} else {
543
+							if ($dhtml) {
544
+								$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
545
+							} else {
546
+								$editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
547
+							}
548
+						}
549
+					} else {
550
+						$editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
551
+					}
552
+					break;
553
+
554
+				case 'dhtmltextarea':
555
+				case 'dhtmltext':
556
+					$editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60);
557
+					if ($var['form_dsc']) {
558
+						$editor->setDescription($var['form_dsc']);
559
+					}
560
+					break;
561
+
562
+				case 'fckeditor':
563
+					if (!$xoops22) {
564
+						if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) {
565
+							include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php');
566
+							$editor = new XoopsFormFckeditor(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
567
+						} else {
568
+							if ($dhtml) {
569
+								$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
570
+							} else {
571
+								$editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
572
+							}
573
+						}
574
+					} else {
575
+						$editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs);
576
+					}
577
+					break;
578
+
579
+				case 'inbetween':
580
+					if (!$xoops22) {
581
+						if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) {
582
+							include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php');
583
+							$editor = new XoopsFormInbetweenTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
584
+						} else {
585
+							if ($dhtml) {
586
+								$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
587
+							} else {
588
+								$editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
589
+							}
590
+						}
591
+					} else {
592
+						$editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs);
593
+					}
594
+					break;
595
+
596
+				case 'koivi':
597
+					if (!$xoops22) {
598
+						if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) {
599
+							include_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php');
600
+							$editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px');
601
+						} else {
602
+							if ($dhtml) {
603
+								$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
604
+							} else {
605
+								$editor = new XoopsFormTextArea($caption, $name, $value, 7, 60);
606
+							}
607
+						}
608
+					} else {
609
+						$editor = new XoopsFormEditor($caption, 'koivi', $editor_configs);
610
+					}
611
+					break;
612
+
613
+				case 'spaw':
614
+					if (!$xoops22) {
615
+						if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) {
616
+							include_once(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php');
617
+							$editor = new XoopsFormSpaw($caption, $name, $value);
618
+						}
619
+					} else {
620
+						$editor = new XoopsFormEditor($caption, 'spaw', $editor_configs);
621
+					}
622
+					break;
623
+
624
+				case 'htmlarea':
625
+					if (!$xoops22) {
626
+						if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) {
627
+							include_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php');
628
+							$editor = new XoopsFormHtmlarea($caption, $name, $value);
629
+						}
630
+					} else {
631
+						$editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs);
632
+					}
633
+					break;
634
+
635
+				default:
636
+				case 'textarea':
637
+					$form_rows = isset($control['rows']) ? $control['rows'] : 5;
638
+					$form_cols = isset($control['cols']) ? $control['cols'] : 60;
639
+
640
+					$editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
641
+					if ($var['form_dsc']) {
642
+						$editor->setDescription($var['form_dsc']);
643
+					}
644
+					break;
645
+
646
+			}
647
+		}
648
+
649
+		return $editor;
650
+	}
651
+
652
+	/**
653
+	 * @param                  $key
654
+	 * @param                  $var
655
+	 * @param  bool            $multiple
656
+	 * @return XoopsFormSelect
657
+	 */
658
+	public function getThemeSelect($key, $var, $multiple = false)
659
+	{
660
+		$size         = $multiple ? 5 : 1;
661
+		$theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
662
+
663
+		$handle  = opendir(XOOPS_THEME_PATH . '/');
664
+		$dirlist = array();
665
+		while (false !== ($file = readdir($handle))) {
666
+			if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') {
667
+				$dirlist[$file] = $file;
668
+			}
669
+		}
670
+		closedir($handle);
671
+		if (!empty($dirlist)) {
672
+			asort($dirlist);
673
+			$theme_select->addOptionArray($dirlist);
674
+		}
675
+
676
+		return $theme_select;
677
+	}
678
+
679
+	/**
680
+	 * @param $keyname
681
+	 * @return bool
682
+	 */
683
+	public function &getElementById($keyname)
684
+	{
685
+		foreach ($this->_elements as $eleObj) {
686
+			if ($eleObj->getName() == $keyname) {
687
+				$ret =& $eleObj;
688
+				break;
689
+			}
690
+		}
691
+
692
+		return isset($ret) ? $ret : false;
693
+	}
694
+
695
+	/**
696
+	 * create HTML to output the form as a theme-enabled table with validation.
697
+	 *
698
+	 * @return string
699
+	 */
700
+	public function render()
701
+	{
702
+		$required = $this->getRequired();
703
+		$ret      = "
704 704
             <form name='" .
705
-                    $this->getName() .
706
-                    "' id='" .
707
-                    $this->getName() .
708
-                    "' action='" .
709
-                    $this->getAction() .
710
-                    "' method='" .
711
-                    $this->getMethod() .
712
-                    "' onsubmit='return xoopsFormValidate_" .
713
-                    $this->getName() .
714
-                    "(this);'" .
715
-                    $this->getExtra() .
716
-                    ">
705
+					$this->getName() .
706
+					"' id='" .
707
+					$this->getName() .
708
+					"' action='" .
709
+					$this->getAction() .
710
+					"' method='" .
711
+					$this->getMethod() .
712
+					"' onsubmit='return xoopsFormValidate_" .
713
+					$this->getName() .
714
+					"(this);'" .
715
+					$this->getExtra() .
716
+					">
717 717
             <table width='100%' class='outer' cellspacing='1'>
718 718
             <tr><th colspan='2'>" .
719
-                    $this->getTitle() .
720
-                    '</th></tr>
719
+					$this->getTitle() .
720
+					'</th></tr>
721 721
         ';
722
-        $hidden   = '';
723
-        $class    = 'even';
724
-        foreach ($this->getElements() as $ele) {
725
-            if (!is_object($ele)) {
726
-                $ret .= $ele;
727
-            } elseif (!$ele->isHidden()) {
728
-                //$class = ( $class == 'even' ) ? 'odd': 'even';
729
-                $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
730
-                if ($ele->getDescription() !== '') {
731
-                    $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
732
-                }
733
-                $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
734
-            } else {
735
-                $hidden .= $ele->render();
736
-            }
737
-        }
738
-        $ret .= "</table>\n$hidden\n</form>\n";
739
-        $ret .= $this->renderValidationJS(true);
740
-
741
-        return $ret;
742
-    }
743
-
744
-    /**
745
-     * assign to smarty form template instead of displaying directly
746
-     *
747
-     * @param XoopsTpl &$tpl       reference to a {@link Smarty} object
748
-     * @param bool   $smartyName
749
-     * @see     Smarty
750
-     */
751
-    public function assign(XoopsTpl $tpl, $smartyName = false)
752
-    {
753
-        $i        = 0;
754
-        $elements = array();
755
-        foreach ($this->getElements() as $ele) {
756
-            $n                             = ($ele->getName() !== '') ? $ele->getName() : $i;
757
-            $elements[$n]['name']          = $ele->getName();
758
-            $elements[$n]['caption']       = $ele->getCaption();
759
-            $elements[$n]['body']          = $ele->render();
760
-            $elements[$n]['hidden']        = $ele->isHidden();
761
-            $elements[$n]['section']       = strtolower(get_class($ele)) == strtolower('SmartFormSection');
762
-            $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose';
763
-            $elements[$n]['hide']          = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false;
764
-            if ($ele->getDescription() !== '') {
765
-                $elements[$n]['description'] = $ele->getDescription();
766
-            }
767
-            ++$i;
768
-        }
769
-        $js = $this->renderValidationJS();
770
-        if (!$smartyName) {
771
-            $smartyName = $this->getName();
772
-        }
773
-
774
-        $tpl->assign($smartyName, array(
775
-            'title'      => $this->getTitle(),
776
-            'name'       => $this->getName(),
777
-            'action'     => $this->getAction(),
778
-            'method'     => $this->getMethod(),
779
-            'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
780
-            'javascript' => $js,
781
-            'elements'   => $elements
782
-        ));
783
-    }
784
-
785
-    /**
786
-     * @param  bool   $withtags
787
-     * @return string
788
-     */
789
-    public function renderValidationJS($withtags = true)
790
-    {
791
-        $js = '';
792
-        if ($withtags) {
793
-            $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
794
-        }
795
-        $myts     = MyTextSanitizer::getInstance();
796
-        $formname = $this->getName();
797
-        $js .= "function xoopsFormValidate_{$formname}(myform) {";
798
-        // First, output code to check required elements
799
-        $elements = $this->getRequired();
800
-        foreach ($elements as $elt) {
801
-            $eltname    = $elt->getName();
802
-            $eltcaption = trim($elt->getCaption());
803
-            $eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
804
-            $eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
805
-            if (strtolower(get_class($elt)) === 'xoopsformradio') {
806
-                $js .= 'var myOption = -1;';
807
-                $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
722
+		$hidden   = '';
723
+		$class    = 'even';
724
+		foreach ($this->getElements() as $ele) {
725
+			if (!is_object($ele)) {
726
+				$ret .= $ele;
727
+			} elseif (!$ele->isHidden()) {
728
+				//$class = ( $class == 'even' ) ? 'odd': 'even';
729
+				$ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
730
+				if ($ele->getDescription() !== '') {
731
+					$ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
732
+				}
733
+				$ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
734
+			} else {
735
+				$hidden .= $ele->render();
736
+			}
737
+		}
738
+		$ret .= "</table>\n$hidden\n</form>\n";
739
+		$ret .= $this->renderValidationJS(true);
740
+
741
+		return $ret;
742
+	}
743
+
744
+	/**
745
+	 * assign to smarty form template instead of displaying directly
746
+	 *
747
+	 * @param XoopsTpl &$tpl       reference to a {@link Smarty} object
748
+	 * @param bool   $smartyName
749
+	 * @see     Smarty
750
+	 */
751
+	public function assign(XoopsTpl $tpl, $smartyName = false)
752
+	{
753
+		$i        = 0;
754
+		$elements = array();
755
+		foreach ($this->getElements() as $ele) {
756
+			$n                             = ($ele->getName() !== '') ? $ele->getName() : $i;
757
+			$elements[$n]['name']          = $ele->getName();
758
+			$elements[$n]['caption']       = $ele->getCaption();
759
+			$elements[$n]['body']          = $ele->render();
760
+			$elements[$n]['hidden']        = $ele->isHidden();
761
+			$elements[$n]['section']       = strtolower(get_class($ele)) == strtolower('SmartFormSection');
762
+			$elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose';
763
+			$elements[$n]['hide']          = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false;
764
+			if ($ele->getDescription() !== '') {
765
+				$elements[$n]['description'] = $ele->getDescription();
766
+			}
767
+			++$i;
768
+		}
769
+		$js = $this->renderValidationJS();
770
+		if (!$smartyName) {
771
+			$smartyName = $this->getName();
772
+		}
773
+
774
+		$tpl->assign($smartyName, array(
775
+			'title'      => $this->getTitle(),
776
+			'name'       => $this->getName(),
777
+			'action'     => $this->getAction(),
778
+			'method'     => $this->getMethod(),
779
+			'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
780
+			'javascript' => $js,
781
+			'elements'   => $elements
782
+		));
783
+	}
784
+
785
+	/**
786
+	 * @param  bool   $withtags
787
+	 * @return string
788
+	 */
789
+	public function renderValidationJS($withtags = true)
790
+	{
791
+		$js = '';
792
+		if ($withtags) {
793
+			$js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
794
+		}
795
+		$myts     = MyTextSanitizer::getInstance();
796
+		$formname = $this->getName();
797
+		$js .= "function xoopsFormValidate_{$formname}(myform) {";
798
+		// First, output code to check required elements
799
+		$elements = $this->getRequired();
800
+		foreach ($elements as $elt) {
801
+			$eltname    = $elt->getName();
802
+			$eltcaption = trim($elt->getCaption());
803
+			$eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
804
+			$eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
805
+			if (strtolower(get_class($elt)) === 'xoopsformradio') {
806
+				$js .= 'var myOption = -1;';
807
+				$js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
808 808
                     if (myform.{$eltname}[i].checked) {
809 809
                         myOption = i; i = -1;
810 810
                     }
811 811
                 }
812 812
                 if (myOption == -1) {
813 813
                     window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n";
814
-            } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') {
815
-                $js .= 'var hasSelections = false;';
816
-                $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
814
+			} elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') {
815
+				$js .= 'var hasSelections = false;';
816
+				$js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
817 817
                     if (myform['{$eltname}[]'].options[i].selected) {
818 818
                         hasSelections = true;
819 819
                     }
@@ -821,11 +821,11 @@  discard block
 block discarded – undo
821 821
                 }
822 822
                 if (hasSelections == false) {
823 823
                     window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n";
824
-            } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' || strtolower(get_class($elt)) === 'smartformcheckelement') {
825
-                $js .= 'var hasSelections = false;';
826
-                //sometimes, there is an implicit '[]', sometimes not
827
-                if (strpos($eltname, '[') === false) {
828
-                    $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
824
+			} elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' || strtolower(get_class($elt)) === 'smartformcheckelement') {
825
+				$js .= 'var hasSelections = false;';
826
+				//sometimes, there is an implicit '[]', sometimes not
827
+				if (strpos($eltname, '[') === false) {
828
+					$js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
829 829
                         if (myform['{$eltname}[]'][i].checked) {
830 830
                             hasSelections = true;
831 831
                         }
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
                     }
834 834
                     if (hasSelections == false) {
835 835
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n";
836
-                } else {
837
-                    $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
836
+				} else {
837
+					$js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
838 838
                         if (myform['{$eltname}'][i].checked) {
839 839
                             hasSelections = true;
840 840
                         }
@@ -842,25 +842,25 @@  discard block
 block discarded – undo
842 842
                     }
843 843
                     if (hasSelections == false) {
844 844
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
845
-                }
846
-            } else {
847
-                $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
848
-            }
849
-        }
850
-        // Now, handle custom validation code
851
-        $elements =& $this->getElements(true);
852
-        foreach ($elements as $elt) {
853
-            if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') {
854
-                if ($eltjs = $elt->renderValidationJS()) {
855
-                    $js .= $eltjs . "\n";
856
-                }
857
-            }
858
-        }
859
-        $js .= "return true;\n}\n";
860
-        if ($withtags) {
861
-            $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n";
862
-        }
863
-
864
-        return $js;
865
-    }
845
+				}
846
+			} else {
847
+				$js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
848
+			}
849
+		}
850
+		// Now, handle custom validation code
851
+		$elements =& $this->getElements(true);
852
+		foreach ($elements as $elt) {
853
+			if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') {
854
+				if ($eltjs = $elt->renderValidationJS()) {
855
+					$js .= $eltjs . "\n";
856
+				}
857
+			}
858
+		}
859
+		$js .= "return true;\n}\n";
860
+		if ($withtags) {
861
+			$js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n";
862
+		}
863
+
864
+		return $js;
865
+	}
866 866
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
 /**
16 16
  * Including the XoopsFormLoader classes
17 17
  */
18
-include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
19
-include_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php';
20
-include_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php';
18
+include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
19
+include_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsection.php';
20
+include_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsectionclose.php';
21 21
 
22 22
 /**
23 23
  * SmartForm base class
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false)
54 54
     {
55
-        $this->targetObject           =& $target;
55
+        $this->targetObject           = & $target;
56 56
         $this->form_fields            = $form_fields;
57 57
         $this->_cancel_js_action      = $cancel_js_action;
58 58
         $this->_captcha               = $captcha;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
     public function addCaptcha()
82 82
     {
83
-        include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php');
83
+        include_once(SMARTOBJECT_ROOT_PATH.'include/captcha/formcaptcha.php');
84 84
         $this->addElement(new XoopsFormCaptcha(), true);
85 85
     }
86 86
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function addCustomButton($name, $caption, $onclick = false)
93 93
     {
94
-        $custom_button_array    = array(
94
+        $custom_button_array = array(
95 95
             'name'    => $name,
96 96
             'caption' => $caption,
97 97
             'onclick' => $onclick
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         if ($key) {
113 113
             if ($this->targetObject->vars[$key]['readonly']) {
114 114
                 $formElement->setExtra('disabled="disabled"');
115
-                $formElement->setName($key . '-readonly');
115
+                $formElement->setName($key.'-readonly');
116 116
                 // Since this element is disable, we still want to pass it's value in the form
117 117
                 $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
118 118
                 $this->addElement($hidden);
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $this->addElement($hidden);
124 124
                 $otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
125 125
                 $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
126
-                $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
126
+                $formElement->setExtra('onchange="'.$onchangedString.'"'.' '.$otherExtra);
127 127
             } else {
128 128
                 if (isset($var['form_extra'])) {
129 129
                     $formElement->setExtra($var['form_extra']);
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
             asort($group_list);
291 291
             foreach ($permissions as $permission) {
292 292
                 if ($this->targetObject->isNew()) {
293
-                    if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
294
-                        $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
293
+                    if (isset($smartModuleConfig['def_perm_'.$permission['perm_name']])) {
294
+                        $groups_value = $smartModuleConfig['def_perm_'.$permission['perm_name']];
295 295
                     }
296 296
                 } else {
297 297
                     $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
         } else {
324 324
             $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
325 325
         }
326
-        $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
326
+        $butt_create->setExtra('onclick="this.form.elements.op.value=\''.$form_name.'\'"');
327 327
         $button_tray->addElement($butt_create);
328 328
 
329 329
         //creating custom buttons
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
             foreach ($this->_custom_button as $custom_button) {
332 332
                 $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
333 333
                 if ($custom_button['onclick']) {
334
-                    $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
334
+                    $butt_custom->setExtra('onclick="'.$custom_button['onclick'].'"');
335 335
                 }
336 336
                 $button_tray->addElement($butt_custom);
337 337
                 unset($butt_custom);
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
         // creating the "cancel" button
342 342
         $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
343 343
         if ($this->_cancel_js_action) {
344
-            $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
344
+            $butt_cancel->setExtra('onclick="'.$this->_cancel_js_action.'"');
345 345
         } else {
346 346
             $butt_cancel->setExtra('onclick="history.go(-1)"');
347 347
         }
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
     {
360 360
         switch ($controlName) {
361 361
             case 'check':
362
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php');
362
+                include_once(SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformcheckelement.php');
363 363
                 $control    = $this->targetObject->getControl($key);
364 364
                 $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
365 365
                 $controlObj->addOptionArray($control['options']);
@@ -426,38 +426,38 @@  discard block
 block discarded – undo
426 426
                 break;
427 427
 
428 428
             case 'urllink':
429
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php');
429
+                include_once(SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformurllinkelement.php');
430 430
 
431 431
                 return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
432 432
                 break;
433 433
 
434 434
             case 'richfile':
435
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php');
435
+                include_once(SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformrichfileelement.php');
436 436
 
437 437
                 return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
438 438
                 break;
439 439
             case 'section':
440
-                include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php');
440
+                include_once(SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformsection.php');
441 441
 
442 442
                 return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
443 443
                 break;
444 444
 
445 445
             default:
446
-                $classname = 'SmartForm' . ucfirst($controlName) . 'Element';
446
+                $classname = 'SmartForm'.ucfirst($controlName).'Element';
447 447
                 if (!class_exists($classname)) {
448
-                    if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
449
-                        include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php');
448
+                    if (file_exists(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php')) {
449
+                        include_once(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php');
450 450
                     } else {
451 451
                         // perhaps this is a control created by the module
452 452
                         $moduleName             = $this->targetObject->handler->_moduleName;
453
-                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
454
-                        $classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
455
-                        $classFileName          = strtolower($classname) . '.php';
453
+                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath.'class/form/elements/';
454
+                        $classname              = ucfirst($moduleName).ucfirst($controlName).'Element';
455
+                        $classFileName          = strtolower($classname).'.php';
456 456
 
457
-                        if (file_exists($moduleFormElementsPath . $classFileName)) {
458
-                            include_once($moduleFormElementsPath . $classFileName);
457
+                        if (file_exists($moduleFormElementsPath.$classFileName)) {
458
+                            include_once($moduleFormElementsPath.$classFileName);
459 459
                         } else {
460
-                            trigger_error($classname . ' Not found', E_USER_WARNING);
460
+                            trigger_error($classname.' Not found', E_USER_WARNING);
461 461
 
462 462
                             return new XoopsFormLabel(); //Empty object
463 463
                         }
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
         $editor_configs['height'] = '400px';
527 527
 
528 528
         $dhtml            = true;
529
-        $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
529
+        $xoopseditorclass = XOOPS_ROOT_PATH.'/class/xoopsform/formeditor.php';
530 530
 
531 531
         if (file_exists($xoopseditorclass)) {
532 532
             include_once($xoopseditorclass);
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
 
537 537
                 case 'tiny':
538 538
                     if (!$xoops22) {
539
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
540
-                            include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php');
539
+                        if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
540
+                            include_once(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php');
541 541
                             $editor = new XoopsFormTinyTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
542 542
                         } else {
543 543
                             if ($dhtml) {
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 
562 562
                 case 'fckeditor':
563 563
                     if (!$xoops22) {
564
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) {
565
-                            include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php');
564
+                        if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/fckeditor/formfckeditor.php')) {
565
+                            include_once(XOOPS_ROOT_PATH.'/class/xoopseditor/fckeditor/formfckeditor.php');
566 566
                             $editor = new XoopsFormFckeditor(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
567 567
                         } else {
568 568
                             if ($dhtml) {
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
 
579 579
                 case 'inbetween':
580 580
                     if (!$xoops22) {
581
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) {
582
-                            include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php');
581
+                        if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/inbetween/forminbetweentextarea.php')) {
582
+                            include_once(XOOPS_ROOT_PATH.'/class/xoopseditor/inbetween/forminbetweentextarea.php');
583 583
                             $editor = new XoopsFormInbetweenTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true);
584 584
                         } else {
585 585
                             if ($dhtml) {
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
 
596 596
                 case 'koivi':
597 597
                     if (!$xoops22) {
598
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) {
599
-                            include_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php');
598
+                        if (is_readable(XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php')) {
599
+                            include_once(XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php');
600 600
                             $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px');
601 601
                         } else {
602 602
                             if ($dhtml) {
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
 
613 613
                 case 'spaw':
614 614
                     if (!$xoops22) {
615
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) {
616
-                            include_once(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php');
615
+                        if (is_readable(XOOPS_ROOT_PATH.'/class/spaw/formspaw.php')) {
616
+                            include_once(XOOPS_ROOT_PATH.'/class/spaw/formspaw.php');
617 617
                             $editor = new XoopsFormSpaw($caption, $name, $value);
618 618
                         }
619 619
                     } else {
@@ -623,8 +623,8 @@  discard block
 block discarded – undo
623 623
 
624 624
                 case 'htmlarea':
625 625
                     if (!$xoops22) {
626
-                        if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) {
627
-                            include_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php');
626
+                        if (is_readable(XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php')) {
627
+                            include_once(XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php');
628 628
                             $editor = new XoopsFormHtmlarea($caption, $name, $value);
629 629
                         }
630 630
                     } else {
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
         $size         = $multiple ? 5 : 1;
661 661
         $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
662 662
 
663
-        $handle  = opendir(XOOPS_THEME_PATH . '/');
663
+        $handle  = opendir(XOOPS_THEME_PATH.'/');
664 664
         $dirlist = array();
665 665
         while (false !== ($file = readdir($handle))) {
666
-            if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') {
666
+            if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') {
667 667
                 $dirlist[$file] = $file;
668 668
             }
669 669
         }
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
     {
685 685
         foreach ($this->_elements as $eleObj) {
686 686
             if ($eleObj->getName() == $keyname) {
687
-                $ret =& $eleObj;
687
+                $ret = & $eleObj;
688 688
                 break;
689 689
             }
690 690
         }
@@ -702,21 +702,21 @@  discard block
 block discarded – undo
702 702
         $required = $this->getRequired();
703 703
         $ret      = "
704 704
             <form name='" .
705
-                    $this->getName() .
706
-                    "' id='" .
707
-                    $this->getName() .
708
-                    "' action='" .
709
-                    $this->getAction() .
710
-                    "' method='" .
711
-                    $this->getMethod() .
712
-                    "' onsubmit='return xoopsFormValidate_" .
713
-                    $this->getName() .
714
-                    "(this);'" .
715
-                    $this->getExtra() .
705
+                    $this->getName().
706
+                    "' id='".
707
+                    $this->getName().
708
+                    "' action='".
709
+                    $this->getAction().
710
+                    "' method='".
711
+                    $this->getMethod().
712
+                    "' onsubmit='return xoopsFormValidate_".
713
+                    $this->getName().
714
+                    "(this);'".
715
+                    $this->getExtra().
716 716
                     ">
717 717
             <table width='100%' class='outer' cellspacing='1'>
718 718
             <tr><th colspan='2'>" .
719
-                    $this->getTitle() .
719
+                    $this->getTitle().
720 720
                     '</th></tr>
721 721
         ';
722 722
         $hidden   = '';
@@ -726,11 +726,11 @@  discard block
 block discarded – undo
726 726
                 $ret .= $ele;
727 727
             } elseif (!$ele->isHidden()) {
728 728
                 //$class = ( $class == 'even' ) ? 'odd': 'even';
729
-                $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
729
+                $ret .= "<tr id='".$ele->getName()."' valign='top' align='left'><td class='head'>".$ele->getCaption();
730 730
                 if ($ele->getDescription() !== '') {
731
-                    $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
731
+                    $ret .= '<br><br><span style="font-weight: normal;">'.$ele->getDescription().'</span>';
732 732
                 }
733
-                $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
733
+                $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n";
734 734
             } else {
735 735
                 $hidden .= $ele->render();
736 736
             }
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
             'name'       => $this->getName(),
777 777
             'action'     => $this->getAction(),
778 778
             'method'     => $this->getMethod(),
779
-            'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
779
+            'extra'      => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(),
780 780
             'javascript' => $js,
781 781
             'elements'   => $elements
782 782
         ));
@@ -844,15 +844,15 @@  discard block
 block discarded – undo
844 844
                         window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
845 845
                 }
846 846
             } else {
847
-                $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
847
+                $js .= "if ( myform.{$eltname}.value == \"\" ) "."{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
848 848
             }
849 849
         }
850 850
         // Now, handle custom validation code
851
-        $elements =& $this->getElements(true);
851
+        $elements = & $this->getElements(true);
852 852
         foreach ($elements as $elt) {
853 853
             if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') {
854 854
                 if ($eltjs = $elt->renderValidationJS()) {
855
-                    $js .= $eltjs . "\n";
855
+                    $js .= $eltjs."\n";
856 856
                 }
857 857
             }
858 858
         }
Please login to merge, or discard this patch.
class/member.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -237,7 +237,7 @@
 block discarded – undo
237 237
      * Creates a random number with a specified number of $digits
238 238
      *
239 239
      * @param  int $digits number of digits
240
-     * @return return int random number
240
+     * @return string int random number
241 241
      * @author xHelp Team
242 242
      *
243 243
      * @access public
Please login to merge, or discard this patch.
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -46,227 +46,227 @@
 block discarded – undo
46 46
  */
47 47
 class SmartobjectMemberHandler extends XoopsMemberHandler
48 48
 {
49
-    /**
50
-     * constructor
51
-     * @param XoopsDatabase $db
52
-     */
53
-    public function __construct(XoopsDatabase $db)
54
-    {
55
-        parent::__construct($db);
56
-        $this->_uHandler = xoops_getModuleHandler('user', 'smartobject');
57
-    }
49
+	/**
50
+	 * constructor
51
+	 * @param XoopsDatabase $db
52
+	 */
53
+	public function __construct(XoopsDatabase $db)
54
+	{
55
+		parent::__construct($db);
56
+		$this->_uHandler = xoops_getModuleHandler('user', 'smartobject');
57
+	}
58 58
 
59
-    /**
60
-     * @param       $userObj
61
-     * @param  bool $groups
62
-     * @param  bool $notifyUser
63
-     * @param  bool $password
64
-     * @return bool
65
-     */
66
-    public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false)
67
-    {
68
-        $email = $userObj->getVar('email');
69
-        if (!$userObj->getVar('email') || $email === '') {
70
-            $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL);
59
+	/**
60
+	 * @param       $userObj
61
+	 * @param  bool $groups
62
+	 * @param  bool $notifyUser
63
+	 * @param  bool $password
64
+	 * @return bool
65
+	 */
66
+	public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false)
67
+	{
68
+		$email = $userObj->getVar('email');
69
+		if (!$userObj->getVar('email') || $email === '') {
70
+			$userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL);
71 71
 
72
-            return false;
73
-        }
72
+			return false;
73
+		}
74 74
 
75
-        $password = $userObj->getVar('pass');
76
-        // randomly generating the password if not already set
77
-        if ('' === $password) {
78
-            $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6);
79
-        }
80
-        $userObj->setVar('pass', md5($password));
75
+		$password = $userObj->getVar('pass');
76
+		// randomly generating the password if not already set
77
+		if ('' === $password) {
78
+			$password = substr(md5(uniqid(mt_rand(), 1)), 0, 6);
79
+		}
80
+		$userObj->setVar('pass', md5($password));
81 81
 
82
-        // if no username is set, let's generate one
83
-        $unamecount = 20;
84
-        $uname      = $userObj->getVar('uname');
85
-        if (!$uname || $uname === '') {
86
-            $usernames = $this->genUserNames($email, $unamecount);
87
-            $newuser   = false;
88
-            $i         = 0;
89
-            while ($newuser === false) {
90
-                $crit  = new Criteria('uname', $usernames[$i]);
91
-                $count = $this->getUserCount($crit);
92
-                if ($count == 0) {
93
-                    $newuser = true;
94
-                } else {
95
-                    //Move to next username
96
-                    ++$i;
97
-                    if ($i == $unamecount) {
98
-                        //Get next batch of usernames to try, reset counter
99
-                        $usernames = $this->genUserNames($email, $unamecount);
100
-                        $i         = 0;
101
-                    }
102
-                }
103
-            }
104
-        }
82
+		// if no username is set, let's generate one
83
+		$unamecount = 20;
84
+		$uname      = $userObj->getVar('uname');
85
+		if (!$uname || $uname === '') {
86
+			$usernames = $this->genUserNames($email, $unamecount);
87
+			$newuser   = false;
88
+			$i         = 0;
89
+			while ($newuser === false) {
90
+				$crit  = new Criteria('uname', $usernames[$i]);
91
+				$count = $this->getUserCount($crit);
92
+				if ($count == 0) {
93
+					$newuser = true;
94
+				} else {
95
+					//Move to next username
96
+					++$i;
97
+					if ($i == $unamecount) {
98
+						//Get next batch of usernames to try, reset counter
99
+						$usernames = $this->genUserNames($email, $unamecount);
100
+						$i         = 0;
101
+					}
102
+				}
103
+			}
104
+		}
105 105
 
106
-        global $xoopsConfig;
106
+		global $xoopsConfig;
107 107
 
108
-        $configHandler   = xoops_getHandler('config');
109
-        $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
110
-        switch ($xoopsConfigUser['activation_type']) {
111
-            case 0:
112
-                $level           = 0;
113
-                $mailtemplate    = 'smartmail_activate_user.tpl';
114
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email);
115
-                break;
116
-            case 1:
117
-                $level           = 1;
118
-                $mailtemplate    = 'smartmail_auto_activate_user.tpl';
119
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email);
120
-                break;
121
-            case 2:
122
-            default:
123
-                $level           = 0;
124
-                $mailtemplate    = 'smartmail_admin_activate_user.tpl';
125
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email);
126
-        }
108
+		$configHandler   = xoops_getHandler('config');
109
+		$xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
110
+		switch ($xoopsConfigUser['activation_type']) {
111
+			case 0:
112
+				$level           = 0;
113
+				$mailtemplate    = 'smartmail_activate_user.tpl';
114
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email);
115
+				break;
116
+			case 1:
117
+				$level           = 1;
118
+				$mailtemplate    = 'smartmail_auto_activate_user.tpl';
119
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email);
120
+				break;
121
+			case 2:
122
+			default:
123
+				$level           = 0;
124
+				$mailtemplate    = 'smartmail_admin_activate_user.tpl';
125
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email);
126
+		}
127 127
 
128
-        $userObj->setVar('uname', $usernames[$i]);
129
-        $userObj->setVar('user_avatar', 'blank.gif');
130
-        $userObj->setVar('user_regdate', time());
131
-        $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']);
132
-        $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
133
-        $userObj->setVar('actkey', $actkey);
134
-        $userObj->setVar('email', $email);
135
-        $userObj->setVar('notify_method', 2);
136
-        $userObj->setVar('level', $userObj);
128
+		$userObj->setVar('uname', $usernames[$i]);
129
+		$userObj->setVar('user_avatar', 'blank.gif');
130
+		$userObj->setVar('user_regdate', time());
131
+		$userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']);
132
+		$actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
133
+		$userObj->setVar('actkey', $actkey);
134
+		$userObj->setVar('email', $email);
135
+		$userObj->setVar('notify_method', 2);
136
+		$userObj->setVar('level', $userObj);
137 137
 
138
-        if ($this->insertUser($userObj)) {
138
+		if ($this->insertUser($userObj)) {
139 139
 
140
-            // if $groups=false, Add the user to Registered Users group
141
-            if (!$groups) {
142
-                $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid'));
143
-            } else {
144
-                foreach ($groups as $groupid) {
145
-                    $this->addUserToGroup($groupid, $userObj->getVar('uid'));
146
-                }
147
-            }
148
-        } else {
149
-            return false;
150
-        }
140
+			// if $groups=false, Add the user to Registered Users group
141
+			if (!$groups) {
142
+				$this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid'));
143
+			} else {
144
+				foreach ($groups as $groupid) {
145
+					$this->addUserToGroup($groupid, $userObj->getVar('uid'));
146
+				}
147
+			}
148
+		} else {
149
+			return false;
150
+		}
151 151
 
152
-        if ($notifyUser) {
153
-            // send some notifications
154
-            $xoopsMailer =& getMailer();
155
-            $xoopsMailer->useMail();
156
-            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
157
-            $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
158
-            $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
159
-            $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
160
-            $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
161
-            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
162
-            $xoopsMailer->assign('NAME', $userObj->getVar('name'));
163
-            $xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
164
-            $xoopsMailer->setToUsers($userObj);
165
-            $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
166
-            $xoopsMailer->setFromName($xoopsConfig['sitename']);
167
-            $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename']));
152
+		if ($notifyUser) {
153
+			// send some notifications
154
+			$xoopsMailer =& getMailer();
155
+			$xoopsMailer->useMail();
156
+			$xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
157
+			$xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
158
+			$xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
159
+			$xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
160
+			$xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
161
+			$xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
162
+			$xoopsMailer->assign('NAME', $userObj->getVar('name'));
163
+			$xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
164
+			$xoopsMailer->setToUsers($userObj);
165
+			$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
166
+			$xoopsMailer->setFromName($xoopsConfig['sitename']);
167
+			$xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename']));
168 168
 
169
-            if (!$xoopsMailer->send(true)) {
170
-                /**
171
-                 * @todo trap error if email was not sent
172
-                 */
173
-                $xoopsMailer->getErrors(true);
174
-            }
175
-        }
169
+			if (!$xoopsMailer->send(true)) {
170
+				/**
171
+				 * @todo trap error if email was not sent
172
+				 */
173
+				$xoopsMailer->getErrors(true);
174
+			}
175
+		}
176 176
 
177
-        return true;
178
-    }
177
+		return true;
178
+	}
179 179
 
180
-    /**
181
-     * Generates an array of usernames
182
-     *
183
-     * @param  string $email email of user
184
-     * @param  int    $count number of names to generate
185
-     * @return array  $names
186
-     * @internal param string $name name of user
187
-     * @author   xHelp Team
188
-     *
189
-     * @access   public
190
-     */
191
-    public function genUserNames($email, $count = 20)
192
-    {
193
-        $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username
180
+	/**
181
+	 * Generates an array of usernames
182
+	 *
183
+	 * @param  string $email email of user
184
+	 * @param  int    $count number of names to generate
185
+	 * @return array  $names
186
+	 * @internal param string $name name of user
187
+	 * @author   xHelp Team
188
+	 *
189
+	 * @access   public
190
+	 */
191
+	public function genUserNames($email, $count = 20)
192
+	{
193
+		$name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username
194 194
 
195
-        $names  = array();
196
-        $userid = explode('@', $email);
195
+		$names  = array();
196
+		$userid = explode('@', $email);
197 197
 
198
-        $basename    = '';
199
-        $hasbasename = false;
200
-        $emailname   = $userid[0];
198
+		$basename    = '';
199
+		$hasbasename = false;
200
+		$emailname   = $userid[0];
201 201
 
202
-        $names[] = $emailname;
202
+		$names[] = $emailname;
203 203
 
204
-        if (strlen($name) > 0) {
205
-            $name = explode(' ', trim($name));
206
-            if (count($name) > 1) {
207
-                $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
208
-            } else {
209
-                $basename = strtolower($name[0]);
210
-            }
211
-            $basename = xoops_substr($basename, 0, 60, '');
212
-            //Prevent Duplication of Email Username and Name
213
-            if (!in_array($basename, $names)) {
214
-                $names[]     = $basename;
215
-                $hasbasename = true;
216
-            }
217
-        }
204
+		if (strlen($name) > 0) {
205
+			$name = explode(' ', trim($name));
206
+			if (count($name) > 1) {
207
+				$basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
208
+			} else {
209
+				$basename = strtolower($name[0]);
210
+			}
211
+			$basename = xoops_substr($basename, 0, 60, '');
212
+			//Prevent Duplication of Email Username and Name
213
+			if (!in_array($basename, $names)) {
214
+				$names[]     = $basename;
215
+				$hasbasename = true;
216
+			}
217
+		}
218 218
 
219
-        $i          = count($names);
220
-        $onbasename = 1;
221
-        while ($i < $count) {
222
-            $num = $this->genRandNumber();
223
-            if ($onbasename < 0 && $hasbasename) {
224
-                $names[] = xoops_substr($basename, 0, 58, '') . $num;
225
-            } else {
226
-                $names[] = xoops_substr($emailname, 0, 58, '') . $num;
227
-            }
228
-            $i          = count($names);
229
-            $onbasename = ~$onbasename;
230
-            $num        = '';
231
-        }
219
+		$i          = count($names);
220
+		$onbasename = 1;
221
+		while ($i < $count) {
222
+			$num = $this->genRandNumber();
223
+			if ($onbasename < 0 && $hasbasename) {
224
+				$names[] = xoops_substr($basename, 0, 58, '') . $num;
225
+			} else {
226
+				$names[] = xoops_substr($emailname, 0, 58, '') . $num;
227
+			}
228
+			$i          = count($names);
229
+			$onbasename = ~$onbasename;
230
+			$num        = '';
231
+		}
232 232
 
233
-        return $names;
234
-    }
233
+		return $names;
234
+	}
235 235
 
236
-    /**
237
-     * Creates a random number with a specified number of $digits
238
-     *
239
-     * @param  int    $digits number of digits
240
-     * @return return int random number
241
-     * @author xHelp Team
242
-     *
243
-     * @access public
244
-     */
245
-    public function genRandNumber($digits = 2)
246
-    {
247
-        $this->initRand();
248
-        $tmp = array();
236
+	/**
237
+	 * Creates a random number with a specified number of $digits
238
+	 *
239
+	 * @param  int    $digits number of digits
240
+	 * @return return int random number
241
+	 * @author xHelp Team
242
+	 *
243
+	 * @access public
244
+	 */
245
+	public function genRandNumber($digits = 2)
246
+	{
247
+		$this->initRand();
248
+		$tmp = array();
249 249
 
250
-        for ($i = 0; $i < $digits; ++$i) {
251
-            $tmp[$i] = (mt_rand() % 9);
252
-        }
250
+		for ($i = 0; $i < $digits; ++$i) {
251
+			$tmp[$i] = (mt_rand() % 9);
252
+		}
253 253
 
254
-        return implode('', $tmp);
255
-    }
254
+		return implode('', $tmp);
255
+	}
256 256
 
257
-    /**
258
-     * Gives the random number generator a seed to start from
259
-     *
260
-     * @return void
261
-     *
262
-     * @access public
263
-     */
264
-    public function initRand()
265
-    {
266
-        static $randCalled = false;
267
-        if (!$randCalled) {
268
-            mt_srand((double)microtime() * 1000000);
269
-            $randCalled = true;
270
-        }
271
-    }
257
+	/**
258
+	 * Gives the random number generator a seed to start from
259
+	 *
260
+	 * @return void
261
+	 *
262
+	 * @access public
263
+	 */
264
+	public function initRand()
265
+	{
266
+		static $randCalled = false;
267
+		if (!$randCalled) {
268
+			mt_srand((double)microtime() * 1000000);
269
+			$randCalled = true;
270
+		}
271
+	}
272 272
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 // ------------------------------------------------------------------------- //
31 31
 
32 32
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
33
-require_once XOOPS_ROOT_PATH . '/kernel/user.php';
34
-require_once XOOPS_ROOT_PATH . '/kernel/group.php';
35
-require_once XOOPS_ROOT_PATH . '/kernel/member.php';
33
+require_once XOOPS_ROOT_PATH.'/kernel/user.php';
34
+require_once XOOPS_ROOT_PATH.'/kernel/group.php';
35
+require_once XOOPS_ROOT_PATH.'/kernel/member.php';
36 36
 
37 37
 /**
38 38
  * XOOPS member handler class.
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 
152 152
         if ($notifyUser) {
153 153
             // send some notifications
154
-            $xoopsMailer =& getMailer();
154
+            $xoopsMailer = & getMailer();
155 155
             $xoopsMailer->useMail();
156
-            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
156
+            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/mail_template');
157 157
             $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
158 158
             $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
159 159
             $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
160 160
             $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
161
-            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
161
+            $xoopsMailer->assign('SITEURL', XOOPS_URL.'/');
162 162
             $xoopsMailer->assign('NAME', $userObj->getVar('name'));
163 163
             $xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
164 164
             $xoopsMailer->setToUsers($userObj);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         if (strlen($name) > 0) {
205 205
             $name = explode(' ', trim($name));
206 206
             if (count($name) > 1) {
207
-                $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
207
+                $basename = strtolower(substr($name[0], 0, 1).$name[count($name) - 1]);
208 208
             } else {
209 209
                 $basename = strtolower($name[0]);
210 210
             }
@@ -221,9 +221,9 @@  discard block
 block discarded – undo
221 221
         while ($i < $count) {
222 222
             $num = $this->genRandNumber();
223 223
             if ($onbasename < 0 && $hasbasename) {
224
-                $names[] = xoops_substr($basename, 0, 58, '') . $num;
224
+                $names[] = xoops_substr($basename, 0, 58, '').$num;
225 225
             } else {
226
-                $names[] = xoops_substr($emailname, 0, 58, '') . $num;
226
+                $names[] = xoops_substr($emailname, 0, 58, '').$num;
227 227
             }
228 228
             $i          = count($names);
229 229
             $onbasename = ~$onbasename;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     {
266 266
         static $randCalled = false;
267 267
         if (!$randCalled) {
268
-            mt_srand((double)microtime() * 1000000);
268
+            mt_srand((double) microtime() * 1000000);
269 269
             $randCalled = true;
270 270
         }
271 271
     }
Please login to merge, or discard this patch.
class/smartdbupdater.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     }
142 142
 
143 143
     /**
144
-     * @param $field
144
+     * @param string $field
145 145
      * @return bool
146 146
      */
147 147
     public function fieldExists($field)
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
     /**
624 624
      * Use to update a table
625 625
      *
626
-     * @param object $table {@link SmartDbTable} that will be updated
626
+     * @param SmartDbTable $table {@link SmartDbTable} that will be updated
627 627
      *
628 628
      * @see SmartDbTable
629 629
      *
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
     /**
726 726
      * @param $module
727 727
      * @param $item
728
-     * @return bool
728
+     * @return false|null
729 729
      */
730 730
     public function upgradeObjectItem($module, $item)
731 731
     {
Please login to merge, or discard this patch.
Indentation   +814 added lines, -814 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
20 20
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
21
-    include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php');
21
+	include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php');
22 22
 }
23 23
 /**
24 24
  * Include the language constants for the SmartObjectDBUpdater
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 global $xoopsConfig;
27 27
 $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
28 28
 if (!file_exists($common_file)) {
29
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
29
+	$common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
30 30
 }
31 31
 include($common_file);
32 32
 
@@ -35,500 +35,500 @@  discard block
 block discarded – undo
35 35
  */
36 36
 class SmartDbTable
37 37
 {
38
-    /**
39
-     * @var string $_name name of the table
40
-     */
41
-    public $_name;
42
-    /**
43
-     * @var string $_structure structure of the table
44
-     */
45
-    public $_structure;
46
-
47
-    /**
48
-     * @var array $_data containing valued of each records to be added
49
-     */
50
-    public $_data;
51
-
52
-    /**
53
-     * @var array $_alteredFields containing fields to be altered
54
-     */
55
-    public $_alteredFields;
56
-
57
-    /**
58
-     * @var array $_newFields containing new fields to be added
59
-     */
60
-    public $_newFields;
61
-
62
-    /**
63
-     * @var array $_droppedFields containing fields to be dropped
64
-     */
65
-    public $_droppedFields;
66
-
67
-    /**
68
-     * @var array $_flagForDrop flag table to drop it
69
-     */
70
-    public $_flagForDrop = false;
71
-
72
-    /**
73
-     * @var array $_updatedFields containing fields which values will be updated
74
-     */
75
-    public $_updatedFields;
76
-
77
-    /**
78
-     * @var array $_updatedFields containing fields which values will be updated
79
-     */ //felix
80
-    public $_updatedWhere;
81
-
82
-    public $_existingFieldsArray = false;
83
-
84
-    /**
85
-     * Constructor
86
-     *
87
-     * @param string $name name of the table
88
-     *
89
-     */
90
-    public function __construct($name)
91
-    {
92
-        $this->_name = $name;
93
-        $this->_data = array();
94
-    }
95
-
96
-    /**
97
-     * Return the table name, prefixed with site table prefix
98
-     *
99
-     * @return string table name
100
-     *
101
-     */
102
-    public function name()
103
-    {
104
-        global $xoopsDB;
105
-
106
-        return $xoopsDB->prefix($this->_name);
107
-    }
108
-
109
-    /**
110
-     * Checks if the table already exists in the database
111
-     *
112
-     * @return bool TRUE if it exists, FALSE if not
113
-     *
114
-     */
115
-    public function exists()
116
-    {
117
-        return smart_TableExists($this->_name);
118
-    }
119
-
120
-    /**
121
-     * @return mixed
122
-     */
123
-    public function getExistingFieldsArray()
124
-    {
125
-        global $xoopsDB;
126
-        $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
127
-        while ($existing_field = $xoopsDB->fetchArray($result)) {
128
-            $fields[$existing_field['Field']] = $existing_field['Type'];
129
-            if ($existing_field['Null'] !== 'YES') {
130
-                $fields[$existing_field['Field']] .= ' NOT NULL';
131
-            }
132
-            if ($existing_field['Extra']) {
133
-                $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
134
-            }
135
-            if (!($existing_field['Default'] === null) && ($existing_field['Default'] || $existing_field['Default'] === '' || $existing_field['Default'] == 0)) {
136
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
137
-            }
138
-        }
139
-
140
-        return $fields;
141
-    }
142
-
143
-    /**
144
-     * @param $field
145
-     * @return bool
146
-     */
147
-    public function fieldExists($field)
148
-    {
149
-        $existingFields = $this->getExistingFieldsArray();
150
-
151
-        return isset($existingFields[$field]);
152
-    }
153
-
154
-    /**
155
-     * Set the table structure
156
-     *
157
-     * Example:
158
-     *
159
-     *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
160
-     *                `date` int(11) NOT NULL default '0',
161
-     *                `status` int(1) NOT NULL default '-1',
162
-     *                `itemid` int(11) NOT NULL default '0',
163
-     *                `uid` int(11) NOT NULL default '0',
164
-     *                `price` float NOT NULL default '0',
165
-     *                `currency` varchar(100) NOT NULL default '',
166
-     *                PRIMARY KEY  (`transactionid`)");
167
-     *
168
-     * @param string $structure table structure
169
-     *
170
-     */
171
-    public function setStructure($structure)
172
-    {
173
-        $this->_structure = $structure;
174
-    }
175
-
176
-    /**
177
-     * Return the table structure
178
-     *
179
-     * @return string table structure
180
-     *
181
-     */
182
-    public function getStructure()
183
-    {
184
-        return sprintf($this->_structure, $this->name());
185
-    }
186
-
187
-    /**
188
-     * Add values of a record to be added
189
-     *
190
-     * @param string $data values of a record
191
-     *
192
-     */
193
-    public function setData($data)
194
-    {
195
-        $this->_data[] = $data;
196
-    }
197
-
198
-    /**
199
-     * Get the data array
200
-     *
201
-     * @return array containing the records values to be added
202
-     *
203
-     */
204
-    public function getData()
205
-    {
206
-        return $this->_data;
207
-    }
208
-
209
-    /**
210
-     * Use to insert data in a table
211
-     *
212
-     * @return bool true if success, false if an error occured
213
-     *
214
-     */
215
-    public function addData()
216
-    {
217
-        global $xoopsDB;
218
-        foreach ($this->getData() as $data) {
219
-            $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
220
-            $ret   = $xoopsDB->query($query);
221
-            if (!$ret) {
222
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
223
-            } else {
224
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
225
-            }
226
-        }
227
-
228
-        return $ret;
229
-    }
230
-
231
-    /**
232
-     * Add a field to be added
233
-     *
234
-     * @param string $name       name of the field
235
-     * @param string $properties properties of the field
236
-     * @param bool   $newname
237
-     * @param bool   $showerror
238
-     */
239
-    public function addAlteredField($name, $properties, $newname = false, $showerror = true)
240
-    {
241
-        $field['name']          = $name;
242
-        $field['properties']    = $properties;
243
-        $field['showerror']     = $showerror;
244
-        $field['newname']       = $newname;
245
-        $this->_alteredFields[] = $field;
246
-    }
247
-    /**
248
-     * Invert values 0 to 1 and 1 to 0
249
-     *
250
-     * @param string $name     name of the field
251
-     * @param        $newValue
252
-     * @param        $oldValue
253
-     * @internal param string $old old propertie
254
-     * @internal param string $new new propertie
255
-     */ //felix
256
-    public function addUpdatedWhere($name, $newValue, $oldValue)
257
-    {
258
-        $field['name']         = $name;
259
-        $field['value']        = $newValue;
260
-        $field['where']        = $oldValue;
261
-        $this->_updatedWhere[] = $field;
262
-    }
263
-
264
-    /**
265
-     * Add new field of a record to be added
266
-     *
267
-     * @param string $name       name of the field
268
-     * @param string $properties properties of the field
269
-     *
270
-     */
271
-    public function addNewField($name, $properties)
272
-    {
273
-        $field['name']       = $name;
274
-        $field['properties'] = $properties;
275
-        $this->_newFields[]  = $field;
276
-    }
277
-
278
-    /**
279
-     * Get fields that need to be altered
280
-     *
281
-     * @return array fields that need to be altered
282
-     *
283
-     */
284
-    public function getAlteredFields()
285
-    {
286
-        return $this->_alteredFields;
287
-    }
288
-
289
-    /**
290
-     * Add field for which the value will be updated
291
-     *
292
-     * @param string $name  name of the field
293
-     * @param string $value value to be set
294
-     *
295
-     */
296
-    public function addUpdatedField($name, $value)
297
-    {
298
-        $field['name']          = $name;
299
-        $field['value']         = $value;
300
-        $this->_updatedFields[] = $field;
301
-    }
302
-
303
-    /**
304
-     * Get new fields to be added
305
-     *
306
-     * @return array fields to be added
307
-     *
308
-     */
309
-    public function getNewFields()
310
-    {
311
-        return $this->_newFields;
312
-    }
313
-
314
-    /**
315
-     * Get fields which values need to be updated
316
-     *
317
-     * @return array fields which values need to be updated
318
-     *
319
-     */
320
-    public function getUpdatedFields()
321
-    {
322
-        return $this->_updatedFields;
323
-    }
324
-    /**
325
-     * Get fields which values need to be updated
326
-     *
327
-     * @return array fields which values need to be updated
328
-     *
329
-     */ //felix
330
-    public function getUpdatedWhere()
331
-    {
332
-        return $this->_updatedWhere;
333
-    }
334
-
335
-    /**
336
-     * Add values of a record to be added
337
-     *
338
-     * @param string $name name of the field
339
-     *
340
-     */
341
-    public function addDroppedField($name)
342
-    {
343
-        $this->_droppedFields[] = $name;
344
-    }
345
-
346
-    /**
347
-     * Get fields that need to be dropped
348
-     *
349
-     * @return array fields that need to be dropped
350
-     *
351
-     */
352
-    public function getDroppedFields()
353
-    {
354
-        return $this->_droppedFields;
355
-    }
356
-
357
-    /**
358
-     * Set the flag to drop the table
359
-     *
360
-     */
361
-    public function setFlagForDrop()
362
-    {
363
-        $this->_flagForDrop = true;
364
-    }
365
-
366
-    /**
367
-     * Use to create a table
368
-     *
369
-     * @return bool true if success, false if an error occured
370
-     *
371
-     */
372
-    public function createTable()
373
-    {
374
-        global $xoopsDB;
375
-        $query = $this->getStructure();
376
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
377
-        //xoops_debug($query);
378
-        $ret = $xoopsDB->query($query);
379
-        if (!$ret) {
380
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
381
-        } else {
382
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
383
-        }
384
-
385
-        return $ret;
386
-    }
387
-
388
-    /**
389
-     * Use to drop a table
390
-     *
391
-     * @return bool true if success, false if an error occured
392
-     *
393
-     */
394
-    public function dropTable()
395
-    {
396
-        global $xoopsDB;
397
-        $query = sprintf('DROP TABLE %s', $this->name());
398
-        $ret   = $xoopsDB->query($query);
399
-        if (!$ret) {
400
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
401
-
402
-            return false;
403
-        } else {
404
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
405
-
406
-            return true;
407
-        }
408
-    }
409
-
410
-    /**
411
-     * Use to alter a table
412
-     *
413
-     * @return bool true if success, false if an error occured
414
-     *
415
-     */
416
-    public function alterTable()
417
-    {
418
-        global $xoopsDB;
419
-        $ret = true;
420
-
421
-        foreach ($this->getAlteredFields() as $alteredField) {
422
-            if (!$alteredField['newname']) {
423
-                $alteredField['newname'] = $alteredField['name'];
424
-            }
425
-
426
-            $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
427
-            $ret   = $ret && $xoopsDB->query($query);
428
-            if ($alteredField['showerror']) {
429
-                if (!$ret) {
430
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
431
-                } else {
432
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
433
-                }
434
-            }
435
-        }
436
-
437
-        return $ret;
438
-    }
439
-
440
-    /**
441
-     * Use to add new fileds in the table
442
-     *
443
-     * @return bool true if success, false if an error occured
444
-     *
445
-     */
446
-    public function addNewFields()
447
-    {
448
-        global $xoopsDB;
449
-        $ret = true;
450
-        foreach ($this->getNewFields() as $newField) {
451
-            $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
452
-            //echo $query;
453
-            $ret = $ret && $xoopsDB->query($query);
454
-            if (!$ret) {
455
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
456
-            } else {
457
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
458
-            }
459
-        }
460
-
461
-        return $ret;
462
-    }
463
-
464
-    /**
465
-     * Use to update fields values
466
-     *
467
-     * @return bool true if success, false if an error occured
468
-     *
469
-     */
470
-    public function updateFieldsValues()
471
-    {
472
-        global $xoopsDB;
473
-        $ret = true;
474
-        foreach ($this->getUpdatedFields() as $updatedField) {
475
-            $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
476
-            $ret   = $ret && $xoopsDB->query($query);
477
-            if (!$ret) {
478
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
479
-            } else {
480
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
481
-            }
482
-        }
483
-
484
-        return $ret;
485
-    }
486
-    /**
487
-     * Use to update fields values
488
-     *
489
-     * @return bool true if success, false if an error occured
490
-     *
491
-     */ //felix
492
-    public function updateWhereValues()
493
-    {
494
-        global $xoopsDB;
495
-        $ret = true;
496
-        foreach ($this->getUpdatedWhere() as $updatedWhere) {
497
-            $query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
498
-            //echo $query."<br>";
499
-            $ret = $ret && $xoopsDB->query($query);
500
-            if (!$ret) {
501
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
502
-            } else {
503
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
504
-            }
505
-        }
506
-
507
-        return $ret;
508
-    }
509
-
510
-    /**
511
-     * Use to drop fields
512
-     *
513
-     * @return bool true if success, false if an error occured
514
-     *
515
-     */
516
-    public function dropFields()
517
-    {
518
-        global $xoopsDB;
519
-        $ret = true;
520
-        foreach ($this->getDroppedFields() as $droppedField) {
521
-            $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
522
-            $ret   = $ret && $xoopsDB->query($query);
523
-            if (!$ret) {
524
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
525
-            } else {
526
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
527
-            }
528
-        }
529
-
530
-        return $ret;
531
-    }
38
+	/**
39
+	 * @var string $_name name of the table
40
+	 */
41
+	public $_name;
42
+	/**
43
+	 * @var string $_structure structure of the table
44
+	 */
45
+	public $_structure;
46
+
47
+	/**
48
+	 * @var array $_data containing valued of each records to be added
49
+	 */
50
+	public $_data;
51
+
52
+	/**
53
+	 * @var array $_alteredFields containing fields to be altered
54
+	 */
55
+	public $_alteredFields;
56
+
57
+	/**
58
+	 * @var array $_newFields containing new fields to be added
59
+	 */
60
+	public $_newFields;
61
+
62
+	/**
63
+	 * @var array $_droppedFields containing fields to be dropped
64
+	 */
65
+	public $_droppedFields;
66
+
67
+	/**
68
+	 * @var array $_flagForDrop flag table to drop it
69
+	 */
70
+	public $_flagForDrop = false;
71
+
72
+	/**
73
+	 * @var array $_updatedFields containing fields which values will be updated
74
+	 */
75
+	public $_updatedFields;
76
+
77
+	/**
78
+	 * @var array $_updatedFields containing fields which values will be updated
79
+	 */ //felix
80
+	public $_updatedWhere;
81
+
82
+	public $_existingFieldsArray = false;
83
+
84
+	/**
85
+	 * Constructor
86
+	 *
87
+	 * @param string $name name of the table
88
+	 *
89
+	 */
90
+	public function __construct($name)
91
+	{
92
+		$this->_name = $name;
93
+		$this->_data = array();
94
+	}
95
+
96
+	/**
97
+	 * Return the table name, prefixed with site table prefix
98
+	 *
99
+	 * @return string table name
100
+	 *
101
+	 */
102
+	public function name()
103
+	{
104
+		global $xoopsDB;
105
+
106
+		return $xoopsDB->prefix($this->_name);
107
+	}
108
+
109
+	/**
110
+	 * Checks if the table already exists in the database
111
+	 *
112
+	 * @return bool TRUE if it exists, FALSE if not
113
+	 *
114
+	 */
115
+	public function exists()
116
+	{
117
+		return smart_TableExists($this->_name);
118
+	}
119
+
120
+	/**
121
+	 * @return mixed
122
+	 */
123
+	public function getExistingFieldsArray()
124
+	{
125
+		global $xoopsDB;
126
+		$result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
127
+		while ($existing_field = $xoopsDB->fetchArray($result)) {
128
+			$fields[$existing_field['Field']] = $existing_field['Type'];
129
+			if ($existing_field['Null'] !== 'YES') {
130
+				$fields[$existing_field['Field']] .= ' NOT NULL';
131
+			}
132
+			if ($existing_field['Extra']) {
133
+				$fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
134
+			}
135
+			if (!($existing_field['Default'] === null) && ($existing_field['Default'] || $existing_field['Default'] === '' || $existing_field['Default'] == 0)) {
136
+				$fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
137
+			}
138
+		}
139
+
140
+		return $fields;
141
+	}
142
+
143
+	/**
144
+	 * @param $field
145
+	 * @return bool
146
+	 */
147
+	public function fieldExists($field)
148
+	{
149
+		$existingFields = $this->getExistingFieldsArray();
150
+
151
+		return isset($existingFields[$field]);
152
+	}
153
+
154
+	/**
155
+	 * Set the table structure
156
+	 *
157
+	 * Example:
158
+	 *
159
+	 *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
160
+	 *                `date` int(11) NOT NULL default '0',
161
+	 *                `status` int(1) NOT NULL default '-1',
162
+	 *                `itemid` int(11) NOT NULL default '0',
163
+	 *                `uid` int(11) NOT NULL default '0',
164
+	 *                `price` float NOT NULL default '0',
165
+	 *                `currency` varchar(100) NOT NULL default '',
166
+	 *                PRIMARY KEY  (`transactionid`)");
167
+	 *
168
+	 * @param string $structure table structure
169
+	 *
170
+	 */
171
+	public function setStructure($structure)
172
+	{
173
+		$this->_structure = $structure;
174
+	}
175
+
176
+	/**
177
+	 * Return the table structure
178
+	 *
179
+	 * @return string table structure
180
+	 *
181
+	 */
182
+	public function getStructure()
183
+	{
184
+		return sprintf($this->_structure, $this->name());
185
+	}
186
+
187
+	/**
188
+	 * Add values of a record to be added
189
+	 *
190
+	 * @param string $data values of a record
191
+	 *
192
+	 */
193
+	public function setData($data)
194
+	{
195
+		$this->_data[] = $data;
196
+	}
197
+
198
+	/**
199
+	 * Get the data array
200
+	 *
201
+	 * @return array containing the records values to be added
202
+	 *
203
+	 */
204
+	public function getData()
205
+	{
206
+		return $this->_data;
207
+	}
208
+
209
+	/**
210
+	 * Use to insert data in a table
211
+	 *
212
+	 * @return bool true if success, false if an error occured
213
+	 *
214
+	 */
215
+	public function addData()
216
+	{
217
+		global $xoopsDB;
218
+		foreach ($this->getData() as $data) {
219
+			$query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
220
+			$ret   = $xoopsDB->query($query);
221
+			if (!$ret) {
222
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
223
+			} else {
224
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
225
+			}
226
+		}
227
+
228
+		return $ret;
229
+	}
230
+
231
+	/**
232
+	 * Add a field to be added
233
+	 *
234
+	 * @param string $name       name of the field
235
+	 * @param string $properties properties of the field
236
+	 * @param bool   $newname
237
+	 * @param bool   $showerror
238
+	 */
239
+	public function addAlteredField($name, $properties, $newname = false, $showerror = true)
240
+	{
241
+		$field['name']          = $name;
242
+		$field['properties']    = $properties;
243
+		$field['showerror']     = $showerror;
244
+		$field['newname']       = $newname;
245
+		$this->_alteredFields[] = $field;
246
+	}
247
+	/**
248
+	 * Invert values 0 to 1 and 1 to 0
249
+	 *
250
+	 * @param string $name     name of the field
251
+	 * @param        $newValue
252
+	 * @param        $oldValue
253
+	 * @internal param string $old old propertie
254
+	 * @internal param string $new new propertie
255
+	 */ //felix
256
+	public function addUpdatedWhere($name, $newValue, $oldValue)
257
+	{
258
+		$field['name']         = $name;
259
+		$field['value']        = $newValue;
260
+		$field['where']        = $oldValue;
261
+		$this->_updatedWhere[] = $field;
262
+	}
263
+
264
+	/**
265
+	 * Add new field of a record to be added
266
+	 *
267
+	 * @param string $name       name of the field
268
+	 * @param string $properties properties of the field
269
+	 *
270
+	 */
271
+	public function addNewField($name, $properties)
272
+	{
273
+		$field['name']       = $name;
274
+		$field['properties'] = $properties;
275
+		$this->_newFields[]  = $field;
276
+	}
277
+
278
+	/**
279
+	 * Get fields that need to be altered
280
+	 *
281
+	 * @return array fields that need to be altered
282
+	 *
283
+	 */
284
+	public function getAlteredFields()
285
+	{
286
+		return $this->_alteredFields;
287
+	}
288
+
289
+	/**
290
+	 * Add field for which the value will be updated
291
+	 *
292
+	 * @param string $name  name of the field
293
+	 * @param string $value value to be set
294
+	 *
295
+	 */
296
+	public function addUpdatedField($name, $value)
297
+	{
298
+		$field['name']          = $name;
299
+		$field['value']         = $value;
300
+		$this->_updatedFields[] = $field;
301
+	}
302
+
303
+	/**
304
+	 * Get new fields to be added
305
+	 *
306
+	 * @return array fields to be added
307
+	 *
308
+	 */
309
+	public function getNewFields()
310
+	{
311
+		return $this->_newFields;
312
+	}
313
+
314
+	/**
315
+	 * Get fields which values need to be updated
316
+	 *
317
+	 * @return array fields which values need to be updated
318
+	 *
319
+	 */
320
+	public function getUpdatedFields()
321
+	{
322
+		return $this->_updatedFields;
323
+	}
324
+	/**
325
+	 * Get fields which values need to be updated
326
+	 *
327
+	 * @return array fields which values need to be updated
328
+	 *
329
+	 */ //felix
330
+	public function getUpdatedWhere()
331
+	{
332
+		return $this->_updatedWhere;
333
+	}
334
+
335
+	/**
336
+	 * Add values of a record to be added
337
+	 *
338
+	 * @param string $name name of the field
339
+	 *
340
+	 */
341
+	public function addDroppedField($name)
342
+	{
343
+		$this->_droppedFields[] = $name;
344
+	}
345
+
346
+	/**
347
+	 * Get fields that need to be dropped
348
+	 *
349
+	 * @return array fields that need to be dropped
350
+	 *
351
+	 */
352
+	public function getDroppedFields()
353
+	{
354
+		return $this->_droppedFields;
355
+	}
356
+
357
+	/**
358
+	 * Set the flag to drop the table
359
+	 *
360
+	 */
361
+	public function setFlagForDrop()
362
+	{
363
+		$this->_flagForDrop = true;
364
+	}
365
+
366
+	/**
367
+	 * Use to create a table
368
+	 *
369
+	 * @return bool true if success, false if an error occured
370
+	 *
371
+	 */
372
+	public function createTable()
373
+	{
374
+		global $xoopsDB;
375
+		$query = $this->getStructure();
376
+		$query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
377
+		//xoops_debug($query);
378
+		$ret = $xoopsDB->query($query);
379
+		if (!$ret) {
380
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
381
+		} else {
382
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
383
+		}
384
+
385
+		return $ret;
386
+	}
387
+
388
+	/**
389
+	 * Use to drop a table
390
+	 *
391
+	 * @return bool true if success, false if an error occured
392
+	 *
393
+	 */
394
+	public function dropTable()
395
+	{
396
+		global $xoopsDB;
397
+		$query = sprintf('DROP TABLE %s', $this->name());
398
+		$ret   = $xoopsDB->query($query);
399
+		if (!$ret) {
400
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
401
+
402
+			return false;
403
+		} else {
404
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
405
+
406
+			return true;
407
+		}
408
+	}
409
+
410
+	/**
411
+	 * Use to alter a table
412
+	 *
413
+	 * @return bool true if success, false if an error occured
414
+	 *
415
+	 */
416
+	public function alterTable()
417
+	{
418
+		global $xoopsDB;
419
+		$ret = true;
420
+
421
+		foreach ($this->getAlteredFields() as $alteredField) {
422
+			if (!$alteredField['newname']) {
423
+				$alteredField['newname'] = $alteredField['name'];
424
+			}
425
+
426
+			$query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
427
+			$ret   = $ret && $xoopsDB->query($query);
428
+			if ($alteredField['showerror']) {
429
+				if (!$ret) {
430
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
431
+				} else {
432
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
433
+				}
434
+			}
435
+		}
436
+
437
+		return $ret;
438
+	}
439
+
440
+	/**
441
+	 * Use to add new fileds in the table
442
+	 *
443
+	 * @return bool true if success, false if an error occured
444
+	 *
445
+	 */
446
+	public function addNewFields()
447
+	{
448
+		global $xoopsDB;
449
+		$ret = true;
450
+		foreach ($this->getNewFields() as $newField) {
451
+			$query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
452
+			//echo $query;
453
+			$ret = $ret && $xoopsDB->query($query);
454
+			if (!$ret) {
455
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
456
+			} else {
457
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
458
+			}
459
+		}
460
+
461
+		return $ret;
462
+	}
463
+
464
+	/**
465
+	 * Use to update fields values
466
+	 *
467
+	 * @return bool true if success, false if an error occured
468
+	 *
469
+	 */
470
+	public function updateFieldsValues()
471
+	{
472
+		global $xoopsDB;
473
+		$ret = true;
474
+		foreach ($this->getUpdatedFields() as $updatedField) {
475
+			$query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
476
+			$ret   = $ret && $xoopsDB->query($query);
477
+			if (!$ret) {
478
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
479
+			} else {
480
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
481
+			}
482
+		}
483
+
484
+		return $ret;
485
+	}
486
+	/**
487
+	 * Use to update fields values
488
+	 *
489
+	 * @return bool true if success, false if an error occured
490
+	 *
491
+	 */ //felix
492
+	public function updateWhereValues()
493
+	{
494
+		global $xoopsDB;
495
+		$ret = true;
496
+		foreach ($this->getUpdatedWhere() as $updatedWhere) {
497
+			$query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
498
+			//echo $query."<br>";
499
+			$ret = $ret && $xoopsDB->query($query);
500
+			if (!$ret) {
501
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
502
+			} else {
503
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
504
+			}
505
+		}
506
+
507
+		return $ret;
508
+	}
509
+
510
+	/**
511
+	 * Use to drop fields
512
+	 *
513
+	 * @return bool true if success, false if an error occured
514
+	 *
515
+	 */
516
+	public function dropFields()
517
+	{
518
+		global $xoopsDB;
519
+		$ret = true;
520
+		foreach ($this->getDroppedFields() as $droppedField) {
521
+			$query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
522
+			$ret   = $ret && $xoopsDB->query($query);
523
+			if (!$ret) {
524
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
525
+			} else {
526
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
527
+			}
528
+		}
529
+
530
+		return $ret;
531
+	}
532 532
 }
533 533
 
534 534
 /**
@@ -542,328 +542,328 @@  discard block
 block discarded – undo
542 542
  */
543 543
 class SmartobjectDbupdater
544 544
 {
545
-    public $_dbTypesArray;
546
-
547
-    /**
548
-     * SmartobjectDbupdater constructor.
549
-     */
550
-    public function __construct()
551
-    {
552
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
553
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
554
-        $this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
555
-        $this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
556
-        $this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
557
-        $this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
558
-        $this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
559
-        $this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
560
-        $this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
561
-        $this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
562
-        $this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
563
-        $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
564
-        $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
565
-        $this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
566
-        $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
567
-        $this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
568
-        $this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
569
-        $this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
570
-    }
571
-
572
-    /**
573
-     * Use to execute a general query
574
-     *
575
-     * @param string $query   query that will be executed
576
-     * @param string $goodmsg message displayed on success
577
-     * @param string $badmsg  message displayed on error
578
-     *
579
-     * @return bool true if success, false if an error occured
580
-     *
581
-     */
582
-    public function runQuery($query, $goodmsg, $badmsg)
583
-    {
584
-        global $xoopsDB;
585
-        $ret = $xoopsDB->query($query);
586
-        if (!$ret) {
587
-            echo "&nbsp;&nbsp;$badmsg<br>";
588
-
589
-            return false;
590
-        } else {
591
-            echo "&nbsp;&nbsp;$goodmsg<br>";
592
-
593
-            return true;
594
-        }
595
-    }
596
-
597
-    /**
598
-     * Use to rename a table
599
-     *
600
-     * @param string $from name of the table to rename
601
-     * @param string $to   new name of the renamed table
602
-     *
603
-     * @return bool true if success, false if an error occured
604
-     */
605
-    public function renameTable($from, $to)
606
-    {
607
-        global $xoopsDB;
608
-        $from  = $xoopsDB->prefix($from);
609
-        $to    = $xoopsDB->prefix($to);
610
-        $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
611
-        $ret   = $xoopsDB->query($query);
612
-        if (!$ret) {
613
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
614
-
615
-            return false;
616
-        } else {
617
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
618
-
619
-            return true;
620
-        }
621
-    }
622
-
623
-    /**
624
-     * Use to update a table
625
-     *
626
-     * @param object $table {@link SmartDbTable} that will be updated
627
-     *
628
-     * @see SmartDbTable
629
-     *
630
-     * @return bool true if success, false if an error occured
631
-     */
632
-    public function updateTable($table)
633
-    {
634
-        global $xoopsDB;
635
-        $ret = true;
636
-        // If table has a structure, create the table
637
-        if ($table->getStructure()) {
638
-            $ret = $table->createTable() && $ret;
639
-        }
640
-        // If table is flag for drop, drop it
641
-        if ($table->_flagForDrop) {
642
-            $ret = $table->dropTable() && $ret;
643
-        }
644
-        // If table has data, insert it
645
-        if ($table->getData()) {
646
-            $ret = $table->addData() && $ret;
647
-        }
648
-        // If table has new fields to be added, add them
649
-        if ($table->getNewFields()) {
650
-            $ret = $table->addNewFields() && $ret;
651
-        }
652
-        // If table has altered field, alter the table
653
-        if ($table->getAlteredFields()) {
654
-            $ret = $table->alterTable() && $ret;
655
-        }
656
-        // If table has updated field values, update the table
657
-        if ($table->getUpdatedFields()) {
658
-            $ret = $table->updateFieldsValues($table) && $ret;
659
-        }
660
-        // If table has dropped field, alter the table
661
-        if ($table->getDroppedFields()) {
662
-            $ret = $table->dropFields($table) && $ret;
663
-        }
664
-        //felix
665
-        // If table has updated field values, update the table
666
-        if ($table->getUpdatedWhere()) {
667
-            $ret = $table->UpdateWhereValues($table) && $ret;
668
-        }
669
-
670
-        return $ret;
671
-    }
672
-
673
-    /**
674
-     * @param $module
675
-     * @param $item
676
-     */
677
-    public function automaticUpgrade($module, $item)
678
-    {
679
-        if (is_array($item)) {
680
-            foreach ($item as $v) {
681
-                $this->upgradeObjectItem($module, $v);
682
-            }
683
-        } else {
684
-            $this->upgradeObjectItem($module, $item);
685
-        }
686
-    }
687
-
688
-    /**
689
-     * @param $var
690
-     * @return string
691
-     */
692
-    public function getFieldTypeFromVar($var)
693
-    {
694
-        $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
695
-
696
-        return $ret;
697
-    }
698
-
699
-    /**
700
-     * @param         $var
701
-     * @param  bool   $key
702
-     * @return string
703
-     */
704
-    public function getFieldDefaultFromVar($var, $key = false)
705
-    {
706
-        if ($var['value']) {
707
-            return $var['value'];
708
-        } else {
709
-            if (in_array($var['data_type'], array(
710
-                XOBJ_DTYPE_INT,
711
-                XOBJ_DTYPE_STIME,
712
-                XOBJ_DTYPE_MTIME,
713
-                XOBJ_DTYPE_LTIME,
714
-                XOBJ_DTYPE_TIME_ONLY,
715
-                XOBJ_DTYPE_URLLINK,
716
-                XOBJ_DTYPE_FILE
717
-            ))) {
718
-                return '0';
719
-            } else {
720
-                return '';
721
-            }
722
-        }
723
-    }
724
-
725
-    /**
726
-     * @param $module
727
-     * @param $item
728
-     * @return bool
729
-     */
730
-    public function upgradeObjectItem($module, $item)
731
-    {
732
-        $moduleHandler = xoops_getModuleHandler($item, $module);
733
-        if (!$moduleHandler) {
734
-            return false;
735
-        }
736
-
737
-        $table      = new SmartDbTable($module . '_' . $item);
738
-        $object     = $moduleHandler->create();
739
-        $objectVars = $object->getVars();
740
-
741
-        if (!$table->exists()) {
742
-            // table was never created, let's do it
743
-            $structure = '';
744
-            foreach ($objectVars as $key => $var) {
745
-                if ($var['persistent']) {
746
-                    $type = $this->getFieldTypeFromVar($var);
747
-                    if ($key == $moduleHandler->keyName) {
748
-                        $extra = 'auto_increment';
749
-                    } else {
750
-                        $default = $this->getFieldDefaultFromVar($var);
751
-                        $extra   = "default '$default'
545
+	public $_dbTypesArray;
546
+
547
+	/**
548
+	 * SmartobjectDbupdater constructor.
549
+	 */
550
+	public function __construct()
551
+	{
552
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
553
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
554
+		$this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
555
+		$this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
556
+		$this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
557
+		$this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
558
+		$this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
559
+		$this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
560
+		$this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
561
+		$this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
562
+		$this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
563
+		$this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
564
+		$this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
565
+		$this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
566
+		$this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
567
+		$this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
568
+		$this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
569
+		$this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
570
+	}
571
+
572
+	/**
573
+	 * Use to execute a general query
574
+	 *
575
+	 * @param string $query   query that will be executed
576
+	 * @param string $goodmsg message displayed on success
577
+	 * @param string $badmsg  message displayed on error
578
+	 *
579
+	 * @return bool true if success, false if an error occured
580
+	 *
581
+	 */
582
+	public function runQuery($query, $goodmsg, $badmsg)
583
+	{
584
+		global $xoopsDB;
585
+		$ret = $xoopsDB->query($query);
586
+		if (!$ret) {
587
+			echo "&nbsp;&nbsp;$badmsg<br>";
588
+
589
+			return false;
590
+		} else {
591
+			echo "&nbsp;&nbsp;$goodmsg<br>";
592
+
593
+			return true;
594
+		}
595
+	}
596
+
597
+	/**
598
+	 * Use to rename a table
599
+	 *
600
+	 * @param string $from name of the table to rename
601
+	 * @param string $to   new name of the renamed table
602
+	 *
603
+	 * @return bool true if success, false if an error occured
604
+	 */
605
+	public function renameTable($from, $to)
606
+	{
607
+		global $xoopsDB;
608
+		$from  = $xoopsDB->prefix($from);
609
+		$to    = $xoopsDB->prefix($to);
610
+		$query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
611
+		$ret   = $xoopsDB->query($query);
612
+		if (!$ret) {
613
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
614
+
615
+			return false;
616
+		} else {
617
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
618
+
619
+			return true;
620
+		}
621
+	}
622
+
623
+	/**
624
+	 * Use to update a table
625
+	 *
626
+	 * @param object $table {@link SmartDbTable} that will be updated
627
+	 *
628
+	 * @see SmartDbTable
629
+	 *
630
+	 * @return bool true if success, false if an error occured
631
+	 */
632
+	public function updateTable($table)
633
+	{
634
+		global $xoopsDB;
635
+		$ret = true;
636
+		// If table has a structure, create the table
637
+		if ($table->getStructure()) {
638
+			$ret = $table->createTable() && $ret;
639
+		}
640
+		// If table is flag for drop, drop it
641
+		if ($table->_flagForDrop) {
642
+			$ret = $table->dropTable() && $ret;
643
+		}
644
+		// If table has data, insert it
645
+		if ($table->getData()) {
646
+			$ret = $table->addData() && $ret;
647
+		}
648
+		// If table has new fields to be added, add them
649
+		if ($table->getNewFields()) {
650
+			$ret = $table->addNewFields() && $ret;
651
+		}
652
+		// If table has altered field, alter the table
653
+		if ($table->getAlteredFields()) {
654
+			$ret = $table->alterTable() && $ret;
655
+		}
656
+		// If table has updated field values, update the table
657
+		if ($table->getUpdatedFields()) {
658
+			$ret = $table->updateFieldsValues($table) && $ret;
659
+		}
660
+		// If table has dropped field, alter the table
661
+		if ($table->getDroppedFields()) {
662
+			$ret = $table->dropFields($table) && $ret;
663
+		}
664
+		//felix
665
+		// If table has updated field values, update the table
666
+		if ($table->getUpdatedWhere()) {
667
+			$ret = $table->UpdateWhereValues($table) && $ret;
668
+		}
669
+
670
+		return $ret;
671
+	}
672
+
673
+	/**
674
+	 * @param $module
675
+	 * @param $item
676
+	 */
677
+	public function automaticUpgrade($module, $item)
678
+	{
679
+		if (is_array($item)) {
680
+			foreach ($item as $v) {
681
+				$this->upgradeObjectItem($module, $v);
682
+			}
683
+		} else {
684
+			$this->upgradeObjectItem($module, $item);
685
+		}
686
+	}
687
+
688
+	/**
689
+	 * @param $var
690
+	 * @return string
691
+	 */
692
+	public function getFieldTypeFromVar($var)
693
+	{
694
+		$ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
695
+
696
+		return $ret;
697
+	}
698
+
699
+	/**
700
+	 * @param         $var
701
+	 * @param  bool   $key
702
+	 * @return string
703
+	 */
704
+	public function getFieldDefaultFromVar($var, $key = false)
705
+	{
706
+		if ($var['value']) {
707
+			return $var['value'];
708
+		} else {
709
+			if (in_array($var['data_type'], array(
710
+				XOBJ_DTYPE_INT,
711
+				XOBJ_DTYPE_STIME,
712
+				XOBJ_DTYPE_MTIME,
713
+				XOBJ_DTYPE_LTIME,
714
+				XOBJ_DTYPE_TIME_ONLY,
715
+				XOBJ_DTYPE_URLLINK,
716
+				XOBJ_DTYPE_FILE
717
+			))) {
718
+				return '0';
719
+			} else {
720
+				return '';
721
+			}
722
+		}
723
+	}
724
+
725
+	/**
726
+	 * @param $module
727
+	 * @param $item
728
+	 * @return bool
729
+	 */
730
+	public function upgradeObjectItem($module, $item)
731
+	{
732
+		$moduleHandler = xoops_getModuleHandler($item, $module);
733
+		if (!$moduleHandler) {
734
+			return false;
735
+		}
736
+
737
+		$table      = new SmartDbTable($module . '_' . $item);
738
+		$object     = $moduleHandler->create();
739
+		$objectVars = $object->getVars();
740
+
741
+		if (!$table->exists()) {
742
+			// table was never created, let's do it
743
+			$structure = '';
744
+			foreach ($objectVars as $key => $var) {
745
+				if ($var['persistent']) {
746
+					$type = $this->getFieldTypeFromVar($var);
747
+					if ($key == $moduleHandler->keyName) {
748
+						$extra = 'auto_increment';
749
+					} else {
750
+						$default = $this->getFieldDefaultFromVar($var);
751
+						$extra   = "default '$default'
752 752
 ";
753
-                    }
754
-                    $structure .= "`$key` $type not null $extra,
753
+					}
754
+					$structure .= "`$key` $type not null $extra,
755 755
 ";
756
-                }
757
-            }
758
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
756
+				}
757
+			}
758
+			$structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
759 759
 ';
760
-            $table->setStructure($structure);
761
-            if (!$this->updateTable($table)) {
762
-                /**
763
-                 * @todo trap the errors
764
-                 */
765
-            }
766
-        } else {
767
-            $existingFieldsArray = $table->getExistingFieldsArray();
768
-            foreach ($objectVars as $key => $var) {
769
-                if ($var['persistent']) {
770
-                    if (!isset($existingFieldsArray[$key])) {
771
-                        // the fiels does not exist, let's create it
772
-                        $type    = $this->getFieldTypeFromVar($var);
773
-                        $default = $this->getFieldDefaultFromVar($var);
774
-                        $table->addNewField($key, "$type not null default '$default'");
775
-                    } else {
776
-                        // if field already exists, let's check if the definition is correct
777
-                        $definition = strtolower($existingFieldsArray[$key]);
778
-                        $type       = $this->getFieldTypeFromVar($var);
779
-                        if ($key == $moduleHandler->keyName) {
780
-                            $extra = 'auto_increment';
781
-                        } else {
782
-                            $default = $this->getFieldDefaultFromVar($var, $key);
783
-                            $extra   = "default '$default'";
784
-                        }
785
-                        $actual_definition = "$type not null $extra";
786
-                        if ($definition != $actual_definition) {
787
-                            $table->addAlteredField($key, $actual_definition);
788
-                        }
789
-                    }
790
-                }
791
-            }
792
-
793
-            // check to see if there are some unused fields left in the table
794
-            foreach ($existingFieldsArray as $key => $v) {
795
-                if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
796
-                    $table->addDroppedField($key);
797
-                }
798
-            }
799
-
800
-            if (!$this->updateTable($table)) {
801
-                /**
802
-                 * @todo trap the errors
803
-                 */
804
-            }
805
-        }
806
-    }
807
-
808
-    /**
809
-     * @param $module
810
-     * @return bool
811
-     */
812
-    public function moduleUpgrade(&$module)
813
-    {
814
-        $dirname = $module->getVar('dirname');
815
-
816
-        ob_start();
817
-
818
-        $table = new SmartDbTable($dirname . '_meta');
819
-        if (!$table->exists()) {
820
-            $table->setStructure("
760
+			$table->setStructure($structure);
761
+			if (!$this->updateTable($table)) {
762
+				/**
763
+				 * @todo trap the errors
764
+				 */
765
+			}
766
+		} else {
767
+			$existingFieldsArray = $table->getExistingFieldsArray();
768
+			foreach ($objectVars as $key => $var) {
769
+				if ($var['persistent']) {
770
+					if (!isset($existingFieldsArray[$key])) {
771
+						// the fiels does not exist, let's create it
772
+						$type    = $this->getFieldTypeFromVar($var);
773
+						$default = $this->getFieldDefaultFromVar($var);
774
+						$table->addNewField($key, "$type not null default '$default'");
775
+					} else {
776
+						// if field already exists, let's check if the definition is correct
777
+						$definition = strtolower($existingFieldsArray[$key]);
778
+						$type       = $this->getFieldTypeFromVar($var);
779
+						if ($key == $moduleHandler->keyName) {
780
+							$extra = 'auto_increment';
781
+						} else {
782
+							$default = $this->getFieldDefaultFromVar($var, $key);
783
+							$extra   = "default '$default'";
784
+						}
785
+						$actual_definition = "$type not null $extra";
786
+						if ($definition != $actual_definition) {
787
+							$table->addAlteredField($key, $actual_definition);
788
+						}
789
+					}
790
+				}
791
+			}
792
+
793
+			// check to see if there are some unused fields left in the table
794
+			foreach ($existingFieldsArray as $key => $v) {
795
+				if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
796
+					$table->addDroppedField($key);
797
+				}
798
+			}
799
+
800
+			if (!$this->updateTable($table)) {
801
+				/**
802
+				 * @todo trap the errors
803
+				 */
804
+			}
805
+		}
806
+	}
807
+
808
+	/**
809
+	 * @param $module
810
+	 * @return bool
811
+	 */
812
+	public function moduleUpgrade(&$module)
813
+	{
814
+		$dirname = $module->getVar('dirname');
815
+
816
+		ob_start();
817
+
818
+		$table = new SmartDbTable($dirname . '_meta');
819
+		if (!$table->exists()) {
820
+			$table->setStructure("
821 821
               `metakey` varchar(50) NOT NULL default '',
822 822
               `metavalue` varchar(255) NOT NULL default '',
823 823
               PRIMARY KEY (`metakey`)");
824
-            $table->setData("'version',0");
825
-            if (!$this->updateTable($table)) {
826
-                /**
827
-                 * @todo trap the errors
828
-                 */
829
-            }
830
-        }
831
-
832
-        $dbVersion = smart_GetMeta('version', $dirname);
833
-        if (!$dbVersion) {
834
-            $dbVersion = 0;
835
-        }
836
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
837
-        echo 'Database version: ' . $dbVersion . '<br>';
838
-        echo 'New database version: ' . $newDbVersion . '<br>';
839
-
840
-        if ($newDbVersion > $dbVersion) {
841
-            for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
842
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
843
-                if (function_exists($upgrade_function)) {
844
-                    $upgrade_function();
845
-                }
846
-            }
847
-        }
848
-
849
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
850
-
851
-        // if there is a function to execute for this DB version, let's do it
852
-        //$function_
853
-
854
-        $module_info = smart_getModuleInfo($dirname);
855
-        $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
856
-
857
-        echo '</code>';
858
-
859
-        $feedback = ob_get_clean();
860
-        if (method_exists($module, 'setMessage')) {
861
-            $module->setMessage($feedback);
862
-        } else {
863
-            echo $feedback;
864
-        }
865
-        smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
866
-
867
-        return true;
868
-    }
824
+			$table->setData("'version',0");
825
+			if (!$this->updateTable($table)) {
826
+				/**
827
+				 * @todo trap the errors
828
+				 */
829
+			}
830
+		}
831
+
832
+		$dbVersion = smart_GetMeta('version', $dirname);
833
+		if (!$dbVersion) {
834
+			$dbVersion = 0;
835
+		}
836
+		$newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
837
+		echo 'Database version: ' . $dbVersion . '<br>';
838
+		echo 'New database version: ' . $newDbVersion . '<br>';
839
+
840
+		if ($newDbVersion > $dbVersion) {
841
+			for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
842
+				$upgrade_function = $dirname . '_db_upgrade_' . $i;
843
+				if (function_exists($upgrade_function)) {
844
+					$upgrade_function();
845
+				}
846
+			}
847
+		}
848
+
849
+		echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
850
+
851
+		// if there is a function to execute for this DB version, let's do it
852
+		//$function_
853
+
854
+		$module_info = smart_getModuleInfo($dirname);
855
+		$this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
856
+
857
+		echo '</code>';
858
+
859
+		$feedback = ob_get_clean();
860
+		if (method_exists($module, 'setMessage')) {
861
+			$module->setMessage($feedback);
862
+		} else {
863
+			echo $feedback;
864
+		}
865
+		smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
866
+
867
+		return true;
868
+	}
869 869
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
  */
19 19
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
20 20
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
21
-    include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php');
21
+    include_once(XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php');
22 22
 }
23 23
 /**
24 24
  * Include the language constants for the SmartObjectDBUpdater
25 25
  */
26 26
 global $xoopsConfig;
27
-$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
27
+$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php';
28 28
 if (!file_exists($common_file)) {
29
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
29
+    $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php';
30 30
 }
31 31
 include($common_file);
32 32
 
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
     public function getExistingFieldsArray()
124 124
     {
125 125
         global $xoopsDB;
126
-        $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
126
+        $result = $xoopsDB->query('SHOW COLUMNS FROM '.$this->name());
127 127
         while ($existing_field = $xoopsDB->fetchArray($result)) {
128 128
             $fields[$existing_field['Field']] = $existing_field['Type'];
129 129
             if ($existing_field['Null'] !== 'YES') {
130 130
                 $fields[$existing_field['Field']] .= ' NOT NULL';
131 131
             }
132 132
             if ($existing_field['Extra']) {
133
-                $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
133
+                $fields[$existing_field['Field']] .= ' '.$existing_field['Extra'];
134 134
             }
135 135
             if (!($existing_field['Default'] === null) && ($existing_field['Default'] || $existing_field['Default'] === '' || $existing_field['Default'] == 0)) {
136
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
136
+                $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'";
137 137
             }
138 138
         }
139 139
 
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
             $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
220 220
             $ret   = $xoopsDB->query($query);
221 221
             if (!$ret) {
222
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
222
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>';
223 223
             } else {
224
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
224
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>';
225 225
             }
226 226
         }
227 227
 
@@ -373,13 +373,13 @@  discard block
 block discarded – undo
373 373
     {
374 374
         global $xoopsDB;
375 375
         $query = $this->getStructure();
376
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
376
+        $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
377 377
         //xoops_debug($query);
378 378
         $ret = $xoopsDB->query($query);
379 379
         if (!$ret) {
380
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
380
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
381 381
         } else {
382
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
382
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>';
383 383
         }
384 384
 
385 385
         return $ret;
@@ -397,11 +397,11 @@  discard block
 block discarded – undo
397 397
         $query = sprintf('DROP TABLE %s', $this->name());
398 398
         $ret   = $xoopsDB->query($query);
399 399
         if (!$ret) {
400
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
400
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
401 401
 
402 402
             return false;
403 403
         } else {
404
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
404
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>';
405 405
 
406 406
             return true;
407 407
         }
@@ -427,9 +427,9 @@  discard block
 block discarded – undo
427 427
             $ret   = $ret && $xoopsDB->query($query);
428 428
             if ($alteredField['showerror']) {
429 429
                 if (!$ret) {
430
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
430
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>';
431 431
                 } else {
432
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
432
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>';
433 433
                 }
434 434
             }
435 435
         }
@@ -452,9 +452,9 @@  discard block
 block discarded – undo
452 452
             //echo $query;
453 453
             $ret = $ret && $xoopsDB->query($query);
454 454
             if (!$ret) {
455
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
455
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>';
456 456
             } else {
457
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
457
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>';
458 458
             }
459 459
         }
460 460
 
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
             $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
476 476
             $ret   = $ret && $xoopsDB->query($query);
477 477
             if (!$ret) {
478
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
478
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
479 479
             } else {
480
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
480
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
481 481
             }
482 482
         }
483 483
 
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
             //echo $query."<br>";
499 499
             $ret = $ret && $xoopsDB->query($query);
500 500
             if (!$ret) {
501
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
501
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
502 502
             } else {
503
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
503
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
504 504
             }
505 505
         }
506 506
 
@@ -521,9 +521,9 @@  discard block
 block discarded – undo
521 521
             $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
522 522
             $ret   = $ret && $xoopsDB->query($query);
523 523
             if (!$ret) {
524
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
524
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>';
525 525
             } else {
526
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
526
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>';
527 527
             }
528 528
         }
529 529
 
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
         $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
611 611
         $ret   = $xoopsDB->query($query);
612 612
         if (!$ret) {
613
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
613
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>';
614 614
 
615 615
             return false;
616 616
         } else {
617
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
617
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>';
618 618
 
619 619
             return true;
620 620
         }
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             return false;
735 735
         }
736 736
 
737
-        $table      = new SmartDbTable($module . '_' . $item);
737
+        $table      = new SmartDbTable($module.'_'.$item);
738 738
         $object     = $moduleHandler->create();
739 739
         $objectVars = $object->getVars();
740 740
 
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 ";
756 756
                 }
757 757
             }
758
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
758
+            $structure .= 'PRIMARY KEY  (`'.$moduleHandler->keyName.'`)
759 759
 ';
760 760
             $table->setStructure($structure);
761 761
             if (!$this->updateTable($table)) {
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 
816 816
         ob_start();
817 817
 
818
-        $table = new SmartDbTable($dirname . '_meta');
818
+        $table = new SmartDbTable($dirname.'_meta');
819 819
         if (!$table->exists()) {
820 820
             $table->setStructure("
821 821
               `metakey` varchar(50) NOT NULL default '',
@@ -833,20 +833,20 @@  discard block
 block discarded – undo
833 833
         if (!$dbVersion) {
834 834
             $dbVersion = 0;
835 835
         }
836
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
837
-        echo 'Database version: ' . $dbVersion . '<br>';
838
-        echo 'New database version: ' . $newDbVersion . '<br>';
836
+        $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0;
837
+        echo 'Database version: '.$dbVersion.'<br>';
838
+        echo 'New database version: '.$newDbVersion.'<br>';
839 839
 
840 840
         if ($newDbVersion > $dbVersion) {
841 841
             for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
842
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
842
+                $upgrade_function = $dirname.'_db_upgrade_'.$i;
843 843
                 if (function_exists($upgrade_function)) {
844 844
                     $upgrade_function();
845 845
                 }
846 846
             }
847 847
         }
848 848
 
849
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
849
+        echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>';
850 850
 
851 851
         // if there is a function to execute for this DB version, let's do it
852 852
         //$function_
Please login to merge, or discard this patch.
class/smartexport.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     /**
198 198
      * @param $val
199 199
      * @param $separator
200
-     * @param $trimFunction
200
+     * @param false|string $trimFunction
201 201
      * @return mixed|string
202 202
      */
203 203
     public function valToCsvHelper($val, $separator, $trimFunction)
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
     }
249 249
 
250 250
     /**
251
-     * @param $content
251
+     * @param string $content
252 252
      */
253 253
     public function saveExportFile($content)
254 254
     {
Please login to merge, or discard this patch.
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -19,110 +19,110 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class SmartObjectExport
21 21
 {
22
-    public $handler;
23
-    public $criteria;
24
-    public $fields;
25
-    public $format;
26
-    public $filename;
27
-    public $filepath;
28
-    public $options;
29
-    public $outputMethods = false;
30
-    public $notDisplayFields;
22
+	public $handler;
23
+	public $criteria;
24
+	public $fields;
25
+	public $format;
26
+	public $filename;
27
+	public $filepath;
28
+	public $options;
29
+	public $outputMethods = false;
30
+	public $notDisplayFields;
31 31
 
32
-    /**
33
-     * Constructor
34
-     *
35
-     * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export
36
-     * @param CriteriaElement      $criteria      containing the criteria of the query fetching the objects to be exported
37
-     * @param array|bool  $fields        fields to be exported. If FALSE then all fields will be exported
38
-     * @param bool|string $filename      name of the file to be created
39
-     * @param bool|string $filepath      path where the file will be saved
40
-     * @param string      $format        format of the ouputed export. Currently only supports CSV
41
-     * @param array|bool  $options       options of the format to be exported in
42
-     */
43
-    public function __construct(SmartPersistableObjectHandler $objectHandler, CriteriaElement $criteria = null, $fields = false, $filename = false, $filepath = false, $format = 'csv', $options = false)
44
-    {
45
-        $this->handler          = $objectHandler;
46
-        $this->criteria         = $criteria;
47
-        $this->fields           = $fields;
48
-        $this->filename         = $filename;
49
-        $this->format           = $format;
50
-        $this->options          = $options;
51
-        $this->notDisplayFields = false;
52
-    }
32
+	/**
33
+	 * Constructor
34
+	 *
35
+	 * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export
36
+	 * @param CriteriaElement      $criteria      containing the criteria of the query fetching the objects to be exported
37
+	 * @param array|bool  $fields        fields to be exported. If FALSE then all fields will be exported
38
+	 * @param bool|string $filename      name of the file to be created
39
+	 * @param bool|string $filepath      path where the file will be saved
40
+	 * @param string      $format        format of the ouputed export. Currently only supports CSV
41
+	 * @param array|bool  $options       options of the format to be exported in
42
+	 */
43
+	public function __construct(SmartPersistableObjectHandler $objectHandler, CriteriaElement $criteria = null, $fields = false, $filename = false, $filepath = false, $format = 'csv', $options = false)
44
+	{
45
+		$this->handler          = $objectHandler;
46
+		$this->criteria         = $criteria;
47
+		$this->fields           = $fields;
48
+		$this->filename         = $filename;
49
+		$this->format           = $format;
50
+		$this->options          = $options;
51
+		$this->notDisplayFields = false;
52
+	}
53 53
 
54
-    /**
55
-     * Renders the export
56
-     * @param $filename
57
-     */
58
-    public function render($filename)
59
-    {
60
-        $this->filename = $filename;
54
+	/**
55
+	 * Renders the export
56
+	 * @param $filename
57
+	 */
58
+	public function render($filename)
59
+	{
60
+		$this->filename = $filename;
61 61
 
62
-        $objects        = $this->handler->getObjects($this->criteria);
63
-        $rows           = array();
64
-        $columnsHeaders = array();
65
-        $firstObject    = true;
66
-        foreach ($objects as $object) {
67
-            $row = array();
68
-            foreach ($object->vars as $key => $var) {
69
-                if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) {
70
-                    if ($this->outputMethods && isset($this->outputMethods[$key]) && method_exists($object, $this->outputMethods[$key])) {
71
-                        $method    = $this->outputMethods[$key];
72
-                        $row[$key] = $object->$method();
73
-                    } else {
74
-                        $row[$key] = $object->getVar($key);
75
-                    }
76
-                    if ($firstObject) {
77
-                        // then set the columnsHeaders array as well
78
-                        $columnsHeaders[$key] = $var['form_caption'];
79
-                    }
80
-                }
81
-            }
82
-            $firstObject = false;
83
-            $rows[]      = $row;
84
-            unset($row);
85
-        }
86
-        $data                   = array();
87
-        $data['rows']           = $rows;
88
-        $data['columnsHeaders'] = $columnsHeaders;
89
-        $smartExportRenderer    = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options);
90
-        $smartExportRenderer->execute();
91
-    }
62
+		$objects        = $this->handler->getObjects($this->criteria);
63
+		$rows           = array();
64
+		$columnsHeaders = array();
65
+		$firstObject    = true;
66
+		foreach ($objects as $object) {
67
+			$row = array();
68
+			foreach ($object->vars as $key => $var) {
69
+				if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) {
70
+					if ($this->outputMethods && isset($this->outputMethods[$key]) && method_exists($object, $this->outputMethods[$key])) {
71
+						$method    = $this->outputMethods[$key];
72
+						$row[$key] = $object->$method();
73
+					} else {
74
+						$row[$key] = $object->getVar($key);
75
+					}
76
+					if ($firstObject) {
77
+						// then set the columnsHeaders array as well
78
+						$columnsHeaders[$key] = $var['form_caption'];
79
+					}
80
+				}
81
+			}
82
+			$firstObject = false;
83
+			$rows[]      = $row;
84
+			unset($row);
85
+		}
86
+		$data                   = array();
87
+		$data['rows']           = $rows;
88
+		$data['columnsHeaders'] = $columnsHeaders;
89
+		$smartExportRenderer    = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options);
90
+		$smartExportRenderer->execute();
91
+	}
92 92
 
93
-    /**
94
-     * Set an array contaning the alternate methods to use instead of the default getVar()
95
-     *
96
-     * $outputMethods array example: 'uid' => 'getUserName'...
97
-     * @param $outputMethods
98
-     */
99
-    public function setOuptutMethods($outputMethods)
100
-    {
101
-        $this->outputMethods = $outputMethods;
102
-    }
93
+	/**
94
+	 * Set an array contaning the alternate methods to use instead of the default getVar()
95
+	 *
96
+	 * $outputMethods array example: 'uid' => 'getUserName'...
97
+	 * @param $outputMethods
98
+	 */
99
+	public function setOuptutMethods($outputMethods)
100
+	{
101
+		$this->outputMethods = $outputMethods;
102
+	}
103 103
 
104
-    /*
104
+	/*
105 105
      * Set an array of fields that we don't want in export
106 106
      */
107
-    /**
108
-     * @param $fields
109
-     */
110
-    public function setNotDisplayFields($fields)
111
-    {
112
-        if (!$this->notDisplayFields) {
113
-            if (is_array($fields)) {
114
-                $this->notDisplayFields = $fields;
115
-            } else {
116
-                $this->notDisplayFields = array($fields);
117
-            }
118
-        } else {
119
-            if (is_array($fields)) {
120
-                $this->notDisplayFields = array_merge($this->notDisplayFields, $fields);
121
-            } else {
122
-                $this->notDisplayFields[] = $fields;
123
-            }
124
-        }
125
-    }
107
+	/**
108
+	 * @param $fields
109
+	 */
110
+	public function setNotDisplayFields($fields)
111
+	{
112
+		if (!$this->notDisplayFields) {
113
+			if (is_array($fields)) {
114
+				$this->notDisplayFields = $fields;
115
+			} else {
116
+				$this->notDisplayFields = array($fields);
117
+			}
118
+		} else {
119
+			if (is_array($fields)) {
120
+				$this->notDisplayFields = array_merge($this->notDisplayFields, $fields);
121
+			} else {
122
+				$this->notDisplayFields[] = $fields;
123
+			}
124
+		}
125
+	}
126 126
 }
127 127
 
128 128
 /**
@@ -136,181 +136,181 @@  discard block
 block discarded – undo
136 136
  */
137 137
 class SmartExportRenderer
138 138
 {
139
-    public $data;
140
-    public $format;
141
-    public $filename;
142
-    public $filepath;
143
-    public $options;
139
+	public $data;
140
+	public $format;
141
+	public $filename;
142
+	public $filepath;
143
+	public $options;
144 144
 
145
-    /**
146
-     * Constructor
147
-     *
148
-     * @param array       $data     contains the data to be exported
149
-     * @param bool|string $filename name of the file in which the exported data will be saved
150
-     * @param bool|string $filepath path where the file will be saved
151
-     * @param string      $format   format of the ouputed export. Currently only supports CSV
152
-     * @param array       $options  options of the format to be exported in
153
-     */
154
-    public function __construct($data, $filename = false, $filepath = false, $format = 'csv', $options = array('separator' => ';'))
155
-    {
156
-        $this->data     = $data;
157
-        $this->format   = $format;
158
-        $this->filename = $filename;
159
-        $this->filepath = $filepath;
160
-        $this->options  = $options;
161
-    }
145
+	/**
146
+	 * Constructor
147
+	 *
148
+	 * @param array       $data     contains the data to be exported
149
+	 * @param bool|string $filename name of the file in which the exported data will be saved
150
+	 * @param bool|string $filepath path where the file will be saved
151
+	 * @param string      $format   format of the ouputed export. Currently only supports CSV
152
+	 * @param array       $options  options of the format to be exported in
153
+	 */
154
+	public function __construct($data, $filename = false, $filepath = false, $format = 'csv', $options = array('separator' => ';'))
155
+	{
156
+		$this->data     = $data;
157
+		$this->format   = $format;
158
+		$this->filename = $filename;
159
+		$this->filepath = $filepath;
160
+		$this->options  = $options;
161
+	}
162 162
 
163
-    /**
164
-     * @param         $dataArray
165
-     * @param         $separator
166
-     * @param  string $trim
167
-     * @param  bool   $removeEmptyLines
168
-     * @return string
169
-     */
170
-    public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true)
171
-    {
172
-        if (!is_array($dataArray) || empty($dataArray)) {
173
-            return '';
174
-        }
175
-        switch ($trim) {
176
-            case 'none':
177
-                $trimFunction = false;
178
-                break;
179
-            case 'left':
180
-                $trimFunction = 'ltrim';
181
-                break;
182
-            case 'right':
183
-                $trimFunction = 'rtrim';
184
-                break;
185
-            default: //'both':
186
-                $trimFunction = 'trim';
187
-                break;
188
-        }
189
-        $ret = array();
190
-        foreach ($dataArray as $key => $field) {
191
-            $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction);
192
-        }
163
+	/**
164
+	 * @param         $dataArray
165
+	 * @param         $separator
166
+	 * @param  string $trim
167
+	 * @param  bool   $removeEmptyLines
168
+	 * @return string
169
+	 */
170
+	public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true)
171
+	{
172
+		if (!is_array($dataArray) || empty($dataArray)) {
173
+			return '';
174
+		}
175
+		switch ($trim) {
176
+			case 'none':
177
+				$trimFunction = false;
178
+				break;
179
+			case 'left':
180
+				$trimFunction = 'ltrim';
181
+				break;
182
+			case 'right':
183
+				$trimFunction = 'rtrim';
184
+				break;
185
+			default: //'both':
186
+				$trimFunction = 'trim';
187
+				break;
188
+		}
189
+		$ret = array();
190
+		foreach ($dataArray as $key => $field) {
191
+			$ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction);
192
+		}
193 193
 
194
-        return implode($separator, $ret);
195
-    }
194
+		return implode($separator, $ret);
195
+	}
196 196
 
197
-    /**
198
-     * @param $val
199
-     * @param $separator
200
-     * @param $trimFunction
201
-     * @return mixed|string
202
-     */
203
-    public function valToCsvHelper($val, $separator, $trimFunction)
204
-    {
205
-        if ($trimFunction) {
206
-            $val = $trimFunction ($val);
207
-        }
208
-        //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it.
209
-        $needQuote = false;
210
-        do {
211
-            if (strpos($val, '"') !== false) {
212
-                $val       = str_replace('"', '""', $val);
213
-                $needQuote = true;
214
-                break;
215
-            }
216
-            if (strpos($val, $separator) !== false) {
217
-                $needQuote = true;
218
-                break;
219
-            }
220
-            if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac
221
-                $needQuote = true;
222
-                break;
223
-            }
224
-        } while (false);
225
-        if ($needQuote) {
226
-            $val = '"' . $val . '"';
227
-        }
197
+	/**
198
+	 * @param $val
199
+	 * @param $separator
200
+	 * @param $trimFunction
201
+	 * @return mixed|string
202
+	 */
203
+	public function valToCsvHelper($val, $separator, $trimFunction)
204
+	{
205
+		if ($trimFunction) {
206
+			$val = $trimFunction ($val);
207
+		}
208
+		//If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it.
209
+		$needQuote = false;
210
+		do {
211
+			if (strpos($val, '"') !== false) {
212
+				$val       = str_replace('"', '""', $val);
213
+				$needQuote = true;
214
+				break;
215
+			}
216
+			if (strpos($val, $separator) !== false) {
217
+				$needQuote = true;
218
+				break;
219
+			}
220
+			if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac
221
+				$needQuote = true;
222
+				break;
223
+			}
224
+		} while (false);
225
+		if ($needQuote) {
226
+			$val = '"' . $val . '"';
227
+		}
228 228
 
229
-        return $val;
230
-    }
229
+		return $val;
230
+	}
231 231
 
232
-    public function execute()
233
-    {
234
-        $exportFileData = '';
232
+	public function execute()
233
+	{
234
+		$exportFileData = '';
235 235
 
236
-        switch ($this->format) {
237
-            case 'csv':
238
-                $separator = isset($this->options['separator']) ? $this->options['separator'] : ';';
239
-                $firstRow  = implode($separator, $this->data['columnsHeaders']);
240
-                $exportFileData .= $firstRow . "\r\n";
236
+		switch ($this->format) {
237
+			case 'csv':
238
+				$separator = isset($this->options['separator']) ? $this->options['separator'] : ';';
239
+				$firstRow  = implode($separator, $this->data['columnsHeaders']);
240
+				$exportFileData .= $firstRow . "\r\n";
241 241
 
242
-                foreach ($this->data['rows'] as $cols) {
243
-                    $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n";
244
-                }
245
-                break;
246
-        }
247
-        $this->saveExportFile($exportFileData);
248
-    }
242
+				foreach ($this->data['rows'] as $cols) {
243
+					$exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n";
244
+				}
245
+				break;
246
+		}
247
+		$this->saveExportFile($exportFileData);
248
+	}
249 249
 
250
-    /**
251
-     * @param $content
252
-     */
253
-    public function saveExportFile($content)
254
-    {
255
-        switch ($this->format) {
256
-            case 'csv':
257
-                $this->saveCsv($content);
258
-                break;
259
-        }
260
-    }
250
+	/**
251
+	 * @param $content
252
+	 */
253
+	public function saveExportFile($content)
254
+	{
255
+		switch ($this->format) {
256
+			case 'csv':
257
+				$this->saveCsv($content);
258
+				break;
259
+		}
260
+	}
261 261
 
262
-    /**
263
-     * @param $content
264
-     */
265
-    public function saveCsv($content)
266
-    {
267
-        if (!$this->filepath) {
268
-            $this->filepath = XOOPS_UPLOAD_PATH . '/';
269
-        }
270
-        if (!$this->filename) {
271
-            $this->filename .= time();
272
-            $this->filename .= '.csv';
273
-        }
262
+	/**
263
+	 * @param $content
264
+	 */
265
+	public function saveCsv($content)
266
+	{
267
+		if (!$this->filepath) {
268
+			$this->filepath = XOOPS_UPLOAD_PATH . '/';
269
+		}
270
+		if (!$this->filename) {
271
+			$this->filename .= time();
272
+			$this->filename .= '.csv';
273
+		}
274 274
 
275
-        $fullFileName = $this->filepath . $this->filename;
275
+		$fullFileName = $this->filepath . $this->filename;
276 276
 
277
-        if (!$handle = fopen($fullFileName, 'a+')) {
278
-            trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING);
279
-        } elseif (fwrite($handle, $content) === false) {
280
-            trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING);
281
-        } else {
282
-            $mimeType  = 'text/csv';
283
-            $file      = strrev($this->filename);
284
-            $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--'))));
285
-            if ($temp_name === '') {
286
-                $file_name = $this->filename;
287
-            } else {
288
-                $file_name = $temp_name;
289
-            }
290
-            $fullFileName = $this->filepath . stripslashes(trim($this->filename));
277
+		if (!$handle = fopen($fullFileName, 'a+')) {
278
+			trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING);
279
+		} elseif (fwrite($handle, $content) === false) {
280
+			trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING);
281
+		} else {
282
+			$mimeType  = 'text/csv';
283
+			$file      = strrev($this->filename);
284
+			$temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--'))));
285
+			if ($temp_name === '') {
286
+				$file_name = $this->filename;
287
+			} else {
288
+				$file_name = $temp_name;
289
+			}
290
+			$fullFileName = $this->filepath . stripslashes(trim($this->filename));
291 291
 
292
-            if (ini_get('zlib.output_compression')) {
293
-                ini_set('zlib.output_compression', 'Off');
294
-            }
292
+			if (ini_get('zlib.output_compression')) {
293
+				ini_set('zlib.output_compression', 'Off');
294
+			}
295 295
 
296
-            header('Pragma: public');
297
-            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
298
-            header('Cache-Control: private', false);
299
-            header('Content-Transfer-Encoding: binary');
300
-            if (isset($mimeType)) {
301
-                header('Content-Type: ' . $mimeType);
302
-            }
296
+			header('Pragma: public');
297
+			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
298
+			header('Cache-Control: private', false);
299
+			header('Content-Transfer-Encoding: binary');
300
+			if (isset($mimeType)) {
301
+				header('Content-Type: ' . $mimeType);
302
+			}
303 303
 
304
-            header('Content-Disposition: attachment; filename=' . $file_name);
304
+			header('Content-Disposition: attachment; filename=' . $file_name);
305 305
 
306
-            if (isset($mimeType) && false !== strpos($mimeType, 'text/')) {
307
-                $fp = fopen($fullFileName, 'r');
308
-            } else {
309
-                $fp = fopen($fullFileName, 'rb');
310
-            }
311
-            fpassthru($fp);
312
-            exit();
313
-        }
314
-        fclose($handle);
315
-    }
306
+			if (isset($mimeType) && false !== strpos($mimeType, 'text/')) {
307
+				$fp = fopen($fullFileName, 'r');
308
+			} else {
309
+				$fp = fopen($fullFileName, 'rb');
310
+			}
311
+			fpassthru($fp);
312
+			exit();
313
+		}
314
+		fclose($handle);
315
+	}
316 316
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
     public function valToCsvHelper($val, $separator, $trimFunction)
204 204
     {
205 205
         if ($trimFunction) {
206
-            $val = $trimFunction ($val);
206
+            $val = $trimFunction($val);
207 207
         }
208 208
         //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it.
209 209
         $needQuote = false;
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
             }
224 224
         } while (false);
225 225
         if ($needQuote) {
226
-            $val = '"' . $val . '"';
226
+            $val = '"'.$val.'"';
227 227
         }
228 228
 
229 229
         return $val;
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
             case 'csv':
238 238
                 $separator = isset($this->options['separator']) ? $this->options['separator'] : ';';
239 239
                 $firstRow  = implode($separator, $this->data['columnsHeaders']);
240
-                $exportFileData .= $firstRow . "\r\n";
240
+                $exportFileData .= $firstRow."\r\n";
241 241
 
242 242
                 foreach ($this->data['rows'] as $cols) {
243
-                    $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n";
243
+                    $exportFileData .= $this->arrayToCsvString($cols, $separator)."\r\n";
244 244
                 }
245 245
                 break;
246 246
         }
@@ -265,19 +265,19 @@  discard block
 block discarded – undo
265 265
     public function saveCsv($content)
266 266
     {
267 267
         if (!$this->filepath) {
268
-            $this->filepath = XOOPS_UPLOAD_PATH . '/';
268
+            $this->filepath = XOOPS_UPLOAD_PATH.'/';
269 269
         }
270 270
         if (!$this->filename) {
271 271
             $this->filename .= time();
272 272
             $this->filename .= '.csv';
273 273
         }
274 274
 
275
-        $fullFileName = $this->filepath . $this->filename;
275
+        $fullFileName = $this->filepath.$this->filename;
276 276
 
277 277
         if (!$handle = fopen($fullFileName, 'a+')) {
278
-            trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING);
278
+            trigger_error('Unable to open '.$fullFileName, E_USER_WARNING);
279 279
         } elseif (fwrite($handle, $content) === false) {
280
-            trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING);
280
+            trigger_error('Unable to write in '.$fullFileName, E_USER_WARNING);
281 281
         } else {
282 282
             $mimeType  = 'text/csv';
283 283
             $file      = strrev($this->filename);
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             } else {
288 288
                 $file_name = $temp_name;
289 289
             }
290
-            $fullFileName = $this->filepath . stripslashes(trim($this->filename));
290
+            $fullFileName = $this->filepath.stripslashes(trim($this->filename));
291 291
 
292 292
             if (ini_get('zlib.output_compression')) {
293 293
                 ini_set('zlib.output_compression', 'Off');
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
             header('Cache-Control: private', false);
299 299
             header('Content-Transfer-Encoding: binary');
300 300
             if (isset($mimeType)) {
301
-                header('Content-Type: ' . $mimeType);
301
+                header('Content-Type: '.$mimeType);
302 302
             }
303 303
 
304
-            header('Content-Disposition: attachment; filename=' . $file_name);
304
+            header('Content-Disposition: attachment; filename='.$file_name);
305 305
 
306 306
             if (isset($mimeType) && false !== strpos($mimeType, 'text/')) {
307 307
                 $fp = fopen($fullFileName, 'r');
Please login to merge, or discard this patch.
class/smartmetagen.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     }
166 166
 
167 167
     /**
168
-     * @param $keywords
168
+     * @param string|boolean $keywords
169 169
      */
170 170
     public function setKeywords($keywords)
171 171
     {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
     }
174 174
 
175 175
     /**
176
-     * @param $categoryPath
176
+     * @param boolean $categoryPath
177 177
      */
178 178
     public function setCategoryPath($categoryPath)
179 179
     {
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     }
183 183
 
184 184
     /**
185
-     * @param $description
185
+     * @param boolean $description
186 186
      */
187 187
     public function setDescription($description)
188 188
     {
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
     }
243 243
 
244 244
     /**
245
-     * @param $text
246
-     * @param $minChar
245
+     * @param string $text
246
+     * @param integer $minChar
247 247
      * @return array
248 248
      */
249 249
     public function findMetaKeywords($text, $minChar)
Please login to merge, or discard this patch.
Indentation   +348 added lines, -348 removed lines patch added patch discarded remove patch
@@ -18,320 +18,320 @@  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
-        $pattern = array(
88
-            '/%09/', // Tab
89
-            '/%20/', // Space
90
-            '/%21/', // !
91
-            '/%22/', // "
92
-            '/%23/', // #
93
-            '/%25/', // %
94
-            '/%26/', // &
95
-            '/%27/', // '
96
-            '/%28/', // (
97
-            '/%29/', // )
98
-            '/%2C/', // ,
99
-            '/%2F/', // /
100
-            '/%3A/', // :
101
-            '/%3B/', // ;
102
-            '/%3C/', // <
103
-            '/%3D/', // =
104
-            '/%3E/', // >
105
-            '/%3F/', // ?
106
-            '/%40/', // @
107
-            '/%5B/', // [
108
-            '/%5C/', // \
109
-            '/%5D/', // ]
110
-            '/%5E/', // ^
111
-            '/%7B/', // {
112
-            '/%7C/', // |
113
-            '/%7D/', // }
114
-            '/%7E/', // ~
115
-            "/\./" // .
116
-        );
117
-        $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
118
-        $title   = preg_replace($pattern, $rep_pat, $title);
119
-
120
-        // Transformation des caract�res accentu�s
121
-        $pattern = array(
122
-            '/%B0/', // °
123
-            '/%E8/', // è
124
-            '/%E9/', // é
125
-            '/%EA/', // ê
126
-            '/%EB/', // ë
127
-            '/%E7/', // ç
128
-            '/%E0/', // à
129
-            '/%E2/', // â
130
-            '/%E4/', // ä
131
-            '/%EE/', // î
132
-            '/%EF/', // ï
133
-            '/%F9/', // ù
134
-            '/%FC/', // ü
135
-            '/%FB/', // û
136
-            '/%F4/', // ô
137
-            '/%F6/', // ö
138
-        );        
139
-        $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o');
140
-        $title   = preg_replace($pattern, $rep_pat, $title);
141
-
142
-        $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
143
-        $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau
144
-        $title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
145
-
146
-        if (count($title) > 0) {
147
-            if ($withExt) {
148
-                $title .= '.html';
149
-            }
150
-
151
-            return $title;
152
-        } else {
153
-            return '';
154
-        }
155
-    }
156
-
157
-    /**
158
-     * @param $document
159
-     * @return mixed
160
-     */
161
-    public function html2text($document)
162
-    {
163
-        return smart_html2text($document);
164
-    }
165
-
166
-    /**
167
-     * @param $title
168
-     */
169
-    public function setTitle($title)
170
-    {
171
-        global $xoopsModule, $xoopsModuleConfig;
172
-        $this->_title          = $this->html2text($title);
173
-        $this->_title          = $this->purifyText($this->_title);
174
-        $this->_original_title = $this->_title;
175
-
176
-        $moduleName = $xoopsModule->getVar('name');
177
-
178
-        $titleTag = array();
179
-
180
-        $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true;
181
-
182
-        if ($moduleName && $show_mod_name_breadcrumb) {
183
-            $titleTag['module'] = $moduleName;
184
-        }
185
-
186
-        if (isset($this->_title) && ($this->_title !== '') && (strtoupper($this->_title) != strtoupper($moduleName))) {
187
-            $titleTag['title'] = $this->_title;
188
-        }
189
-
190
-        if (isset($this->_categoryPath) && ($this->_categoryPath !== '')) {
191
-            $titleTag['category'] = $this->_categoryPath;
192
-        }
193
-
194
-        $ret = isset($titleTag['title']) ? $titleTag['title'] : '';
195
-
196
-        if (isset($titleTag['category']) && $titleTag['category'] !== '') {
197
-            if ($ret !== '') {
198
-                $ret .= ' - ';
199
-            }
200
-            $ret .= $titleTag['category'];
201
-        }
202
-        if (isset($titleTag['module']) && $titleTag['module'] !== '') {
203
-            if ($ret !== '') {
204
-                $ret .= ' - ';
205
-            }
206
-            $ret .= $titleTag['module'];
207
-        }
208
-        $this->_title = $ret;
209
-    }
210
-
211
-    /**
212
-     * @param $keywords
213
-     */
214
-    public function setKeywords($keywords)
215
-    {
216
-        $this->_keywords = $keywords;
217
-    }
218
-
219
-    /**
220
-     * @param $categoryPath
221
-     */
222
-    public function setCategoryPath($categoryPath)
223
-    {
224
-        $categoryPath        = $this->html2text($categoryPath);
225
-        $this->_categoryPath = $categoryPath;
226
-    }
227
-
228
-    /**
229
-     * @param $description
230
-     */
231
-    public function setDescription($description)
232
-    {
233
-        if (!$description) {
234
-            global $xoopsModuleConfig;
235
-            if (isset($xoopsModuleConfig['module_meta_description'])) {
236
-                $description = $xoopsModuleConfig['module_meta_description'];
237
-            }
238
-        }
239
-
240
-        $description = $this->html2text($description);
241
-        $description = $this->purifyText($description);
242
-
243
-        $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description);
244
-        $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description);
245
-        $description = preg_replace('/[ ]* [ ]*/', ' ', $description);
246
-        $description = stripslashes($description);
247
-
248
-        $this->_description      = $description;
249
-        $this->_meta_description = $this->createMetaDescription();
250
-    }
251
-
252
-    public function createTitleTag()
253
-    {
254
-    }
255
-
256
-    /**
257
-     * @param               $text
258
-     * @param  bool         $keyword
259
-     * @return mixed|string
260
-     */
261
-    public function purifyText($text, $keyword = false)
262
-    {
263
-        return smart_purifyText($text, $keyword);
264
-    }
265
-
266
-    /**
267
-     * @param  int    $maxWords
268
-     * @return string
269
-     */
270
-    public function createMetaDescription($maxWords = 100)
271
-    {
272
-        $words = array();
273
-        $words = explode(' ', $this->_description);
274
-
275
-        // Only keep $maxWords words
276
-        $newWords = array();
277
-        $i        = 0;
278
-
279
-        while ($i < $maxWords - 1 && $i < count($words)) {
280
-            $newWords[] = $words[$i];
281
-            ++$i;
282
-        }
283
-        $ret = implode(' ', $newWords);
284
-
285
-        return $ret;
286
-    }
287
-
288
-    /**
289
-     * @param $text
290
-     * @param $minChar
291
-     * @return array
292
-     */
293
-    public function findMetaKeywords($text, $minChar)
294
-    {
295
-        $keywords = array();
296
-
297
-        $text = $this->purifyText($text);
298
-        $text = $this->html2text($text);
299
-
300
-        $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text);
301
-        $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text);
302
-        $text = preg_replace('/[ ]* [ ]*/', ' ', $text);
303
-        $text = stripslashes($text);
304
-        $text =
305
-
306
-        $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY);
307
-
308
-        foreach ($originalKeywords as $originalKeyword) {
309
-            $secondRoundKeywords = explode("'", $originalKeyword);
310
-            foreach ($secondRoundKeywords as $secondRoundKeyword) {
311
-                if (strlen($secondRoundKeyword) >= $minChar) {
312
-                    if (!in_array($secondRoundKeyword, $keywords)) {
313
-                        $keywords[] = trim($secondRoundKeyword);
314
-                    }
315
-                }
316
-            }
317
-        }
318
-
319
-        return $keywords;
320
-    }
321
-
322
-    /**
323
-     * @return string
324
-     */
325
-    public function createMetaKeywords()
326
-    {
327
-        global $xoopsModuleConfig;
328
-        $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
329
-        if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] !== '') {
330
-            $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']);
331
-            $keywords       = array_merge($keywords, $moduleKeywords);
332
-        }
333
-
334
-        /* 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
+		$pattern = array(
88
+			'/%09/', // Tab
89
+			'/%20/', // Space
90
+			'/%21/', // !
91
+			'/%22/', // "
92
+			'/%23/', // #
93
+			'/%25/', // %
94
+			'/%26/', // &
95
+			'/%27/', // '
96
+			'/%28/', // (
97
+			'/%29/', // )
98
+			'/%2C/', // ,
99
+			'/%2F/', // /
100
+			'/%3A/', // :
101
+			'/%3B/', // ;
102
+			'/%3C/', // <
103
+			'/%3D/', // =
104
+			'/%3E/', // >
105
+			'/%3F/', // ?
106
+			'/%40/', // @
107
+			'/%5B/', // [
108
+			'/%5C/', // \
109
+			'/%5D/', // ]
110
+			'/%5E/', // ^
111
+			'/%7B/', // {
112
+			'/%7C/', // |
113
+			'/%7D/', // }
114
+			'/%7E/', // ~
115
+			"/\./" // .
116
+		);
117
+		$rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
118
+		$title   = preg_replace($pattern, $rep_pat, $title);
119
+
120
+		// Transformation des caract�res accentu�s
121
+		$pattern = array(
122
+			'/%B0/', // °
123
+			'/%E8/', // è
124
+			'/%E9/', // é
125
+			'/%EA/', // ê
126
+			'/%EB/', // ë
127
+			'/%E7/', // ç
128
+			'/%E0/', // à
129
+			'/%E2/', // â
130
+			'/%E4/', // ä
131
+			'/%EE/', // î
132
+			'/%EF/', // ï
133
+			'/%F9/', // ù
134
+			'/%FC/', // ü
135
+			'/%FB/', // û
136
+			'/%F4/', // ô
137
+			'/%F6/', // ö
138
+		);        
139
+		$rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o');
140
+		$title   = preg_replace($pattern, $rep_pat, $title);
141
+
142
+		$tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
143
+		$tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau
144
+		$title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
145
+
146
+		if (count($title) > 0) {
147
+			if ($withExt) {
148
+				$title .= '.html';
149
+			}
150
+
151
+			return $title;
152
+		} else {
153
+			return '';
154
+		}
155
+	}
156
+
157
+	/**
158
+	 * @param $document
159
+	 * @return mixed
160
+	 */
161
+	public function html2text($document)
162
+	{
163
+		return smart_html2text($document);
164
+	}
165
+
166
+	/**
167
+	 * @param $title
168
+	 */
169
+	public function setTitle($title)
170
+	{
171
+		global $xoopsModule, $xoopsModuleConfig;
172
+		$this->_title          = $this->html2text($title);
173
+		$this->_title          = $this->purifyText($this->_title);
174
+		$this->_original_title = $this->_title;
175
+
176
+		$moduleName = $xoopsModule->getVar('name');
177
+
178
+		$titleTag = array();
179
+
180
+		$show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true;
181
+
182
+		if ($moduleName && $show_mod_name_breadcrumb) {
183
+			$titleTag['module'] = $moduleName;
184
+		}
185
+
186
+		if (isset($this->_title) && ($this->_title !== '') && (strtoupper($this->_title) != strtoupper($moduleName))) {
187
+			$titleTag['title'] = $this->_title;
188
+		}
189
+
190
+		if (isset($this->_categoryPath) && ($this->_categoryPath !== '')) {
191
+			$titleTag['category'] = $this->_categoryPath;
192
+		}
193
+
194
+		$ret = isset($titleTag['title']) ? $titleTag['title'] : '';
195
+
196
+		if (isset($titleTag['category']) && $titleTag['category'] !== '') {
197
+			if ($ret !== '') {
198
+				$ret .= ' - ';
199
+			}
200
+			$ret .= $titleTag['category'];
201
+		}
202
+		if (isset($titleTag['module']) && $titleTag['module'] !== '') {
203
+			if ($ret !== '') {
204
+				$ret .= ' - ';
205
+			}
206
+			$ret .= $titleTag['module'];
207
+		}
208
+		$this->_title = $ret;
209
+	}
210
+
211
+	/**
212
+	 * @param $keywords
213
+	 */
214
+	public function setKeywords($keywords)
215
+	{
216
+		$this->_keywords = $keywords;
217
+	}
218
+
219
+	/**
220
+	 * @param $categoryPath
221
+	 */
222
+	public function setCategoryPath($categoryPath)
223
+	{
224
+		$categoryPath        = $this->html2text($categoryPath);
225
+		$this->_categoryPath = $categoryPath;
226
+	}
227
+
228
+	/**
229
+	 * @param $description
230
+	 */
231
+	public function setDescription($description)
232
+	{
233
+		if (!$description) {
234
+			global $xoopsModuleConfig;
235
+			if (isset($xoopsModuleConfig['module_meta_description'])) {
236
+				$description = $xoopsModuleConfig['module_meta_description'];
237
+			}
238
+		}
239
+
240
+		$description = $this->html2text($description);
241
+		$description = $this->purifyText($description);
242
+
243
+		$description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description);
244
+		$description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description);
245
+		$description = preg_replace('/[ ]* [ ]*/', ' ', $description);
246
+		$description = stripslashes($description);
247
+
248
+		$this->_description      = $description;
249
+		$this->_meta_description = $this->createMetaDescription();
250
+	}
251
+
252
+	public function createTitleTag()
253
+	{
254
+	}
255
+
256
+	/**
257
+	 * @param               $text
258
+	 * @param  bool         $keyword
259
+	 * @return mixed|string
260
+	 */
261
+	public function purifyText($text, $keyword = false)
262
+	{
263
+		return smart_purifyText($text, $keyword);
264
+	}
265
+
266
+	/**
267
+	 * @param  int    $maxWords
268
+	 * @return string
269
+	 */
270
+	public function createMetaDescription($maxWords = 100)
271
+	{
272
+		$words = array();
273
+		$words = explode(' ', $this->_description);
274
+
275
+		// Only keep $maxWords words
276
+		$newWords = array();
277
+		$i        = 0;
278
+
279
+		while ($i < $maxWords - 1 && $i < count($words)) {
280
+			$newWords[] = $words[$i];
281
+			++$i;
282
+		}
283
+		$ret = implode(' ', $newWords);
284
+
285
+		return $ret;
286
+	}
287
+
288
+	/**
289
+	 * @param $text
290
+	 * @param $minChar
291
+	 * @return array
292
+	 */
293
+	public function findMetaKeywords($text, $minChar)
294
+	{
295
+		$keywords = array();
296
+
297
+		$text = $this->purifyText($text);
298
+		$text = $this->html2text($text);
299
+
300
+		$text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text);
301
+		$text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text);
302
+		$text = preg_replace('/[ ]* [ ]*/', ' ', $text);
303
+		$text = stripslashes($text);
304
+		$text =
305
+
306
+		$originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY);
307
+
308
+		foreach ($originalKeywords as $originalKeyword) {
309
+			$secondRoundKeywords = explode("'", $originalKeyword);
310
+			foreach ($secondRoundKeywords as $secondRoundKeyword) {
311
+				if (strlen($secondRoundKeyword) >= $minChar) {
312
+					if (!in_array($secondRoundKeyword, $keywords)) {
313
+						$keywords[] = trim($secondRoundKeyword);
314
+					}
315
+				}
316
+			}
317
+		}
318
+
319
+		return $keywords;
320
+	}
321
+
322
+	/**
323
+	 * @return string
324
+	 */
325
+	public function createMetaKeywords()
326
+	{
327
+		global $xoopsModuleConfig;
328
+		$keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
329
+		if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] !== '') {
330
+			$moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']);
331
+			$keywords       = array_merge($keywords, $moduleKeywords);
332
+		}
333
+
334
+		/* Commenting this out as it may cause problem on XOOPS ML websites
335 335
          $return_keywords = array();
336 336
 
337 337
          // Cleaning for duplicate keywords
@@ -341,43 +341,43 @@  discard block
 block discarded – undo
341 341
          }
342 342
          }*/
343 343
 
344
-        // Only take the first 90 keywords
345
-        $newKeywords = array();
346
-        $i           = 0;
347
-        while ($i < 90 - 1 && isset($keywords[$i])) {
348
-            $newKeywords[] = $keywords[$i];
349
-            ++$i;
350
-        }
351
-        $ret = implode(', ', $newKeywords);
352
-
353
-        return $ret;
354
-    }
355
-
356
-    public function autoBuildMeta_keywords()
357
-    {
358
-    }
359
-
360
-    public function buildAutoMetaTags()
361
-    {
362
-        global $xoopsModule, $xoopsModuleConfig;
363
-
364
-        $this->_keywords         = $this->createMetaKeywords();
365
-        $this->_meta_description = $this->createMetaDescription();
366
-        $this->_title            = $this->createTitleTag();
367
-    }
368
-
369
-    public function createMetaTags()
370
-    {
371
-        global $xoopsTpl, $xoTheme;
372
-
373
-        if (is_object($xoTheme)) {
374
-            $xoTheme->addMeta('meta', 'keywords', $this->_keywords);
375
-            $xoTheme->addMeta('meta', 'description', $this->_description);
376
-            $xoTheme->addMeta('meta', 'title', $this->_title);
377
-        } else {
378
-            $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords);
379
-            $xoopsTpl->assign('xoops_meta_description', $this->_description);
380
-        }
381
-        $xoopsTpl->assign('xoops_pagetitle', $this->_title);
382
-    }
344
+		// Only take the first 90 keywords
345
+		$newKeywords = array();
346
+		$i           = 0;
347
+		while ($i < 90 - 1 && isset($keywords[$i])) {
348
+			$newKeywords[] = $keywords[$i];
349
+			++$i;
350
+		}
351
+		$ret = implode(', ', $newKeywords);
352
+
353
+		return $ret;
354
+	}
355
+
356
+	public function autoBuildMeta_keywords()
357
+	{
358
+	}
359
+
360
+	public function buildAutoMetaTags()
361
+	{
362
+		global $xoopsModule, $xoopsModuleConfig;
363
+
364
+		$this->_keywords         = $this->createMetaKeywords();
365
+		$this->_meta_description = $this->createMetaDescription();
366
+		$this->_title            = $this->createTitleTag();
367
+	}
368
+
369
+	public function createMetaTags()
370
+	{
371
+		global $xoopsTpl, $xoTheme;
372
+
373
+		if (is_object($xoTheme)) {
374
+			$xoTheme->addMeta('meta', 'keywords', $this->_keywords);
375
+			$xoTheme->addMeta('meta', 'description', $this->_description);
376
+			$xoTheme->addMeta('meta', 'title', $this->_title);
377
+		} else {
378
+			$xoopsTpl->assign('xoops_meta_keywords', $this->_keywords);
379
+			$xoopsTpl->assign('xoops_meta_description', $this->_description);
380
+		}
381
+		$xoopsTpl->assign('xoops_pagetitle', $this->_title);
382
+	}
383 383
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
     public function createMetaKeywords()
326 326
     {
327 327
         global $xoopsModuleConfig;
328
-        $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
328
+        $keywords = $this->findMetaKeywords($this->_original_title.' '.$this->_description, $this->_minChar);
329 329
         if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] !== '') {
330 330
             $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']);
331 331
             $keywords       = array_merge($keywords, $moduleKeywords);
Please login to merge, or discard this patch.
class/smartobjectlink.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
      * @access public
62 62
      * @param  string $key    key of the object's variable to be returned
63 63
      * @param  string $format format to use for the output
64
-     * @return mixed  formatted value of the variable
64
+     * @return integer  formatted value of the variable
65 65
      */
66 66
     public function getVar($key, $format = 's')
67 67
     {
Please login to merge, or discard this patch.
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -35,164 +35,164 @@  discard block
 block discarded – undo
35 35
  */
36 36
 class SmartobjectLink extends SmartObject
37 37
 {
38
-    /**
39
-     * SmartobjectLink constructor.
40
-     */
41
-    public function __construct()
42
-    {
43
-        $this->initVar('linkid', XOBJ_DTYPE_INT, '', true);
44
-        $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false);
45
-        $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC);
46
-        $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true);
47
-        $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true);
48
-        $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC);
49
-        $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true);
50
-        $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true);
51
-        $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true);
52
-        $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true);
53
-        $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC);
54
-        $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC);
55
-        $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true);
56
-    }
57
-
58
-    /**
59
-     * returns a specific variable for the object in a proper format
60
-     *
61
-     * @access public
62
-     * @param  string $key    key of the object's variable to be returned
63
-     * @param  string $format format to use for the output
64
-     * @return mixed  formatted value of the variable
65
-     */
66
-    public function getVar($key, $format = 's')
67
-    {
68
-        if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) {
69
-            //            return call_user_func(array($this, $key));
70
-            return $this->{$key}();
71
-        }
72
-
73
-        return parent::getVar($key, $format);
74
-    }
75
-
76
-    /**
77
-     * @return string
78
-     */
79
-    public function from_uid()
80
-    {
81
-        $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true);
82
-
83
-        return $ret;
84
-    }
85
-
86
-    /**
87
-     * @param  bool   $withContact
88
-     * @return string
89
-     */
90
-    public function to_uid($withContact = false)
91
-    {
92
-        $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true);
93
-
94
-        return $ret;
95
-    }
96
-
97
-    /**
98
-     * @return string
99
-     */
100
-    public function date()
101
-    {
102
-        $ret = formatTimestamp($this->getVar('date', 'e'));
103
-
104
-        return $ret;
105
-    }
106
-
107
-    /**
108
-     * @param  bool         $full
109
-     * @return mixed|string
110
-     */
111
-    public function link($full = false)
112
-    {
113
-        $ret = $this->getVar('link', 'e');
114
-        if ($full) {
115
-            $myts = MyTextSanitizer::getInstance();
116
-            $ret  = $myts->displayTarea($ret);
117
-
118
-            return $ret;
119
-        } else {
120
-            $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>';
121
-
122
-            return $ret;
123
-        }
124
-    }
125
-
126
-    /**
127
-     * @return string
128
-     */
129
-    public function getViewItemLink()
130
-    {
131
-        $ret = '<a href="' .
132
-               SMARTOBJECT_URL .
133
-               'admin/link.php?op=view&linkid=' .
134
-               $this->getVar('linkid') .
135
-               '"><img src="' .
136
-               SMARTOBJECT_IMAGES_ACTIONS_URL .
137
-               'mail_find.png" alt="' .
138
-               _AM_SOBJECT_SENT_LINK_VIEW .
139
-               '" title="' .
140
-               _AM_SOBJECT_SENT_LINK_VIEW .
141
-               '" /></a>';
142
-
143
-        return $ret;
144
-    }
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public function getFromInfo()
150
-    {
151
-        // check if from_uid represent a user
152
-
153
-        if ($this->getVar('from_uid')) {
154
-            $user = smart_getLinkedUnameFromId($this->getVar('from_uid'));
155
-            if ($user == $GLOBALS['xoopsConfig']['anonymous']) {
156
-                $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>';
157
-            }
158
-        } else {
159
-            $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>';
160
-        }
161
-
162
-        return $user;
163
-    }
164
-
165
-    /**
166
-     * @return array
167
-     */
168
-    public function toArray()
169
-    {
170
-        $ret             = parent::toArray();
171
-        $ret['fromInfo'] = $this->getFromInfo();
172
-        $ret['toInfo']   = $this->getToInfo();
173
-        $ret['fullLink'] = $this->link(true);
174
-
175
-        return $ret;
176
-    }
177
-
178
-    /**
179
-     * @return string
180
-     */
181
-    public function getToInfo()
182
-    {
183
-        // check if from_uid represent a user
184
-
185
-        if ($this->getVar('to_uid')) {
186
-            $user = smart_getLinkedUnameFromId($this->getVar('to_uid'));
187
-            if ($user == $GLOBALS['xoopsConfig']['anonymous']) {
188
-                $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>';
189
-            }
190
-        } else {
191
-            $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>';
192
-        }
193
-
194
-        return $user;
195
-    }
38
+	/**
39
+	 * SmartobjectLink constructor.
40
+	 */
41
+	public function __construct()
42
+	{
43
+		$this->initVar('linkid', XOBJ_DTYPE_INT, '', true);
44
+		$this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false);
45
+		$this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC);
46
+		$this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true);
47
+		$this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true);
48
+		$this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC);
49
+		$this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true);
50
+		$this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true);
51
+		$this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true);
52
+		$this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true);
53
+		$this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC);
54
+		$this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC);
55
+		$this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true);
56
+	}
57
+
58
+	/**
59
+	 * returns a specific variable for the object in a proper format
60
+	 *
61
+	 * @access public
62
+	 * @param  string $key    key of the object's variable to be returned
63
+	 * @param  string $format format to use for the output
64
+	 * @return mixed  formatted value of the variable
65
+	 */
66
+	public function getVar($key, $format = 's')
67
+	{
68
+		if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) {
69
+			//            return call_user_func(array($this, $key));
70
+			return $this->{$key}();
71
+		}
72
+
73
+		return parent::getVar($key, $format);
74
+	}
75
+
76
+	/**
77
+	 * @return string
78
+	 */
79
+	public function from_uid()
80
+	{
81
+		$ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true);
82
+
83
+		return $ret;
84
+	}
85
+
86
+	/**
87
+	 * @param  bool   $withContact
88
+	 * @return string
89
+	 */
90
+	public function to_uid($withContact = false)
91
+	{
92
+		$ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true);
93
+
94
+		return $ret;
95
+	}
96
+
97
+	/**
98
+	 * @return string
99
+	 */
100
+	public function date()
101
+	{
102
+		$ret = formatTimestamp($this->getVar('date', 'e'));
103
+
104
+		return $ret;
105
+	}
106
+
107
+	/**
108
+	 * @param  bool         $full
109
+	 * @return mixed|string
110
+	 */
111
+	public function link($full = false)
112
+	{
113
+		$ret = $this->getVar('link', 'e');
114
+		if ($full) {
115
+			$myts = MyTextSanitizer::getInstance();
116
+			$ret  = $myts->displayTarea($ret);
117
+
118
+			return $ret;
119
+		} else {
120
+			$ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>';
121
+
122
+			return $ret;
123
+		}
124
+	}
125
+
126
+	/**
127
+	 * @return string
128
+	 */
129
+	public function getViewItemLink()
130
+	{
131
+		$ret = '<a href="' .
132
+			   SMARTOBJECT_URL .
133
+			   'admin/link.php?op=view&linkid=' .
134
+			   $this->getVar('linkid') .
135
+			   '"><img src="' .
136
+			   SMARTOBJECT_IMAGES_ACTIONS_URL .
137
+			   'mail_find.png" alt="' .
138
+			   _AM_SOBJECT_SENT_LINK_VIEW .
139
+			   '" title="' .
140
+			   _AM_SOBJECT_SENT_LINK_VIEW .
141
+			   '" /></a>';
142
+
143
+		return $ret;
144
+	}
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public function getFromInfo()
150
+	{
151
+		// check if from_uid represent a user
152
+
153
+		if ($this->getVar('from_uid')) {
154
+			$user = smart_getLinkedUnameFromId($this->getVar('from_uid'));
155
+			if ($user == $GLOBALS['xoopsConfig']['anonymous']) {
156
+				$user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>';
157
+			}
158
+		} else {
159
+			$user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>';
160
+		}
161
+
162
+		return $user;
163
+	}
164
+
165
+	/**
166
+	 * @return array
167
+	 */
168
+	public function toArray()
169
+	{
170
+		$ret             = parent::toArray();
171
+		$ret['fromInfo'] = $this->getFromInfo();
172
+		$ret['toInfo']   = $this->getToInfo();
173
+		$ret['fullLink'] = $this->link(true);
174
+
175
+		return $ret;
176
+	}
177
+
178
+	/**
179
+	 * @return string
180
+	 */
181
+	public function getToInfo()
182
+	{
183
+		// check if from_uid represent a user
184
+
185
+		if ($this->getVar('to_uid')) {
186
+			$user = smart_getLinkedUnameFromId($this->getVar('to_uid'));
187
+			if ($user == $GLOBALS['xoopsConfig']['anonymous']) {
188
+				$user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>';
189
+			}
190
+		} else {
191
+			$user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>';
192
+		}
193
+
194
+		return $user;
195
+	}
196 196
 }
197 197
 
198 198
 /**
@@ -200,12 +200,12 @@  discard block
 block discarded – undo
200 200
  */
201 201
 class SmartobjectLinkHandler extends SmartPersistableObjectHandler
202 202
 {
203
-    /**
204
-     * SmartobjectLinkHandler constructor.
205
-     * @param XoopsDatabase $db
206
-     */
207
-    public function __construct(XoopsDatabase $db)
208
-    {
209
-        parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject');
210
-    }
203
+	/**
204
+	 * SmartobjectLinkHandler constructor.
205
+	 * @param XoopsDatabase $db
206
+	 */
207
+	public function __construct(XoopsDatabase $db)
208
+	{
209
+		parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject');
210
+	}
211 211
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 // -------------------------------------------------------------------------//
29 29
 
30 30
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
31
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
31
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
32 32
 
33 33
 /**
34 34
  * Class SmartobjectLink
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
             return $ret;
119 119
         } else {
120
-            $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>';
120
+            $ret = '<a href="'.$ret.'" alt="'.$this->getVar('link', 'e').'" title="'.$this->getVar('link', 'e').'">'._AM_SOBJECT_SENT_LINKS_GOTO.'</a>';
121 121
 
122 122
             return $ret;
123 123
         }
@@ -128,16 +128,16 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function getViewItemLink()
130 130
     {
131
-        $ret = '<a href="' .
132
-               SMARTOBJECT_URL .
133
-               'admin/link.php?op=view&linkid=' .
134
-               $this->getVar('linkid') .
135
-               '"><img src="' .
136
-               SMARTOBJECT_IMAGES_ACTIONS_URL .
137
-               'mail_find.png" alt="' .
138
-               _AM_SOBJECT_SENT_LINK_VIEW .
139
-               '" title="' .
140
-               _AM_SOBJECT_SENT_LINK_VIEW .
131
+        $ret = '<a href="'.
132
+               SMARTOBJECT_URL.
133
+               'admin/link.php?op=view&linkid='.
134
+               $this->getVar('linkid').
135
+               '"><img src="'.
136
+               SMARTOBJECT_IMAGES_ACTIONS_URL.
137
+               'mail_find.png" alt="'.
138
+               _AM_SOBJECT_SENT_LINK_VIEW.
139
+               '" title="'.
140
+               _AM_SOBJECT_SENT_LINK_VIEW.
141 141
                '" /></a>';
142 142
 
143 143
         return $ret;
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
         if ($this->getVar('from_uid')) {
154 154
             $user = smart_getLinkedUnameFromId($this->getVar('from_uid'));
155 155
             if ($user == $GLOBALS['xoopsConfig']['anonymous']) {
156
-                $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>';
156
+                $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>';
157 157
             }
158 158
         } else {
159
-            $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>';
159
+            $user = '<a href="mailto:'.$this->getVar('from_email').'">'.$this->getVar('from_email').'</a>';
160 160
         }
161 161
 
162 162
         return $user;
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
         if ($this->getVar('to_uid')) {
186 186
             $user = smart_getLinkedUnameFromId($this->getVar('to_uid'));
187 187
             if ($user == $GLOBALS['xoopsConfig']['anonymous']) {
188
-                $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>';
188
+                $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>';
189 189
             }
190 190
         } else {
191
-            $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>';
191
+            $user = '<a href="mailto:'.$this->getVar('to_email').'">'.$this->getVar('to_email').'</a>';
192 192
         }
193 193
 
194 194
         return $user;
Please login to merge, or discard this patch.