1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * Publisher class
14: *
15: * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/
16: * @license GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17: * @package Class
18: * @subpackage Utils
19: * @since 1.0
20: * @author trabis <lusopoemas@gmail.com>
21: * @version $Id$
22: */
23:
24: class PublisherCommentsPlugin extends Xoops\Module\Plugin\PluginAbstract implements CommentsPluginInterface
25: {
26: /**
27: * @return string
28: */
29: public function itemName()
30: {
31: return 'itemid';
32: }
33:
34: /**
35: * @return string
36: */
37: public function pageName()
38: {
39: return 'item.php';
40: }
41:
42: /**
43: * @return array
44: */
45: public function extraParams()
46: {
47: return array();
48: }
49:
50: /**
51: * This method will be executed upon successful post of an approved comment.
52: * This includes comment posts by administrators, and change of comment status from 'pending' to 'active' state.
53: * An CommentsComment object that has been approved will be passed as the first and only parameter.
54: * This should be useful for example notifying the item submitter of a comment post.
55: *
56: * @param CommentsComment $comment
57: *
58: * @return void
59: */
60: public function approve(CommentsComment $comment)
61: {
62: //Where are you looking at?
63: }
64:
65: /**
66: * This method will be executed whenever the total number of 'active' comments for an item is changed.
67: *
68: * @param int $item_id The unique ID of an item
69: * @param int $total_num The total number of active comments
70: *
71: * @return void
72: */
73: public function update($item_id, $total_num)
74: {
75: $db = Xoops::getInstance()->db();
76: $sql = 'UPDATE ' . $db->prefix('publisher_items') . ' SET comments = ' . (int)($total_num) . ' WHERE itemid = ' . (int)($item_id);
77: $db->query($sql);
78: }
79:
80: /**
81: * This method will be executed whenever a new comment form is displayed.
82: * You can set a default title for the comment and a header to be displayed on top of the form
83: * ex: return array(
84: * 'title' => 'My Article Title',
85: * 'text' => 'Content of the article');
86: * 'timestamp' => time(); //Date of the article in unix format
87: * 'uid' => Id of the article author
88: *
89: * @param int $item_id The unique ID of an item
90: *
91: * @return array
92: */
93: public function itemInfo($item_id)
94: {
95: $ret = array();
96: include_once dirname(dirname(__DIR__)) . '/include/common.php';
97:
98: /* @var $itemObj PublisherItem */
99: $itemObj = Publisher::getInstance()->getItemHandler()->get((int)($item_id));
100: $ret['text'] = '';
101: $summary = $itemObj->summary();
102: if ($summary != '') {
103: $ret['text'] .= $summary . '<br /><br />';
104: }
105: $ret['text'] .= $itemObj->body();
106: $ret['title'] = $itemObj->title();
107: $ret['uid'] = $itemObj->getVar('uid');
108: $ret['timestamp'] = $itemObj->getVar('datesub', 'n');
109: return $ret;
110: }
111: }
112: