This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | /** |
||
4 | * |
||
5 | * Module: SmartPartner |
||
6 | * Author: The SmartFactory <www.smartfactory.ca> |
||
7 | * Licence: GNU |
||
8 | */ |
||
9 | |||
10 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
11 | include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
||
12 | include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecthandler.php'; |
||
13 | |||
14 | // Partners status |
||
15 | define('_SPARTNER_STATUS_NOTSET', -1); |
||
16 | define('_SPARTNER_STATUS_ALL', 0); |
||
17 | define('_SPARTNER_STATUS_SUBMITTED', 1); |
||
18 | define('_SPARTNER_STATUS_ACTIVE', 2); |
||
19 | define('_SPARTNER_STATUS_REJECTED', 3); |
||
20 | define('_SPARTNER_STATUS_INACTIVE', 4); |
||
21 | |||
22 | define('_SPARTNER_NOT_PARTNER_SUBMITTED', 1); |
||
23 | define('_SPARTNER_NOT_PARTNER_APPROVED', 2); |
||
24 | define('_SPARTNER_NOT_PARTNER_NEW', 3); |
||
25 | define('_SPARTNER_NOT_OFFER_NEW', 4); |
||
26 | |||
27 | /** |
||
28 | * Class SmartpartnerPartner |
||
29 | */ |
||
30 | class SmartpartnerPartner extends SmartObject |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
31 | { |
||
32 | public $_extendedInfo = null; |
||
33 | |||
34 | /** |
||
35 | * SmartpartnerPartner constructor. |
||
36 | * @param null $id |
||
37 | */ |
||
38 | public function __construct($id = null) |
||
39 | { |
||
40 | $this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
41 | $this->initVar('id', XOBJ_DTYPE_INT, 0, false); |
||
42 | $this->initVar('categoryid', XOBJ_DTYPE_TXTBOX, '', false); |
||
43 | $this->initVar('datesub', XOBJ_DTYPE_INT, 0, false); |
||
44 | $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false); |
||
45 | $this->initVar('summary', XOBJ_DTYPE_TXTAREA, '', true); |
||
46 | $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false); |
||
47 | $this->initVar('contact_name', XOBJ_DTYPE_TXTBOX, '', false); |
||
48 | $this->initVar('contact_email', XOBJ_DTYPE_TXTBOX, '', false); |
||
49 | $this->initVar('contact_phone', XOBJ_DTYPE_TXTBOX, '', false); |
||
50 | $this->initVar('adress', XOBJ_DTYPE_TXTAREA, '', false); |
||
51 | $this->initVar('url', XOBJ_DTYPE_TXTBOX, '', false); |
||
52 | $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', true); |
||
53 | $this->initVar('image_url', XOBJ_DTYPE_TXTBOX, '', false); |
||
54 | $this->initVar('weight', XOBJ_DTYPE_INT, 0, false, 10); |
||
55 | $this->initVar('hits', XOBJ_DTYPE_INT, 0, true, 10); |
||
56 | $this->initVar('hits_page', XOBJ_DTYPE_INT, 0, true, 10); |
||
57 | $this->initVar('status', XOBJ_DTYPE_INT, _SPARTNER_STATUS_NOTSET, false, 10); |
||
58 | $this->initVar('last_update', XOBJ_DTYPE_INT, 0, false); |
||
59 | $this->initVar('email_priv', XOBJ_DTYPE_INT, 0, false); |
||
60 | $this->initVar('phone_priv', XOBJ_DTYPE_INT, 0, false); |
||
61 | $this->initVar('adress_priv', XOBJ_DTYPE_INT, 0, false); |
||
62 | $this->initVar('showsummary', XOBJ_DTYPE_INT, 1, false); |
||
63 | $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
||
64 | |||
65 | if (isset($id)) { |
||
66 | $smartPartnerPartnerHandler = new SmartpartnerPartnerHandler($this->db); |
||
67 | $partner = $smartPartnerPartnerHandler->get($id); |
||
68 | foreach ($partner->vars as $k => $v) { |
||
69 | $this->assignVar($k, $v['value']); |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function id() |
||
78 | { |
||
79 | return $this->getVar('id'); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return mixed |
||
84 | */ |
||
85 | public function categoryid() |
||
86 | { |
||
87 | return $this->getVar('categoryid'); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return mixed |
||
92 | */ |
||
93 | public function weight() |
||
94 | { |
||
95 | return $this->getVar('weight'); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @return mixed |
||
100 | */ |
||
101 | public function email_priv() |
||
102 | { |
||
103 | return $this->getVar('email_priv'); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return mixed |
||
108 | */ |
||
109 | public function phone_priv() |
||
110 | { |
||
111 | return $this->getVar('phone_priv'); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return mixed |
||
116 | */ |
||
117 | public function adress_priv() |
||
118 | { |
||
119 | return $this->getVar('adress_priv'); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @return mixed |
||
124 | */ |
||
125 | public function hits() |
||
126 | { |
||
127 | return $this->getVar('hits'); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @return mixed |
||
132 | */ |
||
133 | public function hits_page() |
||
134 | { |
||
135 | return $this->getVar('hits_page'); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @param string $format |
||
140 | * @return mixed |
||
141 | */ |
||
142 | public function url($format = 'S') |
||
143 | { |
||
144 | return $this->getVar('url', $format); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @param string $format |
||
149 | * @return mixed|string |
||
150 | */ |
||
151 | public function image($format = 'S') |
||
152 | { |
||
153 | if ($this->getVar('image') != '') { |
||
154 | return $this->getVar('image', $format); |
||
155 | } else { |
||
156 | return 'blank.png'; |
||
157 | } |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @param string $format |
||
162 | * @return mixed |
||
163 | */ |
||
164 | public function image_url($format = 'S') |
||
165 | { |
||
166 | return $this->getVar('image_url', $format); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @param string $format |
||
171 | * @return mixed |
||
172 | */ |
||
173 | View Code Duplication | public function title($format = 'S') |
|
174 | { |
||
175 | $ret = $this->getVar('title', $format); |
||
176 | if (($format === 's') || ($format === 'S') || ($format === 'show')) { |
||
177 | $myts = MyTextSanitizer::getInstance(); |
||
178 | $ret = $myts->displayTarea($ret); |
||
179 | } |
||
180 | |||
181 | return $ret; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * @param string $format |
||
186 | * @return mixed|string |
||
187 | */ |
||
188 | public function datesub($format = 'S') |
||
189 | { |
||
190 | $ret = $this->getVar('datesub', $format); |
||
191 | if (($format === 's') || ($format === 'S') || ($format === 'show')) { |
||
192 | $ret = formatTimestamp($ret, 's'); |
||
193 | } |
||
194 | |||
195 | return $ret; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @param int $maxLength |
||
200 | * @param string $format |
||
201 | * @return mixed|string |
||
202 | */ |
||
203 | public function summary($maxLength = 0, $format = 'S') |
||
204 | { |
||
205 | $ret = $this->getVar('summary', $format); |
||
206 | |||
207 | if ($maxLength != 0) { |
||
208 | if (!XOOPS_USE_MULTIBYTES) { |
||
209 | if (strlen($ret) >= $maxLength) { |
||
210 | $ret = xoops_substr(smartpartner_metagen_html2text($ret), 0, $maxLength); |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | |||
215 | return $ret; |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @param string $format |
||
220 | * @return mixed |
||
221 | */ |
||
222 | public function description($format = 'S') |
||
223 | { |
||
224 | return $this->getVar('description', $format); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * @param string $format |
||
229 | * @return mixed |
||
230 | */ |
||
231 | View Code Duplication | public function contact_name($format = 'S') |
|
232 | { |
||
233 | $ret = $this->getVar('contact_name', $format); |
||
234 | if (($format === 's') || ($format === 'S') || ($format === 'show')) { |
||
235 | $myts = MyTextSanitizer::getInstance(); |
||
236 | $ret = $myts->displayTarea($ret); |
||
237 | } |
||
238 | |||
239 | return $ret; |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * @param string $format |
||
244 | * @return mixed |
||
245 | */ |
||
246 | View Code Duplication | public function contact_email($format = 'S') |
|
247 | { |
||
248 | $ret = $this->getVar('contact_email', $format); |
||
249 | if (($format === 's') || ($format === 'S') || ($format === 'show')) { |
||
250 | $myts = MyTextSanitizer::getInstance(); |
||
251 | $ret = $myts->displayTarea($ret); |
||
252 | } |
||
253 | |||
254 | return $ret; |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * @param string $format |
||
259 | * @return mixed |
||
260 | */ |
||
261 | View Code Duplication | public function contact_phone($format = 'S') |
|
262 | { |
||
263 | $ret = $this->getVar('contact_phone', $format); |
||
264 | if (($format === 's') || ($format === 'S') || ($format === 'show')) { |
||
265 | $myts = MyTextSanitizer::getInstance(); |
||
266 | $ret = $myts->displayTarea($ret); |
||
267 | } |
||
268 | |||
269 | return $ret; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * @param string $format |
||
274 | * @return mixed |
||
275 | */ |
||
276 | public function adress($format = 'S') |
||
277 | { |
||
278 | $ret = $this->getVar('adress', $format); |
||
279 | |||
280 | return $ret; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @return mixed |
||
285 | */ |
||
286 | public function status() |
||
287 | { |
||
288 | return $this->getVar('status'); |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * @param $forWhere |
||
293 | * @return string |
||
294 | */ |
||
295 | public function getUrlLink($forWhere) |
||
296 | { |
||
297 | if ($forWhere === 'block') { |
||
298 | View Code Duplication | if ($this->extentedInfo()) { |
|
299 | return '<a href="' . SMARTPARTNER_URL . 'partner.php?id=' . $this->id() . '">'; |
||
300 | } else { |
||
301 | if ($this->url()) { |
||
302 | return '<a href="' . $this->url() . '" target="_blank">'; |
||
303 | } else { |
||
304 | return ''; |
||
305 | } |
||
306 | } |
||
307 | } elseif ($forWhere === 'index') { |
||
308 | View Code Duplication | if ($this->extentedInfo()) { |
|
309 | return '<a href="' . SMARTPARTNER_URL . 'partner.php?id=' . $this->id() . '">'; |
||
310 | } else { |
||
311 | if ($this->url()) { |
||
312 | return '<a href="' . SMARTPARTNER_URL . 'vpartner.php?id=' . $this->id() . '">'; |
||
313 | } else { |
||
314 | return ''; |
||
315 | } |
||
316 | } |
||
317 | } elseif ($forWhere === 'partner') { |
||
318 | if ($this->url()) { |
||
319 | return '<a href="' . SMARTPARTNER_URL . 'vpartner.php?id=' . $this->id() . '">'; |
||
320 | } else { |
||
321 | return ''; |
||
322 | } |
||
323 | } |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * @return mixed|string |
||
328 | */ |
||
329 | public function getImageUrl() |
||
330 | { |
||
331 | View Code Duplication | if (($this->getVar('image') !== '') && ($this->getVar('image') !== 'blank.png') && ($this->getVar('image') !== '-1')) { |
|
332 | return smartpartner_getImageDir('', false) . $this->image(); |
||
333 | } elseif (!$this->getVar('image_url')) { |
||
334 | return smartpartner_getImageDir('', false) . 'blank.png'; |
||
335 | } else { |
||
336 | return $this->getVar('image_url'); |
||
337 | } |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * @return bool|string |
||
342 | */ |
||
343 | public function getImagePath() |
||
344 | { |
||
345 | if (($this->getVar('image') !== '') && ($this->getVar('image') !== 'blank.png')) { |
||
346 | return smartpartner_getImageDir() . $this->image(); |
||
347 | } else { |
||
348 | return false; |
||
349 | } |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * @return string |
||
354 | */ |
||
355 | public function getImageLink() |
||
356 | { |
||
357 | $ret = "<a href='rrvpartner.php?id=" . $this->id() . "' target='_blank'>"; |
||
358 | if ($this->getVar('image') != '') { |
||
359 | $ret .= "<img src='" . $this->getImageUrl() . "' alt='" . $this->url() . "' border='0' /></a>"; |
||
360 | } else { |
||
361 | $ret .= "<img src='" . $this->image_url() . "' alt='" . $this->url() . "' border='0' /></a>"; |
||
362 | } |
||
363 | |||
364 | return $ret; |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * @return string |
||
369 | */ |
||
370 | public function getStatusName() |
||
371 | { |
||
372 | switch ($this->status()) { |
||
373 | case _SPARTNER_STATUS_ACTIVE: |
||
374 | return _CO_SPARTNER_ACTIVE; |
||
375 | break; |
||
376 | |||
377 | case _SPARTNER_STATUS_INACTIVE: |
||
378 | return _CO_SPARTNER_INACTIVE; |
||
379 | break; |
||
380 | |||
381 | case _SPARTNER_STATUS_REJECTED: |
||
382 | return _CO_SPARTNER_REJECTED; |
||
383 | break; |
||
384 | |||
385 | case _SPARTNER_STATUS_SUBMITTED: |
||
386 | return _CO_SPARTNER_SUBMITTED; |
||
387 | break; |
||
388 | |||
389 | case _SPARTNER_STATUS_NOTSET: |
||
390 | default; |
||
391 | |||
392 | return _CO_SPARTNER_NOTSET; |
||
393 | break; |
||
394 | } |
||
395 | } |
||
396 | |||
397 | /** |
||
398 | * @return bool |
||
399 | */ |
||
400 | public function notLoaded() |
||
401 | { |
||
402 | return ($this->getVar('id') == 0); |
||
403 | } |
||
404 | |||
405 | /** |
||
406 | * @return bool|null |
||
407 | */ |
||
408 | public function extentedInfo() |
||
409 | { |
||
410 | if ($this->_extendedInfo) { |
||
411 | return $this->_extendedInfo; |
||
412 | } |
||
413 | if (!$this->description() && !$this->contact_name() && !$this->contact_email() && !$this->contact_phone() && !$this->adress()) { |
||
414 | $this->_extendedInfo = false; |
||
415 | } else { |
||
416 | $this->_extendedInfo = true; |
||
417 | } |
||
418 | |||
419 | return $this->_extendedInfo; |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * @param bool $force |
||
424 | * @return bool |
||
425 | */ |
||
426 | public function store($force = true) |
||
427 | { |
||
428 | $smartPartnerPartnerHandler = new SmartpartnerPartnerHandler($this->db); |
||
429 | |||
430 | return $smartPartnerPartnerHandler->insert($this, $force); |
||
431 | } |
||
432 | |||
433 | /** |
||
434 | * @return bool |
||
435 | */ |
||
436 | View Code Duplication | public function updateHits() |
|
437 | { |
||
438 | $sql = 'UPDATE ' . $this->db->prefix('smartpartner_partner') . ' SET hits=hits+1 WHERE id = ' . $this->id(); |
||
439 | if ($this->db->queryF($sql)) { |
||
440 | return true; |
||
441 | } else { |
||
442 | return false; |
||
443 | } |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * @return bool |
||
448 | */ |
||
449 | View Code Duplication | public function updateHits_page() |
|
450 | { |
||
451 | $sql = 'UPDATE ' . $this->db->prefix('smartpartner_partner') . ' SET hits_page=hits_page+1 WHERE id = ' . $this->id(); |
||
452 | if ($this->db->queryF($sql)) { |
||
453 | return true; |
||
454 | } else { |
||
455 | return false; |
||
456 | } |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * @param array $notifications |
||
461 | */ |
||
462 | public function sendNotifications($notifications = array()) |
||
463 | { |
||
464 | $smartModule =& smartpartner_getModuleInfo(); |
||
465 | $module_id = $smartModule->getVar('mid'); |
||
466 | |||
467 | $myts = MyTextSanitizer::getInstance(); |
||
468 | $notificationHandler = xoops_getHandler('notification'); |
||
469 | |||
470 | $tags = array(); |
||
471 | $tags['MODULE_NAME'] = $myts->displayTarea($smartModule->getVar('name')); |
||
472 | $tags['PARTNER_NAME'] = $this->title(20); |
||
473 | foreach ($notifications as $notification) { |
||
474 | switch ($notification) { |
||
475 | |||
476 | case _SPARTNER_NOT_PARTNER_SUBMITTED: |
||
477 | $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/admin/partner.php?op=mod&id=' . $this->id(); |
||
478 | $notificationHandler->triggerEvent('global_partner', 0, 'submitted', $tags); |
||
479 | break; |
||
480 | |||
481 | View Code Duplication | case _SPARTNER_NOT_PARTNER_APPROVED: |
|
482 | $tags['PARTNER_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/partner.php?id=' . $this->id(); |
||
483 | $notificationHandler->triggerEvent('partner', $this->id(), 'approved', $tags); |
||
484 | break; |
||
485 | |||
486 | View Code Duplication | case _SPARTNER_NOT_PARTNER_NEW: |
|
487 | $tags['PARTNER_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/partner.php?id=' . $this->id(); |
||
488 | $notificationHandler->triggerEvent('global_partner', 0, 'new_partner', $tags); |
||
489 | break; |
||
490 | |||
491 | case -1: |
||
492 | default: |
||
493 | break; |
||
494 | } |
||
495 | } |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * @param $original_status |
||
500 | * @param $new_status |
||
501 | * @return array |
||
502 | */ |
||
503 | public function getRedirectMsg($original_status, $new_status) |
||
504 | { |
||
505 | $redirect_msgs = array(); |
||
506 | |||
507 | switch ($original_status) { |
||
508 | |||
509 | View Code Duplication | case _SPARTNER_STATUS_NOTSET: |
|
510 | switch ($new_status) { |
||
511 | case _SPARTNER_STATUS_ACTIVE: |
||
512 | $redirect_msgs['success'] = _AM_SPARTNER_NOTSET_ACTIVE_SUCCESS; |
||
513 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
514 | break; |
||
515 | |||
516 | case _SPARTNER_STATUS_INACTIVE: |
||
517 | $redirect_msgs['success'] = _AM_SPARTNER_NOTSET_INACTIVE_SUCCESS; |
||
518 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
519 | break; |
||
520 | } |
||
521 | break; |
||
522 | |||
523 | View Code Duplication | case _SPARTNER_STATUS_SUBMITTED: |
|
524 | switch ($new_status) { |
||
525 | case _SPARTNER_STATUS_ACTIVE: |
||
526 | $redirect_msgs['success'] = _AM_SPARTNER_SUBMITTED_ACTIVE_SUCCESS; |
||
527 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
528 | break; |
||
529 | |||
530 | case _SPARTNER_STATUS_INACTIVE: |
||
531 | $redirect_msgs['success'] = _AM_SPARTNER_SUBMITTED_INACTIVE_SUCCESS; |
||
532 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
533 | break; |
||
534 | |||
535 | case _SPARTNER_STATUS_REJECTED: |
||
536 | $redirect_msgs['success'] = _AM_SPARTNER_SUBMITTED_REJECTED_SUCCESS; |
||
537 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
538 | break; |
||
539 | } |
||
540 | break; |
||
541 | |||
542 | View Code Duplication | case _SPARTNER_STATUS_ACTIVE: |
|
543 | switch ($new_status) { |
||
544 | case _SPARTNER_STATUS_ACTIVE: |
||
545 | $redirect_msgs['success'] = _AM_SPARTNER_ACTIVE_ACTIVE_SUCCESS; |
||
546 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
547 | break; |
||
548 | |||
549 | case _SPARTNER_STATUS_INACTIVE: |
||
550 | $redirect_msgs['success'] = _AM_SPARTNER_ACTIVE_INACTIVE_SUCCESS; |
||
551 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
552 | break; |
||
553 | |||
554 | } |
||
555 | break; |
||
556 | |||
557 | View Code Duplication | case _SPARTNER_STATUS_INACTIVE: |
|
558 | switch ($new_status) { |
||
559 | case _SPARTNER_STATUS_ACTIVE: |
||
560 | $redirect_msgs['success'] = _AM_SPARTNER_INACTIVE_ACTIVE_SUCCESS; |
||
561 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
562 | break; |
||
563 | |||
564 | case _SPARTNER_STATUS_INACTIVE: |
||
565 | $redirect_msgs['success'] = _AM_SPARTNER_INACTIVE_INACTIVE_SUCCESS; |
||
566 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
567 | break; |
||
568 | |||
569 | } |
||
570 | break; |
||
571 | |||
572 | View Code Duplication | case _SPARTNER_STATUS_REJECTED: |
|
573 | switch ($new_status) { |
||
574 | case _SPARTNER_STATUS_ACTIVE: |
||
575 | $redirect_msgs['success'] = _AM_SPARTNER_REJECTED_ACTIVE_SUCCESS; |
||
576 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
577 | break; |
||
578 | |||
579 | case _SPARTNER_STATUS_INACTIVE: |
||
580 | $redirect_msgs['success'] = _AM_SPARTNER_REJECTED_INACTIVE_SUCCESS; |
||
581 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
582 | break; |
||
583 | |||
584 | case _SPARTNER_STATUS_REJECTED: |
||
585 | $redirect_msgs['success'] = _AM_SPARTNER_REJECTED_REJECTED_SUCCESS; |
||
586 | $redirect_msgs['error'] = _AM_SPARTNER_PARTNER_NOT_UPDATED; |
||
587 | break; |
||
588 | } |
||
589 | break; |
||
590 | } |
||
591 | |||
592 | return $redirect_msgs; |
||
593 | } |
||
594 | |||
595 | /** |
||
596 | * @return array |
||
597 | */ |
||
598 | public function getAvailableStatus() |
||
599 | { |
||
600 | switch ($this->status()) { |
||
601 | View Code Duplication | case _SPARTNER_STATUS_NOTSET: |
|
602 | $ret = array( |
||
603 | _SPARTNER_STATUS_ACTIVE => _AM_SPARTNER_ACTIVE, |
||
604 | _SPARTNER_STATUS_INACTIVE => _AM_SPARTNER_INACTIVE |
||
605 | ); |
||
606 | break; |
||
607 | View Code Duplication | case _SPARTNER_STATUS_SUBMITTED: |
|
608 | $ret = array( |
||
609 | _SPARTNER_STATUS_ACTIVE => _AM_SPARTNER_ACTIVE, |
||
610 | _SPARTNER_STATUS_REJECTED => _AM_SPARTNER_REJECTED, |
||
611 | _SPARTNER_STATUS_INACTIVE => _AM_SPARTNER_INACTIVE |
||
612 | ); |
||
613 | break; |
||
614 | |||
615 | View Code Duplication | case _SPARTNER_STATUS_ACTIVE: |
|
616 | $ret = array( |
||
617 | _SPARTNER_STATUS_ACTIVE => _AM_SPARTNER_ACTIVE, |
||
618 | _SPARTNER_STATUS_INACTIVE => _AM_SPARTNER_INACTIVE |
||
619 | ); |
||
620 | break; |
||
621 | |||
622 | View Code Duplication | case _SPARTNER_STATUS_INACTIVE: |
|
623 | $ret = array( |
||
624 | _SPARTNER_STATUS_ACTIVE => _AM_SPARTNER_ACTIVE, |
||
625 | _SPARTNER_STATUS_INACTIVE => _AM_SPARTNER_INACTIVE |
||
626 | ); |
||
627 | break; |
||
628 | |||
629 | View Code Duplication | case _SPARTNER_STATUS_REJECTED: |
|
630 | $ret = array( |
||
631 | _SPARTNER_STATUS_ACTIVE => _AM_SPARTNER_ACTIVE, |
||
632 | _SPARTNER_STATUS_REJECTED => _AM_SPARTNER_REJECTED, |
||
633 | _SPARTNER_STATUS_INACTIVE => _AM_SPARTNER_INACTIVE |
||
634 | ); |
||
635 | break; |
||
636 | } |
||
637 | |||
638 | return $ret; |
||
639 | } |
||
640 | |||
641 | public function setUpdated() |
||
642 | { |
||
643 | $this->setVar('last_update', time()); |
||
644 | $this->store(); |
||
645 | } |
||
646 | |||
647 | /** |
||
648 | * @return mixed |
||
649 | */ |
||
650 | public function getFiles() |
||
651 | { |
||
652 | global $smartPartnerFileHandler; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
653 | |||
654 | return $smartPartnerFileHandler->getAllFiles($this->id(), _SPARTNER_STATUS_FILE_ACTIVE); |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * @param string $url_link_type |
||
659 | * @return mixed |
||
660 | */ |
||
661 | public function toArray($url_link_type = 'partner') |
||
662 | { |
||
663 | $smartConfig = smartpartner_getModuleConfig(); |
||
664 | |||
665 | $partner['id'] = $this->id(); |
||
666 | $partner['categoryid'] = $this->categoryid(); |
||
667 | $partner['hits'] = $this->hits(); |
||
668 | $partner['hits_page'] = $this->hits_page(); |
||
669 | $partner['url'] = $this->url(); |
||
670 | $partner['urllink'] = $this->getUrlLink($url_link_type); |
||
671 | $partner['image'] = $this->getImageUrl(); |
||
672 | |||
673 | $partner['title'] = $this->title(); |
||
674 | $partner['datesub'] = $this->datesub(); |
||
675 | $partner['clean_title'] = $partner['title']; |
||
676 | $partner['summary'] = $this->summary(); |
||
677 | |||
678 | $partner['contact_name'] = $this->contact_name(); |
||
679 | $partner['contact_email'] = $this->contact_email(); |
||
680 | $partner['contact_phone'] = $this->contact_phone(); |
||
681 | $partner['adress'] = $this->adress(); |
||
682 | $partner['email_priv'] = $this->email_priv(); |
||
683 | $partner['phone_priv'] = $this->phone_priv(); |
||
684 | $partner['adress_priv'] = $this->adress_priv(); |
||
685 | |||
686 | $image_info = smartpartner_imageResize($this->getImagePath(), $smartConfig['img_max_width'], $smartConfig['img_max_height']); |
||
687 | $partner['img_attr'] = $image_info[3]; |
||
688 | |||
689 | $partner['readmore'] = $this->extentedInfo(); |
||
690 | if ((time() - $this->datesub('e')) < ($smartConfig['updated_period'] * 24 * 3600)) { |
||
691 | $partner['update_status'] = 'new'; |
||
692 | } elseif ((time() - $this->getVar('last_update')) < ($smartConfig['updated_period'] * 24 * 3600)) { |
||
693 | $partner['update_status'] = 'updated'; |
||
694 | } else { |
||
695 | $partner['update_status'] = 'none'; |
||
696 | } |
||
697 | //-------------- |
||
698 | global $smartPermissionsHandler, $smartPartnerPartnerHandler, $xoopsUser; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
699 | include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectpermission.php'; |
||
700 | if (!$smartPartnerPartnerHandler) { |
||
701 | $smartPartnerPartnerHandler = smartpartner_gethandler('partner'); |
||
702 | } |
||
703 | $smartPermissionsHandler = new SmartobjectPermissionHandler($smartPartnerPartnerHandler); |
||
704 | $grantedGroups = $smartPermissionsHandler->getGrantedGroups('full_view', $this->id()); |
||
705 | $partGrantedGroups = $smartPermissionsHandler->getGrantedGroups('partial_view', $this->id()); |
||
706 | |||
707 | $userGroups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
||
708 | |||
709 | if (array_intersect($userGroups, $grantedGroups)) { |
||
710 | $partner['display_type'] = 'full'; |
||
711 | } elseif (array_intersect($userGroups, $partGrantedGroups)) { |
||
712 | $partner['display_type'] = 'part'; |
||
713 | } else { |
||
714 | $partner['display_type'] = 'none'; |
||
715 | } |
||
716 | if ($this->description() != '' && $partner['display_type'] === 'full') { |
||
717 | $partner['description'] = $this->description(); |
||
718 | } else { |
||
719 | //$partner['description'] = $this->summary(); |
||
720 | } |
||
721 | $partner['showsummary'] = $this->getVar('showsummary'); |
||
722 | |||
723 | //-------------- |
||
724 | |||
725 | // Hightlighting searched words |
||
726 | $highlight = true; |
||
727 | if ($highlight && isset($_GET['keywords'])) { |
||
728 | $myts = MyTextSanitizer::getInstance(); |
||
729 | $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
||
730 | $h = new SmartpartnerKeyhighlighter($keywords, true, 'smartpartner_highlighter'); |
||
731 | $partner['title'] = $h->highlight($partner['title']); |
||
732 | $partner['summary'] = $h->highlight($partner['summary']); |
||
733 | $partner['description'] = $h->highlight($partner['description']); |
||
734 | $partner['contact_name'] = $h->highlight($partner['contact_name']); |
||
735 | $partner['contact_email'] = $h->highlight($partner['contact_email']); |
||
736 | $partner['contact_phone'] = $h->highlight($partner['contact_phone']); |
||
737 | $partner['adress'] = $h->highlight($partner['adress']); |
||
738 | } |
||
739 | |||
740 | return $partner; |
||
741 | } |
||
742 | } |
||
743 | |||
744 | /** |
||
745 | * Partner handler class. |
||
746 | * This class is responsible for providing data access mechanisms to the data source |
||
747 | * of Partner class objects. |
||
748 | * |
||
749 | * @author marcan <[email protected]> |
||
750 | * @package SmartPartner |
||
751 | */ |
||
752 | class SmartpartnerPartnerHandler extends SmartPersistableObjectHandler |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
753 | { |
||
754 | /** |
||
755 | * Constructor |
||
756 | * |
||
757 | * @param XoopsDatabase $db reference to a xoops_db object |
||
758 | */ |
||
759 | |||
760 | public function __construct(XoopsDatabase $db) |
||
761 | { |
||
762 | xoops_loadLanguage('common', 'smartpartner'); |
||
763 | parent::__construct($db, 'partner', 'id', 'title', false, 'smartpartner'); |
||
764 | $this->addPermission('full_view', _CO_SPARTNER_FULL_PERM_READ, _CO_SPARTNER_FULL_PERM_READ_DSC); |
||
765 | $this->addPermission('partial_view', _CO_SPARTNER_PART_PERM_READ, _CO_SPARTNER_PART_PERM_READ_DSC); |
||
766 | } |
||
767 | |||
768 | /** |
||
769 | * Singleton - prevent multiple instances of this class |
||
770 | * |
||
771 | * @param objecs|XoopsDatabase $db |
||
772 | * @return object <a href='psi_element://SmartpartnerCategoryHandler'>SmartpartnerCategoryHandler</a> |
||
773 | * @access public |
||
774 | */ |
||
775 | public function getInstance(XoopsDatabase $db) |
||
776 | { |
||
777 | static $instance; |
||
778 | if (null === $instance) { |
||
779 | $instance = new static($db); |
||
780 | } |
||
781 | |||
782 | return $instance; |
||
783 | } |
||
784 | |||
785 | /** |
||
786 | * @param bool $isNew |
||
787 | * @return SmartpartnerPartner |
||
788 | */ |
||
789 | public function create($isNew = true) |
||
790 | { |
||
791 | $partner = new SmartpartnerPartner(); |
||
792 | if ($isNew) { |
||
793 | $partner->setNew(); |
||
794 | } |
||
795 | |||
796 | return $partner; |
||
797 | } |
||
798 | |||
799 | /** |
||
800 | * retrieve a Partner |
||
801 | * |
||
802 | * @param int $id partnerid of the user |
||
803 | * @param bool $as_object |
||
804 | * @param bool $debug |
||
805 | * @param bool $criteria |
||
806 | * @return mixed reference to the <a href='psi_element://SmartpartnerPartner'>SmartpartnerPartner</a> object, FALSE if failed |
||
807 | * object, FALSE if failed |
||
808 | */ |
||
809 | public function get($id, $as_object = true, $debug = false, $criteria = false) |
||
810 | { |
||
811 | if ((int)$id > 0) { |
||
812 | $sql = 'SELECT * FROM ' . $this->table . ' WHERE id=' . $id; |
||
813 | if (!$result = $this->db->query($sql)) { |
||
814 | return false; |
||
815 | } |
||
816 | |||
817 | $numrows = $this->db->getRowsNum($result); |
||
818 | if ($numrows == 1) { |
||
819 | $partner = new SmartpartnerPartner(); |
||
820 | $partner->assignVars($this->db->fetchArray($result)); |
||
821 | global $smartpartnerPartnerCatLinkHandler; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
822 | if (!$smartpartnerPartnerCatLinkHandler) { |
||
823 | $smartpartnerPartnerCatLinkHandler = smartpartner_gethandler('partner_cat_link'); |
||
824 | } |
||
825 | $partner->setVar('categoryid', $smartpartnerPartnerCatLinkHandler->getParentIds($partner->getVar('id'))); |
||
826 | |||
827 | return $partner; |
||
828 | } |
||
829 | } |
||
830 | $ret = false; |
||
831 | |||
832 | return $ret; |
||
833 | } |
||
834 | |||
835 | /** |
||
836 | * insert a new Partner in the database |
||
837 | * |
||
838 | * @param XoopsObject $partner |
||
839 | * @param bool $force |
||
840 | * @param bool $checkObject |
||
841 | * @param bool $debug |
||
842 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
||
843 | * @internal param XoopsObject $partner reference to the <a href='psi_element://SmartpartnerPartner'>SmartpartnerPartner</a> object object |
||
844 | */ |
||
845 | public function insert(XoopsObject $partner, $force = false, $checkObject = true, $debug = false) |
||
846 | { |
||
847 | if (strtolower(get_class($partner)) != strtolower($this->className)) { |
||
848 | return false; |
||
849 | } |
||
850 | |||
851 | if (!$partner->isDirty()) { |
||
852 | return true; |
||
853 | } |
||
854 | |||
855 | if (!$partner->cleanVars()) { |
||
856 | return false; |
||
857 | } |
||
858 | |||
859 | foreach ($partner->cleanVars as $k => $v) { |
||
860 | ${$k} = $v; |
||
861 | } |
||
862 | |||
863 | if ($partner->isNew()) { |
||
864 | $sql = |
||
865 | sprintf('INSERT INTO %s (id, weight, hits, hits_page, url, image, image_url, title, datesub, summary, description, contact_name, contact_email, contact_phone, adress, `status`, `last_update`, `email_priv`, `phone_priv`, `adress_priv`, `showsummary`) VALUES (null, %u, %u, %u, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %u, %u, %u, %u, %u, %u)', |
||
866 | $this->table, $weight, $hits, $hits_page, $this->db->quoteString($url), $this->db->quoteString($image), $this->db->quoteString($image_url), $this->db->quoteString($title), |
||
867 | time(), $this->db->quoteString($summary), $this->db->quoteString($description), $this->db->quoteString($contact_name), $this->db->quoteString($contact_email), |
||
868 | $this->db->quoteString($contact_phone), $this->db->quoteString($adress), $status, time(), $email_priv, $phone_priv, $adress_priv, $showsummary); |
||
869 | } else { |
||
870 | $sql = |
||
871 | sprintf('UPDATE %s SET weight = %u, hits = %u, hits_page = %u, url = %s, image = %s, image_url = %s, title = %s, datesub = %s, summary = %s, description = %s, contact_name = %s, contact_email = %s, contact_phone = %s, adress = %s, `status` = %u, `last_update` = %u, `email_priv` = %u, `phone_priv` = %u, `adress_priv` = %u, `showsummary` = %u WHERE id = %u', |
||
872 | $this->table, $weight, $hits, $hits_page, $this->db->quoteString($url), $this->db->quoteString($image), $this->db->quoteString($image_url), $this->db->quoteString($title), |
||
873 | $this->db->quoteString($datesub), $this->db->quoteString($summary), $this->db->quoteString($description), $this->db->quoteString($contact_name), |
||
874 | $this->db->quoteString($contact_email), $this->db->quoteString($contact_phone), $this->db->quoteString($adress), $status, time(), $email_priv, $phone_priv, $adress_priv, |
||
875 | $showsummary, $id); |
||
876 | } |
||
877 | |||
878 | //echo "<br>" . $sql . "<br>";exit; |
||
879 | |||
880 | View Code Duplication | if (false != $force) { |
|
881 | $result = $this->db->queryF($sql); |
||
882 | } else { |
||
883 | $result = $this->db->query($sql); |
||
884 | } |
||
885 | |||
886 | if (!$result) { |
||
887 | return false; |
||
888 | } |
||
889 | if ($partner->isNew()) { |
||
890 | $partner->assignVar('id', $this->db->getInsertId()); |
||
891 | } |
||
892 | global $smartpartnerPartnerCatLinkHandler; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
893 | $criteria = new CriteriaCompo(); |
||
894 | $criteria->add(new Criteria('partnerid', $partner->getVar('id'))); |
||
895 | $links = $smartpartnerPartnerCatLinkHandler->getObjects($criteria); |
||
896 | $categoryid = explode('|', $partner->getVar('categoryid')); |
||
897 | $parent_array = array(); |
||
898 | foreach ($links as $link) { |
||
899 | if (!in_array($link->getVar('categoryid'), $categoryid)) { |
||
900 | $smartpartnerPartnerCatLinkHandler->delete($link); |
||
901 | } else { |
||
902 | $parent_array[] = $link->getVar('categoryid'); |
||
903 | } |
||
904 | } |
||
905 | foreach ($categoryid as $cat) { |
||
906 | if (!in_array($cat, $parent_array)) { |
||
907 | $linkObj = $smartpartnerPartnerCatLinkHandler->create(); |
||
908 | $linkObj->setVar('partnerid', $partner->getVar('id')); |
||
909 | $linkObj->setVar('categoryid', $cat); |
||
910 | $smartpartnerPartnerCatLinkHandler->insert($linkObj); |
||
911 | } |
||
912 | } |
||
913 | if (isset($_POST['partial_view']) || isset($_POST['full_view'])) { |
||
914 | $smartPermissionsHandler = new SmartobjectPermissionHandler($this); |
||
915 | $smartPermissionsHandler->storeAllPermissionsForId($partner->id()); |
||
916 | } |
||
917 | |||
918 | return true; |
||
919 | } |
||
920 | |||
921 | /** |
||
922 | * delete a Partner from the database |
||
923 | * |
||
924 | * @param XoopsObject $partner reference to the Partner to delete |
||
925 | * @param bool $force |
||
926 | * @return bool FALSE if failed. |
||
927 | */ |
||
928 | public function delete(XoopsObject $partner, $force = false) |
||
929 | { |
||
930 | global $smartPartnerOfferHandler, $smartpartnerPartnerCatLinkHandler; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
931 | $partnerModule =& smartpartner_getModuleInfo(); |
||
932 | $module_id = $partnerModule->getVar('mid'); |
||
933 | |||
934 | if (strtolower(get_class($partner)) != strtolower($this->className)) { |
||
935 | return false; |
||
936 | } |
||
937 | |||
938 | $sql = sprintf('DELETE FROM %s WHERE id = %u', $this->table, $partner->getVar('id')); |
||
939 | |||
940 | View Code Duplication | if (false != $force) { |
|
941 | $result = $this->db->queryF($sql); |
||
942 | } else { |
||
943 | $result = $this->db->query($sql); |
||
944 | } |
||
945 | if (!$result) { |
||
946 | return false; |
||
947 | } |
||
948 | $criteria = new CriteriaCompo(); |
||
949 | $criteria->add(new Criteria('partnerid', $partner->getVar('id'))); |
||
950 | $offersObj = $smartPartnerOfferHandler->getObjects($criteria); |
||
951 | |||
952 | foreach ($offersObj as $offerObj) { |
||
953 | $smartPartnerOfferHandler->delete($offerObj, 1); |
||
954 | } |
||
955 | $linksObj = $smartpartnerPartnerCatLinkHandler->getObjects($criteria); |
||
956 | foreach ($linksObj as $linkObj) { |
||
957 | $smartpartnerPartnerCatLinkHandler->delete($linkObj, 1); |
||
958 | } |
||
959 | |||
960 | return true; |
||
961 | } |
||
962 | |||
963 | /** |
||
964 | * retrieve Partners from the database |
||
965 | * |
||
966 | * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
||
967 | * @param bool $id_as_key use the partnerid as key for the array? |
||
968 | * @param bool $as_object |
||
969 | * @param bool $sql |
||
970 | * @param bool $debug |
||
971 | * @return array array of <a href='psi_element://SmartpartnerPartner'>SmartpartnerPartner</a> objects |
||
972 | * objects |
||
973 | */ |
||
974 | public function getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false)//&getObjects($criteria = null, $id_as_key = false) |
||
975 | { |
||
976 | $ret = array(); |
||
977 | $limit = $start = 0; |
||
978 | $sql = 'SELECT * FROM ' . $this->table; |
||
979 | |||
980 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
981 | $whereClause = $criteria->renderWhere(); |
||
982 | |||
983 | View Code Duplication | if ($whereClause !== 'WHERE ()') { |
|
984 | $sql .= ' ' . $criteria->renderWhere(); |
||
985 | if ($criteria->getSort() != '') { |
||
986 | $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
||
987 | } |
||
988 | $limit = $criteria->getLimit(); |
||
989 | $start = $criteria->getStart(); |
||
990 | } |
||
991 | } |
||
992 | |||
993 | //echo "<br>" . $sql . "<br>";exit; |
||
994 | $result = $this->db->query($sql, $limit, $start); |
||
995 | if (!$result) { |
||
996 | return $ret; |
||
997 | } |
||
998 | |||
999 | if (count($result) == 0) { |
||
1000 | return $ret; |
||
1001 | } |
||
1002 | global $smartpartnerPartnerCatLinkHandler; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
1003 | if (!isset($smartpartnerPartnerCatLinkHandler)) { |
||
1004 | $smartpartnerPartnerCatLinkHandler = smartpartner_gethandler('partner_cat_link'); |
||
1005 | } |
||
1006 | while ($myrow = $this->db->fetchArray($result)) { |
||
1007 | $partner = new SmartpartnerPartner(); |
||
1008 | $partner->assignVars($myrow); |
||
1009 | |||
1010 | if (!$id_as_key) { |
||
1011 | $ret[] =& $partner; |
||
1012 | } else { |
||
1013 | $ret[$myrow['id']] =& $partner; |
||
1014 | } |
||
1015 | $partner->setVar('categoryid', $smartpartnerPartnerCatLinkHandler->getParentIds($partner->getVar('id'))); |
||
1016 | unset($partner); |
||
1017 | } |
||
1018 | |||
1019 | return $ret; |
||
1020 | } |
||
1021 | |||
1022 | /** |
||
1023 | * count Partners matching a condition |
||
1024 | * |
||
1025 | * @param CriteriaElement $criteria {@link CriteriaElement} to match |
||
1026 | * @return int count of partners |
||
1027 | */ |
||
1028 | public function getCount(CriteriaElement $criteria = null) |
||
1029 | { |
||
1030 | $sql = 'SELECT COUNT(*) FROM ' . $this->table; |
||
1031 | View Code Duplication | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
1032 | $whereClause = $criteria->renderWhere(); |
||
1033 | if ($whereClause !== 'WHERE ()') { |
||
1034 | $sql .= ' ' . $criteria->renderWhere(); |
||
1035 | } |
||
1036 | } |
||
1037 | |||
1038 | //echo "<br>" . $sql . "<br>"; |
||
1039 | $result = $this->db->query($sql); |
||
1040 | if (!$result) { |
||
1041 | return 0; |
||
1042 | } |
||
1043 | list($count) = $this->db->fetchRow($result); |
||
1044 | |||
1045 | return $count; |
||
1046 | } |
||
1047 | |||
1048 | /** |
||
1049 | * @param int $status |
||
1050 | * @return int |
||
1051 | */ |
||
1052 | public function getPartnerCount($status = _SPARTNER_STATUS_ACTIVE) |
||
1053 | { |
||
1054 | if ($status != _SPARTNER_STATUS_ALL) { |
||
1055 | $criteriaStatus = new CriteriaCompo(); |
||
1056 | $criteriaStatus->add(new Criteria('status', $status)); |
||
1057 | } |
||
1058 | |||
1059 | $criteria = new CriteriaCompo(); |
||
1060 | if (isset($criteriaStatus)) { |
||
1061 | $criteria->add($criteriaStatus); |
||
1062 | } |
||
1063 | |||
1064 | return $this->getCount($criteria); |
||
1065 | } |
||
1066 | |||
1067 | /** |
||
1068 | * @param array $queryarray |
||
1069 | * @param string $andor |
||
1070 | * @param int $limit |
||
1071 | * @param int $offset |
||
1072 | * @param int $userid |
||
1073 | * @return array |
||
1074 | */ |
||
1075 | public function &getObjectsForSearch($queryarray = array(), $andor = 'AND', $limit = 0, $offset = 0, $userid = 0) |
||
1076 | { |
||
1077 | global $xoopsConfig; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
1078 | |||
1079 | $ret = array(); |
||
1080 | $sql = 'SELECT title, id |
||
1081 | FROM ' . $this->table . ' |
||
1082 | '; |
||
1083 | if ($queryarray) { |
||
1084 | $criteriaKeywords = new CriteriaCompo(); |
||
1085 | for ($i = 0, $iMax = count($queryarray); $i < $iMax; ++$i) { |
||
1086 | $criteriaKeyword = new CriteriaCompo(); |
||
1087 | $criteriaKeyword->add(new Criteria('title', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1088 | $criteriaKeyword->add(new Criteria('summary', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1089 | $criteriaKeyword->add(new Criteria('description', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1090 | $criteriaKeyword->add(new Criteria('contact_name', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1091 | $criteriaKeyword->add(new Criteria('contact_email', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1092 | $criteriaKeyword->add(new Criteria('contact_phone', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1093 | $criteriaKeyword->add(new Criteria('adress', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1094 | $criteriaKeywords->add($criteriaKeyword, $andor); |
||
1095 | unset($criteriaKeyword); |
||
1096 | } |
||
1097 | } |
||
1098 | |||
1099 | $criteria = new CriteriaCompo(); |
||
1100 | |||
1101 | if (!empty($criteriaKeywords)) { |
||
1102 | $criteria->add($criteriaKeywords, 'AND'); |
||
1103 | } |
||
1104 | |||
1105 | $criteria->add(new Criteria('status', _SPARTNER_STATUS_ACTIVE, '='), 'AND'); |
||
1106 | |||
1107 | if ($userid != 0) { |
||
1108 | $criteria->add(new Criteria('id', $userid), 'AND'); |
||
1109 | } |
||
1110 | |||
1111 | $criteria->setSort('datesub'); |
||
1112 | $criteria->setOrder('DESC'); |
||
1113 | |||
1114 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
1115 | $sql .= ' ' . $criteria->renderWhere(); |
||
1116 | if ($criteria->getSort() != '') { |
||
1117 | $sql .= ' ORDER BY ' . $criteria->getSort() . ' |
||
1118 | ' . $criteria->getOrder(); |
||
1119 | } |
||
1120 | } |
||
1121 | |||
1122 | //echo "<br>$sql<br>"; |
||
1123 | |||
1124 | $result = $this->db->query($sql, $limit, $offset); |
||
1125 | // If no records from db, return empty array |
||
1126 | if (!$result) { |
||
1127 | return $ret; |
||
1128 | } |
||
1129 | |||
1130 | // Add each returned record to the result array |
||
1131 | while ($myrow = $this->db->fetchArray($result)) { |
||
1132 | $item['id'] = $myrow['id']; |
||
1133 | $item['title'] = $myrow['title']; |
||
1134 | $ret[] = $item; |
||
1135 | unset($item); |
||
1136 | } |
||
1137 | |||
1138 | return $ret; |
||
1139 | } |
||
1140 | |||
1141 | /** |
||
1142 | * @param int $limit |
||
1143 | * @param int $start |
||
1144 | * @param int $status |
||
1145 | * @param string $sort |
||
1146 | * @param string $order |
||
1147 | * @param bool $asobject |
||
1148 | * @return array |
||
1149 | */ |
||
1150 | View Code Duplication | public function getPartners($limit = 0, $start = 0, $status = _SPARTNER_STATUS_ACTIVE, $sort = 'title', $order = 'ASC', $asobject = true) |
|
1151 | { |
||
1152 | global $xoopsUser; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
1153 | if ($status != _SPARTNER_STATUS_ALL) { |
||
1154 | $criteriaStatus = new CriteriaCompo(); |
||
1155 | $criteriaStatus->add(new Criteria('status', $status)); |
||
1156 | } |
||
1157 | |||
1158 | $criteria = new CriteriaCompo(); |
||
1159 | if (isset($criteriaStatus)) { |
||
1160 | $criteria->add($criteriaStatus); |
||
1161 | } |
||
1162 | $criteria->setLimit($limit); |
||
1163 | $criteria->setStart($start); |
||
1164 | $criteria->setSort($sort); |
||
1165 | $criteria->setOrder($order); |
||
1166 | $ret = $this->getObjects($criteria); |
||
1167 | |||
1168 | return $ret; |
||
1169 | } |
||
1170 | |||
1171 | /** |
||
1172 | * @param int $categoryid |
||
1173 | * @param int $status |
||
1174 | * @param string $sort |
||
1175 | * @param string $order |
||
1176 | * @param bool $asobject |
||
1177 | * @return array |
||
1178 | */ |
||
1179 | View Code Duplication | public function getPartnersForIndex($categoryid = 0, $status = _SPARTNER_STATUS_ACTIVE, $sort = 'title', $order = 'ASC', $asobject = true) |
|
1180 | { |
||
1181 | global $xoopsUser; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
1182 | if ($status != _SPARTNER_STATUS_ALL) { |
||
1183 | $criteriaStatus = new CriteriaCompo(); |
||
1184 | $criteriaStatus->add(new Criteria('status', $status)); |
||
1185 | } |
||
1186 | |||
1187 | $criteria = new CriteriaCompo(); |
||
1188 | if (isset($criteriaStatus)) { |
||
1189 | $criteria->add($criteriaStatus); |
||
1190 | } |
||
1191 | if ($categoryid != -1) { |
||
1192 | $criteria->add(new Criteria('categoryid', $categoryid)); |
||
1193 | } |
||
1194 | $criteria->setSort($sort); |
||
1195 | $criteria->setOrder($order); |
||
1196 | $ret = $this->getObjects($criteria); |
||
1197 | |||
1198 | return $ret; |
||
1199 | } |
||
1200 | |||
1201 | /** |
||
1202 | * @param null $status |
||
1203 | * @return bool|mixed |
||
1204 | */ |
||
1205 | public function getRandomPartner($status = null) |
||
1206 | { |
||
1207 | $ret = false; |
||
1208 | |||
1209 | // Getting the number of partners |
||
1210 | $totalPartners = $this->getPartnerCount($status); |
||
1211 | |||
1212 | if ($totalPartners > 0) { |
||
1213 | --$totalPartners; |
||
1214 | mt_srand((double)microtime() * 1000000); |
||
1215 | $entrynumber = mt_rand(0, $totalPartners); |
||
1216 | $partner = $this->getPartners(1, $entrynumber, $status); |
||
1217 | if ($partner) { |
||
1218 | $ret =& $partner[0]; |
||
1219 | } |
||
1220 | } |
||
1221 | |||
1222 | return $ret; |
||
1223 | } |
||
1224 | |||
1225 | /** |
||
1226 | * delete Partners matching a set of conditions |
||
1227 | * |
||
1228 | * @param CriteriaElement $criteria {@link CriteriaElement} |
||
1229 | * @return bool FALSE if deletion failed |
||
1230 | */ |
||
1231 | View Code Duplication | public function deleteAll(CriteriaElement $criteria = null) |
|
1232 | { |
||
1233 | $sql = 'DELETE FROM ' . $this->db->prefix('smartpartner_partner'); |
||
1234 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
1235 | $sql .= ' ' . $criteria->renderWhere(); |
||
1236 | } |
||
1237 | if (!$result = $this->db->query($sql)) { |
||
1238 | return false; |
||
1239 | } |
||
1240 | |||
1241 | return true; |
||
1242 | } |
||
1243 | |||
1244 | /** |
||
1245 | * Change a value for a Partner with a certain criteria |
||
1246 | * |
||
1247 | * @param string $fieldname Name of the field |
||
1248 | * @param string $fieldvalue Value to write |
||
1249 | * @param CriteriaElement $criteria {@link CriteriaElement} |
||
1250 | * |
||
1251 | * @param bool $force |
||
1252 | * @return bool |
||
1253 | */ |
||
1254 | View Code Duplication | public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false) |
|
1255 | { |
||
1256 | $set_clause = is_numeric($fieldvalue) ? $fieldname . ' = ' . $fieldvalue : $fieldname . ' = ' . $this->db->quoteString($fieldvalue); |
||
1257 | $sql = 'UPDATE ' . $this->db->prefix('smartpartner_partner') . ' SET ' . $set_clause; |
||
1258 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
1259 | $sql .= ' ' . $criteria->renderWhere(); |
||
1260 | } |
||
1261 | if (!$result = $this->db->queryF($sql)) { |
||
1262 | return false; |
||
1263 | } |
||
1264 | |||
1265 | return true; |
||
1266 | } |
||
1267 | |||
1268 | /** |
||
1269 | * @param int $limit |
||
1270 | * @param int $status |
||
1271 | * @return bool |
||
1272 | */ |
||
1273 | public function getRandomPartners($limit = 0, $status = _SPARTNER_STATUS_ACTIVE) |
||
1274 | { |
||
1275 | $ret = false; |
||
1276 | $sql = 'SELECT id FROM ' . $this->db->prefix('smartpartner_partner') . ' '; |
||
1277 | $sql .= 'WHERE status=' . $status; |
||
1278 | |||
1279 | //echo "<br>" . $sql . "<br>"; |
||
1280 | |||
1281 | $result = $this->db->query($sql); |
||
1282 | |||
1283 | if (!$result) { |
||
1284 | return $ret; |
||
1285 | } |
||
1286 | |||
1287 | if (count($result) == 0) { |
||
1288 | return $ret; |
||
1289 | } |
||
1290 | |||
1291 | $partners_ids = array(); |
||
1292 | while ($myrow = $this->db->fetchArray($result)) { |
||
1293 | $partners_ids[] = $myrow['id']; |
||
1294 | } |
||
1295 | |||
1296 | if (count($partners_ids) > 1) { |
||
1297 | $key_arr = array_values($partners_ids); |
||
1298 | $key_rand = array_rand($key_arr, count($key_arr)); |
||
1299 | $ids = implode(', ', $key_rand); |
||
1300 | echo $ids; |
||
1301 | |||
1302 | return $ret; |
||
1303 | } else { |
||
1304 | return $ret; |
||
1305 | } |
||
1306 | } |
||
1307 | |||
1308 | /* function getFaqsFromSearch($queryarray = array(), $andor = 'AND', $limit = 0, $offset = 0, $userid = 0) |
||
1309 | { |
||
1310 | |||
1311 | Global $xoopsUser; |
||
1312 | |||
1313 | $ret = array(); |
||
1314 | |||
1315 | $hModule = xoops_getHandler('module'); |
||
1316 | $hModConfig = xoops_getHandler('config'); |
||
1317 | $smartModule =& $hModule->getByDirname('smartfaq'); |
||
1318 | $module_id = $smartModule->getVar('mid'); |
||
1319 | |||
1320 | $gpermHandler = xoops_getHandler('groupperm'); |
||
1321 | $groups = ($xoopsUser) ? ($xoopsUser->getGroups()): XOOPS_GROUP_ANONYMOUS; |
||
1322 | $userIsAdmin = sf_userIsAdmin(); |
||
1323 | |||
1324 | if ($userid != 0) { |
||
1325 | $criteriaUser = new CriteriaCompo(); |
||
1326 | $criteriaUser->add(new Criteria('faq.uid', $userid), 'OR'); |
||
1327 | $criteriaUser->add(new Criteria('answer.uid', $userid), 'OR'); |
||
1328 | } |
||
1329 | |||
1330 | If ($queryarray) { |
||
1331 | $criteriaKeywords = new CriteriaCompo(); |
||
1332 | for ($i = 0, $iMax = count($queryarray); $i < $iMax; ++$i) { |
||
1333 | $criteriaKeyword = new CriteriaCompo(); |
||
1334 | $criteriaKeyword->add(new Criteria('faq.question', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1335 | $criteriaKeyword->add(new Criteria('answer.answer', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
1336 | $criteriaKeywords->add($criteriaKeyword, $andor); |
||
1337 | } |
||
1338 | } |
||
1339 | |||
1340 | // Categories for which user has access |
||
1341 | if (!$userIsAdmin) { |
||
1342 | $categoriesGranted = $gpermHandler->getItemIds('category_read', $groups, $module_id); |
||
1343 | $grantedCategories = new Criteria('faq.categoryid', "(".implode(',', $categoriesGranted).")", 'IN'); |
||
1344 | } |
||
1345 | // FAQs for which user has access |
||
1346 | if (!$userIsAdmin) { |
||
1347 | $faqsGranted = $gpermHandler->getItemIds('item_read', $groups, $module_id); |
||
1348 | $grantedFaq = new Criteria('faq.faqid', "(".implode(',', $faqsGranted).")", 'IN'); |
||
1349 | } |
||
1350 | |||
1351 | $criteriaPermissions = new CriteriaCompo(); |
||
1352 | if (!$userIsAdmin) { |
||
1353 | $criteriaPermissions->add($grantedCategories, 'AND'); |
||
1354 | $criteriaPermissions->add($grantedFaq, 'AND'); |
||
1355 | } |
||
1356 | |||
1357 | $criteriaAnswersStatus = new CriteriaCompo(); |
||
1358 | $criteriaAnswersStatus->add(new Criteria('answer.status', _SF_AN_STATUS_APPROVED)); |
||
1359 | |||
1360 | $criteriaFasStatus = new CriteriaCompo(); |
||
1361 | $criteriaFasStatus->add(new Criteria('faq.status', _SF_STATUS_OPENED), 'OR'); |
||
1362 | $criteriaFasStatus->add(new Criteria('faq.status', _SF_STATUS_PUBLISHED), 'OR'); |
||
1363 | |||
1364 | $criteria = new CriteriaCompo(); |
||
1365 | If (!empty($criteriaUser)) { |
||
1366 | $criteria->add($criteriaUser, 'AND'); |
||
1367 | } |
||
1368 | |||
1369 | If (!empty($criteriaKeywords)) { |
||
1370 | $criteria->add($criteriaKeywords, 'AND'); |
||
1371 | } |
||
1372 | |||
1373 | If (!empty($criteriaPermissions) && (!$userIsAdmin)) { |
||
1374 | $criteria->add($criteriaPermissions); |
||
1375 | } |
||
1376 | |||
1377 | If (!empty($criteriaAnswersStatus)) { |
||
1378 | $criteria->add($criteriaAnswersStatus, 'AND'); |
||
1379 | } |
||
1380 | |||
1381 | If (!empty($criteriaFasStatus)) { |
||
1382 | $criteria->add($criteriaFasStatus, 'AND'); |
||
1383 | } |
||
1384 | |||
1385 | $criteria->setLimit($limit); |
||
1386 | $criteria->setStart($offset); |
||
1387 | $criteria->setSort('faq.datesub'); |
||
1388 | $criteria->setOrder('DESC'); |
||
1389 | |||
1390 | $sql = 'SELECT faq.faqid FROM '.$this->db->prefix('smartfaq_faq') . ' as faq INNER JOIN '.$this->db->prefix('smartfaq_answers') . ' as answer ON faq.faqid = answer.faqid'; |
||
1391 | |||
1392 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
1393 | $whereClause = $criteria->renderWhere(); |
||
1394 | |||
1395 | If ($whereClause != 'WHERE ()') { |
||
1396 | $sql .= ' '.$criteria->renderWhere(); |
||
1397 | if ($criteria->getSort() != '') { |
||
1398 | $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
||
1399 | } |
||
1400 | $limit = $criteria->getLimit(); |
||
1401 | $start = $criteria->getStart(); |
||
1402 | } |
||
1403 | } |
||
1404 | |||
1405 | //echo "<br>" . $sql . "<br>"; |
||
1406 | |||
1407 | $result = $this->db->query($sql, $limit, $start); |
||
1408 | if (!$result) { |
||
1409 | echo "- query did not work -"; |
||
1410 | |||
1411 | return $ret; |
||
1412 | } |
||
1413 | |||
1414 | If (count($result) == 0) { |
||
1415 | return $ret; |
||
1416 | } |
||
1417 | |||
1418 | while ($myrow = $this->db->fetchArray($result)) { |
||
1419 | $faq = new sfFaq($myrow['faqid']); |
||
1420 | $ret[] =& $faq; |
||
1421 | unset($faq); |
||
1422 | } |
||
1423 | |||
1424 | return $ret; |
||
1425 | }*/ |
||
1426 | } |
||
1427 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.