14if (!defined(
'XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
18include_once XOOPS_ROOT_PATH.
'/include/comment_constants.php';
23 $com_mode = isset($_POST[
'com_mode']) ? htmlspecialchars(trim($_POST[
'com_mode']), ENT_QUOTES) :
'flat';
24 $com_order = isset($_POST[
'com_order']) ? (int)$_POST[
'com_order'] : XOOPS_COMMENT_OLD1ST;
25 $com_id = isset($_POST[
'com_id']) ? (int)$_POST[
'com_id'] : 0;
26 $op = $_POST[
'op'] ??
'delete';
28 $com_mode = isset($_GET[
'com_mode']) ? htmlspecialchars(trim($_GET[
'com_mode']), ENT_QUOTES) :
'flat';
29 $com_order = isset($_GET[
'com_order']) ? (int)$_GET[
'com_order'] : XOOPS_COMMENT_OLD1ST;
30 $com_id = isset($_GET[
'com_id']) ? (int)$_GET[
'com_id'] : 0;
34if (
'system' == $xoopsModule->getVar(
'dirname')) {
35 $comment_handler =& xoops_gethandler(
'comment');
36 $comment =& $comment_handler->get($com_id);
37 $module_handler =& xoops_gethandler(
'module');
38 $module =& $module_handler->get($comment->getVar(
'com_modid'));
39 $comment_config = $module->getInfo(
'comments');
40 $com_modid = $module->getVar(
'mid');
41 $redirect_page = XOOPS_URL.
'/modules/system/admin.php?fct=comments&com_modid='.$com_modid.
'&com_itemid';
42 $moddir = $module->getVar(
'dirname');
45 if (XOOPS_COMMENT_APPROVENONE == $xoopsModuleConfig[
'com_rule']) {
48 $comment_config = $xoopsModule->getInfo(
'comments');
49 $com_modid = $xoopsModule->getVar(
'mid');
50 $redirect_page = $comment_config[
'pageName'].
'?';
51 $comment_confirm_extra = [];
52 if (isset($comment_config[
'extraParams']) && is_array($comment_config[
'extraParams'])) {
53 foreach ($comment_config[
'extraParams'] as $extra_param) {
54 if (isset(${$extra_param})) {
55 $redirect_page .= $extra_param.
'='.${$extra_param}.
'&';
58 $comment_confirm_extra [$extra_param] = ${$extra_param};
59 } elseif (isset($_GET[$extra_param])) {
60 $redirect_page .= $extra_param.
'='.$_GET[$extra_param].
'&';
63 $comment_confirm_extra [$extra_param] = $_GET[$extra_param];
67 $redirect_page .= $comment_config[
'itemName'];
68 $moddir = $xoopsModule->getVar(
'dirname');
73if (!is_object($xoopsUser)) {
75}
else if (!$xoopsUser->isAdmin($com_modid)) {
76 $sysperm_handler =& xoops_gethandler(
'groupperm');
77 if (!$sysperm_handler->checkRight(
'system_admin', LEGACY_SYSTEM_COMMENT, $xoopsUser->getGroups())) {
82if (
false !== $accesserror) {
83 $ref = xoops_getenv(
'HTTP_REFERER');
85 redirect_header($ref, 2, _NOPERM);
87 redirect_header($redirect_page.
'?'.$comment_config[
'itemName'].
'='.(
int)$com_itemid, 2, _NOPERM);
92$t_root =& XCube_Root::getSingleton();
94$t_root->mLanguageManager->loadPageTypeMessageCatalog(
'comment');
98 $comment_handler = xoops_gethandler(
'comment');
99 $comment =& $comment_handler->get($com_id);
100 if (!$comment_handler->delete($comment)) {
101 include XOOPS_ROOT_PATH.
'/header.php';
102 xoops_error(_CM_COMDELETENG.
' (ID: '.$comment->getVar(
'com_id').
')');
103 include XOOPS_ROOT_PATH.
'/footer.php';
107 $com_itemid = $comment->getVar(
'com_itemid');
110 if (isset($comment_config[
'callback'][
'update']) &&
'' !== trim($comment_config[
'callback'][
'update'])) {
112 if (!function_exists($comment_config[
'callback'][
'update'])) {
113 if (isset($comment_config[
'callbackFile'])) {
114 $callbackfile = trim($comment_config[
'callbackFile']);
115 if (
'' != $callbackfile && file_exists(XOOPS_ROOT_PATH .
'/modules/' . $moddir .
'/' . $callbackfile)) {
116 include_once XOOPS_ROOT_PATH.
'/modules/'.$moddir.
'/'.$callbackfile;
118 if (!function_exists($comment_config[
'callback'][
'update'])) {
127 $criteria->add(
new Criteria(
'com_itemid', $com_itemid));
128 $criteria->add(
new Criteria(
'com_status', XOOPS_COMMENT_ACTIVE));
129 $comment_count = $comment_handler->getCount($criteria);
130 $comment_config[
'callback'][
'update']($com_itemid, $comment_count);
135 if (0 !== $comment->getVar(
'com_uid')) {
136 $member_handler =& xoops_gethandler(
'member');
137 $com_poster =& $member_handler->getUser($comment->getVar(
'com_uid'));
138 if (is_object($com_poster)) {
139 $member_handler->updateUserByField($com_poster,
'posts', $com_poster->getVar(
'posts') - 1);
144 $thread_comments =& $comment_handler->getThread($comment->getVar(
'com_rootid'), $com_id);
146 include_once XOOPS_ROOT_PATH.
'/class/tree.php';
147 $xot =
new XoopsObjectTree($thread_comments,
'com_id',
'com_pid',
'com_rootid');
149 $child_comments =& $xot->getFirstChild($com_id);
152 $new_pid = $comment->getVar(
'com_pid');
154 foreach (array_keys($child_comments) as $i) {
155 $child_comments[$i]->setVar(
'com_pid', $new_pid);
157 if (
false !== $comment->isRoot()) {
158 $new_rootid = $child_comments[$i]->getVar(
'com_id');
159 $child_comments[$i]->setVar(
'com_rootid', $child_comments[$i]->getVar(
'com_id'));
160 if (!$comment_handler->insert($child_comments[$i])) {
161 $errs[] =
'Could not change comment parent ID from <b>'.$com_id.
'</b> to <b>'.$new_pid.
'</b>. (ID: '.$new_rootid.
')';
164 $c_child_comments =& $xot->getAllChild($new_rootid);
165 $cc_count = is_countable($c_child_comments) ? count($c_child_comments) : 0;
166 foreach (array_keys($c_child_comments) as $j) {
167 $c_child_comments[$j]->setVar(
'com_rootid', $new_rootid);
168 if (!$comment_handler->insert($c_child_comments[$j])) {
169 $errs[] =
'Could not change comment root ID from <b>'.$com_id.
'</b> to <b>'.$new_rootid.
'</b>.';
174 if (!$comment_handler->insert($child_comments[$i])) {
175 $errs[] =
'Could not change comment parent ID from <b>'.$com_id.
'</b> to <b>'.$new_pid.
'</b>.';
179 if (count($errs) > 0) {
180 include XOOPS_ROOT_PATH.
'/header.php';
182 include XOOPS_ROOT_PATH.
'/footer.php';
185 redirect_header($redirect_page.
'='.$com_itemid.
'&com_order='.$com_order.
'&com_mode='.$com_mode, 1, _CM_COMDELETED);
189 $comment_handler = xoops_gethandler(
'comment');
190 $comment =& $comment_handler->get($com_id);
191 $com_rootid = $comment->getVar(
'com_rootid');
194 $thread_comments =& $comment_handler->getThread($com_rootid, $com_id);
197 include_once XOOPS_ROOT_PATH.
'/class/tree.php';
198 $xot =
new XoopsObjectTree($thread_comments,
'com_id',
'com_pid',
'com_rootid');
199 $child_comments =& $xot->getAllChild($com_id);
201 $child_comments[$com_id] =& $comment;
204 $member_handler =& xoops_gethandler(
'member');
205 foreach (array_keys($child_comments) as $i) {
206 if (!$comment_handler->delete($child_comments[$i])) {
207 $msgs[] = _CM_COMDELETENG.
' (ID: '.$child_comments[$i]->getVar(
'com_id').
')';
209 $msgs[] = _CM_COMDELETED.
' (ID: '.$child_comments[$i]->getVar(
'com_id').
')';
211 $poster_id = $child_comments[$i]->getVar(
'com_uid');
212 if ($poster_id > 0) {
213 $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1);
217 foreach ($deleted_num as $user_id => $post_num) {
219 $com_poster = $member_handler->getUser($user_id);
220 if (is_object($com_poster)) {
221 $member_handler->updateUserByField($com_poster,
'posts', $com_poster->getVar(
'posts') - $post_num);
225 $com_itemid = $comment->getVar(
'com_itemid');
228 if (isset($comment_config[
'callback'][
'update']) &&
'' !== trim($comment_config[
'callback'][
'update'])) {
230 if (!function_exists($comment_config[
'callback'][
'update'])) {
231 if (isset($comment_config[
'callbackFile'])) {
232 $callbackfile = trim($comment_config[
'callbackFile']);
233 if (
'' !== $callbackfile && file_exists(XOOPS_ROOT_PATH .
'/modules/' . $moddir .
'/' . $callbackfile)) {
234 include_once XOOPS_ROOT_PATH.
'/modules/'.$moddir.
'/'.$callbackfile;
236 if (!function_exists($comment_config[
'callback'][
'update'])) {
245 $criteria->add(
new Criteria(
'com_itemid', $com_itemid));
246 $criteria->add(
new Criteria(
'com_status', XOOPS_COMMENT_ACTIVE));
247 $comment_count = $comment_handler->getCount($criteria);
248 $comment_config[
'callback'][
'update']($com_itemid, $comment_count);
252 include XOOPS_ROOT_PATH.
'/header.php';
255 echo
'<br><a href="'.$redirect_page.
'='.$com_itemid.
'&com_order='.$com_order.
'&com_mode='.$com_mode.
'">'._BACK.
'</a>';
256 include XOOPS_ROOT_PATH.
'/footer.php';
261 include XOOPS_ROOT_PATH.
'/header.php';
262 $comment_confirm = [
'com_id' => $com_id,
'com_mode' => $com_mode,
'com_order' => $com_order,
'op' => [_CM_DELETEONE =>
'delete_one', _CM_DELETEALL =>
'delete_all']];
263 if (!empty($comment_confirm_extra) && is_array($comment_confirm_extra)) {
264 $comment_confirm = $comment_confirm + $comment_confirm_extra;
266 xoops_confirm($comment_confirm,
'comment_delete.php', _CM_DELETESELECT);
267 include XOOPS_ROOT_PATH.
'/footer.php';