topicadmin_moderate.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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_moderate.php 36334 2017-01-03 01:32:35Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if(!empty($_G['tid'])) {
  12. $_GET['moderate'] = array($_G['tid']);
  13. }
  14. $allow_operation = array('delete', 'highlight', 'open', 'close', 'stick', 'digest', 'bump', 'down', 'recommend', 'type', 'move', 'recommend_group');
  15. $operations = empty($_GET['operations']) ? array() : $_GET['operations'];
  16. if($operations && $operations != array_intersect($operations, $allow_operation) || (!$_G['group']['allowdelpost'] && in_array('delete', $operations)) || (!$_G['group']['allowstickthread'] && in_array('stick', $operations))) {
  17. showmessage('admin_moderate_invalid');
  18. }
  19. $threadlist = $loglist = $posttablearr = $authors = array();
  20. $crimenum = $crimeauthor = '';
  21. $recommend_group_count = 0;
  22. $operation = getgpc('operation');
  23. loadcache('threadtableids');
  24. $threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
  25. if(!in_array(0, $threadtableids)) {
  26. $threadtableids = array_merge(array(0), $threadtableids);
  27. }
  28. if($_GET['moderate']) {
  29. foreach($threadtableids as $tableid) {
  30. foreach(C::t('forum_thread')->fetch_all_by_tid_fid_displayorder($_GET['moderate'], $_G['fid'], null, '', 0, $_G['tpp'], '', '', $tableid) as $thread) {
  31. if($thread['closed'] > 1 && $operation && !in_array($operation, array('delete', 'highlight', 'stick', 'digest', 'bump', 'down')) || $thread['displayorder'] < 0 && $thread['displayorder'] != -4) {
  32. if($operation == 'recommend_group') {
  33. $recommend_group_count ++;
  34. }
  35. continue;
  36. }
  37. $thread['lastposterenc'] = rawurlencode($thread['lastposter']);
  38. $thread['dblastpost'] = $thread['lastpost'];
  39. $thread['lastpost'] = dgmdate($thread['lastpost'], 'u');
  40. $posttablearr[$thread['posttableid'] ? $thread['posttableid'] : 0][] = $thread['tid'];
  41. $authors[$thread['authorid']] = 1;
  42. $threadlist[$thread['tid']] = $thread;
  43. $_G['tid'] = empty($_G['tid']) ? $thread['tid'] : $_G['tid'];
  44. }
  45. if(!empty($threadlist)) {
  46. break;
  47. }
  48. }
  49. }
  50. if(empty($threadlist)) {
  51. if($recommend_group_count) {
  52. showmessage('recommend_group_invalid');
  53. }
  54. showmessage('admin_moderate_invalid');
  55. }
  56. $authorcount = count(array_keys($authors));
  57. $modpostsnum = count($threadlist);
  58. $single = $modpostsnum == 1 ? TRUE : FALSE;
  59. $frommodcp = getgpc('frommodcp');
  60. switch($frommodcp) {
  61. case '1':
  62. $_G['referer'] = "forum.php?mod=modcp&action=thread&fid=$_G[fid]&op=thread&do=list";
  63. break;
  64. case '2':
  65. $_G['referer'] = "forum.php?mod=modcp&action=forum&op=recommend".(getgpc('show') ? "&show=getgpc('show')" : '')."&fid=$_G[fid]";
  66. break;
  67. default:
  68. if(in_array('delete', $operations) || in_array('move', $operations) && !strpos($_SERVER['HTTP_REFERER'], 'search.php?mod=forum')) {
  69. $_G['referer'] = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].(!empty($_GET['listextra']) ? '&'.rawurldecode($_GET['listextra']) : '');
  70. } else {
  71. $_G['referer'] = $_GET['redirect'];
  72. }
  73. break;
  74. }
  75. $optgroup = $_GET['optgroup'] = isset($_GET['optgroup']) ? intval($_GET['optgroup']) : 0;
  76. $expirationstick = getgpc('expirationstick');
  77. $defaultcheck = array();
  78. foreach ($allow_operation as $v) {
  79. $defaultcheck[$v] = '';
  80. }
  81. $defaultcheck[$operation] = 'checked="checked"';
  82. if(!submitcheck('modsubmit')) {
  83. $stickcheck = $closecheck = $digestcheck = array('', '', '', '', '');
  84. $expirationdigest = $expirationhighlight = $expirationclose = '';
  85. if($_GET['optgroup'] == 1 && $single) {
  86. empty($threadlist[$_G['tid']]['displayorder']) ? $stickcheck[0] ='selected="selected"' : $stickcheck[$threadlist[$_G['tid']]['displayorder']] = 'selected="selected"';
  87. empty($threadlist[$_G['tid']]['digest']) ? $digestcheck[0] = 'selected="selected"' : $digestcheck[$threadlist[$_G['tid']]['digest']] = 'selected="selected"';
  88. $string = sprintf('%02d', $threadlist[$_G['tid']]['highlight']);
  89. $stylestr = sprintf('%03b', $string[0]);
  90. for($i = 1; $i <= 3; $i++) {
  91. $stylecheck[$i] = $stylestr[$i - 1] ? 1 : 0;
  92. }
  93. $colorcheck = $string[1];
  94. $_G['forum']['modrecommend'] = is_array($_G['forum']['modrecommend']) ? $_G['forum']['modrecommend'] : array();
  95. $expirationstick = get_expiration($_G['tid'], 'EST');
  96. $expirationdigest = get_expiration($_G['tid'], 'EDI');
  97. $expirationhighlight = get_expiration($_G['tid'], 'EHL');
  98. } elseif($_GET['optgroup'] == 2 || $_GET['optgroup'] == 5) {
  99. require_once libfile('function/forumlist');
  100. $forumselect = forumselect(FALSE, 0, $threadlist[$_G['tid']]['fid'], $_G['adminid']==1 ? TRUE : FALSE);
  101. $typeselect = typeselect($single ? $threadlist[$_G['tid']]['typeid'] : 0);
  102. } elseif($_GET['optgroup'] == 4 && $single) {
  103. empty($threadlist[$_G['tid']]['closed']) ? $closecheck[0] = 'checked="checked"' : $closecheck[1] = 'checked="checked"';
  104. if($threadlist[$_G['tid']]['closed']) {
  105. $expirationclose = get_expiration($_G['tid'], 'ECL');
  106. }
  107. } elseif($_GET['optgroup'] == 3 && ($modpostsnum == 1 || $authorcount == 1)) {
  108. include_once libfile('function/member');
  109. $crimenum = crime('getcount', $threadlist[$_G['tid']]['authorid'], 'crime_delpost');
  110. $crimeauthor = $threadlist[$_G['tid']]['author'];
  111. }
  112. $imgattach = array();
  113. if(count($threadlist) == 1 && $operation == 'recommend') {
  114. $imgattach = C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'tid', $_G['tid'], '', array(1, -1));
  115. $oldthread = C::t('forum_forumrecommend')->fetch($_G['tid']);
  116. if($oldthread) {
  117. $threadlist[$_G['tid']]['subject'] = $oldthread['subject'];
  118. $selectposition[$oldthread['position']] = ' selected="selected"';
  119. $selectattach = $oldthread['aid'];
  120. } else {
  121. $selectattach = $imgattach[0]['aid'];
  122. $selectposition[0] = ' selected="selected"';
  123. }
  124. }
  125. include template('forum/topicadmin');
  126. } else {
  127. $tidsarr = array_keys($threadlist);
  128. $moderatetids = dimplode($tidsarr);
  129. $reason = checkreasonpm();
  130. $stampstatus = 0;
  131. $stampaction = 'SPA';
  132. if(empty($operations)) {
  133. showmessage('admin_nonexistence');
  134. } else {
  135. $images = array();
  136. foreach($operations as $operation) {
  137. $updatemodlog = TRUE;
  138. if($operation == 'stick') {
  139. $sticklevel = intval($_GET['sticklevel']);
  140. if($sticklevel < 0 || $sticklevel > 3 || $sticklevel > $_G['group']['allowstickthread']) {
  141. showmessage('no_privilege_stickthread');
  142. }
  143. $expiration = checkexpiration($_GET['expirationstick'], $operation);
  144. $expirationstick = $sticklevel ? $_GET['expirationstick'] : 0;
  145. $forumstickthreads = $_G['setting']['forumstickthreads'];
  146. $forumstickthreads = isset($forumstickthreads) ? dunserialize($forumstickthreads) : array();
  147. C::t('forum_thread')->update($tidsarr, array('displayorder'=>$sticklevel, 'moderated'=>1), true);
  148. $delkeys = array_keys($threadlist);
  149. foreach($delkeys as $k) {
  150. unset($forumstickthreads[$k]);
  151. }
  152. C::t('common_setting')->update('forumstickthreads', $forumstickthreads);
  153. $stickmodify = 0;
  154. foreach($threadlist as $thread) {
  155. $stickmodify = (in_array($thread['displayorder'], array(2, 3)) || in_array($sticklevel, array(2, 3))) && $sticklevel != $thread['displayorder'] ? 1 : $stickmodify;
  156. C::t('common_member_secwhite')->add($thread['authorid']);
  157. }
  158. if($_G['setting']['globalstick'] && $stickmodify) {
  159. require_once libfile('function/cache');
  160. updatecache('globalstick');
  161. }
  162. $modaction = $sticklevel ? ($expiration ? 'EST' : 'STK') : 'UST';
  163. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('STK', 'UST', 'EST', 'UES'), array('status' => 0));
  164. C::t('forum_threadhidelog')->delete_by_tid($tidsarr);
  165. if(!$sticklevel) {
  166. $stampaction = 'SPD';
  167. }
  168. $stampstatus = 1;
  169. } elseif($operation == 'highlight') {
  170. if(!$_G['group']['allowhighlightthread']) {
  171. showmessage('no_privilege_highlightthread');
  172. }
  173. $highlight_style = $_GET['highlight_style'];
  174. $highlight_color = $_GET['highlight_color'];
  175. $highlight_bgcolor = $_GET['highlight_bgcolor'];
  176. $expiration = checkexpiration($_GET['expirationhighlight'], $operation);
  177. $stylebin = '';
  178. for($i = 1; $i <= 3; $i++) {
  179. $stylebin .= empty($highlight_style[$i]) ? '0' : '1';
  180. }
  181. $highlight_style = bindec($stylebin);
  182. if($highlight_style < 0 || $highlight_style > 7 || $highlight_color < 0 || $highlight_color > 8) {
  183. showmessage('parameters_error ');
  184. }
  185. $bgcolor = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9#]/", '', $_GET['highlight_bgcolor']));
  186. C::t('forum_thread')->update($tidsarr, array('highlight'=>$highlight_style.$highlight_color, 'moderated'=>1, 'bgcolor' => $bgcolor), true);
  187. C::t('forum_forumrecommend')->update($tidsarr, array('highlight' => $highlight_style.$highlight_color));
  188. C::t('forum_threadhidelog')->delete_by_tid($tidsarr);
  189. $modaction = ($highlight_style + $highlight_color) ? ($expiration ? 'EHL' : 'HLT') : 'UHL';
  190. $expiration = $modaction == 'UHL' ? 0 : $expiration;
  191. foreach($threadlist as $thread) {
  192. C::t('common_member_secwhite')->add($thread['authorid']);
  193. }
  194. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('HLT', 'UHL', 'EHL', 'UEH'), array('status' => 0));
  195. } elseif($operation == 'digest') {
  196. $digestlevel = intval($_GET['digestlevel']);
  197. if($digestlevel < 0 || $digestlevel > 3 || $digestlevel > $_G['group']['allowdigestthread']) {
  198. showmessage('no_privilege_digestthread');
  199. }
  200. $expiration = checkexpiration($_GET['expirationdigest'], $operation);
  201. $expirationdigest = $digestlevel ? $expirationdigest : 0;
  202. C::t('forum_thread')->update($tidsarr, array('digest'=>$digestlevel, 'moderated'=>1), true);
  203. C::t('forum_threadhidelog')->delete_by_tid($tidsarr);
  204. foreach($threadlist as $thread) {
  205. if($thread['digest'] != $digestlevel) {
  206. if($digestlevel == $thread['digest']) continue;
  207. $extsql = array();
  208. if($digestlevel > 0 && $thread['digest'] == 0) {
  209. $extsql = array('digestposts' => 1);
  210. }
  211. if($digestlevel == 0 && $thread['digest'] > 0) {
  212. $extsql = array('digestposts' => -1);
  213. }
  214. if($digestlevel == 0) {
  215. $stampaction = 'SPD';
  216. }
  217. updatecreditbyaction('digest', $thread['authorid'], $extsql, '', $digestlevel - $thread['digest']);
  218. C::t('common_member_secwhite')->add($thread['authorid']);
  219. }
  220. }
  221. $modaction = $digestlevel ? ($expiration ? 'EDI' : 'DIG') : 'UDG';
  222. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('DIG', 'UDI', 'EDI', 'UED'), array('status' => 0));
  223. $stampstatus = 2;
  224. } elseif($operation == 'recommend') {
  225. if(!$_G['group']['allowrecommendthread']) {
  226. showmessage('no_privilege_recommendthread');
  227. }
  228. $isrecommend = $_GET['isrecommend'];
  229. $modrecommend = !empty($_G['forum']['modrecommend']) ? $_G['forum']['modrecommend'] : array();
  230. $imgw = $modrecommend['imagewidth'] ? intval($modrecommend['imagewidth']) : 200;
  231. $imgh = $modrecommend['imageheight'] ? intval($modrecommend['imageheight']) : 150;
  232. $expiration = checkexpiration($_GET['expirationrecommend'], $operation);
  233. C::t('forum_thread')->update($tidsarr, array('moderated'=>1), true);
  234. $modaction = $isrecommend ? 'REC' : 'URE';
  235. $thread = daddslashes($thread, 1);
  236. $selectattach = $_GET['selectattach'];
  237. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('REC'), array('status' => 0));
  238. if($isrecommend) {
  239. C::t('forum_threadhidelog')->delete_by_tid($tidsarr);
  240. $oldrecommendlist = $addthread = array();
  241. foreach(C::t('forum_forumrecommend')->fetch_all($tidsarr) as $row) {
  242. $oldrecommendlist[$row['tid']] = $row;
  243. }
  244. foreach($threadlist as $thread) {
  245. if(count($threadlist) > 1) {
  246. if($oldrecommendlist[$thread['tid']]) {
  247. $oldthread = $oldrecommendlist[$thread['tid']];
  248. $reducetitle = $oldthread['subject'];
  249. $selectattach = $oldthread['aid'];
  250. $typeid = $oldthread['typeid'];
  251. $position = $oldthread['position'];
  252. } else {
  253. $reducetitle = $thread['subject'];
  254. $typeid = 0;
  255. $position = 0;
  256. }
  257. } else {
  258. if(empty($_GET['reducetitle'])) {
  259. $reducetitle = $thread['subject'];
  260. } else {
  261. $reducetitle = $_GET['reducetitle'];
  262. }
  263. $typeid = $selectattach ? 1 : 0;
  264. empty($_GET['position']) && $position = 0;
  265. }
  266. if($selectattach) {
  267. $key = md5($selectattach.'|'.$imgw.'|'.$imgh);
  268. $filename = $selectattach."\t".$imgw."\t".$imgh."\t".$key;
  269. } else {
  270. $selectattach = 0;
  271. $filename = '';
  272. }
  273. $addthread[] = array(
  274. 'fid' => $thread['fid'],
  275. 'tid' => $thread['tid'],
  276. 'typeid' => $typeid,
  277. 'displayorder' => 0,
  278. 'subject' => $reducetitle,
  279. 'author' => $thread['author'],
  280. 'authorid' => $thread['authorid'],
  281. 'moderatorid' => $_G['uid'],
  282. 'expiration' => $expiration,
  283. 'position' => $position,
  284. 'aid' => $selectattach,
  285. 'filename' => $filename,
  286. 'highlight' => $thread['highlight']
  287. );
  288. $reducetitle = '';
  289. }
  290. if($addthread) {
  291. foreach($addthread as $row) {
  292. C::t('forum_forumrecommend')->insert($row, false, true);
  293. }
  294. }
  295. } else {
  296. C::t('forum_forumrecommend')->delete($tidsarr);
  297. $stampaction = 'SPD';
  298. }
  299. $stampstatus = 3;
  300. } elseif($operation == 'bump') {
  301. if(!$_G['group']['allowbumpthread']) {
  302. showmessage('no_privilege_bumpthread');
  303. }
  304. $modaction = 'BMP';
  305. $thread = $threadlist;
  306. $thread = array_pop($thread);
  307. $expiration = checkexpiration($_GET['expirationbump'], $operation);
  308. if(!$expiration) {
  309. $expiration = $_G['timestamp'];
  310. }
  311. C::t('forum_thread')->update($tidsarr, array('lastpost'=>$expiration, 'moderated'=>1), true);
  312. C::t('forum_forum')->update($_G['fid'], array('lastpost' => "$thread[tid]\t$thread[subject]\t$expiration\t$thread[lastposter]"));
  313. $_G['forum']['threadcaches'] && deletethreadcaches($thread['tid']);
  314. } elseif($operation == 'down') {
  315. if(!$_G['group']['allowbumpthread']) {
  316. showmessage('no_privilege_downthread');
  317. }
  318. $modaction = 'DWN';
  319. $downtime = TIMESTAMP - 86400 * 730;
  320. C::t('forum_thread')->update($tidsarr, array('lastpost'=>$downtime, 'moderated'=>1), true);
  321. $_G['forum']['threadcaches'] && deletethreadcaches($thread['tid']);
  322. } elseif($operation == 'delete') {
  323. if(!$_G['group']['allowdelpost']) {
  324. showmessage('no_privilege_delpost');
  325. }
  326. loadcache('threadtableids');
  327. $stickmodify = 0;
  328. $deleteredirect = $remarkclosed = array();
  329. foreach($threadlist as $thread) {
  330. if($thread['digest']) {
  331. updatecreditbyaction('digest', $thread['authorid'], array('digestposts' => -1), '', -$thread['digest']);
  332. }
  333. if(in_array($thread['displayorder'], array(2, 3))) {
  334. $stickmodify = 1;
  335. }
  336. if($_G['forum']['status'] == 3 && $thread['closed'] > 1) {
  337. $deleteredirect[] = $thread['closed'];
  338. }
  339. if($thread['isgroup'] == 1 && $thread['closed'] > 1) {
  340. $remarkclosed[] = $thread['closed'];
  341. }
  342. }
  343. $modaction = 'DEL';
  344. require_once libfile('function/delete');
  345. $tids = array_keys($threadlist);
  346. if($_G['forum']['recyclebin']) {
  347. deletethread($tids, true, true, true);
  348. manage_addnotify('verifyrecycle', $modpostsnum);
  349. } else {
  350. deletethread($tids, true, true);
  351. $updatemodlog = FALSE;
  352. }
  353. if($_G['group']['allowbanuser'] && ($_GET['banuser'] || $_GET['userdelpost']) && $_G['deleteauthorids']) {
  354. $members = C::t('common_member')->fetch_all($_G['deleteauthorids']);
  355. $banuins = array();
  356. foreach($members as $member) {
  357. if(($_G['cache']['usergroups'][$member['groupid']]['type'] == 'system' &&
  358. in_array($member['groupid'], array(1, 2, 3, 6, 7, 8))) || $_G['cache']['usergroups'][$member['groupid']]['type'] == 'special') {
  359. continue;
  360. }
  361. $banuins[$member['uid']] = $member['uid'];
  362. }
  363. if($banuins) {
  364. if($_GET['banuser']) {
  365. C::t('common_member')->update($banuins, array('groupid' => 4));
  366. }
  367. if($_GET['userdelpost']) {
  368. deletememberpost($banuins);
  369. }
  370. }
  371. }
  372. $forumstickthreads = $_G['setting']['forumstickthreads'];
  373. $forumstickthreads = !empty($forumstickthreads) ? dunserialize($forumstickthreads) : array();
  374. $delkeys = array_keys($threadlist);
  375. foreach($delkeys as $k) {
  376. unset($forumstickthreads[$k]);
  377. }
  378. C::t('common_setting')->update('forumstickthreads', $forumstickthreads);
  379. C::t('forum_forum_threadtable')->delete_none_threads();
  380. if(!empty($deleteredirect)) {
  381. deletethread($deleteredirect);
  382. }
  383. if(!empty($remarkclosed)) {
  384. C::t('forum_thread')->update($remarkclosed, array('closed'=>0));
  385. }
  386. if($_G['setting']['globalstick'] && $stickmodify) {
  387. require_once libfile('function/cache');
  388. updatecache('globalstick');
  389. }
  390. updateforumcount($_G['fid']);
  391. if($_GET['crimerecord']) {
  392. include_once libfile('function/member');
  393. foreach($threadlist as $thread) {
  394. crime('recordaction', $thread['authorid'], 'crime_delpost', lang('forum/misc', 'crime_postreason', array('reason' => $reason, 'tid' => $thread['tid'], 'pid' => 0)));
  395. }
  396. }
  397. } elseif($operation == 'close') {
  398. if(!$_G['group']['allowclosethread']) {
  399. showmessage('no_privilege_closethread');
  400. }
  401. $expiration = checkexpiration($_GET['expirationclose'], $operation);
  402. $modaction = $expiration ? 'ECL' : 'CLS';
  403. C::t('forum_thread')->update($tidsarr, array('closed'=>1, 'moderated'=>1), true);
  404. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('CLS','OPN','ECL','UCL','EOP','UEO'), array('status' => 0));
  405. } elseif($operation == 'open') {
  406. if(!$_G['group']['allowclosethread']) {
  407. showmessage('no_privilege_openthread');
  408. }
  409. $expiration = checkexpiration($_GET['expirationclose'], $operation);
  410. $modaction = $expiration ? 'EOP' : 'OPN';
  411. C::t('forum_thread')->update($tidsarr, array('closed'=>0, 'moderated'=>1), true);
  412. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('CLS','OPN','ECL','UCL','EOP','UEO'), array('status' => 0));
  413. } elseif($operation == 'move') {
  414. if(!$_G['group']['allowmovethread']) {
  415. showmessage('no_privilege_movethread');
  416. }
  417. $moveto = $_GET['moveto'];
  418. $toforum = C::t('forum_forum')->fetch_info_by_fid($moveto);
  419. if(!$toforum || ($_G['adminid'] != 1 && $toforum['status'] != 1) || $toforum['type'] == 'group') {
  420. showmessage('admin_move_invalid');
  421. } elseif($_G['fid'] == $toforum['fid']) {
  422. continue;
  423. } else {
  424. $moveto = $toforum['fid'];
  425. $modnewthreads = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 1) && $toforum['modnewposts'] ? 1 : 0;
  426. $modnewreplies = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 2) && $toforum['modnewposts'] ? 1 : 0;
  427. if($modnewthreads || $modnewreplies) {
  428. showmessage('admin_move_have_mod');
  429. }
  430. }
  431. if($_G['adminid'] == 3) {
  432. $priv = C::t('forum_forumfield')->check_moderator_for_uid($moveto, $_G['uid'], $_G['member']['accessmasks']);
  433. if((($priv['postperm'] && !in_array($_G['groupid'], explode("\t", $priv['postperm']))) || ($_G['member']['accessmasks'] && ($priv['allowview'] || $priv['allowreply'] || $priv['allowgetattach'] || $priv['allowpostattach']) && !$priv['allowpost'])) && !$priv['istargetmod']) {
  434. showmessage('admin_move_nopermission');
  435. }
  436. }
  437. $moderate = array();
  438. $stickmodify = 0;
  439. $toforumallowspecial = array(
  440. 1 => $toforum['allowpostspecial'] & 1,
  441. 2 => $toforum['allowpostspecial'] & 2,
  442. 3 => isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]) && ($toforum['allowpostspecial'] & 4),
  443. 4 => $toforum['allowpostspecial'] & 8,
  444. 5 => $toforum['allowpostspecial'] & 16,
  445. 127 => $_G['setting']['threadplugins'] ? dunserialize($toforum['threadplugin']) : array(),
  446. );
  447. foreach($threadlist as $tid => $thread) {
  448. $allowmove = 0;
  449. if(!$thread['special']) {
  450. $allowmove = 1;
  451. } else {
  452. if($thread['special'] != 127) {
  453. $allowmove = $toforum['allowpostspecial'] ? $toforumallowspecial[$thread['special']] : 0;
  454. } else {
  455. if($toforumallowspecial[127]) {
  456. $posttable = getposttablebytid($thread['tid']);
  457. $message = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid']);
  458. $message = $message['message'];
  459. $sppos = strrpos($message, chr(0).chr(0).chr(0));
  460. $specialextra = substr($message, $sppos + 3);
  461. $allowmove = in_array($specialextra, $toforumallowspecial[127]);
  462. } else {
  463. $allowmove = 0;
  464. }
  465. }
  466. }
  467. if($allowmove) {
  468. $moderate[] = $tid;
  469. if(in_array($thread['displayorder'], array(2, 3))) {
  470. $stickmodify = 1;
  471. }
  472. if($_GET['type'] == 'redirect') {
  473. $insertdata = array(
  474. 'fid' => $thread['fid'],
  475. 'readperm' => $thread['readperm'],
  476. 'author' => $thread['author'],
  477. 'authorid' => $thread['authorid'],
  478. 'subject' => $thread['subject'],
  479. 'dateline' => $thread['dateline'],
  480. 'lastpost' => $thread['dblastpost'],
  481. 'lastposter' => $thread['lastposter'],
  482. 'views' => 0,
  483. 'replies' => 0,
  484. 'displayorder' => 0,
  485. 'digest' => 0,
  486. 'closed' => $thread['tid'],
  487. 'special' => 0,
  488. 'attachment' => 0,
  489. 'typeid' => $_GET['threadtypeid']
  490. );
  491. $newtid = C::t('forum_thread')->insert($insertdata, true);
  492. if($newtid) {
  493. C::t('forum_threadclosed')->insert(array('tid' => $thread['tid'], 'redirect' => $newtid), true, true);
  494. }
  495. }
  496. }
  497. }
  498. if(!$moderatetids = implode(',', $moderate)) {
  499. showmessage('admin_moderate_invalid');
  500. }
  501. $fieldarr = array(
  502. 'fid' => $moveto,
  503. 'isgroup' => 0,
  504. 'typeid' => $_GET['threadtypeid'],
  505. 'moderated' => 1
  506. );
  507. if($_G['adminid'] == 3) {
  508. $fieldarr['displayorder'] = 0;
  509. }
  510. C::t('forum_thread')->update($tidsarr, $fieldarr, true);
  511. C::t('forum_forumrecommend')->update($tidsarr, array('fid' => $moveto));
  512. loadcache('posttableids');
  513. $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
  514. foreach($posttableids as $id) {
  515. C::t('forum_post')->update_by_tid($id, $tidsarr, array('fid' => $moveto));
  516. }
  517. $typeoptionvars = C::t('forum_typeoptionvar')->fetch_all_by_tid_optionid($tidsarr);
  518. foreach($typeoptionvars as $typeoptionvar) {
  519. C::t('forum_typeoptionvar')->update_by_tid($typeoptionvar['tid'], array('fid' => $moveto));
  520. C::t('forum_optionvalue')->update($typeoptionvar['sortid'], $typeoptionvar['tid'], $_G['fid'], "fid='$moveto'");
  521. }
  522. if($_G['setting']['globalstick'] && $stickmodify) {
  523. require_once libfile('function/cache');
  524. updatecache('globalstick');
  525. }
  526. $modaction = 'MOV';
  527. $_G['toforum'] = $toforum;
  528. updateforumcount($moveto);
  529. updateforumcount($_G['fid']);
  530. } elseif($operation == 'type') {
  531. if(!$_G['group']['allowedittypethread']) {
  532. showmessage('no_privilege_edittypethread');
  533. }
  534. if(!isset($_G['forum']['threadtypes']['types'][$_GET['typeid']]) && ($_GET['typeid'] != 0 || $_G['forum']['threadtypes']['required'])) {
  535. showmessage('admin_type_invalid');
  536. }
  537. C::t('forum_thread')->update($tidsarr, array('typeid'=>$_GET['typeid'], 'moderated'=>1), true);
  538. $modaction = 'TYP';
  539. } elseif($operation == 'recommend_group') {
  540. if($_G['forum']['status'] != 3 || !in_array($_G['adminid'], array(1, 2))) {
  541. showmessage('undefined_action');
  542. }
  543. $moveto = $_GET['moveto'];
  544. $toforum = C::t('forum_forum')->fetch_info_by_fid($moveto);
  545. if(!$toforum || $toforum['status'] != 1 || $toforum['type'] == 'group') {
  546. showmessage('admin_move_invalid');
  547. } elseif($_G['fid'] == $toforum['fid']) {
  548. continue;
  549. }
  550. $moderate = array();
  551. $toforumallowspecial = array(
  552. 1 => $toforum['allowpostspecial'] & 1,
  553. 2 => $toforum['allowpostspecial'] & 2,
  554. 3 => isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]) && ($toforum['allowpostspecial'] & 4),
  555. 4 => $toforum['allowpostspecial'] & 8,
  556. 5 => $toforum['allowpostspecial'] & 16,
  557. 127 => $_G['setting']['threadplugins'] ? dunserialize($toforum['threadplugin']) : array(),
  558. );
  559. foreach($threadlist as $tid => $thread) {
  560. $allowmove = 0;
  561. if($thread['closed']) {
  562. continue;
  563. }
  564. if(!$thread['special']) {
  565. $allowmove = 1;
  566. } else {
  567. if($thread['special'] != 127) {
  568. $allowmove = $toforum['allowpostspecial'] ? $toforumallowspecial[$thread['special']] : 0;
  569. } else {
  570. if($toforumallowspecial[127]) {
  571. $posttable = getposttablebytid($thread['tid']);
  572. $message = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid']);
  573. $message = $message['message'];
  574. $sppos = strrpos($message, chr(0).chr(0).chr(0));
  575. $specialextra = substr($message, $sppos + 3);
  576. $allowmove = in_array($specialextra, $toforumallowspecial[127]);
  577. } else {
  578. $allowmove = 0;
  579. }
  580. }
  581. }
  582. if($allowmove) {
  583. $moderate[] = $tid;
  584. $newthread = array(
  585. 'fid' => $moveto,
  586. 'readperm' => $thread['readperm'],
  587. 'author' => $thread['author'],
  588. 'authorid' => $thread['authorid'],
  589. 'subject' => $thread['subject'],
  590. 'dateline' => $thread['dateline'],
  591. 'lastpost' => TIMESTAMP,
  592. 'lastposter' => $thread['lastposter'],
  593. 'views' => $thread['views'],
  594. 'replies' => $thread['replies'],
  595. 'displayorder' => 0,
  596. 'digest' => $thread['digest'],
  597. 'closed' => $thread['tid'],
  598. 'special' => $thread['special'],
  599. 'attachment' => $thread['attachment'],
  600. 'isgroup' => $thread['isgroup']
  601. );
  602. $newtid = C::t('forum_thread')->insert($newthread, true);
  603. C::t('forum_thread')->update($thread['tid'], array('closed'=>$newtid, 'moderated'=>1), true);
  604. }
  605. }
  606. if(!$moderatetids = implode(',', $moderate)) {
  607. showmessage('admin_succeed', $_G['referer']);
  608. }
  609. $modaction = 'REG';
  610. }
  611. if($updatemodlog) {
  612. if($operation != 'delete') {
  613. updatemodlog($moderatetids, $modaction, $expiration);
  614. } else {
  615. updatemodlog($moderatetids, $modaction, $expiration, 0, $reason);
  616. }
  617. }
  618. updatemodworks($modaction, $modpostsnum);
  619. foreach($threadlist as $thread) {
  620. modlog($thread, $modaction);
  621. }
  622. if($sendreasonpm) {
  623. $modactioncode = lang('forum/modaction');
  624. $modtype = $modaction;
  625. $modaction = $modactioncode[$modaction];
  626. foreach($threadlist as $thread) {
  627. if($operation == 'move') {
  628. sendreasonpm($thread, 'reason_move', array('tid' => $thread['tid'], 'subject' => $thread['subject'], 'modaction' => $modaction, 'reason' => $reason, 'tofid' => $toforum['fid'], 'toname' => $toforum['name'], 'from_id' => 0, 'from_idtype' => 'movethread'), 'post');
  629. } else {
  630. sendreasonpm($thread, 'reason_moderate', array('tid' => $thread['tid'], 'subject' => $thread['subject'], 'modaction' => $modaction, 'reason' => $reason, 'from_id' => 0, 'from_idtype' => 'moderate_'.$modtype), 'post');
  631. }
  632. }
  633. }
  634. if($stampstatus) {
  635. set_stamp($stampstatus, $stampaction, $threadlist, $expiration);
  636. }
  637. }
  638. showmessage('admin_succeed', $_G['referer']);
  639. }
  640. }
  641. function checkexpiration($expiration, $operation) {
  642. global $_G;
  643. if(!empty($expiration) && in_array($operation, array('recommend', 'stick', 'digest', 'highlight', 'close', 'open', 'bump'))) {
  644. $expiration = strtotime($expiration) - $_G['setting']['timeoffset'] * 3600 + date('Z');
  645. if(dgmdate($expiration, 'Ymd') <= dgmdate(TIMESTAMP, 'Ymd') || ($expiration > TIMESTAMP + 86400 * 180)) {
  646. showmessage('admin_expiration_invalid', '', array('min'=>dgmdate(TIMESTAMP, 'Y-m-d'), 'max'=>dgmdate(TIMESTAMP + 86400 * 180, 'Y-m-d')));
  647. }
  648. } else {
  649. $expiration = 0;
  650. }
  651. return $expiration;
  652. }
  653. function set_stamp($typeid, $stampaction, &$threadlist, $expiration) {
  654. global $_G;
  655. $moderatetids = array_keys($threadlist);
  656. if(empty($threadlist)) {
  657. return false;
  658. }
  659. if(array_key_exists($typeid, $_G['cache']['stamptypeid'])) {
  660. if($stampaction == 'SPD') {
  661. C::t('forum_thread')->update($moderatetids, array('stamp'=>-1), true);
  662. } else {
  663. C::t('forum_thread')->update($moderatetids, array('stamp'=>$_G['cache']['stamptypeid'][$typeid]), true);
  664. }
  665. !empty($moderatetids) && updatemodlog($moderatetids, $stampaction, $expiration, 0, '', $_G['cache']['stamptypeid'][$typeid]);
  666. }
  667. }
  668. function get_expiration($tid, $action) {
  669. $tid = intval($tid);
  670. if(empty($tid) || empty($action)) {
  671. return '';
  672. }
  673. $row = C::t('forum_threadmod')->fetch_by_tid_action_status($tid, $action);
  674. return $row['expiration'] ? date('Y-m-d H:i', $row['expiration']) : '';
  675. }
  676. ?>