topicadmin_delcomment.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: topicadmin_delcomment.php 31950 2012-10-25 09:05:44Z liulanbo $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!$_G['group']['allowdelpost'] || empty($_GET['topiclist'])) {
  12. showmessage('no_privilege_delcomment');
  13. }
  14. if(!submitcheck('modsubmit')) {
  15. $commentid = $_GET['topiclist'][0];
  16. $pid = C::t('forum_postcomment')->fetch($commentid);
  17. $pid = $pid['pid'];
  18. if(!$pid) {
  19. showmessage('postcomment_not_found');
  20. }
  21. $deleteid = '<input type="hidden" name="topiclist" value="'.$commentid.'" />';
  22. include template('forum/topicadmin_action');
  23. } else {
  24. $reason = checkreasonpm();
  25. $modaction = 'DCM';
  26. $commentid = intval($_GET['topiclist']);
  27. $postcomment = C::t('forum_postcomment')->fetch($commentid);
  28. if(!$postcomment) {
  29. showmessage('postcomment_not_found');
  30. }
  31. C::t('forum_postcomment')->delete($commentid);
  32. $result = C::t('forum_postcomment')->count_by_pid($postcomment['pid']);
  33. if(!$result) {
  34. C::t('forum_post')->update($_G['thread']['posttableid'], $postcomment['pid'], array('comment' => 0));
  35. }
  36. if($thread['comments']) {
  37. C::t('forum_thread')->update($_G['tid'], array('comments' => $thread['comments'] - 1));
  38. }
  39. if(!$postcomment['rpid']) {
  40. updatepostcredits('-', $postcomment['authorid'], 'reply', $_G['fid']);
  41. }
  42. $totalcomment = array();
  43. foreach(C::t('forum_postcomment')->fetch_all_by_pid_score($postcomment['pid'], 1) as $comment) {
  44. if(strexists($comment['comment'], '<br />')) {
  45. if(preg_match_all("/([^:]+?):\s<i>(\d+)<\/i>/", $comment['comment'], $a)) {
  46. foreach($a[1] as $k => $itemk) {
  47. $totalcomment[trim($itemk)][] = $a[2][$k];
  48. }
  49. }
  50. }
  51. }
  52. $totalv = '';
  53. foreach($totalcomment as $itemk => $itemv) {
  54. $totalv .= strip_tags(trim($itemk)).': <i>'.(sprintf('%1.1f', array_sum($itemv) / count($itemv))).'</i> ';
  55. }
  56. if($totalv) {
  57. C::t('forum_postcomment')->update_by_pid($postcomment['pid'], array('comment' => $totalv, 'dateline' => TIMESTAMP + 1), false, false, 0);
  58. } else {
  59. C::t('forum_postcomment')->delete_by_pid($postcomment['pid'], false, 0);
  60. }
  61. C::t('forum_postcache')->delete($postcomment['pid']);
  62. $resultarray = array(
  63. 'redirect' => "forum.php?mod=viewthread&tid=$_G[tid]&page=$page",
  64. 'reasonpm' => ($sendreasonpm ? array('data' => array($postcomment), 'var' => 'post', 'item' => 'reason_delete_comment', 'notictype' => 'pcomment') : array()),
  65. 'reasonvar' => array('tid' => $thread['tid'], 'pid' => $postcomment['pid'], 'subject' => $thread['subject'], 'modaction' => $modaction, 'reason' => $reason),
  66. 'modtids' => 0,
  67. 'modlog' => $thread
  68. );
  69. }
  70. ?>