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: * page module
14: *
15: * @copyright XOOPS Project (http://xoops.org)
16: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17: * @since 2.6.0
18: * @author Mage Grégory (AKA Mage)
19: * @version $Id$
20: */
21:
22: class PageCommentsPlugin extends Xoops\Module\Plugin\PluginAbstract implements CommentsPluginInterface
23: {
24: /**
25: * @return string
26: */
27: public function itemName()
28: {
29: return 'id';
30: }
31:
32: /**
33: * @return string
34: */
35: public function pageName()
36: {
37: return 'viewpage.php';
38: }
39:
40: /**
41: * @return array
42: */
43: public function extraParams()
44: {
45: return array();
46: }
47:
48: /**
49: * This method will be executed upon successful post of an approved comment.
50: * This includes comment posts by administrators, and change of comment status from 'pending' to 'active' state.
51: * An CommentsComment object that has been approved will be passed as the first and only parameter.
52: * This should be useful for example notifying the item submitter of a comment post.
53: *
54: * @param CommentsComment $comment
55: *
56: * @return void
57: */
58: public function approve(CommentsComment $comment)
59: {
60: //Where are you looking at?
61: }
62:
63: /**
64: * This method will be executed whenever the total number of 'active' comments for an item is changed.
65: *
66: * @param int $item_id The unique ID of an item
67: * @param int $total_num The total number of active comments
68: *
69: * @return void
70: */
71: public function update($item_id, $total_num)
72: {
73: $db = Xoops::getInstance()->db();
74: $sql = 'UPDATE ' . $db->prefix('page_content') . ' SET content_comments = ' . (int)($total_num) . ' WHERE content_id = ' . (int)($item_id);
75: $db->query($sql);
76: }
77:
78: /**
79: * This method will be executed whenever a new comment form is displayed.
80: * You can set a default title for the comment and a header to be displayed on top of the form
81: * ex: return array(
82: * 'title' => 'My Article Title',
83: * 'text' => 'Content of the article');
84: * 'timestamp' => time(); //Date of the article in unix format
85: * 'uid' => Id of the article author
86: *
87: * @param int $item_id The unique ID of an item
88: *
89: * @return array
90: */
91: public function itemInfo($item_id)
92: {
93: $ret = array();
94: // Get handler
95: $content_Handler = \Xoops::getModuleHelper('page')->getContentHandler();
96: $view_content = $content_Handler->get($item_id);
97: if (count($view_content) == 0 || $view_content->getVar('content_status') == 0) {
98: return $ret;
99: } else {
100: $ret['title'] = $view_content->getVar('content_title');
101: $ret['text'] = $view_content->getVar('content_shorttext') . $view_content->getVar('content_text');
102: $ret['uid'] = $view_content->getVar('content_author');
103: $ret['timestamp'] = $view_content->getVar('content_create');
104: }
105: return $ret;
106: }
107: }
108: