14if (!defined(
'XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
18$t_root =& XCube_Root::getSingleton();
19$t_root->mLanguageManager->loadPageTypeMessageCatalog(
'comment');
21include_once XOOPS_ROOT_PATH.
'/include/comment_constants.php';
23$com_id = isset($_POST[
'com_id']) ? (int)$_POST[
'com_id'] : 0;
26if (
'system' == $xoopsModule->getVar(
'dirname')) {
30 $comment_handler =& xoops_gethandler(
'comment');
31 $comment =& $comment_handler->get($com_id);
32 $module_handler =& xoops_gethandler(
'module');
33 $module =& $module_handler->get($comment->getVar(
'com_modid'));
34 $comment_config = $module->getInfo(
'comments');
35 $com_modid = $module->getVar(
'mid');
36 $redirect_page = XOOPS_URL.
'/modules/system/admin.php?fct=comments&com_modid='.$com_modid.
'&com_itemid';
37 $moddir = $module->getVar(
'dirname');
40 if (XOOPS_COMMENT_APPROVENONE == $xoopsModuleConfig[
'com_rule']) {
43 $comment_config = $xoopsModule->getInfo(
'comments');
44 $com_modid = $xoopsModule->getVar(
'mid');
45 $redirect_page = $comment_config[
'pageName'].
'?';
46 if (isset($comment_config[
'extraParams']) && is_array($comment_config[
'extraParams'])) {
48 foreach ($comment_config[
'extraParams'] as $extra_param) {
49 $extra_params .= isset($_POST[$extra_param]) ? $extra_param.
'='.$myts->stripSlashesGPC($_POST[$extra_param]).
'&' : $extra_param.
'=&';
51 $redirect_page .= $extra_params;
53 $redirect_page .= $comment_config[
'itemName'];
54 $comment_url = $redirect_page;
55 $moddir = $xoopsModule->getVar(
'dirname');
60 if (isset($_POST[
'com_dopost'])) {
62 } elseif (isset($_POST[
'com_dopreview'])) {
65 if (isset($_POST[
'com_dodelete'])) {
69 $com_mode = isset($_POST[
'com_mode']) ? htmlspecialchars(trim($_POST[
'com_mode']), ENT_QUOTES) :
'flat';
70 $com_order = isset($_POST[
'com_order']) ? (int)$_POST[
'com_order'] : XOOPS_COMMENT_OLD1ST;
71 $com_itemid = isset($_POST[
'com_itemid']) ? (int)$_POST[
'com_itemid'] : 0;
72 $com_pid = isset($_POST[
'com_pid']) ? (int)$_POST[
'com_pid'] : 0;
73 $com_rootid = isset($_POST[
'com_rootid']) ? (int)$_POST[
'com_rootid'] : 0;
74 $com_status = isset($_POST[
'com_status']) ? (int)$_POST[
'com_status'] : 0;
75 $dosmiley = (isset($_POST[
'dosmiley']) && (int)$_POST[
'dosmiley'] > 0) ? 1 : 0;
76 $doxcode = (isset($_POST[
'doxcode']) && (int)$_POST[
'doxcode'] > 0) ? 1 : 0;
77 $dobr = (isset($_POST[
'dobr']) && (int)$_POST[
'dobr'] > 0) ? 1 : 0;
78 $dohtml = (isset($_POST[
'dohtml']) && (int)$_POST[
'dohtml'] > 0) ? 1 : 0;
79 $doimage = (isset($_POST[
'doimage']) && (int)$_POST[
'doimage'] > 0) ? 1 : 0;
80 $com_icon = isset($_POST[
'com_icon']) ? trim($_POST[
'com_icon']) :
'';
81 $noname = isset($_POST[
'noname']) ? (int)$_POST[
'noname'] : 0;
89 include XOOPS_ROOT_PATH.
'/include/comment_delete.php';
94 $com_title = $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST[
'com_title']));
96 if (is_object($xoopsUser)) {
97 if (!$xoopsUser->isAdmin($com_modid)) {
98 $sysperm_handler =& xoops_gethandler(
'groupperm');
99 if (!$sysperm_handler->checkRight(
'system_admin', LEGACY_SYSTEM_COMMENT, $xoopsUser->getGroups())) {
107 $p_comment =& $myts->previewTarea($_POST[
'com_text'], $dohtml, $dosmiley, $doxcode, $doimage, $dobr);
108 $com_text = $myts->htmlSpecialChars($myts->stripSlashesGPC($_POST[
'com_text']));
109 if (
'system' !== $xoopsModule->getVar(
'dirname')) {
110 include XOOPS_ROOT_PATH.
'/header.php';
111 themecenterposts($com_title, $p_comment);
112 include XOOPS_ROOT_PATH.
'/include/comment_form.php';
113 include XOOPS_ROOT_PATH.
'/footer.php';
116 themecenterposts($com_title, $p_comment);
117 include XOOPS_ROOT_PATH.
'/include/comment_form.php';
123 $comment_handler =& xoops_gethandler(
'comment');
124 $add_userpost =
false;
125 $call_approvefunc =
false;
126 $call_updatefunc =
false;
128 $notify_event =
false;
129 if (!empty($com_id)) {
130 $comment =& $comment_handler->get($com_id);
131 $accesserror =
false;
133 if (is_object($xoopsUser)) {
134 $sysperm_handler =& xoops_gethandler(
'groupperm');
135 if ($xoopsUser->isAdmin($com_modid) || $sysperm_handler->checkRight(
'system_admin', LEGACY_SYSTEM_COMMENT, $xoopsUser->getGroups())) {
136 if (!empty($com_status) && XOOPS_COMMENT_PENDING != $com_status) {
137 $old_com_status = $comment->getVar(
'com_status');
138 $comment->setVar(
'com_status', $com_status);
140 if (XOOPS_COMMENT_PENDING == $old_com_status) {
141 $add_userpost =
true;
142 if (XOOPS_COMMENT_ACTIVE == $com_status) {
143 $call_updatefunc =
true;
144 $call_approvefunc =
true;
146 $notify_event =
'comment';
148 } elseif (XOOPS_COMMENT_HIDDEN == $old_com_status && XOOPS_COMMENT_ACTIVE == $com_status) {
149 $call_updatefunc =
true;
152 } elseif (XOOPS_COMMENT_ACTIVE == $old_com_status && XOOPS_COMMENT_HIDDEN == $com_status) {
153 $call_updatefunc =
true;
158 if ($comment->getVar(
'com_uid') !== $xoopsUser->getVar(
'uid')) {
166 if (
false !== $accesserror) {
167 redirect_header($redirect_page.
'='.$com_itemid.
'&com_id='.$com_id.
'&com_mode='.$com_mode.
'&com_order='.$com_order, 1, _NOPERM);
171 $comment = $comment_handler->create();
172 $comment->setVar(
'com_created', time());
173 $comment->setVar(
'com_pid', $com_pid);
174 $comment->setVar(
'com_itemid', $com_itemid);
175 $comment->setVar(
'com_rootid', $com_rootid);
176 $comment->setVar(
'com_ip', xoops_getenv(
'REMOTE_ADDR'));
177 if (is_object($xoopsUser)) {
178 $sysperm_handler =& xoops_gethandler(
'groupperm');
179 if ($xoopsUser->isAdmin($com_modid) || $sysperm_handler->checkRight(
'system_admin', LEGACY_SYSTEM_COMMENT, $xoopsUser->getGroups())) {
180 $comment->setVar(
'com_status', XOOPS_COMMENT_ACTIVE);
181 $add_userpost =
true;
182 $call_approvefunc =
true;
183 $call_updatefunc =
true;
185 $notify_event =
'comment';
188 switch ($xoopsModuleConfig[
'com_rule']) {
189 case XOOPS_COMMENT_APPROVEALL:
190 case XOOPS_COMMENT_APPROVEUSER:
191 $comment->setVar(
'com_status', XOOPS_COMMENT_ACTIVE);
192 $add_userpost =
true;
193 $call_approvefunc =
true;
194 $call_updatefunc =
true;
196 $notify_event =
'comment';
198 case XOOPS_COMMENT_APPROVEADMIN:
200 $comment->setVar(
'com_status', XOOPS_COMMENT_PENDING);
201 $notify_event =
'comment_submit';
205 if (!empty($xoopsModuleConfig[
'com_anonpost']) && !empty($noname)) {
208 $uid = $xoopsUser->getVar(
'uid');
213 if (1 !== $xoopsModuleConfig[
'com_anonpost']) {
214 redirect_header($redirect_page.
'='.$com_itemid.
'&com_id='.$com_id.
'&com_mode='.$com_mode.
'&com_order='.$com_order, 1, _NOPERM);
219 switch ($xoopsModuleConfig[
'com_rule']) {
220 case XOOPS_COMMENT_APPROVEALL:
221 $comment->setVar(
'com_status', XOOPS_COMMENT_ACTIVE);
222 $add_userpost =
true;
223 $call_approvefunc =
true;
224 $call_updatefunc =
true;
226 $notify_event =
'comment';
228 case XOOPS_COMMENT_APPROVEADMIN:
229 case XOOPS_COMMENT_APPROVEUSER:
231 $comment->setVar(
'com_status', XOOPS_COMMENT_PENDING);
233 $notify_event =
'comment_submit';
237 $comment->setVar(
'com_uid', $uid);
239 $com_title = xoops_trim($_POST[
'com_title']);
240 $com_title = (
'' == $com_title) ? _NOTITLE : $com_title;
241 $comment->setVar(
'com_title', $com_title);
242 $comment->setVar(
'com_text', $_POST[
'com_text']);
243 $comment->setVar(
'dohtml', $dohtml);
244 $comment->setVar(
'dosmiley', $dosmiley);
245 $comment->setVar(
'doxcode', $doxcode);
246 $comment->setVar(
'doimage', $doimage);
247 $comment->setVar(
'dobr', $dobr);
248 $comment->setVar(
'com_icon', $com_icon);
249 $comment->setVar(
'com_modified', time());
250 $comment->setVar(
'com_modid', $com_modid);
251 if (!empty($extra_params)) {
252 $comment->setVar(
'com_exparams', str_replace(
'&',
'&', $extra_params));
254 if (
false !== $comment_handler->insert($comment)) {
255 $newcid = $comment->getVar(
'com_id');
258 if (0 == $com_rootid) {
259 $com_rootid = $newcid;
260 if (!$comment_handler->updateByField($comment,
'com_rootid', $com_rootid)) {
261 $comment_handler->delete($comment);
262 include XOOPS_ROOT_PATH.
'/header.php';
264 include XOOPS_ROOT_PATH.
'/footer.php';
269 if (
false !== $call_approvefunc && isset($comment_config[
'callback'][
'approve']) &&
'' !== trim($comment_config[
'callback'][
'approve'])) {
271 if (!function_exists($comment_config[
'callback'][
'approve'])) {
272 if (isset($comment_config[
'callbackFile'])) {
273 $callbackfile = trim($comment_config[
'callbackFile']);
274 if (
'' != $callbackfile && file_exists(XOOPS_ROOT_PATH .
'/modules/' . $moddir .
'/' . $callbackfile)) {
275 include_once XOOPS_ROOT_PATH.
'/modules/'.$moddir.
'/'.$callbackfile;
277 if (!function_exists($comment_config[
'callback'][
'approve'])) {
285 $comment_config[
'callback'][
'approve']($comment);
290 if (
false !== $call_updatefunc && isset($comment_config[
'callback'][
'update']) &&
'' != trim($comment_config[
'callback'][
'update'])) {
292 if (!function_exists($comment_config[
'callback'][
'update'])) {
293 if (isset($comment_config[
'callbackFile'])) {
294 $callbackfile = trim($comment_config[
'callbackFile']);
295 if (
'' !== $callbackfile && file_exists(XOOPS_ROOT_PATH .
'/modules/' . $moddir .
'/' . $callbackfile)) {
296 include_once XOOPS_ROOT_PATH.
'/modules/'.$moddir.
'/'.$callbackfile;
298 if (!function_exists($comment_config[
'callback'][
'update'])) {
307 $criteria->add(
new Criteria(
'com_itemid', $com_itemid));
308 $criteria->add(
new Criteria(
'com_status', XOOPS_COMMENT_ACTIVE));
309 $comment_count = $comment_handler->getCount($criteria);
310 $func = $comment_config[
'callback'][
'update'];
311 call_user_func_array($func, [$com_itemid, $comment_count, $comment->getVar(
'com_id')]);
316 $uid = $comment->getVar(
'com_uid');
317 if ($uid > 0 &&
false !== $add_userpost) {
318 $member_handler =& xoops_gethandler(
'member');
319 $poster =& $member_handler->getUser($uid);
320 if (is_object($poster)) {
321 $member_handler->updateUserByField($poster,
'posts', $poster->getVar(
'posts') + 1);
328 $not_modid = $com_modid;
329 include_once XOOPS_ROOT_PATH .
'/include/notification_functions.php';
330 $not_catinfo =& notificationCommentCategoryInfo($not_modid);
331 $not_category = $not_catinfo[
'name'];
332 $not_itemid = $com_itemid;
333 $not_event = $notify_event;
338 if (
'system' == $xoopsModule->getVar(
'dirname')) {
339 $module_handler =& xoops_gethandler(
'module');
340 $not_module =& $module_handler->get($not_modid);
342 $not_module =& $xoopsModule;
344 if (!isset($comment_url)) {
345 $com_config =& $not_module->getInfo(
'comments');
346 $comment_url = $com_config[
'pageName'] .
'?';
347 if (isset($com_config[
'extraParams']) && is_array($com_config[
'extraParams'])) {
349 foreach ($com_config[
'extraParams'] as $extra_param) {
350 $extra_params .= isset($_POST[$extra_param]) ? $extra_param.
'='.$_POST[$extra_param].
'&' : $extra_param.
'=&';
353 $comment_url .= $extra_params;
355 $comment_url .= $com_config[
'itemName'];
357 $comment_tags[
'X_COMMENT_URL'] = XOOPS_URL .
'/modules/' . $not_module->getVar(
'dirname') .
'/' .$comment_url .
'=' . $com_itemid.
'&com_id='.$newcid.
'&com_rootid='.$com_rootid.
'&com_mode='.$com_mode.
'&com_order='.$com_order.
'#comment'.$newcid;
358 $notification_handler =& xoops_gethandler(
'notification');
359 $notification_handler->triggerEvent($not_category, $not_itemid, $not_event, $comment_tags,
false, $not_modid);
362 if (!isset($comment_post_results)) {
365 if (XOOPS_COMMENT_ACTIVE == $comment->getVar(
'com_status')) {
366 redirect_header($redirect_page.
'='.$com_itemid.
'&com_id='.$newcid.
'&com_rootid='.$com_rootid.
'&com_mode='.$com_mode.
'&com_order='.$com_order.
'#comment'.$newcid, 2, _CM_THANKSPOST);
369 redirect_header($redirect_page.
'='.$com_itemid.
'&com_mode='.$com_mode.
'&com_order='.$com_order.
'#comment'.$newcid, 2, _CM_THANKSPOST);
373 if (!isset($purge_comment_post_results)) {
374 include XOOPS_ROOT_PATH.
'/header.php';
375 xoops_error($comment->getErrors());
376 include XOOPS_ROOT_PATH.
'/footer.php';
378 $comment_post_results = $comment->getErrors();
383 redirect_header(XOOPS_URL.
'/', 2);