@@ -31,548 +31,548 @@ |
||
31 | 31 | */ |
32 | 32 | class SmartObjectController |
33 | 33 | { |
34 | - public $handler; |
|
35 | - |
|
36 | - /** |
|
37 | - * SmartObjectController constructor. |
|
38 | - * @param $handler |
|
39 | - */ |
|
40 | - public function __construct($handler) |
|
41 | - { |
|
42 | - $this->handler = $handler; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param $smartObj |
|
47 | - */ |
|
48 | - public function postDataToObject(&$smartObj) |
|
49 | - { |
|
50 | - foreach (array_keys($smartObj->vars) as $key) { |
|
51 | - switch ($smartObj->vars[$key]['data_type']) { |
|
52 | - case XOBJ_DTYPE_IMAGE: |
|
53 | - if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] !== '') { |
|
54 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
55 | - $smartObj->setVar($key, $_POST['url_' . $key]); |
|
56 | - if (file_exists($oldFile)) { |
|
57 | - unlink($oldFile); |
|
58 | - } |
|
59 | - } |
|
60 | - if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') { |
|
61 | - $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
62 | - $smartObj->setVar($key, ''); |
|
63 | - if (file_exists($oldFile)) { |
|
64 | - unlink($oldFile); |
|
65 | - } |
|
66 | - } |
|
67 | - break; |
|
68 | - |
|
69 | - case XOBJ_DTYPE_URLLINK: |
|
70 | - $linkObj = $smartObj->getUrlLinkObj($key); |
|
71 | - $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
72 | - $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
73 | - $linkObj->setVar('target', $_POST['target_' . $key]); |
|
74 | - $linkObj->setVar('url', $_POST['url_' . $key]); |
|
75 | - if ($linkObj->getVar('url') !== '') { |
|
76 | - $smartObj->storeUrlLinkObj($linkObj); |
|
77 | - } |
|
78 | - //todo: catch errors |
|
79 | - $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
80 | - break; |
|
81 | - |
|
82 | - case XOBJ_DTYPE_FILE: |
|
83 | - if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] === '') { |
|
84 | - $fileObj = $smartObj->getFileObj($key); |
|
85 | - $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
86 | - $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
87 | - $fileObj->setVar('url', $_POST['url_' . $key]); |
|
88 | - if (!($fileObj->getVar('url') === '' && $fileObj->getVar('url') === '' && $fileObj->getVar('url') === '')) { |
|
89 | - $res = $smartObj->storeFileObj($fileObj); |
|
90 | - if ($res) { |
|
91 | - $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
92 | - } else { |
|
93 | - //error setted, but no error message (to be improved) |
|
94 | - $smartObj->setErrors($fileObj->getErrors()); |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - break; |
|
99 | - |
|
100 | - case XOBJ_DTYPE_STIME: |
|
101 | - case XOBJ_DTYPE_MTIME: |
|
102 | - case XOBJ_DTYPE_LTIME: |
|
103 | - // check if this field's value is available in the POST array |
|
104 | - if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
105 | - $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
106 | - } else { |
|
107 | - $value = strtotime($_POST[$key]); |
|
108 | - //if strtotime returns false, the value is already a time stamp |
|
109 | - if (!$value) { |
|
110 | - $value = (int)$_POST[$key]; |
|
111 | - } |
|
112 | - } |
|
113 | - $smartObj->setVar($key, $value); |
|
114 | - |
|
115 | - break; |
|
116 | - |
|
117 | - default: |
|
118 | - $smartObj->setVar($key, $_POST[$key]); |
|
119 | - break; |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param $smartObj |
|
126 | - * @param $objectid |
|
127 | - * @param $created_success_msg |
|
128 | - * @param $modified_success_msg |
|
129 | - * @param bool $redirect_page |
|
130 | - * @param bool $debug |
|
131 | - * @return mixed |
|
132 | - */ |
|
133 | - public function doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false) |
|
134 | - { |
|
135 | - global $smart_previous_page; |
|
136 | - |
|
137 | - $this->postDataToObject($smartObj); |
|
138 | - |
|
139 | - if ($smartObj->isNew()) { |
|
140 | - $redirect_msg = $created_success_msg; |
|
141 | - } else { |
|
142 | - $redirect_msg = $modified_success_msg; |
|
143 | - } |
|
144 | - |
|
145 | - // Check if there were uploaded files |
|
146 | - if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
147 | - include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php'; |
|
148 | - $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
149 | - foreach ($_FILES as $name => $file_array) { |
|
150 | - if (isset($file_array['name']) && $file_array['name'] !== '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
151 | - if ($uploaderObj->fetchMedia($name)) { |
|
152 | - $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
153 | - if ($uploaderObj->upload()) { |
|
154 | - // Find the related field in the SmartObject |
|
155 | - $related_field = str_replace('upload_', '', $name); |
|
156 | - $uploadedArray[] = $related_field; |
|
157 | - //si c'est un fichier Rich |
|
158 | - if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) { |
|
159 | - $object_fileurl = $smartObj->getUploadDir(); |
|
160 | - $fileObj = $smartObj->getFileObj($related_field); |
|
161 | - $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
162 | - $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
163 | - $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
164 | - $smartObj->storeFileObj($fileObj); |
|
165 | - //todo: catch errors |
|
166 | - $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
167 | - } else { |
|
168 | - $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
169 | - unlink($old_file); |
|
170 | - $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
171 | - } |
|
172 | - } else { |
|
173 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
174 | - } |
|
175 | - } else { |
|
176 | - $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
177 | - } |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - if ($debug) { |
|
183 | - $storeResult = $this->handler->insertD($smartObj); |
|
184 | - } else { |
|
185 | - $storeResult = $this->handler->insert($smartObj); |
|
186 | - } |
|
187 | - |
|
188 | - if ($storeResult) { |
|
189 | - if ($this->handler->getPermissions()) { |
|
190 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
191 | - $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - if ($redirect_page === null) { |
|
196 | - return $smartObj; |
|
197 | - } else { |
|
198 | - if (!$storeResult) { |
|
199 | - redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
200 | - } |
|
201 | - |
|
202 | - $redirect_page = $redirect_page ?: smart_get_page_before_form(); |
|
203 | - |
|
204 | - redirect_header($redirect_page, 2, $redirect_msg); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Store the object in the database autmatically from a form sending POST data |
|
210 | - * |
|
211 | - * @param string $created_success_msg message to display if new object was created |
|
212 | - * @param string $modified_success_msg message to display if object was successfully edited |
|
213 | - * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
214 | - * @param bool $debug |
|
215 | - * @param bool $x_param |
|
216 | - * @return bool |
|
217 | - * @internal param string $created_redir_page redirect page after creating the object |
|
218 | - * @internal param string $modified_redir_page redirect page after editing the object |
|
219 | - * @internal param bool $exit if set to TRUE then the script ends |
|
220 | - */ |
|
221 | - public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false) |
|
222 | - { |
|
223 | - $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
224 | - if ($debug) { |
|
225 | - if ($x_param) { |
|
226 | - $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
227 | - } else { |
|
228 | - $smartObj = $this->handler->getD($objectid); |
|
229 | - } |
|
230 | - } else { |
|
231 | - if ($x_param) { |
|
232 | - $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
233 | - } else { |
|
234 | - $smartObj = $this->handler->get($objectid); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
239 | - if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
240 | - if ($smartObj->isNew()) { |
|
241 | - // This is a new object. We need to store the meta data and then the language data |
|
242 | - // First, we will get rid of the multilanguage data to only store the meta data |
|
243 | - $smartObj->stripMultilanguageFields(); |
|
244 | - $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
245 | - /** |
|
246 | - * @todo we need to trap potential errors here |
|
247 | - */ |
|
248 | - |
|
249 | - // ok, the meta daa is stored. Let's recreate the object and then |
|
250 | - // get rid of anything not multilanguage |
|
251 | - unset($smartObj); |
|
252 | - $smartObj = $this->handler->get($objectid); |
|
253 | - $smartObj->stripNonMultilanguageFields(); |
|
254 | - |
|
255 | - $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
256 | - $this->handler->changeTableNameForML(); |
|
257 | - $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
258 | - |
|
259 | - return $ret; |
|
260 | - } |
|
261 | - } else { |
|
262 | - return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @return bool |
|
268 | - */ |
|
269 | - public function storeSmartObjectD() |
|
270 | - { |
|
271 | - return $this->storeSmartObject(true); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * @param bool $debug |
|
276 | - * @param bool $xparam |
|
277 | - * @return bool |
|
278 | - */ |
|
279 | - public function storeSmartObject($debug = false, $xparam = false) |
|
280 | - { |
|
281 | - $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
282 | - |
|
283 | - return $ret; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Handles deletion of an object which keyid is passed as a GET param |
|
288 | - * |
|
289 | - * @param bool $confirm_msg |
|
290 | - * @param string $op |
|
291 | - * @param bool $userSide |
|
292 | - * @return bool |
|
293 | - * @internal param string $redir_page redirect page after deleting the object |
|
294 | - */ |
|
295 | - public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
296 | - { |
|
297 | - global $smart_previous_page; |
|
298 | - |
|
299 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
300 | - $smartObj = $this->handler->get($objectid); |
|
301 | - |
|
302 | - if ($smartObj->isNew()) { |
|
303 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
304 | - } |
|
305 | - |
|
306 | - $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
307 | - if ($confirm) { |
|
308 | - if (!$this->handler->delete($smartObj)) { |
|
309 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
310 | - exit; |
|
311 | - } |
|
312 | - |
|
313 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
314 | - } else { |
|
315 | - // no confirm: show deletion condition |
|
316 | - |
|
317 | - xoops_cp_header(); |
|
318 | - |
|
319 | - if (!$confirm_msg) { |
|
320 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
321 | - } |
|
322 | - |
|
323 | - xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), |
|
324 | - sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
325 | - |
|
326 | - xoops_cp_footer(); |
|
327 | - } |
|
328 | - exit(); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @param bool $confirm_msg |
|
333 | - * @param string $op |
|
334 | - */ |
|
335 | - public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
336 | - { |
|
337 | - global $smart_previous_page, $xoopsTpl; |
|
338 | - |
|
339 | - $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
340 | - $smartObj = $this->handler->get($objectid); |
|
341 | - |
|
342 | - if ($smartObj->isNew()) { |
|
343 | - redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
344 | - } |
|
345 | - |
|
346 | - $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
347 | - if ($confirm) { |
|
348 | - if (!$this->handler->delete($smartObj)) { |
|
349 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
350 | - exit; |
|
351 | - } |
|
352 | - |
|
353 | - redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
354 | - } else { |
|
355 | - // no confirm: show deletion condition |
|
356 | - if (!$confirm_msg) { |
|
357 | - $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
358 | - } |
|
359 | - |
|
360 | - ob_start(); |
|
361 | - xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), |
|
362 | - sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
363 | - $smartobjectDeleteConfirm = ob_get_clean(); |
|
364 | - $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
370 | - * |
|
371 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
372 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
373 | - * @param bool $withimage |
|
374 | - * @return string admin side link to the object |
|
375 | - */ |
|
376 | - public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
377 | - { |
|
378 | - $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
379 | - if ($onlyUrl) { |
|
380 | - return $ret; |
|
381 | - } elseif ($withimage) { |
|
382 | - return "<a href='" . |
|
383 | - $ret . |
|
384 | - "'><img src='" . |
|
385 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
386 | - "viewmag.png' style='vertical-align: middle;' alt='" . |
|
387 | - _CO_SOBJECT_ADMIN_VIEW . |
|
388 | - "' title='" . |
|
389 | - _CO_SOBJECT_ADMIN_VIEW . |
|
390 | - "'/></a>"; |
|
391 | - } |
|
392 | - |
|
393 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Retreive the object user side link |
|
398 | - * |
|
399 | - * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
400 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
401 | - * @return string user side link to the object |
|
402 | - */ |
|
403 | - public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
404 | - { |
|
405 | - $seoMode = smart_getModuleModeSEO($this->handler->_moduleName); |
|
406 | - $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName); |
|
407 | - |
|
408 | - /** |
|
409 | - * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
410 | - */ |
|
411 | - //$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName); |
|
412 | - $seoIncludeId = true; |
|
413 | - |
|
414 | - if ($seoMode === 'rewrite') { |
|
415 | - $ret = XOOPS_URL . |
|
416 | - '/' . |
|
417 | - $seoModuleName . |
|
418 | - '.' . |
|
419 | - $this->handler->_itemname . |
|
420 | - ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . |
|
421 | - '/' . |
|
422 | - $smartObj->getVar('short_url') . |
|
423 | - '.html'; |
|
424 | - } elseif ($seoMode === 'pathinfo') { |
|
425 | - $ret = SMARTOBJECT_URL . |
|
426 | - 'seo.php/' . |
|
427 | - $seoModuleName . |
|
428 | - '.' . |
|
429 | - $this->handler->_itemname . |
|
430 | - ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . |
|
431 | - '/' . |
|
432 | - $smartObj->getVar('short_url') . |
|
433 | - '.html'; |
|
434 | - } else { |
|
435 | - $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
436 | - } |
|
437 | - |
|
438 | - if (!$onlyUrl) { |
|
439 | - $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
440 | - } |
|
441 | - |
|
442 | - return $ret; |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * @param $smartObj |
|
447 | - * @param bool $onlyUrl |
|
448 | - * @param bool $withimage |
|
449 | - * @return string |
|
450 | - */ |
|
451 | - public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
452 | - { |
|
453 | - $ret = $this->handler->_moduleUrl . |
|
454 | - 'admin/' . |
|
455 | - $this->handler->_page . |
|
456 | - '?op=mod&' . |
|
457 | - $this->handler->keyName . |
|
458 | - '=' . |
|
459 | - $smartObj->getVar($this->handler->keyName) . |
|
460 | - '&language=' . |
|
461 | - $smartObj->getVar('language'); |
|
462 | - if ($onlyUrl) { |
|
463 | - return $ret; |
|
464 | - } elseif ($withimage) { |
|
465 | - return "<a href='" . |
|
466 | - $ret . |
|
467 | - "'><img src='" . |
|
468 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
469 | - "wizard.png' style='vertical-align: middle;' alt='" . |
|
470 | - _CO_SOBJECT_LANGUAGE_MODIFY . |
|
471 | - "' title='" . |
|
472 | - _CO_SOBJECT_LANGUAGE_MODIFY . |
|
473 | - "'/></a>"; |
|
474 | - } |
|
475 | - |
|
476 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @param $smartObj |
|
481 | - * @param bool $onlyUrl |
|
482 | - * @param bool $withimage |
|
483 | - * @param bool $userSide |
|
484 | - * @return string |
|
485 | - */ |
|
486 | - public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
487 | - { |
|
488 | - $admin_side = $userSide ? '' : 'admin/'; |
|
489 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
490 | - if ($onlyUrl) { |
|
491 | - return $ret; |
|
492 | - } elseif ($withimage) { |
|
493 | - return "<a href='" . |
|
494 | - $ret . |
|
495 | - "'><img src='" . |
|
496 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
497 | - "edit.png' style='vertical-align: middle;' alt='" . |
|
498 | - _CO_SOBJECT_MODIFY . |
|
499 | - "' title='" . |
|
500 | - _CO_SOBJECT_MODIFY . |
|
501 | - "'/></a>"; |
|
502 | - } |
|
503 | - |
|
504 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * @param $smartObj |
|
509 | - * @param bool $onlyUrl |
|
510 | - * @param bool $withimage |
|
511 | - * @param bool $userSide |
|
512 | - * @return string |
|
513 | - */ |
|
514 | - public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
515 | - { |
|
516 | - $admin_side = $userSide ? '' : 'admin/'; |
|
517 | - $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
518 | - if ($onlyUrl) { |
|
519 | - return $ret; |
|
520 | - } elseif ($withimage) { |
|
521 | - return "<a href='" . |
|
522 | - $ret . |
|
523 | - "'><img src='" . |
|
524 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
525 | - "editdelete.png' style='vertical-align: middle;' alt='" . |
|
526 | - _CO_SOBJECT_DELETE . |
|
527 | - "' title='" . |
|
528 | - _CO_SOBJECT_DELETE . |
|
529 | - "'/></a>"; |
|
530 | - } |
|
531 | - |
|
532 | - return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * @param $smartObj |
|
537 | - * @return string |
|
538 | - */ |
|
539 | - public function getPrintAndMailLink($smartObj) |
|
540 | - { |
|
541 | - global $xoopsConfig; |
|
542 | - |
|
543 | - $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
544 | - $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
545 | - $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>'; |
|
546 | - |
|
547 | - $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName); |
|
548 | - $link = smart_getCurrentPage(); |
|
549 | - $mid = $smartModule->getVar('mid'); |
|
550 | - $friendlink = "<a href=\"javascript:openWithSelfMain('" . |
|
551 | - SMARTOBJECT_URL . |
|
552 | - 'sendlink.php?link=' . |
|
553 | - $link . |
|
554 | - '&mid=' . |
|
555 | - $mid . |
|
556 | - "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" . |
|
557 | - SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
558 | - "mail_send.png\" alt=\"" . |
|
559 | - _CO_SOBJECT_EMAIL . |
|
560 | - "\" title=\"" . |
|
561 | - _CO_SOBJECT_EMAIL . |
|
562 | - "\" style=\"vertical-align: middle;\"/></a>"; |
|
563 | - |
|
564 | - $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
565 | - |
|
566 | - return $ret; |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * @return string |
|
571 | - */ |
|
572 | - public function getModuleItemString() |
|
573 | - { |
|
574 | - $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
575 | - |
|
576 | - return $ret; |
|
577 | - } |
|
34 | + public $handler; |
|
35 | + |
|
36 | + /** |
|
37 | + * SmartObjectController constructor. |
|
38 | + * @param $handler |
|
39 | + */ |
|
40 | + public function __construct($handler) |
|
41 | + { |
|
42 | + $this->handler = $handler; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param $smartObj |
|
47 | + */ |
|
48 | + public function postDataToObject(&$smartObj) |
|
49 | + { |
|
50 | + foreach (array_keys($smartObj->vars) as $key) { |
|
51 | + switch ($smartObj->vars[$key]['data_type']) { |
|
52 | + case XOBJ_DTYPE_IMAGE: |
|
53 | + if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] !== '') { |
|
54 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
55 | + $smartObj->setVar($key, $_POST['url_' . $key]); |
|
56 | + if (file_exists($oldFile)) { |
|
57 | + unlink($oldFile); |
|
58 | + } |
|
59 | + } |
|
60 | + if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') { |
|
61 | + $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e'); |
|
62 | + $smartObj->setVar($key, ''); |
|
63 | + if (file_exists($oldFile)) { |
|
64 | + unlink($oldFile); |
|
65 | + } |
|
66 | + } |
|
67 | + break; |
|
68 | + |
|
69 | + case XOBJ_DTYPE_URLLINK: |
|
70 | + $linkObj = $smartObj->getUrlLinkObj($key); |
|
71 | + $linkObj->setVar('caption', $_POST['caption_' . $key]); |
|
72 | + $linkObj->setVar('description', $_POST['desc_' . $key]); |
|
73 | + $linkObj->setVar('target', $_POST['target_' . $key]); |
|
74 | + $linkObj->setVar('url', $_POST['url_' . $key]); |
|
75 | + if ($linkObj->getVar('url') !== '') { |
|
76 | + $smartObj->storeUrlLinkObj($linkObj); |
|
77 | + } |
|
78 | + //todo: catch errors |
|
79 | + $smartObj->setVar($key, $linkObj->getVar('urllinkid')); |
|
80 | + break; |
|
81 | + |
|
82 | + case XOBJ_DTYPE_FILE: |
|
83 | + if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] === '') { |
|
84 | + $fileObj = $smartObj->getFileObj($key); |
|
85 | + $fileObj->setVar('caption', $_POST['caption_' . $key]); |
|
86 | + $fileObj->setVar('description', $_POST['desc_' . $key]); |
|
87 | + $fileObj->setVar('url', $_POST['url_' . $key]); |
|
88 | + if (!($fileObj->getVar('url') === '' && $fileObj->getVar('url') === '' && $fileObj->getVar('url') === '')) { |
|
89 | + $res = $smartObj->storeFileObj($fileObj); |
|
90 | + if ($res) { |
|
91 | + $smartObj->setVar($key, $fileObj->getVar('fileid')); |
|
92 | + } else { |
|
93 | + //error setted, but no error message (to be improved) |
|
94 | + $smartObj->setErrors($fileObj->getErrors()); |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + break; |
|
99 | + |
|
100 | + case XOBJ_DTYPE_STIME: |
|
101 | + case XOBJ_DTYPE_MTIME: |
|
102 | + case XOBJ_DTYPE_LTIME: |
|
103 | + // check if this field's value is available in the POST array |
|
104 | + if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) { |
|
105 | + $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time']; |
|
106 | + } else { |
|
107 | + $value = strtotime($_POST[$key]); |
|
108 | + //if strtotime returns false, the value is already a time stamp |
|
109 | + if (!$value) { |
|
110 | + $value = (int)$_POST[$key]; |
|
111 | + } |
|
112 | + } |
|
113 | + $smartObj->setVar($key, $value); |
|
114 | + |
|
115 | + break; |
|
116 | + |
|
117 | + default: |
|
118 | + $smartObj->setVar($key, $_POST[$key]); |
|
119 | + break; |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param $smartObj |
|
126 | + * @param $objectid |
|
127 | + * @param $created_success_msg |
|
128 | + * @param $modified_success_msg |
|
129 | + * @param bool $redirect_page |
|
130 | + * @param bool $debug |
|
131 | + * @return mixed |
|
132 | + */ |
|
133 | + public function doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false) |
|
134 | + { |
|
135 | + global $smart_previous_page; |
|
136 | + |
|
137 | + $this->postDataToObject($smartObj); |
|
138 | + |
|
139 | + if ($smartObj->isNew()) { |
|
140 | + $redirect_msg = $created_success_msg; |
|
141 | + } else { |
|
142 | + $redirect_msg = $modified_success_msg; |
|
143 | + } |
|
144 | + |
|
145 | + // Check if there were uploaded files |
|
146 | + if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { |
|
147 | + include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php'; |
|
148 | + $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); |
|
149 | + foreach ($_FILES as $name => $file_array) { |
|
150 | + if (isset($file_array['name']) && $file_array['name'] !== '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { |
|
151 | + if ($uploaderObj->fetchMedia($name)) { |
|
152 | + $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName()); |
|
153 | + if ($uploaderObj->upload()) { |
|
154 | + // Find the related field in the SmartObject |
|
155 | + $related_field = str_replace('upload_', '', $name); |
|
156 | + $uploadedArray[] = $related_field; |
|
157 | + //si c'est un fichier Rich |
|
158 | + if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) { |
|
159 | + $object_fileurl = $smartObj->getUploadDir(); |
|
160 | + $fileObj = $smartObj->getFileObj($related_field); |
|
161 | + $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); |
|
162 | + $fileObj->setVar('caption', $_POST['caption_' . $related_field]); |
|
163 | + $fileObj->setVar('description', $_POST['desc_' . $related_field]); |
|
164 | + $smartObj->storeFileObj($fileObj); |
|
165 | + //todo: catch errors |
|
166 | + $smartObj->setVar($related_field, $fileObj->getVar('fileid')); |
|
167 | + } else { |
|
168 | + $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); |
|
169 | + unlink($old_file); |
|
170 | + $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); |
|
171 | + } |
|
172 | + } else { |
|
173 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
174 | + } |
|
175 | + } else { |
|
176 | + $smartObj->setErrors($uploaderObj->getErrors(false)); |
|
177 | + } |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + if ($debug) { |
|
183 | + $storeResult = $this->handler->insertD($smartObj); |
|
184 | + } else { |
|
185 | + $storeResult = $this->handler->insert($smartObj); |
|
186 | + } |
|
187 | + |
|
188 | + if ($storeResult) { |
|
189 | + if ($this->handler->getPermissions()) { |
|
190 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
191 | + $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id()); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + if ($redirect_page === null) { |
|
196 | + return $smartObj; |
|
197 | + } else { |
|
198 | + if (!$storeResult) { |
|
199 | + redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); |
|
200 | + } |
|
201 | + |
|
202 | + $redirect_page = $redirect_page ?: smart_get_page_before_form(); |
|
203 | + |
|
204 | + redirect_header($redirect_page, 2, $redirect_msg); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Store the object in the database autmatically from a form sending POST data |
|
210 | + * |
|
211 | + * @param string $created_success_msg message to display if new object was created |
|
212 | + * @param string $modified_success_msg message to display if object was successfully edited |
|
213 | + * @param bool|string $redirect_page redirect page, if not set, then we backup once |
|
214 | + * @param bool $debug |
|
215 | + * @param bool $x_param |
|
216 | + * @return bool |
|
217 | + * @internal param string $created_redir_page redirect page after creating the object |
|
218 | + * @internal param string $modified_redir_page redirect page after editing the object |
|
219 | + * @internal param bool $exit if set to TRUE then the script ends |
|
220 | + */ |
|
221 | + public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false) |
|
222 | + { |
|
223 | + $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0; |
|
224 | + if ($debug) { |
|
225 | + if ($x_param) { |
|
226 | + $smartObj = $this->handler->getD($objectid, true, $x_param); |
|
227 | + } else { |
|
228 | + $smartObj = $this->handler->getD($objectid); |
|
229 | + } |
|
230 | + } else { |
|
231 | + if ($x_param) { |
|
232 | + $smartObj = $this->handler->get($objectid, true, false, false, $x_param); |
|
233 | + } else { |
|
234 | + $smartObj = $this->handler->get($objectid); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + // if handler is the Multilanguage handler, we will need to treat this for multilanguage |
|
239 | + if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) { |
|
240 | + if ($smartObj->isNew()) { |
|
241 | + // This is a new object. We need to store the meta data and then the language data |
|
242 | + // First, we will get rid of the multilanguage data to only store the meta data |
|
243 | + $smartObj->stripMultilanguageFields(); |
|
244 | + $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
245 | + /** |
|
246 | + * @todo we need to trap potential errors here |
|
247 | + */ |
|
248 | + |
|
249 | + // ok, the meta daa is stored. Let's recreate the object and then |
|
250 | + // get rid of anything not multilanguage |
|
251 | + unset($smartObj); |
|
252 | + $smartObj = $this->handler->get($objectid); |
|
253 | + $smartObj->stripNonMultilanguageFields(); |
|
254 | + |
|
255 | + $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName)); |
|
256 | + $this->handler->changeTableNameForML(); |
|
257 | + $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
258 | + |
|
259 | + return $ret; |
|
260 | + } |
|
261 | + } else { |
|
262 | + return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug); |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @return bool |
|
268 | + */ |
|
269 | + public function storeSmartObjectD() |
|
270 | + { |
|
271 | + return $this->storeSmartObject(true); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * @param bool $debug |
|
276 | + * @param bool $xparam |
|
277 | + * @return bool |
|
278 | + */ |
|
279 | + public function storeSmartObject($debug = false, $xparam = false) |
|
280 | + { |
|
281 | + $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam); |
|
282 | + |
|
283 | + return $ret; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Handles deletion of an object which keyid is passed as a GET param |
|
288 | + * |
|
289 | + * @param bool $confirm_msg |
|
290 | + * @param string $op |
|
291 | + * @param bool $userSide |
|
292 | + * @return bool |
|
293 | + * @internal param string $redir_page redirect page after deleting the object |
|
294 | + */ |
|
295 | + public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false) |
|
296 | + { |
|
297 | + global $smart_previous_page; |
|
298 | + |
|
299 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
300 | + $smartObj = $this->handler->get($objectid); |
|
301 | + |
|
302 | + if ($smartObj->isNew()) { |
|
303 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
304 | + } |
|
305 | + |
|
306 | + $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
307 | + if ($confirm) { |
|
308 | + if (!$this->handler->delete($smartObj)) { |
|
309 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
310 | + exit; |
|
311 | + } |
|
312 | + |
|
313 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
314 | + } else { |
|
315 | + // no confirm: show deletion condition |
|
316 | + |
|
317 | + xoops_cp_header(); |
|
318 | + |
|
319 | + if (!$confirm_msg) { |
|
320 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
321 | + } |
|
322 | + |
|
323 | + xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), |
|
324 | + sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
325 | + |
|
326 | + xoops_cp_footer(); |
|
327 | + } |
|
328 | + exit(); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @param bool $confirm_msg |
|
333 | + * @param string $op |
|
334 | + */ |
|
335 | + public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del') |
|
336 | + { |
|
337 | + global $smart_previous_page, $xoopsTpl; |
|
338 | + |
|
339 | + $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0; |
|
340 | + $smartObj = $this->handler->get($objectid); |
|
341 | + |
|
342 | + if ($smartObj->isNew()) { |
|
343 | + redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED); |
|
344 | + } |
|
345 | + |
|
346 | + $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0; |
|
347 | + if ($confirm) { |
|
348 | + if (!$this->handler->delete($smartObj)) { |
|
349 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors()); |
|
350 | + exit; |
|
351 | + } |
|
352 | + |
|
353 | + redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS); |
|
354 | + } else { |
|
355 | + // no confirm: show deletion condition |
|
356 | + if (!$confirm_msg) { |
|
357 | + $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM; |
|
358 | + } |
|
359 | + |
|
360 | + ob_start(); |
|
361 | + xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), |
|
362 | + sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE); |
|
363 | + $smartobjectDeleteConfirm = ob_get_clean(); |
|
364 | + $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm); |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Retreive the object admin side link for a {@link SmartObjectSingleView} page |
|
370 | + * |
|
371 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
372 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
373 | + * @param bool $withimage |
|
374 | + * @return string admin side link to the object |
|
375 | + */ |
|
376 | + public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false) |
|
377 | + { |
|
378 | + $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
379 | + if ($onlyUrl) { |
|
380 | + return $ret; |
|
381 | + } elseif ($withimage) { |
|
382 | + return "<a href='" . |
|
383 | + $ret . |
|
384 | + "'><img src='" . |
|
385 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
386 | + "viewmag.png' style='vertical-align: middle;' alt='" . |
|
387 | + _CO_SOBJECT_ADMIN_VIEW . |
|
388 | + "' title='" . |
|
389 | + _CO_SOBJECT_ADMIN_VIEW . |
|
390 | + "'/></a>"; |
|
391 | + } |
|
392 | + |
|
393 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Retreive the object user side link |
|
398 | + * |
|
399 | + * @param SmartObject $smartObj reference to the object from which we want the user side link |
|
400 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
401 | + * @return string user side link to the object |
|
402 | + */ |
|
403 | + public function getItemLink(SmartObject $smartObj, $onlyUrl = false) |
|
404 | + { |
|
405 | + $seoMode = smart_getModuleModeSEO($this->handler->_moduleName); |
|
406 | + $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName); |
|
407 | + |
|
408 | + /** |
|
409 | + * $seoIncludeId feature is not finished yet, so let's put it always to true |
|
410 | + */ |
|
411 | + //$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName); |
|
412 | + $seoIncludeId = true; |
|
413 | + |
|
414 | + if ($seoMode === 'rewrite') { |
|
415 | + $ret = XOOPS_URL . |
|
416 | + '/' . |
|
417 | + $seoModuleName . |
|
418 | + '.' . |
|
419 | + $this->handler->_itemname . |
|
420 | + ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . |
|
421 | + '/' . |
|
422 | + $smartObj->getVar('short_url') . |
|
423 | + '.html'; |
|
424 | + } elseif ($seoMode === 'pathinfo') { |
|
425 | + $ret = SMARTOBJECT_URL . |
|
426 | + 'seo.php/' . |
|
427 | + $seoModuleName . |
|
428 | + '.' . |
|
429 | + $this->handler->_itemname . |
|
430 | + ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . |
|
431 | + '/' . |
|
432 | + $smartObj->getVar('short_url') . |
|
433 | + '.html'; |
|
434 | + } else { |
|
435 | + $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
436 | + } |
|
437 | + |
|
438 | + if (!$onlyUrl) { |
|
439 | + $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
440 | + } |
|
441 | + |
|
442 | + return $ret; |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * @param $smartObj |
|
447 | + * @param bool $onlyUrl |
|
448 | + * @param bool $withimage |
|
449 | + * @return string |
|
450 | + */ |
|
451 | + public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true) |
|
452 | + { |
|
453 | + $ret = $this->handler->_moduleUrl . |
|
454 | + 'admin/' . |
|
455 | + $this->handler->_page . |
|
456 | + '?op=mod&' . |
|
457 | + $this->handler->keyName . |
|
458 | + '=' . |
|
459 | + $smartObj->getVar($this->handler->keyName) . |
|
460 | + '&language=' . |
|
461 | + $smartObj->getVar('language'); |
|
462 | + if ($onlyUrl) { |
|
463 | + return $ret; |
|
464 | + } elseif ($withimage) { |
|
465 | + return "<a href='" . |
|
466 | + $ret . |
|
467 | + "'><img src='" . |
|
468 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
469 | + "wizard.png' style='vertical-align: middle;' alt='" . |
|
470 | + _CO_SOBJECT_LANGUAGE_MODIFY . |
|
471 | + "' title='" . |
|
472 | + _CO_SOBJECT_LANGUAGE_MODIFY . |
|
473 | + "'/></a>"; |
|
474 | + } |
|
475 | + |
|
476 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @param $smartObj |
|
481 | + * @param bool $onlyUrl |
|
482 | + * @param bool $withimage |
|
483 | + * @param bool $userSide |
|
484 | + * @return string |
|
485 | + */ |
|
486 | + public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
487 | + { |
|
488 | + $admin_side = $userSide ? '' : 'admin/'; |
|
489 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
490 | + if ($onlyUrl) { |
|
491 | + return $ret; |
|
492 | + } elseif ($withimage) { |
|
493 | + return "<a href='" . |
|
494 | + $ret . |
|
495 | + "'><img src='" . |
|
496 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
497 | + "edit.png' style='vertical-align: middle;' alt='" . |
|
498 | + _CO_SOBJECT_MODIFY . |
|
499 | + "' title='" . |
|
500 | + _CO_SOBJECT_MODIFY . |
|
501 | + "'/></a>"; |
|
502 | + } |
|
503 | + |
|
504 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * @param $smartObj |
|
509 | + * @param bool $onlyUrl |
|
510 | + * @param bool $withimage |
|
511 | + * @param bool $userSide |
|
512 | + * @return string |
|
513 | + */ |
|
514 | + public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false) |
|
515 | + { |
|
516 | + $admin_side = $userSide ? '' : 'admin/'; |
|
517 | + $ret = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
518 | + if ($onlyUrl) { |
|
519 | + return $ret; |
|
520 | + } elseif ($withimage) { |
|
521 | + return "<a href='" . |
|
522 | + $ret . |
|
523 | + "'><img src='" . |
|
524 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
525 | + "editdelete.png' style='vertical-align: middle;' alt='" . |
|
526 | + _CO_SOBJECT_DELETE . |
|
527 | + "' title='" . |
|
528 | + _CO_SOBJECT_DELETE . |
|
529 | + "'/></a>"; |
|
530 | + } |
|
531 | + |
|
532 | + return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>'; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * @param $smartObj |
|
537 | + * @return string |
|
538 | + */ |
|
539 | + public function getPrintAndMailLink($smartObj) |
|
540 | + { |
|
541 | + global $xoopsConfig; |
|
542 | + |
|
543 | + $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName); |
|
544 | + $js = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);"; |
|
545 | + $printlink = '<a href="' . $js . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>'; |
|
546 | + |
|
547 | + $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName); |
|
548 | + $link = smart_getCurrentPage(); |
|
549 | + $mid = $smartModule->getVar('mid'); |
|
550 | + $friendlink = "<a href=\"javascript:openWithSelfMain('" . |
|
551 | + SMARTOBJECT_URL . |
|
552 | + 'sendlink.php?link=' . |
|
553 | + $link . |
|
554 | + '&mid=' . |
|
555 | + $mid . |
|
556 | + "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" . |
|
557 | + SMARTOBJECT_IMAGES_ACTIONS_URL . |
|
558 | + "mail_send.png\" alt=\"" . |
|
559 | + _CO_SOBJECT_EMAIL . |
|
560 | + "\" title=\"" . |
|
561 | + _CO_SOBJECT_EMAIL . |
|
562 | + "\" style=\"vertical-align: middle;\"/></a>"; |
|
563 | + |
|
564 | + $ret = '<span id="smartobject_print_button">' . $printlink . ' </span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>'; |
|
565 | + |
|
566 | + return $ret; |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * @return string |
|
571 | + */ |
|
572 | + public function getModuleItemString() |
|
573 | + { |
|
574 | + $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname; |
|
575 | + |
|
576 | + return $ret; |
|
577 | + } |
|
578 | 578 | } |
@@ -37,125 +37,125 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class SmartobjectRating extends SmartObject |
39 | 39 | { |
40 | - public $_modulePlugin = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectRating constructor. |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | - $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | - $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | - $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | - $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | - $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | - $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | - |
|
55 | - $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | - |
|
57 | - $this->setControl('dirname', array( |
|
58 | - 'handler' => 'rating', |
|
59 | - 'method' => 'getModuleList', |
|
60 | - 'onSelect' => 'submit' |
|
61 | - )); |
|
62 | - |
|
63 | - $this->setControl('item', array( |
|
64 | - 'object' => &$this, |
|
65 | - 'method' => 'getItemList' |
|
66 | - )); |
|
67 | - |
|
68 | - $this->setControl('uid', 'user'); |
|
69 | - |
|
70 | - $this->setControl('rate', array( |
|
71 | - 'handler' => 'rating', |
|
72 | - 'method' => 'getRateList' |
|
73 | - )); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $key |
|
78 | - * @param string $format |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - public function getVar($key, $format = 's') |
|
82 | - { |
|
83 | - if ($format === 's' && in_array($key, array('name', 'dirname'))) { |
|
84 | - // return call_user_func(array($this, $key)); |
|
85 | - return $this->{$key}(); |
|
86 | - } |
|
87 | - |
|
88 | - return parent::getVar($key, $format); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function name() |
|
95 | - { |
|
96 | - $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
97 | - |
|
98 | - return $ret; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - public function dirname() |
|
105 | - { |
|
106 | - global $smartobjectRatingHandler; |
|
107 | - $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | - |
|
109 | - return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return mixed |
|
114 | - */ |
|
115 | - public function getItemList() |
|
116 | - { |
|
117 | - $plugin = $this->getModulePlugin(); |
|
118 | - |
|
119 | - return $plugin->getItemList(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function getItemValue() |
|
126 | - { |
|
127 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | - $plugin = $this->getModulePlugin(); |
|
129 | - $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | - if (!$pluginItemInfo) { |
|
131 | - return ''; |
|
132 | - } |
|
133 | - $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | - |
|
136 | - return $ret; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return mixed |
|
141 | - */ |
|
142 | - public function getRateValue() |
|
143 | - { |
|
144 | - return $this->getVar('rate'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public function getModulePlugin() |
|
151 | - { |
|
152 | - if (!$this->_modulePlugin) { |
|
153 | - global $smartobjectRatingHandler; |
|
154 | - $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | - } |
|
156 | - |
|
157 | - return $this->_modulePlugin; |
|
158 | - } |
|
40 | + public $_modulePlugin = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectRating constructor. |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | + $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | + $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | + $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | + $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | + $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | + $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | + |
|
55 | + $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | + |
|
57 | + $this->setControl('dirname', array( |
|
58 | + 'handler' => 'rating', |
|
59 | + 'method' => 'getModuleList', |
|
60 | + 'onSelect' => 'submit' |
|
61 | + )); |
|
62 | + |
|
63 | + $this->setControl('item', array( |
|
64 | + 'object' => &$this, |
|
65 | + 'method' => 'getItemList' |
|
66 | + )); |
|
67 | + |
|
68 | + $this->setControl('uid', 'user'); |
|
69 | + |
|
70 | + $this->setControl('rate', array( |
|
71 | + 'handler' => 'rating', |
|
72 | + 'method' => 'getRateList' |
|
73 | + )); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $key |
|
78 | + * @param string $format |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + public function getVar($key, $format = 's') |
|
82 | + { |
|
83 | + if ($format === 's' && in_array($key, array('name', 'dirname'))) { |
|
84 | + // return call_user_func(array($this, $key)); |
|
85 | + return $this->{$key}(); |
|
86 | + } |
|
87 | + |
|
88 | + return parent::getVar($key, $format); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function name() |
|
95 | + { |
|
96 | + $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
97 | + |
|
98 | + return $ret; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + public function dirname() |
|
105 | + { |
|
106 | + global $smartobjectRatingHandler; |
|
107 | + $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | + |
|
109 | + return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return mixed |
|
114 | + */ |
|
115 | + public function getItemList() |
|
116 | + { |
|
117 | + $plugin = $this->getModulePlugin(); |
|
118 | + |
|
119 | + return $plugin->getItemList(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function getItemValue() |
|
126 | + { |
|
127 | + $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | + $plugin = $this->getModulePlugin(); |
|
129 | + $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | + if (!$pluginItemInfo) { |
|
131 | + return ''; |
|
132 | + } |
|
133 | + $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | + $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | + |
|
136 | + return $ret; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return mixed |
|
141 | + */ |
|
142 | + public function getRateValue() |
|
143 | + { |
|
144 | + return $this->getVar('rate'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public function getModulePlugin() |
|
151 | + { |
|
152 | + if (!$this->_modulePlugin) { |
|
153 | + global $smartobjectRatingHandler; |
|
154 | + $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | + } |
|
156 | + |
|
157 | + return $this->_modulePlugin; |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,93 +163,93 @@ discard block |
||
163 | 163 | */ |
164 | 164 | class SmartobjectRatingHandler extends SmartPersistableObjectHandler |
165 | 165 | { |
166 | - public $_rateOptions = array(); |
|
167 | - public $_moduleList = false; |
|
168 | - public $pluginsObject; |
|
169 | - |
|
170 | - /** |
|
171 | - * SmartobjectRatingHandler constructor. |
|
172 | - * @param XoopsDatabase $db |
|
173 | - */ |
|
174 | - public function __construct(XoopsDatabase $db) |
|
175 | - { |
|
176 | - parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
177 | - $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
178 | - |
|
179 | - $this->_rateOptions[1] = 1; |
|
180 | - $this->_rateOptions[2] = 2; |
|
181 | - $this->_rateOptions[3] = 3; |
|
182 | - $this->_rateOptions[4] = 4; |
|
183 | - $this->_rateOptions[5] = 5; |
|
184 | - |
|
185 | - $this->pluginsObject = new SmartPluginHandler(); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function getModuleList() |
|
192 | - { |
|
193 | - if (!$this->_moduleList) { |
|
194 | - $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | - $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | - foreach ($moduleArray as $k => $v) { |
|
197 | - $this->_moduleList[$k] = $v; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - return $this->_moduleList; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function getRateList() |
|
208 | - { |
|
209 | - return $this->_rateOptions; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param $itemid |
|
214 | - * @param $dirname |
|
215 | - * @param $item |
|
216 | - * @return int |
|
217 | - */ |
|
218 | - public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | - { |
|
220 | - $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | - $result = $this->db->query($sql); |
|
222 | - if (!$result) { |
|
223 | - return 0; |
|
224 | - } |
|
225 | - list($average, $sum) = $this->db->fetchRow($result); |
|
226 | - $ret['average'] = isset($average) ? $average : 0; |
|
227 | - $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | - |
|
229 | - return $ret; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $item |
|
234 | - * @param $itemid |
|
235 | - * @param $dirname |
|
236 | - * @param $uid |
|
237 | - * @return bool |
|
238 | - */ |
|
239 | - public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | - { |
|
241 | - $criteria = new CriteriaCompo(); |
|
242 | - $criteria->add(new Criteria('item', $item)); |
|
243 | - $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | - $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | - $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | - |
|
247 | - $ret = $this->getObjects($criteria); |
|
248 | - |
|
249 | - if (!$ret) { |
|
250 | - return false; |
|
251 | - } else { |
|
252 | - return $ret[0]; |
|
253 | - } |
|
254 | - } |
|
166 | + public $_rateOptions = array(); |
|
167 | + public $_moduleList = false; |
|
168 | + public $pluginsObject; |
|
169 | + |
|
170 | + /** |
|
171 | + * SmartobjectRatingHandler constructor. |
|
172 | + * @param XoopsDatabase $db |
|
173 | + */ |
|
174 | + public function __construct(XoopsDatabase $db) |
|
175 | + { |
|
176 | + parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
177 | + $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
178 | + |
|
179 | + $this->_rateOptions[1] = 1; |
|
180 | + $this->_rateOptions[2] = 2; |
|
181 | + $this->_rateOptions[3] = 3; |
|
182 | + $this->_rateOptions[4] = 4; |
|
183 | + $this->_rateOptions[5] = 5; |
|
184 | + |
|
185 | + $this->pluginsObject = new SmartPluginHandler(); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function getModuleList() |
|
192 | + { |
|
193 | + if (!$this->_moduleList) { |
|
194 | + $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | + $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | + foreach ($moduleArray as $k => $v) { |
|
197 | + $this->_moduleList[$k] = $v; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + return $this->_moduleList; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function getRateList() |
|
208 | + { |
|
209 | + return $this->_rateOptions; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param $itemid |
|
214 | + * @param $dirname |
|
215 | + * @param $item |
|
216 | + * @return int |
|
217 | + */ |
|
218 | + public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | + { |
|
220 | + $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | + $result = $this->db->query($sql); |
|
222 | + if (!$result) { |
|
223 | + return 0; |
|
224 | + } |
|
225 | + list($average, $sum) = $this->db->fetchRow($result); |
|
226 | + $ret['average'] = isset($average) ? $average : 0; |
|
227 | + $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | + |
|
229 | + return $ret; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $item |
|
234 | + * @param $itemid |
|
235 | + * @param $dirname |
|
236 | + * @param $uid |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | + public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | + { |
|
241 | + $criteria = new CriteriaCompo(); |
|
242 | + $criteria->add(new Criteria('item', $item)); |
|
243 | + $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | + $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | + $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | + |
|
247 | + $ret = $this->getObjects($criteria); |
|
248 | + |
|
249 | + if (!$ret) { |
|
250 | + return false; |
|
251 | + } else { |
|
252 | + return $ret[0]; |
|
253 | + } |
|
254 | + } |
|
255 | 255 | } |
@@ -8,22 +8,22 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class SmartobjectUrlLink extends SmartobjectBasedUrl |
10 | 10 | { |
11 | - /** |
|
12 | - * SmartobjectUrlLink constructor. |
|
13 | - */ |
|
14 | - public function __construct() |
|
15 | - { |
|
16 | - parent::__construct(); |
|
17 | - $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
18 | - $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
11 | + /** |
|
12 | + * SmartobjectUrlLink constructor. |
|
13 | + */ |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + parent::__construct(); |
|
17 | + $this->quickInitVar('urllinkid', XOBJ_DTYPE_TXTBOX, true); |
|
18 | + $this->quickInitVar('target', XOBJ_DTYPE_TXTBOX, true); |
|
19 | 19 | |
20 | - $this->setControl('target', array( |
|
21 | - 'options' => array( |
|
22 | - '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
23 | - '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
24 | - ) |
|
25 | - )); |
|
26 | - } |
|
20 | + $this->setControl('target', array( |
|
21 | + 'options' => array( |
|
22 | + '_self' => _CO_SOBJECT_URLLINK_SELF, |
|
23 | + '_blank' => _CO_SOBJECT_URLLINK_BLANK |
|
24 | + ) |
|
25 | + )); |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class SmartobjectUrlLinkHandler extends SmartPersistableObjectHandler |
33 | 33 | { |
34 | - /** |
|
35 | - * SmartobjectUrlLinkHandler constructor. |
|
36 | - * @param XoopsDatabase $db |
|
37 | - */ |
|
38 | - public function __construct(XoopsDatabase $db) |
|
39 | - { |
|
40 | - parent::__construct($db, 'urllink', 'urllinkid', 'caption', 'desc', 'smartobject'); |
|
41 | - } |
|
34 | + /** |
|
35 | + * SmartobjectUrlLinkHandler constructor. |
|
36 | + * @param XoopsDatabase $db |
|
37 | + */ |
|
38 | + public function __construct(XoopsDatabase $db) |
|
39 | + { |
|
40 | + parent::__construct($db, 'urllink', 'urllinkid', 'caption', 'desc', 'smartobject'); |
|
41 | + } |
|
42 | 42 | } |
@@ -19,96 +19,96 @@ |
||
19 | 19 | */ |
20 | 20 | class SmartHighlighter |
21 | 21 | { |
22 | - /** |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - public $preg_keywords = ''; |
|
26 | - /** |
|
27 | - * @access private |
|
28 | - */ |
|
29 | - public $keywords = ''; |
|
30 | - /** |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - public $singlewords = false; |
|
34 | - /** |
|
35 | - * @access private |
|
36 | - */ |
|
37 | - public $replace_callback = null; |
|
22 | + /** |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + public $preg_keywords = ''; |
|
26 | + /** |
|
27 | + * @access private |
|
28 | + */ |
|
29 | + public $keywords = ''; |
|
30 | + /** |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + public $singlewords = false; |
|
34 | + /** |
|
35 | + * @access private |
|
36 | + */ |
|
37 | + public $replace_callback = null; |
|
38 | 38 | |
39 | - public $content; |
|
39 | + public $content; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Main constructor |
|
43 | - * |
|
44 | - * This is the main constructor of keyhighlighter class. <br> |
|
45 | - * It's the only public method of the class. |
|
46 | - * @param string $keywords the keywords you want to highlight |
|
47 | - * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | - * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | - * <code> |
|
50 | - * <?php |
|
51 | - * require ('keyhighlighter.class.php'); |
|
52 | - * |
|
53 | - * function my_highlighter ($matches) { |
|
54 | - * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | - * } |
|
56 | - * |
|
57 | - * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | - * readfile ('http://www.w3c.org/'); |
|
59 | - * ?> |
|
60 | - * </code> |
|
61 | - */ |
|
62 | - // public function __construct () |
|
63 | - public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | - { |
|
65 | - $this->keywords = $keywords; |
|
66 | - $this->singlewords = $singlewords; |
|
67 | - $this->replace_callback = $replace_callback; |
|
68 | - } |
|
41 | + /** |
|
42 | + * Main constructor |
|
43 | + * |
|
44 | + * This is the main constructor of keyhighlighter class. <br> |
|
45 | + * It's the only public method of the class. |
|
46 | + * @param string $keywords the keywords you want to highlight |
|
47 | + * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | + * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | + * <code> |
|
50 | + * <?php |
|
51 | + * require ('keyhighlighter.class.php'); |
|
52 | + * |
|
53 | + * function my_highlighter ($matches) { |
|
54 | + * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | + * } |
|
56 | + * |
|
57 | + * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | + * readfile ('http://www.w3c.org/'); |
|
59 | + * ?> |
|
60 | + * </code> |
|
61 | + */ |
|
62 | + // public function __construct () |
|
63 | + public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | + { |
|
65 | + $this->keywords = $keywords; |
|
66 | + $this->singlewords = $singlewords; |
|
67 | + $this->replace_callback = $replace_callback; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @access private |
|
72 | - * @param $replace_matches |
|
73 | - * @return mixed |
|
74 | - */ |
|
75 | - public function replace($replace_matches) |
|
76 | - { |
|
77 | - $patterns = array(); |
|
78 | - if ($this->singlewords) { |
|
79 | - $keywords = explode(' ', $this->preg_keywords); |
|
80 | - foreach ($keywords as $keyword) { |
|
81 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | - } |
|
83 | - } else { |
|
84 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | - } |
|
70 | + /** |
|
71 | + * @access private |
|
72 | + * @param $replace_matches |
|
73 | + * @return mixed |
|
74 | + */ |
|
75 | + public function replace($replace_matches) |
|
76 | + { |
|
77 | + $patterns = array(); |
|
78 | + if ($this->singlewords) { |
|
79 | + $keywords = explode(' ', $this->preg_keywords); |
|
80 | + foreach ($keywords as $keyword) { |
|
81 | + $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | + } |
|
83 | + } else { |
|
84 | + $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | + } |
|
86 | 86 | |
87 | - $result = $replace_matches[0]; |
|
87 | + $result = $replace_matches[0]; |
|
88 | 88 | |
89 | - foreach ($patterns as $pattern) { |
|
90 | - if (null !== $this->replace_callback) { |
|
91 | - $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | - } else { |
|
93 | - $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | - } |
|
95 | - } |
|
89 | + foreach ($patterns as $pattern) { |
|
90 | + if (null !== $this->replace_callback) { |
|
91 | + $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | + } else { |
|
93 | + $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - return $result; |
|
98 | - } |
|
97 | + return $result; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @access private |
|
102 | - * @param $buffer |
|
103 | - * @return mixed|string |
|
104 | - */ |
|
105 | - public function highlight($buffer) |
|
106 | - { |
|
107 | - $buffer = '>' . $buffer . '<'; |
|
108 | - $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | - $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", array(&$this, 'replace'), $buffer); |
|
110 | - $buffer = substr($buffer, 1, -1); |
|
100 | + /** |
|
101 | + * @access private |
|
102 | + * @param $buffer |
|
103 | + * @return mixed|string |
|
104 | + */ |
|
105 | + public function highlight($buffer) |
|
106 | + { |
|
107 | + $buffer = '>' . $buffer . '<'; |
|
108 | + $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | + $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", array(&$this, 'replace'), $buffer); |
|
110 | + $buffer = substr($buffer, 1, -1); |
|
111 | 111 | |
112 | - return $buffer; |
|
113 | - } |
|
112 | + return $buffer; |
|
113 | + } |
|
114 | 114 | } |
@@ -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 | - include_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 | + include_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 | } |
@@ -89,51 +89,51 @@ |
||
89 | 89 | */ |
90 | 90 | class SmartUploader extends XoopsMediaUploader |
91 | 91 | { |
92 | - public $ext; |
|
93 | - public $dimension; |
|
92 | + public $ext; |
|
93 | + public $dimension; |
|
94 | 94 | |
95 | - /** |
|
96 | - * No admin check for uploads |
|
97 | - */ |
|
98 | - public $noAdminSizeCheck; |
|
95 | + /** |
|
96 | + * No admin check for uploads |
|
97 | + */ |
|
98 | + public $noAdminSizeCheck; |
|
99 | 99 | |
100 | - /** |
|
101 | - * Constructor |
|
102 | - * |
|
103 | - * @param string $uploadDir |
|
104 | - * @param array|int $allowedMimeTypes |
|
105 | - * @param int $maxFileSize |
|
106 | - * @param int $maxWidth |
|
107 | - * @param int $maxHeight |
|
108 | - * @internal param int $cmodvalue |
|
109 | - */ |
|
110 | - public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize, $maxWidth = 0, $maxHeight = 0) |
|
111 | - { |
|
112 | - parent::__construct($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
|
113 | - } |
|
100 | + /** |
|
101 | + * Constructor |
|
102 | + * |
|
103 | + * @param string $uploadDir |
|
104 | + * @param array|int $allowedMimeTypes |
|
105 | + * @param int $maxFileSize |
|
106 | + * @param int $maxWidth |
|
107 | + * @param int $maxHeight |
|
108 | + * @internal param int $cmodvalue |
|
109 | + */ |
|
110 | + public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize, $maxWidth = 0, $maxHeight = 0) |
|
111 | + { |
|
112 | + parent::__construct($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @param $value |
|
117 | - */ |
|
118 | - public function noAdminSizeCheck($value) |
|
119 | - { |
|
120 | - $this->noAdminSizeCheck = $value; |
|
121 | - } |
|
115 | + /** |
|
116 | + * @param $value |
|
117 | + */ |
|
118 | + public function noAdminSizeCheck($value) |
|
119 | + { |
|
120 | + $this->noAdminSizeCheck = $value; |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Is the file the right size? |
|
125 | - * |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - public function checkMaxFileSize() |
|
129 | - { |
|
130 | - if ($this->noAdminSizeCheck) { |
|
131 | - return true; |
|
132 | - } |
|
133 | - if ($this->mediaSize > $this->maxFileSize) { |
|
134 | - return false; |
|
135 | - } |
|
123 | + /** |
|
124 | + * Is the file the right size? |
|
125 | + * |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + public function checkMaxFileSize() |
|
129 | + { |
|
130 | + if ($this->noAdminSizeCheck) { |
|
131 | + return true; |
|
132 | + } |
|
133 | + if ($this->mediaSize > $this->maxFileSize) { |
|
134 | + return false; |
|
135 | + } |
|
136 | 136 | |
137 | - return true; |
|
138 | - } |
|
137 | + return true; |
|
138 | + } |
|
139 | 139 | } |
@@ -17,31 +17,31 @@ discard block |
||
17 | 17 | include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
18 | 18 | |
19 | 19 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
20 | - define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
20 | + define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
21 | 21 | } |
22 | 22 | if (!defined('XOBJ_DTYPE_CURRENCY')) { |
23 | - define('XOBJ_DTYPE_CURRENCY', 200); |
|
23 | + define('XOBJ_DTYPE_CURRENCY', 200); |
|
24 | 24 | } |
25 | 25 | if (!defined('XOBJ_DTYPE_FLOAT')) { |
26 | - define('XOBJ_DTYPE_FLOAT', 201); |
|
26 | + define('XOBJ_DTYPE_FLOAT', 201); |
|
27 | 27 | } |
28 | 28 | if (!defined('XOBJ_DTYPE_TIME_ONLY')) { |
29 | - define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
29 | + define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
30 | 30 | } |
31 | 31 | if (!defined('XOBJ_DTYPE_URLLINK')) { |
32 | - define('XOBJ_DTYPE_URLLINK', 203); |
|
32 | + define('XOBJ_DTYPE_URLLINK', 203); |
|
33 | 33 | } |
34 | 34 | if (!defined('XOBJ_DTYPE_FILE')) { |
35 | - define('XOBJ_DTYPE_FILE', 204); |
|
35 | + define('XOBJ_DTYPE_FILE', 204); |
|
36 | 36 | } |
37 | 37 | if (!defined('XOBJ_DTYPE_IMAGE')) { |
38 | - define('XOBJ_DTYPE_IMAGE', 205); |
|
38 | + define('XOBJ_DTYPE_IMAGE', 205); |
|
39 | 39 | } |
40 | 40 | if (!defined('XOBJ_DTYPE_FORM_SECTION')) { |
41 | - define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
41 | + define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
42 | 42 | } |
43 | 43 | if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) { |
44 | - define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
44 | + define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -55,1355 +55,1355 @@ discard block |
||
55 | 55 | */ |
56 | 56 | class SmartObject extends XoopsObject |
57 | 57 | { |
58 | - public $_image_path; |
|
59 | - public $_image_url; |
|
60 | - |
|
61 | - public $seoEnabled = false; |
|
62 | - public $titleField; |
|
63 | - public $summaryField = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Reference to the handler managing this object |
|
67 | - * |
|
68 | - * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
69 | - */ |
|
70 | - public $handler; |
|
71 | - |
|
72 | - /** |
|
73 | - * References to control objects, managing the form fields of this object |
|
74 | - */ |
|
75 | - public $controls = array(); |
|
76 | - |
|
77 | - /** |
|
78 | - * SmartObject constructor. |
|
79 | - * @param $handler |
|
80 | - */ |
|
81 | - public function __construct($handler) |
|
82 | - { |
|
83 | - $this->handler = $handler; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Checks if the user has a specific access on this object |
|
88 | - * |
|
89 | - * @param $perm_name |
|
90 | - * @return bool: TRUE if user has access, false if not |
|
91 | - * @internal param string $gperm_name name of the permission to test |
|
92 | - */ |
|
93 | - public function accessGranted($perm_name) |
|
94 | - { |
|
95 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
96 | - |
|
97 | - return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param $section_name |
|
102 | - * @param bool $value |
|
103 | - * @param bool $hide |
|
104 | - */ |
|
105 | - public function addFormSection($section_name, $value = false, $hide = false) |
|
106 | - { |
|
107 | - $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
108 | - $this->vars[$section_name]['hide'] = $hide; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param $section_name |
|
113 | - */ |
|
114 | - public function closeSection($section_name) |
|
115 | - { |
|
116 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * |
|
121 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
122 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
123 | - * @param mixed $value default value of this variable |
|
124 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
125 | - * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
126 | - * @param string $options does this data have any select options? |
|
127 | - * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
128 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
129 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
130 | - * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
131 | - * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
132 | - * @param bool $displayOnForm |
|
133 | - */ |
|
134 | - public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false, |
|
135 | - $persistent = true, $displayOnForm = true |
|
136 | - ) { |
|
137 | - //url_ is reserved for files. |
|
138 | - if (0 === strpos($key, 'url_')) { |
|
139 | - trigger_error("Cannot use variable starting with 'url_'."); |
|
140 | - } |
|
141 | - parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
142 | - if ($this->handler && (!$form_caption || $form_caption === '')) { |
|
143 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
144 | - if (defined($dyn_form_caption)) { |
|
145 | - $form_caption = constant($dyn_form_caption); |
|
146 | - } |
|
147 | - } |
|
148 | - if ($this->handler && (!$form_dsc || $form_dsc === '')) { |
|
149 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
150 | - if (defined($dyn_form_dsc)) { |
|
151 | - $form_dsc = constant($dyn_form_dsc); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - $this->vars[$key] = array_merge($this->vars[$key], array( |
|
156 | - 'multilingual' => $multilingual, |
|
157 | - 'form_caption' => $form_caption, |
|
158 | - 'form_dsc' => $form_dsc, |
|
159 | - 'sortby' => $sortby, |
|
160 | - 'persistent' => $persistent, |
|
161 | - 'displayOnForm' => $displayOnForm, |
|
162 | - 'displayOnSingleView' => true, |
|
163 | - 'readonly' => false |
|
164 | - )); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param $key |
|
169 | - * @param $data_type |
|
170 | - * @param bool $itemName |
|
171 | - * @param string $form_caption |
|
172 | - * @param bool $sortby |
|
173 | - * @param string $value |
|
174 | - * @param bool $displayOnForm |
|
175 | - * @param bool $required |
|
176 | - */ |
|
177 | - public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false) |
|
178 | - { |
|
179 | - $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
180 | - $this->vars[$key]['itemName'] = $itemName; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Quickly initiate a var |
|
185 | - * |
|
186 | - * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
187 | - * |
|
188 | - * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
189 | - * - all other vars are NULL or '' depending of the parameter |
|
190 | - * |
|
191 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
192 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
193 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
194 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
195 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
196 | - * @param mixed $value default value of this variable |
|
197 | - */ |
|
198 | - public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null) |
|
199 | - { |
|
200 | - $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
201 | - $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @param $varname |
|
206 | - * @param bool $displayOnForm |
|
207 | - * @param string $default |
|
208 | - */ |
|
209 | - public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
210 | - { |
|
211 | - switch ($varname) { |
|
212 | - case 'dohtml': |
|
213 | - $value = $default !== 'notdefined' ? $default : true; |
|
214 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
215 | - $this->setControl($varname, 'yesno'); |
|
216 | - break; |
|
217 | - |
|
218 | - case 'dobr': |
|
219 | - $value = ($default === 'notdefined') ? true : $default; |
|
220 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
221 | - $this->setControl($varname, 'yesno'); |
|
222 | - break; |
|
223 | - |
|
224 | - case 'doimage': |
|
225 | - $value = $default !== 'notdefined' ? $default : true; |
|
226 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
227 | - $this->setControl($varname, 'yesno'); |
|
228 | - break; |
|
229 | - |
|
230 | - case 'dosmiley': |
|
231 | - $value = $default !== 'notdefined' ? $default : true; |
|
232 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
233 | - $this->setControl($varname, 'yesno'); |
|
234 | - break; |
|
235 | - |
|
236 | - case 'doxcode': |
|
237 | - $value = $default !== 'notdefined' ? $default : true; |
|
238 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
239 | - $this->setControl($varname, 'yesno'); |
|
240 | - break; |
|
241 | - |
|
242 | - case 'meta_keywords': |
|
243 | - $value = $default !== 'notdefined' ? $default : ''; |
|
244 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
245 | - $this->setControl('meta_keywords', array( |
|
246 | - 'name' => 'textarea', |
|
247 | - 'form_editor' => 'textarea' |
|
248 | - )); |
|
249 | - break; |
|
250 | - |
|
251 | - case 'meta_description': |
|
252 | - $value = $default !== 'notdefined' ? $default : ''; |
|
253 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
254 | - $this->setControl('meta_description', array( |
|
255 | - 'name' => 'textarea', |
|
256 | - 'form_editor' => 'textarea' |
|
257 | - )); |
|
258 | - break; |
|
259 | - |
|
260 | - case 'short_url': |
|
261 | - $value = $default !== 'notdefined' ? $default : ''; |
|
262 | - $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
263 | - break; |
|
264 | - |
|
265 | - case 'hierarchy_path': |
|
266 | - $value = $default !== 'notdefined' ? $default : ''; |
|
267 | - $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'counter': |
|
271 | - $value = $default !== 'notdefined' ? $default : 0; |
|
272 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
273 | - break; |
|
274 | - |
|
275 | - case 'weight': |
|
276 | - $value = $default !== 'notdefined' ? $default : 0; |
|
277 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
278 | - break; |
|
279 | - case 'custom_css': |
|
280 | - $value = $default !== 'notdefined' ? $default : ''; |
|
281 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
282 | - $this->setControl('custom_css', array( |
|
283 | - 'name' => 'textarea', |
|
284 | - 'form_editor' => 'textarea' |
|
285 | - )); |
|
286 | - break; |
|
287 | - } |
|
288 | - $this->hideFieldFromSingleView($varname); |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Set control information for an instance variable |
|
293 | - * |
|
294 | - * The $options parameter can be a string or an array. Using a string |
|
295 | - * is the quickest way: |
|
296 | - * |
|
297 | - * $this->setControl('date', 'date_time'); |
|
298 | - * |
|
299 | - * This will create a date and time selectbox for the 'date' var on the |
|
300 | - * form to edit or create this item. |
|
301 | - * |
|
302 | - * Here are the currently supported controls: |
|
303 | - * |
|
304 | - * - color |
|
305 | - * - country |
|
306 | - * - date_time |
|
307 | - * - date |
|
308 | ||
309 | - * - group |
|
310 | - * - group_multi |
|
311 | - * - image |
|
312 | - * - imageupload |
|
313 | - * - label |
|
314 | - * - language |
|
315 | - * - parentcategory |
|
316 | - * - password |
|
317 | - * - select_multi |
|
318 | - * - select |
|
319 | - * - text |
|
320 | - * - textarea |
|
321 | - * - theme |
|
322 | - * - theme_multi |
|
323 | - * - timezone |
|
324 | - * - user |
|
325 | - * - user_multi |
|
326 | - * - yesno |
|
327 | - * |
|
328 | - * Now, using an array as $options, you can customize what information to |
|
329 | - * use in the control. For example, if one needs to display a select box for |
|
330 | - * the user to choose the status of an item. We only need to tell SmartObject |
|
331 | - * what method to execute within what handler to retreive the options of the |
|
332 | - * selectbox. |
|
333 | - * |
|
334 | - * $this->setControl('status', array('name' => false, |
|
335 | - * 'itemHandler' => 'item', |
|
336 | - * 'method' => 'getStatus', |
|
337 | - * 'module' => 'smartshop')); |
|
338 | - * |
|
339 | - * In this example, the array elements are the following: |
|
340 | - * - name: false, as we don't need to set a special control here. |
|
341 | - * we will use the default control related to the object type (defined in initVar) |
|
342 | - * - itemHandler: name of the object for which we will use the handler |
|
343 | - * - method: name of the method of this handler that we will execute |
|
344 | - * - module: name of the module from wich the handler is |
|
345 | - * |
|
346 | - * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
347 | - * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
348 | - * |
|
349 | - * Another example of the use of $options as an array is for TextArea: |
|
350 | - * |
|
351 | - * $this->setControl('body', array('name' => 'textarea', |
|
352 | - * 'form_editor' => 'default')); |
|
353 | - * |
|
354 | - * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
355 | - * the 'default' editor, providing it is defined in the module |
|
356 | - * preferences: $xoopsModuleConfig['default_editor'] |
|
357 | - * |
|
358 | - * Of course, you can force the use of a specific editor: |
|
359 | - * |
|
360 | - * $this->setControl('body', array('name' => 'textarea', |
|
361 | - * 'form_editor' => 'koivi')); |
|
362 | - * |
|
363 | - * Here is a list of supported editor: |
|
364 | - * - tiny: TinyEditor |
|
365 | - * - dhtmltextarea: XOOPS DHTML Area |
|
366 | - * - fckeditor: FCKEditor |
|
367 | - * - inbetween: InBetween |
|
368 | - * - koivi: Koivi |
|
369 | - * - spaw: Spaw WYSIWYG Editor |
|
370 | - * - htmlarea: HTMLArea |
|
371 | - * - textarea: basic textarea with no options |
|
372 | - * |
|
373 | - * @param string $var name of the variable for which we want to set a control |
|
374 | - * @param array $options |
|
375 | - */ |
|
376 | - public function setControl($var, $options = array()) |
|
377 | - { |
|
378 | - if (isset($this->controls[$var])) { |
|
379 | - unset($this->controls[$var]); |
|
380 | - } |
|
381 | - if (is_string($options)) { |
|
382 | - $options = array('name' => $options); |
|
383 | - } |
|
384 | - $this->controls[$var] = $options; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Get control information for an instance variable |
|
389 | - * |
|
390 | - * @param string $var |
|
391 | - * @return bool|mixed |
|
392 | - */ |
|
393 | - public function getControl($var) |
|
394 | - { |
|
395 | - return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Create the form for this object |
|
400 | - * |
|
401 | - * @param $form_caption |
|
402 | - * @param $form_name |
|
403 | - * @param bool $form_action |
|
404 | - * @param string $submit_button_caption |
|
405 | - * @param bool $cancel_js_action |
|
406 | - * @param bool $captcha |
|
407 | - * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
408 | - * object for this object |
|
409 | - * @see SmartObjectForm::SmartObjectForm() |
|
410 | - */ |
|
411 | - public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false) |
|
412 | - { |
|
413 | - include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
414 | - $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
415 | - |
|
416 | - return $form; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * @return array |
|
421 | - */ |
|
422 | - public function toArray() |
|
423 | - { |
|
424 | - $ret = array(); |
|
425 | - $vars =& $this->getVars(); |
|
426 | - foreach ($vars as $key => $var) { |
|
427 | - $value = $this->getVar($key); |
|
428 | - $ret[$key] = $value; |
|
429 | - } |
|
430 | - if ($this->handler->identifierName !== '') { |
|
431 | - $controller = new SmartObjectController($this->handler); |
|
432 | - /** |
|
433 | - * Addition of some automatic value |
|
434 | - */ |
|
435 | - $ret['itemLink'] = $controller->getItemLink($this); |
|
436 | - $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
437 | - $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
438 | - $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
439 | - $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
440 | - } |
|
441 | - |
|
442 | - // Hightlighting searched words |
|
443 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'); |
|
444 | - $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
445 | - |
|
446 | - if ($highlight && isset($_GET['keywords'])) { |
|
447 | - $myts = MyTextSanitizer::getInstance(); |
|
448 | - $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
449 | - $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
450 | - foreach ($this->handler->highlightFields as $field) { |
|
451 | - $ret[$field] = $h->highlight($ret[$field]); |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - return $ret; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * add an error |
|
460 | - * |
|
461 | - * @param $err_str |
|
462 | - * @param bool $prefix |
|
463 | - * @internal param string $value error to add |
|
464 | - * @access public |
|
465 | - */ |
|
466 | - public function setErrors($err_str, $prefix = false) |
|
467 | - { |
|
468 | - if (is_array($err_str)) { |
|
469 | - foreach ($err_str as $str) { |
|
470 | - $this->setErrors($str, $prefix); |
|
471 | - } |
|
472 | - } else { |
|
473 | - if ($prefix) { |
|
474 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
475 | - } |
|
476 | - parent::setErrors($err_str); |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * @param $field |
|
482 | - * @param bool $required |
|
483 | - */ |
|
484 | - public function setFieldAsRequired($field, $required = true) |
|
485 | - { |
|
486 | - if (is_array($field)) { |
|
487 | - foreach ($field as $v) { |
|
488 | - $this->doSetFieldAsRequired($v, $required); |
|
489 | - } |
|
490 | - } else { |
|
491 | - $this->doSetFieldAsRequired($field, $required); |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * @param $field |
|
497 | - */ |
|
498 | - public function setFieldForSorting($field) |
|
499 | - { |
|
500 | - if (is_array($field)) { |
|
501 | - foreach ($field as $v) { |
|
502 | - $this->doSetFieldForSorting($v); |
|
503 | - } |
|
504 | - } else { |
|
505 | - $this->doSetFieldForSorting($field); |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * @return bool |
|
511 | - */ |
|
512 | - public function hasError() |
|
513 | - { |
|
514 | - return count($this->_errors) > 0; |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * @param $url |
|
519 | - * @param $path |
|
520 | - */ |
|
521 | - public function setImageDir($url, $path) |
|
522 | - { |
|
523 | - $this->_image_url = $url; |
|
524 | - $this->_image_path = $path; |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Retreive the group that have been granted access to a specific permission for this object |
|
529 | - * |
|
530 | - * @param $group_perm |
|
531 | - * @return string $group_perm name of the permission |
|
532 | - */ |
|
533 | - public function getGroupPerm($group_perm) |
|
534 | - { |
|
535 | - if (!$this->handler->getPermissions()) { |
|
536 | - $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
537 | - |
|
538 | - return false; |
|
539 | - } |
|
540 | - |
|
541 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
542 | - $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
543 | - |
|
544 | - if (count($ret) == 0) { |
|
545 | - return false; |
|
546 | - } else { |
|
547 | - return $ret; |
|
548 | - } |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * @param bool $path |
|
553 | - * @return mixed |
|
554 | - */ |
|
555 | - public function getImageDir($path = false) |
|
556 | - { |
|
557 | - if ($path) { |
|
558 | - return $this->_image_path; |
|
559 | - } else { |
|
560 | - return $this->_image_url; |
|
561 | - } |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * @param bool $path |
|
566 | - * @return mixed |
|
567 | - */ |
|
568 | - public function getUploadDir($path = false) |
|
569 | - { |
|
570 | - if ($path) { |
|
571 | - return $this->_image_path; |
|
572 | - } else { |
|
573 | - return $this->_image_url; |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * @param string $key |
|
579 | - * @param string $info |
|
580 | - * @return array |
|
581 | - */ |
|
582 | - public function getVarInfo($key = '', $info = '') |
|
583 | - { |
|
584 | - if (isset($this->vars[$key][$info])) { |
|
585 | - return $this->vars[$key][$info]; |
|
586 | - } elseif ($info === '' && isset($this->vars[$key])) { |
|
587 | - return $this->vars[$key]; |
|
588 | - } else { |
|
589 | - return $this->vars; |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Get the id of the object |
|
595 | - * |
|
596 | - * @return int id of this object |
|
597 | - */ |
|
598 | - public function id() |
|
599 | - { |
|
600 | - return $this->getVar($this->handler->keyName, 'e'); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Return the value of the title field of this object |
|
605 | - * |
|
606 | - * @param string $format |
|
607 | - * @return string |
|
608 | - */ |
|
609 | - public function title($format = 's') |
|
610 | - { |
|
611 | - return $this->getVar($this->handler->identifierName, $format); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Return the value of the title field of this object |
|
616 | - * |
|
617 | - * @return string |
|
618 | - */ |
|
619 | - public function summary() |
|
620 | - { |
|
621 | - if ($this->handler->summaryName) { |
|
622 | - return $this->getVar($this->handler->summaryName); |
|
623 | - } else { |
|
624 | - return false; |
|
625 | - } |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Retreive the object admin side link, displayijng a SingleView page |
|
630 | - * |
|
631 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
632 | - * @return string user side link to the object |
|
633 | - */ |
|
634 | - public function getAdminViewItemLink($onlyUrl = false) |
|
635 | - { |
|
636 | - $controller = new SmartObjectController($this->handler); |
|
637 | - |
|
638 | - return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * Retreive the object user side link |
|
643 | - * |
|
644 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
645 | - * @return string user side link to the object |
|
646 | - */ |
|
647 | - public function getItemLink($onlyUrl = false) |
|
648 | - { |
|
649 | - $controller = new SmartObjectController($this->handler); |
|
650 | - |
|
651 | - return $controller->getItemLink($this, $onlyUrl); |
|
652 | - } |
|
653 | - |
|
654 | - /** |
|
655 | - * @param bool $onlyUrl |
|
656 | - * @param bool $withimage |
|
657 | - * @param bool $userSide |
|
658 | - * @return string |
|
659 | - */ |
|
660 | - public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
661 | - { |
|
662 | - $controller = new SmartObjectController($this->handler); |
|
663 | - |
|
664 | - return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * @param bool $onlyUrl |
|
669 | - * @param bool $withimage |
|
670 | - * @param bool $userSide |
|
671 | - * @return string |
|
672 | - */ |
|
673 | - public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
674 | - { |
|
675 | - $controller = new SmartObjectController($this->handler); |
|
676 | - |
|
677 | - return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * @return string |
|
682 | - */ |
|
683 | - public function getPrintAndMailLink() |
|
684 | - { |
|
685 | - $controller = new SmartObjectController($this->handler); |
|
686 | - |
|
687 | - return $controller->getPrintAndMailLink($this); |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * @param $sortsel |
|
692 | - * @return array|bool |
|
693 | - */ |
|
694 | - public function getFieldsForSorting($sortsel) |
|
695 | - { |
|
696 | - $ret = array(); |
|
697 | - |
|
698 | - foreach ($this->vars as $key => $field_info) { |
|
699 | - if ($field_info['sortby']) { |
|
700 | - $ret[$key]['caption'] = $field_info['form_caption']; |
|
701 | - $ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : ''; |
|
702 | - } |
|
703 | - } |
|
704 | - |
|
705 | - if (count($ret) > 0) { |
|
706 | - return $ret; |
|
707 | - } else { |
|
708 | - return false; |
|
709 | - } |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * @param $key |
|
714 | - * @param $newType |
|
715 | - */ |
|
716 | - public function setType($key, $newType) |
|
717 | - { |
|
718 | - $this->vars[$key]['data_type'] = $newType; |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * @param $key |
|
723 | - * @param $info |
|
724 | - * @param $value |
|
725 | - */ |
|
726 | - public function setVarInfo($key, $info, $value) |
|
727 | - { |
|
728 | - $this->vars[$key][$info] = $value; |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * @param $key |
|
733 | - * @param bool $editor |
|
734 | - * @return string |
|
735 | - */ |
|
736 | - public function getValueFor($key, $editor = true) |
|
737 | - { |
|
738 | - global $xoopsModuleConfig; |
|
739 | - |
|
740 | - $ret = $this->getVar($key, 'n'); |
|
741 | - $myts = MyTextSanitizer::getInstance(); |
|
742 | - |
|
743 | - $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
744 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
745 | - |
|
746 | - $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
747 | - $smiley = true; |
|
748 | - $xcode = true; |
|
749 | - $image = true; |
|
750 | - $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
751 | - $formatML = true; |
|
752 | - |
|
753 | - if ($form_editor === 'default') { |
|
754 | - global $xoopsModuleConfig; |
|
755 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
756 | - } |
|
757 | - |
|
758 | - if ($editor) { |
|
759 | - if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
760 | - $br = false; |
|
761 | - $formatML = !$editor; |
|
762 | - } else { |
|
763 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - if (method_exists($myts, 'formatForML')) { |
|
768 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
769 | - } else { |
|
770 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
771 | - } |
|
772 | - } |
|
773 | - |
|
774 | - /** |
|
775 | - * clean values of all variables of the object for storage. |
|
776 | - * also add slashes whereever needed |
|
777 | - * |
|
778 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
779 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
780 | - * as a string separated by | |
|
781 | - * |
|
782 | - * @return bool true if successful |
|
783 | - * @access public |
|
784 | - */ |
|
785 | - public function cleanVars() |
|
786 | - { |
|
787 | - $ts = MyTextSanitizer::getInstance(); |
|
788 | - $existing_errors = $this->getErrors(); |
|
789 | - $this->_errors = array(); |
|
790 | - foreach ($this->vars as $k => $v) { |
|
791 | - $cleanv = $v['value']; |
|
792 | - if (!$v['changed']) { |
|
793 | - } else { |
|
794 | - $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
795 | - switch ($v['data_type']) { |
|
796 | - case XOBJ_DTYPE_TXTBOX: |
|
797 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
798 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
799 | - continue 2; |
|
800 | - } |
|
801 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
802 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
803 | - continue 2; |
|
804 | - } |
|
805 | - if (!$v['not_gpc']) { |
|
806 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
807 | - } else { |
|
808 | - $cleanv = $ts->censorString($cleanv); |
|
809 | - } |
|
810 | - break; |
|
811 | - case XOBJ_DTYPE_TXTAREA: |
|
812 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
813 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
814 | - continue 2; |
|
815 | - } |
|
816 | - if (!$v['not_gpc']) { |
|
817 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
818 | - } else { |
|
819 | - $cleanv = $ts->censorString($cleanv); |
|
820 | - } |
|
821 | - break; |
|
822 | - case XOBJ_DTYPE_SOURCE: |
|
823 | - if (!$v['not_gpc']) { |
|
824 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
825 | - } else { |
|
826 | - $cleanv = $cleanv; |
|
827 | - } |
|
828 | - break; |
|
829 | - case XOBJ_DTYPE_INT: |
|
830 | - case XOBJ_DTYPE_TIME_ONLY: |
|
831 | - $cleanv = (int)$cleanv; |
|
832 | - break; |
|
833 | - |
|
834 | - case XOBJ_DTYPE_CURRENCY: |
|
835 | - $cleanv = smart_currency($cleanv); |
|
836 | - break; |
|
837 | - |
|
838 | - case XOBJ_DTYPE_FLOAT: |
|
839 | - $cleanv = smart_float($cleanv); |
|
840 | - break; |
|
841 | - |
|
842 | - case XOBJ_DTYPE_EMAIL: |
|
843 | - if ($v['required'] && $cleanv === '') { |
|
844 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
845 | - continue 2; |
|
846 | - } |
|
847 | - if ($cleanv !== '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
848 | - $this->setErrors('Invalid Email'); |
|
849 | - continue 2; |
|
850 | - } |
|
851 | - if (!$v['not_gpc']) { |
|
852 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
853 | - } |
|
854 | - break; |
|
855 | - case XOBJ_DTYPE_URL: |
|
856 | - if ($v['required'] && $cleanv === '') { |
|
857 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
858 | - continue 2; |
|
859 | - } |
|
860 | - if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
861 | - $cleanv = 'http://' . $cleanv; |
|
862 | - } |
|
863 | - if (!$v['not_gpc']) { |
|
864 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
865 | - } |
|
866 | - break; |
|
867 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
868 | - $cleanv = implode('|', $cleanv); |
|
869 | - break; |
|
870 | - case XOBJ_DTYPE_ARRAY: |
|
871 | - $cleanv = serialize($cleanv); |
|
872 | - break; |
|
873 | - case XOBJ_DTYPE_STIME: |
|
874 | - case XOBJ_DTYPE_MTIME: |
|
875 | - case XOBJ_DTYPE_LTIME: |
|
876 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
877 | - if (!($cleanv > 0)) { |
|
878 | - $cleanv = strtotime($cleanv); |
|
879 | - } |
|
880 | - break; |
|
881 | - default: |
|
882 | - break; |
|
883 | - } |
|
884 | - } |
|
885 | - $this->cleanVars[$k] =& $cleanv; |
|
886 | - unset($cleanv); |
|
887 | - } |
|
888 | - if (count($this->_errors) > 0) { |
|
889 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
890 | - |
|
891 | - return false; |
|
892 | - } |
|
893 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
894 | - $this->unsetDirty(); |
|
895 | - |
|
896 | - return true; |
|
897 | - } |
|
898 | - |
|
899 | - /** |
|
900 | - * returns a specific variable for the object in a proper format |
|
901 | - * |
|
902 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
903 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
904 | - * as a string separated by | |
|
905 | - * |
|
906 | - * @access public |
|
907 | - * @param string $key key of the object's variable to be returned |
|
908 | - * @param string $format format to use for the output |
|
909 | - * @return mixed formatted value of the variable |
|
910 | - */ |
|
911 | - public function getVar($key, $format = 's') |
|
912 | - { |
|
913 | - global $myts; |
|
914 | - |
|
915 | - $ret = $this->vars[$key]['value']; |
|
916 | - |
|
917 | - switch ($this->vars[$key]['data_type']) { |
|
918 | - |
|
919 | - case XOBJ_DTYPE_TXTBOX: |
|
920 | - switch (strtolower($format)) { |
|
921 | - case 's': |
|
922 | - case 'show': |
|
923 | - // ML Hack by marcan |
|
924 | - $ts = MyTextSanitizer::getInstance(); |
|
925 | - $ret = $ts->htmlSpecialChars($ret); |
|
926 | - |
|
927 | - if (method_exists($myts, 'formatForML')) { |
|
928 | - return $ts->formatForML($ret); |
|
929 | - } else { |
|
930 | - return $ret; |
|
931 | - } |
|
932 | - break 1; |
|
933 | - // End of ML Hack by marcan |
|
934 | - |
|
935 | - case 'clean': |
|
936 | - $ts = MyTextSanitizer::getInstance(); |
|
937 | - |
|
938 | - $ret = smart_html2text($ret); |
|
939 | - $ret = smart_purifyText($ret); |
|
940 | - |
|
941 | - if (method_exists($myts, 'formatForML')) { |
|
942 | - return $ts->formatForML($ret); |
|
943 | - } else { |
|
944 | - return $ret; |
|
945 | - } |
|
946 | - break 1; |
|
947 | - // End of ML Hack by marcan |
|
948 | - |
|
949 | - case 'e': |
|
950 | - case 'edit': |
|
951 | - $ts = MyTextSanitizer::getInstance(); |
|
952 | - |
|
953 | - return $ts->htmlSpecialChars($ret); |
|
954 | - break 1; |
|
955 | - case 'p': |
|
956 | - case 'preview': |
|
957 | - case 'f': |
|
958 | - case 'formpreview': |
|
959 | - $ts = MyTextSanitizer::getInstance(); |
|
960 | - |
|
961 | - return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
962 | - break 1; |
|
963 | - case 'n': |
|
964 | - case 'none': |
|
965 | - default: |
|
966 | - break 1; |
|
967 | - } |
|
968 | - break; |
|
969 | - case XOBJ_DTYPE_LTIME: |
|
970 | - switch (strtolower($format)) { |
|
971 | - case 's': |
|
972 | - case 'show': |
|
973 | - case 'p': |
|
974 | - case 'preview': |
|
975 | - case 'f': |
|
976 | - case 'formpreview': |
|
977 | - $ret = formatTimestamp($ret, _DATESTRING); |
|
978 | - |
|
979 | - return $ret; |
|
980 | - break 1; |
|
981 | - case 'n': |
|
982 | - case 'none': |
|
983 | - case 'e': |
|
984 | - case 'edit': |
|
985 | - break 1; |
|
986 | - default: |
|
987 | - break 1; |
|
988 | - } |
|
989 | - break; |
|
990 | - case XOBJ_DTYPE_STIME: |
|
991 | - switch (strtolower($format)) { |
|
992 | - case 's': |
|
993 | - case 'show': |
|
994 | - case 'p': |
|
995 | - case 'preview': |
|
996 | - case 'f': |
|
997 | - case 'formpreview': |
|
998 | - $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
999 | - |
|
1000 | - return $ret; |
|
1001 | - break 1; |
|
1002 | - case 'n': |
|
1003 | - case 'none': |
|
1004 | - case 'e': |
|
1005 | - case 'edit': |
|
1006 | - break 1; |
|
1007 | - default: |
|
1008 | - break 1; |
|
1009 | - } |
|
1010 | - break; |
|
1011 | - case XOBJ_DTYPE_TIME_ONLY: |
|
1012 | - switch (strtolower($format)) { |
|
1013 | - case 's': |
|
1014 | - case 'show': |
|
1015 | - case 'p': |
|
1016 | - case 'preview': |
|
1017 | - case 'f': |
|
1018 | - case 'formpreview': |
|
1019 | - $ret = formatTimestamp($ret, 'G:i'); |
|
1020 | - |
|
1021 | - return $ret; |
|
1022 | - break 1; |
|
1023 | - case 'n': |
|
1024 | - case 'none': |
|
1025 | - case 'e': |
|
1026 | - case 'edit': |
|
1027 | - break 1; |
|
1028 | - default: |
|
1029 | - break 1; |
|
1030 | - } |
|
1031 | - break; |
|
1032 | - |
|
1033 | - case XOBJ_DTYPE_CURRENCY: |
|
1034 | - $decimal_section_original = strstr($ret, '.'); |
|
1035 | - $decimal_section = $decimal_section_original; |
|
1036 | - if ($decimal_section) { |
|
1037 | - if (strlen($decimal_section) == 1) { |
|
1038 | - $decimal_section = '.00'; |
|
1039 | - } elseif (strlen($decimal_section) == 2) { |
|
1040 | - $decimal_section .= '0'; |
|
1041 | - } |
|
1042 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1043 | - } else { |
|
1044 | - $ret .= '.00'; |
|
1045 | - } |
|
1046 | - break; |
|
1047 | - |
|
1048 | - case XOBJ_DTYPE_TXTAREA: |
|
1049 | - switch (strtolower($format)) { |
|
1050 | - case 's': |
|
1051 | - case 'show': |
|
1052 | - $ts = MyTextSanitizer::getInstance(); |
|
1053 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1054 | - |
|
1055 | - $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1056 | - |
|
1057 | - $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1058 | - $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1059 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * Hack by marcan <INBOX> for SCSPRO |
|
1063 | - * Setting mastop as the main editor |
|
1064 | - */ |
|
1065 | - if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1066 | - $br = false; |
|
1067 | - } |
|
1068 | - /** |
|
1069 | - * Hack by marcan <INBOX> for SCSPRO |
|
1070 | - * Setting mastop as the main editor |
|
1071 | - */ |
|
1072 | - |
|
1073 | - return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1074 | - break 1; |
|
1075 | - case 'e': |
|
1076 | - case 'edit': |
|
1077 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1078 | - break 1; |
|
1079 | - case 'p': |
|
1080 | - case 'preview': |
|
1081 | - $ts = MyTextSanitizer::getInstance(); |
|
1082 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1083 | - $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1084 | - $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1085 | - $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1086 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1087 | - |
|
1088 | - return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1089 | - break 1; |
|
1090 | - case 'f': |
|
1091 | - case 'formpreview': |
|
1092 | - $ts = MyTextSanitizer::getInstance(); |
|
1093 | - |
|
1094 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1095 | - break 1; |
|
1096 | - case 'n': |
|
1097 | - case 'none': |
|
1098 | - default: |
|
1099 | - break 1; |
|
1100 | - } |
|
1101 | - break; |
|
1102 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1103 | - $ret =& explode('|', $ret); |
|
1104 | - break; |
|
1105 | - case XOBJ_DTYPE_ARRAY: |
|
1106 | - $ret =& unserialize($ret); |
|
1107 | - break; |
|
1108 | - case XOBJ_DTYPE_SOURCE: |
|
1109 | - switch (strtolower($format)) { |
|
1110 | - case 's': |
|
1111 | - case 'show': |
|
1112 | - break 1; |
|
1113 | - case 'e': |
|
1114 | - case 'edit': |
|
1115 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1116 | - break 1; |
|
1117 | - case 'p': |
|
1118 | - case 'preview': |
|
1119 | - $ts = MyTextSanitizer::getInstance(); |
|
1120 | - |
|
1121 | - return $ts->stripSlashesGPC($ret); |
|
1122 | - break 1; |
|
1123 | - case 'f': |
|
1124 | - case 'formpreview': |
|
1125 | - $ts = MyTextSanitizer::getInstance(); |
|
1126 | - |
|
1127 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1128 | - break 1; |
|
1129 | - case 'n': |
|
1130 | - case 'none': |
|
1131 | - default: |
|
1132 | - break 1; |
|
1133 | - } |
|
1134 | - break; |
|
1135 | - default: |
|
1136 | - if ($this->vars[$key]['options'] !== '' && $ret != '') { |
|
1137 | - switch (strtolower($format)) { |
|
1138 | - case 's': |
|
1139 | - case 'show': |
|
1140 | - $selected = explode('|', $ret); |
|
1141 | - $options = explode('|', $this->vars[$key]['options']); |
|
1142 | - $i = 1; |
|
1143 | - $ret = array(); |
|
1144 | - foreach ($options as $op) { |
|
1145 | - if (in_array($i, $selected)) { |
|
1146 | - $ret[] = $op; |
|
1147 | - } |
|
1148 | - ++$i; |
|
1149 | - } |
|
1150 | - |
|
1151 | - return implode(', ', $ret); |
|
1152 | - case 'e': |
|
1153 | - case 'edit': |
|
1154 | - $ret = explode('|', $ret); |
|
1155 | - break 1; |
|
1156 | - default: |
|
1157 | - break 1; |
|
1158 | - } |
|
1159 | - } |
|
1160 | - break; |
|
1161 | - } |
|
1162 | - |
|
1163 | - return $ret; |
|
1164 | - } |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * @param $key |
|
1168 | - */ |
|
1169 | - public function doMakeFieldreadOnly($key) |
|
1170 | - { |
|
1171 | - if (isset($this->vars[$key])) { |
|
1172 | - $this->vars[$key]['readonly'] = true; |
|
1173 | - $this->vars[$key]['displayOnForm'] = true; |
|
1174 | - } |
|
1175 | - } |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * @param $key |
|
1179 | - */ |
|
1180 | - public function makeFieldReadOnly($key) |
|
1181 | - { |
|
1182 | - if (is_array($key)) { |
|
1183 | - foreach ($key as $v) { |
|
1184 | - $this->doMakeFieldreadOnly($v); |
|
1185 | - } |
|
1186 | - } else { |
|
1187 | - $this->doMakeFieldreadOnly($key); |
|
1188 | - } |
|
1189 | - } |
|
1190 | - |
|
1191 | - /** |
|
1192 | - * @param $key |
|
1193 | - */ |
|
1194 | - public function doHideFieldFromForm($key) |
|
1195 | - { |
|
1196 | - if (isset($this->vars[$key])) { |
|
1197 | - $this->vars[$key]['displayOnForm'] = false; |
|
1198 | - } |
|
1199 | - } |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * @param $key |
|
1203 | - */ |
|
1204 | - public function doHideFieldFromSingleView($key) |
|
1205 | - { |
|
1206 | - if (isset($this->vars[$key])) { |
|
1207 | - $this->vars[$key]['displayOnSingleView'] = false; |
|
1208 | - } |
|
1209 | - } |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * @param $key |
|
1213 | - */ |
|
1214 | - public function hideFieldFromForm($key) |
|
1215 | - { |
|
1216 | - if (is_array($key)) { |
|
1217 | - foreach ($key as $v) { |
|
1218 | - $this->doHideFieldFromForm($v); |
|
1219 | - } |
|
1220 | - } else { |
|
1221 | - $this->doHideFieldFromForm($key); |
|
1222 | - } |
|
1223 | - } |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * @param $key |
|
1227 | - */ |
|
1228 | - public function hideFieldFromSingleView($key) |
|
1229 | - { |
|
1230 | - if (is_array($key)) { |
|
1231 | - foreach ($key as $v) { |
|
1232 | - $this->doHideFieldFromSingleView($v); |
|
1233 | - } |
|
1234 | - } else { |
|
1235 | - $this->doHideFieldFromSingleView($key); |
|
1236 | - } |
|
1237 | - } |
|
1238 | - |
|
1239 | - /** |
|
1240 | - * @param $key |
|
1241 | - */ |
|
1242 | - public function doShowFieldOnForm($key) |
|
1243 | - { |
|
1244 | - if (isset($this->vars[$key])) { |
|
1245 | - $this->vars[$key]['displayOnForm'] = true; |
|
1246 | - } |
|
1247 | - } |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1251 | - * |
|
1252 | - * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1253 | - * @param bool $userSide for futur use, to do something different on the user side |
|
1254 | - * @param array $actions |
|
1255 | - * @param bool $headerAsRow |
|
1256 | - * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1257 | - */ |
|
1258 | - public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true) |
|
1259 | - { |
|
1260 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
1261 | - $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
1262 | - // add all fields mark as displayOnSingleView except the keyid |
|
1263 | - foreach ($this->vars as $key => $var) { |
|
1264 | - if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1265 | - $is_header = ($key == $this->handler->identifierName); |
|
1266 | - $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
1267 | - } |
|
1268 | - } |
|
1269 | - |
|
1270 | - if ($fetchOnly) { |
|
1271 | - $ret = $singleview->render($fetchOnly); |
|
1272 | - |
|
1273 | - return $ret; |
|
1274 | - } else { |
|
1275 | - $singleview->render($fetchOnly); |
|
1276 | - } |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * @param $key |
|
1281 | - */ |
|
1282 | - public function doDisplayFieldOnSingleView($key) |
|
1283 | - { |
|
1284 | - if (isset($this->vars[$key])) { |
|
1285 | - $this->vars[$key]['displayOnSingleView'] = true; |
|
1286 | - } |
|
1287 | - } |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * @param $field |
|
1291 | - * @param bool $required |
|
1292 | - */ |
|
1293 | - public function doSetFieldAsRequired($field, $required = true) |
|
1294 | - { |
|
1295 | - $this->setVarInfo($field, 'required', $required); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * @param $field |
|
1300 | - */ |
|
1301 | - public function doSetFieldForSorting($field) |
|
1302 | - { |
|
1303 | - $this->setVarInfo($field, 'sortby', true); |
|
1304 | - } |
|
1305 | - |
|
1306 | - /** |
|
1307 | - * @param $key |
|
1308 | - */ |
|
1309 | - public function showFieldOnForm($key) |
|
1310 | - { |
|
1311 | - if (is_array($key)) { |
|
1312 | - foreach ($key as $v) { |
|
1313 | - $this->doShowFieldOnForm($v); |
|
1314 | - } |
|
1315 | - } else { |
|
1316 | - $this->doShowFieldOnForm($key); |
|
1317 | - } |
|
1318 | - } |
|
1319 | - |
|
1320 | - /** |
|
1321 | - * @param $key |
|
1322 | - */ |
|
1323 | - public function displayFieldOnSingleView($key) |
|
1324 | - { |
|
1325 | - if (is_array($key)) { |
|
1326 | - foreach ($key as $v) { |
|
1327 | - $this->doDisplayFieldOnSingleView($v); |
|
1328 | - } |
|
1329 | - } else { |
|
1330 | - $this->doDisplayFieldOnSingleView($key); |
|
1331 | - } |
|
1332 | - } |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * @param $key |
|
1336 | - */ |
|
1337 | - public function doSetAdvancedFormFields($key) |
|
1338 | - { |
|
1339 | - if (isset($this->vars[$key])) { |
|
1340 | - $this->vars[$key]['advancedform'] = true; |
|
1341 | - } |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * @param $key |
|
1346 | - */ |
|
1347 | - public function setAdvancedFormFields($key) |
|
1348 | - { |
|
1349 | - if (is_array($key)) { |
|
1350 | - foreach ($key as $v) { |
|
1351 | - $this->doSetAdvancedFormFields($v); |
|
1352 | - } |
|
1353 | - } else { |
|
1354 | - $this->doSetAdvancedFormFields($key); |
|
1355 | - } |
|
1356 | - } |
|
1357 | - |
|
1358 | - /** |
|
1359 | - * @param $key |
|
1360 | - * @return mixed |
|
1361 | - */ |
|
1362 | - public function getUrlLinkObj($key) |
|
1363 | - { |
|
1364 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1365 | - $urllinkid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1366 | - if ($urllinkid != 0) { |
|
1367 | - return $smartobjectLinkurlHandler->get($urllinkid); |
|
1368 | - } else { |
|
1369 | - return $smartobjectLinkurlHandler->create(); |
|
1370 | - } |
|
1371 | - } |
|
1372 | - |
|
1373 | - /** |
|
1374 | - * @param $urlLinkObj |
|
1375 | - * @return mixed |
|
1376 | - */ |
|
1377 | - public function &storeUrlLinkObj($urlLinkObj) |
|
1378 | - { |
|
1379 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1380 | - |
|
1381 | - return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1382 | - } |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * @param $key |
|
1386 | - * @return mixed |
|
1387 | - */ |
|
1388 | - public function getFileObj($key) |
|
1389 | - { |
|
1390 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1391 | - $fileid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1392 | - if ($fileid != 0) { |
|
1393 | - return $smartobjectFileHandler->get($fileid); |
|
1394 | - } else { |
|
1395 | - return $smartobjectFileHandler->create(); |
|
1396 | - } |
|
1397 | - } |
|
1398 | - |
|
1399 | - /** |
|
1400 | - * @param $fileObj |
|
1401 | - * @return mixed |
|
1402 | - */ |
|
1403 | - public function &storeFileObj($fileObj) |
|
1404 | - { |
|
1405 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1406 | - |
|
1407 | - return $smartobjectFileHandler->insert($fileObj); |
|
1408 | - } |
|
58 | + public $_image_path; |
|
59 | + public $_image_url; |
|
60 | + |
|
61 | + public $seoEnabled = false; |
|
62 | + public $titleField; |
|
63 | + public $summaryField = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Reference to the handler managing this object |
|
67 | + * |
|
68 | + * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
69 | + */ |
|
70 | + public $handler; |
|
71 | + |
|
72 | + /** |
|
73 | + * References to control objects, managing the form fields of this object |
|
74 | + */ |
|
75 | + public $controls = array(); |
|
76 | + |
|
77 | + /** |
|
78 | + * SmartObject constructor. |
|
79 | + * @param $handler |
|
80 | + */ |
|
81 | + public function __construct($handler) |
|
82 | + { |
|
83 | + $this->handler = $handler; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Checks if the user has a specific access on this object |
|
88 | + * |
|
89 | + * @param $perm_name |
|
90 | + * @return bool: TRUE if user has access, false if not |
|
91 | + * @internal param string $gperm_name name of the permission to test |
|
92 | + */ |
|
93 | + public function accessGranted($perm_name) |
|
94 | + { |
|
95 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
96 | + |
|
97 | + return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param $section_name |
|
102 | + * @param bool $value |
|
103 | + * @param bool $hide |
|
104 | + */ |
|
105 | + public function addFormSection($section_name, $value = false, $hide = false) |
|
106 | + { |
|
107 | + $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
108 | + $this->vars[$section_name]['hide'] = $hide; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param $section_name |
|
113 | + */ |
|
114 | + public function closeSection($section_name) |
|
115 | + { |
|
116 | + $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * |
|
121 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
122 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
123 | + * @param mixed $value default value of this variable |
|
124 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
125 | + * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
126 | + * @param string $options does this data have any select options? |
|
127 | + * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
128 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
129 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
130 | + * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
131 | + * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
132 | + * @param bool $displayOnForm |
|
133 | + */ |
|
134 | + public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false, |
|
135 | + $persistent = true, $displayOnForm = true |
|
136 | + ) { |
|
137 | + //url_ is reserved for files. |
|
138 | + if (0 === strpos($key, 'url_')) { |
|
139 | + trigger_error("Cannot use variable starting with 'url_'."); |
|
140 | + } |
|
141 | + parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
142 | + if ($this->handler && (!$form_caption || $form_caption === '')) { |
|
143 | + $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
144 | + if (defined($dyn_form_caption)) { |
|
145 | + $form_caption = constant($dyn_form_caption); |
|
146 | + } |
|
147 | + } |
|
148 | + if ($this->handler && (!$form_dsc || $form_dsc === '')) { |
|
149 | + $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
150 | + if (defined($dyn_form_dsc)) { |
|
151 | + $form_dsc = constant($dyn_form_dsc); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + $this->vars[$key] = array_merge($this->vars[$key], array( |
|
156 | + 'multilingual' => $multilingual, |
|
157 | + 'form_caption' => $form_caption, |
|
158 | + 'form_dsc' => $form_dsc, |
|
159 | + 'sortby' => $sortby, |
|
160 | + 'persistent' => $persistent, |
|
161 | + 'displayOnForm' => $displayOnForm, |
|
162 | + 'displayOnSingleView' => true, |
|
163 | + 'readonly' => false |
|
164 | + )); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param $key |
|
169 | + * @param $data_type |
|
170 | + * @param bool $itemName |
|
171 | + * @param string $form_caption |
|
172 | + * @param bool $sortby |
|
173 | + * @param string $value |
|
174 | + * @param bool $displayOnForm |
|
175 | + * @param bool $required |
|
176 | + */ |
|
177 | + public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false) |
|
178 | + { |
|
179 | + $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
180 | + $this->vars[$key]['itemName'] = $itemName; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Quickly initiate a var |
|
185 | + * |
|
186 | + * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
187 | + * |
|
188 | + * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
189 | + * - all other vars are NULL or '' depending of the parameter |
|
190 | + * |
|
191 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
192 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
193 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
194 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
195 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
196 | + * @param mixed $value default value of this variable |
|
197 | + */ |
|
198 | + public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null) |
|
199 | + { |
|
200 | + $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
201 | + $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @param $varname |
|
206 | + * @param bool $displayOnForm |
|
207 | + * @param string $default |
|
208 | + */ |
|
209 | + public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
210 | + { |
|
211 | + switch ($varname) { |
|
212 | + case 'dohtml': |
|
213 | + $value = $default !== 'notdefined' ? $default : true; |
|
214 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
215 | + $this->setControl($varname, 'yesno'); |
|
216 | + break; |
|
217 | + |
|
218 | + case 'dobr': |
|
219 | + $value = ($default === 'notdefined') ? true : $default; |
|
220 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
221 | + $this->setControl($varname, 'yesno'); |
|
222 | + break; |
|
223 | + |
|
224 | + case 'doimage': |
|
225 | + $value = $default !== 'notdefined' ? $default : true; |
|
226 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
227 | + $this->setControl($varname, 'yesno'); |
|
228 | + break; |
|
229 | + |
|
230 | + case 'dosmiley': |
|
231 | + $value = $default !== 'notdefined' ? $default : true; |
|
232 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
233 | + $this->setControl($varname, 'yesno'); |
|
234 | + break; |
|
235 | + |
|
236 | + case 'doxcode': |
|
237 | + $value = $default !== 'notdefined' ? $default : true; |
|
238 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
239 | + $this->setControl($varname, 'yesno'); |
|
240 | + break; |
|
241 | + |
|
242 | + case 'meta_keywords': |
|
243 | + $value = $default !== 'notdefined' ? $default : ''; |
|
244 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
245 | + $this->setControl('meta_keywords', array( |
|
246 | + 'name' => 'textarea', |
|
247 | + 'form_editor' => 'textarea' |
|
248 | + )); |
|
249 | + break; |
|
250 | + |
|
251 | + case 'meta_description': |
|
252 | + $value = $default !== 'notdefined' ? $default : ''; |
|
253 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
254 | + $this->setControl('meta_description', array( |
|
255 | + 'name' => 'textarea', |
|
256 | + 'form_editor' => 'textarea' |
|
257 | + )); |
|
258 | + break; |
|
259 | + |
|
260 | + case 'short_url': |
|
261 | + $value = $default !== 'notdefined' ? $default : ''; |
|
262 | + $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
263 | + break; |
|
264 | + |
|
265 | + case 'hierarchy_path': |
|
266 | + $value = $default !== 'notdefined' ? $default : ''; |
|
267 | + $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'counter': |
|
271 | + $value = $default !== 'notdefined' ? $default : 0; |
|
272 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
273 | + break; |
|
274 | + |
|
275 | + case 'weight': |
|
276 | + $value = $default !== 'notdefined' ? $default : 0; |
|
277 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
278 | + break; |
|
279 | + case 'custom_css': |
|
280 | + $value = $default !== 'notdefined' ? $default : ''; |
|
281 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
282 | + $this->setControl('custom_css', array( |
|
283 | + 'name' => 'textarea', |
|
284 | + 'form_editor' => 'textarea' |
|
285 | + )); |
|
286 | + break; |
|
287 | + } |
|
288 | + $this->hideFieldFromSingleView($varname); |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Set control information for an instance variable |
|
293 | + * |
|
294 | + * The $options parameter can be a string or an array. Using a string |
|
295 | + * is the quickest way: |
|
296 | + * |
|
297 | + * $this->setControl('date', 'date_time'); |
|
298 | + * |
|
299 | + * This will create a date and time selectbox for the 'date' var on the |
|
300 | + * form to edit or create this item. |
|
301 | + * |
|
302 | + * Here are the currently supported controls: |
|
303 | + * |
|
304 | + * - color |
|
305 | + * - country |
|
306 | + * - date_time |
|
307 | + * - date |
|
308 | ||
309 | + * - group |
|
310 | + * - group_multi |
|
311 | + * - image |
|
312 | + * - imageupload |
|
313 | + * - label |
|
314 | + * - language |
|
315 | + * - parentcategory |
|
316 | + * - password |
|
317 | + * - select_multi |
|
318 | + * - select |
|
319 | + * - text |
|
320 | + * - textarea |
|
321 | + * - theme |
|
322 | + * - theme_multi |
|
323 | + * - timezone |
|
324 | + * - user |
|
325 | + * - user_multi |
|
326 | + * - yesno |
|
327 | + * |
|
328 | + * Now, using an array as $options, you can customize what information to |
|
329 | + * use in the control. For example, if one needs to display a select box for |
|
330 | + * the user to choose the status of an item. We only need to tell SmartObject |
|
331 | + * what method to execute within what handler to retreive the options of the |
|
332 | + * selectbox. |
|
333 | + * |
|
334 | + * $this->setControl('status', array('name' => false, |
|
335 | + * 'itemHandler' => 'item', |
|
336 | + * 'method' => 'getStatus', |
|
337 | + * 'module' => 'smartshop')); |
|
338 | + * |
|
339 | + * In this example, the array elements are the following: |
|
340 | + * - name: false, as we don't need to set a special control here. |
|
341 | + * we will use the default control related to the object type (defined in initVar) |
|
342 | + * - itemHandler: name of the object for which we will use the handler |
|
343 | + * - method: name of the method of this handler that we will execute |
|
344 | + * - module: name of the module from wich the handler is |
|
345 | + * |
|
346 | + * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
347 | + * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
348 | + * |
|
349 | + * Another example of the use of $options as an array is for TextArea: |
|
350 | + * |
|
351 | + * $this->setControl('body', array('name' => 'textarea', |
|
352 | + * 'form_editor' => 'default')); |
|
353 | + * |
|
354 | + * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
355 | + * the 'default' editor, providing it is defined in the module |
|
356 | + * preferences: $xoopsModuleConfig['default_editor'] |
|
357 | + * |
|
358 | + * Of course, you can force the use of a specific editor: |
|
359 | + * |
|
360 | + * $this->setControl('body', array('name' => 'textarea', |
|
361 | + * 'form_editor' => 'koivi')); |
|
362 | + * |
|
363 | + * Here is a list of supported editor: |
|
364 | + * - tiny: TinyEditor |
|
365 | + * - dhtmltextarea: XOOPS DHTML Area |
|
366 | + * - fckeditor: FCKEditor |
|
367 | + * - inbetween: InBetween |
|
368 | + * - koivi: Koivi |
|
369 | + * - spaw: Spaw WYSIWYG Editor |
|
370 | + * - htmlarea: HTMLArea |
|
371 | + * - textarea: basic textarea with no options |
|
372 | + * |
|
373 | + * @param string $var name of the variable for which we want to set a control |
|
374 | + * @param array $options |
|
375 | + */ |
|
376 | + public function setControl($var, $options = array()) |
|
377 | + { |
|
378 | + if (isset($this->controls[$var])) { |
|
379 | + unset($this->controls[$var]); |
|
380 | + } |
|
381 | + if (is_string($options)) { |
|
382 | + $options = array('name' => $options); |
|
383 | + } |
|
384 | + $this->controls[$var] = $options; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Get control information for an instance variable |
|
389 | + * |
|
390 | + * @param string $var |
|
391 | + * @return bool|mixed |
|
392 | + */ |
|
393 | + public function getControl($var) |
|
394 | + { |
|
395 | + return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Create the form for this object |
|
400 | + * |
|
401 | + * @param $form_caption |
|
402 | + * @param $form_name |
|
403 | + * @param bool $form_action |
|
404 | + * @param string $submit_button_caption |
|
405 | + * @param bool $cancel_js_action |
|
406 | + * @param bool $captcha |
|
407 | + * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
408 | + * object for this object |
|
409 | + * @see SmartObjectForm::SmartObjectForm() |
|
410 | + */ |
|
411 | + public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false) |
|
412 | + { |
|
413 | + include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
414 | + $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
415 | + |
|
416 | + return $form; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * @return array |
|
421 | + */ |
|
422 | + public function toArray() |
|
423 | + { |
|
424 | + $ret = array(); |
|
425 | + $vars =& $this->getVars(); |
|
426 | + foreach ($vars as $key => $var) { |
|
427 | + $value = $this->getVar($key); |
|
428 | + $ret[$key] = $value; |
|
429 | + } |
|
430 | + if ($this->handler->identifierName !== '') { |
|
431 | + $controller = new SmartObjectController($this->handler); |
|
432 | + /** |
|
433 | + * Addition of some automatic value |
|
434 | + */ |
|
435 | + $ret['itemLink'] = $controller->getItemLink($this); |
|
436 | + $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
437 | + $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
438 | + $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
439 | + $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
440 | + } |
|
441 | + |
|
442 | + // Hightlighting searched words |
|
443 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'); |
|
444 | + $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
445 | + |
|
446 | + if ($highlight && isset($_GET['keywords'])) { |
|
447 | + $myts = MyTextSanitizer::getInstance(); |
|
448 | + $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
449 | + $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
450 | + foreach ($this->handler->highlightFields as $field) { |
|
451 | + $ret[$field] = $h->highlight($ret[$field]); |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + return $ret; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * add an error |
|
460 | + * |
|
461 | + * @param $err_str |
|
462 | + * @param bool $prefix |
|
463 | + * @internal param string $value error to add |
|
464 | + * @access public |
|
465 | + */ |
|
466 | + public function setErrors($err_str, $prefix = false) |
|
467 | + { |
|
468 | + if (is_array($err_str)) { |
|
469 | + foreach ($err_str as $str) { |
|
470 | + $this->setErrors($str, $prefix); |
|
471 | + } |
|
472 | + } else { |
|
473 | + if ($prefix) { |
|
474 | + $err_str = '[' . $prefix . '] ' . $err_str; |
|
475 | + } |
|
476 | + parent::setErrors($err_str); |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * @param $field |
|
482 | + * @param bool $required |
|
483 | + */ |
|
484 | + public function setFieldAsRequired($field, $required = true) |
|
485 | + { |
|
486 | + if (is_array($field)) { |
|
487 | + foreach ($field as $v) { |
|
488 | + $this->doSetFieldAsRequired($v, $required); |
|
489 | + } |
|
490 | + } else { |
|
491 | + $this->doSetFieldAsRequired($field, $required); |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * @param $field |
|
497 | + */ |
|
498 | + public function setFieldForSorting($field) |
|
499 | + { |
|
500 | + if (is_array($field)) { |
|
501 | + foreach ($field as $v) { |
|
502 | + $this->doSetFieldForSorting($v); |
|
503 | + } |
|
504 | + } else { |
|
505 | + $this->doSetFieldForSorting($field); |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * @return bool |
|
511 | + */ |
|
512 | + public function hasError() |
|
513 | + { |
|
514 | + return count($this->_errors) > 0; |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * @param $url |
|
519 | + * @param $path |
|
520 | + */ |
|
521 | + public function setImageDir($url, $path) |
|
522 | + { |
|
523 | + $this->_image_url = $url; |
|
524 | + $this->_image_path = $path; |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Retreive the group that have been granted access to a specific permission for this object |
|
529 | + * |
|
530 | + * @param $group_perm |
|
531 | + * @return string $group_perm name of the permission |
|
532 | + */ |
|
533 | + public function getGroupPerm($group_perm) |
|
534 | + { |
|
535 | + if (!$this->handler->getPermissions()) { |
|
536 | + $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
537 | + |
|
538 | + return false; |
|
539 | + } |
|
540 | + |
|
541 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
542 | + $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
543 | + |
|
544 | + if (count($ret) == 0) { |
|
545 | + return false; |
|
546 | + } else { |
|
547 | + return $ret; |
|
548 | + } |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * @param bool $path |
|
553 | + * @return mixed |
|
554 | + */ |
|
555 | + public function getImageDir($path = false) |
|
556 | + { |
|
557 | + if ($path) { |
|
558 | + return $this->_image_path; |
|
559 | + } else { |
|
560 | + return $this->_image_url; |
|
561 | + } |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * @param bool $path |
|
566 | + * @return mixed |
|
567 | + */ |
|
568 | + public function getUploadDir($path = false) |
|
569 | + { |
|
570 | + if ($path) { |
|
571 | + return $this->_image_path; |
|
572 | + } else { |
|
573 | + return $this->_image_url; |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * @param string $key |
|
579 | + * @param string $info |
|
580 | + * @return array |
|
581 | + */ |
|
582 | + public function getVarInfo($key = '', $info = '') |
|
583 | + { |
|
584 | + if (isset($this->vars[$key][$info])) { |
|
585 | + return $this->vars[$key][$info]; |
|
586 | + } elseif ($info === '' && isset($this->vars[$key])) { |
|
587 | + return $this->vars[$key]; |
|
588 | + } else { |
|
589 | + return $this->vars; |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Get the id of the object |
|
595 | + * |
|
596 | + * @return int id of this object |
|
597 | + */ |
|
598 | + public function id() |
|
599 | + { |
|
600 | + return $this->getVar($this->handler->keyName, 'e'); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Return the value of the title field of this object |
|
605 | + * |
|
606 | + * @param string $format |
|
607 | + * @return string |
|
608 | + */ |
|
609 | + public function title($format = 's') |
|
610 | + { |
|
611 | + return $this->getVar($this->handler->identifierName, $format); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Return the value of the title field of this object |
|
616 | + * |
|
617 | + * @return string |
|
618 | + */ |
|
619 | + public function summary() |
|
620 | + { |
|
621 | + if ($this->handler->summaryName) { |
|
622 | + return $this->getVar($this->handler->summaryName); |
|
623 | + } else { |
|
624 | + return false; |
|
625 | + } |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * Retreive the object admin side link, displayijng a SingleView page |
|
630 | + * |
|
631 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
632 | + * @return string user side link to the object |
|
633 | + */ |
|
634 | + public function getAdminViewItemLink($onlyUrl = false) |
|
635 | + { |
|
636 | + $controller = new SmartObjectController($this->handler); |
|
637 | + |
|
638 | + return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * Retreive the object user side link |
|
643 | + * |
|
644 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
645 | + * @return string user side link to the object |
|
646 | + */ |
|
647 | + public function getItemLink($onlyUrl = false) |
|
648 | + { |
|
649 | + $controller = new SmartObjectController($this->handler); |
|
650 | + |
|
651 | + return $controller->getItemLink($this, $onlyUrl); |
|
652 | + } |
|
653 | + |
|
654 | + /** |
|
655 | + * @param bool $onlyUrl |
|
656 | + * @param bool $withimage |
|
657 | + * @param bool $userSide |
|
658 | + * @return string |
|
659 | + */ |
|
660 | + public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
661 | + { |
|
662 | + $controller = new SmartObjectController($this->handler); |
|
663 | + |
|
664 | + return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * @param bool $onlyUrl |
|
669 | + * @param bool $withimage |
|
670 | + * @param bool $userSide |
|
671 | + * @return string |
|
672 | + */ |
|
673 | + public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
674 | + { |
|
675 | + $controller = new SmartObjectController($this->handler); |
|
676 | + |
|
677 | + return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * @return string |
|
682 | + */ |
|
683 | + public function getPrintAndMailLink() |
|
684 | + { |
|
685 | + $controller = new SmartObjectController($this->handler); |
|
686 | + |
|
687 | + return $controller->getPrintAndMailLink($this); |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * @param $sortsel |
|
692 | + * @return array|bool |
|
693 | + */ |
|
694 | + public function getFieldsForSorting($sortsel) |
|
695 | + { |
|
696 | + $ret = array(); |
|
697 | + |
|
698 | + foreach ($this->vars as $key => $field_info) { |
|
699 | + if ($field_info['sortby']) { |
|
700 | + $ret[$key]['caption'] = $field_info['form_caption']; |
|
701 | + $ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : ''; |
|
702 | + } |
|
703 | + } |
|
704 | + |
|
705 | + if (count($ret) > 0) { |
|
706 | + return $ret; |
|
707 | + } else { |
|
708 | + return false; |
|
709 | + } |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * @param $key |
|
714 | + * @param $newType |
|
715 | + */ |
|
716 | + public function setType($key, $newType) |
|
717 | + { |
|
718 | + $this->vars[$key]['data_type'] = $newType; |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * @param $key |
|
723 | + * @param $info |
|
724 | + * @param $value |
|
725 | + */ |
|
726 | + public function setVarInfo($key, $info, $value) |
|
727 | + { |
|
728 | + $this->vars[$key][$info] = $value; |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * @param $key |
|
733 | + * @param bool $editor |
|
734 | + * @return string |
|
735 | + */ |
|
736 | + public function getValueFor($key, $editor = true) |
|
737 | + { |
|
738 | + global $xoopsModuleConfig; |
|
739 | + |
|
740 | + $ret = $this->getVar($key, 'n'); |
|
741 | + $myts = MyTextSanitizer::getInstance(); |
|
742 | + |
|
743 | + $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
744 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
745 | + |
|
746 | + $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
747 | + $smiley = true; |
|
748 | + $xcode = true; |
|
749 | + $image = true; |
|
750 | + $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
751 | + $formatML = true; |
|
752 | + |
|
753 | + if ($form_editor === 'default') { |
|
754 | + global $xoopsModuleConfig; |
|
755 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
756 | + } |
|
757 | + |
|
758 | + if ($editor) { |
|
759 | + if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
760 | + $br = false; |
|
761 | + $formatML = !$editor; |
|
762 | + } else { |
|
763 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + if (method_exists($myts, 'formatForML')) { |
|
768 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
769 | + } else { |
|
770 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
771 | + } |
|
772 | + } |
|
773 | + |
|
774 | + /** |
|
775 | + * clean values of all variables of the object for storage. |
|
776 | + * also add slashes whereever needed |
|
777 | + * |
|
778 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
779 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
780 | + * as a string separated by | |
|
781 | + * |
|
782 | + * @return bool true if successful |
|
783 | + * @access public |
|
784 | + */ |
|
785 | + public function cleanVars() |
|
786 | + { |
|
787 | + $ts = MyTextSanitizer::getInstance(); |
|
788 | + $existing_errors = $this->getErrors(); |
|
789 | + $this->_errors = array(); |
|
790 | + foreach ($this->vars as $k => $v) { |
|
791 | + $cleanv = $v['value']; |
|
792 | + if (!$v['changed']) { |
|
793 | + } else { |
|
794 | + $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
795 | + switch ($v['data_type']) { |
|
796 | + case XOBJ_DTYPE_TXTBOX: |
|
797 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
798 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
799 | + continue 2; |
|
800 | + } |
|
801 | + if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
802 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
803 | + continue 2; |
|
804 | + } |
|
805 | + if (!$v['not_gpc']) { |
|
806 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
807 | + } else { |
|
808 | + $cleanv = $ts->censorString($cleanv); |
|
809 | + } |
|
810 | + break; |
|
811 | + case XOBJ_DTYPE_TXTAREA: |
|
812 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
813 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
814 | + continue 2; |
|
815 | + } |
|
816 | + if (!$v['not_gpc']) { |
|
817 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
818 | + } else { |
|
819 | + $cleanv = $ts->censorString($cleanv); |
|
820 | + } |
|
821 | + break; |
|
822 | + case XOBJ_DTYPE_SOURCE: |
|
823 | + if (!$v['not_gpc']) { |
|
824 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
825 | + } else { |
|
826 | + $cleanv = $cleanv; |
|
827 | + } |
|
828 | + break; |
|
829 | + case XOBJ_DTYPE_INT: |
|
830 | + case XOBJ_DTYPE_TIME_ONLY: |
|
831 | + $cleanv = (int)$cleanv; |
|
832 | + break; |
|
833 | + |
|
834 | + case XOBJ_DTYPE_CURRENCY: |
|
835 | + $cleanv = smart_currency($cleanv); |
|
836 | + break; |
|
837 | + |
|
838 | + case XOBJ_DTYPE_FLOAT: |
|
839 | + $cleanv = smart_float($cleanv); |
|
840 | + break; |
|
841 | + |
|
842 | + case XOBJ_DTYPE_EMAIL: |
|
843 | + if ($v['required'] && $cleanv === '') { |
|
844 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
845 | + continue 2; |
|
846 | + } |
|
847 | + if ($cleanv !== '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
848 | + $this->setErrors('Invalid Email'); |
|
849 | + continue 2; |
|
850 | + } |
|
851 | + if (!$v['not_gpc']) { |
|
852 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
853 | + } |
|
854 | + break; |
|
855 | + case XOBJ_DTYPE_URL: |
|
856 | + if ($v['required'] && $cleanv === '') { |
|
857 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
858 | + continue 2; |
|
859 | + } |
|
860 | + if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
861 | + $cleanv = 'http://' . $cleanv; |
|
862 | + } |
|
863 | + if (!$v['not_gpc']) { |
|
864 | + $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
865 | + } |
|
866 | + break; |
|
867 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
868 | + $cleanv = implode('|', $cleanv); |
|
869 | + break; |
|
870 | + case XOBJ_DTYPE_ARRAY: |
|
871 | + $cleanv = serialize($cleanv); |
|
872 | + break; |
|
873 | + case XOBJ_DTYPE_STIME: |
|
874 | + case XOBJ_DTYPE_MTIME: |
|
875 | + case XOBJ_DTYPE_LTIME: |
|
876 | + $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
877 | + if (!($cleanv > 0)) { |
|
878 | + $cleanv = strtotime($cleanv); |
|
879 | + } |
|
880 | + break; |
|
881 | + default: |
|
882 | + break; |
|
883 | + } |
|
884 | + } |
|
885 | + $this->cleanVars[$k] =& $cleanv; |
|
886 | + unset($cleanv); |
|
887 | + } |
|
888 | + if (count($this->_errors) > 0) { |
|
889 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
890 | + |
|
891 | + return false; |
|
892 | + } |
|
893 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
894 | + $this->unsetDirty(); |
|
895 | + |
|
896 | + return true; |
|
897 | + } |
|
898 | + |
|
899 | + /** |
|
900 | + * returns a specific variable for the object in a proper format |
|
901 | + * |
|
902 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
903 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
904 | + * as a string separated by | |
|
905 | + * |
|
906 | + * @access public |
|
907 | + * @param string $key key of the object's variable to be returned |
|
908 | + * @param string $format format to use for the output |
|
909 | + * @return mixed formatted value of the variable |
|
910 | + */ |
|
911 | + public function getVar($key, $format = 's') |
|
912 | + { |
|
913 | + global $myts; |
|
914 | + |
|
915 | + $ret = $this->vars[$key]['value']; |
|
916 | + |
|
917 | + switch ($this->vars[$key]['data_type']) { |
|
918 | + |
|
919 | + case XOBJ_DTYPE_TXTBOX: |
|
920 | + switch (strtolower($format)) { |
|
921 | + case 's': |
|
922 | + case 'show': |
|
923 | + // ML Hack by marcan |
|
924 | + $ts = MyTextSanitizer::getInstance(); |
|
925 | + $ret = $ts->htmlSpecialChars($ret); |
|
926 | + |
|
927 | + if (method_exists($myts, 'formatForML')) { |
|
928 | + return $ts->formatForML($ret); |
|
929 | + } else { |
|
930 | + return $ret; |
|
931 | + } |
|
932 | + break 1; |
|
933 | + // End of ML Hack by marcan |
|
934 | + |
|
935 | + case 'clean': |
|
936 | + $ts = MyTextSanitizer::getInstance(); |
|
937 | + |
|
938 | + $ret = smart_html2text($ret); |
|
939 | + $ret = smart_purifyText($ret); |
|
940 | + |
|
941 | + if (method_exists($myts, 'formatForML')) { |
|
942 | + return $ts->formatForML($ret); |
|
943 | + } else { |
|
944 | + return $ret; |
|
945 | + } |
|
946 | + break 1; |
|
947 | + // End of ML Hack by marcan |
|
948 | + |
|
949 | + case 'e': |
|
950 | + case 'edit': |
|
951 | + $ts = MyTextSanitizer::getInstance(); |
|
952 | + |
|
953 | + return $ts->htmlSpecialChars($ret); |
|
954 | + break 1; |
|
955 | + case 'p': |
|
956 | + case 'preview': |
|
957 | + case 'f': |
|
958 | + case 'formpreview': |
|
959 | + $ts = MyTextSanitizer::getInstance(); |
|
960 | + |
|
961 | + return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
962 | + break 1; |
|
963 | + case 'n': |
|
964 | + case 'none': |
|
965 | + default: |
|
966 | + break 1; |
|
967 | + } |
|
968 | + break; |
|
969 | + case XOBJ_DTYPE_LTIME: |
|
970 | + switch (strtolower($format)) { |
|
971 | + case 's': |
|
972 | + case 'show': |
|
973 | + case 'p': |
|
974 | + case 'preview': |
|
975 | + case 'f': |
|
976 | + case 'formpreview': |
|
977 | + $ret = formatTimestamp($ret, _DATESTRING); |
|
978 | + |
|
979 | + return $ret; |
|
980 | + break 1; |
|
981 | + case 'n': |
|
982 | + case 'none': |
|
983 | + case 'e': |
|
984 | + case 'edit': |
|
985 | + break 1; |
|
986 | + default: |
|
987 | + break 1; |
|
988 | + } |
|
989 | + break; |
|
990 | + case XOBJ_DTYPE_STIME: |
|
991 | + switch (strtolower($format)) { |
|
992 | + case 's': |
|
993 | + case 'show': |
|
994 | + case 'p': |
|
995 | + case 'preview': |
|
996 | + case 'f': |
|
997 | + case 'formpreview': |
|
998 | + $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
999 | + |
|
1000 | + return $ret; |
|
1001 | + break 1; |
|
1002 | + case 'n': |
|
1003 | + case 'none': |
|
1004 | + case 'e': |
|
1005 | + case 'edit': |
|
1006 | + break 1; |
|
1007 | + default: |
|
1008 | + break 1; |
|
1009 | + } |
|
1010 | + break; |
|
1011 | + case XOBJ_DTYPE_TIME_ONLY: |
|
1012 | + switch (strtolower($format)) { |
|
1013 | + case 's': |
|
1014 | + case 'show': |
|
1015 | + case 'p': |
|
1016 | + case 'preview': |
|
1017 | + case 'f': |
|
1018 | + case 'formpreview': |
|
1019 | + $ret = formatTimestamp($ret, 'G:i'); |
|
1020 | + |
|
1021 | + return $ret; |
|
1022 | + break 1; |
|
1023 | + case 'n': |
|
1024 | + case 'none': |
|
1025 | + case 'e': |
|
1026 | + case 'edit': |
|
1027 | + break 1; |
|
1028 | + default: |
|
1029 | + break 1; |
|
1030 | + } |
|
1031 | + break; |
|
1032 | + |
|
1033 | + case XOBJ_DTYPE_CURRENCY: |
|
1034 | + $decimal_section_original = strstr($ret, '.'); |
|
1035 | + $decimal_section = $decimal_section_original; |
|
1036 | + if ($decimal_section) { |
|
1037 | + if (strlen($decimal_section) == 1) { |
|
1038 | + $decimal_section = '.00'; |
|
1039 | + } elseif (strlen($decimal_section) == 2) { |
|
1040 | + $decimal_section .= '0'; |
|
1041 | + } |
|
1042 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1043 | + } else { |
|
1044 | + $ret .= '.00'; |
|
1045 | + } |
|
1046 | + break; |
|
1047 | + |
|
1048 | + case XOBJ_DTYPE_TXTAREA: |
|
1049 | + switch (strtolower($format)) { |
|
1050 | + case 's': |
|
1051 | + case 'show': |
|
1052 | + $ts = MyTextSanitizer::getInstance(); |
|
1053 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1054 | + |
|
1055 | + $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1056 | + |
|
1057 | + $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1058 | + $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1059 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * Hack by marcan <INBOX> for SCSPRO |
|
1063 | + * Setting mastop as the main editor |
|
1064 | + */ |
|
1065 | + if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1066 | + $br = false; |
|
1067 | + } |
|
1068 | + /** |
|
1069 | + * Hack by marcan <INBOX> for SCSPRO |
|
1070 | + * Setting mastop as the main editor |
|
1071 | + */ |
|
1072 | + |
|
1073 | + return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1074 | + break 1; |
|
1075 | + case 'e': |
|
1076 | + case 'edit': |
|
1077 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1078 | + break 1; |
|
1079 | + case 'p': |
|
1080 | + case 'preview': |
|
1081 | + $ts = MyTextSanitizer::getInstance(); |
|
1082 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1083 | + $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1084 | + $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1085 | + $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1086 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1087 | + |
|
1088 | + return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1089 | + break 1; |
|
1090 | + case 'f': |
|
1091 | + case 'formpreview': |
|
1092 | + $ts = MyTextSanitizer::getInstance(); |
|
1093 | + |
|
1094 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1095 | + break 1; |
|
1096 | + case 'n': |
|
1097 | + case 'none': |
|
1098 | + default: |
|
1099 | + break 1; |
|
1100 | + } |
|
1101 | + break; |
|
1102 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1103 | + $ret =& explode('|', $ret); |
|
1104 | + break; |
|
1105 | + case XOBJ_DTYPE_ARRAY: |
|
1106 | + $ret =& unserialize($ret); |
|
1107 | + break; |
|
1108 | + case XOBJ_DTYPE_SOURCE: |
|
1109 | + switch (strtolower($format)) { |
|
1110 | + case 's': |
|
1111 | + case 'show': |
|
1112 | + break 1; |
|
1113 | + case 'e': |
|
1114 | + case 'edit': |
|
1115 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1116 | + break 1; |
|
1117 | + case 'p': |
|
1118 | + case 'preview': |
|
1119 | + $ts = MyTextSanitizer::getInstance(); |
|
1120 | + |
|
1121 | + return $ts->stripSlashesGPC($ret); |
|
1122 | + break 1; |
|
1123 | + case 'f': |
|
1124 | + case 'formpreview': |
|
1125 | + $ts = MyTextSanitizer::getInstance(); |
|
1126 | + |
|
1127 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1128 | + break 1; |
|
1129 | + case 'n': |
|
1130 | + case 'none': |
|
1131 | + default: |
|
1132 | + break 1; |
|
1133 | + } |
|
1134 | + break; |
|
1135 | + default: |
|
1136 | + if ($this->vars[$key]['options'] !== '' && $ret != '') { |
|
1137 | + switch (strtolower($format)) { |
|
1138 | + case 's': |
|
1139 | + case 'show': |
|
1140 | + $selected = explode('|', $ret); |
|
1141 | + $options = explode('|', $this->vars[$key]['options']); |
|
1142 | + $i = 1; |
|
1143 | + $ret = array(); |
|
1144 | + foreach ($options as $op) { |
|
1145 | + if (in_array($i, $selected)) { |
|
1146 | + $ret[] = $op; |
|
1147 | + } |
|
1148 | + ++$i; |
|
1149 | + } |
|
1150 | + |
|
1151 | + return implode(', ', $ret); |
|
1152 | + case 'e': |
|
1153 | + case 'edit': |
|
1154 | + $ret = explode('|', $ret); |
|
1155 | + break 1; |
|
1156 | + default: |
|
1157 | + break 1; |
|
1158 | + } |
|
1159 | + } |
|
1160 | + break; |
|
1161 | + } |
|
1162 | + |
|
1163 | + return $ret; |
|
1164 | + } |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * @param $key |
|
1168 | + */ |
|
1169 | + public function doMakeFieldreadOnly($key) |
|
1170 | + { |
|
1171 | + if (isset($this->vars[$key])) { |
|
1172 | + $this->vars[$key]['readonly'] = true; |
|
1173 | + $this->vars[$key]['displayOnForm'] = true; |
|
1174 | + } |
|
1175 | + } |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * @param $key |
|
1179 | + */ |
|
1180 | + public function makeFieldReadOnly($key) |
|
1181 | + { |
|
1182 | + if (is_array($key)) { |
|
1183 | + foreach ($key as $v) { |
|
1184 | + $this->doMakeFieldreadOnly($v); |
|
1185 | + } |
|
1186 | + } else { |
|
1187 | + $this->doMakeFieldreadOnly($key); |
|
1188 | + } |
|
1189 | + } |
|
1190 | + |
|
1191 | + /** |
|
1192 | + * @param $key |
|
1193 | + */ |
|
1194 | + public function doHideFieldFromForm($key) |
|
1195 | + { |
|
1196 | + if (isset($this->vars[$key])) { |
|
1197 | + $this->vars[$key]['displayOnForm'] = false; |
|
1198 | + } |
|
1199 | + } |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * @param $key |
|
1203 | + */ |
|
1204 | + public function doHideFieldFromSingleView($key) |
|
1205 | + { |
|
1206 | + if (isset($this->vars[$key])) { |
|
1207 | + $this->vars[$key]['displayOnSingleView'] = false; |
|
1208 | + } |
|
1209 | + } |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * @param $key |
|
1213 | + */ |
|
1214 | + public function hideFieldFromForm($key) |
|
1215 | + { |
|
1216 | + if (is_array($key)) { |
|
1217 | + foreach ($key as $v) { |
|
1218 | + $this->doHideFieldFromForm($v); |
|
1219 | + } |
|
1220 | + } else { |
|
1221 | + $this->doHideFieldFromForm($key); |
|
1222 | + } |
|
1223 | + } |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * @param $key |
|
1227 | + */ |
|
1228 | + public function hideFieldFromSingleView($key) |
|
1229 | + { |
|
1230 | + if (is_array($key)) { |
|
1231 | + foreach ($key as $v) { |
|
1232 | + $this->doHideFieldFromSingleView($v); |
|
1233 | + } |
|
1234 | + } else { |
|
1235 | + $this->doHideFieldFromSingleView($key); |
|
1236 | + } |
|
1237 | + } |
|
1238 | + |
|
1239 | + /** |
|
1240 | + * @param $key |
|
1241 | + */ |
|
1242 | + public function doShowFieldOnForm($key) |
|
1243 | + { |
|
1244 | + if (isset($this->vars[$key])) { |
|
1245 | + $this->vars[$key]['displayOnForm'] = true; |
|
1246 | + } |
|
1247 | + } |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1251 | + * |
|
1252 | + * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1253 | + * @param bool $userSide for futur use, to do something different on the user side |
|
1254 | + * @param array $actions |
|
1255 | + * @param bool $headerAsRow |
|
1256 | + * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1257 | + */ |
|
1258 | + public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true) |
|
1259 | + { |
|
1260 | + include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
1261 | + $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
1262 | + // add all fields mark as displayOnSingleView except the keyid |
|
1263 | + foreach ($this->vars as $key => $var) { |
|
1264 | + if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1265 | + $is_header = ($key == $this->handler->identifierName); |
|
1266 | + $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
1267 | + } |
|
1268 | + } |
|
1269 | + |
|
1270 | + if ($fetchOnly) { |
|
1271 | + $ret = $singleview->render($fetchOnly); |
|
1272 | + |
|
1273 | + return $ret; |
|
1274 | + } else { |
|
1275 | + $singleview->render($fetchOnly); |
|
1276 | + } |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * @param $key |
|
1281 | + */ |
|
1282 | + public function doDisplayFieldOnSingleView($key) |
|
1283 | + { |
|
1284 | + if (isset($this->vars[$key])) { |
|
1285 | + $this->vars[$key]['displayOnSingleView'] = true; |
|
1286 | + } |
|
1287 | + } |
|
1288 | + |
|
1289 | + /** |
|
1290 | + * @param $field |
|
1291 | + * @param bool $required |
|
1292 | + */ |
|
1293 | + public function doSetFieldAsRequired($field, $required = true) |
|
1294 | + { |
|
1295 | + $this->setVarInfo($field, 'required', $required); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * @param $field |
|
1300 | + */ |
|
1301 | + public function doSetFieldForSorting($field) |
|
1302 | + { |
|
1303 | + $this->setVarInfo($field, 'sortby', true); |
|
1304 | + } |
|
1305 | + |
|
1306 | + /** |
|
1307 | + * @param $key |
|
1308 | + */ |
|
1309 | + public function showFieldOnForm($key) |
|
1310 | + { |
|
1311 | + if (is_array($key)) { |
|
1312 | + foreach ($key as $v) { |
|
1313 | + $this->doShowFieldOnForm($v); |
|
1314 | + } |
|
1315 | + } else { |
|
1316 | + $this->doShowFieldOnForm($key); |
|
1317 | + } |
|
1318 | + } |
|
1319 | + |
|
1320 | + /** |
|
1321 | + * @param $key |
|
1322 | + */ |
|
1323 | + public function displayFieldOnSingleView($key) |
|
1324 | + { |
|
1325 | + if (is_array($key)) { |
|
1326 | + foreach ($key as $v) { |
|
1327 | + $this->doDisplayFieldOnSingleView($v); |
|
1328 | + } |
|
1329 | + } else { |
|
1330 | + $this->doDisplayFieldOnSingleView($key); |
|
1331 | + } |
|
1332 | + } |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * @param $key |
|
1336 | + */ |
|
1337 | + public function doSetAdvancedFormFields($key) |
|
1338 | + { |
|
1339 | + if (isset($this->vars[$key])) { |
|
1340 | + $this->vars[$key]['advancedform'] = true; |
|
1341 | + } |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * @param $key |
|
1346 | + */ |
|
1347 | + public function setAdvancedFormFields($key) |
|
1348 | + { |
|
1349 | + if (is_array($key)) { |
|
1350 | + foreach ($key as $v) { |
|
1351 | + $this->doSetAdvancedFormFields($v); |
|
1352 | + } |
|
1353 | + } else { |
|
1354 | + $this->doSetAdvancedFormFields($key); |
|
1355 | + } |
|
1356 | + } |
|
1357 | + |
|
1358 | + /** |
|
1359 | + * @param $key |
|
1360 | + * @return mixed |
|
1361 | + */ |
|
1362 | + public function getUrlLinkObj($key) |
|
1363 | + { |
|
1364 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1365 | + $urllinkid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1366 | + if ($urllinkid != 0) { |
|
1367 | + return $smartobjectLinkurlHandler->get($urllinkid); |
|
1368 | + } else { |
|
1369 | + return $smartobjectLinkurlHandler->create(); |
|
1370 | + } |
|
1371 | + } |
|
1372 | + |
|
1373 | + /** |
|
1374 | + * @param $urlLinkObj |
|
1375 | + * @return mixed |
|
1376 | + */ |
|
1377 | + public function &storeUrlLinkObj($urlLinkObj) |
|
1378 | + { |
|
1379 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1380 | + |
|
1381 | + return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1382 | + } |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * @param $key |
|
1386 | + * @return mixed |
|
1387 | + */ |
|
1388 | + public function getFileObj($key) |
|
1389 | + { |
|
1390 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1391 | + $fileid = $this->getVar($key) !== null ? $this->getVar($key) : 0; |
|
1392 | + if ($fileid != 0) { |
|
1393 | + return $smartobjectFileHandler->get($fileid); |
|
1394 | + } else { |
|
1395 | + return $smartobjectFileHandler->create(); |
|
1396 | + } |
|
1397 | + } |
|
1398 | + |
|
1399 | + /** |
|
1400 | + * @param $fileObj |
|
1401 | + * @return mixed |
|
1402 | + */ |
|
1403 | + public function &storeFileObj($fileObj) |
|
1404 | + { |
|
1405 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1406 | + |
|
1407 | + return $smartobjectFileHandler->insert($fileObj); |
|
1408 | + } |
|
1409 | 1409 | } |
@@ -21,77 +21,77 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class SmartObjectColumn |
23 | 23 | { |
24 | - public $_keyname; |
|
25 | - public $_align; |
|
26 | - public $_width; |
|
27 | - public $_customMethodForValue; |
|
28 | - public $_extraParams; |
|
29 | - public $_sortable; |
|
30 | - public $_customCaption; |
|
31 | - |
|
32 | - /** |
|
33 | - * SmartObjectColumn constructor. |
|
34 | - * @param $keyname |
|
35 | - * @param string $align |
|
36 | - * @param bool $width |
|
37 | - * @param bool $customMethodForValue |
|
38 | - * @param bool $param |
|
39 | - * @param bool $customCaption |
|
40 | - * @param bool $sortable |
|
41 | - */ |
|
42 | - public function __construct($keyname, $align = 'left', $width = false, $customMethodForValue = false, $param = false, $customCaption = false, $sortable = true) |
|
43 | - { |
|
44 | - $this->_keyname = $keyname; |
|
45 | - $this->_align = $align; |
|
46 | - $this->_width = $width; |
|
47 | - $this->_customMethodForValue = $customMethodForValue; |
|
48 | - $this->_sortable = $sortable; |
|
49 | - $this->_param = $param; |
|
50 | - $this->_customCaption = $customCaption; |
|
51 | - } |
|
52 | - |
|
53 | - public function getKeyName() |
|
54 | - { |
|
55 | - return $this->_keyname; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getAlign() |
|
62 | - { |
|
63 | - return $this->_align; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function isSortable() |
|
70 | - { |
|
71 | - return $this->_sortable; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return bool|string |
|
76 | - */ |
|
77 | - public function getWidth() |
|
78 | - { |
|
79 | - if ($this->_width) { |
|
80 | - $ret = $this->_width; |
|
81 | - } else { |
|
82 | - $ret = ''; |
|
83 | - } |
|
84 | - |
|
85 | - return $ret; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function getCustomCaption() |
|
92 | - { |
|
93 | - return $this->_customCaption; |
|
94 | - } |
|
24 | + public $_keyname; |
|
25 | + public $_align; |
|
26 | + public $_width; |
|
27 | + public $_customMethodForValue; |
|
28 | + public $_extraParams; |
|
29 | + public $_sortable; |
|
30 | + public $_customCaption; |
|
31 | + |
|
32 | + /** |
|
33 | + * SmartObjectColumn constructor. |
|
34 | + * @param $keyname |
|
35 | + * @param string $align |
|
36 | + * @param bool $width |
|
37 | + * @param bool $customMethodForValue |
|
38 | + * @param bool $param |
|
39 | + * @param bool $customCaption |
|
40 | + * @param bool $sortable |
|
41 | + */ |
|
42 | + public function __construct($keyname, $align = 'left', $width = false, $customMethodForValue = false, $param = false, $customCaption = false, $sortable = true) |
|
43 | + { |
|
44 | + $this->_keyname = $keyname; |
|
45 | + $this->_align = $align; |
|
46 | + $this->_width = $width; |
|
47 | + $this->_customMethodForValue = $customMethodForValue; |
|
48 | + $this->_sortable = $sortable; |
|
49 | + $this->_param = $param; |
|
50 | + $this->_customCaption = $customCaption; |
|
51 | + } |
|
52 | + |
|
53 | + public function getKeyName() |
|
54 | + { |
|
55 | + return $this->_keyname; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getAlign() |
|
62 | + { |
|
63 | + return $this->_align; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function isSortable() |
|
70 | + { |
|
71 | + return $this->_sortable; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return bool|string |
|
76 | + */ |
|
77 | + public function getWidth() |
|
78 | + { |
|
79 | + if ($this->_width) { |
|
80 | + $ret = $this->_width; |
|
81 | + } else { |
|
82 | + $ret = ''; |
|
83 | + } |
|
84 | + |
|
85 | + return $ret; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function getCustomCaption() |
|
92 | + { |
|
93 | + return $this->_customCaption; |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -105,819 +105,819 @@ discard block |
||
105 | 105 | */ |
106 | 106 | class SmartObjectTable |
107 | 107 | { |
108 | - public $_id; |
|
109 | - public $_objectHandler; |
|
110 | - public $_columns; |
|
111 | - public $_criteria; |
|
112 | - public $_actions; |
|
113 | - public $_objects = false; |
|
114 | - public $_aObjects; |
|
115 | - public $_custom_actions; |
|
116 | - public $_sortsel; |
|
117 | - public $_ordersel; |
|
118 | - public $_limitsel; |
|
119 | - public $_filtersel; |
|
120 | - public $_filterseloptions; |
|
121 | - public $_filtersel2; |
|
122 | - public $_filtersel2options; |
|
123 | - public $_filtersel2optionsDefault; |
|
124 | - |
|
125 | - public $_tempObject; |
|
126 | - public $_tpl; |
|
127 | - public $_introButtons; |
|
128 | - public $_quickSearch = false; |
|
129 | - public $_actionButtons = false; |
|
130 | - public $_head_css_class = 'bg3'; |
|
131 | - public $_hasActions = false; |
|
132 | - public $_userSide = false; |
|
133 | - public $_printerFriendlyPage = false; |
|
134 | - public $_tableHeader = false; |
|
135 | - public $_tableFooter = false; |
|
136 | - public $_showActionsColumnTitle = true; |
|
137 | - public $_isTree = false; |
|
138 | - public $_showFilterAndLimit = true; |
|
139 | - public $_enableColumnsSorting = true; |
|
140 | - public $_customTemplate = false; |
|
141 | - public $_withSelectedActions = array(); |
|
142 | - |
|
143 | - /** |
|
144 | - * Constructor |
|
145 | - * |
|
146 | - * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
147 | - * @param CriteriaElement $criteria |
|
148 | - * @param array $actions array representing the actions to offer |
|
149 | - * |
|
150 | - * @param bool $userSide |
|
151 | - * @internal param array $columns array representing the columns to display in the table |
|
152 | - */ |
|
153 | - public function __construct(SmartPersistableObjectHandler $objectHandler, CriteriaElement $criteria = null, $actions = array('edit', 'delete'), $userSide = false) |
|
154 | - { |
|
155 | - $this->_id = $objectHandler->className; |
|
156 | - $this->_objectHandler = $objectHandler; |
|
157 | - |
|
158 | - if (!$criteria) { |
|
159 | - $criteria = new CriteriaCompo(); |
|
160 | - } |
|
161 | - $this->_criteria = $criteria; |
|
162 | - $this->_actions = $actions; |
|
163 | - $this->_custom_actions = array(); |
|
164 | - $this->_userSide = $userSide; |
|
165 | - if ($userSide) { |
|
166 | - $this->_head_css_class = 'head'; |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param $op |
|
172 | - * @param bool $caption |
|
173 | - * @param bool $text |
|
174 | - */ |
|
175 | - public function addActionButton($op, $caption = false, $text = false) |
|
176 | - { |
|
177 | - $action = array( |
|
178 | - 'op' => $op, |
|
179 | - 'caption' => $caption, |
|
180 | - 'text' => $text |
|
181 | - ); |
|
182 | - $this->_actionButtons[] = $action; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param $columnObj |
|
187 | - */ |
|
188 | - public function addColumn($columnObj) |
|
189 | - { |
|
190 | - $this->_columns[] = $columnObj; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @param $name |
|
195 | - * @param $location |
|
196 | - * @param $value |
|
197 | - */ |
|
198 | - public function addIntroButton($name, $location, $value) |
|
199 | - { |
|
200 | - $introButton = array(); |
|
201 | - $introButton['name'] = $name; |
|
202 | - $introButton['location'] = $location; |
|
203 | - $introButton['value'] = $value; |
|
204 | - $this->_introButtons[] = $introButton; |
|
205 | - unset($introButton); |
|
206 | - } |
|
207 | - |
|
208 | - public function addPrinterFriendlyLink() |
|
209 | - { |
|
210 | - $current_urls = smart_getCurrentUrls(); |
|
211 | - $current_url = $current_urls['full']; |
|
212 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @param $fields |
|
217 | - * @param string $caption |
|
218 | - */ |
|
219 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
220 | - { |
|
221 | - $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param $content |
|
226 | - */ |
|
227 | - public function addHeader($content) |
|
228 | - { |
|
229 | - $this->_tableHeader = $content; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $content |
|
234 | - */ |
|
235 | - public function addFooter($content) |
|
236 | - { |
|
237 | - $this->_tableFooter = $content; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param $caption |
|
242 | - */ |
|
243 | - public function addDefaultIntroButton($caption) |
|
244 | - { |
|
245 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * @param $method |
|
250 | - */ |
|
251 | - public function addCustomAction($method) |
|
252 | - { |
|
253 | - $this->_custom_actions[] = $method; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @param $default_sort |
|
258 | - */ |
|
259 | - public function setDefaultSort($default_sort) |
|
260 | - { |
|
261 | - $this->_sortsel = $default_sort; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function getDefaultSort() |
|
268 | - { |
|
269 | - if ($this->_sortsel) { |
|
270 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
271 | - } else { |
|
272 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param $default_order |
|
278 | - */ |
|
279 | - public function setDefaultOrder($default_order) |
|
280 | - { |
|
281 | - $this->_ordersel = $default_order; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public function getDefaultOrder() |
|
288 | - { |
|
289 | - if ($this->_ordersel) { |
|
290 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
291 | - } else { |
|
292 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * @param array $actions |
|
298 | - */ |
|
299 | - public function addWithSelectedActions($actions = array()) |
|
300 | - { |
|
301 | - $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
302 | - $this->_withSelectedActions = $actions; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Adding a filter in the table |
|
307 | - * |
|
308 | - * @param string $key key to the field that will be used for sorting |
|
309 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
310 | - * @param bool $default |
|
311 | - */ |
|
312 | - public function addFilter($key, $method, $default = false) |
|
313 | - { |
|
314 | - $this->_filterseloptions[$key] = $method; |
|
315 | - $this->_filtersel2optionsDefault = $default; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * @param $default_filter |
|
320 | - */ |
|
321 | - public function setDefaultFilter($default_filter) |
|
322 | - { |
|
323 | - $this->_filtersel = $default_filter; |
|
324 | - } |
|
325 | - |
|
326 | - public function isForUserSide() |
|
327 | - { |
|
328 | - $this->_userSide = true; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @param $template |
|
333 | - */ |
|
334 | - public function setCustomTemplate($template) |
|
335 | - { |
|
336 | - $this->_customTemplate = $template; |
|
337 | - } |
|
338 | - |
|
339 | - public function setSortOrder() |
|
340 | - { |
|
341 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
342 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
343 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
344 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
345 | - |
|
346 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
347 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
348 | - } else { |
|
349 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
350 | - } |
|
351 | - |
|
352 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
353 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
354 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
355 | - $ordersArray = $this->getOrdersArray(); |
|
356 | - $this->_criteria->setOrder($this->_ordersel); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * @param $id |
|
361 | - */ |
|
362 | - public function setTableId($id) |
|
363 | - { |
|
364 | - $this->_id = $id; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * @param $objects |
|
369 | - */ |
|
370 | - public function setObjects($objects) |
|
371 | - { |
|
372 | - $this->_objects = $objects; |
|
373 | - } |
|
374 | - |
|
375 | - public function createTableRows() |
|
376 | - { |
|
377 | - $this->_aObjects = array(); |
|
378 | - |
|
379 | - $doWeHaveActions = false; |
|
380 | - |
|
381 | - $objectclass = 'odd'; |
|
382 | - if (count($this->_objects) > 0) { |
|
383 | - foreach ($this->_objects as $object) { |
|
384 | - $aObject = array(); |
|
385 | - |
|
386 | - $i = 0; |
|
387 | - |
|
388 | - $aColumns = array(); |
|
389 | - |
|
390 | - foreach ($this->_columns as $column) { |
|
391 | - $aColumn = array(); |
|
392 | - |
|
393 | - if ($i == 0) { |
|
394 | - $class = 'head'; |
|
395 | - } elseif ($i % 2 == 0) { |
|
396 | - $class = 'even'; |
|
397 | - } else { |
|
398 | - $class = 'odd'; |
|
399 | - } |
|
400 | - if (method_exists($object, 'initiateCustomFields')) { |
|
401 | - //$object->initiateCustomFields(); |
|
402 | - } |
|
403 | - if ($column->_keyname === 'checked') { |
|
404 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '" />'; |
|
405 | - } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
406 | - $method = $column->_customMethodForValue; |
|
407 | - if ($column->_param) { |
|
408 | - $value = $object->$method($column->_param); |
|
409 | - } else { |
|
410 | - $value = $object->$method(); |
|
411 | - } |
|
412 | - } else { |
|
413 | - /** |
|
414 | - * If the column is the identifier, then put a link on it |
|
415 | - */ |
|
416 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
417 | - $value = $object->getItemLink(); |
|
418 | - } else { |
|
419 | - $value = $object->getVar($column->getKeyName()); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - $aColumn['value'] = $value; |
|
424 | - $aColumn['class'] = $class; |
|
425 | - $aColumn['width'] = $column->getWidth(); |
|
426 | - $aColumn['align'] = $column->getAlign(); |
|
427 | - |
|
428 | - $aColumns[] = $aColumn; |
|
429 | - ++$i; |
|
430 | - } |
|
431 | - |
|
432 | - $aObject['columns'] = $aColumns; |
|
433 | - $aObject['id'] = $object->id(); |
|
434 | - |
|
435 | - $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
436 | - |
|
437 | - $aObject['class'] = $objectclass; |
|
438 | - |
|
439 | - $actions = array(); |
|
440 | - |
|
441 | - // Adding the custom actions if any |
|
442 | - foreach ($this->_custom_actions as $action) { |
|
443 | - if (method_exists($object, $action)) { |
|
444 | - $actions[] = $object->$action(); |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
449 | - $controller = new SmartObjectController($this->_objectHandler); |
|
450 | - |
|
451 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
452 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
453 | - } |
|
454 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
455 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
456 | - } |
|
457 | - $aObject['actions'] = $actions; |
|
458 | - |
|
459 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
460 | - |
|
461 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
462 | - |
|
463 | - $this->_aObjects[] = $aObject; |
|
464 | - } |
|
465 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
466 | - } else { |
|
467 | - $colspan = count($this->_columns) + 1; |
|
468 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
469 | - } |
|
470 | - $this->_hasActions = $doWeHaveActions; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * @param bool $debug |
|
475 | - * @return mixed |
|
476 | - */ |
|
477 | - public function fetchObjects($debug = false) |
|
478 | - { |
|
479 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - public function getDefaultFilter() |
|
486 | - { |
|
487 | - if ($this->_filtersel) { |
|
488 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
489 | - } else { |
|
490 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @return array|bool |
|
496 | - */ |
|
497 | - public function getFiltersArray() |
|
498 | - { |
|
499 | - $ret = array(); |
|
500 | - $field = array(); |
|
501 | - $field['caption'] = _CO_OBJ_NONE; |
|
502 | - $field['selected'] = ''; |
|
503 | - $ret['default'] = $field; |
|
504 | - unset($field); |
|
505 | - |
|
506 | - if ($this->_filterseloptions) { |
|
507 | - foreach ($this->_filterseloptions as $key => $value) { |
|
508 | - $field = array(); |
|
509 | - if (is_array($value)) { |
|
510 | - $field['caption'] = $key; |
|
511 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
512 | - } else { |
|
513 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
514 | - $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
515 | - } |
|
516 | - $ret[$key] = $field; |
|
517 | - unset($field); |
|
518 | - } |
|
519 | - } else { |
|
520 | - $ret = false; |
|
521 | - } |
|
522 | - |
|
523 | - return $ret; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * @param $default_filter2 |
|
528 | - */ |
|
529 | - public function setDefaultFilter2($default_filter2) |
|
530 | - { |
|
531 | - $this->_filtersel2 = $default_filter2; |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * @return string |
|
536 | - */ |
|
537 | - public function getDefaultFilter2() |
|
538 | - { |
|
539 | - if ($this->_filtersel2) { |
|
540 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
541 | - } else { |
|
542 | - return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * @return array |
|
548 | - */ |
|
549 | - public function getFilters2Array() |
|
550 | - { |
|
551 | - $ret = array(); |
|
552 | - |
|
553 | - foreach ($this->_filtersel2options as $key => $value) { |
|
554 | - $field = array(); |
|
555 | - $field['caption'] = $value; |
|
556 | - $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
557 | - $ret[$key] = $field; |
|
558 | - unset($field); |
|
559 | - } |
|
560 | - |
|
561 | - return $ret; |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * @param $limitsArray |
|
566 | - * @param $params_of_the_options_sel |
|
567 | - */ |
|
568 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
569 | - { |
|
570 | - // Rendering the form to select options on the table |
|
571 | - $current_urls = smart_getCurrentUrls(); |
|
572 | - $current_url = $current_urls['full']; |
|
573 | - |
|
574 | - /** |
|
575 | - * What was $params_of_the_options_sel doing again ? |
|
576 | - */ |
|
577 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
578 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
579 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * @return array |
|
584 | - */ |
|
585 | - public function getLimitsArray() |
|
586 | - { |
|
587 | - $ret = array(); |
|
588 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
589 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? "selected='selected'" : ''; |
|
590 | - |
|
591 | - $ret['5']['caption'] = '5'; |
|
592 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ''; |
|
593 | - |
|
594 | - $ret['10']['caption'] = '10'; |
|
595 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ''; |
|
596 | - |
|
597 | - $ret['15']['caption'] = '15'; |
|
598 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ''; |
|
599 | - |
|
600 | - $ret['20']['caption'] = '20'; |
|
601 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ''; |
|
602 | - |
|
603 | - $ret['25']['caption'] = '25'; |
|
604 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ''; |
|
605 | - |
|
606 | - $ret['30']['caption'] = '30'; |
|
607 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ''; |
|
608 | - |
|
609 | - $ret['35']['caption'] = '35'; |
|
610 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ''; |
|
611 | - |
|
612 | - $ret['40']['caption'] = '40'; |
|
613 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ''; |
|
614 | - |
|
615 | - return $ret; |
|
616 | - } |
|
617 | - |
|
618 | - /** |
|
619 | - * @return bool |
|
620 | - */ |
|
621 | - public function getObjects() |
|
622 | - { |
|
623 | - return $this->_objects; |
|
624 | - } |
|
625 | - |
|
626 | - public function hideActionColumnTitle() |
|
627 | - { |
|
628 | - $this->_showActionsColumnTitle = false; |
|
629 | - } |
|
630 | - |
|
631 | - public function hideFilterAndLimit() |
|
632 | - { |
|
633 | - $this->_showFilterAndLimit = false; |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * @return array |
|
638 | - */ |
|
639 | - public function getOrdersArray() |
|
640 | - { |
|
641 | - $ret = array(); |
|
642 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
643 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
644 | - |
|
645 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
646 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
647 | - |
|
648 | - return $ret; |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * @return mixed|string|void |
|
653 | - */ |
|
654 | - public function renderD() |
|
655 | - { |
|
656 | - return $this->render(false, true); |
|
657 | - } |
|
658 | - |
|
659 | - public function renderForPrint() |
|
660 | - { |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * @param bool $fetchOnly |
|
665 | - * @param bool $debug |
|
666 | - * @return mixed|string|void |
|
667 | - */ |
|
668 | - public function render($fetchOnly = false, $debug = false) |
|
669 | - { |
|
670 | - include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
671 | - |
|
672 | - $this->_tpl = new XoopsTpl(); |
|
673 | - |
|
674 | - /** |
|
675 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
676 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
677 | - * and we will free it after |
|
678 | - */ |
|
679 | - $this->_tempObject = $this->_objectHandler->create(); |
|
680 | - |
|
681 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
682 | - |
|
683 | - $this->setSortOrder(); |
|
684 | - |
|
685 | - if (!$this->_isTree) { |
|
686 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
687 | - } else { |
|
688 | - $this->_limitsel = 'all'; |
|
689 | - } |
|
690 | - |
|
691 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
692 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
693 | - $limitsArray = $this->getLimitsArray(); |
|
694 | - $this->_criteria->setLimit($this->_limitsel); |
|
695 | - |
|
696 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
697 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
698 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
699 | - $filtersArray = $this->getFiltersArray(); |
|
700 | - |
|
701 | - if ($filtersArray) { |
|
702 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
703 | - } |
|
704 | - |
|
705 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
706 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
707 | - // check if method associate with this filter exists in the handler |
|
708 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
709 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
710 | - $this->_criteria->add($filter['criteria']); |
|
711 | - } else { |
|
712 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
713 | - |
|
714 | - // then we will create the selfilter2 options by calling this method |
|
715 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
716 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
717 | - |
|
718 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
719 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
720 | - |
|
721 | - $filters2Array = $this->getFilters2Array(); |
|
722 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
723 | - |
|
724 | - smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
725 | - if ($this->_filtersel2 !== 'default') { |
|
726 | - $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
727 | - } |
|
728 | - } |
|
729 | - } |
|
730 | - } |
|
731 | - // Check if we have a quicksearch |
|
732 | - |
|
733 | - if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
734 | - $quicksearch_criteria = new CriteriaCompo(); |
|
735 | - if (is_array($this->_quickSearch['fields'])) { |
|
736 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
737 | - $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
738 | - } |
|
739 | - } else { |
|
740 | - $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
741 | - } |
|
742 | - $this->_criteria->add($quicksearch_criteria); |
|
743 | - } |
|
744 | - |
|
745 | - $this->_objects = $this->fetchObjects($debug); |
|
746 | - |
|
747 | - include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
748 | - if ($this->_criteria->getLimit() > 0) { |
|
749 | - |
|
750 | - /** |
|
751 | - * Geeting rid of the old params |
|
752 | - * $new_get_array is an array containing the new GET parameters |
|
753 | - */ |
|
754 | - $new_get_array = array(); |
|
755 | - |
|
756 | - /** |
|
757 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
758 | - * but without the pagenave parameters. This array will be used in the |
|
759 | - * OptionsSelection |
|
760 | - */ |
|
761 | - $params_of_the_options_sel = array(); |
|
762 | - |
|
763 | - $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
764 | - foreach ($_GET as $k => $v) { |
|
765 | - if (!in_array($k, $not_needed_params)) { |
|
766 | - $new_get_array[] = "$k=$v"; |
|
767 | - $params_of_the_options_sel[] = "$k=$v"; |
|
768 | - } |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Adding the new params of the pagenav |
|
773 | - */ |
|
774 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
775 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
776 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
777 | - $otherParams = implode('&', $new_get_array); |
|
778 | - |
|
779 | - $pagenav = |
|
780 | - new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
781 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
782 | - } |
|
783 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
784 | - |
|
785 | - // retreive the current url and the query string |
|
786 | - $current_urls = smart_getCurrentUrls(); |
|
787 | - $current_url = $current_urls['full_phpself']; |
|
788 | - $query_string = $current_urls['querystring']; |
|
789 | - if ($query_string) { |
|
790 | - $query_string = str_replace('?', '', $query_string); |
|
791 | - } |
|
792 | - $query_stringArray = explode('&', $query_string); |
|
793 | - $new_query_stringArray = array(); |
|
794 | - foreach ($query_stringArray as $query_string) { |
|
795 | - if (strpos($query_string, 'sortsel') == false && strpos($query_string, 'ordersel') == false) { |
|
796 | - $new_query_stringArray[] = $query_string; |
|
797 | - } |
|
798 | - } |
|
799 | - $new_query_string = implode('&', $new_query_stringArray); |
|
800 | - |
|
801 | - $orderArray = array(); |
|
802 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
803 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
804 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
805 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
806 | - |
|
807 | - $aColumns = array(); |
|
808 | - |
|
809 | - foreach ($this->_columns as $column) { |
|
810 | - $qs_param = ''; |
|
811 | - $aColumn = array(); |
|
812 | - $aColumn['width'] = $column->getWidth(); |
|
813 | - $aColumn['align'] = $column->getAlign(); |
|
814 | - $aColumn['key'] = $column->getKeyName(); |
|
815 | - if ($column->_keyname === 'checked') { |
|
816 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' |
|
817 | - . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' |
|
818 | - . $this->_id |
|
819 | - . ', \'selected_smartobjects\');" />'; |
|
820 | - } elseif ($column->getCustomCaption()) { |
|
821 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
822 | - } else { |
|
823 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
824 | - } |
|
825 | - // Are we doing a GET sort on this column ? |
|
826 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
827 | - || ($this->_sortsel == $column->getKeyName()); |
|
828 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
829 | - |
|
830 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
831 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
832 | - } |
|
833 | - if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
834 | - $aColumn['caption'] = $aColumn['caption']; |
|
835 | - } elseif ($getSort) { |
|
836 | - $aColumn['caption'] = '<a href="' |
|
837 | - . $current_url |
|
838 | - . '?' |
|
839 | - . $this->_objectHandler->_itemname |
|
840 | - . '_' |
|
841 | - . 'sortsel=' |
|
842 | - . $column->getKeyName() |
|
843 | - . '&' |
|
844 | - . $this->_objectHandler->_itemname |
|
845 | - . '_' |
|
846 | - . 'ordersel=' |
|
847 | - . $orderArray[$order]['neworder'] |
|
848 | - . $qs_param |
|
849 | - . '&' |
|
850 | - . $new_query_string |
|
851 | - . '">' |
|
852 | - . $aColumn['caption'] |
|
853 | - . ' <img src="' |
|
854 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
855 | - . $orderArray[$order]['image'] |
|
856 | - . '" alt="ASC" /></a>'; |
|
857 | - } else { |
|
858 | - $aColumn['caption'] = '<a href="' |
|
859 | - . $current_url |
|
860 | - . '?' |
|
861 | - . $this->_objectHandler->_itemname |
|
862 | - . '_' |
|
863 | - . 'sortsel=' |
|
864 | - . $column->getKeyName() |
|
865 | - . '&' |
|
866 | - . $this->_objectHandler->_itemname |
|
867 | - . '_' |
|
868 | - . 'ordersel=ASC' |
|
869 | - . $qs_param |
|
870 | - . '&' |
|
871 | - . $new_query_string |
|
872 | - . '">' |
|
873 | - . $aColumn['caption'] |
|
874 | - . '</a>'; |
|
875 | - } |
|
876 | - $aColumns[] = $aColumn; |
|
877 | - } |
|
878 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
879 | - |
|
880 | - if ($this->_quickSearch) { |
|
881 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
882 | - } |
|
883 | - |
|
884 | - $this->createTableRows(); |
|
885 | - |
|
886 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
887 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
888 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
889 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
890 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
891 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
892 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
893 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
894 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
895 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
896 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
897 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
898 | - if (!empty($this->_withSelectedActions)) { |
|
899 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
900 | - } |
|
901 | - |
|
902 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
903 | - if ($fetchOnly) { |
|
904 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
905 | - } else { |
|
906 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
907 | - } |
|
908 | - } |
|
909 | - |
|
910 | - public function disableColumnsSorting() |
|
911 | - { |
|
912 | - $this->_enableColumnsSorting = false; |
|
913 | - } |
|
914 | - |
|
915 | - /** |
|
916 | - * @param bool $debug |
|
917 | - * @return mixed|string|void |
|
918 | - */ |
|
919 | - public function fetch($debug = false) |
|
920 | - { |
|
921 | - return $this->render(true, $debug); |
|
922 | - } |
|
108 | + public $_id; |
|
109 | + public $_objectHandler; |
|
110 | + public $_columns; |
|
111 | + public $_criteria; |
|
112 | + public $_actions; |
|
113 | + public $_objects = false; |
|
114 | + public $_aObjects; |
|
115 | + public $_custom_actions; |
|
116 | + public $_sortsel; |
|
117 | + public $_ordersel; |
|
118 | + public $_limitsel; |
|
119 | + public $_filtersel; |
|
120 | + public $_filterseloptions; |
|
121 | + public $_filtersel2; |
|
122 | + public $_filtersel2options; |
|
123 | + public $_filtersel2optionsDefault; |
|
124 | + |
|
125 | + public $_tempObject; |
|
126 | + public $_tpl; |
|
127 | + public $_introButtons; |
|
128 | + public $_quickSearch = false; |
|
129 | + public $_actionButtons = false; |
|
130 | + public $_head_css_class = 'bg3'; |
|
131 | + public $_hasActions = false; |
|
132 | + public $_userSide = false; |
|
133 | + public $_printerFriendlyPage = false; |
|
134 | + public $_tableHeader = false; |
|
135 | + public $_tableFooter = false; |
|
136 | + public $_showActionsColumnTitle = true; |
|
137 | + public $_isTree = false; |
|
138 | + public $_showFilterAndLimit = true; |
|
139 | + public $_enableColumnsSorting = true; |
|
140 | + public $_customTemplate = false; |
|
141 | + public $_withSelectedActions = array(); |
|
142 | + |
|
143 | + /** |
|
144 | + * Constructor |
|
145 | + * |
|
146 | + * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler} |
|
147 | + * @param CriteriaElement $criteria |
|
148 | + * @param array $actions array representing the actions to offer |
|
149 | + * |
|
150 | + * @param bool $userSide |
|
151 | + * @internal param array $columns array representing the columns to display in the table |
|
152 | + */ |
|
153 | + public function __construct(SmartPersistableObjectHandler $objectHandler, CriteriaElement $criteria = null, $actions = array('edit', 'delete'), $userSide = false) |
|
154 | + { |
|
155 | + $this->_id = $objectHandler->className; |
|
156 | + $this->_objectHandler = $objectHandler; |
|
157 | + |
|
158 | + if (!$criteria) { |
|
159 | + $criteria = new CriteriaCompo(); |
|
160 | + } |
|
161 | + $this->_criteria = $criteria; |
|
162 | + $this->_actions = $actions; |
|
163 | + $this->_custom_actions = array(); |
|
164 | + $this->_userSide = $userSide; |
|
165 | + if ($userSide) { |
|
166 | + $this->_head_css_class = 'head'; |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param $op |
|
172 | + * @param bool $caption |
|
173 | + * @param bool $text |
|
174 | + */ |
|
175 | + public function addActionButton($op, $caption = false, $text = false) |
|
176 | + { |
|
177 | + $action = array( |
|
178 | + 'op' => $op, |
|
179 | + 'caption' => $caption, |
|
180 | + 'text' => $text |
|
181 | + ); |
|
182 | + $this->_actionButtons[] = $action; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param $columnObj |
|
187 | + */ |
|
188 | + public function addColumn($columnObj) |
|
189 | + { |
|
190 | + $this->_columns[] = $columnObj; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @param $name |
|
195 | + * @param $location |
|
196 | + * @param $value |
|
197 | + */ |
|
198 | + public function addIntroButton($name, $location, $value) |
|
199 | + { |
|
200 | + $introButton = array(); |
|
201 | + $introButton['name'] = $name; |
|
202 | + $introButton['location'] = $location; |
|
203 | + $introButton['value'] = $value; |
|
204 | + $this->_introButtons[] = $introButton; |
|
205 | + unset($introButton); |
|
206 | + } |
|
207 | + |
|
208 | + public function addPrinterFriendlyLink() |
|
209 | + { |
|
210 | + $current_urls = smart_getCurrentUrls(); |
|
211 | + $current_url = $current_urls['full']; |
|
212 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @param $fields |
|
217 | + * @param string $caption |
|
218 | + */ |
|
219 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
220 | + { |
|
221 | + $this->_quickSearch = array('fields' => $fields, 'caption' => $caption); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param $content |
|
226 | + */ |
|
227 | + public function addHeader($content) |
|
228 | + { |
|
229 | + $this->_tableHeader = $content; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $content |
|
234 | + */ |
|
235 | + public function addFooter($content) |
|
236 | + { |
|
237 | + $this->_tableFooter = $content; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param $caption |
|
242 | + */ |
|
243 | + public function addDefaultIntroButton($caption) |
|
244 | + { |
|
245 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * @param $method |
|
250 | + */ |
|
251 | + public function addCustomAction($method) |
|
252 | + { |
|
253 | + $this->_custom_actions[] = $method; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @param $default_sort |
|
258 | + */ |
|
259 | + public function setDefaultSort($default_sort) |
|
260 | + { |
|
261 | + $this->_sortsel = $default_sort; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function getDefaultSort() |
|
268 | + { |
|
269 | + if ($this->_sortsel) { |
|
270 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
271 | + } else { |
|
272 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param $default_order |
|
278 | + */ |
|
279 | + public function setDefaultOrder($default_order) |
|
280 | + { |
|
281 | + $this->_ordersel = $default_order; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public function getDefaultOrder() |
|
288 | + { |
|
289 | + if ($this->_ordersel) { |
|
290 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
291 | + } else { |
|
292 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * @param array $actions |
|
298 | + */ |
|
299 | + public function addWithSelectedActions($actions = array()) |
|
300 | + { |
|
301 | + $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
302 | + $this->_withSelectedActions = $actions; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Adding a filter in the table |
|
307 | + * |
|
308 | + * @param string $key key to the field that will be used for sorting |
|
309 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
310 | + * @param bool $default |
|
311 | + */ |
|
312 | + public function addFilter($key, $method, $default = false) |
|
313 | + { |
|
314 | + $this->_filterseloptions[$key] = $method; |
|
315 | + $this->_filtersel2optionsDefault = $default; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * @param $default_filter |
|
320 | + */ |
|
321 | + public function setDefaultFilter($default_filter) |
|
322 | + { |
|
323 | + $this->_filtersel = $default_filter; |
|
324 | + } |
|
325 | + |
|
326 | + public function isForUserSide() |
|
327 | + { |
|
328 | + $this->_userSide = true; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @param $template |
|
333 | + */ |
|
334 | + public function setCustomTemplate($template) |
|
335 | + { |
|
336 | + $this->_customTemplate = $template; |
|
337 | + } |
|
338 | + |
|
339 | + public function setSortOrder() |
|
340 | + { |
|
341 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
342 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
343 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
344 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
345 | + |
|
346 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
347 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
348 | + } else { |
|
349 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
350 | + } |
|
351 | + |
|
352 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
353 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
354 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
355 | + $ordersArray = $this->getOrdersArray(); |
|
356 | + $this->_criteria->setOrder($this->_ordersel); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * @param $id |
|
361 | + */ |
|
362 | + public function setTableId($id) |
|
363 | + { |
|
364 | + $this->_id = $id; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * @param $objects |
|
369 | + */ |
|
370 | + public function setObjects($objects) |
|
371 | + { |
|
372 | + $this->_objects = $objects; |
|
373 | + } |
|
374 | + |
|
375 | + public function createTableRows() |
|
376 | + { |
|
377 | + $this->_aObjects = array(); |
|
378 | + |
|
379 | + $doWeHaveActions = false; |
|
380 | + |
|
381 | + $objectclass = 'odd'; |
|
382 | + if (count($this->_objects) > 0) { |
|
383 | + foreach ($this->_objects as $object) { |
|
384 | + $aObject = array(); |
|
385 | + |
|
386 | + $i = 0; |
|
387 | + |
|
388 | + $aColumns = array(); |
|
389 | + |
|
390 | + foreach ($this->_columns as $column) { |
|
391 | + $aColumn = array(); |
|
392 | + |
|
393 | + if ($i == 0) { |
|
394 | + $class = 'head'; |
|
395 | + } elseif ($i % 2 == 0) { |
|
396 | + $class = 'even'; |
|
397 | + } else { |
|
398 | + $class = 'odd'; |
|
399 | + } |
|
400 | + if (method_exists($object, 'initiateCustomFields')) { |
|
401 | + //$object->initiateCustomFields(); |
|
402 | + } |
|
403 | + if ($column->_keyname === 'checked') { |
|
404 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '" />'; |
|
405 | + } elseif ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
406 | + $method = $column->_customMethodForValue; |
|
407 | + if ($column->_param) { |
|
408 | + $value = $object->$method($column->_param); |
|
409 | + } else { |
|
410 | + $value = $object->$method(); |
|
411 | + } |
|
412 | + } else { |
|
413 | + /** |
|
414 | + * If the column is the identifier, then put a link on it |
|
415 | + */ |
|
416 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
417 | + $value = $object->getItemLink(); |
|
418 | + } else { |
|
419 | + $value = $object->getVar($column->getKeyName()); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + $aColumn['value'] = $value; |
|
424 | + $aColumn['class'] = $class; |
|
425 | + $aColumn['width'] = $column->getWidth(); |
|
426 | + $aColumn['align'] = $column->getAlign(); |
|
427 | + |
|
428 | + $aColumns[] = $aColumn; |
|
429 | + ++$i; |
|
430 | + } |
|
431 | + |
|
432 | + $aObject['columns'] = $aColumns; |
|
433 | + $aObject['id'] = $object->id(); |
|
434 | + |
|
435 | + $objectclass = ($objectclass === 'even') ? 'odd' : 'even'; |
|
436 | + |
|
437 | + $aObject['class'] = $objectclass; |
|
438 | + |
|
439 | + $actions = array(); |
|
440 | + |
|
441 | + // Adding the custom actions if any |
|
442 | + foreach ($this->_custom_actions as $action) { |
|
443 | + if (method_exists($object, $action)) { |
|
444 | + $actions[] = $object->$action(); |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
449 | + $controller = new SmartObjectController($this->_objectHandler); |
|
450 | + |
|
451 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
452 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
453 | + } |
|
454 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
455 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
456 | + } |
|
457 | + $aObject['actions'] = $actions; |
|
458 | + |
|
459 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
460 | + |
|
461 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
462 | + |
|
463 | + $this->_aObjects[] = $aObject; |
|
464 | + } |
|
465 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
466 | + } else { |
|
467 | + $colspan = count($this->_columns) + 1; |
|
468 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
469 | + } |
|
470 | + $this->_hasActions = $doWeHaveActions; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * @param bool $debug |
|
475 | + * @return mixed |
|
476 | + */ |
|
477 | + public function fetchObjects($debug = false) |
|
478 | + { |
|
479 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + public function getDefaultFilter() |
|
486 | + { |
|
487 | + if ($this->_filtersel) { |
|
488 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
489 | + } else { |
|
490 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @return array|bool |
|
496 | + */ |
|
497 | + public function getFiltersArray() |
|
498 | + { |
|
499 | + $ret = array(); |
|
500 | + $field = array(); |
|
501 | + $field['caption'] = _CO_OBJ_NONE; |
|
502 | + $field['selected'] = ''; |
|
503 | + $ret['default'] = $field; |
|
504 | + unset($field); |
|
505 | + |
|
506 | + if ($this->_filterseloptions) { |
|
507 | + foreach ($this->_filterseloptions as $key => $value) { |
|
508 | + $field = array(); |
|
509 | + if (is_array($value)) { |
|
510 | + $field['caption'] = $key; |
|
511 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
512 | + } else { |
|
513 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
514 | + $field['selected'] = $this->_filtersel == $key ? "selected='selected'" : ''; |
|
515 | + } |
|
516 | + $ret[$key] = $field; |
|
517 | + unset($field); |
|
518 | + } |
|
519 | + } else { |
|
520 | + $ret = false; |
|
521 | + } |
|
522 | + |
|
523 | + return $ret; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * @param $default_filter2 |
|
528 | + */ |
|
529 | + public function setDefaultFilter2($default_filter2) |
|
530 | + { |
|
531 | + $this->_filtersel2 = $default_filter2; |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * @return string |
|
536 | + */ |
|
537 | + public function getDefaultFilter2() |
|
538 | + { |
|
539 | + if ($this->_filtersel2) { |
|
540 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
541 | + } else { |
|
542 | + return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * @return array |
|
548 | + */ |
|
549 | + public function getFilters2Array() |
|
550 | + { |
|
551 | + $ret = array(); |
|
552 | + |
|
553 | + foreach ($this->_filtersel2options as $key => $value) { |
|
554 | + $field = array(); |
|
555 | + $field['caption'] = $value; |
|
556 | + $field['selected'] = $this->_filtersel2 == $key ? "selected='selected'" : ''; |
|
557 | + $ret[$key] = $field; |
|
558 | + unset($field); |
|
559 | + } |
|
560 | + |
|
561 | + return $ret; |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * @param $limitsArray |
|
566 | + * @param $params_of_the_options_sel |
|
567 | + */ |
|
568 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
569 | + { |
|
570 | + // Rendering the form to select options on the table |
|
571 | + $current_urls = smart_getCurrentUrls(); |
|
572 | + $current_url = $current_urls['full']; |
|
573 | + |
|
574 | + /** |
|
575 | + * What was $params_of_the_options_sel doing again ? |
|
576 | + */ |
|
577 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
578 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
579 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * @return array |
|
584 | + */ |
|
585 | + public function getLimitsArray() |
|
586 | + { |
|
587 | + $ret = array(); |
|
588 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
589 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? "selected='selected'" : ''; |
|
590 | + |
|
591 | + $ret['5']['caption'] = '5'; |
|
592 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? "selected='selected'" : ''; |
|
593 | + |
|
594 | + $ret['10']['caption'] = '10'; |
|
595 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? "selected='selected'" : ''; |
|
596 | + |
|
597 | + $ret['15']['caption'] = '15'; |
|
598 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? "selected='selected'" : ''; |
|
599 | + |
|
600 | + $ret['20']['caption'] = '20'; |
|
601 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? "selected='selected'" : ''; |
|
602 | + |
|
603 | + $ret['25']['caption'] = '25'; |
|
604 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? "selected='selected'" : ''; |
|
605 | + |
|
606 | + $ret['30']['caption'] = '30'; |
|
607 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? "selected='selected'" : ''; |
|
608 | + |
|
609 | + $ret['35']['caption'] = '35'; |
|
610 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? "selected='selected'" : ''; |
|
611 | + |
|
612 | + $ret['40']['caption'] = '40'; |
|
613 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? "selected='selected'" : ''; |
|
614 | + |
|
615 | + return $ret; |
|
616 | + } |
|
617 | + |
|
618 | + /** |
|
619 | + * @return bool |
|
620 | + */ |
|
621 | + public function getObjects() |
|
622 | + { |
|
623 | + return $this->_objects; |
|
624 | + } |
|
625 | + |
|
626 | + public function hideActionColumnTitle() |
|
627 | + { |
|
628 | + $this->_showActionsColumnTitle = false; |
|
629 | + } |
|
630 | + |
|
631 | + public function hideFilterAndLimit() |
|
632 | + { |
|
633 | + $this->_showFilterAndLimit = false; |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * @return array |
|
638 | + */ |
|
639 | + public function getOrdersArray() |
|
640 | + { |
|
641 | + $ret = array(); |
|
642 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
643 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
644 | + |
|
645 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
646 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? "selected='selected'" : ''; |
|
647 | + |
|
648 | + return $ret; |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * @return mixed|string|void |
|
653 | + */ |
|
654 | + public function renderD() |
|
655 | + { |
|
656 | + return $this->render(false, true); |
|
657 | + } |
|
658 | + |
|
659 | + public function renderForPrint() |
|
660 | + { |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * @param bool $fetchOnly |
|
665 | + * @param bool $debug |
|
666 | + * @return mixed|string|void |
|
667 | + */ |
|
668 | + public function render($fetchOnly = false, $debug = false) |
|
669 | + { |
|
670 | + include_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
671 | + |
|
672 | + $this->_tpl = new XoopsTpl(); |
|
673 | + |
|
674 | + /** |
|
675 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
676 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
677 | + * and we will free it after |
|
678 | + */ |
|
679 | + $this->_tempObject = $this->_objectHandler->create(); |
|
680 | + |
|
681 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
682 | + |
|
683 | + $this->setSortOrder(); |
|
684 | + |
|
685 | + if (!$this->_isTree) { |
|
686 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
687 | + } else { |
|
688 | + $this->_limitsel = 'all'; |
|
689 | + } |
|
690 | + |
|
691 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
692 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
693 | + $limitsArray = $this->getLimitsArray(); |
|
694 | + $this->_criteria->setLimit($this->_limitsel); |
|
695 | + |
|
696 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
697 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
698 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
699 | + $filtersArray = $this->getFiltersArray(); |
|
700 | + |
|
701 | + if ($filtersArray) { |
|
702 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
703 | + } |
|
704 | + |
|
705 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
706 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
707 | + // check if method associate with this filter exists in the handler |
|
708 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
709 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
710 | + $this->_criteria->add($filter['criteria']); |
|
711 | + } else { |
|
712 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
713 | + |
|
714 | + // then we will create the selfilter2 options by calling this method |
|
715 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
716 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
717 | + |
|
718 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
719 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
720 | + |
|
721 | + $filters2Array = $this->getFilters2Array(); |
|
722 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
723 | + |
|
724 | + smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
725 | + if ($this->_filtersel2 !== 'default') { |
|
726 | + $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2)); |
|
727 | + } |
|
728 | + } |
|
729 | + } |
|
730 | + } |
|
731 | + // Check if we have a quicksearch |
|
732 | + |
|
733 | + if (isset($_POST['quicksearch_' . $this->_id]) && $_POST['quicksearch_' . $this->_id] != '') { |
|
734 | + $quicksearch_criteria = new CriteriaCompo(); |
|
735 | + if (is_array($this->_quickSearch['fields'])) { |
|
736 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
737 | + $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
738 | + } |
|
739 | + } else { |
|
740 | + $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
741 | + } |
|
742 | + $this->_criteria->add($quicksearch_criteria); |
|
743 | + } |
|
744 | + |
|
745 | + $this->_objects = $this->fetchObjects($debug); |
|
746 | + |
|
747 | + include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
748 | + if ($this->_criteria->getLimit() > 0) { |
|
749 | + |
|
750 | + /** |
|
751 | + * Geeting rid of the old params |
|
752 | + * $new_get_array is an array containing the new GET parameters |
|
753 | + */ |
|
754 | + $new_get_array = array(); |
|
755 | + |
|
756 | + /** |
|
757 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
758 | + * but without the pagenave parameters. This array will be used in the |
|
759 | + * OptionsSelection |
|
760 | + */ |
|
761 | + $params_of_the_options_sel = array(); |
|
762 | + |
|
763 | + $not_needed_params = array('sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName); |
|
764 | + foreach ($_GET as $k => $v) { |
|
765 | + if (!in_array($k, $not_needed_params)) { |
|
766 | + $new_get_array[] = "$k=$v"; |
|
767 | + $params_of_the_options_sel[] = "$k=$v"; |
|
768 | + } |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Adding the new params of the pagenav |
|
773 | + */ |
|
774 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
775 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
776 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
777 | + $otherParams = implode('&', $new_get_array); |
|
778 | + |
|
779 | + $pagenav = |
|
780 | + new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
781 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
782 | + } |
|
783 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
784 | + |
|
785 | + // retreive the current url and the query string |
|
786 | + $current_urls = smart_getCurrentUrls(); |
|
787 | + $current_url = $current_urls['full_phpself']; |
|
788 | + $query_string = $current_urls['querystring']; |
|
789 | + if ($query_string) { |
|
790 | + $query_string = str_replace('?', '', $query_string); |
|
791 | + } |
|
792 | + $query_stringArray = explode('&', $query_string); |
|
793 | + $new_query_stringArray = array(); |
|
794 | + foreach ($query_stringArray as $query_string) { |
|
795 | + if (strpos($query_string, 'sortsel') == false && strpos($query_string, 'ordersel') == false) { |
|
796 | + $new_query_stringArray[] = $query_string; |
|
797 | + } |
|
798 | + } |
|
799 | + $new_query_string = implode('&', $new_query_stringArray); |
|
800 | + |
|
801 | + $orderArray = array(); |
|
802 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
803 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
804 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
805 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
806 | + |
|
807 | + $aColumns = array(); |
|
808 | + |
|
809 | + foreach ($this->_columns as $column) { |
|
810 | + $qs_param = ''; |
|
811 | + $aColumn = array(); |
|
812 | + $aColumn['width'] = $column->getWidth(); |
|
813 | + $aColumn['align'] = $column->getAlign(); |
|
814 | + $aColumn['key'] = $column->getKeyName(); |
|
815 | + if ($column->_keyname === 'checked') { |
|
816 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' |
|
817 | + . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' |
|
818 | + . $this->_id |
|
819 | + . ', \'selected_smartobjects\');" />'; |
|
820 | + } elseif ($column->getCustomCaption()) { |
|
821 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
822 | + } else { |
|
823 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
824 | + } |
|
825 | + // Are we doing a GET sort on this column ? |
|
826 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
827 | + || ($this->_sortsel == $column->getKeyName()); |
|
828 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
829 | + |
|
830 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && $_REQUEST['quicksearch_' . $this->_id] != '') { |
|
831 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
832 | + } |
|
833 | + if (!$this->_enableColumnsSorting || $column->_keyname === 'checked' || !$column->isSortable()) { |
|
834 | + $aColumn['caption'] = $aColumn['caption']; |
|
835 | + } elseif ($getSort) { |
|
836 | + $aColumn['caption'] = '<a href="' |
|
837 | + . $current_url |
|
838 | + . '?' |
|
839 | + . $this->_objectHandler->_itemname |
|
840 | + . '_' |
|
841 | + . 'sortsel=' |
|
842 | + . $column->getKeyName() |
|
843 | + . '&' |
|
844 | + . $this->_objectHandler->_itemname |
|
845 | + . '_' |
|
846 | + . 'ordersel=' |
|
847 | + . $orderArray[$order]['neworder'] |
|
848 | + . $qs_param |
|
849 | + . '&' |
|
850 | + . $new_query_string |
|
851 | + . '">' |
|
852 | + . $aColumn['caption'] |
|
853 | + . ' <img src="' |
|
854 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
855 | + . $orderArray[$order]['image'] |
|
856 | + . '" alt="ASC" /></a>'; |
|
857 | + } else { |
|
858 | + $aColumn['caption'] = '<a href="' |
|
859 | + . $current_url |
|
860 | + . '?' |
|
861 | + . $this->_objectHandler->_itemname |
|
862 | + . '_' |
|
863 | + . 'sortsel=' |
|
864 | + . $column->getKeyName() |
|
865 | + . '&' |
|
866 | + . $this->_objectHandler->_itemname |
|
867 | + . '_' |
|
868 | + . 'ordersel=ASC' |
|
869 | + . $qs_param |
|
870 | + . '&' |
|
871 | + . $new_query_string |
|
872 | + . '">' |
|
873 | + . $aColumn['caption'] |
|
874 | + . '</a>'; |
|
875 | + } |
|
876 | + $aColumns[] = $aColumn; |
|
877 | + } |
|
878 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
879 | + |
|
880 | + if ($this->_quickSearch) { |
|
881 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
882 | + } |
|
883 | + |
|
884 | + $this->createTableRows(); |
|
885 | + |
|
886 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
887 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
888 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
889 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
890 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
891 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
892 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
893 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
894 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
895 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
896 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
897 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
898 | + if (!empty($this->_withSelectedActions)) { |
|
899 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
900 | + } |
|
901 | + |
|
902 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
903 | + if ($fetchOnly) { |
|
904 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
905 | + } else { |
|
906 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
907 | + } |
|
908 | + } |
|
909 | + |
|
910 | + public function disableColumnsSorting() |
|
911 | + { |
|
912 | + $this->_enableColumnsSorting = false; |
|
913 | + } |
|
914 | + |
|
915 | + /** |
|
916 | + * @param bool $debug |
|
917 | + * @return mixed|string|void |
|
918 | + */ |
|
919 | + public function fetch($debug = false) |
|
920 | + { |
|
921 | + return $this->render(true, $debug); |
|
922 | + } |
|
923 | 923 | } |
@@ -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 | - include_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 | + include_once($filename); |
|
43 | + $function = 'smarthook_' . $lower_hook_name; |
|
44 | + if (function_exists($function)) { |
|
45 | + $function(); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |