PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/source/include/modcp/modcp_thread.php

https://github.com/kuaileshike/upload
PHP | 377 lines | 299 code | 72 blank | 6 comment | 107 complexity | 3af67faa960a575debb115aa1958d855 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: modcp_thread.php 28845 2012-03-15 00:59:32Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_MODCP')) {
  9. exit('Access Denied');
  10. }
  11. $op = !in_array($op , array('thread', 'post')) ? 'thread' : $op;
  12. $do = getgpc('do') ? dhtmlspecialchars(getgpc('do')) : '';
  13. $modtpl = $op == 'post' ? 'modcp_post' : 'modcp_thread';
  14. $modtpl = 'forum/'.$modtpl;
  15. $threadoptionselect = array('','','','','','', '', '', '', '', 999=>'', 888=>'');
  16. $threadoptionselect[getgpc('threadoption')] = 'selected';
  17. if($op == 'thread') {
  18. $result = array();
  19. foreach (array('threadoption', 'viewsless', 'viewsmore', 'repliesless', 'repliesmore', 'noreplydays', 'typeid') as $key) {
  20. $_GET[''.$key] = isset($_GET[''.$key]) && is_numeric($_GET[''.$key]) ? intval($_GET[''.$key]) : '';
  21. $result[$key] = $_GET[''.$key];
  22. }
  23. foreach (array('starttime', 'endtime', 'keywords', 'users') as $key) {
  24. $result[$key] = isset($_GET[''.$key]) ? dhtmlspecialchars($_GET[''.$key]) : '';
  25. }
  26. if($_G['fid'] && $_G['forum']['ismoderator']) {
  27. if($do == 'search' && submitcheck('submit', 1)) {
  28. $conditions = array();
  29. if($_GET['threadoption'] > 0 && $_GET['threadoption'] < 255) {
  30. $conditions['specialthread'] = 1;
  31. $conditions['special'] = $_GET['threadoption'];
  32. } elseif($_GET['threadoption'] == 999) {
  33. $conditions['digest'] = array(1,2,3);
  34. } elseif($_GET['threadoption'] == 888) {
  35. $conditions['sticky'] = 1;
  36. }
  37. $_GET['viewsless'] !== ''? $conditions['viewsless'] = $_GET['viewsless'] : '';
  38. $_GET['viewsmore'] !== ''? $conditions['viewsmore'] = $_GET['viewsmore'] : '';
  39. $_GET['repliesless'] !== ''? $conditions['repliesless'] = $_GET['repliesless'] : '';
  40. $_GET['repliesmore'] !== ''? $conditions['repliesmore'] = $_GET['repliesmore'] : '';
  41. $_GET['noreplydays'] !== ''? $conditions['noreplydays'] = $_GET['noreplydays'] : '';
  42. $_GET['starttime'] != '' ? $conditions['starttime'] = $_GET['starttime'] : '';
  43. $_GET['endtime'] != '' ? $conditions['endtime'] = $_GET['endtime'] : '';
  44. if(trim($_GET['keywords'])) {
  45. $conditions['keywords'] = $_GET['keywords'];
  46. }
  47. if(trim($_GET['users'])) {
  48. $conditions['users'] = trim($_GET['users']);
  49. }
  50. if($_GET['typeid']) {
  51. $conditions['intype'] = $_GET['typeid'];
  52. }
  53. if(!empty($conditions)) {
  54. $conditions['inforum'] = $_G['fid'];
  55. if(!isset($conditions['sticky'])) $conditions['sticky'] = 0;
  56. $tids = $comma = '';
  57. $count = 0;
  58. foreach(C::t('forum_thread')->fetch_all_search($conditions, 0, 0, 1000, 'displayorder DESC, lastpost') as $thread) {
  59. $tids .= $comma.$thread['tid'];
  60. $comma = ',';
  61. $count ++;
  62. }
  63. $result['tids'] = $tids;
  64. $result['count'] = $count;
  65. $result['fid'] = $_G['fid'];
  66. $modsession->set('srchresult', $result, true);
  67. unset($result, $tids);
  68. $do = 'list';
  69. $page = 1;
  70. } else {
  71. $do = '';
  72. }
  73. }
  74. $page = $_G['page'];
  75. $total = 0;
  76. $query = $multipage = '';
  77. if(empty($do)) {
  78. $total = C::t('forum_thread')->count_by_fid_typeid_displayorder($_G['fid'], $_GET['typeid'], 0, '>=');
  79. $tpage = ceil($total / $_G['tpp']);
  80. $page = min($tpage, $page);
  81. $multipage = multi($total, $_G['tpp'], $page, "$cpscript?mod=modcp&amp;action=$_GET[action]&amp;op=$op&amp;fid=$_G[fid]&amp;do=$do");
  82. if($total) {
  83. $start = ($page - 1) * $_G['tpp'];
  84. $threads = C::t('forum_thread')->fetch_all_by_fid_typeid_displayorder($_G['fid'], $_GET['typeid'], 0, '>=', $start, $_G['tpp']);
  85. }
  86. } else {
  87. $result = $modsession->get('srchresult');
  88. $threadoptionselect[$result['threadoption']] = 'selected';
  89. if($result['fid'] == $_G['fid']) {
  90. $total = $result['count'];
  91. $tpage = ceil($total / $_G['tpp']);
  92. $page = min($tpage, $page);
  93. $multipage = multi($total, $_G['tpp'], $page, "$cpscript?mod=modcp&amp;action=$_GET[action]&amp;op=$op&amp;fid=$_G[fid]&amp;do=$do");
  94. if($total) {
  95. $start = ($page - 1) * $_G['tpp'];
  96. $threads = C::t('forum_thread')->fetch_all_by_tid_fid_displayorder(explode(',', $result['tids']), null, null, 'lastpost', $start, $_G['tpp']);
  97. }
  98. }
  99. }
  100. $postlist = array();
  101. if(!empty($threads)) {
  102. require_once libfile('function/misc');
  103. foreach($threads as $thread) {
  104. $postlist[] = procthread($thread);
  105. }
  106. }
  107. }
  108. return;
  109. }
  110. if($op == 'post') {
  111. $error = 0;
  112. $result = array();
  113. $_GET['starttime'] = !preg_match("/^(0|\d{4}\-\d{1,2}\-\d{1,2})$/", getgpc('starttime')) ? dgmdate(TIMESTAMP - 86400 * ($_G['adminid'] == 2 ? 13 : ($_G['adminid'] == 3 ? 6 : 60)), 'Y-m-d') : getgpc('starttime');
  114. $_GET['endtime'] = $_G['adminid'] == 3 || !preg_match("/^(0|\d{4}\-\d{1,2}\-\d{1,2})$/", getgpc('endtime')) ? dgmdate(TIMESTAMP, 'Y-m-d') : getgpc('endtime');
  115. foreach (array('threadoption', 'starttime', 'endtime', 'keywords', 'users', 'useip') as $key) {
  116. $$key = isset($_GET[''.$key]) ? trim($_GET[''.$key]) : '';
  117. $result[$key] = dhtmlspecialchars($$key);
  118. }
  119. $threadoptionselect = range(1, 3);
  120. $posttableid = intval($_GET['posttableid']);
  121. $posttableselect = getposttableselect();
  122. $cachekey = 'srchresult_p_'.$posttableid.'_'.$_G['fid'];
  123. $fidadd = '';
  124. $fidaddarr = array();
  125. if($_G['fid'] && $modforums['list'][$_G['fid']]) {
  126. $fidaddarr = array($_G['fid']);
  127. $fidadd = "AND fid='$_G[fid]'";
  128. } else {
  129. if($_G['adminid'] == 1 && $_G['adminid'] == $_G['groupid']) {
  130. $fidadd = '';
  131. } elseif(!$modforums['fids']) {
  132. $fidaddarr = array(0);
  133. $fidadd = 'AND 0 ';
  134. } else {
  135. $fidaddarr = explode(',', $modforums['fids']);
  136. $fidadd = "AND fid in($modforums[fids])";
  137. }
  138. }
  139. if($do == 'delete' && submitcheck('deletesubmit')) {
  140. if(!$_G['group']['allowmassprune']) {
  141. $error = 4;
  142. return;
  143. }
  144. $pidsdelete = $tidsdelete = array();
  145. $prune = array('forums' => array(), 'thread' => array());
  146. if($pids = dimplode($_GET['delete'])) {
  147. $result = $modsession->get($cachekey);
  148. $result['pids'] = explode(',', $result['pids']);
  149. $keys = array_flip($result['pids']);
  150. foreach(C::t('forum_post')->fetch_all($posttableid, $_GET['delete'], false) as $post) {
  151. if($fidaddarr && !in_array($post['fid'], $fidaddarr)) {
  152. continue;
  153. }
  154. $prune['forums'][$post['fid']] = $post['fid'];
  155. $pidsdelete[$post['fid']][$post['pid']] = $post['pid'];
  156. $pids_tids[$post['pid']] = $post['tid'];
  157. if($post['first']) {
  158. $tidsdelete[$post['pid']] = $post['tid'];
  159. } else {
  160. @$prune['thread'][$post['tid']]++;
  161. }
  162. $key = $keys[$post['pid']];
  163. unset($result['pids'][$key]);
  164. }
  165. $result['pids'] = implode(',', $result['pids']);
  166. $result['count'] = count($result['pids']);
  167. $modsession->set($cachekey, $result, true);
  168. unset($result);
  169. }
  170. if($pidsdelete) {
  171. require_once libfile('function/post');
  172. require_once libfile('function/delete');
  173. $forums = C::t('forum_forum')->fetch_all($prune['forums']);
  174. foreach($pidsdelete as $fid => $pids) {
  175. foreach($pids as $pid) {
  176. if(!$tidsdelete[$pid]) {
  177. $deletedposts = deletepost($pid, 'pid', !getgpc('nocredit'), $posttableid, $forums[$fid]['recyclebin']);
  178. updatemodlog($pids_tids[$pid], 'DLP');
  179. } else {
  180. $deletedthreads = deletethread(array($tidsdelete[$pid]), false, !getgpc('nocredit'), $forums[$fid]['recyclebin']);
  181. updatemodlog($tidsdelete[$pid], 'DEL');
  182. }
  183. }
  184. }
  185. if(count($prune['thread']) < 50) {
  186. foreach($prune['thread'] as $tid => $decrease) {
  187. updatethreadcount($tid);
  188. }
  189. } else {
  190. $repliesarray = array();
  191. foreach($prune['thread'] as $tid => $decrease) {
  192. $repliesarray[$decrease][] = $tid;
  193. }
  194. foreach($repliesarray as $decrease => $tidarray) {
  195. C::t('forum_thread')->increase($tidarray, array('replies'=>-$decrease));
  196. }
  197. }
  198. foreach(array_unique($prune['forums']) as $id) {
  199. updateforumcount($id);
  200. }
  201. }
  202. $do = 'list';
  203. showmessage('modcp_thread_delete_succeed', '', array(), array('break' => 1));
  204. }
  205. if($do == 'search' && submitcheck('searchsubmit', 1)) {
  206. if(($starttime == '0' && $endtime == '0') || ($keywords == '' && $useip == '' && $users == '')) {
  207. $error = 1;
  208. return ;
  209. }
  210. $sql = '';
  211. if($threadoption == 1) {
  212. $first = 1;
  213. } elseif($threadoption == 2) {
  214. $first = 0;
  215. }
  216. if($starttime != '0') {
  217. $starttime = strtotime($starttime);
  218. }
  219. if($_G['adminid'] == 1 && $endtime != dgmdate(TIMESTAMP, 'Y-m-d')) {
  220. if($endtime != '0') {
  221. $endtime = strtotime($endtime);
  222. }
  223. } else {
  224. $endtime = TIMESTAMP;
  225. }
  226. if(($_G['adminid'] == 2 && $endtime - $starttime > 86400 * 14) || ($_G['adminid'] == 3 && $endtime - $starttime > 86400 * 7)) {
  227. $error = '2';
  228. return;
  229. }
  230. if($users != '') {
  231. $uids = C::t('common_member')->fetch_all_uid_by_username(array_map('trim', explode(',', $users)));
  232. if(!$uids) {
  233. $uids = array(0);
  234. }
  235. }
  236. if(trim($keywords)) {
  237. foreach(explode(',', str_replace(' ', '', $keywords)) as $value) {
  238. if(strlen($value) <= 3) {
  239. $error = 3;
  240. return;
  241. }
  242. }
  243. }
  244. $useip = trim($useip);
  245. if($useip != '') {
  246. $useip = str_replace('*', '%', $useip);
  247. }
  248. if($uids || $keywords || $useip) {
  249. $pids = array();
  250. foreach(C::t('forum_post')->fetch_all_by_search($posttableid, null, $keywords, 0, $fidaddarr, $uids, null, $starttime, $endtime, $useip, $first, 0, 1000) as $post) {
  251. $pids[] = $post['pid'];
  252. }
  253. $result['pids'] = implode(',', $pids);
  254. $result['count'] = count($pids);
  255. $result['fid'] = $_G['fid'];
  256. $result['posttableid'] = $posttableid;
  257. $modsession->set($cachekey, $result, true);
  258. unset($result, $pids);
  259. $do = 'list';
  260. $page = 1;
  261. } else {
  262. $do = '';
  263. }
  264. }
  265. $page = max(1, intval($_G['page']));
  266. $total = 0;
  267. $query = $multipage = '';
  268. if($do == 'list') {
  269. $postarray = array();
  270. $result = $modsession->get($cachekey);
  271. $threadoptionselect[$result['threadoption']] = 'selected';
  272. if($result['fid'] == $_G['fid']) {
  273. $total = $result['count'];
  274. $tpage = ceil($total / $_G['tpp']);
  275. $page = min($tpage, $page);
  276. $multipage = multi($total, $_G['tpp'], $page, "$cpscript?mod=modcp&amp;action=$_GET[action]&amp;op=$op&amp;fid=$_G[fid]&amp;do=$do");
  277. if($total && $result['pids']) {
  278. $start = ($page - 1) * $_G['tpp'];
  279. $tids = array();
  280. $postlist = C::t('forum_post')->fetch_all_by_pid($result['posttableid'], explode(',', $result['pids']), true, 'DESC', $start, $_G['tpp']);
  281. foreach($postlist as $post) {
  282. $tids[$post['tid']] = $post['tid'];
  283. }
  284. $threadlist = C::t('forum_thread')->fetch_all($tids);
  285. foreach($postlist as $post) {
  286. $post['tsubject'] = $threadlist[$post['tid']]['subject'];
  287. $postarray[] = $post;
  288. }
  289. unset($threadlist, $postlist, $tids);
  290. }
  291. }
  292. }
  293. $postlist = array();
  294. if($postarray) {
  295. require_once libfile('function/post');
  296. foreach($postarray as $post) {
  297. $post['dateline'] = dgmdate($post['dateline']);
  298. $post['message'] = messagecutstr($post['message'], 200);
  299. $post['forum'] = $modforums['list'][$post['fid']];
  300. $post['modthreadkey'] = modauthkey($post['tid']);
  301. $postlist[] = $post;
  302. }
  303. }
  304. }
  305. ?>