1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_MODULE_PATH . "/legacy/class/AbstractListAction.class.php";
14: require_once XOOPS_MODULE_PATH . "/legacy/admin/forms/CommentFilterForm.class.php";
15: require_once XOOPS_MODULE_PATH . "/legacy/admin/forms/CommentListForm.class.php";
16: require_once XOOPS_MODULE_PATH . "/legacy/admin/actions/CommentEditAction.class.php";
17:
18: class Legacy_CommentListAction extends Legacy_AbstractListAction
19: {
20: var $mCommentObjects = array();
21: var $mActionForm = null;
22: var $mpageArr = array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0);
23:
24: function prepare(&$controller, &$xoopsUser)
25: {
26: $this->mActionForm =new Legacy_CommentListForm();
27: $this->mActionForm->prepare();
28: }
29:
30: function &_getHandler()
31: {
32: $handler =& xoops_getmodulehandler('comment');
33: return $handler;
34: }
35:
36: function &_getPageNavi()
37: {
38: $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
39: if (isset($_REQUEST[$navi->mPrefix.'perpage']) && intval($_REQUEST[$navi->mPrefix.'perpage']) == 0) {
40: $navi->setPerpage(0);
41: }
42: return $navi;
43: }
44:
45: function &_getFilterForm()
46: {
47: $filter =new Legacy_CommentFilterForm($this->_getPageNavi(), $this->_getHandler());
48: return $filter;
49: }
50:
51: function _getBaseUrl()
52: {
53: return "./index.php?action=CommentList";
54: }
55:
56: function executeViewIndex(&$controller, &$xoopsUser, &$render)
57: {
58:
59:
60:
61: foreach (array_keys($this->mObjects) as $key) {
62: $this->mObjects[$key]->loadModule();
63: $this->mObjects[$key]->loadUser();
64: $this->mObjects[$key]->loadStatus();
65: }
66:
67: $moduleArr = array();
68: $handler =& xoops_getmodulehandler('comment');
69: $modIds = $handler->getModuleIds();
70:
71: $moduleHandler =& xoops_gethandler('module');
72: foreach ($modIds as $mid) {
73: $module =& $moduleHandler->get($mid);
74: if (is_object($module)) {
75: $moduleArr[] =& $module;
76: }
77: unset ($module);
78: }
79:
80: $statusArr = array();
81: $statusHandler =& xoops_getmodulehandler('commentstatus');
82: $statusArr =& $statusHandler->getObjects();
83:
84: $render->setTemplateName("comment_list.html");
85: $render->setAttribute("objects", $this->mObjects);
86: $render->setAttribute("pageNavi", $this->mFilter->mNavi);
87: $render->setAttribute("moduleArr", $moduleArr);
88: $render->setAttribute("statusArr", $statusArr);
89: $render->setAttribute('filterForm', $this->mFilter);
90: $render->setAttribute('pageArr', $this->mpageArr);
91:
92: $comment_handler =& $this->_getHandler();
93: $comment_total = $comment_handler->getCount();
94: $pending_comment_total = $comment_handler->getCount(new Criteria('com_status', XOOPS_COMMENT_PENDING));
95: $active_comment_total = $comment_handler->getCount(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
96: $hidden_comment_total = $comment_handler->getCount(new Criteria('com_status', XOOPS_COMMENT_HIDDEN));
97: $render->setAttribute('CommentTotal', $comment_total);
98: $render->setAttribute('pendingCommentTotal', $pending_comment_total);
99: $render->setAttribute('activeCommentTotal', $active_comment_total);
100: $render->setAttribute('hiddenCommentTotal', $hidden_comment_total);
101: }
102:
103: function execute(&$controller, &$xoopsUser)
104: {
105: if (xoops_getrequest('_form_control_cancel') != null) {
106: return LEGACY_FRAME_VIEW_CANCEL;
107: }
108:
109: $this->mActionForm->fetch();
110: $this->mActionForm->validate();
111:
112: if ($this->mActionForm->hasError()) {
113: return $this->_processConfirm($controller, $xoopsUser);
114: }
115: else {
116: return $this->_processSave($controller, $xoopsUser);
117: }
118: }
119:
120: function _processConfirm(&$controller,&$xoopsUser)
121: {
122: $statusArr = $this->mActionForm->get('status');
123: $commentHandler =& xoops_getmodulehandler('comment');
124:
125:
126:
127: foreach (array_keys($statusArr) as $cid) {
128: $comment =& $commentHandler->get($cid);
129: if (is_object($comment)) {
130: $this->mCommentObjects[$cid] =& $comment;
131: }
132: unset($comment);
133: }
134:
135: return LEGACY_FRAME_VIEW_INPUT;
136: }
137:
138: function _processSave(&$controller, &$xoopsUser)
139: {
140: $statusArr = $this->mActionForm->get('status');
141:
142: $comment_handler = xoops_gethandler('comment');
143:
144: foreach(array_keys($statusArr) as $cid) {
145: $comment =& $comment_handler->get($cid);
146: if (is_object($comment)) {
147: $olddata['com_status'] = $comment->get('com_status');
148: $newdata['com_status'] = $this->mActionForm->get('status', $cid);
149: if (count(array_diff_assoc($olddata, $newdata)) > 0 ) {
150: $comment->set('com_status', $this->mActionForm->get('status', $cid));
151: if (!$comment_handler->insert($comment)) {
152: return LEGACY_FRAME_VIEW_ERROR;
153: }
154:
155: $add_userpost = false;
156: $call_approvefunc = false;
157: $call_updatefunc = false;
158: $notify_event = false;
159:
160: if (!empty($newdata['com_status']) && $newdata['com_status'] != XOOPS_COMMENT_PENDING) {
161: if (XOOPS_COMMENT_PENDING == $olddata['com_status']) {
162: $add_userpost = true;
163: if (XOOPS_COMMENT_ACTIVE == $newdata['com_status']) {
164: $call_updatefunc = true;
165: $call_approvefunc = true;
166: $notify_event = 'comment';
167: }
168: } elseif (XOOPS_COMMENT_HIDDEN == $olddata['com_status'] && XOOPS_COMMENT_ACTIVE == $newdata['com_status']) {
169: $call_updatefunc = true;
170: } elseif (XOOPS_COMMENT_ACTIVE == $olddata['com_status'] && XOOPS_COMMENT_HIDDEN == $newdata['com_status']) {
171: $call_updatefunc = true;
172: }
173: }
174:
175: $comment_config = Legacy_CommentEditAction::loadCallbackFile($comment);
176:
177: if ($comment_config && $call_approvefunc != false ) {
178: $function = $comment_config['callback']['approve'];
179: if (function_exists($function)) {
180: call_user_func($function, $comment);
181: }
182: }
183:
184: if ($comment_config && $call_updatefunc != false ) {
185: $function = $comment_config['callback']['update'];
186: if (function_exists($function)) {
187: $criteria = new CriteriaCompo(new Criteria('com_modid', $comment->getVar('com_modid')));
188: $criteria->add(new Criteria('com_itemid', $comment->getVar('com_itemid')));
189: $criteria->add(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
190: $comment_count = $comment_handler->getCount($criteria);
191: call_user_func_array($function, array($comment->getVar('com_itemid'), $comment_count, $comment->getVar('com_id')));
192: }
193: }
194:
195: $uid = $comment->getVar('com_uid');
196: if ($uid > 0 && false != $add_userpost) {
197: $member_handler =& xoops_gethandler('member');
198: $poster =& $member_handler->getUser($uid);
199: if (is_object($poster)) {
200: $member_handler->updateUserByField($poster, 'posts', $poster->getVar('posts') + 1);
201: }
202: }
203:
204:
205:
206:
207: if ($notify_event) {
208: $not_modid = $comment->getVar('com_modid');
209: include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
210: $not_catinfo =& notificationCommentCategoryInfo($not_modid);
211: $not_category = $not_catinfo['name'];
212: $not_itemid = $comment->getVar('com_itemid');
213: $not_event = $notify_event;
214: $comment_tags = array();
215: $module_handler =& xoops_gethandler('module');
216: $not_module =& $module_handler->get($not_modid);
217: $com_config =& $not_module->getInfo('comments');
218: $comment_url = $com_config['pageName'] . '?';
219:
220:
221:
222: $comment_url .= $com_config['itemName'];
223: $comment_tags['X_COMMENT_URL'] = XOOPS_URL . '/modules/' . $not_module->getVar('dirname') . '/' .$comment_url . '=' . $comment->getVar('com_itemid').'&com_id='.$comment->getVar('com_id').'&com_rootid='.$comment->getVar('com_rootid').'#comment'.$comment->getVar('com_id');
224: $notification_handler =& xoops_gethandler('notification');
225: $notification_handler->triggerEvent ($not_category, $not_itemid, $not_event, $comment_tags, false, $not_modid);
226: }
227: }
228: }
229: }
230:
231: foreach(array_keys($statusArr) as $cid) {
232: if($this->mActionForm->get('delete', $cid) == 1) {
233: $comment =& $comment_handler->get($cid);
234: if (is_object($comment)) {
235: if( !$comment_handler->delete($comment) ) {
236: return LEGACY_FRAME_VIEW_ERROR;
237: }
238:
239: if ($comment->get('com_status') != 1 && $comment->get('com_uid') > 0) {
240: $memberhandler =& xoops_gethandler('member');
241: $user =& $memberhandler->getUser($comment->get('com_uid'));
242: if (is_object($user)) {
243: $count = $user->get('posts');
244: if($count > 0) {
245: $memberhandler->updateUserByField($user, 'posts', $count - 1);
246: }
247: }
248: }
249:
250: $thread_comments =& $comment_handler->getThread($comment->getVar('com_rootid'), $cid);
251: include_once XOOPS_ROOT_PATH.'/class/tree.php';
252: $xot = new XoopsObjectTree($thread_comments, 'com_id', 'com_pid', 'com_rootid');
253: $child_comments =& $xot->getFirstChild($cid);
254:
255: $new_pid = $comment->getVar('com_pid');
256: $errs = array();
257: foreach (array_keys($child_comments) as $i) {
258: $child_comments[$i]->setVar('com_pid', $new_pid);
259:
260: if (false != $comment->isRoot()) {
261: $new_rootid = $child_comments[$i]->getVar('com_id');
262: $child_comments[$i]->setVar('com_rootid', $child_comments[$i]->getVar('com_id'));
263: if (!$comment_handler->insert($child_comments[$i])) {
264: $errs[] = 'Could not change comment parent ID from <b>'.$cid.'</b> to <b>'.$new_pid.'</b>. (ID: '.$new_rootid.')';
265: } else {
266:
267: $c_child_comments =& $xot->getAllChild($new_rootid);
268: $cc_count = count($c_child_comments);
269: foreach (array_keys($c_child_comments) as $j) {
270: $c_child_comments[$j]->setVar('com_rootid', $new_rootid);
271: if (!$comment_handler->insert($c_child_comments[$j])) {
272: $errs[] = 'Could not change comment root ID from <b>'.$cid.'</b> to <b>'.$new_rootid.'</b>.';
273: }
274: }
275: }
276: } else {
277: if (!$comment_handler->insert($child_comments[$i])) {
278: $errs[] = 'Could not change comment parent ID from <b>'.$cid.'</b> to <b>'.$new_pid.'</b>.';
279: }
280: }
281: }
282: if (count($errs) > 0) {
283: return LEGACY_FRAME_VIEW_ERROR;
284: }
285:
286:
287:
288:
289: $comment_config = Legacy_CommentEditAction::loadCallbackFile($comment);
290:
291: if ($comment_config ) {
292: $function = $comment_config['callback']['update'];
293: if (function_exists($function)) {
294: $criteria = new CriteriaCompo(new Criteria('com_modid', $comment->getVar('com_modid')));
295: $criteria->add(new Criteria('com_itemid', $comment->getVar('com_itemid')));
296: $criteria->add(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
297: $comment_count = $comment_handler->getCount($criteria);
298: call_user_func_array($function, array($comment->getVar('com_itemid'), $comment_count, $comment->getVar('com_id')));
299: }
300: }
301: }
302: }
303: }
304: return LEGACY_FRAME_VIEW_SUCCESS;
305:
306: }
307:
308: 309: 310:
311: function executeViewInput(&$controller, &$xoopsUser, &$render)
312: {
313: foreach (array_keys($this->mCommentObjects) as $key) {
314: $this->mCommentObjects[$key]->loadModule();
315: $this->mCommentObjects[$key]->loadUser();
316: $this->mCommentObjects[$key]->loadStatus();
317: }
318:
319: $render->setTemplateName("comment_list_confirm.html");
320: $render->setAttribute('commentObjects', $this->mCommentObjects);
321: $render->setAttribute('actionForm', $this->mActionForm);
322:
323:
324:
325:
326: $t_arr = $this->mActionForm->get('status');
327: $render->setAttribute('cids', array_keys($t_arr));
328: }
329:
330: function executeViewSuccess(&$controller,&$xoopsUser,&$renderer)
331: {
332: $controller->executeForward('./index.php?action=CommentList');
333: }
334:
335: function executeViewError(&$controller, &$xoopsUser, &$renderer)
336: {
337: $controller->executeRedirect('./index.php?action=CommentList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
338: }
339:
340: function executeViewCancel(&$controller,&$xoopsUser,&$renderer)
341: {
342: $controller->executeForward('./index.php?action=CommentList');
343: }
344:
345: }
346:
347: ?>
348: