Completed
Branch master (2d4977)
by Michael
03:20
created
class/smartobject.php 1 patch
Indentation   +791 added lines, -793 removed lines patch added patch discarded remove patch
@@ -5,16 +5,14 @@  discard block
 block discarded – undo
5 5
  *
6 6
  * @license GNU
7 7
  * @author marcan <[email protected]>
8
-
9 8
  * @version $Id: smartobject.php 1409 2008-04-02 20:48:27Z malanciault $
10
-
11 9
  * @link http://smartfactory.ca The SmartFactory
12 10
  * @package SmartObject
13 11
  * @subpackage SmartObjectCore
14 12
  */
15 13
 
16 14
 if (!defined("XOOPS_ROOT_PATH")) {
17
-    die("XOOPS root path not defined");
15
+	die("XOOPS root path not defined");
18 16
 }
19 17
 
20 18
 include_once XOOPS_ROOT_PATH . "/modules/smartobject/include/common.php";
@@ -42,35 +40,35 @@  discard block
 block discarded – undo
42 40
  */
43 41
 class SmartObject extends XoopsObject {
44 42
 
45
-    var $_image_path;
46
-    var $_image_url;
43
+	var $_image_path;
44
+	var $_image_url;
47 45
 
48
-    var $seoEnabled = false;
49
-    var $titleField;
50
-    var $summaryField=false;
46
+	var $seoEnabled = false;
47
+	var $titleField;
48
+	var $summaryField=false;
51 49
 
52
-    /**
50
+	/**
53 51
 	 * Reference to the handler managing this object
54 52
 	 *
55 53
 	 * @var object reference to {@link SmartPersistableObjectHandler}
56 54
 	 */
57
-    var $handler;
55
+	var $handler;
58 56
 
59
-    /**
57
+	/**
60 58
 	 * References to control objects, managing the form fields of this object
61 59
 	 */
62
-    var $controls = array();
60
+	var $controls = array();
63 61
 
64
-    function SmartObject(&$handler) {
65
-    	$this->handler = $handler;
66
-    }
62
+	function SmartObject(&$handler) {
63
+		$this->handler = $handler;
64
+	}
67 65
 
68 66
 	/**
69
-	* Checks if the user has a specific access on this object
70
-	*
71
-	* @param string $gperm_name name of the permission to test
72
-	* @return boolean : TRUE if user has access, false if not
73
-	**/
67
+	 * Checks if the user has a specific access on this object
68
+	 *
69
+	 * @param string $gperm_name name of the permission to test
70
+	 * @return boolean : TRUE if user has access, false if not
71
+	 **/
74 72
 	function accessGranted($perm_name) {
75 73
 		$smartpermissions_handler = new SmartobjectPermissionHandler($this->handler);
76 74
 		return $smartpermissions_handler->accessGranted($perm_name, $this->id());
@@ -83,295 +81,295 @@  discard block
 block discarded – undo
83 81
 		$this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
84 82
 	}
85 83
 
86
-    /**
87
-    *
88
-    * @param string $key key of this field. This needs to be the name of the field in the related database table
89
-    * @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)
90
-    * @param mixed $value default value of this variable
91
-    * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table
92
-    * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
93
-    * @param string $options does this data have any select options?
94
-    * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
95
-    * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
96
-    * @param string $form_dsc description of this variable in a {@link SmartobjectForm}
97
-    * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable
98
-    * @param bool $persistent set to FALSE if this field is not to be saved in the database
99
-    */
100
-    function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual=false, $form_caption='', $form_dsc='', $sortby=false, $persistent=true, $displayOnForm=true) {
101
-        //url_ is reserved for files.
102
-        if (substr($key, 0,4) == 'url_' ) {
103
-	        trigger_error("Cannot use variable starting with 'url_'.");
104
-	    }
105
-        parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
106
-        if ($this->handler && (!$form_caption || $form_caption == '')) {
107
-        	$dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
108
-        	if (defined($dyn_form_caption)) {
84
+	/**
85
+	 *
86
+	 * @param string $key key of this field. This needs to be the name of the field in the related database table
87
+	 * @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)
88
+	 * @param mixed $value default value of this variable
89
+	 * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table
90
+	 * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
91
+	 * @param string $options does this data have any select options?
92
+	 * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
93
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
94
+	 * @param string $form_dsc description of this variable in a {@link SmartobjectForm}
95
+	 * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable
96
+	 * @param bool $persistent set to FALSE if this field is not to be saved in the database
97
+	 */
98
+	function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual=false, $form_caption='', $form_dsc='', $sortby=false, $persistent=true, $displayOnForm=true) {
99
+		//url_ is reserved for files.
100
+		if (substr($key, 0,4) == 'url_' ) {
101
+			trigger_error("Cannot use variable starting with 'url_'.");
102
+		}
103
+		parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
104
+		if ($this->handler && (!$form_caption || $form_caption == '')) {
105
+			$dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
106
+			if (defined($dyn_form_caption)) {
109 107
 				$form_caption = constant($dyn_form_caption);
110
-        	}
111
-        }
112
-        if ($this->handler && (!$form_dsc || $form_dsc == '')) {
113
-        	$dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
114
-        	if (defined($dyn_form_dsc)) {
108
+			}
109
+		}
110
+		if ($this->handler && (!$form_dsc || $form_dsc == '')) {
111
+			$dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
112
+			if (defined($dyn_form_dsc)) {
115 113
 				$form_dsc = constant($dyn_form_dsc);
116
-        	}
117
-        }
114
+			}
115
+		}
118 116
 
119 117
 
120
-        $this->vars[$key] = array_merge($this->vars[$key], array('multilingual' => $multilingual,
121
-        'form_caption' => $form_caption,
122
-        'form_dsc' => $form_dsc,
123
-        'sortby' => $sortby,
124
-        'persistent' => $persistent,
125
-        'displayOnForm' => $displayOnForm,
126
-        'displayOnSingleView' => true,
127
-        'readonly' => false));
128
-    }
118
+		$this->vars[$key] = array_merge($this->vars[$key], array('multilingual' => $multilingual,
119
+		'form_caption' => $form_caption,
120
+		'form_dsc' => $form_dsc,
121
+		'sortby' => $sortby,
122
+		'persistent' => $persistent,
123
+		'displayOnForm' => $displayOnForm,
124
+		'displayOnSingleView' => true,
125
+		'readonly' => false));
126
+	}
129 127
 
130
-    function initNonPersistableVar($key, $data_type, $itemName=false, $form_caption='', $sortby=false, $value='', $displayOnForm=false, $required=false) {
128
+	function initNonPersistableVar($key, $data_type, $itemName=false, $form_caption='', $sortby=false, $value='', $displayOnForm=false, $required=false) {
131 129
 		$this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
132 130
 		$this->vars[$key]['itemName'] = $itemName;
133
-    }
131
+	}
134 132
 
135 133
 	/**
136
-	* Quickly initiate a var
137
-	*
138
-	* Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
139
-	*
140
-	* - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
141
-	* - all other vars are NULL or '' depending of the parameter
142
-	*
143
-    * @param string $key key of this field. This needs to be the name of the field in the related database table
144
-    * @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)
145
-    * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table
146
-    * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
147
-    * @param string $form_dsc description of this variable in a {@link SmartobjectForm}
148
-    * @param mixed $value default value of this variable
149
-    */
134
+	 * Quickly initiate a var
135
+	 *
136
+	 * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
137
+	 *
138
+	 * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
139
+	 * - all other vars are NULL or '' depending of the parameter
140
+	 *
141
+	 * @param string $key key of this field. This needs to be the name of the field in the related database table
142
+	 * @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)
143
+	 * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table
144
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
145
+	 * @param string $form_dsc description of this variable in a {@link SmartobjectForm}
146
+	 * @param mixed $value default value of this variable
147
+	 */
150 148
 	function quickInitVar($key, $data_type, $required=false, $form_caption='', $form_dsc='', $value = null) {
151 149
 		$maxlength = $data_type == 'XOBJ_DTYPE_TXTBOX' ? 255 : null;
152 150
 		$this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
153 151
 	}
154 152
 
155
-    function initCommonVar($varname, $displayOnForm=true, $default='notdefined') {
156
-
157
-    	switch ($varname) {
158
-            case "dohtml":
159
-            	$value = $default != 'notdefined' ? $default : true;
160
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, "", false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
161
-                $this->setControl($varname, "yesno");
162
-                break;
163
-
164
-            case "dobr":
165
-            	$value = ($default === 'notdefined') ? true : $default;
166
-                $this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
167
-                $this->setControl($varname, "yesno");
168
-                break;
169
-
170
-            case "doimage":
171
-            	$value = $default != 'notdefined' ? $default : true;
172
-                $this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
173
-                $this->setControl($varname, "yesno");
174
-                break;
175
-
176
-            case "dosmiley":
177
-            	$value = $default != 'notdefined' ? $default : true;
178
-                $this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
179
-                $this->setControl($varname, "yesno");
180
-                break;
181
-
182
-            case "doxcode":
183
-            	$value = $default != 'notdefined' ? $default : true;
184
-                $this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
185
-                $this->setControl($varname, "yesno");
186
-                break;
187
-
188
-            case "meta_keywords":
189
-            	$value = $default != 'notdefined' ? $default : '';
190
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
191
-        		$this->setControl('meta_keywords', array(
153
+	function initCommonVar($varname, $displayOnForm=true, $default='notdefined') {
154
+
155
+		switch ($varname) {
156
+			case "dohtml":
157
+				$value = $default != 'notdefined' ? $default : true;
158
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, "", false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
159
+				$this->setControl($varname, "yesno");
160
+				break;
161
+
162
+			case "dobr":
163
+				$value = ($default === 'notdefined') ? true : $default;
164
+				$this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
165
+				$this->setControl($varname, "yesno");
166
+				break;
167
+
168
+			case "doimage":
169
+				$value = $default != 'notdefined' ? $default : true;
170
+				$this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
171
+				$this->setControl($varname, "yesno");
172
+				break;
173
+
174
+			case "dosmiley":
175
+				$value = $default != 'notdefined' ? $default : true;
176
+				$this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
177
+				$this->setControl($varname, "yesno");
178
+				break;
179
+
180
+			case "doxcode":
181
+				$value = $default != 'notdefined' ? $default : true;
182
+				$this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, "", false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
183
+				$this->setControl($varname, "yesno");
184
+				break;
185
+
186
+			case "meta_keywords":
187
+				$value = $default != 'notdefined' ? $default : '';
188
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
189
+				$this->setControl('meta_keywords', array(
192 190
 										'name' => 'textarea',
193
-                                        'form_editor'=>'textarea'
194
-                                        ));
195
-                break;
196
-
197
-            case "meta_description":
198
-            	$value = $default != 'notdefined' ? $default : '';
199
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
200
-        		$this->setControl('meta_description', array(
191
+										'form_editor'=>'textarea'
192
+										));
193
+				break;
194
+
195
+			case "meta_description":
196
+				$value = $default != 'notdefined' ? $default : '';
197
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
198
+				$this->setControl('meta_description', array(
201 199
 										'name' => 'textarea',
202
-                                        'form_editor'=>'textarea'
203
-                                        ));
204
-                break;
205
-
206
-            case "short_url":
207
-            	$value = $default != 'notdefined' ? $default : '';
208
-                $this->initVar($varname, XOBJ_DTYPE_TXTBOX,$value, false, null, "", false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
209
-                break;
210
-
211
-            case "hierarchy_path":
212
-            	$value = $default != 'notdefined' ? $default : '';
213
-                $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, "", false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
214
-                break;
215
-
216
-            case "counter":
217
-            	$value = $default != 'notdefined' ? $default : 0;
218
-                $this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
219
-                break;
220
-
221
-            case "weight":
222
-            	$value = $default != 'notdefined' ? $default : 0;
223
-                $this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
224
-                break;
225
-            case "custom_css":
226
-            	$value = $default != 'notdefined' ? $default : '';
227
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
228
-        		$this->setControl('custom_css', array(
200
+										'form_editor'=>'textarea'
201
+										));
202
+				break;
203
+
204
+			case "short_url":
205
+				$value = $default != 'notdefined' ? $default : '';
206
+				$this->initVar($varname, XOBJ_DTYPE_TXTBOX,$value, false, null, "", false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
207
+				break;
208
+
209
+			case "hierarchy_path":
210
+				$value = $default != 'notdefined' ? $default : '';
211
+				$this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, "", false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
212
+				break;
213
+
214
+			case "counter":
215
+				$value = $default != 'notdefined' ? $default : 0;
216
+				$this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
217
+				break;
218
+
219
+			case "weight":
220
+				$value = $default != 'notdefined' ? $default : 0;
221
+				$this->initVar($varname, XOBJ_DTYPE_INT,$value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
222
+				break;
223
+			case "custom_css":
224
+				$value = $default != 'notdefined' ? $default : '';
225
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
226
+				$this->setControl('custom_css', array(
229 227
 									'name' => 'textarea',
230 228
 									'form_editor'=>'textarea',
231 229
 									));
232
-                break;
233
-        }
230
+				break;
231
+		}
234 232
 		$this->hideFieldFromSingleView($varname);
235
-    }
236
-
237
-    /**
238
-     * Set control information for an instance variable
239
-     *
240
-     * The $options parameter can be a string or an array. Using a string
241
-     * is the quickest way :
242
-     *
243
-     * $this->setControl('date', 'date_time');
244
-     *
245
-     * This will create a date and time selectbox for the 'date' var on the
246
-     * form to edit or create this item.
247
-     *
248
-     * Here are the currently supported controls :
233
+	}
234
+
235
+	/**
236
+	 * Set control information for an instance variable
237
+	 *
238
+	 * The $options parameter can be a string or an array. Using a string
239
+	 * is the quickest way :
240
+	 *
241
+	 * $this->setControl('date', 'date_time');
242
+	 *
243
+	 * This will create a date and time selectbox for the 'date' var on the
244
+	 * form to edit or create this item.
245
+	 *
246
+	 * Here are the currently supported controls :
247
+	 *
248
+	 * 		- color
249
+	 * 		- country
250
+	 * 		- date_time
251
+	 * 		- date
252
+	 * 		- email
253
+	 * 		- group
254
+	 * 		- group_multi
255
+	 * 		- image
256
+	 * 		- imageupload
257
+	 * 		- label
258
+	 * 		- language
259
+	 * 		- parentcategory
260
+	 * 		- password
261
+	 * 		- select_multi
262
+	 * 		- select
263
+	 * 		- text
264
+	 * 		- textarea
265
+	 * 		- theme
266
+	 * 		- theme_multi
267
+	 * 		- timezone
268
+	 * 		- user
269
+	 * 		- user_multi
270
+	 * 		- yesno
271
+	 *
272
+	 * Now, using an array as $options, you can customize what information to
273
+	 * use in the control. For example, if one needs to display a select box for
274
+	 * the user to choose the status of an item. We only need to tell SmartObject
275
+	 * what method to execute within what handler to retreive the options of the
276
+	 * selectbox.
277
+	 *
278
+	 * $this->setControl('status', array('name' => false,
279
+	 * 	                                 'itemHandler' => 'item',
280
+	 *                                   'method' => 'getStatus',
281
+	 *                                   'module' => 'smartshop'));
282
+	 *
283
+	 * In this example, the array elements are the following :
284
+	 * 		- name : false, as we don't need to set a special control here.
285
+	 * 				 we will use the default control related to the object type (defined in initVar)
286
+	 * 		- itemHandler : name of the object for which we will use the handler
287
+	 * 		- method : name of the method of this handler that we will execute
288
+	 * 		- module : name of the module from wich the handler is
289
+	 *
290
+	 * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
291
+	 * populate this selectbox with the result from SmartshopItemHandler::getStatus()
292
+	 *
293
+	 * Another example of the use of $options as an array is for TextArea :
294
+	 *
295
+	 * $this->setControl('body', array('name' => 'textarea',
296
+	 *                                   'form_editor' => 'default'));
297
+	 *
298
+	 * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
299
+	 * the 'default' editor, providing it is defined in the module
300
+	 * preferences : $xoopsModuleConfig['default_editor']
301
+	 *
302
+	 * Of course, you can force the use of a specific editor :
303
+	 *
304
+	 * $this->setControl('body', array('name' => 'textarea',
305
+	 *                                   'form_editor' => 'koivi'));
306
+	 *
307
+	 * Here is a list of supported editor :
308
+	 * 		- tiny : TinyEditor
309
+	 * 		- dhtmltextarea : XOOPS DHTML Area
310
+	 * 		- fckeditor	: FCKEditor
311
+	 * 		- inbetween : InBetween
312
+	 * 		- koivi : Koivi
313
+	 * 		- spaw : Spaw WYSIWYG Editor
314
+	 * 		- htmlarea : HTMLArea
315
+	 * 		- textarea : basic textarea with no options
316
+	 *
317
+	 * @param string $var name of the variable for which we want to set a control
318
+	 * @param array $options
319
+	 */
320
+	function setControl($var, $options=array()) {
321
+		if (isset($this->controls[$var])) {
322
+			unset($this->controls[$var]);
323
+		}
324
+		if (is_string($options)) {
325
+			$options = array('name' => $options);
326
+		}
327
+		$this->controls[$var] = $options;
328
+	}
329
+
330
+	/**
331
+	 * Get control information for an instance variable
249 332
 	 *
250
-     * 		- color
251
-     * 		- country
252
-     * 		- date_time
253
-     * 		- date
254
-     * 		- email
255
-     * 		- group
256
-     * 		- group_multi
257
-     * 		- image
258
-     * 		- imageupload
259
-     * 		- label
260
-     * 		- language
261
-     * 		- parentcategory
262
-     * 		- password
263
-     * 		- select_multi
264
-     * 		- select
265
-     * 		- text
266
-     * 		- textarea
267
-     * 		- theme
268
-     * 		- theme_multi
269
-     * 		- timezone
270
-     * 		- user
271
-     * 		- user_multi
272
-     * 		- yesno
273
-     *
274
-     * Now, using an array as $options, you can customize what information to
275
-     * use in the control. For example, if one needs to display a select box for
276
-     * the user to choose the status of an item. We only need to tell SmartObject
277
-     * what method to execute within what handler to retreive the options of the
278
-     * selectbox.
279
-     *
280
-     * $this->setControl('status', array('name' => false,
281
-     * 	                                 'itemHandler' => 'item',
282
-     *                                   'method' => 'getStatus',
283
-     *                                   'module' => 'smartshop'));
284
-     *
285
-     * In this example, the array elements are the following :
286
-     * 		- name : false, as we don't need to set a special control here.
287
-     * 				 we will use the default control related to the object type (defined in initVar)
288
-     * 		- itemHandler : name of the object for which we will use the handler
289
-     * 		- method : name of the method of this handler that we will execute
290
-     * 		- module : name of the module from wich the handler is
291
-     *
292
-     * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
293
-     * populate this selectbox with the result from SmartshopItemHandler::getStatus()
294
-     *
295
-     * Another example of the use of $options as an array is for TextArea :
296
-     *
297
-     * $this->setControl('body', array('name' => 'textarea',
298
-     *                                   'form_editor' => 'default'));
299
-     *
300
-     * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
301
-     * the 'default' editor, providing it is defined in the module
302
-     * preferences : $xoopsModuleConfig['default_editor']
303
-     *
304
-     * Of course, you can force the use of a specific editor :
305
-     *
306
-     * $this->setControl('body', array('name' => 'textarea',
307
-     *                                   'form_editor' => 'koivi'));
308
-     *
309
-     * Here is a list of supported editor :
310
-     * 		- tiny : TinyEditor
311
-     * 		- dhtmltextarea : XOOPS DHTML Area
312
-     * 		- fckeditor	: FCKEditor
313
-     * 		- inbetween : InBetween
314
-     * 		- koivi : Koivi
315
-     * 		- spaw : Spaw WYSIWYG Editor
316
-     * 		- htmlarea : HTMLArea
317
-     * 		- textarea : basic textarea with no options
318
-     *
319
-     * @param string $var name of the variable for which we want to set a control
320
-     * @param array $options
321
-     */
322
-    function setControl($var, $options=array()) {
323
-        if (isset($this->controls[$var])) {
324
-        	unset($this->controls[$var]);
325
-        }
326
-        if (is_string($options)) {
327
-            $options = array('name' => $options);
328
-        }
329
-        $this->controls[$var] = $options;
330
-    }
331
-
332
-    /**
333
-     * Get control information for an instance variable
334
-     *
335
-     * @param string $var
336
-     */
337
-    function getControl($var) {
338
-        return isset($this->controls[$var]) ? $this->controls[$var] : false;
339
-    }
340
-
341
-    /**
342
-    * Create the form for this object
343
-    *
344
-    * @return a {@link SmartobjectForm} object for this object
345
-    *
346
-    * @see SmartObjectForm::SmartObjectForm()
347
-    */
348
-    function getForm($form_caption, $form_name, $form_action=false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action=false, $captcha=false)
349
-    {
350
-        include_once SMARTOBJECT_ROOT_PATH . "class/form/smartobjectform.php";
351
-        $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
352
-
353
-        return $form;
354
-    }
355
-
356
-    function toArray()
357
-    {
358
-        $ret = array();
359
-        $vars = $this->getVars();
360
-        foreach ($vars as $key=>$var) {
361
-            $value = $this->getVar($key);
362
-            $ret[$key] = $value;
363
-        }
364
-        if ($this->handler->identifierName != "") {
365
-        	$controller = new SmartObjectController($this->handler);
366
-        	/**
367
-	    	 * Addition of some automatic value
368
-	    	 */
369
-        	$ret['itemLink'] = $controller->getItemLink($this);
370
-        	$ret['itemUrl'] = $controller->getItemLink($this, true);
371
-        	$ret['editItemLink'] = $controller->getEditItemLink($this, false, true);
372
-        	$ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true);
373
-        	$ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
374
-        }
333
+	 * @param string $var
334
+	 */
335
+	function getControl($var) {
336
+		return isset($this->controls[$var]) ? $this->controls[$var] : false;
337
+	}
338
+
339
+	/**
340
+	 * Create the form for this object
341
+	 *
342
+	 * @return a {@link SmartobjectForm} object for this object
343
+	 *
344
+	 * @see SmartObjectForm::SmartObjectForm()
345
+	 */
346
+	function getForm($form_caption, $form_name, $form_action=false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action=false, $captcha=false)
347
+	{
348
+		include_once SMARTOBJECT_ROOT_PATH . "class/form/smartobjectform.php";
349
+		$form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
350
+
351
+		return $form;
352
+	}
353
+
354
+	function toArray()
355
+	{
356
+		$ret = array();
357
+		$vars = $this->getVars();
358
+		foreach ($vars as $key=>$var) {
359
+			$value = $this->getVar($key);
360
+			$ret[$key] = $value;
361
+		}
362
+		if ($this->handler->identifierName != "") {
363
+			$controller = new SmartObjectController($this->handler);
364
+			/**
365
+			 * Addition of some automatic value
366
+			 */
367
+			$ret['itemLink'] = $controller->getItemLink($this);
368
+			$ret['itemUrl'] = $controller->getItemLink($this, true);
369
+			$ret['editItemLink'] = $controller->getEditItemLink($this, false, true);
370
+			$ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true);
371
+			$ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
372
+		}
375 373
 
376 374
 		// Hightlighting searched words
377 375
 		include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php');
@@ -387,64 +385,64 @@  discard block
 block discarded – undo
387 385
 			}
388 386
 		}
389 387
 
390
-        return $ret;
391
-    }
392
-
393
-    /**
394
-     * add an error
395
-     *
396
-     * @param string $value error to add
397
-     * @access public
398
-     */
399
-    function setErrors($err_str, $prefix=false)
400
-    {
401
-    	if (is_array($err_str)) {
402
-            foreach($err_str as $str) {
403
-                $this->setErrors($str, $prefix);
404
-            }
405
-        } else {
406
-        	if ($prefix) {
407
-        		$err_str = "[" . $prefix . "] " . $err_str;
408
-        	}
409
-            parent::setErrors($err_str);
410
-        }
411
-    }
412
-
413
-    function setFieldAsRequired($field, $required=true) {
414
-    	if (is_array($field)) {
388
+		return $ret;
389
+	}
390
+
391
+	/**
392
+	 * add an error
393
+	 *
394
+	 * @param string $value error to add
395
+	 * @access public
396
+	 */
397
+	function setErrors($err_str, $prefix=false)
398
+	{
399
+		if (is_array($err_str)) {
400
+			foreach($err_str as $str) {
401
+				$this->setErrors($str, $prefix);
402
+			}
403
+		} else {
404
+			if ($prefix) {
405
+				$err_str = "[" . $prefix . "] " . $err_str;
406
+			}
407
+			parent::setErrors($err_str);
408
+		}
409
+	}
410
+
411
+	function setFieldAsRequired($field, $required=true) {
412
+		if (is_array($field)) {
415 413
 			foreach($field as $v) {
416 414
 				$this->doSetFieldAsRequired($v, $required);
417 415
 			}
418
-    	} else {
419
-    		$this->doSetFieldAsRequired($field, $required);
420
-    	}
421
-    }
416
+		} else {
417
+			$this->doSetFieldAsRequired($field, $required);
418
+		}
419
+	}
422 420
 
423
-    function setFieldForSorting($field) {
424
-    	if (is_array($field)) {
421
+	function setFieldForSorting($field) {
422
+		if (is_array($field)) {
425 423
 			foreach($field as $v) {
426 424
 				$this->doSetFieldForSorting($v);
427 425
 			}
428
-    	} else {
429
-    		$this->doSetFieldForSorting($field);
430
-    	}
431
-    }
432
-
433
-    function hasError() {
434
-    	return count($this->_errors) > 0;
435
-    }
436
-
437
-    function setImageDir($url, $path)
438
-    {
439
-        $this->_image_url = $url;
440
-        $this->_image_path = $path;
441
-    }
442
-
443
-    /**
444
-     * Retreive the group that have been granted access to a specific permission for this object
445
-     *
446
-     * @return string $group_perm name of the permission
447
-     */
426
+		} else {
427
+			$this->doSetFieldForSorting($field);
428
+		}
429
+	}
430
+
431
+	function hasError() {
432
+		return count($this->_errors) > 0;
433
+	}
434
+
435
+	function setImageDir($url, $path)
436
+	{
437
+		$this->_image_url = $url;
438
+		$this->_image_path = $path;
439
+	}
440
+
441
+	/**
442
+	 * Retreive the group that have been granted access to a specific permission for this object
443
+	 *
444
+	 * @return string $group_perm name of the permission
445
+	 */
448 446
 	function getGroupPerm($group_perm) {
449 447
 		if (!$this->handler->getPermissions()) {
450 448
 			$this->setError("Trying to access a permission that does not exists for thisobject's handler");
@@ -461,25 +459,25 @@  discard block
 block discarded – undo
461 459
 		}
462 460
 	}
463 461
 
464
-    function getImageDir($path=false)
465
-    {
466
-        if ($path) {
467
-            return $this->_image_path;
468
-        } else {
469
-            return $this->_image_url;
470
-        }
471
-    }
462
+	function getImageDir($path=false)
463
+	{
464
+		if ($path) {
465
+			return $this->_image_path;
466
+		} else {
467
+			return $this->_image_url;
468
+		}
469
+	}
472 470
 
473 471
 	function getUploadDir($path=false)
474
-    {
475
-        if ($path) {
476
-            return $this->_image_path;
477
-        } else {
478
-            return $this->_image_url;
479
-        }
480
-    }
481
-
482
-    function getVarInfo($key = '', $info = '') {
472
+	{
473
+		if ($path) {
474
+			return $this->_image_path;
475
+		} else {
476
+			return $this->_image_url;
477
+		}
478
+	}
479
+
480
+	function getVarInfo($key = '', $info = '') {
483 481
 		if (isset($this->vars[$key][$info])) {
484 482
 			return $this->vars[$key][$info];
485 483
 		}elseif ($info == '' && isset($this->vars[$key])) {
@@ -489,80 +487,80 @@  discard block
 block discarded – undo
489 487
 		}
490 488
 	}
491 489
 
492
-    /**
493
-     * Get the id of the object
494
-     *
495
-     * @return int id of this object
496
-     */
497
-    function id() {
498
-    	return $this->getVar($this->handler->keyName, 'e');
499
-    }
500
-
501
-    /**
502
-     * Return the value of the title field of this object
503
-     *
504
-     * @return string
505
-     */
506
-    function title($format='s')
507
-    {
508
-        return $this->getVar($this->handler->identifierName, $format);
509
-    }
510
-
511
-    /**
512
-     * Return the value of the title field of this object
513
-     *
514
-     * @return string
515
-     */
516
-    function summary()
517
-    {
518
-        if ($this->handler->summaryName) {
519
-            return $this->getVar($this->handler->summaryName);
520
-        } else {
521
-            return false;
522
-        }
523
-    }
524
-
525
-    /**
526
-     * Retreive the object admin side link, displayijng a SingleView page
527
-     *
528
-     * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link
529
-     * @return string user side link to the object
530
-     */
531
-    function getAdminViewItemLink($onlyUrl=false)
532
-    {
533
-    	$controller = new SmartObjectController($this->handler);
534
-    	return $controller->getAdminViewItemLink($this, $onlyUrl);
535
-    }
536
-
537
-    /**
538
-     * Retreive the object user side link
539
-     *
540
-     * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link
541
-     * @return string user side link to the object
542
-     */
543
-    function getItemLink($onlyUrl=false)
544
-    {
545
-    	$controller = new SmartObjectController($this->handler);
546
-    	return $controller->getItemLink($this, $onlyUrl);
547
-    }
548
-
549
-    function getEditItemLink($onlyUrl=false, $withimage=true, $userSide=false)
550
-    {
551
-    	$controller = new SmartObjectController($this->handler);
552
-    	return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
553
-    }
554
-
555
-    function getDeleteItemLink($onlyUrl=false, $withimage=false, $userSide=false)
556
-    {
557
-    	$controller = new SmartObjectController($this->handler);
558
-    	return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
559
-    }
560
-
561
-    function getPrintAndMailLink()
562
-    {
563
-    	$controller = new SmartObjectController($this->handler);
564
-    	return $controller->getPrintAndMailLink($this);
565
-    }
490
+	/**
491
+	 * Get the id of the object
492
+	 *
493
+	 * @return int id of this object
494
+	 */
495
+	function id() {
496
+		return $this->getVar($this->handler->keyName, 'e');
497
+	}
498
+
499
+	/**
500
+	 * Return the value of the title field of this object
501
+	 *
502
+	 * @return string
503
+	 */
504
+	function title($format='s')
505
+	{
506
+		return $this->getVar($this->handler->identifierName, $format);
507
+	}
508
+
509
+	/**
510
+	 * Return the value of the title field of this object
511
+	 *
512
+	 * @return string
513
+	 */
514
+	function summary()
515
+	{
516
+		if ($this->handler->summaryName) {
517
+			return $this->getVar($this->handler->summaryName);
518
+		} else {
519
+			return false;
520
+		}
521
+	}
522
+
523
+	/**
524
+	 * Retreive the object admin side link, displayijng a SingleView page
525
+	 *
526
+	 * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link
527
+	 * @return string user side link to the object
528
+	 */
529
+	function getAdminViewItemLink($onlyUrl=false)
530
+	{
531
+		$controller = new SmartObjectController($this->handler);
532
+		return $controller->getAdminViewItemLink($this, $onlyUrl);
533
+	}
534
+
535
+	/**
536
+	 * Retreive the object user side link
537
+	 *
538
+	 * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link
539
+	 * @return string user side link to the object
540
+	 */
541
+	function getItemLink($onlyUrl=false)
542
+	{
543
+		$controller = new SmartObjectController($this->handler);
544
+		return $controller->getItemLink($this, $onlyUrl);
545
+	}
546
+
547
+	function getEditItemLink($onlyUrl=false, $withimage=true, $userSide=false)
548
+	{
549
+		$controller = new SmartObjectController($this->handler);
550
+		return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
551
+	}
552
+
553
+	function getDeleteItemLink($onlyUrl=false, $withimage=false, $userSide=false)
554
+	{
555
+		$controller = new SmartObjectController($this->handler);
556
+		return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
557
+	}
558
+
559
+	function getPrintAndMailLink()
560
+	{
561
+		$controller = new SmartObjectController($this->handler);
562
+		return $controller->getPrintAndMailLink($this);
563
+	}
566 564
 
567 565
 	function getFieldsForSorting($sortsel) {
568 566
 		$ret = array();
@@ -590,12 +588,12 @@  discard block
 block discarded – undo
590 588
 	}
591 589
 
592 590
 	function getValueFor($key, $editor=true) {
593
-    	global $xoopsModuleConfig;
591
+		global $xoopsModuleConfig;
594 592
 
595
-    	$ret = $this->getVar($key, 'n');
596
-    	$myts = MyTextSanitizer::getInstance();
593
+		$ret = $this->getVar($key, 'n');
594
+		$myts = MyTextSanitizer::getInstance();
597 595
 
598
-    	$control = isset($this->controls[$key]) ? $this->controls[$key] : false;
596
+		$control = isset($this->controls[$key]) ? $this->controls[$key] : false;
599 597
 		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
600 598
 
601 599
 		$html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
@@ -605,7 +603,7 @@  discard block
 block discarded – undo
605 603
 		$br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
606 604
 		$formatML = true;
607 605
 
608
-    	if ($form_editor == 'default') {
606
+		if ($form_editor == 'default') {
609 607
 			global $xoopsModuleConfig;
610 608
 			$form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
611 609
 		}
@@ -626,260 +624,260 @@  discard block
 block discarded – undo
626 624
 		}
627 625
 	}
628 626
 
629
-    /**
630
-     * clean values of all variables of the object for storage.
631
-     * also add slashes whereever needed
632
-     *
633
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
634
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
635
-     * as a string separated by |
636
-     *
637
-     * @return bool true if successful
638
-     * @access public
639
-     */
640
-    function cleanVars()
641
-    {
642
-        $ts =& MyTextSanitizer::getInstance();
643
-        $existing_errors = $this->getErrors();
644
-        $this->_errors = array();
645
-        foreach ($this->vars as $k => $v) {
627
+	/**
628
+	 * clean values of all variables of the object for storage.
629
+	 * also add slashes whereever needed
630
+	 *
631
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
632
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
633
+	 * as a string separated by |
634
+	 *
635
+	 * @return bool true if successful
636
+	 * @access public
637
+	 */
638
+	function cleanVars()
639
+	{
640
+		$ts =& MyTextSanitizer::getInstance();
641
+		$existing_errors = $this->getErrors();
642
+		$this->_errors = array();
643
+		foreach ($this->vars as $k => $v) {
646 644
 			$cleanv = $v['value'];
647
-            if (!$v['changed']) {
648
-            } else {
649
-                $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
650
-                switch ($v['data_type']) {
651
-                case XOBJ_DTYPE_TXTBOX:
652
-                    if ($v['required'] && $cleanv != '0' && $cleanv == '') {
653
-                        $this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
654
-                        continue;
655
-                    }
656
-                    if (isset($v['maxlength']) && strlen($cleanv) > intval($v['maxlength'])) {
657
-                        $this->setErrors( sprintf( _XOBJ_ERR_SHORTERTHAN, $k, intval( $v['maxlength'] ) ) );
658
-                        continue;
659
-                    }
660
-                    if (!$v['not_gpc']) {
661
-                        $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
662
-                    } else {
663
-                        $cleanv = $ts->censorString($cleanv);
664
-                    }
665
-                    break;
666
-                case XOBJ_DTYPE_TXTAREA:
667
-                    if ($v['required'] && $cleanv != '0' && $cleanv == '') {
668
-                        $this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
669
-                        continue;
670
-                    }
671
-                    if (!$v['not_gpc']) {
672
-                        $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
673
-                    } else {
674
-                        $cleanv = $ts->censorString($cleanv);
675
-                    }
676
-                    break;
677
-                case XOBJ_DTYPE_SOURCE:
678
-                    if (!$v['not_gpc']) {
679
-                        $cleanv = $ts->stripSlashesGPC($cleanv);
680
-                    } else {
681
-                        $cleanv = $cleanv;
682
-                    }
683
-                    break;
684
-                case XOBJ_DTYPE_INT:
685
-                case XOBJ_DTYPE_TIME_ONLY:
686
-                    $cleanv = intval($cleanv);
687
-                    break;
688
-
689
-                case XOBJ_DTYPE_CURRENCY:
690
-                    $cleanv = smart_currency($cleanv);
691
-                    break;
692
-
693
-                case XOBJ_DTYPE_FLOAT:
694
-                    $cleanv = smart_float($cleanv);
695
-                    break;
696
-
697
-                case XOBJ_DTYPE_EMAIL:
698
-                    if ($v['required'] && $cleanv == '') {
699
-                        $this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
700
-                        continue;
701
-                    }
702
-                    if ($cleanv != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$cleanv)) {
703
-                        $this->setErrors("Invalid Email");
704
-                        continue;
705
-                    }
706
-                    if (!$v['not_gpc']) {
707
-                        $cleanv = $ts->stripSlashesGPC($cleanv);
708
-                    }
709
-                    break;
710
-                case XOBJ_DTYPE_URL:
711
-                    if ($v['required'] && $cleanv == '') {
712
-                        $this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
713
-                        continue;
714
-                    }
715
-                    if ($cleanv != '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
716
-                        $cleanv = 'http://' . $cleanv;
717
-                    }
718
-                    if (!$v['not_gpc']) {
719
-                        $cleanv =& $ts->stripSlashesGPC($cleanv);
720
-                    }
721
-                    break;
722
-                case XOBJ_DTYPE_SIMPLE_ARRAY:
723
-                    $cleanv = implode('|', $cleanv);
724
-                    break;
725
-                case XOBJ_DTYPE_ARRAY:
726
-                    $cleanv = serialize($cleanv);
727
-                    break;
728
-                case XOBJ_DTYPE_STIME:
729
-                case XOBJ_DTYPE_MTIME:
730
-                case XOBJ_DTYPE_LTIME:
731
-                    $cleanv = !is_string($cleanv) ? intval($cleanv) : strtotime($cleanv);
732
-                    if (!($cleanv > 0)) {
733
-                    	$cleanv = strtotime($cleanv);
734
-                    }
735
-                    break;
736
-                default:
737
-                    break;
738
-                }
739
-            }
740
-            $this->cleanVars[$k] =& $cleanv;
741
-            unset($cleanv);
742
-        }
743
-        if (count($this->_errors) > 0) {
744
-	        $this->_errors = array_merge($existing_errors, $this->_errors);
745
-            return false;
746
-        }
747
-	    $this->_errors = array_merge($existing_errors, $this->_errors);
748
-        $this->unsetDirty();
749
-        return true;
750
-    }
751
-
752
-    /**
753
-    * returns a specific variable for the object in a proper format
754
-    *
755
-    * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
756
-    * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
757
-    * as a string separated by |
758
-    *
759
-    * @access public
760
-    * @param string $key key of the object's variable to be returned
761
-    * @param string $format format to use for the output
762
-    * @return mixed formatted value of the variable
763
-    */
764
-    function getVar($key, $format = 's')
765
-    {
766
-    	global $myts;
767
-
768
-        $ret = $this->vars[$key]['value'];
769
-
770
-        switch ($this->vars[$key]['data_type']) {
771
-
772
-        case XOBJ_DTYPE_TXTBOX:
773
-            switch (strtolower($format)) {
774
-            case 's':
775
-            case 'show':
776
-            	// ML Hack by marcan
777
-                $ts =& MyTextSanitizer::getInstance();
778
-                $ret = $ts->htmlSpecialChars($ret);
779
-
780
-                if (method_exists($myts, 'formatForML')) {
781
-                	return $ts->formatForML($ret);
782
-                } else {
783
-                	return $ret;
784
-                }
785
-            	break 1;
786
-            	// End of ML Hack by marcan
787
-
788
-            case 'clean':
645
+			if (!$v['changed']) {
646
+			} else {
647
+				$cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
648
+				switch ($v['data_type']) {
649
+				case XOBJ_DTYPE_TXTBOX:
650
+					if ($v['required'] && $cleanv != '0' && $cleanv == '') {
651
+						$this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
652
+						continue;
653
+					}
654
+					if (isset($v['maxlength']) && strlen($cleanv) > intval($v['maxlength'])) {
655
+						$this->setErrors( sprintf( _XOBJ_ERR_SHORTERTHAN, $k, intval( $v['maxlength'] ) ) );
656
+						continue;
657
+					}
658
+					if (!$v['not_gpc']) {
659
+						$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
660
+					} else {
661
+						$cleanv = $ts->censorString($cleanv);
662
+					}
663
+					break;
664
+				case XOBJ_DTYPE_TXTAREA:
665
+					if ($v['required'] && $cleanv != '0' && $cleanv == '') {
666
+						$this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
667
+						continue;
668
+					}
669
+					if (!$v['not_gpc']) {
670
+						$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
671
+					} else {
672
+						$cleanv = $ts->censorString($cleanv);
673
+					}
674
+					break;
675
+				case XOBJ_DTYPE_SOURCE:
676
+					if (!$v['not_gpc']) {
677
+						$cleanv = $ts->stripSlashesGPC($cleanv);
678
+					} else {
679
+						$cleanv = $cleanv;
680
+					}
681
+					break;
682
+				case XOBJ_DTYPE_INT:
683
+				case XOBJ_DTYPE_TIME_ONLY:
684
+					$cleanv = intval($cleanv);
685
+					break;
686
+
687
+				case XOBJ_DTYPE_CURRENCY:
688
+					$cleanv = smart_currency($cleanv);
689
+					break;
690
+
691
+				case XOBJ_DTYPE_FLOAT:
692
+					$cleanv = smart_float($cleanv);
693
+					break;
694
+
695
+				case XOBJ_DTYPE_EMAIL:
696
+					if ($v['required'] && $cleanv == '') {
697
+						$this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
698
+						continue;
699
+					}
700
+					if ($cleanv != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$cleanv)) {
701
+						$this->setErrors("Invalid Email");
702
+						continue;
703
+					}
704
+					if (!$v['not_gpc']) {
705
+						$cleanv = $ts->stripSlashesGPC($cleanv);
706
+					}
707
+					break;
708
+				case XOBJ_DTYPE_URL:
709
+					if ($v['required'] && $cleanv == '') {
710
+						$this->setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
711
+						continue;
712
+					}
713
+					if ($cleanv != '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
714
+						$cleanv = 'http://' . $cleanv;
715
+					}
716
+					if (!$v['not_gpc']) {
717
+						$cleanv =& $ts->stripSlashesGPC($cleanv);
718
+					}
719
+					break;
720
+				case XOBJ_DTYPE_SIMPLE_ARRAY:
721
+					$cleanv = implode('|', $cleanv);
722
+					break;
723
+				case XOBJ_DTYPE_ARRAY:
724
+					$cleanv = serialize($cleanv);
725
+					break;
726
+				case XOBJ_DTYPE_STIME:
727
+				case XOBJ_DTYPE_MTIME:
728
+				case XOBJ_DTYPE_LTIME:
729
+					$cleanv = !is_string($cleanv) ? intval($cleanv) : strtotime($cleanv);
730
+					if (!($cleanv > 0)) {
731
+						$cleanv = strtotime($cleanv);
732
+					}
733
+					break;
734
+				default:
735
+					break;
736
+				}
737
+			}
738
+			$this->cleanVars[$k] =& $cleanv;
739
+			unset($cleanv);
740
+		}
741
+		if (count($this->_errors) > 0) {
742
+			$this->_errors = array_merge($existing_errors, $this->_errors);
743
+			return false;
744
+		}
745
+		$this->_errors = array_merge($existing_errors, $this->_errors);
746
+		$this->unsetDirty();
747
+		return true;
748
+	}
749
+
750
+	/**
751
+	 * returns a specific variable for the object in a proper format
752
+	 *
753
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
754
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
755
+	 * as a string separated by |
756
+	 *
757
+	 * @access public
758
+	 * @param string $key key of the object's variable to be returned
759
+	 * @param string $format format to use for the output
760
+	 * @return mixed formatted value of the variable
761
+	 */
762
+	function getVar($key, $format = 's')
763
+	{
764
+		global $myts;
765
+
766
+		$ret = $this->vars[$key]['value'];
767
+
768
+		switch ($this->vars[$key]['data_type']) {
769
+
770
+		case XOBJ_DTYPE_TXTBOX:
771
+			switch (strtolower($format)) {
772
+			case 's':
773
+			case 'show':
774
+				// ML Hack by marcan
775
+				$ts =& MyTextSanitizer::getInstance();
776
+				$ret = $ts->htmlSpecialChars($ret);
777
+
778
+				if (method_exists($myts, 'formatForML')) {
779
+					return $ts->formatForML($ret);
780
+				} else {
781
+					return $ret;
782
+				}
783
+				break 1;
784
+				// End of ML Hack by marcan
785
+
786
+			case 'clean':
789 787
 				$ts =& MyTextSanitizer::getInstance();
790 788
 
791 789
 				$ret = smart_html2text($ret);
792 790
 				$ret = smart_purifyText($ret);
793 791
 
794
-                if (method_exists($myts, 'formatForML')) {
795
-                	return $ts->formatForML($ret);
796
-                } else {
797
-                	return $ret;
798
-                }
799
-            	break 1;
800
-            	// End of ML Hack by marcan
801
-
802
-            case 'e':
803
-            case 'edit':
804
-                $ts =& MyTextSanitizer::getInstance();
805
-                return $ts->htmlSpecialChars($ret);
806
-                break 1;
807
-            case 'p':
808
-            case 'preview':
809
-            case 'f':
810
-            case 'formpreview':
811
-                $ts =& MyTextSanitizer::getInstance();
812
-                return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
813
-                break 1;
814
-            case 'n':
815
-            case 'none':
816
-            default:
817
-                break 1;
818
-            }
819
-            break;
820
-        case XOBJ_DTYPE_LTIME:
821
-            switch (strtolower($format)) {
822
-            case 's':
823
-            case 'show':
824
-            case 'p':
825
-            case 'preview':
826
-            case 'f':
827
-            case 'formpreview':
828
-                $ret = formatTimestamp($ret, _DATESTRING);
829
-                return $ret;
830
-            	break 1;
831
-            case 'n':
832
-            case 'none':
833
-            case 'e':
834
-            case 'edit':
835
-                break 1;
836
-            default:
837
-                break 1;
838
-            }
839
-            break;
840
-        case XOBJ_DTYPE_STIME:
841
-            switch (strtolower($format)) {
842
-            case 's':
843
-            case 'show':
844
-            case 'p':
845
-            case 'preview':
846
-            case 'f':
847
-            case 'formpreview':
848
-                $ret = formatTimestamp($ret, _SHORTDATESTRING);
849
-                return $ret;
850
-            	break 1;
851
-            case 'n':
852
-            case 'none':
853
-            case 'e':
854
-            case 'edit':
855
-                break 1;
856
-            default:
857
-                break 1;
858
-            }
859
-            break;
860
-        case XOBJ_DTYPE_TIME_ONLY:
861
-            switch (strtolower($format)) {
862
-            case 's':
863
-            case 'show':
864
-            case 'p':
865
-            case 'preview':
866
-            case 'f':
867
-            case 'formpreview':
868
-                $ret = formatTimestamp($ret, 'G:i');
869
-                return $ret;
870
-            	break 1;
871
-            case 'n':
872
-            case 'none':
873
-            case 'e':
874
-            case 'edit':
875
-                break 1;
876
-            default:
877
-                break 1;
878
-            }
879
-            break;
880
-
881
-        case XOBJ_DTYPE_CURRENCY:
882
-	        $decimal_section_original = strstr($ret, '.');
792
+				if (method_exists($myts, 'formatForML')) {
793
+					return $ts->formatForML($ret);
794
+				} else {
795
+					return $ret;
796
+				}
797
+				break 1;
798
+				// End of ML Hack by marcan
799
+
800
+			case 'e':
801
+			case 'edit':
802
+				$ts =& MyTextSanitizer::getInstance();
803
+				return $ts->htmlSpecialChars($ret);
804
+				break 1;
805
+			case 'p':
806
+			case 'preview':
807
+			case 'f':
808
+			case 'formpreview':
809
+				$ts =& MyTextSanitizer::getInstance();
810
+				return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
811
+				break 1;
812
+			case 'n':
813
+			case 'none':
814
+			default:
815
+				break 1;
816
+			}
817
+			break;
818
+		case XOBJ_DTYPE_LTIME:
819
+			switch (strtolower($format)) {
820
+			case 's':
821
+			case 'show':
822
+			case 'p':
823
+			case 'preview':
824
+			case 'f':
825
+			case 'formpreview':
826
+				$ret = formatTimestamp($ret, _DATESTRING);
827
+				return $ret;
828
+				break 1;
829
+			case 'n':
830
+			case 'none':
831
+			case 'e':
832
+			case 'edit':
833
+				break 1;
834
+			default:
835
+				break 1;
836
+			}
837
+			break;
838
+		case XOBJ_DTYPE_STIME:
839
+			switch (strtolower($format)) {
840
+			case 's':
841
+			case 'show':
842
+			case 'p':
843
+			case 'preview':
844
+			case 'f':
845
+			case 'formpreview':
846
+				$ret = formatTimestamp($ret, _SHORTDATESTRING);
847
+				return $ret;
848
+				break 1;
849
+			case 'n':
850
+			case 'none':
851
+			case 'e':
852
+			case 'edit':
853
+				break 1;
854
+			default:
855
+				break 1;
856
+			}
857
+			break;
858
+		case XOBJ_DTYPE_TIME_ONLY:
859
+			switch (strtolower($format)) {
860
+			case 's':
861
+			case 'show':
862
+			case 'p':
863
+			case 'preview':
864
+			case 'f':
865
+			case 'formpreview':
866
+				$ret = formatTimestamp($ret, 'G:i');
867
+				return $ret;
868
+				break 1;
869
+			case 'n':
870
+			case 'none':
871
+			case 'e':
872
+			case 'edit':
873
+				break 1;
874
+			default:
875
+				break 1;
876
+			}
877
+			break;
878
+
879
+		case XOBJ_DTYPE_CURRENCY:
880
+			$decimal_section_original = strstr($ret, '.');
883 881
 			$decimal_section = $decimal_section_original;
884 882
 			if ($decimal_section) {
885 883
 				if (strlen($decimal_section) == 1) {
@@ -893,118 +891,118 @@  discard block
 block discarded – undo
893 891
 			}
894 892
 		break;
895 893
 
896
-        case XOBJ_DTYPE_TXTAREA:
897
-            switch (strtolower($format)) {
898
-            case 's':
899
-            case 'show':
900
-                $ts =& MyTextSanitizer::getInstance();
901
-                $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
894
+		case XOBJ_DTYPE_TXTAREA:
895
+			switch (strtolower($format)) {
896
+			case 's':
897
+			case 'show':
898
+				$ts =& MyTextSanitizer::getInstance();
899
+				$html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
902 900
 
903
-                $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
901
+				$xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
904 902
 
905
-                $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
906
-                $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
907
-                $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
903
+				$smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
904
+				$image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
905
+				$br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
908 906
 
909 907
 				/**
910
-		 		 * Hack by marcan <INBOX> for SCSPRO
908
+				 * Hack by marcan <INBOX> for SCSPRO
911 909
 				 * Setting mastop as the main editor
912
-		 		 */
913
-                if (defined('XOOPS_EDITOR_IS_HTML')) {
914
-                	$br = false;
915
-                }
910
+				 */
911
+				if (defined('XOOPS_EDITOR_IS_HTML')) {
912
+					$br = false;
913
+				}
916 914
 				/**
917
-		 		 * Hack by marcan <INBOX> for SCSPRO
915
+				 * Hack by marcan <INBOX> for SCSPRO
918 916
 				 * Setting mastop as the main editor
919
-		 		 */
920
-
921
-                return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
922
-                break 1;
923
-            case 'e':
924
-            case 'edit':
925
-                return htmlspecialchars($ret, ENT_QUOTES);
926
-                break 1;
927
-            case 'p':
928
-            case 'preview':
929
-                $ts =& MyTextSanitizer::getInstance();
930
-                $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
931
-                $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
932
-                $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
933
-                $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
934
-                $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
935
-                return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
936
-                break 1;
937
-            case 'f':
938
-            case 'formpreview':
939
-                $ts =& MyTextSanitizer::getInstance();
940
-                return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
941
-                break 1;
942
-            case 'n':
943
-            case 'none':
944
-            default:
945
-                break 1;
946
-            }
947
-            break;
948
-        case XOBJ_DTYPE_SIMPLE_ARRAY:
949
-            $ret =& explode('|', $ret);
950
-            break;
951
-        case XOBJ_DTYPE_ARRAY:
952
-            $ret =& unserialize($ret);
953
-            break;
954
-        case XOBJ_DTYPE_SOURCE:
955
-            switch (strtolower($format)) {
956
-            case 's':
957
-            case 'show':
958
-                break 1;
959
-            case 'e':
960
-            case 'edit':
961
-                return htmlspecialchars($ret, ENT_QUOTES);
962
-                break 1;
963
-            case 'p':
964
-            case 'preview':
965
-                $ts =& MyTextSanitizer::getInstance();
966
-                return $ts->stripSlashesGPC($ret);
967
-                break 1;
968
-            case 'f':
969
-            case 'formpreview':
970
-                $ts =& MyTextSanitizer::getInstance();
971
-                return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
972
-                break 1;
973
-            case 'n':
974
-            case 'none':
975
-            default:
976
-                break 1;
977
-            }
978
-            break;
979
-        default:
980
-            if ($this->vars[$key]['options'] != '' && $ret != '') {
981
-                switch (strtolower($format)) {
982
-                case 's':
983
-                case 'show':
917
+				 */
918
+
919
+				return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
920
+				break 1;
921
+			case 'e':
922
+			case 'edit':
923
+				return htmlspecialchars($ret, ENT_QUOTES);
924
+				break 1;
925
+			case 'p':
926
+			case 'preview':
927
+				$ts =& MyTextSanitizer::getInstance();
928
+				$html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
929
+				$xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
930
+				$smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
931
+				$image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
932
+				$br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
933
+				return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
934
+				break 1;
935
+			case 'f':
936
+			case 'formpreview':
937
+				$ts =& MyTextSanitizer::getInstance();
938
+				return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
939
+				break 1;
940
+			case 'n':
941
+			case 'none':
942
+			default:
943
+				break 1;
944
+			}
945
+			break;
946
+		case XOBJ_DTYPE_SIMPLE_ARRAY:
947
+			$ret =& explode('|', $ret);
948
+			break;
949
+		case XOBJ_DTYPE_ARRAY:
950
+			$ret =& unserialize($ret);
951
+			break;
952
+		case XOBJ_DTYPE_SOURCE:
953
+			switch (strtolower($format)) {
954
+			case 's':
955
+			case 'show':
956
+				break 1;
957
+			case 'e':
958
+			case 'edit':
959
+				return htmlspecialchars($ret, ENT_QUOTES);
960
+				break 1;
961
+			case 'p':
962
+			case 'preview':
963
+				$ts =& MyTextSanitizer::getInstance();
964
+				return $ts->stripSlashesGPC($ret);
965
+				break 1;
966
+			case 'f':
967
+			case 'formpreview':
968
+				$ts =& MyTextSanitizer::getInstance();
969
+				return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
970
+				break 1;
971
+			case 'n':
972
+			case 'none':
973
+			default:
974
+				break 1;
975
+			}
976
+			break;
977
+		default:
978
+			if ($this->vars[$key]['options'] != '' && $ret != '') {
979
+				switch (strtolower($format)) {
980
+				case 's':
981
+				case 'show':
984 982
 					$selected = explode('|', $ret);
985
-                    $options = explode('|', $this->vars[$key]['options']);
986
-                    $i = 1;
987
-                    $ret = array();
988
-                    foreach ($options as $op) {
989
-                        if (in_array($i, $selected)) {
990
-                            $ret[] = $op;
991
-                        }
992
-                        $i++;
993
-                    }
994
-                    return implode(', ', $ret);
995
-                case 'e':
996
-                case 'edit':
997
-                    $ret = explode('|', $ret);
998
-                    break 1;
999
-                default:
1000
-                    break 1;
1001
-                }
1002
-
1003
-            }
1004
-            break;
1005
-        }
1006
-        return $ret;
1007
-    }
983
+					$options = explode('|', $this->vars[$key]['options']);
984
+					$i = 1;
985
+					$ret = array();
986
+					foreach ($options as $op) {
987
+						if (in_array($i, $selected)) {
988
+							$ret[] = $op;
989
+						}
990
+						$i++;
991
+					}
992
+					return implode(', ', $ret);
993
+				case 'e':
994
+				case 'edit':
995
+					$ret = explode('|', $ret);
996
+					break 1;
997
+				default:
998
+					break 1;
999
+				}
1000
+
1001
+			}
1002
+			break;
1003
+		}
1004
+		return $ret;
1005
+	}
1008 1006
 
1009 1007
 	function doMakeFieldreadOnly($key) {
1010 1008
 		if (isset($this->vars[$key])) {
@@ -1068,7 +1066,7 @@  discard block
 block discarded – undo
1068 1066
 	 * @param bool $userSide for futur use, to do something different on the user side
1069 1067
 	 * @return content of the template if $fetchOnly or nothing if !$fetchOnly
1070 1068
 	 */
1071
-    function displaySingleObject($fetchOnly=false, $userSide=false, $actions=array(), $headerAsRow=true) {
1069
+	function displaySingleObject($fetchOnly=false, $userSide=false, $actions=array(), $headerAsRow=true) {
1072 1070
 		include_once SMARTOBJECT_ROOT_PATH."class/smartobjectsingleview.php";
1073 1071
 		$singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow);
1074 1072
 		// add all fields mark as displayOnSingleView except the keyid
@@ -1085,7 +1083,7 @@  discard block
 block discarded – undo
1085 1083
 		}else {
1086 1084
 			$singleview->render($fetchOnly);
1087 1085
 		}
1088
-    }
1086
+	}
1089 1087
 
1090 1088
 	function doDisplayFieldOnSingleView($key) {
1091 1089
 		if (isset($this->vars[$key])) {
@@ -1093,13 +1091,13 @@  discard block
 block discarded – undo
1093 1091
 		}
1094 1092
 	}
1095 1093
 
1096
-    function doSetFieldAsRequired($field, $required=true) {
1094
+	function doSetFieldAsRequired($field, $required=true) {
1097 1095
 		$this->setVarInfo($field, 'required', $required);
1098
-    }
1096
+	}
1099 1097
 
1100
-    function doSetFieldForSorting($field) {
1098
+	function doSetFieldForSorting($field) {
1101 1099
 		$this->setVarInfo($field, 'sortby', true);
1102
-    }
1100
+	}
1103 1101
 
1104 1102
 	function showFieldOnForm($key) {
1105 1103
 		if (is_array($key)) {
Please login to merge, or discard this patch.
class/smarthookhandler.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (!defined("XOOPS_ROOT_PATH")) {
3
-    die("XOOPS root path not defined");
3
+	die("XOOPS root path not defined");
4 4
 }
5 5
 
6 6
 class SmartHookHandler {
7 7
 
8
-    function SmartHookHandler() {
8
+	function SmartHookHandler() {
9 9
 
10
-    }
10
+	}
11 11
 
12 12
 	/**
13 13
 	 * Access the only instance of this class
14
-     *
15
-     * @return	object
16
-     *
17
-     * @static
18
-     * @staticvar   object
14
+	 *
15
+	 * @return	object
16
+	 *
17
+	 * @static
18
+	 * @staticvar   object
19 19
 	 */
20 20
 	function &getInstance()
21 21
 	{
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 		return $instance;
27 27
 	}
28 28
 
29
-    function executeHook($hook_name) {
30
-    	$lower_hook_name = strtolower($hook_name);
29
+	function executeHook($hook_name) {
30
+		$lower_hook_name = strtolower($hook_name);
31 31
 		$filename = SMARTOBJECT_ROOT_PATH . 'include/custom_code/' . $lower_hook_name . '.php';
32 32
 		if (file_exists($filename)) {
33 33
 			include_once($filename);
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 				$function();
37 37
 			}
38 38
 		}
39
-    }
39
+	}
40 40
 
41 41
 }
42 42
 ?>
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
class/smartobjectsregistry.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
 
20 20
 	/**
21 21
 	 * Access the only instance of this class
22
-     *
23
-     * @return	object
24
-     *
25
-     * @static
26
-     * @staticvar   object
22
+	 *
23
+	 * @return	object
24
+	 *
25
+	 * @static
26
+	 * @staticvar   object
27 27
 	 */
28 28
 	function &getInstance()
29 29
 	{
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 	}
36 36
 
37 37
 	/**
38
-    * Adding objects to the registry
39
-    *
40
-    * @param SmartPersistableObjectHandler $handler of the objects to add
41
-    * @param CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key)
42
-    *
43
-    * @return FALSE if an error occured
44
-    */
38
+	 * Adding objects to the registry
39
+	 *
40
+	 * @param SmartPersistableObjectHandler $handler of the objects to add
41
+	 * @param CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key)
42
+	 *
43
+	 * @return FALSE if an error occured
44
+	 */
45 45
 	function addObjectsFromHandler(&$handler, $criteria=false) {
46 46
 		if (method_exists($handler, 'getObjects')) {
47 47
 			$objects = $handler->getObjects($criteria, true);
@@ -53,15 +53,15 @@  discard block
 block discarded – undo
53 53
 	}
54 54
 
55 55
 	/**
56
-    * Adding objects to the registry from an item name
57
-    * This method will fetch the handler of the item / module and call the addObjectsFromHandler
58
-    *
59
-    * @param string $item name of the item
60
-    * @param string $modulename name of the module
61
-    * @param CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key)
62
-    *
63
-    * @return FALSE if an error occured
64
-    */
56
+	 * Adding objects to the registry from an item name
57
+	 * This method will fetch the handler of the item / module and call the addObjectsFromHandler
58
+	 *
59
+	 * @param string $item name of the item
60
+	 * @param string $modulename name of the module
61
+	 * @param CriteriaCompo $criteria to pass to the getObjects method of the handler (with id_as_key)
62
+	 *
63
+	 * @return FALSE if an error occured
64
+	 */
65 65
 	function addObjectsFromItemName($item, $modulename=false, $criteria=false) {
66 66
 		if (!$modulename) {
67 67
 			global $xoopsModule;
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
 	}
84 84
 
85 85
 	/**
86
-    * Fetching objects from the registry
87
-    *
88
-    * @param string $itemname
89
-    * @param string $modulename
90
-    *
91
-    * @return the requested objects or FALSE if they don't exists in the registry
92
-    */
86
+	 * Fetching objects from the registry
87
+	 *
88
+	 * @param string $itemname
89
+	 * @param string $modulename
90
+	 *
91
+	 * @return the requested objects or FALSE if they don't exists in the registry
92
+	 */
93 93
 	function getObjects($itemname, $modulename) {
94 94
 		if (!$modulename) {
95 95
 			global $xoopsModule;
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 	}
114 114
 
115 115
 	/**
116
-    * Fetching objects from the registry, as a list : objectid => identifier
117
-    *
118
-    * @param string $itemname
119
-    * @param string $modulename
120
-    *
121
-    * @return the requested objects or FALSE if they don't exists in the registry
122
-    */
116
+	 * Fetching objects from the registry, as a list : objectid => identifier
117
+	 *
118
+	 * @param string $itemname
119
+	 * @param string $modulename
120
+	 *
121
+	 * @return the requested objects or FALSE if they don't exists in the registry
122
+	 */
123 123
 	function getList($itemname, $modulename) {
124 124
 		if (!$modulename) {
125 125
 			global $xoopsModule;
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
 	}
144 144
 
145 145
 	/**
146
-    * Retreive a single object
147
-    *
148
-    * @param string $itemname
149
-    * @param string $key
150
-    *
151
-    * @return the requestd object or FALSE if they don't exists in the registry
152
-    */
146
+	 * Retreive a single object
147
+	 *
148
+	 * @param string $itemname
149
+	 * @param string $key
150
+	 *
151
+	 * @return the requestd object or FALSE if they don't exists in the registry
152
+	 */
153 153
 	function getSingleObject($itemname, $key, $modulename=false) {
154 154
 		if (!$modulename) {
155 155
 			global $xoopsModule;
Please login to merge, or discard this patch.
class/smartuploader.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -29,27 +29,27 @@  discard block
 block discarded – undo
29 29
 // Project: The XOOPS Project                                                //
30 30
 // ------------------------------------------------------------------------- //
31 31
 /**
32
- * !
33
- * Example
34
- *
35
- * include_once 'uploader.php';
36
- * $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
37
- * $maxfilesize = 50000;
38
- * $maxfilewidth = 120;
39
- * $maxfileheight = 120;
40
- * $uploader = new SmartUploader('/home/xoops/uploads', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
41
- * if ($uploader->fetchMedia($HTTP_POST_VARS['uploade_file_name'])) {
42
- * if (!$uploader->upload()) {
43
- * echo $uploader->getErrors();
44
- * } else {
45
- * echo '<h4>File uploaded successfully!</h4>'
46
- * echo 'Saved as: ' . $uploader->getSavedFileName() . '<br />';
47
- * echo 'Full path: ' . $uploader->getSavedDestination();
48
- * }
49
- * } else {
50
- * echo $uploader->getErrors();
51
- * }
52
- */
32
+	 * !
33
+	 * Example
34
+	 *
35
+	 * include_once 'uploader.php';
36
+	 * $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
37
+	 * $maxfilesize = 50000;
38
+	 * $maxfilewidth = 120;
39
+	 * $maxfileheight = 120;
40
+	 * $uploader = new SmartUploader('/home/xoops/uploads', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
41
+	 * if ($uploader->fetchMedia($HTTP_POST_VARS['uploade_file_name'])) {
42
+	 * if (!$uploader->upload()) {
43
+	 * echo $uploader->getErrors();
44
+	 * } else {
45
+	 * echo '<h4>File uploaded successfully!</h4>'
46
+	 * echo 'Saved as: ' . $uploader->getSavedFileName() . '<br />';
47
+	 * echo 'Full path: ' . $uploader->getSavedDestination();
48
+	 * }
49
+	 * } else {
50
+	 * echo $uploader->getErrors();
51
+	 * }
52
+	 */
53 53
 
54 54
 /**
55 55
  * Upload Media files
@@ -88,49 +88,49 @@  discard block
 block discarded – undo
88 88
 class SmartUploader extends XoopsMediaUploader
89 89
 {
90 90
 
91
-    var $ext;
92
-    var $dimension;
91
+	var $ext;
92
+	var $dimension;
93 93
 
94
-    /**
95
-     * No admin check for uploads
96
-     */
97
-    var $noadmin_sizecheck;
98
-    /**
99
-     * Constructor
100
-     *
101
-     * @param string $uploadDir
102
-     * @param array $allowedMimeTypes
103
-     * @param int $maxFileSize
104
-     * @param int $maxWidth
105
-     * @param int $maxHeight
106
-     * @param int $cmodvalue
107
-     */
108
-    function SmartUploader($uploadDir, $allowedMimeTypes = 0, $maxFileSize, $maxWidth = 0, $maxHeight = 0)
109
-    {
110
-        $this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
111
-    }
94
+	/**
95
+	 * No admin check for uploads
96
+	 */
97
+	var $noadmin_sizecheck;
98
+	/**
99
+	 * Constructor
100
+	 *
101
+	 * @param string $uploadDir
102
+	 * @param array $allowedMimeTypes
103
+	 * @param int $maxFileSize
104
+	 * @param int $maxWidth
105
+	 * @param int $maxHeight
106
+	 * @param int $cmodvalue
107
+	 */
108
+	function SmartUploader($uploadDir, $allowedMimeTypes = 0, $maxFileSize, $maxWidth = 0, $maxHeight = 0)
109
+	{
110
+		$this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
111
+	}
112 112
 
113
-    function noAdminSizeCheck($value)
114
-    {
115
-        $this->noadmin_sizecheck = $value;
116
-    }
113
+	function noAdminSizeCheck($value)
114
+	{
115
+		$this->noadmin_sizecheck = $value;
116
+	}
117 117
 
118
-    /**
119
-     * Is the file the right size?
120
-     *
121
-     * @return bool
122
-     */
123
-    function checkMaxFileSize()
124
-    {
125
-        if ($this->noadmin_sizecheck)
126
-        {
127
-            return true;
128
-        }
129
-        if ($this->mediaSize > $this->maxFileSize)
130
-        {
131
-            return false;
132
-        }
133
-        return true;
134
-    }
118
+	/**
119
+	 * Is the file the right size?
120
+	 *
121
+	 * @return bool
122
+	 */
123
+	function checkMaxFileSize()
124
+	{
125
+		if ($this->noadmin_sizecheck)
126
+		{
127
+			return true;
128
+		}
129
+		if ($this->mediaSize > $this->maxFileSize)
130
+		{
131
+			return false;
132
+		}
133
+		return true;
134
+	}
135 135
 }
136 136
 ?>
137 137
\ No newline at end of file
Please login to merge, or discard this patch.
class/smartplugins.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
 
18 18
 	function getItemList() {
19 19
 		$itemsArray = $this->_infoArray['items'];
20
-    	foreach ($itemsArray as $k=>$v) {
20
+		foreach ($itemsArray as $k=>$v) {
21 21
 			$ret[$k] = $v['caption'];
22
-    	}
23
-    	return $ret;
22
+		}
23
+		return $ret;
24 24
 	}
25 25
 
26 26
 	function getItem() {
Please login to merge, or discard this patch.
class/smartobjecttag.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,25 +28,25 @@
 block discarded – undo
28 28
 // -------------------------------------------------------------------------//
29 29
 
30 30
 if (!defined("XOOPS_ROOT_PATH")) {
31
-    die("XOOPS root path not defined");
31
+	die("XOOPS root path not defined");
32 32
 }
33 33
 include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartmlobject.php";
34 34
 class SmartobjectTag extends SmartMlObject {
35 35
 
36
-    function SmartobjectTag() {
36
+	function SmartobjectTag() {
37 37
 		$this->initVar('tagid', XOBJ_DTYPE_INT, '', true);
38
-        $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true);
39
-        $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC);
40
-        $this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC);
38
+		$this->initVar('name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_TAG_TAGID_CAPTION, _CO_SOBJECT_TAG_TAGID_DSC, true);
39
+		$this->initVar('description', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_TAG_DESCRIPTION_CAPTION, _CO_SOBJECT_TAG_DESCRIPTION_DSC);
40
+		$this->initVar('value', XOBJ_DTYPE_TXTAREA, '', true, null, '', true, _CO_SOBJECT_TAG_VALUE_CAPTION, _CO_SOBJECT_TAG_VALUE_DSC);
41 41
 
42 42
 		// call parent constructor to get Multilanguage field initiated
43
-        $this->SmartMlObject();
44
-    }
43
+		$this->SmartMlObject();
44
+	}
45 45
 }
46 46
 class SmartobjectTagHandler extends SmartPersistableMlObjectHandler {
47
-    function SmartobjectTagHandler($db) {
48
-        $this->SmartPersistableObjectHandler($db, 'tag', 'tagid', 'name', 'description', 'smartobject');
49
-    }
47
+	function SmartobjectTagHandler($db) {
48
+		$this->SmartPersistableObjectHandler($db, 'tag', 'tagid', 'name', 'description', 'smartobject');
49
+	}
50 50
 
51 51
 	function getLanguages() {
52 52
 		include_once XOOPS_ROOT_PATH."/class/xoopslists.php";
Please login to merge, or discard this patch.
class/smartmlobject.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -16,78 +16,78 @@
 block discarded – undo
16 16
 }
17 17
 include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartobject.php";
18 18
 /**
19
- * SmartObject base Multilanguage-enabled class
20
- *
21
- * Base class representing a single SmartObject with multilanguages capabilities
22
- *
23
- * @package SmartObject
24
- * @author marcan <[email protected]>
25
- * @link http://smartfactory.ca The SmartFactory
26
- */
19
+	 * SmartObject base Multilanguage-enabled class
20
+	 *
21
+	 * Base class representing a single SmartObject with multilanguages capabilities
22
+	 *
23
+	 * @package SmartObject
24
+	 * @author marcan <[email protected]>
25
+	 * @link http://smartfactory.ca The SmartFactory
26
+	 */
27 27
 class SmartMlObject extends SmartObject {
28
-    function SmartMlObject() {
29
-        $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, "", true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true);
28
+	function SmartMlObject() {
29
+		$this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, "", true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true);
30 30
 		$this->setControl('language', 'language');
31
-    }
31
+	}
32 32
 
33
-    /**
34
-     * If object is not new, change the control of the not-multilanguage fields
35
-     *
36
-     * We need to intercept this function from SmartObject because if the object is not new...
37
-     */
33
+	/**
34
+	 * If object is not new, change the control of the not-multilanguage fields
35
+	 *
36
+	 * We need to intercept this function from SmartObject because if the object is not new...
37
+	 */
38 38
    // function getForm() {
39 39
 
40
-    //}
41
-
42
-    /**
43
-     * Strip Multilanguage Fields
44
-     *
45
-     * Get rid of all the multilanguage fields to have an object with only global fields.
46
-     * This will be usefull when creating the ML object for the first time. Then we will be able
47
-     * to create translations.
48
-     */
49
-     function stripMultilanguageFields() {
50
-     	$objectVars = $this->getVars();
51
-     	$newObjectVars = array();
52
-     	foreach($objectVars as $key=>$var) {
53
-     		if (!$var['multilingual']) {
54
-     			$newObjectVars[$key] = $var;
55
-     		}
56
-     	}
57
-     	$this->vars = $newObjectVars;
58
-     }
59
-
60
-     function stripNonMultilanguageFields() {
61
-     	$objectVars = $this->getVars();
62
-     	$newObjectVars = array();
63
-     	foreach($objectVars as $key=>$var) {
64
-     		if ($var['multilingual'] || $key == $this->handler->keyName) {
65
-     			$newObjectVars[$key] = $var;
66
-     		}
67
-     	}
68
-     	$this->vars = $newObjectVars;
69
-     }
70
-
71
-     /**
72
-      * Make non multilanguage fields read only
73
-      *
74
-      * This is used when we are creating/editing a translation.
75
-      * We only want to edit the multilanguag fields, not the global one.
76
-      */
77
-     function makeNonMLFieldReadOnly() {
78
-     	foreach($this->getVars() as $key=>$var) {
79
-     		//if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) {
80
-     		if ((!$var['multilingual'] && $key <> $this->handler->keyName)) {
81
-     			$this->setControl($key, 'label');
82
-     		}
83
-     	}
84
-     }
85
-
86
-    function getEditLanguageLink($onlyUrl=false, $withimage=true)
87
-    {
88
-    	$controller = new SmartObjectController($this->handler);
89
-    	return $controller->getEditLanguageLink($this, $onlyUrl, $withimage);
90
-    }
40
+	//}
41
+
42
+	/**
43
+	 * Strip Multilanguage Fields
44
+	 *
45
+	 * Get rid of all the multilanguage fields to have an object with only global fields.
46
+	 * This will be usefull when creating the ML object for the first time. Then we will be able
47
+	 * to create translations.
48
+	 */
49
+	 function stripMultilanguageFields() {
50
+	 	$objectVars = $this->getVars();
51
+	 	$newObjectVars = array();
52
+	 	foreach($objectVars as $key=>$var) {
53
+	 		if (!$var['multilingual']) {
54
+	 			$newObjectVars[$key] = $var;
55
+	 		}
56
+	 	}
57
+	 	$this->vars = $newObjectVars;
58
+	 }
59
+
60
+	 function stripNonMultilanguageFields() {
61
+	 	$objectVars = $this->getVars();
62
+	 	$newObjectVars = array();
63
+	 	foreach($objectVars as $key=>$var) {
64
+	 		if ($var['multilingual'] || $key == $this->handler->keyName) {
65
+	 			$newObjectVars[$key] = $var;
66
+	 		}
67
+	 	}
68
+	 	$this->vars = $newObjectVars;
69
+	 }
70
+
71
+	 /**
72
+	  * Make non multilanguage fields read only
73
+	  *
74
+	  * This is used when we are creating/editing a translation.
75
+	  * We only want to edit the multilanguag fields, not the global one.
76
+	  */
77
+	 function makeNonMLFieldReadOnly() {
78
+	 	foreach($this->getVars() as $key=>$var) {
79
+	 		//if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) {
80
+	 		if ((!$var['multilingual'] && $key <> $this->handler->keyName)) {
81
+	 			$this->setControl($key, 'label');
82
+	 		}
83
+	 	}
84
+	 }
85
+
86
+	function getEditLanguageLink($onlyUrl=false, $withimage=true)
87
+	{
88
+		$controller = new SmartObjectController($this->handler);
89
+		return $controller->getEditLanguageLink($this, $onlyUrl, $withimage);
90
+	}
91 91
 
92 92
 }
93 93
 
Please login to merge, or discard this patch.
class/smartobjecthandler.php 1 patch
Indentation   +847 added lines, -847 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 if (!defined("XOOPS_ROOT_PATH")) {
15
-    die("XOOPS root path not defined");
15
+	die("XOOPS root path not defined");
16 16
 }
17 17
 
18 18
 
@@ -30,855 +30,855 @@  discard block
 block discarded – undo
30 30
 
31 31
 class SmartPersistableObjectHandler extends XoopsObjectHandler {
32 32
 
33
-    var $_itemname;
34
-
35
-    /**
36
-     * Name of the table use to store this {@link SmartObject}
37
-     *
38
-     * Note that the name of the table needs to be free of the database prefix.
39
-     * For example "smartsection_categories"
40
-     * @var string
41
-     */
42
-    var $table;
43
-
44
-    /**
45
-     * Name of the table key that uniquely identify each {@link SmartObject}
46
-     *
47
-     * For example : "categoryid"
48
-     * @var string
49
-     */
50
-    var $keyName;
51
-
52
-    /**
53
-     * Name of the class derived from {@link SmartObject} and which this handler is handling
54
-     *
55
-     * Note that this string needs to be lowercase
56
-     *
57
-     * For example : "smartsectioncategory"
58
-     * @var string
59
-     */
60
-    var $className;
61
-
62
-    /**
63
-     * Name of the field which properly identify the {@link SmartObject}
64
-     *
65
-     * For example : "name" (this will be the category's name)
66
-     * @var string
67
-     */
68
-    var $identifierName;
69
-
70
-    /**
71
-     * Name of the field which will be use as a summary for the object
72
-     *
73
-     * For example : "summary"
74
-     * @var string
75
-     */
76
-    var $summaryName;
77
-
78
-    /**
79
-     * Page name use to basically manage and display the {@link SmartObject}
80
-     *
81
-     * This page needs to be the same in user side and admin side
82
-     *
83
-     * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
84
-     * @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
85
-     * @var string
86
-     */
87
-    var $_page;
88
-
89
-    /**
90
-     * Full path of the module using this {@link SmartObject}
91
-     *
92
-     * <code>XOOPS_URL . "/modules/smartsection/"</code>
93
-     * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
94
-     * @var string
95
-     */
96
-    var $_modulePath;
97
-
98
-    var $_moduleUrl;
99
-
100
-    var $_moduleName;
101
-
102
-    var $_uploadUrl;
103
-
104
-    var $_uploadPath;
105
-
106
-    var $_allowedMimeTypes = 0;
107
-
108
-    var $_maxFileSize = 1000000;
109
-
110
-    var $_maxWidth = 500;
111
-
112
-    var $_maxHeight = 500;
113
-
114
-    var $highlightFields = array();
115
-
116
-    /**
117
-     * Array containing the events name and functions
118
-     *
119
-     * @var array
120
-     */
121
-    var $eventArray = array();
122
-
123
-    /**
124
-     * Array containing the permissions that this handler will manage on the objects
125
-     *
126
-     * @var array
127
-     */
128
-    var $permissionsArray = false;
129
-
130
-    var $generalSQL=false;
131
-
132
-    var $_eventHooks=array();
133
-    var $_disabledEvents=array();
134
-
135
-    /**
136
-     * Constructor - called from child classes
137
-     *
138
-     * @param object $db {@link XoopsDatabase} object
139
-     * @param string $tablename Name of the table use to store this {@link SmartObject}
140
-     * @param string Name of the class derived from {@link SmartObject} and which this handler is handling
141
-     * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject}
142
-     * @param string $idenfierName Name of the field which properly identify the {@link SmartObject}
143
-     * @param string $page Page name use to basically manage and display the {@link SmartObject}
144
-     * @param string $moduleName name of the module
145
-     */
146
-    function SmartPersistableObjectHandler(&$db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) {
147
-
148
-        $this->XoopsObjectHandler($db);
149
-
150
-        $this->_itemname = $itemname;
151
-        $this->_moduleName = $modulename;
152
-        $this->table = $db->prefix($modulename . "_" . $itemname);
153
-        $this->keyName = $keyname;
154
-        $this->className = ucfirst($modulename) . ucfirst($itemname);
155
-        $this->identifierName = $idenfierName;
156
-        $this->summaryName = $summaryName;
157
-        $this->_page = $itemname . ".php";
158
-        $this->_modulePath = XOOPS_ROOT_PATH . "/modules/" . $this->_moduleName . "/";
159
-        $this->_moduleUrl = XOOPS_URL . "/modules/" . $this->_moduleName . "/";
160
-        $this->_uploadPath = XOOPS_UPLOAD_PATH . "/" . $this->_moduleName . "/";
161
-        $this->_uploadUrl = XOOPS_UPLOAD_URL . "/" . $this->_moduleName . "/";
162
-    }
163
-
164
-    function addEventHook($event, $method) {
165
-        $this->_eventHooks[$event] = $method;
166
-    }
167
-
168
-    /**
169
-     * Add a permission that this handler will manage for its objects
170
-     *
171
-     * Example : $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
172
-     *
173
-     * @param string $perm_name name of the permission
174
-     * @param string $caption caption of the control that will be displayed in the form
175
-     * @param string $description description of the control that will be displayed in the form
176
-     */
177
-    function addPermission($perm_name, $caption, $description=false) {
178
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
179
-
180
-        $this->permissionsArray[] = array(
33
+	var $_itemname;
34
+
35
+	/**
36
+	 * Name of the table use to store this {@link SmartObject}
37
+	 *
38
+	 * Note that the name of the table needs to be free of the database prefix.
39
+	 * For example "smartsection_categories"
40
+	 * @var string
41
+	 */
42
+	var $table;
43
+
44
+	/**
45
+	 * Name of the table key that uniquely identify each {@link SmartObject}
46
+	 *
47
+	 * For example : "categoryid"
48
+	 * @var string
49
+	 */
50
+	var $keyName;
51
+
52
+	/**
53
+	 * Name of the class derived from {@link SmartObject} and which this handler is handling
54
+	 *
55
+	 * Note that this string needs to be lowercase
56
+	 *
57
+	 * For example : "smartsectioncategory"
58
+	 * @var string
59
+	 */
60
+	var $className;
61
+
62
+	/**
63
+	 * Name of the field which properly identify the {@link SmartObject}
64
+	 *
65
+	 * For example : "name" (this will be the category's name)
66
+	 * @var string
67
+	 */
68
+	var $identifierName;
69
+
70
+	/**
71
+	 * Name of the field which will be use as a summary for the object
72
+	 *
73
+	 * For example : "summary"
74
+	 * @var string
75
+	 */
76
+	var $summaryName;
77
+
78
+	/**
79
+	 * Page name use to basically manage and display the {@link SmartObject}
80
+	 *
81
+	 * This page needs to be the same in user side and admin side
82
+	 *
83
+	 * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
84
+	 * @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
85
+	 * @var string
86
+	 */
87
+	var $_page;
88
+
89
+	/**
90
+	 * Full path of the module using this {@link SmartObject}
91
+	 *
92
+	 * <code>XOOPS_URL . "/modules/smartsection/"</code>
93
+	 * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
94
+	 * @var string
95
+	 */
96
+	var $_modulePath;
97
+
98
+	var $_moduleUrl;
99
+
100
+	var $_moduleName;
101
+
102
+	var $_uploadUrl;
103
+
104
+	var $_uploadPath;
105
+
106
+	var $_allowedMimeTypes = 0;
107
+
108
+	var $_maxFileSize = 1000000;
109
+
110
+	var $_maxWidth = 500;
111
+
112
+	var $_maxHeight = 500;
113
+
114
+	var $highlightFields = array();
115
+
116
+	/**
117
+	 * Array containing the events name and functions
118
+	 *
119
+	 * @var array
120
+	 */
121
+	var $eventArray = array();
122
+
123
+	/**
124
+	 * Array containing the permissions that this handler will manage on the objects
125
+	 *
126
+	 * @var array
127
+	 */
128
+	var $permissionsArray = false;
129
+
130
+	var $generalSQL=false;
131
+
132
+	var $_eventHooks=array();
133
+	var $_disabledEvents=array();
134
+
135
+	/**
136
+	 * Constructor - called from child classes
137
+	 *
138
+	 * @param object $db {@link XoopsDatabase} object
139
+	 * @param string $tablename Name of the table use to store this {@link SmartObject}
140
+	 * @param string Name of the class derived from {@link SmartObject} and which this handler is handling
141
+	 * @param string $keyname Name of the table key that uniquely identify each {@link SmartObject}
142
+	 * @param string $idenfierName Name of the field which properly identify the {@link SmartObject}
143
+	 * @param string $page Page name use to basically manage and display the {@link SmartObject}
144
+	 * @param string $moduleName name of the module
145
+	 */
146
+	function SmartPersistableObjectHandler(&$db, $itemname, $keyname, $idenfierName, $summaryName, $modulename) {
147
+
148
+		$this->XoopsObjectHandler($db);
149
+
150
+		$this->_itemname = $itemname;
151
+		$this->_moduleName = $modulename;
152
+		$this->table = $db->prefix($modulename . "_" . $itemname);
153
+		$this->keyName = $keyname;
154
+		$this->className = ucfirst($modulename) . ucfirst($itemname);
155
+		$this->identifierName = $idenfierName;
156
+		$this->summaryName = $summaryName;
157
+		$this->_page = $itemname . ".php";
158
+		$this->_modulePath = XOOPS_ROOT_PATH . "/modules/" . $this->_moduleName . "/";
159
+		$this->_moduleUrl = XOOPS_URL . "/modules/" . $this->_moduleName . "/";
160
+		$this->_uploadPath = XOOPS_UPLOAD_PATH . "/" . $this->_moduleName . "/";
161
+		$this->_uploadUrl = XOOPS_UPLOAD_URL . "/" . $this->_moduleName . "/";
162
+	}
163
+
164
+	function addEventHook($event, $method) {
165
+		$this->_eventHooks[$event] = $method;
166
+	}
167
+
168
+	/**
169
+	 * Add a permission that this handler will manage for its objects
170
+	 *
171
+	 * Example : $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
172
+	 *
173
+	 * @param string $perm_name name of the permission
174
+	 * @param string $caption caption of the control that will be displayed in the form
175
+	 * @param string $description description of the control that will be displayed in the form
176
+	 */
177
+	function addPermission($perm_name, $caption, $description=false) {
178
+		include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
179
+
180
+		$this->permissionsArray[] = array(
181 181
    			'perm_name' => $perm_name,
182 182
    			'caption' => $caption,
183 183
    			'description' => $description
184
-        );
185
-    }
186
-
187
-    function setGrantedObjectsCriteria(&$criteria, $perm_name) {
188
-        $smartpermissions_handler = new SmartobjectPermissionHandler($this);
189
-        $grantedItems = $smartpermissions_handler->getGrantedItems($perm_name);
190
-        if (count($grantedItems) > 0) {
191
-            $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
192
-            return true;
193
-        } else {
194
-            return false;
195
-        }
196
-    }
197
-
198
-    function setUploaderConfig($_uploadPath=false, $_allowedMimeTypes=false, $_maxFileSize=false, $_maxWidth=false, $_maxHeight=false) {
199
-        $this->_uploadPath = $_uploadPath ? $_uploadPath : $this->_uploadPath;
200
-        $this->_allowedMimeTypes = $_allowedMimeTypes ? $_allowedMimeTypes : $this->_allowedMimeTypes;
201
-        $this->_maxFileSize = $_maxFileSize ? $_maxFileSize : $this->_maxFileSize;
202
-        $this->_maxWidth = $_maxWidth ? $_maxWidth : $this->_maxWidth;
203
-        $this->_maxHeight = $_maxHeight ? $_maxHeight : $this->_maxHeight;
204
-    }
205
-
206
-    /**
207
-     * create a new {@link SmartObject}
208
-     *
209
-     * @param bool $isNew Flag the new objects as "new"?
210
-     *
211
-     * @return object {@link SmartObject}
212
-     */
213
-    function &create($isNew = true) {
214
-        $obj = new $this->className($this);
215
-        $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
216
-        if (!$obj->handler) {
217
-            $obj->handler =& $this;
218
-        }
219
-
220
-        if ($isNew === true) {
221
-            $obj->setNew();
222
-        }
223
-        return $obj;
224
-    }
225
-
226
-    function getImageUrl() {
227
-        return $this->_uploadUrl . $this->_itemname . "/";
228
-    }
229
-
230
-    function getImagePath() {
231
-        $dir = $this->_uploadPath . $this->_itemname;
232
-        if (!file_exists($dir)) {
233
-            smart_admin_mkdir($dir);
234
-        }
235
-        return $dir . "/";
236
-    }
237
-
238
-    /**
239
-     * retrieve a {@link SmartObject}
240
-     *
241
-     * @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
242
-     * @param bool $as_object whether to return an object or an array
243
-     * @return mixed reference to the {@link SmartObject}, FALSE if failed
244
-     */
245
-    function &get($id, $as_object = true, $debug=false, $criteria=false) {
246
-        if (!$criteria) {
247
-            $criteria = new CriteriaCompo();
248
-        }
249
-        if (is_array($this->keyName)) {
250
-            for ($i = 0; $i < count($this->keyName); $i++) {
251
-                /**
252
-                 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
253
-                 * Is the fact that we removed the intval() represents a security risk ?
254
-                 */
255
-                //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
256
-                $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
257
-            }
258
-        }
259
-        else {
260
-            //$criteria = new Criteria($this->keyName, intval($id), '=', $this->_itemname);
261
-            /**
262
-            * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
263
-            * Is the fact that we removed the intval() represents a security risk ?
264
-            */
265
-            $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
266
-        }
267
-        $criteria->setLimit(1);
268
-        if ($debug) {
269
-            $obj_array = $this->getObjectsD($criteria, false, $as_object);
270
-        } else {
271
-            $obj_array = $this->getObjects($criteria, false, $as_object);
272
-            //patch : weird bug of indexing by id even if id_as_key = false;
273
-            if(!isset($obj_array[0]) && is_object($obj_array[$id])){
274
-                $obj_array[0] = $obj_array[$id];
275
-                unset($obj_array[$id]);
276
-                $obj_array[0]->unsetNew();
277
-            }
278
-        }
279
-
280
-        if (count($obj_array) != 1) {
281
-            $obj = $this->create();
282
-            return $obj;
283
-        }
284
-
285
-        return $obj_array[0];
286
-    }
287
-
288
-    /**
289
-     * retrieve a {@link SmartObject}
290
-     *
291
-     * @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
292
-     * @param bool $as_object whether to return an object or an array
293
-     * @return mixed reference to the {@link SmartObject}, FALSE if failed
294
-     */
295
-    function &getD($id, $as_object = true) {
296
-        return $this->get($id, $as_object, true);
297
-    }
298
-
299
-    /**
300
-     * retrieve objects from the database
301
-     *
302
-     * @param object $criteria {@link CriteriaElement} conditions to be met
303
-     * @param bool $id_as_key use the ID as key for the array?
304
-     * @param bool $as_object return an array of objects?
305
-     *
306
-     * @return array
307
-     */
308
-    function getObjects($criteria = null, $id_as_key = false, $as_object = true, $sql=false, $debug=false)
309
-    {
310
-        $ret = array();
311
-        $limit = $start = 0;
312
-
313
-        if ($this->generalSQL) {
314
-            $sql = $this->generalSQL;
315
-        } elseif(!$sql) {
316
-            $sql = 'SELECT * FROM '.$this->table . " AS " . $this->_itemname;
317
-        }
318
-
319
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
320
-            $sql .= ' '.$criteria->renderWhere();
321
-            if ($criteria->getSort() != '') {
322
-                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
323
-            }
324
-            $limit = $criteria->getLimit();
325
-            $start = $criteria->getStart();
326
-        }
327
-        if ($debug) {
328
-            xoops_debug($sql);
329
-        }
330
-
331
-        $result = $this->db->query($sql, $limit, $start);
332
-        if (!$result) {
333
-            return $ret;
334
-        }
335
-        return $this->convertResultSet($result, $id_as_key, $as_object);
336
-    }
337
-
338
-    function query($sql, $criteria, $force=false, $debug=false)
339
-    {
340
-        $ret = array();
341
-
342
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
343
-            $sql .= ' '.$criteria->renderWhere();
344
-            if ($criteria->groupby) {
345
-                $sql .= $criteria->getGroupby();
346
-            }
347
-            if ($criteria->getSort() != '') {
348
-                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
349
-            }
350
-
351
-        }
352
-        if ($debug) {
353
-            xoops_debug($sql);
354
-        }
355
-
356
-        if ($force) {
357
-            $result = $this->db->queryF($sql);
358
-        } else {
359
-            $result = $this->db->query($sql);
360
-        }
361
-
362
-        if (!$result) {
363
-            return $ret;
364
-        }
365
-
366
-        while ($myrow = $this->db->fetchArray($result)) {
367
-            $ret[] = $myrow;
368
-        }
369
-
370
-        return $ret;
371
-    }
372
-
373
-    /**
374
-     * retrieve objects with debug mode - so will show the query
375
-     *
376
-     * @param object $criteria {@link CriteriaElement} conditions to be met
377
-     * @param bool $id_as_key use the ID as key for the array?
378
-     * @param bool $as_object return an array of objects?
379
-     *
380
-     * @return array
381
-     */
382
-    function getObjectsD($criteria = null, $id_as_key = false, $as_object = true, $sql = false)
383
-    {
384
-        return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
385
-    }
386
-
387
-    function getObjectsAsArray($arrayObjects) {
388
-        $ret = array();
389
-        foreach ($arrayObjects as $key => $object) {
390
-            $ret[$key] = $object->toArray();
391
-        }
392
-        if (count($ret > 0)) {
393
-            return $ret;
394
-        } else {
395
-            return false;
396
-        }
397
-    }
398
-
399
-    /**
400
-     * Convert a database resultset to a returnable array
401
-     *
402
-     * @param object $result database resultset
403
-     * @param bool $id_as_key - should NOT be used with joint keys
404
-     * @param bool $as_object
405
-     *
406
-     * @return array
407
-     */
408
-    function convertResultSet($result, $id_as_key = false, $as_object = true) {
409
-        $ret = array();
410
-        while ($myrow = $this->db->fetchArray($result)) {
411
-
412
-            $obj =& $this->create(false);
413
-            $obj->assignVars($myrow);
414
-            if (!$id_as_key) {
415
-                if ($as_object) {
416
-                    $ret[] =& $obj;
417
-                }
418
-                else {
419
-                    $ret[] = $obj->toArray();
420
-                }
421
-            } else {
422
-                if ($as_object) {
423
-                    $value =& $obj;
424
-                }
425
-                else {
426
-                    $value = $obj->toArray();
427
-                }
428
-                if ($id_as_key === 'parentid') {
429
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
430
-                } else {
431
-                    $ret[$obj->getVar($this->keyName)] = $value;
432
-                }
433
-            }
434
-            unset($obj);
435
-        }
436
-
437
-        return $ret;
438
-    }
439
-
440
-    function getListD($criteria = null, $limit = 0, $start = 0) {
441
-        return $this->getList($criteria, $limit, $start, true);
442
-    }
443
-
444
-    /**
445
-     * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
446
-     *
447
-     * @param object $criteria {@link CriteriaElement} conditions to be met
448
-     * @param int   $limit      Max number of objects to fetch
449
-     * @param int   $start      Which record to start at
450
-     *
451
-     * @return array
452
-     */
453
-    function getList($criteria = null, $limit = 0, $start = 0, $debug=false) {
454
-        $ret = array();
455
-        if ($criteria == null) {
456
-            $criteria = new CriteriaCompo();
457
-        }
458
-
459
-        if ($criteria->getSort() == '') {
460
-            $criteria->setSort($this->getIdentifierName());
461
-        }
462
-
463
-        $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName) ;
464
-        if(!empty($this->identifierName)){
465
-            $sql .= ', '.$this->getIdentifierName();
466
-        }
467
-        $sql .= ' FROM '.$this->table . " AS " . $this->_itemname;
468
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
469
-            $sql .= ' '.$criteria->renderWhere();
470
-            if ($criteria->getSort() != '') {
471
-                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
472
-            }
473
-            $limit = $criteria->getLimit();
474
-            $start = $criteria->getStart();
475
-        }
476
-
477
-        if ($debug) {
478
-            xoops_debug($sql);
479
-        }
480
-
481
-        $result = $this->db->query($sql, $limit, $start);
482
-        if (!$result) {
483
-            return $ret;
484
-        }
485
-
486
-        $myts =& MyTextSanitizer::getInstance();
487
-        while ($myrow = $this->db->fetchArray($result)) {
488
-            //identifiers should be textboxes, so sanitize them like that
489
-            $ret[$myrow[$this->keyName]] = empty($this->identifierName)?1:$myts->displayTarea($myrow[$this->identifierName]);
490
-        }
491
-        return $ret;
492
-    }
493
-
494
-    /**
495
-     * count objects matching a condition
496
-     *
497
-     * @param object $criteria {@link CriteriaElement} to match
498
-     * @return int count of objects
499
-     */
500
-    function getCount($criteria = null)
501
-    {
502
-        $field = "";
503
-        $groupby = false;
504
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
505
-            if ($criteria->groupby != "") {
506
-                $groupby = true;
507
-                $field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
508
-            }
509
-        }
510
-        /**
511
-         * if we have a generalSQL, lets used this one.
512
-         * This needs to be improved...
513
-         */
514
-        if ($this->generalSQL) {
515
-            $sql = $this->generalSQL;
516
-            $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
517
-        } else {
518
-            $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table . ' AS ' . $this->_itemname;
519
-        }
520
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
521
-            $sql .= ' '.$criteria->renderWhere();
522
-            if ($criteria->groupby != "") {
523
-                $sql .= $criteria->getGroupby();
524
-            }
525
-        }
526
-
527
-        $result = $this->db->query($sql);
528
-        if (!$result) {
529
-            return 0;
530
-        }
531
-        if ($groupby == false) {
532
-            list($count) = $this->db->fetchRow($result);
533
-            return $count;
534
-        }
535
-        else {
536
-            $ret = array();
537
-            while (list($id, $count) = $this->db->fetchRow($result)) {
538
-                $ret[$id] = $count;
539
-            }
540
-            return $ret;
541
-        }
542
-    }
543
-
544
-    /**
545
-     * delete an object from the database
546
-     *
547
-     * @param object $obj reference to the object to delete
548
-     * @param bool $force
549
-     * @return bool FALSE if failed.
550
-     */
551
-    function delete(&$obj, $force = false)
552
-    {
553
-        $eventResult = $this->executeEvent('beforeDelete', $obj);
554
-        if (!$eventResult) {
555
-            $obj->setErrors("An error occured during the BeforeDelete event");
556
-            return false;
557
-        }
558
-
559
-        if (is_array($this->keyName)) {
560
-            $clause = array();
561
-            for ($i = 0; $i < count($this->keyName); $i++) {
562
-                $clause[] = $this->keyName[$i]." = ".$obj->getVar($this->keyName[$i]);
563
-            }
564
-            $whereclause = implode(" AND ", $clause);
565
-        }
566
-        else {
567
-            $whereclause = $this->keyName." = ".$obj->getVar($this->keyName);
568
-        }
569
-        $sql = "DELETE FROM ".$this->table . " WHERE ".$whereclause;
570
-        if (false != $force) {
571
-            $result = $this->db->queryF($sql);
572
-        } else {
573
-            $result = $this->db->query($sql);
574
-        }
575
-        if (!$result) {
576
-            return false;
577
-        }
578
-
579
-        $eventResult = $this->executeEvent('afterDelete', $obj);
580
-        if (!$eventResult) {
581
-            $obj->setErrors("An error occured during the AfterDelete event");
582
-            return false;
583
-        }
584
-        return true;
585
-    }
586
-
587
-    function disableEvent($event) {
588
-        if (is_array($event)) {
589
-            foreach($event as $v) {
590
-                $this->_disabledEvents[] = $v;
591
-            }
592
-        } else {
593
-            $this->_disabledEvents[] = $event;
594
-        }
595
-    }
596
-
597
-    function getPermissions() {
598
-        return $this->permissionsArray;
599
-    }
600
-
601
-    /**
602
-     * insert a new object in the database
603
-     *
604
-     * @param object $obj reference to the object
605
-     * @param bool $force whether to force the query execution despite security settings
606
-     * @param bool $checkObject check if the object is dirty and clean the attributes
607
-     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
608
-     */
609
-    function insert(&$obj, $force = false, $checkObject = true, $debug=false)
610
-    {
611
-        if ($checkObject != false) {
612
-            if (!is_object($obj)) {
613
-                return false;
614
-            }
615
-            /**
616
-             * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
617
-             */
618
-            if (!is_a($obj, $this->className)) {
619
-                $obj->setError(get_class($obj)." Differs from ".$this->className);
620
-                return false;
621
-            }
622
-            if (!$obj->isDirty()) {
623
-                $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
624
-                return true;
625
-            }
626
-        }
627
-
628
-        if ($obj->seoEnabled) {
629
-            // Auto create meta tags if empty
630
-            $smartobject_metagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
631
-
632
-            if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
633
-
634
-                if (!$obj->meta_keywords()) {
635
-                    $obj->setVar('meta_keywords', $smartobject_metagen->_keywords);
636
-                }
637
-
638
-                if (!$obj->meta_description()) {
639
-                    $obj->setVar('meta_description', $smartobject_metagen->_meta_description);
640
-                }
641
-            }
642
-
643
-            // Auto create short_url if empty
644
-            if (!$obj->short_url()) {
645
-                $obj->setVar('short_url', $smartobject_metagen->generateSeoTitle($obj->title('n'), false));
646
-            }
647
-        }
648
-
649
-        $eventResult = $this->executeEvent('beforeSave', $obj);
650
-        if (!$eventResult) {
651
-            $obj->setErrors("An error occured during the BeforeSave event");
652
-            return false;
653
-        }
654
-
655
-        if ($obj->isNew()) {
656
-            $eventResult = $this->executeEvent('beforeInsert', $obj);
657
-            if (!$eventResult) {
658
-                $obj->setErrors("An error occured during the BeforeInsert event");
659
-                return false;
660
-            }
661
-
662
-        }	else {
663
-            $eventResult = $this->executeEvent('beforeUpdate', $obj);
664
-            if (!$eventResult) {
665
-                $obj->setErrors("An error occured during the BeforeUpdate event");
666
-                return false;
667
-            }
668
-        }
669
-        if (!$obj->cleanVars()) {
670
-            $obj->setErrors('Variables were not cleaned properly.');
671
-            return false;
672
-        }
673
-        $fieldsToStoreInDB = array();
674
-        foreach ($obj->cleanVars as $k => $v) {
675
-            if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
676
-                $cleanvars[$k] = intval($v);
677
-            } elseif (is_array($v) ) {
678
-                $cleanvars[ $k ] = $this->db->quoteString( implode( ',', $v ) );
679
-            } else {
680
-                $cleanvars[$k] = $this->db->quoteString($v);
681
-            }
682
-            if ($obj->vars[$k]['persistent']) {
683
-                $fieldsToStoreInDB[$k] = $cleanvars[$k];
684
-            }
685
-
686
-        }
687
-        if ($obj->isNew()) {
688
-            if (!is_array($this->keyName)) {
689
-                if ($cleanvars[$this->keyName] < 1) {
690
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
691
-                }
692
-            }
693
-
694
-            $sql = "INSERT INTO ".$this->table." (".implode(',', array_keys($fieldsToStoreInDB)).") VALUES (".implode(',', array_values($fieldsToStoreInDB)) .")";
695
-
696
-        } else {
697
-
698
-            $sql = "UPDATE ".$this->table." SET";
699
-            foreach ($fieldsToStoreInDB as $key => $value) {
700
-                if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
701
-                    continue;
702
-                }
703
-                if (isset($notfirst) ) {
704
-                    $sql .= ",";
705
-                }
706
-                $sql .= " ".$key." = ".$value;
707
-                $notfirst = true;
708
-            }
709
-            if (is_array($this->keyName)) {
710
-                $whereclause = "";
711
-                for ($i = 0; $i < count($this->keyName); $i++) {
712
-                    if ($i > 0) {
713
-                        $whereclause .= " AND ";
714
-                    }
715
-                    $whereclause .= $this->keyName[$i]." = ".$obj->getVar($this->keyName[$i]);
716
-                }
717
-            }
718
-            else {
719
-                $whereclause = $this->keyName." = ".$obj->getVar($this->keyName);
720
-            }
721
-            $sql .= " WHERE ".$whereclause;
722
-        }
723
-
724
-        if ($debug) {
725
-            xoops_debug($sql);
726
-        }
727
-
728
-        if (false != $force) {
729
-            $result = $this->db->queryF($sql);
730
-        } else {
731
-            $result = $this->db->query($sql);
732
-        }
733
-
734
-        if (!$result) {
735
-            $obj->setErrors($this->db->error());
736
-            return false;
737
-        }
738
-
739
-        if ($obj->isNew() && !is_array($this->keyName)) {
740
-            $obj->assignVar($this->keyName, $this->db->getInsertId());
741
-        }
742
-        $eventResult = $this->executeEvent('afterSave', $obj);
743
-        if (!$eventResult) {
744
-            $obj->setErrors("An error occured during the AfterSave event");
745
-            return false;
746
-        }
747
-
748
-        if ($obj->isNew()) {
749
-            $obj->unsetNew();
750
-            $eventResult = $this->executeEvent('afterInsert', $obj);
751
-            if (!$eventResult) {
752
-                $obj->setErrors("An error occured during the AfterInsert event");
753
-                return false;
754
-            }
755
-        } else {
756
-            $eventResult = $this->executeEvent('afterUpdate', $obj);
757
-            if (!$eventResult) {
758
-                $obj->setErrors("An error occured during the AfterUpdate event");
759
-                return false;
760
-            }
761
-        }
762
-        return true;
763
-    }
764
-
765
-    function insertD(&$obj, $force = false, $checkObject = true, $debug=false)
766
-    {
767
-        return $this->insert($obj, $force, $checkObject, true);
768
-    }
769
-
770
-    /**
771
-     * Change a value for objects with a certain criteria
772
-     *
773
-     * @param   string  $fieldname  Name of the field
774
-     * @param   string  $fieldvalue Value to write
775
-     * @param   object  $criteria   {@link CriteriaElement}
776
-     *
777
-     * @return  bool
778
-     **/
779
-    function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false)
780
-    {
781
-        $set_clause = $fieldname . ' = ';
782
-        if ( is_numeric( $fieldvalue ) ) {
783
-            $set_clause .=  $fieldvalue;
784
-        } elseif ( is_array( $fieldvalue ) ) {
785
-            $set_clause .= $this->db->quoteString( implode( ',', $fieldvalue ) );
786
-        } else {
787
-            $set_clause .= $this->db->quoteString( $fieldvalue );
788
-        }
789
-        $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
790
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
791
-            $sql .= ' '.$criteria->renderWhere();
792
-        }
793
-        if (false != $force) {
794
-            $result = $this->db->queryF($sql);
795
-        } else {
796
-            $result = $this->db->query($sql);
797
-        }
798
-        if (!$result) {
799
-            return false;
800
-        }
801
-        return true;
802
-    }
803
-
804
-    /**
805
-     * delete all objects meeting the conditions
806
-     *
807
-     * @param object $criteria {@link CriteriaElement} with conditions to meet
808
-     * @return bool
809
-     */
810
-
811
-    function deleteAll($criteria = null)
812
-    {
813
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
814
-            $sql = 'DELETE FROM '.$this->table;
815
-            $sql .= ' '.$criteria->renderWhere();
816
-            if (!$this->db->query($sql)) {
817
-                return false;
818
-            }
819
-            $rows = $this->db->getAffectedRows();
820
-            return $rows > 0 ? $rows : true;
821
-        }
822
-        return false;
823
-    }
824
-
825
-    function getModuleInfo() {
826
-        return smart_getModuleInfo($this->_moduleName);
827
-    }
828
-
829
-    function getModuleConfig() {
830
-        return smart_getModuleConfig($this->_moduleName);
831
-    }
832
-
833
-    function getModuleItemString() {
834
-        $ret = $this->_moduleName . '_' . $this->_itemname;
835
-        return $ret;
836
-    }
837
-
838
-    function updateCounter($object) {
839
-        if (isset($object->vars['counter'])) {
840
-            $new_counter = $object->getVar('counter') + 1;
841
-            $sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
842
-            $this->query($sql, null, true);
843
-        }
844
-    }
845
-
846
-    /**
847
-     * Execute the function associated with an event
848
-     * This method will check if the function is available
849
-     *
850
-     * @param string $event name of the event
851
-     * @param object $obj $object on which is performed the event
852
-     * @return mixed result of the execution of the function or FALSE if the function was not executed
853
-     */
854
-    function executeEvent($event, &$executeEventObj) {
855
-        if (!in_array($event, $this->_disabledEvents)) {
856
-            if (method_exists($this, $event)) {
857
-                $ret = $this->$event($executeEventObj);
858
-            } else {
859
-                // check to see if there is a hook for this event
860
-                if (isset($this->_eventHooks[$event])) {
861
-                    $method = $this->_eventHooks[$event];
862
-                    // check to see if the method specified by this hook exists
863
-                    if (method_exists($this, $method)) {
864
-                        $ret = $this->$method($executeEventObj);
865
-
866
-                    }
867
-                }
868
-                $ret = true;
869
-            }
870
-            return $ret;
871
-        }
872
-        return true;
873
-    }
874
-
875
-    function getIdentifierName($withprefix=true) {
876
-        if ($withprefix) {
877
-            return $this->_itemname . "." . $this->identifierName;
878
-        } else {
879
-            return $this->identifierName;
880
-        }
881
-    }
184
+		);
185
+	}
186
+
187
+	function setGrantedObjectsCriteria(&$criteria, $perm_name) {
188
+		$smartpermissions_handler = new SmartobjectPermissionHandler($this);
189
+		$grantedItems = $smartpermissions_handler->getGrantedItems($perm_name);
190
+		if (count($grantedItems) > 0) {
191
+			$criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
192
+			return true;
193
+		} else {
194
+			return false;
195
+		}
196
+	}
197
+
198
+	function setUploaderConfig($_uploadPath=false, $_allowedMimeTypes=false, $_maxFileSize=false, $_maxWidth=false, $_maxHeight=false) {
199
+		$this->_uploadPath = $_uploadPath ? $_uploadPath : $this->_uploadPath;
200
+		$this->_allowedMimeTypes = $_allowedMimeTypes ? $_allowedMimeTypes : $this->_allowedMimeTypes;
201
+		$this->_maxFileSize = $_maxFileSize ? $_maxFileSize : $this->_maxFileSize;
202
+		$this->_maxWidth = $_maxWidth ? $_maxWidth : $this->_maxWidth;
203
+		$this->_maxHeight = $_maxHeight ? $_maxHeight : $this->_maxHeight;
204
+	}
205
+
206
+	/**
207
+	 * create a new {@link SmartObject}
208
+	 *
209
+	 * @param bool $isNew Flag the new objects as "new"?
210
+	 *
211
+	 * @return object {@link SmartObject}
212
+	 */
213
+	function &create($isNew = true) {
214
+		$obj = new $this->className($this);
215
+		$obj->setImageDir($this->getImageUrl(), $this->getImagePath());
216
+		if (!$obj->handler) {
217
+			$obj->handler =& $this;
218
+		}
219
+
220
+		if ($isNew === true) {
221
+			$obj->setNew();
222
+		}
223
+		return $obj;
224
+	}
225
+
226
+	function getImageUrl() {
227
+		return $this->_uploadUrl . $this->_itemname . "/";
228
+	}
229
+
230
+	function getImagePath() {
231
+		$dir = $this->_uploadPath . $this->_itemname;
232
+		if (!file_exists($dir)) {
233
+			smart_admin_mkdir($dir);
234
+		}
235
+		return $dir . "/";
236
+	}
237
+
238
+	/**
239
+	 * retrieve a {@link SmartObject}
240
+	 *
241
+	 * @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
242
+	 * @param bool $as_object whether to return an object or an array
243
+	 * @return mixed reference to the {@link SmartObject}, FALSE if failed
244
+	 */
245
+	function &get($id, $as_object = true, $debug=false, $criteria=false) {
246
+		if (!$criteria) {
247
+			$criteria = new CriteriaCompo();
248
+		}
249
+		if (is_array($this->keyName)) {
250
+			for ($i = 0; $i < count($this->keyName); $i++) {
251
+				/**
252
+				 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
253
+				 * Is the fact that we removed the intval() represents a security risk ?
254
+				 */
255
+				//$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
256
+				$criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
257
+			}
258
+		}
259
+		else {
260
+			//$criteria = new Criteria($this->keyName, intval($id), '=', $this->_itemname);
261
+			/**
262
+			 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
263
+			 * Is the fact that we removed the intval() represents a security risk ?
264
+			 */
265
+			$criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
266
+		}
267
+		$criteria->setLimit(1);
268
+		if ($debug) {
269
+			$obj_array = $this->getObjectsD($criteria, false, $as_object);
270
+		} else {
271
+			$obj_array = $this->getObjects($criteria, false, $as_object);
272
+			//patch : weird bug of indexing by id even if id_as_key = false;
273
+			if(!isset($obj_array[0]) && is_object($obj_array[$id])){
274
+				$obj_array[0] = $obj_array[$id];
275
+				unset($obj_array[$id]);
276
+				$obj_array[0]->unsetNew();
277
+			}
278
+		}
279
+
280
+		if (count($obj_array) != 1) {
281
+			$obj = $this->create();
282
+			return $obj;
283
+		}
284
+
285
+		return $obj_array[0];
286
+	}
287
+
288
+	/**
289
+	 * retrieve a {@link SmartObject}
290
+	 *
291
+	 * @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
292
+	 * @param bool $as_object whether to return an object or an array
293
+	 * @return mixed reference to the {@link SmartObject}, FALSE if failed
294
+	 */
295
+	function &getD($id, $as_object = true) {
296
+		return $this->get($id, $as_object, true);
297
+	}
298
+
299
+	/**
300
+	 * retrieve objects from the database
301
+	 *
302
+	 * @param object $criteria {@link CriteriaElement} conditions to be met
303
+	 * @param bool $id_as_key use the ID as key for the array?
304
+	 * @param bool $as_object return an array of objects?
305
+	 *
306
+	 * @return array
307
+	 */
308
+	function getObjects($criteria = null, $id_as_key = false, $as_object = true, $sql=false, $debug=false)
309
+	{
310
+		$ret = array();
311
+		$limit = $start = 0;
312
+
313
+		if ($this->generalSQL) {
314
+			$sql = $this->generalSQL;
315
+		} elseif(!$sql) {
316
+			$sql = 'SELECT * FROM '.$this->table . " AS " . $this->_itemname;
317
+		}
318
+
319
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
320
+			$sql .= ' '.$criteria->renderWhere();
321
+			if ($criteria->getSort() != '') {
322
+				$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
323
+			}
324
+			$limit = $criteria->getLimit();
325
+			$start = $criteria->getStart();
326
+		}
327
+		if ($debug) {
328
+			xoops_debug($sql);
329
+		}
330
+
331
+		$result = $this->db->query($sql, $limit, $start);
332
+		if (!$result) {
333
+			return $ret;
334
+		}
335
+		return $this->convertResultSet($result, $id_as_key, $as_object);
336
+	}
337
+
338
+	function query($sql, $criteria, $force=false, $debug=false)
339
+	{
340
+		$ret = array();
341
+
342
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
343
+			$sql .= ' '.$criteria->renderWhere();
344
+			if ($criteria->groupby) {
345
+				$sql .= $criteria->getGroupby();
346
+			}
347
+			if ($criteria->getSort() != '') {
348
+				$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
349
+			}
350
+
351
+		}
352
+		if ($debug) {
353
+			xoops_debug($sql);
354
+		}
355
+
356
+		if ($force) {
357
+			$result = $this->db->queryF($sql);
358
+		} else {
359
+			$result = $this->db->query($sql);
360
+		}
361
+
362
+		if (!$result) {
363
+			return $ret;
364
+		}
365
+
366
+		while ($myrow = $this->db->fetchArray($result)) {
367
+			$ret[] = $myrow;
368
+		}
369
+
370
+		return $ret;
371
+	}
372
+
373
+	/**
374
+	 * retrieve objects with debug mode - so will show the query
375
+	 *
376
+	 * @param object $criteria {@link CriteriaElement} conditions to be met
377
+	 * @param bool $id_as_key use the ID as key for the array?
378
+	 * @param bool $as_object return an array of objects?
379
+	 *
380
+	 * @return array
381
+	 */
382
+	function getObjectsD($criteria = null, $id_as_key = false, $as_object = true, $sql = false)
383
+	{
384
+		return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
385
+	}
386
+
387
+	function getObjectsAsArray($arrayObjects) {
388
+		$ret = array();
389
+		foreach ($arrayObjects as $key => $object) {
390
+			$ret[$key] = $object->toArray();
391
+		}
392
+		if (count($ret > 0)) {
393
+			return $ret;
394
+		} else {
395
+			return false;
396
+		}
397
+	}
398
+
399
+	/**
400
+	 * Convert a database resultset to a returnable array
401
+	 *
402
+	 * @param object $result database resultset
403
+	 * @param bool $id_as_key - should NOT be used with joint keys
404
+	 * @param bool $as_object
405
+	 *
406
+	 * @return array
407
+	 */
408
+	function convertResultSet($result, $id_as_key = false, $as_object = true) {
409
+		$ret = array();
410
+		while ($myrow = $this->db->fetchArray($result)) {
411
+
412
+			$obj =& $this->create(false);
413
+			$obj->assignVars($myrow);
414
+			if (!$id_as_key) {
415
+				if ($as_object) {
416
+					$ret[] =& $obj;
417
+				}
418
+				else {
419
+					$ret[] = $obj->toArray();
420
+				}
421
+			} else {
422
+				if ($as_object) {
423
+					$value =& $obj;
424
+				}
425
+				else {
426
+					$value = $obj->toArray();
427
+				}
428
+				if ($id_as_key === 'parentid') {
429
+					$ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
430
+				} else {
431
+					$ret[$obj->getVar($this->keyName)] = $value;
432
+				}
433
+			}
434
+			unset($obj);
435
+		}
436
+
437
+		return $ret;
438
+	}
439
+
440
+	function getListD($criteria = null, $limit = 0, $start = 0) {
441
+		return $this->getList($criteria, $limit, $start, true);
442
+	}
443
+
444
+	/**
445
+	 * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
446
+	 *
447
+	 * @param object $criteria {@link CriteriaElement} conditions to be met
448
+	 * @param int   $limit      Max number of objects to fetch
449
+	 * @param int   $start      Which record to start at
450
+	 *
451
+	 * @return array
452
+	 */
453
+	function getList($criteria = null, $limit = 0, $start = 0, $debug=false) {
454
+		$ret = array();
455
+		if ($criteria == null) {
456
+			$criteria = new CriteriaCompo();
457
+		}
458
+
459
+		if ($criteria->getSort() == '') {
460
+			$criteria->setSort($this->getIdentifierName());
461
+		}
462
+
463
+		$sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName) ;
464
+		if(!empty($this->identifierName)){
465
+			$sql .= ', '.$this->getIdentifierName();
466
+		}
467
+		$sql .= ' FROM '.$this->table . " AS " . $this->_itemname;
468
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
469
+			$sql .= ' '.$criteria->renderWhere();
470
+			if ($criteria->getSort() != '') {
471
+				$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
472
+			}
473
+			$limit = $criteria->getLimit();
474
+			$start = $criteria->getStart();
475
+		}
476
+
477
+		if ($debug) {
478
+			xoops_debug($sql);
479
+		}
480
+
481
+		$result = $this->db->query($sql, $limit, $start);
482
+		if (!$result) {
483
+			return $ret;
484
+		}
485
+
486
+		$myts =& MyTextSanitizer::getInstance();
487
+		while ($myrow = $this->db->fetchArray($result)) {
488
+			//identifiers should be textboxes, so sanitize them like that
489
+			$ret[$myrow[$this->keyName]] = empty($this->identifierName)?1:$myts->displayTarea($myrow[$this->identifierName]);
490
+		}
491
+		return $ret;
492
+	}
493
+
494
+	/**
495
+	 * count objects matching a condition
496
+	 *
497
+	 * @param object $criteria {@link CriteriaElement} to match
498
+	 * @return int count of objects
499
+	 */
500
+	function getCount($criteria = null)
501
+	{
502
+		$field = "";
503
+		$groupby = false;
504
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
505
+			if ($criteria->groupby != "") {
506
+				$groupby = true;
507
+				$field = $criteria->groupby.", "; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
508
+			}
509
+		}
510
+		/**
511
+		 * if we have a generalSQL, lets used this one.
512
+		 * This needs to be improved...
513
+		 */
514
+		if ($this->generalSQL) {
515
+			$sql = $this->generalSQL;
516
+			$sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
517
+		} else {
518
+			$sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table . ' AS ' . $this->_itemname;
519
+		}
520
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
521
+			$sql .= ' '.$criteria->renderWhere();
522
+			if ($criteria->groupby != "") {
523
+				$sql .= $criteria->getGroupby();
524
+			}
525
+		}
526
+
527
+		$result = $this->db->query($sql);
528
+		if (!$result) {
529
+			return 0;
530
+		}
531
+		if ($groupby == false) {
532
+			list($count) = $this->db->fetchRow($result);
533
+			return $count;
534
+		}
535
+		else {
536
+			$ret = array();
537
+			while (list($id, $count) = $this->db->fetchRow($result)) {
538
+				$ret[$id] = $count;
539
+			}
540
+			return $ret;
541
+		}
542
+	}
543
+
544
+	/**
545
+	 * delete an object from the database
546
+	 *
547
+	 * @param object $obj reference to the object to delete
548
+	 * @param bool $force
549
+	 * @return bool FALSE if failed.
550
+	 */
551
+	function delete(&$obj, $force = false)
552
+	{
553
+		$eventResult = $this->executeEvent('beforeDelete', $obj);
554
+		if (!$eventResult) {
555
+			$obj->setErrors("An error occured during the BeforeDelete event");
556
+			return false;
557
+		}
558
+
559
+		if (is_array($this->keyName)) {
560
+			$clause = array();
561
+			for ($i = 0; $i < count($this->keyName); $i++) {
562
+				$clause[] = $this->keyName[$i]." = ".$obj->getVar($this->keyName[$i]);
563
+			}
564
+			$whereclause = implode(" AND ", $clause);
565
+		}
566
+		else {
567
+			$whereclause = $this->keyName." = ".$obj->getVar($this->keyName);
568
+		}
569
+		$sql = "DELETE FROM ".$this->table . " WHERE ".$whereclause;
570
+		if (false != $force) {
571
+			$result = $this->db->queryF($sql);
572
+		} else {
573
+			$result = $this->db->query($sql);
574
+		}
575
+		if (!$result) {
576
+			return false;
577
+		}
578
+
579
+		$eventResult = $this->executeEvent('afterDelete', $obj);
580
+		if (!$eventResult) {
581
+			$obj->setErrors("An error occured during the AfterDelete event");
582
+			return false;
583
+		}
584
+		return true;
585
+	}
586
+
587
+	function disableEvent($event) {
588
+		if (is_array($event)) {
589
+			foreach($event as $v) {
590
+				$this->_disabledEvents[] = $v;
591
+			}
592
+		} else {
593
+			$this->_disabledEvents[] = $event;
594
+		}
595
+	}
596
+
597
+	function getPermissions() {
598
+		return $this->permissionsArray;
599
+	}
600
+
601
+	/**
602
+	 * insert a new object in the database
603
+	 *
604
+	 * @param object $obj reference to the object
605
+	 * @param bool $force whether to force the query execution despite security settings
606
+	 * @param bool $checkObject check if the object is dirty and clean the attributes
607
+	 * @return bool FALSE if failed, TRUE if already present and unchanged or successful
608
+	 */
609
+	function insert(&$obj, $force = false, $checkObject = true, $debug=false)
610
+	{
611
+		if ($checkObject != false) {
612
+			if (!is_object($obj)) {
613
+				return false;
614
+			}
615
+			/**
616
+			 * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
617
+			 */
618
+			if (!is_a($obj, $this->className)) {
619
+				$obj->setError(get_class($obj)." Differs from ".$this->className);
620
+				return false;
621
+			}
622
+			if (!$obj->isDirty()) {
623
+				$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
624
+				return true;
625
+			}
626
+		}
627
+
628
+		if ($obj->seoEnabled) {
629
+			// Auto create meta tags if empty
630
+			$smartobject_metagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
631
+
632
+			if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
633
+
634
+				if (!$obj->meta_keywords()) {
635
+					$obj->setVar('meta_keywords', $smartobject_metagen->_keywords);
636
+				}
637
+
638
+				if (!$obj->meta_description()) {
639
+					$obj->setVar('meta_description', $smartobject_metagen->_meta_description);
640
+				}
641
+			}
642
+
643
+			// Auto create short_url if empty
644
+			if (!$obj->short_url()) {
645
+				$obj->setVar('short_url', $smartobject_metagen->generateSeoTitle($obj->title('n'), false));
646
+			}
647
+		}
648
+
649
+		$eventResult = $this->executeEvent('beforeSave', $obj);
650
+		if (!$eventResult) {
651
+			$obj->setErrors("An error occured during the BeforeSave event");
652
+			return false;
653
+		}
654
+
655
+		if ($obj->isNew()) {
656
+			$eventResult = $this->executeEvent('beforeInsert', $obj);
657
+			if (!$eventResult) {
658
+				$obj->setErrors("An error occured during the BeforeInsert event");
659
+				return false;
660
+			}
661
+
662
+		}	else {
663
+			$eventResult = $this->executeEvent('beforeUpdate', $obj);
664
+			if (!$eventResult) {
665
+				$obj->setErrors("An error occured during the BeforeUpdate event");
666
+				return false;
667
+			}
668
+		}
669
+		if (!$obj->cleanVars()) {
670
+			$obj->setErrors('Variables were not cleaned properly.');
671
+			return false;
672
+		}
673
+		$fieldsToStoreInDB = array();
674
+		foreach ($obj->cleanVars as $k => $v) {
675
+			if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
676
+				$cleanvars[$k] = intval($v);
677
+			} elseif (is_array($v) ) {
678
+				$cleanvars[ $k ] = $this->db->quoteString( implode( ',', $v ) );
679
+			} else {
680
+				$cleanvars[$k] = $this->db->quoteString($v);
681
+			}
682
+			if ($obj->vars[$k]['persistent']) {
683
+				$fieldsToStoreInDB[$k] = $cleanvars[$k];
684
+			}
685
+
686
+		}
687
+		if ($obj->isNew()) {
688
+			if (!is_array($this->keyName)) {
689
+				if ($cleanvars[$this->keyName] < 1) {
690
+					$cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
691
+				}
692
+			}
693
+
694
+			$sql = "INSERT INTO ".$this->table." (".implode(',', array_keys($fieldsToStoreInDB)).") VALUES (".implode(',', array_values($fieldsToStoreInDB)) .")";
695
+
696
+		} else {
697
+
698
+			$sql = "UPDATE ".$this->table." SET";
699
+			foreach ($fieldsToStoreInDB as $key => $value) {
700
+				if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
701
+					continue;
702
+				}
703
+				if (isset($notfirst) ) {
704
+					$sql .= ",";
705
+				}
706
+				$sql .= " ".$key." = ".$value;
707
+				$notfirst = true;
708
+			}
709
+			if (is_array($this->keyName)) {
710
+				$whereclause = "";
711
+				for ($i = 0; $i < count($this->keyName); $i++) {
712
+					if ($i > 0) {
713
+						$whereclause .= " AND ";
714
+					}
715
+					$whereclause .= $this->keyName[$i]." = ".$obj->getVar($this->keyName[$i]);
716
+				}
717
+			}
718
+			else {
719
+				$whereclause = $this->keyName." = ".$obj->getVar($this->keyName);
720
+			}
721
+			$sql .= " WHERE ".$whereclause;
722
+		}
723
+
724
+		if ($debug) {
725
+			xoops_debug($sql);
726
+		}
727
+
728
+		if (false != $force) {
729
+			$result = $this->db->queryF($sql);
730
+		} else {
731
+			$result = $this->db->query($sql);
732
+		}
733
+
734
+		if (!$result) {
735
+			$obj->setErrors($this->db->error());
736
+			return false;
737
+		}
738
+
739
+		if ($obj->isNew() && !is_array($this->keyName)) {
740
+			$obj->assignVar($this->keyName, $this->db->getInsertId());
741
+		}
742
+		$eventResult = $this->executeEvent('afterSave', $obj);
743
+		if (!$eventResult) {
744
+			$obj->setErrors("An error occured during the AfterSave event");
745
+			return false;
746
+		}
747
+
748
+		if ($obj->isNew()) {
749
+			$obj->unsetNew();
750
+			$eventResult = $this->executeEvent('afterInsert', $obj);
751
+			if (!$eventResult) {
752
+				$obj->setErrors("An error occured during the AfterInsert event");
753
+				return false;
754
+			}
755
+		} else {
756
+			$eventResult = $this->executeEvent('afterUpdate', $obj);
757
+			if (!$eventResult) {
758
+				$obj->setErrors("An error occured during the AfterUpdate event");
759
+				return false;
760
+			}
761
+		}
762
+		return true;
763
+	}
764
+
765
+	function insertD(&$obj, $force = false, $checkObject = true, $debug=false)
766
+	{
767
+		return $this->insert($obj, $force, $checkObject, true);
768
+	}
769
+
770
+	/**
771
+	 * Change a value for objects with a certain criteria
772
+	 *
773
+	 * @param   string  $fieldname  Name of the field
774
+	 * @param   string  $fieldvalue Value to write
775
+	 * @param   object  $criteria   {@link CriteriaElement}
776
+	 *
777
+	 * @return  bool
778
+	 **/
779
+	function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false)
780
+	{
781
+		$set_clause = $fieldname . ' = ';
782
+		if ( is_numeric( $fieldvalue ) ) {
783
+			$set_clause .=  $fieldvalue;
784
+		} elseif ( is_array( $fieldvalue ) ) {
785
+			$set_clause .= $this->db->quoteString( implode( ',', $fieldvalue ) );
786
+		} else {
787
+			$set_clause .= $this->db->quoteString( $fieldvalue );
788
+		}
789
+		$sql = 'UPDATE '.$this->table.' SET '.$set_clause;
790
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
791
+			$sql .= ' '.$criteria->renderWhere();
792
+		}
793
+		if (false != $force) {
794
+			$result = $this->db->queryF($sql);
795
+		} else {
796
+			$result = $this->db->query($sql);
797
+		}
798
+		if (!$result) {
799
+			return false;
800
+		}
801
+		return true;
802
+	}
803
+
804
+	/**
805
+	 * delete all objects meeting the conditions
806
+	 *
807
+	 * @param object $criteria {@link CriteriaElement} with conditions to meet
808
+	 * @return bool
809
+	 */
810
+
811
+	function deleteAll($criteria = null)
812
+	{
813
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
814
+			$sql = 'DELETE FROM '.$this->table;
815
+			$sql .= ' '.$criteria->renderWhere();
816
+			if (!$this->db->query($sql)) {
817
+				return false;
818
+			}
819
+			$rows = $this->db->getAffectedRows();
820
+			return $rows > 0 ? $rows : true;
821
+		}
822
+		return false;
823
+	}
824
+
825
+	function getModuleInfo() {
826
+		return smart_getModuleInfo($this->_moduleName);
827
+	}
828
+
829
+	function getModuleConfig() {
830
+		return smart_getModuleConfig($this->_moduleName);
831
+	}
832
+
833
+	function getModuleItemString() {
834
+		$ret = $this->_moduleName . '_' . $this->_itemname;
835
+		return $ret;
836
+	}
837
+
838
+	function updateCounter($object) {
839
+		if (isset($object->vars['counter'])) {
840
+			$new_counter = $object->getVar('counter') + 1;
841
+			$sql = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
842
+			$this->query($sql, null, true);
843
+		}
844
+	}
845
+
846
+	/**
847
+	 * Execute the function associated with an event
848
+	 * This method will check if the function is available
849
+	 *
850
+	 * @param string $event name of the event
851
+	 * @param object $obj $object on which is performed the event
852
+	 * @return mixed result of the execution of the function or FALSE if the function was not executed
853
+	 */
854
+	function executeEvent($event, &$executeEventObj) {
855
+		if (!in_array($event, $this->_disabledEvents)) {
856
+			if (method_exists($this, $event)) {
857
+				$ret = $this->$event($executeEventObj);
858
+			} else {
859
+				// check to see if there is a hook for this event
860
+				if (isset($this->_eventHooks[$event])) {
861
+					$method = $this->_eventHooks[$event];
862
+					// check to see if the method specified by this hook exists
863
+					if (method_exists($this, $method)) {
864
+						$ret = $this->$method($executeEventObj);
865
+
866
+					}
867
+				}
868
+				$ret = true;
869
+			}
870
+			return $ret;
871
+		}
872
+		return true;
873
+	}
874
+
875
+	function getIdentifierName($withprefix=true) {
876
+		if ($withprefix) {
877
+			return $this->_itemname . "." . $this->identifierName;
878
+		} else {
879
+			return $this->identifierName;
880
+		}
881
+	}
882 882
 }
883 883
 
884 884
 
Please login to merge, or discard this patch.
class/smartaddto.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
  */
8 8
 
9 9
 if (!defined("XOOPS_ROOT_PATH")) {
10
-    die("XOOPS root path not defined");
10
+	die("XOOPS root path not defined");
11 11
 }
12 12
 
13 13
 class SmartAddTo {
Please login to merge, or discard this patch.