/source/include/topicadmin/topicadmin_moderate.php

https://github.com/jinbo51/DiscuzX · PHP · 721 lines · 642 code · 73 blank · 6 comment · 226 complexity · e16303eacf9c072349aac6d9987ba0a0 MD5 · raw file

  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 31971 2012-10-29 02:54:20Z monkey $
  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. }
  157. if($_G['setting']['globalstick'] && $stickmodify) {
  158. require_once libfile('function/cache');
  159. updatecache('globalstick');
  160. }
  161. $modaction = $sticklevel ? ($expiration ? 'EST' : 'STK') : 'UST';
  162. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('STK', 'UST', 'EST', 'UES'), array('status' => 0));
  163. if(!$sticklevel) {
  164. $stampaction = 'SPD';
  165. }
  166. $stampstatus = 1;
  167. } elseif($operation == 'highlight') {
  168. if(!$_G['group']['allowhighlightthread']) {
  169. showmessage('no_privilege_highlightthread');
  170. }
  171. $highlight_style = $_GET['highlight_style'];
  172. $highlight_color = $_GET['highlight_color'];
  173. $highlight_bgcolor = $_GET['highlight_bgcolor'];
  174. $expiration = checkexpiration($_GET['expirationhighlight'], $operation);
  175. $stylebin = '';
  176. for($i = 1; $i <= 3; $i++) {
  177. $stylebin .= empty($highlight_style[$i]) ? '0' : '1';
  178. }
  179. $highlight_style = bindec($stylebin);
  180. if($highlight_style < 0 || $highlight_style > 7 || $highlight_color < 0 || $highlight_color > 8) {
  181. showmessage('parameters_error ');
  182. }
  183. $bgcolor = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9#]/", '', $_GET['highlight_bgcolor']));
  184. C::t('forum_thread')->update($tidsarr, array('highlight'=>$highlight_style.$highlight_color, 'moderated'=>1, 'bgcolor' => $bgcolor), true);
  185. C::t('forum_forumrecommend')->update($tidsarr, array('highlight' => $highlight_style.$highlight_color));
  186. $modaction = ($highlight_style + $highlight_color) ? ($expiration ? 'EHL' : 'HLT') : 'UHL';
  187. $expiration = $modaction == 'UHL' ? 0 : $expiration;
  188. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('HLT', 'UHL', 'EHL', 'UEH'), array('status' => 0));
  189. } elseif($operation == 'digest') {
  190. $digestlevel = intval($_GET['digestlevel']);
  191. if($digestlevel < 0 || $digestlevel > 3 || $digestlevel > $_G['group']['allowdigestthread']) {
  192. showmessage('no_privilege_digestthread');
  193. }
  194. $expiration = checkexpiration($_GET['expirationdigest'], $operation);
  195. $expirationdigest = $digestlevel ? $expirationdigest : 0;
  196. C::t('forum_thread')->update($tidsarr, array('digest'=>$digestlevel, 'moderated'=>1), true);
  197. foreach($threadlist as $thread) {
  198. if($thread['digest'] != $digestlevel) {
  199. if($digestlevel == $thread['digest']) continue;
  200. $extsql = array();
  201. if($digestlevel > 0 && $thread['digest'] == 0) {
  202. $extsql = array('digestposts' => 1);
  203. }
  204. if($digestlevel == 0 && $thread['digest'] > 0) {
  205. $extsql = array('digestposts' => -1);
  206. }
  207. if($digestlevel == 0) {
  208. $stampaction = 'SPD';
  209. }
  210. updatecreditbyaction('digest', $thread['authorid'], $extsql, '', $digestlevel - $thread['digest']);
  211. }
  212. }
  213. $modaction = $digestlevel ? ($expiration ? 'EDI' : 'DIG') : 'UDG';
  214. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('DIG', 'UDI', 'EDI', 'UED'), array('status' => 0));
  215. $stampstatus = 2;
  216. } elseif($operation == 'recommend') {
  217. if(!$_G['group']['allowrecommendthread']) {
  218. showmessage('no_privilege_recommendthread');
  219. }
  220. $isrecommend = $_GET['isrecommend'];
  221. $modrecommend = !empty($_G['forum']['modrecommend']) ? $_G['forum']['modrecommend'] : array();
  222. $imgw = $modrecommend['imagewidth'] ? intval($modrecommend['imagewidth']) : 200;
  223. $imgh = $modrecommend['imageheight'] ? intval($modrecommend['imageheight']) : 150;
  224. $expiration = checkexpiration($_GET['expirationrecommend'], $operation);
  225. C::t('forum_thread')->update($tidsarr, array('moderated'=>1), true);
  226. $modaction = $isrecommend ? 'REC' : 'URE';
  227. $thread = daddslashes($thread, 1);
  228. $selectattach = $_GET['selectattach'];
  229. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('REC'), array('status' => 0));
  230. if($isrecommend) {
  231. $oldrecommendlist = $addthread = array();
  232. foreach(C::t('forum_forumrecommend')->fetch_all($tidsarr) as $row) {
  233. $oldrecommendlist[$row['tid']] = $row;
  234. }
  235. foreach($threadlist as $thread) {
  236. if(count($threadlist) > 1) {
  237. if($oldrecommendlist[$thread['tid']]) {
  238. $oldthread = $oldrecommendlist[$thread['tid']];
  239. $reducetitle = $oldthread['subject'];
  240. $selectattach = $oldthread['aid'];
  241. $typeid = $oldthread['typeid'];
  242. $position = $oldthread['position'];
  243. } else {
  244. $reducetitle = $thread['subject'];
  245. $typeid = 0;
  246. $position = 0;
  247. }
  248. } else {
  249. if(empty($_GET['reducetitle'])) {
  250. $reducetitle = $thread['subject'];
  251. } else {
  252. $reducetitle = $_GET['reducetitle'];
  253. }
  254. $typeid = $selectattach ? 1 : 0;
  255. empty($_GET['position']) && $position = 0;
  256. }
  257. if($selectattach) {
  258. $key = md5($selectattach.'|'.$imgw.'|'.$imgh);
  259. $filename = $selectattach."\t".$imgw."\t".$imgh."\t".$key;
  260. } else {
  261. $selectattach = 0;
  262. $filename = '';
  263. }
  264. $addthread[] = array(
  265. 'fid' => $thread['fid'],
  266. 'tid' => $thread['tid'],
  267. 'typeid' => $typeid,
  268. 'displayorder' => 0,
  269. 'subject' => $reducetitle,
  270. 'author' => $thread['author'],
  271. 'authorid' => $thread['authorid'],
  272. 'moderatorid' => $_G['uid'],
  273. 'expiration' => $expiration,
  274. 'position' => $position,
  275. 'aid' => $selectattach,
  276. 'filename' => $filename,
  277. 'highlight' => $thread['highlight']
  278. );
  279. $reducetitle = '';
  280. }
  281. if($addthread) {
  282. foreach($addthread as $row) {
  283. C::t('forum_forumrecommend')->insert($row, false, true);
  284. }
  285. }
  286. } else {
  287. C::t('forum_forumrecommend')->delete($tidsarr);
  288. $stampaction = 'SPD';
  289. }
  290. $stampstatus = 3;
  291. } elseif($operation == 'bump') {
  292. if(!$_G['group']['allowbumpthread']) {
  293. showmessage('no_privilege_bumpthread');
  294. }
  295. $modaction = 'BMP';
  296. $thread = $threadlist;
  297. $thread = array_pop($thread);
  298. $expiration = checkexpiration($_GET['expirationbump'], $operation);
  299. if(!$expiration) {
  300. $expiration = $_G['timestamp'];
  301. }
  302. C::t('forum_thread')->update($tidsarr, array('lastpost'=>$expiration, 'moderated'=>1), true);
  303. C::t('forum_forum')->update($_G['fid'], array('lastpost' => "$thread[tid]\t$thread[subject]\t$expiration\t$thread[lastposter]"));
  304. $_G['forum']['threadcaches'] && deletethreadcaches($thread['tid']);
  305. } elseif($operation == 'down') {
  306. if(!$_G['group']['allowbumpthread']) {
  307. showmessage('no_privilege_downthread');
  308. }
  309. $modaction = 'DWN';
  310. $downtime = TIMESTAMP - 86400 * 730;
  311. C::t('forum_thread')->update($tidsarr, array('lastpost'=>$downtime, 'moderated'=>1), true);
  312. $_G['forum']['threadcaches'] && deletethreadcaches($thread['tid']);
  313. } elseif($operation == 'delete') {
  314. if(!$_G['group']['allowdelpost']) {
  315. showmessage('no_privilege_delpost');
  316. }
  317. loadcache('threadtableids');
  318. $stickmodify = 0;
  319. $deleteredirect = $remarkclosed = array();
  320. foreach($threadlist as $thread) {
  321. if($thread['digest']) {
  322. updatecreditbyaction('digest', $thread['authorid'], array('digestposts' => -1), '', -$thread['digest']);
  323. }
  324. if(in_array($thread['displayorder'], array(2, 3))) {
  325. $stickmodify = 1;
  326. }
  327. if($_G['forum']['status'] == 3 && $thread['closed'] > 1) {
  328. $deleteredirect[] = $thread['closed'];
  329. }
  330. if($thread['isgroup'] == 1 && $thread['closed'] > 1) {
  331. $remarkclosed[] = $thread['closed'];
  332. }
  333. }
  334. $modaction = 'DEL';
  335. require_once libfile('function/delete');
  336. $tids = array_keys($threadlist);
  337. if($_G['forum']['recyclebin']) {
  338. deletethread($tids, true, true, true);
  339. manage_addnotify('verifyrecycle', $modpostsnum);
  340. } else {
  341. deletethread($tids, true, true);
  342. $updatemodlog = FALSE;
  343. }
  344. $forumstickthreads = $_G['setting']['forumstickthreads'];
  345. $forumstickthreads = !empty($forumstickthreads) ? dunserialize($forumstickthreads) : array();
  346. $delkeys = array_keys($threadlist);
  347. foreach($delkeys as $k) {
  348. unset($forumstickthreads[$k]);
  349. }
  350. C::t('common_setting')->update('forumstickthreads', $forumstickthreads);
  351. C::t('forum_forum_threadtable')->delete_none_threads();
  352. if(!empty($deleteredirect)) {
  353. deletethread($deleteredirect);
  354. }
  355. if(!empty($remarkclosed)) {
  356. C::t('forum_thread')->update($remarkclosed, array('closed'=>0));
  357. }
  358. if($_G['setting']['globalstick'] && $stickmodify) {
  359. require_once libfile('function/cache');
  360. updatecache('globalstick');
  361. }
  362. updateforumcount($_G['fid']);
  363. if($_GET['crimerecord']) {
  364. include_once libfile('function/member');
  365. foreach($threadlist as $thread) {
  366. crime('recordaction', $thread['authorid'], 'crime_delpost', lang('forum/misc', 'crime_postreason', array('reason' => $reason, 'tid' => $thread['tid'], 'pid' => 0)));
  367. }
  368. }
  369. } elseif($operation == 'close') {
  370. if(!$_G['group']['allowclosethread']) {
  371. showmessage('no_privilege_closethread');
  372. }
  373. $expiration = checkexpiration($_GET['expirationclose'], $operation);
  374. $modaction = $expiration ? 'ECL' : 'CLS';
  375. C::t('forum_thread')->update($tidsarr, array('closed'=>1, 'moderated'=>1), true);
  376. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('CLS','OPN','ECL','UCL','EOP','UEO'), array('status' => 0));
  377. } elseif($operation == 'open') {
  378. if(!$_G['group']['allowclosethread']) {
  379. showmessage('no_privilege_openthread');
  380. }
  381. $expiration = checkexpiration($_GET['expirationclose'], $operation);
  382. $modaction = $expiration ? 'EOP' : 'OPN';
  383. C::t('forum_thread')->update($tidsarr, array('closed'=>0, 'moderated'=>1), true);
  384. C::t('forum_threadmod')->update_by_tid_action($tidsarr, array('CLS','OPN','ECL','UCL','EOP','UEO'), array('status' => 0));
  385. } elseif($operation == 'move') {
  386. if(!$_G['group']['allowmovethread']) {
  387. showmessage('no_privilege_movethread');
  388. }
  389. $moveto = $_GET['moveto'];
  390. $toforum = C::t('forum_forum')->fetch_info_by_fid($moveto);
  391. if(!$toforum || ($_G['adminid'] != 1 && $toforum['status'] != 1) || $toforum['type'] == 'group') {
  392. showmessage('admin_move_invalid');
  393. } elseif($_G['fid'] == $toforum['fid']) {
  394. continue;
  395. } else {
  396. $moveto = $toforum['fid'];
  397. $modnewthreads = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 1) && $toforum['modnewposts'] ? 1 : 0;
  398. $modnewreplies = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 2) && $toforum['modnewposts'] ? 1 : 0;
  399. if($modnewthreads || $modnewreplies) {
  400. showmessage('admin_move_have_mod');
  401. }
  402. }
  403. if($_G['adminid'] == 3) {
  404. $priv = C::t('forum_forumfield')->check_moderator_for_uid($moveto, $_G['uid'], $_G['member']['accessmasks']);
  405. 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']) {
  406. showmessage('admin_move_nopermission');
  407. }
  408. }
  409. $moderate = array();
  410. $stickmodify = 0;
  411. $toforumallowspecial = array(
  412. 1 => $toforum['allowpostspecial'] & 1,
  413. 2 => $toforum['allowpostspecial'] & 2,
  414. 3 => isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]) && ($toforum['allowpostspecial'] & 4),
  415. 4 => $toforum['allowpostspecial'] & 8,
  416. 5 => $toforum['allowpostspecial'] & 16,
  417. 127 => $_G['setting']['threadplugins'] ? dunserialize($toforum['threadplugin']) : array(),
  418. );
  419. foreach($threadlist as $tid => $thread) {
  420. $allowmove = 0;
  421. if(!$thread['special']) {
  422. $allowmove = 1;
  423. } else {
  424. if($thread['special'] != 127) {
  425. $allowmove = $toforum['allowpostspecial'] ? $toforumallowspecial[$thread['special']] : 0;
  426. } else {
  427. if($toforumallowspecial[127]) {
  428. $posttable = getposttablebytid($thread['tid']);
  429. $message = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid']);
  430. $message = $message['message'];
  431. $sppos = strrpos($message, chr(0).chr(0).chr(0));
  432. $specialextra = substr($message, $sppos + 3);
  433. $allowmove = in_array($specialextra, $toforumallowspecial[127]);
  434. } else {
  435. $allowmove = 0;
  436. }
  437. }
  438. }
  439. if($allowmove) {
  440. $moderate[] = $tid;
  441. if(in_array($thread['displayorder'], array(2, 3))) {
  442. $stickmodify = 1;
  443. }
  444. if($_GET['type'] == 'redirect') {
  445. $insertdata = array(
  446. 'fid' => $thread['fid'],
  447. 'readperm' => $thread['readperm'],
  448. 'author' => $thread['author'],
  449. 'authorid' => $thread['authorid'],
  450. 'subject' => $thread['subject'],
  451. 'dateline' => $thread['dateline'],
  452. 'lastpost' => $thread['dblastpost'],
  453. 'lastposter' => $thread['lastposter'],
  454. 'views' => 0,
  455. 'replies' => 0,
  456. 'displayorder' => 0,
  457. 'digest' => 0,
  458. 'closed' => $thread['tid'],
  459. 'special' => 0,
  460. 'attachment' => 0,
  461. 'typeid' => $_GET['threadtypeid']
  462. );
  463. $newtid = C::t('forum_thread')->insert($insertdata, true);
  464. if($newtid) {
  465. C::t('forum_threadclosed')->insert(array('tid' => $thread['tid'], 'redirect' => $newtid), true, true);
  466. }
  467. }
  468. }
  469. }
  470. if(!$moderatetids = implode(',', $moderate)) {
  471. showmessage('admin_moderate_invalid');
  472. }
  473. $fieldarr = array(
  474. 'fid' => $moveto,
  475. 'isgroup' => 0,
  476. 'typeid' => $_GET['threadtypeid'],
  477. 'moderated' => 1
  478. );
  479. if($_G['adminid'] == 3) {
  480. $fieldarr['displayorder'] = 0;
  481. }
  482. C::t('forum_thread')->update($tidsarr, $fieldarr, true);
  483. C::t('forum_forumrecommend')->update($tidsarr, array('fid' => $moveto));
  484. loadcache('posttableids');
  485. $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
  486. foreach($posttableids as $id) {
  487. C::t('forum_post')->update_by_tid($id, $tidsarr, array('fid' => $moveto));
  488. }
  489. $typeoptionvars = C::t('forum_typeoptionvar')->fetch_all_by_tid_optionid($tidsarr);
  490. foreach($typeoptionvars as $typeoptionvar) {
  491. C::t('forum_typeoptionvar')->update_by_tid($typeoptionvar['tid'], array('fid' => $moveto));
  492. C::t('forum_optionvalue')->update($typeoptionvar['sortid'], $typeoptionvar['tid'], $_G['fid'], "fid='$moveto'");
  493. }
  494. if($_G['setting']['globalstick'] && $stickmodify) {
  495. require_once libfile('function/cache');
  496. updatecache('globalstick');
  497. }
  498. $modaction = 'MOV';
  499. $_G['toforum'] = $toforum;
  500. updateforumcount($moveto);
  501. updateforumcount($_G['fid']);
  502. } elseif($operation == 'type') {
  503. if(!$_G['group']['allowedittypethread']) {
  504. showmessage('no_privilege_edittypethread');
  505. }
  506. if(!isset($_G['forum']['threadtypes']['types'][$_GET['typeid']]) && ($_GET['typeid'] != 0 || $_G['forum']['threadtypes']['required'])) {
  507. showmessage('admin_type_invalid');
  508. }
  509. C::t('forum_thread')->update($tidsarr, array('typeid'=>$_GET['typeid'], 'moderated'=>1), true);
  510. $modaction = 'TYP';
  511. } elseif($operation == 'recommend_group') {
  512. if($_G['forum']['status'] != 3 || !in_array($_G['adminid'], array(1, 2))) {
  513. showmessage('undefined_action');
  514. }
  515. $moveto = $_GET['moveto'];
  516. $toforum = C::t('forum_forum')->fetch_info_by_fid($moveto);
  517. if(!$toforum || $toforum['status'] != 1 || $toforum['type'] == 'group') {
  518. showmessage('admin_move_invalid');
  519. } elseif($_G['fid'] == $toforum['fid']) {
  520. continue;
  521. }
  522. $moderate = array();
  523. $toforumallowspecial = array(
  524. 1 => $toforum['allowpostspecial'] & 1,
  525. 2 => $toforum['allowpostspecial'] & 2,
  526. 3 => isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]) && ($toforum['allowpostspecial'] & 4),
  527. 4 => $toforum['allowpostspecial'] & 8,
  528. 5 => $toforum['allowpostspecial'] & 16,
  529. 127 => $_G['setting']['threadplugins'] ? dunserialize($toforum['threadplugin']) : array(),
  530. );
  531. foreach($threadlist as $tid => $thread) {
  532. $allowmove = 0;
  533. if($thread['closed']) {
  534. continue;
  535. }
  536. if(!$thread['special']) {
  537. $allowmove = 1;
  538. } else {
  539. if($thread['special'] != 127) {
  540. $allowmove = $toforum['allowpostspecial'] ? $toforumallowspecial[$thread['special']] : 0;
  541. } else {
  542. if($toforumallowspecial[127]) {
  543. $posttable = getposttablebytid($thread['tid']);
  544. $message = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid']);
  545. $message = $message['message'];
  546. $sppos = strrpos($message, chr(0).chr(0).chr(0));
  547. $specialextra = substr($message, $sppos + 3);
  548. $allowmove = in_array($specialextra, $toforumallowspecial[127]);
  549. } else {
  550. $allowmove = 0;
  551. }
  552. }
  553. }
  554. if($allowmove) {
  555. $moderate[] = $tid;
  556. $newthread = array(
  557. 'fid' => $moveto,
  558. 'readperm' => $thread['readperm'],
  559. 'author' => $thread['author'],
  560. 'authorid' => $thread['authorid'],
  561. 'subject' => $thread['subject'],
  562. 'dateline' => $thread['dateline'],
  563. 'lastpost' => TIMESTAMP,
  564. 'lastposter' => $thread['lastposter'],
  565. 'views' => $thread['views'],
  566. 'replies' => $thread['replies'],
  567. 'displayorder' => 0,
  568. 'digest' => $thread['digest'],
  569. 'closed' => $thread['tid'],
  570. 'special' => $thread['special'],
  571. 'attachment' => $thread['attachment'],
  572. 'isgroup' => $thread['isgroup']
  573. );
  574. $newtid = C::t('forum_thread')->insert($newthread, true);
  575. C::t('forum_thread')->update($thread['tid'], array('closed'=>$newtid, 'moderated'=>1), true);
  576. }
  577. }
  578. if(!$moderatetids = implode(',', $moderate)) {
  579. showmessage('admin_succeed', $_G['referer']);
  580. }
  581. $modaction = 'REG';
  582. }
  583. if($updatemodlog) {
  584. if($operation != 'delete') {
  585. updatemodlog($moderatetids, $modaction, $expiration);
  586. } else {
  587. updatemodlog($moderatetids, $modaction, $expiration, 0, $reason);
  588. }
  589. }
  590. updatemodworks($modaction, $modpostsnum);
  591. foreach($threadlist as $thread) {
  592. modlog($thread, $modaction);
  593. }
  594. if($sendreasonpm) {
  595. $modactioncode = lang('forum/modaction');
  596. $modtype = $modaction;
  597. $modaction = $modactioncode[$modaction];
  598. foreach($threadlist as $thread) {
  599. if($operation == 'move') {
  600. 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');
  601. } else {
  602. sendreasonpm($thread, 'reason_moderate', array('tid' => $thread['tid'], 'subject' => $thread['subject'], 'modaction' => $modaction, 'reason' => $reason, 'from_id' => 0, 'from_idtype' => 'moderate_'.$modtype), 'post');
  603. }
  604. }
  605. }
  606. if($stampstatus) {
  607. set_stamp($stampstatus, $stampaction, $threadlist, $expiration);
  608. }
  609. }
  610. showmessage('admin_succeed', $_G['referer']);
  611. }
  612. }
  613. function checkexpiration($expiration, $operation) {
  614. global $_G;
  615. if(!empty($expiration) && in_array($operation, array('recommend', 'stick', 'digest', 'highlight', 'close', 'open', 'bump'))) {
  616. $expiration = strtotime($expiration) - $_G['setting']['timeoffset'] * 3600 + date('Z');
  617. if(dgmdate($expiration, 'Ymd') <= dgmdate(TIMESTAMP, 'Ymd') || ($expiration > TIMESTAMP + 86400 * 180)) {
  618. showmessage('admin_expiration_invalid', '', array('min'=>dgmdate(TIMESTAMP, 'Y-m-d'), 'max'=>dgmdate(TIMESTAMP + 86400 * 180, 'Y-m-d')));
  619. }
  620. } else {
  621. $expiration = 0;
  622. }
  623. return $expiration;
  624. }
  625. function set_stamp($typeid, $stampaction, &$threadlist, $expiration) {
  626. global $_G;
  627. $moderatetids = array_keys($threadlist);
  628. if(empty($threadlist)) {
  629. return false;
  630. }
  631. if(array_key_exists($typeid, $_G['cache']['stamptypeid'])) {
  632. if($stampaction == 'SPD') {
  633. C::t('forum_thread')->update($moderatetids, array('stamp'=>-1), true);
  634. } else {
  635. C::t('forum_thread')->update($moderatetids, array('stamp'=>$_G['cache']['stamptypeid'][$typeid]), true);
  636. }
  637. !empty($moderatetids) && updatemodlog($moderatetids, $stampaction, $expiration, 0, '', $_G['cache']['stamptypeid'][$typeid]);
  638. }
  639. }
  640. function get_expiration($tid, $action) {
  641. $tid = intval($tid);
  642. if(empty($tid) || empty($action)) {
  643. return '';
  644. }
  645. $row = C::t('forum_threadmod')->fetch_by_tid_action_status($tid, $action);
  646. return $row['expiration'] ? date('Y-m-d H:i', $row['expiration']) : '';
  647. }
  648. ?>