PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/source/include/topicadmin/topicadmin_moderate.php

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