@@ -17,31 +17,31 @@ discard block |
||
17 | 17 | require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
18 | 18 | |
19 | 19 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
20 | - define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
20 | + define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
21 | 21 | } |
22 | 22 | if (!defined('XOBJ_DTYPE_CURRENCY')) { |
23 | - define('XOBJ_DTYPE_CURRENCY', 200); |
|
23 | + define('XOBJ_DTYPE_CURRENCY', 200); |
|
24 | 24 | } |
25 | 25 | if (!defined('XOBJ_DTYPE_FLOAT')) { |
26 | - define('XOBJ_DTYPE_FLOAT', 201); |
|
26 | + define('XOBJ_DTYPE_FLOAT', 201); |
|
27 | 27 | } |
28 | 28 | if (!defined('XOBJ_DTYPE_TIME_ONLY')) { |
29 | - define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
29 | + define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
30 | 30 | } |
31 | 31 | if (!defined('XOBJ_DTYPE_URLLINK')) { |
32 | - define('XOBJ_DTYPE_URLLINK', 203); |
|
32 | + define('XOBJ_DTYPE_URLLINK', 203); |
|
33 | 33 | } |
34 | 34 | if (!defined('XOBJ_DTYPE_FILE')) { |
35 | - define('XOBJ_DTYPE_FILE', 204); |
|
35 | + define('XOBJ_DTYPE_FILE', 204); |
|
36 | 36 | } |
37 | 37 | if (!defined('XOBJ_DTYPE_IMAGE')) { |
38 | - define('XOBJ_DTYPE_IMAGE', 205); |
|
38 | + define('XOBJ_DTYPE_IMAGE', 205); |
|
39 | 39 | } |
40 | 40 | if (!defined('XOBJ_DTYPE_FORM_SECTION')) { |
41 | - define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
41 | + define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
42 | 42 | } |
43 | 43 | if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) { |
44 | - define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
44 | + define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -55,1399 +55,1399 @@ discard block |
||
55 | 55 | */ |
56 | 56 | class SmartObject extends XoopsObject |
57 | 57 | { |
58 | - public $_image_path; |
|
59 | - public $_image_url; |
|
60 | - |
|
61 | - public $seoEnabled = false; |
|
62 | - public $titleField; |
|
63 | - public $summaryField = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Reference to the handler managing this object |
|
67 | - * |
|
68 | - * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
69 | - */ |
|
70 | - public $handler; |
|
71 | - |
|
72 | - /** |
|
73 | - * References to control objects, managing the form fields of this object |
|
74 | - */ |
|
75 | - public $controls = array(); |
|
76 | - |
|
77 | - /** |
|
78 | - * SmartObject constructor. |
|
79 | - * @param $handler |
|
80 | - */ |
|
81 | - public function __construct($handler) |
|
82 | - { |
|
83 | - $this->handler = $handler; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Checks if the user has a specific access on this object |
|
88 | - * |
|
89 | - * @param $perm_name |
|
90 | - * @return bool: TRUE if user has access, false if not |
|
91 | - * @internal param string $gperm_name name of the permission to test |
|
92 | - */ |
|
93 | - public function accessGranted($perm_name) |
|
94 | - { |
|
95 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
96 | - |
|
97 | - return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param $section_name |
|
102 | - * @param bool $value |
|
103 | - * @param bool $hide |
|
104 | - */ |
|
105 | - public function addFormSection($section_name, $value = false, $hide = false) |
|
106 | - { |
|
107 | - $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
108 | - $this->vars[$section_name]['hide'] = $hide; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param $section_name |
|
113 | - */ |
|
114 | - public function closeSection($section_name) |
|
115 | - { |
|
116 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * |
|
121 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
122 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
123 | - * @param mixed $value default value of this variable |
|
124 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
125 | - * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
126 | - * @param string $options does this data have any select options? |
|
127 | - * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
128 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
129 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
130 | - * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
131 | - * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
132 | - * @param bool $displayOnForm |
|
133 | - */ |
|
134 | - public function initVar( |
|
135 | - $key, |
|
136 | - $data_type, |
|
137 | - $value = null, |
|
138 | - $required = false, |
|
139 | - $maxlength = null, |
|
140 | - $options = '', |
|
141 | - $multilingual = false, |
|
142 | - $form_caption = '', |
|
143 | - $form_dsc = '', |
|
144 | - $sortby = false, |
|
145 | - $persistent = true, |
|
146 | - $displayOnForm = true |
|
147 | - ) { |
|
148 | - //url_ is reserved for files. |
|
149 | - if (0 === strpos($key, 'url_')) { |
|
150 | - trigger_error("Cannot use variable starting with 'url_'."); |
|
151 | - } |
|
152 | - parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
153 | - if ($this->handler && (!$form_caption || $form_caption === '')) { |
|
154 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
155 | - if (defined($dyn_form_caption)) { |
|
156 | - $form_caption = constant($dyn_form_caption); |
|
157 | - } |
|
158 | - } |
|
159 | - if ($this->handler && (!$form_dsc || $form_dsc === '')) { |
|
160 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
161 | - if (defined($dyn_form_dsc)) { |
|
162 | - $form_dsc = constant($dyn_form_dsc); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - $this->vars[$key] = array_merge($this->vars[$key], array( |
|
167 | - 'multilingual' => $multilingual, |
|
168 | - 'form_caption' => $form_caption, |
|
169 | - 'form_dsc' => $form_dsc, |
|
170 | - 'sortby' => $sortby, |
|
171 | - 'persistent' => $persistent, |
|
172 | - 'displayOnForm' => $displayOnForm, |
|
173 | - 'displayOnSingleView' => true, |
|
174 | - 'readonly' => false |
|
175 | - )); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @param $key |
|
180 | - * @param $data_type |
|
181 | - * @param bool $itemName |
|
182 | - * @param string $form_caption |
|
183 | - * @param bool $sortby |
|
184 | - * @param string $value |
|
185 | - * @param bool $displayOnForm |
|
186 | - * @param bool $required |
|
187 | - */ |
|
188 | - public function initNonPersistableVar( |
|
189 | - $key, |
|
190 | - $data_type, |
|
191 | - $itemName = false, |
|
192 | - $form_caption = '', |
|
193 | - $sortby = false, |
|
194 | - $value = '', |
|
195 | - $displayOnForm = false, |
|
196 | - $required = false |
|
197 | - ) { |
|
198 | - $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
199 | - $this->vars[$key]['itemName'] = $itemName; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Quickly initiate a var |
|
204 | - * |
|
205 | - * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
206 | - * |
|
207 | - * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
208 | - * - all other vars are NULL or '' depending of the parameter |
|
209 | - * |
|
210 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
211 | - * @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) |
|
212 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
213 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
214 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
215 | - * @param mixed $value default value of this variable |
|
216 | - */ |
|
217 | - public function quickInitVar( |
|
218 | - $key, |
|
219 | - $data_type, |
|
220 | - $required = false, |
|
221 | - $form_caption = '', |
|
222 | - $form_dsc = '', |
|
223 | - $value = null |
|
224 | - ) { |
|
225 | - $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
226 | - $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param $varname |
|
231 | - * @param bool $displayOnForm |
|
232 | - * @param string $default |
|
233 | - */ |
|
234 | - public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
235 | - { |
|
236 | - switch ($varname) { |
|
237 | - case 'dohtml': |
|
238 | - $value = $default !== 'notdefined' ? $default : true; |
|
239 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
240 | - $this->setControl($varname, 'yesno'); |
|
241 | - break; |
|
242 | - |
|
243 | - case 'dobr': |
|
244 | - $value = ($default === 'notdefined') ? true : $default; |
|
245 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
246 | - $this->setControl($varname, 'yesno'); |
|
247 | - break; |
|
248 | - |
|
249 | - case 'doimage': |
|
250 | - $value = $default !== 'notdefined' ? $default : true; |
|
251 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
252 | - $this->setControl($varname, 'yesno'); |
|
253 | - break; |
|
254 | - |
|
255 | - case 'dosmiley': |
|
256 | - $value = $default !== 'notdefined' ? $default : true; |
|
257 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
258 | - $this->setControl($varname, 'yesno'); |
|
259 | - break; |
|
260 | - |
|
261 | - case 'doxcode': |
|
262 | - $value = $default !== 'notdefined' ? $default : true; |
|
263 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
264 | - $this->setControl($varname, 'yesno'); |
|
265 | - break; |
|
266 | - |
|
267 | - case 'meta_keywords': |
|
268 | - $value = $default !== 'notdefined' ? $default : ''; |
|
269 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
270 | - $this->setControl('meta_keywords', array( |
|
271 | - 'name' => 'textarea', |
|
272 | - 'form_editor' => 'textarea' |
|
273 | - )); |
|
274 | - break; |
|
275 | - |
|
276 | - case 'meta_description': |
|
277 | - $value = $default !== 'notdefined' ? $default : ''; |
|
278 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
279 | - $this->setControl('meta_description', array( |
|
280 | - 'name' => 'textarea', |
|
281 | - 'form_editor' => 'textarea' |
|
282 | - )); |
|
283 | - break; |
|
284 | - |
|
285 | - case 'short_url': |
|
286 | - $value = $default !== 'notdefined' ? $default : ''; |
|
287 | - $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
288 | - break; |
|
289 | - |
|
290 | - case 'hierarchy_path': |
|
291 | - $value = $default !== 'notdefined' ? $default : ''; |
|
292 | - $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
293 | - break; |
|
294 | - |
|
295 | - case 'counter': |
|
296 | - $value = $default !== 'notdefined' ? $default : 0; |
|
297 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
298 | - break; |
|
299 | - |
|
300 | - case 'weight': |
|
301 | - $value = $default !== 'notdefined' ? $default : 0; |
|
302 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
303 | - break; |
|
304 | - case 'custom_css': |
|
305 | - $value = $default !== 'notdefined' ? $default : ''; |
|
306 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
307 | - $this->setControl('custom_css', array( |
|
308 | - 'name' => 'textarea', |
|
309 | - 'form_editor' => 'textarea' |
|
310 | - )); |
|
311 | - break; |
|
312 | - } |
|
313 | - $this->hideFieldFromSingleView($varname); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Set control information for an instance variable |
|
318 | - * |
|
319 | - * The $options parameter can be a string or an array. Using a string |
|
320 | - * is the quickest way: |
|
321 | - * |
|
322 | - * $this->setControl('date', 'date_time'); |
|
323 | - * |
|
324 | - * This will create a date and time selectbox for the 'date' var on the |
|
325 | - * form to edit or create this item. |
|
326 | - * |
|
327 | - * Here are the currently supported controls: |
|
328 | - * |
|
329 | - * - color |
|
330 | - * - country |
|
331 | - * - date_time |
|
332 | - * - date |
|
333 | ||
334 | - * - group |
|
335 | - * - group_multi |
|
336 | - * - image |
|
337 | - * - imageupload |
|
338 | - * - label |
|
339 | - * - language |
|
340 | - * - parentcategory |
|
341 | - * - password |
|
342 | - * - select_multi |
|
343 | - * - select |
|
344 | - * - text |
|
345 | - * - textarea |
|
346 | - * - theme |
|
347 | - * - theme_multi |
|
348 | - * - timezone |
|
349 | - * - user |
|
350 | - * - user_multi |
|
351 | - * - yesno |
|
352 | - * |
|
353 | - * Now, using an array as $options, you can customize what information to |
|
354 | - * use in the control. For example, if one needs to display a select box for |
|
355 | - * the user to choose the status of an item. We only need to tell SmartObject |
|
356 | - * what method to execute within what handler to retreive the options of the |
|
357 | - * selectbox. |
|
358 | - * |
|
359 | - * $this->setControl('status', array('name' => false, |
|
360 | - * 'itemHandler' => 'item', |
|
361 | - * 'method' => 'getStatus', |
|
362 | - * 'module' => 'smartshop')); |
|
363 | - * |
|
364 | - * In this example, the array elements are the following: |
|
365 | - * - name: false, as we don't need to set a special control here. |
|
366 | - * we will use the default control related to the object type (defined in initVar) |
|
367 | - * - itemHandler: name of the object for which we will use the handler |
|
368 | - * - method: name of the method of this handler that we will execute |
|
369 | - * - module: name of the module from wich the handler is |
|
370 | - * |
|
371 | - * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
372 | - * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
373 | - * |
|
374 | - * Another example of the use of $options as an array is for TextArea: |
|
375 | - * |
|
376 | - * $this->setControl('body', array('name' => 'textarea', |
|
377 | - * 'form_editor' => 'default')); |
|
378 | - * |
|
379 | - * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
380 | - * the 'default' editor, providing it is defined in the module |
|
381 | - * preferences: $xoopsModuleConfig['default_editor'] |
|
382 | - * |
|
383 | - * Of course, you can force the use of a specific editor: |
|
384 | - * |
|
385 | - * $this->setControl('body', array('name' => 'textarea', |
|
386 | - * 'form_editor' => 'koivi')); |
|
387 | - * |
|
388 | - * Here is a list of supported editor: |
|
389 | - * - tiny: TinyEditor |
|
390 | - * - dhtmltextarea: XOOPS DHTML Area |
|
391 | - * - fckeditor: FCKEditor |
|
392 | - * - inbetween: InBetween |
|
393 | - * - koivi: Koivi |
|
394 | - * - spaw: Spaw WYSIWYG Editor |
|
395 | - * - htmlarea: HTMLArea |
|
396 | - * - textarea: basic textarea with no options |
|
397 | - * |
|
398 | - * @param string $var name of the variable for which we want to set a control |
|
399 | - * @param array $options |
|
400 | - */ |
|
401 | - public function setControl($var, $options = array()) |
|
402 | - { |
|
403 | - if (isset($this->controls[$var])) { |
|
404 | - unset($this->controls[$var]); |
|
405 | - } |
|
406 | - if (is_string($options)) { |
|
407 | - $options = array('name' => $options); |
|
408 | - } |
|
409 | - $this->controls[$var] = $options; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get control information for an instance variable |
|
414 | - * |
|
415 | - * @param string $var |
|
416 | - * @return bool|mixed |
|
417 | - */ |
|
418 | - public function getControl($var) |
|
419 | - { |
|
420 | - return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Create the form for this object |
|
425 | - * |
|
426 | - * @param $form_caption |
|
427 | - * @param $form_name |
|
428 | - * @param bool $form_action |
|
429 | - * @param string $submit_button_caption |
|
430 | - * @param bool $cancel_js_action |
|
431 | - * @param bool $captcha |
|
432 | - * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
433 | - * object for this object |
|
434 | - * @see SmartObjectForm::SmartObjectForm() |
|
435 | - */ |
|
436 | - public function getForm( |
|
437 | - $form_caption, |
|
438 | - $form_name, |
|
439 | - $form_action = false, |
|
440 | - $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
441 | - $cancel_js_action = false, |
|
442 | - $captcha = false |
|
443 | - ) { |
|
444 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
445 | - $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
446 | - |
|
447 | - return $form; |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * @return array |
|
452 | - */ |
|
453 | - public function toArray() |
|
454 | - { |
|
455 | - $ret = array(); |
|
456 | - $vars =& $this->getVars(); |
|
457 | - foreach ($vars as $key => $var) { |
|
458 | - $value = $this->getVar($key); |
|
459 | - $ret[$key] = $value; |
|
460 | - } |
|
461 | - if ($this->handler->identifierName !== '') { |
|
462 | - $controller = new SmartObjectController($this->handler); |
|
463 | - /** |
|
464 | - * Addition of some automatic value |
|
465 | - */ |
|
466 | - $ret['itemLink'] = $controller->getItemLink($this); |
|
467 | - $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
468 | - $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
469 | - $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
470 | - $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
471 | - } |
|
472 | - |
|
473 | - // Hightlighting searched words |
|
474 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
475 | - $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
476 | - |
|
477 | - if ($highlight && isset($_GET['keywords'])) { |
|
478 | - $myts = MyTextSanitizer::getInstance(); |
|
479 | - $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
480 | - $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
481 | - foreach ($this->handler->highlightFields as $field) { |
|
482 | - $ret[$field] = $h->highlight($ret[$field]); |
|
483 | - } |
|
484 | - } |
|
485 | - |
|
486 | - return $ret; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * add an error |
|
491 | - * |
|
492 | - * @param $err_str |
|
493 | - * @param bool $prefix |
|
494 | - * @internal param string $value error to add |
|
495 | - * @access public |
|
496 | - */ |
|
497 | - public function setErrors($err_str, $prefix = false) |
|
498 | - { |
|
499 | - if (is_array($err_str)) { |
|
500 | - foreach ($err_str as $str) { |
|
501 | - $this->setErrors($str, $prefix); |
|
502 | - } |
|
503 | - } else { |
|
504 | - if ($prefix) { |
|
505 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
506 | - } |
|
507 | - parent::setErrors($err_str); |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * @param $field |
|
513 | - * @param bool $required |
|
514 | - */ |
|
515 | - public function setFieldAsRequired($field, $required = true) |
|
516 | - { |
|
517 | - if (is_array($field)) { |
|
518 | - foreach ($field as $v) { |
|
519 | - $this->doSetFieldAsRequired($v, $required); |
|
520 | - } |
|
521 | - } else { |
|
522 | - $this->doSetFieldAsRequired($field, $required); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * @param $field |
|
528 | - */ |
|
529 | - public function setFieldForSorting($field) |
|
530 | - { |
|
531 | - if (is_array($field)) { |
|
532 | - foreach ($field as $v) { |
|
533 | - $this->doSetFieldForSorting($v); |
|
534 | - } |
|
535 | - } else { |
|
536 | - $this->doSetFieldForSorting($field); |
|
537 | - } |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * @return bool |
|
542 | - */ |
|
543 | - public function hasError() |
|
544 | - { |
|
545 | - return count($this->_errors) > 0; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * @param $url |
|
550 | - * @param $path |
|
551 | - */ |
|
552 | - public function setImageDir($url, $path) |
|
553 | - { |
|
554 | - $this->_image_url = $url; |
|
555 | - $this->_image_path = $path; |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * Retreive the group that have been granted access to a specific permission for this object |
|
560 | - * |
|
561 | - * @param $group_perm |
|
562 | - * @return string $group_perm name of the permission |
|
563 | - */ |
|
564 | - public function getGroupPerm($group_perm) |
|
565 | - { |
|
566 | - if (!$this->handler->getPermissions()) { |
|
567 | - $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
568 | - |
|
569 | - return false; |
|
570 | - } |
|
571 | - |
|
572 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
573 | - $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
574 | - |
|
575 | - if (count($ret) == 0) { |
|
576 | - return false; |
|
577 | - } else { |
|
578 | - return $ret; |
|
579 | - } |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * @param bool $path |
|
584 | - * @return mixed |
|
585 | - */ |
|
586 | - public function getImageDir($path = false) |
|
587 | - { |
|
588 | - if ($path) { |
|
589 | - return $this->_image_path; |
|
590 | - } else { |
|
591 | - return $this->_image_url; |
|
592 | - } |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * @param bool $path |
|
597 | - * @return mixed |
|
598 | - */ |
|
599 | - public function getUploadDir($path = false) |
|
600 | - { |
|
601 | - if ($path) { |
|
602 | - return $this->_image_path; |
|
603 | - } else { |
|
604 | - return $this->_image_url; |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * @param string $key |
|
610 | - * @param string $info |
|
611 | - * @return array |
|
612 | - */ |
|
613 | - public function getVarInfo($key = '', $info = '') |
|
614 | - { |
|
615 | - if (isset($this->vars[$key][$info])) { |
|
616 | - return $this->vars[$key][$info]; |
|
617 | - } elseif ($info === '' && isset($this->vars[$key])) { |
|
618 | - return $this->vars[$key]; |
|
619 | - } else { |
|
620 | - return $this->vars; |
|
621 | - } |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Get the id of the object |
|
626 | - * |
|
627 | - * @return int id of this object |
|
628 | - */ |
|
629 | - public function id() |
|
630 | - { |
|
631 | - return $this->getVar($this->handler->keyName, 'e'); |
|
632 | - } |
|
633 | - |
|
634 | - /** |
|
635 | - * Return the value of the title field of this object |
|
636 | - * |
|
637 | - * @param string $format |
|
638 | - * @return string |
|
639 | - */ |
|
640 | - public function title($format = 's') |
|
641 | - { |
|
642 | - return $this->getVar($this->handler->identifierName, $format); |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Return the value of the title field of this object |
|
647 | - * |
|
648 | - * @return string |
|
649 | - */ |
|
650 | - public function summary() |
|
651 | - { |
|
652 | - if ($this->handler->summaryName) { |
|
653 | - return $this->getVar($this->handler->summaryName); |
|
654 | - } else { |
|
655 | - return false; |
|
656 | - } |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Retreive the object admin side link, displayijng a SingleView page |
|
661 | - * |
|
662 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
663 | - * @return string user side link to the object |
|
664 | - */ |
|
665 | - public function getAdminViewItemLink($onlyUrl = false) |
|
666 | - { |
|
667 | - $controller = new SmartObjectController($this->handler); |
|
668 | - |
|
669 | - return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Retreive the object user side link |
|
674 | - * |
|
675 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
676 | - * @return string user side link to the object |
|
677 | - */ |
|
678 | - public function getItemLink($onlyUrl = false) |
|
679 | - { |
|
680 | - $controller = new SmartObjectController($this->handler); |
|
681 | - |
|
682 | - return $controller->getItemLink($this, $onlyUrl); |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * @param bool $onlyUrl |
|
687 | - * @param bool $withimage |
|
688 | - * @param bool $userSide |
|
689 | - * @return string |
|
690 | - */ |
|
691 | - public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
692 | - { |
|
693 | - $controller = new SmartObjectController($this->handler); |
|
694 | - |
|
695 | - return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * @param bool $onlyUrl |
|
700 | - * @param bool $withimage |
|
701 | - * @param bool $userSide |
|
702 | - * @return string |
|
703 | - */ |
|
704 | - public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
705 | - { |
|
706 | - $controller = new SmartObjectController($this->handler); |
|
707 | - |
|
708 | - return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * @return string |
|
713 | - */ |
|
714 | - public function getPrintAndMailLink() |
|
715 | - { |
|
716 | - $controller = new SmartObjectController($this->handler); |
|
717 | - |
|
718 | - return $controller->getPrintAndMailLink($this); |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * @param $sortsel |
|
723 | - * @return array|bool |
|
724 | - */ |
|
725 | - public function getFieldsForSorting($sortsel) |
|
726 | - { |
|
727 | - $ret = array(); |
|
728 | - |
|
729 | - foreach ($this->vars as $key => $field_info) { |
|
730 | - if ($field_info['sortby']) { |
|
731 | - $ret[$key]['caption'] = $field_info['form_caption']; |
|
732 | - $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
733 | - } |
|
734 | - } |
|
735 | - |
|
736 | - if (count($ret) > 0) { |
|
737 | - return $ret; |
|
738 | - } else { |
|
739 | - return false; |
|
740 | - } |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * @param $key |
|
745 | - * @param $newType |
|
746 | - */ |
|
747 | - public function setType($key, $newType) |
|
748 | - { |
|
749 | - $this->vars[$key]['data_type'] = $newType; |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * @param $key |
|
754 | - * @param $info |
|
755 | - * @param $value |
|
756 | - */ |
|
757 | - public function setVarInfo($key, $info, $value) |
|
758 | - { |
|
759 | - $this->vars[$key][$info] = $value; |
|
760 | - } |
|
761 | - |
|
762 | - /** |
|
763 | - * @param $key |
|
764 | - * @param bool $editor |
|
765 | - * @return string |
|
766 | - */ |
|
767 | - public function getValueFor($key, $editor = true) |
|
768 | - { |
|
769 | - global $xoopsModuleConfig; |
|
770 | - |
|
771 | - $ret = $this->getVar($key, 'n'); |
|
772 | - $myts = MyTextSanitizer::getInstance(); |
|
773 | - |
|
774 | - $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
775 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
776 | - |
|
777 | - $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
778 | - $smiley = true; |
|
779 | - $xcode = true; |
|
780 | - $image = true; |
|
781 | - $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
782 | - $formatML = true; |
|
783 | - |
|
784 | - if ($form_editor === 'default') { |
|
785 | - global $xoopsModuleConfig; |
|
786 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
787 | - } |
|
788 | - |
|
789 | - if ($editor) { |
|
790 | - if (defined('XOOPS_EDITOR_IS_HTML') |
|
791 | - && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
792 | - $br = false; |
|
793 | - $formatML = !$editor; |
|
794 | - } else { |
|
795 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
796 | - } |
|
797 | - } |
|
798 | - |
|
799 | - if (method_exists($myts, 'formatForML')) { |
|
800 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
801 | - } else { |
|
802 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
803 | - } |
|
804 | - } |
|
805 | - |
|
806 | - /** |
|
807 | - * clean values of all variables of the object for storage. |
|
808 | - * also add slashes whereever needed |
|
809 | - * |
|
810 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
811 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
812 | - * as a string separated by | |
|
813 | - * |
|
814 | - * @return bool true if successful |
|
815 | - * @access public |
|
816 | - */ |
|
817 | - public function cleanVars() |
|
818 | - { |
|
819 | - $ts = MyTextSanitizer::getInstance(); |
|
820 | - $existing_errors = $this->getErrors(); |
|
821 | - $this->_errors = array(); |
|
822 | - foreach ($this->vars as $k => $v) { |
|
823 | - $cleanv = $v['value']; |
|
824 | - if (!$v['changed']) { |
|
825 | - } else { |
|
826 | - $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
827 | - switch ($v['data_type']) { |
|
828 | - case XOBJ_DTYPE_TXTBOX: |
|
829 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
830 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
831 | - continue 2; |
|
832 | - } |
|
833 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
834 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
835 | - continue 2; |
|
836 | - } |
|
837 | - if (!$v['not_gpc']) { |
|
838 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
839 | - } else { |
|
840 | - $cleanv = $ts->censorString($cleanv); |
|
841 | - } |
|
842 | - break; |
|
843 | - case XOBJ_DTYPE_TXTAREA: |
|
844 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
845 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
846 | - continue 2; |
|
847 | - } |
|
848 | - if (!$v['not_gpc']) { |
|
849 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
850 | - } else { |
|
851 | - $cleanv = $ts->censorString($cleanv); |
|
852 | - } |
|
853 | - break; |
|
854 | - case XOBJ_DTYPE_SOURCE: |
|
855 | - if (!$v['not_gpc']) { |
|
856 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
857 | - } else { |
|
858 | - $cleanv = $cleanv; |
|
859 | - } |
|
860 | - break; |
|
861 | - case XOBJ_DTYPE_INT: |
|
862 | - case XOBJ_DTYPE_TIME_ONLY: |
|
863 | - $cleanv = (int)$cleanv; |
|
864 | - break; |
|
865 | - |
|
866 | - case XOBJ_DTYPE_CURRENCY: |
|
867 | - $cleanv = smart_currency($cleanv); |
|
868 | - break; |
|
869 | - |
|
870 | - case XOBJ_DTYPE_FLOAT: |
|
871 | - $cleanv = smart_float($cleanv); |
|
872 | - break; |
|
873 | - |
|
874 | - case XOBJ_DTYPE_EMAIL: |
|
875 | - if ($v['required'] && $cleanv === '') { |
|
876 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
877 | - continue 2; |
|
878 | - } |
|
879 | - if ($cleanv !== '' |
|
880 | - && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
881 | - $this->setErrors('Invalid Email'); |
|
882 | - continue 2; |
|
883 | - } |
|
884 | - if (!$v['not_gpc']) { |
|
885 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
886 | - } |
|
887 | - break; |
|
888 | - case XOBJ_DTYPE_URL: |
|
889 | - if ($v['required'] && $cleanv === '') { |
|
890 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
891 | - continue 2; |
|
892 | - } |
|
893 | - if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
894 | - $cleanv = 'http://' . $cleanv; |
|
895 | - } |
|
896 | - if (!$v['not_gpc']) { |
|
897 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
898 | - } |
|
899 | - break; |
|
900 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
901 | - $cleanv = implode('|', $cleanv); |
|
902 | - break; |
|
903 | - case XOBJ_DTYPE_ARRAY: |
|
904 | - $cleanv = serialize($cleanv); |
|
905 | - break; |
|
906 | - case XOBJ_DTYPE_STIME: |
|
907 | - case XOBJ_DTYPE_MTIME: |
|
908 | - case XOBJ_DTYPE_LTIME: |
|
909 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
910 | - if (!($cleanv > 0)) { |
|
911 | - $cleanv = strtotime($cleanv); |
|
912 | - } |
|
913 | - break; |
|
914 | - default: |
|
915 | - break; |
|
916 | - } |
|
917 | - } |
|
918 | - $this->cleanVars[$k] =& $cleanv; |
|
919 | - unset($cleanv); |
|
920 | - } |
|
921 | - if (count($this->_errors) > 0) { |
|
922 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
923 | - |
|
924 | - return false; |
|
925 | - } |
|
926 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
927 | - $this->unsetDirty(); |
|
928 | - |
|
929 | - return true; |
|
930 | - } |
|
931 | - |
|
932 | - /** |
|
933 | - * returns a specific variable for the object in a proper format |
|
934 | - * |
|
935 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
936 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
937 | - * as a string separated by | |
|
938 | - * |
|
939 | - * @access public |
|
940 | - * @param string $key key of the object's variable to be returned |
|
941 | - * @param string $format format to use for the output |
|
942 | - * @return mixed formatted value of the variable |
|
943 | - */ |
|
944 | - public function getVar($key, $format = 's') |
|
945 | - { |
|
946 | - global $myts; |
|
947 | - |
|
948 | - $ret = $this->vars[$key]['value']; |
|
949 | - |
|
950 | - switch ($this->vars[$key]['data_type']) { |
|
951 | - |
|
952 | - case XOBJ_DTYPE_TXTBOX: |
|
953 | - switch (strtolower($format)) { |
|
954 | - case 's': |
|
955 | - case 'show': |
|
956 | - // ML Hack by marcan |
|
957 | - $ts = MyTextSanitizer::getInstance(); |
|
958 | - $ret = $ts->htmlSpecialChars($ret); |
|
959 | - |
|
960 | - if (method_exists($myts, 'formatForML')) { |
|
961 | - return $ts->formatForML($ret); |
|
962 | - } else { |
|
963 | - return $ret; |
|
964 | - } |
|
965 | - break 1; |
|
966 | - // End of ML Hack by marcan |
|
967 | - |
|
968 | - case 'clean': |
|
969 | - $ts = MyTextSanitizer::getInstance(); |
|
970 | - |
|
971 | - $ret = smart_html2text($ret); |
|
972 | - $ret = smart_purifyText($ret); |
|
973 | - |
|
974 | - if (method_exists($myts, 'formatForML')) { |
|
975 | - return $ts->formatForML($ret); |
|
976 | - } else { |
|
977 | - return $ret; |
|
978 | - } |
|
979 | - break 1; |
|
980 | - // End of ML Hack by marcan |
|
981 | - |
|
982 | - case 'e': |
|
983 | - case 'edit': |
|
984 | - $ts = MyTextSanitizer::getInstance(); |
|
985 | - |
|
986 | - return $ts->htmlSpecialChars($ret); |
|
987 | - break 1; |
|
988 | - case 'p': |
|
989 | - case 'preview': |
|
990 | - case 'f': |
|
991 | - case 'formpreview': |
|
992 | - $ts = MyTextSanitizer::getInstance(); |
|
993 | - |
|
994 | - return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
995 | - break 1; |
|
996 | - case 'n': |
|
997 | - case 'none': |
|
998 | - default: |
|
999 | - break 1; |
|
1000 | - } |
|
1001 | - break; |
|
1002 | - case XOBJ_DTYPE_LTIME: |
|
1003 | - switch (strtolower($format)) { |
|
1004 | - case 's': |
|
1005 | - case 'show': |
|
1006 | - case 'p': |
|
1007 | - case 'preview': |
|
1008 | - case 'f': |
|
1009 | - case 'formpreview': |
|
1010 | - $ret = formatTimestamp($ret, _DATESTRING); |
|
1011 | - |
|
1012 | - return $ret; |
|
1013 | - break 1; |
|
1014 | - case 'n': |
|
1015 | - case 'none': |
|
1016 | - case 'e': |
|
1017 | - case 'edit': |
|
1018 | - break 1; |
|
1019 | - default: |
|
1020 | - break 1; |
|
1021 | - } |
|
1022 | - break; |
|
1023 | - case XOBJ_DTYPE_STIME: |
|
1024 | - switch (strtolower($format)) { |
|
1025 | - case 's': |
|
1026 | - case 'show': |
|
1027 | - case 'p': |
|
1028 | - case 'preview': |
|
1029 | - case 'f': |
|
1030 | - case 'formpreview': |
|
1031 | - $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
1032 | - |
|
1033 | - return $ret; |
|
1034 | - break 1; |
|
1035 | - case 'n': |
|
1036 | - case 'none': |
|
1037 | - case 'e': |
|
1038 | - case 'edit': |
|
1039 | - break 1; |
|
1040 | - default: |
|
1041 | - break 1; |
|
1042 | - } |
|
1043 | - break; |
|
1044 | - case XOBJ_DTYPE_TIME_ONLY: |
|
1045 | - switch (strtolower($format)) { |
|
1046 | - case 's': |
|
1047 | - case 'show': |
|
1048 | - case 'p': |
|
1049 | - case 'preview': |
|
1050 | - case 'f': |
|
1051 | - case 'formpreview': |
|
1052 | - $ret = formatTimestamp($ret, 'G:i'); |
|
1053 | - |
|
1054 | - return $ret; |
|
1055 | - break 1; |
|
1056 | - case 'n': |
|
1057 | - case 'none': |
|
1058 | - case 'e': |
|
1059 | - case 'edit': |
|
1060 | - break 1; |
|
1061 | - default: |
|
1062 | - break 1; |
|
1063 | - } |
|
1064 | - break; |
|
1065 | - |
|
1066 | - case XOBJ_DTYPE_CURRENCY: |
|
1067 | - $decimal_section_original = strstr($ret, '.'); |
|
1068 | - $decimal_section = $decimal_section_original; |
|
1069 | - if ($decimal_section) { |
|
1070 | - if (strlen($decimal_section) == 1) { |
|
1071 | - $decimal_section = '.00'; |
|
1072 | - } elseif (strlen($decimal_section) == 2) { |
|
1073 | - $decimal_section .= '0'; |
|
1074 | - } |
|
1075 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1076 | - } else { |
|
1077 | - $ret .= '.00'; |
|
1078 | - } |
|
1079 | - break; |
|
1080 | - |
|
1081 | - case XOBJ_DTYPE_TXTAREA: |
|
1082 | - switch (strtolower($format)) { |
|
1083 | - case 's': |
|
1084 | - case 'show': |
|
1085 | - $ts = MyTextSanitizer::getInstance(); |
|
1086 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1087 | - |
|
1088 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
1089 | - || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1090 | - |
|
1091 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1092 | - || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1093 | - $image = (!isset($this->vars['doimage']['value']) |
|
1094 | - || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1095 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Hack by marcan <INBOX> for SCSPRO |
|
1099 | - * Setting mastop as the main editor |
|
1100 | - */ |
|
1101 | - if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1102 | - $br = false; |
|
1103 | - } |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * Hack by marcan <INBOX> for SCSPRO |
|
1107 | - * Setting mastop as the main editor |
|
1108 | - */ |
|
1109 | - |
|
1110 | - return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1111 | - break 1; |
|
1112 | - case 'e': |
|
1113 | - case 'edit': |
|
1114 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1115 | - break 1; |
|
1116 | - case 'p': |
|
1117 | - case 'preview': |
|
1118 | - $ts = MyTextSanitizer::getInstance(); |
|
1119 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1120 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
1121 | - || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1122 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1123 | - || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1124 | - $image = (!isset($this->vars['doimage']['value']) |
|
1125 | - || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1126 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1127 | - |
|
1128 | - return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1129 | - break 1; |
|
1130 | - case 'f': |
|
1131 | - case 'formpreview': |
|
1132 | - $ts = MyTextSanitizer::getInstance(); |
|
1133 | - |
|
1134 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1135 | - break 1; |
|
1136 | - case 'n': |
|
1137 | - case 'none': |
|
1138 | - default: |
|
1139 | - break 1; |
|
1140 | - } |
|
1141 | - break; |
|
1142 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1143 | - $ret =& explode('|', $ret); |
|
1144 | - break; |
|
1145 | - case XOBJ_DTYPE_ARRAY: |
|
1146 | - $ret =& unserialize($ret); |
|
1147 | - break; |
|
1148 | - case XOBJ_DTYPE_SOURCE: |
|
1149 | - switch (strtolower($format)) { |
|
1150 | - case 's': |
|
1151 | - case 'show': |
|
1152 | - break 1; |
|
1153 | - case 'e': |
|
1154 | - case 'edit': |
|
1155 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1156 | - break 1; |
|
1157 | - case 'p': |
|
1158 | - case 'preview': |
|
1159 | - $ts = MyTextSanitizer::getInstance(); |
|
1160 | - |
|
1161 | - return $ts->stripSlashesGPC($ret); |
|
1162 | - break 1; |
|
1163 | - case 'f': |
|
1164 | - case 'formpreview': |
|
1165 | - $ts = MyTextSanitizer::getInstance(); |
|
1166 | - |
|
1167 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1168 | - break 1; |
|
1169 | - case 'n': |
|
1170 | - case 'none': |
|
1171 | - default: |
|
1172 | - break 1; |
|
1173 | - } |
|
1174 | - break; |
|
1175 | - default: |
|
1176 | - if ($this->vars[$key]['options'] !== '' && $ret != '') { |
|
1177 | - switch (strtolower($format)) { |
|
1178 | - case 's': |
|
1179 | - case 'show': |
|
1180 | - $selected = explode('|', $ret); |
|
1181 | - $options = explode('|', $this->vars[$key]['options']); |
|
1182 | - $i = 1; |
|
1183 | - $ret = array(); |
|
1184 | - foreach ($options as $op) { |
|
1185 | - if (in_array($i, $selected)) { |
|
1186 | - $ret[] = $op; |
|
1187 | - } |
|
1188 | - ++$i; |
|
1189 | - } |
|
1190 | - |
|
1191 | - return implode(', ', $ret); |
|
1192 | - case 'e': |
|
1193 | - case 'edit': |
|
1194 | - $ret = explode('|', $ret); |
|
1195 | - break 1; |
|
1196 | - default: |
|
1197 | - break 1; |
|
1198 | - } |
|
1199 | - } |
|
1200 | - break; |
|
1201 | - } |
|
1202 | - |
|
1203 | - return $ret; |
|
1204 | - } |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * @param $key |
|
1208 | - */ |
|
1209 | - public function doMakeFieldreadOnly($key) |
|
1210 | - { |
|
1211 | - if (isset($this->vars[$key])) { |
|
1212 | - $this->vars[$key]['readonly'] = true; |
|
1213 | - $this->vars[$key]['displayOnForm'] = true; |
|
1214 | - } |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * @param $key |
|
1219 | - */ |
|
1220 | - public function makeFieldReadOnly($key) |
|
1221 | - { |
|
1222 | - if (is_array($key)) { |
|
1223 | - foreach ($key as $v) { |
|
1224 | - $this->doMakeFieldreadOnly($v); |
|
1225 | - } |
|
1226 | - } else { |
|
1227 | - $this->doMakeFieldreadOnly($key); |
|
1228 | - } |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * @param $key |
|
1233 | - */ |
|
1234 | - public function doHideFieldFromForm($key) |
|
1235 | - { |
|
1236 | - if (isset($this->vars[$key])) { |
|
1237 | - $this->vars[$key]['displayOnForm'] = false; |
|
1238 | - } |
|
1239 | - } |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * @param $key |
|
1243 | - */ |
|
1244 | - public function doHideFieldFromSingleView($key) |
|
1245 | - { |
|
1246 | - if (isset($this->vars[$key])) { |
|
1247 | - $this->vars[$key]['displayOnSingleView'] = false; |
|
1248 | - } |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * @param $key |
|
1253 | - */ |
|
1254 | - public function hideFieldFromForm($key) |
|
1255 | - { |
|
1256 | - if (is_array($key)) { |
|
1257 | - foreach ($key as $v) { |
|
1258 | - $this->doHideFieldFromForm($v); |
|
1259 | - } |
|
1260 | - } else { |
|
1261 | - $this->doHideFieldFromForm($key); |
|
1262 | - } |
|
1263 | - } |
|
1264 | - |
|
1265 | - /** |
|
1266 | - * @param $key |
|
1267 | - */ |
|
1268 | - public function hideFieldFromSingleView($key) |
|
1269 | - { |
|
1270 | - if (is_array($key)) { |
|
1271 | - foreach ($key as $v) { |
|
1272 | - $this->doHideFieldFromSingleView($v); |
|
1273 | - } |
|
1274 | - } else { |
|
1275 | - $this->doHideFieldFromSingleView($key); |
|
1276 | - } |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * @param $key |
|
1281 | - */ |
|
1282 | - public function doShowFieldOnForm($key) |
|
1283 | - { |
|
1284 | - if (isset($this->vars[$key])) { |
|
1285 | - $this->vars[$key]['displayOnForm'] = true; |
|
1286 | - } |
|
1287 | - } |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1291 | - * |
|
1292 | - * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1293 | - * @param bool $userSide for futur use, to do something different on the user side |
|
1294 | - * @param array $actions |
|
1295 | - * @param bool $headerAsRow |
|
1296 | - * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1297 | - */ |
|
1298 | - public function displaySingleObject( |
|
1299 | - $fetchOnly = false, |
|
1300 | - $userSide = false, |
|
1301 | - $actions = array(), |
|
1302 | - $headerAsRow = true |
|
1303 | - ) { |
|
1304 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
1305 | - $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
1306 | - // add all fields mark as displayOnSingleView except the keyid |
|
1307 | - foreach ($this->vars as $key => $var) { |
|
1308 | - if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1309 | - $is_header = ($key == $this->handler->identifierName); |
|
1310 | - $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
1311 | - } |
|
1312 | - } |
|
1313 | - |
|
1314 | - if ($fetchOnly) { |
|
1315 | - $ret = $singleview->render($fetchOnly); |
|
1316 | - |
|
1317 | - return $ret; |
|
1318 | - } else { |
|
1319 | - $singleview->render($fetchOnly); |
|
1320 | - } |
|
1321 | - } |
|
1322 | - |
|
1323 | - /** |
|
1324 | - * @param $key |
|
1325 | - */ |
|
1326 | - public function doDisplayFieldOnSingleView($key) |
|
1327 | - { |
|
1328 | - if (isset($this->vars[$key])) { |
|
1329 | - $this->vars[$key]['displayOnSingleView'] = true; |
|
1330 | - } |
|
1331 | - } |
|
1332 | - |
|
1333 | - /** |
|
1334 | - * @param $field |
|
1335 | - * @param bool $required |
|
1336 | - */ |
|
1337 | - public function doSetFieldAsRequired($field, $required = true) |
|
1338 | - { |
|
1339 | - $this->setVarInfo($field, 'required', $required); |
|
1340 | - } |
|
1341 | - |
|
1342 | - /** |
|
1343 | - * @param $field |
|
1344 | - */ |
|
1345 | - public function doSetFieldForSorting($field) |
|
1346 | - { |
|
1347 | - $this->setVarInfo($field, 'sortby', true); |
|
1348 | - } |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * @param $key |
|
1352 | - */ |
|
1353 | - public function showFieldOnForm($key) |
|
1354 | - { |
|
1355 | - if (is_array($key)) { |
|
1356 | - foreach ($key as $v) { |
|
1357 | - $this->doShowFieldOnForm($v); |
|
1358 | - } |
|
1359 | - } else { |
|
1360 | - $this->doShowFieldOnForm($key); |
|
1361 | - } |
|
1362 | - } |
|
1363 | - |
|
1364 | - /** |
|
1365 | - * @param $key |
|
1366 | - */ |
|
1367 | - public function displayFieldOnSingleView($key) |
|
1368 | - { |
|
1369 | - if (is_array($key)) { |
|
1370 | - foreach ($key as $v) { |
|
1371 | - $this->doDisplayFieldOnSingleView($v); |
|
1372 | - } |
|
1373 | - } else { |
|
1374 | - $this->doDisplayFieldOnSingleView($key); |
|
1375 | - } |
|
1376 | - } |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * @param $key |
|
1380 | - */ |
|
1381 | - public function doSetAdvancedFormFields($key) |
|
1382 | - { |
|
1383 | - if (isset($this->vars[$key])) { |
|
1384 | - $this->vars[$key]['advancedform'] = true; |
|
1385 | - } |
|
1386 | - } |
|
1387 | - |
|
1388 | - /** |
|
1389 | - * @param $key |
|
1390 | - */ |
|
1391 | - public function setAdvancedFormFields($key) |
|
1392 | - { |
|
1393 | - if (is_array($key)) { |
|
1394 | - foreach ($key as $v) { |
|
1395 | - $this->doSetAdvancedFormFields($v); |
|
1396 | - } |
|
1397 | - } else { |
|
1398 | - $this->doSetAdvancedFormFields($key); |
|
1399 | - } |
|
1400 | - } |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * @param $key |
|
1404 | - * @return mixed |
|
1405 | - */ |
|
1406 | - public function getUrlLinkObj($key) |
|
1407 | - { |
|
1408 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1409 | - $urllinkid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1410 | - if ($urllinkid != 0) { |
|
1411 | - return $smartobjectLinkurlHandler->get($urllinkid); |
|
1412 | - } else { |
|
1413 | - return $smartobjectLinkurlHandler->create(); |
|
1414 | - } |
|
1415 | - } |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * @param $urlLinkObj |
|
1419 | - * @return mixed |
|
1420 | - */ |
|
1421 | - public function &storeUrlLinkObj($urlLinkObj) |
|
1422 | - { |
|
1423 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1424 | - |
|
1425 | - return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1426 | - } |
|
1427 | - |
|
1428 | - /** |
|
1429 | - * @param $key |
|
1430 | - * @return mixed |
|
1431 | - */ |
|
1432 | - public function getFileObj($key) |
|
1433 | - { |
|
1434 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1435 | - $fileid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1436 | - if ($fileid != 0) { |
|
1437 | - return $smartobjectFileHandler->get($fileid); |
|
1438 | - } else { |
|
1439 | - return $smartobjectFileHandler->create(); |
|
1440 | - } |
|
1441 | - } |
|
1442 | - |
|
1443 | - /** |
|
1444 | - * @param $fileObj |
|
1445 | - * @return mixed |
|
1446 | - */ |
|
1447 | - public function &storeFileObj($fileObj) |
|
1448 | - { |
|
1449 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1450 | - |
|
1451 | - return $smartobjectFileHandler->insert($fileObj); |
|
1452 | - } |
|
58 | + public $_image_path; |
|
59 | + public $_image_url; |
|
60 | + |
|
61 | + public $seoEnabled = false; |
|
62 | + public $titleField; |
|
63 | + public $summaryField = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Reference to the handler managing this object |
|
67 | + * |
|
68 | + * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
69 | + */ |
|
70 | + public $handler; |
|
71 | + |
|
72 | + /** |
|
73 | + * References to control objects, managing the form fields of this object |
|
74 | + */ |
|
75 | + public $controls = array(); |
|
76 | + |
|
77 | + /** |
|
78 | + * SmartObject constructor. |
|
79 | + * @param $handler |
|
80 | + */ |
|
81 | + public function __construct($handler) |
|
82 | + { |
|
83 | + $this->handler = $handler; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Checks if the user has a specific access on this object |
|
88 | + * |
|
89 | + * @param $perm_name |
|
90 | + * @return bool: TRUE if user has access, false if not |
|
91 | + * @internal param string $gperm_name name of the permission to test |
|
92 | + */ |
|
93 | + public function accessGranted($perm_name) |
|
94 | + { |
|
95 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
96 | + |
|
97 | + return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param $section_name |
|
102 | + * @param bool $value |
|
103 | + * @param bool $hide |
|
104 | + */ |
|
105 | + public function addFormSection($section_name, $value = false, $hide = false) |
|
106 | + { |
|
107 | + $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
108 | + $this->vars[$section_name]['hide'] = $hide; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param $section_name |
|
113 | + */ |
|
114 | + public function closeSection($section_name) |
|
115 | + { |
|
116 | + $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * |
|
121 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
122 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
123 | + * @param mixed $value default value of this variable |
|
124 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
125 | + * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
126 | + * @param string $options does this data have any select options? |
|
127 | + * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
128 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
129 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
130 | + * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
131 | + * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
132 | + * @param bool $displayOnForm |
|
133 | + */ |
|
134 | + public function initVar( |
|
135 | + $key, |
|
136 | + $data_type, |
|
137 | + $value = null, |
|
138 | + $required = false, |
|
139 | + $maxlength = null, |
|
140 | + $options = '', |
|
141 | + $multilingual = false, |
|
142 | + $form_caption = '', |
|
143 | + $form_dsc = '', |
|
144 | + $sortby = false, |
|
145 | + $persistent = true, |
|
146 | + $displayOnForm = true |
|
147 | + ) { |
|
148 | + //url_ is reserved for files. |
|
149 | + if (0 === strpos($key, 'url_')) { |
|
150 | + trigger_error("Cannot use variable starting with 'url_'."); |
|
151 | + } |
|
152 | + parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
153 | + if ($this->handler && (!$form_caption || $form_caption === '')) { |
|
154 | + $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
155 | + if (defined($dyn_form_caption)) { |
|
156 | + $form_caption = constant($dyn_form_caption); |
|
157 | + } |
|
158 | + } |
|
159 | + if ($this->handler && (!$form_dsc || $form_dsc === '')) { |
|
160 | + $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
161 | + if (defined($dyn_form_dsc)) { |
|
162 | + $form_dsc = constant($dyn_form_dsc); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + $this->vars[$key] = array_merge($this->vars[$key], array( |
|
167 | + 'multilingual' => $multilingual, |
|
168 | + 'form_caption' => $form_caption, |
|
169 | + 'form_dsc' => $form_dsc, |
|
170 | + 'sortby' => $sortby, |
|
171 | + 'persistent' => $persistent, |
|
172 | + 'displayOnForm' => $displayOnForm, |
|
173 | + 'displayOnSingleView' => true, |
|
174 | + 'readonly' => false |
|
175 | + )); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @param $key |
|
180 | + * @param $data_type |
|
181 | + * @param bool $itemName |
|
182 | + * @param string $form_caption |
|
183 | + * @param bool $sortby |
|
184 | + * @param string $value |
|
185 | + * @param bool $displayOnForm |
|
186 | + * @param bool $required |
|
187 | + */ |
|
188 | + public function initNonPersistableVar( |
|
189 | + $key, |
|
190 | + $data_type, |
|
191 | + $itemName = false, |
|
192 | + $form_caption = '', |
|
193 | + $sortby = false, |
|
194 | + $value = '', |
|
195 | + $displayOnForm = false, |
|
196 | + $required = false |
|
197 | + ) { |
|
198 | + $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
199 | + $this->vars[$key]['itemName'] = $itemName; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Quickly initiate a var |
|
204 | + * |
|
205 | + * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
206 | + * |
|
207 | + * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
208 | + * - all other vars are NULL or '' depending of the parameter |
|
209 | + * |
|
210 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
211 | + * @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) |
|
212 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
213 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
214 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
215 | + * @param mixed $value default value of this variable |
|
216 | + */ |
|
217 | + public function quickInitVar( |
|
218 | + $key, |
|
219 | + $data_type, |
|
220 | + $required = false, |
|
221 | + $form_caption = '', |
|
222 | + $form_dsc = '', |
|
223 | + $value = null |
|
224 | + ) { |
|
225 | + $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
226 | + $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param $varname |
|
231 | + * @param bool $displayOnForm |
|
232 | + * @param string $default |
|
233 | + */ |
|
234 | + public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
235 | + { |
|
236 | + switch ($varname) { |
|
237 | + case 'dohtml': |
|
238 | + $value = $default !== 'notdefined' ? $default : true; |
|
239 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
240 | + $this->setControl($varname, 'yesno'); |
|
241 | + break; |
|
242 | + |
|
243 | + case 'dobr': |
|
244 | + $value = ($default === 'notdefined') ? true : $default; |
|
245 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
246 | + $this->setControl($varname, 'yesno'); |
|
247 | + break; |
|
248 | + |
|
249 | + case 'doimage': |
|
250 | + $value = $default !== 'notdefined' ? $default : true; |
|
251 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
252 | + $this->setControl($varname, 'yesno'); |
|
253 | + break; |
|
254 | + |
|
255 | + case 'dosmiley': |
|
256 | + $value = $default !== 'notdefined' ? $default : true; |
|
257 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
258 | + $this->setControl($varname, 'yesno'); |
|
259 | + break; |
|
260 | + |
|
261 | + case 'doxcode': |
|
262 | + $value = $default !== 'notdefined' ? $default : true; |
|
263 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
264 | + $this->setControl($varname, 'yesno'); |
|
265 | + break; |
|
266 | + |
|
267 | + case 'meta_keywords': |
|
268 | + $value = $default !== 'notdefined' ? $default : ''; |
|
269 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
270 | + $this->setControl('meta_keywords', array( |
|
271 | + 'name' => 'textarea', |
|
272 | + 'form_editor' => 'textarea' |
|
273 | + )); |
|
274 | + break; |
|
275 | + |
|
276 | + case 'meta_description': |
|
277 | + $value = $default !== 'notdefined' ? $default : ''; |
|
278 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
279 | + $this->setControl('meta_description', array( |
|
280 | + 'name' => 'textarea', |
|
281 | + 'form_editor' => 'textarea' |
|
282 | + )); |
|
283 | + break; |
|
284 | + |
|
285 | + case 'short_url': |
|
286 | + $value = $default !== 'notdefined' ? $default : ''; |
|
287 | + $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
288 | + break; |
|
289 | + |
|
290 | + case 'hierarchy_path': |
|
291 | + $value = $default !== 'notdefined' ? $default : ''; |
|
292 | + $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
293 | + break; |
|
294 | + |
|
295 | + case 'counter': |
|
296 | + $value = $default !== 'notdefined' ? $default : 0; |
|
297 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
298 | + break; |
|
299 | + |
|
300 | + case 'weight': |
|
301 | + $value = $default !== 'notdefined' ? $default : 0; |
|
302 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
303 | + break; |
|
304 | + case 'custom_css': |
|
305 | + $value = $default !== 'notdefined' ? $default : ''; |
|
306 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
307 | + $this->setControl('custom_css', array( |
|
308 | + 'name' => 'textarea', |
|
309 | + 'form_editor' => 'textarea' |
|
310 | + )); |
|
311 | + break; |
|
312 | + } |
|
313 | + $this->hideFieldFromSingleView($varname); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Set control information for an instance variable |
|
318 | + * |
|
319 | + * The $options parameter can be a string or an array. Using a string |
|
320 | + * is the quickest way: |
|
321 | + * |
|
322 | + * $this->setControl('date', 'date_time'); |
|
323 | + * |
|
324 | + * This will create a date and time selectbox for the 'date' var on the |
|
325 | + * form to edit or create this item. |
|
326 | + * |
|
327 | + * Here are the currently supported controls: |
|
328 | + * |
|
329 | + * - color |
|
330 | + * - country |
|
331 | + * - date_time |
|
332 | + * - date |
|
333 | ||
334 | + * - group |
|
335 | + * - group_multi |
|
336 | + * - image |
|
337 | + * - imageupload |
|
338 | + * - label |
|
339 | + * - language |
|
340 | + * - parentcategory |
|
341 | + * - password |
|
342 | + * - select_multi |
|
343 | + * - select |
|
344 | + * - text |
|
345 | + * - textarea |
|
346 | + * - theme |
|
347 | + * - theme_multi |
|
348 | + * - timezone |
|
349 | + * - user |
|
350 | + * - user_multi |
|
351 | + * - yesno |
|
352 | + * |
|
353 | + * Now, using an array as $options, you can customize what information to |
|
354 | + * use in the control. For example, if one needs to display a select box for |
|
355 | + * the user to choose the status of an item. We only need to tell SmartObject |
|
356 | + * what method to execute within what handler to retreive the options of the |
|
357 | + * selectbox. |
|
358 | + * |
|
359 | + * $this->setControl('status', array('name' => false, |
|
360 | + * 'itemHandler' => 'item', |
|
361 | + * 'method' => 'getStatus', |
|
362 | + * 'module' => 'smartshop')); |
|
363 | + * |
|
364 | + * In this example, the array elements are the following: |
|
365 | + * - name: false, as we don't need to set a special control here. |
|
366 | + * we will use the default control related to the object type (defined in initVar) |
|
367 | + * - itemHandler: name of the object for which we will use the handler |
|
368 | + * - method: name of the method of this handler that we will execute |
|
369 | + * - module: name of the module from wich the handler is |
|
370 | + * |
|
371 | + * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
372 | + * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
373 | + * |
|
374 | + * Another example of the use of $options as an array is for TextArea: |
|
375 | + * |
|
376 | + * $this->setControl('body', array('name' => 'textarea', |
|
377 | + * 'form_editor' => 'default')); |
|
378 | + * |
|
379 | + * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
380 | + * the 'default' editor, providing it is defined in the module |
|
381 | + * preferences: $xoopsModuleConfig['default_editor'] |
|
382 | + * |
|
383 | + * Of course, you can force the use of a specific editor: |
|
384 | + * |
|
385 | + * $this->setControl('body', array('name' => 'textarea', |
|
386 | + * 'form_editor' => 'koivi')); |
|
387 | + * |
|
388 | + * Here is a list of supported editor: |
|
389 | + * - tiny: TinyEditor |
|
390 | + * - dhtmltextarea: XOOPS DHTML Area |
|
391 | + * - fckeditor: FCKEditor |
|
392 | + * - inbetween: InBetween |
|
393 | + * - koivi: Koivi |
|
394 | + * - spaw: Spaw WYSIWYG Editor |
|
395 | + * - htmlarea: HTMLArea |
|
396 | + * - textarea: basic textarea with no options |
|
397 | + * |
|
398 | + * @param string $var name of the variable for which we want to set a control |
|
399 | + * @param array $options |
|
400 | + */ |
|
401 | + public function setControl($var, $options = array()) |
|
402 | + { |
|
403 | + if (isset($this->controls[$var])) { |
|
404 | + unset($this->controls[$var]); |
|
405 | + } |
|
406 | + if (is_string($options)) { |
|
407 | + $options = array('name' => $options); |
|
408 | + } |
|
409 | + $this->controls[$var] = $options; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get control information for an instance variable |
|
414 | + * |
|
415 | + * @param string $var |
|
416 | + * @return bool|mixed |
|
417 | + */ |
|
418 | + public function getControl($var) |
|
419 | + { |
|
420 | + return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Create the form for this object |
|
425 | + * |
|
426 | + * @param $form_caption |
|
427 | + * @param $form_name |
|
428 | + * @param bool $form_action |
|
429 | + * @param string $submit_button_caption |
|
430 | + * @param bool $cancel_js_action |
|
431 | + * @param bool $captcha |
|
432 | + * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
433 | + * object for this object |
|
434 | + * @see SmartObjectForm::SmartObjectForm() |
|
435 | + */ |
|
436 | + public function getForm( |
|
437 | + $form_caption, |
|
438 | + $form_name, |
|
439 | + $form_action = false, |
|
440 | + $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
441 | + $cancel_js_action = false, |
|
442 | + $captcha = false |
|
443 | + ) { |
|
444 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
445 | + $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
446 | + |
|
447 | + return $form; |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * @return array |
|
452 | + */ |
|
453 | + public function toArray() |
|
454 | + { |
|
455 | + $ret = array(); |
|
456 | + $vars =& $this->getVars(); |
|
457 | + foreach ($vars as $key => $var) { |
|
458 | + $value = $this->getVar($key); |
|
459 | + $ret[$key] = $value; |
|
460 | + } |
|
461 | + if ($this->handler->identifierName !== '') { |
|
462 | + $controller = new SmartObjectController($this->handler); |
|
463 | + /** |
|
464 | + * Addition of some automatic value |
|
465 | + */ |
|
466 | + $ret['itemLink'] = $controller->getItemLink($this); |
|
467 | + $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
468 | + $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
469 | + $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
470 | + $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
471 | + } |
|
472 | + |
|
473 | + // Hightlighting searched words |
|
474 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
|
475 | + $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
476 | + |
|
477 | + if ($highlight && isset($_GET['keywords'])) { |
|
478 | + $myts = MyTextSanitizer::getInstance(); |
|
479 | + $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
480 | + $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
481 | + foreach ($this->handler->highlightFields as $field) { |
|
482 | + $ret[$field] = $h->highlight($ret[$field]); |
|
483 | + } |
|
484 | + } |
|
485 | + |
|
486 | + return $ret; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * add an error |
|
491 | + * |
|
492 | + * @param $err_str |
|
493 | + * @param bool $prefix |
|
494 | + * @internal param string $value error to add |
|
495 | + * @access public |
|
496 | + */ |
|
497 | + public function setErrors($err_str, $prefix = false) |
|
498 | + { |
|
499 | + if (is_array($err_str)) { |
|
500 | + foreach ($err_str as $str) { |
|
501 | + $this->setErrors($str, $prefix); |
|
502 | + } |
|
503 | + } else { |
|
504 | + if ($prefix) { |
|
505 | + $err_str = '[' . $prefix . '] ' . $err_str; |
|
506 | + } |
|
507 | + parent::setErrors($err_str); |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * @param $field |
|
513 | + * @param bool $required |
|
514 | + */ |
|
515 | + public function setFieldAsRequired($field, $required = true) |
|
516 | + { |
|
517 | + if (is_array($field)) { |
|
518 | + foreach ($field as $v) { |
|
519 | + $this->doSetFieldAsRequired($v, $required); |
|
520 | + } |
|
521 | + } else { |
|
522 | + $this->doSetFieldAsRequired($field, $required); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * @param $field |
|
528 | + */ |
|
529 | + public function setFieldForSorting($field) |
|
530 | + { |
|
531 | + if (is_array($field)) { |
|
532 | + foreach ($field as $v) { |
|
533 | + $this->doSetFieldForSorting($v); |
|
534 | + } |
|
535 | + } else { |
|
536 | + $this->doSetFieldForSorting($field); |
|
537 | + } |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * @return bool |
|
542 | + */ |
|
543 | + public function hasError() |
|
544 | + { |
|
545 | + return count($this->_errors) > 0; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * @param $url |
|
550 | + * @param $path |
|
551 | + */ |
|
552 | + public function setImageDir($url, $path) |
|
553 | + { |
|
554 | + $this->_image_url = $url; |
|
555 | + $this->_image_path = $path; |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * Retreive the group that have been granted access to a specific permission for this object |
|
560 | + * |
|
561 | + * @param $group_perm |
|
562 | + * @return string $group_perm name of the permission |
|
563 | + */ |
|
564 | + public function getGroupPerm($group_perm) |
|
565 | + { |
|
566 | + if (!$this->handler->getPermissions()) { |
|
567 | + $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
568 | + |
|
569 | + return false; |
|
570 | + } |
|
571 | + |
|
572 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
573 | + $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
574 | + |
|
575 | + if (count($ret) == 0) { |
|
576 | + return false; |
|
577 | + } else { |
|
578 | + return $ret; |
|
579 | + } |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * @param bool $path |
|
584 | + * @return mixed |
|
585 | + */ |
|
586 | + public function getImageDir($path = false) |
|
587 | + { |
|
588 | + if ($path) { |
|
589 | + return $this->_image_path; |
|
590 | + } else { |
|
591 | + return $this->_image_url; |
|
592 | + } |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * @param bool $path |
|
597 | + * @return mixed |
|
598 | + */ |
|
599 | + public function getUploadDir($path = false) |
|
600 | + { |
|
601 | + if ($path) { |
|
602 | + return $this->_image_path; |
|
603 | + } else { |
|
604 | + return $this->_image_url; |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * @param string $key |
|
610 | + * @param string $info |
|
611 | + * @return array |
|
612 | + */ |
|
613 | + public function getVarInfo($key = '', $info = '') |
|
614 | + { |
|
615 | + if (isset($this->vars[$key][$info])) { |
|
616 | + return $this->vars[$key][$info]; |
|
617 | + } elseif ($info === '' && isset($this->vars[$key])) { |
|
618 | + return $this->vars[$key]; |
|
619 | + } else { |
|
620 | + return $this->vars; |
|
621 | + } |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Get the id of the object |
|
626 | + * |
|
627 | + * @return int id of this object |
|
628 | + */ |
|
629 | + public function id() |
|
630 | + { |
|
631 | + return $this->getVar($this->handler->keyName, 'e'); |
|
632 | + } |
|
633 | + |
|
634 | + /** |
|
635 | + * Return the value of the title field of this object |
|
636 | + * |
|
637 | + * @param string $format |
|
638 | + * @return string |
|
639 | + */ |
|
640 | + public function title($format = 's') |
|
641 | + { |
|
642 | + return $this->getVar($this->handler->identifierName, $format); |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Return the value of the title field of this object |
|
647 | + * |
|
648 | + * @return string |
|
649 | + */ |
|
650 | + public function summary() |
|
651 | + { |
|
652 | + if ($this->handler->summaryName) { |
|
653 | + return $this->getVar($this->handler->summaryName); |
|
654 | + } else { |
|
655 | + return false; |
|
656 | + } |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Retreive the object admin side link, displayijng a SingleView page |
|
661 | + * |
|
662 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
663 | + * @return string user side link to the object |
|
664 | + */ |
|
665 | + public function getAdminViewItemLink($onlyUrl = false) |
|
666 | + { |
|
667 | + $controller = new SmartObjectController($this->handler); |
|
668 | + |
|
669 | + return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Retreive the object user side link |
|
674 | + * |
|
675 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
676 | + * @return string user side link to the object |
|
677 | + */ |
|
678 | + public function getItemLink($onlyUrl = false) |
|
679 | + { |
|
680 | + $controller = new SmartObjectController($this->handler); |
|
681 | + |
|
682 | + return $controller->getItemLink($this, $onlyUrl); |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * @param bool $onlyUrl |
|
687 | + * @param bool $withimage |
|
688 | + * @param bool $userSide |
|
689 | + * @return string |
|
690 | + */ |
|
691 | + public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
692 | + { |
|
693 | + $controller = new SmartObjectController($this->handler); |
|
694 | + |
|
695 | + return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * @param bool $onlyUrl |
|
700 | + * @param bool $withimage |
|
701 | + * @param bool $userSide |
|
702 | + * @return string |
|
703 | + */ |
|
704 | + public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
705 | + { |
|
706 | + $controller = new SmartObjectController($this->handler); |
|
707 | + |
|
708 | + return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * @return string |
|
713 | + */ |
|
714 | + public function getPrintAndMailLink() |
|
715 | + { |
|
716 | + $controller = new SmartObjectController($this->handler); |
|
717 | + |
|
718 | + return $controller->getPrintAndMailLink($this); |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * @param $sortsel |
|
723 | + * @return array|bool |
|
724 | + */ |
|
725 | + public function getFieldsForSorting($sortsel) |
|
726 | + { |
|
727 | + $ret = array(); |
|
728 | + |
|
729 | + foreach ($this->vars as $key => $field_info) { |
|
730 | + if ($field_info['sortby']) { |
|
731 | + $ret[$key]['caption'] = $field_info['form_caption']; |
|
732 | + $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
733 | + } |
|
734 | + } |
|
735 | + |
|
736 | + if (count($ret) > 0) { |
|
737 | + return $ret; |
|
738 | + } else { |
|
739 | + return false; |
|
740 | + } |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * @param $key |
|
745 | + * @param $newType |
|
746 | + */ |
|
747 | + public function setType($key, $newType) |
|
748 | + { |
|
749 | + $this->vars[$key]['data_type'] = $newType; |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * @param $key |
|
754 | + * @param $info |
|
755 | + * @param $value |
|
756 | + */ |
|
757 | + public function setVarInfo($key, $info, $value) |
|
758 | + { |
|
759 | + $this->vars[$key][$info] = $value; |
|
760 | + } |
|
761 | + |
|
762 | + /** |
|
763 | + * @param $key |
|
764 | + * @param bool $editor |
|
765 | + * @return string |
|
766 | + */ |
|
767 | + public function getValueFor($key, $editor = true) |
|
768 | + { |
|
769 | + global $xoopsModuleConfig; |
|
770 | + |
|
771 | + $ret = $this->getVar($key, 'n'); |
|
772 | + $myts = MyTextSanitizer::getInstance(); |
|
773 | + |
|
774 | + $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
775 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
776 | + |
|
777 | + $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
778 | + $smiley = true; |
|
779 | + $xcode = true; |
|
780 | + $image = true; |
|
781 | + $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
782 | + $formatML = true; |
|
783 | + |
|
784 | + if ($form_editor === 'default') { |
|
785 | + global $xoopsModuleConfig; |
|
786 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
787 | + } |
|
788 | + |
|
789 | + if ($editor) { |
|
790 | + if (defined('XOOPS_EDITOR_IS_HTML') |
|
791 | + && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
792 | + $br = false; |
|
793 | + $formatML = !$editor; |
|
794 | + } else { |
|
795 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
796 | + } |
|
797 | + } |
|
798 | + |
|
799 | + if (method_exists($myts, 'formatForML')) { |
|
800 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
801 | + } else { |
|
802 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
803 | + } |
|
804 | + } |
|
805 | + |
|
806 | + /** |
|
807 | + * clean values of all variables of the object for storage. |
|
808 | + * also add slashes whereever needed |
|
809 | + * |
|
810 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
811 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
812 | + * as a string separated by | |
|
813 | + * |
|
814 | + * @return bool true if successful |
|
815 | + * @access public |
|
816 | + */ |
|
817 | + public function cleanVars() |
|
818 | + { |
|
819 | + $ts = MyTextSanitizer::getInstance(); |
|
820 | + $existing_errors = $this->getErrors(); |
|
821 | + $this->_errors = array(); |
|
822 | + foreach ($this->vars as $k => $v) { |
|
823 | + $cleanv = $v['value']; |
|
824 | + if (!$v['changed']) { |
|
825 | + } else { |
|
826 | + $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
827 | + switch ($v['data_type']) { |
|
828 | + case XOBJ_DTYPE_TXTBOX: |
|
829 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
830 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
831 | + continue 2; |
|
832 | + } |
|
833 | + if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
834 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
835 | + continue 2; |
|
836 | + } |
|
837 | + if (!$v['not_gpc']) { |
|
838 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
839 | + } else { |
|
840 | + $cleanv = $ts->censorString($cleanv); |
|
841 | + } |
|
842 | + break; |
|
843 | + case XOBJ_DTYPE_TXTAREA: |
|
844 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
845 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
846 | + continue 2; |
|
847 | + } |
|
848 | + if (!$v['not_gpc']) { |
|
849 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
850 | + } else { |
|
851 | + $cleanv = $ts->censorString($cleanv); |
|
852 | + } |
|
853 | + break; |
|
854 | + case XOBJ_DTYPE_SOURCE: |
|
855 | + if (!$v['not_gpc']) { |
|
856 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
857 | + } else { |
|
858 | + $cleanv = $cleanv; |
|
859 | + } |
|
860 | + break; |
|
861 | + case XOBJ_DTYPE_INT: |
|
862 | + case XOBJ_DTYPE_TIME_ONLY: |
|
863 | + $cleanv = (int)$cleanv; |
|
864 | + break; |
|
865 | + |
|
866 | + case XOBJ_DTYPE_CURRENCY: |
|
867 | + $cleanv = smart_currency($cleanv); |
|
868 | + break; |
|
869 | + |
|
870 | + case XOBJ_DTYPE_FLOAT: |
|
871 | + $cleanv = smart_float($cleanv); |
|
872 | + break; |
|
873 | + |
|
874 | + case XOBJ_DTYPE_EMAIL: |
|
875 | + if ($v['required'] && $cleanv === '') { |
|
876 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
877 | + continue 2; |
|
878 | + } |
|
879 | + if ($cleanv !== '' |
|
880 | + && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
881 | + $this->setErrors('Invalid Email'); |
|
882 | + continue 2; |
|
883 | + } |
|
884 | + if (!$v['not_gpc']) { |
|
885 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
886 | + } |
|
887 | + break; |
|
888 | + case XOBJ_DTYPE_URL: |
|
889 | + if ($v['required'] && $cleanv === '') { |
|
890 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
891 | + continue 2; |
|
892 | + } |
|
893 | + if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
894 | + $cleanv = 'http://' . $cleanv; |
|
895 | + } |
|
896 | + if (!$v['not_gpc']) { |
|
897 | + $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
898 | + } |
|
899 | + break; |
|
900 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
901 | + $cleanv = implode('|', $cleanv); |
|
902 | + break; |
|
903 | + case XOBJ_DTYPE_ARRAY: |
|
904 | + $cleanv = serialize($cleanv); |
|
905 | + break; |
|
906 | + case XOBJ_DTYPE_STIME: |
|
907 | + case XOBJ_DTYPE_MTIME: |
|
908 | + case XOBJ_DTYPE_LTIME: |
|
909 | + $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
910 | + if (!($cleanv > 0)) { |
|
911 | + $cleanv = strtotime($cleanv); |
|
912 | + } |
|
913 | + break; |
|
914 | + default: |
|
915 | + break; |
|
916 | + } |
|
917 | + } |
|
918 | + $this->cleanVars[$k] =& $cleanv; |
|
919 | + unset($cleanv); |
|
920 | + } |
|
921 | + if (count($this->_errors) > 0) { |
|
922 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
923 | + |
|
924 | + return false; |
|
925 | + } |
|
926 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
927 | + $this->unsetDirty(); |
|
928 | + |
|
929 | + return true; |
|
930 | + } |
|
931 | + |
|
932 | + /** |
|
933 | + * returns a specific variable for the object in a proper format |
|
934 | + * |
|
935 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
936 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
937 | + * as a string separated by | |
|
938 | + * |
|
939 | + * @access public |
|
940 | + * @param string $key key of the object's variable to be returned |
|
941 | + * @param string $format format to use for the output |
|
942 | + * @return mixed formatted value of the variable |
|
943 | + */ |
|
944 | + public function getVar($key, $format = 's') |
|
945 | + { |
|
946 | + global $myts; |
|
947 | + |
|
948 | + $ret = $this->vars[$key]['value']; |
|
949 | + |
|
950 | + switch ($this->vars[$key]['data_type']) { |
|
951 | + |
|
952 | + case XOBJ_DTYPE_TXTBOX: |
|
953 | + switch (strtolower($format)) { |
|
954 | + case 's': |
|
955 | + case 'show': |
|
956 | + // ML Hack by marcan |
|
957 | + $ts = MyTextSanitizer::getInstance(); |
|
958 | + $ret = $ts->htmlSpecialChars($ret); |
|
959 | + |
|
960 | + if (method_exists($myts, 'formatForML')) { |
|
961 | + return $ts->formatForML($ret); |
|
962 | + } else { |
|
963 | + return $ret; |
|
964 | + } |
|
965 | + break 1; |
|
966 | + // End of ML Hack by marcan |
|
967 | + |
|
968 | + case 'clean': |
|
969 | + $ts = MyTextSanitizer::getInstance(); |
|
970 | + |
|
971 | + $ret = smart_html2text($ret); |
|
972 | + $ret = smart_purifyText($ret); |
|
973 | + |
|
974 | + if (method_exists($myts, 'formatForML')) { |
|
975 | + return $ts->formatForML($ret); |
|
976 | + } else { |
|
977 | + return $ret; |
|
978 | + } |
|
979 | + break 1; |
|
980 | + // End of ML Hack by marcan |
|
981 | + |
|
982 | + case 'e': |
|
983 | + case 'edit': |
|
984 | + $ts = MyTextSanitizer::getInstance(); |
|
985 | + |
|
986 | + return $ts->htmlSpecialChars($ret); |
|
987 | + break 1; |
|
988 | + case 'p': |
|
989 | + case 'preview': |
|
990 | + case 'f': |
|
991 | + case 'formpreview': |
|
992 | + $ts = MyTextSanitizer::getInstance(); |
|
993 | + |
|
994 | + return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
995 | + break 1; |
|
996 | + case 'n': |
|
997 | + case 'none': |
|
998 | + default: |
|
999 | + break 1; |
|
1000 | + } |
|
1001 | + break; |
|
1002 | + case XOBJ_DTYPE_LTIME: |
|
1003 | + switch (strtolower($format)) { |
|
1004 | + case 's': |
|
1005 | + case 'show': |
|
1006 | + case 'p': |
|
1007 | + case 'preview': |
|
1008 | + case 'f': |
|
1009 | + case 'formpreview': |
|
1010 | + $ret = formatTimestamp($ret, _DATESTRING); |
|
1011 | + |
|
1012 | + return $ret; |
|
1013 | + break 1; |
|
1014 | + case 'n': |
|
1015 | + case 'none': |
|
1016 | + case 'e': |
|
1017 | + case 'edit': |
|
1018 | + break 1; |
|
1019 | + default: |
|
1020 | + break 1; |
|
1021 | + } |
|
1022 | + break; |
|
1023 | + case XOBJ_DTYPE_STIME: |
|
1024 | + switch (strtolower($format)) { |
|
1025 | + case 's': |
|
1026 | + case 'show': |
|
1027 | + case 'p': |
|
1028 | + case 'preview': |
|
1029 | + case 'f': |
|
1030 | + case 'formpreview': |
|
1031 | + $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
1032 | + |
|
1033 | + return $ret; |
|
1034 | + break 1; |
|
1035 | + case 'n': |
|
1036 | + case 'none': |
|
1037 | + case 'e': |
|
1038 | + case 'edit': |
|
1039 | + break 1; |
|
1040 | + default: |
|
1041 | + break 1; |
|
1042 | + } |
|
1043 | + break; |
|
1044 | + case XOBJ_DTYPE_TIME_ONLY: |
|
1045 | + switch (strtolower($format)) { |
|
1046 | + case 's': |
|
1047 | + case 'show': |
|
1048 | + case 'p': |
|
1049 | + case 'preview': |
|
1050 | + case 'f': |
|
1051 | + case 'formpreview': |
|
1052 | + $ret = formatTimestamp($ret, 'G:i'); |
|
1053 | + |
|
1054 | + return $ret; |
|
1055 | + break 1; |
|
1056 | + case 'n': |
|
1057 | + case 'none': |
|
1058 | + case 'e': |
|
1059 | + case 'edit': |
|
1060 | + break 1; |
|
1061 | + default: |
|
1062 | + break 1; |
|
1063 | + } |
|
1064 | + break; |
|
1065 | + |
|
1066 | + case XOBJ_DTYPE_CURRENCY: |
|
1067 | + $decimal_section_original = strstr($ret, '.'); |
|
1068 | + $decimal_section = $decimal_section_original; |
|
1069 | + if ($decimal_section) { |
|
1070 | + if (strlen($decimal_section) == 1) { |
|
1071 | + $decimal_section = '.00'; |
|
1072 | + } elseif (strlen($decimal_section) == 2) { |
|
1073 | + $decimal_section .= '0'; |
|
1074 | + } |
|
1075 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1076 | + } else { |
|
1077 | + $ret .= '.00'; |
|
1078 | + } |
|
1079 | + break; |
|
1080 | + |
|
1081 | + case XOBJ_DTYPE_TXTAREA: |
|
1082 | + switch (strtolower($format)) { |
|
1083 | + case 's': |
|
1084 | + case 'show': |
|
1085 | + $ts = MyTextSanitizer::getInstance(); |
|
1086 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1087 | + |
|
1088 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
1089 | + || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1090 | + |
|
1091 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1092 | + || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1093 | + $image = (!isset($this->vars['doimage']['value']) |
|
1094 | + || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1095 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Hack by marcan <INBOX> for SCSPRO |
|
1099 | + * Setting mastop as the main editor |
|
1100 | + */ |
|
1101 | + if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1102 | + $br = false; |
|
1103 | + } |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * Hack by marcan <INBOX> for SCSPRO |
|
1107 | + * Setting mastop as the main editor |
|
1108 | + */ |
|
1109 | + |
|
1110 | + return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1111 | + break 1; |
|
1112 | + case 'e': |
|
1113 | + case 'edit': |
|
1114 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1115 | + break 1; |
|
1116 | + case 'p': |
|
1117 | + case 'preview': |
|
1118 | + $ts = MyTextSanitizer::getInstance(); |
|
1119 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1120 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
1121 | + || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1122 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1123 | + || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1124 | + $image = (!isset($this->vars['doimage']['value']) |
|
1125 | + || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1126 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1127 | + |
|
1128 | + return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1129 | + break 1; |
|
1130 | + case 'f': |
|
1131 | + case 'formpreview': |
|
1132 | + $ts = MyTextSanitizer::getInstance(); |
|
1133 | + |
|
1134 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1135 | + break 1; |
|
1136 | + case 'n': |
|
1137 | + case 'none': |
|
1138 | + default: |
|
1139 | + break 1; |
|
1140 | + } |
|
1141 | + break; |
|
1142 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1143 | + $ret =& explode('|', $ret); |
|
1144 | + break; |
|
1145 | + case XOBJ_DTYPE_ARRAY: |
|
1146 | + $ret =& unserialize($ret); |
|
1147 | + break; |
|
1148 | + case XOBJ_DTYPE_SOURCE: |
|
1149 | + switch (strtolower($format)) { |
|
1150 | + case 's': |
|
1151 | + case 'show': |
|
1152 | + break 1; |
|
1153 | + case 'e': |
|
1154 | + case 'edit': |
|
1155 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1156 | + break 1; |
|
1157 | + case 'p': |
|
1158 | + case 'preview': |
|
1159 | + $ts = MyTextSanitizer::getInstance(); |
|
1160 | + |
|
1161 | + return $ts->stripSlashesGPC($ret); |
|
1162 | + break 1; |
|
1163 | + case 'f': |
|
1164 | + case 'formpreview': |
|
1165 | + $ts = MyTextSanitizer::getInstance(); |
|
1166 | + |
|
1167 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1168 | + break 1; |
|
1169 | + case 'n': |
|
1170 | + case 'none': |
|
1171 | + default: |
|
1172 | + break 1; |
|
1173 | + } |
|
1174 | + break; |
|
1175 | + default: |
|
1176 | + if ($this->vars[$key]['options'] !== '' && $ret != '') { |
|
1177 | + switch (strtolower($format)) { |
|
1178 | + case 's': |
|
1179 | + case 'show': |
|
1180 | + $selected = explode('|', $ret); |
|
1181 | + $options = explode('|', $this->vars[$key]['options']); |
|
1182 | + $i = 1; |
|
1183 | + $ret = array(); |
|
1184 | + foreach ($options as $op) { |
|
1185 | + if (in_array($i, $selected)) { |
|
1186 | + $ret[] = $op; |
|
1187 | + } |
|
1188 | + ++$i; |
|
1189 | + } |
|
1190 | + |
|
1191 | + return implode(', ', $ret); |
|
1192 | + case 'e': |
|
1193 | + case 'edit': |
|
1194 | + $ret = explode('|', $ret); |
|
1195 | + break 1; |
|
1196 | + default: |
|
1197 | + break 1; |
|
1198 | + } |
|
1199 | + } |
|
1200 | + break; |
|
1201 | + } |
|
1202 | + |
|
1203 | + return $ret; |
|
1204 | + } |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * @param $key |
|
1208 | + */ |
|
1209 | + public function doMakeFieldreadOnly($key) |
|
1210 | + { |
|
1211 | + if (isset($this->vars[$key])) { |
|
1212 | + $this->vars[$key]['readonly'] = true; |
|
1213 | + $this->vars[$key]['displayOnForm'] = true; |
|
1214 | + } |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * @param $key |
|
1219 | + */ |
|
1220 | + public function makeFieldReadOnly($key) |
|
1221 | + { |
|
1222 | + if (is_array($key)) { |
|
1223 | + foreach ($key as $v) { |
|
1224 | + $this->doMakeFieldreadOnly($v); |
|
1225 | + } |
|
1226 | + } else { |
|
1227 | + $this->doMakeFieldreadOnly($key); |
|
1228 | + } |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * @param $key |
|
1233 | + */ |
|
1234 | + public function doHideFieldFromForm($key) |
|
1235 | + { |
|
1236 | + if (isset($this->vars[$key])) { |
|
1237 | + $this->vars[$key]['displayOnForm'] = false; |
|
1238 | + } |
|
1239 | + } |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * @param $key |
|
1243 | + */ |
|
1244 | + public function doHideFieldFromSingleView($key) |
|
1245 | + { |
|
1246 | + if (isset($this->vars[$key])) { |
|
1247 | + $this->vars[$key]['displayOnSingleView'] = false; |
|
1248 | + } |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * @param $key |
|
1253 | + */ |
|
1254 | + public function hideFieldFromForm($key) |
|
1255 | + { |
|
1256 | + if (is_array($key)) { |
|
1257 | + foreach ($key as $v) { |
|
1258 | + $this->doHideFieldFromForm($v); |
|
1259 | + } |
|
1260 | + } else { |
|
1261 | + $this->doHideFieldFromForm($key); |
|
1262 | + } |
|
1263 | + } |
|
1264 | + |
|
1265 | + /** |
|
1266 | + * @param $key |
|
1267 | + */ |
|
1268 | + public function hideFieldFromSingleView($key) |
|
1269 | + { |
|
1270 | + if (is_array($key)) { |
|
1271 | + foreach ($key as $v) { |
|
1272 | + $this->doHideFieldFromSingleView($v); |
|
1273 | + } |
|
1274 | + } else { |
|
1275 | + $this->doHideFieldFromSingleView($key); |
|
1276 | + } |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * @param $key |
|
1281 | + */ |
|
1282 | + public function doShowFieldOnForm($key) |
|
1283 | + { |
|
1284 | + if (isset($this->vars[$key])) { |
|
1285 | + $this->vars[$key]['displayOnForm'] = true; |
|
1286 | + } |
|
1287 | + } |
|
1288 | + |
|
1289 | + /** |
|
1290 | + * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1291 | + * |
|
1292 | + * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1293 | + * @param bool $userSide for futur use, to do something different on the user side |
|
1294 | + * @param array $actions |
|
1295 | + * @param bool $headerAsRow |
|
1296 | + * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1297 | + */ |
|
1298 | + public function displaySingleObject( |
|
1299 | + $fetchOnly = false, |
|
1300 | + $userSide = false, |
|
1301 | + $actions = array(), |
|
1302 | + $headerAsRow = true |
|
1303 | + ) { |
|
1304 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
1305 | + $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
1306 | + // add all fields mark as displayOnSingleView except the keyid |
|
1307 | + foreach ($this->vars as $key => $var) { |
|
1308 | + if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1309 | + $is_header = ($key == $this->handler->identifierName); |
|
1310 | + $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
1311 | + } |
|
1312 | + } |
|
1313 | + |
|
1314 | + if ($fetchOnly) { |
|
1315 | + $ret = $singleview->render($fetchOnly); |
|
1316 | + |
|
1317 | + return $ret; |
|
1318 | + } else { |
|
1319 | + $singleview->render($fetchOnly); |
|
1320 | + } |
|
1321 | + } |
|
1322 | + |
|
1323 | + /** |
|
1324 | + * @param $key |
|
1325 | + */ |
|
1326 | + public function doDisplayFieldOnSingleView($key) |
|
1327 | + { |
|
1328 | + if (isset($this->vars[$key])) { |
|
1329 | + $this->vars[$key]['displayOnSingleView'] = true; |
|
1330 | + } |
|
1331 | + } |
|
1332 | + |
|
1333 | + /** |
|
1334 | + * @param $field |
|
1335 | + * @param bool $required |
|
1336 | + */ |
|
1337 | + public function doSetFieldAsRequired($field, $required = true) |
|
1338 | + { |
|
1339 | + $this->setVarInfo($field, 'required', $required); |
|
1340 | + } |
|
1341 | + |
|
1342 | + /** |
|
1343 | + * @param $field |
|
1344 | + */ |
|
1345 | + public function doSetFieldForSorting($field) |
|
1346 | + { |
|
1347 | + $this->setVarInfo($field, 'sortby', true); |
|
1348 | + } |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * @param $key |
|
1352 | + */ |
|
1353 | + public function showFieldOnForm($key) |
|
1354 | + { |
|
1355 | + if (is_array($key)) { |
|
1356 | + foreach ($key as $v) { |
|
1357 | + $this->doShowFieldOnForm($v); |
|
1358 | + } |
|
1359 | + } else { |
|
1360 | + $this->doShowFieldOnForm($key); |
|
1361 | + } |
|
1362 | + } |
|
1363 | + |
|
1364 | + /** |
|
1365 | + * @param $key |
|
1366 | + */ |
|
1367 | + public function displayFieldOnSingleView($key) |
|
1368 | + { |
|
1369 | + if (is_array($key)) { |
|
1370 | + foreach ($key as $v) { |
|
1371 | + $this->doDisplayFieldOnSingleView($v); |
|
1372 | + } |
|
1373 | + } else { |
|
1374 | + $this->doDisplayFieldOnSingleView($key); |
|
1375 | + } |
|
1376 | + } |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * @param $key |
|
1380 | + */ |
|
1381 | + public function doSetAdvancedFormFields($key) |
|
1382 | + { |
|
1383 | + if (isset($this->vars[$key])) { |
|
1384 | + $this->vars[$key]['advancedform'] = true; |
|
1385 | + } |
|
1386 | + } |
|
1387 | + |
|
1388 | + /** |
|
1389 | + * @param $key |
|
1390 | + */ |
|
1391 | + public function setAdvancedFormFields($key) |
|
1392 | + { |
|
1393 | + if (is_array($key)) { |
|
1394 | + foreach ($key as $v) { |
|
1395 | + $this->doSetAdvancedFormFields($v); |
|
1396 | + } |
|
1397 | + } else { |
|
1398 | + $this->doSetAdvancedFormFields($key); |
|
1399 | + } |
|
1400 | + } |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * @param $key |
|
1404 | + * @return mixed |
|
1405 | + */ |
|
1406 | + public function getUrlLinkObj($key) |
|
1407 | + { |
|
1408 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1409 | + $urllinkid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1410 | + if ($urllinkid != 0) { |
|
1411 | + return $smartobjectLinkurlHandler->get($urllinkid); |
|
1412 | + } else { |
|
1413 | + return $smartobjectLinkurlHandler->create(); |
|
1414 | + } |
|
1415 | + } |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * @param $urlLinkObj |
|
1419 | + * @return mixed |
|
1420 | + */ |
|
1421 | + public function &storeUrlLinkObj($urlLinkObj) |
|
1422 | + { |
|
1423 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1424 | + |
|
1425 | + return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1426 | + } |
|
1427 | + |
|
1428 | + /** |
|
1429 | + * @param $key |
|
1430 | + * @return mixed |
|
1431 | + */ |
|
1432 | + public function getFileObj($key) |
|
1433 | + { |
|
1434 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1435 | + $fileid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1436 | + if ($fileid != 0) { |
|
1437 | + return $smartobjectFileHandler->get($fileid); |
|
1438 | + } else { |
|
1439 | + return $smartobjectFileHandler->create(); |
|
1440 | + } |
|
1441 | + } |
|
1442 | + |
|
1443 | + /** |
|
1444 | + * @param $fileObj |
|
1445 | + * @return mixed |
|
1446 | + */ |
|
1447 | + public function &storeFileObj($fileObj) |
|
1448 | + { |
|
1449 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1450 | + |
|
1451 | + return $smartobjectFileHandler->insert($fileObj); |
|
1452 | + } |
|
1453 | 1453 | } |
@@ -24,82 +24,82 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class SmartMlObject extends SmartObject |
26 | 26 | { |
27 | - /** |
|
28 | - * SmartMlObject constructor. |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
|
33 | - $this->setControl('language', 'language'); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * If object is not new, change the control of the not-multilanguage fields |
|
38 | - * |
|
39 | - * We need to intercept this function from SmartObject because if the object is not new... |
|
40 | - */ |
|
41 | - // function getForm() { |
|
42 | - |
|
43 | - //} |
|
44 | - |
|
45 | - /** |
|
46 | - * Strip Multilanguage Fields |
|
47 | - * |
|
48 | - * Get rid of all the multilanguage fields to have an object with only global fields. |
|
49 | - * This will be usefull when creating the ML object for the first time. Then we will be able |
|
50 | - * to create translations. |
|
51 | - */ |
|
52 | - public function stripMultilanguageFields() |
|
53 | - { |
|
54 | - $objectVars =& $this->getVars(); |
|
55 | - $newObjectVars = array(); |
|
56 | - foreach ($objectVars as $key => $var) { |
|
57 | - if (!$var['multilingual']) { |
|
58 | - $newObjectVars[$key] = $var; |
|
59 | - } |
|
60 | - } |
|
61 | - $this->vars = $newObjectVars; |
|
62 | - } |
|
63 | - |
|
64 | - public function stripNonMultilanguageFields() |
|
65 | - { |
|
66 | - $objectVars =& $this->getVars(); |
|
67 | - $newObjectVars = array(); |
|
68 | - foreach ($objectVars as $key => $var) { |
|
69 | - if ($var['multilingual'] || $key == $this->handler->keyName) { |
|
70 | - $newObjectVars[$key] = $var; |
|
71 | - } |
|
72 | - } |
|
73 | - $this->vars = $newObjectVars; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Make non multilanguage fields read only |
|
78 | - * |
|
79 | - * This is used when we are creating/editing a translation. |
|
80 | - * We only want to edit the multilanguag fields, not the global one. |
|
81 | - */ |
|
82 | - public function makeNonMLFieldReadOnly() |
|
83 | - { |
|
84 | - foreach ($this->getVars() as $key => $var) { |
|
85 | - //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
86 | - if (!$var['multilingual'] && $key != $this->handler->keyName) { |
|
87 | - $this->setControl($key, 'label'); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param bool $onlyUrl |
|
94 | - * @param bool $withimage |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
|
98 | - { |
|
99 | - $controller = new SmartObjectController($this->handler); |
|
100 | - |
|
101 | - return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
|
102 | - } |
|
27 | + /** |
|
28 | + * SmartMlObject constructor. |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
|
33 | + $this->setControl('language', 'language'); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * If object is not new, change the control of the not-multilanguage fields |
|
38 | + * |
|
39 | + * We need to intercept this function from SmartObject because if the object is not new... |
|
40 | + */ |
|
41 | + // function getForm() { |
|
42 | + |
|
43 | + //} |
|
44 | + |
|
45 | + /** |
|
46 | + * Strip Multilanguage Fields |
|
47 | + * |
|
48 | + * Get rid of all the multilanguage fields to have an object with only global fields. |
|
49 | + * This will be usefull when creating the ML object for the first time. Then we will be able |
|
50 | + * to create translations. |
|
51 | + */ |
|
52 | + public function stripMultilanguageFields() |
|
53 | + { |
|
54 | + $objectVars =& $this->getVars(); |
|
55 | + $newObjectVars = array(); |
|
56 | + foreach ($objectVars as $key => $var) { |
|
57 | + if (!$var['multilingual']) { |
|
58 | + $newObjectVars[$key] = $var; |
|
59 | + } |
|
60 | + } |
|
61 | + $this->vars = $newObjectVars; |
|
62 | + } |
|
63 | + |
|
64 | + public function stripNonMultilanguageFields() |
|
65 | + { |
|
66 | + $objectVars =& $this->getVars(); |
|
67 | + $newObjectVars = array(); |
|
68 | + foreach ($objectVars as $key => $var) { |
|
69 | + if ($var['multilingual'] || $key == $this->handler->keyName) { |
|
70 | + $newObjectVars[$key] = $var; |
|
71 | + } |
|
72 | + } |
|
73 | + $this->vars = $newObjectVars; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Make non multilanguage fields read only |
|
78 | + * |
|
79 | + * This is used when we are creating/editing a translation. |
|
80 | + * We only want to edit the multilanguag fields, not the global one. |
|
81 | + */ |
|
82 | + public function makeNonMLFieldReadOnly() |
|
83 | + { |
|
84 | + foreach ($this->getVars() as $key => $var) { |
|
85 | + //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
86 | + if (!$var['multilingual'] && $key != $this->handler->keyName) { |
|
87 | + $this->setControl($key, 'label'); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param bool $onlyUrl |
|
94 | + * @param bool $withimage |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
|
98 | + { |
|
99 | + $controller = new SmartObjectController($this->handler); |
|
100 | + |
|
101 | + return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,60 +107,60 @@ discard block |
||
107 | 107 | */ |
108 | 108 | class SmartPersistableMlObjectHandler extends SmartPersistableObjectHandler |
109 | 109 | { |
110 | - /** |
|
111 | - * @param null $criteria |
|
112 | - * @param bool $id_as_key |
|
113 | - * @param bool $as_object |
|
114 | - * @param bool $debug |
|
115 | - * @param bool $language |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - public function getObjects( |
|
119 | - $criteria = null, |
|
120 | - $id_as_key = false, |
|
121 | - $as_object = true, |
|
122 | - $debug = false, |
|
123 | - $language = false |
|
124 | - ) { |
|
125 | - // Create the first part of the SQL query to join the "_text" table |
|
126 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
127 | - |
|
128 | - if ($language) { |
|
129 | - // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
130 | - |
|
131 | - // if no criteria was previously created, let's create it |
|
132 | - if (!$criteria) { |
|
133 | - $criteria = new CriteriaCompo(); |
|
134 | - } |
|
135 | - $criteria->add(new Criteria('language', $language)); |
|
136 | - |
|
137 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
138 | - } |
|
139 | - |
|
140 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param mixed $id |
|
145 | - * @param bool $language |
|
146 | - * @param bool $as_object |
|
147 | - * @param bool $debug |
|
148 | - * @return mixed |
|
149 | - */ |
|
150 | - public function &get($id, $language = false, $as_object = true, $debug = false) |
|
151 | - { |
|
152 | - if (!$language) { |
|
153 | - return parent::get($id, $as_object, $debug); |
|
154 | - } else { |
|
155 | - $criteria = new CriteriaCompo(); |
|
156 | - $criteria->add(new Criteria('language', $language)); |
|
157 | - |
|
158 | - return parent::get($id, $as_object, $debug, $criteria); |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - public function changeTableNameForML() |
|
163 | - { |
|
164 | - $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
165 | - } |
|
110 | + /** |
|
111 | + * @param null $criteria |
|
112 | + * @param bool $id_as_key |
|
113 | + * @param bool $as_object |
|
114 | + * @param bool $debug |
|
115 | + * @param bool $language |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + public function getObjects( |
|
119 | + $criteria = null, |
|
120 | + $id_as_key = false, |
|
121 | + $as_object = true, |
|
122 | + $debug = false, |
|
123 | + $language = false |
|
124 | + ) { |
|
125 | + // Create the first part of the SQL query to join the "_text" table |
|
126 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
127 | + |
|
128 | + if ($language) { |
|
129 | + // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
130 | + |
|
131 | + // if no criteria was previously created, let's create it |
|
132 | + if (!$criteria) { |
|
133 | + $criteria = new CriteriaCompo(); |
|
134 | + } |
|
135 | + $criteria->add(new Criteria('language', $language)); |
|
136 | + |
|
137 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
138 | + } |
|
139 | + |
|
140 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param mixed $id |
|
145 | + * @param bool $language |
|
146 | + * @param bool $as_object |
|
147 | + * @param bool $debug |
|
148 | + * @return mixed |
|
149 | + */ |
|
150 | + public function &get($id, $language = false, $as_object = true, $debug = false) |
|
151 | + { |
|
152 | + if (!$language) { |
|
153 | + return parent::get($id, $as_object, $debug); |
|
154 | + } else { |
|
155 | + $criteria = new CriteriaCompo(); |
|
156 | + $criteria->add(new Criteria('language', $language)); |
|
157 | + |
|
158 | + return parent::get($id, $as_object, $debug, $criteria); |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + public function changeTableNameForML() |
|
163 | + { |
|
164 | + $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
165 | + } |
|
166 | 166 | } |
@@ -37,115 +37,115 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class SmartobjectCurrency extends SmartObject |
39 | 39 | { |
40 | - public $_modulePlugin = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectCurrency constructor. |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
48 | - $this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
|
49 | - $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
|
50 | - $this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
|
51 | - $this->quickInitVar('rate', XOBJ_DTYPE_FLOAT, true, _CO_SOBJECT_CURRENCY_RATE, '', '1.0'); |
|
52 | - $this->quickInitVar('default_currency', XOBJ_DTYPE_INT, false, _CO_SOBJECT_CURRENCY_DEFAULT, '', false); |
|
53 | - |
|
54 | - $this->setControl('symbol', array( |
|
55 | - 'name' => 'text', |
|
56 | - 'size' => '15', |
|
57 | - 'maxlength' => '15' |
|
58 | - )); |
|
59 | - |
|
60 | - $this->setControl('iso4217', array( |
|
61 | - 'name' => 'text', |
|
62 | - 'size' => '5', |
|
63 | - 'maxlength' => '5' |
|
64 | - )); |
|
65 | - |
|
66 | - $this->setControl('rate', array( |
|
67 | - 'name' => 'text', |
|
68 | - 'size' => '5', |
|
69 | - 'maxlength' => '5' |
|
70 | - )); |
|
71 | - |
|
72 | - $this->setControl('rate', array( |
|
73 | - 'name' => 'text', |
|
74 | - 'size' => '5', |
|
75 | - 'maxlength' => '5' |
|
76 | - )); |
|
77 | - |
|
78 | - $this->hideFieldFromForm('default_currency'); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $key |
|
83 | - * @param string $format |
|
84 | - * @return mixed |
|
85 | - */ |
|
86 | - public function getVar($key, $format = 's') |
|
87 | - { |
|
88 | - if ($format === 's' && in_array($key, array('rate', 'default_currency'))) { |
|
89 | - // return call_user_func(array($this, $key)); |
|
90 | - return $this->{$key}(); |
|
91 | - } |
|
92 | - |
|
93 | - return parent::getVar($key, $format); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return mixed |
|
98 | - */ |
|
99 | - public function getCurrencyLink() |
|
100 | - { |
|
101 | - $ret = $this->getVar('name', 'e'); |
|
102 | - |
|
103 | - return $ret; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return mixed |
|
108 | - */ |
|
109 | - public function getCode() |
|
110 | - { |
|
111 | - $ret = $this->getVar('iso4217', 'e'); |
|
112 | - |
|
113 | - return $ret; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @return float|int|mixed|string |
|
118 | - */ |
|
119 | - public function rate() |
|
120 | - { |
|
121 | - return smart_currency($this->getVar('rate', 'e')); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function defaultCurrency() |
|
128 | - { |
|
129 | - if ($this->getVar('default_currency', 'e') === true) { |
|
130 | - return _YES; |
|
131 | - } else { |
|
132 | - return _NO; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function getDefaultCurrencyControl() |
|
140 | - { |
|
141 | - $radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
|
142 | - if ($this->getVar('default_currency', 'e')) { |
|
143 | - $radio_box .= 'checked'; |
|
144 | - } |
|
145 | - $radio_box .= '>'; |
|
146 | - |
|
147 | - return $radio_box; |
|
148 | - } |
|
40 | + public $_modulePlugin = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectCurrency constructor. |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
48 | + $this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
|
49 | + $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
|
50 | + $this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
|
51 | + $this->quickInitVar('rate', XOBJ_DTYPE_FLOAT, true, _CO_SOBJECT_CURRENCY_RATE, '', '1.0'); |
|
52 | + $this->quickInitVar('default_currency', XOBJ_DTYPE_INT, false, _CO_SOBJECT_CURRENCY_DEFAULT, '', false); |
|
53 | + |
|
54 | + $this->setControl('symbol', array( |
|
55 | + 'name' => 'text', |
|
56 | + 'size' => '15', |
|
57 | + 'maxlength' => '15' |
|
58 | + )); |
|
59 | + |
|
60 | + $this->setControl('iso4217', array( |
|
61 | + 'name' => 'text', |
|
62 | + 'size' => '5', |
|
63 | + 'maxlength' => '5' |
|
64 | + )); |
|
65 | + |
|
66 | + $this->setControl('rate', array( |
|
67 | + 'name' => 'text', |
|
68 | + 'size' => '5', |
|
69 | + 'maxlength' => '5' |
|
70 | + )); |
|
71 | + |
|
72 | + $this->setControl('rate', array( |
|
73 | + 'name' => 'text', |
|
74 | + 'size' => '5', |
|
75 | + 'maxlength' => '5' |
|
76 | + )); |
|
77 | + |
|
78 | + $this->hideFieldFromForm('default_currency'); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $key |
|
83 | + * @param string $format |
|
84 | + * @return mixed |
|
85 | + */ |
|
86 | + public function getVar($key, $format = 's') |
|
87 | + { |
|
88 | + if ($format === 's' && in_array($key, array('rate', 'default_currency'))) { |
|
89 | + // return call_user_func(array($this, $key)); |
|
90 | + return $this->{$key}(); |
|
91 | + } |
|
92 | + |
|
93 | + return parent::getVar($key, $format); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return mixed |
|
98 | + */ |
|
99 | + public function getCurrencyLink() |
|
100 | + { |
|
101 | + $ret = $this->getVar('name', 'e'); |
|
102 | + |
|
103 | + return $ret; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return mixed |
|
108 | + */ |
|
109 | + public function getCode() |
|
110 | + { |
|
111 | + $ret = $this->getVar('iso4217', 'e'); |
|
112 | + |
|
113 | + return $ret; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @return float|int|mixed|string |
|
118 | + */ |
|
119 | + public function rate() |
|
120 | + { |
|
121 | + return smart_currency($this->getVar('rate', 'e')); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function defaultCurrency() |
|
128 | + { |
|
129 | + if ($this->getVar('default_currency', 'e') === true) { |
|
130 | + return _YES; |
|
131 | + } else { |
|
132 | + return _NO; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function getDefaultCurrencyControl() |
|
140 | + { |
|
141 | + $radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
|
142 | + if ($this->getVar('default_currency', 'e')) { |
|
143 | + $radio_box .= 'checked'; |
|
144 | + } |
|
145 | + $radio_box .= '>'; |
|
146 | + |
|
147 | + return $radio_box; |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -153,22 +153,22 @@ discard block |
||
153 | 153 | */ |
154 | 154 | class SmartObjectCurrencyHandler extends SmartPersistableObjectHandler |
155 | 155 | { |
156 | - /** |
|
157 | - * SmartObjectCurrencyHandler constructor. |
|
158 | - * @param XoopsDatabase $db |
|
159 | - */ |
|
160 | - public function __construct(XoopsDatabase $db) |
|
161 | - { |
|
162 | - parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function getCurrencies() |
|
169 | - { |
|
170 | - $currenciesObj = $this->getObjects(null, true); |
|
171 | - |
|
172 | - return $currenciesObj; |
|
173 | - } |
|
156 | + /** |
|
157 | + * SmartObjectCurrencyHandler constructor. |
|
158 | + * @param XoopsDatabase $db |
|
159 | + */ |
|
160 | + public function __construct(XoopsDatabase $db) |
|
161 | + { |
|
162 | + parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function getCurrencies() |
|
169 | + { |
|
170 | + $currenciesObj = $this->getObjects(null, true); |
|
171 | + |
|
172 | + return $currenciesObj; |
|
173 | + } |
|
174 | 174 | } |
@@ -36,227 +36,227 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class SmartobjectCustomtag extends SmartObject |
38 | 38 | { |
39 | - public $content = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * SmartobjectCustomtag constructor. |
|
43 | - */ |
|
44 | - public function __construct() |
|
45 | - { |
|
46 | - $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
47 | - $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
48 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
49 | - $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
50 | - $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
51 | - |
|
52 | - $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
53 | - $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
54 | - $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
55 | - $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
56 | - |
|
57 | - $this->setControl('content', array( |
|
58 | - 'name' => 'textarea', |
|
59 | - 'form_editor' => 'textarea', |
|
60 | - 'form_rows' => 25 |
|
61 | - )); |
|
62 | - $this->setControl('language', array( |
|
63 | - 'name' => 'language', |
|
64 | - 'all' => true |
|
65 | - )); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param string $key |
|
70 | - * @param string $format |
|
71 | - * @return mixed |
|
72 | - */ |
|
73 | - public function getVar($key, $format = 's') |
|
74 | - { |
|
75 | - if ($format === 's' && in_array($key, array())) { |
|
76 | - // return call_user_func(array($this, $key)); |
|
77 | - return $this->{$key}(); |
|
78 | - } |
|
79 | - |
|
80 | - return parent::getVar($key, $format); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return bool|mixed |
|
85 | - */ |
|
86 | - public function render() |
|
87 | - { |
|
88 | - if (!$this->content) { |
|
89 | - $ret = $this->getVar('content'); |
|
90 | - $this->content = $ret; |
|
91 | - } |
|
92 | - |
|
93 | - return $this->content; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return bool|mixed|string |
|
98 | - */ |
|
99 | - public function renderWithPhp() |
|
100 | - { |
|
101 | - if (!$this->content) { |
|
102 | - $ret = $this->getVar('content'); |
|
103 | - $this->content = $ret; |
|
104 | - } else { |
|
105 | - $ret = $this->content; |
|
106 | - } |
|
107 | - |
|
108 | - // check for PHP if we are not on admin side |
|
109 | - if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
110 | - $ret = str_replace('[php]', '', $ret); |
|
111 | - // we have PHP code, let's evaluate |
|
112 | - eval($ret); |
|
113 | - |
|
114 | - return ''; |
|
115 | - } |
|
116 | - |
|
117 | - return $this->content; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getXoopsCode() |
|
124 | - { |
|
125 | - $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
126 | - |
|
127 | - return $ret; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function getCloneLink() |
|
134 | - { |
|
135 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/customtag.php?op=clone&customtagid=' . $this->id() . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" style="vertical-align: middle;" alt="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" title="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '"></a>'; |
|
136 | - |
|
137 | - return $ret; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param $var |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - public function emptyString($var) |
|
145 | - { |
|
146 | - return (strlen($var) > 0); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return mixed|string |
|
151 | - */ |
|
152 | - public function generateTag() |
|
153 | - { |
|
154 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
155 | - $title = xoops_substr($title, 0, 10, ''); |
|
156 | - // Transformation des ponctuations |
|
157 | - $pattern = array( |
|
158 | - '/%09/', // Tab |
|
159 | - '/%20/', // Space |
|
160 | - '/%21/', // ! |
|
161 | - '/%22/', // " |
|
162 | - '/%23/', // # |
|
163 | - '/%25/', // % |
|
164 | - '/%26/', // & |
|
165 | - '/%27/', // ' |
|
166 | - '/%28/', // ( |
|
167 | - '/%29/', // ) |
|
168 | - '/%2C/', // , |
|
169 | - '/%2F/', // / |
|
170 | - '/%3A/', // : |
|
171 | - '/%3B/', // ; |
|
172 | - '/%3C/', // < |
|
173 | - '/%3D/', // = |
|
174 | - '/%3E/', // > |
|
175 | - '/%3F/', // ? |
|
176 | - '/%40/', // @ |
|
177 | - '/%5B/', // [ |
|
178 | - '/%5C/', // \ |
|
179 | - '/%5D/', // ] |
|
180 | - '/%5E/', // ^ |
|
181 | - '/%7B/', // { |
|
182 | - '/%7C/', // | |
|
183 | - '/%7D/', // } |
|
184 | - '/%7E/', // ~ |
|
185 | - "/\./" // . |
|
186 | - ); |
|
187 | - $rep_pat = array( |
|
188 | - '-', |
|
189 | - '-', |
|
190 | - '-', |
|
191 | - '-', |
|
192 | - '-', |
|
193 | - '-100', |
|
194 | - '-', |
|
195 | - '-', |
|
196 | - '-', |
|
197 | - '-', |
|
198 | - '-', |
|
199 | - '-', |
|
200 | - '-', |
|
201 | - '-', |
|
202 | - '-', |
|
203 | - '-', |
|
204 | - '-', |
|
205 | - '-', |
|
206 | - '-at-', |
|
207 | - '-', |
|
208 | - '-', |
|
209 | - '-', |
|
210 | - '-', |
|
211 | - '-', |
|
212 | - '-', |
|
213 | - '-', |
|
214 | - '-', |
|
215 | - '-' |
|
216 | - ); |
|
217 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
218 | - |
|
219 | - // Transformation des caractères accentués |
|
220 | - $pattern = array( |
|
221 | - '/%B0/', // ° |
|
222 | - '/%E8/', // è |
|
223 | - '/%E9/', // é |
|
224 | - '/%EA/', // ê |
|
225 | - '/%EB/', // ë |
|
226 | - '/%E7/', // ç |
|
227 | - '/%E0/', // à |
|
228 | - '/%E2/', // â |
|
229 | - '/%E4/', // ä |
|
230 | - '/%EE/', // î |
|
231 | - '/%EF/', // ï |
|
232 | - '/%F9/', // ù |
|
233 | - '/%FC/', // ü |
|
234 | - '/%FB/', // û |
|
235 | - '/%F4/', // ô |
|
236 | - '/%F6/', // ö |
|
237 | - ); |
|
238 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
239 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
240 | - |
|
241 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
242 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
243 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
244 | - |
|
245 | - $title .= time(); |
|
246 | - $title = md5($title); |
|
247 | - |
|
248 | - return $title; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return mixed |
|
253 | - */ |
|
254 | - public function getCustomtagName() |
|
255 | - { |
|
256 | - $ret = $this->getVar('name'); |
|
257 | - |
|
258 | - return $ret; |
|
259 | - } |
|
39 | + public $content = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * SmartobjectCustomtag constructor. |
|
43 | + */ |
|
44 | + public function __construct() |
|
45 | + { |
|
46 | + $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
47 | + $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
48 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
49 | + $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
50 | + $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
51 | + |
|
52 | + $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
53 | + $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
54 | + $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
55 | + $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
56 | + |
|
57 | + $this->setControl('content', array( |
|
58 | + 'name' => 'textarea', |
|
59 | + 'form_editor' => 'textarea', |
|
60 | + 'form_rows' => 25 |
|
61 | + )); |
|
62 | + $this->setControl('language', array( |
|
63 | + 'name' => 'language', |
|
64 | + 'all' => true |
|
65 | + )); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param string $key |
|
70 | + * @param string $format |
|
71 | + * @return mixed |
|
72 | + */ |
|
73 | + public function getVar($key, $format = 's') |
|
74 | + { |
|
75 | + if ($format === 's' && in_array($key, array())) { |
|
76 | + // return call_user_func(array($this, $key)); |
|
77 | + return $this->{$key}(); |
|
78 | + } |
|
79 | + |
|
80 | + return parent::getVar($key, $format); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return bool|mixed |
|
85 | + */ |
|
86 | + public function render() |
|
87 | + { |
|
88 | + if (!$this->content) { |
|
89 | + $ret = $this->getVar('content'); |
|
90 | + $this->content = $ret; |
|
91 | + } |
|
92 | + |
|
93 | + return $this->content; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return bool|mixed|string |
|
98 | + */ |
|
99 | + public function renderWithPhp() |
|
100 | + { |
|
101 | + if (!$this->content) { |
|
102 | + $ret = $this->getVar('content'); |
|
103 | + $this->content = $ret; |
|
104 | + } else { |
|
105 | + $ret = $this->content; |
|
106 | + } |
|
107 | + |
|
108 | + // check for PHP if we are not on admin side |
|
109 | + if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
110 | + $ret = str_replace('[php]', '', $ret); |
|
111 | + // we have PHP code, let's evaluate |
|
112 | + eval($ret); |
|
113 | + |
|
114 | + return ''; |
|
115 | + } |
|
116 | + |
|
117 | + return $this->content; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getXoopsCode() |
|
124 | + { |
|
125 | + $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
126 | + |
|
127 | + return $ret; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function getCloneLink() |
|
134 | + { |
|
135 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/customtag.php?op=clone&customtagid=' . $this->id() . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" style="vertical-align: middle;" alt="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" title="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '"></a>'; |
|
136 | + |
|
137 | + return $ret; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param $var |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + public function emptyString($var) |
|
145 | + { |
|
146 | + return (strlen($var) > 0); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return mixed|string |
|
151 | + */ |
|
152 | + public function generateTag() |
|
153 | + { |
|
154 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
155 | + $title = xoops_substr($title, 0, 10, ''); |
|
156 | + // Transformation des ponctuations |
|
157 | + $pattern = array( |
|
158 | + '/%09/', // Tab |
|
159 | + '/%20/', // Space |
|
160 | + '/%21/', // ! |
|
161 | + '/%22/', // " |
|
162 | + '/%23/', // # |
|
163 | + '/%25/', // % |
|
164 | + '/%26/', // & |
|
165 | + '/%27/', // ' |
|
166 | + '/%28/', // ( |
|
167 | + '/%29/', // ) |
|
168 | + '/%2C/', // , |
|
169 | + '/%2F/', // / |
|
170 | + '/%3A/', // : |
|
171 | + '/%3B/', // ; |
|
172 | + '/%3C/', // < |
|
173 | + '/%3D/', // = |
|
174 | + '/%3E/', // > |
|
175 | + '/%3F/', // ? |
|
176 | + '/%40/', // @ |
|
177 | + '/%5B/', // [ |
|
178 | + '/%5C/', // \ |
|
179 | + '/%5D/', // ] |
|
180 | + '/%5E/', // ^ |
|
181 | + '/%7B/', // { |
|
182 | + '/%7C/', // | |
|
183 | + '/%7D/', // } |
|
184 | + '/%7E/', // ~ |
|
185 | + "/\./" // . |
|
186 | + ); |
|
187 | + $rep_pat = array( |
|
188 | + '-', |
|
189 | + '-', |
|
190 | + '-', |
|
191 | + '-', |
|
192 | + '-', |
|
193 | + '-100', |
|
194 | + '-', |
|
195 | + '-', |
|
196 | + '-', |
|
197 | + '-', |
|
198 | + '-', |
|
199 | + '-', |
|
200 | + '-', |
|
201 | + '-', |
|
202 | + '-', |
|
203 | + '-', |
|
204 | + '-', |
|
205 | + '-', |
|
206 | + '-at-', |
|
207 | + '-', |
|
208 | + '-', |
|
209 | + '-', |
|
210 | + '-', |
|
211 | + '-', |
|
212 | + '-', |
|
213 | + '-', |
|
214 | + '-', |
|
215 | + '-' |
|
216 | + ); |
|
217 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
218 | + |
|
219 | + // Transformation des caractères accentués |
|
220 | + $pattern = array( |
|
221 | + '/%B0/', // ° |
|
222 | + '/%E8/', // è |
|
223 | + '/%E9/', // é |
|
224 | + '/%EA/', // ê |
|
225 | + '/%EB/', // ë |
|
226 | + '/%E7/', // ç |
|
227 | + '/%E0/', // à |
|
228 | + '/%E2/', // â |
|
229 | + '/%E4/', // ä |
|
230 | + '/%EE/', // î |
|
231 | + '/%EF/', // ï |
|
232 | + '/%F9/', // ù |
|
233 | + '/%FC/', // ü |
|
234 | + '/%FB/', // û |
|
235 | + '/%F4/', // ô |
|
236 | + '/%F6/', // ö |
|
237 | + ); |
|
238 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
239 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
240 | + |
|
241 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
242 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
243 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
244 | + |
|
245 | + $title .= time(); |
|
246 | + $title = md5($title); |
|
247 | + |
|
248 | + return $title; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return mixed |
|
253 | + */ |
|
254 | + public function getCustomtagName() |
|
255 | + { |
|
256 | + $ret = $this->getVar('name'); |
|
257 | + |
|
258 | + return $ret; |
|
259 | + } |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -264,48 +264,48 @@ discard block |
||
264 | 264 | */ |
265 | 265 | class SmartobjectCustomtagHandler extends SmartPersistableObjectHandler |
266 | 266 | { |
267 | - public $objects = false; |
|
268 | - |
|
269 | - /** |
|
270 | - * SmartobjectCustomtagHandler constructor. |
|
271 | - * @param XoopsDatabase $db |
|
272 | - */ |
|
273 | - public function __construct(XoopsDatabase $db) |
|
274 | - { |
|
275 | - parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
276 | - $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @return array|bool |
|
281 | - */ |
|
282 | - public function getCustomtagsByName() |
|
283 | - { |
|
284 | - if (!$this->objects) { |
|
285 | - global $xoopsConfig; |
|
286 | - |
|
287 | - $ret = array(); |
|
288 | - |
|
289 | - $criteria = new CriteriaCompo(); |
|
290 | - |
|
291 | - $criteria_language = new CriteriaCompo(); |
|
292 | - $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
293 | - $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
294 | - $criteria->add($criteria_language); |
|
295 | - |
|
296 | - $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
297 | - $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
298 | - |
|
299 | - if ($granted_ids && count($granted_ids) > 0) { |
|
300 | - $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
301 | - $customtagsObj = $this->getObjects($criteria, true); |
|
302 | - foreach ($customtagsObj as $customtagObj) { |
|
303 | - $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
304 | - } |
|
305 | - } |
|
306 | - $this->objects = $ret; |
|
307 | - } |
|
308 | - |
|
309 | - return $this->objects; |
|
310 | - } |
|
267 | + public $objects = false; |
|
268 | + |
|
269 | + /** |
|
270 | + * SmartobjectCustomtagHandler constructor. |
|
271 | + * @param XoopsDatabase $db |
|
272 | + */ |
|
273 | + public function __construct(XoopsDatabase $db) |
|
274 | + { |
|
275 | + parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
276 | + $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @return array|bool |
|
281 | + */ |
|
282 | + public function getCustomtagsByName() |
|
283 | + { |
|
284 | + if (!$this->objects) { |
|
285 | + global $xoopsConfig; |
|
286 | + |
|
287 | + $ret = array(); |
|
288 | + |
|
289 | + $criteria = new CriteriaCompo(); |
|
290 | + |
|
291 | + $criteria_language = new CriteriaCompo(); |
|
292 | + $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
293 | + $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
294 | + $criteria->add($criteria_language); |
|
295 | + |
|
296 | + $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
297 | + $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
298 | + |
|
299 | + if ($granted_ids && count($granted_ids) > 0) { |
|
300 | + $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
301 | + $customtagsObj = $this->getObjects($criteria, true); |
|
302 | + foreach ($customtagsObj as $customtagObj) { |
|
303 | + $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
304 | + } |
|
305 | + } |
|
306 | + $this->objects = $ret; |
|
307 | + } |
|
308 | + |
|
309 | + return $this->objects; |
|
310 | + } |
|
311 | 311 | } |
@@ -35,154 +35,154 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class SmartobjectLink extends SmartObject |
37 | 37 | { |
38 | - /** |
|
39 | - * SmartobjectLink constructor. |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
44 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
45 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
46 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
47 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
48 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
49 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
50 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
51 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
52 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
53 | - $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
54 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
55 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * returns a specific variable for the object in a proper format |
|
60 | - * |
|
61 | - * @access public |
|
62 | - * @param string $key key of the object's variable to be returned |
|
63 | - * @param string $format format to use for the output |
|
64 | - * @return mixed formatted value of the variable |
|
65 | - */ |
|
66 | - public function getVar($key, $format = 's') |
|
67 | - { |
|
68 | - if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
69 | - // return call_user_func(array($this, $key)); |
|
70 | - return $this->{$key}(); |
|
71 | - } |
|
72 | - |
|
73 | - return parent::getVar($key, $format); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function from_uid() |
|
80 | - { |
|
81 | - $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
82 | - |
|
83 | - return $ret; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param bool $withContact |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function to_uid($withContact = false) |
|
91 | - { |
|
92 | - $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
93 | - |
|
94 | - return $ret; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function date() |
|
101 | - { |
|
102 | - $ret = formatTimestamp($this->getVar('date', 'e')); |
|
103 | - |
|
104 | - return $ret; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param bool $full |
|
109 | - * @return mixed|string |
|
110 | - */ |
|
111 | - public function link($full = false) |
|
112 | - { |
|
113 | - $ret = $this->getVar('link', 'e'); |
|
114 | - if ($full) { |
|
115 | - $myts = MyTextSanitizer::getInstance(); |
|
116 | - $ret = $myts->displayTarea($ret); |
|
117 | - |
|
118 | - return $ret; |
|
119 | - } else { |
|
120 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
121 | - |
|
122 | - return $ret; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getViewItemLink() |
|
130 | - { |
|
131 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
132 | - |
|
133 | - return $ret; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function getFromInfo() |
|
140 | - { |
|
141 | - // check if from_uid represent a user |
|
142 | - |
|
143 | - if ($this->getVar('from_uid')) { |
|
144 | - $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
145 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
146 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
147 | - } |
|
148 | - } else { |
|
149 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
150 | - } |
|
151 | - |
|
152 | - return $user; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @return array |
|
157 | - */ |
|
158 | - public function toArray() |
|
159 | - { |
|
160 | - $ret = parent::toArray(); |
|
161 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
162 | - $ret['toInfo'] = $this->getToInfo(); |
|
163 | - $ret['fullLink'] = $this->link(true); |
|
164 | - |
|
165 | - return $ret; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function getToInfo() |
|
172 | - { |
|
173 | - // check if from_uid represent a user |
|
174 | - |
|
175 | - if ($this->getVar('to_uid')) { |
|
176 | - $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
177 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
178 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
179 | - } |
|
180 | - } else { |
|
181 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
182 | - } |
|
183 | - |
|
184 | - return $user; |
|
185 | - } |
|
38 | + /** |
|
39 | + * SmartobjectLink constructor. |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
44 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
45 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
46 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
47 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
48 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
49 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
50 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
51 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
52 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
53 | + $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
54 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
55 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * returns a specific variable for the object in a proper format |
|
60 | + * |
|
61 | + * @access public |
|
62 | + * @param string $key key of the object's variable to be returned |
|
63 | + * @param string $format format to use for the output |
|
64 | + * @return mixed formatted value of the variable |
|
65 | + */ |
|
66 | + public function getVar($key, $format = 's') |
|
67 | + { |
|
68 | + if ($format === 's' && in_array($key, array('from_uid', 'to_uid', 'date', 'link'))) { |
|
69 | + // return call_user_func(array($this, $key)); |
|
70 | + return $this->{$key}(); |
|
71 | + } |
|
72 | + |
|
73 | + return parent::getVar($key, $format); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function from_uid() |
|
80 | + { |
|
81 | + $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
82 | + |
|
83 | + return $ret; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param bool $withContact |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function to_uid($withContact = false) |
|
91 | + { |
|
92 | + $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
93 | + |
|
94 | + return $ret; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function date() |
|
101 | + { |
|
102 | + $ret = formatTimestamp($this->getVar('date', 'e')); |
|
103 | + |
|
104 | + return $ret; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param bool $full |
|
109 | + * @return mixed|string |
|
110 | + */ |
|
111 | + public function link($full = false) |
|
112 | + { |
|
113 | + $ret = $this->getVar('link', 'e'); |
|
114 | + if ($full) { |
|
115 | + $myts = MyTextSanitizer::getInstance(); |
|
116 | + $ret = $myts->displayTarea($ret); |
|
117 | + |
|
118 | + return $ret; |
|
119 | + } else { |
|
120 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
121 | + |
|
122 | + return $ret; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getViewItemLink() |
|
130 | + { |
|
131 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
132 | + |
|
133 | + return $ret; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function getFromInfo() |
|
140 | + { |
|
141 | + // check if from_uid represent a user |
|
142 | + |
|
143 | + if ($this->getVar('from_uid')) { |
|
144 | + $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
145 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
146 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
147 | + } |
|
148 | + } else { |
|
149 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
150 | + } |
|
151 | + |
|
152 | + return $user; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @return array |
|
157 | + */ |
|
158 | + public function toArray() |
|
159 | + { |
|
160 | + $ret = parent::toArray(); |
|
161 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
162 | + $ret['toInfo'] = $this->getToInfo(); |
|
163 | + $ret['fullLink'] = $this->link(true); |
|
164 | + |
|
165 | + return $ret; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function getToInfo() |
|
172 | + { |
|
173 | + // check if from_uid represent a user |
|
174 | + |
|
175 | + if ($this->getVar('to_uid')) { |
|
176 | + $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
177 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
178 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
179 | + } |
|
180 | + } else { |
|
181 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
182 | + } |
|
183 | + |
|
184 | + return $user; |
|
185 | + } |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | */ |
191 | 191 | class SmartobjectLinkHandler extends SmartPersistableObjectHandler |
192 | 192 | { |
193 | - /** |
|
194 | - * SmartobjectLinkHandler constructor. |
|
195 | - * @param XoopsDatabase $db |
|
196 | - */ |
|
197 | - public function __construct(XoopsDatabase $db) |
|
198 | - { |
|
199 | - parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
200 | - } |
|
193 | + /** |
|
194 | + * SmartobjectLinkHandler constructor. |
|
195 | + * @param XoopsDatabase $db |
|
196 | + */ |
|
197 | + public function __construct(XoopsDatabase $db) |
|
198 | + { |
|
199 | + parent::__construct($db, 'link', 'linkid', 'subject', 'body', 'smartobject'); |
|
200 | + } |
|
201 | 201 | } |
@@ -20,39 +20,39 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class SmartObjectRow |
22 | 22 | { |
23 | - public $_keyname; |
|
24 | - public $_align; |
|
25 | - public $_customMethodForValue; |
|
26 | - public $_header; |
|
27 | - public $_class; |
|
23 | + public $_keyname; |
|
24 | + public $_align; |
|
25 | + public $_customMethodForValue; |
|
26 | + public $_header; |
|
27 | + public $_class; |
|
28 | 28 | |
29 | - /** |
|
30 | - * SmartObjectRow constructor. |
|
31 | - * @param $keyname |
|
32 | - * @param bool $customMethodForValue |
|
33 | - * @param bool $header |
|
34 | - * @param bool $class |
|
35 | - */ |
|
36 | - public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false) |
|
37 | - { |
|
38 | - $this->_keyname = $keyname; |
|
39 | - $this->_customMethodForValue = $customMethodForValue; |
|
40 | - $this->_header = $header; |
|
41 | - $this->_class = $class; |
|
42 | - } |
|
29 | + /** |
|
30 | + * SmartObjectRow constructor. |
|
31 | + * @param $keyname |
|
32 | + * @param bool $customMethodForValue |
|
33 | + * @param bool $header |
|
34 | + * @param bool $class |
|
35 | + */ |
|
36 | + public function __construct($keyname, $customMethodForValue = false, $header = false, $class = false) |
|
37 | + { |
|
38 | + $this->_keyname = $keyname; |
|
39 | + $this->_customMethodForValue = $customMethodForValue; |
|
40 | + $this->_header = $header; |
|
41 | + $this->_class = $class; |
|
42 | + } |
|
43 | 43 | |
44 | - public function getKeyName() |
|
45 | - { |
|
46 | - return $this->_keyname; |
|
47 | - } |
|
44 | + public function getKeyName() |
|
45 | + { |
|
46 | + return $this->_keyname; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public function isHeader() |
|
53 | - { |
|
54 | - return $this->_header; |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public function isHeader() |
|
53 | + { |
|
54 | + return $this->_header; |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -66,94 +66,94 @@ discard block |
||
66 | 66 | */ |
67 | 67 | class SmartObjectSingleView |
68 | 68 | { |
69 | - public $_object; |
|
70 | - public $_userSide; |
|
71 | - public $_tpl; |
|
72 | - public $_rows; |
|
73 | - public $_actions; |
|
74 | - public $_headerAsRow = true; |
|
69 | + public $_object; |
|
70 | + public $_userSide; |
|
71 | + public $_tpl; |
|
72 | + public $_rows; |
|
73 | + public $_actions; |
|
74 | + public $_headerAsRow = true; |
|
75 | 75 | |
76 | - /** |
|
77 | - * Constructor |
|
78 | - * @param $object |
|
79 | - * @param bool $userSide |
|
80 | - * @param array $actions |
|
81 | - * @param bool $headerAsRow |
|
82 | - */ |
|
83 | - public function __construct($object, $userSide = false, $actions = array(), $headerAsRow = true) |
|
84 | - { |
|
85 | - $this->_object = $object; |
|
86 | - $this->_userSide = $userSide; |
|
87 | - $this->_actions = $actions; |
|
88 | - $this->_headerAsRow = $headerAsRow; |
|
89 | - } |
|
76 | + /** |
|
77 | + * Constructor |
|
78 | + * @param $object |
|
79 | + * @param bool $userSide |
|
80 | + * @param array $actions |
|
81 | + * @param bool $headerAsRow |
|
82 | + */ |
|
83 | + public function __construct($object, $userSide = false, $actions = array(), $headerAsRow = true) |
|
84 | + { |
|
85 | + $this->_object = $object; |
|
86 | + $this->_userSide = $userSide; |
|
87 | + $this->_actions = $actions; |
|
88 | + $this->_headerAsRow = $headerAsRow; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param $rowObj |
|
93 | - */ |
|
94 | - public function addRow($rowObj) |
|
95 | - { |
|
96 | - $this->_rows[] = $rowObj; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @param $rowObj |
|
93 | + */ |
|
94 | + public function addRow($rowObj) |
|
95 | + { |
|
96 | + $this->_rows[] = $rowObj; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param bool $fetchOnly |
|
101 | - * @param bool $debug |
|
102 | - * @return mixed|string|void |
|
103 | - */ |
|
104 | - public function render($fetchOnly = false, $debug = false) |
|
105 | - { |
|
106 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
99 | + /** |
|
100 | + * @param bool $fetchOnly |
|
101 | + * @param bool $debug |
|
102 | + * @return mixed|string|void |
|
103 | + */ |
|
104 | + public function render($fetchOnly = false, $debug = false) |
|
105 | + { |
|
106 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
107 | 107 | |
108 | - $this->_tpl = new XoopsTpl(); |
|
109 | - $vars = $this->_object->vars; |
|
110 | - $smartobjectObjectArray = array(); |
|
108 | + $this->_tpl = new XoopsTpl(); |
|
109 | + $vars = $this->_object->vars; |
|
110 | + $smartobjectObjectArray = array(); |
|
111 | 111 | |
112 | - foreach ($this->_rows as $row) { |
|
113 | - $key = $row->getKeyName(); |
|
114 | - if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
115 | - $method = $row->_customMethodForValue; |
|
116 | - $value = $this->_object->$method(); |
|
117 | - } else { |
|
118 | - $value = $this->_object->getVar($row->getKeyName()); |
|
119 | - } |
|
120 | - if ($row->isHeader()) { |
|
121 | - $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
122 | - $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
123 | - } else { |
|
124 | - $smartobjectObjectArray[$key]['value'] = $value; |
|
125 | - $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
126 | - $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
127 | - } |
|
128 | - } |
|
129 | - $action_row = ''; |
|
130 | - if (in_array('edit', $this->_actions)) { |
|
131 | - $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
132 | - } |
|
133 | - if (in_array('delete', $this->_actions)) { |
|
134 | - $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
135 | - } |
|
136 | - if ($action_row) { |
|
137 | - $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
138 | - $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
139 | - } |
|
112 | + foreach ($this->_rows as $row) { |
|
113 | + $key = $row->getKeyName(); |
|
114 | + if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) { |
|
115 | + $method = $row->_customMethodForValue; |
|
116 | + $value = $this->_object->$method(); |
|
117 | + } else { |
|
118 | + $value = $this->_object->getVar($row->getKeyName()); |
|
119 | + } |
|
120 | + if ($row->isHeader()) { |
|
121 | + $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']); |
|
122 | + $this->_tpl->assign('smartobject_single_view_header_value', $value); |
|
123 | + } else { |
|
124 | + $smartobjectObjectArray[$key]['value'] = $value; |
|
125 | + $smartobjectObjectArray[$key]['header'] = $row->isHeader(); |
|
126 | + $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption']; |
|
127 | + } |
|
128 | + } |
|
129 | + $action_row = ''; |
|
130 | + if (in_array('edit', $this->_actions)) { |
|
131 | + $action_row .= $this->_object->getEditItemLink(false, true, true); |
|
132 | + } |
|
133 | + if (in_array('delete', $this->_actions)) { |
|
134 | + $action_row .= $this->_object->getDeleteItemLink(false, true, true); |
|
135 | + } |
|
136 | + if ($action_row) { |
|
137 | + $smartobjectObjectArray['zaction']['value'] = $action_row; |
|
138 | + $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS; |
|
139 | + } |
|
140 | 140 | |
141 | - $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
142 | - $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
141 | + $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow); |
|
142 | + $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray); |
|
143 | 143 | |
144 | - if ($fetchOnly) { |
|
145 | - return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
146 | - } else { |
|
147 | - $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
148 | - } |
|
149 | - } |
|
144 | + if ($fetchOnly) { |
|
145 | + return $this->_tpl->fetch('db:smartobject_singleview_display.tpl'); |
|
146 | + } else { |
|
147 | + $this->_tpl->display('db:smartobject_singleview_display.tpl'); |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @param bool $debug |
|
153 | - * @return mixed|string|void |
|
154 | - */ |
|
155 | - public function fetch($debug = false) |
|
156 | - { |
|
157 | - return $this->render(true, $debug); |
|
158 | - } |
|
151 | + /** |
|
152 | + * @param bool $debug |
|
153 | + * @return mixed|string|void |
|
154 | + */ |
|
155 | + public function fetch($debug = false) |
|
156 | + { |
|
157 | + return $this->render(true, $debug); |
|
158 | + } |
|
159 | 159 | } |
@@ -6,44 +6,44 @@ |
||
6 | 6 | */ |
7 | 7 | class SmartHookHandler |
8 | 8 | { |
9 | - /** |
|
10 | - * SmartHookHandler constructor. |
|
11 | - */ |
|
12 | - public function __construct() |
|
13 | - { |
|
14 | - } |
|
9 | + /** |
|
10 | + * SmartHookHandler constructor. |
|
11 | + */ |
|
12 | + public function __construct() |
|
13 | + { |
|
14 | + } |
|
15 | 15 | |
16 | - /** |
|
17 | - * Access the only instance of this class |
|
18 | - * |
|
19 | - * @return XoopsObject |
|
20 | - * |
|
21 | - * @static |
|
22 | - * @staticvar object |
|
23 | - */ |
|
24 | - public static function getInstance() |
|
25 | - { |
|
26 | - static $instance; |
|
27 | - if (null === $instance) { |
|
28 | - $instance = new static(); |
|
29 | - } |
|
16 | + /** |
|
17 | + * Access the only instance of this class |
|
18 | + * |
|
19 | + * @return XoopsObject |
|
20 | + * |
|
21 | + * @static |
|
22 | + * @staticvar object |
|
23 | + */ |
|
24 | + public static function getInstance() |
|
25 | + { |
|
26 | + static $instance; |
|
27 | + if (null === $instance) { |
|
28 | + $instance = new static(); |
|
29 | + } |
|
30 | 30 | |
31 | - return $instance; |
|
32 | - } |
|
31 | + return $instance; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param $hook_name |
|
36 | - */ |
|
37 | - public function executeHook($hook_name) |
|
38 | - { |
|
39 | - $lower_hook_name = strtolower($hook_name); |
|
40 | - $filename = SMARTOBJECT_ROOT_PATH . 'include/custom_code/' . $lower_hook_name . '.php'; |
|
41 | - if (file_exists($filename)) { |
|
42 | - require_once $filename; |
|
43 | - $function = 'smarthook_' . $lower_hook_name; |
|
44 | - if (function_exists($function)) { |
|
45 | - $function(); |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
34 | + /** |
|
35 | + * @param $hook_name |
|
36 | + */ |
|
37 | + public function executeHook($hook_name) |
|
38 | + { |
|
39 | + $lower_hook_name = strtolower($hook_name); |
|
40 | + $filename = SMARTOBJECT_ROOT_PATH . 'include/custom_code/' . $lower_hook_name . '.php'; |
|
41 | + if (file_exists($filename)) { |
|
42 | + require_once $filename; |
|
43 | + $function = 'smarthook_' . $lower_hook_name; |
|
44 | + if (function_exists($function)) { |
|
45 | + $function(); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -34,227 +34,227 @@ |
||
34 | 34 | */ |
35 | 35 | class SmartobjectMemberHandler extends XoopsMemberHandler |
36 | 36 | { |
37 | - /** |
|
38 | - * constructor |
|
39 | - * @param XoopsDatabase $db |
|
40 | - */ |
|
41 | - public function __construct(XoopsDatabase $db) |
|
42 | - { |
|
43 | - parent::__construct($db); |
|
44 | - $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
45 | - } |
|
37 | + /** |
|
38 | + * constructor |
|
39 | + * @param XoopsDatabase $db |
|
40 | + */ |
|
41 | + public function __construct(XoopsDatabase $db) |
|
42 | + { |
|
43 | + parent::__construct($db); |
|
44 | + $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param $userObj |
|
49 | - * @param bool $groups |
|
50 | - * @param bool $notifyUser |
|
51 | - * @param bool $password |
|
52 | - * @return bool |
|
53 | - */ |
|
54 | - public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
55 | - { |
|
56 | - $email = $userObj->getVar('email'); |
|
57 | - if (!$userObj->getVar('email') || $email === '') { |
|
58 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
47 | + /** |
|
48 | + * @param $userObj |
|
49 | + * @param bool $groups |
|
50 | + * @param bool $notifyUser |
|
51 | + * @param bool $password |
|
52 | + * @return bool |
|
53 | + */ |
|
54 | + public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
55 | + { |
|
56 | + $email = $userObj->getVar('email'); |
|
57 | + if (!$userObj->getVar('email') || $email === '') { |
|
58 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
59 | 59 | |
60 | - return false; |
|
61 | - } |
|
60 | + return false; |
|
61 | + } |
|
62 | 62 | |
63 | - $password = $userObj->getVar('pass'); |
|
64 | - // randomly generating the password if not already set |
|
65 | - if ('' === $password) { |
|
66 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
67 | - } |
|
68 | - $userObj->setVar('pass', md5($password)); |
|
63 | + $password = $userObj->getVar('pass'); |
|
64 | + // randomly generating the password if not already set |
|
65 | + if ('' === $password) { |
|
66 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
67 | + } |
|
68 | + $userObj->setVar('pass', md5($password)); |
|
69 | 69 | |
70 | - // if no username is set, let's generate one |
|
71 | - $unamecount = 20; |
|
72 | - $uname = $userObj->getVar('uname'); |
|
73 | - if (!$uname || $uname === '') { |
|
74 | - $usernames = $this->genUserNames($email, $unamecount); |
|
75 | - $newuser = false; |
|
76 | - $i = 0; |
|
77 | - while ($newuser === false) { |
|
78 | - $crit = new Criteria('uname', $usernames[$i]); |
|
79 | - $count = $this->getUserCount($crit); |
|
80 | - if ($count == 0) { |
|
81 | - $newuser = true; |
|
82 | - } else { |
|
83 | - //Move to next username |
|
84 | - ++$i; |
|
85 | - if ($i == $unamecount) { |
|
86 | - //Get next batch of usernames to try, reset counter |
|
87 | - $usernames = $this->genUserNames($email, $unamecount); |
|
88 | - $i = 0; |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
92 | - } |
|
70 | + // if no username is set, let's generate one |
|
71 | + $unamecount = 20; |
|
72 | + $uname = $userObj->getVar('uname'); |
|
73 | + if (!$uname || $uname === '') { |
|
74 | + $usernames = $this->genUserNames($email, $unamecount); |
|
75 | + $newuser = false; |
|
76 | + $i = 0; |
|
77 | + while ($newuser === false) { |
|
78 | + $crit = new Criteria('uname', $usernames[$i]); |
|
79 | + $count = $this->getUserCount($crit); |
|
80 | + if ($count == 0) { |
|
81 | + $newuser = true; |
|
82 | + } else { |
|
83 | + //Move to next username |
|
84 | + ++$i; |
|
85 | + if ($i == $unamecount) { |
|
86 | + //Get next batch of usernames to try, reset counter |
|
87 | + $usernames = $this->genUserNames($email, $unamecount); |
|
88 | + $i = 0; |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - global $xoopsConfig; |
|
94 | + global $xoopsConfig; |
|
95 | 95 | |
96 | - $configHandler = xoops_getHandler('config'); |
|
97 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
98 | - switch ($xoopsConfigUser['activation_type']) { |
|
99 | - case 0: |
|
100 | - $level = 0; |
|
101 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
102 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
103 | - break; |
|
104 | - case 1: |
|
105 | - $level = 1; |
|
106 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
107 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
108 | - break; |
|
109 | - case 2: |
|
110 | - default: |
|
111 | - $level = 0; |
|
112 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
113 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
114 | - } |
|
96 | + $configHandler = xoops_getHandler('config'); |
|
97 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
98 | + switch ($xoopsConfigUser['activation_type']) { |
|
99 | + case 0: |
|
100 | + $level = 0; |
|
101 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
102 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
103 | + break; |
|
104 | + case 1: |
|
105 | + $level = 1; |
|
106 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
107 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
108 | + break; |
|
109 | + case 2: |
|
110 | + default: |
|
111 | + $level = 0; |
|
112 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
113 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
114 | + } |
|
115 | 115 | |
116 | - $userObj->setVar('uname', $usernames[$i]); |
|
117 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
118 | - $userObj->setVar('user_regdate', time()); |
|
119 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
120 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
121 | - $userObj->setVar('actkey', $actkey); |
|
122 | - $userObj->setVar('email', $email); |
|
123 | - $userObj->setVar('notify_method', 2); |
|
124 | - $userObj->setVar('level', $userObj); |
|
116 | + $userObj->setVar('uname', $usernames[$i]); |
|
117 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
118 | + $userObj->setVar('user_regdate', time()); |
|
119 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
120 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
121 | + $userObj->setVar('actkey', $actkey); |
|
122 | + $userObj->setVar('email', $email); |
|
123 | + $userObj->setVar('notify_method', 2); |
|
124 | + $userObj->setVar('level', $userObj); |
|
125 | 125 | |
126 | - if ($this->insertUser($userObj)) { |
|
126 | + if ($this->insertUser($userObj)) { |
|
127 | 127 | |
128 | - // if $groups=false, Add the user to Registered Users group |
|
129 | - if (!$groups) { |
|
130 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
131 | - } else { |
|
132 | - foreach ($groups as $groupid) { |
|
133 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
134 | - } |
|
135 | - } |
|
136 | - } else { |
|
137 | - return false; |
|
138 | - } |
|
128 | + // if $groups=false, Add the user to Registered Users group |
|
129 | + if (!$groups) { |
|
130 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
131 | + } else { |
|
132 | + foreach ($groups as $groupid) { |
|
133 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
134 | + } |
|
135 | + } |
|
136 | + } else { |
|
137 | + return false; |
|
138 | + } |
|
139 | 139 | |
140 | - if ($notifyUser) { |
|
141 | - // send some notifications |
|
142 | - $xoopsMailer = xoops_getMailer(); |
|
143 | - $xoopsMailer->useMail(); |
|
144 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
145 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
146 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
147 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
148 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
149 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
150 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
151 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
152 | - $xoopsMailer->setToUsers($userObj); |
|
153 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
154 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
155 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
140 | + if ($notifyUser) { |
|
141 | + // send some notifications |
|
142 | + $xoopsMailer = xoops_getMailer(); |
|
143 | + $xoopsMailer->useMail(); |
|
144 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
145 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
146 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
147 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
148 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
149 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
150 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
151 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
152 | + $xoopsMailer->setToUsers($userObj); |
|
153 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
154 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
155 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
156 | 156 | |
157 | - if (!$xoopsMailer->send(true)) { |
|
158 | - /** |
|
159 | - * @todo trap error if email was not sent |
|
160 | - */ |
|
161 | - $xoopsMailer->getErrors(true); |
|
162 | - } |
|
163 | - } |
|
157 | + if (!$xoopsMailer->send(true)) { |
|
158 | + /** |
|
159 | + * @todo trap error if email was not sent |
|
160 | + */ |
|
161 | + $xoopsMailer->getErrors(true); |
|
162 | + } |
|
163 | + } |
|
164 | 164 | |
165 | - return true; |
|
166 | - } |
|
165 | + return true; |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Generates an array of usernames |
|
170 | - * |
|
171 | - * @param string $email email of user |
|
172 | - * @param int $count number of names to generate |
|
173 | - * @return array $names |
|
174 | - * @internal param string $name name of user |
|
175 | - * @author xHelp Team |
|
176 | - * |
|
177 | - * @access public |
|
178 | - */ |
|
179 | - public function genUserNames($email, $count = 20) |
|
180 | - { |
|
181 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
168 | + /** |
|
169 | + * Generates an array of usernames |
|
170 | + * |
|
171 | + * @param string $email email of user |
|
172 | + * @param int $count number of names to generate |
|
173 | + * @return array $names |
|
174 | + * @internal param string $name name of user |
|
175 | + * @author xHelp Team |
|
176 | + * |
|
177 | + * @access public |
|
178 | + */ |
|
179 | + public function genUserNames($email, $count = 20) |
|
180 | + { |
|
181 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
182 | 182 | |
183 | - $names = array(); |
|
184 | - $userid = explode('@', $email); |
|
183 | + $names = array(); |
|
184 | + $userid = explode('@', $email); |
|
185 | 185 | |
186 | - $basename = ''; |
|
187 | - $hasbasename = false; |
|
188 | - $emailname = $userid[0]; |
|
186 | + $basename = ''; |
|
187 | + $hasbasename = false; |
|
188 | + $emailname = $userid[0]; |
|
189 | 189 | |
190 | - $names[] = $emailname; |
|
190 | + $names[] = $emailname; |
|
191 | 191 | |
192 | - if (strlen($name) > 0) { |
|
193 | - $name = explode(' ', trim($name)); |
|
194 | - if (count($name) > 1) { |
|
195 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
196 | - } else { |
|
197 | - $basename = strtolower($name[0]); |
|
198 | - } |
|
199 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
200 | - //Prevent Duplication of Email Username and Name |
|
201 | - if (!in_array($basename, $names)) { |
|
202 | - $names[] = $basename; |
|
203 | - $hasbasename = true; |
|
204 | - } |
|
205 | - } |
|
192 | + if (strlen($name) > 0) { |
|
193 | + $name = explode(' ', trim($name)); |
|
194 | + if (count($name) > 1) { |
|
195 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
196 | + } else { |
|
197 | + $basename = strtolower($name[0]); |
|
198 | + } |
|
199 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
200 | + //Prevent Duplication of Email Username and Name |
|
201 | + if (!in_array($basename, $names)) { |
|
202 | + $names[] = $basename; |
|
203 | + $hasbasename = true; |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - $i = count($names); |
|
208 | - $onbasename = 1; |
|
209 | - while ($i < $count) { |
|
210 | - $num = $this->genRandNumber(); |
|
211 | - if ($onbasename < 0 && $hasbasename) { |
|
212 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
213 | - } else { |
|
214 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
215 | - } |
|
216 | - $i = count($names); |
|
217 | - $onbasename = ~$onbasename; |
|
218 | - $num = ''; |
|
219 | - } |
|
207 | + $i = count($names); |
|
208 | + $onbasename = 1; |
|
209 | + while ($i < $count) { |
|
210 | + $num = $this->genRandNumber(); |
|
211 | + if ($onbasename < 0 && $hasbasename) { |
|
212 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
213 | + } else { |
|
214 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
215 | + } |
|
216 | + $i = count($names); |
|
217 | + $onbasename = ~$onbasename; |
|
218 | + $num = ''; |
|
219 | + } |
|
220 | 220 | |
221 | - return $names; |
|
222 | - } |
|
221 | + return $names; |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Creates a random number with a specified number of $digits |
|
226 | - * |
|
227 | - * @param int $digits number of digits |
|
228 | - * @return return int random number |
|
229 | - * @author xHelp Team |
|
230 | - * |
|
231 | - * @access public |
|
232 | - */ |
|
233 | - public function genRandNumber($digits = 2) |
|
234 | - { |
|
235 | - $this->initRand(); |
|
236 | - $tmp = array(); |
|
224 | + /** |
|
225 | + * Creates a random number with a specified number of $digits |
|
226 | + * |
|
227 | + * @param int $digits number of digits |
|
228 | + * @return return int random number |
|
229 | + * @author xHelp Team |
|
230 | + * |
|
231 | + * @access public |
|
232 | + */ |
|
233 | + public function genRandNumber($digits = 2) |
|
234 | + { |
|
235 | + $this->initRand(); |
|
236 | + $tmp = array(); |
|
237 | 237 | |
238 | - for ($i = 0; $i < $digits; ++$i) { |
|
239 | - $tmp[$i] = (mt_rand() % 9); |
|
240 | - } |
|
238 | + for ($i = 0; $i < $digits; ++$i) { |
|
239 | + $tmp[$i] = (mt_rand() % 9); |
|
240 | + } |
|
241 | 241 | |
242 | - return implode('', $tmp); |
|
243 | - } |
|
242 | + return implode('', $tmp); |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * Gives the random number generator a seed to start from |
|
247 | - * |
|
248 | - * @return void |
|
249 | - * |
|
250 | - * @access public |
|
251 | - */ |
|
252 | - public function initRand() |
|
253 | - { |
|
254 | - static $randCalled = false; |
|
255 | - if (!$randCalled) { |
|
256 | - mt_srand((double)microtime() * 1000000); |
|
257 | - $randCalled = true; |
|
258 | - } |
|
259 | - } |
|
245 | + /** |
|
246 | + * Gives the random number generator a seed to start from |
|
247 | + * |
|
248 | + * @return void |
|
249 | + * |
|
250 | + * @access public |
|
251 | + */ |
|
252 | + public function initRand() |
|
253 | + { |
|
254 | + static $randCalled = false; |
|
255 | + if (!$randCalled) { |
|
256 | + mt_srand((double)microtime() * 1000000); |
|
257 | + $randCalled = true; |
|
258 | + } |
|
259 | + } |
|
260 | 260 | } |
@@ -18,123 +18,123 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class SmartobjectCategory extends SmartSeoObject |
20 | 20 | { |
21 | - public $_categoryPath; |
|
22 | - |
|
23 | - /** |
|
24 | - * SmartobjectCategory constructor. |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
29 | - $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
30 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
31 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
32 | - $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
33 | - |
|
34 | - $this->initCommonVar('doxcode'); |
|
35 | - |
|
36 | - $this->setControl('image', array('name' => 'image')); |
|
37 | - $this->setControl('parentid', array('name' => 'parentcategory')); |
|
38 | - $this->setControl('description', array( |
|
39 | - 'name' => 'textarea', |
|
40 | - 'itemHandler' => false, |
|
41 | - 'method' => false, |
|
42 | - 'module' => false, |
|
43 | - 'form_editor' => 'default' |
|
44 | - )); |
|
45 | - |
|
46 | - // call parent constructor to get SEO fields initiated |
|
47 | - parent::__construct(); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * returns a specific variable for the object in a proper format |
|
52 | - * |
|
53 | - * @access public |
|
54 | - * @param string $key key of the object's variable to be returned |
|
55 | - * @param string $format format to use for the output |
|
56 | - * @return mixed formatted value of the variable |
|
57 | - */ |
|
58 | - public function getVar($key, $format = 's') |
|
59 | - { |
|
60 | - if ($format === 's' && in_array($key, array('description', 'image'))) { |
|
61 | - // return call_user_func(array($this, $key)); |
|
62 | - return $this->{$key}(); |
|
63 | - } |
|
64 | - |
|
65 | - return parent::getVar($key, $format); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function description() |
|
72 | - { |
|
73 | - return $this->getValueFor('description', false); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return bool|mixed |
|
78 | - */ |
|
79 | - public function image() |
|
80 | - { |
|
81 | - $ret = $this->getVar('image', 'e'); |
|
82 | - if ($ret == '-1') { |
|
83 | - return false; |
|
84 | - } else { |
|
85 | - return $ret; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function toArray() |
|
93 | - { |
|
94 | - $this->setVar('doxcode', true); |
|
95 | - global $myts; |
|
96 | - $objectArray = parent::toArray(); |
|
97 | - if ($objectArray['image']) { |
|
98 | - $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
99 | - } |
|
100 | - |
|
101 | - return $objectArray; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Create the complete path of a category |
|
106 | - * |
|
107 | - * @todo this could be improved as it uses multiple queries |
|
108 | - * @param bool $withAllLink make all name clickable |
|
109 | - * @param bool $currentCategory |
|
110 | - * @return string complete path (breadcrumb) |
|
111 | - */ |
|
112 | - public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
113 | - { |
|
114 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
115 | - $controller = new SmartObjectController($this->handler); |
|
116 | - |
|
117 | - if (!$this->_categoryPath) { |
|
118 | - if ($withAllLink && !$currentCategory) { |
|
119 | - $ret = $controller->getItemLink($this); |
|
120 | - } else { |
|
121 | - $currentCategory = false; |
|
122 | - $ret = $this->getVar('name'); |
|
123 | - } |
|
124 | - $parentid = $this->getVar('parentid'); |
|
125 | - if ($parentid != 0) { |
|
126 | - $parentObj = $this->handler->get($parentid); |
|
127 | - if ($parentObj->isNew()) { |
|
128 | - exit; |
|
129 | - } |
|
130 | - $parentid = $parentObj->getVar('parentid'); |
|
131 | - $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
132 | - } |
|
133 | - $this->_categoryPath = $ret; |
|
134 | - } |
|
135 | - |
|
136 | - return $this->_categoryPath; |
|
137 | - } |
|
21 | + public $_categoryPath; |
|
22 | + |
|
23 | + /** |
|
24 | + * SmartobjectCategory constructor. |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
29 | + $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
30 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
31 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
32 | + $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
33 | + |
|
34 | + $this->initCommonVar('doxcode'); |
|
35 | + |
|
36 | + $this->setControl('image', array('name' => 'image')); |
|
37 | + $this->setControl('parentid', array('name' => 'parentcategory')); |
|
38 | + $this->setControl('description', array( |
|
39 | + 'name' => 'textarea', |
|
40 | + 'itemHandler' => false, |
|
41 | + 'method' => false, |
|
42 | + 'module' => false, |
|
43 | + 'form_editor' => 'default' |
|
44 | + )); |
|
45 | + |
|
46 | + // call parent constructor to get SEO fields initiated |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * returns a specific variable for the object in a proper format |
|
52 | + * |
|
53 | + * @access public |
|
54 | + * @param string $key key of the object's variable to be returned |
|
55 | + * @param string $format format to use for the output |
|
56 | + * @return mixed formatted value of the variable |
|
57 | + */ |
|
58 | + public function getVar($key, $format = 's') |
|
59 | + { |
|
60 | + if ($format === 's' && in_array($key, array('description', 'image'))) { |
|
61 | + // return call_user_func(array($this, $key)); |
|
62 | + return $this->{$key}(); |
|
63 | + } |
|
64 | + |
|
65 | + return parent::getVar($key, $format); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function description() |
|
72 | + { |
|
73 | + return $this->getValueFor('description', false); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return bool|mixed |
|
78 | + */ |
|
79 | + public function image() |
|
80 | + { |
|
81 | + $ret = $this->getVar('image', 'e'); |
|
82 | + if ($ret == '-1') { |
|
83 | + return false; |
|
84 | + } else { |
|
85 | + return $ret; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function toArray() |
|
93 | + { |
|
94 | + $this->setVar('doxcode', true); |
|
95 | + global $myts; |
|
96 | + $objectArray = parent::toArray(); |
|
97 | + if ($objectArray['image']) { |
|
98 | + $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
99 | + } |
|
100 | + |
|
101 | + return $objectArray; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Create the complete path of a category |
|
106 | + * |
|
107 | + * @todo this could be improved as it uses multiple queries |
|
108 | + * @param bool $withAllLink make all name clickable |
|
109 | + * @param bool $currentCategory |
|
110 | + * @return string complete path (breadcrumb) |
|
111 | + */ |
|
112 | + public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
113 | + { |
|
114 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
115 | + $controller = new SmartObjectController($this->handler); |
|
116 | + |
|
117 | + if (!$this->_categoryPath) { |
|
118 | + if ($withAllLink && !$currentCategory) { |
|
119 | + $ret = $controller->getItemLink($this); |
|
120 | + } else { |
|
121 | + $currentCategory = false; |
|
122 | + $ret = $this->getVar('name'); |
|
123 | + } |
|
124 | + $parentid = $this->getVar('parentid'); |
|
125 | + if ($parentid != 0) { |
|
126 | + $parentObj = $this->handler->get($parentid); |
|
127 | + if ($parentObj->isNew()) { |
|
128 | + exit; |
|
129 | + } |
|
130 | + $parentid = $parentObj->getVar('parentid'); |
|
131 | + $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
132 | + } |
|
133 | + $this->_categoryPath = $ret; |
|
134 | + } |
|
135 | + |
|
136 | + return $this->_categoryPath; |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,91 +142,91 @@ discard block |
||
142 | 142 | */ |
143 | 143 | class SmartobjectCategoryHandler extends SmartPersistableObjectHandler |
144 | 144 | { |
145 | - public $allCategoriesObj = false; |
|
146 | - public $_allCategoriesId = false; |
|
147 | - |
|
148 | - /** |
|
149 | - * SmartobjectCategoryHandler constructor. |
|
150 | - * @param XoopsDatabase $db |
|
151 | - * @param $modulename |
|
152 | - */ |
|
153 | - public function __construct(XoopsDatabase $db, $modulename) |
|
154 | - { |
|
155 | - parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param int $parentid |
|
160 | - * @param bool $perm_name |
|
161 | - * @param string $sort |
|
162 | - * @param string $order |
|
163 | - * @return array|bool |
|
164 | - */ |
|
165 | - public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC') |
|
166 | - { |
|
167 | - if (!$this->allCategoriesObj) { |
|
168 | - $criteria = new CriteriaCompo(); |
|
169 | - $criteria->setSort($sort); |
|
170 | - $criteria->setOrder($order); |
|
171 | - global $xoopsUser; |
|
172 | - $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin(); |
|
173 | - |
|
174 | - if ($perm_name && !$userIsAdmin) { |
|
175 | - if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) { |
|
176 | - return false; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - $this->allCategoriesObj = $this->getObjects($criteria, 'parentid'); |
|
181 | - } |
|
182 | - |
|
183 | - $ret = array(); |
|
184 | - if (isset($this->allCategoriesObj[$parentid])) { |
|
185 | - foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) { |
|
186 | - $ret[$categoryid]['self'] = $categoryObj->toArray(); |
|
187 | - if (isset($this->allCategoriesObj[$categoryid])) { |
|
188 | - $ret[$categoryid]['sub'] = $this->getAllCategoriesArray($categoryid); |
|
189 | - $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return $ret; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $parentid |
|
199 | - * @param bool $asString |
|
200 | - * @return array|string |
|
201 | - */ |
|
202 | - public function getParentIds($parentid, $asString = true) |
|
203 | - { |
|
204 | - if (!$this->allCategoriesId) { |
|
205 | - $ret = array(); |
|
206 | - $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid'; |
|
207 | - |
|
208 | - $result = $this->db->query($sql); |
|
209 | - |
|
210 | - if (!$result) { |
|
211 | - return $ret; |
|
212 | - } |
|
213 | - |
|
214 | - while ($myrow = $this->db->fetchArray($result)) { |
|
215 | - $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $retArray = array($parentid); |
|
220 | - while ($parentid != 0) { |
|
221 | - $parentid = $this->allCategoriesId[$parentid]; |
|
222 | - if ($parentid != 0) { |
|
223 | - $retArray[] = $parentid; |
|
224 | - } |
|
225 | - } |
|
226 | - if ($asString) { |
|
227 | - return implode(', ', $retArray); |
|
228 | - } else { |
|
229 | - return $retArray; |
|
230 | - } |
|
231 | - } |
|
145 | + public $allCategoriesObj = false; |
|
146 | + public $_allCategoriesId = false; |
|
147 | + |
|
148 | + /** |
|
149 | + * SmartobjectCategoryHandler constructor. |
|
150 | + * @param XoopsDatabase $db |
|
151 | + * @param $modulename |
|
152 | + */ |
|
153 | + public function __construct(XoopsDatabase $db, $modulename) |
|
154 | + { |
|
155 | + parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param int $parentid |
|
160 | + * @param bool $perm_name |
|
161 | + * @param string $sort |
|
162 | + * @param string $order |
|
163 | + * @return array|bool |
|
164 | + */ |
|
165 | + public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC') |
|
166 | + { |
|
167 | + if (!$this->allCategoriesObj) { |
|
168 | + $criteria = new CriteriaCompo(); |
|
169 | + $criteria->setSort($sort); |
|
170 | + $criteria->setOrder($order); |
|
171 | + global $xoopsUser; |
|
172 | + $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin(); |
|
173 | + |
|
174 | + if ($perm_name && !$userIsAdmin) { |
|
175 | + if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) { |
|
176 | + return false; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + $this->allCategoriesObj = $this->getObjects($criteria, 'parentid'); |
|
181 | + } |
|
182 | + |
|
183 | + $ret = array(); |
|
184 | + if (isset($this->allCategoriesObj[$parentid])) { |
|
185 | + foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) { |
|
186 | + $ret[$categoryid]['self'] = $categoryObj->toArray(); |
|
187 | + if (isset($this->allCategoriesObj[$categoryid])) { |
|
188 | + $ret[$categoryid]['sub'] = $this->getAllCategoriesArray($categoryid); |
|
189 | + $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return $ret; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $parentid |
|
199 | + * @param bool $asString |
|
200 | + * @return array|string |
|
201 | + */ |
|
202 | + public function getParentIds($parentid, $asString = true) |
|
203 | + { |
|
204 | + if (!$this->allCategoriesId) { |
|
205 | + $ret = array(); |
|
206 | + $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid'; |
|
207 | + |
|
208 | + $result = $this->db->query($sql); |
|
209 | + |
|
210 | + if (!$result) { |
|
211 | + return $ret; |
|
212 | + } |
|
213 | + |
|
214 | + while ($myrow = $this->db->fetchArray($result)) { |
|
215 | + $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $retArray = array($parentid); |
|
220 | + while ($parentid != 0) { |
|
221 | + $parentid = $this->allCategoriesId[$parentid]; |
|
222 | + if ($parentid != 0) { |
|
223 | + $retArray[] = $parentid; |
|
224 | + } |
|
225 | + } |
|
226 | + if ($asString) { |
|
227 | + return implode(', ', $retArray); |
|
228 | + } else { |
|
229 | + return $retArray; |
|
230 | + } |
|
231 | + } |
|
232 | 232 | } |