23 public $mCommentObjects = [];
24 public $mActionForm =
null;
25 public $mpageArr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0];
27 public function prepare(&$controller, &$xoopsUser)
30 $this->mActionForm->prepare();
33 public function &_getHandler()
35 $handler =& xoops_getmodulehandler(
'comment');
39 public function &_getPageNavi()
41 $navi =
new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
42 if (isset($_REQUEST[$navi->mPrefix.
'perpage']) && 0 == (
int)$_REQUEST[$navi->mPrefix .
'perpage']) {
48 public function &_getFilterForm()
54 public function _getBaseUrl()
56 return './index.php?action=CommentList';
59 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
64 foreach (array_keys($this->mObjects) as $key) {
65 $this->mObjects[$key]->loadModule();
66 $this->mObjects[$key]->loadUser();
67 $this->mObjects[$key]->loadStatus();
71 $handler =& xoops_getmodulehandler(
'comment');
72 $modIds = $handler->getModuleIds();
74 $moduleHandler =& xoops_gethandler(
'module');
75 foreach ($modIds as $mid) {
76 $module =& $moduleHandler->get($mid);
77 if (is_object($module)) {
78 $moduleArr[] =& $module;
84 $statusHandler =& xoops_getmodulehandler(
'commentstatus');
85 $statusArr =& $statusHandler->getObjects();
87 $render->setTemplateName(
'comment_list.html');
88 $render->setAttribute(
'objects', $this->mObjects);
89 $render->setAttribute(
'pageNavi', $this->mFilter->mNavi);
90 $render->setAttribute(
'moduleArr', $moduleArr);
91 $render->setAttribute(
'statusArr', $statusArr);
92 $render->setAttribute(
'filterForm', $this->mFilter);
93 $render->setAttribute(
'pageArr', $this->mpageArr);
95 $render->setAttribute(
'actionForm', $this->mActionForm);
97 $comment_handler =& $this->_getHandler();
98 $comment_total = $comment_handler->getCount();
99 $pending_comment_total = $comment_handler->getCount(
new Criteria(
'com_status', XOOPS_COMMENT_PENDING));
100 $active_comment_total = $comment_handler->getCount(
new Criteria(
'com_status', XOOPS_COMMENT_ACTIVE));
101 $hidden_comment_total = $comment_handler->getCount(
new Criteria(
'com_status', XOOPS_COMMENT_HIDDEN));
102 $render->setAttribute(
'CommentTotal', $comment_total);
103 $render->setAttribute(
'pendingCommentTotal', $pending_comment_total);
104 $render->setAttribute(
'activeCommentTotal', $active_comment_total);
105 $render->setAttribute(
'hiddenCommentTotal', $hidden_comment_total);
108 public function execute(&$controller, &$xoopsUser)
110 if (
null != xoops_getrequest(
'_form_control_cancel')) {
111 return LEGACY_FRAME_VIEW_CANCEL;
114 $this->mActionForm->fetch();
115 $this->mActionForm->validate();
117 if ($this->mActionForm->hasError()) {
118 return $this->_processConfirm($controller, $xoopsUser);
120 return $this->_processSave($controller, $xoopsUser);
124 public function _processConfirm(&$controller, &$xoopsUser)
126 $statusArr = $this->mActionForm->get(
'status');
127 $commentHandler =& xoops_getmodulehandler(
'comment');
131 foreach (array_keys($statusArr) as $cid) {
132 $comment =& $commentHandler->get($cid);
133 if (is_object($comment)) {
134 $this->mCommentObjects[$cid] =& $comment;
139 return LEGACY_FRAME_VIEW_INPUT;
142 public function _processSave(&$controller, &$xoopsUser)
144 $statusArr = $this->mActionForm->get(
'status');
146 $comment_handler = xoops_gethandler(
'comment');
148 foreach (array_keys($statusArr) as $cid) {
149 $comment =& $comment_handler->get($cid);
150 if (is_object($comment)) {
151 $olddata[
'com_status'] = $comment->get(
'com_status');
152 $newdata[
'com_status'] = $this->mActionForm->get(
'status', $cid);
153 if (count(array_diff_assoc($olddata, $newdata)) > 0) {
154 $comment->set(
'com_status', $this->mActionForm->get(
'status', $cid));
155 if (!$comment_handler->insert($comment)) {
156 return LEGACY_FRAME_VIEW_ERROR;
159 $add_userpost =
false;
160 $call_approvefunc =
false;
161 $call_updatefunc =
false;
162 $notify_event =
false;
164 if (!empty($newdata[
'com_status']) && XOOPS_COMMENT_PENDING != $newdata[
'com_status']) {
165 if (XOOPS_COMMENT_PENDING == $olddata[
'com_status']) {
166 $add_userpost =
true;
167 if (XOOPS_COMMENT_ACTIVE == $newdata[
'com_status']) {
168 $call_updatefunc =
true;
169 $call_approvefunc =
true;
170 $notify_event =
'comment';
172 } elseif (XOOPS_COMMENT_HIDDEN == $olddata[
'com_status'] && XOOPS_COMMENT_ACTIVE == $newdata[
'com_status']) {
173 $call_updatefunc =
true;
174 } elseif (XOOPS_COMMENT_ACTIVE == $olddata[
'com_status'] && XOOPS_COMMENT_HIDDEN == $newdata[
'com_status']) {
175 $call_updatefunc =
true;
181 if ($comment_config &&
false != $call_approvefunc) {
182 $function = $comment_config[
'callback'][
'approve'];
183 if (function_exists($function)) {
184 call_user_func($function, $comment);
188 if ($comment_config &&
false != $call_updatefunc) {
189 $function = $comment_config[
'callback'][
'update'];
190 if (function_exists($function)) {
192 $criteria->add(
new Criteria(
'com_itemid', $comment->getVar(
'com_itemid')));
193 $criteria->add(
new Criteria(
'com_status', XOOPS_COMMENT_ACTIVE));
194 $comment_count = $comment_handler->getCount($criteria);
195 call_user_func_array($function, [$comment->getVar(
'com_itemid'), $comment_count, $comment->getVar(
'com_id')]);
199 $uid = $comment->getVar(
'com_uid');
200 if ($uid > 0 &&
false != $add_userpost) {
201 $member_handler =& xoops_gethandler(
'member');
202 $poster =& $member_handler->getUser($uid);
203 if (is_object($poster)) {
204 $member_handler->updateUserByField($poster,
'posts', $poster->getVar(
'posts') + 1);
212 $not_modid = $comment->getVar(
'com_modid');
213 include_once XOOPS_ROOT_PATH .
'/include/notification_functions.php';
214 $not_catinfo =& notificationCommentCategoryInfo($not_modid);
215 $not_category = $not_catinfo[
'name'];
216 $not_itemid = $comment->getVar(
'com_itemid');
217 $not_event = $notify_event;
219 $module_handler =& xoops_gethandler(
'module');
220 $not_module =& $module_handler->get($not_modid);
221 $com_config =& $not_module->getInfo(
'comments');
222 $comment_url = $com_config[
'pageName'] .
'?';
226 $comment_url .= $com_config[
'itemName'];
227 $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');
228 $notification_handler =& xoops_gethandler(
'notification');
229 $notification_handler->triggerEvent($not_category, $not_itemid, $not_event, $comment_tags,
false, $not_modid);
235 foreach (array_keys($statusArr) as $cid) {
236 if (1 == $this->mActionForm->get(
'delete', $cid)) {
237 $comment =& $comment_handler->get($cid);
238 if (is_object($comment)) {
239 if (!$comment_handler->delete($comment)) {
240 return LEGACY_FRAME_VIEW_ERROR;
243 if (1 != $comment->get(
'com_status') && $comment->get(
'com_uid') > 0) {
244 $memberhandler =& xoops_gethandler(
'member');
245 $user =& $memberhandler->getUser($comment->get(
'com_uid'));
246 if (is_object($user)) {
247 $count = $user->get(
'posts');
249 $memberhandler->updateUserByField($user,
'posts', $count - 1);
254 $thread_comments =& $comment_handler->getThread($comment->getVar(
'com_rootid'), $cid);
255 include_once XOOPS_ROOT_PATH.
'/class/tree.php';
256 $xot =
new XoopsObjectTree($thread_comments,
'com_id',
'com_pid',
'com_rootid');
257 $child_comments =& $xot->getFirstChild($cid);
259 $new_pid = $comment->getVar(
'com_pid');
261 foreach (array_keys($child_comments) as $i) {
262 $child_comments[$i]->setVar(
'com_pid', $new_pid);
264 if (
false != $comment->isRoot()) {
265 $new_rootid = $child_comments[$i]->getVar(
'com_id');
266 $child_comments[$i]->setVar(
'com_rootid', $child_comments[$i]->getVar(
'com_id'));
267 if (!$comment_handler->insert($child_comments[$i])) {
268 $errs[] =
'Could not change comment parent ID from <b>'.$cid.
'</b> to <b>'.$new_pid.
'</b>. (ID: '.$new_rootid.
')';
271 $c_child_comments =& $xot->getAllChild($new_rootid);
272 $cc_count = is_countable($c_child_comments) ? count($c_child_comments) : 0;
273 foreach (array_keys($c_child_comments) as $j) {
274 $c_child_comments[$j]->setVar(
'com_rootid', $new_rootid);
275 if (!$comment_handler->insert($c_child_comments[$j])) {
276 $errs[] =
'Could not change comment root ID from <b>'.$cid.
'</b> to <b>'.$new_rootid.
'</b>.';
281 if (!$comment_handler->insert($child_comments[$i])) {
282 $errs[] =
'Could not change comment parent ID from <b>'.$cid.
'</b> to <b>'.$new_pid.
'</b>.';
286 if (count($errs) > 0) {
287 return LEGACY_FRAME_VIEW_ERROR;
295 if ($comment_config) {
296 $function = $comment_config[
'callback'][
'update'];
297 if (function_exists($function)) {
299 $criteria->add(
new Criteria(
'com_itemid', $comment->getVar(
'com_itemid')));
300 $criteria->add(
new Criteria(
'com_status', XOOPS_COMMENT_ACTIVE));
301 $comment_count = $comment_handler->getCount($criteria);
302 call_user_func_array($function, [$comment->getVar(
'com_itemid'), $comment_count, $comment->getVar(
'com_id')]);
308 return LEGACY_FRAME_VIEW_SUCCESS;
319 foreach (array_keys($this->mCommentObjects) as $key) {
320 $this->mCommentObjects[$key]->loadModule();
321 $this->mCommentObjects[$key]->loadUser();
322 $this->mCommentObjects[$key]->loadStatus();
325 $render->setTemplateName(
'comment_list_confirm.html');
326 $render->setAttribute(
'commentObjects', $this->mCommentObjects);
327 $render->setAttribute(
'actionForm', $this->mActionForm);
332 $t_arr = $this->mActionForm->get(
'status');
333 $render->setAttribute(
'cids', array_keys($t_arr));
336 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
338 $controller->executeForward(
'./index.php?action=CommentList');
341 public function executeViewError(&$controller, &$xoopsUser, &$renderer)
343 $controller->executeRedirect(
'./index.php?action=CommentList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
346 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
348 $controller->executeForward(
'./index.php?action=CommentList');