Completed
Push — master ( 01b1a5...81f493 )
by Michael
04:03
created
class/smartobject.php 3 patches
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     }
166 166
 
167 167
     /**
168
-     * @param        $key
168
+     * @param        string $key
169 169
      * @param        $data_type
170 170
      * @param bool   $itemName
171 171
      * @param string $form_caption
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
194 194
      * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
195 195
      * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
196
-     * @param mixed  $value        default value of this variable
196
+     * @param string|false  $value        default value of this variable
197 197
      */
198 198
     public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null)
199 199
     {
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     }
203 203
 
204 204
     /**
205
-     * @param        $varname
205
+     * @param        string $varname
206 206
      * @param bool   $displayOnForm
207 207
      * @param string $default
208 208
      */
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
     /**
459 459
      * add an error
460 460
      *
461
-     * @param      $err_str
461
+     * @param      string $err_str
462 462
      * @param bool $prefix
463 463
      * @internal param string $value error to add
464 464
      * @access   public
@@ -720,8 +720,8 @@  discard block
 block discarded – undo
720 720
 
721 721
     /**
722 722
      * @param $key
723
-     * @param $info
724
-     * @param $value
723
+     * @param string $info
724
+     * @param boolean $value
725 725
      */
726 726
     public function setVarInfo($key, $info, $value)
727 727
     {
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
     }
730 730
 
731 731
     /**
732
-     * @param         $key
732
+     * @param         string $key
733 733
      * @param  bool   $editor
734 734
      * @return string
735 735
      */
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
      * @access public
907 907
      * @param  string $key    key of the object's variable to be returned
908 908
      * @param  string $format format to use for the output
909
-     * @return mixed  formatted value of the variable
909
+     * @return string  formatted value of the variable
910 910
      */
911 911
     public function getVar($key, $format = 's')
912 912
     {
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
     }
1210 1210
 
1211 1211
     /**
1212
-     * @param $key
1212
+     * @param string $key
1213 1213
      */
1214 1214
     public function hideFieldFromForm($key)
1215 1215
     {
Please login to merge, or discard this patch.
Indentation   +1360 added lines, -1360 removed lines patch added patch discarded remove patch
@@ -17,31 +17,31 @@  discard block
 block discarded – undo
17 17
 include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
18 18
 
19 19
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
20
-    define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
20
+	define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
21 21
 }
22 22
 if (!defined('XOBJ_DTYPE_CURRENCY')) {
23
-    define('XOBJ_DTYPE_CURRENCY', 200);
23
+	define('XOBJ_DTYPE_CURRENCY', 200);
24 24
 }
25 25
 if (!defined('XOBJ_DTYPE_FLOAT')) {
26
-    define('XOBJ_DTYPE_FLOAT', 201);
26
+	define('XOBJ_DTYPE_FLOAT', 201);
27 27
 }
28 28
 if (!defined('XOBJ_DTYPE_TIME_ONLY')) {
29
-    define('XOBJ_DTYPE_TIME_ONLY', 202);
29
+	define('XOBJ_DTYPE_TIME_ONLY', 202);
30 30
 }
31 31
 if (!defined('XOBJ_DTYPE_URLLINK')) {
32
-    define('XOBJ_DTYPE_URLLINK', 203);
32
+	define('XOBJ_DTYPE_URLLINK', 203);
33 33
 }
34 34
 if (!defined('XOBJ_DTYPE_FILE')) {
35
-    define('XOBJ_DTYPE_FILE', 204);
35
+	define('XOBJ_DTYPE_FILE', 204);
36 36
 }
37 37
 if (!defined('XOBJ_DTYPE_IMAGE')) {
38
-    define('XOBJ_DTYPE_IMAGE', 205);
38
+	define('XOBJ_DTYPE_IMAGE', 205);
39 39
 }
40 40
 if (!defined('XOBJ_DTYPE_FORM_SECTION')) {
41
-    define('XOBJ_DTYPE_FORM_SECTION', 210);
41
+	define('XOBJ_DTYPE_FORM_SECTION', 210);
42 42
 }
43 43
 if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) {
44
-    define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
44
+	define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
45 45
 }
46 46
 
47 47
 /**
@@ -55,1355 +55,1355 @@  discard block
 block discarded – undo
55 55
  */
56 56
 class SmartObject extends XoopsObject
57 57
 {
58
-    public $_image_path;
59
-    public $_image_url;
60
-
61
-    public $seoEnabled   = false;
62
-    public $titleField;
63
-    public $summaryField = false;
64
-
65
-    /**
66
-     * Reference to the handler managing this object
67
-     *
68
-     * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
69
-     */
70
-    public $handler;
71
-
72
-    /**
73
-     * References to control objects, managing the form fields of this object
74
-     */
75
-    public $controls = array();
76
-
77
-    /**
78
-     * SmartObject constructor.
79
-     * @param $handler
80
-     */
81
-    public function __construct($handler)
82
-    {
83
-        $this->handler = $handler;
84
-    }
85
-
86
-    /**
87
-     * Checks if the user has a specific access on this object
88
-     *
89
-     * @param $perm_name
90
-     * @return bool: TRUE if user has access, false if not
91
-     * @internal param string $gperm_name name of the permission to test
92
-     */
93
-    public function accessGranted($perm_name)
94
-    {
95
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
96
-
97
-        return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
98
-    }
99
-
100
-    /**
101
-     * @param      $section_name
102
-     * @param bool $value
103
-     * @param bool $hide
104
-     */
105
-    public function addFormSection($section_name, $value = false, $hide = false)
106
-    {
107
-        $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
108
-        $this->vars[$section_name]['hide'] = $hide;
109
-    }
110
-
111
-    /**
112
-     * @param $section_name
113
-     */
114
-    public function closeSection($section_name)
115
-    {
116
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
117
-    }
118
-
119
-    /**
120
-     *
121
-     * @param string $key           key of this field. This needs to be the name of the field in the related database table
122
-     * @param int    $data_type     set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
123
-     * @param mixed  $value         default value of this variable
124
-     * @param bool   $required      set to TRUE if this variable needs to have a value set before storing the object in the table
125
-     * @param int    $maxlength     maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
126
-     * @param string $options       does this data have any select options?
127
-     * @param bool   $multilingual  is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
128
-     * @param string $form_caption  caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
129
-     * @param string $form_dsc      description of this variable in a {@link SmartobjectForm}
130
-     * @param bool   $sortby        set to TRUE to make this field used to sort objects in SmartObjectTable
131
-     * @param bool   $persistent    set to FALSE if this field is not to be saved in the database
132
-     * @param bool   $displayOnForm
133
-     */
134
-    public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false,
135
-                            $persistent = true, $displayOnForm = true
136
-    ) {
137
-        //url_ is reserved for files.
138
-        if (0 === strpos($key, 'url_')) {
139
-            trigger_error("Cannot use variable starting with 'url_'.");
140
-        }
141
-        parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
142
-        if ($this->handler && (!$form_caption || $form_caption === '')) {
143
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
144
-            if (defined($dyn_form_caption)) {
145
-                $form_caption = constant($dyn_form_caption);
146
-            }
147
-        }
148
-        if ($this->handler && (!$form_dsc || $form_dsc === '')) {
149
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
150
-            if (defined($dyn_form_dsc)) {
151
-                $form_dsc = constant($dyn_form_dsc);
152
-            }
153
-        }
154
-
155
-        $this->vars[$key] = array_merge($this->vars[$key], array(
156
-            'multilingual'        => $multilingual,
157
-            'form_caption'        => $form_caption,
158
-            'form_dsc'            => $form_dsc,
159
-            'sortby'              => $sortby,
160
-            'persistent'          => $persistent,
161
-            'displayOnForm'       => $displayOnForm,
162
-            'displayOnSingleView' => true,
163
-            'readonly'            => false
164
-        ));
165
-    }
166
-
167
-    /**
168
-     * @param        $key
169
-     * @param        $data_type
170
-     * @param bool   $itemName
171
-     * @param string $form_caption
172
-     * @param bool   $sortby
173
-     * @param string $value
174
-     * @param bool   $displayOnForm
175
-     * @param bool   $required
176
-     */
177
-    public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false)
178
-    {
179
-        $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
180
-        $this->vars[$key]['itemName'] = $itemName;
181
-    }
182
-
183
-    /**
184
-     * Quickly initiate a var
185
-     *
186
-     * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
187
-     *
188
-     * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
189
-     * - all other vars are NULL or '' depending of the parameter
190
-     *
191
-     * @param string $key          key of this field. This needs to be the name of the field in the related database table
192
-     * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
193
-     * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
194
-     * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
195
-     * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
196
-     * @param mixed  $value        default value of this variable
197
-     */
198
-    public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null)
199
-    {
200
-        $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null;
201
-        $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
202
-    }
203
-
204
-    /**
205
-     * @param        $varname
206
-     * @param bool   $displayOnForm
207
-     * @param string $default
208
-     */
209
-    public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
210
-    {
211
-        switch ($varname) {
212
-            case 'dohtml':
213
-                $value = $default !== 'notdefined' ? $default : true;
214
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
215
-                $this->setControl($varname, 'yesno');
216
-                break;
217
-
218
-            case 'dobr':
219
-                $value = ($default === 'notdefined') ? true : $default;
220
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
221
-                $this->setControl($varname, 'yesno');
222
-                break;
223
-
224
-            case 'doimage':
225
-                $value = $default !== 'notdefined' ? $default : true;
226
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
227
-                $this->setControl($varname, 'yesno');
228
-                break;
229
-
230
-            case 'dosmiley':
231
-                $value = $default !== 'notdefined' ? $default : true;
232
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
233
-                $this->setControl($varname, 'yesno');
234
-                break;
235
-
236
-            case 'doxcode':
237
-                $value = $default !== 'notdefined' ? $default : true;
238
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
239
-                $this->setControl($varname, 'yesno');
240
-                break;
241
-
242
-            case 'meta_keywords':
243
-                $value = $default !== 'notdefined' ? $default : '';
244
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
245
-                $this->setControl('meta_keywords', array(
246
-                    'name'        => 'textarea',
247
-                    'form_editor' => 'textarea'
248
-                ));
249
-                break;
250
-
251
-            case 'meta_description':
252
-                $value = $default !== 'notdefined' ? $default : '';
253
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
254
-                $this->setControl('meta_description', array(
255
-                    'name'        => 'textarea',
256
-                    'form_editor' => 'textarea'
257
-                ));
258
-                break;
259
-
260
-            case 'short_url':
261
-                $value = $default !== 'notdefined' ? $default : '';
262
-                $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
263
-                break;
264
-
265
-            case 'hierarchy_path':
266
-                $value = $default !== 'notdefined' ? $default : '';
267
-                $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
268
-                break;
269
-
270
-            case 'counter':
271
-                $value = $default !== 'notdefined' ? $default : 0;
272
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
273
-                break;
274
-
275
-            case 'weight':
276
-                $value = $default !== 'notdefined' ? $default : 0;
277
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
278
-                break;
279
-            case 'custom_css':
280
-                $value = $default !== 'notdefined' ? $default : '';
281
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
282
-                $this->setControl('custom_css', array(
283
-                    'name'        => 'textarea',
284
-                    'form_editor' => 'textarea'
285
-                ));
286
-                break;
287
-        }
288
-        $this->hideFieldFromSingleView($varname);
289
-    }
290
-
291
-    /**
292
-     * Set control information for an instance variable
293
-     *
294
-     * The $options parameter can be a string or an array. Using a string
295
-     * is the quickest way:
296
-     *
297
-     * $this->setControl('date', 'date_time');
298
-     *
299
-     * This will create a date and time selectbox for the 'date' var on the
300
-     * form to edit or create this item.
301
-     *
302
-     * Here are the currently supported controls:
303
-     *
304
-     *      - color
305
-     *      - country
306
-     *      - date_time
307
-     *      - date
308
-     *      - email
309
-     *      - group
310
-     *      - group_multi
311
-     *      - image
312
-     *      - imageupload
313
-     *      - label
314
-     *      - language
315
-     *      - parentcategory
316
-     *      - password
317
-     *      - select_multi
318
-     *      - select
319
-     *      - text
320
-     *      - textarea
321
-     *      - theme
322
-     *      - theme_multi
323
-     *      - timezone
324
-     *      - user
325
-     *      - user_multi
326
-     *      - yesno
327
-     *
328
-     * Now, using an array as $options, you can customize what information to
329
-     * use in the control. For example, if one needs to display a select box for
330
-     * the user to choose the status of an item. We only need to tell SmartObject
331
-     * what method to execute within what handler to retreive the options of the
332
-     * selectbox.
333
-     *
334
-     * $this->setControl('status', array('name' => false,
335
-     *                                   'itemHandler' => 'item',
336
-     *                                   'method' => 'getStatus',
337
-     *                                   'module' => 'smartshop'));
338
-     *
339
-     * In this example, the array elements are the following:
340
-     *      - name: false, as we don't need to set a special control here.
341
-     *               we will use the default control related to the object type (defined in initVar)
342
-     *      - itemHandler: name of the object for which we will use the handler
343
-     *      - method: name of the method of this handler that we will execute
344
-     *      - module: name of the module from wich the handler is
345
-     *
346
-     * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
347
-     * populate this selectbox with the result from SmartshopItemHandler::getStatus()
348
-     *
349
-     * Another example of the use of $options as an array is for TextArea:
350
-     *
351
-     * $this->setControl('body', array('name' => 'textarea',
352
-     *                                   'form_editor' => 'default'));
353
-     *
354
-     * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
355
-     * the 'default' editor, providing it is defined in the module
356
-     * preferences: $xoopsModuleConfig['default_editor']
357
-     *
358
-     * Of course, you can force the use of a specific editor:
359
-     *
360
-     * $this->setControl('body', array('name' => 'textarea',
361
-     *                                   'form_editor' => 'koivi'));
362
-     *
363
-     * Here is a list of supported editor:
364
-     *      - tiny: TinyEditor
365
-     *      - dhtmltextarea: XOOPS DHTML Area
366
-     *      - fckeditor: FCKEditor
367
-     *      - inbetween: InBetween
368
-     *      - koivi: Koivi
369
-     *      - spaw: Spaw WYSIWYG Editor
370
-     *      - htmlarea: HTMLArea
371
-     *      - textarea: basic textarea with no options
372
-     *
373
-     * @param string $var     name of the variable for which we want to set a control
374
-     * @param array  $options
375
-     */
376
-    public function setControl($var, $options = array())
377
-    {
378
-        if (isset($this->controls[$var])) {
379
-            unset($this->controls[$var]);
380
-        }
381
-        if (is_string($options)) {
382
-            $options = array('name' => $options);
383
-        }
384
-        $this->controls[$var] = $options;
385
-    }
386
-
387
-    /**
388
-     * Get control information for an instance variable
389
-     *
390
-     * @param  string     $var
391
-     * @return bool|mixed
392
-     */
393
-    public function getControl($var)
394
-    {
395
-        return isset($this->controls[$var]) ? $this->controls[$var] : false;
396
-    }
397
-
398
-    /**
399
-     * Create the form for this object
400
-     *
401
-     * @param         $form_caption
402
-     * @param         $form_name
403
-     * @param  bool   $form_action
404
-     * @param  string $submit_button_caption
405
-     * @param  bool   $cancel_js_action
406
-     * @param  bool   $captcha
407
-     * @return a      <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
408
-     *                                      object for this object
409
-     * @see SmartObjectForm::SmartObjectForm()
410
-     */
411
-    public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false)
412
-    {
413
-        include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
414
-        $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
415
-
416
-        return $form;
417
-    }
418
-
419
-    /**
420
-     * @return array
421
-     */
422
-    public function toArray()
423
-    {
424
-        $ret  = array();
425
-        $vars =& $this->getVars();
426
-        foreach ($vars as $key => $var) {
427
-            $value     = $this->getVar($key);
428
-            $ret[$key] = $value;
429
-        }
430
-        if ($this->handler->identifierName !== '') {
431
-            $controller = new SmartObjectController($this->handler);
432
-            /**
433
-             * Addition of some automatic value
434
-             */
435
-            $ret['itemLink']         = $controller->getItemLink($this);
436
-            $ret['itemUrl']          = $controller->getItemLink($this, true);
437
-            $ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
438
-            $ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
439
-            $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
440
-        }
441
-
442
-        // Hightlighting searched words
443
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php');
444
-        $highlight = smart_getConfig('module_search_highlighter', false, true);
445
-
446
-        if ($highlight && isset($_GET['keywords'])) {
447
-            $myts     = MyTextSanitizer::getInstance();
448
-            $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
449
-            $h        = new SmartHighlighter($keywords, true, 'smart_highlighter');
450
-            foreach ($this->handler->highlightFields as $field) {
451
-                $ret[$field] = $h->highlight($ret[$field]);
452
-            }
453
-        }
454
-
455
-        return $ret;
456
-    }
457
-
458
-    /**
459
-     * add an error
460
-     *
461
-     * @param      $err_str
462
-     * @param bool $prefix
463
-     * @internal param string $value error to add
464
-     * @access   public
465
-     */
466
-    public function setErrors($err_str, $prefix = false)
467
-    {
468
-        if (is_array($err_str)) {
469
-            foreach ($err_str as $str) {
470
-                $this->setErrors($str, $prefix);
471
-            }
472
-        } else {
473
-            if ($prefix) {
474
-                $err_str = '[' . $prefix . '] ' . $err_str;
475
-            }
476
-            parent::setErrors($err_str);
477
-        }
478
-    }
479
-
480
-    /**
481
-     * @param      $field
482
-     * @param bool $required
483
-     */
484
-    public function setFieldAsRequired($field, $required = true)
485
-    {
486
-        if (is_array($field)) {
487
-            foreach ($field as $v) {
488
-                $this->doSetFieldAsRequired($v, $required);
489
-            }
490
-        } else {
491
-            $this->doSetFieldAsRequired($field, $required);
492
-        }
493
-    }
494
-
495
-    /**
496
-     * @param $field
497
-     */
498
-    public function setFieldForSorting($field)
499
-    {
500
-        if (is_array($field)) {
501
-            foreach ($field as $v) {
502
-                $this->doSetFieldForSorting($v);
503
-            }
504
-        } else {
505
-            $this->doSetFieldForSorting($field);
506
-        }
507
-    }
508
-
509
-    /**
510
-     * @return bool
511
-     */
512
-    public function hasError()
513
-    {
514
-        return count($this->_errors) > 0;
515
-    }
516
-
517
-    /**
518
-     * @param $url
519
-     * @param $path
520
-     */
521
-    public function setImageDir($url, $path)
522
-    {
523
-        $this->_image_url  = $url;
524
-        $this->_image_path = $path;
525
-    }
526
-
527
-    /**
528
-     * Retreive the group that have been granted access to a specific permission for this object
529
-     *
530
-     * @param $group_perm
531
-     * @return string $group_perm name of the permission
532
-     */
533
-    public function getGroupPerm($group_perm)
534
-    {
535
-        if (!$this->handler->getPermissions()) {
536
-            $this->setError("Trying to access a permission that does not exists for thisobject's handler");
537
-
538
-            return false;
539
-        }
540
-
541
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
542
-        $ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
543
-
544
-        if (count($ret) == 0) {
545
-            return false;
546
-        } else {
547
-            return $ret;
548
-        }
549
-    }
550
-
551
-    /**
552
-     * @param  bool  $path
553
-     * @return mixed
554
-     */
555
-    public function getImageDir($path = false)
556
-    {
557
-        if ($path) {
558
-            return $this->_image_path;
559
-        } else {
560
-            return $this->_image_url;
561
-        }
562
-    }
563
-
564
-    /**
565
-     * @param  bool  $path
566
-     * @return mixed
567
-     */
568
-    public function getUploadDir($path = false)
569
-    {
570
-        if ($path) {
571
-            return $this->_image_path;
572
-        } else {
573
-            return $this->_image_url;
574
-        }
575
-    }
576
-
577
-    /**
578
-     * @param  string $key
579
-     * @param  string $info
580
-     * @return array
581
-     */
582
-    public function getVarInfo($key = '', $info = '')
583
-    {
584
-        if (isset($this->vars[$key][$info])) {
585
-            return $this->vars[$key][$info];
586
-        } elseif ($info === '' && isset($this->vars[$key])) {
587
-            return $this->vars[$key];
588
-        } else {
589
-            return $this->vars;
590
-        }
591
-    }
592
-
593
-    /**
594
-     * Get the id of the object
595
-     *
596
-     * @return int id of this object
597
-     */
598
-    public function id()
599
-    {
600
-        return $this->getVar($this->handler->keyName, 'e');
601
-    }
602
-
603
-    /**
604
-     * Return the value of the title field of this object
605
-     *
606
-     * @param  string $format
607
-     * @return string
608
-     */
609
-    public function title($format = 's')
610
-    {
611
-        return $this->getVar($this->handler->identifierName, $format);
612
-    }
613
-
614
-    /**
615
-     * Return the value of the title field of this object
616
-     *
617
-     * @return string
618
-     */
619
-    public function summary()
620
-    {
621
-        if ($this->handler->summaryName) {
622
-            return $this->getVar($this->handler->summaryName);
623
-        } else {
624
-            return false;
625
-        }
626
-    }
627
-
628
-    /**
629
-     * Retreive the object admin side link, displayijng a SingleView page
630
-     *
631
-     * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
632
-     * @return string user side link to the object
633
-     */
634
-    public function getAdminViewItemLink($onlyUrl = false)
635
-    {
636
-        $controller = new SmartObjectController($this->handler);
637
-
638
-        return $controller->getAdminViewItemLink($this, $onlyUrl);
639
-    }
640
-
641
-    /**
642
-     * Retreive the object user side link
643
-     *
644
-     * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
645
-     * @return string user side link to the object
646
-     */
647
-    public function getItemLink($onlyUrl = false)
648
-    {
649
-        $controller = new SmartObjectController($this->handler);
650
-
651
-        return $controller->getItemLink($this, $onlyUrl);
652
-    }
653
-
654
-    /**
655
-     * @param  bool   $onlyUrl
656
-     * @param  bool   $withimage
657
-     * @param  bool   $userSide
658
-     * @return string
659
-     */
660
-    public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
661
-    {
662
-        $controller = new SmartObjectController($this->handler);
663
-
664
-        return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
665
-    }
666
-
667
-    /**
668
-     * @param  bool   $onlyUrl
669
-     * @param  bool   $withimage
670
-     * @param  bool   $userSide
671
-     * @return string
672
-     */
673
-    public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
674
-    {
675
-        $controller = new SmartObjectController($this->handler);
676
-
677
-        return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
678
-    }
679
-
680
-    /**
681
-     * @return string
682
-     */
683
-    public function getPrintAndMailLink()
684
-    {
685
-        $controller = new SmartObjectController($this->handler);
686
-
687
-        return $controller->getPrintAndMailLink($this);
688
-    }
689
-
690
-    /**
691
-     * @param $sortsel
692
-     * @return array|bool
693
-     */
694
-    public function getFieldsForSorting($sortsel)
695
-    {
696
-        $ret = array();
697
-
698
-        foreach ($this->vars as $key => $field_info) {
699
-            if ($field_info['sortby']) {
700
-                $ret[$key]['caption']  = $field_info['form_caption'];
701
-                $ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : '';
702
-            }
703
-        }
704
-
705
-        if (count($ret) > 0) {
706
-            return $ret;
707
-        } else {
708
-            return false;
709
-        }
710
-    }
711
-
712
-    /**
713
-     * @param $key
714
-     * @param $newType
715
-     */
716
-    public function setType($key, $newType)
717
-    {
718
-        $this->vars[$key]['data_type'] = $newType;
719
-    }
720
-
721
-    /**
722
-     * @param $key
723
-     * @param $info
724
-     * @param $value
725
-     */
726
-    public function setVarInfo($key, $info, $value)
727
-    {
728
-        $this->vars[$key][$info] = $value;
729
-    }
730
-
731
-    /**
732
-     * @param         $key
733
-     * @param  bool   $editor
734
-     * @return string
735
-     */
736
-    public function getValueFor($key, $editor = true)
737
-    {
738
-        global $xoopsModuleConfig;
739
-
740
-        $ret  = $this->getVar($key, 'n');
741
-        $myts = MyTextSanitizer::getInstance();
742
-
743
-        $control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
744
-        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
745
-
746
-        $html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
747
-        $smiley   = true;
748
-        $xcode    = true;
749
-        $image    = true;
750
-        $br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
751
-        $formatML = true;
752
-
753
-        if ($form_editor === 'default') {
754
-            global $xoopsModuleConfig;
755
-            $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
756
-        }
757
-
758
-        if ($editor) {
759
-            if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) {
760
-                $br       = false;
761
-                $formatML = !$editor;
762
-            } else {
763
-                return htmlspecialchars($ret, ENT_QUOTES);
764
-            }
765
-        }
766
-
767
-        if (method_exists($myts, 'formatForML')) {
768
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
769
-        } else {
770
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
771
-        }
772
-    }
773
-
774
-    /**
775
-     * clean values of all variables of the object for storage.
776
-     * also add slashes whereever needed
777
-     *
778
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
779
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
780
-     * as a string separated by |
781
-     *
782
-     * @return bool true if successful
783
-     * @access public
784
-     */
785
-    public function cleanVars()
786
-    {
787
-        $ts              = MyTextSanitizer::getInstance();
788
-        $existing_errors = $this->getErrors();
789
-        $this->_errors   = array();
790
-        foreach ($this->vars as $k => $v) {
791
-            $cleanv = $v['value'];
792
-            if (!$v['changed']) {
793
-            } else {
794
-                $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
795
-                switch ($v['data_type']) {
796
-                    case XOBJ_DTYPE_TXTBOX:
797
-                        if ($v['required'] && $cleanv != '0' && $cleanv == '') {
798
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
799
-                            continue 2;
800
-                        }
801
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
802
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
803
-                            continue 2;
804
-                        }
805
-                        if (!$v['not_gpc']) {
806
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
807
-                        } else {
808
-                            $cleanv = $ts->censorString($cleanv);
809
-                        }
810
-                        break;
811
-                    case XOBJ_DTYPE_TXTAREA:
812
-                        if ($v['required'] && $cleanv != '0' && $cleanv == '') {
813
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
814
-                            continue 2;
815
-                        }
816
-                        if (!$v['not_gpc']) {
817
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
818
-                        } else {
819
-                            $cleanv = $ts->censorString($cleanv);
820
-                        }
821
-                        break;
822
-                    case XOBJ_DTYPE_SOURCE:
823
-                        if (!$v['not_gpc']) {
824
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
825
-                        } else {
826
-                            $cleanv = $cleanv;
827
-                        }
828
-                        break;
829
-                    case XOBJ_DTYPE_INT:
830
-                    case XOBJ_DTYPE_TIME_ONLY:
831
-                        $cleanv = (int)$cleanv;
832
-                        break;
833
-
834
-                    case XOBJ_DTYPE_CURRENCY:
835
-                        $cleanv = smart_currency($cleanv);
836
-                        break;
837
-
838
-                    case XOBJ_DTYPE_FLOAT:
839
-                        $cleanv = smart_float($cleanv);
840
-                        break;
841
-
842
-                    case XOBJ_DTYPE_EMAIL:
843
-                        if ($v['required'] && $cleanv === '') {
844
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
845
-                            continue 2;
846
-                        }
847
-                        if ($cleanv !== '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
848
-                            $this->setErrors('Invalid Email');
849
-                            continue 2;
850
-                        }
851
-                        if (!$v['not_gpc']) {
852
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
853
-                        }
854
-                        break;
855
-                    case XOBJ_DTYPE_URL:
856
-                        if ($v['required'] && $cleanv === '') {
857
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
858
-                            continue 2;
859
-                        }
860
-                        if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
861
-                            $cleanv = 'http://' . $cleanv;
862
-                        }
863
-                        if (!$v['not_gpc']) {
864
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
865
-                        }
866
-                        break;
867
-                    case XOBJ_DTYPE_SIMPLE_ARRAY:
868
-                        $cleanv = implode('|', $cleanv);
869
-                        break;
870
-                    case XOBJ_DTYPE_ARRAY:
871
-                        $cleanv = serialize($cleanv);
872
-                        break;
873
-                    case XOBJ_DTYPE_STIME:
874
-                    case XOBJ_DTYPE_MTIME:
875
-                    case XOBJ_DTYPE_LTIME:
876
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
877
-                        if (!($cleanv > 0)) {
878
-                            $cleanv = strtotime($cleanv);
879
-                        }
880
-                        break;
881
-                    default:
882
-                        break;
883
-                }
884
-            }
885
-            $this->cleanVars[$k] =& $cleanv;
886
-            unset($cleanv);
887
-        }
888
-        if (count($this->_errors) > 0) {
889
-            $this->_errors = array_merge($existing_errors, $this->_errors);
890
-
891
-            return false;
892
-        }
893
-        $this->_errors = array_merge($existing_errors, $this->_errors);
894
-        $this->unsetDirty();
895
-
896
-        return true;
897
-    }
898
-
899
-    /**
900
-     * returns a specific variable for the object in a proper format
901
-     *
902
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
903
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
904
-     * as a string separated by |
905
-     *
906
-     * @access public
907
-     * @param  string $key    key of the object's variable to be returned
908
-     * @param  string $format format to use for the output
909
-     * @return mixed  formatted value of the variable
910
-     */
911
-    public function getVar($key, $format = 's')
912
-    {
913
-        global $myts;
914
-
915
-        $ret = $this->vars[$key]['value'];
916
-
917
-        switch ($this->vars[$key]['data_type']) {
918
-
919
-            case XOBJ_DTYPE_TXTBOX:
920
-                switch (strtolower($format)) {
921
-                    case 's':
922
-                    case 'show':
923
-                        // ML Hack by marcan
924
-                        $ts  = MyTextSanitizer::getInstance();
925
-                        $ret = $ts->htmlSpecialChars($ret);
926
-
927
-                        if (method_exists($myts, 'formatForML')) {
928
-                            return $ts->formatForML($ret);
929
-                        } else {
930
-                            return $ret;
931
-                        }
932
-                        break 1;
933
-                    // End of ML Hack by marcan
934
-
935
-                    case 'clean':
936
-                        $ts = MyTextSanitizer::getInstance();
937
-
938
-                        $ret = smart_html2text($ret);
939
-                        $ret = smart_purifyText($ret);
940
-
941
-                        if (method_exists($myts, 'formatForML')) {
942
-                            return $ts->formatForML($ret);
943
-                        } else {
944
-                            return $ret;
945
-                        }
946
-                        break 1;
947
-                    // End of ML Hack by marcan
948
-
949
-                    case 'e':
950
-                    case 'edit':
951
-                        $ts = MyTextSanitizer::getInstance();
952
-
953
-                        return $ts->htmlSpecialChars($ret);
954
-                        break 1;
955
-                    case 'p':
956
-                    case 'preview':
957
-                    case 'f':
958
-                    case 'formpreview':
959
-                        $ts = MyTextSanitizer::getInstance();
960
-
961
-                        return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
962
-                        break 1;
963
-                    case 'n':
964
-                    case 'none':
965
-                    default:
966
-                        break 1;
967
-                }
968
-                break;
969
-            case XOBJ_DTYPE_LTIME:
970
-                switch (strtolower($format)) {
971
-                    case 's':
972
-                    case 'show':
973
-                    case 'p':
974
-                    case 'preview':
975
-                    case 'f':
976
-                    case 'formpreview':
977
-                        $ret = formatTimestamp($ret, _DATESTRING);
978
-
979
-                        return $ret;
980
-                        break 1;
981
-                    case 'n':
982
-                    case 'none':
983
-                    case 'e':
984
-                    case 'edit':
985
-                        break 1;
986
-                    default:
987
-                        break 1;
988
-                }
989
-                break;
990
-            case XOBJ_DTYPE_STIME:
991
-                switch (strtolower($format)) {
992
-                    case 's':
993
-                    case 'show':
994
-                    case 'p':
995
-                    case 'preview':
996
-                    case 'f':
997
-                    case 'formpreview':
998
-                        $ret = formatTimestamp($ret, _SHORTDATESTRING);
999
-
1000
-                        return $ret;
1001
-                        break 1;
1002
-                    case 'n':
1003
-                    case 'none':
1004
-                    case 'e':
1005
-                    case 'edit':
1006
-                        break 1;
1007
-                    default:
1008
-                        break 1;
1009
-                }
1010
-                break;
1011
-            case XOBJ_DTYPE_TIME_ONLY:
1012
-                switch (strtolower($format)) {
1013
-                    case 's':
1014
-                    case 'show':
1015
-                    case 'p':
1016
-                    case 'preview':
1017
-                    case 'f':
1018
-                    case 'formpreview':
1019
-                        $ret = formatTimestamp($ret, 'G:i');
1020
-
1021
-                        return $ret;
1022
-                        break 1;
1023
-                    case 'n':
1024
-                    case 'none':
1025
-                    case 'e':
1026
-                    case 'edit':
1027
-                        break 1;
1028
-                    default:
1029
-                        break 1;
1030
-                }
1031
-                break;
1032
-
1033
-            case XOBJ_DTYPE_CURRENCY:
1034
-                $decimal_section_original = strstr($ret, '.');
1035
-                $decimal_section          = $decimal_section_original;
1036
-                if ($decimal_section) {
1037
-                    if (strlen($decimal_section) == 1) {
1038
-                        $decimal_section = '.00';
1039
-                    } elseif (strlen($decimal_section) == 2) {
1040
-                        $decimal_section .= '0';
1041
-                    }
1042
-                    $ret = str_replace($decimal_section_original, $decimal_section, $ret);
1043
-                } else {
1044
-                    $ret .= '.00';
1045
-                }
1046
-                break;
1047
-
1048
-            case XOBJ_DTYPE_TXTAREA:
1049
-                switch (strtolower($format)) {
1050
-                    case 's':
1051
-                    case 'show':
1052
-                        $ts   = MyTextSanitizer::getInstance();
1053
-                        $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1054
-
1055
-                        $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1056
-
1057
-                        $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1058
-                        $image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1059
-                        $br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1060
-
1061
-                        /**
1062
-                         * Hack by marcan <INBOX> for SCSPRO
1063
-                         * Setting mastop as the main editor
1064
-                         */
1065
-                        if (defined('XOOPS_EDITOR_IS_HTML')) {
1066
-                            $br = false;
1067
-                        }
1068
-                        /**
1069
-                         * Hack by marcan <INBOX> for SCSPRO
1070
-                         * Setting mastop as the main editor
1071
-                         */
1072
-
1073
-                        return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1074
-                        break 1;
1075
-                    case 'e':
1076
-                    case 'edit':
1077
-                        return htmlspecialchars($ret, ENT_QUOTES);
1078
-                        break 1;
1079
-                    case 'p':
1080
-                    case 'preview':
1081
-                        $ts     = MyTextSanitizer::getInstance();
1082
-                        $html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1083
-                        $xcode  = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1084
-                        $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1085
-                        $image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1086
-                        $br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1087
-
1088
-                        return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1089
-                        break 1;
1090
-                    case 'f':
1091
-                    case 'formpreview':
1092
-                        $ts = MyTextSanitizer::getInstance();
1093
-
1094
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1095
-                        break 1;
1096
-                    case 'n':
1097
-                    case 'none':
1098
-                    default:
1099
-                        break 1;
1100
-                }
1101
-                break;
1102
-            case XOBJ_DTYPE_SIMPLE_ARRAY:
1103
-                $ret =& explode('|', $ret);
1104
-                break;
1105
-            case XOBJ_DTYPE_ARRAY:
1106
-                $ret =& unserialize($ret);
1107
-                break;
1108
-            case XOBJ_DTYPE_SOURCE:
1109
-                switch (strtolower($format)) {
1110
-                    case 's':
1111
-                    case 'show':
1112
-                        break 1;
1113
-                    case 'e':
1114
-                    case 'edit':
1115
-                        return htmlspecialchars($ret, ENT_QUOTES);
1116
-                        break 1;
1117
-                    case 'p':
1118
-                    case 'preview':
1119
-                        $ts = MyTextSanitizer::getInstance();
1120
-
1121
-                        return $ts->stripSlashesGPC($ret);
1122
-                        break 1;
1123
-                    case 'f':
1124
-                    case 'formpreview':
1125
-                        $ts = MyTextSanitizer::getInstance();
1126
-
1127
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1128
-                        break 1;
1129
-                    case 'n':
1130
-                    case 'none':
1131
-                    default:
1132
-                        break 1;
1133
-                }
1134
-                break;
1135
-            default:
1136
-                if ($this->vars[$key]['options'] !== '' && $ret != '') {
1137
-                    switch (strtolower($format)) {
1138
-                        case 's':
1139
-                        case 'show':
1140
-                            $selected = explode('|', $ret);
1141
-                            $options  = explode('|', $this->vars[$key]['options']);
1142
-                            $i        = 1;
1143
-                            $ret      = array();
1144
-                            foreach ($options as $op) {
1145
-                                if (in_array($i, $selected)) {
1146
-                                    $ret[] = $op;
1147
-                                }
1148
-                                ++$i;
1149
-                            }
1150
-
1151
-                            return implode(', ', $ret);
1152
-                        case 'e':
1153
-                        case 'edit':
1154
-                            $ret = explode('|', $ret);
1155
-                            break 1;
1156
-                        default:
1157
-                            break 1;
1158
-                    }
1159
-                }
1160
-                break;
1161
-        }
1162
-
1163
-        return $ret;
1164
-    }
1165
-
1166
-    /**
1167
-     * @param $key
1168
-     */
1169
-    public function doMakeFieldreadOnly($key)
1170
-    {
1171
-        if (isset($this->vars[$key])) {
1172
-            $this->vars[$key]['readonly']      = true;
1173
-            $this->vars[$key]['displayOnForm'] = true;
1174
-        }
1175
-    }
1176
-
1177
-    /**
1178
-     * @param $key
1179
-     */
1180
-    public function makeFieldReadOnly($key)
1181
-    {
1182
-        if (is_array($key)) {
1183
-            foreach ($key as $v) {
1184
-                $this->doMakeFieldreadOnly($v);
1185
-            }
1186
-        } else {
1187
-            $this->doMakeFieldreadOnly($key);
1188
-        }
1189
-    }
1190
-
1191
-    /**
1192
-     * @param $key
1193
-     */
1194
-    public function doHideFieldFromForm($key)
1195
-    {
1196
-        if (isset($this->vars[$key])) {
1197
-            $this->vars[$key]['displayOnForm'] = false;
1198
-        }
1199
-    }
1200
-
1201
-    /**
1202
-     * @param $key
1203
-     */
1204
-    public function doHideFieldFromSingleView($key)
1205
-    {
1206
-        if (isset($this->vars[$key])) {
1207
-            $this->vars[$key]['displayOnSingleView'] = false;
1208
-        }
1209
-    }
1210
-
1211
-    /**
1212
-     * @param $key
1213
-     */
1214
-    public function hideFieldFromForm($key)
1215
-    {
1216
-        if (is_array($key)) {
1217
-            foreach ($key as $v) {
1218
-                $this->doHideFieldFromForm($v);
1219
-            }
1220
-        } else {
1221
-            $this->doHideFieldFromForm($key);
1222
-        }
1223
-    }
1224
-
1225
-    /**
1226
-     * @param $key
1227
-     */
1228
-    public function hideFieldFromSingleView($key)
1229
-    {
1230
-        if (is_array($key)) {
1231
-            foreach ($key as $v) {
1232
-                $this->doHideFieldFromSingleView($v);
1233
-            }
1234
-        } else {
1235
-            $this->doHideFieldFromSingleView($key);
1236
-        }
1237
-    }
1238
-
1239
-    /**
1240
-     * @param $key
1241
-     */
1242
-    public function doShowFieldOnForm($key)
1243
-    {
1244
-        if (isset($this->vars[$key])) {
1245
-            $this->vars[$key]['displayOnForm'] = true;
1246
-        }
1247
-    }
1248
-
1249
-    /**
1250
-     * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1251
-     *
1252
-     * @param  bool    $fetchOnly   if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1253
-     * @param  bool    $userSide    for futur use, to do something different on the user side
1254
-     * @param  array   $actions
1255
-     * @param  bool    $headerAsRow
1256
-     * @return content of the template if $fetchOnly or nothing if !$fetchOnly
1257
-     */
1258
-    public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true)
1259
-    {
1260
-        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1261
-        $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow);
1262
-        // add all fields mark as displayOnSingleView except the keyid
1263
-        foreach ($this->vars as $key => $var) {
1264
-            if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1265
-                $is_header = ($key == $this->handler->identifierName);
1266
-                $singleview->addRow(new SmartObjectRow($key, false, $is_header));
1267
-            }
1268
-        }
1269
-
1270
-        if ($fetchOnly) {
1271
-            $ret = $singleview->render($fetchOnly);
1272
-
1273
-            return $ret;
1274
-        } else {
1275
-            $singleview->render($fetchOnly);
1276
-        }
1277
-    }
1278
-
1279
-    /**
1280
-     * @param $key
1281
-     */
1282
-    public function doDisplayFieldOnSingleView($key)
1283
-    {
1284
-        if (isset($this->vars[$key])) {
1285
-            $this->vars[$key]['displayOnSingleView'] = true;
1286
-        }
1287
-    }
1288
-
1289
-    /**
1290
-     * @param      $field
1291
-     * @param bool $required
1292
-     */
1293
-    public function doSetFieldAsRequired($field, $required = true)
1294
-    {
1295
-        $this->setVarInfo($field, 'required', $required);
1296
-    }
1297
-
1298
-    /**
1299
-     * @param $field
1300
-     */
1301
-    public function doSetFieldForSorting($field)
1302
-    {
1303
-        $this->setVarInfo($field, 'sortby', true);
1304
-    }
1305
-
1306
-    /**
1307
-     * @param $key
1308
-     */
1309
-    public function showFieldOnForm($key)
1310
-    {
1311
-        if (is_array($key)) {
1312
-            foreach ($key as $v) {
1313
-                $this->doShowFieldOnForm($v);
1314
-            }
1315
-        } else {
1316
-            $this->doShowFieldOnForm($key);
1317
-        }
1318
-    }
1319
-
1320
-    /**
1321
-     * @param $key
1322
-     */
1323
-    public function displayFieldOnSingleView($key)
1324
-    {
1325
-        if (is_array($key)) {
1326
-            foreach ($key as $v) {
1327
-                $this->doDisplayFieldOnSingleView($v);
1328
-            }
1329
-        } else {
1330
-            $this->doDisplayFieldOnSingleView($key);
1331
-        }
1332
-    }
1333
-
1334
-    /**
1335
-     * @param $key
1336
-     */
1337
-    public function doSetAdvancedFormFields($key)
1338
-    {
1339
-        if (isset($this->vars[$key])) {
1340
-            $this->vars[$key]['advancedform'] = true;
1341
-        }
1342
-    }
1343
-
1344
-    /**
1345
-     * @param $key
1346
-     */
1347
-    public function setAdvancedFormFields($key)
1348
-    {
1349
-        if (is_array($key)) {
1350
-            foreach ($key as $v) {
1351
-                $this->doSetAdvancedFormFields($v);
1352
-            }
1353
-        } else {
1354
-            $this->doSetAdvancedFormFields($key);
1355
-        }
1356
-    }
1357
-
1358
-    /**
1359
-     * @param $key
1360
-     * @return mixed
1361
-     */
1362
-    public function getUrlLinkObj($key)
1363
-    {
1364
-        $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1365
-        $urllinkid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1366
-        if ($urllinkid != 0) {
1367
-            return $smartobjectLinkurlHandler->get($urllinkid);
1368
-        } else {
1369
-            return $smartobjectLinkurlHandler->create();
1370
-        }
1371
-    }
1372
-
1373
-    /**
1374
-     * @param $urlLinkObj
1375
-     * @return mixed
1376
-     */
1377
-    public function &storeUrlLinkObj($urlLinkObj)
1378
-    {
1379
-        $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1380
-
1381
-        return $smartobjectLinkurlHandler->insert($urlLinkObj);
1382
-    }
1383
-
1384
-    /**
1385
-     * @param $key
1386
-     * @return mixed
1387
-     */
1388
-    public function getFileObj($key)
1389
-    {
1390
-        $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1391
-        $fileid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1392
-        if ($fileid != 0) {
1393
-            return $smartobjectFileHandler->get($fileid);
1394
-        } else {
1395
-            return $smartobjectFileHandler->create();
1396
-        }
1397
-    }
1398
-
1399
-    /**
1400
-     * @param $fileObj
1401
-     * @return mixed
1402
-     */
1403
-    public function &storeFileObj($fileObj)
1404
-    {
1405
-        $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1406
-
1407
-        return $smartobjectFileHandler->insert($fileObj);
1408
-    }
58
+	public $_image_path;
59
+	public $_image_url;
60
+
61
+	public $seoEnabled   = false;
62
+	public $titleField;
63
+	public $summaryField = false;
64
+
65
+	/**
66
+	 * Reference to the handler managing this object
67
+	 *
68
+	 * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
69
+	 */
70
+	public $handler;
71
+
72
+	/**
73
+	 * References to control objects, managing the form fields of this object
74
+	 */
75
+	public $controls = array();
76
+
77
+	/**
78
+	 * SmartObject constructor.
79
+	 * @param $handler
80
+	 */
81
+	public function __construct($handler)
82
+	{
83
+		$this->handler = $handler;
84
+	}
85
+
86
+	/**
87
+	 * Checks if the user has a specific access on this object
88
+	 *
89
+	 * @param $perm_name
90
+	 * @return bool: TRUE if user has access, false if not
91
+	 * @internal param string $gperm_name name of the permission to test
92
+	 */
93
+	public function accessGranted($perm_name)
94
+	{
95
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
96
+
97
+		return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
98
+	}
99
+
100
+	/**
101
+	 * @param      $section_name
102
+	 * @param bool $value
103
+	 * @param bool $hide
104
+	 */
105
+	public function addFormSection($section_name, $value = false, $hide = false)
106
+	{
107
+		$this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
108
+		$this->vars[$section_name]['hide'] = $hide;
109
+	}
110
+
111
+	/**
112
+	 * @param $section_name
113
+	 */
114
+	public function closeSection($section_name)
115
+	{
116
+		$this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
117
+	}
118
+
119
+	/**
120
+	 *
121
+	 * @param string $key           key of this field. This needs to be the name of the field in the related database table
122
+	 * @param int    $data_type     set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
123
+	 * @param mixed  $value         default value of this variable
124
+	 * @param bool   $required      set to TRUE if this variable needs to have a value set before storing the object in the table
125
+	 * @param int    $maxlength     maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
126
+	 * @param string $options       does this data have any select options?
127
+	 * @param bool   $multilingual  is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
128
+	 * @param string $form_caption  caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
129
+	 * @param string $form_dsc      description of this variable in a {@link SmartobjectForm}
130
+	 * @param bool   $sortby        set to TRUE to make this field used to sort objects in SmartObjectTable
131
+	 * @param bool   $persistent    set to FALSE if this field is not to be saved in the database
132
+	 * @param bool   $displayOnForm
133
+	 */
134
+	public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false,
135
+							$persistent = true, $displayOnForm = true
136
+	) {
137
+		//url_ is reserved for files.
138
+		if (0 === strpos($key, 'url_')) {
139
+			trigger_error("Cannot use variable starting with 'url_'.");
140
+		}
141
+		parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
142
+		if ($this->handler && (!$form_caption || $form_caption === '')) {
143
+			$dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
144
+			if (defined($dyn_form_caption)) {
145
+				$form_caption = constant($dyn_form_caption);
146
+			}
147
+		}
148
+		if ($this->handler && (!$form_dsc || $form_dsc === '')) {
149
+			$dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
150
+			if (defined($dyn_form_dsc)) {
151
+				$form_dsc = constant($dyn_form_dsc);
152
+			}
153
+		}
154
+
155
+		$this->vars[$key] = array_merge($this->vars[$key], array(
156
+			'multilingual'        => $multilingual,
157
+			'form_caption'        => $form_caption,
158
+			'form_dsc'            => $form_dsc,
159
+			'sortby'              => $sortby,
160
+			'persistent'          => $persistent,
161
+			'displayOnForm'       => $displayOnForm,
162
+			'displayOnSingleView' => true,
163
+			'readonly'            => false
164
+		));
165
+	}
166
+
167
+	/**
168
+	 * @param        $key
169
+	 * @param        $data_type
170
+	 * @param bool   $itemName
171
+	 * @param string $form_caption
172
+	 * @param bool   $sortby
173
+	 * @param string $value
174
+	 * @param bool   $displayOnForm
175
+	 * @param bool   $required
176
+	 */
177
+	public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false)
178
+	{
179
+		$this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
180
+		$this->vars[$key]['itemName'] = $itemName;
181
+	}
182
+
183
+	/**
184
+	 * Quickly initiate a var
185
+	 *
186
+	 * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
187
+	 *
188
+	 * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
189
+	 * - all other vars are NULL or '' depending of the parameter
190
+	 *
191
+	 * @param string $key          key of this field. This needs to be the name of the field in the related database table
192
+	 * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
193
+	 * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
194
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
195
+	 * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
196
+	 * @param mixed  $value        default value of this variable
197
+	 */
198
+	public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null)
199
+	{
200
+		$maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null;
201
+		$this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
202
+	}
203
+
204
+	/**
205
+	 * @param        $varname
206
+	 * @param bool   $displayOnForm
207
+	 * @param string $default
208
+	 */
209
+	public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
210
+	{
211
+		switch ($varname) {
212
+			case 'dohtml':
213
+				$value = $default !== 'notdefined' ? $default : true;
214
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
215
+				$this->setControl($varname, 'yesno');
216
+				break;
217
+
218
+			case 'dobr':
219
+				$value = ($default === 'notdefined') ? true : $default;
220
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
221
+				$this->setControl($varname, 'yesno');
222
+				break;
223
+
224
+			case 'doimage':
225
+				$value = $default !== 'notdefined' ? $default : true;
226
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
227
+				$this->setControl($varname, 'yesno');
228
+				break;
229
+
230
+			case 'dosmiley':
231
+				$value = $default !== 'notdefined' ? $default : true;
232
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
233
+				$this->setControl($varname, 'yesno');
234
+				break;
235
+
236
+			case 'doxcode':
237
+				$value = $default !== 'notdefined' ? $default : true;
238
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
239
+				$this->setControl($varname, 'yesno');
240
+				break;
241
+
242
+			case 'meta_keywords':
243
+				$value = $default !== 'notdefined' ? $default : '';
244
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
245
+				$this->setControl('meta_keywords', array(
246
+					'name'        => 'textarea',
247
+					'form_editor' => 'textarea'
248
+				));
249
+				break;
250
+
251
+			case 'meta_description':
252
+				$value = $default !== 'notdefined' ? $default : '';
253
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
254
+				$this->setControl('meta_description', array(
255
+					'name'        => 'textarea',
256
+					'form_editor' => 'textarea'
257
+				));
258
+				break;
259
+
260
+			case 'short_url':
261
+				$value = $default !== 'notdefined' ? $default : '';
262
+				$this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
263
+				break;
264
+
265
+			case 'hierarchy_path':
266
+				$value = $default !== 'notdefined' ? $default : '';
267
+				$this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
268
+				break;
269
+
270
+			case 'counter':
271
+				$value = $default !== 'notdefined' ? $default : 0;
272
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
273
+				break;
274
+
275
+			case 'weight':
276
+				$value = $default !== 'notdefined' ? $default : 0;
277
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
278
+				break;
279
+			case 'custom_css':
280
+				$value = $default !== 'notdefined' ? $default : '';
281
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
282
+				$this->setControl('custom_css', array(
283
+					'name'        => 'textarea',
284
+					'form_editor' => 'textarea'
285
+				));
286
+				break;
287
+		}
288
+		$this->hideFieldFromSingleView($varname);
289
+	}
290
+
291
+	/**
292
+	 * Set control information for an instance variable
293
+	 *
294
+	 * The $options parameter can be a string or an array. Using a string
295
+	 * is the quickest way:
296
+	 *
297
+	 * $this->setControl('date', 'date_time');
298
+	 *
299
+	 * This will create a date and time selectbox for the 'date' var on the
300
+	 * form to edit or create this item.
301
+	 *
302
+	 * Here are the currently supported controls:
303
+	 *
304
+	 *      - color
305
+	 *      - country
306
+	 *      - date_time
307
+	 *      - date
308
+	 *      - email
309
+	 *      - group
310
+	 *      - group_multi
311
+	 *      - image
312
+	 *      - imageupload
313
+	 *      - label
314
+	 *      - language
315
+	 *      - parentcategory
316
+	 *      - password
317
+	 *      - select_multi
318
+	 *      - select
319
+	 *      - text
320
+	 *      - textarea
321
+	 *      - theme
322
+	 *      - theme_multi
323
+	 *      - timezone
324
+	 *      - user
325
+	 *      - user_multi
326
+	 *      - yesno
327
+	 *
328
+	 * Now, using an array as $options, you can customize what information to
329
+	 * use in the control. For example, if one needs to display a select box for
330
+	 * the user to choose the status of an item. We only need to tell SmartObject
331
+	 * what method to execute within what handler to retreive the options of the
332
+	 * selectbox.
333
+	 *
334
+	 * $this->setControl('status', array('name' => false,
335
+	 *                                   'itemHandler' => 'item',
336
+	 *                                   'method' => 'getStatus',
337
+	 *                                   'module' => 'smartshop'));
338
+	 *
339
+	 * In this example, the array elements are the following:
340
+	 *      - name: false, as we don't need to set a special control here.
341
+	 *               we will use the default control related to the object type (defined in initVar)
342
+	 *      - itemHandler: name of the object for which we will use the handler
343
+	 *      - method: name of the method of this handler that we will execute
344
+	 *      - module: name of the module from wich the handler is
345
+	 *
346
+	 * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
347
+	 * populate this selectbox with the result from SmartshopItemHandler::getStatus()
348
+	 *
349
+	 * Another example of the use of $options as an array is for TextArea:
350
+	 *
351
+	 * $this->setControl('body', array('name' => 'textarea',
352
+	 *                                   'form_editor' => 'default'));
353
+	 *
354
+	 * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
355
+	 * the 'default' editor, providing it is defined in the module
356
+	 * preferences: $xoopsModuleConfig['default_editor']
357
+	 *
358
+	 * Of course, you can force the use of a specific editor:
359
+	 *
360
+	 * $this->setControl('body', array('name' => 'textarea',
361
+	 *                                   'form_editor' => 'koivi'));
362
+	 *
363
+	 * Here is a list of supported editor:
364
+	 *      - tiny: TinyEditor
365
+	 *      - dhtmltextarea: XOOPS DHTML Area
366
+	 *      - fckeditor: FCKEditor
367
+	 *      - inbetween: InBetween
368
+	 *      - koivi: Koivi
369
+	 *      - spaw: Spaw WYSIWYG Editor
370
+	 *      - htmlarea: HTMLArea
371
+	 *      - textarea: basic textarea with no options
372
+	 *
373
+	 * @param string $var     name of the variable for which we want to set a control
374
+	 * @param array  $options
375
+	 */
376
+	public function setControl($var, $options = array())
377
+	{
378
+		if (isset($this->controls[$var])) {
379
+			unset($this->controls[$var]);
380
+		}
381
+		if (is_string($options)) {
382
+			$options = array('name' => $options);
383
+		}
384
+		$this->controls[$var] = $options;
385
+	}
386
+
387
+	/**
388
+	 * Get control information for an instance variable
389
+	 *
390
+	 * @param  string     $var
391
+	 * @return bool|mixed
392
+	 */
393
+	public function getControl($var)
394
+	{
395
+		return isset($this->controls[$var]) ? $this->controls[$var] : false;
396
+	}
397
+
398
+	/**
399
+	 * Create the form for this object
400
+	 *
401
+	 * @param         $form_caption
402
+	 * @param         $form_name
403
+	 * @param  bool   $form_action
404
+	 * @param  string $submit_button_caption
405
+	 * @param  bool   $cancel_js_action
406
+	 * @param  bool   $captcha
407
+	 * @return a      <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
408
+	 *                                      object for this object
409
+	 * @see SmartObjectForm::SmartObjectForm()
410
+	 */
411
+	public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false)
412
+	{
413
+		include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
414
+		$form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
415
+
416
+		return $form;
417
+	}
418
+
419
+	/**
420
+	 * @return array
421
+	 */
422
+	public function toArray()
423
+	{
424
+		$ret  = array();
425
+		$vars =& $this->getVars();
426
+		foreach ($vars as $key => $var) {
427
+			$value     = $this->getVar($key);
428
+			$ret[$key] = $value;
429
+		}
430
+		if ($this->handler->identifierName !== '') {
431
+			$controller = new SmartObjectController($this->handler);
432
+			/**
433
+			 * Addition of some automatic value
434
+			 */
435
+			$ret['itemLink']         = $controller->getItemLink($this);
436
+			$ret['itemUrl']          = $controller->getItemLink($this, true);
437
+			$ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
438
+			$ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
439
+			$ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
440
+		}
441
+
442
+		// Hightlighting searched words
443
+		include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php');
444
+		$highlight = smart_getConfig('module_search_highlighter', false, true);
445
+
446
+		if ($highlight && isset($_GET['keywords'])) {
447
+			$myts     = MyTextSanitizer::getInstance();
448
+			$keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
449
+			$h        = new SmartHighlighter($keywords, true, 'smart_highlighter');
450
+			foreach ($this->handler->highlightFields as $field) {
451
+				$ret[$field] = $h->highlight($ret[$field]);
452
+			}
453
+		}
454
+
455
+		return $ret;
456
+	}
457
+
458
+	/**
459
+	 * add an error
460
+	 *
461
+	 * @param      $err_str
462
+	 * @param bool $prefix
463
+	 * @internal param string $value error to add
464
+	 * @access   public
465
+	 */
466
+	public function setErrors($err_str, $prefix = false)
467
+	{
468
+		if (is_array($err_str)) {
469
+			foreach ($err_str as $str) {
470
+				$this->setErrors($str, $prefix);
471
+			}
472
+		} else {
473
+			if ($prefix) {
474
+				$err_str = '[' . $prefix . '] ' . $err_str;
475
+			}
476
+			parent::setErrors($err_str);
477
+		}
478
+	}
479
+
480
+	/**
481
+	 * @param      $field
482
+	 * @param bool $required
483
+	 */
484
+	public function setFieldAsRequired($field, $required = true)
485
+	{
486
+		if (is_array($field)) {
487
+			foreach ($field as $v) {
488
+				$this->doSetFieldAsRequired($v, $required);
489
+			}
490
+		} else {
491
+			$this->doSetFieldAsRequired($field, $required);
492
+		}
493
+	}
494
+
495
+	/**
496
+	 * @param $field
497
+	 */
498
+	public function setFieldForSorting($field)
499
+	{
500
+		if (is_array($field)) {
501
+			foreach ($field as $v) {
502
+				$this->doSetFieldForSorting($v);
503
+			}
504
+		} else {
505
+			$this->doSetFieldForSorting($field);
506
+		}
507
+	}
508
+
509
+	/**
510
+	 * @return bool
511
+	 */
512
+	public function hasError()
513
+	{
514
+		return count($this->_errors) > 0;
515
+	}
516
+
517
+	/**
518
+	 * @param $url
519
+	 * @param $path
520
+	 */
521
+	public function setImageDir($url, $path)
522
+	{
523
+		$this->_image_url  = $url;
524
+		$this->_image_path = $path;
525
+	}
526
+
527
+	/**
528
+	 * Retreive the group that have been granted access to a specific permission for this object
529
+	 *
530
+	 * @param $group_perm
531
+	 * @return string $group_perm name of the permission
532
+	 */
533
+	public function getGroupPerm($group_perm)
534
+	{
535
+		if (!$this->handler->getPermissions()) {
536
+			$this->setError("Trying to access a permission that does not exists for thisobject's handler");
537
+
538
+			return false;
539
+		}
540
+
541
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
542
+		$ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
543
+
544
+		if (count($ret) == 0) {
545
+			return false;
546
+		} else {
547
+			return $ret;
548
+		}
549
+	}
550
+
551
+	/**
552
+	 * @param  bool  $path
553
+	 * @return mixed
554
+	 */
555
+	public function getImageDir($path = false)
556
+	{
557
+		if ($path) {
558
+			return $this->_image_path;
559
+		} else {
560
+			return $this->_image_url;
561
+		}
562
+	}
563
+
564
+	/**
565
+	 * @param  bool  $path
566
+	 * @return mixed
567
+	 */
568
+	public function getUploadDir($path = false)
569
+	{
570
+		if ($path) {
571
+			return $this->_image_path;
572
+		} else {
573
+			return $this->_image_url;
574
+		}
575
+	}
576
+
577
+	/**
578
+	 * @param  string $key
579
+	 * @param  string $info
580
+	 * @return array
581
+	 */
582
+	public function getVarInfo($key = '', $info = '')
583
+	{
584
+		if (isset($this->vars[$key][$info])) {
585
+			return $this->vars[$key][$info];
586
+		} elseif ($info === '' && isset($this->vars[$key])) {
587
+			return $this->vars[$key];
588
+		} else {
589
+			return $this->vars;
590
+		}
591
+	}
592
+
593
+	/**
594
+	 * Get the id of the object
595
+	 *
596
+	 * @return int id of this object
597
+	 */
598
+	public function id()
599
+	{
600
+		return $this->getVar($this->handler->keyName, 'e');
601
+	}
602
+
603
+	/**
604
+	 * Return the value of the title field of this object
605
+	 *
606
+	 * @param  string $format
607
+	 * @return string
608
+	 */
609
+	public function title($format = 's')
610
+	{
611
+		return $this->getVar($this->handler->identifierName, $format);
612
+	}
613
+
614
+	/**
615
+	 * Return the value of the title field of this object
616
+	 *
617
+	 * @return string
618
+	 */
619
+	public function summary()
620
+	{
621
+		if ($this->handler->summaryName) {
622
+			return $this->getVar($this->handler->summaryName);
623
+		} else {
624
+			return false;
625
+		}
626
+	}
627
+
628
+	/**
629
+	 * Retreive the object admin side link, displayijng a SingleView page
630
+	 *
631
+	 * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
632
+	 * @return string user side link to the object
633
+	 */
634
+	public function getAdminViewItemLink($onlyUrl = false)
635
+	{
636
+		$controller = new SmartObjectController($this->handler);
637
+
638
+		return $controller->getAdminViewItemLink($this, $onlyUrl);
639
+	}
640
+
641
+	/**
642
+	 * Retreive the object user side link
643
+	 *
644
+	 * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
645
+	 * @return string user side link to the object
646
+	 */
647
+	public function getItemLink($onlyUrl = false)
648
+	{
649
+		$controller = new SmartObjectController($this->handler);
650
+
651
+		return $controller->getItemLink($this, $onlyUrl);
652
+	}
653
+
654
+	/**
655
+	 * @param  bool   $onlyUrl
656
+	 * @param  bool   $withimage
657
+	 * @param  bool   $userSide
658
+	 * @return string
659
+	 */
660
+	public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
661
+	{
662
+		$controller = new SmartObjectController($this->handler);
663
+
664
+		return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
665
+	}
666
+
667
+	/**
668
+	 * @param  bool   $onlyUrl
669
+	 * @param  bool   $withimage
670
+	 * @param  bool   $userSide
671
+	 * @return string
672
+	 */
673
+	public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
674
+	{
675
+		$controller = new SmartObjectController($this->handler);
676
+
677
+		return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
678
+	}
679
+
680
+	/**
681
+	 * @return string
682
+	 */
683
+	public function getPrintAndMailLink()
684
+	{
685
+		$controller = new SmartObjectController($this->handler);
686
+
687
+		return $controller->getPrintAndMailLink($this);
688
+	}
689
+
690
+	/**
691
+	 * @param $sortsel
692
+	 * @return array|bool
693
+	 */
694
+	public function getFieldsForSorting($sortsel)
695
+	{
696
+		$ret = array();
697
+
698
+		foreach ($this->vars as $key => $field_info) {
699
+			if ($field_info['sortby']) {
700
+				$ret[$key]['caption']  = $field_info['form_caption'];
701
+				$ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : '';
702
+			}
703
+		}
704
+
705
+		if (count($ret) > 0) {
706
+			return $ret;
707
+		} else {
708
+			return false;
709
+		}
710
+	}
711
+
712
+	/**
713
+	 * @param $key
714
+	 * @param $newType
715
+	 */
716
+	public function setType($key, $newType)
717
+	{
718
+		$this->vars[$key]['data_type'] = $newType;
719
+	}
720
+
721
+	/**
722
+	 * @param $key
723
+	 * @param $info
724
+	 * @param $value
725
+	 */
726
+	public function setVarInfo($key, $info, $value)
727
+	{
728
+		$this->vars[$key][$info] = $value;
729
+	}
730
+
731
+	/**
732
+	 * @param         $key
733
+	 * @param  bool   $editor
734
+	 * @return string
735
+	 */
736
+	public function getValueFor($key, $editor = true)
737
+	{
738
+		global $xoopsModuleConfig;
739
+
740
+		$ret  = $this->getVar($key, 'n');
741
+		$myts = MyTextSanitizer::getInstance();
742
+
743
+		$control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
744
+		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
745
+
746
+		$html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
747
+		$smiley   = true;
748
+		$xcode    = true;
749
+		$image    = true;
750
+		$br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
751
+		$formatML = true;
752
+
753
+		if ($form_editor === 'default') {
754
+			global $xoopsModuleConfig;
755
+			$form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
756
+		}
757
+
758
+		if ($editor) {
759
+			if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) {
760
+				$br       = false;
761
+				$formatML = !$editor;
762
+			} else {
763
+				return htmlspecialchars($ret, ENT_QUOTES);
764
+			}
765
+		}
766
+
767
+		if (method_exists($myts, 'formatForML')) {
768
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
769
+		} else {
770
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
771
+		}
772
+	}
773
+
774
+	/**
775
+	 * clean values of all variables of the object for storage.
776
+	 * also add slashes whereever needed
777
+	 *
778
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
779
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
780
+	 * as a string separated by |
781
+	 *
782
+	 * @return bool true if successful
783
+	 * @access public
784
+	 */
785
+	public function cleanVars()
786
+	{
787
+		$ts              = MyTextSanitizer::getInstance();
788
+		$existing_errors = $this->getErrors();
789
+		$this->_errors   = array();
790
+		foreach ($this->vars as $k => $v) {
791
+			$cleanv = $v['value'];
792
+			if (!$v['changed']) {
793
+			} else {
794
+				$cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
795
+				switch ($v['data_type']) {
796
+					case XOBJ_DTYPE_TXTBOX:
797
+						if ($v['required'] && $cleanv != '0' && $cleanv == '') {
798
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
799
+							continue 2;
800
+						}
801
+						if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
802
+							$this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
803
+							continue 2;
804
+						}
805
+						if (!$v['not_gpc']) {
806
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
807
+						} else {
808
+							$cleanv = $ts->censorString($cleanv);
809
+						}
810
+						break;
811
+					case XOBJ_DTYPE_TXTAREA:
812
+						if ($v['required'] && $cleanv != '0' && $cleanv == '') {
813
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
814
+							continue 2;
815
+						}
816
+						if (!$v['not_gpc']) {
817
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
818
+						} else {
819
+							$cleanv = $ts->censorString($cleanv);
820
+						}
821
+						break;
822
+					case XOBJ_DTYPE_SOURCE:
823
+						if (!$v['not_gpc']) {
824
+							$cleanv = $ts->stripSlashesGPC($cleanv);
825
+						} else {
826
+							$cleanv = $cleanv;
827
+						}
828
+						break;
829
+					case XOBJ_DTYPE_INT:
830
+					case XOBJ_DTYPE_TIME_ONLY:
831
+						$cleanv = (int)$cleanv;
832
+						break;
833
+
834
+					case XOBJ_DTYPE_CURRENCY:
835
+						$cleanv = smart_currency($cleanv);
836
+						break;
837
+
838
+					case XOBJ_DTYPE_FLOAT:
839
+						$cleanv = smart_float($cleanv);
840
+						break;
841
+
842
+					case XOBJ_DTYPE_EMAIL:
843
+						if ($v['required'] && $cleanv === '') {
844
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
845
+							continue 2;
846
+						}
847
+						if ($cleanv !== '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
848
+							$this->setErrors('Invalid Email');
849
+							continue 2;
850
+						}
851
+						if (!$v['not_gpc']) {
852
+							$cleanv = $ts->stripSlashesGPC($cleanv);
853
+						}
854
+						break;
855
+					case XOBJ_DTYPE_URL:
856
+						if ($v['required'] && $cleanv === '') {
857
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
858
+							continue 2;
859
+						}
860
+						if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
861
+							$cleanv = 'http://' . $cleanv;
862
+						}
863
+						if (!$v['not_gpc']) {
864
+							$cleanv =& $ts->stripSlashesGPC($cleanv);
865
+						}
866
+						break;
867
+					case XOBJ_DTYPE_SIMPLE_ARRAY:
868
+						$cleanv = implode('|', $cleanv);
869
+						break;
870
+					case XOBJ_DTYPE_ARRAY:
871
+						$cleanv = serialize($cleanv);
872
+						break;
873
+					case XOBJ_DTYPE_STIME:
874
+					case XOBJ_DTYPE_MTIME:
875
+					case XOBJ_DTYPE_LTIME:
876
+						$cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
877
+						if (!($cleanv > 0)) {
878
+							$cleanv = strtotime($cleanv);
879
+						}
880
+						break;
881
+					default:
882
+						break;
883
+				}
884
+			}
885
+			$this->cleanVars[$k] =& $cleanv;
886
+			unset($cleanv);
887
+		}
888
+		if (count($this->_errors) > 0) {
889
+			$this->_errors = array_merge($existing_errors, $this->_errors);
890
+
891
+			return false;
892
+		}
893
+		$this->_errors = array_merge($existing_errors, $this->_errors);
894
+		$this->unsetDirty();
895
+
896
+		return true;
897
+	}
898
+
899
+	/**
900
+	 * returns a specific variable for the object in a proper format
901
+	 *
902
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
903
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
904
+	 * as a string separated by |
905
+	 *
906
+	 * @access public
907
+	 * @param  string $key    key of the object's variable to be returned
908
+	 * @param  string $format format to use for the output
909
+	 * @return mixed  formatted value of the variable
910
+	 */
911
+	public function getVar($key, $format = 's')
912
+	{
913
+		global $myts;
914
+
915
+		$ret = $this->vars[$key]['value'];
916
+
917
+		switch ($this->vars[$key]['data_type']) {
918
+
919
+			case XOBJ_DTYPE_TXTBOX:
920
+				switch (strtolower($format)) {
921
+					case 's':
922
+					case 'show':
923
+						// ML Hack by marcan
924
+						$ts  = MyTextSanitizer::getInstance();
925
+						$ret = $ts->htmlSpecialChars($ret);
926
+
927
+						if (method_exists($myts, 'formatForML')) {
928
+							return $ts->formatForML($ret);
929
+						} else {
930
+							return $ret;
931
+						}
932
+						break 1;
933
+					// End of ML Hack by marcan
934
+
935
+					case 'clean':
936
+						$ts = MyTextSanitizer::getInstance();
937
+
938
+						$ret = smart_html2text($ret);
939
+						$ret = smart_purifyText($ret);
940
+
941
+						if (method_exists($myts, 'formatForML')) {
942
+							return $ts->formatForML($ret);
943
+						} else {
944
+							return $ret;
945
+						}
946
+						break 1;
947
+					// End of ML Hack by marcan
948
+
949
+					case 'e':
950
+					case 'edit':
951
+						$ts = MyTextSanitizer::getInstance();
952
+
953
+						return $ts->htmlSpecialChars($ret);
954
+						break 1;
955
+					case 'p':
956
+					case 'preview':
957
+					case 'f':
958
+					case 'formpreview':
959
+						$ts = MyTextSanitizer::getInstance();
960
+
961
+						return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
962
+						break 1;
963
+					case 'n':
964
+					case 'none':
965
+					default:
966
+						break 1;
967
+				}
968
+				break;
969
+			case XOBJ_DTYPE_LTIME:
970
+				switch (strtolower($format)) {
971
+					case 's':
972
+					case 'show':
973
+					case 'p':
974
+					case 'preview':
975
+					case 'f':
976
+					case 'formpreview':
977
+						$ret = formatTimestamp($ret, _DATESTRING);
978
+
979
+						return $ret;
980
+						break 1;
981
+					case 'n':
982
+					case 'none':
983
+					case 'e':
984
+					case 'edit':
985
+						break 1;
986
+					default:
987
+						break 1;
988
+				}
989
+				break;
990
+			case XOBJ_DTYPE_STIME:
991
+				switch (strtolower($format)) {
992
+					case 's':
993
+					case 'show':
994
+					case 'p':
995
+					case 'preview':
996
+					case 'f':
997
+					case 'formpreview':
998
+						$ret = formatTimestamp($ret, _SHORTDATESTRING);
999
+
1000
+						return $ret;
1001
+						break 1;
1002
+					case 'n':
1003
+					case 'none':
1004
+					case 'e':
1005
+					case 'edit':
1006
+						break 1;
1007
+					default:
1008
+						break 1;
1009
+				}
1010
+				break;
1011
+			case XOBJ_DTYPE_TIME_ONLY:
1012
+				switch (strtolower($format)) {
1013
+					case 's':
1014
+					case 'show':
1015
+					case 'p':
1016
+					case 'preview':
1017
+					case 'f':
1018
+					case 'formpreview':
1019
+						$ret = formatTimestamp($ret, 'G:i');
1020
+
1021
+						return $ret;
1022
+						break 1;
1023
+					case 'n':
1024
+					case 'none':
1025
+					case 'e':
1026
+					case 'edit':
1027
+						break 1;
1028
+					default:
1029
+						break 1;
1030
+				}
1031
+				break;
1032
+
1033
+			case XOBJ_DTYPE_CURRENCY:
1034
+				$decimal_section_original = strstr($ret, '.');
1035
+				$decimal_section          = $decimal_section_original;
1036
+				if ($decimal_section) {
1037
+					if (strlen($decimal_section) == 1) {
1038
+						$decimal_section = '.00';
1039
+					} elseif (strlen($decimal_section) == 2) {
1040
+						$decimal_section .= '0';
1041
+					}
1042
+					$ret = str_replace($decimal_section_original, $decimal_section, $ret);
1043
+				} else {
1044
+					$ret .= '.00';
1045
+				}
1046
+				break;
1047
+
1048
+			case XOBJ_DTYPE_TXTAREA:
1049
+				switch (strtolower($format)) {
1050
+					case 's':
1051
+					case 'show':
1052
+						$ts   = MyTextSanitizer::getInstance();
1053
+						$html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1054
+
1055
+						$xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1056
+
1057
+						$smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1058
+						$image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1059
+						$br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1060
+
1061
+						/**
1062
+						 * Hack by marcan <INBOX> for SCSPRO
1063
+						 * Setting mastop as the main editor
1064
+						 */
1065
+						if (defined('XOOPS_EDITOR_IS_HTML')) {
1066
+							$br = false;
1067
+						}
1068
+						/**
1069
+						 * Hack by marcan <INBOX> for SCSPRO
1070
+						 * Setting mastop as the main editor
1071
+						 */
1072
+
1073
+						return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1074
+						break 1;
1075
+					case 'e':
1076
+					case 'edit':
1077
+						return htmlspecialchars($ret, ENT_QUOTES);
1078
+						break 1;
1079
+					case 'p':
1080
+					case 'preview':
1081
+						$ts     = MyTextSanitizer::getInstance();
1082
+						$html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1083
+						$xcode  = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1084
+						$smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1085
+						$image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1086
+						$br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1087
+
1088
+						return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1089
+						break 1;
1090
+					case 'f':
1091
+					case 'formpreview':
1092
+						$ts = MyTextSanitizer::getInstance();
1093
+
1094
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1095
+						break 1;
1096
+					case 'n':
1097
+					case 'none':
1098
+					default:
1099
+						break 1;
1100
+				}
1101
+				break;
1102
+			case XOBJ_DTYPE_SIMPLE_ARRAY:
1103
+				$ret =& explode('|', $ret);
1104
+				break;
1105
+			case XOBJ_DTYPE_ARRAY:
1106
+				$ret =& unserialize($ret);
1107
+				break;
1108
+			case XOBJ_DTYPE_SOURCE:
1109
+				switch (strtolower($format)) {
1110
+					case 's':
1111
+					case 'show':
1112
+						break 1;
1113
+					case 'e':
1114
+					case 'edit':
1115
+						return htmlspecialchars($ret, ENT_QUOTES);
1116
+						break 1;
1117
+					case 'p':
1118
+					case 'preview':
1119
+						$ts = MyTextSanitizer::getInstance();
1120
+
1121
+						return $ts->stripSlashesGPC($ret);
1122
+						break 1;
1123
+					case 'f':
1124
+					case 'formpreview':
1125
+						$ts = MyTextSanitizer::getInstance();
1126
+
1127
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1128
+						break 1;
1129
+					case 'n':
1130
+					case 'none':
1131
+					default:
1132
+						break 1;
1133
+				}
1134
+				break;
1135
+			default:
1136
+				if ($this->vars[$key]['options'] !== '' && $ret != '') {
1137
+					switch (strtolower($format)) {
1138
+						case 's':
1139
+						case 'show':
1140
+							$selected = explode('|', $ret);
1141
+							$options  = explode('|', $this->vars[$key]['options']);
1142
+							$i        = 1;
1143
+							$ret      = array();
1144
+							foreach ($options as $op) {
1145
+								if (in_array($i, $selected)) {
1146
+									$ret[] = $op;
1147
+								}
1148
+								++$i;
1149
+							}
1150
+
1151
+							return implode(', ', $ret);
1152
+						case 'e':
1153
+						case 'edit':
1154
+							$ret = explode('|', $ret);
1155
+							break 1;
1156
+						default:
1157
+							break 1;
1158
+					}
1159
+				}
1160
+				break;
1161
+		}
1162
+
1163
+		return $ret;
1164
+	}
1165
+
1166
+	/**
1167
+	 * @param $key
1168
+	 */
1169
+	public function doMakeFieldreadOnly($key)
1170
+	{
1171
+		if (isset($this->vars[$key])) {
1172
+			$this->vars[$key]['readonly']      = true;
1173
+			$this->vars[$key]['displayOnForm'] = true;
1174
+		}
1175
+	}
1176
+
1177
+	/**
1178
+	 * @param $key
1179
+	 */
1180
+	public function makeFieldReadOnly($key)
1181
+	{
1182
+		if (is_array($key)) {
1183
+			foreach ($key as $v) {
1184
+				$this->doMakeFieldreadOnly($v);
1185
+			}
1186
+		} else {
1187
+			$this->doMakeFieldreadOnly($key);
1188
+		}
1189
+	}
1190
+
1191
+	/**
1192
+	 * @param $key
1193
+	 */
1194
+	public function doHideFieldFromForm($key)
1195
+	{
1196
+		if (isset($this->vars[$key])) {
1197
+			$this->vars[$key]['displayOnForm'] = false;
1198
+		}
1199
+	}
1200
+
1201
+	/**
1202
+	 * @param $key
1203
+	 */
1204
+	public function doHideFieldFromSingleView($key)
1205
+	{
1206
+		if (isset($this->vars[$key])) {
1207
+			$this->vars[$key]['displayOnSingleView'] = false;
1208
+		}
1209
+	}
1210
+
1211
+	/**
1212
+	 * @param $key
1213
+	 */
1214
+	public function hideFieldFromForm($key)
1215
+	{
1216
+		if (is_array($key)) {
1217
+			foreach ($key as $v) {
1218
+				$this->doHideFieldFromForm($v);
1219
+			}
1220
+		} else {
1221
+			$this->doHideFieldFromForm($key);
1222
+		}
1223
+	}
1224
+
1225
+	/**
1226
+	 * @param $key
1227
+	 */
1228
+	public function hideFieldFromSingleView($key)
1229
+	{
1230
+		if (is_array($key)) {
1231
+			foreach ($key as $v) {
1232
+				$this->doHideFieldFromSingleView($v);
1233
+			}
1234
+		} else {
1235
+			$this->doHideFieldFromSingleView($key);
1236
+		}
1237
+	}
1238
+
1239
+	/**
1240
+	 * @param $key
1241
+	 */
1242
+	public function doShowFieldOnForm($key)
1243
+	{
1244
+		if (isset($this->vars[$key])) {
1245
+			$this->vars[$key]['displayOnForm'] = true;
1246
+		}
1247
+	}
1248
+
1249
+	/**
1250
+	 * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1251
+	 *
1252
+	 * @param  bool    $fetchOnly   if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1253
+	 * @param  bool    $userSide    for futur use, to do something different on the user side
1254
+	 * @param  array   $actions
1255
+	 * @param  bool    $headerAsRow
1256
+	 * @return content of the template if $fetchOnly or nothing if !$fetchOnly
1257
+	 */
1258
+	public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true)
1259
+	{
1260
+		include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1261
+		$singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow);
1262
+		// add all fields mark as displayOnSingleView except the keyid
1263
+		foreach ($this->vars as $key => $var) {
1264
+			if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1265
+				$is_header = ($key == $this->handler->identifierName);
1266
+				$singleview->addRow(new SmartObjectRow($key, false, $is_header));
1267
+			}
1268
+		}
1269
+
1270
+		if ($fetchOnly) {
1271
+			$ret = $singleview->render($fetchOnly);
1272
+
1273
+			return $ret;
1274
+		} else {
1275
+			$singleview->render($fetchOnly);
1276
+		}
1277
+	}
1278
+
1279
+	/**
1280
+	 * @param $key
1281
+	 */
1282
+	public function doDisplayFieldOnSingleView($key)
1283
+	{
1284
+		if (isset($this->vars[$key])) {
1285
+			$this->vars[$key]['displayOnSingleView'] = true;
1286
+		}
1287
+	}
1288
+
1289
+	/**
1290
+	 * @param      $field
1291
+	 * @param bool $required
1292
+	 */
1293
+	public function doSetFieldAsRequired($field, $required = true)
1294
+	{
1295
+		$this->setVarInfo($field, 'required', $required);
1296
+	}
1297
+
1298
+	/**
1299
+	 * @param $field
1300
+	 */
1301
+	public function doSetFieldForSorting($field)
1302
+	{
1303
+		$this->setVarInfo($field, 'sortby', true);
1304
+	}
1305
+
1306
+	/**
1307
+	 * @param $key
1308
+	 */
1309
+	public function showFieldOnForm($key)
1310
+	{
1311
+		if (is_array($key)) {
1312
+			foreach ($key as $v) {
1313
+				$this->doShowFieldOnForm($v);
1314
+			}
1315
+		} else {
1316
+			$this->doShowFieldOnForm($key);
1317
+		}
1318
+	}
1319
+
1320
+	/**
1321
+	 * @param $key
1322
+	 */
1323
+	public function displayFieldOnSingleView($key)
1324
+	{
1325
+		if (is_array($key)) {
1326
+			foreach ($key as $v) {
1327
+				$this->doDisplayFieldOnSingleView($v);
1328
+			}
1329
+		} else {
1330
+			$this->doDisplayFieldOnSingleView($key);
1331
+		}
1332
+	}
1333
+
1334
+	/**
1335
+	 * @param $key
1336
+	 */
1337
+	public function doSetAdvancedFormFields($key)
1338
+	{
1339
+		if (isset($this->vars[$key])) {
1340
+			$this->vars[$key]['advancedform'] = true;
1341
+		}
1342
+	}
1343
+
1344
+	/**
1345
+	 * @param $key
1346
+	 */
1347
+	public function setAdvancedFormFields($key)
1348
+	{
1349
+		if (is_array($key)) {
1350
+			foreach ($key as $v) {
1351
+				$this->doSetAdvancedFormFields($v);
1352
+			}
1353
+		} else {
1354
+			$this->doSetAdvancedFormFields($key);
1355
+		}
1356
+	}
1357
+
1358
+	/**
1359
+	 * @param $key
1360
+	 * @return mixed
1361
+	 */
1362
+	public function getUrlLinkObj($key)
1363
+	{
1364
+		$smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1365
+		$urllinkid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1366
+		if ($urllinkid != 0) {
1367
+			return $smartobjectLinkurlHandler->get($urllinkid);
1368
+		} else {
1369
+			return $smartobjectLinkurlHandler->create();
1370
+		}
1371
+	}
1372
+
1373
+	/**
1374
+	 * @param $urlLinkObj
1375
+	 * @return mixed
1376
+	 */
1377
+	public function &storeUrlLinkObj($urlLinkObj)
1378
+	{
1379
+		$smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1380
+
1381
+		return $smartobjectLinkurlHandler->insert($urlLinkObj);
1382
+	}
1383
+
1384
+	/**
1385
+	 * @param $key
1386
+	 * @return mixed
1387
+	 */
1388
+	public function getFileObj($key)
1389
+	{
1390
+		$smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1391
+		$fileid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1392
+		if ($fileid != 0) {
1393
+			return $smartobjectFileHandler->get($fileid);
1394
+		} else {
1395
+			return $smartobjectFileHandler->create();
1396
+		}
1397
+	}
1398
+
1399
+	/**
1400
+	 * @param $fileObj
1401
+	 * @return mixed
1402
+	 */
1403
+	public function &storeFileObj($fileObj)
1404
+	{
1405
+		$smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1406
+
1407
+		return $smartobjectFileHandler->insert($fileObj);
1408
+	}
1409 1409
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 
13 13
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
14 14
 
15
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
15
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
16 16
 
17
-include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
17
+include_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php';
18 18
 
19 19
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
20 20
     define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function closeSection($section_name)
115 115
     {
116
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
116
+        $this->initVar('close_section_'.$section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
117 117
     }
118 118
 
119 119
     /**
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
         }
141 141
         parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
142 142
         if ($this->handler && (!$form_caption || $form_caption === '')) {
143
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
143
+            $dyn_form_caption = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key);
144 144
             if (defined($dyn_form_caption)) {
145 145
                 $form_caption = constant($dyn_form_caption);
146 146
             }
147 147
         }
148 148
         if ($this->handler && (!$form_dsc || $form_dsc === '')) {
149
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
149
+            $dyn_form_dsc = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key.'_DSC');
150 150
             if (defined($dyn_form_dsc)) {
151 151
                 $form_dsc = constant($dyn_form_dsc);
152 152
             }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
      */
411 411
     public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false)
412 412
     {
413
-        include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
413
+        include_once SMARTOBJECT_ROOT_PATH.'class/form/smartobjectform.php';
414 414
         $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
415 415
 
416 416
         return $form;
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
     public function toArray()
423 423
     {
424 424
         $ret  = array();
425
-        $vars =& $this->getVars();
425
+        $vars = & $this->getVars();
426 426
         foreach ($vars as $key => $var) {
427 427
             $value     = $this->getVar($key);
428 428
             $ret[$key] = $value;
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
         }
441 441
 
442 442
         // Hightlighting searched words
443
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php');
443
+        include_once(SMARTOBJECT_ROOT_PATH.'class/smarthighlighter.php');
444 444
         $highlight = smart_getConfig('module_search_highlighter', false, true);
445 445
 
446 446
         if ($highlight && isset($_GET['keywords'])) {
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
             }
472 472
         } else {
473 473
             if ($prefix) {
474
-                $err_str = '[' . $prefix . '] ' . $err_str;
474
+                $err_str = '['.$prefix.'] '.$err_str;
475 475
             }
476 476
             parent::setErrors($err_str);
477 477
         }
@@ -798,8 +798,8 @@  discard block
 block discarded – undo
798 798
                             $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
799 799
                             continue 2;
800 800
                         }
801
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
802
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
801
+                        if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) {
802
+                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength']));
803 803
                             continue 2;
804 804
                         }
805 805
                         if (!$v['not_gpc']) {
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
                         break;
829 829
                     case XOBJ_DTYPE_INT:
830 830
                     case XOBJ_DTYPE_TIME_ONLY:
831
-                        $cleanv = (int)$cleanv;
831
+                        $cleanv = (int) $cleanv;
832 832
                         break;
833 833
 
834 834
                     case XOBJ_DTYPE_CURRENCY:
@@ -858,10 +858,10 @@  discard block
 block discarded – undo
858 858
                             continue 2;
859 859
                         }
860 860
                         if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
861
-                            $cleanv = 'http://' . $cleanv;
861
+                            $cleanv = 'http://'.$cleanv;
862 862
                         }
863 863
                         if (!$v['not_gpc']) {
864
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
864
+                            $cleanv = & $ts->stripSlashesGPC($cleanv);
865 865
                         }
866 866
                         break;
867 867
                     case XOBJ_DTYPE_SIMPLE_ARRAY:
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
                     case XOBJ_DTYPE_STIME:
874 874
                     case XOBJ_DTYPE_MTIME:
875 875
                     case XOBJ_DTYPE_LTIME:
876
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
876
+                        $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv);
877 877
                         if (!($cleanv > 0)) {
878 878
                             $cleanv = strtotime($cleanv);
879 879
                         }
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
                         break;
883 883
                 }
884 884
             }
885
-            $this->cleanVars[$k] =& $cleanv;
885
+            $this->cleanVars[$k] = & $cleanv;
886 886
             unset($cleanv);
887 887
         }
888 888
         if (count($this->_errors) > 0) {
@@ -1100,10 +1100,10 @@  discard block
 block discarded – undo
1100 1100
                 }
1101 1101
                 break;
1102 1102
             case XOBJ_DTYPE_SIMPLE_ARRAY:
1103
-                $ret =& explode('|', $ret);
1103
+                $ret = & explode('|', $ret);
1104 1104
                 break;
1105 1105
             case XOBJ_DTYPE_ARRAY:
1106
-                $ret =& unserialize($ret);
1106
+                $ret = & unserialize($ret);
1107 1107
                 break;
1108 1108
             case XOBJ_DTYPE_SOURCE:
1109 1109
                 switch (strtolower($format)) {
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
      */
1258 1258
     public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true)
1259 1259
     {
1260
-        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1260
+        include_once SMARTOBJECT_ROOT_PATH.'class/smartobjectsingleview.php';
1261 1261
         $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow);
1262 1262
         // add all fields mark as displayOnSingleView except the keyid
1263 1263
         foreach ($this->vars as $key => $var) {
Please login to merge, or discard this patch.
class/smartobjectcontroller.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 
124 124
     /**
125 125
      * @param        $smartObj
126
-     * @param        $objectid
127
-     * @param        $created_success_msg
128
-     * @param        $modified_success_msg
126
+     * @param        integer $objectid
127
+     * @param        string $created_success_msg
128
+     * @param        string $modified_success_msg
129 129
      * @param  bool  $redirect_page
130 130
      * @param  bool  $debug
131 131
      * @return mixed
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      * @param  bool   $confirm_msg
290 290
      * @param  string $op
291 291
      * @param  bool   $userSide
292
-     * @return bool
292
+     * @return boolean|null
293 293
      * @internal param string $redir_page redirect page after deleting the object
294 294
      */
295 295
     public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
     }
444 444
 
445 445
     /**
446
-     * @param         $smartObj
446
+     * @param         SmartMlObject $smartObj
447 447
      * @param  bool   $onlyUrl
448 448
      * @param  bool   $withimage
449 449
      * @return string
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
     }
534 534
 
535 535
     /**
536
-     * @param $smartObj
536
+     * @param SmartObject $smartObj
537 537
      * @return string
538 538
      */
539 539
     public function getPrintAndMailLink($smartObj)
Please login to merge, or discard this patch.
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -31,548 +31,548 @@
 block discarded – undo
31 31
  */
32 32
 class SmartObjectController
33 33
 {
34
-    public $handler;
35
-
36
-    /**
37
-     * SmartObjectController constructor.
38
-     * @param $handler
39
-     */
40
-    public function __construct($handler)
41
-    {
42
-        $this->handler = $handler;
43
-    }
44
-
45
-    /**
46
-     * @param $smartObj
47
-     */
48
-    public function postDataToObject(&$smartObj)
49
-    {
50
-        foreach (array_keys($smartObj->vars) as $key) {
51
-            switch ($smartObj->vars[$key]['data_type']) {
52
-                case XOBJ_DTYPE_IMAGE:
53
-                    if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] !== '') {
54
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
55
-                        $smartObj->setVar($key, $_POST['url_' . $key]);
56
-                        if (file_exists($oldFile)) {
57
-                            unlink($oldFile);
58
-                        }
59
-                    }
60
-                    if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
61
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
62
-                        $smartObj->setVar($key, '');
63
-                        if (file_exists($oldFile)) {
64
-                            unlink($oldFile);
65
-                        }
66
-                    }
67
-                    break;
68
-
69
-                case XOBJ_DTYPE_URLLINK:
70
-                    $linkObj = $smartObj->getUrlLinkObj($key);
71
-                    $linkObj->setVar('caption', $_POST['caption_' . $key]);
72
-                    $linkObj->setVar('description', $_POST['desc_' . $key]);
73
-                    $linkObj->setVar('target', $_POST['target_' . $key]);
74
-                    $linkObj->setVar('url', $_POST['url_' . $key]);
75
-                    if ($linkObj->getVar('url') !== '') {
76
-                        $smartObj->storeUrlLinkObj($linkObj);
77
-                    }
78
-                    //todo: catch errors
79
-                    $smartObj->setVar($key, $linkObj->getVar('urllinkid'));
80
-                    break;
81
-
82
-                case XOBJ_DTYPE_FILE:
83
-                    if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] === '') {
84
-                        $fileObj = $smartObj->getFileObj($key);
85
-                        $fileObj->setVar('caption', $_POST['caption_' . $key]);
86
-                        $fileObj->setVar('description', $_POST['desc_' . $key]);
87
-                        $fileObj->setVar('url', $_POST['url_' . $key]);
88
-                        if (!($fileObj->getVar('url') === '' && $fileObj->getVar('url') === '' && $fileObj->getVar('url') === '')) {
89
-                            $res = $smartObj->storeFileObj($fileObj);
90
-                            if ($res) {
91
-                                $smartObj->setVar($key, $fileObj->getVar('fileid'));
92
-                            } else {
93
-                                //error setted, but no error message (to be improved)
94
-                                $smartObj->setErrors($fileObj->getErrors());
95
-                            }
96
-                        }
97
-                    }
98
-                    break;
99
-
100
-                case XOBJ_DTYPE_STIME:
101
-                case XOBJ_DTYPE_MTIME:
102
-                case XOBJ_DTYPE_LTIME:
103
-                    // check if this field's value is available in the POST array
104
-                    if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
105
-                        $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
106
-                    } else {
107
-                        $value = strtotime($_POST[$key]);
108
-                        //if strtotime returns false, the value is already a time stamp
109
-                        if (!$value) {
110
-                            $value = (int)$_POST[$key];
111
-                        }
112
-                    }
113
-                    $smartObj->setVar($key, $value);
114
-
115
-                    break;
116
-
117
-                default:
118
-                    $smartObj->setVar($key, $_POST[$key]);
119
-                    break;
120
-            }
121
-        }
122
-    }
123
-
124
-    /**
125
-     * @param        $smartObj
126
-     * @param        $objectid
127
-     * @param        $created_success_msg
128
-     * @param        $modified_success_msg
129
-     * @param  bool  $redirect_page
130
-     * @param  bool  $debug
131
-     * @return mixed
132
-     */
133
-    public function doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false)
134
-    {
135
-        global $smart_previous_page;
136
-
137
-        $this->postDataToObject($smartObj);
138
-
139
-        if ($smartObj->isNew()) {
140
-            $redirect_msg = $created_success_msg;
141
-        } else {
142
-            $redirect_msg = $modified_success_msg;
143
-        }
144
-
145
-        // Check if there were uploaded files
146
-        if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
147
-            include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
148
-            $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
149
-            foreach ($_FILES as $name => $file_array) {
150
-                if (isset($file_array['name']) && $file_array['name'] !== '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
151
-                    if ($uploaderObj->fetchMedia($name)) {
152
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
153
-                        if ($uploaderObj->upload()) {
154
-                            // Find the related field in the SmartObject
155
-                            $related_field   = str_replace('upload_', '', $name);
156
-                            $uploadedArray[] = $related_field;
157
-                            //si c'est un fichier Rich
158
-                            if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) {
159
-                                $object_fileurl = $smartObj->getUploadDir();
160
-                                $fileObj        = $smartObj->getFileObj($related_field);
161
-                                $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
162
-                                $fileObj->setVar('caption', $_POST['caption_' . $related_field]);
163
-                                $fileObj->setVar('description', $_POST['desc_' . $related_field]);
164
-                                $smartObj->storeFileObj($fileObj);
165
-                                //todo: catch errors
166
-                                $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
167
-                            } else {
168
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
169
-                                unlink($old_file);
170
-                                $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
171
-                            }
172
-                        } else {
173
-                            $smartObj->setErrors($uploaderObj->getErrors(false));
174
-                        }
175
-                    } else {
176
-                        $smartObj->setErrors($uploaderObj->getErrors(false));
177
-                    }
178
-                }
179
-            }
180
-        }
181
-
182
-        if ($debug) {
183
-            $storeResult = $this->handler->insertD($smartObj);
184
-        } else {
185
-            $storeResult = $this->handler->insert($smartObj);
186
-        }
187
-
188
-        if ($storeResult) {
189
-            if ($this->handler->getPermissions()) {
190
-                $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
191
-                $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
192
-            }
193
-        }
194
-
195
-        if ($redirect_page === null) {
196
-            return $smartObj;
197
-        } else {
198
-            if (!$storeResult) {
199
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
200
-            }
201
-
202
-            $redirect_page = $redirect_page ?: smart_get_page_before_form();
203
-
204
-            redirect_header($redirect_page, 2, $redirect_msg);
205
-        }
206
-    }
207
-
208
-    /**
209
-     * Store the object in the database autmatically from a form sending POST data
210
-     *
211
-     * @param  string      $created_success_msg  message to display if new object was created
212
-     * @param  string      $modified_success_msg message to display if object was successfully edited
213
-     * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
214
-     * @param  bool        $debug
215
-     * @param  bool        $x_param
216
-     * @return bool
217
-     * @internal param string $created_redir_page redirect page after creating the object
218
-     * @internal param string $modified_redir_page redirect page after editing the object
219
-     * @internal param bool $exit if set to TRUE then the script ends
220
-     */
221
-    public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false)
222
-    {
223
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
224
-        if ($debug) {
225
-            if ($x_param) {
226
-                $smartObj = $this->handler->getD($objectid, true, $x_param);
227
-            } else {
228
-                $smartObj = $this->handler->getD($objectid);
229
-            }
230
-        } else {
231
-            if ($x_param) {
232
-                $smartObj = $this->handler->get($objectid, true, false, false, $x_param);
233
-            } else {
234
-                $smartObj = $this->handler->get($objectid);
235
-            }
236
-        }
237
-
238
-        // if handler is the Multilanguage handler, we will need to treat this for multilanguage
239
-        if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
240
-            if ($smartObj->isNew()) {
241
-                // This is a new object. We need to store the meta data and then the language data
242
-                // First, we will get rid of the multilanguage data to only store the meta data
243
-                $smartObj->stripMultilanguageFields();
244
-                $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
245
-                /**
246
-                 * @todo we need to trap potential errors here
247
-                 */
248
-
249
-                // ok, the meta daa is stored. Let's recreate the object and then
250
-                // get rid of anything not multilanguage
251
-                unset($smartObj);
252
-                $smartObj = $this->handler->get($objectid);
253
-                $smartObj->stripNonMultilanguageFields();
254
-
255
-                $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
256
-                $this->handler->changeTableNameForML();
257
-                $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
258
-
259
-                return $ret;
260
-            }
261
-        } else {
262
-            return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
263
-        }
264
-    }
265
-
266
-    /**
267
-     * @return bool
268
-     */
269
-    public function storeSmartObjectD()
270
-    {
271
-        return $this->storeSmartObject(true);
272
-    }
273
-
274
-    /**
275
-     * @param  bool $debug
276
-     * @param  bool $xparam
277
-     * @return bool
278
-     */
279
-    public function storeSmartObject($debug = false, $xparam = false)
280
-    {
281
-        $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
282
-
283
-        return $ret;
284
-    }
285
-
286
-    /**
287
-     * Handles deletion of an object which keyid is passed as a GET param
288
-     *
289
-     * @param  bool   $confirm_msg
290
-     * @param  string $op
291
-     * @param  bool   $userSide
292
-     * @return bool
293
-     * @internal param string $redir_page redirect page after deleting the object
294
-     */
295
-    public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
296
-    {
297
-        global $smart_previous_page;
298
-
299
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
300
-        $smartObj = $this->handler->get($objectid);
301
-
302
-        if ($smartObj->isNew()) {
303
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
304
-        }
305
-
306
-        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
307
-        if ($confirm) {
308
-            if (!$this->handler->delete($smartObj)) {
309
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
310
-                exit;
311
-            }
312
-
313
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
314
-        } else {
315
-            // no confirm: show deletion condition
316
-
317
-            xoops_cp_header();
318
-
319
-            if (!$confirm_msg) {
320
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
321
-            }
322
-
323
-            xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
324
-                          sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
325
-
326
-            xoops_cp_footer();
327
-        }
328
-        exit();
329
-    }
330
-
331
-    /**
332
-     * @param bool   $confirm_msg
333
-     * @param string $op
334
-     */
335
-    public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
336
-    {
337
-        global $smart_previous_page, $xoopsTpl;
338
-
339
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
340
-        $smartObj = $this->handler->get($objectid);
341
-
342
-        if ($smartObj->isNew()) {
343
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
344
-        }
345
-
346
-        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
347
-        if ($confirm) {
348
-            if (!$this->handler->delete($smartObj)) {
349
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
350
-                exit;
351
-            }
352
-
353
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
354
-        } else {
355
-            // no confirm: show deletion condition
356
-            if (!$confirm_msg) {
357
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
358
-            }
359
-
360
-            ob_start();
361
-            xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
362
-                          sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
363
-            $smartobjectDeleteConfirm = ob_get_clean();
364
-            $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
365
-        }
366
-    }
367
-
368
-    /**
369
-     * Retreive the object admin side link for a {@link SmartObjectSingleView} page
370
-     *
371
-     * @param  SmartObject $smartObj  reference to the object from which we want the user side link
372
-     * @param  bool   $onlyUrl   wether or not to return a simple URL or a full <a> link
373
-     * @param  bool   $withimage
374
-     * @return string admin side link to the object
375
-     */
376
-    public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
377
-    {
378
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
379
-        if ($onlyUrl) {
380
-            return $ret;
381
-        } elseif ($withimage) {
382
-            return "<a href='" .
383
-                   $ret .
384
-                   "'><img src='" .
385
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
386
-                   "viewmag.png' style='vertical-align: middle;' alt='" .
387
-                   _CO_SOBJECT_ADMIN_VIEW .
388
-                   "'  title='" .
389
-                   _CO_SOBJECT_ADMIN_VIEW .
390
-                   "'/></a>";
391
-        }
392
-
393
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
394
-    }
395
-
396
-    /**
397
-     * Retreive the object user side link
398
-     *
399
-     * @param  SmartObject $smartObj reference to the object from which we want the user side link
400
-     * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
401
-     * @return string user side link to the object
402
-     */
403
-    public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
404
-    {
405
-        $seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
406
-        $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
407
-
408
-        /**
409
-         * $seoIncludeId feature is not finished yet, so let's put it always to true
410
-         */
411
-        //$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
412
-        $seoIncludeId = true;
413
-
414
-        if ($seoMode === 'rewrite') {
415
-            $ret = XOOPS_URL .
416
-                   '/' .
417
-                   $seoModuleName .
418
-                   '.' .
419
-                   $this->handler->_itemname .
420
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
421
-                   '/' .
422
-                   $smartObj->getVar('short_url') .
423
-                   '.html';
424
-        } elseif ($seoMode === 'pathinfo') {
425
-            $ret = SMARTOBJECT_URL .
426
-                   'seo.php/' .
427
-                   $seoModuleName .
428
-                   '.' .
429
-                   $this->handler->_itemname .
430
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
431
-                   '/' .
432
-                   $smartObj->getVar('short_url') .
433
-                   '.html';
434
-        } else {
435
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
436
-        }
437
-
438
-        if (!$onlyUrl) {
439
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
440
-        }
441
-
442
-        return $ret;
443
-    }
444
-
445
-    /**
446
-     * @param         $smartObj
447
-     * @param  bool   $onlyUrl
448
-     * @param  bool   $withimage
449
-     * @return string
450
-     */
451
-    public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
452
-    {
453
-        $ret = $this->handler->_moduleUrl .
454
-               'admin/' .
455
-               $this->handler->_page .
456
-               '?op=mod&' .
457
-               $this->handler->keyName .
458
-               '=' .
459
-               $smartObj->getVar($this->handler->keyName) .
460
-               '&language=' .
461
-               $smartObj->getVar('language');
462
-        if ($onlyUrl) {
463
-            return $ret;
464
-        } elseif ($withimage) {
465
-            return "<a href='" .
466
-                   $ret .
467
-                   "'><img src='" .
468
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
469
-                   "wizard.png' style='vertical-align: middle;' alt='" .
470
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
471
-                   "'  title='" .
472
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
473
-                   "'/></a>";
474
-        }
475
-
476
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
477
-    }
478
-
479
-    /**
480
-     * @param         $smartObj
481
-     * @param  bool   $onlyUrl
482
-     * @param  bool   $withimage
483
-     * @param  bool   $userSide
484
-     * @return string
485
-     */
486
-    public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
487
-    {
488
-        $admin_side = $userSide ? '' : 'admin/';
489
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
490
-        if ($onlyUrl) {
491
-            return $ret;
492
-        } elseif ($withimage) {
493
-            return "<a href='" .
494
-                   $ret .
495
-                   "'><img src='" .
496
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
497
-                   "edit.png' style='vertical-align: middle;' alt='" .
498
-                   _CO_SOBJECT_MODIFY .
499
-                   "'  title='" .
500
-                   _CO_SOBJECT_MODIFY .
501
-                   "'/></a>";
502
-        }
503
-
504
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
505
-    }
506
-
507
-    /**
508
-     * @param         $smartObj
509
-     * @param  bool   $onlyUrl
510
-     * @param  bool   $withimage
511
-     * @param  bool   $userSide
512
-     * @return string
513
-     */
514
-    public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
515
-    {
516
-        $admin_side = $userSide ? '' : 'admin/';
517
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
518
-        if ($onlyUrl) {
519
-            return $ret;
520
-        } elseif ($withimage) {
521
-            return "<a href='" .
522
-                   $ret .
523
-                   "'><img src='" .
524
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
525
-                   "editdelete.png' style='vertical-align: middle;' alt='" .
526
-                   _CO_SOBJECT_DELETE .
527
-                   "'  title='" .
528
-                   _CO_SOBJECT_DELETE .
529
-                   "'/></a>";
530
-        }
531
-
532
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
533
-    }
534
-
535
-    /**
536
-     * @param $smartObj
537
-     * @return string
538
-     */
539
-    public function getPrintAndMailLink($smartObj)
540
-    {
541
-        global $xoopsConfig;
542
-
543
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
544
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
545
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
546
-
547
-        $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
548
-        $link        = smart_getCurrentPage();
549
-        $mid         = $smartModule->getVar('mid');
550
-        $friendlink  = "<a href=\"javascript:openWithSelfMain('" .
551
-                       SMARTOBJECT_URL .
552
-                       'sendlink.php?link=' .
553
-                       $link .
554
-                       '&amp;mid=' .
555
-                       $mid .
556
-                       "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" .
557
-                       SMARTOBJECT_IMAGES_ACTIONS_URL .
558
-                       "mail_send.png\"  alt=\"" .
559
-                       _CO_SOBJECT_EMAIL .
560
-                       "\" title=\"" .
561
-                       _CO_SOBJECT_EMAIL .
562
-                       "\" style=\"vertical-align: middle;\"/></a>";
563
-
564
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
565
-
566
-        return $ret;
567
-    }
568
-
569
-    /**
570
-     * @return string
571
-     */
572
-    public function getModuleItemString()
573
-    {
574
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
575
-
576
-        return $ret;
577
-    }
34
+	public $handler;
35
+
36
+	/**
37
+	 * SmartObjectController constructor.
38
+	 * @param $handler
39
+	 */
40
+	public function __construct($handler)
41
+	{
42
+		$this->handler = $handler;
43
+	}
44
+
45
+	/**
46
+	 * @param $smartObj
47
+	 */
48
+	public function postDataToObject(&$smartObj)
49
+	{
50
+		foreach (array_keys($smartObj->vars) as $key) {
51
+			switch ($smartObj->vars[$key]['data_type']) {
52
+				case XOBJ_DTYPE_IMAGE:
53
+					if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] !== '') {
54
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
55
+						$smartObj->setVar($key, $_POST['url_' . $key]);
56
+						if (file_exists($oldFile)) {
57
+							unlink($oldFile);
58
+						}
59
+					}
60
+					if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
61
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
62
+						$smartObj->setVar($key, '');
63
+						if (file_exists($oldFile)) {
64
+							unlink($oldFile);
65
+						}
66
+					}
67
+					break;
68
+
69
+				case XOBJ_DTYPE_URLLINK:
70
+					$linkObj = $smartObj->getUrlLinkObj($key);
71
+					$linkObj->setVar('caption', $_POST['caption_' . $key]);
72
+					$linkObj->setVar('description', $_POST['desc_' . $key]);
73
+					$linkObj->setVar('target', $_POST['target_' . $key]);
74
+					$linkObj->setVar('url', $_POST['url_' . $key]);
75
+					if ($linkObj->getVar('url') !== '') {
76
+						$smartObj->storeUrlLinkObj($linkObj);
77
+					}
78
+					//todo: catch errors
79
+					$smartObj->setVar($key, $linkObj->getVar('urllinkid'));
80
+					break;
81
+
82
+				case XOBJ_DTYPE_FILE:
83
+					if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] === '') {
84
+						$fileObj = $smartObj->getFileObj($key);
85
+						$fileObj->setVar('caption', $_POST['caption_' . $key]);
86
+						$fileObj->setVar('description', $_POST['desc_' . $key]);
87
+						$fileObj->setVar('url', $_POST['url_' . $key]);
88
+						if (!($fileObj->getVar('url') === '' && $fileObj->getVar('url') === '' && $fileObj->getVar('url') === '')) {
89
+							$res = $smartObj->storeFileObj($fileObj);
90
+							if ($res) {
91
+								$smartObj->setVar($key, $fileObj->getVar('fileid'));
92
+							} else {
93
+								//error setted, but no error message (to be improved)
94
+								$smartObj->setErrors($fileObj->getErrors());
95
+							}
96
+						}
97
+					}
98
+					break;
99
+
100
+				case XOBJ_DTYPE_STIME:
101
+				case XOBJ_DTYPE_MTIME:
102
+				case XOBJ_DTYPE_LTIME:
103
+					// check if this field's value is available in the POST array
104
+					if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
105
+						$value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
106
+					} else {
107
+						$value = strtotime($_POST[$key]);
108
+						//if strtotime returns false, the value is already a time stamp
109
+						if (!$value) {
110
+							$value = (int)$_POST[$key];
111
+						}
112
+					}
113
+					$smartObj->setVar($key, $value);
114
+
115
+					break;
116
+
117
+				default:
118
+					$smartObj->setVar($key, $_POST[$key]);
119
+					break;
120
+			}
121
+		}
122
+	}
123
+
124
+	/**
125
+	 * @param        $smartObj
126
+	 * @param        $objectid
127
+	 * @param        $created_success_msg
128
+	 * @param        $modified_success_msg
129
+	 * @param  bool  $redirect_page
130
+	 * @param  bool  $debug
131
+	 * @return mixed
132
+	 */
133
+	public function doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false)
134
+	{
135
+		global $smart_previous_page;
136
+
137
+		$this->postDataToObject($smartObj);
138
+
139
+		if ($smartObj->isNew()) {
140
+			$redirect_msg = $created_success_msg;
141
+		} else {
142
+			$redirect_msg = $modified_success_msg;
143
+		}
144
+
145
+		// Check if there were uploaded files
146
+		if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
147
+			include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
148
+			$uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
149
+			foreach ($_FILES as $name => $file_array) {
150
+				if (isset($file_array['name']) && $file_array['name'] !== '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
151
+					if ($uploaderObj->fetchMedia($name)) {
152
+						$uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
153
+						if ($uploaderObj->upload()) {
154
+							// Find the related field in the SmartObject
155
+							$related_field   = str_replace('upload_', '', $name);
156
+							$uploadedArray[] = $related_field;
157
+							//si c'est un fichier Rich
158
+							if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) {
159
+								$object_fileurl = $smartObj->getUploadDir();
160
+								$fileObj        = $smartObj->getFileObj($related_field);
161
+								$fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
162
+								$fileObj->setVar('caption', $_POST['caption_' . $related_field]);
163
+								$fileObj->setVar('description', $_POST['desc_' . $related_field]);
164
+								$smartObj->storeFileObj($fileObj);
165
+								//todo: catch errors
166
+								$smartObj->setVar($related_field, $fileObj->getVar('fileid'));
167
+							} else {
168
+								$old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
169
+								unlink($old_file);
170
+								$smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
171
+							}
172
+						} else {
173
+							$smartObj->setErrors($uploaderObj->getErrors(false));
174
+						}
175
+					} else {
176
+						$smartObj->setErrors($uploaderObj->getErrors(false));
177
+					}
178
+				}
179
+			}
180
+		}
181
+
182
+		if ($debug) {
183
+			$storeResult = $this->handler->insertD($smartObj);
184
+		} else {
185
+			$storeResult = $this->handler->insert($smartObj);
186
+		}
187
+
188
+		if ($storeResult) {
189
+			if ($this->handler->getPermissions()) {
190
+				$smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
191
+				$smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
192
+			}
193
+		}
194
+
195
+		if ($redirect_page === null) {
196
+			return $smartObj;
197
+		} else {
198
+			if (!$storeResult) {
199
+				redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
200
+			}
201
+
202
+			$redirect_page = $redirect_page ?: smart_get_page_before_form();
203
+
204
+			redirect_header($redirect_page, 2, $redirect_msg);
205
+		}
206
+	}
207
+
208
+	/**
209
+	 * Store the object in the database autmatically from a form sending POST data
210
+	 *
211
+	 * @param  string      $created_success_msg  message to display if new object was created
212
+	 * @param  string      $modified_success_msg message to display if object was successfully edited
213
+	 * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
214
+	 * @param  bool        $debug
215
+	 * @param  bool        $x_param
216
+	 * @return bool
217
+	 * @internal param string $created_redir_page redirect page after creating the object
218
+	 * @internal param string $modified_redir_page redirect page after editing the object
219
+	 * @internal param bool $exit if set to TRUE then the script ends
220
+	 */
221
+	public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false)
222
+	{
223
+		$objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
224
+		if ($debug) {
225
+			if ($x_param) {
226
+				$smartObj = $this->handler->getD($objectid, true, $x_param);
227
+			} else {
228
+				$smartObj = $this->handler->getD($objectid);
229
+			}
230
+		} else {
231
+			if ($x_param) {
232
+				$smartObj = $this->handler->get($objectid, true, false, false, $x_param);
233
+			} else {
234
+				$smartObj = $this->handler->get($objectid);
235
+			}
236
+		}
237
+
238
+		// if handler is the Multilanguage handler, we will need to treat this for multilanguage
239
+		if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
240
+			if ($smartObj->isNew()) {
241
+				// This is a new object. We need to store the meta data and then the language data
242
+				// First, we will get rid of the multilanguage data to only store the meta data
243
+				$smartObj->stripMultilanguageFields();
244
+				$newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
245
+				/**
246
+				 * @todo we need to trap potential errors here
247
+				 */
248
+
249
+				// ok, the meta daa is stored. Let's recreate the object and then
250
+				// get rid of anything not multilanguage
251
+				unset($smartObj);
252
+				$smartObj = $this->handler->get($objectid);
253
+				$smartObj->stripNonMultilanguageFields();
254
+
255
+				$smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
256
+				$this->handler->changeTableNameForML();
257
+				$ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
258
+
259
+				return $ret;
260
+			}
261
+		} else {
262
+			return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
263
+		}
264
+	}
265
+
266
+	/**
267
+	 * @return bool
268
+	 */
269
+	public function storeSmartObjectD()
270
+	{
271
+		return $this->storeSmartObject(true);
272
+	}
273
+
274
+	/**
275
+	 * @param  bool $debug
276
+	 * @param  bool $xparam
277
+	 * @return bool
278
+	 */
279
+	public function storeSmartObject($debug = false, $xparam = false)
280
+	{
281
+		$ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
282
+
283
+		return $ret;
284
+	}
285
+
286
+	/**
287
+	 * Handles deletion of an object which keyid is passed as a GET param
288
+	 *
289
+	 * @param  bool   $confirm_msg
290
+	 * @param  string $op
291
+	 * @param  bool   $userSide
292
+	 * @return bool
293
+	 * @internal param string $redir_page redirect page after deleting the object
294
+	 */
295
+	public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
296
+	{
297
+		global $smart_previous_page;
298
+
299
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
300
+		$smartObj = $this->handler->get($objectid);
301
+
302
+		if ($smartObj->isNew()) {
303
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
304
+		}
305
+
306
+		$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
307
+		if ($confirm) {
308
+			if (!$this->handler->delete($smartObj)) {
309
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
310
+				exit;
311
+			}
312
+
313
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
314
+		} else {
315
+			// no confirm: show deletion condition
316
+
317
+			xoops_cp_header();
318
+
319
+			if (!$confirm_msg) {
320
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
321
+			}
322
+
323
+			xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
324
+						  sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
325
+
326
+			xoops_cp_footer();
327
+		}
328
+		exit();
329
+	}
330
+
331
+	/**
332
+	 * @param bool   $confirm_msg
333
+	 * @param string $op
334
+	 */
335
+	public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
336
+	{
337
+		global $smart_previous_page, $xoopsTpl;
338
+
339
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
340
+		$smartObj = $this->handler->get($objectid);
341
+
342
+		if ($smartObj->isNew()) {
343
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
344
+		}
345
+
346
+		$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
347
+		if ($confirm) {
348
+			if (!$this->handler->delete($smartObj)) {
349
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
350
+				exit;
351
+			}
352
+
353
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
354
+		} else {
355
+			// no confirm: show deletion condition
356
+			if (!$confirm_msg) {
357
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
358
+			}
359
+
360
+			ob_start();
361
+			xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
362
+						  sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
363
+			$smartobjectDeleteConfirm = ob_get_clean();
364
+			$xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
365
+		}
366
+	}
367
+
368
+	/**
369
+	 * Retreive the object admin side link for a {@link SmartObjectSingleView} page
370
+	 *
371
+	 * @param  SmartObject $smartObj  reference to the object from which we want the user side link
372
+	 * @param  bool   $onlyUrl   wether or not to return a simple URL or a full <a> link
373
+	 * @param  bool   $withimage
374
+	 * @return string admin side link to the object
375
+	 */
376
+	public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
377
+	{
378
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
379
+		if ($onlyUrl) {
380
+			return $ret;
381
+		} elseif ($withimage) {
382
+			return "<a href='" .
383
+				   $ret .
384
+				   "'><img src='" .
385
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
386
+				   "viewmag.png' style='vertical-align: middle;' alt='" .
387
+				   _CO_SOBJECT_ADMIN_VIEW .
388
+				   "'  title='" .
389
+				   _CO_SOBJECT_ADMIN_VIEW .
390
+				   "'/></a>";
391
+		}
392
+
393
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
394
+	}
395
+
396
+	/**
397
+	 * Retreive the object user side link
398
+	 *
399
+	 * @param  SmartObject $smartObj reference to the object from which we want the user side link
400
+	 * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
401
+	 * @return string user side link to the object
402
+	 */
403
+	public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
404
+	{
405
+		$seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
406
+		$seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
407
+
408
+		/**
409
+		 * $seoIncludeId feature is not finished yet, so let's put it always to true
410
+		 */
411
+		//$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
412
+		$seoIncludeId = true;
413
+
414
+		if ($seoMode === 'rewrite') {
415
+			$ret = XOOPS_URL .
416
+				   '/' .
417
+				   $seoModuleName .
418
+				   '.' .
419
+				   $this->handler->_itemname .
420
+				   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
421
+				   '/' .
422
+				   $smartObj->getVar('short_url') .
423
+				   '.html';
424
+		} elseif ($seoMode === 'pathinfo') {
425
+			$ret = SMARTOBJECT_URL .
426
+				   'seo.php/' .
427
+				   $seoModuleName .
428
+				   '.' .
429
+				   $this->handler->_itemname .
430
+				   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
431
+				   '/' .
432
+				   $smartObj->getVar('short_url') .
433
+				   '.html';
434
+		} else {
435
+			$ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
436
+		}
437
+
438
+		if (!$onlyUrl) {
439
+			$ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
440
+		}
441
+
442
+		return $ret;
443
+	}
444
+
445
+	/**
446
+	 * @param         $smartObj
447
+	 * @param  bool   $onlyUrl
448
+	 * @param  bool   $withimage
449
+	 * @return string
450
+	 */
451
+	public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
452
+	{
453
+		$ret = $this->handler->_moduleUrl .
454
+			   'admin/' .
455
+			   $this->handler->_page .
456
+			   '?op=mod&' .
457
+			   $this->handler->keyName .
458
+			   '=' .
459
+			   $smartObj->getVar($this->handler->keyName) .
460
+			   '&language=' .
461
+			   $smartObj->getVar('language');
462
+		if ($onlyUrl) {
463
+			return $ret;
464
+		} elseif ($withimage) {
465
+			return "<a href='" .
466
+				   $ret .
467
+				   "'><img src='" .
468
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
469
+				   "wizard.png' style='vertical-align: middle;' alt='" .
470
+				   _CO_SOBJECT_LANGUAGE_MODIFY .
471
+				   "'  title='" .
472
+				   _CO_SOBJECT_LANGUAGE_MODIFY .
473
+				   "'/></a>";
474
+		}
475
+
476
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
477
+	}
478
+
479
+	/**
480
+	 * @param         $smartObj
481
+	 * @param  bool   $onlyUrl
482
+	 * @param  bool   $withimage
483
+	 * @param  bool   $userSide
484
+	 * @return string
485
+	 */
486
+	public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
487
+	{
488
+		$admin_side = $userSide ? '' : 'admin/';
489
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
490
+		if ($onlyUrl) {
491
+			return $ret;
492
+		} elseif ($withimage) {
493
+			return "<a href='" .
494
+				   $ret .
495
+				   "'><img src='" .
496
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
497
+				   "edit.png' style='vertical-align: middle;' alt='" .
498
+				   _CO_SOBJECT_MODIFY .
499
+				   "'  title='" .
500
+				   _CO_SOBJECT_MODIFY .
501
+				   "'/></a>";
502
+		}
503
+
504
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
505
+	}
506
+
507
+	/**
508
+	 * @param         $smartObj
509
+	 * @param  bool   $onlyUrl
510
+	 * @param  bool   $withimage
511
+	 * @param  bool   $userSide
512
+	 * @return string
513
+	 */
514
+	public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
515
+	{
516
+		$admin_side = $userSide ? '' : 'admin/';
517
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
518
+		if ($onlyUrl) {
519
+			return $ret;
520
+		} elseif ($withimage) {
521
+			return "<a href='" .
522
+				   $ret .
523
+				   "'><img src='" .
524
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
525
+				   "editdelete.png' style='vertical-align: middle;' alt='" .
526
+				   _CO_SOBJECT_DELETE .
527
+				   "'  title='" .
528
+				   _CO_SOBJECT_DELETE .
529
+				   "'/></a>";
530
+		}
531
+
532
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
533
+	}
534
+
535
+	/**
536
+	 * @param $smartObj
537
+	 * @return string
538
+	 */
539
+	public function getPrintAndMailLink($smartObj)
540
+	{
541
+		global $xoopsConfig;
542
+
543
+		$printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
544
+		$js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
545
+		$printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
546
+
547
+		$smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
548
+		$link        = smart_getCurrentPage();
549
+		$mid         = $smartModule->getVar('mid');
550
+		$friendlink  = "<a href=\"javascript:openWithSelfMain('" .
551
+					   SMARTOBJECT_URL .
552
+					   'sendlink.php?link=' .
553
+					   $link .
554
+					   '&amp;mid=' .
555
+					   $mid .
556
+					   "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" .
557
+					   SMARTOBJECT_IMAGES_ACTIONS_URL .
558
+					   "mail_send.png\"  alt=\"" .
559
+					   _CO_SOBJECT_EMAIL .
560
+					   "\" title=\"" .
561
+					   _CO_SOBJECT_EMAIL .
562
+					   "\" style=\"vertical-align: middle;\"/></a>";
563
+
564
+		$ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
565
+
566
+		return $ret;
567
+	}
568
+
569
+	/**
570
+	 * @return string
571
+	 */
572
+	public function getModuleItemString()
573
+	{
574
+		$ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
575
+
576
+		return $ret;
577
+	}
578 578
 }
Please login to merge, or discard this patch.
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  * @credit  Jan Keller Pedersen <[email protected]> - IDG Danmark A/S <www.idg.dk>
24 24
  * @link    http://smartfactory.ca The SmartFactory
25 25
  */
26
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
27
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecthandler.php';
26
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
27
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobjecthandler.php';
28 28
 
29 29
 /**
30 30
  * Class SmartObjectController
@@ -50,15 +50,15 @@  discard block
 block discarded – undo
50 50
         foreach (array_keys($smartObj->vars) as $key) {
51 51
             switch ($smartObj->vars[$key]['data_type']) {
52 52
                 case XOBJ_DTYPE_IMAGE:
53
-                    if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] !== '') {
54
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
55
-                        $smartObj->setVar($key, $_POST['url_' . $key]);
53
+                    if (isset($_POST['url_'.$key]) && $_POST['url_'.$key] !== '') {
54
+                        $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e');
55
+                        $smartObj->setVar($key, $_POST['url_'.$key]);
56 56
                         if (file_exists($oldFile)) {
57 57
                             unlink($oldFile);
58 58
                         }
59 59
                     }
60
-                    if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
61
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
60
+                    if (isset($_POST['delete_'.$key]) && $_POST['delete_'.$key] == '1') {
61
+                        $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e');
62 62
                         $smartObj->setVar($key, '');
63 63
                         if (file_exists($oldFile)) {
64 64
                             unlink($oldFile);
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 
69 69
                 case XOBJ_DTYPE_URLLINK:
70 70
                     $linkObj = $smartObj->getUrlLinkObj($key);
71
-                    $linkObj->setVar('caption', $_POST['caption_' . $key]);
72
-                    $linkObj->setVar('description', $_POST['desc_' . $key]);
73
-                    $linkObj->setVar('target', $_POST['target_' . $key]);
74
-                    $linkObj->setVar('url', $_POST['url_' . $key]);
71
+                    $linkObj->setVar('caption', $_POST['caption_'.$key]);
72
+                    $linkObj->setVar('description', $_POST['desc_'.$key]);
73
+                    $linkObj->setVar('target', $_POST['target_'.$key]);
74
+                    $linkObj->setVar('url', $_POST['url_'.$key]);
75 75
                     if ($linkObj->getVar('url') !== '') {
76 76
                         $smartObj->storeUrlLinkObj($linkObj);
77 77
                     }
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
                     break;
81 81
 
82 82
                 case XOBJ_DTYPE_FILE:
83
-                    if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] === '') {
83
+                    if (!isset($_FILES['upload_'.$key]['name']) || $_FILES['upload_'.$key]['name'] === '') {
84 84
                         $fileObj = $smartObj->getFileObj($key);
85
-                        $fileObj->setVar('caption', $_POST['caption_' . $key]);
86
-                        $fileObj->setVar('description', $_POST['desc_' . $key]);
87
-                        $fileObj->setVar('url', $_POST['url_' . $key]);
85
+                        $fileObj->setVar('caption', $_POST['caption_'.$key]);
86
+                        $fileObj->setVar('description', $_POST['desc_'.$key]);
87
+                        $fileObj->setVar('url', $_POST['url_'.$key]);
88 88
                         if (!($fileObj->getVar('url') === '' && $fileObj->getVar('url') === '' && $fileObj->getVar('url') === '')) {
89 89
                             $res = $smartObj->storeFileObj($fileObj);
90 90
                             if ($res) {
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                         $value = strtotime($_POST[$key]);
108 108
                         //if strtotime returns false, the value is already a time stamp
109 109
                         if (!$value) {
110
-                            $value = (int)$_POST[$key];
110
+                            $value = (int) $_POST[$key];
111 111
                         }
112 112
                     }
113 113
                     $smartObj->setVar($key, $value);
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
 
145 145
         // Check if there were uploaded files
146 146
         if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
147
-            include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
147
+            include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartuploader.php';
148 148
             $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
149 149
             foreach ($_FILES as $name => $file_array) {
150 150
                 if (isset($file_array['name']) && $file_array['name'] !== '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
151 151
                     if ($uploaderObj->fetchMedia($name)) {
152
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
152
+                        $uploaderObj->setTargetFileName(time().'_'.$uploaderObj->getMediaName());
153 153
                         if ($uploaderObj->upload()) {
154 154
                             // Find the related field in the SmartObject
155 155
                             $related_field   = str_replace('upload_', '', $name);
@@ -158,14 +158,14 @@  discard block
 block discarded – undo
158 158
                             if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) {
159 159
                                 $object_fileurl = $smartObj->getUploadDir();
160 160
                                 $fileObj        = $smartObj->getFileObj($related_field);
161
-                                $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
162
-                                $fileObj->setVar('caption', $_POST['caption_' . $related_field]);
163
-                                $fileObj->setVar('description', $_POST['desc_' . $related_field]);
161
+                                $fileObj->setVar('url', $object_fileurl.$uploaderObj->getSavedFileName());
162
+                                $fileObj->setVar('caption', $_POST['caption_'.$related_field]);
163
+                                $fileObj->setVar('description', $_POST['desc_'.$related_field]);
164 164
                                 $smartObj->storeFileObj($fileObj);
165 165
                                 //todo: catch errors
166 166
                                 $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
167 167
                             } else {
168
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
168
+                                $old_file = $smartObj->getUploadDir(true).$smartObj->getVar($related_field);
169 169
                                 unlink($old_file);
170 170
                                 $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
171 171
                             }
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             return $smartObj;
197 197
         } else {
198 198
             if (!$storeResult) {
199
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
199
+                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR.$smartObj->getHtmlErrors());
200 200
             }
201 201
 
202 202
             $redirect_page = $redirect_page ?: smart_get_page_before_form();
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false)
222 222
     {
223
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
223
+        $objectid = isset($_POST[$this->handler->keyName]) ? (int) $_POST[$this->handler->keyName] : 0;
224 224
         if ($debug) {
225 225
             if ($x_param) {
226 226
                 $smartObj = $this->handler->getD($objectid, true, $x_param);
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
     {
297 297
         global $smart_previous_page;
298 298
 
299
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
299
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
300 300
         $smartObj = $this->handler->get($objectid);
301 301
 
302 302
         if ($smartObj->isNew()) {
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
         $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
307 307
         if ($confirm) {
308 308
             if (!$this->handler->delete($smartObj)) {
309
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
309
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
310 310
                 exit;
311 311
             }
312 312
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     {
337 337
         global $smart_previous_page, $xoopsTpl;
338 338
 
339
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
339
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
340 340
         $smartObj = $this->handler->get($objectid);
341 341
 
342 342
         if ($smartObj->isNew()) {
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
         $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
347 347
         if ($confirm) {
348 348
             if (!$this->handler->delete($smartObj)) {
349
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
349
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
350 350
                 exit;
351 351
             }
352 352
 
@@ -375,22 +375,22 @@  discard block
 block discarded – undo
375 375
      */
376 376
     public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
377 377
     {
378
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
378
+        $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=view&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
379 379
         if ($onlyUrl) {
380 380
             return $ret;
381 381
         } elseif ($withimage) {
382
-            return "<a href='" .
383
-                   $ret .
384
-                   "'><img src='" .
385
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
386
-                   "viewmag.png' style='vertical-align: middle;' alt='" .
387
-                   _CO_SOBJECT_ADMIN_VIEW .
388
-                   "'  title='" .
389
-                   _CO_SOBJECT_ADMIN_VIEW .
382
+            return "<a href='".
383
+                   $ret.
384
+                   "'><img src='".
385
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
386
+                   "viewmag.png' style='vertical-align: middle;' alt='".
387
+                   _CO_SOBJECT_ADMIN_VIEW.
388
+                   "'  title='".
389
+                   _CO_SOBJECT_ADMIN_VIEW.
390 390
                    "'/></a>";
391 391
         }
392 392
 
393
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
393
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
394 394
     }
395 395
 
396 396
     /**
@@ -412,31 +412,31 @@  discard block
 block discarded – undo
412 412
         $seoIncludeId = true;
413 413
 
414 414
         if ($seoMode === 'rewrite') {
415
-            $ret = XOOPS_URL .
416
-                   '/' .
417
-                   $seoModuleName .
418
-                   '.' .
419
-                   $this->handler->_itemname .
420
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
421
-                   '/' .
422
-                   $smartObj->getVar('short_url') .
415
+            $ret = XOOPS_URL.
416
+                   '/'.
417
+                   $seoModuleName.
418
+                   '.'.
419
+                   $this->handler->_itemname.
420
+                   ($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').
421
+                   '/'.
422
+                   $smartObj->getVar('short_url').
423 423
                    '.html';
424 424
         } elseif ($seoMode === 'pathinfo') {
425
-            $ret = SMARTOBJECT_URL .
426
-                   'seo.php/' .
427
-                   $seoModuleName .
428
-                   '.' .
429
-                   $this->handler->_itemname .
430
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
431
-                   '/' .
432
-                   $smartObj->getVar('short_url') .
425
+            $ret = SMARTOBJECT_URL.
426
+                   'seo.php/'.
427
+                   $seoModuleName.
428
+                   '.'.
429
+                   $this->handler->_itemname.
430
+                   ($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').
431
+                   '/'.
432
+                   $smartObj->getVar('short_url').
433 433
                    '.html';
434 434
         } else {
435
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
435
+            $ret = $this->handler->_moduleUrl.$this->handler->_page.'?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
436 436
         }
437 437
 
438 438
         if (!$onlyUrl) {
439
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
439
+            $ret = "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
440 440
         }
441 441
 
442 442
         return $ret;
@@ -450,30 +450,30 @@  discard block
 block discarded – undo
450 450
      */
451 451
     public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
452 452
     {
453
-        $ret = $this->handler->_moduleUrl .
454
-               'admin/' .
455
-               $this->handler->_page .
456
-               '?op=mod&' .
457
-               $this->handler->keyName .
458
-               '=' .
459
-               $smartObj->getVar($this->handler->keyName) .
460
-               '&language=' .
453
+        $ret = $this->handler->_moduleUrl.
454
+               'admin/'.
455
+               $this->handler->_page.
456
+               '?op=mod&'.
457
+               $this->handler->keyName.
458
+               '='.
459
+               $smartObj->getVar($this->handler->keyName).
460
+               '&language='.
461 461
                $smartObj->getVar('language');
462 462
         if ($onlyUrl) {
463 463
             return $ret;
464 464
         } elseif ($withimage) {
465
-            return "<a href='" .
466
-                   $ret .
467
-                   "'><img src='" .
468
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
469
-                   "wizard.png' style='vertical-align: middle;' alt='" .
470
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
471
-                   "'  title='" .
472
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
465
+            return "<a href='".
466
+                   $ret.
467
+                   "'><img src='".
468
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
469
+                   "wizard.png' style='vertical-align: middle;' alt='".
470
+                   _CO_SOBJECT_LANGUAGE_MODIFY.
471
+                   "'  title='".
472
+                   _CO_SOBJECT_LANGUAGE_MODIFY.
473 473
                    "'/></a>";
474 474
         }
475 475
 
476
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
476
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
477 477
     }
478 478
 
479 479
     /**
@@ -486,22 +486,22 @@  discard block
 block discarded – undo
486 486
     public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
487 487
     {
488 488
         $admin_side = $userSide ? '' : 'admin/';
489
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
489
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
490 490
         if ($onlyUrl) {
491 491
             return $ret;
492 492
         } elseif ($withimage) {
493
-            return "<a href='" .
494
-                   $ret .
495
-                   "'><img src='" .
496
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
497
-                   "edit.png' style='vertical-align: middle;' alt='" .
498
-                   _CO_SOBJECT_MODIFY .
499
-                   "'  title='" .
500
-                   _CO_SOBJECT_MODIFY .
493
+            return "<a href='".
494
+                   $ret.
495
+                   "'><img src='".
496
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
497
+                   "edit.png' style='vertical-align: middle;' alt='".
498
+                   _CO_SOBJECT_MODIFY.
499
+                   "'  title='".
500
+                   _CO_SOBJECT_MODIFY.
501 501
                    "'/></a>";
502 502
         }
503 503
 
504
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
504
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
505 505
     }
506 506
 
507 507
     /**
@@ -514,22 +514,22 @@  discard block
 block discarded – undo
514 514
     public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
515 515
     {
516 516
         $admin_side = $userSide ? '' : 'admin/';
517
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
517
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=del&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
518 518
         if ($onlyUrl) {
519 519
             return $ret;
520 520
         } elseif ($withimage) {
521
-            return "<a href='" .
522
-                   $ret .
523
-                   "'><img src='" .
524
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
525
-                   "editdelete.png' style='vertical-align: middle;' alt='" .
526
-                   _CO_SOBJECT_DELETE .
527
-                   "'  title='" .
528
-                   _CO_SOBJECT_DELETE .
521
+            return "<a href='".
522
+                   $ret.
523
+                   "'><img src='".
524
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
525
+                   "editdelete.png' style='vertical-align: middle;' alt='".
526
+                   _CO_SOBJECT_DELETE.
527
+                   "'  title='".
528
+                   _CO_SOBJECT_DELETE.
529 529
                    "'/></a>";
530 530
         }
531 531
 
532
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
532
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
533 533
     }
534 534
 
535 535
     /**
@@ -540,28 +540,28 @@  discard block
 block discarded – undo
540 540
     {
541 541
         global $xoopsConfig;
542 542
 
543
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
544
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
545
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
543
+        $printlink = $this->handler->_moduleUrl.'print.php?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
544
+        $js        = "javascript:openWithSelfMain('".$printlink."', 'smartpopup', 700, 519);";
545
+        $printlink = '<a href="'.$js.'"><img  src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
546 546
 
547 547
         $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
548 548
         $link        = smart_getCurrentPage();
549 549
         $mid         = $smartModule->getVar('mid');
550
-        $friendlink  = "<a href=\"javascript:openWithSelfMain('" .
551
-                       SMARTOBJECT_URL .
552
-                       'sendlink.php?link=' .
553
-                       $link .
554
-                       '&amp;mid=' .
555
-                       $mid .
556
-                       "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" .
557
-                       SMARTOBJECT_IMAGES_ACTIONS_URL .
558
-                       "mail_send.png\"  alt=\"" .
559
-                       _CO_SOBJECT_EMAIL .
560
-                       "\" title=\"" .
561
-                       _CO_SOBJECT_EMAIL .
550
+        $friendlink  = "<a href=\"javascript:openWithSelfMain('".
551
+                       SMARTOBJECT_URL.
552
+                       'sendlink.php?link='.
553
+                       $link.
554
+                       '&amp;mid='.
555
+                       $mid.
556
+                       "', ',',',',',','sendmessage', 674, 500);\"><img src=\"".
557
+                       SMARTOBJECT_IMAGES_ACTIONS_URL.
558
+                       "mail_send.png\"  alt=\"".
559
+                       _CO_SOBJECT_EMAIL.
560
+                       "\" title=\"".
561
+                       _CO_SOBJECT_EMAIL.
562 562
                        "\" style=\"vertical-align: middle;\"/></a>";
563 563
 
564
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
564
+        $ret = '<span id="smartobject_print_button">'.$printlink.'&nbsp;</span>'.'<span id="smartobject_mail_button">'.$friendlink.'</span>';
565 565
 
566 566
         return $ret;
567 567
     }
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
      */
572 572
     public function getModuleItemString()
573 573
     {
574
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
574
+        $ret = $this->handler->_moduleName.'_'.$this->handler->_itemname;
575 575
 
576 576
         return $ret;
577 577
     }
Please login to merge, or discard this patch.
class/smartobjecthandler.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @param XoopsDatabase $db           {@link XoopsDatabase}
134 134
      *                                           object
135
-     * @param                      $itemname
135
+     * @param                      string $itemname
136 136
      * @param string               $keyname      Name of the table key that uniquely identify each {@link SmartObject}
137 137
      * @param string               $idenfierName Name of the field which properly identify the {@link SmartObject}
138
-     * @param                      $summaryName
138
+     * @param                      string $summaryName
139 139
      * @param                      $modulename
140 140
      * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
141 141
      * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
     /**
193 193
      * @param $criteria
194
-     * @param $perm_name
194
+     * @param boolean $perm_name
195 195
      * @return bool
196 196
      */
197 197
     public function setGrantedObjectsCriteria(&$criteria, $perm_name)
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
     }
376 376
 
377 377
     /**
378
-     * @param        $sql
378
+     * @param        string $sql
379 379
      * @param        $criteria
380 380
      * @param  bool  $force
381 381
      * @param  bool  $debug
Please login to merge, or discard this patch.
Indentation   +966 added lines, -966 removed lines patch added patch discarded remove patch
@@ -25,970 +25,970 @@
 block discarded – undo
25 25
  */
26 26
 class SmartPersistableObjectHandler extends XoopsObjectHandler
27 27
 {
28
-    public $_itemname;
29
-
30
-    /**
31
-     * Name of the table use to store this {@link SmartObject}
32
-     *
33
-     * Note that the name of the table needs to be free of the database prefix.
34
-     * For example "smartsection_categories"
35
-     * @var string
36
-     */
37
-    public $table;
38
-
39
-    /**
40
-     * Name of the table key that uniquely identify each {@link SmartObject}
41
-     *
42
-     * For example: "categoryid"
43
-     * @var string
44
-     */
45
-    public $keyName;
46
-
47
-    /**
48
-     * Name of the class derived from {@link SmartObject} and which this handler is handling
49
-     *
50
-     * Note that this string needs to be lowercase
51
-     *
52
-     * For example: "smartsectioncategory"
53
-     * @var string
54
-     */
55
-    public $className;
56
-
57
-    /**
58
-     * Name of the field which properly identify the {@link SmartObject}
59
-     *
60
-     * For example: "name" (this will be the category's name)
61
-     * @var string
62
-     */
63
-    public $identifierName;
64
-
65
-    /**
66
-     * Name of the field which will be use as a summary for the object
67
-     *
68
-     * For example: "summary"
69
-     * @var string
70
-     */
71
-    public $summaryName;
72
-
73
-    /**
74
-     * Page name use to basically manage and display the {@link SmartObject}
75
-     *
76
-     * This page needs to be the same in user side and admin side
77
-     *
78
-     * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
79
-     * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
80
-     * @var string
81
-     */
82
-    public $_page;
83
-
84
-    /**
85
-     * Full path of the module using this {@link SmartObject}
86
-     *
87
-     * <code>XOOPS_URL . "/modules/smartsection/"</code>
88
-     * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
89
-     * @var string
90
-     */
91
-    public $_modulePath;
92
-
93
-    public $_moduleUrl;
94
-
95
-    public $_moduleName;
96
-
97
-    public $_uploadUrl;
98
-
99
-    public $_uploadPath;
100
-
101
-    public $_allowedMimeTypes = 0;
102
-
103
-    public $_maxFileSize = 1000000;
104
-
105
-    public $_maxWidth = 500;
106
-
107
-    public $_maxHeight = 500;
108
-
109
-    public $highlightFields = array();
110
-
111
-    /**
112
-     * Array containing the events name and functions
113
-     *
114
-     * @var array
115
-     */
116
-    public $eventArray = array();
117
-
118
-    /**
119
-     * Array containing the permissions that this handler will manage on the objects
120
-     *
121
-     * @var array
122
-     */
123
-    public $permissionsArray = false;
124
-
125
-    public $generalSQL = false;
126
-
127
-    public $_eventHooks     = array();
128
-    public $_disabledEvents = array();
129
-
130
-    /**
131
-     * Constructor - called from child classes
132
-     *
133
-     * @param XoopsDatabase $db           {@link XoopsDatabase}
134
-     *                                           object
135
-     * @param                      $itemname
136
-     * @param string               $keyname      Name of the table key that uniquely identify each {@link SmartObject}
137
-     * @param string               $idenfierName Name of the field which properly identify the {@link SmartObject}
138
-     * @param                      $summaryName
139
-     * @param                      $modulename
140
-     * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
141
-     * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
142
-     * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
143
-     * @internal param string $moduleName name of the module
144
-     */
145
-    public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
146
-    {
147
-        parent::__construct($db);
148
-
149
-        $this->_itemname      = $itemname;
150
-        $this->_moduleName    = $modulename;
151
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
152
-        $this->keyName        = $keyname;
153
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
154
-        $this->identifierName = $idenfierName;
155
-        $this->summaryName    = $summaryName;
156
-        $this->_page          = $itemname . '.php';
157
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
158
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
159
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
160
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
161
-    }
162
-
163
-    /**
164
-     * @param $event
165
-     * @param $method
166
-     */
167
-    public function addEventHook($event, $method)
168
-    {
169
-        $this->_eventHooks[$event] = $method;
170
-    }
171
-
172
-    /**
173
-     * Add a permission that this handler will manage for its objects
174
-     *
175
-     * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
176
-     *
177
-     * @param string      $perm_name   name of the permission
178
-     * @param string      $caption     caption of the control that will be displayed in the form
179
-     * @param bool|string $description description of the control that will be displayed in the form
180
-     */
181
-    public function addPermission($perm_name, $caption, $description = false)
182
-    {
183
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
184
-
185
-        $this->permissionsArray[] = array(
186
-            'perm_name'   => $perm_name,
187
-            'caption'     => $caption,
188
-            'description' => $description
189
-        );
190
-    }
191
-
192
-    /**
193
-     * @param $criteria
194
-     * @param $perm_name
195
-     * @return bool
196
-     */
197
-    public function setGrantedObjectsCriteria(&$criteria, $perm_name)
198
-    {
199
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
200
-        $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
201
-        if (count($grantedItems) > 0) {
202
-            $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
203
-
204
-            return true;
205
-        } else {
206
-            return false;
207
-        }
208
-    }
209
-
210
-    /**
211
-     * @param bool $_uploadPath
212
-     * @param bool $_allowedMimeTypes
213
-     * @param bool $_maxFileSize
214
-     * @param bool $_maxWidth
215
-     * @param bool $_maxHeight
216
-     */
217
-    public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false)
218
-    {
219
-        $this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
220
-        $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
221
-        $this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
222
-        $this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
223
-        $this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
224
-    }
225
-
226
-    /**
227
-     * create a new {@link SmartObject}
228
-     *
229
-     * @param bool $isNew Flag the new objects as "new"?
230
-     *
231
-     * @return SmartObject {@link SmartObject}
232
-     */
233
-    public function create($isNew = true)
234
-    {
235
-        $obj = new $this->className($this);
236
-        $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
237
-        if (!$obj->handler) {
238
-            $obj->handler =& $this;
239
-        }
240
-
241
-        if ($isNew === true) {
242
-            $obj->setNew();
243
-        }
244
-
245
-        return $obj;
246
-    }
247
-
248
-    /**
249
-     * @return string
250
-     */
251
-    public function getImageUrl()
252
-    {
253
-        return $this->_uploadUrl . $this->_itemname . '/';
254
-    }
255
-
256
-    /**
257
-     * @return string
258
-     */
259
-    public function getImagePath()
260
-    {
261
-        $dir = $this->_uploadPath . $this->_itemname;
262
-        if (!file_exists($dir)) {
263
-            smart_admin_mkdir($dir);
264
-        }
265
-
266
-        return $dir . '/';
267
-    }
268
-
269
-    /**
270
-     * retrieve a {@link SmartObject}
271
-     *
272
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
273
-     * @param  bool  $as_object whether to return an object or an array
274
-     * @param  bool  $debug
275
-     * @param  bool  $criteria
276
-     * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
277
-     *                         FALSE if failed
278
-     */
279
-    public function get($id, $as_object = true, $debug = false, $criteria = false)
280
-    {
281
-        if (!$criteria) {
282
-            $criteria = new CriteriaCompo();
283
-        }
284
-        if (is_array($this->keyName)) {
285
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
286
-                /**
287
-                 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
288
-                 * Is the fact that we removed the (int)() represents a security risk ?
289
-                 */
290
-                //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
291
-                $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
292
-            }
293
-        } else {
294
-            //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname);
295
-            /**
296
-             * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
297
-             * Is the fact that we removed the (int)() represents a security risk ?
298
-             */
299
-            $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
300
-        }
301
-        $criteria->setLimit(1);
302
-        if ($debug) {
303
-            $obj_array = $this->getObjectsD($criteria, false, $as_object);
304
-        } else {
305
-            $obj_array = $this->getObjects($criteria, false, $as_object);
306
-            //patch: weird bug of indexing by id even if id_as_key = false;
307
-            if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
308
-                $obj_array[0] = $obj_array[$id];
309
-                unset($obj_array[$id]);
310
-                $obj_array[0]->unsetNew();
311
-            }
312
-        }
313
-
314
-        if (count($obj_array) != 1) {
315
-            $obj = $this->create();
316
-
317
-            return $obj;
318
-        }
319
-
320
-        return $obj_array[0];
321
-    }
322
-
323
-    /**
324
-     * retrieve a {@link SmartObject}
325
-     *
326
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
327
-     * @param  bool  $as_object whether to return an object or an array
328
-     * @return mixed reference to the {@link SmartObject}, FALSE if failed
329
-     */
330
-    public function &getD($id, $as_object = true)
331
-    {
332
-        return $this->get($id, $as_object, true);
333
-    }
334
-
335
-    /**
336
-     * retrieve objects from the database
337
-     *
338
-     * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
339
-     * @param bool   $id_as_key use the ID as key for the array?
340
-     * @param bool   $as_object return an array of objects?
341
-     *
342
-     * @param  bool  $sql
343
-     * @param  bool  $debug
344
-     * @return array
345
-     */
346
-    public function getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false)
347
-    {
348
-        $ret   = array();
349
-        $limit = $start = 0;
350
-
351
-        if ($this->generalSQL) {
352
-            $sql = $this->generalSQL;
353
-        } elseif (!$sql) {
354
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
355
-        }
356
-
357
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
358
-            $sql .= ' ' . $criteria->renderWhere();
359
-            if ($criteria->getSort() !== '') {
360
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
361
-            }
362
-            $limit = $criteria->getLimit();
363
-            $start = $criteria->getStart();
364
-        }
365
-        if ($debug) {
366
-            xoops_debug($sql);
367
-        }
368
-
369
-        $result = $this->db->query($sql, $limit, $start);
370
-        if (!$result) {
371
-            return $ret;
372
-        }
373
-
374
-        return $this->convertResultSet($result, $id_as_key, $as_object);
375
-    }
376
-
377
-    /**
378
-     * @param        $sql
379
-     * @param        $criteria
380
-     * @param  bool  $force
381
-     * @param  bool  $debug
382
-     * @return array
383
-     */
384
-    public function query($sql, $criteria, $force = false, $debug = false)
385
-    {
386
-        $ret = array();
387
-
388
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
389
-            $sql .= ' ' . $criteria->renderWhere();
390
-            if ($criteria->groupby) {
391
-                $sql .= $criteria->getGroupby();
392
-            }
393
-            if ($criteria->getSort() !== '') {
394
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
395
-            }
396
-        }
397
-        if ($debug) {
398
-            xoops_debug($sql);
399
-        }
400
-
401
-        if ($force) {
402
-            $result = $this->db->queryF($sql);
403
-        } else {
404
-            $result = $this->db->query($sql);
405
-        }
406
-
407
-        if (!$result) {
408
-            return $ret;
409
-        }
410
-
411
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
412
-            $ret[] = $myrow;
413
-        }
414
-
415
-        return $ret;
416
-    }
417
-
418
-    /**
419
-     * retrieve objects with debug mode - so will show the query
420
-     *
421
-     * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
422
-     * @param bool   $id_as_key use the ID as key for the array?
423
-     * @param bool   $as_object return an array of objects?
424
-     *
425
-     * @param  bool  $sql
426
-     * @return array
427
-     */
428
-    public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
429
-    {
430
-        return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
431
-    }
432
-
433
-    /**
434
-     * @param $arrayObjects
435
-     * @return array|bool
436
-     */
437
-    public function getObjectsAsArray($arrayObjects)
438
-    {
439
-        $ret = array();
440
-        foreach ($arrayObjects as $key => $object) {
441
-            $ret[$key] = $object->toArray();
442
-        }
443
-        if (count($ret > 0)) {
444
-            return $ret;
445
-        } else {
446
-            return false;
447
-        }
448
-    }
449
-
450
-    /**
451
-     * Convert a database resultset to a returnable array
452
-     *
453
-     * @param object $result    database resultset
454
-     * @param bool   $id_as_key - should NOT be used with joint keys
455
-     * @param bool   $as_object
456
-     *
457
-     * @return array
458
-     */
459
-    public function convertResultSet($result, $id_as_key = false, $as_object = true)
460
-    {
461
-        $ret = array();
462
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
463
-            $obj = $this->create(false);
464
-            $obj->assignVars($myrow);
465
-            if (!$id_as_key) {
466
-                if ($as_object) {
467
-                    $ret[] =& $obj;
468
-                } else {
469
-                    $ret[] = $obj->toArray();
470
-                }
471
-            } else {
472
-                if ($as_object) {
473
-                    $value =& $obj;
474
-                } else {
475
-                    $value = $obj->toArray();
476
-                }
477
-                if ($id_as_key === 'parentid') {
478
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
479
-                } else {
480
-                    $ret[$obj->getVar($this->keyName)] = $value;
481
-                }
482
-            }
483
-            unset($obj);
484
-        }
485
-
486
-        return $ret;
487
-    }
488
-
489
-    /**
490
-     * @param  null  $criteria
491
-     * @param  int   $limit
492
-     * @param  int   $start
493
-     * @return array
494
-     */
495
-    public function getListD($criteria = null, $limit = 0, $start = 0)
496
-    {
497
-        return $this->getList($criteria, $limit, $start, true);
498
-    }
499
-
500
-    /**
501
-     * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
502
-     *
503
-     * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
504
-     * @param int    $limit    Max number of objects to fetch
505
-     * @param int    $start    Which record to start at
506
-     *
507
-     * @param  bool  $debug
508
-     * @return array
509
-     */
510
-    public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
511
-    {
512
-        $ret = array();
513
-        if ($criteria === null) {
514
-            $criteria = new CriteriaCompo();
515
-        }
516
-
517
-        if ($criteria->getSort() === '') {
518
-            $criteria->setSort($this->getIdentifierName());
519
-        }
520
-
521
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
522
-        if (!empty($this->identifierName)) {
523
-            $sql .= ', ' . $this->getIdentifierName();
524
-        }
525
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
526
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
527
-            $sql .= ' ' . $criteria->renderWhere();
528
-            if ($criteria->getSort() !== '') {
529
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
530
-            }
531
-            $limit = $criteria->getLimit();
532
-            $start = $criteria->getStart();
533
-        }
534
-
535
-        if ($debug) {
536
-            xoops_debug($sql);
537
-        }
538
-
539
-        $result = $this->db->query($sql, $limit, $start);
540
-        if (!$result) {
541
-            return $ret;
542
-        }
543
-
544
-        $myts = MyTextSanitizer::getInstance();
545
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
546
-            //identifiers should be textboxes, so sanitize them like that
547
-            $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
548
-        }
549
-
550
-        return $ret;
551
-    }
552
-
553
-    /**
554
-     * count objects matching a condition
555
-     *
556
-     * @param  CriteriaElement $criteria {@link CriteriaElement} to match
557
-     * @return int    count of objects
558
-     */
559
-    public function getCount(CriteriaElement $criteria = null)
560
-    {
561
-        $field   = '';
562
-        $groupby = false;
563
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
564
-            if ($criteria->groupby !== '') {
565
-                $groupby = true;
566
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
567
-            }
568
-        }
569
-        /**
570
-         * if we have a generalSQL, lets used this one.
571
-         * This needs to be improved...
572
-         */
573
-        if ($this->generalSQL) {
574
-            $sql = $this->generalSQL;
575
-            $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
576
-        } else {
577
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
578
-        }
579
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
580
-            $sql .= ' ' . $criteria->renderWhere();
581
-            if ($criteria->groupby !== '') {
582
-                $sql .= $criteria->getGroupby();
583
-            }
584
-        }
585
-
586
-        $result = $this->db->query($sql);
587
-        if (!$result) {
588
-            return 0;
589
-        }
590
-        if ($groupby === false) {
591
-            list($count) = $this->db->fetchRow($result);
592
-
593
-            return $count;
594
-        } else {
595
-            $ret = array();
596
-            while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
597
-                $ret[$id] = $count;
598
-            }
599
-
600
-            return $ret;
601
-        }
602
-    }
603
-
604
-    /**
605
-     * delete an object from the database
606
-     *
607
-     * @param  XoopsObject $obj   reference to the object to delete
608
-     * @param  bool        $force
609
-     * @return bool        FALSE if failed.
610
-     */
611
-    public function delete(XoopsObject $obj, $force = false)
612
-    {
613
-        $eventResult = $this->executeEvent('beforeDelete', $obj);
614
-        if (!$eventResult) {
615
-            $obj->setErrors('An error occured during the BeforeDelete event');
616
-
617
-            return false;
618
-        }
619
-
620
-        if (is_array($this->keyName)) {
621
-            $clause = array();
622
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
623
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
624
-            }
625
-            $whereclause = implode(' AND ', $clause);
626
-        } else {
627
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
628
-        }
629
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
630
-        if (false !== $force) {
631
-            $result = $this->db->queryF($sql);
632
-        } else {
633
-            $result = $this->db->query($sql);
634
-        }
635
-        if (!$result) {
636
-            return false;
637
-        }
638
-
639
-        $eventResult = $this->executeEvent('afterDelete', $obj);
640
-        if (!$eventResult) {
641
-            $obj->setErrors('An error occured during the AfterDelete event');
642
-
643
-            return false;
644
-        }
645
-
646
-        return true;
647
-    }
648
-
649
-    /**
650
-     * @param $event
651
-     */
652
-    public function disableEvent($event)
653
-    {
654
-        if (is_array($event)) {
655
-            foreach ($event as $v) {
656
-                $this->_disabledEvents[] = $v;
657
-            }
658
-        } else {
659
-            $this->_disabledEvents[] = $event;
660
-        }
661
-    }
662
-
663
-    /**
664
-     * @return array
665
-     */
666
-    public function getPermissions()
667
-    {
668
-        return $this->permissionsArray;
669
-    }
670
-
671
-    /**
672
-     * insert a new object in the database
673
-     *
674
-     * @param  XoopsObject $obj         reference to the object
675
-     * @param  bool        $force       whether to force the query execution despite security settings
676
-     * @param  bool        $checkObject check if the object is dirty and clean the attributes
677
-     * @param  bool        $debug
678
-     * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
679
-     */
680
-    public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
681
-    {
682
-        if ($checkObject !== false) {
683
-            if (!is_object($obj)) {
684
-                return false;
685
-            }
686
-            /**
687
-             * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
688
-             */
689
-            if (!is_a($obj, $this->className)) {
690
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
691
-
692
-                return false;
693
-            }
694
-            if (!$obj->isDirty()) {
695
-                $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
696
-
697
-                return true;
698
-            }
699
-        }
700
-
701
-        if ($obj->seoEnabled) {
702
-            // Auto create meta tags if empty
703
-            $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
704
-
705
-            if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
706
-                if (!$obj->meta_keywords()) {
707
-                    $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
708
-                }
709
-
710
-                if (!$obj->meta_description()) {
711
-                    $obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
712
-                }
713
-            }
714
-
715
-            // Auto create short_url if empty
716
-            if (!$obj->short_url()) {
717
-                $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
718
-            }
719
-        }
720
-
721
-        $eventResult = $this->executeEvent('beforeSave', $obj);
722
-        if (!$eventResult) {
723
-            $obj->setErrors('An error occured during the BeforeSave event');
724
-
725
-            return false;
726
-        }
727
-
728
-        if ($obj->isNew()) {
729
-            $eventResult = $this->executeEvent('beforeInsert', $obj);
730
-            if (!$eventResult) {
731
-                $obj->setErrors('An error occured during the BeforeInsert event');
732
-
733
-                return false;
734
-            }
735
-        } else {
736
-            $eventResult = $this->executeEvent('beforeUpdate', $obj);
737
-            if (!$eventResult) {
738
-                $obj->setErrors('An error occured during the BeforeUpdate event');
739
-
740
-                return false;
741
-            }
742
-        }
743
-        if (!$obj->cleanVars()) {
744
-            $obj->setErrors('Variables were not cleaned properly.');
745
-
746
-            return false;
747
-        }
748
-        $fieldsToStoreInDB = array();
749
-        foreach ($obj->cleanVars as $k => $v) {
750
-            if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
751
-                $cleanvars[$k] = (int)$v;
752
-            } elseif (is_array($v)) {
753
-                $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
754
-            } else {
755
-                $cleanvars[$k] = $this->db->quoteString($v);
756
-            }
757
-            if ($obj->vars[$k]['persistent']) {
758
-                $fieldsToStoreInDB[$k] = $cleanvars[$k];
759
-            }
760
-        }
761
-        if ($obj->isNew()) {
762
-            if (!is_array($this->keyName)) {
763
-                if ($cleanvars[$this->keyName] < 1) {
764
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
765
-                }
766
-            }
767
-
768
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
769
-        } else {
770
-            $sql = 'UPDATE ' . $this->table . ' SET';
771
-            foreach ($fieldsToStoreInDB as $key => $value) {
772
-                if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
773
-                    continue;
774
-                }
775
-                if (isset($notfirst)) {
776
-                    $sql .= ',';
777
-                }
778
-                $sql .= ' ' . $key . ' = ' . $value;
779
-                $notfirst = true;
780
-            }
781
-            if (is_array($this->keyName)) {
782
-                $whereclause = '';
783
-                for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
784
-                    if ($i > 0) {
785
-                        $whereclause .= ' AND ';
786
-                    }
787
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
788
-                }
789
-            } else {
790
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
791
-            }
792
-            $sql .= ' WHERE ' . $whereclause;
793
-        }
794
-
795
-        if ($debug) {
796
-            xoops_debug($sql);
797
-        }
798
-
799
-        if (false != $force) {
800
-            $result = $this->db->queryF($sql);
801
-        } else {
802
-            $result = $this->db->query($sql);
803
-        }
804
-
805
-        if (!$result) {
806
-            $obj->setErrors($this->db->error());
807
-
808
-            return false;
809
-        }
810
-
811
-        if ($obj->isNew() && !is_array($this->keyName)) {
812
-            $obj->assignVar($this->keyName, $this->db->getInsertId());
813
-        }
814
-        $eventResult = $this->executeEvent('afterSave', $obj);
815
-        if (!$eventResult) {
816
-            $obj->setErrors('An error occured during the AfterSave event');
817
-
818
-            return false;
819
-        }
820
-
821
-        if ($obj->isNew()) {
822
-            $obj->unsetNew();
823
-            $eventResult = $this->executeEvent('afterInsert', $obj);
824
-            if (!$eventResult) {
825
-                $obj->setErrors('An error occured during the AfterInsert event');
826
-
827
-                return false;
828
-            }
829
-        } else {
830
-            $eventResult = $this->executeEvent('afterUpdate', $obj);
831
-            if (!$eventResult) {
832
-                $obj->setErrors('An error occured during the AfterUpdate event');
833
-
834
-                return false;
835
-            }
836
-        }
837
-
838
-        return true;
839
-    }
840
-
841
-    /**
842
-     * @param       $obj
843
-     * @param  bool $force
844
-     * @param  bool $checkObject
845
-     * @param  bool $debug
846
-     * @return bool
847
-     */
848
-    public function insertD($obj, $force = false, $checkObject = true, $debug = false)
849
-    {
850
-        return $this->insert($obj, $force, $checkObject, true);
851
-    }
852
-
853
-    /**
854
-     * Change a value for objects with a certain criteria
855
-     *
856
-     * @param string $fieldname  Name of the field
857
-     * @param string $fieldvalue Value to write
858
-     * @param CriteriaElement $criteria   {@link CriteriaElement}
859
-     *
860
-     * @param  bool $force
861
-     * @return bool
862
-     */
863
-    public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
864
-    {
865
-        $set_clause = $fieldname . ' = ';
866
-        if (is_numeric($fieldvalue)) {
867
-            $set_clause .= $fieldvalue;
868
-        } elseif (is_array($fieldvalue)) {
869
-            $set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
870
-        } else {
871
-            $set_clause .= $this->db->quoteString($fieldvalue);
872
-        }
873
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
874
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
875
-            $sql .= ' ' . $criteria->renderWhere();
876
-        }
877
-        if (false != $force) {
878
-            $result = $this->db->queryF($sql);
879
-        } else {
880
-            $result = $this->db->query($sql);
881
-        }
882
-        if (!$result) {
883
-            return false;
884
-        }
885
-
886
-        return true;
887
-    }
888
-
889
-    /**
890
-     * delete all objects meeting the conditions
891
-     *
892
-     * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
893
-     * @return bool
894
-     */
895
-
896
-    public function deleteAll(CriteriaElement $criteria = null)
897
-    {
898
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
899
-            $sql = 'DELETE FROM ' . $this->table;
900
-            $sql .= ' ' . $criteria->renderWhere();
901
-            if (!$this->db->query($sql)) {
902
-                return false;
903
-            }
904
-            $rows = $this->db->getAffectedRows();
905
-
906
-            return $rows > 0 ? $rows : true;
907
-        }
908
-
909
-        return false;
910
-    }
911
-
912
-    /**
913
-     * @return mixed
914
-     */
915
-    public function getModuleInfo()
916
-    {
917
-        return smart_getModuleInfo($this->_moduleName);
918
-    }
919
-
920
-    /**
921
-     * @return bool
922
-     */
923
-    public function getModuleConfig()
924
-    {
925
-        return smart_getModuleConfig($this->_moduleName);
926
-    }
927
-
928
-    /**
929
-     * @return string
930
-     */
931
-    public function getModuleItemString()
932
-    {
933
-        $ret = $this->_moduleName . '_' . $this->_itemname;
934
-
935
-        return $ret;
936
-    }
937
-
938
-    /**
939
-     * @param $object
940
-     */
941
-    public function updateCounter($object)
942
-    {
943
-        if (isset($object->vars['counter'])) {
944
-            $new_counter = $object->getVar('counter') + 1;
945
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
946
-            $this->query($sql, null, true);
947
-        }
948
-    }
949
-
950
-    /**
951
-     * Execute the function associated with an event
952
-     * This method will check if the function is available
953
-     *
954
-     * @param  string $event           name of the event
955
-     * @param         $executeEventObj
956
-     * @return mixed  result of the execution of the function or FALSE if the function was not executed
957
-     * @internal param object $obj $object on which is performed the event
958
-     */
959
-    public function executeEvent($event, &$executeEventObj)
960
-    {
961
-        if (!in_array($event, $this->_disabledEvents)) {
962
-            if (method_exists($this, $event)) {
963
-                $ret = $this->$event($executeEventObj);
964
-            } else {
965
-                // check to see if there is a hook for this event
966
-                if (isset($this->_eventHooks[$event])) {
967
-                    $method = $this->_eventHooks[$event];
968
-                    // check to see if the method specified by this hook exists
969
-                    if (method_exists($this, $method)) {
970
-                        $ret = $this->$method($executeEventObj);
971
-                    }
972
-                }
973
-                $ret = true;
974
-            }
975
-
976
-            return $ret;
977
-        }
978
-
979
-        return true;
980
-    }
981
-
982
-    /**
983
-     * @param  bool   $withprefix
984
-     * @return string
985
-     */
986
-    public function getIdentifierName($withprefix = true)
987
-    {
988
-        if ($withprefix) {
989
-            return $this->_itemname . '.' . $this->identifierName;
990
-        } else {
991
-            return $this->identifierName;
992
-        }
993
-    }
28
+	public $_itemname;
29
+
30
+	/**
31
+	 * Name of the table use to store this {@link SmartObject}
32
+	 *
33
+	 * Note that the name of the table needs to be free of the database prefix.
34
+	 * For example "smartsection_categories"
35
+	 * @var string
36
+	 */
37
+	public $table;
38
+
39
+	/**
40
+	 * Name of the table key that uniquely identify each {@link SmartObject}
41
+	 *
42
+	 * For example: "categoryid"
43
+	 * @var string
44
+	 */
45
+	public $keyName;
46
+
47
+	/**
48
+	 * Name of the class derived from {@link SmartObject} and which this handler is handling
49
+	 *
50
+	 * Note that this string needs to be lowercase
51
+	 *
52
+	 * For example: "smartsectioncategory"
53
+	 * @var string
54
+	 */
55
+	public $className;
56
+
57
+	/**
58
+	 * Name of the field which properly identify the {@link SmartObject}
59
+	 *
60
+	 * For example: "name" (this will be the category's name)
61
+	 * @var string
62
+	 */
63
+	public $identifierName;
64
+
65
+	/**
66
+	 * Name of the field which will be use as a summary for the object
67
+	 *
68
+	 * For example: "summary"
69
+	 * @var string
70
+	 */
71
+	public $summaryName;
72
+
73
+	/**
74
+	 * Page name use to basically manage and display the {@link SmartObject}
75
+	 *
76
+	 * This page needs to be the same in user side and admin side
77
+	 *
78
+	 * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
79
+	 * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
80
+	 * @var string
81
+	 */
82
+	public $_page;
83
+
84
+	/**
85
+	 * Full path of the module using this {@link SmartObject}
86
+	 *
87
+	 * <code>XOOPS_URL . "/modules/smartsection/"</code>
88
+	 * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
89
+	 * @var string
90
+	 */
91
+	public $_modulePath;
92
+
93
+	public $_moduleUrl;
94
+
95
+	public $_moduleName;
96
+
97
+	public $_uploadUrl;
98
+
99
+	public $_uploadPath;
100
+
101
+	public $_allowedMimeTypes = 0;
102
+
103
+	public $_maxFileSize = 1000000;
104
+
105
+	public $_maxWidth = 500;
106
+
107
+	public $_maxHeight = 500;
108
+
109
+	public $highlightFields = array();
110
+
111
+	/**
112
+	 * Array containing the events name and functions
113
+	 *
114
+	 * @var array
115
+	 */
116
+	public $eventArray = array();
117
+
118
+	/**
119
+	 * Array containing the permissions that this handler will manage on the objects
120
+	 *
121
+	 * @var array
122
+	 */
123
+	public $permissionsArray = false;
124
+
125
+	public $generalSQL = false;
126
+
127
+	public $_eventHooks     = array();
128
+	public $_disabledEvents = array();
129
+
130
+	/**
131
+	 * Constructor - called from child classes
132
+	 *
133
+	 * @param XoopsDatabase $db           {@link XoopsDatabase}
134
+	 *                                           object
135
+	 * @param                      $itemname
136
+	 * @param string               $keyname      Name of the table key that uniquely identify each {@link SmartObject}
137
+	 * @param string               $idenfierName Name of the field which properly identify the {@link SmartObject}
138
+	 * @param                      $summaryName
139
+	 * @param                      $modulename
140
+	 * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
141
+	 * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
142
+	 * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
143
+	 * @internal param string $moduleName name of the module
144
+	 */
145
+	public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
146
+	{
147
+		parent::__construct($db);
148
+
149
+		$this->_itemname      = $itemname;
150
+		$this->_moduleName    = $modulename;
151
+		$this->table          = $db->prefix($modulename . '_' . $itemname);
152
+		$this->keyName        = $keyname;
153
+		$this->className      = ucfirst($modulename) . ucfirst($itemname);
154
+		$this->identifierName = $idenfierName;
155
+		$this->summaryName    = $summaryName;
156
+		$this->_page          = $itemname . '.php';
157
+		$this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
158
+		$this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
159
+		$this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
160
+		$this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
161
+	}
162
+
163
+	/**
164
+	 * @param $event
165
+	 * @param $method
166
+	 */
167
+	public function addEventHook($event, $method)
168
+	{
169
+		$this->_eventHooks[$event] = $method;
170
+	}
171
+
172
+	/**
173
+	 * Add a permission that this handler will manage for its objects
174
+	 *
175
+	 * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
176
+	 *
177
+	 * @param string      $perm_name   name of the permission
178
+	 * @param string      $caption     caption of the control that will be displayed in the form
179
+	 * @param bool|string $description description of the control that will be displayed in the form
180
+	 */
181
+	public function addPermission($perm_name, $caption, $description = false)
182
+	{
183
+		include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
184
+
185
+		$this->permissionsArray[] = array(
186
+			'perm_name'   => $perm_name,
187
+			'caption'     => $caption,
188
+			'description' => $description
189
+		);
190
+	}
191
+
192
+	/**
193
+	 * @param $criteria
194
+	 * @param $perm_name
195
+	 * @return bool
196
+	 */
197
+	public function setGrantedObjectsCriteria(&$criteria, $perm_name)
198
+	{
199
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this);
200
+		$grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
201
+		if (count($grantedItems) > 0) {
202
+			$criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
203
+
204
+			return true;
205
+		} else {
206
+			return false;
207
+		}
208
+	}
209
+
210
+	/**
211
+	 * @param bool $_uploadPath
212
+	 * @param bool $_allowedMimeTypes
213
+	 * @param bool $_maxFileSize
214
+	 * @param bool $_maxWidth
215
+	 * @param bool $_maxHeight
216
+	 */
217
+	public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false)
218
+	{
219
+		$this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
220
+		$this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
221
+		$this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
222
+		$this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
223
+		$this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
224
+	}
225
+
226
+	/**
227
+	 * create a new {@link SmartObject}
228
+	 *
229
+	 * @param bool $isNew Flag the new objects as "new"?
230
+	 *
231
+	 * @return SmartObject {@link SmartObject}
232
+	 */
233
+	public function create($isNew = true)
234
+	{
235
+		$obj = new $this->className($this);
236
+		$obj->setImageDir($this->getImageUrl(), $this->getImagePath());
237
+		if (!$obj->handler) {
238
+			$obj->handler =& $this;
239
+		}
240
+
241
+		if ($isNew === true) {
242
+			$obj->setNew();
243
+		}
244
+
245
+		return $obj;
246
+	}
247
+
248
+	/**
249
+	 * @return string
250
+	 */
251
+	public function getImageUrl()
252
+	{
253
+		return $this->_uploadUrl . $this->_itemname . '/';
254
+	}
255
+
256
+	/**
257
+	 * @return string
258
+	 */
259
+	public function getImagePath()
260
+	{
261
+		$dir = $this->_uploadPath . $this->_itemname;
262
+		if (!file_exists($dir)) {
263
+			smart_admin_mkdir($dir);
264
+		}
265
+
266
+		return $dir . '/';
267
+	}
268
+
269
+	/**
270
+	 * retrieve a {@link SmartObject}
271
+	 *
272
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
273
+	 * @param  bool  $as_object whether to return an object or an array
274
+	 * @param  bool  $debug
275
+	 * @param  bool  $criteria
276
+	 * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
277
+	 *                         FALSE if failed
278
+	 */
279
+	public function get($id, $as_object = true, $debug = false, $criteria = false)
280
+	{
281
+		if (!$criteria) {
282
+			$criteria = new CriteriaCompo();
283
+		}
284
+		if (is_array($this->keyName)) {
285
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
286
+				/**
287
+				 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
288
+				 * Is the fact that we removed the (int)() represents a security risk ?
289
+				 */
290
+				//$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
291
+				$criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
292
+			}
293
+		} else {
294
+			//$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname);
295
+			/**
296
+			 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
297
+			 * Is the fact that we removed the (int)() represents a security risk ?
298
+			 */
299
+			$criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
300
+		}
301
+		$criteria->setLimit(1);
302
+		if ($debug) {
303
+			$obj_array = $this->getObjectsD($criteria, false, $as_object);
304
+		} else {
305
+			$obj_array = $this->getObjects($criteria, false, $as_object);
306
+			//patch: weird bug of indexing by id even if id_as_key = false;
307
+			if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
308
+				$obj_array[0] = $obj_array[$id];
309
+				unset($obj_array[$id]);
310
+				$obj_array[0]->unsetNew();
311
+			}
312
+		}
313
+
314
+		if (count($obj_array) != 1) {
315
+			$obj = $this->create();
316
+
317
+			return $obj;
318
+		}
319
+
320
+		return $obj_array[0];
321
+	}
322
+
323
+	/**
324
+	 * retrieve a {@link SmartObject}
325
+	 *
326
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
327
+	 * @param  bool  $as_object whether to return an object or an array
328
+	 * @return mixed reference to the {@link SmartObject}, FALSE if failed
329
+	 */
330
+	public function &getD($id, $as_object = true)
331
+	{
332
+		return $this->get($id, $as_object, true);
333
+	}
334
+
335
+	/**
336
+	 * retrieve objects from the database
337
+	 *
338
+	 * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
339
+	 * @param bool   $id_as_key use the ID as key for the array?
340
+	 * @param bool   $as_object return an array of objects?
341
+	 *
342
+	 * @param  bool  $sql
343
+	 * @param  bool  $debug
344
+	 * @return array
345
+	 */
346
+	public function getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false)
347
+	{
348
+		$ret   = array();
349
+		$limit = $start = 0;
350
+
351
+		if ($this->generalSQL) {
352
+			$sql = $this->generalSQL;
353
+		} elseif (!$sql) {
354
+			$sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
355
+		}
356
+
357
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
358
+			$sql .= ' ' . $criteria->renderWhere();
359
+			if ($criteria->getSort() !== '') {
360
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
361
+			}
362
+			$limit = $criteria->getLimit();
363
+			$start = $criteria->getStart();
364
+		}
365
+		if ($debug) {
366
+			xoops_debug($sql);
367
+		}
368
+
369
+		$result = $this->db->query($sql, $limit, $start);
370
+		if (!$result) {
371
+			return $ret;
372
+		}
373
+
374
+		return $this->convertResultSet($result, $id_as_key, $as_object);
375
+	}
376
+
377
+	/**
378
+	 * @param        $sql
379
+	 * @param        $criteria
380
+	 * @param  bool  $force
381
+	 * @param  bool  $debug
382
+	 * @return array
383
+	 */
384
+	public function query($sql, $criteria, $force = false, $debug = false)
385
+	{
386
+		$ret = array();
387
+
388
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
389
+			$sql .= ' ' . $criteria->renderWhere();
390
+			if ($criteria->groupby) {
391
+				$sql .= $criteria->getGroupby();
392
+			}
393
+			if ($criteria->getSort() !== '') {
394
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
395
+			}
396
+		}
397
+		if ($debug) {
398
+			xoops_debug($sql);
399
+		}
400
+
401
+		if ($force) {
402
+			$result = $this->db->queryF($sql);
403
+		} else {
404
+			$result = $this->db->query($sql);
405
+		}
406
+
407
+		if (!$result) {
408
+			return $ret;
409
+		}
410
+
411
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
412
+			$ret[] = $myrow;
413
+		}
414
+
415
+		return $ret;
416
+	}
417
+
418
+	/**
419
+	 * retrieve objects with debug mode - so will show the query
420
+	 *
421
+	 * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
422
+	 * @param bool   $id_as_key use the ID as key for the array?
423
+	 * @param bool   $as_object return an array of objects?
424
+	 *
425
+	 * @param  bool  $sql
426
+	 * @return array
427
+	 */
428
+	public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
429
+	{
430
+		return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
431
+	}
432
+
433
+	/**
434
+	 * @param $arrayObjects
435
+	 * @return array|bool
436
+	 */
437
+	public function getObjectsAsArray($arrayObjects)
438
+	{
439
+		$ret = array();
440
+		foreach ($arrayObjects as $key => $object) {
441
+			$ret[$key] = $object->toArray();
442
+		}
443
+		if (count($ret > 0)) {
444
+			return $ret;
445
+		} else {
446
+			return false;
447
+		}
448
+	}
449
+
450
+	/**
451
+	 * Convert a database resultset to a returnable array
452
+	 *
453
+	 * @param object $result    database resultset
454
+	 * @param bool   $id_as_key - should NOT be used with joint keys
455
+	 * @param bool   $as_object
456
+	 *
457
+	 * @return array
458
+	 */
459
+	public function convertResultSet($result, $id_as_key = false, $as_object = true)
460
+	{
461
+		$ret = array();
462
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
463
+			$obj = $this->create(false);
464
+			$obj->assignVars($myrow);
465
+			if (!$id_as_key) {
466
+				if ($as_object) {
467
+					$ret[] =& $obj;
468
+				} else {
469
+					$ret[] = $obj->toArray();
470
+				}
471
+			} else {
472
+				if ($as_object) {
473
+					$value =& $obj;
474
+				} else {
475
+					$value = $obj->toArray();
476
+				}
477
+				if ($id_as_key === 'parentid') {
478
+					$ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
479
+				} else {
480
+					$ret[$obj->getVar($this->keyName)] = $value;
481
+				}
482
+			}
483
+			unset($obj);
484
+		}
485
+
486
+		return $ret;
487
+	}
488
+
489
+	/**
490
+	 * @param  null  $criteria
491
+	 * @param  int   $limit
492
+	 * @param  int   $start
493
+	 * @return array
494
+	 */
495
+	public function getListD($criteria = null, $limit = 0, $start = 0)
496
+	{
497
+		return $this->getList($criteria, $limit, $start, true);
498
+	}
499
+
500
+	/**
501
+	 * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
502
+	 *
503
+	 * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
504
+	 * @param int    $limit    Max number of objects to fetch
505
+	 * @param int    $start    Which record to start at
506
+	 *
507
+	 * @param  bool  $debug
508
+	 * @return array
509
+	 */
510
+	public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
511
+	{
512
+		$ret = array();
513
+		if ($criteria === null) {
514
+			$criteria = new CriteriaCompo();
515
+		}
516
+
517
+		if ($criteria->getSort() === '') {
518
+			$criteria->setSort($this->getIdentifierName());
519
+		}
520
+
521
+		$sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
522
+		if (!empty($this->identifierName)) {
523
+			$sql .= ', ' . $this->getIdentifierName();
524
+		}
525
+		$sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
526
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
527
+			$sql .= ' ' . $criteria->renderWhere();
528
+			if ($criteria->getSort() !== '') {
529
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
530
+			}
531
+			$limit = $criteria->getLimit();
532
+			$start = $criteria->getStart();
533
+		}
534
+
535
+		if ($debug) {
536
+			xoops_debug($sql);
537
+		}
538
+
539
+		$result = $this->db->query($sql, $limit, $start);
540
+		if (!$result) {
541
+			return $ret;
542
+		}
543
+
544
+		$myts = MyTextSanitizer::getInstance();
545
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
546
+			//identifiers should be textboxes, so sanitize them like that
547
+			$ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
548
+		}
549
+
550
+		return $ret;
551
+	}
552
+
553
+	/**
554
+	 * count objects matching a condition
555
+	 *
556
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} to match
557
+	 * @return int    count of objects
558
+	 */
559
+	public function getCount(CriteriaElement $criteria = null)
560
+	{
561
+		$field   = '';
562
+		$groupby = false;
563
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
564
+			if ($criteria->groupby !== '') {
565
+				$groupby = true;
566
+				$field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
567
+			}
568
+		}
569
+		/**
570
+		 * if we have a generalSQL, lets used this one.
571
+		 * This needs to be improved...
572
+		 */
573
+		if ($this->generalSQL) {
574
+			$sql = $this->generalSQL;
575
+			$sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
576
+		} else {
577
+			$sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
578
+		}
579
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
580
+			$sql .= ' ' . $criteria->renderWhere();
581
+			if ($criteria->groupby !== '') {
582
+				$sql .= $criteria->getGroupby();
583
+			}
584
+		}
585
+
586
+		$result = $this->db->query($sql);
587
+		if (!$result) {
588
+			return 0;
589
+		}
590
+		if ($groupby === false) {
591
+			list($count) = $this->db->fetchRow($result);
592
+
593
+			return $count;
594
+		} else {
595
+			$ret = array();
596
+			while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
597
+				$ret[$id] = $count;
598
+			}
599
+
600
+			return $ret;
601
+		}
602
+	}
603
+
604
+	/**
605
+	 * delete an object from the database
606
+	 *
607
+	 * @param  XoopsObject $obj   reference to the object to delete
608
+	 * @param  bool        $force
609
+	 * @return bool        FALSE if failed.
610
+	 */
611
+	public function delete(XoopsObject $obj, $force = false)
612
+	{
613
+		$eventResult = $this->executeEvent('beforeDelete', $obj);
614
+		if (!$eventResult) {
615
+			$obj->setErrors('An error occured during the BeforeDelete event');
616
+
617
+			return false;
618
+		}
619
+
620
+		if (is_array($this->keyName)) {
621
+			$clause = array();
622
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
623
+				$clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
624
+			}
625
+			$whereclause = implode(' AND ', $clause);
626
+		} else {
627
+			$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
628
+		}
629
+		$sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
630
+		if (false !== $force) {
631
+			$result = $this->db->queryF($sql);
632
+		} else {
633
+			$result = $this->db->query($sql);
634
+		}
635
+		if (!$result) {
636
+			return false;
637
+		}
638
+
639
+		$eventResult = $this->executeEvent('afterDelete', $obj);
640
+		if (!$eventResult) {
641
+			$obj->setErrors('An error occured during the AfterDelete event');
642
+
643
+			return false;
644
+		}
645
+
646
+		return true;
647
+	}
648
+
649
+	/**
650
+	 * @param $event
651
+	 */
652
+	public function disableEvent($event)
653
+	{
654
+		if (is_array($event)) {
655
+			foreach ($event as $v) {
656
+				$this->_disabledEvents[] = $v;
657
+			}
658
+		} else {
659
+			$this->_disabledEvents[] = $event;
660
+		}
661
+	}
662
+
663
+	/**
664
+	 * @return array
665
+	 */
666
+	public function getPermissions()
667
+	{
668
+		return $this->permissionsArray;
669
+	}
670
+
671
+	/**
672
+	 * insert a new object in the database
673
+	 *
674
+	 * @param  XoopsObject $obj         reference to the object
675
+	 * @param  bool        $force       whether to force the query execution despite security settings
676
+	 * @param  bool        $checkObject check if the object is dirty and clean the attributes
677
+	 * @param  bool        $debug
678
+	 * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
679
+	 */
680
+	public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
681
+	{
682
+		if ($checkObject !== false) {
683
+			if (!is_object($obj)) {
684
+				return false;
685
+			}
686
+			/**
687
+			 * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
688
+			 */
689
+			if (!is_a($obj, $this->className)) {
690
+				$obj->setError(get_class($obj) . ' Differs from ' . $this->className);
691
+
692
+				return false;
693
+			}
694
+			if (!$obj->isDirty()) {
695
+				$obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
696
+
697
+				return true;
698
+			}
699
+		}
700
+
701
+		if ($obj->seoEnabled) {
702
+			// Auto create meta tags if empty
703
+			$smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
704
+
705
+			if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
706
+				if (!$obj->meta_keywords()) {
707
+					$obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
708
+				}
709
+
710
+				if (!$obj->meta_description()) {
711
+					$obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
712
+				}
713
+			}
714
+
715
+			// Auto create short_url if empty
716
+			if (!$obj->short_url()) {
717
+				$obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
718
+			}
719
+		}
720
+
721
+		$eventResult = $this->executeEvent('beforeSave', $obj);
722
+		if (!$eventResult) {
723
+			$obj->setErrors('An error occured during the BeforeSave event');
724
+
725
+			return false;
726
+		}
727
+
728
+		if ($obj->isNew()) {
729
+			$eventResult = $this->executeEvent('beforeInsert', $obj);
730
+			if (!$eventResult) {
731
+				$obj->setErrors('An error occured during the BeforeInsert event');
732
+
733
+				return false;
734
+			}
735
+		} else {
736
+			$eventResult = $this->executeEvent('beforeUpdate', $obj);
737
+			if (!$eventResult) {
738
+				$obj->setErrors('An error occured during the BeforeUpdate event');
739
+
740
+				return false;
741
+			}
742
+		}
743
+		if (!$obj->cleanVars()) {
744
+			$obj->setErrors('Variables were not cleaned properly.');
745
+
746
+			return false;
747
+		}
748
+		$fieldsToStoreInDB = array();
749
+		foreach ($obj->cleanVars as $k => $v) {
750
+			if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
751
+				$cleanvars[$k] = (int)$v;
752
+			} elseif (is_array($v)) {
753
+				$cleanvars[$k] = $this->db->quoteString(implode(',', $v));
754
+			} else {
755
+				$cleanvars[$k] = $this->db->quoteString($v);
756
+			}
757
+			if ($obj->vars[$k]['persistent']) {
758
+				$fieldsToStoreInDB[$k] = $cleanvars[$k];
759
+			}
760
+		}
761
+		if ($obj->isNew()) {
762
+			if (!is_array($this->keyName)) {
763
+				if ($cleanvars[$this->keyName] < 1) {
764
+					$cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
765
+				}
766
+			}
767
+
768
+			$sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
769
+		} else {
770
+			$sql = 'UPDATE ' . $this->table . ' SET';
771
+			foreach ($fieldsToStoreInDB as $key => $value) {
772
+				if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
773
+					continue;
774
+				}
775
+				if (isset($notfirst)) {
776
+					$sql .= ',';
777
+				}
778
+				$sql .= ' ' . $key . ' = ' . $value;
779
+				$notfirst = true;
780
+			}
781
+			if (is_array($this->keyName)) {
782
+				$whereclause = '';
783
+				for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
784
+					if ($i > 0) {
785
+						$whereclause .= ' AND ';
786
+					}
787
+					$whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
788
+				}
789
+			} else {
790
+				$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
791
+			}
792
+			$sql .= ' WHERE ' . $whereclause;
793
+		}
794
+
795
+		if ($debug) {
796
+			xoops_debug($sql);
797
+		}
798
+
799
+		if (false != $force) {
800
+			$result = $this->db->queryF($sql);
801
+		} else {
802
+			$result = $this->db->query($sql);
803
+		}
804
+
805
+		if (!$result) {
806
+			$obj->setErrors($this->db->error());
807
+
808
+			return false;
809
+		}
810
+
811
+		if ($obj->isNew() && !is_array($this->keyName)) {
812
+			$obj->assignVar($this->keyName, $this->db->getInsertId());
813
+		}
814
+		$eventResult = $this->executeEvent('afterSave', $obj);
815
+		if (!$eventResult) {
816
+			$obj->setErrors('An error occured during the AfterSave event');
817
+
818
+			return false;
819
+		}
820
+
821
+		if ($obj->isNew()) {
822
+			$obj->unsetNew();
823
+			$eventResult = $this->executeEvent('afterInsert', $obj);
824
+			if (!$eventResult) {
825
+				$obj->setErrors('An error occured during the AfterInsert event');
826
+
827
+				return false;
828
+			}
829
+		} else {
830
+			$eventResult = $this->executeEvent('afterUpdate', $obj);
831
+			if (!$eventResult) {
832
+				$obj->setErrors('An error occured during the AfterUpdate event');
833
+
834
+				return false;
835
+			}
836
+		}
837
+
838
+		return true;
839
+	}
840
+
841
+	/**
842
+	 * @param       $obj
843
+	 * @param  bool $force
844
+	 * @param  bool $checkObject
845
+	 * @param  bool $debug
846
+	 * @return bool
847
+	 */
848
+	public function insertD($obj, $force = false, $checkObject = true, $debug = false)
849
+	{
850
+		return $this->insert($obj, $force, $checkObject, true);
851
+	}
852
+
853
+	/**
854
+	 * Change a value for objects with a certain criteria
855
+	 *
856
+	 * @param string $fieldname  Name of the field
857
+	 * @param string $fieldvalue Value to write
858
+	 * @param CriteriaElement $criteria   {@link CriteriaElement}
859
+	 *
860
+	 * @param  bool $force
861
+	 * @return bool
862
+	 */
863
+	public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
864
+	{
865
+		$set_clause = $fieldname . ' = ';
866
+		if (is_numeric($fieldvalue)) {
867
+			$set_clause .= $fieldvalue;
868
+		} elseif (is_array($fieldvalue)) {
869
+			$set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
870
+		} else {
871
+			$set_clause .= $this->db->quoteString($fieldvalue);
872
+		}
873
+		$sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
874
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
875
+			$sql .= ' ' . $criteria->renderWhere();
876
+		}
877
+		if (false != $force) {
878
+			$result = $this->db->queryF($sql);
879
+		} else {
880
+			$result = $this->db->query($sql);
881
+		}
882
+		if (!$result) {
883
+			return false;
884
+		}
885
+
886
+		return true;
887
+	}
888
+
889
+	/**
890
+	 * delete all objects meeting the conditions
891
+	 *
892
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
893
+	 * @return bool
894
+	 */
895
+
896
+	public function deleteAll(CriteriaElement $criteria = null)
897
+	{
898
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
899
+			$sql = 'DELETE FROM ' . $this->table;
900
+			$sql .= ' ' . $criteria->renderWhere();
901
+			if (!$this->db->query($sql)) {
902
+				return false;
903
+			}
904
+			$rows = $this->db->getAffectedRows();
905
+
906
+			return $rows > 0 ? $rows : true;
907
+		}
908
+
909
+		return false;
910
+	}
911
+
912
+	/**
913
+	 * @return mixed
914
+	 */
915
+	public function getModuleInfo()
916
+	{
917
+		return smart_getModuleInfo($this->_moduleName);
918
+	}
919
+
920
+	/**
921
+	 * @return bool
922
+	 */
923
+	public function getModuleConfig()
924
+	{
925
+		return smart_getModuleConfig($this->_moduleName);
926
+	}
927
+
928
+	/**
929
+	 * @return string
930
+	 */
931
+	public function getModuleItemString()
932
+	{
933
+		$ret = $this->_moduleName . '_' . $this->_itemname;
934
+
935
+		return $ret;
936
+	}
937
+
938
+	/**
939
+	 * @param $object
940
+	 */
941
+	public function updateCounter($object)
942
+	{
943
+		if (isset($object->vars['counter'])) {
944
+			$new_counter = $object->getVar('counter') + 1;
945
+			$sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
946
+			$this->query($sql, null, true);
947
+		}
948
+	}
949
+
950
+	/**
951
+	 * Execute the function associated with an event
952
+	 * This method will check if the function is available
953
+	 *
954
+	 * @param  string $event           name of the event
955
+	 * @param         $executeEventObj
956
+	 * @return mixed  result of the execution of the function or FALSE if the function was not executed
957
+	 * @internal param object $obj $object on which is performed the event
958
+	 */
959
+	public function executeEvent($event, &$executeEventObj)
960
+	{
961
+		if (!in_array($event, $this->_disabledEvents)) {
962
+			if (method_exists($this, $event)) {
963
+				$ret = $this->$event($executeEventObj);
964
+			} else {
965
+				// check to see if there is a hook for this event
966
+				if (isset($this->_eventHooks[$event])) {
967
+					$method = $this->_eventHooks[$event];
968
+					// check to see if the method specified by this hook exists
969
+					if (method_exists($this, $method)) {
970
+						$ret = $this->$method($executeEventObj);
971
+					}
972
+				}
973
+				$ret = true;
974
+			}
975
+
976
+			return $ret;
977
+		}
978
+
979
+		return true;
980
+	}
981
+
982
+	/**
983
+	 * @param  bool   $withprefix
984
+	 * @return string
985
+	 */
986
+	public function getIdentifierName($withprefix = true)
987
+	{
988
+		if ($withprefix) {
989
+			return $this->_itemname . '.' . $this->identifierName;
990
+		} else {
991
+			return $this->identifierName;
992
+		}
993
+	}
994 994
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -148,16 +148,16 @@  discard block
 block discarded – undo
148 148
 
149 149
         $this->_itemname      = $itemname;
150 150
         $this->_moduleName    = $modulename;
151
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
151
+        $this->table          = $db->prefix($modulename.'_'.$itemname);
152 152
         $this->keyName        = $keyname;
153
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
153
+        $this->className      = ucfirst($modulename).ucfirst($itemname);
154 154
         $this->identifierName = $idenfierName;
155 155
         $this->summaryName    = $summaryName;
156
-        $this->_page          = $itemname . '.php';
157
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
158
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
159
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
160
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
156
+        $this->_page          = $itemname.'.php';
157
+        $this->_modulePath    = XOOPS_ROOT_PATH.'/modules/'.$this->_moduleName.'/';
158
+        $this->_moduleUrl     = XOOPS_URL.'/modules/'.$this->_moduleName.'/';
159
+        $this->_uploadPath    = XOOPS_UPLOAD_PATH.'/'.$this->_moduleName.'/';
160
+        $this->_uploadUrl     = XOOPS_UPLOAD_URL.'/'.$this->_moduleName.'/';
161 161
     }
162 162
 
163 163
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function addPermission($perm_name, $caption, $description = false)
182 182
     {
183
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
183
+        include_once(SMARTOBJECT_ROOT_PATH.'class/smartobjectpermission.php');
184 184
 
185 185
         $this->permissionsArray[] = array(
186 186
             'perm_name'   => $perm_name,
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
200 200
         $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
201 201
         if (count($grantedItems) > 0) {
202
-            $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
202
+            $criteria->add(new Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN'));
203 203
 
204 204
             return true;
205 205
         } else {
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         $obj = new $this->className($this);
236 236
         $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
237 237
         if (!$obj->handler) {
238
-            $obj->handler =& $this;
238
+            $obj->handler = & $this;
239 239
         }
240 240
 
241 241
         if ($isNew === true) {
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      */
251 251
     public function getImageUrl()
252 252
     {
253
-        return $this->_uploadUrl . $this->_itemname . '/';
253
+        return $this->_uploadUrl.$this->_itemname.'/';
254 254
     }
255 255
 
256 256
     /**
@@ -258,12 +258,12 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function getImagePath()
260 260
     {
261
-        $dir = $this->_uploadPath . $this->_itemname;
261
+        $dir = $this->_uploadPath.$this->_itemname;
262 262
         if (!file_exists($dir)) {
263 263
             smart_admin_mkdir($dir);
264 264
         }
265 265
 
266
-        return $dir . '/';
266
+        return $dir.'/';
267 267
     }
268 268
 
269 269
     /**
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
         if ($this->generalSQL) {
352 352
             $sql = $this->generalSQL;
353 353
         } elseif (!$sql) {
354
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
354
+            $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname;
355 355
         }
356 356
 
357 357
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
358
-            $sql .= ' ' . $criteria->renderWhere();
358
+            $sql .= ' '.$criteria->renderWhere();
359 359
             if ($criteria->getSort() !== '') {
360
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
360
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
361 361
             }
362 362
             $limit = $criteria->getLimit();
363 363
             $start = $criteria->getStart();
@@ -386,12 +386,12 @@  discard block
 block discarded – undo
386 386
         $ret = array();
387 387
 
388 388
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
389
-            $sql .= ' ' . $criteria->renderWhere();
389
+            $sql .= ' '.$criteria->renderWhere();
390 390
             if ($criteria->groupby) {
391 391
                 $sql .= $criteria->getGroupby();
392 392
             }
393 393
             if ($criteria->getSort() !== '') {
394
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
394
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
395 395
             }
396 396
         }
397 397
         if ($debug) {
@@ -464,18 +464,18 @@  discard block
 block discarded – undo
464 464
             $obj->assignVars($myrow);
465 465
             if (!$id_as_key) {
466 466
                 if ($as_object) {
467
-                    $ret[] =& $obj;
467
+                    $ret[] = & $obj;
468 468
                 } else {
469 469
                     $ret[] = $obj->toArray();
470 470
                 }
471 471
             } else {
472 472
                 if ($as_object) {
473
-                    $value =& $obj;
473
+                    $value = & $obj;
474 474
                 } else {
475 475
                     $value = $obj->toArray();
476 476
                 }
477 477
                 if ($id_as_key === 'parentid') {
478
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
478
+                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value;
479 479
                 } else {
480 480
                     $ret[$obj->getVar($this->keyName)] = $value;
481 481
                 }
@@ -518,15 +518,15 @@  discard block
 block discarded – undo
518 518
             $criteria->setSort($this->getIdentifierName());
519 519
         }
520 520
 
521
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
521
+        $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
522 522
         if (!empty($this->identifierName)) {
523
-            $sql .= ', ' . $this->getIdentifierName();
523
+            $sql .= ', '.$this->getIdentifierName();
524 524
         }
525
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
525
+        $sql .= ' FROM '.$this->table.' AS '.$this->_itemname;
526 526
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
527
-            $sql .= ' ' . $criteria->renderWhere();
527
+            $sql .= ' '.$criteria->renderWhere();
528 528
             if ($criteria->getSort() !== '') {
529
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
529
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
530 530
             }
531 531
             $limit = $criteria->getLimit();
532 532
             $start = $criteria->getStart();
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
564 564
             if ($criteria->groupby !== '') {
565 565
                 $groupby = true;
566
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
566
+                $field   = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
567 567
             }
568 568
         }
569 569
         /**
@@ -574,10 +574,10 @@  discard block
 block discarded – undo
574 574
             $sql = $this->generalSQL;
575 575
             $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
576 576
         } else {
577
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
577
+            $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname;
578 578
         }
579 579
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
580
-            $sql .= ' ' . $criteria->renderWhere();
580
+            $sql .= ' '.$criteria->renderWhere();
581 581
             if ($criteria->groupby !== '') {
582 582
                 $sql .= $criteria->getGroupby();
583 583
             }
@@ -620,13 +620,13 @@  discard block
 block discarded – undo
620 620
         if (is_array($this->keyName)) {
621 621
             $clause = array();
622 622
             for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
623
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
623
+                $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
624 624
             }
625 625
             $whereclause = implode(' AND ', $clause);
626 626
         } else {
627
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
627
+            $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
628 628
         }
629
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
629
+        $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause;
630 630
         if (false !== $force) {
631 631
             $result = $this->db->queryF($sql);
632 632
         } else {
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
              * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
688 688
              */
689 689
             if (!is_a($obj, $this->className)) {
690
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
690
+                $obj->setError(get_class($obj).' Differs from '.$this->className);
691 691
 
692 692
                 return false;
693 693
             }
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
         $fieldsToStoreInDB = array();
749 749
         foreach ($obj->cleanVars as $k => $v) {
750 750
             if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
751
-                $cleanvars[$k] = (int)$v;
751
+                $cleanvars[$k] = (int) $v;
752 752
             } elseif (is_array($v)) {
753 753
                 $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
754 754
             } else {
@@ -761,13 +761,13 @@  discard block
 block discarded – undo
761 761
         if ($obj->isNew()) {
762 762
             if (!is_array($this->keyName)) {
763 763
                 if ($cleanvars[$this->keyName] < 1) {
764
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
764
+                    $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
765 765
                 }
766 766
             }
767 767
 
768
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
768
+            $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')';
769 769
         } else {
770
-            $sql = 'UPDATE ' . $this->table . ' SET';
770
+            $sql = 'UPDATE '.$this->table.' SET';
771 771
             foreach ($fieldsToStoreInDB as $key => $value) {
772 772
                 if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
773 773
                     continue;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
                 if (isset($notfirst)) {
776 776
                     $sql .= ',';
777 777
                 }
778
-                $sql .= ' ' . $key . ' = ' . $value;
778
+                $sql .= ' '.$key.' = '.$value;
779 779
                 $notfirst = true;
780 780
             }
781 781
             if (is_array($this->keyName)) {
@@ -784,12 +784,12 @@  discard block
 block discarded – undo
784 784
                     if ($i > 0) {
785 785
                         $whereclause .= ' AND ';
786 786
                     }
787
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
787
+                    $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
788 788
                 }
789 789
             } else {
790
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
790
+                $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
791 791
             }
792
-            $sql .= ' WHERE ' . $whereclause;
792
+            $sql .= ' WHERE '.$whereclause;
793 793
         }
794 794
 
795 795
         if ($debug) {
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
      */
863 863
     public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
864 864
     {
865
-        $set_clause = $fieldname . ' = ';
865
+        $set_clause = $fieldname.' = ';
866 866
         if (is_numeric($fieldvalue)) {
867 867
             $set_clause .= $fieldvalue;
868 868
         } elseif (is_array($fieldvalue)) {
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
         } else {
871 871
             $set_clause .= $this->db->quoteString($fieldvalue);
872 872
         }
873
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
873
+        $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
874 874
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
875
-            $sql .= ' ' . $criteria->renderWhere();
875
+            $sql .= ' '.$criteria->renderWhere();
876 876
         }
877 877
         if (false != $force) {
878 878
             $result = $this->db->queryF($sql);
@@ -896,8 +896,8 @@  discard block
 block discarded – undo
896 896
     public function deleteAll(CriteriaElement $criteria = null)
897 897
     {
898 898
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
899
-            $sql = 'DELETE FROM ' . $this->table;
900
-            $sql .= ' ' . $criteria->renderWhere();
899
+            $sql = 'DELETE FROM '.$this->table;
900
+            $sql .= ' '.$criteria->renderWhere();
901 901
             if (!$this->db->query($sql)) {
902 902
                 return false;
903 903
             }
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
      */
931 931
     public function getModuleItemString()
932 932
     {
933
-        $ret = $this->_moduleName . '_' . $this->_itemname;
933
+        $ret = $this->_moduleName.'_'.$this->_itemname;
934 934
 
935 935
         return $ret;
936 936
     }
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
     {
943 943
         if (isset($object->vars['counter'])) {
944 944
             $new_counter = $object->getVar('counter') + 1;
945
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
945
+            $sql         = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id();
946 946
             $this->query($sql, null, true);
947 947
         }
948 948
     }
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
     public function getIdentifierName($withprefix = true)
987 987
     {
988 988
         if ($withprefix) {
989
-            return $this->_itemname . '.' . $this->identifierName;
989
+            return $this->_itemname.'.'.$this->identifierName;
990 990
         } else {
991 991
             return $this->identifierName;
992 992
         }
Please login to merge, or discard this patch.
class/smartobjectpermission.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
      */
33 33
     /**
34 34
      * @param        $gperm_name
35
-     * @param  null  $id
35
+     * @param  integer  $id
36 36
      * @return array
37 37
      */
38 38
     public function getGrantedGroups($gperm_name, $id = null)
Please login to merge, or discard this patch.
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@  discard block
 block discarded – undo
11 11
 
12 12
 class SmartobjectPermissionHandler extends XoopsObjectHandler
13 13
 {
14
-    public $handler;
15
-
16
-    /**
17
-     * SmartobjectPermissionHandler constructor.
18
-     * @param XoopsDatabase $handler
19
-     */
20
-    public function __construct($handler)
21
-    {
22
-        $this->handler = $handler;
23
-    }
24
-
25
-    /*
14
+	public $handler;
15
+
16
+	/**
17
+	 * SmartobjectPermissionHandler constructor.
18
+	 * @param XoopsDatabase $handler
19
+	 */
20
+	public function __construct($handler)
21
+	{
22
+		$this->handler = $handler;
23
+	}
24
+
25
+	/*
26 26
      * Returns permissions for a certain type
27 27
      *
28 28
      * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know)
@@ -30,73 +30,73 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @return array
32 32
      */
33
-    /**
34
-     * @param        $gperm_name
35
-     * @param  null  $id
36
-     * @return array
37
-     */
38
-    public function getGrantedGroups($gperm_name, $id = null)
39
-    {
40
-        static $groups;
41
-
42
-        if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) {
43
-            $smartModule = $this->handler->getModuleInfo();
44
-            //Get group permissions handler
45
-            $gpermHandler = xoops_getHandler('groupperm');
46
-
47
-            //Get groups allowed for an item id
48
-            $allowedgroups            = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid'));
49
-            $groups[$gperm_name][$id] = $allowedgroups;
50
-        }
51
-        //Return the permission array
52
-        return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array();
53
-    }
54
-
55
-    /**
56
-     * @param        $item_ids_array
57
-     * @param  bool  $gperm_name
58
-     * @return array
59
-     */
60
-    public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false)
61
-    {
62
-        static $groups;
63
-
64
-        if ($gperm_name) {
65
-            if (isset($groups[$gperm_name])) {
66
-                return $groups[$gperm_name];
67
-            }
68
-        } else {
69
-            // if !$gperm_name then we will fetch all permissions in the module so we don't need them again
70
-            return $groups;
71
-        }
72
-
73
-        $smartModule = $this->handler->getModuleInfo();
74
-
75
-        $criteria = new CriteriaCompo();
76
-        $criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid')));
77
-
78
-        if ($gperm_name) {
79
-            $criteria->add(new Criteria('gperm_name', $gperm_name));
80
-        }
81
-
82
-        //Get group permissions handler
83
-        $gpermHandler = xoops_getHandler('groupperm');
84
-
85
-        $permissionsObj = $gpermHandler->getObjects($criteria);
86
-
87
-        foreach ($permissionsObj as $permissionObj) {
88
-            $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid');
89
-        }
90
-
91
-        //Return the permission array
92
-        if ($gperm_name) {
93
-            return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array();
94
-        } else {
95
-            return isset($groups) ? $groups : array();
96
-        }
97
-    }
98
-
99
-    /*
33
+	/**
34
+	 * @param        $gperm_name
35
+	 * @param  null  $id
36
+	 * @return array
37
+	 */
38
+	public function getGrantedGroups($gperm_name, $id = null)
39
+	{
40
+		static $groups;
41
+
42
+		if (!isset($groups[$gperm_name]) || ($id !== null && !isset($groups[$gperm_name][$id]))) {
43
+			$smartModule = $this->handler->getModuleInfo();
44
+			//Get group permissions handler
45
+			$gpermHandler = xoops_getHandler('groupperm');
46
+
47
+			//Get groups allowed for an item id
48
+			$allowedgroups            = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid'));
49
+			$groups[$gperm_name][$id] = $allowedgroups;
50
+		}
51
+		//Return the permission array
52
+		return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : array();
53
+	}
54
+
55
+	/**
56
+	 * @param        $item_ids_array
57
+	 * @param  bool  $gperm_name
58
+	 * @return array
59
+	 */
60
+	public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false)
61
+	{
62
+		static $groups;
63
+
64
+		if ($gperm_name) {
65
+			if (isset($groups[$gperm_name])) {
66
+				return $groups[$gperm_name];
67
+			}
68
+		} else {
69
+			// if !$gperm_name then we will fetch all permissions in the module so we don't need them again
70
+			return $groups;
71
+		}
72
+
73
+		$smartModule = $this->handler->getModuleInfo();
74
+
75
+		$criteria = new CriteriaCompo();
76
+		$criteria->add(new Criteria('gperm_modid', $smartModule->getVar('mid')));
77
+
78
+		if ($gperm_name) {
79
+			$criteria->add(new Criteria('gperm_name', $gperm_name));
80
+		}
81
+
82
+		//Get group permissions handler
83
+		$gpermHandler = xoops_getHandler('groupperm');
84
+
85
+		$permissionsObj = $gpermHandler->getObjects($criteria);
86
+
87
+		foreach ($permissionsObj as $permissionObj) {
88
+			$groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid');
89
+		}
90
+
91
+		//Return the permission array
92
+		if ($gperm_name) {
93
+			return isset($groups[$gperm_name]) ? $groups[$gperm_name] : array();
94
+		} else {
95
+			return isset($groups) ? $groups : array();
96
+		}
97
+	}
98
+
99
+	/*
100 100
      * Returns permissions for a certain type
101 101
      *
102 102
      * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know)
@@ -104,123 +104,123 @@  discard block
 block discarded – undo
104 104
      *
105 105
      * @return array
106 106
      */
107
-    /**
108
-     * @param        $gperm_name
109
-     * @param  null  $id
110
-     * @return array
111
-     */
112
-    public function getGrantedItems($gperm_name, $id = null)
113
-    {
114
-        global $xoopsUser;
115
-        static $permissions;
116
-
117
-        if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) {
118
-            $smartModule = $this->handler->getModuleInfo();
119
-
120
-            if (is_object($smartModule)) {
121
-
122
-                //Get group permissions handler
123
-                $gpermHandler = xoops_getHandler('groupperm');
124
-
125
-                //Get user's groups
126
-                $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
127
-
128
-                //Get all allowed item ids in this module and for this user's groups
129
-                $userpermissions          = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid'));
130
-                $permissions[$gperm_name] = $userpermissions;
131
-            }
132
-        }
133
-        //Return the permission array
134
-        return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array();
135
-    }
136
-
137
-    /**
138
-     * @param $id
139
-     */
140
-    public function storeAllPermissionsForId($id)
141
-    {
142
-        foreach ($this->handler->getPermissions() as $permission) {
143
-            $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']);
144
-        }
145
-    }
146
-
147
-    /**
148
-     * Saves permissions for the selected category
149
-     *
150
-     *  saveCategory_Permissions()
151
-     *
152
-     * @param  array  $groups    : group with granted permission
153
-     * @param         $itemid
154
-     * @param  string $perm_name : name of the permission
155
-     * @return bool   : TRUE if the no errors occured
156
-     * @internal param int $categoryID: categoryID on which we are setting permissions for Categories and Forums
157
-     */
158
-
159
-    public function saveItem_Permissions($groups, $itemid, $perm_name)
160
-    {
161
-        $smartModule = $this->handler->getModuleInfo();
162
-
163
-        $result       = true;
164
-        $module_id    = $smartModule->getVar('mid');
165
-        $gpermHandler = xoops_getHandler('groupperm');
166
-
167
-        // First, if the permissions are already there, delete them
168
-        $gpermHandler->deleteByModule($module_id, $perm_name, $itemid);
169
-        //echo "itemid: $itemid - perm: $perm_name - modid: $module_id";
170
-        //exit;
171
-        // Save the new permissions
172
-
173
-        if (count($groups) > 0) {
174
-            foreach ($groups as $group_id) {
175
-                $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id);
176
-            }
177
-        }
178
-
179
-        return $result;
180
-    }
181
-
182
-    /**
183
-     * Delete all permission for a specific item
184
-     *
185
-     *  deletePermissions()
186
-     *
187
-     * @param  integer $itemid     : id of the item for which to delete the permissions
188
-     * @param          $gperm_name
189
-     * @return bool:   TRUE if the no errors occured
190
-     */
191
-    public function deletePermissions($itemid, $gperm_name)
192
-    {
193
-        global $xoopsModule;
194
-
195
-        $smartModule =& smartsection_getModuleInfo();
196
-
197
-        $result       = true;
198
-        $module_id    = $smartModule->getVar('mid');
199
-        $gpermHandler = xoops_getHandler('groupperm');
200
-
201
-        $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid);
202
-
203
-        return $result;
204
-    }
205
-
206
-    /**
207
-     * Checks if the user has access to a specific permission on a given object
208
-     *
209
-     * @param  string   $gperm_name   name of the permission to test
210
-     * @param  int      $gperm_itemid id of the object to check
211
-     * @return boolean: TRUE if user has access, FALSE if not
212
-     **/
213
-    public function accessGranted($gperm_name, $gperm_itemid)
214
-    {
215
-        global $xoopsUser;
216
-
217
-        $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
218
-        $smartModule   = $this->handler->getModuleInfo();
219
-        $gperm_modid   = $smartModule->getVar('mid');
220
-
221
-        //Get group permissions handler
222
-        $gpermHandler = xoops_getHandler('groupperm');
223
-
224
-        return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid);
225
-    }
107
+	/**
108
+	 * @param        $gperm_name
109
+	 * @param  null  $id
110
+	 * @return array
111
+	 */
112
+	public function getGrantedItems($gperm_name, $id = null)
113
+	{
114
+		global $xoopsUser;
115
+		static $permissions;
116
+
117
+		if (!isset($permissions[$gperm_name]) || ($id !== null && !isset($permissions[$gperm_name][$id]))) {
118
+			$smartModule = $this->handler->getModuleInfo();
119
+
120
+			if (is_object($smartModule)) {
121
+
122
+				//Get group permissions handler
123
+				$gpermHandler = xoops_getHandler('groupperm');
124
+
125
+				//Get user's groups
126
+				$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
127
+
128
+				//Get all allowed item ids in this module and for this user's groups
129
+				$userpermissions          = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid'));
130
+				$permissions[$gperm_name] = $userpermissions;
131
+			}
132
+		}
133
+		//Return the permission array
134
+		return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : array();
135
+	}
136
+
137
+	/**
138
+	 * @param $id
139
+	 */
140
+	public function storeAllPermissionsForId($id)
141
+	{
142
+		foreach ($this->handler->getPermissions() as $permission) {
143
+			$this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']);
144
+		}
145
+	}
146
+
147
+	/**
148
+	 * Saves permissions for the selected category
149
+	 *
150
+	 *  saveCategory_Permissions()
151
+	 *
152
+	 * @param  array  $groups    : group with granted permission
153
+	 * @param         $itemid
154
+	 * @param  string $perm_name : name of the permission
155
+	 * @return bool   : TRUE if the no errors occured
156
+	 * @internal param int $categoryID: categoryID on which we are setting permissions for Categories and Forums
157
+	 */
158
+
159
+	public function saveItem_Permissions($groups, $itemid, $perm_name)
160
+	{
161
+		$smartModule = $this->handler->getModuleInfo();
162
+
163
+		$result       = true;
164
+		$module_id    = $smartModule->getVar('mid');
165
+		$gpermHandler = xoops_getHandler('groupperm');
166
+
167
+		// First, if the permissions are already there, delete them
168
+		$gpermHandler->deleteByModule($module_id, $perm_name, $itemid);
169
+		//echo "itemid: $itemid - perm: $perm_name - modid: $module_id";
170
+		//exit;
171
+		// Save the new permissions
172
+
173
+		if (count($groups) > 0) {
174
+			foreach ($groups as $group_id) {
175
+				$gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id);
176
+			}
177
+		}
178
+
179
+		return $result;
180
+	}
181
+
182
+	/**
183
+	 * Delete all permission for a specific item
184
+	 *
185
+	 *  deletePermissions()
186
+	 *
187
+	 * @param  integer $itemid     : id of the item for which to delete the permissions
188
+	 * @param          $gperm_name
189
+	 * @return bool:   TRUE if the no errors occured
190
+	 */
191
+	public function deletePermissions($itemid, $gperm_name)
192
+	{
193
+		global $xoopsModule;
194
+
195
+		$smartModule =& smartsection_getModuleInfo();
196
+
197
+		$result       = true;
198
+		$module_id    = $smartModule->getVar('mid');
199
+		$gpermHandler = xoops_getHandler('groupperm');
200
+
201
+		$gpermHandler->deleteByModule($module_id, $gperm_name, $itemid);
202
+
203
+		return $result;
204
+	}
205
+
206
+	/**
207
+	 * Checks if the user has access to a specific permission on a given object
208
+	 *
209
+	 * @param  string   $gperm_name   name of the permission to test
210
+	 * @param  int      $gperm_itemid id of the object to check
211
+	 * @return boolean: TRUE if user has access, FALSE if not
212
+	 **/
213
+	public function accessGranted($gperm_name, $gperm_itemid)
214
+	{
215
+		global $xoopsUser;
216
+
217
+		$gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
218
+		$smartModule   = $this->handler->getModuleInfo();
219
+		$gperm_modid   = $smartModule->getVar('mid');
220
+
221
+		//Get group permissions handler
222
+		$gpermHandler = xoops_getHandler('groupperm');
223
+
224
+		return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid);
225
+	}
226 226
 }
Please login to merge, or discard this patch.
class/smartobjectsregistry.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
     /**
19 19
      * Access the only instance of this class
20 20
      *
21
-     * @return XoopsObject
21
+     * @return SmartObjectsRegistry
22 22
      *
23 23
      * @static
24 24
      * @staticvar   object
Please login to merge, or discard this patch.
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -13,169 +13,169 @@
 block discarded – undo
13 13
  */
14 14
 class SmartObjectsRegistry
15 15
 {
16
-    public $_registryArray;
16
+	public $_registryArray;
17 17
 
18
-    /**
19
-     * Access the only instance of this class
20
-     *
21
-     * @return XoopsObject
22
-     *
23
-     * @static
24
-     * @staticvar   object
25
-     */
26
-    public static function getInstance()
27
-    {
28
-        static $instance;
29
-        if (null === $instance) {
30
-            $instance = new static();
31
-        }
18
+	/**
19
+	 * Access the only instance of this class
20
+	 *
21
+	 * @return XoopsObject
22
+	 *
23
+	 * @static
24
+	 * @staticvar   object
25
+	 */
26
+	public static function getInstance()
27
+	{
28
+		static $instance;
29
+		if (null === $instance) {
30
+			$instance = new static();
31
+		}
32 32
 
33
-        return $instance;
34
-    }
33
+		return $instance;
34
+	}
35 35
 
36
-    /**
37
-     * Adding objects to the registry
38
-     *
39
-     * @param  SmartPersistableObjectHandler $handler  of the objects to add
40
-     * @param  bool|CriteriaCompo            $criteria to pass to the getObjects method of the handler (with id_as_key)
41
-     * @return FALSE                         if an error occured
42
-     */
43
-    public function addObjectsFromHandler(&$handler, $criteria = false)
44
-    {
45
-        if (method_exists($handler, 'getObjects')) {
46
-            $objects                                                                     = $handler->getObjects($criteria, true);
47
-            $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects;
36
+	/**
37
+	 * Adding objects to the registry
38
+	 *
39
+	 * @param  SmartPersistableObjectHandler $handler  of the objects to add
40
+	 * @param  bool|CriteriaCompo            $criteria to pass to the getObjects method of the handler (with id_as_key)
41
+	 * @return FALSE                         if an error occured
42
+	 */
43
+	public function addObjectsFromHandler(&$handler, $criteria = false)
44
+	{
45
+		if (method_exists($handler, 'getObjects')) {
46
+			$objects                                                                     = $handler->getObjects($criteria, true);
47
+			$this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects;
48 48
 
49
-            return $objects;
50
-        } else {
51
-            return false;
52
-        }
53
-    }
49
+			return $objects;
50
+		} else {
51
+			return false;
52
+		}
53
+	}
54 54
 
55
-    /**
56
-     * Adding objects to the registry from an item name
57
-     * This method will fetch the handler of the item / module and call the addObjectsFromHandler
58
-     *
59
-     * @param  string             $item       name of the item
60
-     * @param  bool|string        $modulename name of the module
61
-     * @param  bool|CriteriaCompo $criteria   to pass to the getObjects method of the handler (with id_as_key)
62
-     * @return FALSE              if an error occured
63
-     */
64
-    public function addObjectsFromItemName($item, $modulename = false, $criteria = false)
65
-    {
66
-        if (!$modulename) {
67
-            global $xoopsModule;
68
-            if (!is_object($xoopsModule)) {
69
-                return false;
70
-            } else {
71
-                $modulename = $xoopsModule->dirname();
72
-            }
73
-        }
74
-        $objectHandler = xoops_getModuleHandler($item, $modulename);
55
+	/**
56
+	 * Adding objects to the registry from an item name
57
+	 * This method will fetch the handler of the item / module and call the addObjectsFromHandler
58
+	 *
59
+	 * @param  string             $item       name of the item
60
+	 * @param  bool|string        $modulename name of the module
61
+	 * @param  bool|CriteriaCompo $criteria   to pass to the getObjects method of the handler (with id_as_key)
62
+	 * @return FALSE              if an error occured
63
+	 */
64
+	public function addObjectsFromItemName($item, $modulename = false, $criteria = false)
65
+	{
66
+		if (!$modulename) {
67
+			global $xoopsModule;
68
+			if (!is_object($xoopsModule)) {
69
+				return false;
70
+			} else {
71
+				$modulename = $xoopsModule->dirname();
72
+			}
73
+		}
74
+		$objectHandler = xoops_getModuleHandler($item, $modulename);
75 75
 
76
-        if (method_exists($objectHandler, 'getObjects')) {
77
-            $objects                                                                                 = $objectHandler->getObjects($criteria, true);
78
-            $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects;
76
+		if (method_exists($objectHandler, 'getObjects')) {
77
+			$objects                                                                                 = $objectHandler->getObjects($criteria, true);
78
+			$this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects;
79 79
 
80
-            return $objects;
81
-        } else {
82
-            return false;
83
-        }
84
-    }
80
+			return $objects;
81
+		} else {
82
+			return false;
83
+		}
84
+	}
85 85
 
86
-    /**
87
-     * Fetching objects from the registry
88
-     *
89
-     * @param string $itemname
90
-     * @param string $modulename
91
-     *
92
-     * @return the requested objects or FALSE if they don't exists in the registry
93
-     */
94
-    public function getObjects($itemname, $modulename)
95
-    {
96
-        if (!$modulename) {
97
-            global $xoopsModule;
98
-            if (!is_object($xoopsModule)) {
99
-                return false;
100
-            } else {
101
-                $modulename = $xoopsModule->dirname();
102
-            }
103
-        }
104
-        if (isset($this->_registryArray['objects'][$modulename][$itemname])) {
105
-            return $this->_registryArray['objects'][$modulename][$itemname];
106
-        } else {
107
-            // if they were not in registry, let's fetch them and add them to the reigistry
108
-            $moduleHandler = xoops_getModuleHandler($itemname, $modulename);
109
-            if (method_exists($moduleHandler, 'getObjects')) {
110
-                $objects = $moduleHandler->getObjects();
111
-            }
112
-            $this->_registryArray['objects'][$modulename][$itemname] = $objects;
86
+	/**
87
+	 * Fetching objects from the registry
88
+	 *
89
+	 * @param string $itemname
90
+	 * @param string $modulename
91
+	 *
92
+	 * @return the requested objects or FALSE if they don't exists in the registry
93
+	 */
94
+	public function getObjects($itemname, $modulename)
95
+	{
96
+		if (!$modulename) {
97
+			global $xoopsModule;
98
+			if (!is_object($xoopsModule)) {
99
+				return false;
100
+			} else {
101
+				$modulename = $xoopsModule->dirname();
102
+			}
103
+		}
104
+		if (isset($this->_registryArray['objects'][$modulename][$itemname])) {
105
+			return $this->_registryArray['objects'][$modulename][$itemname];
106
+		} else {
107
+			// if they were not in registry, let's fetch them and add them to the reigistry
108
+			$moduleHandler = xoops_getModuleHandler($itemname, $modulename);
109
+			if (method_exists($moduleHandler, 'getObjects')) {
110
+				$objects = $moduleHandler->getObjects();
111
+			}
112
+			$this->_registryArray['objects'][$modulename][$itemname] = $objects;
113 113
 
114
-            return $objects;
115
-        }
116
-    }
114
+			return $objects;
115
+		}
116
+	}
117 117
 
118
-    /**
119
-     * Fetching objects from the registry, as a list: objectid => identifier
120
-     *
121
-     * @param string $itemname
122
-     * @param string $modulename
123
-     *
124
-     * @return the requested objects or FALSE if they don't exists in the registry
125
-     */
126
-    public function getList($itemname, $modulename)
127
-    {
128
-        if (!$modulename) {
129
-            global $xoopsModule;
130
-            if (!is_object($xoopsModule)) {
131
-                return false;
132
-            } else {
133
-                $modulename = $xoopsModule->dirname();
134
-            }
135
-        }
136
-        if (isset($this->_registryArray['list'][$modulename][$itemname])) {
137
-            return $this->_registryArray['list'][$modulename][$itemname];
138
-        } else {
139
-            // if they were not in registry, let's fetch them and add them to the reigistry
140
-            $moduleHandler = xoops_getModuleHandler($itemname, $modulename);
141
-            if (method_exists($moduleHandler, 'getList')) {
142
-                $objects = $moduleHandler->getList();
143
-            }
144
-            $this->_registryArray['list'][$modulename][$itemname] = $objects;
118
+	/**
119
+	 * Fetching objects from the registry, as a list: objectid => identifier
120
+	 *
121
+	 * @param string $itemname
122
+	 * @param string $modulename
123
+	 *
124
+	 * @return the requested objects or FALSE if they don't exists in the registry
125
+	 */
126
+	public function getList($itemname, $modulename)
127
+	{
128
+		if (!$modulename) {
129
+			global $xoopsModule;
130
+			if (!is_object($xoopsModule)) {
131
+				return false;
132
+			} else {
133
+				$modulename = $xoopsModule->dirname();
134
+			}
135
+		}
136
+		if (isset($this->_registryArray['list'][$modulename][$itemname])) {
137
+			return $this->_registryArray['list'][$modulename][$itemname];
138
+		} else {
139
+			// if they were not in registry, let's fetch them and add them to the reigistry
140
+			$moduleHandler = xoops_getModuleHandler($itemname, $modulename);
141
+			if (method_exists($moduleHandler, 'getList')) {
142
+				$objects = $moduleHandler->getList();
143
+			}
144
+			$this->_registryArray['list'][$modulename][$itemname] = $objects;
145 145
 
146
-            return $objects;
147
-        }
148
-    }
146
+			return $objects;
147
+		}
148
+	}
149 149
 
150
-    /**
151
-     * Retreive a single object
152
-     *
153
-     * @param string $itemname
154
-     * @param string $key
155
-     *
156
-     * @param  bool $modulename
157
-     * @return the  requestd object or FALSE if they don't exists in the registry
158
-     */
159
-    public function getSingleObject($itemname, $key, $modulename = false)
160
-    {
161
-        if (!$modulename) {
162
-            global $xoopsModule;
163
-            if (!is_object($xoopsModule)) {
164
-                return false;
165
-            } else {
166
-                $modulename = $xoopsModule->dirname();
167
-            }
168
-        }
169
-        if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) {
170
-            return $this->_registryArray['objects'][$modulename][$itemname][$key];
171
-        } else {
172
-            $objectHandler = xoops_getModuleHandler($itemname, $modulename);
173
-            $object        = $objectHandler->get($key);
174
-            if (!$object->isNew()) {
175
-                return $object;
176
-            } else {
177
-                return false;
178
-            }
179
-        }
180
-    }
150
+	/**
151
+	 * Retreive a single object
152
+	 *
153
+	 * @param string $itemname
154
+	 * @param string $key
155
+	 *
156
+	 * @param  bool $modulename
157
+	 * @return the  requestd object or FALSE if they don't exists in the registry
158
+	 */
159
+	public function getSingleObject($itemname, $key, $modulename = false)
160
+	{
161
+		if (!$modulename) {
162
+			global $xoopsModule;
163
+			if (!is_object($xoopsModule)) {
164
+				return false;
165
+			} else {
166
+				$modulename = $xoopsModule->dirname();
167
+			}
168
+		}
169
+		if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) {
170
+			return $this->_registryArray['objects'][$modulename][$itemname][$key];
171
+		} else {
172
+			$objectHandler = xoops_getModuleHandler($itemname, $modulename);
173
+			$object        = $objectHandler->get($key);
174
+			if (!$object->isNew()) {
175
+				return $object;
176
+			} else {
177
+				return false;
178
+			}
179
+		}
180
+	}
181 181
 }
Please login to merge, or discard this patch.
include/functions.php 3 patches
Doc Comments   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 }
326 326
 
327 327
 /**
328
- * @param              $key
328
+ * @param              string $key
329 329
  * @param  bool        $moduleName
330 330
  * @param  string      $default
331 331
  * @return null|string
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 
388 388
 /**
389 389
  * Thanks to the NewBB2 Development Team
390
- * @param $target
390
+ * @param string $target
391 391
  * @return bool
392 392
  */
393 393
 function smart_admin_mkdir($target)
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 
541 541
 /**
542 542
  * @param $dirname
543
- * @return bool
543
+ * @return boolean|null
544 544
  */
545 545
 function smart_deleteFile($dirname)
546 546
 {
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 }
756 756
 
757 757
 /**
758
- * @param $name
758
+ * @param string $name
759 759
  */
760 760
 function smart_close_collapsable($name)
761 761
 {
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 }
766 766
 
767 767
 /**
768
- * @param     $name
768
+ * @param     string $name
769 769
  * @param     $value
770 770
  * @param int $time
771 771
  */
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 }
780 780
 
781 781
 /**
782
- * @param         $name
782
+ * @param         string $name
783 783
  * @param  string $default
784 784
  * @return string
785 785
  */
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
 }
939 939
 
940 940
 /**
941
- * @param $src
941
+ * @param string $src
942 942
  */
943 943
 function smart_addScript($src)
944 944
 {
@@ -1115,8 +1115,8 @@  discard block
 block discarded – undo
1115 1115
 }
1116 1116
 
1117 1117
 /**
1118
- * @param $module
1119
- * @param $file
1118
+ * @param string $module
1119
+ * @param string $file
1120 1120
  */
1121 1121
 function smart_loadLanguageFile($module, $file)
1122 1122
 {
@@ -1232,7 +1232,7 @@  discard block
 block discarded – undo
1232 1232
  * This function should be able to cover almost all floats that appear in an european environment.
1233 1233
  * @param            $str
1234 1234
  * @param  bool      $set
1235
- * @return float|int
1235
+ * @return double
1236 1236
  */
1237 1237
 function smart_getfloat($str, $set = false)
1238 1238
 {
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
 /**
1268 1268
  * @param                         $var
1269 1269
  * @param  bool                   $currencyObj
1270
- * @return float|int|mixed|string
1270
+ * @return string
1271 1271
  */
1272 1272
 function smart_currency($var, $currencyObj = false)
1273 1273
 {
@@ -1295,7 +1295,7 @@  discard block
 block discarded – undo
1295 1295
 
1296 1296
 /**
1297 1297
  * @param $var
1298
- * @return float|int|mixed|string
1298
+ * @return string
1299 1299
  */
1300 1300
 function smart_float($var)
1301 1301
 {
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
 /**
1344 1344
  * @param $moduleName
1345 1345
  * @param $items
1346
- * @return array
1346
+ * @return string[]
1347 1347
  */
1348 1348
 function smart_getTablesArray($moduleName, $items)
1349 1349
 {
Please login to merge, or discard this patch.
Indentation   +733 added lines, -733 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 (substr($xv, 2, 1) == '2') {
70
-        $xoops22 = true;
71
-    }
67
+	$xoops22 = false;
68
+	$xv      = str_replace('XOOPS ', '', XOOPS_VERSION);
69
+	if (substr($xv, 2, 1) == '2') {
70
+		$xoops22 = true;
71
+	}
72 72
 
73
-    return $xoops22;
73
+	return $xoops22;
74 74
 }
75 75
 
76 76
 /**
@@ -81,34 +81,34 @@  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 && (isset($smartModuleConfig['show_mod_name_breadcrumb']) && !$smartModuleConfig['show_mod_name_breadcrumb'])) {
95
-        return '';
96
-    }
97
-    if (!$withLink) {
98
-        return $smartModule->getVar('name');
99
-    } else {
100
-        $seoMode = smart_getModuleModeSEO($moduleName);
101
-        if ($seoMode === 'rewrite') {
102
-            $seoModuleName = smart_getModuleNameForSEO($moduleName);
103
-            $ret           = XOOPS_URL . '/' . $seoModuleName . '/';
104
-        } elseif ($seoMode === 'pathinfo') {
105
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
106
-        } else {
107
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/';
108
-        }
109
-
110
-        return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
111
-    }
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 && (isset($smartModuleConfig['show_mod_name_breadcrumb']) && !$smartModuleConfig['show_mod_name_breadcrumb'])) {
95
+		return '';
96
+	}
97
+	if (!$withLink) {
98
+		return $smartModule->getVar('name');
99
+	} else {
100
+		$seoMode = smart_getModuleModeSEO($moduleName);
101
+		if ($seoMode === 'rewrite') {
102
+			$seoModuleName = smart_getModuleNameForSEO($moduleName);
103
+			$ret           = XOOPS_URL . '/' . $seoModuleName . '/';
104
+		} elseif ($seoMode === 'pathinfo') {
105
+			$ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
106
+		} else {
107
+			$ret = XOOPS_URL . '/modules/' . $moduleName . '/';
108
+		}
109
+
110
+		return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
111
+	}
112 112
 }
113 113
 
114 114
 /**
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
  */
118 118
 function smart_getModuleNameForSEO($moduleName = false)
119 119
 {
120
-    $smartModule       = smart_getModuleInfo($moduleName);
121
-    $smartModuleConfig = smart_getModuleConfig($moduleName);
122
-    if (isset($smartModuleConfig['seo_module_name'])) {
123
-        return $smartModuleConfig['seo_module_name'];
124
-    }
125
-    $ret = smart_getModuleName(false, false, $moduleName);
126
-
127
-    return strtolower($ret);
120
+	$smartModule       = smart_getModuleInfo($moduleName);
121
+	$smartModuleConfig = smart_getModuleConfig($moduleName);
122
+	if (isset($smartModuleConfig['seo_module_name'])) {
123
+		return $smartModuleConfig['seo_module_name'];
124
+	}
125
+	$ret = smart_getModuleName(false, false, $moduleName);
126
+
127
+	return strtolower($ret);
128 128
 }
129 129
 
130 130
 /**
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
  */
134 134
 function smart_getModuleModeSEO($moduleName = false)
135 135
 {
136
-    $smartModule       = smart_getModuleInfo($moduleName);
137
-    $smartModuleConfig = smart_getModuleConfig($moduleName);
136
+	$smartModule       = smart_getModuleInfo($moduleName);
137
+	$smartModuleConfig = smart_getModuleConfig($moduleName);
138 138
 
139
-    return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false;
139
+	return isset($smartModuleConfig['seo_mode']) ? $smartModuleConfig['seo_mode'] : false;
140 140
 }
141 141
 
142 142
 /**
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
  */
146 146
 function smart_getModuleIncludeIdSEO($moduleName = false)
147 147
 {
148
-    $smartModule       = smart_getModuleInfo($moduleName);
149
-    $smartModuleConfig = smart_getModuleConfig($moduleName);
148
+	$smartModule       = smart_getModuleInfo($moduleName);
149
+	$smartModuleConfig = smart_getModuleConfig($moduleName);
150 150
 
151
-    return !empty($smartModuleConfig['seo_inc_id']);
151
+	return !empty($smartModuleConfig['seo_inc_id']);
152 152
 }
153 153
 
154 154
 /**
@@ -157,26 +157,26 @@  discard block
 block discarded – undo
157 157
  */
158 158
 function smart_getenv($key)
159 159
 {
160
-    $ret = '';
161
-    $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : '');
160
+	$ret = '';
161
+	$ret = isset($_SERVER[$key]) ? $_SERVER[$key] : (isset($_ENV[$key]) ? $_ENV[$key] : '');
162 162
 
163
-    return $ret;
163
+	return $ret;
164 164
 }
165 165
 
166 166
 function smart_xoops_cp_header()
167 167
 {
168
-    xoops_cp_header();
169
-    global $xoopsModule, $xoopsConfig;
170
-    /**
171
-     * include SmartObject admin language file
172
-     */
173
-    $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
174
-    if (file_exists($fileName)) {
175
-        include_once $fileName;
176
-    } else {
177
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
178
-    }
179
-    ?>
168
+	xoops_cp_header();
169
+	global $xoopsModule, $xoopsConfig;
170
+	/**
171
+	 * include SmartObject admin language file
172
+	 */
173
+	$fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
174
+	if (file_exists($fileName)) {
175
+		include_once $fileName;
176
+	} else {
177
+		include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
178
+	}
179
+	?>
180 180
     <script type='text/javascript'>
181 181
         <!--
182 182
         var smart_url = '<?php echo SMARTOBJECT_URL ?>';
@@ -189,14 +189,14 @@  discard block
 block discarded – undo
189 189
         src='<?php echo SMARTOBJECT_URL ?>include/smart.js'></script>
190 190
     <?php
191 191
 
192
-    /**
193
-     * Include the admin language constants for the SmartObject Framework
194
-     */
195
-    $admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php';
196
-    if (!file_exists($admin_file)) {
197
-        $admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php';
198
-    }
199
-    include_once($admin_file);
192
+	/**
193
+	 * Include the admin language constants for the SmartObject Framework
194
+	 */
195
+	$admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php';
196
+	if (!file_exists($admin_file)) {
197
+		$admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php';
198
+	}
199
+	include_once($admin_file);
200 200
 }
201 201
 
202 202
 /**
@@ -210,21 +210,21 @@  discard block
 block discarded – undo
210 210
  */
211 211
 function smart_TableExists($table)
212 212
 {
213
-    $bRetVal = false;
214
-    //Verifies that a MySQL table exists
215
-    $xoopsDB  = XoopsDatabaseFactory::getDatabaseConnection();
216
-    $realname = $xoopsDB->prefix($table);
217
-    $sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
218
-    $ret      = $xoopsDB->queryF($sql);
219
-    while (list($m_table) = $xoopsDB->fetchRow($ret)) {
220
-        if ($m_table == $realname) {
221
-            $bRetVal = true;
222
-            break;
223
-        }
224
-    }
225
-    $xoopsDB->freeRecordSet($ret);
226
-
227
-    return $bRetVal;
213
+	$bRetVal = false;
214
+	//Verifies that a MySQL table exists
215
+	$xoopsDB  = XoopsDatabaseFactory::getDatabaseConnection();
216
+	$realname = $xoopsDB->prefix($table);
217
+	$sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
218
+	$ret      = $xoopsDB->queryF($sql);
219
+	while (list($m_table) = $xoopsDB->fetchRow($ret)) {
220
+		if ($m_table == $realname) {
221
+			$bRetVal = true;
222
+			break;
223
+		}
224
+	}
225
+	$xoopsDB->freeRecordSet($ret);
226
+
227
+	return $bRetVal;
228 228
 }
229 229
 
230 230
 /**
@@ -239,19 +239,19 @@  discard block
 block discarded – undo
239 239
  */
240 240
 function smart_GetMeta($key, $moduleName = false)
241 241
 {
242
-    if (!$moduleName) {
243
-        $moduleName = smart_getCurrentModuleName();
244
-    }
245
-    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
246
-    $sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
247
-    $ret     = $xoopsDB->query($sql);
248
-    if (!$ret) {
249
-        $value = false;
250
-    } else {
251
-        list($value) = $xoopsDB->fetchRow($ret);
252
-    }
253
-
254
-    return $value;
242
+	if (!$moduleName) {
243
+		$moduleName = smart_getCurrentModuleName();
244
+	}
245
+	$xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
246
+	$sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
247
+	$ret     = $xoopsDB->query($sql);
248
+	if (!$ret) {
249
+		$value = false;
250
+	} else {
251
+		list($value) = $xoopsDB->fetchRow($ret);
252
+	}
253
+
254
+	return $value;
255 255
 }
256 256
 
257 257
 /**
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
  */
260 260
 function smart_getCurrentModuleName()
261 261
 {
262
-    global $xoopsModule;
263
-    if (is_object($xoopsModule)) {
264
-        return $xoopsModule->getVar('dirname');
265
-    } else {
266
-        return false;
267
-    }
262
+	global $xoopsModule;
263
+	if (is_object($xoopsModule)) {
264
+		return $xoopsModule->getVar('dirname');
265
+	} else {
266
+		return false;
267
+	}
268 268
 }
269 269
 
270 270
 /**
@@ -280,22 +280,22 @@  discard block
 block discarded – undo
280 280
  */
281 281
 function smart_SetMeta($key, $value, $moduleName = false)
282 282
 {
283
-    if (!$moduleName) {
284
-        $moduleName = smart_getCurrentModuleName();
285
-    }
286
-    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
287
-    $ret     = smart_GetMeta($key, $moduleName);
288
-    if ($ret === '0' || $ret > 0) {
289
-        $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
290
-    } else {
291
-        $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
292
-    }
293
-    $ret = $xoopsDB->queryF($sql);
294
-    if (!$ret) {
295
-        return false;
296
-    }
297
-
298
-    return true;
283
+	if (!$moduleName) {
284
+		$moduleName = smart_getCurrentModuleName();
285
+	}
286
+	$xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
287
+	$ret     = smart_GetMeta($key, $moduleName);
288
+	if ($ret === '0' || $ret > 0) {
289
+		$sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
290
+	} else {
291
+		$sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
292
+	}
293
+	$ret = $xoopsDB->queryF($sql);
294
+	if (!$ret) {
295
+		return false;
296
+	}
297
+
298
+	return true;
299 299
 }
300 300
 
301 301
 // Thanks to Mithrandir:-)
@@ -308,20 +308,20 @@  discard block
 block discarded – undo
308 308
  */
309 309
 function smart_substr($str, $start, $length, $trimmarker = '...')
310 310
 {
311
-    // if the string is empty, let's get out ;-)
312
-    if ($str === '') {
313
-        return $str;
314
-    }
315
-    // reverse a string that is shortened with '' as trimmarker
316
-    $reversed_string = strrev(xoops_substr($str, $start, $length, ''));
317
-    // find first space in reversed string
318
-    $position_of_space = strpos($reversed_string, ' ', 0);
319
-    // truncate the original string to a length of $length
320
-    // minus the position of the last space
321
-    // plus the length of the $trimmarker
322
-    $truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker);
323
-
324
-    return $truncated_string;
311
+	// if the string is empty, let's get out ;-)
312
+	if ($str === '') {
313
+		return $str;
314
+	}
315
+	// reverse a string that is shortened with '' as trimmarker
316
+	$reversed_string = strrev(xoops_substr($str, $start, $length, ''));
317
+	// find first space in reversed string
318
+	$position_of_space = strpos($reversed_string, ' ', 0);
319
+	// truncate the original string to a length of $length
320
+	// minus the position of the last space
321
+	// plus the length of the $trimmarker
322
+	$truncated_string = xoops_substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker);
323
+
324
+	return $truncated_string;
325 325
 }
326 326
 
327 327
 /**
@@ -332,19 +332,19 @@  discard block
 block discarded – undo
332 332
  */
333 333
 function smart_getConfig($key, $moduleName = false, $default = 'default_is_undefined')
334 334
 {
335
-    if (!$moduleName) {
336
-        $moduleName = smart_getCurrentModuleName();
337
-    }
338
-    $configs = smart_getModuleConfig($moduleName);
339
-    if (isset($configs[$key])) {
340
-        return $configs[$key];
341
-    } else {
342
-        if ($default === 'default_is_undefined') {
343
-            return null;
344
-        } else {
345
-            return $default;
346
-        }
347
-    }
335
+	if (!$moduleName) {
336
+		$moduleName = smart_getCurrentModuleName();
337
+	}
338
+	$configs = smart_getModuleConfig($moduleName);
339
+	if (isset($configs[$key])) {
340
+		return $configs[$key];
341
+	} else {
342
+		if ($default === 'default_is_undefined') {
343
+			return null;
344
+		} else {
345
+			return $default;
346
+		}
347
+	}
348 348
 }
349 349
 
350 350
 /**
@@ -357,32 +357,32 @@  discard block
 block discarded – undo
357 357
  */
358 358
 function smart_copyr($source, $dest)
359 359
 {
360
-    // Simple copy for a file
361
-    if (is_file($source)) {
362
-        return copy($source, $dest);
363
-    }
364
-    // Make destination directory
365
-    if (!is_dir($dest)) {
366
-        mkdir($dest);
367
-    }
368
-    // Loop through the folder
369
-    $dir = dir($source);
370
-    while (false !== $entry = $dir->read()) {
371
-        // Skip pointers
372
-        if ($entry === '.' || $entry === '..') {
373
-            continue;
374
-        }
375
-        // Deep copy directories
376
-        if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) {
377
-            copyr("$source/$entry", "$dest/$entry");
378
-        } else {
379
-            copy("$source/$entry", "$dest/$entry");
380
-        }
381
-    }
382
-    // Clean up
383
-    $dir->close();
384
-
385
-    return true;
360
+	// Simple copy for a file
361
+	if (is_file($source)) {
362
+		return copy($source, $dest);
363
+	}
364
+	// Make destination directory
365
+	if (!is_dir($dest)) {
366
+		mkdir($dest);
367
+	}
368
+	// Loop through the folder
369
+	$dir = dir($source);
370
+	while (false !== $entry = $dir->read()) {
371
+		// Skip pointers
372
+		if ($entry === '.' || $entry === '..') {
373
+			continue;
374
+		}
375
+		// Deep copy directories
376
+		if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) {
377
+			copyr("$source/$entry", "$dest/$entry");
378
+		} else {
379
+			copy("$source/$entry", "$dest/$entry");
380
+		}
381
+	}
382
+	// Clean up
383
+	$dir->close();
384
+
385
+	return true;
386 386
 }
387 387
 
388 388
 /**
@@ -392,26 +392,26 @@  discard block
 block discarded – undo
392 392
  */
393 393
 function smart_admin_mkdir($target)
394 394
 {
395
-    // http://www.php.net/manual/en/function.mkdir.php
396
-    // saint at corenova.com
397
-    // bart at cdasites dot com
398
-    if (is_dir($target) || empty($target)) {
399
-        return true; // best case check first
400
-    }
401
-    if (file_exists($target) && !is_dir($target)) {
402
-        return false;
403
-    }
404
-    if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) {
405
-        if (!file_exists($target)) {
406
-            $res = mkdir($target, 0777); // crawl back up & create dir tree
407
-            smart_admin_chmod($target);
408
-
409
-            return $res;
410
-        }
411
-    }
412
-    $res = is_dir($target);
413
-
414
-    return $res;
395
+	// http://www.php.net/manual/en/function.mkdir.php
396
+	// saint at corenova.com
397
+	// bart at cdasites dot com
398
+	if (is_dir($target) || empty($target)) {
399
+		return true; // best case check first
400
+	}
401
+	if (file_exists($target) && !is_dir($target)) {
402
+		return false;
403
+	}
404
+	if (smart_admin_mkdir(substr($target, 0, strrpos($target, '/')))) {
405
+		if (!file_exists($target)) {
406
+			$res = mkdir($target, 0777); // crawl back up & create dir tree
407
+			smart_admin_chmod($target);
408
+
409
+			return $res;
410
+		}
411
+	}
412
+	$res = is_dir($target);
413
+
414
+	return $res;
415 415
 }
416 416
 
417 417
 /**
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
  */
423 423
 function smart_admin_chmod($target, $mode = 0777)
424 424
 {
425
-    return @ chmod($target, $mode);
425
+	return @ chmod($target, $mode);
426 426
 }
427 427
 
428 428
 /**
@@ -433,31 +433,31 @@  discard block
 block discarded – undo
433 433
  */
434 434
 function smart_imageResize($src, $maxWidth, $maxHeight)
435 435
 {
436
-    $width  = '';
437
-    $height = '';
438
-    $type   = '';
439
-    $attr   = '';
440
-    if (file_exists($src)) {
441
-        list($width, $height, $type, $attr) = getimagesize($src);
442
-        if ($width > $maxWidth) {
443
-            $originalWidth = $width;
444
-            $width         = $maxWidth;
445
-            $height        = $width * $height / $originalWidth;
446
-        }
447
-        if ($height > $maxHeight) {
448
-            $originalHeight = $height;
449
-            $height         = $maxHeight;
450
-            $width          = $height * $width / $originalHeight;
451
-        }
452
-        $attr = " width='$width' height='$height'";
453
-    }
454
-
455
-    return array(
456
-        $width,
457
-        $height,
458
-        $type,
459
-        $attr
460
-    );
436
+	$width  = '';
437
+	$height = '';
438
+	$type   = '';
439
+	$attr   = '';
440
+	if (file_exists($src)) {
441
+		list($width, $height, $type, $attr) = getimagesize($src);
442
+		if ($width > $maxWidth) {
443
+			$originalWidth = $width;
444
+			$width         = $maxWidth;
445
+			$height        = $width * $height / $originalWidth;
446
+		}
447
+		if ($height > $maxHeight) {
448
+			$originalHeight = $height;
449
+			$height         = $maxHeight;
450
+			$width          = $height * $width / $originalHeight;
451
+		}
452
+		$attr = " width='$width' height='$height'";
453
+	}
454
+
455
+	return array(
456
+		$width,
457
+		$height,
458
+		$type,
459
+		$attr
460
+	);
461 461
 }
462 462
 
463 463
 /**
@@ -466,34 +466,34 @@  discard block
 block discarded – undo
466 466
  */
467 467
 function smart_getModuleInfo($moduleName = false)
468 468
 {
469
-    static $smartModules;
470
-    if (isset($smartModules[$moduleName])) {
471
-        $ret =& $smartModules[$moduleName];
472
-
473
-        return $ret;
474
-    }
475
-    global $xoopsModule;
476
-    if (!$moduleName) {
477
-        if (isset($xoopsModule) && is_object($xoopsModule)) {
478
-            $smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule;
479
-
480
-            return $smartModules[$xoopsModule->getVar('dirname')];
481
-        }
482
-    }
483
-    if (!isset($smartModules[$moduleName])) {
484
-        if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
485
-            $smartModules[$moduleName] = $xoopsModule;
486
-        } else {
487
-            $hModule = xoops_getHandler('module');
488
-            if ($moduleName !== 'xoops') {
489
-                $smartModules[$moduleName] = $hModule->getByDirname($moduleName);
490
-            } else {
491
-                $smartModules[$moduleName] = $hModule->getByDirname('system');
492
-            }
493
-        }
494
-    }
495
-
496
-    return $smartModules[$moduleName];
469
+	static $smartModules;
470
+	if (isset($smartModules[$moduleName])) {
471
+		$ret =& $smartModules[$moduleName];
472
+
473
+		return $ret;
474
+	}
475
+	global $xoopsModule;
476
+	if (!$moduleName) {
477
+		if (isset($xoopsModule) && is_object($xoopsModule)) {
478
+			$smartModules[$xoopsModule->getVar('dirname')] = $xoopsModule;
479
+
480
+			return $smartModules[$xoopsModule->getVar('dirname')];
481
+		}
482
+	}
483
+	if (!isset($smartModules[$moduleName])) {
484
+		if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
485
+			$smartModules[$moduleName] = $xoopsModule;
486
+		} else {
487
+			$hModule = xoops_getHandler('module');
488
+			if ($moduleName !== 'xoops') {
489
+				$smartModules[$moduleName] = $hModule->getByDirname($moduleName);
490
+			} else {
491
+				$smartModules[$moduleName] = $hModule->getByDirname('system');
492
+			}
493
+		}
494
+	}
495
+
496
+	return $smartModules[$moduleName];
497 497
 }
498 498
 
499 499
 /**
@@ -502,40 +502,40 @@  discard block
 block discarded – undo
502 502
  */
503 503
 function smart_getModuleConfig($moduleName = false)
504 504
 {
505
-    static $smartConfigs;
506
-    if (isset($smartConfigs[$moduleName])) {
507
-        $ret =& $smartConfigs[$moduleName];
508
-
509
-        return $ret;
510
-    }
511
-    global $xoopsModule, $xoopsModuleConfig;
512
-    if (!$moduleName) {
513
-        if (isset($xoopsModule) && is_object($xoopsModule)) {
514
-            $smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig;
515
-
516
-            return $smartConfigs[$xoopsModule->getVar('dirname')];
517
-        }
518
-    }
519
-    // if we still did not found the xoopsModule, this is because there is none
520
-    if (!$moduleName) {
521
-        $ret = false;
522
-
523
-        return $ret;
524
-    }
525
-    if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
526
-        $smartConfigs[$moduleName] = $xoopsModuleConfig;
527
-    } else {
528
-        $module = smart_getModuleInfo($moduleName);
529
-        if (!is_object($module)) {
530
-            $ret = false;
531
-
532
-            return $ret;
533
-        }
534
-        $hModConfig                = xoops_getHandler('config');
535
-        $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
536
-    }
537
-
538
-    return $smartConfigs[$moduleName];
505
+	static $smartConfigs;
506
+	if (isset($smartConfigs[$moduleName])) {
507
+		$ret =& $smartConfigs[$moduleName];
508
+
509
+		return $ret;
510
+	}
511
+	global $xoopsModule, $xoopsModuleConfig;
512
+	if (!$moduleName) {
513
+		if (isset($xoopsModule) && is_object($xoopsModule)) {
514
+			$smartConfigs[$xoopsModule->getVar('dirname')] = $xoopsModuleConfig;
515
+
516
+			return $smartConfigs[$xoopsModule->getVar('dirname')];
517
+		}
518
+	}
519
+	// if we still did not found the xoopsModule, this is because there is none
520
+	if (!$moduleName) {
521
+		$ret = false;
522
+
523
+		return $ret;
524
+	}
525
+	if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $moduleName) {
526
+		$smartConfigs[$moduleName] = $xoopsModuleConfig;
527
+	} else {
528
+		$module = smart_getModuleInfo($moduleName);
529
+		if (!is_object($module)) {
530
+			$ret = false;
531
+
532
+			return $ret;
533
+		}
534
+		$hModConfig                = xoops_getHandler('config');
535
+		$smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
536
+	}
537
+
538
+	return $smartConfigs[$moduleName];
539 539
 }
540 540
 
541 541
 /**
@@ -544,10 +544,10 @@  discard block
 block discarded – undo
544 544
  */
545 545
 function smart_deleteFile($dirname)
546 546
 {
547
-    // Simple delete for a file
548
-    if (is_file($dirname)) {
549
-        return unlink($dirname);
550
-    }
547
+	// Simple delete for a file
548
+	if (is_file($dirname)) {
549
+		return unlink($dirname);
550
+	}
551 551
 }
552 552
 
553 553
 /**
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
  */
557 557
 function smart_formatErrors($errors = array())
558 558
 {
559
-    $ret = '';
560
-    foreach ($errors as $key => $value) {
561
-        $ret .= '<br> - ' . $value;
562
-    }
559
+	$ret = '';
560
+	foreach ($errors as $key => $value) {
561
+		$ret .= '<br> - ' . $value;
562
+	}
563 563
 
564
-    return $ret;
564
+	return $ret;
565 565
 }
566 566
 
567 567
 /**
@@ -575,64 +575,64 @@  discard block
 block discarded – undo
575 575
  */
576 576
 function smart_getLinkedUnameFromId($userid = 0, $name = 0, $users = array(), $withContact = false)
577 577
 {
578
-    if (!is_numeric($userid)) {
579
-        return $userid;
580
-    }
581
-    $userid = (int)$userid;
582
-    if ($userid > 0) {
583
-        if ($users == array()) {
584
-            //fetching users
585
-            $memberHandler = xoops_getHandler('member');
586
-            $user          =& $memberHandler->getUser($userid);
587
-        } else {
588
-            if (!isset($users[$userid])) {
589
-                return $GLOBALS['xoopsConfig']['anonymous'];
590
-            }
591
-            $user =& $users[$userid];
592
-        }
593
-        if (is_object($user)) {
594
-            $ts        = MyTextSanitizer:: getInstance();
595
-            $username  = $user->getVar('uname');
596
-            $fullname  = '';
597
-            $fullname2 = $user->getVar('name');
598
-            if ($name && !empty($fullname2)) {
599
-                $fullname = $user->getVar('name');
600
-            }
601
-            if (!empty($fullname)) {
602
-                $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
603
-            } else {
604
-                $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
605
-            }
606
-            // add contact info: email + PM
607
-            if ($withContact) {
608
-                $linkeduser .= ' <a href="mailto:' .
609
-                               $user->getVar('email') .
610
-                               '"><img style="vertical-align: middle;" src="' .
611
-                               XOOPS_URL .
612
-                               '/images/icons/email.gif' .
613
-                               '" alt="' .
614
-                               _CO_SOBJECT_SEND_EMAIL .
615
-                               '" title="' .
616
-                               _CO_SOBJECT_SEND_EMAIL .
617
-                               '"/></a>';
618
-                $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
619
-                $linkeduser .= ' <a href="' .
620
-                               $js .
621
-                               '"><img style="vertical-align: middle;" src="' .
622
-                               XOOPS_URL .
623
-                               '/images/icons/pm.gif' .
624
-                               '" alt="' .
625
-                               _CO_SOBJECT_SEND_PM .
626
-                               '" title="' .
627
-                               _CO_SOBJECT_SEND_PM .
628
-                               '"/></a>';
629
-            }
630
-
631
-            return $linkeduser;
632
-        }
633
-    }
634
-
635
-    return $GLOBALS['xoopsConfig']['anonymous'];
578
+	if (!is_numeric($userid)) {
579
+		return $userid;
580
+	}
581
+	$userid = (int)$userid;
582
+	if ($userid > 0) {
583
+		if ($users == array()) {
584
+			//fetching users
585
+			$memberHandler = xoops_getHandler('member');
586
+			$user          =& $memberHandler->getUser($userid);
587
+		} else {
588
+			if (!isset($users[$userid])) {
589
+				return $GLOBALS['xoopsConfig']['anonymous'];
590
+			}
591
+			$user =& $users[$userid];
592
+		}
593
+		if (is_object($user)) {
594
+			$ts        = MyTextSanitizer:: getInstance();
595
+			$username  = $user->getVar('uname');
596
+			$fullname  = '';
597
+			$fullname2 = $user->getVar('name');
598
+			if ($name && !empty($fullname2)) {
599
+				$fullname = $user->getVar('name');
600
+			}
601
+			if (!empty($fullname)) {
602
+				$linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
603
+			} else {
604
+				$linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
605
+			}
606
+			// add contact info: email + PM
607
+			if ($withContact) {
608
+				$linkeduser .= ' <a href="mailto:' .
609
+							   $user->getVar('email') .
610
+							   '"><img style="vertical-align: middle;" src="' .
611
+							   XOOPS_URL .
612
+							   '/images/icons/email.gif' .
613
+							   '" alt="' .
614
+							   _CO_SOBJECT_SEND_EMAIL .
615
+							   '" title="' .
616
+							   _CO_SOBJECT_SEND_EMAIL .
617
+							   '"/></a>';
618
+				$js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
619
+				$linkeduser .= ' <a href="' .
620
+							   $js .
621
+							   '"><img style="vertical-align: middle;" src="' .
622
+							   XOOPS_URL .
623
+							   '/images/icons/pm.gif' .
624
+							   '" alt="' .
625
+							   _CO_SOBJECT_SEND_PM .
626
+							   '" title="' .
627
+							   _CO_SOBJECT_SEND_PM .
628
+							   '"/></a>';
629
+			}
630
+
631
+			return $linkeduser;
632
+		}
633
+	}
634
+
635
+	return $GLOBALS['xoopsConfig']['anonymous'];
636 636
 }
637 637
 
638 638
 /**
@@ -643,33 +643,33 @@  discard block
 block discarded – undo
643 643
  */
644 644
 function smart_adminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1)
645 645
 {
646
-    global $xoopsModule, $xoopsConfig;
647
-    include_once XOOPS_ROOT_PATH . '/class/template.php';
648
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
649
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
650
-    } else {
651
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
652
-    }
653
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
654
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
655
-    } else {
656
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
657
-    }
658
-    $headermenu = array();
659
-    $adminmenu  = array();
660
-    include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
661
-    $tpl = new XoopsTpl();
662
-    $tpl->assign(array(
663
-                     'headermenu'      => $headermenu,
664
-                     'adminmenu'       => $adminmenu,
665
-                     'current'         => $currentoption,
666
-                     'breadcrumb'      => $breadcrumb,
667
-                     'headermenucount' => count($headermenu),
668
-                     'submenus'        => $submenus,
669
-                     'currentsub'      => $currentsub,
670
-                     'submenuscount'   => count($submenus)
671
-                 ));
672
-    $tpl->display('db:smartobject_admin_menu.tpl');
646
+	global $xoopsModule, $xoopsConfig;
647
+	include_once XOOPS_ROOT_PATH . '/class/template.php';
648
+	if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
649
+		include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
650
+	} else {
651
+		include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
652
+	}
653
+	if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
654
+		include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
655
+	} else {
656
+		include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
657
+	}
658
+	$headermenu = array();
659
+	$adminmenu  = array();
660
+	include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
661
+	$tpl = new XoopsTpl();
662
+	$tpl->assign(array(
663
+					 'headermenu'      => $headermenu,
664
+					 'adminmenu'       => $adminmenu,
665
+					 'current'         => $currentoption,
666
+					 'breadcrumb'      => $breadcrumb,
667
+					 'headermenucount' => count($headermenu),
668
+					 'submenus'        => $submenus,
669
+					 'currentsub'      => $currentsub,
670
+					 'submenuscount'   => count($submenus)
671
+				 ));
672
+	$tpl->display('db:smartobject_admin_menu.tpl');
673 673
 }
674 674
 
675 675
 /**
@@ -679,13 +679,13 @@  discard block
 block discarded – undo
679 679
  */
680 680
 function smart_collapsableBar($id = '', $title = '', $dsc = '')
681 681
 {
682
-    global $xoopsModule;
683
-    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')\";>";
684
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a>&nbsp;" . $title . '</h3>';
685
-    echo "<div id='" . $id . "'>";
686
-    if ($dsc !== '') {
687
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
688
-    }
682
+	global $xoopsModule;
683
+	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')\";>";
684
+	echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a>&nbsp;" . $title . '</h3>';
685
+	echo "<div id='" . $id . "'>";
686
+	if ($dsc !== '') {
687
+		echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
688
+	}
689 689
 }
690 690
 
691 691
 /**
@@ -695,15 +695,15 @@  discard block
 block discarded – undo
695 695
  */
696 696
 function smart_ajaxCollapsableBar($id = '', $title = '', $dsc = '')
697 697
 {
698
-    global $xoopsModule;
699
-    $onClick = "ajaxtogglecollapse('$id')";
700
-    //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
701
-    echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
702
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a>&nbsp;" . $title . '</h3>';
703
-    echo "<div id='" . $id . "'>";
704
-    if ($dsc !== '') {
705
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
706
-    }
698
+	global $xoopsModule;
699
+	$onClick = "ajaxtogglecollapse('$id')";
700
+	//$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
701
+	echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
702
+	echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a>&nbsp;" . $title . '</h3>';
703
+	echo "<div id='" . $id . "'>";
704
+	if ($dsc !== '') {
705
+		echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
706
+	}
707 707
 }
708 708
 
709 709
 /**
@@ -730,20 +730,20 @@  discard block
 block discarded – undo
730 730
  */
731 731
 function smart_openclose_collapsable($name)
732 732
 {
733
-    $urls        = smart_getCurrentUrls();
734
-    $path        = $urls['phpself'];
735
-    $cookie_name = $path . '_smart_collaps_' . $name;
736
-    $cookie_name = str_replace('.', '_', $cookie_name);
737
-    $cookie      = smart_getCookieVar($cookie_name, '');
738
-    if ($cookie === 'none') {
739
-        echo '
733
+	$urls        = smart_getCurrentUrls();
734
+	$path        = $urls['phpself'];
735
+	$cookie_name = $path . '_smart_collaps_' . $name;
736
+	$cookie_name = str_replace('.', '_', $cookie_name);
737
+	$cookie      = smart_getCookieVar($cookie_name, '');
738
+	if ($cookie === 'none') {
739
+		echo '
740 740
                 <script type="text/javascript"><!--
741 741
                 togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon");
742 742
                     //-->
743 743
                 </script>
744 744
                 ';
745
-    }
746
-    /*  if ($cookie == 'none') {
745
+	}
746
+	/*  if ($cookie == 'none') {
747 747
      echo '
748 748
      <script type="text/javascript"><!--
749 749
      hideElement("' . $name . '");
@@ -759,9 +759,9 @@  discard block
 block discarded – undo
759 759
  */
760 760
 function smart_close_collapsable($name)
761 761
 {
762
-    echo '</div>';
763
-    smart_openclose_collapsable($name);
764
-    echo '<br>';
762
+	echo '</div>';
763
+	smart_openclose_collapsable($name);
764
+	echo '<br>';
765 765
 }
766 766
 
767 767
 /**
@@ -771,11 +771,11 @@  discard block
 block discarded – undo
771 771
  */
772 772
 function smart_setCookieVar($name, $value, $time = 0)
773 773
 {
774
-    if ($time == 0) {
775
-        $time = time() + 3600 * 24 * 365;
776
-        //$time = '';
777
-    }
778
-    setcookie($name, $value, $time, '/');
774
+	if ($time == 0) {
775
+		$time = time() + 3600 * 24 * 365;
776
+		//$time = '';
777
+	}
778
+	setcookie($name, $value, $time, '/');
779 779
 }
780 780
 
781 781
 /**
@@ -785,12 +785,12 @@  discard block
 block discarded – undo
785 785
  */
786 786
 function smart_getCookieVar($name, $default = '')
787 787
 {
788
-    $name = str_replace('.', '_', $name);
789
-    if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
790
-        return $_COOKIE[$name];
791
-    } else {
792
-        return $default;
793
-    }
788
+	$name = str_replace('.', '_', $name);
789
+	if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
790
+		return $_COOKIE[$name];
791
+	} else {
792
+		return $default;
793
+	}
794 794
 }
795 795
 
796 796
 /**
@@ -798,25 +798,25 @@  discard block
 block discarded – undo
798 798
  */
799 799
 function smart_getCurrentUrls()
800 800
 {
801
-    $urls        = array();
802
-    $http        = (strpos(XOOPS_URL, 'https://') === false) ? 'http://' : 'https://';
803
-    $phpself     = $_SERVER['PHP_SELF'];
804
-    $httphost    = $_SERVER['HTTP_HOST'];
805
-    $querystring = $_SERVER['QUERY_STRING'];
806
-    if ($querystring !== '') {
807
-        $querystring = '?' . $querystring;
808
-    }
809
-    $currenturl           = $http . $httphost . $phpself . $querystring;
810
-    $urls                 = array();
811
-    $urls['http']         = $http;
812
-    $urls['httphost']     = $httphost;
813
-    $urls['phpself']      = $phpself;
814
-    $urls['querystring']  = $querystring;
815
-    $urls['full_phpself'] = $http . $httphost . $phpself;
816
-    $urls['full']         = $currenturl;
817
-    $urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
818
-
819
-    return $urls;
801
+	$urls        = array();
802
+	$http        = (strpos(XOOPS_URL, 'https://') === false) ? 'http://' : 'https://';
803
+	$phpself     = $_SERVER['PHP_SELF'];
804
+	$httphost    = $_SERVER['HTTP_HOST'];
805
+	$querystring = $_SERVER['QUERY_STRING'];
806
+	if ($querystring !== '') {
807
+		$querystring = '?' . $querystring;
808
+	}
809
+	$currenturl           = $http . $httphost . $phpself . $querystring;
810
+	$urls                 = array();
811
+	$urls['http']         = $http;
812
+	$urls['httphost']     = $httphost;
813
+	$urls['phpself']      = $phpself;
814
+	$urls['querystring']  = $querystring;
815
+	$urls['full_phpself'] = $http . $httphost . $phpself;
816
+	$urls['full']         = $currenturl;
817
+	$urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
818
+
819
+	return $urls;
820 820
 }
821 821
 
822 822
 /**
@@ -824,9 +824,9 @@  discard block
 block discarded – undo
824 824
  */
825 825
 function smart_getCurrentPage()
826 826
 {
827
-    $urls = smart_getCurrentUrls();
827
+	$urls = smart_getCurrentUrls();
828 828
 
829
-    return $urls['full'];
829
+	return $urls['full'];
830 830
 }
831 831
 
832 832
 /**
@@ -889,39 +889,39 @@  discard block
 block discarded – undo
889 889
  */
890 890
 function smart_modFooter()
891 891
 {
892
-    global $xoopsConfig, $xoopsModule, $xoopsModuleConfig;
893
-
894
-    include_once XOOPS_ROOT_PATH . '/class/template.php';
895
-    $tpl = new XoopsTpl();
896
-
897
-    $hModule      = xoops_getHandler('module');
898
-    $versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
899
-    $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
900
-    $modfooter    = "<a href='" .
901
-                    $versioninfo->getInfo('support_site_url') .
902
-                    "' target='_blank'><img src='" .
903
-                    XOOPS_URL .
904
-                    '/modules/' .
905
-                    $xoopsModule->getVar('dirname') .
906
-                    "/assets/images/cssbutton.gif' title='" .
907
-                    $modfootertxt .
908
-                    "' alt='" .
909
-                    $modfootertxt .
910
-                    "'/></a>";
911
-    $tpl->assign('modfooter', $modfooter);
912
-
913
-    if (!defined('_AM_SOBJECT_XOOPS_PRO')) {
914
-        define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?');
915
-    }
916
-    $smartobjectConfig = smart_getModuleConfig('smartobject');
917
-    $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
918
-    $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.html');
892
+	global $xoopsConfig, $xoopsModule, $xoopsModuleConfig;
893
+
894
+	include_once XOOPS_ROOT_PATH . '/class/template.php';
895
+	$tpl = new XoopsTpl();
896
+
897
+	$hModule      = xoops_getHandler('module');
898
+	$versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
899
+	$modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
900
+	$modfooter    = "<a href='" .
901
+					$versioninfo->getInfo('support_site_url') .
902
+					"' target='_blank'><img src='" .
903
+					XOOPS_URL .
904
+					'/modules/' .
905
+					$xoopsModule->getVar('dirname') .
906
+					"/assets/images/cssbutton.gif' title='" .
907
+					$modfootertxt .
908
+					"' alt='" .
909
+					$modfootertxt .
910
+					"'/></a>";
911
+	$tpl->assign('modfooter', $modfooter);
912
+
913
+	if (!defined('_AM_SOBJECT_XOOPS_PRO')) {
914
+		define('_AM_SOBJECT_XOOPS_PRO', 'Do you need help with this module ?<br>Do you need new features not yet available?');
915
+	}
916
+	$smartobjectConfig = smart_getModuleConfig('smartobject');
917
+	$tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
918
+	$tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.html');
919 919
 }
920 920
 
921 921
 function smart_xoops_cp_footer()
922 922
 {
923
-    smart_modFooter();
924
-    xoops_cp_footer();
923
+	smart_modFooter();
924
+	xoops_cp_footer();
925 925
 }
926 926
 
927 927
 /**
@@ -930,11 +930,11 @@  discard block
 block discarded – undo
930 930
  */
931 931
 function smart_sanitizeForCommonTags($text)
932 932
 {
933
-    global $xoopsConfig;
934
-    $text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text);
935
-    $text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text);
933
+	global $xoopsConfig;
934
+	$text = str_replace('{X_SITENAME}', $xoopsConfig['sitename'], $text);
935
+	$text = str_replace('{X_ADMINMAIL}', $xoopsConfig['adminmail'], $text);
936 936
 
937
-    return $text;
937
+	return $text;
938 938
 }
939 939
 
940 940
 /**
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
  */
943 943
 function smart_addScript($src)
944 944
 {
945
-    echo '<script src="' . $src . '" type="text/javascript"></script>';
945
+	echo '<script src="' . $src . '" type="text/javascript"></script>';
946 946
 }
947 947
 
948 948
 /**
@@ -950,17 +950,17 @@  discard block
 block discarded – undo
950 950
  */
951 951
 function smart_addStyle($src)
952 952
 {
953
-    if ($src === 'smartobject') {
954
-        $src = SMARTOBJECT_URL . 'assets/css/module.css';
955
-    }
956
-    echo smart_get_css_link($src);
953
+	if ($src === 'smartobject') {
954
+		$src = SMARTOBJECT_URL . 'assets/css/module.css';
955
+	}
956
+	echo smart_get_css_link($src);
957 957
 }
958 958
 
959 959
 function smart_addAdminAjaxSupport()
960 960
 {
961
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
962
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
963
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
961
+	smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
962
+	smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
963
+	smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
964 964
 }
965 965
 
966 966
 /**
@@ -969,11 +969,11 @@  discard block
 block discarded – undo
969 969
  */
970 970
 function smart_sanitizeForSmartpopupLink($text)
971 971
 {
972
-    $patterns[]     = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU";
973
-    $replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>";
974
-    $ret            = preg_replace($patterns, $replacements, $text);
972
+	$patterns[]     = "/\[smartpopup=(['\"]?)([^\"'<>]*)\\1](.*)\[\/smartpopup\]/sU";
973
+	$replacements[] = "<a href=\"javascript:openWithSelfMain('\\2', 'smartpopup', 700, 519);\">\\3</a>";
974
+	$ret            = preg_replace($patterns, $replacements, $text);
975 975
 
976
-    return $ret;
976
+	return $ret;
977 977
 }
978 978
 
979 979
 /**
@@ -988,25 +988,25 @@  discard block
 block discarded – undo
988 988
  */
989 989
 function smart_getImageSize($url, & $width, & $height)
990 990
 {
991
-    if (empty($width) || empty($height)) {
992
-        if (!$dimension = @ getimagesize($url)) {
993
-            return false;
994
-        }
995
-        if (!empty($width)) {
996
-            $height = $dimension[1] * $width / $dimension[0];
997
-        } elseif (!empty($height)) {
998
-            $width = $dimension[0] * $height / $dimension[1];
999
-        } else {
1000
-            list($width, $height) = array(
1001
-                $dimension[0],
1002
-                $dimension[1]
1003
-            );
1004
-        }
1005
-
1006
-        return true;
1007
-    } else {
1008
-        return true;
1009
-    }
991
+	if (empty($width) || empty($height)) {
992
+		if (!$dimension = @ getimagesize($url)) {
993
+			return false;
994
+		}
995
+		if (!empty($width)) {
996
+			$height = $dimension[1] * $width / $dimension[0];
997
+		} elseif (!empty($height)) {
998
+			$width = $dimension[0] * $height / $dimension[1];
999
+		} else {
1000
+			list($width, $height) = array(
1001
+				$dimension[0],
1002
+				$dimension[1]
1003
+			);
1004
+		}
1005
+
1006
+		return true;
1007
+	} else {
1008
+		return true;
1009
+	}
1010 1010
 }
1011 1011
 
1012 1012
 /**
@@ -1019,8 +1019,8 @@  discard block
 block discarded – undo
1019 1019
  */
1020 1020
 function smart_htmlnumericentities($str)
1021 1021
 {
1022
-    //    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
1023
-    return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { return '&#' . ord($m[0]) . chr(59); }, $str);
1022
+	//    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
1023
+	return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { return '&#' . ord($m[0]) . chr(59); }, $str);
1024 1024
 }
1025 1025
 
1026 1026
 /**
@@ -1030,24 +1030,24 @@  discard block
 block discarded – undo
1030 1030
  */
1031 1031
 function smart_getcorehandler($name, $optional = false)
1032 1032
 {
1033
-    static $handlers;
1034
-    $name = strtolower(trim($name));
1035
-    if (!isset($handlers[$name])) {
1036
-        if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1037
-            require_once $hnd_file;
1038
-        }
1039
-        $class = 'Xoops' . ucfirst($name) . 'Handler';
1040
-        if (class_exists($class)) {
1041
-            $handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops');
1042
-        }
1043
-    }
1044
-    if (!isset($handlers[$name]) && !$optional) {
1045
-        trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1046
-    }
1047
-    if (isset($handlers[$name])) {
1048
-        return $handlers[$name];
1049
-    }
1050
-    $inst = false;
1033
+	static $handlers;
1034
+	$name = strtolower(trim($name));
1035
+	if (!isset($handlers[$name])) {
1036
+		if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1037
+			require_once $hnd_file;
1038
+		}
1039
+		$class = 'Xoops' . ucfirst($name) . 'Handler';
1040
+		if (class_exists($class)) {
1041
+			$handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops');
1042
+		}
1043
+	}
1044
+	if (!isset($handlers[$name]) && !$optional) {
1045
+		trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1046
+	}
1047
+	if (isset($handlers[$name])) {
1048
+		return $handlers[$name];
1049
+	}
1050
+	$inst = false;
1051 1051
 }
1052 1052
 
1053 1053
 /**
@@ -1056,15 +1056,15 @@  discard block
 block discarded – undo
1056 1056
  */
1057 1057
 function smart_sanitizeAdsenses_callback($matches)
1058 1058
 {
1059
-    global $smartobjectAdsenseHandler;
1060
-    if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) {
1061
-        $adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]];
1062
-        $ret        = $adsenseObj->render();
1063
-
1064
-        return $ret;
1065
-    } else {
1066
-        return '';
1067
-    }
1059
+	global $smartobjectAdsenseHandler;
1060
+	if (isset($smartobjectAdsenseHandler->objects[$matches[1]])) {
1061
+		$adsenseObj = $smartobjectAdsenseHandler->objects[$matches[1]];
1062
+		$ret        = $adsenseObj->render();
1063
+
1064
+		return $ret;
1065
+	} else {
1066
+		return '';
1067
+	}
1068 1068
 }
1069 1069
 
1070 1070
 /**
@@ -1073,13 +1073,13 @@  discard block
 block discarded – undo
1073 1073
  */
1074 1074
 function smart_sanitizeAdsenses($text)
1075 1075
 {
1076
-    $patterns     = array();
1077
-    $replacements = array();
1076
+	$patterns     = array();
1077
+	$replacements = array();
1078 1078
 
1079
-    $patterns[] = "/\[adsense](.*)\[\/adsense\]/sU";
1080
-    $text       = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text);
1079
+	$patterns[] = "/\[adsense](.*)\[\/adsense\]/sU";
1080
+	$text       = preg_replace_callback($patterns, 'smart_sanitizeAdsenses_callback', $text);
1081 1081
 
1082
-    return $text;
1082
+	return $text;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1088,15 +1088,15 @@  discard block
 block discarded – undo
1088 1088
  */
1089 1089
 function smart_sanitizeCustomtags_callback($matches)
1090 1090
 {
1091
-    global $smartobjectCustomtagHandler;
1092
-    if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) {
1093
-        $customObj = $smartobjectCustomtagHandler->objects[$matches[1]];
1094
-        $ret       = $customObj->renderWithPhp();
1095
-
1096
-        return $ret;
1097
-    } else {
1098
-        return '';
1099
-    }
1091
+	global $smartobjectCustomtagHandler;
1092
+	if (isset($smartobjectCustomtagHandler->objects[$matches[1]])) {
1093
+		$customObj = $smartobjectCustomtagHandler->objects[$matches[1]];
1094
+		$ret       = $customObj->renderWithPhp();
1095
+
1096
+		return $ret;
1097
+	} else {
1098
+		return '';
1099
+	}
1100 1100
 }
1101 1101
 
1102 1102
 /**
@@ -1105,13 +1105,13 @@  discard block
 block discarded – undo
1105 1105
  */
1106 1106
 function smart_sanitizeCustomtags($text)
1107 1107
 {
1108
-    $patterns     = array();
1109
-    $replacements = array();
1108
+	$patterns     = array();
1109
+	$replacements = array();
1110 1110
 
1111
-    $patterns[] = "/\[customtag](.*)\[\/customtag\]/sU";
1112
-    $text       = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text);
1111
+	$patterns[] = "/\[customtag](.*)\[\/customtag\]/sU";
1112
+	$text       = preg_replace_callback($patterns, 'smart_sanitizeCustomtags_callback', $text);
1113 1113
 
1114
-    return $text;
1114
+	return $text;
1115 1115
 }
1116 1116
 
1117 1117
 /**
@@ -1120,20 +1120,20 @@  discard block
 block discarded – undo
1120 1120
  */
1121 1121
 function smart_loadLanguageFile($module, $file)
1122 1122
 {
1123
-    global $xoopsConfig;
1124
-
1125
-    $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1126
-    if (!file_exists($filename)) {
1127
-        $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1128
-    }
1129
-    if (file_exists($filename)) {
1130
-        include_once($filename);
1131
-    }
1123
+	global $xoopsConfig;
1124
+
1125
+	$filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1126
+	if (!file_exists($filename)) {
1127
+		$filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1128
+	}
1129
+	if (file_exists($filename)) {
1130
+		include_once($filename);
1131
+	}
1132 1132
 }
1133 1133
 
1134 1134
 function smart_loadCommonLanguageFile()
1135 1135
 {
1136
-    smart_loadLanguageFile('smartobject', 'common');
1136
+	smart_loadLanguageFile('smartobject', 'common');
1137 1137
 }
1138 1138
 
1139 1139
 /**
@@ -1143,35 +1143,35 @@  discard block
 block discarded – undo
1143 1143
  */
1144 1144
 function smart_purifyText($text, $keyword = false)
1145 1145
 {
1146
-    global $myts;
1147
-    $text = str_replace('&nbsp;', ' ', $text);
1148
-    $text = str_replace('<br>', ' ', $text);
1149
-    $text = str_replace('<br>', ' ', $text);
1150
-    $text = str_replace('<br', ' ', $text);
1151
-    $text = strip_tags($text);
1152
-    $text = html_entity_decode($text);
1153
-    $text = $myts->undoHtmlSpecialChars($text);
1154
-    $text = str_replace(')', ' ', $text);
1155
-    $text = str_replace('(', ' ', $text);
1156
-    $text = str_replace(':', ' ', $text);
1157
-    $text = str_replace('&euro', ' euro ', $text);
1158
-    $text = str_replace('&hellip', '...', $text);
1159
-    $text = str_replace('&rsquo', ' ', $text);
1160
-    $text = str_replace('!', ' ', $text);
1161
-    $text = str_replace('?', ' ', $text);
1162
-    $text = str_replace('"', ' ', $text);
1163
-    $text = str_replace('-', ' ', $text);
1164
-    $text = str_replace('\n', ' ', $text);
1165
-    $text = str_replace('&#8213;', ' ', $text);
1166
-
1167
-    if ($keyword) {
1168
-        $text = str_replace('.', ' ', $text);
1169
-        $text = str_replace(',', ' ', $text);
1170
-        $text = str_replace('\'', ' ', $text);
1171
-    }
1172
-    $text = str_replace(';', ' ', $text);
1173
-
1174
-    return $text;
1146
+	global $myts;
1147
+	$text = str_replace('&nbsp;', ' ', $text);
1148
+	$text = str_replace('<br>', ' ', $text);
1149
+	$text = str_replace('<br>', ' ', $text);
1150
+	$text = str_replace('<br', ' ', $text);
1151
+	$text = strip_tags($text);
1152
+	$text = html_entity_decode($text);
1153
+	$text = $myts->undoHtmlSpecialChars($text);
1154
+	$text = str_replace(')', ' ', $text);
1155
+	$text = str_replace('(', ' ', $text);
1156
+	$text = str_replace(':', ' ', $text);
1157
+	$text = str_replace('&euro', ' euro ', $text);
1158
+	$text = str_replace('&hellip', '...', $text);
1159
+	$text = str_replace('&rsquo', ' ', $text);
1160
+	$text = str_replace('!', ' ', $text);
1161
+	$text = str_replace('?', ' ', $text);
1162
+	$text = str_replace('"', ' ', $text);
1163
+	$text = str_replace('-', ' ', $text);
1164
+	$text = str_replace('\n', ' ', $text);
1165
+	$text = str_replace('&#8213;', ' ', $text);
1166
+
1167
+	if ($keyword) {
1168
+		$text = str_replace('.', ' ', $text);
1169
+		$text = str_replace(',', ' ', $text);
1170
+		$text = str_replace('\'', ' ', $text);
1171
+	}
1172
+	$text = str_replace(';', ' ', $text);
1173
+
1174
+	return $text;
1175 1175
 }
1176 1176
 
1177 1177
 /**
@@ -1180,49 +1180,49 @@  discard block
 block discarded – undo
1180 1180
  */
1181 1181
 function smart_html2text($document)
1182 1182
 {
1183
-    // PHP Manual:: function preg_replace
1184
-    // $document should contain an HTML document.
1185
-    // This will remove HTML tags, javascript sections
1186
-    // and white space. It will also convert some
1187
-    // common HTML entities to their text equivalent.
1188
-    // Credits: newbb2
1189
-    $search = array(
1190
-        "'<script[^>]*?>.*?</script>'si",  // Strip out javascript
1191
-        "'<img.*?/>'si",       // Strip out img tags
1192
-        "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
1193
-        "'([\r\n])[\s]+'",                // Strip out white space
1194
-        "'&(quot|#34);'i",                // Replace HTML entities
1195
-        "'&(amp|#38);'i",
1196
-        "'&(lt|#60);'i",
1197
-        "'&(gt|#62);'i",
1198
-        "'&(nbsp|#160);'i",
1199
-        "'&(iexcl|#161);'i",
1200
-        "'&(cent|#162);'i",
1201
-        "'&(pound|#163);'i",
1202
-        "'&(copy|#169);'i",
1203
-        "'&#(\d+);'e"
1204
-    );                    // evaluate as php
1205
-
1206
-    $replace = array(
1207
-        '',
1208
-        '',
1209
-        '',
1210
-        "\\1",
1211
-        "\"",
1212
-        '&',
1213
-        '<',
1214
-        '>',
1215
-        ' ',
1216
-        chr(161),
1217
-        chr(162),
1218
-        chr(163),
1219
-        chr(169),
1220
-        "chr(\\1)"
1221
-    );
1222
-
1223
-    $text = preg_replace($search, $replace, $document);
1224
-
1225
-    return $text;
1183
+	// PHP Manual:: function preg_replace
1184
+	// $document should contain an HTML document.
1185
+	// This will remove HTML tags, javascript sections
1186
+	// and white space. It will also convert some
1187
+	// common HTML entities to their text equivalent.
1188
+	// Credits: newbb2
1189
+	$search = array(
1190
+		"'<script[^>]*?>.*?</script>'si",  // Strip out javascript
1191
+		"'<img.*?/>'si",       // Strip out img tags
1192
+		"'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
1193
+		"'([\r\n])[\s]+'",                // Strip out white space
1194
+		"'&(quot|#34);'i",                // Replace HTML entities
1195
+		"'&(amp|#38);'i",
1196
+		"'&(lt|#60);'i",
1197
+		"'&(gt|#62);'i",
1198
+		"'&(nbsp|#160);'i",
1199
+		"'&(iexcl|#161);'i",
1200
+		"'&(cent|#162);'i",
1201
+		"'&(pound|#163);'i",
1202
+		"'&(copy|#169);'i",
1203
+		"'&#(\d+);'e"
1204
+	);                    // evaluate as php
1205
+
1206
+	$replace = array(
1207
+		'',
1208
+		'',
1209
+		'',
1210
+		"\\1",
1211
+		"\"",
1212
+		'&',
1213
+		'<',
1214
+		'>',
1215
+		' ',
1216
+		chr(161),
1217
+		chr(162),
1218
+		chr(163),
1219
+		chr(169),
1220
+		"chr(\\1)"
1221
+	);
1222
+
1223
+	$text = preg_replace($search, $replace, $document);
1224
+
1225
+	return $text;
1226 1226
 }
1227 1227
 
1228 1228
 /**
@@ -1236,32 +1236,32 @@  discard block
 block discarded – undo
1236 1236
  */
1237 1237
 function smart_getfloat($str, $set = false)
1238 1238
 {
1239
-    if (preg_match("/([0-9\.,-]+)/", $str, $match)) {
1240
-        // Found number in $str, so set $str that number
1241
-        $str = $match[0];
1242
-        if (false !== strpos($str, ',')) {
1243
-            // A comma exists, that makes it easy, cos we assume it separates the decimal part.
1244
-            $str = str_replace('.', '', $str);    // Erase thousand seps
1245
-            $str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1246
-
1247
-            return (float)$str;
1248
-        } else {
1249
-            // No comma exists, so we have to decide, how a single dot shall be treated
1250
-            if (preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == true && $set['single_dot_as_decimal'] == true) {
1251
-                // Treat single dot as decimal separator
1252
-                return (float)$str;
1253
-            } else {
1254
-                //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1255
-                // Else, treat all dots as thousand seps
1256
-                $str = str_replace('.', '', $str);    // Erase thousand seps
1257
-
1258
-                return (float)$str;
1259
-            }
1260
-        }
1261
-    } else {
1262
-        // No number found, return zero
1263
-        return 0;
1264
-    }
1239
+	if (preg_match("/([0-9\.,-]+)/", $str, $match)) {
1240
+		// Found number in $str, so set $str that number
1241
+		$str = $match[0];
1242
+		if (false !== strpos($str, ',')) {
1243
+			// A comma exists, that makes it easy, cos we assume it separates the decimal part.
1244
+			$str = str_replace('.', '', $str);    // Erase thousand seps
1245
+			$str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1246
+
1247
+			return (float)$str;
1248
+		} else {
1249
+			// No comma exists, so we have to decide, how a single dot shall be treated
1250
+			if (preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == true && $set['single_dot_as_decimal'] == true) {
1251
+				// Treat single dot as decimal separator
1252
+				return (float)$str;
1253
+			} else {
1254
+				//echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1255
+				// Else, treat all dots as thousand seps
1256
+				$str = str_replace('.', '', $str);    // Erase thousand seps
1257
+
1258
+				return (float)$str;
1259
+			}
1260
+		}
1261
+	} else {
1262
+		// No number found, return zero
1263
+		return 0;
1264
+	}
1265 1265
 }
1266 1266
 
1267 1267
 /**
@@ -1271,26 +1271,26 @@  discard block
 block discarded – undo
1271 1271
  */
1272 1272
 function smart_currency($var, $currencyObj = false)
1273 1273
 {
1274
-    $ret = smart_getfloat($var, array('single_dot_as_decimal' => true));
1275
-    $ret = round($ret, 2);
1276
-    // make sur we have at least .00 in the $var
1277
-    $decimal_section_original = strstr($ret, '.');
1278
-    $decimal_section          = $decimal_section_original;
1279
-    if ($decimal_section) {
1280
-        if (strlen($decimal_section) == 1) {
1281
-            $decimal_section = '.00';
1282
-        } elseif (strlen($decimal_section) == 2) {
1283
-            $decimal_section .= '0';
1284
-        }
1285
-        $ret = str_replace($decimal_section_original, $decimal_section, $ret);
1286
-    } else {
1287
-        $ret .= '.00';
1288
-    }
1289
-    if ($currencyObj) {
1290
-        $ret = $ret . ' ' . $currencyObj->getCode();
1291
-    }
1292
-
1293
-    return $ret;
1274
+	$ret = smart_getfloat($var, array('single_dot_as_decimal' => true));
1275
+	$ret = round($ret, 2);
1276
+	// make sur we have at least .00 in the $var
1277
+	$decimal_section_original = strstr($ret, '.');
1278
+	$decimal_section          = $decimal_section_original;
1279
+	if ($decimal_section) {
1280
+		if (strlen($decimal_section) == 1) {
1281
+			$decimal_section = '.00';
1282
+		} elseif (strlen($decimal_section) == 2) {
1283
+			$decimal_section .= '0';
1284
+		}
1285
+		$ret = str_replace($decimal_section_original, $decimal_section, $ret);
1286
+	} else {
1287
+		$ret .= '.00';
1288
+	}
1289
+	if ($currencyObj) {
1290
+		$ret = $ret . ' ' . $currencyObj->getCode();
1291
+	}
1292
+
1293
+	return $ret;
1294 1294
 }
1295 1295
 
1296 1296
 /**
@@ -1299,7 +1299,7 @@  discard block
 block discarded – undo
1299 1299
  */
1300 1300
 function smart_float($var)
1301 1301
 {
1302
-    return smart_currency($var);
1302
+	return smart_currency($var);
1303 1303
 }
1304 1304
 
1305 1305
 /**
@@ -1308,16 +1308,16 @@  discard block
 block discarded – undo
1308 1308
  */
1309 1309
 function smart_getModuleAdminLink($moduleName = false)
1310 1310
 {
1311
-    global $xoopsModule;
1312
-    if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) {
1313
-        $moduleName = $xoopsModule->getVar('dirname');
1314
-    }
1315
-    $ret = '';
1316
-    if ($moduleName) {
1317
-        $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1318
-    }
1319
-
1320
-    return $ret;
1311
+	global $xoopsModule;
1312
+	if (!$moduleName && (isset($xoopsModule) && is_object($xoopsModule))) {
1313
+		$moduleName = $xoopsModule->getVar('dirname');
1314
+	}
1315
+	$ret = '';
1316
+	if ($moduleName) {
1317
+		$ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1318
+	}
1319
+
1320
+	return $ret;
1321 1321
 }
1322 1322
 
1323 1323
 /**
@@ -1325,19 +1325,19 @@  discard block
 block discarded – undo
1325 1325
  */
1326 1326
 function smart_getEditors()
1327 1327
 {
1328
-    $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1329
-    if (!file_exists($filename)) {
1330
-        return false;
1331
-    }
1332
-    include_once $filename;
1333
-    $xoopseditorHandler = XoopsEditorHandler::getInstance();
1334
-    $aList              = $xoopseditorHandler->getList();
1335
-    $ret                = array();
1336
-    foreach ($aList as $k => $v) {
1337
-        $ret[$v] = $k;
1338
-    }
1339
-
1340
-    return $ret;
1328
+	$filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1329
+	if (!file_exists($filename)) {
1330
+		return false;
1331
+	}
1332
+	include_once $filename;
1333
+	$xoopseditorHandler = XoopsEditorHandler::getInstance();
1334
+	$aList              = $xoopseditorHandler->getList();
1335
+	$ret                = array();
1336
+	foreach ($aList as $k => $v) {
1337
+		$ret[$v] = $k;
1338
+	}
1339
+
1340
+	return $ret;
1341 1341
 }
1342 1342
 
1343 1343
 /**
@@ -1347,11 +1347,11 @@  discard block
 block discarded – undo
1347 1347
  */
1348 1348
 function smart_getTablesArray($moduleName, $items)
1349 1349
 {
1350
-    $ret = array();
1351
-    foreach ($items as $item) {
1352
-        $ret[] = $moduleName . '_' . $item;
1353
-    }
1354
-    $ret[] = $moduleName . '_meta';
1350
+	$ret = array();
1351
+	foreach ($items as $item) {
1352
+		$ret[] = $moduleName . '_' . $item;
1353
+	}
1354
+	$ret[] = $moduleName . '_meta';
1355 1355
 
1356
-    return $ret;
1356
+	return $ret;
1357 1357
 }
Please login to merge, or discard this patch.
Spacing   +106 added lines, -106 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
 }
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
         $seoMode = smart_getModuleModeSEO($moduleName);
101 101
         if ($seoMode === 'rewrite') {
102 102
             $seoModuleName = smart_getModuleNameForSEO($moduleName);
103
-            $ret           = XOOPS_URL . '/' . $seoModuleName . '/';
103
+            $ret           = XOOPS_URL.'/'.$seoModuleName.'/';
104 104
         } elseif ($seoMode === 'pathinfo') {
105
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/seo.php/' . $seoModuleName . '/';
105
+            $ret = XOOPS_URL.'/modules/'.$moduleName.'/seo.php/'.$seoModuleName.'/';
106 106
         } else {
107
-            $ret = XOOPS_URL . '/modules/' . $moduleName . '/';
107
+            $ret = XOOPS_URL.'/modules/'.$moduleName.'/';
108 108
         }
109 109
 
110
-        return '<a href="' . $ret . '">' . $smartModule->getVar('name') . '</a>';
110
+        return '<a href="'.$ret.'">'.$smartModule->getVar('name').'</a>';
111 111
     }
112 112
 }
113 113
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
     /**
171 171
      * include SmartObject admin language file
172 172
      */
173
-    $fileName = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
173
+    $fileName = XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/admin.php';
174 174
     if (file_exists($fileName)) {
175 175
         include_once $fileName;
176 176
     } else {
177
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
177
+        include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/admin.php';
178 178
     }
179 179
     ?>
180 180
     <script type='text/javascript'>
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
     /**
193 193
      * Include the admin language constants for the SmartObject Framework
194 194
      */
195
-    $admin_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/admin.php';
195
+    $admin_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/admin.php';
196 196
     if (!file_exists($admin_file)) {
197
-        $admin_file = SMARTOBJECT_ROOT_PATH . 'language/english/admin.php';
197
+        $admin_file = SMARTOBJECT_ROOT_PATH.'language/english/admin.php';
198 198
     }
199 199
     include_once($admin_file);
200 200
 }
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     //Verifies that a MySQL table exists
215 215
     $xoopsDB  = XoopsDatabaseFactory::getDatabaseConnection();
216 216
     $realname = $xoopsDB->prefix($table);
217
-    $sql      = 'SHOW TABLES FROM ' . XOOPS_DB_NAME;
217
+    $sql      = 'SHOW TABLES FROM '.XOOPS_DB_NAME;
218 218
     $ret      = $xoopsDB->queryF($sql);
219 219
     while (list($m_table) = $xoopsDB->fetchRow($ret)) {
220 220
         if ($m_table == $realname) {
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         $moduleName = smart_getCurrentModuleName();
244 244
     }
245 245
     $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
246
-    $sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key));
246
+    $sql     = sprintf('SELECT metavalue FROM %s WHERE metakey=%s', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($key));
247 247
     $ret     = $xoopsDB->query($sql);
248 248
     if (!$ret) {
249 249
         $value = false;
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
     $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
287 287
     $ret     = smart_GetMeta($key, $moduleName);
288 288
     if ($ret === '0' || $ret > 0) {
289
-        $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
289
+        $sql = sprintf('UPDATE %s SET metavalue = %s WHERE metakey = %s', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
290 290
     } else {
291
-        $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName . '_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
291
+        $sql = sprintf('INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)', $xoopsDB->prefix($moduleName.'_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
292 292
     }
293 293
     $ret = $xoopsDB->queryF($sql);
294 294
     if (!$ret) {
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 {
469 469
     static $smartModules;
470 470
     if (isset($smartModules[$moduleName])) {
471
-        $ret =& $smartModules[$moduleName];
471
+        $ret = & $smartModules[$moduleName];
472 472
 
473 473
         return $ret;
474 474
     }
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 {
505 505
     static $smartConfigs;
506 506
     if (isset($smartConfigs[$moduleName])) {
507
-        $ret =& $smartConfigs[$moduleName];
507
+        $ret = & $smartConfigs[$moduleName];
508 508
 
509 509
         return $ret;
510 510
     }
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
             return $ret;
533 533
         }
534 534
         $hModConfig                = xoops_getHandler('config');
535
-        $smartConfigs[$moduleName] =& $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
535
+        $smartConfigs[$moduleName] = & $hModConfig->getConfigsByCat(0, $module->getVar('mid'));
536 536
     }
537 537
 
538 538
     return $smartConfigs[$moduleName];
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 {
559 559
     $ret = '';
560 560
     foreach ($errors as $key => $value) {
561
-        $ret .= '<br> - ' . $value;
561
+        $ret .= '<br> - '.$value;
562 562
     }
563 563
 
564 564
     return $ret;
@@ -578,17 +578,17 @@  discard block
 block discarded – undo
578 578
     if (!is_numeric($userid)) {
579 579
         return $userid;
580 580
     }
581
-    $userid = (int)$userid;
581
+    $userid = (int) $userid;
582 582
     if ($userid > 0) {
583 583
         if ($users == array()) {
584 584
             //fetching users
585 585
             $memberHandler = xoops_getHandler('member');
586
-            $user          =& $memberHandler->getUser($userid);
586
+            $user          = & $memberHandler->getUser($userid);
587 587
         } else {
588 588
             if (!isset($users[$userid])) {
589 589
                 return $GLOBALS['xoopsConfig']['anonymous'];
590 590
             }
591
-            $user =& $users[$userid];
591
+            $user = & $users[$userid];
592 592
         }
593 593
         if (is_object($user)) {
594 594
             $ts        = MyTextSanitizer:: getInstance();
@@ -599,32 +599,32 @@  discard block
 block discarded – undo
599 599
                 $fullname = $user->getVar('name');
600 600
             }
601 601
             if (!empty($fullname)) {
602
-                $linkeduser = "$fullname [<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . $ts->htmlSpecialChars($username) . '</a>]';
602
+                $linkeduser = "$fullname [<a href='".XOOPS_URL.'/userinfo.php?uid='.$userid."'>".$ts->htmlSpecialChars($username).'</a>]';
603 603
             } else {
604
-                $linkeduser = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userid . "'>" . ucwords($ts->htmlSpecialChars($username)) . '</a>';
604
+                $linkeduser = "<a href='".XOOPS_URL.'/userinfo.php?uid='.$userid."'>".ucwords($ts->htmlSpecialChars($username)).'</a>';
605 605
             }
606 606
             // add contact info: email + PM
607 607
             if ($withContact) {
608
-                $linkeduser .= ' <a href="mailto:' .
609
-                               $user->getVar('email') .
610
-                               '"><img style="vertical-align: middle;" src="' .
611
-                               XOOPS_URL .
612
-                               '/images/icons/email.gif' .
613
-                               '" alt="' .
614
-                               _CO_SOBJECT_SEND_EMAIL .
615
-                               '" title="' .
616
-                               _CO_SOBJECT_SEND_EMAIL .
608
+                $linkeduser .= ' <a href="mailto:'.
609
+                               $user->getVar('email').
610
+                               '"><img style="vertical-align: middle;" src="'.
611
+                               XOOPS_URL.
612
+                               '/images/icons/email.gif'.
613
+                               '" alt="'.
614
+                               _CO_SOBJECT_SEND_EMAIL.
615
+                               '" title="'.
616
+                               _CO_SOBJECT_SEND_EMAIL.
617 617
                                '"/></a>';
618
-                $js = "javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $userid . "', 'pmlite',450,370);";
619
-                $linkeduser .= ' <a href="' .
620
-                               $js .
621
-                               '"><img style="vertical-align: middle;" src="' .
622
-                               XOOPS_URL .
623
-                               '/images/icons/pm.gif' .
624
-                               '" alt="' .
625
-                               _CO_SOBJECT_SEND_PM .
626
-                               '" title="' .
627
-                               _CO_SOBJECT_SEND_PM .
618
+                $js = "javascript:openWithSelfMain('".XOOPS_URL.'/pmlite.php?send2=1&to_userid='.$userid."', 'pmlite',450,370);";
619
+                $linkeduser .= ' <a href="'.
620
+                               $js.
621
+                               '"><img style="vertical-align: middle;" src="'.
622
+                               XOOPS_URL.
623
+                               '/images/icons/pm.gif'.
624
+                               '" alt="'.
625
+                               _CO_SOBJECT_SEND_PM.
626
+                               '" title="'.
627
+                               _CO_SOBJECT_SEND_PM.
628 628
                                '"/></a>';
629 629
             }
630 630
 
@@ -644,20 +644,20 @@  discard block
 block discarded – undo
644 644
 function smart_adminMenu($currentoption = 0, $breadcrumb = '', $submenus = false, $currentsub = -1)
645 645
 {
646 646
     global $xoopsModule, $xoopsConfig;
647
-    include_once XOOPS_ROOT_PATH . '/class/template.php';
648
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php')) {
649
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
647
+    include_once XOOPS_ROOT_PATH.'/class/template.php';
648
+    if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/modinfo.php')) {
649
+        include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/modinfo.php';
650 650
     } else {
651
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/modinfo.php';
651
+        include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/modinfo.php';
652 652
     }
653
-    if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php')) {
654
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/admin.php';
653
+    if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/admin.php')) {
654
+        include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/'.$xoopsConfig['language'].'/admin.php';
655 655
     } else {
656
-        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/english/admin.php';
656
+        include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/language/english/admin.php';
657 657
     }
658 658
     $headermenu = array();
659 659
     $adminmenu  = array();
660
-    include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/menu.php';
660
+    include XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/admin/menu.php';
661 661
     $tpl = new XoopsTpl();
662 662
     $tpl->assign(array(
663 663
                      'headermenu'      => $headermenu,
@@ -680,11 +680,11 @@  discard block
 block discarded – undo
680 680
 function smart_collapsableBar($id = '', $title = '', $dsc = '')
681 681
 {
682 682
     global $xoopsModule;
683
-    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')\";>";
684
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a>&nbsp;" . $title . '</h3>';
685
-    echo "<div id='" . $id . "'>";
683
+    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')\";>";
684
+    echo "<img id='".$id."_icon' src=".SMARTOBJECT_URL."assets/images/close12.gif alt='' /></a>&nbsp;".$title.'</h3>';
685
+    echo "<div id='".$id."'>";
686 686
     if ($dsc !== '') {
687
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
687
+        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">".$dsc.'</span>';
688 688
     }
689 689
 }
690 690
 
@@ -698,11 +698,11 @@  discard block
 block discarded – undo
698 698
     global $xoopsModule;
699 699
     $onClick = "ajaxtogglecollapse('$id')";
700 700
     //$onClick = "togglecollapse('$id'); toggleIcon('" . $id . "_icon')";
701
-    echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="' . $onClick . '">';
702
-    echo "<img id='" . $id . "_icon' src=" . SMARTOBJECT_URL . "assets/images/close12.gif alt='' /></a>&nbsp;" . $title . '</h3>';
703
-    echo "<div id='" . $id . "'>";
701
+    echo '<h3 style="border: 1px solid; color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; " onclick="'.$onClick.'">';
702
+    echo "<img id='".$id."_icon' src=".SMARTOBJECT_URL."assets/images/close12.gif alt='' /></a>&nbsp;".$title.'</h3>';
703
+    echo "<div id='".$id."'>";
704 704
     if ($dsc !== '') {
705
-        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $dsc . '</span>';
705
+        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">".$dsc.'</span>';
706 706
     }
707 707
 }
708 708
 
@@ -732,13 +732,13 @@  discard block
 block discarded – undo
732 732
 {
733 733
     $urls        = smart_getCurrentUrls();
734 734
     $path        = $urls['phpself'];
735
-    $cookie_name = $path . '_smart_collaps_' . $name;
735
+    $cookie_name = $path.'_smart_collaps_'.$name;
736 736
     $cookie_name = str_replace('.', '_', $cookie_name);
737 737
     $cookie      = smart_getCookieVar($cookie_name, '');
738 738
     if ($cookie === 'none') {
739 739
         echo '
740 740
                 <script type="text/javascript"><!--
741
-                togglecollapse("' . $name . '"); toggleIcon("' . $name . '_icon");
741
+                togglecollapse("' . $name.'"); toggleIcon("'.$name.'_icon");
742 742
                     //-->
743 743
                 </script>
744 744
                 ';
@@ -804,17 +804,17 @@  discard block
 block discarded – undo
804 804
     $httphost    = $_SERVER['HTTP_HOST'];
805 805
     $querystring = $_SERVER['QUERY_STRING'];
806 806
     if ($querystring !== '') {
807
-        $querystring = '?' . $querystring;
807
+        $querystring = '?'.$querystring;
808 808
     }
809
-    $currenturl           = $http . $httphost . $phpself . $querystring;
809
+    $currenturl           = $http.$httphost.$phpself.$querystring;
810 810
     $urls                 = array();
811 811
     $urls['http']         = $http;
812 812
     $urls['httphost']     = $httphost;
813 813
     $urls['phpself']      = $phpself;
814 814
     $urls['querystring']  = $querystring;
815
-    $urls['full_phpself'] = $http . $httphost . $phpself;
815
+    $urls['full_phpself'] = $http.$httphost.$phpself;
816 816
     $urls['full']         = $currenturl;
817
-    $urls['isHomePage']   = (XOOPS_URL . '/index.php') == ($http . $httphost . $phpself);
817
+    $urls['isHomePage']   = (XOOPS_URL.'/index.php') == ($http.$httphost.$phpself);
818 818
 
819 819
     return $urls;
820 820
 }
@@ -891,22 +891,22 @@  discard block
 block discarded – undo
891 891
 {
892 892
     global $xoopsConfig, $xoopsModule, $xoopsModuleConfig;
893 893
 
894
-    include_once XOOPS_ROOT_PATH . '/class/template.php';
894
+    include_once XOOPS_ROOT_PATH.'/class/template.php';
895 895
     $tpl = new XoopsTpl();
896 896
 
897 897
     $hModule      = xoops_getHandler('module');
898
-    $versioninfo  =& $hModule->get($xoopsModule->getVar('mid'));
899
-    $modfootertxt = 'Module ' . $versioninfo->getInfo('name') . ' - Version ' . $versioninfo->getInfo('version') . '';
900
-    $modfooter    = "<a href='" .
901
-                    $versioninfo->getInfo('support_site_url') .
902
-                    "' target='_blank'><img src='" .
903
-                    XOOPS_URL .
904
-                    '/modules/' .
905
-                    $xoopsModule->getVar('dirname') .
906
-                    "/assets/images/cssbutton.gif' title='" .
907
-                    $modfootertxt .
908
-                    "' alt='" .
909
-                    $modfootertxt .
898
+    $versioninfo  = & $hModule->get($xoopsModule->getVar('mid'));
899
+    $modfootertxt = 'Module '.$versioninfo->getInfo('name').' - Version '.$versioninfo->getInfo('version').'';
900
+    $modfooter    = "<a href='".
901
+                    $versioninfo->getInfo('support_site_url').
902
+                    "' target='_blank'><img src='".
903
+                    XOOPS_URL.
904
+                    '/modules/'.
905
+                    $xoopsModule->getVar('dirname').
906
+                    "/assets/images/cssbutton.gif' title='".
907
+                    $modfootertxt.
908
+                    "' alt='".
909
+                    $modfootertxt.
910 910
                     "'/></a>";
911 911
     $tpl->assign('modfooter', $modfooter);
912 912
 
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
     }
916 916
     $smartobjectConfig = smart_getModuleConfig('smartobject');
917 917
     $tpl->assign('smartobject_enable_admin_footer', $smartobjectConfig['enable_admin_footer']);
918
-    $tpl->display(SMARTOBJECT_ROOT_PATH . 'templates/smartobject_admin_footer.html');
918
+    $tpl->display(SMARTOBJECT_ROOT_PATH.'templates/smartobject_admin_footer.html');
919 919
 }
920 920
 
921 921
 function smart_xoops_cp_footer()
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
  */
943 943
 function smart_addScript($src)
944 944
 {
945
-    echo '<script src="' . $src . '" type="text/javascript"></script>';
945
+    echo '<script src="'.$src.'" type="text/javascript"></script>';
946 946
 }
947 947
 
948 948
 /**
@@ -951,16 +951,16 @@  discard block
 block discarded – undo
951 951
 function smart_addStyle($src)
952 952
 {
953 953
     if ($src === 'smartobject') {
954
-        $src = SMARTOBJECT_URL . 'assets/css/module.css';
954
+        $src = SMARTOBJECT_URL.'assets/css/module.css';
955 955
     }
956 956
     echo smart_get_css_link($src);
957 957
 }
958 958
 
959 959
 function smart_addAdminAjaxSupport()
960 960
 {
961
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/lib/prototype.js');
962
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/scriptaculous.js');
963
-    smart_addScript(SMARTOBJECT_URL . 'include/scriptaculous/src/smart.js');
961
+    smart_addScript(SMARTOBJECT_URL.'include/scriptaculous/lib/prototype.js');
962
+    smart_addScript(SMARTOBJECT_URL.'include/scriptaculous/src/scriptaculous.js');
963
+    smart_addScript(SMARTOBJECT_URL.'include/scriptaculous/src/smart.js');
964 964
 }
965 965
 
966 966
 /**
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
 function smart_htmlnumericentities($str)
1021 1021
 {
1022 1022
     //    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
1023
-    return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function ($m) { return '&#' . ord($m[0]) . chr(59); }, $str);
1023
+    return preg_replace_callback('/[^!-%\x27-;=?-~ ]/', function($m) { return '&#'.ord($m[0]).chr(59); }, $str);
1024 1024
 }
1025 1025
 
1026 1026
 /**
@@ -1033,16 +1033,16 @@  discard block
 block discarded – undo
1033 1033
     static $handlers;
1034 1034
     $name = strtolower(trim($name));
1035 1035
     if (!isset($handlers[$name])) {
1036
-        if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) {
1036
+        if (file_exists($hnd_file = XOOPS_ROOT_PATH.'/kernel/'.$name.'.php')) {
1037 1037
             require_once $hnd_file;
1038 1038
         }
1039
-        $class = 'Xoops' . ucfirst($name) . 'Handler';
1039
+        $class = 'Xoops'.ucfirst($name).'Handler';
1040 1040
         if (class_exists($class)) {
1041
-            $handlers[$name] = new $class ($GLOBALS['xoopsDB'], 'xoops');
1041
+            $handlers[$name] = new $class($GLOBALS['xoopsDB'], 'xoops');
1042 1042
         }
1043 1043
     }
1044 1044
     if (!isset($handlers[$name]) && !$optional) {
1045
-        trigger_error('Class <b>' . $class . '</b> does not exist<br>Handler Name: ' . $name, E_USER_ERROR);
1045
+        trigger_error('Class <b>'.$class.'</b> does not exist<br>Handler Name: '.$name, E_USER_ERROR);
1046 1046
     }
1047 1047
     if (isset($handlers[$name])) {
1048 1048
         return $handlers[$name];
@@ -1122,9 +1122,9 @@  discard block
 block discarded – undo
1122 1122
 {
1123 1123
     global $xoopsConfig;
1124 1124
 
1125
-    $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/' . $xoopsConfig['language'] . '/' . $file . '.php';
1125
+    $filename = XOOPS_ROOT_PATH.'/modules/'.$module.'/language/'.$xoopsConfig['language'].'/'.$file.'.php';
1126 1126
     if (!file_exists($filename)) {
1127
-        $filename = XOOPS_ROOT_PATH . '/modules/' . $module . '/language/english/' . $file . '.php';
1127
+        $filename = XOOPS_ROOT_PATH.'/modules/'.$module.'/language/english/'.$file.'.php';
1128 1128
     }
1129 1129
     if (file_exists($filename)) {
1130 1130
         include_once($filename);
@@ -1187,11 +1187,11 @@  discard block
 block discarded – undo
1187 1187
     // common HTML entities to their text equivalent.
1188 1188
     // Credits: newbb2
1189 1189
     $search = array(
1190
-        "'<script[^>]*?>.*?</script>'si",  // Strip out javascript
1191
-        "'<img.*?/>'si",       // Strip out img tags
1192
-        "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
1193
-        "'([\r\n])[\s]+'",                // Strip out white space
1194
-        "'&(quot|#34);'i",                // Replace HTML entities
1190
+        "'<script[^>]*?>.*?</script>'si", // Strip out javascript
1191
+        "'<img.*?/>'si", // Strip out img tags
1192
+        "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
1193
+        "'([\r\n])[\s]+'", // Strip out white space
1194
+        "'&(quot|#34);'i", // Replace HTML entities
1195 1195
         "'&(amp|#38);'i",
1196 1196
         "'&(lt|#60);'i",
1197 1197
         "'&(gt|#62);'i",
@@ -1201,7 +1201,7 @@  discard block
 block discarded – undo
1201 1201
         "'&(pound|#163);'i",
1202 1202
         "'&(copy|#169);'i",
1203 1203
         "'&#(\d+);'e"
1204
-    );                    // evaluate as php
1204
+    ); // evaluate as php
1205 1205
 
1206 1206
     $replace = array(
1207 1207
         '',
@@ -1241,21 +1241,21 @@  discard block
 block discarded – undo
1241 1241
         $str = $match[0];
1242 1242
         if (false !== strpos($str, ',')) {
1243 1243
             // A comma exists, that makes it easy, cos we assume it separates the decimal part.
1244
-            $str = str_replace('.', '', $str);    // Erase thousand seps
1245
-            $str = str_replace(',', '.', $str);    // Convert , to . for floatval command
1244
+            $str = str_replace('.', '', $str); // Erase thousand seps
1245
+            $str = str_replace(',', '.', $str); // Convert , to . for floatval command
1246 1246
 
1247
-            return (float)$str;
1247
+            return (float) $str;
1248 1248
         } else {
1249 1249
             // No comma exists, so we have to decide, how a single dot shall be treated
1250 1250
             if (preg_match("/^[0-9\-]*[\.]{1}[0-9-]+$/", $str) == true && $set['single_dot_as_decimal'] == true) {
1251 1251
                 // Treat single dot as decimal separator
1252
-                return (float)$str;
1252
+                return (float) $str;
1253 1253
             } else {
1254 1254
                 //echo "str: ".$str; echo "ret: ".str_replace('.', '', $str); echo "<br><br> ";
1255 1255
                 // Else, treat all dots as thousand seps
1256
-                $str = str_replace('.', '', $str);    // Erase thousand seps
1256
+                $str = str_replace('.', '', $str); // Erase thousand seps
1257 1257
 
1258
-                return (float)$str;
1258
+                return (float) $str;
1259 1259
             }
1260 1260
         }
1261 1261
     } else {
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
         $ret .= '.00';
1288 1288
     }
1289 1289
     if ($currencyObj) {
1290
-        $ret = $ret . ' ' . $currencyObj->getCode();
1290
+        $ret = $ret.' '.$currencyObj->getCode();
1291 1291
     }
1292 1292
 
1293 1293
     return $ret;
@@ -1314,7 +1314,7 @@  discard block
 block discarded – undo
1314 1314
     }
1315 1315
     $ret = '';
1316 1316
     if ($moduleName) {
1317
-        $ret = "<a href='" . XOOPS_URL . "/modules/$moduleName/admin/index.php'>" . _CO_SOBJECT_ADMIN_PAGE . '</a>';
1317
+        $ret = "<a href='".XOOPS_URL."/modules/$moduleName/admin/index.php'>"._CO_SOBJECT_ADMIN_PAGE.'</a>';
1318 1318
     }
1319 1319
 
1320 1320
     return $ret;
@@ -1325,7 +1325,7 @@  discard block
 block discarded – undo
1325 1325
  */
1326 1326
 function smart_getEditors()
1327 1327
 {
1328
-    $filename = XOOPS_ROOT_PATH . '/class/xoopseditor/xoopseditor.php';
1328
+    $filename = XOOPS_ROOT_PATH.'/class/xoopseditor/xoopseditor.php';
1329 1329
     if (!file_exists($filename)) {
1330 1330
         return false;
1331 1331
     }
@@ -1349,9 +1349,9 @@  discard block
 block discarded – undo
1349 1349
 {
1350 1350
     $ret = array();
1351 1351
     foreach ($items as $item) {
1352
-        $ret[] = $moduleName . '_' . $item;
1352
+        $ret[] = $moduleName.'_'.$item;
1353 1353
     }
1354
-    $ret[] = $moduleName . '_meta';
1354
+    $ret[] = $moduleName.'_meta';
1355 1355
 
1356 1356
     return $ret;
1357 1357
 }
Please login to merge, or discard this patch.
class/member.php 2 patches
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -46,227 +46,227 @@
 block discarded – undo
46 46
  */
47 47
 class SmartobjectMemberHandler extends XoopsMemberHandler
48 48
 {
49
-    /**
50
-     * constructor
51
-     * @param XoopsDatabase $db
52
-     */
53
-    public function __construct(XoopsDatabase $db)
54
-    {
55
-        parent::__construct($db);
56
-        $this->_uHandler = xoops_getModuleHandler('user', 'smartobject');
57
-    }
49
+	/**
50
+	 * constructor
51
+	 * @param XoopsDatabase $db
52
+	 */
53
+	public function __construct(XoopsDatabase $db)
54
+	{
55
+		parent::__construct($db);
56
+		$this->_uHandler = xoops_getModuleHandler('user', 'smartobject');
57
+	}
58 58
 
59
-    /**
60
-     * @param       $userObj
61
-     * @param  bool $groups
62
-     * @param  bool $notifyUser
63
-     * @param  bool $password
64
-     * @return bool
65
-     */
66
-    public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false)
67
-    {
68
-        $email = $userObj->getVar('email');
69
-        if (!$userObj->getVar('email') || $email === '') {
70
-            $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL);
59
+	/**
60
+	 * @param       $userObj
61
+	 * @param  bool $groups
62
+	 * @param  bool $notifyUser
63
+	 * @param  bool $password
64
+	 * @return bool
65
+	 */
66
+	public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false)
67
+	{
68
+		$email = $userObj->getVar('email');
69
+		if (!$userObj->getVar('email') || $email === '') {
70
+			$userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL);
71 71
 
72
-            return false;
73
-        }
72
+			return false;
73
+		}
74 74
 
75
-        $password = $userObj->getVar('pass');
76
-        // randomly generating the password if not already set
77
-        if ('' === $password) {
78
-            $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6);
79
-        }
80
-        $userObj->setVar('pass', md5($password));
75
+		$password = $userObj->getVar('pass');
76
+		// randomly generating the password if not already set
77
+		if ('' === $password) {
78
+			$password = substr(md5(uniqid(mt_rand(), 1)), 0, 6);
79
+		}
80
+		$userObj->setVar('pass', md5($password));
81 81
 
82
-        // if no username is set, let's generate one
83
-        $unamecount = 20;
84
-        $uname      = $userObj->getVar('uname');
85
-        if (!$uname || $uname === '') {
86
-            $usernames = $this->genUserNames($email, $unamecount);
87
-            $newuser   = false;
88
-            $i         = 0;
89
-            while ($newuser === false) {
90
-                $crit  = new Criteria('uname', $usernames[$i]);
91
-                $count = $this->getUserCount($crit);
92
-                if ($count == 0) {
93
-                    $newuser = true;
94
-                } else {
95
-                    //Move to next username
96
-                    ++$i;
97
-                    if ($i == $unamecount) {
98
-                        //Get next batch of usernames to try, reset counter
99
-                        $usernames = $this->genUserNames($email, $unamecount);
100
-                        $i         = 0;
101
-                    }
102
-                }
103
-            }
104
-        }
82
+		// if no username is set, let's generate one
83
+		$unamecount = 20;
84
+		$uname      = $userObj->getVar('uname');
85
+		if (!$uname || $uname === '') {
86
+			$usernames = $this->genUserNames($email, $unamecount);
87
+			$newuser   = false;
88
+			$i         = 0;
89
+			while ($newuser === false) {
90
+				$crit  = new Criteria('uname', $usernames[$i]);
91
+				$count = $this->getUserCount($crit);
92
+				if ($count == 0) {
93
+					$newuser = true;
94
+				} else {
95
+					//Move to next username
96
+					++$i;
97
+					if ($i == $unamecount) {
98
+						//Get next batch of usernames to try, reset counter
99
+						$usernames = $this->genUserNames($email, $unamecount);
100
+						$i         = 0;
101
+					}
102
+				}
103
+			}
104
+		}
105 105
 
106
-        global $xoopsConfig;
106
+		global $xoopsConfig;
107 107
 
108
-        $configHandler   = xoops_getHandler('config');
109
-        $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
110
-        switch ($xoopsConfigUser['activation_type']) {
111
-            case 0:
112
-                $level           = 0;
113
-                $mailtemplate    = 'smartmail_activate_user.tpl';
114
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email);
115
-                break;
116
-            case 1:
117
-                $level           = 1;
118
-                $mailtemplate    = 'smartmail_auto_activate_user.tpl';
119
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email);
120
-                break;
121
-            case 2:
122
-            default:
123
-                $level           = 0;
124
-                $mailtemplate    = 'smartmail_admin_activate_user.tpl';
125
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email);
126
-        }
108
+		$configHandler   = xoops_getHandler('config');
109
+		$xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
110
+		switch ($xoopsConfigUser['activation_type']) {
111
+			case 0:
112
+				$level           = 0;
113
+				$mailtemplate    = 'smartmail_activate_user.tpl';
114
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email);
115
+				break;
116
+			case 1:
117
+				$level           = 1;
118
+				$mailtemplate    = 'smartmail_auto_activate_user.tpl';
119
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email);
120
+				break;
121
+			case 2:
122
+			default:
123
+				$level           = 0;
124
+				$mailtemplate    = 'smartmail_admin_activate_user.tpl';
125
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email);
126
+		}
127 127
 
128
-        $userObj->setVar('uname', $usernames[$i]);
129
-        $userObj->setVar('user_avatar', 'blank.gif');
130
-        $userObj->setVar('user_regdate', time());
131
-        $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']);
132
-        $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
133
-        $userObj->setVar('actkey', $actkey);
134
-        $userObj->setVar('email', $email);
135
-        $userObj->setVar('notify_method', 2);
136
-        $userObj->setVar('level', $userObj);
128
+		$userObj->setVar('uname', $usernames[$i]);
129
+		$userObj->setVar('user_avatar', 'blank.gif');
130
+		$userObj->setVar('user_regdate', time());
131
+		$userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']);
132
+		$actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
133
+		$userObj->setVar('actkey', $actkey);
134
+		$userObj->setVar('email', $email);
135
+		$userObj->setVar('notify_method', 2);
136
+		$userObj->setVar('level', $userObj);
137 137
 
138
-        if ($this->insertUser($userObj)) {
138
+		if ($this->insertUser($userObj)) {
139 139
 
140
-            // if $groups=false, Add the user to Registered Users group
141
-            if (!$groups) {
142
-                $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid'));
143
-            } else {
144
-                foreach ($groups as $groupid) {
145
-                    $this->addUserToGroup($groupid, $userObj->getVar('uid'));
146
-                }
147
-            }
148
-        } else {
149
-            return false;
150
-        }
140
+			// if $groups=false, Add the user to Registered Users group
141
+			if (!$groups) {
142
+				$this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid'));
143
+			} else {
144
+				foreach ($groups as $groupid) {
145
+					$this->addUserToGroup($groupid, $userObj->getVar('uid'));
146
+				}
147
+			}
148
+		} else {
149
+			return false;
150
+		}
151 151
 
152
-        if ($notifyUser) {
153
-            // send some notifications
154
-            $xoopsMailer =& getMailer();
155
-            $xoopsMailer->useMail();
156
-            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
157
-            $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
158
-            $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
159
-            $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
160
-            $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
161
-            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
162
-            $xoopsMailer->assign('NAME', $userObj->getVar('name'));
163
-            $xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
164
-            $xoopsMailer->setToUsers($userObj);
165
-            $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
166
-            $xoopsMailer->setFromName($xoopsConfig['sitename']);
167
-            $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename']));
152
+		if ($notifyUser) {
153
+			// send some notifications
154
+			$xoopsMailer =& getMailer();
155
+			$xoopsMailer->useMail();
156
+			$xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
157
+			$xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
158
+			$xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
159
+			$xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
160
+			$xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
161
+			$xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
162
+			$xoopsMailer->assign('NAME', $userObj->getVar('name'));
163
+			$xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
164
+			$xoopsMailer->setToUsers($userObj);
165
+			$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
166
+			$xoopsMailer->setFromName($xoopsConfig['sitename']);
167
+			$xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename']));
168 168
 
169
-            if (!$xoopsMailer->send(true)) {
170
-                /**
171
-                 * @todo trap error if email was not sent
172
-                 */
173
-                $xoopsMailer->getErrors(true);
174
-            }
175
-        }
169
+			if (!$xoopsMailer->send(true)) {
170
+				/**
171
+				 * @todo trap error if email was not sent
172
+				 */
173
+				$xoopsMailer->getErrors(true);
174
+			}
175
+		}
176 176
 
177
-        return true;
178
-    }
177
+		return true;
178
+	}
179 179
 
180
-    /**
181
-     * Generates an array of usernames
182
-     *
183
-     * @param  string $email email of user
184
-     * @param  int    $count number of names to generate
185
-     * @return array  $names
186
-     * @internal param string $name name of user
187
-     * @author   xHelp Team
188
-     *
189
-     * @access   public
190
-     */
191
-    public function genUserNames($email, $count = 20)
192
-    {
193
-        $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username
180
+	/**
181
+	 * Generates an array of usernames
182
+	 *
183
+	 * @param  string $email email of user
184
+	 * @param  int    $count number of names to generate
185
+	 * @return array  $names
186
+	 * @internal param string $name name of user
187
+	 * @author   xHelp Team
188
+	 *
189
+	 * @access   public
190
+	 */
191
+	public function genUserNames($email, $count = 20)
192
+	{
193
+		$name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username
194 194
 
195
-        $names  = array();
196
-        $userid = explode('@', $email);
195
+		$names  = array();
196
+		$userid = explode('@', $email);
197 197
 
198
-        $basename    = '';
199
-        $hasbasename = false;
200
-        $emailname   = $userid[0];
198
+		$basename    = '';
199
+		$hasbasename = false;
200
+		$emailname   = $userid[0];
201 201
 
202
-        $names[] = $emailname;
202
+		$names[] = $emailname;
203 203
 
204
-        if (strlen($name) > 0) {
205
-            $name = explode(' ', trim($name));
206
-            if (count($name) > 1) {
207
-                $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
208
-            } else {
209
-                $basename = strtolower($name[0]);
210
-            }
211
-            $basename = xoops_substr($basename, 0, 60, '');
212
-            //Prevent Duplication of Email Username and Name
213
-            if (!in_array($basename, $names)) {
214
-                $names[]     = $basename;
215
-                $hasbasename = true;
216
-            }
217
-        }
204
+		if (strlen($name) > 0) {
205
+			$name = explode(' ', trim($name));
206
+			if (count($name) > 1) {
207
+				$basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
208
+			} else {
209
+				$basename = strtolower($name[0]);
210
+			}
211
+			$basename = xoops_substr($basename, 0, 60, '');
212
+			//Prevent Duplication of Email Username and Name
213
+			if (!in_array($basename, $names)) {
214
+				$names[]     = $basename;
215
+				$hasbasename = true;
216
+			}
217
+		}
218 218
 
219
-        $i          = count($names);
220
-        $onbasename = 1;
221
-        while ($i < $count) {
222
-            $num = $this->genRandNumber();
223
-            if ($onbasename < 0 && $hasbasename) {
224
-                $names[] = xoops_substr($basename, 0, 58, '') . $num;
225
-            } else {
226
-                $names[] = xoops_substr($emailname, 0, 58, '') . $num;
227
-            }
228
-            $i          = count($names);
229
-            $onbasename = ~$onbasename;
230
-            $num        = '';
231
-        }
219
+		$i          = count($names);
220
+		$onbasename = 1;
221
+		while ($i < $count) {
222
+			$num = $this->genRandNumber();
223
+			if ($onbasename < 0 && $hasbasename) {
224
+				$names[] = xoops_substr($basename, 0, 58, '') . $num;
225
+			} else {
226
+				$names[] = xoops_substr($emailname, 0, 58, '') . $num;
227
+			}
228
+			$i          = count($names);
229
+			$onbasename = ~$onbasename;
230
+			$num        = '';
231
+		}
232 232
 
233
-        return $names;
234
-    }
233
+		return $names;
234
+	}
235 235
 
236
-    /**
237
-     * Creates a random number with a specified number of $digits
238
-     *
239
-     * @param  int    $digits number of digits
240
-     * @return return int random number
241
-     * @author xHelp Team
242
-     *
243
-     * @access public
244
-     */
245
-    public function genRandNumber($digits = 2)
246
-    {
247
-        $this->initRand();
248
-        $tmp = array();
236
+	/**
237
+	 * Creates a random number with a specified number of $digits
238
+	 *
239
+	 * @param  int    $digits number of digits
240
+	 * @return return int random number
241
+	 * @author xHelp Team
242
+	 *
243
+	 * @access public
244
+	 */
245
+	public function genRandNumber($digits = 2)
246
+	{
247
+		$this->initRand();
248
+		$tmp = array();
249 249
 
250
-        for ($i = 0; $i < $digits; ++$i) {
251
-            $tmp[$i] = (mt_rand() % 9);
252
-        }
250
+		for ($i = 0; $i < $digits; ++$i) {
251
+			$tmp[$i] = (mt_rand() % 9);
252
+		}
253 253
 
254
-        return implode('', $tmp);
255
-    }
254
+		return implode('', $tmp);
255
+	}
256 256
 
257
-    /**
258
-     * Gives the random number generator a seed to start from
259
-     *
260
-     * @return void
261
-     *
262
-     * @access public
263
-     */
264
-    public function initRand()
265
-    {
266
-        static $randCalled = false;
267
-        if (!$randCalled) {
268
-            mt_srand((double)microtime() * 1000000);
269
-            $randCalled = true;
270
-        }
271
-    }
257
+	/**
258
+	 * Gives the random number generator a seed to start from
259
+	 *
260
+	 * @return void
261
+	 *
262
+	 * @access public
263
+	 */
264
+	public function initRand()
265
+	{
266
+		static $randCalled = false;
267
+		if (!$randCalled) {
268
+			mt_srand((double)microtime() * 1000000);
269
+			$randCalled = true;
270
+		}
271
+	}
272 272
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 // ------------------------------------------------------------------------- //
31 31
 
32 32
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
33
-require_once XOOPS_ROOT_PATH . '/kernel/user.php';
34
-require_once XOOPS_ROOT_PATH . '/kernel/group.php';
35
-require_once XOOPS_ROOT_PATH . '/kernel/member.php';
33
+require_once XOOPS_ROOT_PATH.'/kernel/user.php';
34
+require_once XOOPS_ROOT_PATH.'/kernel/group.php';
35
+require_once XOOPS_ROOT_PATH.'/kernel/member.php';
36 36
 
37 37
 /**
38 38
  * XOOPS member handler class.
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 
152 152
         if ($notifyUser) {
153 153
             // send some notifications
154
-            $xoopsMailer =& getMailer();
154
+            $xoopsMailer = & getMailer();
155 155
             $xoopsMailer->useMail();
156
-            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
156
+            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/mail_template');
157 157
             $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
158 158
             $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
159 159
             $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
160 160
             $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
161
-            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
161
+            $xoopsMailer->assign('SITEURL', XOOPS_URL.'/');
162 162
             $xoopsMailer->assign('NAME', $userObj->getVar('name'));
163 163
             $xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
164 164
             $xoopsMailer->setToUsers($userObj);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         if (strlen($name) > 0) {
205 205
             $name = explode(' ', trim($name));
206 206
             if (count($name) > 1) {
207
-                $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
207
+                $basename = strtolower(substr($name[0], 0, 1).$name[count($name) - 1]);
208 208
             } else {
209 209
                 $basename = strtolower($name[0]);
210 210
             }
@@ -221,9 +221,9 @@  discard block
 block discarded – undo
221 221
         while ($i < $count) {
222 222
             $num = $this->genRandNumber();
223 223
             if ($onbasename < 0 && $hasbasename) {
224
-                $names[] = xoops_substr($basename, 0, 58, '') . $num;
224
+                $names[] = xoops_substr($basename, 0, 58, '').$num;
225 225
             } else {
226
-                $names[] = xoops_substr($emailname, 0, 58, '') . $num;
226
+                $names[] = xoops_substr($emailname, 0, 58, '').$num;
227 227
             }
228 228
             $i          = count($names);
229 229
             $onbasename = ~$onbasename;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
     {
266 266
         static $randCalled = false;
267 267
         if (!$randCalled) {
268
-            mt_srand((double)microtime() * 1000000);
268
+            mt_srand((double) microtime() * 1000000);
269 269
             $randCalled = true;
270 270
         }
271 271
     }
Please login to merge, or discard this patch.
class/smartmlobject.php 2 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -24,82 +24,82 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class SmartMlObject extends SmartObject
26 26
 {
27
-    /**
28
-     * SmartMlObject constructor.
29
-     */
30
-    public function __construct()
31
-    {
32
-        $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true);
33
-        $this->setControl('language', 'language');
34
-    }
35
-
36
-    /**
37
-     * If object is not new, change the control of the not-multilanguage fields
38
-     *
39
-     * We need to intercept this function from SmartObject because if the object is not new...
40
-     */
41
-    // function getForm() {
42
-
43
-    //}
44
-
45
-    /**
46
-     * Strip Multilanguage Fields
47
-     *
48
-     * Get rid of all the multilanguage fields to have an object with only global fields.
49
-     * This will be usefull when creating the ML object for the first time. Then we will be able
50
-     * to create translations.
51
-     */
52
-    public function stripMultilanguageFields()
53
-    {
54
-        $objectVars    =& $this->getVars();
55
-        $newObjectVars = array();
56
-        foreach ($objectVars as $key => $var) {
57
-            if (!$var['multilingual']) {
58
-                $newObjectVars[$key] = $var;
59
-            }
60
-        }
61
-        $this->vars = $newObjectVars;
62
-    }
63
-
64
-    public function stripNonMultilanguageFields()
65
-    {
66
-        $objectVars    =& $this->getVars();
67
-        $newObjectVars = array();
68
-        foreach ($objectVars as $key => $var) {
69
-            if ($var['multilingual'] || $key == $this->handler->keyName) {
70
-                $newObjectVars[$key] = $var;
71
-            }
72
-        }
73
-        $this->vars = $newObjectVars;
74
-    }
75
-
76
-    /**
77
-     * Make non multilanguage fields read only
78
-     *
79
-     * This is used when we are creating/editing a translation.
80
-     * We only want to edit the multilanguag fields, not the global one.
81
-     */
82
-    public function makeNonMLFieldReadOnly()
83
-    {
84
-        foreach ($this->getVars() as $key => $var) {
85
-            //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) {
86
-            if (!$var['multilingual'] && $key != $this->handler->keyName) {
87
-                $this->setControl($key, 'label');
88
-            }
89
-        }
90
-    }
91
-
92
-    /**
93
-     * @param  bool   $onlyUrl
94
-     * @param  bool   $withimage
95
-     * @return string
96
-     */
97
-    public function getEditLanguageLink($onlyUrl = false, $withimage = true)
98
-    {
99
-        $controller = new SmartObjectController($this->handler);
100
-
101
-        return $controller->getEditLanguageLink($this, $onlyUrl, $withimage);
102
-    }
27
+	/**
28
+	 * SmartMlObject constructor.
29
+	 */
30
+	public function __construct()
31
+	{
32
+		$this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true);
33
+		$this->setControl('language', 'language');
34
+	}
35
+
36
+	/**
37
+	 * If object is not new, change the control of the not-multilanguage fields
38
+	 *
39
+	 * We need to intercept this function from SmartObject because if the object is not new...
40
+	 */
41
+	// function getForm() {
42
+
43
+	//}
44
+
45
+	/**
46
+	 * Strip Multilanguage Fields
47
+	 *
48
+	 * Get rid of all the multilanguage fields to have an object with only global fields.
49
+	 * This will be usefull when creating the ML object for the first time. Then we will be able
50
+	 * to create translations.
51
+	 */
52
+	public function stripMultilanguageFields()
53
+	{
54
+		$objectVars    =& $this->getVars();
55
+		$newObjectVars = array();
56
+		foreach ($objectVars as $key => $var) {
57
+			if (!$var['multilingual']) {
58
+				$newObjectVars[$key] = $var;
59
+			}
60
+		}
61
+		$this->vars = $newObjectVars;
62
+	}
63
+
64
+	public function stripNonMultilanguageFields()
65
+	{
66
+		$objectVars    =& $this->getVars();
67
+		$newObjectVars = array();
68
+		foreach ($objectVars as $key => $var) {
69
+			if ($var['multilingual'] || $key == $this->handler->keyName) {
70
+				$newObjectVars[$key] = $var;
71
+			}
72
+		}
73
+		$this->vars = $newObjectVars;
74
+	}
75
+
76
+	/**
77
+	 * Make non multilanguage fields read only
78
+	 *
79
+	 * This is used when we are creating/editing a translation.
80
+	 * We only want to edit the multilanguag fields, not the global one.
81
+	 */
82
+	public function makeNonMLFieldReadOnly()
83
+	{
84
+		foreach ($this->getVars() as $key => $var) {
85
+			//if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) {
86
+			if (!$var['multilingual'] && $key != $this->handler->keyName) {
87
+				$this->setControl($key, 'label');
88
+			}
89
+		}
90
+	}
91
+
92
+	/**
93
+	 * @param  bool   $onlyUrl
94
+	 * @param  bool   $withimage
95
+	 * @return string
96
+	 */
97
+	public function getEditLanguageLink($onlyUrl = false, $withimage = true)
98
+	{
99
+		$controller = new SmartObjectController($this->handler);
100
+
101
+		return $controller->getEditLanguageLink($this, $onlyUrl, $withimage);
102
+	}
103 103
 }
104 104
 
105 105
 /**
@@ -107,70 +107,70 @@  discard block
 block discarded – undo
107 107
  */
108 108
 class SmartPersistableMlObjectHandler extends SmartPersistableObjectHandler
109 109
 {
110
-    /**
111
-     * @param  null  $criteria
112
-     * @param  bool  $id_as_key
113
-     * @param  bool  $as_object
114
-     * @param  bool  $debug
115
-     * @param  bool  $language
116
-     * @return array
117
-     */
118
-    public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $debug = false, $language = false)
119
-    {
120
-        // Create the first part of the SQL query to join the "_text" table
121
-        $sql = 'SELECT * FROM ' .
122
-               $this->table .
123
-               ' AS ' .
124
-               $this->_itemname .
125
-               ' INNER JOIN ' .
126
-               $this->table .
127
-               '_text AS ' .
128
-               $this->_itemname .
129
-               '_text ON ' .
130
-               $this->_itemname .
131
-               '.' .
132
-               $this->keyName .
133
-               '=' .
134
-               $this->_itemname .
135
-               '_text.' .
136
-               $this->keyName;
137
-
138
-        if ($language) {
139
-            // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language
140
-
141
-            // if no criteria was previously created, let's create it
142
-            if (!$criteria) {
143
-                $criteria = new CriteriaCompo();
144
-            }
145
-            $criteria->add(new Criteria('language', $language));
146
-
147
-            return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql);
148
-        }
149
-
150
-        return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql);
151
-    }
152
-
153
-    /**
154
-     * @param  mixed $id
155
-     * @param  bool  $language
156
-     * @param  bool  $as_object
157
-     * @param  bool  $debug
158
-     * @return mixed
159
-     */
160
-    public function &get($id, $language = false, $as_object = true, $debug = false)
161
-    {
162
-        if (!$language) {
163
-            return parent::get($id, $as_object, $debug);
164
-        } else {
165
-            $criteria = new CriteriaCompo();
166
-            $criteria->add(new Criteria('language', $language));
167
-
168
-            return parent::get($id, $as_object, $debug, $criteria);
169
-        }
170
-    }
171
-
172
-    public function changeTableNameForML()
173
-    {
174
-        $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text');
175
-    }
110
+	/**
111
+	 * @param  null  $criteria
112
+	 * @param  bool  $id_as_key
113
+	 * @param  bool  $as_object
114
+	 * @param  bool  $debug
115
+	 * @param  bool  $language
116
+	 * @return array
117
+	 */
118
+	public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $debug = false, $language = false)
119
+	{
120
+		// Create the first part of the SQL query to join the "_text" table
121
+		$sql = 'SELECT * FROM ' .
122
+			   $this->table .
123
+			   ' AS ' .
124
+			   $this->_itemname .
125
+			   ' INNER JOIN ' .
126
+			   $this->table .
127
+			   '_text AS ' .
128
+			   $this->_itemname .
129
+			   '_text ON ' .
130
+			   $this->_itemname .
131
+			   '.' .
132
+			   $this->keyName .
133
+			   '=' .
134
+			   $this->_itemname .
135
+			   '_text.' .
136
+			   $this->keyName;
137
+
138
+		if ($language) {
139
+			// If a language was specified, then let's create a WHERE clause to only return the objects associated with this language
140
+
141
+			// if no criteria was previously created, let's create it
142
+			if (!$criteria) {
143
+				$criteria = new CriteriaCompo();
144
+			}
145
+			$criteria->add(new Criteria('language', $language));
146
+
147
+			return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql);
148
+		}
149
+
150
+		return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql);
151
+	}
152
+
153
+	/**
154
+	 * @param  mixed $id
155
+	 * @param  bool  $language
156
+	 * @param  bool  $as_object
157
+	 * @param  bool  $debug
158
+	 * @return mixed
159
+	 */
160
+	public function &get($id, $language = false, $as_object = true, $debug = false)
161
+	{
162
+		if (!$language) {
163
+			return parent::get($id, $as_object, $debug);
164
+		} else {
165
+			$criteria = new CriteriaCompo();
166
+			$criteria->add(new Criteria('language', $language));
167
+
168
+			return parent::get($id, $as_object, $debug, $criteria);
169
+		}
170
+	}
171
+
172
+	public function changeTableNameForML()
173
+	{
174
+		$this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text');
175
+	}
176 176
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
14
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
14
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
15 15
 
16 16
 /**
17 17
  * SmartObject base Multilanguage-enabled class
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function stripMultilanguageFields()
53 53
     {
54
-        $objectVars    =& $this->getVars();
54
+        $objectVars    = & $this->getVars();
55 55
         $newObjectVars = array();
56 56
         foreach ($objectVars as $key => $var) {
57 57
             if (!$var['multilingual']) {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
     public function stripNonMultilanguageFields()
65 65
     {
66
-        $objectVars    =& $this->getVars();
66
+        $objectVars    = & $this->getVars();
67 67
         $newObjectVars = array();
68 68
         foreach ($objectVars as $key => $var) {
69 69
             if ($var['multilingual'] || $key == $this->handler->keyName) {
@@ -118,21 +118,21 @@  discard block
 block discarded – undo
118 118
     public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $debug = false, $language = false)
119 119
     {
120 120
         // Create the first part of the SQL query to join the "_text" table
121
-        $sql = 'SELECT * FROM ' .
122
-               $this->table .
123
-               ' AS ' .
124
-               $this->_itemname .
125
-               ' INNER JOIN ' .
126
-               $this->table .
127
-               '_text AS ' .
128
-               $this->_itemname .
129
-               '_text ON ' .
130
-               $this->_itemname .
131
-               '.' .
132
-               $this->keyName .
133
-               '=' .
134
-               $this->_itemname .
135
-               '_text.' .
121
+        $sql = 'SELECT * FROM '.
122
+               $this->table.
123
+               ' AS '.
124
+               $this->_itemname.
125
+               ' INNER JOIN '.
126
+               $this->table.
127
+               '_text AS '.
128
+               $this->_itemname.
129
+               '_text ON '.
130
+               $this->_itemname.
131
+               '.'.
132
+               $this->keyName.
133
+               '='.
134
+               $this->_itemname.
135
+               '_text.'.
136 136
                $this->keyName;
137 137
 
138 138
         if ($language) {
@@ -171,6 +171,6 @@  discard block
 block discarded – undo
171 171
 
172 172
     public function changeTableNameForML()
173 173
     {
174
-        $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text');
174
+        $this->table = $this->db->prefix($this->_moduleName.'_'.$this->_itemname.'_text');
175 175
     }
176 176
 }
Please login to merge, or discard this patch.
class/file.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class SmartobjectFile extends SmartobjectBasedUrl
10 10
 {
11
-    /**
12
-     * SmartobjectFile constructor.
13
-     */
14
-    public function __construct()
15
-    {
16
-        parent::__construct();
17
-        $this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME);
18
-    }
11
+	/**
12
+	 * SmartobjectFile constructor.
13
+	 */
14
+	public function __construct()
15
+	{
16
+		parent::__construct();
17
+		$this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME);
18
+	}
19 19
 }
20 20
 
21 21
 /**
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class SmartobjectFileHandler extends SmartPersistableObjectHandler
25 25
 {
26
-    /**
27
-     * SmartobjectFileHandler constructor.
28
-     * @param XoopsDatabase $db
29
-     */
30
-    public function __construct(XoopsDatabase $db)
31
-    {
32
-        parent::__construct($db, 'file', 'fileid', 'caption', 'desc', 'smartobject');
33
-    }
26
+	/**
27
+	 * SmartobjectFileHandler constructor.
28
+	 * @param XoopsDatabase $db
29
+	 */
30
+	public function __construct(XoopsDatabase $db)
31
+	{
32
+		parent::__construct($db, 'file', 'fileid', 'caption', 'desc', 'smartobject');
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
3 3
 
4
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/basedurl.php';
4
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/basedurl.php';
5 5
 
6 6
 /**
7 7
  * Class SmartobjectFile
Please login to merge, or discard this patch.