Completed
Push — master ( 2a36d1...bf34f3 )
by Michael
03:21
created
include/projax/classes/Prototype.php 1 patch
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -15,452 +15,452 @@
 block discarded – undo
15 15
  */
16 16
 class Prototype extends JavaScript
17 17
 {
18
-    public $CALLBACKS = [
19
-        'uninitialized',
20
-        'loading',
21
-        'loaded',
22
-        'interactive',
23
-        'complete',
24
-        'failure',
25
-        'success'
26
-    ];
27
-
28
-    public $AJAX_OPTIONS = [
29
-        'before',
30
-        'after',
31
-        'condition',
32
-        'url',
33
-        'asynchronous',
34
-        'method',
35
-        'insertion',
36
-        'position',
37
-        'form',
38
-        'with',
39
-        'update',
40
-        'script',
41
-        'uninitialized',
42
-        'loading',
43
-        'loaded',
44
-        'interactive',
45
-        'complete',
46
-        'failure',
47
-        'success'
48
-    ];
49
-
50
-    /**
51
-     * @return string
52
-     */
53
-    public function evaluate_remote_response()
54
-    {
55
-        return 'eval(request.responseText)';
56
-    }
57
-
58
-    /**
59
-     * @param $options
60
-     * @return string
61
-     */
62
-    public function form_remote_tag($options)
63
-    {
64
-        $options['form'] = true;
65
-
66
-        return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
-    }
68
-
69
-    /**
70
-     * @param         $name
71
-     * @param  null   $options
72
-     * @param  null   $html_options
73
-     * @return string
74
-     */
75
-    public function link_to_remote($name, $options = null, $html_options = null)
76
-    {
77
-        return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
-    }
79
-
80
-    /**
81
-     * @param         $field_id
82
-     * @param  null   $options
83
-     * @return string
84
-     */
85
-    public function observe_field($field_id, $options = null)
86
-    {
87
-        if (isset($options['frequency']) && $options['frequency'] > 0) {
88
-            return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
-        } else {
90
-            return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
-        }
92
-    }
93
-
94
-    /**
95
-     * @param         $form_id
96
-     * @param  null   $options
97
-     * @return string
98
-     */
99
-    public function observe_form($form_id, $options = null)
100
-    {
101
-        if (isset($options['frequency'])) {
102
-            return $this->_build_observer('Form.Observer', $form_id, $options);
103
-        } else {
104
-            return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
-        }
106
-    }
107
-
108
-    /**
109
-     * @param  null $options
110
-     * @return string
111
-     */
112
-    public function periodically_call_remote($options = null)
113
-    {
114
-        $frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
-        $code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
-
117
-        return $code;
118
-    }
119
-
120
-    /**
121
-     * @param $options
122
-     * @return string
123
-     */
124
-    public function remote_function($options)
125
-    {
126
-        $javascript_options = $this->_options_for_ajax($options);
127
-
128
-        $update = '';
129
-
130
-        if (isset($options['update']) && is_array($options['update'])) {
131
-            $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
-            $update .= empty($update) ? '' : ',';
133
-            $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
-        } else {
135
-            $update .= isset($options['update']) ? $options['update'] : '';
136
-        }
137
-
138
-        $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
-
140
-        $ajax_function .= "'" . $options['url'] . "'";
141
-        $ajax_function .= ',' . $javascript_options . ')';
142
-
143
-        $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
-        $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
-        $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
-        $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
-
148
-        return $ajax_function;
149
-    }
150
-
151
-    /**
152
-     * @param $name
153
-     * @param $value
154
-     * @param $options
155
-     * @return string
156
-     */
157
-    public function submit_to_remote($name, $value, $options)
158
-    {
159
-        if (isset($options['with'])) {
160
-            $options['with'] = 'Form.serialize(this.form)';
161
-        }
162
-
163
-        return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
-    }
165
-
166
-    /**
167
-     * @param      $element_id
168
-     * @param null $options
169
-     * @param      $block
170
-     */
171
-    public function update_element_function($element_id, $options = null, $block)
172
-    {
173
-        $content = isset($options['content']) ? $options['content'] : '';
174
-        $content = $this->escape($content);
175
-    }
176
-
177
-    /**
178
-     * @param $block
179
-     */
180
-    public function update_page($block)
181
-    {
182
-    }
183
-
184
-    /**
185
-     * @param $block
186
-     * @return string
187
-     */
188
-    public function update_page_tag(& $block)
189
-    {
190
-        return $this->tag($block);
191
-    }
192
-
193
-    /////////////////////////////////////////////////////////////////////////////////////
194
-    //                             Private functions
195
-    /////////////////////////////////////////////////////////////////////////////////////
196
-
197
-    /**
198
-     * @param $options
199
-     * @return array
200
-     */
201
-    public function _build_callbacks($options)
202
-    {
203
-        $callbacks = [];
204
-        foreach ($options as $callback => $code) {
205
-            if (in_array($callback, $this->CALLBACKS)) {
206
-                $name             = 'on' . ucfirst($callback);
207
-                $callbacks[$name] = 'function(request){' . $code . '}';
208
-            }
209
-        }
210
-
211
-        return $callbacks;
212
-    }
213
-
214
-    /**
215
-     * @param         $klass
216
-     * @param         $name
217
-     * @param  null   $options
218
-     * @return string
219
-     */
220
-    public function _build_observer($klass, $name, $options = null)
221
-    {
222
-        if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
-            $options['with'] = '\'' . $options['with'] . '=\' + value';
224
-        } elseif (isset($options['with']) && isset($options['update'])) {
225
-            $options['with'] = 'value';
226
-        }
227
-
228
-        $callback = $options['function'] ?: $this->remote_function($options);
229
-
230
-        $javascript = "new $klass('$name', ";
231
-        $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
-        $javascript .= 'function (element,value) { ';
233
-        $javascript .= $callback;
234
-        $javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
-        $javascript .= '})';
236
-
237
-        return $javascript;
238
-    }
239
-
240
-    /**
241
-     * @param $method
242
-     * @return string
243
-     */
244
-    public function _method_option_to_s($method)
245
-    {
246
-        return strstr($method, "'") ? $method : "'$method'";
247
-    }
248
-
249
-    /**
250
-     * @param $options
251
-     * @return string
252
-     */
253
-    public function _options_for_ajax($options)
254
-    {
255
-        $js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
-
257
-        if (isset($options['type']) && 'synchronous' === $option['type']) {
258
-            $js_options['asynchronous'] = 'false';
259
-        }
260
-
261
-        if (isset($options['method'])) {
262
-            $js_options['method'] = $this->_method_option_to_s($options['method']);
263
-        }
264
-
265
-        if (isset($options['position'])) {
266
-            $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
-        }
268
-
269
-        $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
-
271
-        if (isset($options['form'])) {
272
-            $js_options['parameters'] = 'Form.serialize(this)';
273
-        } elseif (isset($options['parameters'])) {
274
-            $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
-        } elseif (isset($options['with'])) {
276
-            $js_options['parameters'] = $options['with'];
277
-        }
278
-
279
-        return $this->_options_for_javascript($js_options);
280
-    }
281
-
282
-    /////////////////////////////////////////////////////////////////////////////////////
283
-    //                            Mergerd Javascript Generator helpers
284
-    /////////////////////////////////////////////////////////////////////////////////////
285
-
286
-    /**
287
-     * @param $javascript
288
-     */
289
-    public function dump($javascript)
290
-    {
291
-        echo $javascript;
292
-    }
293
-
294
-    /**
295
-     * @param         $id
296
-     * @param  null   $extend
297
-     * @return string
298
-     */
299
-    public function ID($id, $extend = null)
300
-    {
301
-        return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
-    }
303
-
304
-    /**
305
-     * @param $message
306
-     * @return string
307
-     */
308
-    public function alert($message)
309
-    {
310
-        return $this->call('alert', $message);
311
-    }
312
-
313
-    /**
314
-     * @param $variable
315
-     * @param $value
316
-     * @return string
317
-     */
318
-    public function assign($variable, $value)
319
-    {
320
-        return "$variable = $value;";
321
-    }
322
-
323
-    /**
324
-     * @param         $function
325
-     * @param  null   $args
326
-     * @return string
327
-     */
328
-    public function call($function, $args = null)
329
-    {
330
-        $arg_str = '';
331
-        if (is_array($args)) {
332
-            foreach ($args as $arg) {
333
-                if (!empty($arg_str)) {
334
-                    $arg_str .= ', ';
335
-                }
336
-                if (is_string($arg)) {
337
-                    $arg_str .= "'$arg'";
338
-                } else {
339
-                    $arg_str .= $arg;
340
-                }
341
-            }
342
-        } else {
343
-            if (is_string($args)) {
344
-                $arg_str .= "'$args'";
345
-            } else {
346
-                $arg_str .= $args;
347
-            }
348
-        }
349
-
350
-        return "$function($arg_str)";
351
-    }
352
-
353
-    /**
354
-     * @param  int    $seconds
355
-     * @param  string $script
356
-     * @return string
357
-     */
358
-    public function delay($seconds = 1, $script = '')
359
-    {
360
-        return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
-    }
362
-
363
-    /**
364
-     * @param $id
365
-     * @return string
366
-     */
367
-    public function hide($id)
368
-    {
369
-        return $this->call('Element.hide', $id);
370
-    }
371
-
372
-    /**
373
-     * @param         $position
374
-     * @param         $id
375
-     * @param  null   $options_for_render
376
-     * @return string
377
-     */
378
-    public function insert_html($position, $id, $options_for_render = null)
379
-    {
380
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
-
382
-        return $this->call('new Insertion.' . ucfirst($position), $args);
383
-    }
384
-
385
-    /**
386
-     * @param $location
387
-     * @return string
388
-     */
389
-    public function redirect_to($location)
390
-    {
391
-        return $this->assign('window.location.href', $location);
392
-    }
393
-
394
-    /**
395
-     * @param $id
396
-     * @return string
397
-     */
398
-    public function remove($id)
399
-    {
400
-        if (is_array($id)) {
401
-            $arr_str = '';
402
-            foreach ($id as $obj) {
403
-                if (!empty($arg_str)) {
404
-                    $arg_str .= ', ';
405
-                }
406
-                $arg_str .= "'$arg'";
407
-            }
408
-
409
-            return "$A[$arg_str].each(Element.remove)";
410
-        } else {
411
-            return "Element.remove('$id')";
412
-        }
413
-    }
414
-
415
-    /**
416
-     * @param $id
417
-     * @param $options_for_render
418
-     * @return string
419
-     */
420
-    public function replace($id, $options_for_render)
421
-    {
422
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
-
424
-        return $this->call('Element.replace', $args);
425
-    }
426
-
427
-    /**
428
-     * @param $id
429
-     * @param $options_for_render
430
-     * @return string
431
-     */
432
-    public function replace_html($id, $options_for_render)
433
-    {
434
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
-
436
-        return $this->call('Element.update', $args);
437
-    }
438
-
439
-    /**
440
-     * @param         $pattern
441
-     * @param  null   $extend
442
-     * @return string
443
-     */
444
-    public function select($pattern, $extend = null)
445
-    {
446
-        return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
-    }
448
-
449
-    /**
450
-     * @param $id
451
-     * @return string
452
-     */
453
-    public function show($id)
454
-    {
455
-        return $this->call('Element.show', $id);
456
-    }
457
-
458
-    /**
459
-     * @param $id
460
-     * @return string
461
-     */
462
-    public function toggle($id)
463
-    {
464
-        return $this->call('Element.toggle', $id);
465
-    }
18
+	public $CALLBACKS = [
19
+		'uninitialized',
20
+		'loading',
21
+		'loaded',
22
+		'interactive',
23
+		'complete',
24
+		'failure',
25
+		'success'
26
+	];
27
+
28
+	public $AJAX_OPTIONS = [
29
+		'before',
30
+		'after',
31
+		'condition',
32
+		'url',
33
+		'asynchronous',
34
+		'method',
35
+		'insertion',
36
+		'position',
37
+		'form',
38
+		'with',
39
+		'update',
40
+		'script',
41
+		'uninitialized',
42
+		'loading',
43
+		'loaded',
44
+		'interactive',
45
+		'complete',
46
+		'failure',
47
+		'success'
48
+	];
49
+
50
+	/**
51
+	 * @return string
52
+	 */
53
+	public function evaluate_remote_response()
54
+	{
55
+		return 'eval(request.responseText)';
56
+	}
57
+
58
+	/**
59
+	 * @param $options
60
+	 * @return string
61
+	 */
62
+	public function form_remote_tag($options)
63
+	{
64
+		$options['form'] = true;
65
+
66
+		return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
+	}
68
+
69
+	/**
70
+	 * @param         $name
71
+	 * @param  null   $options
72
+	 * @param  null   $html_options
73
+	 * @return string
74
+	 */
75
+	public function link_to_remote($name, $options = null, $html_options = null)
76
+	{
77
+		return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
+	}
79
+
80
+	/**
81
+	 * @param         $field_id
82
+	 * @param  null   $options
83
+	 * @return string
84
+	 */
85
+	public function observe_field($field_id, $options = null)
86
+	{
87
+		if (isset($options['frequency']) && $options['frequency'] > 0) {
88
+			return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
+		} else {
90
+			return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
+		}
92
+	}
93
+
94
+	/**
95
+	 * @param         $form_id
96
+	 * @param  null   $options
97
+	 * @return string
98
+	 */
99
+	public function observe_form($form_id, $options = null)
100
+	{
101
+		if (isset($options['frequency'])) {
102
+			return $this->_build_observer('Form.Observer', $form_id, $options);
103
+		} else {
104
+			return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
+		}
106
+	}
107
+
108
+	/**
109
+	 * @param  null $options
110
+	 * @return string
111
+	 */
112
+	public function periodically_call_remote($options = null)
113
+	{
114
+		$frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
+		$code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
+
117
+		return $code;
118
+	}
119
+
120
+	/**
121
+	 * @param $options
122
+	 * @return string
123
+	 */
124
+	public function remote_function($options)
125
+	{
126
+		$javascript_options = $this->_options_for_ajax($options);
127
+
128
+		$update = '';
129
+
130
+		if (isset($options['update']) && is_array($options['update'])) {
131
+			$update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
+			$update .= empty($update) ? '' : ',';
133
+			$update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
+		} else {
135
+			$update .= isset($options['update']) ? $options['update'] : '';
136
+		}
137
+
138
+		$ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
+
140
+		$ajax_function .= "'" . $options['url'] . "'";
141
+		$ajax_function .= ',' . $javascript_options . ')';
142
+
143
+		$ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
+		$ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
+		$ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
+		$ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
+
148
+		return $ajax_function;
149
+	}
150
+
151
+	/**
152
+	 * @param $name
153
+	 * @param $value
154
+	 * @param $options
155
+	 * @return string
156
+	 */
157
+	public function submit_to_remote($name, $value, $options)
158
+	{
159
+		if (isset($options['with'])) {
160
+			$options['with'] = 'Form.serialize(this.form)';
161
+		}
162
+
163
+		return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
+	}
165
+
166
+	/**
167
+	 * @param      $element_id
168
+	 * @param null $options
169
+	 * @param      $block
170
+	 */
171
+	public function update_element_function($element_id, $options = null, $block)
172
+	{
173
+		$content = isset($options['content']) ? $options['content'] : '';
174
+		$content = $this->escape($content);
175
+	}
176
+
177
+	/**
178
+	 * @param $block
179
+	 */
180
+	public function update_page($block)
181
+	{
182
+	}
183
+
184
+	/**
185
+	 * @param $block
186
+	 * @return string
187
+	 */
188
+	public function update_page_tag(& $block)
189
+	{
190
+		return $this->tag($block);
191
+	}
192
+
193
+	/////////////////////////////////////////////////////////////////////////////////////
194
+	//                             Private functions
195
+	/////////////////////////////////////////////////////////////////////////////////////
196
+
197
+	/**
198
+	 * @param $options
199
+	 * @return array
200
+	 */
201
+	public function _build_callbacks($options)
202
+	{
203
+		$callbacks = [];
204
+		foreach ($options as $callback => $code) {
205
+			if (in_array($callback, $this->CALLBACKS)) {
206
+				$name             = 'on' . ucfirst($callback);
207
+				$callbacks[$name] = 'function(request){' . $code . '}';
208
+			}
209
+		}
210
+
211
+		return $callbacks;
212
+	}
213
+
214
+	/**
215
+	 * @param         $klass
216
+	 * @param         $name
217
+	 * @param  null   $options
218
+	 * @return string
219
+	 */
220
+	public function _build_observer($klass, $name, $options = null)
221
+	{
222
+		if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
+			$options['with'] = '\'' . $options['with'] . '=\' + value';
224
+		} elseif (isset($options['with']) && isset($options['update'])) {
225
+			$options['with'] = 'value';
226
+		}
227
+
228
+		$callback = $options['function'] ?: $this->remote_function($options);
229
+
230
+		$javascript = "new $klass('$name', ";
231
+		$javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
+		$javascript .= 'function (element,value) { ';
233
+		$javascript .= $callback;
234
+		$javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
+		$javascript .= '})';
236
+
237
+		return $javascript;
238
+	}
239
+
240
+	/**
241
+	 * @param $method
242
+	 * @return string
243
+	 */
244
+	public function _method_option_to_s($method)
245
+	{
246
+		return strstr($method, "'") ? $method : "'$method'";
247
+	}
248
+
249
+	/**
250
+	 * @param $options
251
+	 * @return string
252
+	 */
253
+	public function _options_for_ajax($options)
254
+	{
255
+		$js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
+
257
+		if (isset($options['type']) && 'synchronous' === $option['type']) {
258
+			$js_options['asynchronous'] = 'false';
259
+		}
260
+
261
+		if (isset($options['method'])) {
262
+			$js_options['method'] = $this->_method_option_to_s($options['method']);
263
+		}
264
+
265
+		if (isset($options['position'])) {
266
+			$js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
+		}
268
+
269
+		$js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
+
271
+		if (isset($options['form'])) {
272
+			$js_options['parameters'] = 'Form.serialize(this)';
273
+		} elseif (isset($options['parameters'])) {
274
+			$js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
+		} elseif (isset($options['with'])) {
276
+			$js_options['parameters'] = $options['with'];
277
+		}
278
+
279
+		return $this->_options_for_javascript($js_options);
280
+	}
281
+
282
+	/////////////////////////////////////////////////////////////////////////////////////
283
+	//                            Mergerd Javascript Generator helpers
284
+	/////////////////////////////////////////////////////////////////////////////////////
285
+
286
+	/**
287
+	 * @param $javascript
288
+	 */
289
+	public function dump($javascript)
290
+	{
291
+		echo $javascript;
292
+	}
293
+
294
+	/**
295
+	 * @param         $id
296
+	 * @param  null   $extend
297
+	 * @return string
298
+	 */
299
+	public function ID($id, $extend = null)
300
+	{
301
+		return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
+	}
303
+
304
+	/**
305
+	 * @param $message
306
+	 * @return string
307
+	 */
308
+	public function alert($message)
309
+	{
310
+		return $this->call('alert', $message);
311
+	}
312
+
313
+	/**
314
+	 * @param $variable
315
+	 * @param $value
316
+	 * @return string
317
+	 */
318
+	public function assign($variable, $value)
319
+	{
320
+		return "$variable = $value;";
321
+	}
322
+
323
+	/**
324
+	 * @param         $function
325
+	 * @param  null   $args
326
+	 * @return string
327
+	 */
328
+	public function call($function, $args = null)
329
+	{
330
+		$arg_str = '';
331
+		if (is_array($args)) {
332
+			foreach ($args as $arg) {
333
+				if (!empty($arg_str)) {
334
+					$arg_str .= ', ';
335
+				}
336
+				if (is_string($arg)) {
337
+					$arg_str .= "'$arg'";
338
+				} else {
339
+					$arg_str .= $arg;
340
+				}
341
+			}
342
+		} else {
343
+			if (is_string($args)) {
344
+				$arg_str .= "'$args'";
345
+			} else {
346
+				$arg_str .= $args;
347
+			}
348
+		}
349
+
350
+		return "$function($arg_str)";
351
+	}
352
+
353
+	/**
354
+	 * @param  int    $seconds
355
+	 * @param  string $script
356
+	 * @return string
357
+	 */
358
+	public function delay($seconds = 1, $script = '')
359
+	{
360
+		return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
+	}
362
+
363
+	/**
364
+	 * @param $id
365
+	 * @return string
366
+	 */
367
+	public function hide($id)
368
+	{
369
+		return $this->call('Element.hide', $id);
370
+	}
371
+
372
+	/**
373
+	 * @param         $position
374
+	 * @param         $id
375
+	 * @param  null   $options_for_render
376
+	 * @return string
377
+	 */
378
+	public function insert_html($position, $id, $options_for_render = null)
379
+	{
380
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
+
382
+		return $this->call('new Insertion.' . ucfirst($position), $args);
383
+	}
384
+
385
+	/**
386
+	 * @param $location
387
+	 * @return string
388
+	 */
389
+	public function redirect_to($location)
390
+	{
391
+		return $this->assign('window.location.href', $location);
392
+	}
393
+
394
+	/**
395
+	 * @param $id
396
+	 * @return string
397
+	 */
398
+	public function remove($id)
399
+	{
400
+		if (is_array($id)) {
401
+			$arr_str = '';
402
+			foreach ($id as $obj) {
403
+				if (!empty($arg_str)) {
404
+					$arg_str .= ', ';
405
+				}
406
+				$arg_str .= "'$arg'";
407
+			}
408
+
409
+			return "$A[$arg_str].each(Element.remove)";
410
+		} else {
411
+			return "Element.remove('$id')";
412
+		}
413
+	}
414
+
415
+	/**
416
+	 * @param $id
417
+	 * @param $options_for_render
418
+	 * @return string
419
+	 */
420
+	public function replace($id, $options_for_render)
421
+	{
422
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
+
424
+		return $this->call('Element.replace', $args);
425
+	}
426
+
427
+	/**
428
+	 * @param $id
429
+	 * @param $options_for_render
430
+	 * @return string
431
+	 */
432
+	public function replace_html($id, $options_for_render)
433
+	{
434
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
+
436
+		return $this->call('Element.update', $args);
437
+	}
438
+
439
+	/**
440
+	 * @param         $pattern
441
+	 * @param  null   $extend
442
+	 * @return string
443
+	 */
444
+	public function select($pattern, $extend = null)
445
+	{
446
+		return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
+	}
448
+
449
+	/**
450
+	 * @param $id
451
+	 * @return string
452
+	 */
453
+	public function show($id)
454
+	{
455
+		return $this->call('Element.show', $id);
456
+	}
457
+
458
+	/**
459
+	 * @param $id
460
+	 * @return string
461
+	 */
462
+	public function toggle($id)
463
+	{
464
+		return $this->call('Element.toggle', $id);
465
+	}
466 466
 }
Please login to merge, or discard this patch.
include/functions.php 2 patches
Indentation   +710 added lines, -710 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
 
12 12
 function smart_get_css_link($cssfile)
13 13
 {
14
-    $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">';
14
+	$ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">';
15 15
 
16
-    return $ret;
16
+	return $ret;
17 17
 }
18 18
 
19 19
 /**
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
  */
22 22
 function smart_get_page_before_form()
23 23
 {
24
-    global $smart_previous_page;
24
+	global $smart_previous_page;
25 25
 
26
-    return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page;
26
+	return isset($_POST['smart_page_before_form']) ? $_POST['smart_page_before_form'] : $smart_previous_page;
27 27
 }
28 28
 
29 29
 /**
@@ -34,29 +34,29 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function smart_userIsAdmin($module = false)
36 36
 {
37
-    global $xoopsUser;
38
-    static $smart_isAdmin;
39
-    if (!$module) {
40
-        global $xoopsModule;
41
-        $module = $xoopsModule->getVar('dirname');
42
-    }
43
-    if (isset($smart_isAdmin[$module])) {
44
-        return $smart_isAdmin[$module];
45
-    }
46
-    if (!$xoopsUser) {
47
-        $smart_isAdmin[$module] = false;
48
-
49
-        return $smart_isAdmin[$module];
50
-    }
51
-    $smart_isAdmin[$module] = false;
52
-    $smartModule            = smart_getModuleInfo($module);
53
-    if (!is_object($smartModule)) {
54
-        return false;
55
-    }
56
-    $module_id              = $smartModule->getVar('mid');
57
-    $smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id);
58
-
59
-    return $smart_isAdmin[$module];
37
+	global $xoopsUser;
38
+	static $smart_isAdmin;
39
+	if (!$module) {
40
+		global $xoopsModule;
41
+		$module = $xoopsModule->getVar('dirname');
42
+	}
43
+	if (isset($smart_isAdmin[$module])) {
44
+		return $smart_isAdmin[$module];
45
+	}
46
+	if (!$xoopsUser) {
47
+		$smart_isAdmin[$module] = false;
48
+
49
+		return $smart_isAdmin[$module];
50
+	}
51
+	$smart_isAdmin[$module] = false;
52
+	$smartModule            = smart_getModuleInfo($module);
53
+	if (!is_object($smartModule)) {
54
+		return false;
55
+	}
56
+	$module_id              = $smartModule->getVar('mid');
57
+	$smart_isAdmin[$module] = $xoopsUser->isAdmin($module_id);
58
+
59
+	return $smart_isAdmin[$module];
60 60
 }
61 61
 
62 62
 /**
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function smart_isXoops22()
66 66
 {
67
-    $xoops22 = false;
68
-    $xv      = str_replace('XOOPS ', '', XOOPS_VERSION);
69
-    if ('2' == substr($xv, 2, 1)) {
70
-        $xoops22 = true;
71
-    }
67
+	$xoops22 = false;
68
+	$xv      = str_replace('XOOPS ', '', XOOPS_VERSION);
69
+	if ('2' == substr($xv, 2, 1)) {
70
+		$xoops22 = true;
71
+	}
72 72
 
73
-    return $xoops22;
73
+	return $xoops22;
74 74
 }
75 75
 
76 76
 /**
@@ -81,36 +81,36 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function smart_getModuleName($withLink = true, $forBreadCrumb = false, $moduleName = false)
83 83
 {
84
-    if (!$moduleName) {
85
-        global $xoopsModule;
86
-        $moduleName = $xoopsModule->getVar('dirname');
87
-    }
88
-    $smartModule       = smart_getModuleInfo($moduleName);
89
-    $smartModuleConfig = smart_getModuleConfig($moduleName);
90
-    if (!isset($smartModule)) {
91
-        return '';
92
-    }
93
-
94
-    if ($forBreadCrumb
95
-        && (isset($smartModuleConfig['show_mod_name_breadcrumb'])
96
-            && !$smartModuleConfig['show_mod_name_breadcrumb'])) {
97
-        return '';
98
-    }
99
-    if (!$withLink) {
100
-        return $smartModule->getVar('name');
101
-    } else {
102
-        $seoMode = smart_getModuleModeSEO($moduleName);
103
-        if ('rewrite' === $seoMode) {
104
-            $seoModuleName = smart_getModuleNameForSEO($moduleName);
105
-            $ret           = XOOPS_URL . '/' . $seoModuleName . '/';
106
-        } elseif ('pathinfo' === $seoMode) {
107
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
108
-        } else {
109
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/';
110
-        }
111
-
112
-        return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
113
-    }
84
+	if (!$moduleName) {
85
+		global $xoopsModule;
86
+		$moduleName = $xoopsModule->getVar('dirname');
87
+	}
88
+	$smartModule       = smart_getModuleInfo($moduleName);
89
+	$smartModuleConfig = smart_getModuleConfig($moduleName);
90
+	if (!isset($smartModule)) {
91
+		return '';
92
+	}
93
+
94
+	if ($forBreadCrumb
95
+		&& (isset($smartModuleConfig['show_mod_name_breadcrumb'])
96
+			&& !$smartModuleConfig['show_mod_name_breadcrumb'])) {
97
+		return '';
98
+	}
99
+	if (!$withLink) {
100
+		return $smartModule->getVar('name');
101
+	} else {
102
+		$seoMode = smart_getModuleModeSEO($moduleName);
103
+		if ('rewrite' === $seoMode) {
104
+			$seoModuleName = smart_getModuleNameForSEO($moduleName);
105
+			$ret           = XOOPS_URL . '/' . $seoModuleName . '/';
106
+		} elseif ('pathinfo' === $seoMode) {
107
+			$ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
108
+		} else {
109
+			$ret = XOOPS_URL . '/modules/' . $moduleName . '/';
110
+		}
111
+
112
+		return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
113
+	}
114 114
 }
115 115
 
116 116
 /**
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
  */
120 120
 function smart_getModuleNameForSEO($moduleName = false)
121 121
 {
122
-    $smartModule       = smart_getModuleInfo($moduleName);
123
-    $smartModuleConfig = smart_getModuleConfig($moduleName);
124
-    if (isset($smartModuleConfig['seo_module_name'])) {
125
-        return $smartModuleConfig['seo_module_name'];
126
-    }
127
-    $ret = smart_getModuleName(false, false, $moduleName);
128
-
129
-    return strtolower($ret);
122
+	$smartModule       = smart_getModuleInfo($moduleName);
123
+	$smartModuleConfig = smart_getModuleConfig($moduleName);
124
+	if (isset($smartModuleConfig['seo_module_name'])) {
125
+		return $smartModuleConfig['seo_module_name'];
126
+	}
127
+	$ret = smart_getModuleName(false, false, $moduleName);
128
+
129
+	return strtolower($ret);
130 130
 }
131 131
 
132 132
 /**
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
  */
136 136
 function smart_getModuleModeSEO($moduleName = false)
137 137
 {
138
-    $smartModule       = smart_getModuleInfo($moduleName);
139
-    $smartModuleConfig = smart_getModuleConfig($moduleName);
138
+	$smartModule       = smart_getModuleInfo($moduleName);
139
+	$smartModuleConfig = smart_getModuleConfig($moduleName);
140 140
 
141
-    return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false;
141
+	return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false;
142 142
 }
143 143
 
144 144
 /**
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
  */
148 148
 function smart_getModuleIncludeIdSEO($moduleName = false)
149 149
 {
150
-    $smartModule       = smart_getModuleInfo($moduleName);
151
-    $smartModuleConfig = smart_getModuleConfig($moduleName);
150
+	$smartModule       = smart_getModuleInfo($moduleName);
151
+	$smartModuleConfig = smart_getModuleConfig($moduleName);
152 152
 
153
-    return !empty($smartModuleConfig['seo_inc_id']);
153
+	return !empty($smartModuleConfig['seo_inc_id']);
154 154
 }
155 155
 
156 156
 /**
@@ -159,25 +159,25 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function smart_getenv($key)
161 161
 {
162
-    $ret = '';
163
-    $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : '');
162
+	$ret = '';
163
+	$ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : '');
164 164
 
165
-    return $ret;
165
+	return $ret;
166 166
 }
167 167
 
168 168
 function smart_xoops_cp_header()
169 169
 {
170
-    xoops_cp_header();
171
-    global $xoopsModule, $xoopsConfig;
172
-    /**
173
-     * include SmartObject admin language file
174
-     */
175
-    $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
176
-    if (file_exists($fileName)) {
177
-        require_once $fileName;
178
-    } else {
179
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
180
-    } ?>
170
+	xoops_cp_header();
171
+	global $xoopsModule, $xoopsConfig;
172
+	/**
173
+	 * include SmartObject admin language file
174
+	 */
175
+	$fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
176
+	if (file_exists($fileName)) {
177
+		require_once $fileName;
178
+	} else {
179
+		require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
180
+	} ?>
181 181
     <script type='text/javascript'>
182 182
         <!--
183 183
         var smart_url = '<?php echo SMARTOBJECT_URL ?>';
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
             src='<?php echo SMARTOBJECT_URL ?>include/smart.js'></script>
191 191
     <?php
192 192
 
193
-    /**
194
-     * Include the admin language constants for the SmartObject Framework
195
-     */
196
-    $admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php';
197
-    if (!file_exists($admin_file)) {
198
-        $admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php';
199
-    }
200
-    require_once $admin_file;
193
+	/**
194
+	 * Include the admin language constants for the SmartObject Framework
195
+	 */
196
+	$admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php';
197
+	if (!file_exists($admin_file)) {
198
+		$admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php';
199
+	}
200
+	require_once $admin_file;
201 201
 }
202 202
 
203 203
 /**
@@ -211,21 +211,21 @@  discard block
 block discarded – undo
211 211
  */
212 212
 function smart_TableExists($table)
213 213
 {
214
-    $bRetVal = false;
215
-    //Verifies that a MySQL table exists
216
-    $xoopsDB  = XoopsDatabaseFactory::getDatabaseConnection();
217
-    $realname = $xoopsDB->prefix($table);
218
-    $sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
219
-    $ret      = $xoopsDB->queryF($sql);
220
-    while (list($m_table) = $xoopsDB->fetchRow($ret)) {
221
-        if ($m_table == $realname) {
222
-            $bRetVal = true;
223
-            break;
224
-        }
225
-    }
226
-    $xoopsDB->freeRecordSet($ret);
227
-
228
-    return $bRetVal;
214
+	$bRetVal = false;
215
+	//Verifies that a MySQL table exists
216
+	$xoopsDB  = XoopsDatabaseFactory::getDatabaseConnection();
217
+	$realname = $xoopsDB->prefix($table);
218
+	$sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
219
+	$ret      = $xoopsDB->queryF($sql);
220
+	while (list($m_table) = $xoopsDB->fetchRow($ret)) {
221
+		if ($m_table == $realname) {
222
+			$bRetVal = true;
223
+			break;
224
+		}
225
+	}
226
+	$xoopsDB->freeRecordSet($ret);
227
+
228
+	return $bRetVal;
229 229
 }
230 230
 
231 231
 /**
@@ -240,19 +240,19 @@  discard block
 block discarded – undo
240 240
  */
241 241
 function smart_GetMeta($key, $moduleName = false)
242 242
 {
243
-    if (!$moduleName) {
244
-        $moduleName = smart_getCurrentModuleName();
245
-    }
246
-    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
247
-    $sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
248
-    $ret     = $xoopsDB->query($sql);
249
-    if (!$ret) {
250
-        $value = false;
251
-    } else {
252
-        list($value) = $xoopsDB->fetchRow($ret);
253
-    }
254
-
255
-    return $value;
243
+	if (!$moduleName) {
244
+		$moduleName = smart_getCurrentModuleName();
245
+	}
246
+	$xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
247
+	$sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
248
+	$ret     = $xoopsDB->query($sql);
249
+	if (!$ret) {
250
+		$value = false;
251
+	} else {
252
+		list($value) = $xoopsDB->fetchRow($ret);
253
+	}
254
+
255
+	return $value;
256 256
 }
257 257
 
258 258
 /**
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
  */
261 261
 function smart_getCurrentModuleName()
262 262
 {
263
-    global $xoopsModule;
264
-    if (is_object($xoopsModule)) {
265
-        return $xoopsModule->getVar('dirname');
266
-    } else {
267
-        return false;
268
-    }
263
+	global $xoopsModule;
264
+	if (is_object($xoopsModule)) {
265
+		return $xoopsModule->getVar('dirname');
266
+	} else {
267
+		return false;
268
+	}
269 269
 }
270 270
 
271 271
 /**
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function smart_SetMeta($key, $value, $moduleName = false)
283 283
 {
284
-    if (!$moduleName) {
285
-        $moduleName = smart_getCurrentModuleName();
286
-    }
287
-    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
288
-    $ret     = smart_GetMeta($key, $moduleName);
289
-    if ('0' === $ret || $ret > 0) {
290
-        $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
291
-    } else {
292
-        $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
293
-    }
294
-    $ret = $xoopsDB->queryF($sql);
295
-    if (!$ret) {
296
-        return false;
297
-    }
298
-
299
-    return true;
284
+	if (!$moduleName) {
285
+		$moduleName = smart_getCurrentModuleName();
286
+	}
287
+	$xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
288
+	$ret     = smart_GetMeta($key, $moduleName);
289
+	if ('0' === $ret || $ret > 0) {
290
+		$sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
291
+	} else {
292
+		$sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
293
+	}
294
+	$ret = $xoopsDB->queryF($sql);
295
+	if (!$ret) {
296
+		return false;
297
+	}
298
+
299
+	return true;
300 300
 }
301 301
 
302 302
 // Thanks to Mithrandir:-)
@@ -309,20 +309,20 @@  discard block
 block discarded – undo
309 309
  */
310 310
 function smart_substr($str, $start, $length, $trimmarker = '...')
311 311
 {
312
-    // if the string is empty, let's get out ;-)
313
-    if ('' === $str) {
314
-        return $str;
315
-    }
316
-    // reverse a string that is shortened with '' as trimmarker
317
-    $reversed_string = strrev(xoops_substr($str, $start, $length, ''));
318
-    // find first space in reversed string
319
-    $position_of_space = strpos($reversed_string, ' ', 0);
320
-    // truncate the original string to a length of $length
321
-    // minus the position of the last space
322
-    // plus the length of the $trimmarker
323
-    $truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker);
324
-
325
-    return $truncated_string;
312
+	// if the string is empty, let's get out ;-)
313
+	if ('' === $str) {
314
+		return $str;
315
+	}
316
+	// reverse a string that is shortened with '' as trimmarker
317
+	$reversed_string = strrev(xoops_substr($str, $start, $length, ''));
318
+	// find first space in reversed string
319
+	$position_of_space = strpos($reversed_string, ' ', 0);
320
+	// truncate the original string to a length of $length
321
+	// minus the position of the last space
322
+	// plus the length of the $trimmarker
323
+	$truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker);
324
+
325
+	return $truncated_string;
326 326
 }
327 327
 
328 328
 /**
@@ -333,19 +333,19 @@  discard block
 block discarded – undo
333 333
  */
334 334
 function smart_getConfig($key, $moduleName = false, $default = 'default_is_undefined')
335 335
 {
336
-    if (!$moduleName) {
337
-        $moduleName = smart_getCurrentModuleName();
338
-    }
339
-    $configs = smart_getModuleConfig($moduleName);
340
-    if (isset($configs[$key])) {
341
-        return $configs[$key];
342
-    } else {
343
-        if ('default_is_undefined' === $default) {
344
-            return null;
345
-        } else {
346
-            return $default;
347
-        }
348
-    }
336
+	if (!$moduleName) {
337
+		$moduleName = smart_getCurrentModuleName();
338
+	}
339
+	$configs = smart_getModuleConfig($moduleName);
340
+	if (isset($configs[$key])) {
341
+		return $configs[$key];
342
+	} else {
343
+		if ('default_is_undefined' === $default) {
344
+			return null;
345
+		} else {
346
+			return $default;
347
+		}
348
+	}
349 349
 }
350 350
 
351 351
 /**
@@ -358,32 +358,32 @@  discard block
 block discarded – undo
358 358
  */
359 359
 function smart_copyr($source, $dest)
360 360
 {
361
-    // Simple copy for a file
362
-    if (is_file($source)) {
363
-        return copy($source, $dest);
364
-    }
365
-    // Make destination directory
366
-    if (!is_dir($dest)) {
367
-        mkdir($dest);
368
-    }
369
-    // Loop through the folder
370
-    $dir = dir($source);
371
-    while (false !== $entry = $dir->read()) {
372
-        // Skip pointers
373
-        if ('.' === $entry || '..' === $entry) {
374
-            continue;
375
-        }
376
-        // Deep copy directories
377
-        if (is_dir("$source/$entry") && ("$source/$entry" !== $dest)) {
378
-            copyr("$source/$entry", "$dest/$entry");
379
-        } else {
380
-            copy("$source/$entry", "$dest/$entry");
381
-        }
382
-    }
383
-    // Clean up
384
-    $dir->close();
385
-
386
-    return true;
361
+	// Simple copy for a file
362
+	if (is_file($source)) {
363
+		return copy($source, $dest);
364
+	}
365
+	// Make destination directory
366
+	if (!is_dir($dest)) {
367
+		mkdir($dest);
368
+	}
369
+	// Loop through the folder
370
+	$dir = dir($source);
371
+	while (false !== $entry = $dir->read()) {
372
+		// Skip pointers
373
+		if ('.' === $entry || '..' === $entry) {
374
+			continue;
375
+		}
376
+		// Deep copy directories
377
+		if (is_dir("$source/$entry") && ("$source/$entry" !== $dest)) {
378
+			copyr("$source/$entry", "$dest/$entry");
379
+		} else {
380
+			copy("$source/$entry", "$dest/$entry");
381
+		}
382
+	}
383
+	// Clean up
384
+	$dir->close();
385
+
386
+	return true;
387 387
 }
388 388
 
389 389
 /**
@@ -393,26 +393,26 @@  discard block
 block discarded – undo
393 393
  */
394 394
 function smart_admin_mkdir($target)
395 395
 {
396
-    // http://www.php.net/manual/en/function.mkdir.php
397
-    // saint at corenova.com
398
-    // bart at cdasites dot com
399
-    if (is_dir($target) || empty($target)) {
400
-        return true; // best case check first
401
-    }
402
-    if (file_exists($target) && !is_dir($target)) {
403
-        return false;
404
-    }
405
-    if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) {
406
-        if (!file_exists($target)) {
407
-            $res = mkdir($target, 0777); // crawl back up & create dir tree
408
-            smart_admin_chmod($target);
409
-
410
-            return $res;
411
-        }
412
-    }
413
-    $res = is_dir($target);
414
-
415
-    return $res;
396
+	// http://www.php.net/manual/en/function.mkdir.php
397
+	// saint at corenova.com
398
+	// bart at cdasites dot com
399
+	if (is_dir($target) || empty($target)) {
400
+		return true; // best case check first
401
+	}
402
+	if (file_exists($target) && !is_dir($target)) {
403
+		return false;
404
+	}
405
+	if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) {
406
+		if (!file_exists($target)) {
407
+			$res = mkdir($target, 0777); // crawl back up & create dir tree
408
+			smart_admin_chmod($target);
409
+
410
+			return $res;
411
+		}
412
+	}
413
+	$res = is_dir($target);
414
+
415
+	return $res;
416 416
 }
417 417
 
418 418
 /**
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
  */
424 424
 function smart_admin_chmod($target, $mode = 0777)
425 425
 {
426
-    return @ chmod($target, $mode);
426
+	return @ chmod($target, $mode);
427 427
 }
428 428
 
429 429
 /**
@@ -434,31 +434,31 @@  discard block
 block discarded – undo
434 434
  */
435 435
 function smart_imageResize($src, $maxWidth, $maxHeight)
436 436
 {
437
-    $width  = '';
438
-    $height = '';
439
-    $type   = '';
440
-    $attr   = '';
441
-    if (file_exists($src)) {
442
-        list($width, $height, $type, $attr) = getimagesize($src);
443
-        if ($width > $maxWidth) {
444
-            $originalWidth = $width;
445
-            $width         = $maxWidth;
446
-            $height        = $width * $height / $originalWidth;
447
-        }
448
-        if ($height > $maxHeight) {
449
-            $originalHeight = $height;
450
-            $height         = $maxHeight;
451
-            $width          = $height * $width / $originalHeight;
452
-        }
453
-        $attr = " width='$width' height='$height'";
454
-    }
455
-
456
-    return [
457
-        $width,
458
-        $height,
459
-        $type,
460
-        $attr
461
-    ];
437
+	$width  = '';
438
+	$height = '';
439
+	$type   = '';
440
+	$attr   = '';
441
+	if (file_exists($src)) {
442
+		list($width, $height, $type, $attr) = getimagesize($src);
443
+		if ($width > $maxWidth) {
444
+			$originalWidth = $width;
445
+			$width         = $maxWidth;
446
+			$height        = $width * $height / $originalWidth;
447
+		}
448
+		if ($height > $maxHeight) {
449
+			$originalHeight = $height;
450
+			$height         = $maxHeight;
451
+			$width          = $height * $width / $originalHeight;
452
+		}
453
+		$attr = " width='$width' height='$height'";
454
+	}
455
+
456
+	return [
457
+		$width,
458
+		$height,
459
+		$type,
460
+		$attr
461
+	];
462 462
 }
463 463
 
464 464
 /**
@@ -467,34 +467,34 @@  discard block
 block discarded – undo
467 467
  */
468 468
 function smart_getModuleInfo($moduleName = false)
469 469
 {
470
-    static $smartModules;
471
-    if (isset($smartModules[$moduleName])) {
472
-        $ret =& $smartModules[$moduleName];
473
-
474
-        return $ret;
475
-    }
476
-    global $xoopsModule;
477
-    if (!$moduleName) {
478
-        if (isset($xoopsModule) && is_object($xoopsModule)) {
479
-            $smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule;
480
-
481
-            return $smartModules[$xoopsModule->getVar('dirname')];
482
-        }
483
-    }
484
-    if (!isset($smartModules[$moduleName])) {
485
-        if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
486
-            $smartModules[$moduleName] = $xoopsModule;
487
-        } else {
488
-            $hModule = xoops_getHandler('module');
489
-            if ('xoops' !== $moduleName) {
490
-                $smartModules[$moduleName] = $hModule->getByDirname($moduleName);
491
-            } else {
492
-                $smartModules[$moduleName] = $hModule->getByDirname('system');
493
-            }
494
-        }
495
-    }
496
-
497
-    return $smartModules[$moduleName];
470
+	static $smartModules;
471
+	if (isset($smartModules[$moduleName])) {
472
+		$ret =& $smartModules[$moduleName];
473
+
474
+		return $ret;
475
+	}
476
+	global $xoopsModule;
477
+	if (!$moduleName) {
478
+		if (isset($xoopsModule) && is_object($xoopsModule)) {
479
+			$smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule;
480
+
481
+			return $smartModules[$xoopsModule->getVar('dirname')];
482
+		}
483
+	}
484
+	if (!isset($smartModules[$moduleName])) {
485
+		if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
486
+			$smartModules[$moduleName] = $xoopsModule;
487
+		} else {
488
+			$hModule = xoops_getHandler('module');
489
+			if ('xoops' !== $moduleName) {
490
+				$smartModules[$moduleName] = $hModule->getByDirname($moduleName);
491
+			} else {
492
+				$smartModules[$moduleName] = $hModule->getByDirname('system');
493
+			}
494
+		}
495
+	}
496
+
497
+	return $smartModules[$moduleName];
498 498
 }
499 499
 
500 500
 /**
@@ -503,40 +503,40 @@  discard block
 block discarded – undo
503 503
  */
504 504
 function smart_getModuleConfig($moduleName = false)
505 505
 {
506
-    static $smartConfigs;
507
-    if (isset($smartConfigs[$moduleName])) {
508
-        $ret =& $smartConfigs[$moduleName];
509
-
510
-        return $ret;
511
-    }
512
-    global $xoopsModule, $xoopsModuleConfig;
513
-    if (!$moduleName) {
514
-        if (isset($xoopsModule) && is_object($xoopsModule)) {
515
-            $smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig;
516
-
517
-            return $smartConfigs[$xoopsModule->getVar('dirname')];
518
-        }
519
-    }
520
-    // if we still did not found the xoopsModule, this is because there is none
521
-    if (!$moduleName) {
522
-        $ret = false;
523
-
524
-        return $ret;
525
-    }
526
-    if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
527
-        $smartConfigs[$moduleName] = $xoopsModuleConfig;
528
-    } else {
529
-        $module = smart_getModuleInfo($moduleName);
530
-        if (!is_object($module)) {
531
-            $ret = false;
532
-
533
-            return $ret;
534
-        }
535
-        $hModConfig                = xoops_getHandler('config');
536
-        $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
537
-    }
538
-
539
-    return $smartConfigs[$moduleName];
506
+	static $smartConfigs;
507
+	if (isset($smartConfigs[$moduleName])) {
508
+		$ret =& $smartConfigs[$moduleName];
509
+
510
+		return $ret;
511
+	}
512
+	global $xoopsModule, $xoopsModuleConfig;
513
+	if (!$moduleName) {
514
+		if (isset($xoopsModule) && is_object($xoopsModule)) {
515
+			$smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig;
516
+
517
+			return $smartConfigs[$xoopsModule->getVar('dirname')];
518
+		}
519
+	}
520
+	// if we still did not found the xoopsModule, this is because there is none
521
+	if (!$moduleName) {
522
+		$ret = false;
523
+
524
+		return $ret;
525
+	}
526
+	if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
527
+		$smartConfigs[$moduleName] = $xoopsModuleConfig;
528
+	} else {
529
+		$module = smart_getModuleInfo($moduleName);
530
+		if (!is_object($module)) {
531
+			$ret = false;
532
+
533
+			return $ret;
534
+		}
535
+		$hModConfig                = xoops_getHandler('config');
536
+		$smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
537
+	}
538
+
539
+	return $smartConfigs[$moduleName];
540 540
 }
541 541
 
542 542
 /**
@@ -545,10 +545,10 @@  discard block
 block discarded – undo
545 545
  */
546 546
 function smart_deleteFile($dirname)
547 547
 {
548
-    // Simple delete for a file
549
-    if (is_file($dirname)) {
550
-        return unlink($dirname);
551
-    }
548
+	// Simple delete for a file
549
+	if (is_file($dirname)) {
550
+		return unlink($dirname);
551
+	}
552 552
 }
553 553
 
554 554
 /**
@@ -557,12 +557,12 @@  discard block
 block discarded – undo
557 557
  */
558 558
 function smart_formatErrors($errors = [])
559 559
 {
560
-    $ret = '';
561
-    foreach ($errors as $key => $value) {
562
-        $ret .= '<br> - ' . $value;
563
-    }
560
+	$ret = '';
561
+	foreach ($errors as $key => $value) {
562
+		$ret .= '<br> - ' . $value;
563
+	}
564 564
 
565
-    return $ret;
565
+	return $ret;
566 566
 }
567 567
 
568 568
 /**
@@ -576,46 +576,46 @@  discard block
 block discarded – undo
576 576
  */
577 577
 function smart_getLinkedUnameFromId($userid = 0, $name = 0, $users = [], $withContact = false)
578 578
 {
579
-    if (!is_numeric($userid)) {
580
-        return $userid;
581
-    }
582
-    $userid = (int)$userid;
583
-    if ($userid > 0) {
584
-        if ($users == []) {
585
-            //fetching users
586
-            $memberHandler = xoops_getHandler('member');
587
-            $user          =& $memberHandler->getUser($userid);
588
-        } else {
589
-            if (!isset($users[$userid])) {
590
-                return $GLOBALS['xoopsConfig']['anonymous'];
591
-            }
592
-            $user =& $users[$userid];
593
-        }
594
-        if (is_object($user)) {
595
-            $ts        = MyTextSanitizer:: getInstance();
596
-            $username  = $user->getVar('uname');
597
-            $fullname  = '';
598
-            $fullname2 = $user->getVar('name');
599
-            if ($name && !empty($fullname2)) {
600
-                $fullname = $user->getVar('name');
601
-            }
602
-            if (!empty($fullname)) {
603
-                $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
604
-            } else {
605
-                $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
606
-            }
607
-            // add contact info: email + PM
608
-            if ($withContact) {
609
-                $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>';
610
-                $js         = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
611
-                $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>';
612
-            }
613
-
614
-            return $linkeduser;
615
-        }
616
-    }
617
-
618
-    return $GLOBALS['xoopsConfig']['anonymous'];
579
+	if (!is_numeric($userid)) {
580
+		return $userid;
581
+	}
582
+	$userid = (int)$userid;
583
+	if ($userid > 0) {
584
+		if ($users == []) {
585
+			//fetching users
586
+			$memberHandler = xoops_getHandler('member');
587
+			$user          =& $memberHandler->getUser($userid);
588
+		} else {
589
+			if (!isset($users[$userid])) {
590
+				return $GLOBALS['xoopsConfig']['anonymous'];
591
+			}
592
+			$user =& $users[$userid];
593
+		}
594
+		if (is_object($user)) {
595
+			$ts        = MyTextSanitizer:: getInstance();
596
+			$username  = $user->getVar('uname');
597
+			$fullname  = '';
598
+			$fullname2 = $user->getVar('name');
599
+			if ($name && !empty($fullname2)) {
600
+				$fullname = $user->getVar('name');
601
+			}
602
+			if (!empty($fullname)) {
603
+				$linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
604
+			} else {
605
+				$linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
606
+			}
607
+			// add contact info: email + PM
608
+			if ($withContact) {
609
+				$linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>';
610
+				$js         = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
611
+				$linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>';
612
+			}
613
+
614
+			return $linkeduser;
615
+		}
616
+	}
617
+
618
+	return $GLOBALS['xoopsConfig']['anonymous'];
619 619
 }
620 620
 
621 621
 /**
@@ -626,33 +626,33 @@  discard block
 block discarded – undo
626 626
  */
627 627
 function smart_adminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1)
628 628
 {
629
-    global $xoopsModule, $xoopsConfig;
630
-    require_once XOOPS_ROOT_PATH . '/class/template.php';
631
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
632
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
633
-    } else {
634
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
635
-    }
636
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
637
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
638
-    } else {
639
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
640
-    }
641
-    $headermenu  = [];
642
-    $adminObject = [];
643
-    include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
644
-    $tpl = new XoopsTpl();
645
-    $tpl->assign([
646
-                     'headermenu'      => $headermenu,
647
-                     'adminmenu'       => $adminObject,
648
-                     'current'         => $currentoption,
649
-                     'breadcrumb'      => $breadcrumb,
650
-                     'headermenucount' => count($headermenu),
651
-                     'submenus'        => $submenus,
652
-                     'currentsub'      => $currentsub,
653
-                     'submenuscount'   => count($submenus)
654
-                 ]);
655
-    $tpl->display('db:smartobject_admin_menu.tpl');
629
+	global $xoopsModule, $xoopsConfig;
630
+	require_once XOOPS_ROOT_PATH . '/class/template.php';
631
+	if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
632
+		require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
633
+	} else {
634
+		require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
635
+	}
636
+	if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
637
+		require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
638
+	} else {
639
+		require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
640
+	}
641
+	$headermenu  = [];
642
+	$adminObject = [];
643
+	include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
644
+	$tpl = new XoopsTpl();
645
+	$tpl->assign([
646
+					 'headermenu'      => $headermenu,
647
+					 'adminmenu'       => $adminObject,
648
+					 'current'         => $currentoption,
649
+					 'breadcrumb'      => $breadcrumb,
650
+					 'headermenucount' => count($headermenu),
651
+					 'submenus'        => $submenus,
652
+					 'currentsub'      => $currentsub,
653
+					 'submenuscount'   => count($submenus)
654
+				 ]);
655
+	$tpl->display('db:smartobject_admin_menu.tpl');
656 656
 }
657 657
 
658 658
 /**
@@ -662,13 +662,13 @@  discard block
 block discarded – undo
662 662
  */
663 663
 function smart_collapsableBar($id = '', $title = '', $dsc = '')
664 664
 {
665
-    global $xoopsModule;
666
-    echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>";
667
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
668
-    echo "<div id='" . $id . "'>";
669
-    if ('' !== $dsc) {
670
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
671
-    }
665
+	global $xoopsModule;
666
+	echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>";
667
+	echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
668
+	echo "<div id='" . $id . "'>";
669
+	if ('' !== $dsc) {
670
+		echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
671
+	}
672 672
 }
673 673
 
674 674
 /**
@@ -678,15 +678,15 @@  discard block
 block discarded – undo
678 678
  */
679 679
 function smart_ajaxCollapsableBar($id = '', $title = '', $dsc = '')
680 680
 {
681
-    global $xoopsModule;
682
-    $onClick = "ajaxtogglecollapse('$id')";
683
-    //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
684
-    echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
685
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
686
-    echo "<div id='" . $id . "'>";
687
-    if ('' !== $dsc) {
688
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
689
-    }
681
+	global $xoopsModule;
682
+	$onClick = "ajaxtogglecollapse('$id')";
683
+	//$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
684
+	echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
685
+	echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
686
+	echo "<div id='" . $id . "'>";
687
+	if ('' !== $dsc) {
688
+		echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
689
+	}
690 690
 }
691 691
 
692 692
 /**
@@ -713,20 +713,20 @@  discard block
 block discarded – undo
713 713
  */
714 714
 function smart_openclose_collapsable($name)
715 715
 {
716
-    $urls        = smart_getCurrentUrls();
717
-    $path        = $urls['phpself'];
718
-    $cookie_name = $path . '_smart_collaps_' . $name;
719
-    $cookie_name = str_replace('.', '_', $cookie_name);
720
-    $cookie      = smart_getCookieVar($cookie_name, '');
721
-    if ('none' === $cookie) {
722
-        echo '
716
+	$urls        = smart_getCurrentUrls();
717
+	$path        = $urls['phpself'];
718
+	$cookie_name = $path . '_smart_collaps_' . $name;
719
+	$cookie_name = str_replace('.', '_', $cookie_name);
720
+	$cookie      = smart_getCookieVar($cookie_name, '');
721
+	if ('none' === $cookie) {
722
+		echo '
723 723
                 <script type="text/javascript"><!--
724 724
                 togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon");
725 725
                     //-->
726 726
                 </script>
727 727
                 ';
728
-    }
729
-    /*  if ($cookie == 'none') {
728
+	}
729
+	/*  if ($cookie == 'none') {
730 730
      echo '
731 731
      <script type="text/javascript"><!--
732 732
      hideElement("' . $name . '");
@@ -742,9 +742,9 @@  discard block
 block discarded – undo
742 742
  */
743 743
 function smart_close_collapsable($name)
744 744
 {
745
-    echo '</div>';
746
-    smart_openclose_collapsable($name);
747
-    echo '<br>';
745
+	echo '</div>';
746
+	smart_openclose_collapsable($name);
747
+	echo '<br>';
748 748
 }
749 749
 
750 750
 /**
@@ -754,11 +754,11 @@  discard block
 block discarded – undo
754 754
  */
755 755
 function smart_setCookieVar($name, $value, $time = 0)
756 756
 {
757
-    if (0 == $time) {
758
-        $time = time() + 3600 * 24 * 365;
759
-        //$time = '';
760
-    }
761
-    setcookie($name, $value, $time, '/');
757
+	if (0 == $time) {
758
+		$time = time() + 3600 * 24 * 365;
759
+		//$time = '';
760
+	}
761
+	setcookie($name, $value, $time, '/');
762 762
 }
763 763
 
764 764
 /**
@@ -768,12 +768,12 @@  discard block
 block discarded – undo
768 768
  */
769 769
 function smart_getCookieVar($name, $default = '')
770 770
 {
771
-    $name = str_replace('.', '_', $name);
772
-    if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
773
-        return $_COOKIE[$name];
774
-    } else {
775
-        return $default;
776
-    }
771
+	$name = str_replace('.', '_', $name);
772
+	if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
773
+		return $_COOKIE[$name];
774
+	} else {
775
+		return $default;
776
+	}
777 777
 }
778 778
 
779 779
 /**
@@ -781,25 +781,25 @@  discard block
 block discarded – undo
781 781
  */
782 782
 function smart_getCurrentUrls()
783 783
 {
784
-    $urls        = [];
785
-    $http        = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://';
786
-    $phpself     = $_SERVER['PHP_SELF'];
787
-    $httphost    = $_SERVER['HTTP_HOST'];
788
-    $querystring = $_SERVER['QUERY_STRING'];
789
-    if ('' !== $querystring) {
790
-        $querystring = '?' . $querystring;
791
-    }
792
-    $currenturl           = $http . $httphost . $phpself . $querystring;
793
-    $urls                 = [];
794
-    $urls['http']         = $http;
795
-    $urls['httphost']     = $httphost;
796
-    $urls['phpself']      = $phpself;
797
-    $urls['querystring']  = $querystring;
798
-    $urls['full_phpself'] = $http . $httphost . $phpself;
799
-    $urls['full']         = $currenturl;
800
-    $urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
801
-
802
-    return $urls;
784
+	$urls        = [];
785
+	$http        = (false === strpos(XOOPS_URL, 'https://')) ? 'http://' : 'https://';
786
+	$phpself     = $_SERVER['PHP_SELF'];
787
+	$httphost    = $_SERVER['HTTP_HOST'];
788
+	$querystring = $_SERVER['QUERY_STRING'];
789
+	if ('' !== $querystring) {
790
+		$querystring = '?' . $querystring;
791
+	}
792
+	$currenturl           = $http . $httphost . $phpself . $querystring;
793
+	$urls                 = [];
794
+	$urls['http']         = $http;
795
+	$urls['httphost']     = $httphost;
796
+	$urls['phpself']      = $phpself;
797
+	$urls['querystring']  = $querystring;
798
+	$urls['full_phpself'] = $http . $httphost . $phpself;
799
+	$urls['full']         = $currenturl;
800
+	$urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
801
+
802
+	return $urls;
803 803
 }
804 804
 
805 805
 /**
@@ -807,9 +807,9 @@  discard block
 block discarded – undo
807 807
  */
808 808
 function smart_getCurrentPage()
809 809
 {
810
-    $urls = smart_getCurrentUrls();
810
+	$urls = smart_getCurrentUrls();
811 811
 
812
-    return $urls['full'];
812
+	return $urls['full'];
813 813
 }
814 814
 
815 815
 /**
@@ -872,29 +872,29 @@  discard block
 block discarded – undo
872 872
  */
873 873
 function smart_modFooter()
874 874
 {
875
-    global $xoopsConfig, $xoopsModule, $xoopsModuleConfig;
876
-
877
-    require_once XOOPS_ROOT_PATH . '/class/template.php';
878
-    $tpl = new XoopsTpl();
879
-
880
-    $hModule      = xoops_getHandler('module');
881
-    $versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
882
-    $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
883
-    $modfooter    = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>";
884
-    $tpl->assign('modfooter', $modfooter);
885
-
886
-    if (!defined('_AM_SOBJECT_XOOPS_PRO')) {
887
-        define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?');
888
-    }
889
-    $smartobjectConfig = smart_getModuleConfig('smartobject');
890
-    $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
891
-    $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl');
875
+	global $xoopsConfig, $xoopsModule, $xoopsModuleConfig;
876
+
877
+	require_once XOOPS_ROOT_PATH . '/class/template.php';
878
+	$tpl = new XoopsTpl();
879
+
880
+	$hModule      = xoops_getHandler('module');
881
+	$versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
882
+	$modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
883
+	$modfooter    = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>";
884
+	$tpl->assign('modfooter', $modfooter);
885
+
886
+	if (!defined('_AM_SOBJECT_XOOPS_PRO')) {
887
+		define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?');
888
+	}
889
+	$smartobjectConfig = smart_getModuleConfig('smartobject');
890
+	$tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
891
+	$tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl');
892 892
 }
893 893
 
894 894
 function smart_xoops_cp_footer()
895 895
 {
896
-    smart_modFooter();
897
-    xoops_cp_footer();
896
+	smart_modFooter();
897
+	xoops_cp_footer();
898 898
 }
899 899
 
900 900
 /**
@@ -903,11 +903,11 @@  discard block
 block discarded – undo
903 903
  */
904 904
 function smart_sanitizeForCommonTags($text)
905 905
 {
906
-    global $xoopsConfig;
907
-    $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text);
908
-    $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text);
906
+	global $xoopsConfig;
907
+	$text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text);
908
+	$text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text);
909 909
 
910
-    return $text;
910
+	return $text;
911 911
 }
912 912
 
913 913
 /**
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
  */
916 916
 function smart_addScript($src)
917 917
 {
918
-    echo '<script src="' . $src . '" type="text/javascript"></script>';
918
+	echo '<script src="' . $src . '" type="text/javascript"></script>';
919 919
 }
920 920
 
921 921
 /**
@@ -923,17 +923,17 @@  discard block
 block discarded – undo
923 923
  */
924 924
 function smart_addStyle($src)
925 925
 {
926
-    if ('smartobject' === $src) {
927
-        $src = SMARTOBJECT_URL . 'assets/css/module.css';
928
-    }
929
-    echo smart_get_css_link($src);
926
+	if ('smartobject' === $src) {
927
+		$src = SMARTOBJECT_URL . 'assets/css/module.css';
928
+	}
929
+	echo smart_get_css_link($src);
930 930
 }
931 931
 
932 932
 function smart_addAdminAjaxSupport()
933 933
 {
934
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
935
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
936
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
934
+	smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
935
+	smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
936
+	smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
937 937
 }
938 938
 
939 939
 /**
@@ -942,11 +942,11 @@  discard block
 block discarded – undo
942 942
  */
943 943
 function smart_sanitizeForSmartpopupLink($text)
944 944
 {
945
-    $patterns[]     = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU";
946
-    $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>";
947
-    $ret            = preg_replace($patterns, $replacements, $text);
945
+	$patterns[]     = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU";
946
+	$replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>";
947
+	$ret            = preg_replace($patterns, $replacements, $text);
948 948
 
949
-    return $ret;
949
+	return $ret;
950 950
 }
951 951
 
952 952
 /**
@@ -961,25 +961,25 @@  discard block
 block discarded – undo
961 961
  */
962 962
 function smart_getImageSize($url, & $width, & $height)
963 963
 {
964
-    if (empty($width) || empty($height)) {
965
-        if (!$dimension = @ getimagesize($url)) {
966
-            return false;
967
-        }
968
-        if (!empty($width)) {
969
-            $height = $dimension[1] * $width / $dimension[0];
970
-        } elseif (!empty($height)) {
971
-            $width = $dimension[0] * $height / $dimension[1];
972
-        } else {
973
-            list($width, $height) = [
974
-                $dimension[0],
975
-                $dimension[1]
976
-            ];
977
-        }
978
-
979
-        return true;
980
-    } else {
981
-        return true;
982
-    }
964
+	if (empty($width) || empty($height)) {
965
+		if (!$dimension = @ getimagesize($url)) {
966
+			return false;
967
+		}
968
+		if (!empty($width)) {
969
+			$height = $dimension[1] * $width / $dimension[0];
970
+		} elseif (!empty($height)) {
971
+			$width = $dimension[0] * $height / $dimension[1];
972
+		} else {
973
+			list($width, $height) = [
974
+				$dimension[0],
975
+				$dimension[1]
976
+			];
977
+		}
978
+
979
+		return true;
980
+	} else {
981
+		return true;
982
+	}
983 983
 }
984 984
 
985 985
 /**
@@ -992,10 +992,10 @@  discard block
 block discarded – undo
992 992
  */
993 993
 function smart_htmlnumericentities($str)
994 994
 {
995
-    //    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
996
-    return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) {
997
-        return '&#' . ord($m[0]) . chr(59);
998
-    }, $str);
995
+	//    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
996
+	return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) {
997
+		return '&#' . ord($m[0]) . chr(59);
998
+	}, $str);
999 999
 }
1000 1000
 
1001 1001
 /**
@@ -1005,24 +1005,24 @@  discard block
 block discarded – undo
1005 1005
  */
1006 1006
 function smart_getcorehandler($name, $optional = false)
1007 1007
 {
1008
-    static $handlers;
1009
-    $name = strtolower(trim($name));
1010
-    if (!isset($handlers[$name])) {
1011
-        if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1012
-            require_once $hnd_file;
1013
-        }
1014
-        $class = 'Xoops' . ucfirst($name) . 'Handler';
1015
-        if (class_exists($class)) {
1016
-            $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops');
1017
-        }
1018
-    }
1019
-    if (!isset($handlers[$name]) && !$optional) {
1020
-        trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1021
-    }
1022
-    if (isset($handlers[$name])) {
1023
-        return $handlers[$name];
1024
-    }
1025
-    $inst = false;
1008
+	static $handlers;
1009
+	$name = strtolower(trim($name));
1010
+	if (!isset($handlers[$name])) {
1011
+		if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1012
+			require_once $hnd_file;
1013
+		}
1014
+		$class = 'Xoops' . ucfirst($name) . 'Handler';
1015
+		if (class_exists($class)) {
1016
+			$handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops');
1017
+		}
1018
+	}
1019
+	if (!isset($handlers[$name]) && !$optional) {
1020
+		trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1021
+	}
1022
+	if (isset($handlers[$name])) {
1023
+		return $handlers[$name];
1024
+	}
1025
+	$inst = false;
1026 1026
 }
1027 1027
 
1028 1028
 /**
@@ -1031,15 +1031,15 @@  discard block
 block discarded – undo
1031 1031
  */
1032 1032
 function smart_sanitizeAdsenses_callback($matches)
1033 1033
 {
1034
-    global $smartobjectAdsenseHandler;
1035
-    if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) {
1036
-        $adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]];
1037
-        $ret        = $adsenseObj->render();
1038
-
1039
-        return $ret;
1040
-    } else {
1041
-        return '';
1042
-    }
1034
+	global $smartobjectAdsenseHandler;
1035
+	if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) {
1036
+		$adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]];
1037
+		$ret        = $adsenseObj->render();
1038
+
1039
+		return $ret;
1040
+	} else {
1041
+		return '';
1042
+	}
1043 1043
 }
1044 1044
 
1045 1045
 /**
@@ -1048,13 +1048,13 @@  discard block
 block discarded – undo
1048 1048
  */
1049 1049
 function smart_sanitizeAdsenses($text)
1050 1050
 {
1051
-    $patterns     = [];
1052
-    $replacements = [];
1051
+	$patterns     = [];
1052
+	$replacements = [];
1053 1053
 
1054
-    $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU";
1055
-    $text       = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text);
1054
+	$patterns[] = "/\[adsense](.*)\[\/adsense\]/sU";
1055
+	$text       = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text);
1056 1056
 
1057
-    return $text;
1057
+	return $text;
1058 1058
 }
1059 1059
 
1060 1060
 /**
@@ -1063,15 +1063,15 @@  discard block
 block discarded – undo
1063 1063
  */
1064 1064
 function smart_sanitizeCustomtags_callback($matches)
1065 1065
 {
1066
-    global $smartobjectCustomtagHandler;
1067
-    if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) {
1068
-        $customObj = $smartobjectCustomtagHandler->objects[$matches[1]];
1069
-        $ret       = $customObj->renderWithPhp();
1070
-
1071
-        return $ret;
1072
-    } else {
1073
-        return '';
1074
-    }
1066
+	global $smartobjectCustomtagHandler;
1067
+	if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) {
1068
+		$customObj = $smartobjectCustomtagHandler->objects[$matches[1]];
1069
+		$ret       = $customObj->renderWithPhp();
1070
+
1071
+		return $ret;
1072
+	} else {
1073
+		return '';
1074
+	}
1075 1075
 }
1076 1076
 
1077 1077
 /**
@@ -1080,13 +1080,13 @@  discard block
 block discarded – undo
1080 1080
  */
1081 1081
 function smart_sanitizeCustomtags($text)
1082 1082
 {
1083
-    $patterns     = [];
1084
-    $replacements = [];
1083
+	$patterns     = [];
1084
+	$replacements = [];
1085 1085
 
1086
-    $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU";
1087
-    $text       = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text);
1086
+	$patterns[] = "/\[customtag](.*)\[\/customtag\]/sU";
1087
+	$text       = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text);
1088 1088
 
1089
-    return $text;
1089
+	return $text;
1090 1090
 }
1091 1091
 
1092 1092
 /**
@@ -1095,20 +1095,20 @@  discard block
 block discarded – undo
1095 1095
  */
1096 1096
 function smart_loadLanguageFile($module, $file)
1097 1097
 {
1098
-    global $xoopsConfig;
1099
-
1100
-    $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1101
-    if (!file_exists($filename)) {
1102
-        $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1103
-    }
1104
-    if (file_exists($filename)) {
1105
-        require_once $filename;
1106
-    }
1098
+	global $xoopsConfig;
1099
+
1100
+	$filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1101
+	if (!file_exists($filename)) {
1102
+		$filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1103
+	}
1104
+	if (file_exists($filename)) {
1105
+		require_once $filename;
1106
+	}
1107 1107
 }
1108 1108
 
1109 1109
 function smart_loadCommonLanguageFile()
1110 1110
 {
1111
-    smart_loadLanguageFile('smartobject', 'common');
1111
+	smart_loadLanguageFile('smartobject', 'common');
1112 1112
 }
1113 1113
 
1114 1114
 /**
@@ -1118,35 +1118,35 @@  discard block
 block discarded – undo
1118 1118
  */
1119 1119
 function smart_purifyText($text, $keyword = false)
1120 1120
 {
1121
-    global $myts;
1122
-    $text = str_replace('&nbsp;', ' ', $text);
1123
-    $text = str_replace('<br>', ' ', $text);
1124
-    $text = str_replace('<br>', ' ', $text);
1125
-    $text = str_replace('<br', ' ', $text);
1126
-    $text = strip_tags($text);
1127
-    $text = html_entity_decode($text);
1128
-    $text = $myts->undoHtmlSpecialChars($text);
1129
-    $text = str_replace(')', ' ', $text);
1130
-    $text = str_replace('(', ' ', $text);
1131
-    $text = str_replace(':', ' ', $text);
1132
-    $text = str_replace('&euro', ' euro ', $text);
1133
-    $text = str_replace('&hellip', '...', $text);
1134
-    $text = str_replace('&rsquo', ' ', $text);
1135
-    $text = str_replace('!', ' ', $text);
1136
-    $text = str_replace('?', ' ', $text);
1137
-    $text = str_replace('"', ' ', $text);
1138
-    $text = str_replace('-', ' ', $text);
1139
-    $text = str_replace('\n', ' ', $text);
1140
-    $text = str_replace('&#8213;', ' ', $text);
1141
-
1142
-    if ($keyword) {
1143
-        $text = str_replace('.', ' ', $text);
1144
-        $text = str_replace(',', ' ', $text);
1145
-        $text = str_replace('\'', ' ', $text);
1146
-    }
1147
-    $text = str_replace(';', ' ', $text);
1148
-
1149
-    return $text;
1121
+	global $myts;
1122
+	$text = str_replace('&nbsp;', ' ', $text);
1123
+	$text = str_replace('<br>', ' ', $text);
1124
+	$text = str_replace('<br>', ' ', $text);
1125
+	$text = str_replace('<br', ' ', $text);
1126
+	$text = strip_tags($text);
1127
+	$text = html_entity_decode($text);
1128
+	$text = $myts->undoHtmlSpecialChars($text);
1129
+	$text = str_replace(')', ' ', $text);
1130
+	$text = str_replace('(', ' ', $text);
1131
+	$text = str_replace(':', ' ', $text);
1132
+	$text = str_replace('&euro', ' euro ', $text);
1133
+	$text = str_replace('&hellip', '...', $text);
1134
+	$text = str_replace('&rsquo', ' ', $text);
1135
+	$text = str_replace('!', ' ', $text);
1136
+	$text = str_replace('?', ' ', $text);
1137
+	$text = str_replace('"', ' ', $text);
1138
+	$text = str_replace('-', ' ', $text);
1139
+	$text = str_replace('\n', ' ', $text);
1140
+	$text = str_replace('&#8213;', ' ', $text);
1141
+
1142
+	if ($keyword) {
1143
+		$text = str_replace('.', ' ', $text);
1144
+		$text = str_replace(',', ' ', $text);
1145
+		$text = str_replace('\'', ' ', $text);
1146
+	}
1147
+	$text = str_replace(';', ' ', $text);
1148
+
1149
+	return $text;
1150 1150
 }
1151 1151
 
1152 1152
 /**
@@ -1155,51 +1155,51 @@  discard block
 block discarded – undo
1155 1155
  */
1156 1156
 function smart_html2text($document)
1157 1157
 {
1158
-    // PHP Manual:: function preg_replace
1159
-    // $document should contain an HTML document.
1160
-    // This will remove HTML tags, javascript sections
1161
-    // and white space. It will also convert some
1162
-    // common HTML entities to their text equivalent.
1163
-    // Credits: newbb2
1164
-    $search = [
1165
-        "'<script[^>]*?>.*?</script>'si", // Strip out javascript
1166
-        "'<img.*?>'si", // Strip out img tags
1167
-        "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
1168
-        "'([\r\n])[\s]+'", // Strip out white space
1169
-        "'&(quot|#34);'i", // Replace HTML entities
1170
-        "'&(amp|#38);'i",
1171
-        "'&(lt|#60);'i",
1172
-        "'&(gt|#62);'i",
1173
-        "'&(nbsp|#160);'i",
1174
-        "'&(iexcl|#161);'i",
1175
-        "'&(cent|#162);'i",
1176
-        "'&(pound|#163);'i",
1177
-        "'&(copy|#169);'i"
1178
-    ]; // evaluate as php
1179
-
1180
-    $replace = [
1181
-        '',
1182
-        '',
1183
-        '',
1184
-        "\\1",
1185
-        "\"",
1186
-        '&',
1187
-        '<',
1188
-        '>',
1189
-        ' ',
1190
-        chr(161),
1191
-        chr(162),
1192
-        chr(163),
1193
-        chr(169),
1194
-    ];
1195
-
1196
-    $text = preg_replace($search, $replace, $document);
1197
-
1198
-    preg_replace_callback('/&#(\d+);/', function ($matches) {
1199
-        return chr($matches[1]);
1200
-    }, $document);
1201
-
1202
-    return $text;
1158
+	// PHP Manual:: function preg_replace
1159
+	// $document should contain an HTML document.
1160
+	// This will remove HTML tags, javascript sections
1161
+	// and white space. It will also convert some
1162
+	// common HTML entities to their text equivalent.
1163
+	// Credits: newbb2
1164
+	$search = [
1165
+		"'<script[^>]*?>.*?</script>'si", // Strip out javascript
1166
+		"'<img.*?>'si", // Strip out img tags
1167
+		"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
1168
+		"'([\r\n])[\s]+'", // Strip out white space
1169
+		"'&(quot|#34);'i", // Replace HTML entities
1170
+		"'&(amp|#38);'i",
1171
+		"'&(lt|#60);'i",
1172
+		"'&(gt|#62);'i",
1173
+		"'&(nbsp|#160);'i",
1174
+		"'&(iexcl|#161);'i",
1175
+		"'&(cent|#162);'i",
1176
+		"'&(pound|#163);'i",
1177
+		"'&(copy|#169);'i"
1178
+	]; // evaluate as php
1179
+
1180
+	$replace = [
1181
+		'',
1182
+		'',
1183
+		'',
1184
+		"\\1",
1185
+		"\"",
1186
+		'&',
1187
+		'<',
1188
+		'>',
1189
+		' ',
1190
+		chr(161),
1191
+		chr(162),
1192
+		chr(163),
1193
+		chr(169),
1194
+	];
1195
+
1196
+	$text = preg_replace($search, $replace, $document);
1197
+
1198
+	preg_replace_callback('/&#(\d+);/', function ($matches) {
1199
+		return chr($matches[1]);
1200
+	}, $document);
1201
+
1202
+	return $text;
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1213,32 +1213,32 @@  discard block
 block discarded – undo
1213 1213
  */
1214 1214
 function smart_getfloat($str, $set = false)
1215 1215
 {
1216
-    if (preg_match("/([0-9\.,-]+)/", $str, $match)) {
1217
-        // Found number in $str, so set $str that number
1218
-        $str = $match[0];
1219
-        if (false !== strpos($str, ',')) {
1220
-            // A comma exists, that makes it easy, cos we assume it separates the decimal part.
1221
-            $str = str_replace('.', '', $str);    // Erase thousand seps
1222
-            $str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1223
-
1224
-            return (float)$str;
1225
-        } else {
1226
-            // No comma exists, so we have to decide, how a single dot shall be treated
1227
-            if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) {
1228
-                // Treat single dot as decimal separator
1229
-                return (float)$str;
1230
-            } else {
1231
-                //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1232
-                // Else, treat all dots as thousand seps
1233
-                $str = str_replace('.', '', $str);    // Erase thousand seps
1234
-
1235
-                return (float)$str;
1236
-            }
1237
-        }
1238
-    } else {
1239
-        // No number found, return zero
1240
-        return 0;
1241
-    }
1216
+	if (preg_match("/([0-9\.,-]+)/", $str, $match)) {
1217
+		// Found number in $str, so set $str that number
1218
+		$str = $match[0];
1219
+		if (false !== strpos($str, ',')) {
1220
+			// A comma exists, that makes it easy, cos we assume it separates the decimal part.
1221
+			$str = str_replace('.', '', $str);    // Erase thousand seps
1222
+			$str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1223
+
1224
+			return (float)$str;
1225
+		} else {
1226
+			// No comma exists, so we have to decide, how a single dot shall be treated
1227
+			if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) {
1228
+				// Treat single dot as decimal separator
1229
+				return (float)$str;
1230
+			} else {
1231
+				//echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1232
+				// Else, treat all dots as thousand seps
1233
+				$str = str_replace('.', '', $str);    // Erase thousand seps
1234
+
1235
+				return (float)$str;
1236
+			}
1237
+		}
1238
+	} else {
1239
+		// No number found, return zero
1240
+		return 0;
1241
+	}
1242 1242
 }
1243 1243
 
1244 1244
 /**
@@ -1248,26 +1248,26 @@  discard block
 block discarded – undo
1248 1248
  */
1249 1249
 function smart_currency($var, $currencyObj = false)
1250 1250
 {
1251
-    $ret = smart_getfloat($var, ['single_dot_as_decimal' => true]);
1252
-    $ret = round($ret, 2);
1253
-    // make sur we have at least .00 in the $var
1254
-    $decimal_section_original = strstr($ret, '.');
1255
-    $decimal_section          = $decimal_section_original;
1256
-    if ($decimal_section) {
1257
-        if (1 == strlen($decimal_section)) {
1258
-            $decimal_section = '.00';
1259
-        } elseif (2 == strlen($decimal_section)) {
1260
-            $decimal_section .= '0';
1261
-        }
1262
-        $ret = str_replace($decimal_section_original, $decimal_section, $ret);
1263
-    } else {
1264
-        $ret .= '.00';
1265
-    }
1266
-    if ($currencyObj) {
1267
-        $ret = $ret . ' ' . $currencyObj->getCode();
1268
-    }
1269
-
1270
-    return $ret;
1251
+	$ret = smart_getfloat($var, ['single_dot_as_decimal' => true]);
1252
+	$ret = round($ret, 2);
1253
+	// make sur we have at least .00 in the $var
1254
+	$decimal_section_original = strstr($ret, '.');
1255
+	$decimal_section          = $decimal_section_original;
1256
+	if ($decimal_section) {
1257
+		if (1 == strlen($decimal_section)) {
1258
+			$decimal_section = '.00';
1259
+		} elseif (2 == strlen($decimal_section)) {
1260
+			$decimal_section .= '0';
1261
+		}
1262
+		$ret = str_replace($decimal_section_original, $decimal_section, $ret);
1263
+	} else {
1264
+		$ret .= '.00';
1265
+	}
1266
+	if ($currencyObj) {
1267
+		$ret = $ret . ' ' . $currencyObj->getCode();
1268
+	}
1269
+
1270
+	return $ret;
1271 1271
 }
1272 1272
 
1273 1273
 /**
@@ -1276,7 +1276,7 @@  discard block
 block discarded – undo
1276 1276
  */
1277 1277
 function smart_float($var)
1278 1278
 {
1279
-    return smart_currency($var);
1279
+	return smart_currency($var);
1280 1280
 }
1281 1281
 
1282 1282
 /**
@@ -1285,16 +1285,16 @@  discard block
 block discarded – undo
1285 1285
  */
1286 1286
 function smart_getModuleAdminLink($moduleName = false)
1287 1287
 {
1288
-    global $xoopsModule;
1289
-    if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) {
1290
-        $moduleName = $xoopsModule->getVar('dirname');
1291
-    }
1292
-    $ret = '';
1293
-    if ($moduleName) {
1294
-        $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1295
-    }
1296
-
1297
-    return $ret;
1288
+	global $xoopsModule;
1289
+	if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) {
1290
+		$moduleName = $xoopsModule->getVar('dirname');
1291
+	}
1292
+	$ret = '';
1293
+	if ($moduleName) {
1294
+		$ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1295
+	}
1296
+
1297
+	return $ret;
1298 1298
 }
1299 1299
 
1300 1300
 /**
@@ -1302,19 +1302,19 @@  discard block
 block discarded – undo
1302 1302
  */
1303 1303
 function smart_getEditors()
1304 1304
 {
1305
-    $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1306
-    if (!file_exists($filename)) {
1307
-        return false;
1308
-    }
1309
-    require_once $filename;
1310
-    $xoopseditorHandler = XoopsEditorHandler::getInstance();
1311
-    $aList              = $xoopseditorHandler->getList();
1312
-    $ret                = [];
1313
-    foreach ($aList as $k => $v) {
1314
-        $ret[$v] = $k;
1315
-    }
1316
-
1317
-    return $ret;
1305
+	$filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1306
+	if (!file_exists($filename)) {
1307
+		return false;
1308
+	}
1309
+	require_once $filename;
1310
+	$xoopseditorHandler = XoopsEditorHandler::getInstance();
1311
+	$aList              = $xoopseditorHandler->getList();
1312
+	$ret                = [];
1313
+	foreach ($aList as $k => $v) {
1314
+		$ret[$v] = $k;
1315
+	}
1316
+
1317
+	return $ret;
1318 1318
 }
1319 1319
 
1320 1320
 /**
@@ -1324,11 +1324,11 @@  discard block
 block discarded – undo
1324 1324
  */
1325 1325
 function smart_getTablesArray($moduleName, $items)
1326 1326
 {
1327
-    $ret = [];
1328
-    foreach ($items as $item) {
1329
-        $ret[] = $moduleName . '_' . $item;
1330
-    }
1331
-    $ret[] = $moduleName . '_meta';
1327
+	$ret = [];
1328
+	foreach ($items as $item) {
1329
+		$ret[] = $moduleName . '_' . $item;
1330
+	}
1331
+	$ret[] = $moduleName . '_meta';
1332 1332
 
1333
-    return $ret;
1333
+	return $ret;
1334 1334
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 function smart_get_css_link($cssfile)
13 13
 {
14
-    $ret = '<link rel="stylesheet" type="text/css" href="' . $cssfile . '">';
14
+    $ret = '<link rel="stylesheet" type="text/css" href="'.$cssfile.'">';
15 15
 
16 16
     return $ret;
17 17
 }
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
         $seoMode = smart_getModuleModeSEO($moduleName);
103 103
         if ('rewrite' === $seoMode) {
104 104
             $seoModuleName = smart_getModuleNameForSEO($moduleName);
105
-            $ret           = XOOPS_URL . '/' . $seoModuleName . '/';
105
+            $ret           = XOOPS_URL.'/'.$seoModuleName.'/';
106 106
         } elseif ('pathinfo' === $seoMode) {
107
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
107
+            $ret = XOOPS_URL.'/modules/'.$moduleName.'/seo.php/'.$seoModuleName.'/';
108 108
         } else {
109
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/';
109
+            $ret = XOOPS_URL.'/modules/'.$moduleName.'/';
110 110
         }
111 111
 
112
-        return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
112
+        return '<a href="'.$ret.'">'.$smartModule->getVar('name').'</a>';
113 113
     }
114 114
 }
115 115
 
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
     /**
173 173
      * include SmartObject admin language file
174 174
      */
175
-    $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
175
+    $fileName = XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/admin.php';
176 176
     if (file_exists($fileName)) {
177 177
         require_once $fileName;
178 178
     } else {
179
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
179
+        require_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/admin.php';
180 180
     } ?>
181 181
     <script type='text/javascript'>
182 182
         <!--
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
     /**
194 194
      * Include the admin language constants for the SmartObject Framework
195 195
      */
196
-    $admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php';
196
+    $admin_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/admin.php';
197 197
     if (!file_exists($admin_file)) {
198
-        $admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php';
198
+        $admin_file = SMARTOBJECT_ROOT_PATH.'language/english/admin.php';
199 199
     }
200 200
     require_once $admin_file;
201 201
 }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
     //Verifies that a MySQL table exists
216 216
     $xoopsDB  = XoopsDatabaseFactory::getDatabaseConnection();
217 217
     $realname = $xoopsDB->prefix($table);
218
-    $sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
218
+    $sql      = 'SHOW TABLES FROM '.XOOPS_DB_NAME;
219 219
     $ret      = $xoopsDB->queryF($sql);
220 220
     while (list($m_table) = $xoopsDB->fetchRow($ret)) {
221 221
         if ($m_table == $realname) {
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         $moduleName = smart_getCurrentModuleName();
245 245
     }
246 246
     $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
247
-    $sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
247
+    $sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($key));
248 248
     $ret     = $xoopsDB->query($sql);
249 249
     if (!$ret) {
250 250
         $value = false;
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
     $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
288 288
     $ret     = smart_GetMeta($key, $moduleName);
289 289
     if ('0' === $ret || $ret > 0) {
290
-        $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
290
+        $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
291 291
     } else {
292
-        $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
292
+        $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
293 293
     }
294 294
     $ret = $xoopsDB->queryF($sql);
295 295
     if (!$ret) {
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
 {
470 470
     static $smartModules;
471 471
     if (isset($smartModules[$moduleName])) {
472
-        $ret =& $smartModules[$moduleName];
472
+        $ret = & $smartModules[$moduleName];
473 473
 
474 474
         return $ret;
475 475
     }
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 {
506 506
     static $smartConfigs;
507 507
     if (isset($smartConfigs[$moduleName])) {
508
-        $ret =& $smartConfigs[$moduleName];
508
+        $ret = & $smartConfigs[$moduleName];
509 509
 
510 510
         return $ret;
511 511
     }
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
             return $ret;
534 534
         }
535 535
         $hModConfig                = xoops_getHandler('config');
536
-        $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
536
+        $smartConfigs[$moduleName] = & $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
537 537
     }
538 538
 
539 539
     return $smartConfigs[$moduleName];
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 {
560 560
     $ret = '';
561 561
     foreach ($errors as $key => $value) {
562
-        $ret .= '<br> - ' . $value;
562
+        $ret .= '<br> - '.$value;
563 563
     }
564 564
 
565 565
     return $ret;
@@ -579,17 +579,17 @@  discard block
 block discarded – undo
579 579
     if (!is_numeric($userid)) {
580 580
         return $userid;
581 581
     }
582
-    $userid = (int)$userid;
582
+    $userid = (int) $userid;
583 583
     if ($userid > 0) {
584 584
         if ($users == []) {
585 585
             //fetching users
586 586
             $memberHandler = xoops_getHandler('member');
587
-            $user          =& $memberHandler->getUser($userid);
587
+            $user          = & $memberHandler->getUser($userid);
588 588
         } else {
589 589
             if (!isset($users[$userid])) {
590 590
                 return $GLOBALS['xoopsConfig']['anonymous'];
591 591
             }
592
-            $user =& $users[$userid];
592
+            $user = & $users[$userid];
593 593
         }
594 594
         if (is_object($user)) {
595 595
             $ts        = MyTextSanitizer:: getInstance();
@@ -600,15 +600,15 @@  discard block
 block discarded – undo
600 600
                 $fullname = $user->getVar('name');
601 601
             }
602 602
             if (!empty($fullname)) {
603
-                $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
603
+                $linkeduser = "$fullname [<a href='".XOOPS_URL.'/userinfo.php?uid='.$userid."'>".$ts->htmlSpecialChars($username).'</a>]';
604 604
             } else {
605
-                $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
605
+                $linkeduser = "<a href='".XOOPS_URL.'/userinfo.php?uid='.$userid."'>".ucwords($ts->htmlSpecialChars($username)).'</a>';
606 606
             }
607 607
             // add contact info: email + PM
608 608
             if ($withContact) {
609
-                $linkeduser .= ' <a href="mailto:' . $user->getVar('email') . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/email.gif' . '" alt="' . _CO_SOBJECT_SEND_EMAIL . '" title="' . _CO_SOBJECT_SEND_EMAIL . '"></a>';
610
-                $js         = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
611
-                $linkeduser .= ' <a href="' . $js . '"><img style="vertical-align: middle;" src="' . XOOPS_URL . '/images/icons/pm.gif' . '" alt="' . _CO_SOBJECT_SEND_PM . '" title="' . _CO_SOBJECT_SEND_PM . '"></a>';
609
+                $linkeduser .= ' <a href="mailto:'.$user->getVar('email').'"><img style="vertical-align: middle;" src="'.XOOPS_URL.'/images/icons/email.gif'.'" alt="'._CO_SOBJECT_SEND_EMAIL.'" title="'._CO_SOBJECT_SEND_EMAIL.'"></a>';
610
+                $js = "javascript:openWithSelfMain('".XOOPS_URL.'/pmlite.php?send2=1&to_userid='.$userid."', 'pmlite',450,370);";
611
+                $linkeduser .= ' <a href="'.$js.'"><img style="vertical-align: middle;" src="'.XOOPS_URL.'/images/icons/pm.gif'.'" alt="'._CO_SOBJECT_SEND_PM.'" title="'._CO_SOBJECT_SEND_PM.'"></a>';
612 612
             }
613 613
 
614 614
             return $linkeduser;
@@ -627,20 +627,20 @@  discard block
 block discarded – undo
627 627
 function smart_adminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1)
628 628
 {
629 629
     global $xoopsModule, $xoopsConfig;
630
-    require_once XOOPS_ROOT_PATH . '/class/template.php';
631
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
632
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
630
+    require_once XOOPS_ROOT_PATH.'/class/template.php';
631
+    if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/modinfo.php')) {
632
+        require_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/modinfo.php';
633 633
     } else {
634
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
634
+        require_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/modinfo.php';
635 635
     }
636
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
637
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
636
+    if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/admin.php')) {
637
+        require_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/admin.php';
638 638
     } else {
639
-        require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
639
+        require_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/admin.php';
640 640
     }
641 641
     $headermenu  = [];
642 642
     $adminObject = [];
643
-    include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
643
+    include XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/admin/menu.php';
644 644
     $tpl = new XoopsTpl();
645 645
     $tpl->assign([
646 646
                      'headermenu'      => $headermenu,
@@ -663,11 +663,11 @@  discard block
 block discarded – undo
663 663
 function smart_collapsableBar($id = '', $title = '', $dsc = '')
664 664
 {
665 665
     global $xoopsModule;
666
-    echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('" . $id . "'); toggleIcon('" . $id . "_icon')\";>";
667
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
668
-    echo "<div id='" . $id . "'>";
666
+    echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"togglecollapse('".$id."'); toggleIcon('".$id."_icon')\";>";
667
+    echo "<img id='".$id."_icon' src=".SMARTOBJECT_URL."assets/images/close12.gif alt=''></a>&nbsp;".$title.'</h3>';
668
+    echo "<div id='".$id."'>";
669 669
     if ('' !== $dsc) {
670
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
670
+        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">".$dsc.'</span>';
671 671
     }
672 672
 }
673 673
 
@@ -681,11 +681,11 @@  discard block
 block discarded – undo
681 681
     global $xoopsModule;
682 682
     $onClick = "ajaxtogglecollapse('$id')";
683 683
     //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
684
-    echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
685
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt=''></a>&nbsp;" . $title . '</h3>';
686
-    echo "<div id='" . $id . "'>";
684
+    echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="'.$onClick.'">';
685
+    echo "<img id='".$id."_icon' src=".SMARTOBJECT_URL."assets/images/close12.gif alt=''></a>&nbsp;".$title.'</h3>';
686
+    echo "<div id='".$id."'>";
687 687
     if ('' !== $dsc) {
688
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
688
+        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">".$dsc.'</span>';
689 689
     }
690 690
 }
691 691
 
@@ -715,13 +715,13 @@  discard block
 block discarded – undo
715 715
 {
716 716
     $urls        = smart_getCurrentUrls();
717 717
     $path        = $urls['phpself'];
718
-    $cookie_name = $path . '_smart_collaps_' . $name;
718
+    $cookie_name = $path.'_smart_collaps_'.$name;
719 719
     $cookie_name = str_replace('.', '_', $cookie_name);
720 720
     $cookie      = smart_getCookieVar($cookie_name, '');
721 721
     if ('none' === $cookie) {
722 722
         echo '
723 723
                 <script type="text/javascript"><!--
724
-                togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon");
724
+                togglecollapse("' . $name.'"); toggleIcon("'.$name.'_icon");
725 725
                     //-->
726 726
                 </script>
727 727
                 ';
@@ -787,17 +787,17 @@  discard block
 block discarded – undo
787 787
     $httphost    = $_SERVER['HTTP_HOST'];
788 788
     $querystring = $_SERVER['QUERY_STRING'];
789 789
     if ('' !== $querystring) {
790
-        $querystring = '?' . $querystring;
790
+        $querystring = '?'.$querystring;
791 791
     }
792
-    $currenturl           = $http . $httphost . $phpself . $querystring;
792
+    $currenturl           = $http.$httphost.$phpself.$querystring;
793 793
     $urls                 = [];
794 794
     $urls['http']         = $http;
795 795
     $urls['httphost']     = $httphost;
796 796
     $urls['phpself']      = $phpself;
797 797
     $urls['querystring']  = $querystring;
798
-    $urls['full_phpself'] = $http . $httphost . $phpself;
798
+    $urls['full_phpself'] = $http.$httphost.$phpself;
799 799
     $urls['full']         = $currenturl;
800
-    $urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
800
+    $urls['isHomePage']   = (XOOPS_URL.'/index.php') == ($http.$httphost.$phpself);
801 801
 
802 802
     return $urls;
803 803
 }
@@ -874,13 +874,13 @@  discard block
 block discarded – undo
874 874
 {
875 875
     global $xoopsConfig, $xoopsModule, $xoopsModuleConfig;
876 876
 
877
-    require_once XOOPS_ROOT_PATH . '/class/template.php';
877
+    require_once XOOPS_ROOT_PATH.'/class/template.php';
878 878
     $tpl = new XoopsTpl();
879 879
 
880 880
     $hModule      = xoops_getHandler('module');
881
-    $versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
882
-    $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
883
-    $modfooter    = "<a href='" . $versioninfo->getInfo('support_site_url') . "' target='_blank'><img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/cssbutton.gif' title='" . $modfootertxt . "' alt='" . $modfootertxt . "'></a>";
881
+    $versioninfo  = & $hModule->get($xoopsModule->getVar('mid'));
882
+    $modfootertxt = 'Module '.$versioninfo->getInfo('name').' - Version '.$versioninfo->getInfo('version').'';
883
+    $modfooter    = "<a href='".$versioninfo->getInfo('support_site_url')."' target='_blank'><img src='".XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/assets/images/cssbutton.gif' title='".$modfootertxt."' alt='".$modfootertxt."'></a>";
884 884
     $tpl->assign('modfooter', $modfooter);
885 885
 
886 886
     if (!defined('_AM_SOBJECT_XOOPS_PRO')) {
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
     }
889 889
     $smartobjectConfig = smart_getModuleConfig('smartobject');
890 890
     $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
891
-    $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.tpl');
891
+    $tpl->display(SMARTOBJECT_ROOT_PATH.'templates/smartobject_admin_footer.tpl');
892 892
 }
893 893
 
894 894
 function smart_xoops_cp_footer()
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
  */
916 916
 function smart_addScript($src)
917 917
 {
918
-    echo '<script src="' . $src . '" type="text/javascript"></script>';
918
+    echo '<script src="'.$src.'" type="text/javascript"></script>';
919 919
 }
920 920
 
921 921
 /**
@@ -924,16 +924,16 @@  discard block
 block discarded – undo
924 924
 function smart_addStyle($src)
925 925
 {
926 926
     if ('smartobject' === $src) {
927
-        $src = SMARTOBJECT_URL . 'assets/css/module.css';
927
+        $src = SMARTOBJECT_URL.'assets/css/module.css';
928 928
     }
929 929
     echo smart_get_css_link($src);
930 930
 }
931 931
 
932 932
 function smart_addAdminAjaxSupport()
933 933
 {
934
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
935
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
936
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
934
+    smart_addScript(SMARTOBJECT_URL.'include/scriptaculous/lib/prototype.js');
935
+    smart_addScript(SMARTOBJECT_URL.'include/scriptaculous/src/scriptaculous.js');
936
+    smart_addScript(SMARTOBJECT_URL.'include/scriptaculous/src/smart.js');
937 937
 }
938 938
 
939 939
 /**
@@ -993,8 +993,8 @@  discard block
 block discarded – undo
993 993
 function smart_htmlnumericentities($str)
994 994
 {
995 995
     //    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
996
-    return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) {
997
-        return '&#' . ord($m[0]) . chr(59);
996
+    return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function($m) {
997
+        return '&#'.ord($m[0]).chr(59);
998 998
     }, $str);
999 999
 }
1000 1000
 
@@ -1008,16 +1008,16 @@  discard block
 block discarded – undo
1008 1008
     static $handlers;
1009 1009
     $name = strtolower(trim($name));
1010 1010
     if (!isset($handlers[$name])) {
1011
-        if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1011
+        if (file_exists($hnd_file = XOOPS_ROOT_PATH.'/kernel/'.$name.'.php')) {
1012 1012
             require_once $hnd_file;
1013 1013
         }
1014
-        $class = 'Xoops' . ucfirst($name) . 'Handler';
1014
+        $class = 'Xoops'.ucfirst($name).'Handler';
1015 1015
         if (class_exists($class)) {
1016 1016
             $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops');
1017 1017
         }
1018 1018
     }
1019 1019
     if (!isset($handlers[$name]) && !$optional) {
1020
-        trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1020
+        trigger_error('Class <b>'.$class.'</b> does not exist<br>Handler Name: '.$name, E_USER_ERROR);
1021 1021
     }
1022 1022
     if (isset($handlers[$name])) {
1023 1023
         return $handlers[$name];
@@ -1097,9 +1097,9 @@  discard block
 block discarded – undo
1097 1097
 {
1098 1098
     global $xoopsConfig;
1099 1099
 
1100
-    $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1100
+    $filename = XOOPS_ROOT_PATH.'/modules/'.$module.'/language/'.$xoopsConfig['language'].'/'.$file.'.php';
1101 1101
     if (!file_exists($filename)) {
1102
-        $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1102
+        $filename = XOOPS_ROOT_PATH.'/modules/'.$module.'/language/english/'.$file.'.php';
1103 1103
     }
1104 1104
     if (file_exists($filename)) {
1105 1105
         require_once $filename;
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
 
1196 1196
     $text = preg_replace($search, $replace, $document);
1197 1197
 
1198
-    preg_replace_callback('/&#(\d+);/', function ($matches) {
1198
+    preg_replace_callback('/&#(\d+);/', function($matches) {
1199 1199
         return chr($matches[1]);
1200 1200
     }, $document);
1201 1201
 
@@ -1218,21 +1218,21 @@  discard block
 block discarded – undo
1218 1218
         $str = $match[0];
1219 1219
         if (false !== strpos($str, ',')) {
1220 1220
             // A comma exists, that makes it easy, cos we assume it separates the decimal part.
1221
-            $str = str_replace('.', '', $str);    // Erase thousand seps
1222
-            $str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1221
+            $str = str_replace('.', '', $str); // Erase thousand seps
1222
+            $str = str_replace(',', '.', $str); // Convert , to . for floatval command
1223 1223
 
1224
-            return (float)$str;
1224
+            return (float) $str;
1225 1225
         } else {
1226 1226
             // No comma exists, so we have to decide, how a single dot shall be treated
1227 1227
             if (true === preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) && true === $set['single_dot_as_decimal']) {
1228 1228
                 // Treat single dot as decimal separator
1229
-                return (float)$str;
1229
+                return (float) $str;
1230 1230
             } else {
1231 1231
                 //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1232 1232
                 // Else, treat all dots as thousand seps
1233
-                $str = str_replace('.', '', $str);    // Erase thousand seps
1233
+                $str = str_replace('.', '', $str); // Erase thousand seps
1234 1234
 
1235
-                return (float)$str;
1235
+                return (float) $str;
1236 1236
             }
1237 1237
         }
1238 1238
     } else {
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
         $ret .= '.00';
1265 1265
     }
1266 1266
     if ($currencyObj) {
1267
-        $ret = $ret . ' ' . $currencyObj->getCode();
1267
+        $ret = $ret.' '.$currencyObj->getCode();
1268 1268
     }
1269 1269
 
1270 1270
     return $ret;
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
     }
1292 1292
     $ret = '';
1293 1293
     if ($moduleName) {
1294
-        $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1294
+        $ret = "<a href='".XOOPS_URL."/modules/$moduleName/admin/index.php'>"._CO_SOBJECT_ADMIN_PAGE.'</a>';
1295 1295
     }
1296 1296
 
1297 1297
     return $ret;
@@ -1302,7 +1302,7 @@  discard block
 block discarded – undo
1302 1302
  */
1303 1303
 function smart_getEditors()
1304 1304
 {
1305
-    $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1305
+    $filename = XOOPS_ROOT_PATH.'/class/xoopseditor/xoopseditor.php';
1306 1306
     if (!file_exists($filename)) {
1307 1307
         return false;
1308 1308
     }
@@ -1326,9 +1326,9 @@  discard block
 block discarded – undo
1326 1326
 {
1327 1327
     $ret = [];
1328 1328
     foreach ($items as $item) {
1329
-        $ret[] = $moduleName . '_' . $item;
1329
+        $ret[] = $moduleName.'_'.$item;
1330 1330
     }
1331
-    $ret[] = $moduleName . '_meta';
1331
+    $ret[] = $moduleName.'_meta';
1332 1332
 
1333 1333
     return $ret;
1334 1334
 }
Please login to merge, or discard this patch.
include/captcha/scripts/img.php 2 patches
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $xoopsLogger->activated = false;
11 11
 
12 12
 if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', $_SERVER['HTTP_REFERER'])) {
13
-    exit();
13
+	exit();
14 14
 }
15 15
 
16 16
 /**
@@ -18,192 +18,192 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class XoopsCaptchaImageHandler
20 20
 {
21
-    public $config = [];
22
-    //var $mode = "gd"; // GD or bmp
23
-    public $code;
24
-    public $invalid = false;
25
-
26
-    public $font;
27
-    public $spacing;
28
-    public $width;
29
-    public $height;
30
-
31
-    /**
32
-     * XoopsCaptchaImageHandler constructor.
33
-     */
34
-    public function __construct()
35
-    {
36
-        if (empty($_SESSION['XoopsCaptcha_name'])) {
37
-            $this->invalid = true;
38
-        }
39
-
40
-        if (!extension_loaded('gd')) {
41
-            $this->mode = 'bmp';
42
-        } else {
43
-            $required_functions = [
44
-                'imagecreatetruecolor',
45
-                'imagecolorallocate',
46
-                'imagefilledrectangle',
47
-                'imagejpeg',
48
-                'imagedestroy',
49
-                'imageftbbox'
50
-            ];
51
-            foreach ($required_functions as $func) {
52
-                if (!function_exists($func)) {
53
-                    $this->mode = 'bmp';
54
-                    break;
55
-                }
56
-            }
57
-        }
58
-    }
59
-
60
-    /**
61
-     * Loading configs from CAPTCHA class
62
-     * @param array $config
63
-     */
64
-    public function setConfig($config = [])
65
-    {
66
-        // Loading default preferences
67
-        $this->config = $config;
68
-    }
69
-
70
-    public function loadImage()
71
-    {
72
-        $this->createCode();
73
-        $this->setCode();
74
-        $this->createImage();
75
-    }
76
-
77
-    /**
78
-     * Create Code
79
-     */
80
-    public function createCode()
81
-    {
82
-        if ($this->invalid) {
83
-            return;
84
-        }
85
-
86
-        if ('bmp' === $this->mode) {
87
-            $this->config['num_chars'] = 4;
88
-            $this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9'));
89
-        } else {
90
-            $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']);
91
-            if (!$this->config['casesensitive']) {
92
-                $this->code = strtoupper($this->code);
93
-            }
94
-        }
95
-    }
96
-
97
-    public function setCode()
98
-    {
99
-        if ($this->invalid) {
100
-            return;
101
-        }
102
-
103
-        $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code;
104
-        $maxAttempts                          = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
105
-
106
-        // Increase the attempt records on refresh
107
-        if (!empty($maxAttempts)) {
108
-            $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++;
109
-            if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
110
-                $this->invalid = true;
111
-            }
112
-        }
113
-    }
114
-
115
-    /**
116
-     * @param  string $file
117
-     * @return string|void
118
-     */
119
-    public function createImage($file = '')
120
-    {
121
-        if ($this->invalid) {
122
-            header('Content-type: image/gif');
123
-            readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif');
124
-
125
-            return;
126
-        }
127
-
128
-        if ('bmp' === $this->mode) {
129
-            return $this->createImageBmp();
130
-        } else {
131
-            return $this->createImageGd();
132
-        }
133
-    }
134
-
135
-    /**
136
-     *  Create CAPTCHA iamge with GD
137
-     *  Originated from DuGris' SecurityImage
138
-     * @param string $file
139
-     */
140
-    //  --------------------------------------------------------------------------- //
141
-    // Class: SecurityImage 1.5                                                    //
142
-    // Author: DuGris aka L. Jen <http://www.dugris.info>                           //
143
-    // Email: [email protected]                                                    //
144
-    // Licence: GNU                                                                 //
145
-    // Project: XOOPS Project                                                   //
146
-    //  --------------------------------------------------------------------------- //
147
-    public function createImageGd($file = '')
148
-    {
149
-        $this->loadFont();
150
-        $this->setImageSize();
151
-
152
-        $this->oImage = imagecreatetruecolor($this->width, $this->height);
153
-        $background   = imagecolorallocate($this->oImage, 255, 255, 255);
154
-        imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background);
155
-
156
-        switch ($this->config['background_type']) {
157
-            default:
158
-            case 0:
159
-                $this->drawBars();
160
-                break;
161
-
162
-            case 1:
163
-                $this->drawCircles();
164
-                break;
165
-
166
-            case 2:
167
-                $this->drawLines();
168
-                break;
169
-
170
-            case 3:
171
-                $this->drawRectangles();
172
-                break;
173
-
174
-            case 4:
175
-                $this->drawEllipses();
176
-                break;
177
-
178
-            case 5:
179
-                $this->drawPolygons();
180
-                break;
181
-
182
-            case 100:
183
-                $this->createFromFile();
184
-                break;
185
-        }
186
-        $this->drawBorder();
187
-        $this->drawCode();
188
-
189
-        if (empty($file)) {
190
-            header('Content-type: image/jpeg');
191
-            imagejpeg($this->oImage);
192
-        } else {
193
-            imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg');
194
-        }
195
-        imagedestroy($this->oImage);
196
-    }
197
-
198
-    /**
199
-     * @param         $name
200
-     * @param  string $extension
201
-     * @return array
202
-     */
203
-    public function _getList($name, $extension = '')
204
-    {
205
-        $items = [];
206
-        /*
21
+	public $config = [];
22
+	//var $mode = "gd"; // GD or bmp
23
+	public $code;
24
+	public $invalid = false;
25
+
26
+	public $font;
27
+	public $spacing;
28
+	public $width;
29
+	public $height;
30
+
31
+	/**
32
+	 * XoopsCaptchaImageHandler constructor.
33
+	 */
34
+	public function __construct()
35
+	{
36
+		if (empty($_SESSION['XoopsCaptcha_name'])) {
37
+			$this->invalid = true;
38
+		}
39
+
40
+		if (!extension_loaded('gd')) {
41
+			$this->mode = 'bmp';
42
+		} else {
43
+			$required_functions = [
44
+				'imagecreatetruecolor',
45
+				'imagecolorallocate',
46
+				'imagefilledrectangle',
47
+				'imagejpeg',
48
+				'imagedestroy',
49
+				'imageftbbox'
50
+			];
51
+			foreach ($required_functions as $func) {
52
+				if (!function_exists($func)) {
53
+					$this->mode = 'bmp';
54
+					break;
55
+				}
56
+			}
57
+		}
58
+	}
59
+
60
+	/**
61
+	 * Loading configs from CAPTCHA class
62
+	 * @param array $config
63
+	 */
64
+	public function setConfig($config = [])
65
+	{
66
+		// Loading default preferences
67
+		$this->config = $config;
68
+	}
69
+
70
+	public function loadImage()
71
+	{
72
+		$this->createCode();
73
+		$this->setCode();
74
+		$this->createImage();
75
+	}
76
+
77
+	/**
78
+	 * Create Code
79
+	 */
80
+	public function createCode()
81
+	{
82
+		if ($this->invalid) {
83
+			return;
84
+		}
85
+
86
+		if ('bmp' === $this->mode) {
87
+			$this->config['num_chars'] = 4;
88
+			$this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9'));
89
+		} else {
90
+			$this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']);
91
+			if (!$this->config['casesensitive']) {
92
+				$this->code = strtoupper($this->code);
93
+			}
94
+		}
95
+	}
96
+
97
+	public function setCode()
98
+	{
99
+		if ($this->invalid) {
100
+			return;
101
+		}
102
+
103
+		$_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code;
104
+		$maxAttempts                          = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
105
+
106
+		// Increase the attempt records on refresh
107
+		if (!empty($maxAttempts)) {
108
+			$_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++;
109
+			if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
110
+				$this->invalid = true;
111
+			}
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * @param  string $file
117
+	 * @return string|void
118
+	 */
119
+	public function createImage($file = '')
120
+	{
121
+		if ($this->invalid) {
122
+			header('Content-type: image/gif');
123
+			readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif');
124
+
125
+			return;
126
+		}
127
+
128
+		if ('bmp' === $this->mode) {
129
+			return $this->createImageBmp();
130
+		} else {
131
+			return $this->createImageGd();
132
+		}
133
+	}
134
+
135
+	/**
136
+	 *  Create CAPTCHA iamge with GD
137
+	 *  Originated from DuGris' SecurityImage
138
+	 * @param string $file
139
+	 */
140
+	//  --------------------------------------------------------------------------- //
141
+	// Class: SecurityImage 1.5                                                    //
142
+	// Author: DuGris aka L. Jen <http://www.dugris.info>                           //
143
+	// Email: [email protected]                                                    //
144
+	// Licence: GNU                                                                 //
145
+	// Project: XOOPS Project                                                   //
146
+	//  --------------------------------------------------------------------------- //
147
+	public function createImageGd($file = '')
148
+	{
149
+		$this->loadFont();
150
+		$this->setImageSize();
151
+
152
+		$this->oImage = imagecreatetruecolor($this->width, $this->height);
153
+		$background   = imagecolorallocate($this->oImage, 255, 255, 255);
154
+		imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background);
155
+
156
+		switch ($this->config['background_type']) {
157
+			default:
158
+			case 0:
159
+				$this->drawBars();
160
+				break;
161
+
162
+			case 1:
163
+				$this->drawCircles();
164
+				break;
165
+
166
+			case 2:
167
+				$this->drawLines();
168
+				break;
169
+
170
+			case 3:
171
+				$this->drawRectangles();
172
+				break;
173
+
174
+			case 4:
175
+				$this->drawEllipses();
176
+				break;
177
+
178
+			case 5:
179
+				$this->drawPolygons();
180
+				break;
181
+
182
+			case 100:
183
+				$this->createFromFile();
184
+				break;
185
+		}
186
+		$this->drawBorder();
187
+		$this->drawCode();
188
+
189
+		if (empty($file)) {
190
+			header('Content-type: image/jpeg');
191
+			imagejpeg($this->oImage);
192
+		} else {
193
+			imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg');
194
+		}
195
+		imagedestroy($this->oImage);
196
+	}
197
+
198
+	/**
199
+	 * @param         $name
200
+	 * @param  string $extension
201
+	 * @return array
202
+	 */
203
+	public function _getList($name, $extension = '')
204
+	{
205
+		$items = [];
206
+		/*
207 207
          if (@ require_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") {
208 208
          load_functions("cache");
209 209
          if ($items = mod_loadCacheFile("captcha_{$name}", "captcha")) {
@@ -211,231 +211,231 @@  discard block
 block discarded – undo
211 211
          }
212 212
          }
213 213
          */
214
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
215
-        $file_path = $this->config['rootpath'] . "/{$name}";
216
-        $files     = XoopsLists::getFileListAsArray($file_path);
217
-        foreach ($files as $item) {
218
-            if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) {
219
-                $items[] = $item;
220
-            }
221
-        }
222
-        if (function_exists('mod_createCacheFile')) {
223
-            mod_createCacheFile($items, "captcha_{$name}", 'captcha');
224
-        }
225
-
226
-        return $items;
227
-    }
228
-
229
-    public function loadFont()
230
-    {
231
-        $fonts      = $this->_getList('fonts', 'ttf');
232
-        $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)];
233
-    }
234
-
235
-    public function setImageSize()
236
-    {
237
-        $MaxCharWidth  = 0;
238
-        $MaxCharHeight = 0;
239
-        $oImage        = imagecreatetruecolor(100, 100);
240
-        $text_color    = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
241
-        $FontSize      = $this->config['fontsize_max'];
242
-        for ($Angle = -30; $Angle <= 30; ++$Angle) {
243
-            for ($i = 65; $i <= 90; ++$i) {
244
-                $CharDetails   = imageftbbox($FontSize, $Angle, $this->font, chr($i), []);
245
-                $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]);
246
-                if ($_MaxCharWidth > $MaxCharWidth) {
247
-                    $MaxCharWidth = $_MaxCharWidth;
248
-                }
249
-                $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]);
250
-                if ($_MaxCharHeight > $MaxCharHeight) {
251
-                    $MaxCharHeight = $_MaxCharHeight;
252
-                }
253
-            }
254
-        }
255
-        imagedestroy($oImage);
256
-
257
-        $this->height  = $MaxCharHeight + 2;
258
-        $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
259
-        $this->width   = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2);
260
-    }
261
-
262
-    /**
263
-     * Return random background
264
-     *
265
-     * @return array
266
-     */
267
-    public function loadBackground()
268
-    {
269
-        $RandBackground = null;
270
-        if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) {
271
-            $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)];
272
-        }
273
-
274
-        return $RandBackground;
275
-    }
276
-
277
-    /**
278
-     * Draw Image background
279
-     */
280
-    public function createFromFile()
281
-    {
282
-        if ($RandImage = $this->loadBackground()) {
283
-            $ImageType = @getimagesize($RandImage);
284
-            switch (@$ImageType[2]) {
285
-                case 1:
286
-                    $BackgroundImage = imagecreatefromgif($RandImage);
287
-                    break;
288
-
289
-                case 2:
290
-                    $BackgroundImage = imagecreatefromjpeg($RandImage);
291
-                    break;
292
-
293
-                case 3:
294
-                    $BackgroundImage = imagecreatefrompng($RandImage);
295
-                    break;
296
-            }
297
-        }
298
-        if (!empty($BackgroundImage)) {
299
-            imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage));
300
-            imagedestroy($BackgroundImage);
301
-        } else {
302
-            $this->drawBars();
303
-        }
304
-    }
305
-
306
-    /**
307
-     * Draw Code
308
-     */
309
-    public function drawCode()
310
-    {
311
-        for ($i = 0; $i < $this->config['num_chars']; ++$i) {
312
-            // select random greyscale colour
313
-            $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
314
-
315
-            // write text to image
316
-            $Angle = mt_rand(10, 30);
317
-            if ($i % 2) {
318
-                $Angle = mt_rand(-10, -30);
319
-            }
320
-
321
-            // select random font size
322
-            $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']);
323
-
324
-            $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []);
325
-            $CharHeight  = abs($CharDetails[1] + $CharDetails[5]);
326
-
327
-            // calculate character starting coordinates
328
-            $posX = ($this->spacing / 2) + ($i * $this->spacing);
329
-            $posY = 2 + ($this->height / 2) + ($CharHeight / 4);
330
-
331
-            imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []);
332
-        }
333
-    }
334
-
335
-    /**
336
-     * Draw Border
337
-     */
338
-    public function drawBorder()
339
-    {
340
-        $rgb          = mt_rand(50, 150);
341
-        $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb);
342
-        imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color);
343
-    }
344
-
345
-    /**
346
-     * Draw Circles background
347
-     */
348
-    public function drawCircles()
349
-    {
350
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
351
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
352
-            imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor);
353
-        }
354
-    }
355
-
356
-    /**
357
-     * Draw Lines background
358
-     */
359
-    public function drawLines()
360
-    {
361
-        for ($i = 0; $i < $this->config['background_num']; ++$i) {
362
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
363
-            imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
364
-        }
365
-    }
366
-
367
-    /**
368
-     * Draw Rectangles background
369
-     */
370
-    public function drawRectangles()
371
-    {
372
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
373
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
374
-            imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
375
-        }
376
-    }
377
-
378
-    /**
379
-     * Draw Bars background
380
-     */
381
-    public function drawBars()
382
-    {
383
-        for ($i = 0; $i <= $this->height;) {
384
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
385
-            imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor);
386
-            $i += 2.5;
387
-        }
388
-        for ($i = 0; $i <= $this->width;) {
389
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
390
-            imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor);
391
-            $i += 2.5;
392
-        }
393
-    }
394
-
395
-    /**
396
-     * Draw Ellipses background
397
-     */
398
-    public function drawEllipses()
399
-    {
400
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
401
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
402
-            imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
403
-        }
404
-    }
405
-
406
-    /**
407
-     * Draw polygons background
408
-     */
409
-    public function drawPolygons()
410
-    {
411
-        for ($i = 1; $i <= $this->config['background_num']; ++$i) {
412
-            $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
413
-            $coords      = [];
414
-            for ($j = 1; $j <= $this->config['polygon_point']; ++$j) {
415
-                $coords[] = mt_rand(0, $this->width);
416
-                $coords[] = mt_rand(0, $this->height);
417
-            }
418
-            imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor);
419
-        }
420
-    }
421
-
422
-    /**
423
-     *  Create CAPTCHA iamge with BMP
424
-     *  TODO
425
-     * @param  string $file
426
-     * @return string
427
-     */
428
-    public function createImageBmp($file = '')
429
-    {
430
-        $image = '';
431
-
432
-        if (empty($file)) {
433
-            header('Content-type: image/bmp');
434
-            echo $image;
435
-        } else {
436
-            return $image;
437
-        }
438
-    }
214
+		require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
215
+		$file_path = $this->config['rootpath'] . "/{$name}";
216
+		$files     = XoopsLists::getFileListAsArray($file_path);
217
+		foreach ($files as $item) {
218
+			if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) {
219
+				$items[] = $item;
220
+			}
221
+		}
222
+		if (function_exists('mod_createCacheFile')) {
223
+			mod_createCacheFile($items, "captcha_{$name}", 'captcha');
224
+		}
225
+
226
+		return $items;
227
+	}
228
+
229
+	public function loadFont()
230
+	{
231
+		$fonts      = $this->_getList('fonts', 'ttf');
232
+		$this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)];
233
+	}
234
+
235
+	public function setImageSize()
236
+	{
237
+		$MaxCharWidth  = 0;
238
+		$MaxCharHeight = 0;
239
+		$oImage        = imagecreatetruecolor(100, 100);
240
+		$text_color    = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
241
+		$FontSize      = $this->config['fontsize_max'];
242
+		for ($Angle = -30; $Angle <= 30; ++$Angle) {
243
+			for ($i = 65; $i <= 90; ++$i) {
244
+				$CharDetails   = imageftbbox($FontSize, $Angle, $this->font, chr($i), []);
245
+				$_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]);
246
+				if ($_MaxCharWidth > $MaxCharWidth) {
247
+					$MaxCharWidth = $_MaxCharWidth;
248
+				}
249
+				$_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]);
250
+				if ($_MaxCharHeight > $MaxCharHeight) {
251
+					$MaxCharHeight = $_MaxCharHeight;
252
+				}
253
+			}
254
+		}
255
+		imagedestroy($oImage);
256
+
257
+		$this->height  = $MaxCharHeight + 2;
258
+		$this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
259
+		$this->width   = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2);
260
+	}
261
+
262
+	/**
263
+	 * Return random background
264
+	 *
265
+	 * @return array
266
+	 */
267
+	public function loadBackground()
268
+	{
269
+		$RandBackground = null;
270
+		if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) {
271
+			$RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)];
272
+		}
273
+
274
+		return $RandBackground;
275
+	}
276
+
277
+	/**
278
+	 * Draw Image background
279
+	 */
280
+	public function createFromFile()
281
+	{
282
+		if ($RandImage = $this->loadBackground()) {
283
+			$ImageType = @getimagesize($RandImage);
284
+			switch (@$ImageType[2]) {
285
+				case 1:
286
+					$BackgroundImage = imagecreatefromgif($RandImage);
287
+					break;
288
+
289
+				case 2:
290
+					$BackgroundImage = imagecreatefromjpeg($RandImage);
291
+					break;
292
+
293
+				case 3:
294
+					$BackgroundImage = imagecreatefrompng($RandImage);
295
+					break;
296
+			}
297
+		}
298
+		if (!empty($BackgroundImage)) {
299
+			imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage));
300
+			imagedestroy($BackgroundImage);
301
+		} else {
302
+			$this->drawBars();
303
+		}
304
+	}
305
+
306
+	/**
307
+	 * Draw Code
308
+	 */
309
+	public function drawCode()
310
+	{
311
+		for ($i = 0; $i < $this->config['num_chars']; ++$i) {
312
+			// select random greyscale colour
313
+			$text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
314
+
315
+			// write text to image
316
+			$Angle = mt_rand(10, 30);
317
+			if ($i % 2) {
318
+				$Angle = mt_rand(-10, -30);
319
+			}
320
+
321
+			// select random font size
322
+			$FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']);
323
+
324
+			$CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []);
325
+			$CharHeight  = abs($CharDetails[1] + $CharDetails[5]);
326
+
327
+			// calculate character starting coordinates
328
+			$posX = ($this->spacing / 2) + ($i * $this->spacing);
329
+			$posY = 2 + ($this->height / 2) + ($CharHeight / 4);
330
+
331
+			imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []);
332
+		}
333
+	}
334
+
335
+	/**
336
+	 * Draw Border
337
+	 */
338
+	public function drawBorder()
339
+	{
340
+		$rgb          = mt_rand(50, 150);
341
+		$border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb);
342
+		imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color);
343
+	}
344
+
345
+	/**
346
+	 * Draw Circles background
347
+	 */
348
+	public function drawCircles()
349
+	{
350
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
351
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
352
+			imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor);
353
+		}
354
+	}
355
+
356
+	/**
357
+	 * Draw Lines background
358
+	 */
359
+	public function drawLines()
360
+	{
361
+		for ($i = 0; $i < $this->config['background_num']; ++$i) {
362
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
363
+			imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
364
+		}
365
+	}
366
+
367
+	/**
368
+	 * Draw Rectangles background
369
+	 */
370
+	public function drawRectangles()
371
+	{
372
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
373
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
374
+			imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
375
+		}
376
+	}
377
+
378
+	/**
379
+	 * Draw Bars background
380
+	 */
381
+	public function drawBars()
382
+	{
383
+		for ($i = 0; $i <= $this->height;) {
384
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
385
+			imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor);
386
+			$i += 2.5;
387
+		}
388
+		for ($i = 0; $i <= $this->width;) {
389
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
390
+			imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor);
391
+			$i += 2.5;
392
+		}
393
+	}
394
+
395
+	/**
396
+	 * Draw Ellipses background
397
+	 */
398
+	public function drawEllipses()
399
+	{
400
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
401
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
402
+			imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
403
+		}
404
+	}
405
+
406
+	/**
407
+	 * Draw polygons background
408
+	 */
409
+	public function drawPolygons()
410
+	{
411
+		for ($i = 1; $i <= $this->config['background_num']; ++$i) {
412
+			$randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
413
+			$coords      = [];
414
+			for ($j = 1; $j <= $this->config['polygon_point']; ++$j) {
415
+				$coords[] = mt_rand(0, $this->width);
416
+				$coords[] = mt_rand(0, $this->height);
417
+			}
418
+			imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor);
419
+		}
420
+	}
421
+
422
+	/**
423
+	 *  Create CAPTCHA iamge with BMP
424
+	 *  TODO
425
+	 * @param  string $file
426
+	 * @return string
427
+	 */
428
+	public function createImageBmp($file = '')
429
+	{
430
+		$image = '';
431
+
432
+		if (empty($file)) {
433
+			header('Content-type: image/bmp');
434
+			echo $image;
435
+		} else {
436
+			return $image;
437
+		}
438
+	}
439 439
 }
440 440
 
441 441
 $config       = @include __DIR__ . '/../config.php';
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@  discard block
 block discarded – undo
5 5
  * D.J.
6 6
  */
7 7
 
8
-include dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/mainfile.php';
8
+include dirname(dirname(dirname(dirname(dirname(__DIR__))))).'/mainfile.php';
9 9
 error_reporting(0);
10 10
 $xoopsLogger->activated = false;
11 11
 
12
-if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', $_SERVER['HTTP_REFERER'])) {
12
+if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/^'.preg_quote(XOOPS_URL, '/').'/', $_SERVER['HTTP_REFERER'])) {
13 13
     exit();
14 14
 }
15 15
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
         if ('bmp' === $this->mode) {
87 87
             $this->config['num_chars'] = 4;
88
-            $this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9'));
88
+            $this->code                = mt_rand(pow(10, $this->config['num_chars'] - 1), (int) str_pad('9', $this->config['num_chars'], '9'));
89 89
         } else {
90 90
             $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']);
91 91
             if (!$this->config['casesensitive']) {
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
             return;
101 101
         }
102 102
 
103
-        $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code;
104
-        $maxAttempts                          = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
103
+        $_SESSION['XoopsCaptcha_sessioncode'] = (string) $this->code;
104
+        $maxAttempts                          = (int) (@$_SESSION['XoopsCaptcha_maxattempts']);
105 105
 
106 106
         // Increase the attempt records on refresh
107 107
         if (!empty($maxAttempts)) {
108
-            $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++;
109
-            if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
108
+            $_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']]++;
109
+            if ($_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']] > $maxAttempts) {
110 110
                 $this->invalid = true;
111 111
             }
112 112
         }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     {
121 121
         if ($this->invalid) {
122 122
             header('Content-type: image/gif');
123
-            readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif');
123
+            readfile(XOOPS_ROOT_PATH.'/images/subject/icon2.gif');
124 124
 
125 125
             return;
126 126
         }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             header('Content-type: image/jpeg');
191 191
             imagejpeg($this->oImage);
192 192
         } else {
193
-            imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg');
193
+            imagejpeg($this->oImage, XOOPS_ROOT_PATH.'/'.$this->config['imagepath'].'/'.$file.'.jpg');
194 194
         }
195 195
         imagedestroy($this->oImage);
196 196
     }
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
          }
212 212
          }
213 213
          */
214
-        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
215
-        $file_path = $this->config['rootpath'] . "/{$name}";
214
+        require_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
215
+        $file_path = $this->config['rootpath']."/{$name}";
216 216
         $files     = XoopsLists::getFileListAsArray($file_path);
217 217
         foreach ($files as $item) {
218 218
             if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) {
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
     public function loadFont()
230 230
     {
231 231
         $fonts      = $this->_getList('fonts', 'ttf');
232
-        $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)];
232
+        $this->font = $this->config['rootpath'].'/fonts/'.$fonts[array_rand($fonts)];
233 233
     }
234 234
 
235 235
     public function setImageSize()
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         imagedestroy($oImage);
256 256
 
257 257
         $this->height  = $MaxCharHeight + 2;
258
-        $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
258
+        $this->spacing = (int) (($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']);
259 259
         $this->width   = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2);
260 260
     }
261 261
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     {
269 269
         $RandBackground = null;
270 270
         if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) {
271
-            $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)];
271
+            $RandBackground = $this->config['rootpath'].'/backgrounds/'.$backgrounds[array_rand($backgrounds)];
272 272
         }
273 273
 
274 274
         return $RandBackground;
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
     }
439 439
 }
440 440
 
441
-$config       = @include __DIR__ . '/../config.php';
441
+$config       = @include __DIR__.'/../config.php';
442 442
 $imageHandler = new XoopsCaptchaImageHandler();
443 443
 $imageHandler->setConfig($config);
444 444
 $imageHandler->loadImage();
Please login to merge, or discard this patch.
include/captcha/captcha.php 2 patches
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -13,253 +13,253 @@
 block discarded – undo
13 13
  */
14 14
 class XoopsCaptcha
15 15
 {
16
-    public $active = true;
17
-    public $mode   = 'text';    // potential values: image, text
18
-    public $config = [];
19
-
20
-    public $message = []; // Logging error messages
21
-
22
-    /**
23
-     * XoopsCaptcha constructor.
24
-     */
25
-    public function __construct()
26
-    {
27
-        // Loading default preferences
28
-        $this->config = @include __DIR__ . '/config.php';
29
-
30
-        $this->setMode($this->config['mode']);
31
-    }
32
-
33
-    /**
34
-     * @return XoopsCaptcha
35
-     */
36
-    public static function getInstance()
37
-    {
38
-        static $instance;
39
-        if (null === $instance) {
40
-            $instance = new static();
41
-        }
42
-
43
-        return $instance;
44
-    }
45
-
46
-    /**
47
-     * @param $name
48
-     * @param $val
49
-     * @return bool
50
-     */
51
-    public function setConfig($name, $val)
52
-    {
53
-        if ('mode' === $name) {
54
-            $this->setMode($val);
55
-        } elseif (isset($this->$name)) {
56
-            $this->$name = $val;
57
-        } else {
58
-            $this->config[$name] = $val;
59
-        }
60
-
61
-        return true;
62
-    }
63
-
64
-    /**
65
-     * Set CAPTCHA mode
66
-     *
67
-     * For future possible modes, right now force to use text or image
68
-     *
69
-     * @param string $mode if no mode is set, just verify current mode
70
-     */
71
-    public function setMode($mode = null)
72
-    {
73
-        if (!empty($mode) && in_array($mode, ['text', 'image'])) {
74
-            $this->mode = $mode;
75
-
76
-            if ('image' !== $this->mode) {
77
-                return;
78
-            }
79
-        }
80
-
81
-        // Disable image mode
82
-        if (!extension_loaded('gd')) {
83
-            $this->mode = 'text';
84
-        } else {
85
-            $required_functions = [
86
-                'imagecreatetruecolor',
87
-                'imagecolorallocate',
88
-                'imagefilledrectangle',
89
-                'imagejpeg',
90
-                'imagedestroy',
91
-                'imageftbbox'
92
-            ];
93
-            foreach ($required_functions as $func) {
94
-                if (!function_exists($func)) {
95
-                    $this->mode = 'text';
96
-                    break;
97
-                }
98
-            }
99
-        }
100
-    }
101
-
102
-    /**
103
-     * Initializing the CAPTCHA class
104
-     * @param string $name
105
-     * @param null   $skipmember
106
-     * @param null   $num_chars
107
-     * @param null   $fontsize_min
108
-     * @param null   $fontsize_max
109
-     * @param null   $background_type
110
-     * @param null   $background_num
111
-     */
112
-    public function init(
113
-        $name = 'xoopscaptcha',
114
-        $skipmember = null,
115
-        $num_chars = null,
116
-        $fontsize_min = null,
117
-        $fontsize_max = null,
118
-        $background_type = null,
119
-        $background_num = null
120
-    ) {
121
-        // Loading RUN-TIME settings
122
-        foreach (array_keys($this->config) as $key) {
123
-            if (isset(${$key}) && null !== ${$key}) {
124
-                $this->config[$key] = ${$key};
125
-            }
126
-        }
127
-        $this->config['name'] = $name;
128
-
129
-        // Skip CAPTCHA for member if set
130
-        if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) {
131
-            $this->active = false;
132
-        }
133
-    }
134
-
135
-    /**
136
-     * Verify user submission
137
-     * @param  null $skipMember
138
-     * @return bool
139
-     */
140
-    public function verify($skipMember = null)
141
-    {
142
-        $sessionName = @$_SESSION['XoopsCaptcha_name'];
143
-        $skipMember  = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember;
144
-        $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
145
-
146
-        $is_valid = false;
147
-
148
-        // Skip CAPTCHA for member if set
149
-        if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) {
150
-            $is_valid = true;
151
-            // Kill too many attempts
152
-        } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) {
153
-            $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
154
-
155
-            // Verify the code
156
-        } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) {
157
-            $func     = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp';
158
-            $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']);
159
-        }
160
-
161
-        if (!empty($maxAttempts)) {
162
-            if (!$is_valid) {
163
-                // Increase the attempt records on failure
164
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++;
165
-                // Log the error message
166
-                $this->message[] = XOOPS_CAPTCHA_INVALID_CODE;
167
-            } else {
168
-
169
-                // reset attempt records on success
170
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null;
171
-            }
172
-        }
173
-        $this->destroyGarbage(true);
174
-
175
-        return $is_valid;
176
-    }
177
-
178
-    /**
179
-     * @return mixed|string
180
-     */
181
-    public function getCaption()
182
-    {
183
-        return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : '';
184
-    }
185
-
186
-    /**
187
-     * @return string
188
-     */
189
-    public function getMessage()
190
-    {
191
-        return implode('<br>', $this->message);
192
-    }
193
-
194
-    /**
195
-     * Destory historical stuff
196
-     * @param  bool $clearSession
197
-     * @return bool
198
-     */
199
-    public function destroyGarbage($clearSession = false)
200
-    {
201
-        require_once __DIR__ . '/' . $this->mode . '.php';
202
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
203
-        $captchaHandler = new $class();
204
-        if (method_exists($captchaHandler, 'destroyGarbage')) {
205
-            $captchaHandler->loadConfig($this->config);
206
-            $captchaHandler->destroyGarbage();
207
-        }
208
-
209
-        if ($clearSession) {
210
-            $_SESSION['XoopsCaptcha_name']        = null;
211
-            $_SESSION['XoopsCaptcha_skipmember']  = null;
212
-            $_SESSION['XoopsCaptcha_sessioncode'] = null;
213
-            $_SESSION['XoopsCaptcha_maxattempts'] = null;
214
-        }
215
-
216
-        return true;
217
-    }
218
-
219
-    /**
220
-     * @return mixed|string
221
-     */
222
-    public function render()
223
-    {
224
-        $form = '';
225
-
226
-        if (!$this->active || empty($this->config['name'])) {
227
-            return $form;
228
-        }
229
-
230
-        $_SESSION['XoopsCaptcha_name']        = $this->config['name'];
231
-        $_SESSION['XoopsCaptcha_skipmember']  = $this->config['skipmember'];
232
-        $maxAttempts                          = $this->config['maxattempt'];
233
-        $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts;
234
-        /*
16
+	public $active = true;
17
+	public $mode   = 'text';    // potential values: image, text
18
+	public $config = [];
19
+
20
+	public $message = []; // Logging error messages
21
+
22
+	/**
23
+	 * XoopsCaptcha constructor.
24
+	 */
25
+	public function __construct()
26
+	{
27
+		// Loading default preferences
28
+		$this->config = @include __DIR__ . '/config.php';
29
+
30
+		$this->setMode($this->config['mode']);
31
+	}
32
+
33
+	/**
34
+	 * @return XoopsCaptcha
35
+	 */
36
+	public static function getInstance()
37
+	{
38
+		static $instance;
39
+		if (null === $instance) {
40
+			$instance = new static();
41
+		}
42
+
43
+		return $instance;
44
+	}
45
+
46
+	/**
47
+	 * @param $name
48
+	 * @param $val
49
+	 * @return bool
50
+	 */
51
+	public function setConfig($name, $val)
52
+	{
53
+		if ('mode' === $name) {
54
+			$this->setMode($val);
55
+		} elseif (isset($this->$name)) {
56
+			$this->$name = $val;
57
+		} else {
58
+			$this->config[$name] = $val;
59
+		}
60
+
61
+		return true;
62
+	}
63
+
64
+	/**
65
+	 * Set CAPTCHA mode
66
+	 *
67
+	 * For future possible modes, right now force to use text or image
68
+	 *
69
+	 * @param string $mode if no mode is set, just verify current mode
70
+	 */
71
+	public function setMode($mode = null)
72
+	{
73
+		if (!empty($mode) && in_array($mode, ['text', 'image'])) {
74
+			$this->mode = $mode;
75
+
76
+			if ('image' !== $this->mode) {
77
+				return;
78
+			}
79
+		}
80
+
81
+		// Disable image mode
82
+		if (!extension_loaded('gd')) {
83
+			$this->mode = 'text';
84
+		} else {
85
+			$required_functions = [
86
+				'imagecreatetruecolor',
87
+				'imagecolorallocate',
88
+				'imagefilledrectangle',
89
+				'imagejpeg',
90
+				'imagedestroy',
91
+				'imageftbbox'
92
+			];
93
+			foreach ($required_functions as $func) {
94
+				if (!function_exists($func)) {
95
+					$this->mode = 'text';
96
+					break;
97
+				}
98
+			}
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * Initializing the CAPTCHA class
104
+	 * @param string $name
105
+	 * @param null   $skipmember
106
+	 * @param null   $num_chars
107
+	 * @param null   $fontsize_min
108
+	 * @param null   $fontsize_max
109
+	 * @param null   $background_type
110
+	 * @param null   $background_num
111
+	 */
112
+	public function init(
113
+		$name = 'xoopscaptcha',
114
+		$skipmember = null,
115
+		$num_chars = null,
116
+		$fontsize_min = null,
117
+		$fontsize_max = null,
118
+		$background_type = null,
119
+		$background_num = null
120
+	) {
121
+		// Loading RUN-TIME settings
122
+		foreach (array_keys($this->config) as $key) {
123
+			if (isset(${$key}) && null !== ${$key}) {
124
+				$this->config[$key] = ${$key};
125
+			}
126
+		}
127
+		$this->config['name'] = $name;
128
+
129
+		// Skip CAPTCHA for member if set
130
+		if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) {
131
+			$this->active = false;
132
+		}
133
+	}
134
+
135
+	/**
136
+	 * Verify user submission
137
+	 * @param  null $skipMember
138
+	 * @return bool
139
+	 */
140
+	public function verify($skipMember = null)
141
+	{
142
+		$sessionName = @$_SESSION['XoopsCaptcha_name'];
143
+		$skipMember  = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember;
144
+		$maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
145
+
146
+		$is_valid = false;
147
+
148
+		// Skip CAPTCHA for member if set
149
+		if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) {
150
+			$is_valid = true;
151
+			// Kill too many attempts
152
+		} elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) {
153
+			$this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
154
+
155
+			// Verify the code
156
+		} elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) {
157
+			$func     = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp';
158
+			$is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']);
159
+		}
160
+
161
+		if (!empty($maxAttempts)) {
162
+			if (!$is_valid) {
163
+				// Increase the attempt records on failure
164
+				$_SESSION['XoopsCaptcha_attempt_' . $sessionName]++;
165
+				// Log the error message
166
+				$this->message[] = XOOPS_CAPTCHA_INVALID_CODE;
167
+			} else {
168
+
169
+				// reset attempt records on success
170
+				$_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null;
171
+			}
172
+		}
173
+		$this->destroyGarbage(true);
174
+
175
+		return $is_valid;
176
+	}
177
+
178
+	/**
179
+	 * @return mixed|string
180
+	 */
181
+	public function getCaption()
182
+	{
183
+		return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : '';
184
+	}
185
+
186
+	/**
187
+	 * @return string
188
+	 */
189
+	public function getMessage()
190
+	{
191
+		return implode('<br>', $this->message);
192
+	}
193
+
194
+	/**
195
+	 * Destory historical stuff
196
+	 * @param  bool $clearSession
197
+	 * @return bool
198
+	 */
199
+	public function destroyGarbage($clearSession = false)
200
+	{
201
+		require_once __DIR__ . '/' . $this->mode . '.php';
202
+		$class          = 'XoopsCaptcha' . ucfirst($this->mode);
203
+		$captchaHandler = new $class();
204
+		if (method_exists($captchaHandler, 'destroyGarbage')) {
205
+			$captchaHandler->loadConfig($this->config);
206
+			$captchaHandler->destroyGarbage();
207
+		}
208
+
209
+		if ($clearSession) {
210
+			$_SESSION['XoopsCaptcha_name']        = null;
211
+			$_SESSION['XoopsCaptcha_skipmember']  = null;
212
+			$_SESSION['XoopsCaptcha_sessioncode'] = null;
213
+			$_SESSION['XoopsCaptcha_maxattempts'] = null;
214
+		}
215
+
216
+		return true;
217
+	}
218
+
219
+	/**
220
+	 * @return mixed|string
221
+	 */
222
+	public function render()
223
+	{
224
+		$form = '';
225
+
226
+		if (!$this->active || empty($this->config['name'])) {
227
+			return $form;
228
+		}
229
+
230
+		$_SESSION['XoopsCaptcha_name']        = $this->config['name'];
231
+		$_SESSION['XoopsCaptcha_skipmember']  = $this->config['skipmember'];
232
+		$maxAttempts                          = $this->config['maxattempt'];
233
+		$_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts;
234
+		/*
235 235
          if (!empty($maxAttempts)) {
236 236
          $_SESSION['XoopsCaptcha_maxattempts_'.$_SESSION['XoopsCaptcha_name']] = $maxAttempts;
237 237
          }
238 238
          */
239 239
 
240
-        // Fail on too many attempts
241
-        if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) {
242
-            $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
243
-            // Load the form element
244
-        } else {
245
-            $form = $this->loadForm();
246
-        }
247
-
248
-        return $form;
249
-    }
250
-
251
-    /**
252
-     * @return mixed
253
-     */
254
-    public function loadForm()
255
-    {
256
-        require_once __DIR__ . '/' . $this->mode . '.php';
257
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
258
-        $captchaHandler = new $class();
259
-        $captchaHandler->loadConfig($this->config);
260
-
261
-        $form = $captchaHandler->render();
262
-
263
-        return $form;
264
-    }
240
+		// Fail on too many attempts
241
+		if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) {
242
+			$form = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
243
+			// Load the form element
244
+		} else {
245
+			$form = $this->loadForm();
246
+		}
247
+
248
+		return $form;
249
+	}
250
+
251
+	/**
252
+	 * @return mixed
253
+	 */
254
+	public function loadForm()
255
+	{
256
+		require_once __DIR__ . '/' . $this->mode . '.php';
257
+		$class          = 'XoopsCaptcha' . ucfirst($this->mode);
258
+		$captchaHandler = new $class();
259
+		$captchaHandler->loadConfig($this->config);
260
+
261
+		$form = $captchaHandler->render();
262
+
263
+		return $form;
264
+	}
265 265
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 class XoopsCaptcha
15 15
 {
16 16
     public $active = true;
17
-    public $mode   = 'text';    // potential values: image, text
17
+    public $mode   = 'text'; // potential values: image, text
18 18
     public $config = [];
19 19
 
20 20
     public $message = []; // Logging error messages
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     public function __construct()
26 26
     {
27 27
         // Loading default preferences
28
-        $this->config = @include __DIR__ . '/config.php';
28
+        $this->config = @include __DIR__.'/config.php';
29 29
 
30 30
         $this->setMode($this->config['mode']);
31 31
     }
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     {
142 142
         $sessionName = @$_SESSION['XoopsCaptcha_name'];
143 143
         $skipMember  = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember;
144
-        $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']);
144
+        $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']);
145 145
 
146 146
         $is_valid = false;
147 147
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) {
150 150
             $is_valid = true;
151 151
             // Kill too many attempts
152
-        } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) {
152
+        } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_'.$sessionName] > $maxAttempts) {
153 153
             $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
154 154
 
155 155
             // Verify the code
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
         if (!empty($maxAttempts)) {
162 162
             if (!$is_valid) {
163 163
                 // Increase the attempt records on failure
164
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++;
164
+                $_SESSION['XoopsCaptcha_attempt_'.$sessionName]++;
165 165
                 // Log the error message
166 166
                 $this->message[] = XOOPS_CAPTCHA_INVALID_CODE;
167 167
             } else {
168 168
 
169 169
                 // reset attempt records on success
170
-                $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null;
170
+                $_SESSION['XoopsCaptcha_attempt_'.$sessionName] = null;
171 171
             }
172 172
         }
173 173
         $this->destroyGarbage(true);
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
      */
199 199
     public function destroyGarbage($clearSession = false)
200 200
     {
201
-        require_once __DIR__ . '/' . $this->mode . '.php';
202
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
201
+        require_once __DIR__.'/'.$this->mode.'.php';
202
+        $class          = 'XoopsCaptcha'.ucfirst($this->mode);
203 203
         $captchaHandler = new $class();
204 204
         if (method_exists($captchaHandler, 'destroyGarbage')) {
205 205
             $captchaHandler->loadConfig($this->config);
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
          */
239 239
 
240 240
         // Fail on too many attempts
241
-        if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) {
241
+        if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_'.$this->config['name']] > $maxAttempts) {
242 242
             $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS;
243 243
             // Load the form element
244 244
         } else {
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
      */
254 254
     public function loadForm()
255 255
     {
256
-        require_once __DIR__ . '/' . $this->mode . '.php';
257
-        $class          = 'XoopsCaptcha' . ucfirst($this->mode);
256
+        require_once __DIR__.'/'.$this->mode.'.php';
257
+        $class          = 'XoopsCaptcha'.ucfirst($this->mode);
258 258
         $captchaHandler = new $class();
259 259
         $captchaHandler->loadConfig($this->config);
260 260
 
Please login to merge, or discard this patch.
include/projax_/classes/Prototype.php 1 patch
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -15,452 +15,452 @@
 block discarded – undo
15 15
  */
16 16
 class Prototype extends JavaScript
17 17
 {
18
-    public $CALLBACKS = [
19
-        'uninitialized',
20
-        'loading',
21
-        'loaded',
22
-        'interactive',
23
-        'complete',
24
-        'failure',
25
-        'success'
26
-    ];
27
-
28
-    public $AJAX_OPTIONS = [
29
-        'before',
30
-        'after',
31
-        'condition',
32
-        'url',
33
-        'asynchronous',
34
-        'method',
35
-        'insertion',
36
-        'position',
37
-        'form',
38
-        'with',
39
-        'update',
40
-        'script',
41
-        'uninitialized',
42
-        'loading',
43
-        'loaded',
44
-        'interactive',
45
-        'complete',
46
-        'failure',
47
-        'success'
48
-    ];
49
-
50
-    /**
51
-     * @return string
52
-     */
53
-    public function evaluate_remote_response()
54
-    {
55
-        return 'eval(request.responseText)';
56
-    }
57
-
58
-    /**
59
-     * @param $options
60
-     * @return string
61
-     */
62
-    public function form_remote_tag($options)
63
-    {
64
-        $options['form'] = true;
65
-
66
-        return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
-    }
68
-
69
-    /**
70
-     * @param         $name
71
-     * @param  null   $options
72
-     * @param  null   $html_options
73
-     * @return string
74
-     */
75
-    public function link_to_remote($name, $options = null, $html_options = null)
76
-    {
77
-        return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
-    }
79
-
80
-    /**
81
-     * @param         $field_id
82
-     * @param  null   $options
83
-     * @return string
84
-     */
85
-    public function observe_field($field_id, $options = null)
86
-    {
87
-        if (isset($options['frequency']) && $options['frequency'] > 0) {
88
-            return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
-        } else {
90
-            return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
-        }
92
-    }
93
-
94
-    /**
95
-     * @param         $form_id
96
-     * @param  null   $options
97
-     * @return string
98
-     */
99
-    public function observe_form($form_id, $options = null)
100
-    {
101
-        if (isset($options['frequency'])) {
102
-            return $this->_build_observer('Form.Observer', $form_id, $options);
103
-        } else {
104
-            return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
-        }
106
-    }
107
-
108
-    /**
109
-     * @param  null $options
110
-     * @return string
111
-     */
112
-    public function periodically_call_remote($options = null)
113
-    {
114
-        $frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
-        $code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
-
117
-        return $code;
118
-    }
119
-
120
-    /**
121
-     * @param $options
122
-     * @return string
123
-     */
124
-    public function remote_function($options)
125
-    {
126
-        $javascript_options = $this->_options_for_ajax($options);
127
-
128
-        $update = '';
129
-
130
-        if (isset($options['update']) && is_array($options['update'])) {
131
-            $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
-            $update .= empty($update) ? '' : ',';
133
-            $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
-        } else {
135
-            $update .= isset($options['update']) ? $options['update'] : '';
136
-        }
137
-
138
-        $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
-
140
-        $ajax_function .= "'" . $options['url'] . "'";
141
-        $ajax_function .= ',' . $javascript_options . ')';
142
-
143
-        $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
-        $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
-        $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
-        $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
-
148
-        return $ajax_function;
149
-    }
150
-
151
-    /**
152
-     * @param $name
153
-     * @param $value
154
-     * @param $options
155
-     * @return string
156
-     */
157
-    public function submit_to_remote($name, $value, $options)
158
-    {
159
-        if (isset($options['with'])) {
160
-            $options['with'] = 'Form.serialize(this.form)';
161
-        }
162
-
163
-        return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
-    }
165
-
166
-    /**
167
-     * @param      $element_id
168
-     * @param null $options
169
-     * @param      $block
170
-     */
171
-    public function update_element_function($element_id, $options = null, $block)
172
-    {
173
-        $content = isset($options['content']) ? $options['content'] : '';
174
-        $content = $this->escape($content);
175
-    }
176
-
177
-    /**
178
-     * @param $block
179
-     */
180
-    public function update_page($block)
181
-    {
182
-    }
183
-
184
-    /**
185
-     * @param $block
186
-     * @return string
187
-     */
188
-    public function update_page_tag(& $block)
189
-    {
190
-        return $this->tag($block);
191
-    }
192
-
193
-    /////////////////////////////////////////////////////////////////////////////////////
194
-    //                             Private functions
195
-    /////////////////////////////////////////////////////////////////////////////////////
196
-
197
-    /**
198
-     * @param $options
199
-     * @return array
200
-     */
201
-    public function _build_callbacks($options)
202
-    {
203
-        $callbacks = [];
204
-        foreach ($options as $callback => $code) {
205
-            if (in_array($callback, $this->CALLBACKS)) {
206
-                $name             = 'on' . ucfirst($callback);
207
-                $callbacks[$name] = 'function(request){' . $code . '}';
208
-            }
209
-        }
210
-
211
-        return $callbacks;
212
-    }
213
-
214
-    /**
215
-     * @param         $klass
216
-     * @param         $name
217
-     * @param  null   $options
218
-     * @return string
219
-     */
220
-    public function _build_observer($klass, $name, $options = null)
221
-    {
222
-        if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
-            $options['with'] = '\'' . $options['with'] . '=\' + value';
224
-        } elseif (isset($options['with']) && isset($options['update'])) {
225
-            $options['with'] = 'value';
226
-        }
227
-
228
-        $callback = $options['function'] ?: $this->remote_function($options);
229
-
230
-        $javascript = "new $klass('$name', ";
231
-        $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
-        $javascript .= 'function (element,value) { ';
233
-        $javascript .= $callback;
234
-        $javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
-        $javascript .= '})';
236
-
237
-        return $javascript;
238
-    }
239
-
240
-    /**
241
-     * @param $method
242
-     * @return string
243
-     */
244
-    public function _method_option_to_s($method)
245
-    {
246
-        return strstr($method, "'") ? $method : "'$method'";
247
-    }
248
-
249
-    /**
250
-     * @param $options
251
-     * @return string
252
-     */
253
-    public function _options_for_ajax($options)
254
-    {
255
-        $js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
-
257
-        if (isset($options['type']) && 'synchronous' === $option['type']) {
258
-            $js_options['asynchronous'] = 'false';
259
-        }
260
-
261
-        if (isset($options['method'])) {
262
-            $js_options['method'] = $this->_method_option_to_s($options['method']);
263
-        }
264
-
265
-        if (isset($options['position'])) {
266
-            $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
-        }
268
-
269
-        $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
-
271
-        if (isset($options['form'])) {
272
-            $js_options['parameters'] = 'Form.serialize(this)';
273
-        } elseif (isset($options['parameters'])) {
274
-            $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
-        } elseif (isset($options['with'])) {
276
-            $js_options['parameters'] = $options['with'];
277
-        }
278
-
279
-        return $this->_options_for_javascript($js_options);
280
-    }
281
-
282
-    /////////////////////////////////////////////////////////////////////////////////////
283
-    //                            Mergerd Javascript Generator helpers
284
-    /////////////////////////////////////////////////////////////////////////////////////
285
-
286
-    /**
287
-     * @param $javascript
288
-     */
289
-    public function dump($javascript)
290
-    {
291
-        echo $javascript;
292
-    }
293
-
294
-    /**
295
-     * @param         $id
296
-     * @param  null   $extend
297
-     * @return string
298
-     */
299
-    public function ID($id, $extend = null)
300
-    {
301
-        return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
-    }
303
-
304
-    /**
305
-     * @param $message
306
-     * @return string
307
-     */
308
-    public function alert($message)
309
-    {
310
-        return $this->call('alert', $message);
311
-    }
312
-
313
-    /**
314
-     * @param $variable
315
-     * @param $value
316
-     * @return string
317
-     */
318
-    public function assign($variable, $value)
319
-    {
320
-        return "$variable = $value;";
321
-    }
322
-
323
-    /**
324
-     * @param         $function
325
-     * @param  null   $args
326
-     * @return string
327
-     */
328
-    public function call($function, $args = null)
329
-    {
330
-        $arg_str = '';
331
-        if (is_array($args)) {
332
-            foreach ($args as $arg) {
333
-                if (!empty($arg_str)) {
334
-                    $arg_str .= ', ';
335
-                }
336
-                if (is_string($arg)) {
337
-                    $arg_str .= "'$arg'";
338
-                } else {
339
-                    $arg_str .= $arg;
340
-                }
341
-            }
342
-        } else {
343
-            if (is_string($args)) {
344
-                $arg_str .= "'$args'";
345
-            } else {
346
-                $arg_str .= $args;
347
-            }
348
-        }
349
-
350
-        return "$function($arg_str)";
351
-    }
352
-
353
-    /**
354
-     * @param  int    $seconds
355
-     * @param  string $script
356
-     * @return string
357
-     */
358
-    public function delay($seconds = 1, $script = '')
359
-    {
360
-        return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
-    }
362
-
363
-    /**
364
-     * @param $id
365
-     * @return string
366
-     */
367
-    public function hide($id)
368
-    {
369
-        return $this->call('Element.hide', $id);
370
-    }
371
-
372
-    /**
373
-     * @param         $position
374
-     * @param         $id
375
-     * @param  null   $options_for_render
376
-     * @return string
377
-     */
378
-    public function insert_html($position, $id, $options_for_render = null)
379
-    {
380
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
-
382
-        return $this->call('new Insertion.' . ucfirst($position), $args);
383
-    }
384
-
385
-    /**
386
-     * @param $location
387
-     * @return string
388
-     */
389
-    public function redirect_to($location)
390
-    {
391
-        return $this->assign('window.location.href', $location);
392
-    }
393
-
394
-    /**
395
-     * @param $id
396
-     * @return string
397
-     */
398
-    public function remove($id)
399
-    {
400
-        if (is_array($id)) {
401
-            $arr_str = '';
402
-            foreach ($id as $obj) {
403
-                if (!empty($arg_str)) {
404
-                    $arg_str .= ', ';
405
-                }
406
-                $arg_str .= "'$arg'";
407
-            }
408
-
409
-            return "$A[$arg_str].each(Element.remove)";
410
-        } else {
411
-            return "Element.remove('$id')";
412
-        }
413
-    }
414
-
415
-    /**
416
-     * @param $id
417
-     * @param $options_for_render
418
-     * @return string
419
-     */
420
-    public function replace($id, $options_for_render)
421
-    {
422
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
-
424
-        return $this->call('Element.replace', $args);
425
-    }
426
-
427
-    /**
428
-     * @param $id
429
-     * @param $options_for_render
430
-     * @return string
431
-     */
432
-    public function replace_html($id, $options_for_render)
433
-    {
434
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
-
436
-        return $this->call('Element.update', $args);
437
-    }
438
-
439
-    /**
440
-     * @param         $pattern
441
-     * @param  null   $extend
442
-     * @return string
443
-     */
444
-    public function select($pattern, $extend = null)
445
-    {
446
-        return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
-    }
448
-
449
-    /**
450
-     * @param $id
451
-     * @return string
452
-     */
453
-    public function show($id)
454
-    {
455
-        return $this->call('Element.show', $id);
456
-    }
457
-
458
-    /**
459
-     * @param $id
460
-     * @return string
461
-     */
462
-    public function toggle($id)
463
-    {
464
-        return $this->call('Element.toggle', $id);
465
-    }
18
+	public $CALLBACKS = [
19
+		'uninitialized',
20
+		'loading',
21
+		'loaded',
22
+		'interactive',
23
+		'complete',
24
+		'failure',
25
+		'success'
26
+	];
27
+
28
+	public $AJAX_OPTIONS = [
29
+		'before',
30
+		'after',
31
+		'condition',
32
+		'url',
33
+		'asynchronous',
34
+		'method',
35
+		'insertion',
36
+		'position',
37
+		'form',
38
+		'with',
39
+		'update',
40
+		'script',
41
+		'uninitialized',
42
+		'loading',
43
+		'loaded',
44
+		'interactive',
45
+		'complete',
46
+		'failure',
47
+		'success'
48
+	];
49
+
50
+	/**
51
+	 * @return string
52
+	 */
53
+	public function evaluate_remote_response()
54
+	{
55
+		return 'eval(request.responseText)';
56
+	}
57
+
58
+	/**
59
+	 * @param $options
60
+	 * @return string
61
+	 */
62
+	public function form_remote_tag($options)
63
+	{
64
+		$options['form'] = true;
65
+
66
+		return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
+	}
68
+
69
+	/**
70
+	 * @param         $name
71
+	 * @param  null   $options
72
+	 * @param  null   $html_options
73
+	 * @return string
74
+	 */
75
+	public function link_to_remote($name, $options = null, $html_options = null)
76
+	{
77
+		return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
+	}
79
+
80
+	/**
81
+	 * @param         $field_id
82
+	 * @param  null   $options
83
+	 * @return string
84
+	 */
85
+	public function observe_field($field_id, $options = null)
86
+	{
87
+		if (isset($options['frequency']) && $options['frequency'] > 0) {
88
+			return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
+		} else {
90
+			return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
+		}
92
+	}
93
+
94
+	/**
95
+	 * @param         $form_id
96
+	 * @param  null   $options
97
+	 * @return string
98
+	 */
99
+	public function observe_form($form_id, $options = null)
100
+	{
101
+		if (isset($options['frequency'])) {
102
+			return $this->_build_observer('Form.Observer', $form_id, $options);
103
+		} else {
104
+			return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
+		}
106
+	}
107
+
108
+	/**
109
+	 * @param  null $options
110
+	 * @return string
111
+	 */
112
+	public function periodically_call_remote($options = null)
113
+	{
114
+		$frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
+		$code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
+
117
+		return $code;
118
+	}
119
+
120
+	/**
121
+	 * @param $options
122
+	 * @return string
123
+	 */
124
+	public function remote_function($options)
125
+	{
126
+		$javascript_options = $this->_options_for_ajax($options);
127
+
128
+		$update = '';
129
+
130
+		if (isset($options['update']) && is_array($options['update'])) {
131
+			$update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
+			$update .= empty($update) ? '' : ',';
133
+			$update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
+		} else {
135
+			$update .= isset($options['update']) ? $options['update'] : '';
136
+		}
137
+
138
+		$ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
+
140
+		$ajax_function .= "'" . $options['url'] . "'";
141
+		$ajax_function .= ',' . $javascript_options . ')';
142
+
143
+		$ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
+		$ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
+		$ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
+		$ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
+
148
+		return $ajax_function;
149
+	}
150
+
151
+	/**
152
+	 * @param $name
153
+	 * @param $value
154
+	 * @param $options
155
+	 * @return string
156
+	 */
157
+	public function submit_to_remote($name, $value, $options)
158
+	{
159
+		if (isset($options['with'])) {
160
+			$options['with'] = 'Form.serialize(this.form)';
161
+		}
162
+
163
+		return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
+	}
165
+
166
+	/**
167
+	 * @param      $element_id
168
+	 * @param null $options
169
+	 * @param      $block
170
+	 */
171
+	public function update_element_function($element_id, $options = null, $block)
172
+	{
173
+		$content = isset($options['content']) ? $options['content'] : '';
174
+		$content = $this->escape($content);
175
+	}
176
+
177
+	/**
178
+	 * @param $block
179
+	 */
180
+	public function update_page($block)
181
+	{
182
+	}
183
+
184
+	/**
185
+	 * @param $block
186
+	 * @return string
187
+	 */
188
+	public function update_page_tag(& $block)
189
+	{
190
+		return $this->tag($block);
191
+	}
192
+
193
+	/////////////////////////////////////////////////////////////////////////////////////
194
+	//                             Private functions
195
+	/////////////////////////////////////////////////////////////////////////////////////
196
+
197
+	/**
198
+	 * @param $options
199
+	 * @return array
200
+	 */
201
+	public function _build_callbacks($options)
202
+	{
203
+		$callbacks = [];
204
+		foreach ($options as $callback => $code) {
205
+			if (in_array($callback, $this->CALLBACKS)) {
206
+				$name             = 'on' . ucfirst($callback);
207
+				$callbacks[$name] = 'function(request){' . $code . '}';
208
+			}
209
+		}
210
+
211
+		return $callbacks;
212
+	}
213
+
214
+	/**
215
+	 * @param         $klass
216
+	 * @param         $name
217
+	 * @param  null   $options
218
+	 * @return string
219
+	 */
220
+	public function _build_observer($klass, $name, $options = null)
221
+	{
222
+		if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
+			$options['with'] = '\'' . $options['with'] . '=\' + value';
224
+		} elseif (isset($options['with']) && isset($options['update'])) {
225
+			$options['with'] = 'value';
226
+		}
227
+
228
+		$callback = $options['function'] ?: $this->remote_function($options);
229
+
230
+		$javascript = "new $klass('$name', ";
231
+		$javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
+		$javascript .= 'function (element,value) { ';
233
+		$javascript .= $callback;
234
+		$javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
+		$javascript .= '})';
236
+
237
+		return $javascript;
238
+	}
239
+
240
+	/**
241
+	 * @param $method
242
+	 * @return string
243
+	 */
244
+	public function _method_option_to_s($method)
245
+	{
246
+		return strstr($method, "'") ? $method : "'$method'";
247
+	}
248
+
249
+	/**
250
+	 * @param $options
251
+	 * @return string
252
+	 */
253
+	public function _options_for_ajax($options)
254
+	{
255
+		$js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
+
257
+		if (isset($options['type']) && 'synchronous' === $option['type']) {
258
+			$js_options['asynchronous'] = 'false';
259
+		}
260
+
261
+		if (isset($options['method'])) {
262
+			$js_options['method'] = $this->_method_option_to_s($options['method']);
263
+		}
264
+
265
+		if (isset($options['position'])) {
266
+			$js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
+		}
268
+
269
+		$js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
+
271
+		if (isset($options['form'])) {
272
+			$js_options['parameters'] = 'Form.serialize(this)';
273
+		} elseif (isset($options['parameters'])) {
274
+			$js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
+		} elseif (isset($options['with'])) {
276
+			$js_options['parameters'] = $options['with'];
277
+		}
278
+
279
+		return $this->_options_for_javascript($js_options);
280
+	}
281
+
282
+	/////////////////////////////////////////////////////////////////////////////////////
283
+	//                            Mergerd Javascript Generator helpers
284
+	/////////////////////////////////////////////////////////////////////////////////////
285
+
286
+	/**
287
+	 * @param $javascript
288
+	 */
289
+	public function dump($javascript)
290
+	{
291
+		echo $javascript;
292
+	}
293
+
294
+	/**
295
+	 * @param         $id
296
+	 * @param  null   $extend
297
+	 * @return string
298
+	 */
299
+	public function ID($id, $extend = null)
300
+	{
301
+		return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
+	}
303
+
304
+	/**
305
+	 * @param $message
306
+	 * @return string
307
+	 */
308
+	public function alert($message)
309
+	{
310
+		return $this->call('alert', $message);
311
+	}
312
+
313
+	/**
314
+	 * @param $variable
315
+	 * @param $value
316
+	 * @return string
317
+	 */
318
+	public function assign($variable, $value)
319
+	{
320
+		return "$variable = $value;";
321
+	}
322
+
323
+	/**
324
+	 * @param         $function
325
+	 * @param  null   $args
326
+	 * @return string
327
+	 */
328
+	public function call($function, $args = null)
329
+	{
330
+		$arg_str = '';
331
+		if (is_array($args)) {
332
+			foreach ($args as $arg) {
333
+				if (!empty($arg_str)) {
334
+					$arg_str .= ', ';
335
+				}
336
+				if (is_string($arg)) {
337
+					$arg_str .= "'$arg'";
338
+				} else {
339
+					$arg_str .= $arg;
340
+				}
341
+			}
342
+		} else {
343
+			if (is_string($args)) {
344
+				$arg_str .= "'$args'";
345
+			} else {
346
+				$arg_str .= $args;
347
+			}
348
+		}
349
+
350
+		return "$function($arg_str)";
351
+	}
352
+
353
+	/**
354
+	 * @param  int    $seconds
355
+	 * @param  string $script
356
+	 * @return string
357
+	 */
358
+	public function delay($seconds = 1, $script = '')
359
+	{
360
+		return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
+	}
362
+
363
+	/**
364
+	 * @param $id
365
+	 * @return string
366
+	 */
367
+	public function hide($id)
368
+	{
369
+		return $this->call('Element.hide', $id);
370
+	}
371
+
372
+	/**
373
+	 * @param         $position
374
+	 * @param         $id
375
+	 * @param  null   $options_for_render
376
+	 * @return string
377
+	 */
378
+	public function insert_html($position, $id, $options_for_render = null)
379
+	{
380
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
+
382
+		return $this->call('new Insertion.' . ucfirst($position), $args);
383
+	}
384
+
385
+	/**
386
+	 * @param $location
387
+	 * @return string
388
+	 */
389
+	public function redirect_to($location)
390
+	{
391
+		return $this->assign('window.location.href', $location);
392
+	}
393
+
394
+	/**
395
+	 * @param $id
396
+	 * @return string
397
+	 */
398
+	public function remove($id)
399
+	{
400
+		if (is_array($id)) {
401
+			$arr_str = '';
402
+			foreach ($id as $obj) {
403
+				if (!empty($arg_str)) {
404
+					$arg_str .= ', ';
405
+				}
406
+				$arg_str .= "'$arg'";
407
+			}
408
+
409
+			return "$A[$arg_str].each(Element.remove)";
410
+		} else {
411
+			return "Element.remove('$id')";
412
+		}
413
+	}
414
+
415
+	/**
416
+	 * @param $id
417
+	 * @param $options_for_render
418
+	 * @return string
419
+	 */
420
+	public function replace($id, $options_for_render)
421
+	{
422
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
+
424
+		return $this->call('Element.replace', $args);
425
+	}
426
+
427
+	/**
428
+	 * @param $id
429
+	 * @param $options_for_render
430
+	 * @return string
431
+	 */
432
+	public function replace_html($id, $options_for_render)
433
+	{
434
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
+
436
+		return $this->call('Element.update', $args);
437
+	}
438
+
439
+	/**
440
+	 * @param         $pattern
441
+	 * @param  null   $extend
442
+	 * @return string
443
+	 */
444
+	public function select($pattern, $extend = null)
445
+	{
446
+		return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
+	}
448
+
449
+	/**
450
+	 * @param $id
451
+	 * @return string
452
+	 */
453
+	public function show($id)
454
+	{
455
+		return $this->call('Element.show', $id);
456
+	}
457
+
458
+	/**
459
+	 * @param $id
460
+	 * @return string
461
+	 */
462
+	public function toggle($id)
463
+	{
464
+		return $this->call('Element.toggle', $id);
465
+	}
466 466
 }
Please login to merge, or discard this patch.
include/rating.rate.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 // defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
10 10
 
11 11
 if (!defined('SMARTOBJECT_URL')) {
12
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
12
+	require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
13 13
 }
14 14
 require_once SMARTOBJECT_ROOT_PATH . 'class/rating.php';
15 15
 require_once SMARTOBJECT_ROOT_PATH . 'include/functions.php';
@@ -23,52 +23,52 @@  discard block
 block discarded – undo
23 23
 $smartobjectPluginHandler = new SmartPluginHandler();
24 24
 $pluginObj                = $smartobjectPluginHandler->getPlugin($module_dirname);
25 25
 if ($pluginObj) {
26
-    $rating_item = $pluginObj->getItem();
27
-    if ($rating_item) {
28
-        $rating_itemid = $pluginObj->getItemIdForItem($rating_item);
29
-        $stats         = $smartobjectRatingHandler->getRatingAverageByItemId($rating_itemid, $module_dirname, $rating_item);
30
-        $xoopsTpl->assign('smartobject_rating_stats_total', $stats['sum']);
31
-        $xoopsTpl->assign('smartobject_rating_stats_average', $stats['average']);
32
-        $xoopsTpl->assign('smartobject_rating_item', $rating_item);
33
-        if (is_object($xoopsUser)) {
34
-            $ratingObj = $smartobjectRatingHandler->already_rated($rating_item, $rating_itemid, $module_dirname, $xoopsUser->getVar('uid'));
35
-            $xoopsTpl->assign('smartobject_user_can_rate', true);
36
-        }
37
-        if (isset($ratingObj) && is_object($ratingObj)) {
38
-            $xoopsTpl->assign('smartobject_user_rate', $ratingObj->getVar('rate'));
39
-            $xoopsTpl->assign('smartobject_rated', true);
40
-        } else {
41
-            $xoopsTpl->assign('smartobject_rating_dirname', $module_dirname);
42
-            $xoopsTpl->assign('smartobject_rating_itemid', $rating_itemid);
43
-            $urls = smart_getCurrentUrls();
44
-            $xoopsTpl->assign('smartobject_rating_current_page', $urls['full']);
45
-            if (isset($xoTheme) && is_object($xoTheme)) {
46
-                $xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css');
47
-            } else {
48
-                //probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme
49
-                //$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>");
50
-            }
51
-        }
52
-    }
26
+	$rating_item = $pluginObj->getItem();
27
+	if ($rating_item) {
28
+		$rating_itemid = $pluginObj->getItemIdForItem($rating_item);
29
+		$stats         = $smartobjectRatingHandler->getRatingAverageByItemId($rating_itemid, $module_dirname, $rating_item);
30
+		$xoopsTpl->assign('smartobject_rating_stats_total', $stats['sum']);
31
+		$xoopsTpl->assign('smartobject_rating_stats_average', $stats['average']);
32
+		$xoopsTpl->assign('smartobject_rating_item', $rating_item);
33
+		if (is_object($xoopsUser)) {
34
+			$ratingObj = $smartobjectRatingHandler->already_rated($rating_item, $rating_itemid, $module_dirname, $xoopsUser->getVar('uid'));
35
+			$xoopsTpl->assign('smartobject_user_can_rate', true);
36
+		}
37
+		if (isset($ratingObj) && is_object($ratingObj)) {
38
+			$xoopsTpl->assign('smartobject_user_rate', $ratingObj->getVar('rate'));
39
+			$xoopsTpl->assign('smartobject_rated', true);
40
+		} else {
41
+			$xoopsTpl->assign('smartobject_rating_dirname', $module_dirname);
42
+			$xoopsTpl->assign('smartobject_rating_itemid', $rating_itemid);
43
+			$urls = smart_getCurrentUrls();
44
+			$xoopsTpl->assign('smartobject_rating_current_page', $urls['full']);
45
+			if (isset($xoTheme) && is_object($xoTheme)) {
46
+				$xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css');
47
+			} else {
48
+				//probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme
49
+				//$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>");
50
+			}
51
+		}
52
+	}
53 53
 }
54 54
 
55 55
 if (isset($_POST['smartobject_rating_submit'])) {
56
-    // The rating form has just been posted. Let's save the info
57
-    $ratingObj = $smartobjectRatingHandler->create();
58
-    $ratingObj->setVar('dirname', $module_dirname);
59
-    $ratingObj->setVar('item', $rating_item);
60
-    $ratingObj->setVar('itemid', $rating_itemid);
61
-    $ratingObj->setVar('uid', $xoopsUser->getVar('uid'));
62
-    $ratingObj->setVar('date', time());
63
-    $ratingObj->setVar('rate', $_POST['smartobject_rating_value']);
64
-    if (!$smartobjectRatingHandler->insert($ratingObj)) {
65
-        if (1062 == $xoopsDB->errno()) {
66
-            $message = _SOBJECT_RATING_DUPLICATE_ENTRY;
67
-        } else {
68
-            $message = _SOBJECT_RATING_ERROR;
69
-        }
70
-    } else {
71
-        $message = _SOBJECT_RATING_SUCCESS;
72
-    }
73
-    redirect_header('', 3, $message);
56
+	// The rating form has just been posted. Let's save the info
57
+	$ratingObj = $smartobjectRatingHandler->create();
58
+	$ratingObj->setVar('dirname', $module_dirname);
59
+	$ratingObj->setVar('item', $rating_item);
60
+	$ratingObj->setVar('itemid', $rating_itemid);
61
+	$ratingObj->setVar('uid', $xoopsUser->getVar('uid'));
62
+	$ratingObj->setVar('date', time());
63
+	$ratingObj->setVar('rate', $_POST['smartobject_rating_value']);
64
+	if (!$smartobjectRatingHandler->insert($ratingObj)) {
65
+		if (1062 == $xoopsDB->errno()) {
66
+			$message = _SOBJECT_RATING_DUPLICATE_ENTRY;
67
+		} else {
68
+			$message = _SOBJECT_RATING_ERROR;
69
+		}
70
+	} else {
71
+		$message = _SOBJECT_RATING_SUCCESS;
72
+	}
73
+	redirect_header('', 3, $message);
74 74
 }
Please login to merge, or discard this patch.
class/smartmetagen.php 2 patches
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -18,350 +18,350 @@  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 = [
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 = [
118
-            '-',
119
-            '-',
120
-            '-',
121
-            '-',
122
-            '-',
123
-            '-100',
124
-            '-',
125
-            '-',
126
-            '-',
127
-            '-',
128
-            '-',
129
-            '-',
130
-            '-',
131
-            '-',
132
-            '-',
133
-            '-',
134
-            '-',
135
-            '-',
136
-            '-at-',
137
-            '-',
138
-            '-',
139
-            '-',
140
-            '-',
141
-            '-',
142
-            '-',
143
-            '-',
144
-            '-',
145
-            '-'
146
-        ];
147
-        $title   = preg_replace($pattern, $rep_pat, $title);
148
-
149
-        // Transformation des caractères accentués
150
-        $pattern = [
151
-            '/%B0/', // °
152
-            '/%E8/', // è
153
-            '/%E9/', // é
154
-            '/%EA/', // ê
155
-            '/%EB/', // ë
156
-            '/%E7/', // ç
157
-            '/%E0/', // à
158
-            '/%E2/', // â
159
-            '/%E4/', // ä
160
-            '/%EE/', // î
161
-            '/%EF/', // ï
162
-            '/%F9/', // ù
163
-            '/%FC/', // ü
164
-            '/%FB/', // û
165
-            '/%F4/', // ô
166
-            '/%F6/', // ö
167
-        ];
168
-        $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'];
169
-        $title   = preg_replace($pattern, $rep_pat, $title);
170
-
171
-        $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
172
-        $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau
173
-        $title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
174
-
175
-        if (count($title) > 0) {
176
-            if ($withExt) {
177
-                $title .= '.html';
178
-            }
179
-
180
-            return $title;
181
-        } else {
182
-            return '';
183
-        }
184
-    }
185
-
186
-    /**
187
-     * @param $document
188
-     * @return mixed
189
-     */
190
-    public function html2text($document)
191
-    {
192
-        return smart_html2text($document);
193
-    }
194
-
195
-    /**
196
-     * @param $title
197
-     */
198
-    public function setTitle($title)
199
-    {
200
-        global $xoopsModule, $xoopsModuleConfig;
201
-        $this->_title          = $this->html2text($title);
202
-        $this->_title          = $this->purifyText($this->_title);
203
-        $this->_original_title = $this->_title;
204
-
205
-        $moduleName = $xoopsModule->getVar('name');
206
-
207
-        $titleTag = [];
208
-
209
-        $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true;
210
-
211
-        if ($moduleName && $show_mod_name_breadcrumb) {
212
-            $titleTag['module'] = $moduleName;
213
-        }
214
-
215
-        if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) {
216
-            $titleTag['title'] = $this->_title;
217
-        }
218
-
219
-        if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) {
220
-            $titleTag['category'] = $this->_categoryPath;
221
-        }
222
-
223
-        $ret = isset($titleTag['title']) ? $titleTag['title'] : '';
224
-
225
-        if (isset($titleTag['category']) && '' !== $titleTag['category']) {
226
-            if ('' !== $ret) {
227
-                $ret .= ' - ';
228
-            }
229
-            $ret .= $titleTag['category'];
230
-        }
231
-        if (isset($titleTag['module']) && '' !== $titleTag['module']) {
232
-            if ('' !== $ret) {
233
-                $ret .= ' - ';
234
-            }
235
-            $ret .= $titleTag['module'];
236
-        }
237
-        $this->_title = $ret;
238
-    }
239
-
240
-    /**
241
-     * @param $keywords
242
-     */
243
-    public function setKeywords($keywords)
244
-    {
245
-        $this->_keywords = $keywords;
246
-    }
247
-
248
-    /**
249
-     * @param $categoryPath
250
-     */
251
-    public function setCategoryPath($categoryPath)
252
-    {
253
-        $categoryPath        = $this->html2text($categoryPath);
254
-        $this->_categoryPath = $categoryPath;
255
-    }
256
-
257
-    /**
258
-     * @param $description
259
-     */
260
-    public function setDescription($description)
261
-    {
262
-        if (!$description) {
263
-            global $xoopsModuleConfig;
264
-            if (isset($xoopsModuleConfig['module_meta_description'])) {
265
-                $description = $xoopsModuleConfig['module_meta_description'];
266
-            }
267
-        }
268
-
269
-        $description = $this->html2text($description);
270
-        $description = $this->purifyText($description);
271
-
272
-        $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description);
273
-        $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description);
274
-        $description = preg_replace('/[ ]* [ ]*/', ' ', $description);
275
-        $description = stripslashes($description);
276
-
277
-        $this->_description      = $description;
278
-        $this->_meta_description = $this->createMetaDescription();
279
-    }
280
-
281
-    public function createTitleTag()
282
-    {
283
-    }
284
-
285
-    /**
286
-     * @param               $text
287
-     * @param  bool         $keyword
288
-     * @return mixed|string
289
-     */
290
-    public function purifyText($text, $keyword = false)
291
-    {
292
-        return smart_purifyText($text, $keyword);
293
-    }
294
-
295
-    /**
296
-     * @param  int $maxWords
297
-     * @return string
298
-     */
299
-    public function createMetaDescription($maxWords = 100)
300
-    {
301
-        $words = [];
302
-        $words = explode(' ', $this->_description);
303
-
304
-        // Only keep $maxWords words
305
-        $newWords = [];
306
-        $i        = 0;
307
-
308
-        while ($i < $maxWords - 1 && $i < count($words)) {
309
-            $newWords[] = $words[$i];
310
-            ++$i;
311
-        }
312
-        $ret = implode(' ', $newWords);
313
-
314
-        return $ret;
315
-    }
316
-
317
-    /**
318
-     * @param $text
319
-     * @param $minChar
320
-     * @return array
321
-     */
322
-    public function findMetaKeywords($text, $minChar)
323
-    {
324
-        $keywords = [];
325
-
326
-        $text = $this->purifyText($text);
327
-        $text = $this->html2text($text);
328
-
329
-        $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text);
330
-        $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text);
331
-        $text = preg_replace('/[ ]* [ ]*/', ' ', $text);
332
-        $text = stripslashes($text);
333
-        $text =
334
-
335
-        $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY);
336
-
337
-        foreach ($originalKeywords as $originalKeyword) {
338
-            $secondRoundKeywords = explode("'", $originalKeyword);
339
-            foreach ($secondRoundKeywords as $secondRoundKeyword) {
340
-                if (strlen($secondRoundKeyword) >= $minChar) {
341
-                    if (!in_array($secondRoundKeyword, $keywords)) {
342
-                        $keywords[] = trim($secondRoundKeyword);
343
-                    }
344
-                }
345
-            }
346
-        }
347
-
348
-        return $keywords;
349
-    }
350
-
351
-    /**
352
-     * @return string
353
-     */
354
-    public function createMetaKeywords()
355
-    {
356
-        global $xoopsModuleConfig;
357
-        $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
358
-        if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords'])
359
-            && '' !== $xoopsModuleConfig['moduleMetaKeywords']) {
360
-            $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']);
361
-            $keywords       = array_merge($keywords, $moduleKeywords);
362
-        }
363
-
364
-        /* 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 = [
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 = [
118
+			'-',
119
+			'-',
120
+			'-',
121
+			'-',
122
+			'-',
123
+			'-100',
124
+			'-',
125
+			'-',
126
+			'-',
127
+			'-',
128
+			'-',
129
+			'-',
130
+			'-',
131
+			'-',
132
+			'-',
133
+			'-',
134
+			'-',
135
+			'-',
136
+			'-at-',
137
+			'-',
138
+			'-',
139
+			'-',
140
+			'-',
141
+			'-',
142
+			'-',
143
+			'-',
144
+			'-',
145
+			'-'
146
+		];
147
+		$title   = preg_replace($pattern, $rep_pat, $title);
148
+
149
+		// Transformation des caractères accentués
150
+		$pattern = [
151
+			'/%B0/', // °
152
+			'/%E8/', // è
153
+			'/%E9/', // é
154
+			'/%EA/', // ê
155
+			'/%EB/', // ë
156
+			'/%E7/', // ç
157
+			'/%E0/', // à
158
+			'/%E2/', // â
159
+			'/%E4/', // ä
160
+			'/%EE/', // î
161
+			'/%EF/', // ï
162
+			'/%F9/', // ù
163
+			'/%FC/', // ü
164
+			'/%FB/', // û
165
+			'/%F4/', // ô
166
+			'/%F6/', // ö
167
+		];
168
+		$rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'];
169
+		$title   = preg_replace($pattern, $rep_pat, $title);
170
+
171
+		$tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau
172
+		$tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau
173
+		$title   = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret
174
+
175
+		if (count($title) > 0) {
176
+			if ($withExt) {
177
+				$title .= '.html';
178
+			}
179
+
180
+			return $title;
181
+		} else {
182
+			return '';
183
+		}
184
+	}
185
+
186
+	/**
187
+	 * @param $document
188
+	 * @return mixed
189
+	 */
190
+	public function html2text($document)
191
+	{
192
+		return smart_html2text($document);
193
+	}
194
+
195
+	/**
196
+	 * @param $title
197
+	 */
198
+	public function setTitle($title)
199
+	{
200
+		global $xoopsModule, $xoopsModuleConfig;
201
+		$this->_title          = $this->html2text($title);
202
+		$this->_title          = $this->purifyText($this->_title);
203
+		$this->_original_title = $this->_title;
204
+
205
+		$moduleName = $xoopsModule->getVar('name');
206
+
207
+		$titleTag = [];
208
+
209
+		$show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true;
210
+
211
+		if ($moduleName && $show_mod_name_breadcrumb) {
212
+			$titleTag['module'] = $moduleName;
213
+		}
214
+
215
+		if (isset($this->_title) && ('' !== $this->_title) && (strtoupper($this->_title) != strtoupper($moduleName))) {
216
+			$titleTag['title'] = $this->_title;
217
+		}
218
+
219
+		if (isset($this->_categoryPath) && ('' !== $this->_categoryPath)) {
220
+			$titleTag['category'] = $this->_categoryPath;
221
+		}
222
+
223
+		$ret = isset($titleTag['title']) ? $titleTag['title'] : '';
224
+
225
+		if (isset($titleTag['category']) && '' !== $titleTag['category']) {
226
+			if ('' !== $ret) {
227
+				$ret .= ' - ';
228
+			}
229
+			$ret .= $titleTag['category'];
230
+		}
231
+		if (isset($titleTag['module']) && '' !== $titleTag['module']) {
232
+			if ('' !== $ret) {
233
+				$ret .= ' - ';
234
+			}
235
+			$ret .= $titleTag['module'];
236
+		}
237
+		$this->_title = $ret;
238
+	}
239
+
240
+	/**
241
+	 * @param $keywords
242
+	 */
243
+	public function setKeywords($keywords)
244
+	{
245
+		$this->_keywords = $keywords;
246
+	}
247
+
248
+	/**
249
+	 * @param $categoryPath
250
+	 */
251
+	public function setCategoryPath($categoryPath)
252
+	{
253
+		$categoryPath        = $this->html2text($categoryPath);
254
+		$this->_categoryPath = $categoryPath;
255
+	}
256
+
257
+	/**
258
+	 * @param $description
259
+	 */
260
+	public function setDescription($description)
261
+	{
262
+		if (!$description) {
263
+			global $xoopsModuleConfig;
264
+			if (isset($xoopsModuleConfig['module_meta_description'])) {
265
+				$description = $xoopsModuleConfig['module_meta_description'];
266
+			}
267
+		}
268
+
269
+		$description = $this->html2text($description);
270
+		$description = $this->purifyText($description);
271
+
272
+		$description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description);
273
+		$description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description);
274
+		$description = preg_replace('/[ ]* [ ]*/', ' ', $description);
275
+		$description = stripslashes($description);
276
+
277
+		$this->_description      = $description;
278
+		$this->_meta_description = $this->createMetaDescription();
279
+	}
280
+
281
+	public function createTitleTag()
282
+	{
283
+	}
284
+
285
+	/**
286
+	 * @param               $text
287
+	 * @param  bool         $keyword
288
+	 * @return mixed|string
289
+	 */
290
+	public function purifyText($text, $keyword = false)
291
+	{
292
+		return smart_purifyText($text, $keyword);
293
+	}
294
+
295
+	/**
296
+	 * @param  int $maxWords
297
+	 * @return string
298
+	 */
299
+	public function createMetaDescription($maxWords = 100)
300
+	{
301
+		$words = [];
302
+		$words = explode(' ', $this->_description);
303
+
304
+		// Only keep $maxWords words
305
+		$newWords = [];
306
+		$i        = 0;
307
+
308
+		while ($i < $maxWords - 1 && $i < count($words)) {
309
+			$newWords[] = $words[$i];
310
+			++$i;
311
+		}
312
+		$ret = implode(' ', $newWords);
313
+
314
+		return $ret;
315
+	}
316
+
317
+	/**
318
+	 * @param $text
319
+	 * @param $minChar
320
+	 * @return array
321
+	 */
322
+	public function findMetaKeywords($text, $minChar)
323
+	{
324
+		$keywords = [];
325
+
326
+		$text = $this->purifyText($text);
327
+		$text = $this->html2text($text);
328
+
329
+		$text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text);
330
+		$text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text);
331
+		$text = preg_replace('/[ ]* [ ]*/', ' ', $text);
332
+		$text = stripslashes($text);
333
+		$text =
334
+
335
+		$originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY);
336
+
337
+		foreach ($originalKeywords as $originalKeyword) {
338
+			$secondRoundKeywords = explode("'", $originalKeyword);
339
+			foreach ($secondRoundKeywords as $secondRoundKeyword) {
340
+				if (strlen($secondRoundKeyword) >= $minChar) {
341
+					if (!in_array($secondRoundKeyword, $keywords)) {
342
+						$keywords[] = trim($secondRoundKeyword);
343
+					}
344
+				}
345
+			}
346
+		}
347
+
348
+		return $keywords;
349
+	}
350
+
351
+	/**
352
+	 * @return string
353
+	 */
354
+	public function createMetaKeywords()
355
+	{
356
+		global $xoopsModuleConfig;
357
+		$keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
358
+		if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords'])
359
+			&& '' !== $xoopsModuleConfig['moduleMetaKeywords']) {
360
+			$moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']);
361
+			$keywords       = array_merge($keywords, $moduleKeywords);
362
+		}
363
+
364
+		/* Commenting this out as it may cause problem on XOOPS ML websites
365 365
          $return_keywords = array();
366 366
 
367 367
          // Cleaning for duplicate keywords
@@ -371,43 +371,43 @@  discard block
 block discarded – undo
371 371
          }
372 372
          }*/
373 373
 
374
-        // Only take the first 90 keywords
375
-        $newKeywords = [];
376
-        $i           = 0;
377
-        while ($i < 90 - 1 && isset($keywords[$i])) {
378
-            $newKeywords[] = $keywords[$i];
379
-            ++$i;
380
-        }
381
-        $ret = implode(', ', $newKeywords);
382
-
383
-        return $ret;
384
-    }
385
-
386
-    public function autoBuildMeta_keywords()
387
-    {
388
-    }
389
-
390
-    public function buildAutoMetaTags()
391
-    {
392
-        global $xoopsModule, $xoopsModuleConfig;
393
-
394
-        $this->_keywords         = $this->createMetaKeywords();
395
-        $this->_meta_description = $this->createMetaDescription();
396
-        $this->_title            = $this->createTitleTag();
397
-    }
398
-
399
-    public function createMetaTags()
400
-    {
401
-        global $xoopsTpl, $xoTheme;
402
-
403
-        if (is_object($xoTheme)) {
404
-            $xoTheme->addMeta('meta', 'keywords', $this->_keywords);
405
-            $xoTheme->addMeta('meta', 'description', $this->_description);
406
-            $xoTheme->addMeta('meta', 'title', $this->_title);
407
-        } else {
408
-            $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords);
409
-            $xoopsTpl->assign('xoops_meta_description', $this->_description);
410
-        }
411
-        $xoopsTpl->assign('xoops_pagetitle', $this->_title);
412
-    }
374
+		// Only take the first 90 keywords
375
+		$newKeywords = [];
376
+		$i           = 0;
377
+		while ($i < 90 - 1 && isset($keywords[$i])) {
378
+			$newKeywords[] = $keywords[$i];
379
+			++$i;
380
+		}
381
+		$ret = implode(', ', $newKeywords);
382
+
383
+		return $ret;
384
+	}
385
+
386
+	public function autoBuildMeta_keywords()
387
+	{
388
+	}
389
+
390
+	public function buildAutoMetaTags()
391
+	{
392
+		global $xoopsModule, $xoopsModuleConfig;
393
+
394
+		$this->_keywords         = $this->createMetaKeywords();
395
+		$this->_meta_description = $this->createMetaDescription();
396
+		$this->_title            = $this->createTitleTag();
397
+	}
398
+
399
+	public function createMetaTags()
400
+	{
401
+		global $xoopsTpl, $xoTheme;
402
+
403
+		if (is_object($xoTheme)) {
404
+			$xoTheme->addMeta('meta', 'keywords', $this->_keywords);
405
+			$xoTheme->addMeta('meta', 'description', $this->_description);
406
+			$xoTheme->addMeta('meta', 'title', $this->_title);
407
+		} else {
408
+			$xoopsTpl->assign('xoops_meta_keywords', $this->_keywords);
409
+			$xoopsTpl->assign('xoops_meta_description', $this->_description);
410
+		}
411
+		$xoopsTpl->assign('xoops_pagetitle', $this->_title);
412
+	}
413 413
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -354,7 +354,7 @@
 block discarded – undo
354 354
     public function createMetaKeywords()
355 355
     {
356 356
         global $xoopsModuleConfig;
357
-        $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar);
357
+        $keywords = $this->findMetaKeywords($this->_original_title.' '.$this->_description, $this->_minChar);
358 358
         if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords'])
359 359
             && '' !== $xoopsModuleConfig['moduleMetaKeywords']) {
360 360
             $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']);
Please login to merge, or discard this patch.
class/smartdbupdater.php 2 patches
Indentation   +817 added lines, -817 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('Restricted access.');
20 20
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
21
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
21
+	require_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,503 +35,503 @@  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 = [];
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 ('YES' !== $existing_field['Null']) {
130
-                $fields[$existing_field['Field']] .= ' NOT NULL';
131
-            }
132
-            if ($existing_field['Extra']) {
133
-                $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
134
-            }
135
-            if (!(null === $existing_field['Default'])
136
-                && ($existing_field['Default']
137
-                    || '' === $existing_field['Default']
138
-                    || 0 == $existing_field['Default'])) {
139
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
140
-            }
141
-        }
142
-
143
-        return $fields;
144
-    }
145
-
146
-    /**
147
-     * @param $field
148
-     * @return bool
149
-     */
150
-    public function fieldExists($field)
151
-    {
152
-        $existingFields = $this->getExistingFieldsArray();
153
-
154
-        return isset($existingFields[$field]);
155
-    }
156
-
157
-    /**
158
-     * Set the table structure
159
-     *
160
-     * Example:
161
-     *
162
-     *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
163
-     *                `date` int(11) NOT NULL default '0',
164
-     *                `status` int(1) NOT NULL default '-1',
165
-     *                `itemid` int(11) NOT NULL default '0',
166
-     *                `uid` int(11) NOT NULL default '0',
167
-     *                `price` float NOT NULL default '0',
168
-     *                `currency` varchar(100) NOT NULL default '',
169
-     *                PRIMARY KEY  (`transactionid`)");
170
-     *
171
-     * @param string $structure table structure
172
-     *
173
-     */
174
-    public function setStructure($structure)
175
-    {
176
-        $this->_structure = $structure;
177
-    }
178
-
179
-    /**
180
-     * Return the table structure
181
-     *
182
-     * @return string table structure
183
-     *
184
-     */
185
-    public function getStructure()
186
-    {
187
-        return sprintf($this->_structure, $this->name());
188
-    }
189
-
190
-    /**
191
-     * Add values of a record to be added
192
-     *
193
-     * @param string $data values of a record
194
-     *
195
-     */
196
-    public function setData($data)
197
-    {
198
-        $this->_data[] = $data;
199
-    }
200
-
201
-    /**
202
-     * Get the data array
203
-     *
204
-     * @return array containing the records values to be added
205
-     *
206
-     */
207
-    public function getData()
208
-    {
209
-        return $this->_data;
210
-    }
211
-
212
-    /**
213
-     * Use to insert data in a table
214
-     *
215
-     * @return bool true if success, false if an error occured
216
-     *
217
-     */
218
-    public function addData()
219
-    {
220
-        global $xoopsDB;
221
-        foreach ($this->getData() as $data) {
222
-            $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
223
-            $ret   = $xoopsDB->query($query);
224
-            if (!$ret) {
225
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
226
-            } else {
227
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
228
-            }
229
-        }
230
-
231
-        return $ret;
232
-    }
233
-
234
-    /**
235
-     * Add a field to be added
236
-     *
237
-     * @param string $name       name of the field
238
-     * @param string $properties properties of the field
239
-     * @param bool   $newname
240
-     * @param bool   $showerror
241
-     */
242
-    public function addAlteredField($name, $properties, $newname = false, $showerror = true)
243
-    {
244
-        $field['name']          = $name;
245
-        $field['properties']    = $properties;
246
-        $field['showerror']     = $showerror;
247
-        $field['newname']       = $newname;
248
-        $this->_alteredFields[] = $field;
249
-    }
250
-    /**
251
-     * Invert values 0 to 1 and 1 to 0
252
-     *
253
-     * @param string $name name of the field
254
-     * @param        $newValue
255
-     * @param        $oldValue
256
-     * @internal param string $old old propertie
257
-     * @internal param string $new new propertie
258
-     */ //felix
259
-    public function addUpdatedWhere($name, $newValue, $oldValue)
260
-    {
261
-        $field['name']         = $name;
262
-        $field['value']        = $newValue;
263
-        $field['where']        = $oldValue;
264
-        $this->_updatedWhere[] = $field;
265
-    }
266
-
267
-    /**
268
-     * Add new field of a record to be added
269
-     *
270
-     * @param string $name       name of the field
271
-     * @param string $properties properties of the field
272
-     *
273
-     */
274
-    public function addNewField($name, $properties)
275
-    {
276
-        $field['name']       = $name;
277
-        $field['properties'] = $properties;
278
-        $this->_newFields[]  = $field;
279
-    }
280
-
281
-    /**
282
-     * Get fields that need to be altered
283
-     *
284
-     * @return array fields that need to be altered
285
-     *
286
-     */
287
-    public function getAlteredFields()
288
-    {
289
-        return $this->_alteredFields;
290
-    }
291
-
292
-    /**
293
-     * Add field for which the value will be updated
294
-     *
295
-     * @param string $name  name of the field
296
-     * @param string $value value to be set
297
-     *
298
-     */
299
-    public function addUpdatedField($name, $value)
300
-    {
301
-        $field['name']          = $name;
302
-        $field['value']         = $value;
303
-        $this->_updatedFields[] = $field;
304
-    }
305
-
306
-    /**
307
-     * Get new fields to be added
308
-     *
309
-     * @return array fields to be added
310
-     *
311
-     */
312
-    public function getNewFields()
313
-    {
314
-        return $this->_newFields;
315
-    }
316
-
317
-    /**
318
-     * Get fields which values need to be updated
319
-     *
320
-     * @return array fields which values need to be updated
321
-     *
322
-     */
323
-    public function getUpdatedFields()
324
-    {
325
-        return $this->_updatedFields;
326
-    }
327
-    /**
328
-     * Get fields which values need to be updated
329
-     *
330
-     * @return array fields which values need to be updated
331
-     *
332
-     */ //felix
333
-    public function getUpdatedWhere()
334
-    {
335
-        return $this->_updatedWhere;
336
-    }
337
-
338
-    /**
339
-     * Add values of a record to be added
340
-     *
341
-     * @param string $name name of the field
342
-     *
343
-     */
344
-    public function addDroppedField($name)
345
-    {
346
-        $this->_droppedFields[] = $name;
347
-    }
348
-
349
-    /**
350
-     * Get fields that need to be dropped
351
-     *
352
-     * @return array fields that need to be dropped
353
-     *
354
-     */
355
-    public function getDroppedFields()
356
-    {
357
-        return $this->_droppedFields;
358
-    }
359
-
360
-    /**
361
-     * Set the flag to drop the table
362
-     *
363
-     */
364
-    public function setFlagForDrop()
365
-    {
366
-        $this->_flagForDrop = true;
367
-    }
368
-
369
-    /**
370
-     * Use to create a table
371
-     *
372
-     * @return bool true if success, false if an error occured
373
-     *
374
-     */
375
-    public function createTable()
376
-    {
377
-        global $xoopsDB;
378
-        $query = $this->getStructure();
379
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
380
-        //xoops_debug($query);
381
-        $ret = $xoopsDB->query($query);
382
-        if (!$ret) {
383
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
384
-        } else {
385
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
386
-        }
387
-
388
-        return $ret;
389
-    }
390
-
391
-    /**
392
-     * Use to drop a table
393
-     *
394
-     * @return bool true if success, false if an error occured
395
-     *
396
-     */
397
-    public function dropTable()
398
-    {
399
-        global $xoopsDB;
400
-        $query = sprintf('DROP TABLE %s', $this->name());
401
-        $ret   = $xoopsDB->query($query);
402
-        if (!$ret) {
403
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
404
-
405
-            return false;
406
-        } else {
407
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
408
-
409
-            return true;
410
-        }
411
-    }
412
-
413
-    /**
414
-     * Use to alter a table
415
-     *
416
-     * @return bool true if success, false if an error occured
417
-     *
418
-     */
419
-    public function alterTable()
420
-    {
421
-        global $xoopsDB;
422
-        $ret = true;
423
-
424
-        foreach ($this->getAlteredFields() as $alteredField) {
425
-            if (!$alteredField['newname']) {
426
-                $alteredField['newname'] = $alteredField['name'];
427
-            }
428
-
429
-            $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
430
-            $ret   = $ret && $xoopsDB->query($query);
431
-            if ($alteredField['showerror']) {
432
-                if (!$ret) {
433
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
434
-                } else {
435
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
436
-                }
437
-            }
438
-        }
439
-
440
-        return $ret;
441
-    }
442
-
443
-    /**
444
-     * Use to add new fileds in the table
445
-     *
446
-     * @return bool true if success, false if an error occured
447
-     *
448
-     */
449
-    public function addNewFields()
450
-    {
451
-        global $xoopsDB;
452
-        $ret = true;
453
-        foreach ($this->getNewFields() as $newField) {
454
-            $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
455
-            //echo $query;
456
-            $ret = $ret && $xoopsDB->query($query);
457
-            if (!$ret) {
458
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
459
-            } else {
460
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
461
-            }
462
-        }
463
-
464
-        return $ret;
465
-    }
466
-
467
-    /**
468
-     * Use to update fields values
469
-     *
470
-     * @return bool true if success, false if an error occured
471
-     *
472
-     */
473
-    public function updateFieldsValues()
474
-    {
475
-        global $xoopsDB;
476
-        $ret = true;
477
-        foreach ($this->getUpdatedFields() as $updatedField) {
478
-            $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
479
-            $ret   = $ret && $xoopsDB->query($query);
480
-            if (!$ret) {
481
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
482
-            } else {
483
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
484
-            }
485
-        }
486
-
487
-        return $ret;
488
-    }
489
-    /**
490
-     * Use to update fields values
491
-     *
492
-     * @return bool true if success, false if an error occured
493
-     *
494
-     */ //felix
495
-    public function updateWhereValues()
496
-    {
497
-        global $xoopsDB;
498
-        $ret = true;
499
-        foreach ($this->getUpdatedWhere() as $updatedWhere) {
500
-            $query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
501
-            //echo $query."<br>";
502
-            $ret = $ret && $xoopsDB->query($query);
503
-            if (!$ret) {
504
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
505
-            } else {
506
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
507
-            }
508
-        }
509
-
510
-        return $ret;
511
-    }
512
-
513
-    /**
514
-     * Use to drop fields
515
-     *
516
-     * @return bool true if success, false if an error occured
517
-     *
518
-     */
519
-    public function dropFields()
520
-    {
521
-        global $xoopsDB;
522
-        $ret = true;
523
-        foreach ($this->getDroppedFields() as $droppedField) {
524
-            $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
525
-            $ret   = $ret && $xoopsDB->query($query);
526
-            if (!$ret) {
527
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
528
-            } else {
529
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
530
-            }
531
-        }
532
-
533
-        return $ret;
534
-    }
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 = [];
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 ('YES' !== $existing_field['Null']) {
130
+				$fields[$existing_field['Field']] .= ' NOT NULL';
131
+			}
132
+			if ($existing_field['Extra']) {
133
+				$fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
134
+			}
135
+			if (!(null === $existing_field['Default'])
136
+				&& ($existing_field['Default']
137
+					|| '' === $existing_field['Default']
138
+					|| 0 == $existing_field['Default'])) {
139
+				$fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
140
+			}
141
+		}
142
+
143
+		return $fields;
144
+	}
145
+
146
+	/**
147
+	 * @param $field
148
+	 * @return bool
149
+	 */
150
+	public function fieldExists($field)
151
+	{
152
+		$existingFields = $this->getExistingFieldsArray();
153
+
154
+		return isset($existingFields[$field]);
155
+	}
156
+
157
+	/**
158
+	 * Set the table structure
159
+	 *
160
+	 * Example:
161
+	 *
162
+	 *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
163
+	 *                `date` int(11) NOT NULL default '0',
164
+	 *                `status` int(1) NOT NULL default '-1',
165
+	 *                `itemid` int(11) NOT NULL default '0',
166
+	 *                `uid` int(11) NOT NULL default '0',
167
+	 *                `price` float NOT NULL default '0',
168
+	 *                `currency` varchar(100) NOT NULL default '',
169
+	 *                PRIMARY KEY  (`transactionid`)");
170
+	 *
171
+	 * @param string $structure table structure
172
+	 *
173
+	 */
174
+	public function setStructure($structure)
175
+	{
176
+		$this->_structure = $structure;
177
+	}
178
+
179
+	/**
180
+	 * Return the table structure
181
+	 *
182
+	 * @return string table structure
183
+	 *
184
+	 */
185
+	public function getStructure()
186
+	{
187
+		return sprintf($this->_structure, $this->name());
188
+	}
189
+
190
+	/**
191
+	 * Add values of a record to be added
192
+	 *
193
+	 * @param string $data values of a record
194
+	 *
195
+	 */
196
+	public function setData($data)
197
+	{
198
+		$this->_data[] = $data;
199
+	}
200
+
201
+	/**
202
+	 * Get the data array
203
+	 *
204
+	 * @return array containing the records values to be added
205
+	 *
206
+	 */
207
+	public function getData()
208
+	{
209
+		return $this->_data;
210
+	}
211
+
212
+	/**
213
+	 * Use to insert data in a table
214
+	 *
215
+	 * @return bool true if success, false if an error occured
216
+	 *
217
+	 */
218
+	public function addData()
219
+	{
220
+		global $xoopsDB;
221
+		foreach ($this->getData() as $data) {
222
+			$query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
223
+			$ret   = $xoopsDB->query($query);
224
+			if (!$ret) {
225
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
226
+			} else {
227
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
228
+			}
229
+		}
230
+
231
+		return $ret;
232
+	}
233
+
234
+	/**
235
+	 * Add a field to be added
236
+	 *
237
+	 * @param string $name       name of the field
238
+	 * @param string $properties properties of the field
239
+	 * @param bool   $newname
240
+	 * @param bool   $showerror
241
+	 */
242
+	public function addAlteredField($name, $properties, $newname = false, $showerror = true)
243
+	{
244
+		$field['name']          = $name;
245
+		$field['properties']    = $properties;
246
+		$field['showerror']     = $showerror;
247
+		$field['newname']       = $newname;
248
+		$this->_alteredFields[] = $field;
249
+	}
250
+	/**
251
+	 * Invert values 0 to 1 and 1 to 0
252
+	 *
253
+	 * @param string $name name of the field
254
+	 * @param        $newValue
255
+	 * @param        $oldValue
256
+	 * @internal param string $old old propertie
257
+	 * @internal param string $new new propertie
258
+	 */ //felix
259
+	public function addUpdatedWhere($name, $newValue, $oldValue)
260
+	{
261
+		$field['name']         = $name;
262
+		$field['value']        = $newValue;
263
+		$field['where']        = $oldValue;
264
+		$this->_updatedWhere[] = $field;
265
+	}
266
+
267
+	/**
268
+	 * Add new field of a record to be added
269
+	 *
270
+	 * @param string $name       name of the field
271
+	 * @param string $properties properties of the field
272
+	 *
273
+	 */
274
+	public function addNewField($name, $properties)
275
+	{
276
+		$field['name']       = $name;
277
+		$field['properties'] = $properties;
278
+		$this->_newFields[]  = $field;
279
+	}
280
+
281
+	/**
282
+	 * Get fields that need to be altered
283
+	 *
284
+	 * @return array fields that need to be altered
285
+	 *
286
+	 */
287
+	public function getAlteredFields()
288
+	{
289
+		return $this->_alteredFields;
290
+	}
291
+
292
+	/**
293
+	 * Add field for which the value will be updated
294
+	 *
295
+	 * @param string $name  name of the field
296
+	 * @param string $value value to be set
297
+	 *
298
+	 */
299
+	public function addUpdatedField($name, $value)
300
+	{
301
+		$field['name']          = $name;
302
+		$field['value']         = $value;
303
+		$this->_updatedFields[] = $field;
304
+	}
305
+
306
+	/**
307
+	 * Get new fields to be added
308
+	 *
309
+	 * @return array fields to be added
310
+	 *
311
+	 */
312
+	public function getNewFields()
313
+	{
314
+		return $this->_newFields;
315
+	}
316
+
317
+	/**
318
+	 * Get fields which values need to be updated
319
+	 *
320
+	 * @return array fields which values need to be updated
321
+	 *
322
+	 */
323
+	public function getUpdatedFields()
324
+	{
325
+		return $this->_updatedFields;
326
+	}
327
+	/**
328
+	 * Get fields which values need to be updated
329
+	 *
330
+	 * @return array fields which values need to be updated
331
+	 *
332
+	 */ //felix
333
+	public function getUpdatedWhere()
334
+	{
335
+		return $this->_updatedWhere;
336
+	}
337
+
338
+	/**
339
+	 * Add values of a record to be added
340
+	 *
341
+	 * @param string $name name of the field
342
+	 *
343
+	 */
344
+	public function addDroppedField($name)
345
+	{
346
+		$this->_droppedFields[] = $name;
347
+	}
348
+
349
+	/**
350
+	 * Get fields that need to be dropped
351
+	 *
352
+	 * @return array fields that need to be dropped
353
+	 *
354
+	 */
355
+	public function getDroppedFields()
356
+	{
357
+		return $this->_droppedFields;
358
+	}
359
+
360
+	/**
361
+	 * Set the flag to drop the table
362
+	 *
363
+	 */
364
+	public function setFlagForDrop()
365
+	{
366
+		$this->_flagForDrop = true;
367
+	}
368
+
369
+	/**
370
+	 * Use to create a table
371
+	 *
372
+	 * @return bool true if success, false if an error occured
373
+	 *
374
+	 */
375
+	public function createTable()
376
+	{
377
+		global $xoopsDB;
378
+		$query = $this->getStructure();
379
+		$query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
380
+		//xoops_debug($query);
381
+		$ret = $xoopsDB->query($query);
382
+		if (!$ret) {
383
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
384
+		} else {
385
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
386
+		}
387
+
388
+		return $ret;
389
+	}
390
+
391
+	/**
392
+	 * Use to drop a table
393
+	 *
394
+	 * @return bool true if success, false if an error occured
395
+	 *
396
+	 */
397
+	public function dropTable()
398
+	{
399
+		global $xoopsDB;
400
+		$query = sprintf('DROP TABLE %s', $this->name());
401
+		$ret   = $xoopsDB->query($query);
402
+		if (!$ret) {
403
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
404
+
405
+			return false;
406
+		} else {
407
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
408
+
409
+			return true;
410
+		}
411
+	}
412
+
413
+	/**
414
+	 * Use to alter a table
415
+	 *
416
+	 * @return bool true if success, false if an error occured
417
+	 *
418
+	 */
419
+	public function alterTable()
420
+	{
421
+		global $xoopsDB;
422
+		$ret = true;
423
+
424
+		foreach ($this->getAlteredFields() as $alteredField) {
425
+			if (!$alteredField['newname']) {
426
+				$alteredField['newname'] = $alteredField['name'];
427
+			}
428
+
429
+			$query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
430
+			$ret   = $ret && $xoopsDB->query($query);
431
+			if ($alteredField['showerror']) {
432
+				if (!$ret) {
433
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
434
+				} else {
435
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
436
+				}
437
+			}
438
+		}
439
+
440
+		return $ret;
441
+	}
442
+
443
+	/**
444
+	 * Use to add new fileds in the table
445
+	 *
446
+	 * @return bool true if success, false if an error occured
447
+	 *
448
+	 */
449
+	public function addNewFields()
450
+	{
451
+		global $xoopsDB;
452
+		$ret = true;
453
+		foreach ($this->getNewFields() as $newField) {
454
+			$query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
455
+			//echo $query;
456
+			$ret = $ret && $xoopsDB->query($query);
457
+			if (!$ret) {
458
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
459
+			} else {
460
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
461
+			}
462
+		}
463
+
464
+		return $ret;
465
+	}
466
+
467
+	/**
468
+	 * Use to update fields values
469
+	 *
470
+	 * @return bool true if success, false if an error occured
471
+	 *
472
+	 */
473
+	public function updateFieldsValues()
474
+	{
475
+		global $xoopsDB;
476
+		$ret = true;
477
+		foreach ($this->getUpdatedFields() as $updatedField) {
478
+			$query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
479
+			$ret   = $ret && $xoopsDB->query($query);
480
+			if (!$ret) {
481
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
482
+			} else {
483
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
484
+			}
485
+		}
486
+
487
+		return $ret;
488
+	}
489
+	/**
490
+	 * Use to update fields values
491
+	 *
492
+	 * @return bool true if success, false if an error occured
493
+	 *
494
+	 */ //felix
495
+	public function updateWhereValues()
496
+	{
497
+		global $xoopsDB;
498
+		$ret = true;
499
+		foreach ($this->getUpdatedWhere() as $updatedWhere) {
500
+			$query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
501
+			//echo $query."<br>";
502
+			$ret = $ret && $xoopsDB->query($query);
503
+			if (!$ret) {
504
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
505
+			} else {
506
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
507
+			}
508
+		}
509
+
510
+		return $ret;
511
+	}
512
+
513
+	/**
514
+	 * Use to drop fields
515
+	 *
516
+	 * @return bool true if success, false if an error occured
517
+	 *
518
+	 */
519
+	public function dropFields()
520
+	{
521
+		global $xoopsDB;
522
+		$ret = true;
523
+		foreach ($this->getDroppedFields() as $droppedField) {
524
+			$query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
525
+			$ret   = $ret && $xoopsDB->query($query);
526
+			if (!$ret) {
527
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
528
+			} else {
529
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
530
+			}
531
+		}
532
+
533
+		return $ret;
534
+	}
535 535
 }
536 536
 
537 537
 /**
@@ -545,328 +545,328 @@  discard block
 block discarded – undo
545 545
  */
546 546
 class SmartobjectDbupdater
547 547
 {
548
-    public $_dbTypesArray;
549
-
550
-    /**
551
-     * SmartobjectDbupdater constructor.
552
-     */
553
-    public function __construct()
554
-    {
555
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
556
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
557
-        $this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
558
-        $this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
559
-        $this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
560
-        $this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
561
-        $this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
562
-        $this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
563
-        $this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
564
-        $this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
565
-        $this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
566
-        $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
567
-        $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
568
-        $this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
569
-        $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
570
-        $this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
571
-        $this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
572
-        $this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
573
-    }
574
-
575
-    /**
576
-     * Use to execute a general query
577
-     *
578
-     * @param string $query   query that will be executed
579
-     * @param string $goodmsg message displayed on success
580
-     * @param string $badmsg  message displayed on error
581
-     *
582
-     * @return bool true if success, false if an error occured
583
-     *
584
-     */
585
-    public function runQuery($query, $goodmsg, $badmsg)
586
-    {
587
-        global $xoopsDB;
588
-        $ret = $xoopsDB->query($query);
589
-        if (!$ret) {
590
-            echo "&nbsp;&nbsp;$badmsg<br>";
591
-
592
-            return false;
593
-        } else {
594
-            echo "&nbsp;&nbsp;$goodmsg<br>";
595
-
596
-            return true;
597
-        }
598
-    }
599
-
600
-    /**
601
-     * Use to rename a table
602
-     *
603
-     * @param string $from name of the table to rename
604
-     * @param string $to   new name of the renamed table
605
-     *
606
-     * @return bool true if success, false if an error occured
607
-     */
608
-    public function renameTable($from, $to)
609
-    {
610
-        global $xoopsDB;
611
-        $from  = $xoopsDB->prefix($from);
612
-        $to    = $xoopsDB->prefix($to);
613
-        $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
614
-        $ret   = $xoopsDB->query($query);
615
-        if (!$ret) {
616
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
617
-
618
-            return false;
619
-        } else {
620
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
621
-
622
-            return true;
623
-        }
624
-    }
625
-
626
-    /**
627
-     * Use to update a table
628
-     *
629
-     * @param object $table {@link SmartDbTable} that will be updated
630
-     *
631
-     * @see SmartDbTable
632
-     *
633
-     * @return bool true if success, false if an error occured
634
-     */
635
-    public function updateTable($table)
636
-    {
637
-        global $xoopsDB;
638
-        $ret = true;
639
-        // If table has a structure, create the table
640
-        if ($table->getStructure()) {
641
-            $ret = $table->createTable() && $ret;
642
-        }
643
-        // If table is flag for drop, drop it
644
-        if ($table->_flagForDrop) {
645
-            $ret = $table->dropTable() && $ret;
646
-        }
647
-        // If table has data, insert it
648
-        if ($table->getData()) {
649
-            $ret = $table->addData() && $ret;
650
-        }
651
-        // If table has new fields to be added, add them
652
-        if ($table->getNewFields()) {
653
-            $ret = $table->addNewFields() && $ret;
654
-        }
655
-        // If table has altered field, alter the table
656
-        if ($table->getAlteredFields()) {
657
-            $ret = $table->alterTable() && $ret;
658
-        }
659
-        // If table has updated field values, update the table
660
-        if ($table->getUpdatedFields()) {
661
-            $ret = $table->updateFieldsValues($table) && $ret;
662
-        }
663
-        // If table has dropped field, alter the table
664
-        if ($table->getDroppedFields()) {
665
-            $ret = $table->dropFields($table) && $ret;
666
-        }
667
-        //felix
668
-        // If table has updated field values, update the table
669
-        if ($table->getUpdatedWhere()) {
670
-            $ret = $table->UpdateWhereValues($table) && $ret;
671
-        }
672
-
673
-        return $ret;
674
-    }
675
-
676
-    /**
677
-     * @param $module
678
-     * @param $item
679
-     */
680
-    public function automaticUpgrade($module, $item)
681
-    {
682
-        if (is_array($item)) {
683
-            foreach ($item as $v) {
684
-                $this->upgradeObjectItem($module, $v);
685
-            }
686
-        } else {
687
-            $this->upgradeObjectItem($module, $item);
688
-        }
689
-    }
690
-
691
-    /**
692
-     * @param $var
693
-     * @return string
694
-     */
695
-    public function getFieldTypeFromVar($var)
696
-    {
697
-        $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
698
-
699
-        return $ret;
700
-    }
701
-
702
-    /**
703
-     * @param         $var
704
-     * @param  bool   $key
705
-     * @return string
706
-     */
707
-    public function getFieldDefaultFromVar($var, $key = false)
708
-    {
709
-        if ($var['value']) {
710
-            return $var['value'];
711
-        } else {
712
-            if (in_array($var['data_type'], [
713
-                XOBJ_DTYPE_INT,
714
-                XOBJ_DTYPE_STIME,
715
-                XOBJ_DTYPE_MTIME,
716
-                XOBJ_DTYPE_LTIME,
717
-                XOBJ_DTYPE_TIME_ONLY,
718
-                XOBJ_DTYPE_URLLINK,
719
-                XOBJ_DTYPE_FILE
720
-            ])) {
721
-                return '0';
722
-            } else {
723
-                return '';
724
-            }
725
-        }
726
-    }
727
-
728
-    /**
729
-     * @param $module
730
-     * @param $item
731
-     * @return bool
732
-     */
733
-    public function upgradeObjectItem($module, $item)
734
-    {
735
-        $moduleHandler = xoops_getModuleHandler($item, $module);
736
-        if (!$moduleHandler) {
737
-            return false;
738
-        }
739
-
740
-        $table      = new SmartDbTable($module . '_' . $item);
741
-        $object     = $moduleHandler->create();
742
-        $objectVars = $object->getVars();
743
-
744
-        if (!$table->exists()) {
745
-            // table was never created, let's do it
746
-            $structure = '';
747
-            foreach ($objectVars as $key => $var) {
748
-                if ($var['persistent']) {
749
-                    $type = $this->getFieldTypeFromVar($var);
750
-                    if ($key == $moduleHandler->keyName) {
751
-                        $extra = 'auto_increment';
752
-                    } else {
753
-                        $default = $this->getFieldDefaultFromVar($var);
754
-                        $extra   = "default '$default'
548
+	public $_dbTypesArray;
549
+
550
+	/**
551
+	 * SmartobjectDbupdater constructor.
552
+	 */
553
+	public function __construct()
554
+	{
555
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
556
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
557
+		$this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
558
+		$this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
559
+		$this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
560
+		$this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
561
+		$this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
562
+		$this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
563
+		$this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
564
+		$this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
565
+		$this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
566
+		$this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
567
+		$this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
568
+		$this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
569
+		$this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
570
+		$this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
571
+		$this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
572
+		$this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
573
+	}
574
+
575
+	/**
576
+	 * Use to execute a general query
577
+	 *
578
+	 * @param string $query   query that will be executed
579
+	 * @param string $goodmsg message displayed on success
580
+	 * @param string $badmsg  message displayed on error
581
+	 *
582
+	 * @return bool true if success, false if an error occured
583
+	 *
584
+	 */
585
+	public function runQuery($query, $goodmsg, $badmsg)
586
+	{
587
+		global $xoopsDB;
588
+		$ret = $xoopsDB->query($query);
589
+		if (!$ret) {
590
+			echo "&nbsp;&nbsp;$badmsg<br>";
591
+
592
+			return false;
593
+		} else {
594
+			echo "&nbsp;&nbsp;$goodmsg<br>";
595
+
596
+			return true;
597
+		}
598
+	}
599
+
600
+	/**
601
+	 * Use to rename a table
602
+	 *
603
+	 * @param string $from name of the table to rename
604
+	 * @param string $to   new name of the renamed table
605
+	 *
606
+	 * @return bool true if success, false if an error occured
607
+	 */
608
+	public function renameTable($from, $to)
609
+	{
610
+		global $xoopsDB;
611
+		$from  = $xoopsDB->prefix($from);
612
+		$to    = $xoopsDB->prefix($to);
613
+		$query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
614
+		$ret   = $xoopsDB->query($query);
615
+		if (!$ret) {
616
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
617
+
618
+			return false;
619
+		} else {
620
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
621
+
622
+			return true;
623
+		}
624
+	}
625
+
626
+	/**
627
+	 * Use to update a table
628
+	 *
629
+	 * @param object $table {@link SmartDbTable} that will be updated
630
+	 *
631
+	 * @see SmartDbTable
632
+	 *
633
+	 * @return bool true if success, false if an error occured
634
+	 */
635
+	public function updateTable($table)
636
+	{
637
+		global $xoopsDB;
638
+		$ret = true;
639
+		// If table has a structure, create the table
640
+		if ($table->getStructure()) {
641
+			$ret = $table->createTable() && $ret;
642
+		}
643
+		// If table is flag for drop, drop it
644
+		if ($table->_flagForDrop) {
645
+			$ret = $table->dropTable() && $ret;
646
+		}
647
+		// If table has data, insert it
648
+		if ($table->getData()) {
649
+			$ret = $table->addData() && $ret;
650
+		}
651
+		// If table has new fields to be added, add them
652
+		if ($table->getNewFields()) {
653
+			$ret = $table->addNewFields() && $ret;
654
+		}
655
+		// If table has altered field, alter the table
656
+		if ($table->getAlteredFields()) {
657
+			$ret = $table->alterTable() && $ret;
658
+		}
659
+		// If table has updated field values, update the table
660
+		if ($table->getUpdatedFields()) {
661
+			$ret = $table->updateFieldsValues($table) && $ret;
662
+		}
663
+		// If table has dropped field, alter the table
664
+		if ($table->getDroppedFields()) {
665
+			$ret = $table->dropFields($table) && $ret;
666
+		}
667
+		//felix
668
+		// If table has updated field values, update the table
669
+		if ($table->getUpdatedWhere()) {
670
+			$ret = $table->UpdateWhereValues($table) && $ret;
671
+		}
672
+
673
+		return $ret;
674
+	}
675
+
676
+	/**
677
+	 * @param $module
678
+	 * @param $item
679
+	 */
680
+	public function automaticUpgrade($module, $item)
681
+	{
682
+		if (is_array($item)) {
683
+			foreach ($item as $v) {
684
+				$this->upgradeObjectItem($module, $v);
685
+			}
686
+		} else {
687
+			$this->upgradeObjectItem($module, $item);
688
+		}
689
+	}
690
+
691
+	/**
692
+	 * @param $var
693
+	 * @return string
694
+	 */
695
+	public function getFieldTypeFromVar($var)
696
+	{
697
+		$ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
698
+
699
+		return $ret;
700
+	}
701
+
702
+	/**
703
+	 * @param         $var
704
+	 * @param  bool   $key
705
+	 * @return string
706
+	 */
707
+	public function getFieldDefaultFromVar($var, $key = false)
708
+	{
709
+		if ($var['value']) {
710
+			return $var['value'];
711
+		} else {
712
+			if (in_array($var['data_type'], [
713
+				XOBJ_DTYPE_INT,
714
+				XOBJ_DTYPE_STIME,
715
+				XOBJ_DTYPE_MTIME,
716
+				XOBJ_DTYPE_LTIME,
717
+				XOBJ_DTYPE_TIME_ONLY,
718
+				XOBJ_DTYPE_URLLINK,
719
+				XOBJ_DTYPE_FILE
720
+			])) {
721
+				return '0';
722
+			} else {
723
+				return '';
724
+			}
725
+		}
726
+	}
727
+
728
+	/**
729
+	 * @param $module
730
+	 * @param $item
731
+	 * @return bool
732
+	 */
733
+	public function upgradeObjectItem($module, $item)
734
+	{
735
+		$moduleHandler = xoops_getModuleHandler($item, $module);
736
+		if (!$moduleHandler) {
737
+			return false;
738
+		}
739
+
740
+		$table      = new SmartDbTable($module . '_' . $item);
741
+		$object     = $moduleHandler->create();
742
+		$objectVars = $object->getVars();
743
+
744
+		if (!$table->exists()) {
745
+			// table was never created, let's do it
746
+			$structure = '';
747
+			foreach ($objectVars as $key => $var) {
748
+				if ($var['persistent']) {
749
+					$type = $this->getFieldTypeFromVar($var);
750
+					if ($key == $moduleHandler->keyName) {
751
+						$extra = 'auto_increment';
752
+					} else {
753
+						$default = $this->getFieldDefaultFromVar($var);
754
+						$extra   = "default '$default'
755 755
 ";
756
-                    }
757
-                    $structure .= "`$key` $type not null $extra,
756
+					}
757
+					$structure .= "`$key` $type not null $extra,
758 758
 ";
759
-                }
760
-            }
761
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
759
+				}
760
+			}
761
+			$structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
762 762
 ';
763
-            $table->setStructure($structure);
764
-            if (!$this->updateTable($table)) {
765
-                /**
766
-                 * @todo trap the errors
767
-                 */
768
-            }
769
-        } else {
770
-            $existingFieldsArray = $table->getExistingFieldsArray();
771
-            foreach ($objectVars as $key => $var) {
772
-                if ($var['persistent']) {
773
-                    if (!isset($existingFieldsArray[$key])) {
774
-                        // the fiels does not exist, let's create it
775
-                        $type    = $this->getFieldTypeFromVar($var);
776
-                        $default = $this->getFieldDefaultFromVar($var);
777
-                        $table->addNewField($key, "$type not null default '$default'");
778
-                    } else {
779
-                        // if field already exists, let's check if the definition is correct
780
-                        $definition = strtolower($existingFieldsArray[$key]);
781
-                        $type       = $this->getFieldTypeFromVar($var);
782
-                        if ($key == $moduleHandler->keyName) {
783
-                            $extra = 'auto_increment';
784
-                        } else {
785
-                            $default = $this->getFieldDefaultFromVar($var, $key);
786
-                            $extra   = "default '$default'";
787
-                        }
788
-                        $actual_definition = "$type not null $extra";
789
-                        if ($definition != $actual_definition) {
790
-                            $table->addAlteredField($key, $actual_definition);
791
-                        }
792
-                    }
793
-                }
794
-            }
795
-
796
-            // check to see if there are some unused fields left in the table
797
-            foreach ($existingFieldsArray as $key => $v) {
798
-                if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
799
-                    $table->addDroppedField($key);
800
-                }
801
-            }
802
-
803
-            if (!$this->updateTable($table)) {
804
-                /**
805
-                 * @todo trap the errors
806
-                 */
807
-            }
808
-        }
809
-    }
810
-
811
-    /**
812
-     * @param $module
813
-     * @return bool
814
-     */
815
-    public function moduleUpgrade(XoopsModule $module)
816
-    {
817
-        $dirname = $module->getVar('dirname');
818
-
819
-        ob_start();
820
-
821
-        $table = new SmartDbTable($dirname . '_meta');
822
-        if (!$table->exists()) {
823
-            $table->setStructure("
763
+			$table->setStructure($structure);
764
+			if (!$this->updateTable($table)) {
765
+				/**
766
+				 * @todo trap the errors
767
+				 */
768
+			}
769
+		} else {
770
+			$existingFieldsArray = $table->getExistingFieldsArray();
771
+			foreach ($objectVars as $key => $var) {
772
+				if ($var['persistent']) {
773
+					if (!isset($existingFieldsArray[$key])) {
774
+						// the fiels does not exist, let's create it
775
+						$type    = $this->getFieldTypeFromVar($var);
776
+						$default = $this->getFieldDefaultFromVar($var);
777
+						$table->addNewField($key, "$type not null default '$default'");
778
+					} else {
779
+						// if field already exists, let's check if the definition is correct
780
+						$definition = strtolower($existingFieldsArray[$key]);
781
+						$type       = $this->getFieldTypeFromVar($var);
782
+						if ($key == $moduleHandler->keyName) {
783
+							$extra = 'auto_increment';
784
+						} else {
785
+							$default = $this->getFieldDefaultFromVar($var, $key);
786
+							$extra   = "default '$default'";
787
+						}
788
+						$actual_definition = "$type not null $extra";
789
+						if ($definition != $actual_definition) {
790
+							$table->addAlteredField($key, $actual_definition);
791
+						}
792
+					}
793
+				}
794
+			}
795
+
796
+			// check to see if there are some unused fields left in the table
797
+			foreach ($existingFieldsArray as $key => $v) {
798
+				if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
799
+					$table->addDroppedField($key);
800
+				}
801
+			}
802
+
803
+			if (!$this->updateTable($table)) {
804
+				/**
805
+				 * @todo trap the errors
806
+				 */
807
+			}
808
+		}
809
+	}
810
+
811
+	/**
812
+	 * @param $module
813
+	 * @return bool
814
+	 */
815
+	public function moduleUpgrade(XoopsModule $module)
816
+	{
817
+		$dirname = $module->getVar('dirname');
818
+
819
+		ob_start();
820
+
821
+		$table = new SmartDbTable($dirname . '_meta');
822
+		if (!$table->exists()) {
823
+			$table->setStructure("
824 824
               `metakey` varchar(50) NOT NULL default '',
825 825
               `metavalue` varchar(255) NOT NULL default '',
826 826
               PRIMARY KEY (`metakey`)");
827
-            $table->setData("'version',0");
828
-            if (!$this->updateTable($table)) {
829
-                /**
830
-                 * @todo trap the errors
831
-                 */
832
-            }
833
-        }
834
-
835
-        $dbVersion = smart_GetMeta('version', $dirname);
836
-        if (!$dbVersion) {
837
-            $dbVersion = 0;
838
-        }
839
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
840
-        echo 'Database version: ' . $dbVersion . '<br>';
841
-        echo 'New database version: ' . $newDbVersion . '<br>';
842
-
843
-        if ($newDbVersion > $dbVersion) {
844
-            for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
845
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
846
-                if (function_exists($upgrade_function)) {
847
-                    $upgrade_function();
848
-                }
849
-            }
850
-        }
851
-
852
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
853
-
854
-        // if there is a function to execute for this DB version, let's do it
855
-        //$function_
856
-
857
-        $module_info = smart_getModuleInfo($dirname);
858
-        $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
859
-
860
-        echo '</code>';
861
-
862
-        $feedback = ob_get_clean();
863
-        if (method_exists($module, 'setMessage')) {
864
-            $module->setMessage($feedback);
865
-        } else {
866
-            echo $feedback;
867
-        }
868
-        smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
869
-
870
-        return true;
871
-    }
827
+			$table->setData("'version',0");
828
+			if (!$this->updateTable($table)) {
829
+				/**
830
+				 * @todo trap the errors
831
+				 */
832
+			}
833
+		}
834
+
835
+		$dbVersion = smart_GetMeta('version', $dirname);
836
+		if (!$dbVersion) {
837
+			$dbVersion = 0;
838
+		}
839
+		$newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
840
+		echo 'Database version: ' . $dbVersion . '<br>';
841
+		echo 'New database version: ' . $newDbVersion . '<br>';
842
+
843
+		if ($newDbVersion > $dbVersion) {
844
+			for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
845
+				$upgrade_function = $dirname . '_db_upgrade_' . $i;
846
+				if (function_exists($upgrade_function)) {
847
+					$upgrade_function();
848
+				}
849
+			}
850
+		}
851
+
852
+		echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
853
+
854
+		// if there is a function to execute for this DB version, let's do it
855
+		//$function_
856
+
857
+		$module_info = smart_getModuleInfo($dirname);
858
+		$this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
859
+
860
+		echo '</code>';
861
+
862
+		$feedback = ob_get_clean();
863
+		if (method_exists($module, 'setMessage')) {
864
+			$module->setMessage($feedback);
865
+		} else {
866
+			echo $feedback;
867
+		}
868
+		smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
869
+
870
+		return true;
871
+	}
872 872
 }
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('Restricted access.');
20 20
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
21
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
21
+    require_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,20 +123,20 @@  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 ('YES' !== $existing_field['Null']) {
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 (!(null === $existing_field['Default'])
136 136
                 && ($existing_field['Default']
137 137
                     || '' === $existing_field['Default']
138 138
                     || 0 == $existing_field['Default'])) {
139
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
139
+                $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'";
140 140
             }
141 141
         }
142 142
 
@@ -222,9 +222,9 @@  discard block
 block discarded – undo
222 222
             $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
223 223
             $ret   = $xoopsDB->query($query);
224 224
             if (!$ret) {
225
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
225
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>';
226 226
             } else {
227
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
227
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>';
228 228
             }
229 229
         }
230 230
 
@@ -376,13 +376,13 @@  discard block
 block discarded – undo
376 376
     {
377 377
         global $xoopsDB;
378 378
         $query = $this->getStructure();
379
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
379
+        $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
380 380
         //xoops_debug($query);
381 381
         $ret = $xoopsDB->query($query);
382 382
         if (!$ret) {
383
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
383
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
384 384
         } else {
385
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
385
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>';
386 386
         }
387 387
 
388 388
         return $ret;
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
         $query = sprintf('DROP TABLE %s', $this->name());
401 401
         $ret   = $xoopsDB->query($query);
402 402
         if (!$ret) {
403
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
403
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
404 404
 
405 405
             return false;
406 406
         } else {
407
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
407
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>';
408 408
 
409 409
             return true;
410 410
         }
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
             $ret   = $ret && $xoopsDB->query($query);
431 431
             if ($alteredField['showerror']) {
432 432
                 if (!$ret) {
433
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
433
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>';
434 434
                 } else {
435
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
435
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>';
436 436
                 }
437 437
             }
438 438
         }
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
             //echo $query;
456 456
             $ret = $ret && $xoopsDB->query($query);
457 457
             if (!$ret) {
458
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
458
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>';
459 459
             } else {
460
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
460
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>';
461 461
             }
462 462
         }
463 463
 
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
             $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
479 479
             $ret   = $ret && $xoopsDB->query($query);
480 480
             if (!$ret) {
481
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
481
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
482 482
             } else {
483
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
483
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
484 484
             }
485 485
         }
486 486
 
@@ -501,9 +501,9 @@  discard block
 block discarded – undo
501 501
             //echo $query."<br>";
502 502
             $ret = $ret && $xoopsDB->query($query);
503 503
             if (!$ret) {
504
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
504
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
505 505
             } else {
506
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
506
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
507 507
             }
508 508
         }
509 509
 
@@ -524,9 +524,9 @@  discard block
 block discarded – undo
524 524
             $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
525 525
             $ret   = $ret && $xoopsDB->query($query);
526 526
             if (!$ret) {
527
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
527
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>';
528 528
             } else {
529
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
529
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>';
530 530
             }
531 531
         }
532 532
 
@@ -613,11 +613,11 @@  discard block
 block discarded – undo
613 613
         $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
614 614
         $ret   = $xoopsDB->query($query);
615 615
         if (!$ret) {
616
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
616
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>';
617 617
 
618 618
             return false;
619 619
         } else {
620
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
620
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>';
621 621
 
622 622
             return true;
623 623
         }
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
             return false;
738 738
         }
739 739
 
740
-        $table      = new SmartDbTable($module . '_' . $item);
740
+        $table      = new SmartDbTable($module.'_'.$item);
741 741
         $object     = $moduleHandler->create();
742 742
         $objectVars = $object->getVars();
743 743
 
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 ";
759 759
                 }
760 760
             }
761
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
761
+            $structure .= 'PRIMARY KEY  (`'.$moduleHandler->keyName.'`)
762 762
 ';
763 763
             $table->setStructure($structure);
764 764
             if (!$this->updateTable($table)) {
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
         ob_start();
820 820
 
821
-        $table = new SmartDbTable($dirname . '_meta');
821
+        $table = new SmartDbTable($dirname.'_meta');
822 822
         if (!$table->exists()) {
823 823
             $table->setStructure("
824 824
               `metakey` varchar(50) NOT NULL default '',
@@ -836,20 +836,20 @@  discard block
 block discarded – undo
836 836
         if (!$dbVersion) {
837 837
             $dbVersion = 0;
838 838
         }
839
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
840
-        echo 'Database version: ' . $dbVersion . '<br>';
841
-        echo 'New database version: ' . $newDbVersion . '<br>';
839
+        $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0;
840
+        echo 'Database version: '.$dbVersion.'<br>';
841
+        echo 'New database version: '.$newDbVersion.'<br>';
842 842
 
843 843
         if ($newDbVersion > $dbVersion) {
844 844
             for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
845
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
845
+                $upgrade_function = $dirname.'_db_upgrade_'.$i;
846 846
                 if (function_exists($upgrade_function)) {
847 847
                     $upgrade_function();
848 848
                 }
849 849
             }
850 850
         }
851 851
 
852
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
852
+        echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>';
853 853
 
854 854
         // if there is a function to execute for this DB version, let's do it
855 855
         //$function_
Please login to merge, or discard this patch.
class/utility.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -5,149 +5,149 @@
 block discarded – undo
5 5
  */
6 6
 class SmartObjectUtility extends XoopsObject
7 7
 {
8
-    /**
9
-     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
10
-     *
11
-     * @param string $folder The full path of the directory to check
12
-     *
13
-     * @return void
14
-     */
15
-    public static function createFolder($folder)
16
-    {
17
-        //        try {
18
-        //            if (!mkdir($folder) && !is_dir($folder)) {
19
-        //                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
20
-        //            } else {
21
-        //                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
22
-        //            }
23
-        //        }
24
-        //        catch (Exception $e) {
25
-        //            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
26
-        //        }
27
-        try {
28
-            if (!file_exists($folder)) {
29
-                if (!mkdir($folder) && !is_dir($folder)) {
30
-                    throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31
-                } else {
32
-                    file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
33
-                }
34
-            }
35
-        } catch (Exception $e) {
36
-            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
37
-        }
38
-    }
8
+	/**
9
+	 * Function responsible for checking if a directory exists, we can also write in and create an index.html file
10
+	 *
11
+	 * @param string $folder The full path of the directory to check
12
+	 *
13
+	 * @return void
14
+	 */
15
+	public static function createFolder($folder)
16
+	{
17
+		//        try {
18
+		//            if (!mkdir($folder) && !is_dir($folder)) {
19
+		//                throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
20
+		//            } else {
21
+		//                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
22
+		//            }
23
+		//        }
24
+		//        catch (Exception $e) {
25
+		//            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
26
+		//        }
27
+		try {
28
+			if (!file_exists($folder)) {
29
+				if (!mkdir($folder) && !is_dir($folder)) {
30
+					throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31
+				} else {
32
+					file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
33
+				}
34
+			}
35
+		} catch (Exception $e) {
36
+			echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
37
+		}
38
+	}
39 39
 
40
-    /**
41
-     * @param $file
42
-     * @param $folder
43
-     * @return bool
44
-     */
45
-    public static function copyFile($file, $folder)
46
-    {
47
-        return copy($file, $folder);
48
-        //        try {
49
-        //            if (!is_dir($folder)) {
50
-        //                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
51
-        //            } else {
52
-        //                return copy($file, $folder);
53
-        //            }
54
-        //        } catch (Exception $e) {
55
-        //            echo 'Caught exception: ', $e->getMessage(), "\n", "<br>";
56
-        //        }
57
-        //        return false;
58
-    }
40
+	/**
41
+	 * @param $file
42
+	 * @param $folder
43
+	 * @return bool
44
+	 */
45
+	public static function copyFile($file, $folder)
46
+	{
47
+		return copy($file, $folder);
48
+		//        try {
49
+		//            if (!is_dir($folder)) {
50
+		//                throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
51
+		//            } else {
52
+		//                return copy($file, $folder);
53
+		//            }
54
+		//        } catch (Exception $e) {
55
+		//            echo 'Caught exception: ', $e->getMessage(), "\n", "<br>";
56
+		//        }
57
+		//        return false;
58
+	}
59 59
 
60
-    /**
61
-     * @param $src
62
-     * @param $dst
63
-     */
64
-    public static function recurseCopy($src, $dst)
65
-    {
66
-        $dir = opendir($src);
67
-        //    @mkdir($dst);
68
-        while (false !== ($file = readdir($dir))) {
69
-            if (('.' !== $file) && ('..' !== $file)) {
70
-                if (is_dir($src . '/' . $file)) {
71
-                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
72
-                } else {
73
-                    copy($src . '/' . $file, $dst . '/' . $file);
74
-                }
75
-            }
76
-        }
77
-        closedir($dir);
78
-    }
60
+	/**
61
+	 * @param $src
62
+	 * @param $dst
63
+	 */
64
+	public static function recurseCopy($src, $dst)
65
+	{
66
+		$dir = opendir($src);
67
+		//    @mkdir($dst);
68
+		while (false !== ($file = readdir($dir))) {
69
+			if (('.' !== $file) && ('..' !== $file)) {
70
+				if (is_dir($src . '/' . $file)) {
71
+					self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
72
+				} else {
73
+					copy($src . '/' . $file, $dst . '/' . $file);
74
+				}
75
+			}
76
+		}
77
+		closedir($dir);
78
+	}
79 79
 
80
-    /**
81
-     *
82
-     * Verifies XOOPS version meets minimum requirements for this module
83
-     * @static
84
-     * @param XoopsModule $module
85
-     *
86
-     * @param null|string $requiredVer
87
-     * @return bool true if meets requirements, false if not
88
-     */
89
-    public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null)
90
-    {
91
-        $moduleDirName = basename(dirname(__DIR__));
92
-        if (null === $module) {
93
-            $module = XoopsModule::getByDirname($moduleDirName);
94
-        }
95
-        xoops_loadLanguage('admin', $moduleDirName);
96
-        //check for minimum XOOPS version
97
-        $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
98
-        $currArray  = explode('.', $currentVer);
99
-        if (null === $requiredVer) {
100
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
101
-        }
102
-        $reqArray = explode('.', $requiredVer);
103
-        $success  = true;
104
-        foreach ($reqArray as $k => $v) {
105
-            if (isset($currArray[$k])) {
106
-                if ($currArray[$k] > $v) {
107
-                    break;
108
-                } elseif ($currArray[$k] == $v) {
109
-                    continue;
110
-                } else {
111
-                    $success = false;
112
-                    break;
113
-                }
114
-            } else {
115
-                if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
116
-                    $success = false;
117
-                    break;
118
-                }
119
-            }
120
-        }
80
+	/**
81
+	 *
82
+	 * Verifies XOOPS version meets minimum requirements for this module
83
+	 * @static
84
+	 * @param XoopsModule $module
85
+	 *
86
+	 * @param null|string $requiredVer
87
+	 * @return bool true if meets requirements, false if not
88
+	 */
89
+	public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null)
90
+	{
91
+		$moduleDirName = basename(dirname(__DIR__));
92
+		if (null === $module) {
93
+			$module = XoopsModule::getByDirname($moduleDirName);
94
+		}
95
+		xoops_loadLanguage('admin', $moduleDirName);
96
+		//check for minimum XOOPS version
97
+		$currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
98
+		$currArray  = explode('.', $currentVer);
99
+		if (null === $requiredVer) {
100
+			$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
101
+		}
102
+		$reqArray = explode('.', $requiredVer);
103
+		$success  = true;
104
+		foreach ($reqArray as $k => $v) {
105
+			if (isset($currArray[$k])) {
106
+				if ($currArray[$k] > $v) {
107
+					break;
108
+				} elseif ($currArray[$k] == $v) {
109
+					continue;
110
+				} else {
111
+					$success = false;
112
+					break;
113
+				}
114
+			} else {
115
+				if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
116
+					$success = false;
117
+					break;
118
+				}
119
+			}
120
+		}
121 121
 
122
-        if (false === $success) {
123
-            $module->setErrors(sprintf(_AM_SOBJECT_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
124
-        }
122
+		if (false === $success) {
123
+			$module->setErrors(sprintf(_AM_SOBJECT_ERROR_BAD_XOOPS, $requiredVer, $currentVer));
124
+		}
125 125
 
126
-        return $success;
127
-    }
126
+		return $success;
127
+	}
128 128
 
129
-    /**
130
-     *
131
-     * Verifies PHP version meets minimum requirements for this module
132
-     * @static
133
-     * @param XoopsModule $module
134
-     *
135
-     * @return bool true if meets requirements, false if not
136
-     */
137
-    public static function checkVerPhp(XoopsModule $module)
138
-    {
139
-        xoops_loadLanguage('admin', $module->dirname());
140
-        // check for minimum PHP version
141
-        $success = true;
142
-        $verNum  = PHP_VERSION;
143
-        $reqVer  = $module->getInfo('min_php');
144
-        if (false !== $reqVer && '' !== $reqVer) {
145
-            if (version_compare($verNum, $reqVer, '<')) {
146
-                $module->setErrors(sprintf(_AM_SOBJECT_ERROR_BAD_PHP, $reqVer, $verNum));
147
-                $success = false;
148
-            }
149
-        }
129
+	/**
130
+	 *
131
+	 * Verifies PHP version meets minimum requirements for this module
132
+	 * @static
133
+	 * @param XoopsModule $module
134
+	 *
135
+	 * @return bool true if meets requirements, false if not
136
+	 */
137
+	public static function checkVerPhp(XoopsModule $module)
138
+	{
139
+		xoops_loadLanguage('admin', $module->dirname());
140
+		// check for minimum PHP version
141
+		$success = true;
142
+		$verNum  = PHP_VERSION;
143
+		$reqVer  = $module->getInfo('min_php');
144
+		if (false !== $reqVer && '' !== $reqVer) {
145
+			if (version_compare($verNum, $reqVer, '<')) {
146
+				$module->setErrors(sprintf(_AM_SOBJECT_ERROR_BAD_PHP, $reqVer, $verNum));
147
+				$success = false;
148
+			}
149
+		}
150 150
 
151
-        return $success;
152
-    }
151
+		return $success;
152
+	}
153 153
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
                 if (!mkdir($folder) && !is_dir($folder)) {
30 30
                     throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
31 31
                 } else {
32
-                    file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
32
+                    file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>');
33 33
                 }
34 34
             }
35 35
         } catch (Exception $e) {
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
         //    @mkdir($dst);
68 68
         while (false !== ($file = readdir($dir))) {
69 69
             if (('.' !== $file) && ('..' !== $file)) {
70
-                if (is_dir($src . '/' . $file)) {
71
-                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
70
+                if (is_dir($src.'/'.$file)) {
71
+                    self::recurseCopy($src.'/'.$file, $dst.'/'.$file);
72 72
                 } else {
73
-                    copy($src . '/' . $file, $dst . '/' . $file);
73
+                    copy($src.'/'.$file, $dst.'/'.$file);
74 74
                 }
75 75
             }
76 76
         }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string
98 98
         $currArray  = explode('.', $currentVer);
99 99
         if (null === $requiredVer) {
100
-            $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string
100
+            $requiredVer = ''.$module->getInfo('min_xoops'); //making sure it's a string
101 101
         }
102 102
         $reqArray = explode('.', $requiredVer);
103 103
         $success  = true;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                     break;
113 113
                 }
114 114
             } else {
115
-                if ((int)$v > 0) { // handles versions like x.x.x.0_RC2
115
+                if ((int) $v > 0) { // handles versions like x.x.x.0_RC2
116 116
                     $success = false;
117 117
                     break;
118 118
                 }
Please login to merge, or discard this patch.