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