Completed
Push — master ( 88111b...b3fce7 )
by Michael
05:58
created
class/PersistableObjectHandler.php 2 patches
Indentation   +976 added lines, -976 removed lines patch added patch discarded remove patch
@@ -29,985 +29,985 @@
 block discarded – undo
29 29
 
30 30
 class PersistableObjectHandler extends \XoopsObjectHandler
31 31
 {
32
-    public $_itemname;
33
-
34
-    /**
35
-     * Name of the table use to store this {@link SmartObject}
36
-     *
37
-     * Note that the name of the table needs to be free of the database prefix.
38
-     * For example "smartsection_categories"
39
-     * @var string
40
-     */
41
-    public $table;
42
-
43
-    /**
44
-     * Name of the table key that uniquely identify each {@link SmartObject}
45
-     *
46
-     * For example: "categoryid"
47
-     * @var string
48
-     */
49
-    public $keyName;
50
-
51
-    /**
52
-     * Name of the class derived from {@link BaseSmartObject} and which this handler is handling
53
-     *
54
-     * Note that this string needs to be lowercase
55
-     *
56
-     * For example: "smartsectioncategory"
57
-     * @var string
58
-     */
59
-    public $className;
60
-
61
-    /**
62
-     * Name of the field which properly identify the {@link SmartObject}
63
-     *
64
-     * For example: "name" (this will be the category's name)
65
-     * @var string
66
-     */
67
-    public $identifierName;
68
-
69
-    /**
70
-     * Name of the field which will be use as a summary for the object
71
-     *
72
-     * For example: "summary"
73
-     * @var string
74
-     */
75
-    public $summaryName;
76
-
77
-    /**
78
-     * Page name use to basically manage and display the {@link SmartObject}
79
-     *
80
-     * This page needs to be the same in user side and admin side
81
-     *
82
-     * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
83
-     * @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
84
-     * @var string
85
-     */
86
-    public $_page;
87
-
88
-    /**
89
-     * Full path of the module using this {@link SmartObject}
90
-     *
91
-     * <code>XOOPS_URL . "/modules/smartsection/"</code>
92
-     * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
93
-     * @var string
94
-     */
95
-    public $_modulePath;
96
-
97
-    public $_moduleUrl;
98
-
99
-    public $_moduleName;
100
-
101
-    public $_uploadUrl;
102
-
103
-    public $_uploadPath;
104
-
105
-    public $_allowedMimeTypes = 0;
106
-
107
-    public $_maxFileSize = 1000000;
108
-
109
-    public $_maxWidth = 500;
110
-
111
-    public $_maxHeight = 500;
112
-
113
-    public $highlightFields = [];
114
-
115
-    /**
116
-     * Array containing the events name and functions
117
-     *
118
-     * @var array
119
-     */
120
-    public $eventArray = [];
121
-
122
-    /**
123
-     * Array containing the permissions that this handler will manage on the objects
124
-     *
125
-     * @var array
126
-     */
127
-    public $permissionsArray = false;
128
-
129
-    public $generalSQL = false;
130
-
131
-    public $_eventHooks     = [];
132
-    public $_disabledEvents = [];
133
-
134
-    /**
135
-     * Constructor - called from child classes
136
-     *
137
-     * @param \XoopsDatabase $db           {@link XoopsDatabase}
138
-     * @param string         $itemname     Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
139
-     * @param string         $keyname      Name of the table key that uniquely identify each {@link SmartObject}
140
-     * @param string         $idenfierName Name of the field which properly identify the {@link SmartObject}
141
-     * @param string         $summaryName
142
-     * @param string         $modulename
143
-     * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
144
-     * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
145
-     * @internal param string $moduleName name of the module
146
-     */
147
-    public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
148
-    {
149
-        parent::__construct($db);
150
-
151
-        $this->_itemname      = $itemname;
152
-        $this->_moduleName    = $modulename;
153
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
154
-        $this->keyName        = $keyname;
32
+	public $_itemname;
33
+
34
+	/**
35
+	 * Name of the table use to store this {@link SmartObject}
36
+	 *
37
+	 * Note that the name of the table needs to be free of the database prefix.
38
+	 * For example "smartsection_categories"
39
+	 * @var string
40
+	 */
41
+	public $table;
42
+
43
+	/**
44
+	 * Name of the table key that uniquely identify each {@link SmartObject}
45
+	 *
46
+	 * For example: "categoryid"
47
+	 * @var string
48
+	 */
49
+	public $keyName;
50
+
51
+	/**
52
+	 * Name of the class derived from {@link BaseSmartObject} and which this handler is handling
53
+	 *
54
+	 * Note that this string needs to be lowercase
55
+	 *
56
+	 * For example: "smartsectioncategory"
57
+	 * @var string
58
+	 */
59
+	public $className;
60
+
61
+	/**
62
+	 * Name of the field which properly identify the {@link SmartObject}
63
+	 *
64
+	 * For example: "name" (this will be the category's name)
65
+	 * @var string
66
+	 */
67
+	public $identifierName;
68
+
69
+	/**
70
+	 * Name of the field which will be use as a summary for the object
71
+	 *
72
+	 * For example: "summary"
73
+	 * @var string
74
+	 */
75
+	public $summaryName;
76
+
77
+	/**
78
+	 * Page name use to basically manage and display the {@link SmartObject}
79
+	 *
80
+	 * This page needs to be the same in user side and admin side
81
+	 *
82
+	 * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
83
+	 * @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
84
+	 * @var string
85
+	 */
86
+	public $_page;
87
+
88
+	/**
89
+	 * Full path of the module using this {@link SmartObject}
90
+	 *
91
+	 * <code>XOOPS_URL . "/modules/smartsection/"</code>
92
+	 * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
93
+	 * @var string
94
+	 */
95
+	public $_modulePath;
96
+
97
+	public $_moduleUrl;
98
+
99
+	public $_moduleName;
100
+
101
+	public $_uploadUrl;
102
+
103
+	public $_uploadPath;
104
+
105
+	public $_allowedMimeTypes = 0;
106
+
107
+	public $_maxFileSize = 1000000;
108
+
109
+	public $_maxWidth = 500;
110
+
111
+	public $_maxHeight = 500;
112
+
113
+	public $highlightFields = [];
114
+
115
+	/**
116
+	 * Array containing the events name and functions
117
+	 *
118
+	 * @var array
119
+	 */
120
+	public $eventArray = [];
121
+
122
+	/**
123
+	 * Array containing the permissions that this handler will manage on the objects
124
+	 *
125
+	 * @var array
126
+	 */
127
+	public $permissionsArray = false;
128
+
129
+	public $generalSQL = false;
130
+
131
+	public $_eventHooks     = [];
132
+	public $_disabledEvents = [];
133
+
134
+	/**
135
+	 * Constructor - called from child classes
136
+	 *
137
+	 * @param \XoopsDatabase $db           {@link XoopsDatabase}
138
+	 * @param string         $itemname     Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
139
+	 * @param string         $keyname      Name of the table key that uniquely identify each {@link SmartObject}
140
+	 * @param string         $idenfierName Name of the field which properly identify the {@link SmartObject}
141
+	 * @param string         $summaryName
142
+	 * @param string         $modulename
143
+	 * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
144
+	 * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
145
+	 * @internal param string $moduleName name of the module
146
+	 */
147
+	public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
148
+	{
149
+		parent::__construct($db);
150
+
151
+		$this->_itemname      = $itemname;
152
+		$this->_moduleName    = $modulename;
153
+		$this->table          = $db->prefix($modulename . '_' . $itemname);
154
+		$this->keyName        = $keyname;
155 155
 //        $this->className      = ucfirst($modulename) . ucfirst($itemname);
156
-        $this->className      = $itemname;
157
-
158
-        $this->identifierName = $idenfierName;
159
-        $this->summaryName    = $summaryName;
160
-        $this->_page          = $itemname . '.php';
161
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
162
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
163
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
164
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
165
-    }
166
-
167
-    /**
168
-     * @param $event
169
-     * @param $method
170
-     */
171
-    public function addEventHook($event, $method)
172
-    {
173
-        $this->_eventHooks[$event] = $method;
174
-    }
175
-
176
-    /**
177
-     * Add a permission that this handler will manage for its objects
178
-     *
179
-     * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
180
-     *
181
-     * @param string      $perm_name   name of the permission
182
-     * @param string      $caption     caption of the control that will be displayed in the form
183
-     * @param bool|string $description description of the control that will be displayed in the form
184
-     */
185
-    public function addPermission($perm_name, $caption, $description = false)
186
-    {
156
+		$this->className      = $itemname;
157
+
158
+		$this->identifierName = $idenfierName;
159
+		$this->summaryName    = $summaryName;
160
+		$this->_page          = $itemname . '.php';
161
+		$this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
162
+		$this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
163
+		$this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
164
+		$this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
165
+	}
166
+
167
+	/**
168
+	 * @param $event
169
+	 * @param $method
170
+	 */
171
+	public function addEventHook($event, $method)
172
+	{
173
+		$this->_eventHooks[$event] = $method;
174
+	}
175
+
176
+	/**
177
+	 * Add a permission that this handler will manage for its objects
178
+	 *
179
+	 * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
180
+	 *
181
+	 * @param string      $perm_name   name of the permission
182
+	 * @param string      $caption     caption of the control that will be displayed in the form
183
+	 * @param bool|string $description description of the control that will be displayed in the form
184
+	 */
185
+	public function addPermission($perm_name, $caption, $description = false)
186
+	{
187 187
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php';
188 188
 
189
-        $this->permissionsArray[] = [
190
-            'perm_name'   => $perm_name,
191
-            'caption'     => $caption,
192
-            'description' => $description
193
-        ];
194
-    }
195
-
196
-    /**
197
-     * @param $criteria
198
-     * @param $perm_name
199
-     * @return bool
200
-     */
201
-    public function setGrantedObjectsCriteria($criteria, $perm_name)
202
-    {
203
-        $smartPermissionsHandler = new PermissionHandler($this);
204
-        $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
205
-        if (count($grantedItems) > 0) {
206
-            $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
207
-
208
-            return true;
209
-        } else {
210
-            return false;
211
-        }
212
-    }
213
-
214
-    /**
215
-     * @param bool $_uploadPath
216
-     * @param bool $_allowedMimeTypes
217
-     * @param bool $_maxFileSize
218
-     * @param bool $_maxWidth
219
-     * @param bool $_maxHeight
220
-     */
221
-    public function setUploaderConfig(
222
-        $_uploadPath = false,
223
-        $_allowedMimeTypes = false,
224
-        $_maxFileSize = false,
225
-        $_maxWidth = false,
226
-        $_maxHeight = false
227
-    ) {
228
-        $this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
229
-        $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
230
-        $this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
231
-        $this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
232
-        $this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
233
-    }
234
-
235
-    /**
236
-     * create a new {@link Smartobject\BaseSmartObject}
237
-     *
238
-     * @param bool $isNew Flag the new objects as "new"?
239
-     *
240
-     * @return Smartobject\BaseSmartObject {@link Smartobject\BaseSmartObject}
241
-     */
242
-    public function create($isNew = true)
243
-    {
189
+		$this->permissionsArray[] = [
190
+			'perm_name'   => $perm_name,
191
+			'caption'     => $caption,
192
+			'description' => $description
193
+		];
194
+	}
195
+
196
+	/**
197
+	 * @param $criteria
198
+	 * @param $perm_name
199
+	 * @return bool
200
+	 */
201
+	public function setGrantedObjectsCriteria($criteria, $perm_name)
202
+	{
203
+		$smartPermissionsHandler = new PermissionHandler($this);
204
+		$grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
205
+		if (count($grantedItems) > 0) {
206
+			$criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
207
+
208
+			return true;
209
+		} else {
210
+			return false;
211
+		}
212
+	}
213
+
214
+	/**
215
+	 * @param bool $_uploadPath
216
+	 * @param bool $_allowedMimeTypes
217
+	 * @param bool $_maxFileSize
218
+	 * @param bool $_maxWidth
219
+	 * @param bool $_maxHeight
220
+	 */
221
+	public function setUploaderConfig(
222
+		$_uploadPath = false,
223
+		$_allowedMimeTypes = false,
224
+		$_maxFileSize = false,
225
+		$_maxWidth = false,
226
+		$_maxHeight = false
227
+	) {
228
+		$this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
229
+		$this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
230
+		$this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
231
+		$this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
232
+		$this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
233
+	}
234
+
235
+	/**
236
+	 * create a new {@link Smartobject\BaseSmartObject}
237
+	 *
238
+	 * @param bool $isNew Flag the new objects as "new"?
239
+	 *
240
+	 * @return Smartobject\BaseSmartObject {@link Smartobject\BaseSmartObject}
241
+	 */
242
+	public function create($isNew = true)
243
+	{
244 244
 //        $obj0 = new $this->className($this);
245 245
 
246
-        $obj =  new $this->className;
247
-
248
-        $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
249
-        if (!$obj->handler) {
250
-            $obj->Handler = $this;
251
-        }
252
-
253
-        if (true === $isNew) {
254
-            $obj->setNew();
255
-        }
256
-
257
-        return $obj;
258
-    }
259
-
260
-    /**
261
-     * @return string
262
-     */
263
-    public function getImageUrl()
264
-    {
265
-        return $this->_uploadUrl . $this->_itemname . '/';
266
-    }
267
-
268
-    /**
269
-     * @return string
270
-     */
271
-    public function getImagePath()
272
-    {
273
-        $dir = $this->_uploadPath . $this->_itemname;
274
-        if (!file_exists($dir)) {
275
-            Smartobject\Utility::mkdirAsAdmin($dir);
276
-        }
277
-
278
-        return $dir . '/';
279
-    }
280
-
281
-    /**
282
-     * retrieve a {@link SmartObject}
283
-     *
284
-     * @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
285
-     * @param  bool  $as_object whether to return an object or an array
286
-     * @param  bool  $debug
287
-     * @param  bool  $criteria
288
-     * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
289
-     *                          FALSE if failed
290
-     */
291
-    public function get($id, $as_object = true, $debug = false, $criteria = false)
292
-    {
293
-        if (!$criteria) {
294
-            $criteria = new \CriteriaCompo();
295
-        }
296
-        if (is_array($this->keyName)) {
297
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
298
-                /**
299
-                 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
300
-                 * Is the fact that we removed the (int)() represents a security risk ?
301
-                 */
302
-                //$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
303
-                $criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
304
-            }
305
-        } else {
306
-            //$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname);
307
-            /**
308
-             * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
309
-             * Is the fact that we removed the (int)() represents a security risk ?
310
-             */
311
-            $criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname));
312
-        }
313
-        $criteria->setLimit(1);
314
-        if ($debug) {
315
-            $obj_array = $this->getObjectsD($criteria, false, $as_object);
316
-        } else {
317
-            $obj_array =& $this->getObjects($criteria, false, $as_object);
318
-            //patch: weird bug of indexing by id even if id_as_key = false;
319
-            if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
320
-                $obj_array[0] = $obj_array[$id];
321
-                unset($obj_array[$id]);
322
-                $obj_array[0]->unsetNew();
323
-            }
324
-        }
325
-
326
-        if (1 != count($obj_array)) {
327
-            $obj = $this->create();
328
-
329
-            return $obj;
330
-        }
331
-
332
-        return $obj_array[0];
333
-    }
334
-
335
-    /**
336
-     * retrieve a {@link SmartObject}
337
-     *
338
-     * @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
339
-     * @param  bool  $as_object whether to return an object or an array
340
-     * @return mixed reference to the {@link SmartObject}, FALSE if failed
341
-     */
342
-    public function &getD($id, $as_object = true)
343
-    {
344
-        return $this->get($id, $as_object, true);
345
-    }
346
-
347
-    /**
348
-     * retrieve objects from the database
349
-     *
350
-     * @param null|\CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
351
-     * @param bool            $id_as_key use the ID as key for the array?
352
-     * @param bool            $as_object return an array of objects?
353
-     *
354
-     * @param  bool           $sql
355
-     * @param  bool           $debug
356
-     * @return array
357
-     */
358
-    public function getObjects(
359
-        \CriteriaElement $criteria = null,
360
-        $id_as_key = false,
361
-        $as_object = true,
362
-        $sql = false,
363
-        $debug = false
364
-    ) {
365
-        $ret   = [];
366
-        $limit = $start = 0;
367
-
368
-        if ($this->generalSQL) {
369
-            $sql = $this->generalSQL;
370
-        } elseif (!$sql) {
371
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
372
-        }
373
-
374
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
375
-            $sql .= ' ' . $criteria->renderWhere();
376
-            if ('' !== $criteria->getSort()) {
377
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
378
-            }
379
-            $limit = $criteria->getLimit();
380
-            $start = $criteria->getStart();
381
-        }
382
-        if ($debug) {
383
-            xoops_debug($sql);
384
-        }
385
-
386
-        $result = $this->db->query($sql, $limit, $start);
387
-        if (!$result) {
388
-            return $ret;
389
-        }
390
-
391
-        return $this->convertResultSet($result, $id_as_key, $as_object);
392
-    }
393
-
394
-    /**
395
-     * @param        $sql
396
-     * @param        $criteria
397
-     * @param  bool  $force
398
-     * @param  bool  $debug
399
-     * @return array
400
-     */
401
-    public function query($sql, $criteria, $force = false, $debug = false)
402
-    {
403
-        $ret = [];
404
-
405
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
406
-            $sql .= ' ' . $criteria->renderWhere();
407
-            if ($criteria->groupby) {
408
-                $sql .= $criteria->getGroupby();
409
-            }
410
-            if ('' !== $criteria->getSort()) {
411
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
412
-            }
413
-        }
414
-        if ($debug) {
415
-            xoops_debug($sql);
416
-        }
417
-
418
-        if ($force) {
419
-            $result = $this->db->queryF($sql);
420
-        } else {
421
-            $result = $this->db->query($sql);
422
-        }
423
-
424
-        if (!$result) {
425
-            return $ret;
426
-        }
427
-
428
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
429
-            $ret[] = $myrow;
430
-        }
431
-
432
-        return $ret;
433
-    }
434
-
435
-    /**
436
-     * retrieve objects with debug mode - so will show the query
437
-     *
438
-     * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
439
-     * @param bool            $id_as_key use the ID as key for the array?
440
-     * @param bool            $as_object return an array of objects?
441
-     *
442
-     * @param  bool           $sql
443
-     * @return array
444
-     */
445
-    public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
446
-    {
447
-        return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
448
-    }
449
-
450
-    /**
451
-     * @param $arrayObjects
452
-     * @return array|bool
453
-     */
454
-    public function getObjectsAsArray($arrayObjects)
455
-    {
456
-        $ret = [];
457
-        foreach ($arrayObjects as $key => $object) {
458
-            $ret[$key] = $object->toArray();
459
-        }
460
-        if (count($ret > 0)) {
461
-            return $ret;
462
-        } else {
463
-            return false;
464
-        }
465
-    }
466
-
467
-    /**
468
-     * Convert a database resultset to a returnable array
469
-     *
470
-     * @param object $result    database resultset
471
-     * @param bool   $id_as_key - should NOT be used with joint keys
472
-     * @param bool   $as_object
473
-     *
474
-     * @return array
475
-     */
476
-    public function convertResultSet($result, $id_as_key = false, $as_object = true)
477
-    {
478
-        $ret = [];
479
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
480
-            $obj = $this->create(false);
481
-            $obj->assignVars($myrow);
482
-            if (!$id_as_key) {
483
-                if ($as_object) {
484
-                    $ret[] =& $obj;
485
-                } else {
486
-                    $ret[] = $obj->toArray();
487
-                }
488
-            } else {
489
-                if ($as_object) {
490
-                    $value =& $obj;
491
-                } else {
492
-                    $value = $obj->toArray();
493
-                }
494
-                if ('parentid' === $id_as_key) {
495
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
496
-                } else {
497
-                    $ret[$obj->getVar($this->keyName)] = $value;
498
-                }
499
-            }
500
-            unset($obj);
501
-        }
502
-
503
-        return $ret;
504
-    }
505
-
506
-    /**
507
-     * @param  null $criteria
508
-     * @param  int  $limit
509
-     * @param  int  $start
510
-     * @return array
511
-     */
512
-    public function getListD($criteria = null, $limit = 0, $start = 0)
513
-    {
514
-        return $this->getList($criteria, $limit, $start, true);
515
-    }
516
-
517
-    /**
518
-     * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
519
-     *
520
-     * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
521
-     * @param int             $limit    Max number of objects to fetch
522
-     * @param int             $start    Which record to start at
523
-     *
524
-     * @param  bool           $debug
525
-     * @return array
526
-     */
527
-    public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
528
-    {
529
-        $ret = [];
530
-        if (null === $criteria) {
531
-            $criteria = new \CriteriaCompo();
532
-        }
533
-
534
-        if ('' === $criteria->getSort()) {
535
-            $criteria->setSort($this->getIdentifierName());
536
-        }
537
-
538
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
539
-        if (!empty($this->identifierName)) {
540
-            $sql .= ', ' . $this->getIdentifierName();
541
-        }
542
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
543
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
544
-            $sql .= ' ' . $criteria->renderWhere();
545
-            if ('' !== $criteria->getSort()) {
546
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
547
-            }
548
-            $limit = $criteria->getLimit();
549
-            $start = $criteria->getStart();
550
-        }
551
-
552
-        if ($debug) {
553
-            xoops_debug($sql);
554
-        }
555
-
556
-        $result = $this->db->query($sql, $limit, $start);
557
-        if (!$result) {
558
-            return $ret;
559
-        }
560
-
561
-        $myts = \MyTextSanitizer::getInstance();
562
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
563
-            //identifiers should be textboxes, so sanitize them like that
564
-            $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
565
-        }
566
-
567
-        return $ret;
568
-    }
569
-
570
-    /**
571
-     * count objects matching a condition
572
-     *
573
-     * @param  CriteriaElement $criteria {@link CriteriaElement} to match
574
-     * @return int             count of objects
575
-     */
576
-    public function getCount(CriteriaElement $criteria = null)
577
-    {
578
-        $field   = '';
579
-        $groupby = false;
580
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
581
-            if ('' !== $criteria->groupby) {
582
-                $groupby = true;
583
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
584
-            }
585
-        }
586
-        /**
587
-         * if we have a generalSQL, lets used this one.
588
-         * This needs to be improved...
589
-         */
590
-        if ($this->generalSQL) {
591
-            $sql = $this->generalSQL;
592
-            $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
593
-        } else {
594
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
595
-        }
596
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
597
-            $sql .= ' ' . $criteria->renderWhere();
598
-            if ('' !== $criteria->groupby) {
599
-                $sql .= $criteria->getGroupby();
600
-            }
601
-        }
602
-
603
-        $result = $this->db->query($sql);
604
-        if (!$result) {
605
-            return 0;
606
-        }
607
-        if (false === $groupby) {
608
-            list($count) = $this->db->fetchRow($result);
609
-
610
-            return $count;
611
-        } else {
612
-            $ret = [];
613
-            while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
614
-                $ret[$id] = $count;
615
-            }
616
-
617
-            return $ret;
618
-        }
619
-    }
620
-
621
-    /**
622
-     * delete an object from the database
623
-     *
624
-     * @param \XoopsObject $obj reference to the object to delete
625
-     * @param  bool        $force
626
-     * @return bool        FALSE if failed.
627
-     */
628
-    public function delete(\XoopsObject $obj, $force = false)
629
-    {
630
-        $eventResult = $this->executeEvent('beforeDelete', $obj);
631
-        if (!$eventResult) {
632
-            $obj->setErrors('An error occured during the BeforeDelete event');
633
-
634
-            return false;
635
-        }
636
-
637
-        if (is_array($this->keyName)) {
638
-            $clause = [];
639
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
640
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
641
-            }
642
-            $whereclause = implode(' AND ', $clause);
643
-        } else {
644
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
645
-        }
646
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
647
-        if (false !== $force) {
648
-            $result = $this->db->queryF($sql);
649
-        } else {
650
-            $result = $this->db->query($sql);
651
-        }
652
-        if (!$result) {
653
-            return false;
654
-        }
655
-
656
-        $eventResult = $this->executeEvent('afterDelete', $obj);
657
-        if (!$eventResult) {
658
-            $obj->setErrors('An error occured during the AfterDelete event');
659
-
660
-            return false;
661
-        }
662
-
663
-        return true;
664
-    }
665
-
666
-    /**
667
-     * @param $event
668
-     */
669
-    public function disableEvent($event)
670
-    {
671
-        if (is_array($event)) {
672
-            foreach ($event as $v) {
673
-                $this->_disabledEvents[] = $v;
674
-            }
675
-        } else {
676
-            $this->_disabledEvents[] = $event;
677
-        }
678
-    }
679
-
680
-    /**
681
-     * @return array
682
-     */
683
-    public function getPermissions()
684
-    {
685
-        return $this->permissionsArray;
686
-    }
687
-
688
-    /**
689
-     * insert a new object in the database
690
-     *
691
-     * @param \XoopsObject $obj         reference to the object
692
-     * @param  bool        $force       whether to force the query execution despite security settings
693
-     * @param  bool        $checkObject check if the object is dirty and clean the attributes
694
-     * @param  bool        $debug
695
-     * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
696
-     */
697
-    public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
698
-    {
699
-        if (false !== $checkObject) {
700
-            if (!is_object($obj)) {
701
-                return false;
702
-            }
703
-            /**
704
-             * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
705
-             */
706
-            if (!is_a($obj, $this->className)) {
707
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
708
-
709
-                return false;
710
-            }
711
-            if (!$obj->isDirty()) {
712
-                $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
713
-
714
-                return true;
715
-            }
716
-        }
717
-
718
-        if ($obj->seoEnabled) {
719
-            // Auto create meta tags if empty
720
-            $smartobjectMetagen = new MetaGen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
721
-
722
-            if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
723
-                if (!$obj->meta_keywords()) {
724
-                    $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
725
-                }
726
-
727
-                if (!$obj->meta_description()) {
728
-                    $obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
729
-                }
730
-            }
731
-
732
-            // Auto create short_url if empty
733
-            if (!$obj->short_url()) {
734
-                $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
735
-            }
736
-        }
737
-
738
-        $eventResult = $this->executeEvent('beforeSave', $obj);
739
-        if (!$eventResult) {
740
-            $obj->setErrors('An error occured during the BeforeSave event');
741
-
742
-            return false;
743
-        }
744
-
745
-        if ($obj->isNew()) {
746
-            $eventResult = $this->executeEvent('beforeInsert', $obj);
747
-            if (!$eventResult) {
748
-                $obj->setErrors('An error occured during the BeforeInsert event');
749
-
750
-                return false;
751
-            }
752
-        } else {
753
-            $eventResult = $this->executeEvent('beforeUpdate', $obj);
754
-            if (!$eventResult) {
755
-                $obj->setErrors('An error occured during the BeforeUpdate event');
756
-
757
-                return false;
758
-            }
759
-        }
760
-        if (!$obj->cleanVars()) {
761
-            $obj->setErrors('Variables were not cleaned properly.');
762
-
763
-            return false;
764
-        }
765
-        $fieldsToStoreInDB = [];
766
-        foreach ($obj->cleanVars as $k => $v) {
767
-            if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) {
768
-                $cleanvars[$k] = (int)$v;
769
-            } elseif (is_array($v)) {
770
-                $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
771
-            } else {
772
-                $cleanvars[$k] = $this->db->quoteString($v);
773
-            }
774
-            if ($obj->vars[$k]['persistent']) {
775
-                $fieldsToStoreInDB[$k] = $cleanvars[$k];
776
-            }
777
-        }
778
-        if ($obj->isNew()) {
779
-            if (!is_array($this->keyName)) {
780
-                if ($cleanvars[$this->keyName] < 1) {
781
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
782
-                }
783
-            }
784
-
785
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
786
-        } else {
787
-            $sql = 'UPDATE ' . $this->table . ' SET';
788
-            foreach ($fieldsToStoreInDB as $key => $value) {
789
-                if ((!is_array($this->keyName) && $key == $this->keyName)
790
-                    || (is_array($this->keyName)
791
-                        && in_array($key, $this->keyName))) {
792
-                    continue;
793
-                }
794
-                if (isset($notfirst)) {
795
-                    $sql .= ',';
796
-                }
797
-                $sql      .= ' ' . $key . ' = ' . $value;
798
-                $notfirst = true;
799
-            }
800
-            if (is_array($this->keyName)) {
801
-                $whereclause = '';
802
-                for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
803
-                    if ($i > 0) {
804
-                        $whereclause .= ' AND ';
805
-                    }
806
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
807
-                }
808
-            } else {
809
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
810
-            }
811
-            $sql .= ' WHERE ' . $whereclause;
812
-        }
813
-
814
-        if ($debug) {
815
-            xoops_debug($sql);
816
-        }
817
-
818
-        if (false !== $force) {
819
-            $result = $this->db->queryF($sql);
820
-        } else {
821
-            $result = $this->db->query($sql);
822
-        }
823
-
824
-        if (!$result) {
825
-            $obj->setErrors($this->db->error());
826
-
827
-            return false;
828
-        }
829
-
830
-        if ($obj->isNew() && !is_array($this->keyName)) {
831
-            $obj->assignVar($this->keyName, $this->db->getInsertId());
832
-        }
833
-        $eventResult = $this->executeEvent('afterSave', $obj);
834
-        if (!$eventResult) {
835
-            $obj->setErrors('An error occured during the AfterSave event');
836
-
837
-            return false;
838
-        }
839
-
840
-        if ($obj->isNew()) {
841
-            $obj->unsetNew();
842
-            $eventResult = $this->executeEvent('afterInsert', $obj);
843
-            if (!$eventResult) {
844
-                $obj->setErrors('An error occured during the AfterInsert event');
845
-
846
-                return false;
847
-            }
848
-        } else {
849
-            $eventResult = $this->executeEvent('afterUpdate', $obj);
850
-            if (!$eventResult) {
851
-                $obj->setErrors('An error occured during the AfterUpdate event');
852
-
853
-                return false;
854
-            }
855
-        }
856
-
857
-        return true;
858
-    }
859
-
860
-    /**
861
-     * @param       $obj
862
-     * @param  bool $force
863
-     * @param  bool $checkObject
864
-     * @param  bool $debug
865
-     * @return bool
866
-     */
867
-    public function insertD($obj, $force = false, $checkObject = true, $debug = false)
868
-    {
869
-        return $this->insert($obj, $force, $checkObject, true);
870
-    }
871
-
872
-    /**
873
-     * Change a value for objects with a certain criteria
874
-     *
875
-     * @param string          $fieldname  Name of the field
876
-     * @param string          $fieldvalue Value to write
877
-     * @param CriteriaElement $criteria   {@link CriteriaElement}
878
-     *
879
-     * @param  bool           $force
880
-     * @return bool
881
-     */
882
-    public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
883
-    {
884
-        $set_clause = $fieldname . ' = ';
885
-        if (is_numeric($fieldvalue)) {
886
-            $set_clause .= $fieldvalue;
887
-        } elseif (is_array($fieldvalue)) {
888
-            $set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
889
-        } else {
890
-            $set_clause .= $this->db->quoteString($fieldvalue);
891
-        }
892
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
893
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
894
-            $sql .= ' ' . $criteria->renderWhere();
895
-        }
896
-        if (false !== $force) {
897
-            $result = $this->db->queryF($sql);
898
-        } else {
899
-            $result = $this->db->query($sql);
900
-        }
901
-        if (!$result) {
902
-            return false;
903
-        }
904
-
905
-        return true;
906
-    }
907
-
908
-    /**
909
-     * delete all objects meeting the conditions
910
-     *
911
-     * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
912
-     * @return bool
913
-     */
914
-
915
-    public function deleteAll(CriteriaElement $criteria = null)
916
-    {
917
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
918
-            $sql = 'DELETE FROM ' . $this->table;
919
-            $sql .= ' ' . $criteria->renderWhere();
920
-            if (!$this->db->query($sql)) {
921
-                return false;
922
-            }
923
-            $rows = $this->db->getAffectedRows();
924
-
925
-            return $rows > 0 ? $rows : true;
926
-        }
927
-
928
-        return false;
929
-    }
930
-
931
-    /**
932
-     * @return mixed
933
-     */
934
-    public function getModuleInfo()
935
-    {
936
-        return Smartobject\Utility::getModuleInfo($this->_moduleName);
937
-    }
938
-
939
-    /**
940
-     * @return bool
941
-     */
942
-    public function getModuleConfig()
943
-    {
944
-        return Smartobject\Utility::getModuleConfig($this->_moduleName);
945
-    }
946
-
947
-    /**
948
-     * @return string
949
-     */
950
-    public function getModuleItemString()
951
-    {
952
-        $ret = $this->_moduleName . '_' . $this->_itemname;
953
-
954
-        return $ret;
955
-    }
956
-
957
-    /**
958
-     * @param $object
959
-     */
960
-    public function updateCounter($object)
961
-    {
962
-        if (isset($object->vars['counter'])) {
963
-            $new_counter = $object->getVar('counter') + 1;
964
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
965
-            $this->query($sql, null, true);
966
-        }
967
-    }
968
-
969
-    /**
970
-     * Execute the function associated with an event
971
-     * This method will check if the function is available
972
-     *
973
-     * @param  string $event name of the event
974
-     * @param         $executeEventObj
975
-     * @return mixed  result of the execution of the function or FALSE if the function was not executed
976
-     * @internal param object $obj $object on which is performed the event
977
-     */
978
-    public function executeEvent($event, &$executeEventObj)
979
-    {
980
-        if (!in_array($event, $this->_disabledEvents)) {
981
-            if (method_exists($this, $event)) {
982
-                $ret = $this->$event($executeEventObj);
983
-            } else {
984
-                // check to see if there is a hook for this event
985
-                if (isset($this->_eventHooks[$event])) {
986
-                    $method = $this->_eventHooks[$event];
987
-                    // check to see if the method specified by this hook exists
988
-                    if (method_exists($this, $method)) {
989
-                        $ret = $this->$method($executeEventObj);
990
-                    }
991
-                }
992
-                $ret = true;
993
-            }
994
-
995
-            return $ret;
996
-        }
997
-
998
-        return true;
999
-    }
1000
-
1001
-    /**
1002
-     * @param  bool $withprefix
1003
-     * @return string
1004
-     */
1005
-    public function getIdentifierName($withprefix = true)
1006
-    {
1007
-        if ($withprefix) {
1008
-            return $this->_itemname . '.' . $this->identifierName;
1009
-        } else {
1010
-            return $this->identifierName;
1011
-        }
1012
-    }
246
+		$obj =  new $this->className;
247
+
248
+		$obj->setImageDir($this->getImageUrl(), $this->getImagePath());
249
+		if (!$obj->handler) {
250
+			$obj->Handler = $this;
251
+		}
252
+
253
+		if (true === $isNew) {
254
+			$obj->setNew();
255
+		}
256
+
257
+		return $obj;
258
+	}
259
+
260
+	/**
261
+	 * @return string
262
+	 */
263
+	public function getImageUrl()
264
+	{
265
+		return $this->_uploadUrl . $this->_itemname . '/';
266
+	}
267
+
268
+	/**
269
+	 * @return string
270
+	 */
271
+	public function getImagePath()
272
+	{
273
+		$dir = $this->_uploadPath . $this->_itemname;
274
+		if (!file_exists($dir)) {
275
+			Smartobject\Utility::mkdirAsAdmin($dir);
276
+		}
277
+
278
+		return $dir . '/';
279
+	}
280
+
281
+	/**
282
+	 * retrieve a {@link SmartObject}
283
+	 *
284
+	 * @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
285
+	 * @param  bool  $as_object whether to return an object or an array
286
+	 * @param  bool  $debug
287
+	 * @param  bool  $criteria
288
+	 * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
289
+	 *                          FALSE if failed
290
+	 */
291
+	public function get($id, $as_object = true, $debug = false, $criteria = false)
292
+	{
293
+		if (!$criteria) {
294
+			$criteria = new \CriteriaCompo();
295
+		}
296
+		if (is_array($this->keyName)) {
297
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
298
+				/**
299
+				 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
300
+				 * Is the fact that we removed the (int)() represents a security risk ?
301
+				 */
302
+				//$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
303
+				$criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
304
+			}
305
+		} else {
306
+			//$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname);
307
+			/**
308
+			 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
309
+			 * Is the fact that we removed the (int)() represents a security risk ?
310
+			 */
311
+			$criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname));
312
+		}
313
+		$criteria->setLimit(1);
314
+		if ($debug) {
315
+			$obj_array = $this->getObjectsD($criteria, false, $as_object);
316
+		} else {
317
+			$obj_array =& $this->getObjects($criteria, false, $as_object);
318
+			//patch: weird bug of indexing by id even if id_as_key = false;
319
+			if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
320
+				$obj_array[0] = $obj_array[$id];
321
+				unset($obj_array[$id]);
322
+				$obj_array[0]->unsetNew();
323
+			}
324
+		}
325
+
326
+		if (1 != count($obj_array)) {
327
+			$obj = $this->create();
328
+
329
+			return $obj;
330
+		}
331
+
332
+		return $obj_array[0];
333
+	}
334
+
335
+	/**
336
+	 * retrieve a {@link SmartObject}
337
+	 *
338
+	 * @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
339
+	 * @param  bool  $as_object whether to return an object or an array
340
+	 * @return mixed reference to the {@link SmartObject}, FALSE if failed
341
+	 */
342
+	public function &getD($id, $as_object = true)
343
+	{
344
+		return $this->get($id, $as_object, true);
345
+	}
346
+
347
+	/**
348
+	 * retrieve objects from the database
349
+	 *
350
+	 * @param null|\CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
351
+	 * @param bool            $id_as_key use the ID as key for the array?
352
+	 * @param bool            $as_object return an array of objects?
353
+	 *
354
+	 * @param  bool           $sql
355
+	 * @param  bool           $debug
356
+	 * @return array
357
+	 */
358
+	public function getObjects(
359
+		\CriteriaElement $criteria = null,
360
+		$id_as_key = false,
361
+		$as_object = true,
362
+		$sql = false,
363
+		$debug = false
364
+	) {
365
+		$ret   = [];
366
+		$limit = $start = 0;
367
+
368
+		if ($this->generalSQL) {
369
+			$sql = $this->generalSQL;
370
+		} elseif (!$sql) {
371
+			$sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
372
+		}
373
+
374
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
375
+			$sql .= ' ' . $criteria->renderWhere();
376
+			if ('' !== $criteria->getSort()) {
377
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
378
+			}
379
+			$limit = $criteria->getLimit();
380
+			$start = $criteria->getStart();
381
+		}
382
+		if ($debug) {
383
+			xoops_debug($sql);
384
+		}
385
+
386
+		$result = $this->db->query($sql, $limit, $start);
387
+		if (!$result) {
388
+			return $ret;
389
+		}
390
+
391
+		return $this->convertResultSet($result, $id_as_key, $as_object);
392
+	}
393
+
394
+	/**
395
+	 * @param        $sql
396
+	 * @param        $criteria
397
+	 * @param  bool  $force
398
+	 * @param  bool  $debug
399
+	 * @return array
400
+	 */
401
+	public function query($sql, $criteria, $force = false, $debug = false)
402
+	{
403
+		$ret = [];
404
+
405
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
406
+			$sql .= ' ' . $criteria->renderWhere();
407
+			if ($criteria->groupby) {
408
+				$sql .= $criteria->getGroupby();
409
+			}
410
+			if ('' !== $criteria->getSort()) {
411
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
412
+			}
413
+		}
414
+		if ($debug) {
415
+			xoops_debug($sql);
416
+		}
417
+
418
+		if ($force) {
419
+			$result = $this->db->queryF($sql);
420
+		} else {
421
+			$result = $this->db->query($sql);
422
+		}
423
+
424
+		if (!$result) {
425
+			return $ret;
426
+		}
427
+
428
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
429
+			$ret[] = $myrow;
430
+		}
431
+
432
+		return $ret;
433
+	}
434
+
435
+	/**
436
+	 * retrieve objects with debug mode - so will show the query
437
+	 *
438
+	 * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
439
+	 * @param bool            $id_as_key use the ID as key for the array?
440
+	 * @param bool            $as_object return an array of objects?
441
+	 *
442
+	 * @param  bool           $sql
443
+	 * @return array
444
+	 */
445
+	public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
446
+	{
447
+		return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
448
+	}
449
+
450
+	/**
451
+	 * @param $arrayObjects
452
+	 * @return array|bool
453
+	 */
454
+	public function getObjectsAsArray($arrayObjects)
455
+	{
456
+		$ret = [];
457
+		foreach ($arrayObjects as $key => $object) {
458
+			$ret[$key] = $object->toArray();
459
+		}
460
+		if (count($ret > 0)) {
461
+			return $ret;
462
+		} else {
463
+			return false;
464
+		}
465
+	}
466
+
467
+	/**
468
+	 * Convert a database resultset to a returnable array
469
+	 *
470
+	 * @param object $result    database resultset
471
+	 * @param bool   $id_as_key - should NOT be used with joint keys
472
+	 * @param bool   $as_object
473
+	 *
474
+	 * @return array
475
+	 */
476
+	public function convertResultSet($result, $id_as_key = false, $as_object = true)
477
+	{
478
+		$ret = [];
479
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
480
+			$obj = $this->create(false);
481
+			$obj->assignVars($myrow);
482
+			if (!$id_as_key) {
483
+				if ($as_object) {
484
+					$ret[] =& $obj;
485
+				} else {
486
+					$ret[] = $obj->toArray();
487
+				}
488
+			} else {
489
+				if ($as_object) {
490
+					$value =& $obj;
491
+				} else {
492
+					$value = $obj->toArray();
493
+				}
494
+				if ('parentid' === $id_as_key) {
495
+					$ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
496
+				} else {
497
+					$ret[$obj->getVar($this->keyName)] = $value;
498
+				}
499
+			}
500
+			unset($obj);
501
+		}
502
+
503
+		return $ret;
504
+	}
505
+
506
+	/**
507
+	 * @param  null $criteria
508
+	 * @param  int  $limit
509
+	 * @param  int  $start
510
+	 * @return array
511
+	 */
512
+	public function getListD($criteria = null, $limit = 0, $start = 0)
513
+	{
514
+		return $this->getList($criteria, $limit, $start, true);
515
+	}
516
+
517
+	/**
518
+	 * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
519
+	 *
520
+	 * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
521
+	 * @param int             $limit    Max number of objects to fetch
522
+	 * @param int             $start    Which record to start at
523
+	 *
524
+	 * @param  bool           $debug
525
+	 * @return array
526
+	 */
527
+	public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
528
+	{
529
+		$ret = [];
530
+		if (null === $criteria) {
531
+			$criteria = new \CriteriaCompo();
532
+		}
533
+
534
+		if ('' === $criteria->getSort()) {
535
+			$criteria->setSort($this->getIdentifierName());
536
+		}
537
+
538
+		$sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
539
+		if (!empty($this->identifierName)) {
540
+			$sql .= ', ' . $this->getIdentifierName();
541
+		}
542
+		$sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
543
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
544
+			$sql .= ' ' . $criteria->renderWhere();
545
+			if ('' !== $criteria->getSort()) {
546
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
547
+			}
548
+			$limit = $criteria->getLimit();
549
+			$start = $criteria->getStart();
550
+		}
551
+
552
+		if ($debug) {
553
+			xoops_debug($sql);
554
+		}
555
+
556
+		$result = $this->db->query($sql, $limit, $start);
557
+		if (!$result) {
558
+			return $ret;
559
+		}
560
+
561
+		$myts = \MyTextSanitizer::getInstance();
562
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
563
+			//identifiers should be textboxes, so sanitize them like that
564
+			$ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
565
+		}
566
+
567
+		return $ret;
568
+	}
569
+
570
+	/**
571
+	 * count objects matching a condition
572
+	 *
573
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} to match
574
+	 * @return int             count of objects
575
+	 */
576
+	public function getCount(CriteriaElement $criteria = null)
577
+	{
578
+		$field   = '';
579
+		$groupby = false;
580
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
581
+			if ('' !== $criteria->groupby) {
582
+				$groupby = true;
583
+				$field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
584
+			}
585
+		}
586
+		/**
587
+		 * if we have a generalSQL, lets used this one.
588
+		 * This needs to be improved...
589
+		 */
590
+		if ($this->generalSQL) {
591
+			$sql = $this->generalSQL;
592
+			$sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
593
+		} else {
594
+			$sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
595
+		}
596
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
597
+			$sql .= ' ' . $criteria->renderWhere();
598
+			if ('' !== $criteria->groupby) {
599
+				$sql .= $criteria->getGroupby();
600
+			}
601
+		}
602
+
603
+		$result = $this->db->query($sql);
604
+		if (!$result) {
605
+			return 0;
606
+		}
607
+		if (false === $groupby) {
608
+			list($count) = $this->db->fetchRow($result);
609
+
610
+			return $count;
611
+		} else {
612
+			$ret = [];
613
+			while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
614
+				$ret[$id] = $count;
615
+			}
616
+
617
+			return $ret;
618
+		}
619
+	}
620
+
621
+	/**
622
+	 * delete an object from the database
623
+	 *
624
+	 * @param \XoopsObject $obj reference to the object to delete
625
+	 * @param  bool        $force
626
+	 * @return bool        FALSE if failed.
627
+	 */
628
+	public function delete(\XoopsObject $obj, $force = false)
629
+	{
630
+		$eventResult = $this->executeEvent('beforeDelete', $obj);
631
+		if (!$eventResult) {
632
+			$obj->setErrors('An error occured during the BeforeDelete event');
633
+
634
+			return false;
635
+		}
636
+
637
+		if (is_array($this->keyName)) {
638
+			$clause = [];
639
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
640
+				$clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
641
+			}
642
+			$whereclause = implode(' AND ', $clause);
643
+		} else {
644
+			$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
645
+		}
646
+		$sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
647
+		if (false !== $force) {
648
+			$result = $this->db->queryF($sql);
649
+		} else {
650
+			$result = $this->db->query($sql);
651
+		}
652
+		if (!$result) {
653
+			return false;
654
+		}
655
+
656
+		$eventResult = $this->executeEvent('afterDelete', $obj);
657
+		if (!$eventResult) {
658
+			$obj->setErrors('An error occured during the AfterDelete event');
659
+
660
+			return false;
661
+		}
662
+
663
+		return true;
664
+	}
665
+
666
+	/**
667
+	 * @param $event
668
+	 */
669
+	public function disableEvent($event)
670
+	{
671
+		if (is_array($event)) {
672
+			foreach ($event as $v) {
673
+				$this->_disabledEvents[] = $v;
674
+			}
675
+		} else {
676
+			$this->_disabledEvents[] = $event;
677
+		}
678
+	}
679
+
680
+	/**
681
+	 * @return array
682
+	 */
683
+	public function getPermissions()
684
+	{
685
+		return $this->permissionsArray;
686
+	}
687
+
688
+	/**
689
+	 * insert a new object in the database
690
+	 *
691
+	 * @param \XoopsObject $obj         reference to the object
692
+	 * @param  bool        $force       whether to force the query execution despite security settings
693
+	 * @param  bool        $checkObject check if the object is dirty and clean the attributes
694
+	 * @param  bool        $debug
695
+	 * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
696
+	 */
697
+	public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
698
+	{
699
+		if (false !== $checkObject) {
700
+			if (!is_object($obj)) {
701
+				return false;
702
+			}
703
+			/**
704
+			 * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
705
+			 */
706
+			if (!is_a($obj, $this->className)) {
707
+				$obj->setError(get_class($obj) . ' Differs from ' . $this->className);
708
+
709
+				return false;
710
+			}
711
+			if (!$obj->isDirty()) {
712
+				$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
713
+
714
+				return true;
715
+			}
716
+		}
717
+
718
+		if ($obj->seoEnabled) {
719
+			// Auto create meta tags if empty
720
+			$smartobjectMetagen = new MetaGen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
721
+
722
+			if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
723
+				if (!$obj->meta_keywords()) {
724
+					$obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
725
+				}
726
+
727
+				if (!$obj->meta_description()) {
728
+					$obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
729
+				}
730
+			}
731
+
732
+			// Auto create short_url if empty
733
+			if (!$obj->short_url()) {
734
+				$obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
735
+			}
736
+		}
737
+
738
+		$eventResult = $this->executeEvent('beforeSave', $obj);
739
+		if (!$eventResult) {
740
+			$obj->setErrors('An error occured during the BeforeSave event');
741
+
742
+			return false;
743
+		}
744
+
745
+		if ($obj->isNew()) {
746
+			$eventResult = $this->executeEvent('beforeInsert', $obj);
747
+			if (!$eventResult) {
748
+				$obj->setErrors('An error occured during the BeforeInsert event');
749
+
750
+				return false;
751
+			}
752
+		} else {
753
+			$eventResult = $this->executeEvent('beforeUpdate', $obj);
754
+			if (!$eventResult) {
755
+				$obj->setErrors('An error occured during the BeforeUpdate event');
756
+
757
+				return false;
758
+			}
759
+		}
760
+		if (!$obj->cleanVars()) {
761
+			$obj->setErrors('Variables were not cleaned properly.');
762
+
763
+			return false;
764
+		}
765
+		$fieldsToStoreInDB = [];
766
+		foreach ($obj->cleanVars as $k => $v) {
767
+			if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) {
768
+				$cleanvars[$k] = (int)$v;
769
+			} elseif (is_array($v)) {
770
+				$cleanvars[$k] = $this->db->quoteString(implode(',', $v));
771
+			} else {
772
+				$cleanvars[$k] = $this->db->quoteString($v);
773
+			}
774
+			if ($obj->vars[$k]['persistent']) {
775
+				$fieldsToStoreInDB[$k] = $cleanvars[$k];
776
+			}
777
+		}
778
+		if ($obj->isNew()) {
779
+			if (!is_array($this->keyName)) {
780
+				if ($cleanvars[$this->keyName] < 1) {
781
+					$cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
782
+				}
783
+			}
784
+
785
+			$sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
786
+		} else {
787
+			$sql = 'UPDATE ' . $this->table . ' SET';
788
+			foreach ($fieldsToStoreInDB as $key => $value) {
789
+				if ((!is_array($this->keyName) && $key == $this->keyName)
790
+					|| (is_array($this->keyName)
791
+						&& in_array($key, $this->keyName))) {
792
+					continue;
793
+				}
794
+				if (isset($notfirst)) {
795
+					$sql .= ',';
796
+				}
797
+				$sql      .= ' ' . $key . ' = ' . $value;
798
+				$notfirst = true;
799
+			}
800
+			if (is_array($this->keyName)) {
801
+				$whereclause = '';
802
+				for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
803
+					if ($i > 0) {
804
+						$whereclause .= ' AND ';
805
+					}
806
+					$whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
807
+				}
808
+			} else {
809
+				$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
810
+			}
811
+			$sql .= ' WHERE ' . $whereclause;
812
+		}
813
+
814
+		if ($debug) {
815
+			xoops_debug($sql);
816
+		}
817
+
818
+		if (false !== $force) {
819
+			$result = $this->db->queryF($sql);
820
+		} else {
821
+			$result = $this->db->query($sql);
822
+		}
823
+
824
+		if (!$result) {
825
+			$obj->setErrors($this->db->error());
826
+
827
+			return false;
828
+		}
829
+
830
+		if ($obj->isNew() && !is_array($this->keyName)) {
831
+			$obj->assignVar($this->keyName, $this->db->getInsertId());
832
+		}
833
+		$eventResult = $this->executeEvent('afterSave', $obj);
834
+		if (!$eventResult) {
835
+			$obj->setErrors('An error occured during the AfterSave event');
836
+
837
+			return false;
838
+		}
839
+
840
+		if ($obj->isNew()) {
841
+			$obj->unsetNew();
842
+			$eventResult = $this->executeEvent('afterInsert', $obj);
843
+			if (!$eventResult) {
844
+				$obj->setErrors('An error occured during the AfterInsert event');
845
+
846
+				return false;
847
+			}
848
+		} else {
849
+			$eventResult = $this->executeEvent('afterUpdate', $obj);
850
+			if (!$eventResult) {
851
+				$obj->setErrors('An error occured during the AfterUpdate event');
852
+
853
+				return false;
854
+			}
855
+		}
856
+
857
+		return true;
858
+	}
859
+
860
+	/**
861
+	 * @param       $obj
862
+	 * @param  bool $force
863
+	 * @param  bool $checkObject
864
+	 * @param  bool $debug
865
+	 * @return bool
866
+	 */
867
+	public function insertD($obj, $force = false, $checkObject = true, $debug = false)
868
+	{
869
+		return $this->insert($obj, $force, $checkObject, true);
870
+	}
871
+
872
+	/**
873
+	 * Change a value for objects with a certain criteria
874
+	 *
875
+	 * @param string          $fieldname  Name of the field
876
+	 * @param string          $fieldvalue Value to write
877
+	 * @param CriteriaElement $criteria   {@link CriteriaElement}
878
+	 *
879
+	 * @param  bool           $force
880
+	 * @return bool
881
+	 */
882
+	public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
883
+	{
884
+		$set_clause = $fieldname . ' = ';
885
+		if (is_numeric($fieldvalue)) {
886
+			$set_clause .= $fieldvalue;
887
+		} elseif (is_array($fieldvalue)) {
888
+			$set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
889
+		} else {
890
+			$set_clause .= $this->db->quoteString($fieldvalue);
891
+		}
892
+		$sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
893
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
894
+			$sql .= ' ' . $criteria->renderWhere();
895
+		}
896
+		if (false !== $force) {
897
+			$result = $this->db->queryF($sql);
898
+		} else {
899
+			$result = $this->db->query($sql);
900
+		}
901
+		if (!$result) {
902
+			return false;
903
+		}
904
+
905
+		return true;
906
+	}
907
+
908
+	/**
909
+	 * delete all objects meeting the conditions
910
+	 *
911
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
912
+	 * @return bool
913
+	 */
914
+
915
+	public function deleteAll(CriteriaElement $criteria = null)
916
+	{
917
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
918
+			$sql = 'DELETE FROM ' . $this->table;
919
+			$sql .= ' ' . $criteria->renderWhere();
920
+			if (!$this->db->query($sql)) {
921
+				return false;
922
+			}
923
+			$rows = $this->db->getAffectedRows();
924
+
925
+			return $rows > 0 ? $rows : true;
926
+		}
927
+
928
+		return false;
929
+	}
930
+
931
+	/**
932
+	 * @return mixed
933
+	 */
934
+	public function getModuleInfo()
935
+	{
936
+		return Smartobject\Utility::getModuleInfo($this->_moduleName);
937
+	}
938
+
939
+	/**
940
+	 * @return bool
941
+	 */
942
+	public function getModuleConfig()
943
+	{
944
+		return Smartobject\Utility::getModuleConfig($this->_moduleName);
945
+	}
946
+
947
+	/**
948
+	 * @return string
949
+	 */
950
+	public function getModuleItemString()
951
+	{
952
+		$ret = $this->_moduleName . '_' . $this->_itemname;
953
+
954
+		return $ret;
955
+	}
956
+
957
+	/**
958
+	 * @param $object
959
+	 */
960
+	public function updateCounter($object)
961
+	{
962
+		if (isset($object->vars['counter'])) {
963
+			$new_counter = $object->getVar('counter') + 1;
964
+			$sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
965
+			$this->query($sql, null, true);
966
+		}
967
+	}
968
+
969
+	/**
970
+	 * Execute the function associated with an event
971
+	 * This method will check if the function is available
972
+	 *
973
+	 * @param  string $event name of the event
974
+	 * @param         $executeEventObj
975
+	 * @return mixed  result of the execution of the function or FALSE if the function was not executed
976
+	 * @internal param object $obj $object on which is performed the event
977
+	 */
978
+	public function executeEvent($event, &$executeEventObj)
979
+	{
980
+		if (!in_array($event, $this->_disabledEvents)) {
981
+			if (method_exists($this, $event)) {
982
+				$ret = $this->$event($executeEventObj);
983
+			} else {
984
+				// check to see if there is a hook for this event
985
+				if (isset($this->_eventHooks[$event])) {
986
+					$method = $this->_eventHooks[$event];
987
+					// check to see if the method specified by this hook exists
988
+					if (method_exists($this, $method)) {
989
+						$ret = $this->$method($executeEventObj);
990
+					}
991
+				}
992
+				$ret = true;
993
+			}
994
+
995
+			return $ret;
996
+		}
997
+
998
+		return true;
999
+	}
1000
+
1001
+	/**
1002
+	 * @param  bool $withprefix
1003
+	 * @return string
1004
+	 */
1005
+	public function getIdentifierName($withprefix = true)
1006
+	{
1007
+		if ($withprefix) {
1008
+			return $this->_itemname . '.' . $this->identifierName;
1009
+		} else {
1010
+			return $this->identifierName;
1011
+		}
1012
+	}
1013 1013
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
 
151 151
         $this->_itemname      = $itemname;
152 152
         $this->_moduleName    = $modulename;
153
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
153
+        $this->table          = $db->prefix($modulename.'_'.$itemname);
154 154
         $this->keyName        = $keyname;
155 155
 //        $this->className      = ucfirst($modulename) . ucfirst($itemname);
156 156
         $this->className      = $itemname;
157 157
 
158 158
         $this->identifierName = $idenfierName;
159 159
         $this->summaryName    = $summaryName;
160
-        $this->_page          = $itemname . '.php';
161
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
162
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
163
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
164
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
160
+        $this->_page          = $itemname.'.php';
161
+        $this->_modulePath    = XOOPS_ROOT_PATH.'/modules/'.$this->_moduleName.'/';
162
+        $this->_moduleUrl     = XOOPS_URL.'/modules/'.$this->_moduleName.'/';
163
+        $this->_uploadPath    = XOOPS_UPLOAD_PATH.'/'.$this->_moduleName.'/';
164
+        $this->_uploadUrl     = XOOPS_UPLOAD_URL.'/'.$this->_moduleName.'/';
165 165
     }
166 166
 
167 167
     /**
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         $smartPermissionsHandler = new PermissionHandler($this);
204 204
         $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
205 205
         if (count($grantedItems) > 0) {
206
-            $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
206
+            $criteria->add(new \Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN'));
207 207
 
208 208
             return true;
209 209
         } else {
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     {
244 244
 //        $obj0 = new $this->className($this);
245 245
 
246
-        $obj =  new $this->className;
246
+        $obj = new $this->className;
247 247
 
248 248
         $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
249 249
         if (!$obj->handler) {
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      */
263 263
     public function getImageUrl()
264 264
     {
265
-        return $this->_uploadUrl . $this->_itemname . '/';
265
+        return $this->_uploadUrl.$this->_itemname.'/';
266 266
     }
267 267
 
268 268
     /**
@@ -270,12 +270,12 @@  discard block
 block discarded – undo
270 270
      */
271 271
     public function getImagePath()
272 272
     {
273
-        $dir = $this->_uploadPath . $this->_itemname;
273
+        $dir = $this->_uploadPath.$this->_itemname;
274 274
         if (!file_exists($dir)) {
275 275
             Smartobject\Utility::mkdirAsAdmin($dir);
276 276
         }
277 277
 
278
-        return $dir . '/';
278
+        return $dir.'/';
279 279
     }
280 280
 
281 281
     /**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         if ($debug) {
315 315
             $obj_array = $this->getObjectsD($criteria, false, $as_object);
316 316
         } else {
317
-            $obj_array =& $this->getObjects($criteria, false, $as_object);
317
+            $obj_array = & $this->getObjects($criteria, false, $as_object);
318 318
             //patch: weird bug of indexing by id even if id_as_key = false;
319 319
             if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
320 320
                 $obj_array[0] = $obj_array[$id];
@@ -368,13 +368,13 @@  discard block
 block discarded – undo
368 368
         if ($this->generalSQL) {
369 369
             $sql = $this->generalSQL;
370 370
         } elseif (!$sql) {
371
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
371
+            $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname;
372 372
         }
373 373
 
374 374
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
375
-            $sql .= ' ' . $criteria->renderWhere();
375
+            $sql .= ' '.$criteria->renderWhere();
376 376
             if ('' !== $criteria->getSort()) {
377
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
377
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
378 378
             }
379 379
             $limit = $criteria->getLimit();
380 380
             $start = $criteria->getStart();
@@ -403,12 +403,12 @@  discard block
 block discarded – undo
403 403
         $ret = [];
404 404
 
405 405
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
406
-            $sql .= ' ' . $criteria->renderWhere();
406
+            $sql .= ' '.$criteria->renderWhere();
407 407
             if ($criteria->groupby) {
408 408
                 $sql .= $criteria->getGroupby();
409 409
             }
410 410
             if ('' !== $criteria->getSort()) {
411
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
411
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
412 412
             }
413 413
         }
414 414
         if ($debug) {
@@ -481,18 +481,18 @@  discard block
 block discarded – undo
481 481
             $obj->assignVars($myrow);
482 482
             if (!$id_as_key) {
483 483
                 if ($as_object) {
484
-                    $ret[] =& $obj;
484
+                    $ret[] = & $obj;
485 485
                 } else {
486 486
                     $ret[] = $obj->toArray();
487 487
                 }
488 488
             } else {
489 489
                 if ($as_object) {
490
-                    $value =& $obj;
490
+                    $value = & $obj;
491 491
                 } else {
492 492
                     $value = $obj->toArray();
493 493
                 }
494 494
                 if ('parentid' === $id_as_key) {
495
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
495
+                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value;
496 496
                 } else {
497 497
                     $ret[$obj->getVar($this->keyName)] = $value;
498 498
                 }
@@ -535,15 +535,15 @@  discard block
 block discarded – undo
535 535
             $criteria->setSort($this->getIdentifierName());
536 536
         }
537 537
 
538
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
538
+        $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
539 539
         if (!empty($this->identifierName)) {
540
-            $sql .= ', ' . $this->getIdentifierName();
540
+            $sql .= ', '.$this->getIdentifierName();
541 541
         }
542
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
542
+        $sql .= ' FROM '.$this->table.' AS '.$this->_itemname;
543 543
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
544
-            $sql .= ' ' . $criteria->renderWhere();
544
+            $sql .= ' '.$criteria->renderWhere();
545 545
             if ('' !== $criteria->getSort()) {
546
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
546
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
547 547
             }
548 548
             $limit = $criteria->getLimit();
549 549
             $start = $criteria->getStart();
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
581 581
             if ('' !== $criteria->groupby) {
582 582
                 $groupby = true;
583
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
583
+                $field   = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
584 584
             }
585 585
         }
586 586
         /**
@@ -591,10 +591,10 @@  discard block
 block discarded – undo
591 591
             $sql = $this->generalSQL;
592 592
             $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
593 593
         } else {
594
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
594
+            $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname;
595 595
         }
596 596
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
597
-            $sql .= ' ' . $criteria->renderWhere();
597
+            $sql .= ' '.$criteria->renderWhere();
598 598
             if ('' !== $criteria->groupby) {
599 599
                 $sql .= $criteria->getGroupby();
600 600
             }
@@ -637,13 +637,13 @@  discard block
 block discarded – undo
637 637
         if (is_array($this->keyName)) {
638 638
             $clause = [];
639 639
             for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
640
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
640
+                $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
641 641
             }
642 642
             $whereclause = implode(' AND ', $clause);
643 643
         } else {
644
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
644
+            $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
645 645
         }
646
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
646
+        $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause;
647 647
         if (false !== $force) {
648 648
             $result = $this->db->queryF($sql);
649 649
         } else {
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
              * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
705 705
              */
706 706
             if (!is_a($obj, $this->className)) {
707
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
707
+                $obj->setError(get_class($obj).' Differs from '.$this->className);
708 708
 
709 709
                 return false;
710 710
             }
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
         $fieldsToStoreInDB = [];
766 766
         foreach ($obj->cleanVars as $k => $v) {
767 767
             if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) {
768
-                $cleanvars[$k] = (int)$v;
768
+                $cleanvars[$k] = (int) $v;
769 769
             } elseif (is_array($v)) {
770 770
                 $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
771 771
             } else {
@@ -778,13 +778,13 @@  discard block
 block discarded – undo
778 778
         if ($obj->isNew()) {
779 779
             if (!is_array($this->keyName)) {
780 780
                 if ($cleanvars[$this->keyName] < 1) {
781
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
781
+                    $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
782 782
                 }
783 783
             }
784 784
 
785
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
785
+            $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')';
786 786
         } else {
787
-            $sql = 'UPDATE ' . $this->table . ' SET';
787
+            $sql = 'UPDATE '.$this->table.' SET';
788 788
             foreach ($fieldsToStoreInDB as $key => $value) {
789 789
                 if ((!is_array($this->keyName) && $key == $this->keyName)
790 790
                     || (is_array($this->keyName)
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
                 if (isset($notfirst)) {
795 795
                     $sql .= ',';
796 796
                 }
797
-                $sql      .= ' ' . $key . ' = ' . $value;
797
+                $sql .= ' '.$key.' = '.$value;
798 798
                 $notfirst = true;
799 799
             }
800 800
             if (is_array($this->keyName)) {
@@ -803,12 +803,12 @@  discard block
 block discarded – undo
803 803
                     if ($i > 0) {
804 804
                         $whereclause .= ' AND ';
805 805
                     }
806
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
806
+                    $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
807 807
                 }
808 808
             } else {
809
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
809
+                $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
810 810
             }
811
-            $sql .= ' WHERE ' . $whereclause;
811
+            $sql .= ' WHERE '.$whereclause;
812 812
         }
813 813
 
814 814
         if ($debug) {
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
      */
882 882
     public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
883 883
     {
884
-        $set_clause = $fieldname . ' = ';
884
+        $set_clause = $fieldname.' = ';
885 885
         if (is_numeric($fieldvalue)) {
886 886
             $set_clause .= $fieldvalue;
887 887
         } elseif (is_array($fieldvalue)) {
@@ -889,9 +889,9 @@  discard block
 block discarded – undo
889 889
         } else {
890 890
             $set_clause .= $this->db->quoteString($fieldvalue);
891 891
         }
892
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
892
+        $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
893 893
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
894
-            $sql .= ' ' . $criteria->renderWhere();
894
+            $sql .= ' '.$criteria->renderWhere();
895 895
         }
896 896
         if (false !== $force) {
897 897
             $result = $this->db->queryF($sql);
@@ -915,8 +915,8 @@  discard block
 block discarded – undo
915 915
     public function deleteAll(CriteriaElement $criteria = null)
916 916
     {
917 917
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
918
-            $sql = 'DELETE FROM ' . $this->table;
919
-            $sql .= ' ' . $criteria->renderWhere();
918
+            $sql = 'DELETE FROM '.$this->table;
919
+            $sql .= ' '.$criteria->renderWhere();
920 920
             if (!$this->db->query($sql)) {
921 921
                 return false;
922 922
             }
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
      */
950 950
     public function getModuleItemString()
951 951
     {
952
-        $ret = $this->_moduleName . '_' . $this->_itemname;
952
+        $ret = $this->_moduleName.'_'.$this->_itemname;
953 953
 
954 954
         return $ret;
955 955
     }
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
     {
962 962
         if (isset($object->vars['counter'])) {
963 963
             $new_counter = $object->getVar('counter') + 1;
964
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
964
+            $sql         = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id();
965 965
             $this->query($sql, null, true);
966 966
         }
967 967
     }
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
     public function getIdentifierName($withprefix = true)
1006 1006
     {
1007 1007
         if ($withprefix) {
1008
-            return $this->_itemname . '.' . $this->identifierName;
1008
+            return $this->_itemname.'.'.$this->identifierName;
1009 1009
         } else {
1010 1010
             return $this->identifierName;
1011 1011
         }
Please login to merge, or discard this patch.
class/Category.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -20,121 +20,121 @@
 block discarded – undo
20 20
  */
21 21
 class Category extends Smartobject\SeoObject
22 22
 {
23
-    public $_categoryPath;
24
-
25
-    /**
26
-     * SmartobjectCategory constructor.
27
-     */
28
-    public function __construct()
29
-    {
30
-        $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true);
31
-        $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC);
32
-        $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC);
33
-        $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC);
34
-        $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC);
35
-
36
-        $this->initCommonVar('doxcode');
37
-
38
-        $this->setControl('image', ['name' => 'image']);
39
-        $this->setControl('parentid', ['name' => 'parentcategory']);
40
-        $this->setControl('description', [
41
-            'name'        => 'textarea',
42
-            'itemHandler' => false,
43
-            'method'      => false,
44
-            'module'      => false,
45
-            'form_editor' => 'default'
46
-        ]);
47
-
48
-        // call parent constructor to get SEO fields initiated
49
-        parent::__construct();
50
-    }
51
-
52
-    /**
53
-     * returns a specific variable for the object in a proper format
54
-     *
55
-     * @access public
56
-     * @param  string $key    key of the object's variable to be returned
57
-     * @param  string $format format to use for the output
58
-     * @return mixed  formatted value of the variable
59
-     */
60
-    public function getVar($key, $format = 's')
61
-    {
62
-        if ('s' === $format && in_array($key, ['description', 'image'])) {
63
-            //            return call_user_func(array($this, $key));
64
-            return $this->{$key}();
65
-        }
66
-
67
-        return parent::getVar($key, $format);
68
-    }
69
-
70
-    /**
71
-     * @return string
72
-     */
73
-    public function description()
74
-    {
75
-        return $this->getValueFor('description', false);
76
-    }
77
-
78
-    /**
79
-     * @return bool|mixed
80
-     */
81
-    public function image()
82
-    {
83
-        $ret = $this->getVar('image', 'e');
84
-        if ('-1' == $ret) {
85
-            return false;
86
-        } else {
87
-            return $ret;
88
-        }
89
-    }
90
-
91
-    /**
92
-     * @return array
93
-     */
94
-    public function toArray()
95
-    {
96
-        $this->setVar('doxcode', true);
97
-        global $myts;
98
-        $objectArray = parent::toArray();
99
-        if ($objectArray['image']) {
100
-            $objectArray['image'] = $this->getImageDir() . $objectArray['image'];
101
-        }
102
-
103
-        return $objectArray;
104
-    }
105
-
106
-    /**
107
-     * Create the complete path of a category
108
-     *
109
-     * @todo this could be improved as it uses multiple queries
110
-     * @param  bool $withAllLink make all name clickable
111
-     * @param  bool $currentCategory
112
-     * @return string complete path (breadcrumb)
113
-     */
114
-    public function getCategoryPath($withAllLink = true, $currentCategory = false)
115
-    {
23
+	public $_categoryPath;
24
+
25
+	/**
26
+	 * SmartobjectCategory constructor.
27
+	 */
28
+	public function __construct()
29
+	{
30
+		$this->initVar('categoryid', XOBJ_DTYPE_INT, '', true);
31
+		$this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC);
32
+		$this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC);
33
+		$this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC);
34
+		$this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC);
35
+
36
+		$this->initCommonVar('doxcode');
37
+
38
+		$this->setControl('image', ['name' => 'image']);
39
+		$this->setControl('parentid', ['name' => 'parentcategory']);
40
+		$this->setControl('description', [
41
+			'name'        => 'textarea',
42
+			'itemHandler' => false,
43
+			'method'      => false,
44
+			'module'      => false,
45
+			'form_editor' => 'default'
46
+		]);
47
+
48
+		// call parent constructor to get SEO fields initiated
49
+		parent::__construct();
50
+	}
51
+
52
+	/**
53
+	 * returns a specific variable for the object in a proper format
54
+	 *
55
+	 * @access public
56
+	 * @param  string $key    key of the object's variable to be returned
57
+	 * @param  string $format format to use for the output
58
+	 * @return mixed  formatted value of the variable
59
+	 */
60
+	public function getVar($key, $format = 's')
61
+	{
62
+		if ('s' === $format && in_array($key, ['description', 'image'])) {
63
+			//            return call_user_func(array($this, $key));
64
+			return $this->{$key}();
65
+		}
66
+
67
+		return parent::getVar($key, $format);
68
+	}
69
+
70
+	/**
71
+	 * @return string
72
+	 */
73
+	public function description()
74
+	{
75
+		return $this->getValueFor('description', false);
76
+	}
77
+
78
+	/**
79
+	 * @return bool|mixed
80
+	 */
81
+	public function image()
82
+	{
83
+		$ret = $this->getVar('image', 'e');
84
+		if ('-1' == $ret) {
85
+			return false;
86
+		} else {
87
+			return $ret;
88
+		}
89
+	}
90
+
91
+	/**
92
+	 * @return array
93
+	 */
94
+	public function toArray()
95
+	{
96
+		$this->setVar('doxcode', true);
97
+		global $myts;
98
+		$objectArray = parent::toArray();
99
+		if ($objectArray['image']) {
100
+			$objectArray['image'] = $this->getImageDir() . $objectArray['image'];
101
+		}
102
+
103
+		return $objectArray;
104
+	}
105
+
106
+	/**
107
+	 * Create the complete path of a category
108
+	 *
109
+	 * @todo this could be improved as it uses multiple queries
110
+	 * @param  bool $withAllLink make all name clickable
111
+	 * @param  bool $currentCategory
112
+	 * @return string complete path (breadcrumb)
113
+	 */
114
+	public function getCategoryPath($withAllLink = true, $currentCategory = false)
115
+	{
116 116
 //        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
117
-        $controller = new ObjectController($this->handler);
118
-
119
-        if (!$this->_categoryPath) {
120
-            if ($withAllLink && !$currentCategory) {
121
-                $ret = $controller->getItemLink($this);
122
-            } else {
123
-                $currentCategory = false;
124
-                $ret             = $this->getVar('name');
125
-            }
126
-            $parentid = $this->getVar('parentid');
127
-            if (0 != $parentid) {
128
-                $parentObj = $this->handler->get($parentid);
129
-                if ($parentObj->isNew()) {
130
-                    exit;
131
-                }
132
-                $parentid = $parentObj->getVar('parentid');
133
-                $ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret;
134
-            }
135
-            $this->_categoryPath = $ret;
136
-        }
137
-
138
-        return $this->_categoryPath;
139
-    }
117
+		$controller = new ObjectController($this->handler);
118
+
119
+		if (!$this->_categoryPath) {
120
+			if ($withAllLink && !$currentCategory) {
121
+				$ret = $controller->getItemLink($this);
122
+			} else {
123
+				$currentCategory = false;
124
+				$ret             = $this->getVar('name');
125
+			}
126
+			$parentid = $this->getVar('parentid');
127
+			if (0 != $parentid) {
128
+				$parentObj = $this->handler->get($parentid);
129
+				if ($parentObj->isNew()) {
130
+					exit;
131
+				}
132
+				$parentid = $parentObj->getVar('parentid');
133
+				$ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret;
134
+			}
135
+			$this->_categoryPath = $ret;
136
+		}
137
+
138
+		return $this->_categoryPath;
139
+	}
140 140
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         global $myts;
98 98
         $objectArray = parent::toArray();
99 99
         if ($objectArray['image']) {
100
-            $objectArray['image'] = $this->getImageDir() . $objectArray['image'];
100
+            $objectArray['image'] = $this->getImageDir().$objectArray['image'];
101 101
         }
102 102
 
103 103
         return $objectArray;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
                     exit;
131 131
                 }
132 132
                 $parentid = $parentObj->getVar('parentid');
133
-                $ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret;
133
+                $ret      = $parentObj->getCategoryPath($withAllLink, $currentCategory).' > '.$ret;
134 134
             }
135 135
             $this->_categoryPath = $ret;
136 136
         }
Please login to merge, or discard this patch.
class/AddTo.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -31,66 +31,66 @@
 block discarded – undo
31 31
 
32 32
 class AddTo
33 33
 {
34
-    public $_layout;
35
-    public $_method;
36
-
37
-    /**
38
-     * Constructor of SmartAddTo
39
-     *
40
-     * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons
41
-     * @param int $method 0=directpage, 1=popup
42
-     */
43
-    public function __construct($layout = 0, $method = 1)
44
-    {
45
-        $layout = (int)$layout;
46
-        if ($layout < 0 || $layout > 3) {
47
-            $layout = 0;
48
-        }
49
-        $this->_layout = $layout;
50
-
51
-        $method = (int)$method;
52
-        if ($method < 0 || $method > 1) {
53
-            $method = 1;
54
-        }
55
-        $this->_method = $method;
56
-    }
57
-
58
-    /**
59
-     * @param  bool $fetchOnly
60
-     * @return mixed|string|void
61
-     */
62
-    public function render($fetchOnly = false)
63
-    {
64
-        global $xoTheme, $xoopsTpl;
65
-
66
-        $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
67
-
68
-        $xoopsTpl->assign('smartobject_addto_method', $this->_method);
69
-        $xoopsTpl->assign('smartobject_addto_layout', $this->_layout);
70
-
71
-        $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/');
72
-
73
-        if ($fetchOnly) {
74
-            return $xoopsTpl->fetch('db:smartobject_addto.tpl');
75
-        } else {
76
-            $xoopsTpl->display('db:smartobject_addto.tpl');
77
-        }
78
-    }
79
-
80
-    /**
81
-     * @return array
82
-     */
83
-    public function renderForBlock()
84
-    {
85
-        global $xoTheme;
86
-
87
-        $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
88
-
89
-        $block                             = [];
90
-        $block['smartobject_addto_method'] = $this->_method;
91
-        $block['smartobject_addto_layout'] = $this->_layout;
92
-        $block['smartobject_addto_url']    = SMARTOBJECT_URL . 'include/addto/';
93
-
94
-        return $block;
95
-    }
34
+	public $_layout;
35
+	public $_method;
36
+
37
+	/**
38
+	 * Constructor of SmartAddTo
39
+	 *
40
+	 * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons
41
+	 * @param int $method 0=directpage, 1=popup
42
+	 */
43
+	public function __construct($layout = 0, $method = 1)
44
+	{
45
+		$layout = (int)$layout;
46
+		if ($layout < 0 || $layout > 3) {
47
+			$layout = 0;
48
+		}
49
+		$this->_layout = $layout;
50
+
51
+		$method = (int)$method;
52
+		if ($method < 0 || $method > 1) {
53
+			$method = 1;
54
+		}
55
+		$this->_method = $method;
56
+	}
57
+
58
+	/**
59
+	 * @param  bool $fetchOnly
60
+	 * @return mixed|string|void
61
+	 */
62
+	public function render($fetchOnly = false)
63
+	{
64
+		global $xoTheme, $xoopsTpl;
65
+
66
+		$xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
67
+
68
+		$xoopsTpl->assign('smartobject_addto_method', $this->_method);
69
+		$xoopsTpl->assign('smartobject_addto_layout', $this->_layout);
70
+
71
+		$xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/');
72
+
73
+		if ($fetchOnly) {
74
+			return $xoopsTpl->fetch('db:smartobject_addto.tpl');
75
+		} else {
76
+			$xoopsTpl->display('db:smartobject_addto.tpl');
77
+		}
78
+	}
79
+
80
+	/**
81
+	 * @return array
82
+	 */
83
+	public function renderForBlock()
84
+	{
85
+		global $xoTheme;
86
+
87
+		$xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
88
+
89
+		$block                             = [];
90
+		$block['smartobject_addto_method'] = $this->_method;
91
+		$block['smartobject_addto_layout'] = $this->_layout;
92
+		$block['smartobject_addto_url']    = SMARTOBJECT_URL . 'include/addto/';
93
+
94
+		return $block;
95
+	}
96 96
 }
Please login to merge, or discard this patch.
class/ObjectRow.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -22,37 +22,37 @@
 block discarded – undo
22 22
  */
23 23
 class ObjectRow
24 24
 {
25
-    public $_keyname;
26
-    public $_align;
27
-    public $_customMethodForValue;
28
-    public $_header;
29
-    public $_class;
25
+	public $_keyname;
26
+	public $_align;
27
+	public $_customMethodForValue;
28
+	public $_header;
29
+	public $_class;
30 30
 
31
-    /**
32
-     * SmartObjectRow constructor.
33
-     * @param      $keyname
34
-     * @param bool $customMethodForValue
35
-     * @param bool $header
36
-     * @param bool $class
37
-     */
38
-    public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false)
39
-    {
40
-        $this->_keyname              = $keyname;
41
-        $this->_customMethodForValue = $customMethodForValue;
42
-        $this->_header               = $header;
43
-        $this->_class                = $class;
44
-    }
31
+	/**
32
+	 * SmartObjectRow constructor.
33
+	 * @param      $keyname
34
+	 * @param bool $customMethodForValue
35
+	 * @param bool $header
36
+	 * @param bool $class
37
+	 */
38
+	public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false)
39
+	{
40
+		$this->_keyname              = $keyname;
41
+		$this->_customMethodForValue = $customMethodForValue;
42
+		$this->_header               = $header;
43
+		$this->_class                = $class;
44
+	}
45 45
 
46
-    public function getKeyName()
47
-    {
48
-        return $this->_keyname;
49
-    }
46
+	public function getKeyName()
47
+	{
48
+		return $this->_keyname;
49
+	}
50 50
 
51
-    /**
52
-     * @return bool
53
-     */
54
-    public function isHeader()
55
-    {
56
-        return $this->_header;
57
-    }
51
+	/**
52
+	 * @return bool
53
+	 */
54
+	public function isHeader()
55
+	{
56
+		return $this->_header;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
class/RatingHandler.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -31,93 +31,93 @@
 block discarded – undo
31 31
  */
32 32
 class RatingHandler extends Smartobject\PersistableObjectHandler
33 33
 {
34
-    public $_rateOptions = [];
35
-    public $_moduleList  = false;
36
-    public $pluginsObject;
37
-
38
-    /**
39
-     * SmartobjectRatingHandler constructor.
40
-     * @param \XoopsDatabase $db
41
-     */
42
-    public function __construct(\XoopsDatabase $db)
43
-    {
44
-        parent::__construct($db, Rating::class, 'ratingid', 'rate', '', 'smartobject');
45
-        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';
46
-
47
-        $this->_rateOptions[1] = 1;
48
-        $this->_rateOptions[2] = 2;
49
-        $this->_rateOptions[3] = 3;
50
-        $this->_rateOptions[4] = 4;
51
-        $this->_rateOptions[5] = 5;
52
-
53
-        $this->pluginsObject = new PluginHandler();
54
-    }
55
-
56
-    /**
57
-     * @return bool
58
-     */
59
-    public function getModuleList()
60
-    {
61
-        if (!$this->_moduleList) {
62
-            $moduleArray          = $this->pluginsObject->getPluginsArray();
63
-            $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION;
64
-            foreach ($moduleArray as $k => $v) {
65
-                $this->_moduleList[$k] = $v;
66
-            }
67
-        }
68
-
69
-        return $this->_moduleList;
70
-    }
71
-
72
-    /**
73
-     * @return array
74
-     */
75
-    public function getRateList()
76
-    {
77
-        return $this->_rateOptions;
78
-    }
79
-
80
-    /**
81
-     * @param $itemid
82
-     * @param $dirname
83
-     * @param $item
84
-     * @return int
85
-     */
86
-    public function getRatingAverageByItemId($itemid, $dirname, $item)
87
-    {
88
-        $sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
89
-        $result = $this->db->query($sql);
90
-        if (!$result) {
91
-            return 0;
92
-        }
93
-        list($average, $sum) = $this->db->fetchRow($result);
94
-        $ret['average'] = isset($average) ? $average : 0;
95
-        $ret['sum']     = isset($sum) ? $sum : 0;
96
-
97
-        return $ret;
98
-    }
99
-
100
-    /**
101
-     * @param $item
102
-     * @param $itemid
103
-     * @param $dirname
104
-     * @param $uid
105
-     * @return bool
106
-     */
107
-    public function already_rated($item, $itemid, $dirname, $uid)
108
-    {
109
-        $criteria = new \CriteriaCompo();
110
-        $criteria->add(new \Criteria('item', $item));
111
-        $criteria->add(new \Criteria('itemid', $itemid));
112
-        $criteria->add(new \Criteria('dirname', $dirname));
113
-        $criteria->add(new \Criteria('user.uid', $uid));
114
-
115
-        $ret =& $this->getObjects($criteria);
116
-
117
-        if (!$ret) {
118
-            return false;
119
-        } else {
120
-            return $ret[0];
121
-        }
122
-    }
34
+	public $_rateOptions = [];
35
+	public $_moduleList  = false;
36
+	public $pluginsObject;
37
+
38
+	/**
39
+	 * SmartobjectRatingHandler constructor.
40
+	 * @param \XoopsDatabase $db
41
+	 */
42
+	public function __construct(\XoopsDatabase $db)
43
+	{
44
+		parent::__construct($db, Rating::class, 'ratingid', 'rate', '', 'smartobject');
45
+		$this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';
46
+
47
+		$this->_rateOptions[1] = 1;
48
+		$this->_rateOptions[2] = 2;
49
+		$this->_rateOptions[3] = 3;
50
+		$this->_rateOptions[4] = 4;
51
+		$this->_rateOptions[5] = 5;
52
+
53
+		$this->pluginsObject = new PluginHandler();
54
+	}
55
+
56
+	/**
57
+	 * @return bool
58
+	 */
59
+	public function getModuleList()
60
+	{
61
+		if (!$this->_moduleList) {
62
+			$moduleArray          = $this->pluginsObject->getPluginsArray();
63
+			$this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION;
64
+			foreach ($moduleArray as $k => $v) {
65
+				$this->_moduleList[$k] = $v;
66
+			}
67
+		}
68
+
69
+		return $this->_moduleList;
70
+	}
71
+
72
+	/**
73
+	 * @return array
74
+	 */
75
+	public function getRateList()
76
+	{
77
+		return $this->_rateOptions;
78
+	}
79
+
80
+	/**
81
+	 * @param $itemid
82
+	 * @param $dirname
83
+	 * @param $item
84
+	 * @return int
85
+	 */
86
+	public function getRatingAverageByItemId($itemid, $dirname, $item)
87
+	{
88
+		$sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
89
+		$result = $this->db->query($sql);
90
+		if (!$result) {
91
+			return 0;
92
+		}
93
+		list($average, $sum) = $this->db->fetchRow($result);
94
+		$ret['average'] = isset($average) ? $average : 0;
95
+		$ret['sum']     = isset($sum) ? $sum : 0;
96
+
97
+		return $ret;
98
+	}
99
+
100
+	/**
101
+	 * @param $item
102
+	 * @param $itemid
103
+	 * @param $dirname
104
+	 * @param $uid
105
+	 * @return bool
106
+	 */
107
+	public function already_rated($item, $itemid, $dirname, $uid)
108
+	{
109
+		$criteria = new \CriteriaCompo();
110
+		$criteria->add(new \Criteria('item', $item));
111
+		$criteria->add(new \Criteria('itemid', $itemid));
112
+		$criteria->add(new \Criteria('dirname', $dirname));
113
+		$criteria->add(new \Criteria('user.uid', $uid));
114
+
115
+		$ret =& $this->getObjects($criteria);
116
+
117
+		if (!$ret) {
118
+			return false;
119
+		} else {
120
+			return $ret[0];
121
+		}
122
+	}
123 123
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public function __construct(\XoopsDatabase $db)
43 43
     {
44 44
         parent::__construct($db, Rating::class, 'ratingid', 'rate', '', 'smartobject');
45
-        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';
45
+        $this->generalSQL = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname.' INNER JOIN '.$this->db->prefix('users').' AS user ON '.$this->_itemname.'.uid=user.uid';
46 46
 
47 47
         $this->_rateOptions[1] = 1;
48 48
         $this->_rateOptions[2] = 2;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public function getRatingAverageByItemId($itemid, $dirname, $item)
87 87
     {
88
-        $sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
88
+        $sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM '.$this->table." WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
89 89
         $result = $this->db->query($sql);
90 90
         if (!$result) {
91 91
             return 0;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $criteria->add(new \Criteria('dirname', $dirname));
113 113
         $criteria->add(new \Criteria('user.uid', $uid));
114 114
 
115
-        $ret =& $this->getObjects($criteria);
115
+        $ret = & $this->getObjects($criteria);
116 116
 
117 117
         if (!$ret) {
118 118
             return false;
Please login to merge, or discard this patch.
class/Plugin.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -25,66 +25,66 @@
 block discarded – undo
25 25
  */
26 26
 class Plugin
27 27
 {
28
-    public $_infoArray;
28
+	public $_infoArray;
29 29
 
30
-    /**
31
-     * SmartPlugin constructor.
32
-     * @param $array
33
-     */
34
-    public function __construct($array)
35
-    {
36
-        $this->_infoArray = $array;
37
-    }
30
+	/**
31
+	 * SmartPlugin constructor.
32
+	 * @param $array
33
+	 */
34
+	public function __construct($array)
35
+	{
36
+		$this->_infoArray = $array;
37
+	}
38 38
 
39
-    /**
40
-     * @param $item
41
-     * @return bool
42
-     */
43
-    public function getItemInfo($item)
44
-    {
45
-        if (isset($this->_infoArray['items'][$item])) {
46
-            return $this->_infoArray['items'][$item];
47
-        } else {
48
-            return false;
49
-        }
50
-    }
39
+	/**
40
+	 * @param $item
41
+	 * @return bool
42
+	 */
43
+	public function getItemInfo($item)
44
+	{
45
+		if (isset($this->_infoArray['items'][$item])) {
46
+			return $this->_infoArray['items'][$item];
47
+		} else {
48
+			return false;
49
+		}
50
+	}
51 51
 
52
-    /**
53
-     * @return mixed
54
-     */
55
-    public function getItemList()
56
-    {
57
-        $itemsArray = $this->_infoArray['items'];
58
-        foreach ($itemsArray as $k => $v) {
59
-            $ret[$k] = $v['caption'];
60
-        }
52
+	/**
53
+	 * @return mixed
54
+	 */
55
+	public function getItemList()
56
+	{
57
+		$itemsArray = $this->_infoArray['items'];
58
+		foreach ($itemsArray as $k => $v) {
59
+			$ret[$k] = $v['caption'];
60
+		}
61 61
 
62
-        return $ret;
63
-    }
62
+		return $ret;
63
+	}
64 64
 
65
-    /**
66
-     * @return bool|int|string
67
-     */
68
-    public function getItem()
69
-    {
70
-        $ret = false;
71
-        foreach ($this->_infoArray['items'] as $k => $v) {
72
-            $search_str = str_replace('%u', '', $v['url']);
73
-            if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
74
-                $ret = $k;
75
-                break;
76
-            }
77
-        }
65
+	/**
66
+	 * @return bool|int|string
67
+	 */
68
+	public function getItem()
69
+	{
70
+		$ret = false;
71
+		foreach ($this->_infoArray['items'] as $k => $v) {
72
+			$search_str = str_replace('%u', '', $v['url']);
73
+			if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
74
+				$ret = $k;
75
+				break;
76
+			}
77
+		}
78 78
 
79
-        return $ret;
80
-    }
79
+		return $ret;
80
+	}
81 81
 
82
-    /**
83
-     * @param $item
84
-     * @return mixed
85
-     */
86
-    public function getItemIdForItem($item)
87
-    {
88
-        return $_REQUEST[$this->_infoArray['items'][$item]['request']];
89
-    }
82
+	/**
83
+	 * @param $item
84
+	 * @return mixed
85
+	 */
86
+	public function getItemIdForItem($item)
87
+	{
88
+		return $_REQUEST[$this->_infoArray['items'][$item]['request']];
89
+	}
90 90
 }
Please login to merge, or discard this patch.
class/MlObject.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -26,80 +26,80 @@
 block discarded – undo
26 26
  */
27 27
 class MlObject extends Smartobject\BaseSmartObject
28 28
 {
29
-    /**
30
-     * SmartMlObject constructor.
31
-     */
32
-    public function __construct()
33
-    {
34
-        $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true);
35
-        $this->setControl('language', 'language');
36
-    }
29
+	/**
30
+	 * SmartMlObject constructor.
31
+	 */
32
+	public function __construct()
33
+	{
34
+		$this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true);
35
+		$this->setControl('language', 'language');
36
+	}
37 37
 
38
-    /**
39
-     * If object is not new, change the control of the not-multilanguage fields
40
-     *
41
-     * We need to intercept this function from SmartObject because if the object is not new...
42
-     */
43
-    // function getForm() {
38
+	/**
39
+	 * If object is not new, change the control of the not-multilanguage fields
40
+	 *
41
+	 * We need to intercept this function from SmartObject because if the object is not new...
42
+	 */
43
+	// function getForm() {
44 44
 
45
-    //}
45
+	//}
46 46
 
47
-    /**
48
-     * Strip Multilanguage Fields
49
-     *
50
-     * Get rid of all the multilanguage fields to have an object with only global fields.
51
-     * This will be usefull when creating the ML object for the first time. Then we will be able
52
-     * to create translations.
53
-     */
54
-    public function stripMultilanguageFields()
55
-    {
56
-        $objectVars    =& $this->getVars();
57
-        $newObjectVars = [];
58
-        foreach ($objectVars as $key => $var) {
59
-            if (!$var['multilingual']) {
60
-                $newObjectVars[$key] = $var;
61
-            }
62
-        }
63
-        $this->vars = $newObjectVars;
64
-    }
47
+	/**
48
+	 * Strip Multilanguage Fields
49
+	 *
50
+	 * Get rid of all the multilanguage fields to have an object with only global fields.
51
+	 * This will be usefull when creating the ML object for the first time. Then we will be able
52
+	 * to create translations.
53
+	 */
54
+	public function stripMultilanguageFields()
55
+	{
56
+		$objectVars    =& $this->getVars();
57
+		$newObjectVars = [];
58
+		foreach ($objectVars as $key => $var) {
59
+			if (!$var['multilingual']) {
60
+				$newObjectVars[$key] = $var;
61
+			}
62
+		}
63
+		$this->vars = $newObjectVars;
64
+	}
65 65
 
66
-    public function stripNonMultilanguageFields()
67
-    {
68
-        $objectVars    =& $this->getVars();
69
-        $newObjectVars = [];
70
-        foreach ($objectVars as $key => $var) {
71
-            if ($var['multilingual'] || $key == $this->handler->keyName) {
72
-                $newObjectVars[$key] = $var;
73
-            }
74
-        }
75
-        $this->vars = $newObjectVars;
76
-    }
66
+	public function stripNonMultilanguageFields()
67
+	{
68
+		$objectVars    =& $this->getVars();
69
+		$newObjectVars = [];
70
+		foreach ($objectVars as $key => $var) {
71
+			if ($var['multilingual'] || $key == $this->handler->keyName) {
72
+				$newObjectVars[$key] = $var;
73
+			}
74
+		}
75
+		$this->vars = $newObjectVars;
76
+	}
77 77
 
78
-    /**
79
-     * Make non multilanguage fields read only
80
-     *
81
-     * This is used when we are creating/editing a translation.
82
-     * We only want to edit the multilanguag fields, not the global one.
83
-     */
84
-    public function makeNonMLFieldReadOnly()
85
-    {
86
-        foreach ($this->getVars() as $key => $var) {
87
-            //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) {
88
-            if (!$var['multilingual'] && $key != $this->handler->keyName) {
89
-                $this->setControl($key, 'label');
90
-            }
91
-        }
92
-    }
78
+	/**
79
+	 * Make non multilanguage fields read only
80
+	 *
81
+	 * This is used when we are creating/editing a translation.
82
+	 * We only want to edit the multilanguag fields, not the global one.
83
+	 */
84
+	public function makeNonMLFieldReadOnly()
85
+	{
86
+		foreach ($this->getVars() as $key => $var) {
87
+			//if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) {
88
+			if (!$var['multilingual'] && $key != $this->handler->keyName) {
89
+				$this->setControl($key, 'label');
90
+			}
91
+		}
92
+	}
93 93
 
94
-    /**
95
-     * @param  bool $onlyUrl
96
-     * @param  bool $withimage
97
-     * @return string
98
-     */
99
-    public function getEditLanguageLink($onlyUrl = false, $withimage = true)
100
-    {
101
-        $controller = new ObjectController($this->handler);
94
+	/**
95
+	 * @param  bool $onlyUrl
96
+	 * @param  bool $withimage
97
+	 * @return string
98
+	 */
99
+	public function getEditLanguageLink($onlyUrl = false, $withimage = true)
100
+	{
101
+		$controller = new ObjectController($this->handler);
102 102
 
103
-        return $controller->getEditLanguageLink($this, $onlyUrl, $withimage);
104
-    }
103
+		return $controller->getEditLanguageLink($this, $onlyUrl, $withimage);
104
+	}
105 105
 }
Please login to merge, or discard this patch.
class/Uploader.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -81,51 +81,51 @@
 block discarded – undo
81 81
  */
82 82
 class Uploader extends \XoopsMediaUploader
83 83
 {
84
-    public $ext;
85
-    public $dimension;
84
+	public $ext;
85
+	public $dimension;
86 86
 
87
-    /**
88
-     * No admin check for uploads
89
-     */
90
-    public $noAdminSizeCheck;
87
+	/**
88
+	 * No admin check for uploads
89
+	 */
90
+	public $noAdminSizeCheck;
91 91
 
92
-    /**
93
-     * Constructor
94
-     *
95
-     * @param string    $uploadDir
96
-     * @param array|int $allowedMimeTypes
97
-     * @param int       $maxFileSize
98
-     * @param int       $maxWidth
99
-     * @param int       $maxHeight
100
-     * @internal param int $cmodvalue
101
-     */
102
-    public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize, $maxWidth = 0, $maxHeight = 0)
103
-    {
104
-        parent::__construct($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
105
-    }
92
+	/**
93
+	 * Constructor
94
+	 *
95
+	 * @param string    $uploadDir
96
+	 * @param array|int $allowedMimeTypes
97
+	 * @param int       $maxFileSize
98
+	 * @param int       $maxWidth
99
+	 * @param int       $maxHeight
100
+	 * @internal param int $cmodvalue
101
+	 */
102
+	public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize, $maxWidth = 0, $maxHeight = 0)
103
+	{
104
+		parent::__construct($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
105
+	}
106 106
 
107
-    /**
108
-     * @param $value
109
-     */
110
-    public function noAdminSizeCheck($value)
111
-    {
112
-        $this->noAdminSizeCheck = $value;
113
-    }
107
+	/**
108
+	 * @param $value
109
+	 */
110
+	public function noAdminSizeCheck($value)
111
+	{
112
+		$this->noAdminSizeCheck = $value;
113
+	}
114 114
 
115
-    /**
116
-     * Is the file the right size?
117
-     *
118
-     * @return bool
119
-     */
120
-    public function checkMaxFileSize()
121
-    {
122
-        if ($this->noAdminSizeCheck) {
123
-            return true;
124
-        }
125
-        if ($this->mediaSize > $this->maxFileSize) {
126
-            return false;
127
-        }
115
+	/**
116
+	 * Is the file the right size?
117
+	 *
118
+	 * @return bool
119
+	 */
120
+	public function checkMaxFileSize()
121
+	{
122
+		if ($this->noAdminSizeCheck) {
123
+			return true;
124
+		}
125
+		if ($this->mediaSize > $this->maxFileSize) {
126
+			return false;
127
+		}
128 128
 
129
-        return true;
130
-    }
129
+		return true;
130
+	}
131 131
 }
Please login to merge, or discard this patch.
class/HookHandler.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -27,44 +27,44 @@
 block discarded – undo
27 27
  */
28 28
 class HookHandler
29 29
 {
30
-    /**
31
-     * SmartHookHandler constructor.
32
-     */
33
-    public function __construct()
34
-    {
35
-    }
30
+	/**
31
+	 * SmartHookHandler constructor.
32
+	 */
33
+	public function __construct()
34
+	{
35
+	}
36 36
 
37
-    /**
38
-     * Access the only instance of this class
39
-     *
40
-     * @return \XoopsModules\Smartobject\HookHandler
41
-     *
42
-     * @static
43
-     * @staticvar   object
44
-     */
45
-    public static function getInstance()
46
-    {
47
-        static $instance;
48
-        if (null === $instance) {
49
-            $instance = new static();
50
-        }
37
+	/**
38
+	 * Access the only instance of this class
39
+	 *
40
+	 * @return \XoopsModules\Smartobject\HookHandler
41
+	 *
42
+	 * @static
43
+	 * @staticvar   object
44
+	 */
45
+	public static function getInstance()
46
+	{
47
+		static $instance;
48
+		if (null === $instance) {
49
+			$instance = new static();
50
+		}
51 51
 
52
-        return $instance;
53
-    }
52
+		return $instance;
53
+	}
54 54
 
55
-    /**
56
-     * @param $hook_name
57
-     */
58
-    public function executeHook($hook_name)
59
-    {
60
-        $lower_hook_name = strtolower($hook_name);
61
-        $filename        = SMARTOBJECT_ROOT_PATH . 'include/custom_code/' . $lower_hook_name . '.php';
62
-        if (file_exists($filename)) {
63
-            require_once $filename;
64
-            $function = 'smarthook_' . $lower_hook_name;
65
-            if (function_exists($function)) {
66
-                $function();
67
-            }
68
-        }
69
-    }
55
+	/**
56
+	 * @param $hook_name
57
+	 */
58
+	public function executeHook($hook_name)
59
+	{
60
+		$lower_hook_name = strtolower($hook_name);
61
+		$filename        = SMARTOBJECT_ROOT_PATH . 'include/custom_code/' . $lower_hook_name . '.php';
62
+		if (file_exists($filename)) {
63
+			require_once $filename;
64
+			$function = 'smarthook_' . $lower_hook_name;
65
+			if (function_exists($function)) {
66
+				$function();
67
+			}
68
+		}
69
+	}
70 70
 }
Please login to merge, or discard this patch.