topicadmin_merge.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_merge.php 31741 2012-09-26 08:12:08Z zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!$_G['group']['allowmergethread']) {
  12. showmessage('no_privilege_mergethread');
  13. }
  14. if(!submitcheck('modsubmit')) {
  15. include template('forum/topicadmin_action');
  16. } else {
  17. $posttable = getposttablebytid($_G['tid']);
  18. $othertid = intval($_GET['othertid']);
  19. $otherposttable = getposttablebytid($othertid);
  20. $modaction = 'MRG';
  21. $reason = checkreasonpm();
  22. $other = C::t('forum_thread')->fetch_by_tid_displayorder($othertid, 0);
  23. if(!$other) {
  24. showmessage('admin_merge_nonexistence');
  25. } elseif($other['special']) {
  26. showmessage('special_noaction');
  27. }
  28. if($othertid == $_G['tid'] || ($_G['adminid'] == 3 && $other['fid'] != $_G['forum']['fid'])) {
  29. showmessage('admin_merge_invalid');
  30. }
  31. $other['views'] = intval($other['views']);
  32. $other['replies']++;
  33. if(!$other['maxposition']) {
  34. $other['maxposition'] = C::t('forum_post')->fetch_maxposition_by_tid($other['posttableid'], $othertid);
  35. }
  36. if(!$thread['maxposition']) {
  37. $thread['maxposition'] = C::t('forum_post')->fetch_maxposition_by_tid($thread['posttableid'], $_G['tid']);
  38. }
  39. $pos = 1;
  40. if($posttable != $otherposttable) {
  41. $pidlist = array();
  42. C::t('forum_post')->increase_position_by_tid($thread['posttableid'], $_G['tid'], $other['maxposition'] + $thread['maxposition']);
  43. C::t('forum_post')->increase_position_by_tid($other['posttableid'], $othertid, $other['maxposition'] + $thread['maxposition']);
  44. foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], false, 'ASC') as $row) {
  45. $pidlist[$row['dateline']] = array('pid' => $row['pid'], 'tid' => $row['tid']);
  46. }
  47. foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$othertid, $othertid, false, 'ASC') as $row) {
  48. $pidlist[$row['dateline']] = array('pid' => $row['pid'], 'tid' => $row['tid']);
  49. }
  50. ksort($pidlist);
  51. foreach($pidlist as $row) {
  52. C::t('forum_post')->update('tid:'.$row['tid'], $row['pid'], array('position' => $pos));
  53. $pos ++;
  54. }
  55. unset($pidlist);
  56. } else {
  57. C::t('forum_post')->increase_position_by_tid($thread['posttableid'], array($_G['tid'], $othertid), $other['maxposition'] + $thread['maxposition']);
  58. foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], array($_G['tid'], $othertid), false, 'ASC') as $row) {
  59. C::t('forum_post')->update('tid:'.$_G['tid'], $row['pid'], array('position' => $pos));
  60. $pos ++;
  61. }
  62. }
  63. if($posttable != $otherposttable) {
  64. foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$othertid, $othertid) as $row) {
  65. C::t('forum_post')->insert('tid:'.$_G['tid'], $row);
  66. }
  67. C::t('forum_post')->delete_by_tid('tid:'.$othertid, $othertid);
  68. }
  69. $query = C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], array($_G['tid'], $othertid), false, 'ASC', 0, 1, null, 0);
  70. foreach($query as $row) {
  71. $firstpost = $row;
  72. }
  73. $postsmerged = C::t('forum_post')->update_by_tid('tid:'.$_G['tid'], $othertid, array('tid' => $_G['tid']));
  74. updateattachtid('tid', array($othertid), $othertid, $_G['tid']);
  75. C::t('forum_thread')->delete_by_tid($othertid);
  76. C::t('forum_threadmod')->delete_by_tid($othertid);
  77. C::t('forum_post')->update_by_tid('tid:'.$_G['tid'], $_G['tid'], array('first' => 0, 'fid' => $_G['forum']['fid']));
  78. C::t('forum_post')->update('tid:'.$_G['tid'], $firstpost['pid'], array('first' => 1));
  79. $fieldarr = array(
  80. 'views' => $other['views'],
  81. 'replies' => $other['replies'],
  82. );
  83. C::t('forum_thread')->increase($_G['tid'], $fieldarr);
  84. $fieldarr = array(
  85. 'authorid' => $firstpost['authorid'],
  86. 'author' => $firstpost['author'],
  87. 'subject' => $firstpost['subject'],
  88. 'dateline' => $firstpost['dateline'],
  89. 'moderated' => 1,
  90. 'maxposition' => $other['maxposition'] + $thread['maxposition'],
  91. );
  92. C::t('forum_thread')->update($_G['tid'], $fieldarr);
  93. updateforumcount($other['fid']);
  94. updateforumcount($_G['fid']);
  95. $_G['forum']['threadcaches'] && deletethreadcaches($thread['tid']);
  96. $modpostsnum ++;
  97. $resultarray = array(
  98. 'redirect' => "forum.php?mod=forumdisplay&fid=$_G[fid]",
  99. 'reasonpm' => ($sendreasonpm ? array('data' => array($thread), 'var' => 'thread', 'item' => 'reason_merge', 'notictype' => 'post') : array()),
  100. 'reasonvar' => array('tid' => $thread['tid'], 'subject' => $thread['subject'], 'modaction' => $modaction, 'reason' => $reason),
  101. 'modtids' => $thread['tid'],
  102. 'modlog' => array($thread, $other)
  103. );
  104. }
  105. ?>