1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: |
|
18: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
19: |
|
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: |
|
28: | class XoopsComment extends XoopsObject
|
29: | {
|
30: |
|
31: | public $com_id;
|
32: | public $com_pid;
|
33: | public $com_modid;
|
34: | public $com_icon;
|
35: | public $com_title;
|
36: | public $com_text;
|
37: | public $com_created;
|
38: | public $com_modified;
|
39: | public $com_uid;
|
40: |
|
41: | public $com_user;
|
42: | public $com_email;
|
43: | public $com_url;
|
44: |
|
45: | public $com_ip;
|
46: | public $com_sig;
|
47: | public $com_itemid;
|
48: | public $com_rootid;
|
49: | public $com_status;
|
50: | public $com_exparams;
|
51: | public $dohtml;
|
52: | public $dosmiley;
|
53: | public $doxcode;
|
54: | public $doimage;
|
55: | public $dobr;
|
56: |
|
57: | |
58: | |
59: |
|
60: | public function __construct()
|
61: | {
|
62: | parent::__construct();
|
63: | $this->initVar('com_id', XOBJ_DTYPE_INT, null, false);
|
64: | $this->initVar('com_pid', XOBJ_DTYPE_INT, 0, false);
|
65: | $this->initVar('com_modid', XOBJ_DTYPE_INT, null, false);
|
66: | $this->initVar('com_icon', XOBJ_DTYPE_OTHER, null, false);
|
67: | $this->initVar('com_title', XOBJ_DTYPE_TXTBOX, null, true, 255, true);
|
68: | $this->initVar('com_text', XOBJ_DTYPE_TXTAREA, null, true, null, true);
|
69: | $this->initVar('com_created', XOBJ_DTYPE_INT, 0, false);
|
70: | $this->initVar('com_modified', XOBJ_DTYPE_INT, 0, false);
|
71: | $this->initVar('com_uid', XOBJ_DTYPE_INT, 0, true);
|
72: |
|
73: | $this->initVar('com_user', XOBJ_DTYPE_TXTBOX, null, false, 60);
|
74: | $this->initVar('com_email', XOBJ_DTYPE_TXTBOX, null, false, 60);
|
75: | $this->initVar('com_url', XOBJ_DTYPE_TXTBOX, null, false, 60);
|
76: |
|
77: | $this->initVar('com_ip', XOBJ_DTYPE_OTHER, null, false);
|
78: | $this->initVar('com_sig', XOBJ_DTYPE_INT, 0, false);
|
79: | $this->initVar('com_itemid', XOBJ_DTYPE_INT, 0, false);
|
80: | $this->initVar('com_rootid', XOBJ_DTYPE_INT, 0, false);
|
81: | $this->initVar('com_status', XOBJ_DTYPE_INT, 0, false);
|
82: | $this->initVar('com_exparams', XOBJ_DTYPE_OTHER, null, false, 255);
|
83: | $this->initVar('dohtml', XOBJ_DTYPE_INT, 0, false);
|
84: | $this->initVar('dosmiley', XOBJ_DTYPE_INT, 0, false);
|
85: | $this->initVar('doxcode', XOBJ_DTYPE_INT, 0, false);
|
86: | $this->initVar('doimage', XOBJ_DTYPE_INT, 0, false);
|
87: | $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false);
|
88: | }
|
89: |
|
90: | |
91: | |
92: | |
93: | |
94: |
|
95: | public function id($format = 'N')
|
96: | {
|
97: | return $this->getVar('com_id', $format);
|
98: | }
|
99: |
|
100: | |
101: | |
102: | |
103: | |
104: |
|
105: | public function com_id($format = '')
|
106: | {
|
107: | return $this->getVar('com_id', $format);
|
108: | }
|
109: |
|
110: | |
111: | |
112: | |
113: | |
114: |
|
115: | public function com_pid($format = '')
|
116: | {
|
117: | return $this->getVar('com_pid', $format);
|
118: | }
|
119: |
|
120: | |
121: | |
122: | |
123: | |
124: |
|
125: | public function com_modid($format = '')
|
126: | {
|
127: | return $this->getVar('com_modid', $format);
|
128: | }
|
129: |
|
130: | |
131: | |
132: | |
133: | |
134: |
|
135: | public function com_icon($format = '')
|
136: | {
|
137: | return $this->getVar('com_icon', $format);
|
138: | }
|
139: |
|
140: | |
141: | |
142: | |
143: | |
144: |
|
145: | public function com_title($format = '')
|
146: | {
|
147: | return $this->getVar('com_title', $format);
|
148: | }
|
149: |
|
150: | |
151: | |
152: | |
153: | |
154: |
|
155: | public function com_text($format = '')
|
156: | {
|
157: | return $this->getVar('com_text', $format);
|
158: | }
|
159: |
|
160: | |
161: | |
162: | |
163: | |
164: |
|
165: | public function com_created($format = '')
|
166: | {
|
167: | return $this->getVar('com_created', $format);
|
168: | }
|
169: |
|
170: | |
171: | |
172: | |
173: | |
174: |
|
175: | public function com_modified($format = '')
|
176: | {
|
177: | return $this->getVar('com_modified', $format);
|
178: | }
|
179: |
|
180: | |
181: | |
182: | |
183: | |
184: |
|
185: | public function com_uid($format = '')
|
186: | {
|
187: | return $this->getVar('com_uid', $format);
|
188: | }
|
189: |
|
190: |
|
191: | |
192: | |
193: | |
194: | |
195: |
|
196: | public function com_user($format = '')
|
197: | {
|
198: | return $this->getVar('com_user', $format);
|
199: | }
|
200: |
|
201: | |
202: | |
203: | |
204: | |
205: |
|
206: | public function com_email($format = '')
|
207: | {
|
208: | return $this->getVar('com_email', $format);
|
209: | }
|
210: |
|
211: | |
212: | |
213: | |
214: | |
215: |
|
216: | public function com_url($format = '')
|
217: | {
|
218: | return $this->getVar('com_url', $format);
|
219: | }
|
220: |
|
221: |
|
222: | |
223: | |
224: | |
225: | |
226: |
|
227: | public function com_ip($format = '')
|
228: | {
|
229: | return $this->getVar('com_ip', $format);
|
230: | }
|
231: |
|
232: | |
233: | |
234: | |
235: | |
236: |
|
237: | public function com_sig($format = '')
|
238: | {
|
239: | return $this->getVar('com_sig', $format);
|
240: | }
|
241: |
|
242: | |
243: | |
244: | |
245: | |
246: |
|
247: | public function com_itemid($format = '')
|
248: | {
|
249: | return $this->getVar('com_itemid', $format);
|
250: | }
|
251: |
|
252: | |
253: | |
254: | |
255: | |
256: |
|
257: | public function com_rootid($format = '')
|
258: | {
|
259: | return $this->getVar('com_rootid', $format);
|
260: | }
|
261: |
|
262: | |
263: | |
264: | |
265: | |
266: |
|
267: | public function com_status($format = '')
|
268: | {
|
269: | return $this->getVar('com_status', $format);
|
270: | }
|
271: |
|
272: | |
273: | |
274: | |
275: | |
276: |
|
277: | public function com_exparams($format = '')
|
278: | {
|
279: | return $this->getVar('com_exparams', $format);
|
280: | }
|
281: |
|
282: | |
283: | |
284: | |
285: | |
286: |
|
287: | public function dohtml($format = '')
|
288: | {
|
289: | return $this->getVar('dohtml', $format);
|
290: | }
|
291: |
|
292: | |
293: | |
294: | |
295: | |
296: |
|
297: | public function dosmiley($format = '')
|
298: | {
|
299: | return $this->getVar('dosmiley', $format);
|
300: | }
|
301: |
|
302: | |
303: | |
304: | |
305: | |
306: |
|
307: | public function doxcode($format = '')
|
308: | {
|
309: | return $this->getVar('doxcode', $format);
|
310: | }
|
311: |
|
312: | |
313: | |
314: | |
315: | |
316: |
|
317: | public function doimage($format = '')
|
318: | {
|
319: | return $this->getVar('doimage', $format);
|
320: | }
|
321: |
|
322: | |
323: | |
324: | |
325: | |
326: |
|
327: | public function dobr($format = '')
|
328: | {
|
329: | return $this->getVar('dobr', $format);
|
330: | }
|
331: |
|
332: | |
333: | |
334: | |
335: | |
336: |
|
337: | public function isRoot()
|
338: | {
|
339: | return ($this->getVar('com_id') == $this->getVar('com_rootid'));
|
340: | }
|
341: | }
|
342: |
|
343: | |
344: | |
345: | |
346: | |
347: | |
348: | |
349: | |
350: | |
351: | |
352: | |
353: | |
354: | |
355: | |
356: | |
357: |
|
358: | class XoopsCommentHandler extends XoopsObjectHandler
|
359: | {
|
360: | |
361: | |
362: | |
363: | |
364: | |
365: | |
366: |
|
367: | public function create($isNew = true)
|
368: | {
|
369: | $comment = new XoopsComment();
|
370: | if ($isNew) {
|
371: | $comment->setNew();
|
372: | }
|
373: |
|
374: | return $comment;
|
375: | }
|
376: |
|
377: | |
378: | |
379: | |
380: | |
381: | |
382: | |
383: |
|
384: | public function get($id)
|
385: | {
|
386: | $comment = false;
|
387: | $id = (int)$id;
|
388: | if ($id > 0) {
|
389: | $sql = 'SELECT * FROM ' . $this->db->prefix('xoopscomments') . ' WHERE com_id=' . $id;
|
390: | $result = $this->db->query($sql);
|
391: | if (!$this->db->isResultSet($result)) {
|
392: | return $comment;
|
393: | }
|
394: | $numrows = $this->db->getRowsNum($result);
|
395: | if ($numrows == 1) {
|
396: | $comment = new XoopsComment();
|
397: | $comment->assignVars($this->db->fetchArray($result));
|
398: | }
|
399: | }
|
400: |
|
401: | return $comment;
|
402: | }
|
403: |
|
404: | |
405: | |
406: | |
407: | |
408: | |
409: | |
410: |
|
411: | public function insert(XoopsObject $comment)
|
412: | {
|
413: | $className = 'XoopsComment';
|
414: | if (!($comment instanceof $className)) {
|
415: | return false;
|
416: | }
|
417: | if (!$comment->isDirty()) {
|
418: | return true;
|
419: | }
|
420: | if (!$comment->cleanVars()) {
|
421: | return false;
|
422: | }
|
423: | foreach ($comment->cleanVars as $k => $v) {
|
424: | ${$k} = $v;
|
425: | }
|
426: |
|
427: | if ($comment->isNew()) {
|
428: | $com_id = $this->db->genId('xoopscomments_com_id_seq');
|
429: | $sql = sprintf('INSERT INTO %s (com_id, com_pid, com_modid, com_icon, com_title, com_text, com_created, com_modified, com_uid, com_user, com_email, com_url, com_ip, com_sig, com_itemid, com_rootid, com_status, com_exparams, dohtml, dosmiley, doxcode, doimage, dobr) VALUES (%u, %u, %u, %s, %s, %s, %u, %u, %u, %s, %s, %s, %s, %u, %u, %u, %u, %s, %u, %u, %u, %u, %u)', $this->db->prefix('xoopscomments'), $com_id, $com_pid, $com_modid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_user), $this->db->quoteString($com_email), $this->db->quoteString($com_url), $this->db->quoteString($com_ip), $com_sig, $com_itemid, $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr);
|
430: | } else {
|
431: | $sql = sprintf('UPDATE %s SET com_pid = %u, com_icon = %s, com_title = %s, com_text = %s, com_created = %u, com_modified = %u, com_uid = %u, com_user = %s, com_email = %s, com_url = %s, com_ip = %s, com_sig = %u, com_itemid = %u, com_rootid = %u, com_status = %u, com_exparams = %s, dohtml = %u, dosmiley = %u, doxcode = %u, doimage = %u, dobr = %u WHERE com_id = %u', $this->db->prefix('xoopscomments'), $com_pid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_user), $this->db->quoteString($com_email), $this->db->quoteString($com_url), $this->db->quoteString($com_ip), $com_sig, $com_itemid, $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr, $com_id);
|
432: | }
|
433: |
|
434: | if (!$result = $this->db->query($sql)) {
|
435: | return false;
|
436: | }
|
437: | if (empty($com_id)) {
|
438: | $com_id = $this->db->getInsertId();
|
439: | }
|
440: | $comment->assignVar('com_id', $com_id);
|
441: |
|
442: | return true;
|
443: | }
|
444: |
|
445: | |
446: | |
447: | |
448: | |
449: | |
450: | |
451: |
|
452: | public function delete(XoopsObject $comment)
|
453: | {
|
454: | $className = 'XoopsComment';
|
455: | if (!($comment instanceof $className)) {
|
456: | return false;
|
457: | }
|
458: | $sql = sprintf('DELETE FROM %s WHERE com_id = %u', $this->db->prefix('xoopscomments'), $comment->getVar('com_id'));
|
459: | if (!$result = $this->db->query($sql)) {
|
460: | return false;
|
461: | }
|
462: |
|
463: | return true;
|
464: | }
|
465: |
|
466: | |
467: | |
468: | |
469: | |
470: | |
471: | |
472: | |
473: |
|
474: | public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
|
475: | {
|
476: | $ret = array();
|
477: | $limit = $start = 0;
|
478: | $sql = 'SELECT * FROM ' . $this->db->prefix('xoopscomments');
|
479: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
480: | $sql .= ' ' . $criteria->renderWhere();
|
481: | $sort = ($criteria->getSort() != '') ? $criteria->getSort() : 'com_id';
|
482: | $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
|
483: | $limit = $criteria->getLimit();
|
484: | $start = $criteria->getStart();
|
485: | }
|
486: | $result = $this->db->query($sql, $limit, $start);
|
487: | if (!$this->db->isResultSet($result)) {
|
488: | return $ret;
|
489: | }
|
490: |
|
491: | while (false !== ($myrow = $this->db->fetchArray($result))) {
|
492: | $comment = new XoopsComment();
|
493: | $comment->assignVars($myrow);
|
494: | if (!$id_as_key) {
|
495: | $ret[] =& $comment;
|
496: | } else {
|
497: | $ret[$myrow['com_id']] = &$comment;
|
498: | }
|
499: | unset($comment);
|
500: | }
|
501: |
|
502: | return $ret;
|
503: | }
|
504: |
|
505: | |
506: | |
507: | |
508: | |
509: | |
510: | |
511: |
|
512: | public function getCount(CriteriaElement $criteria = null)
|
513: | {
|
514: | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('xoopscomments');
|
515: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
516: | $sql .= ' ' . $criteria->renderWhere();
|
517: | }
|
518: | $result = $this->db->query($sql);
|
519: | if (!$this->db->isResultSet($result)) {
|
520: | return 0;
|
521: | }
|
522: | list($count) = $this->db->fetchRow($result);
|
523: |
|
524: | return (int)$count;
|
525: | }
|
526: |
|
527: | |
528: | |
529: | |
530: | |
531: | |
532: | |
533: |
|
534: | public function deleteAll(CriteriaElement $criteria = null)
|
535: | {
|
536: | $sql = 'DELETE FROM ' . $this->db->prefix('xoopscomments');
|
537: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
538: | $sql .= ' ' . $criteria->renderWhere();
|
539: | }
|
540: | if (!$result = $this->db->query($sql)) {
|
541: | return false;
|
542: | }
|
543: |
|
544: | return true;
|
545: | }
|
546: |
|
547: | |
548: | |
549: | |
550: | |
551: | |
552: | |
553: |
|
554: | public function getList(CriteriaElement $criteria = null)
|
555: | {
|
556: | $comments = $this->getObjects($criteria, true);
|
557: | $ret = array();
|
558: | foreach (array_keys($comments) as $i) {
|
559: | $ret[$i] = $comments[$i]->getVar('com_title');
|
560: | }
|
561: |
|
562: | return $ret;
|
563: | }
|
564: |
|
565: | |
566: | |
567: | |
568: | |
569: | |
570: | |
571: | |
572: | |
573: | |
574: | |
575: | |
576: |
|
577: | public function getByItemId($module_id, $item_id, $order = null, $status = null, $limit = null, $start = 0)
|
578: | {
|
579: | $criteria = new CriteriaCompo(new Criteria('com_modid', (int)$module_id));
|
580: | $criteria->add(new Criteria('com_itemid', (int)$item_id));
|
581: | if (isset($status)) {
|
582: | $criteria->add(new Criteria('com_status', (int)$status));
|
583: | }
|
584: | if (isset($order)) {
|
585: | $criteria->setOrder($order);
|
586: | }
|
587: | if (isset($limit)) {
|
588: | $criteria->setLimit($limit);
|
589: | $criteria->setStart($start);
|
590: | }
|
591: |
|
592: | return $this->getObjects($criteria);
|
593: | }
|
594: |
|
595: | |
596: | |
597: | |
598: | |
599: | |
600: | |
601: | |
602: | |
603: |
|
604: | public function getCountByItemId($module_id, $item_id, $status = null)
|
605: | {
|
606: | $criteria = new CriteriaCompo(new Criteria('com_modid', (int)$module_id));
|
607: | $criteria->add(new Criteria('com_itemid', (int)$item_id));
|
608: | if (isset($status)) {
|
609: | $criteria->add(new Criteria('com_status', (int)$status));
|
610: | }
|
611: |
|
612: | return $this->getCount($criteria);
|
613: | }
|
614: |
|
615: | |
616: | |
617: | |
618: | |
619: | |
620: | |
621: | |
622: | |
623: | |
624: |
|
625: | public function getTopComments($module_id, $item_id, $order, $status = null)
|
626: | {
|
627: | $criteria = new CriteriaCompo(new Criteria('com_modid', (int)$module_id));
|
628: | $criteria->add(new Criteria('com_itemid', (int)$item_id));
|
629: | $criteria->add(new Criteria('com_pid', 0));
|
630: | if (isset($status)) {
|
631: | $criteria->add(new Criteria('com_status', (int)$status));
|
632: | }
|
633: | $criteria->setOrder($order);
|
634: |
|
635: | return $this->getObjects($criteria);
|
636: | }
|
637: |
|
638: | |
639: | |
640: | |
641: | |
642: | |
643: | |
644: | |
645: | |
646: |
|
647: | public function getThread($comment_rootid, $comment_id, $status = null)
|
648: | {
|
649: | $criteria = new CriteriaCompo(new Criteria('com_rootid', (int)$comment_rootid));
|
650: | $criteria->add(new Criteria('com_id', (int)$comment_id, '>='));
|
651: | if (isset($status)) {
|
652: | $criteria->add(new Criteria('com_status', (int)$status));
|
653: | }
|
654: |
|
655: | return $this->getObjects($criteria);
|
656: | }
|
657: |
|
658: | |
659: | |
660: | |
661: | |
662: | |
663: | |
664: | |
665: | |
666: |
|
667: | public function updateByField(XoopsComment $comment, $field_name, $field_value)
|
668: | {
|
669: | $comment->unsetNew();
|
670: | $comment->setVar($field_name, $field_value);
|
671: |
|
672: | return $this->insert($comment);
|
673: | }
|
674: |
|
675: | |
676: | |
677: | |
678: | |
679: | |
680: |
|
681: | public function deleteByModule($module_id)
|
682: | {
|
683: | return $this->deleteAll(new Criteria('com_modid', (int)$module_id));
|
684: | }
|
685: | }
|
686: | |