PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/source/admincp/admincp_threads.php

https://github.com/kuaileshike/upload
PHP | 643 lines | 576 code | 61 blank | 6 comment | 143 complexity | 0087facaab7268330fb651b10e552e10 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: admincp_threads.php 26864 2011-12-26 09:20:38Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('function/post');
  12. cpheader();
  13. $optype = $_GET['optype'];
  14. $fromumanage = $_GET['fromumanage'] ? 1 : 0;
  15. if((!$operation && !$optype) || ($operation == 'group' && empty($optype))) {
  16. if(!submitcheck('searchsubmit', 1) && empty($_GET['search'])) {
  17. $newlist = 1;
  18. $_GET['intype'] = '';
  19. $_GET['detail'] = 1;
  20. $_GET['inforum'] = 'all';
  21. $_GET['starttime'] = dgmdate(TIMESTAMP - 86400 * 30, 'Y-n-j');
  22. }
  23. $intypes = '';
  24. if($_GET['inforum'] && $_GET['inforum'] != 'all' && $_GET['intype']) {
  25. $foruminfo = C::t('forum_forumfield')->fetch($_GET['inforum']);
  26. $forumthreadtype = $foruminfo['threadtypes'];
  27. if($forumthreadtype) {
  28. $forumthreadtype = dunserialize($forumthreadtype);
  29. foreach($forumthreadtype['types'] as $typeid => $typename) {
  30. $intypes .= '<option value="'.$typeid.'"'.($typeid == $_GET['intype'] ? ' selected' : '').'>'.$typename.'</option>';
  31. }
  32. }
  33. }
  34. require_once libfile('function/forumlist');
  35. $forumselect = '<b>'.$lang['threads_search_forum'].':</b><br><br><select name="inforum" onchange="ajaxget(\'forum.php?mod=ajax&action=getthreadtypes&selectname=intype&fid=\' + this.value, \'forumthreadtype\')"><option value="all">&nbsp;&nbsp;> '.$lang['all'].'</option><option value="">&nbsp;</option>'.forumselect(FALSE, 0, 0, TRUE).'</select>';
  36. $typeselect = $lang['threads_move_type'].' <span id="forumthreadtype"><select name="intype"><option value=""></option>'.$intypes.'</select></span>';
  37. if(isset($_GET['inforum'])) {
  38. $forumselect = preg_replace("/(\<option value=\"$_GET[inforum]\")(\>)/", "\\1 selected=\"selected\" \\2", $forumselect);
  39. }
  40. $sortselect = '';
  41. $query = C::t('forum_threadtype')->fetch_all_for_order();
  42. foreach($query as $type) {
  43. if($type['special']) {
  44. $sortselect .= '<option value="'.$type['typeid'].'">&nbsp;&nbsp;> '.$type['name'].'</option>';
  45. }
  46. }
  47. if(isset($_GET['insort'])) {
  48. $sortselect = preg_replace("/(\<option value=\"{$_GET['insort']}\")(\>)/", "\\1 selected=\"selected\" \\2", $sortselect);
  49. }
  50. echo <<<EOT
  51. <script src="static/js/calendar.js"></script>
  52. <script type="text/JavaScript">
  53. function page(number) {
  54. $('threadforum').page.value=number;
  55. $('threadforum').searchsubmit.click();
  56. }
  57. </script>
  58. EOT;
  59. shownav('topic', 'nav_maint_threads'.($operation ? '_'.$operation : ''));
  60. showsubmenu('nav_maint_threads'.($operation ? '_'.$operation : ''), array(
  61. array('newlist', 'threads'.($operation ? '&operation='.$operation : ''), !empty($newlist)),
  62. array('search', 'threads'.($operation ? '&operation='.$operation : '').'&search=true', empty($newlist)),
  63. ));
  64. empty($newlist) && showsubmenusteps('', array(
  65. array('threads_search', !$_GET['searchsubmit']),
  66. array('nav_maint_threads', $_GET['searchsubmit'])
  67. ));
  68. if(empty($newlist)) {
  69. $search_tips = 1;
  70. showtips('threads_tips');
  71. }
  72. showtagheader('div', 'threadsearch', !submitcheck('searchsubmit', 1) && empty($newlist));
  73. showformheader('threads'.($operation ? '&operation='.$operation : ''), '', 'threadforum');
  74. showhiddenfields(array('page' => $page, 'pp' => $_GET['pp'] ? $_GET['pp'] : $_GET['perpage']));
  75. showtableheader();
  76. showsetting('threads_search_detail', 'detail', $_GET['detail'], 'radio');
  77. if($operation != 'group') {
  78. showtablerow('', array('class="rowform" colspan="2" style="width:auto;"'), array($forumselect.$typeselect));
  79. }
  80. showsetting('threads_search_perpage', '', $_GET['perpage'], "<select name='perpage'><option value='20'>$lang[perpage_20]</option><option value='50'>$lang[perpage_50]</option><option value='100'>$lang[perpage_100]</option></select>");
  81. if(!$fromumanage) {
  82. empty($_GET['starttime']) && $_GET['starttime'] = date('Y-m-d', time() - 86400 * 30);
  83. }
  84. echo '<input type="hidden" name="fromumanage" value="'.$fromumanage.'">';
  85. showsetting('threads_search_time', array('starttime', 'endtime'), array($_GET['starttime'], $_GET['endtime']), 'daterange');
  86. showsetting('threads_search_user', 'users', $_GET['users'], 'text');
  87. showsetting('threads_search_keyword', 'keywords', $_GET['keywords'], 'text');
  88. showtagheader('tbody', 'advanceoption');
  89. showsetting('threads_search_sort', '', '', '<select name="insort"><option value="all">&nbsp;&nbsp;> '.$lang['all'].'</option><option value="">&nbsp;</option><option value="0">&nbsp;&nbsp;> '.$lang['threads_search_type_none'].'</option>'.$sortselect.'</select>');
  90. showsetting('threads_search_viewrange', array('viewsmore', 'viewsless'), array($_GET['viewsmore'], $_GET['viewsless']), 'range');
  91. showsetting('threads_search_replyrange', array('repliesmore', 'repliesless'), array($_GET['repliesmore'], $_GET['repliesless']), 'range');
  92. showsetting('threads_search_readpermmore', 'readpermmore', $_GET['readpermmore'], 'text');
  93. showsetting('threads_search_pricemore', 'pricemore', $_GET['pricemore'], 'text');
  94. showsetting('threads_search_noreplyday', 'noreplydays', $_GET['noreplydays'], 'text');
  95. showsetting('threads_search_type', array('specialthread', array(
  96. array(0, cplang('unlimited'), array('showspecial' => 'none')),
  97. array(1, cplang('threads_search_include_yes'), array('showspecial' => '')),
  98. array(2, cplang('threads_search_include_no'), array('showspecial' => '')),
  99. ), TRUE), $_GET['specialthread'], 'mradio');
  100. showtablerow('id="showspecial" style="display:'.($_GET['specialthread'] ? '' : 'none').'"', 'class="sub" colspan="2"', mcheckbox('special', array(
  101. 1 => cplang('thread_poll'),
  102. 2 => cplang('thread_trade'),
  103. 3 => cplang('thread_reward'),
  104. 4 => cplang('thread_activity'),
  105. 5 => cplang('thread_debate')
  106. ), $_GET['special'] ? $_GET['special'] : array(0)));
  107. showsetting('threads_search_sticky', array('sticky', array(
  108. array(0, cplang('unlimited')),
  109. array(1, cplang('threads_search_include_yes')),
  110. array(2, cplang('threads_search_include_no')),
  111. ), TRUE), $_GET['sticky'], 'mradio');
  112. showsetting('threads_search_digest', array('digest', array(
  113. array(0, cplang('unlimited')),
  114. array(1, cplang('threads_search_include_yes')),
  115. array(2, cplang('threads_search_include_no')),
  116. ), TRUE), $_GET['digest'], 'mradio');
  117. showsetting('threads_search_attach', array('attach', array(
  118. array(0, cplang('unlimited')),
  119. array(1, cplang('threads_search_include_yes')),
  120. array(2, cplang('threads_search_include_no')),
  121. ), TRUE), $_GET['attach'], 'mradio');
  122. showsetting('threads_rate', array('rate', array(
  123. array(0, cplang('unlimited')),
  124. array(1, cplang('threads_search_include_yes')),
  125. array(2, cplang('threads_search_include_no')),
  126. ), TRUE), $_GET['rate'], 'mradio');
  127. showsetting('threads_highlight', array('highlight', array(
  128. array(0, cplang('unlimited')),
  129. array(1, cplang('threads_search_include_yes')),
  130. array(2, cplang('threads_search_include_no')),
  131. ), TRUE), $_GET['highlight'], 'mradio');
  132. showsetting('threads_save', 'savethread', $_GET['savethread'], 'radio');
  133. showtagfooter('tbody');
  134. showsubmit('searchsubmit', 'submit', '', 'more_options');
  135. showtablefooter();
  136. showformfooter();
  137. showtagfooter('div');
  138. if(submitcheck('searchsubmit', 1) || $newlist) {
  139. $operation == 'group' && $_GET['inforum'] = 'isgroup';
  140. $conditions['inforum'] = $_GET['inforum'] != '' && $_GET['inforum'] != 'all' && $_GET['inforum'] != 'isgroup' ? $_GET['inforum'] : '';
  141. $conditions['isgroup'] = $_GET['inforum'] != '' && $_GET['inforum'] == 'isgroup' ? 1 : 0;
  142. $conditions['intype'] = $_GET['intype'] !== '' ? $_GET['intype'] : '';
  143. $conditions['insort'] = $_GET['insort'] != '' && $_GET['insort'] != 'all' ? $_GET['insort'] : '';
  144. $conditions['viewsless'] = $_GET['viewsless'] != '' ? $_GET['viewsless'] : '';
  145. $conditions['viewsmore'] = $_GET['viewsmore'] != '' ? $_GET['viewsmore'] : '';
  146. $conditions['repliesless'] = $_GET['repliesless'] != '' ? $_GET['repliesless'] : '';
  147. $conditions['repliesmore'] = $_GET['repliesmore'] != '' ? $_GET['repliesmore'] : '';
  148. $conditions['readpermmore'] = $_GET['readpermmore'] != '' ? $_GET['readpermmore'] : '';
  149. $conditions['pricemore'] = $_GET['pricemore'] != '' ? $_GET['pricemore'] : '';
  150. $conditions['beforedays'] = $_GET['beforedays'] != '' ? $_GET['beforedays'] : '';
  151. $conditions['noreplydays'] = $_GET['noreplydays'] != '' ? $_GET['noreplydays'] : '';
  152. $conditions['starttime'] = $_GET['starttime'] != '' ? $_GET['starttime'] : '';
  153. $conditions['endtime'] = $_GET['endtime'] != '' ? $_GET['endtime'] : '';
  154. if(!empty($_GET['savethread'])) {
  155. $conditions['sticky'] = 4;
  156. $conditions['displayorder'] = -4;
  157. }
  158. if(trim($_GET['keywords'])) {
  159. $conditions['keywords'] = $_GET['keywords'];
  160. }
  161. $conditions['users'] = trim($_GET['users']) ? $_GET['users'] : '';
  162. if($_GET['sticky'] == 1) {
  163. $conditions['sticky'] = 1;
  164. } elseif($_GET['sticky'] == 2) {
  165. $conditions['sticky'] = 2;
  166. }
  167. if($_GET['digest'] == 1) {
  168. $conditions['digest'] = 1;
  169. } elseif($_GET['digest'] == 2) {
  170. $conditions['digest'] = 2;
  171. }
  172. if($_GET['attach'] == 1) {
  173. $conditions['attach'] = 1;
  174. } elseif($_GET['attach'] == 2) {
  175. $conditions['attach'] = 2;
  176. }
  177. if($_GET['rate'] == 1) {
  178. $conditions['rate'] = 1;
  179. } elseif($_GET['rate'] == 2) {
  180. $conditions['rate'] = 2;
  181. }
  182. if($_GET['highlight'] == 1) {
  183. $conditions['highlight'] = 1;
  184. } elseif($_GET['highlight'] == 2) {
  185. $conditions['highlight'] = 2;
  186. }
  187. if(!empty($_GET['special'])) {
  188. $specials = $comma = '';
  189. foreach($_GET['special'] as $val) {
  190. $specials .= $comma.'\''.$val.'\'';
  191. $comma = ',';
  192. }
  193. $conditions['special'] = $_GET['special'];
  194. if($_GET['specialthread'] == 1) {
  195. $conditions['specialthread'] = 1;
  196. } elseif($_GET['specialthread'] == 2) {
  197. $conditions['specialthread'] = 2;
  198. }
  199. }
  200. $fids = array();
  201. $tids = $threadcount = '0';
  202. if($conditions) {
  203. if(empty($_GET['savethread']) && !isset($conditions['displayorder']) && !isset($conditions['sticky'])) {
  204. $conditions['sticky'] = 5;
  205. }
  206. if($_GET['detail']) {
  207. $_GET['perpage'] = intval($_GET['perpage']) < 1 ? 20 : intval($_GET['perpage']);
  208. $perpage = $_GET['pp'] ? $_GET['pp'] : $_GET['perpage'];
  209. $start = ($page - 1) * $perpage;
  210. $threads = '';
  211. $groupsname = $groupsfid = $threadlist = array();
  212. $threadcount = C::t('forum_thread')->count_search($conditions);
  213. if($threadcount) {
  214. foreach(C::t('forum_thread')->fetch_all_search($conditions, 0, $start, $perpage, 'tid', 'DESC', ' FORCE INDEX(PRIMARY) ') as $thread) {
  215. $fids[] = $thread['fid'];
  216. if($thread['isgroup']) {
  217. $groupsfid[$thread[fid]] = $thread['fid'];
  218. }
  219. $thread['lastpost'] = dgmdate($thread['lastpost']);
  220. $threadlist[] = $thread;
  221. }
  222. if($groupsfid) {
  223. $query = C::t('forum_forum')->fetch_all_by_fid($groupsfid);
  224. foreach($query as $row) {
  225. $groupsname[$row[fid]] = $row['name'];
  226. }
  227. }
  228. if($threadlist) {
  229. foreach($threadlist as $thread) {
  230. $threads .= showtablerow('', array('class="td25"', '', '', '', 'class="td25"', 'class="td25"'), array(
  231. "<input class=\"checkbox\" type=\"checkbox\" name=\"tidarray[]\" value=\"$thread[tid]\" />",
  232. "<a href=\"forum.php?mod=viewthread&tid=$thread[tid]".($thread['displayorder'] != -4 ? '' : '&modthreadkey='.modauthkey($thread['tid']))."\" target=\"_blank\">$thread[subject]</a>".($thread['readperm'] ? " - [$lang[threads_readperm] $thread[readperm]]" : '').($thread['price'] ? " - [$lang[threads_price] $thread[price]]" : ''),
  233. "<a href=\"forum.php?mod=forumdisplay&fid=$thread[fid]\" target=\"_blank\">".(empty($thread['isgroup']) ? $_G['cache']['forums'][$thread[fid]]['name'] : $groupsname[$thread[fid]])."</a>",
  234. "<a href=\"home.php?mod=space&uid=$thread[authorid]\" target=\"_blank\">$thread[author]</a>",
  235. $thread['replies'],
  236. $thread['views'],
  237. $thread['lastpost']
  238. ), TRUE);
  239. }
  240. }
  241. $multi = multi($threadcount, $perpage, $page, ADMINSCRIPT."?action=threads");
  242. $multi = preg_replace("/href=\"".ADMINSCRIPT."\?action=threads&amp;page=(\d+)\"/", "href=\"javascript:page(\\1)\"", $multi);
  243. $multi = str_replace("window.location='".ADMINSCRIPT."?action=threads&amp;page='+this.value", "page(this.value)", $multi);
  244. }
  245. } else {
  246. $threadcount = C::t('forum_thread')->count_search($conditions);
  247. if($threadcount) {
  248. foreach(C::t('forum_thread')->fetch_all_search($conditions, 0, $start, $perpage, 'tid', 'DESC', ' FORCE INDEX(PRIMARY) ') as $thread) {
  249. $fids[] = $thread['fid'];
  250. $tids .= ','.$thread['tid'];
  251. }
  252. }
  253. $multi = '';
  254. }
  255. }
  256. $fids = implode(',', array_unique($fids));
  257. showtagheader('div', 'threadlist', TRUE);
  258. showformheader('threads&frame=no'.($operation ? '&operation='.$operation : ''), 'target="threadframe"');
  259. showhiddenfields($_GET['detail'] ? array('fids' => $fids) : array('fids' => $fids, 'tids' => $tids));
  260. if(!$search_tips) {
  261. showtableheader(cplang('threads_new_result').' '.$threadcount, 'nobottom');
  262. } else {
  263. showtableheader(cplang('threads_result').' '.$threadcount.' <a href="###" onclick="$(\'threadlist\').style.display=\'none\';$(\'threadsearch\').style.display=\'\';$(\'threadforum\').pp.value=\'\';$(\'threadforum\').page.value=\'\';" class="act lightlink normal">'.cplang('research').'</a>', 'nobottom');
  264. }
  265. if(!$threadcount) {
  266. showtablerow('', 'colspan="3"', cplang('threads_thread_nonexistence'));
  267. } else {
  268. if($_GET['detail']) {
  269. showsubtitle(array('', 'subject', 'forum', 'author', 'threads_replies', 'threads_views', 'threads_lastpost'));
  270. echo $threads;
  271. showtablerow('', array('class="td25" colspan="7"'), array('<input name="chkall" id="chkall" type="checkbox" class="checkbox" onclick="checkAll(\'prefix\', this.form, \'tidarray\', \'chkall\')" /><label for="chkall">'.cplang('select_all').'</label>'));
  272. showtablefooter();
  273. showtableheader('operation', 'notop');
  274. }
  275. showsubtitle(array('', 'operation', 'option'));
  276. showtablerow('', array('class="td25"', 'class="td24"', 'class="rowform" style="width:auto;"'), array(
  277. '<input class="radio" type="radio" id="optype_moveforum" name="optype" value="moveforum" onclick="this.form.modsubmit.disabled=false;">',
  278. $lang['threads_move_forum'],
  279. '<select name="toforum" onchange="$(\'optype_moveforum\').checked=\'checked\';ajaxget(\'forum.php?mod=ajax&action=getthreadtypes&fid=\' + this.value, \'threadtypes\')">'.forumselect(FALSE, 0, 0, TRUE).'</select>'.
  280. $lang['threads_move_type'].' <span id="threadtypes"><select name="threadtypeid" onchange="$(\'optype_moveforum\').checked=\'checked\'"><option value="0"></option></select></span>'
  281. ));
  282. if($operation != 'group') {
  283. showtablerow('', array('class="td25"', 'class="td24"', 'class="rowform" style="width:auto;"'), array(
  284. '<input class="radio" type="radio" id="optype_movesort" name="optype" value="movesort" onclick="this.form.modsubmit.disabled=false;">',
  285. $lang['threads_move_sort'],
  286. '<select name="tosort" onchange="$(\'optype_movesort\').checked=\'checked\';"><option value="0">&nbsp;&nbsp;> '.$lang['threads_search_type_none'].'</option>'.$sortselect.'</select>'
  287. ));
  288. showtablerow('', array('class="td25"', 'class="td24"', 'class="rowform" style="width:auto;"'), array(
  289. '<input class="radio" type="radio" id="optype_stick" name="optype" value="stick" onclick="this.form.modsubmit.disabled=false;">',
  290. $lang['threads_stick'],
  291. '<input class="radio" type="radio" name="stick_level" value="0" onclick="$(\'optype_stick\').checked=\'checked\'"> '.$lang['threads_remove'].' &nbsp; &nbsp;<input class="radio" type="radio" name="stick_level" value="1" onclick="$(\'optype_stick\').checked=\'checked\'"> '.$lang['threads_stick_one'].' &nbsp; &nbsp;<input class="radio" type="radio" name="stick_level" value="2" onclick="$(\'optype_stick\').checked=\'checked\'"> '.$lang['threads_stick_two'].' &nbsp; &nbsp;<input class="radio" type="radio" name="stick_level" value="3" onclick="$(\'optype_stick\').checked=\'checked\'"> '.$lang['threads_stick_three']
  292. ));
  293. showtablerow('', array('class="td25"', 'class="td24"', 'class="rowform" style="width:auto;"'), array(
  294. '<input class="radio" type="radio" id="optype_addstatus" name="optype" value="addstatus" onclick="this.form.modsubmit.disabled=false;">',
  295. $lang['threads_open_close'],
  296. '<input class="radio" type="radio" name="status" value="0" onclick="$(\'optype_addstatus\').checked=\'checked\'"> '.$lang['open'].' &nbsp; &nbsp;<input class="radio" type="radio" name="status" value="1" onclick="$(\'optype_addstatus\').checked=\'checked\'"> '.$lang['closed']
  297. ));
  298. }
  299. showtablerow('', array('class="td25"', 'class="td24"', 'class="rowform" style="width:auto;"'), array(
  300. '<input class="radio" type="radio" id="optype_delete" name="optype" value="delete" onclick="this.form.modsubmit.disabled=false;">',
  301. $lang['threads_delete'],
  302. '<input class="checkbox" type="checkbox" name="donotupdatemember" id="donotupdatemember" value="1" /><label for="donotupdatemember"> '.$lang['threads_delete_no_update_member'].'</label>'
  303. ));
  304. showtablerow('', array('class="td25"', 'class="td24"', 'class="rowform" style="width:auto;"'), array(
  305. '<input class="radio" type="radio" name="optype" id="optype_adddigest" value="adddigest" onclick="this.form.modsubmit.disabled=false;">',
  306. $lang['threads_add_digest'],
  307. '<input class="radio" type="radio" name="digest_level" value="0" onclick="$(\'optype_adddigest\').checked=\'checked\'"> '.$lang['threads_remove'].' &nbsp; &nbsp;<input class="radio" type="radio" name="digest_level" value="1" onclick="$(\'optype_adddigest\').checked=\'checked\'"> '.$lang['threads_digest_one'].' &nbsp; &nbsp;<input class="radio" type="radio" name="digest_level" value="2" onclick="$(\'optype_adddigest\').checked=\'checked\'"> '.$lang['threads_digest_two'].' &nbsp; &nbsp;<input class="radio" type="radio" name="digest_level" value="3" onclick="$(\'optype_adddigest\').checked=\'checked\'"> '.$lang['threads_digest_three']
  308. ));
  309. showtablerow('', array('class="td25"', 'class="td24"', 'class="rowform" style="width:auto;"'), array(
  310. '<input class="radio" type="radio" name="optype" value="deleteattach" onclick="this.form.modsubmit.disabled=false;">',
  311. $lang['threads_delete_attach'],
  312. ''
  313. ));
  314. }
  315. showsubmit('modsubmit', 'submit', '', '', $multi);
  316. showtablefooter();
  317. showformfooter();
  318. echo '<iframe name="threadframe" style="display:none"></iframe>';
  319. showtagfooter('div');
  320. }
  321. } else {
  322. $tidsarray = isset($_GET['tids']) ? explode(',', $_GET['tids']) : $_GET['tidarray'];
  323. $tidsadd = 'tid IN ('.dimplode($tidsarray).')';
  324. if($optype == 'moveforum') {
  325. if(!C::t('forum_forum')->check_forum_exists($_GET['toforum'])) {
  326. cpmsg('threads_move_invalid', '', 'error');
  327. }
  328. C::t('forum_thread')->update($tidsarray, array('fid'=>$_GET['toforum'], 'typeid'=>$_GET['threadtypeid'], 'isgroup'=>0));
  329. loadcache('posttableids');
  330. $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
  331. foreach($posttableids as $id) {
  332. C::t('forum_post')->update_by_tid($id, $tidsarray, array('fid' => $_GET['toforum']));
  333. }
  334. foreach(explode(',', $_GET['fids'].','.$_GET['toforum']) as $fid) {
  335. updateforumcount(intval($fid));
  336. }
  337. $log_handler = Cloud::loadClass('Cloud_Service_SearchHelper');
  338. foreach($_GET['tidarray'] as $tid) {
  339. $log_handler->myThreadLog('move', array('tid' => $tid, 'otherid' => $_GET['toforum']));
  340. }
  341. $cpmsg = cplang('threads_succeed');
  342. } elseif($optype == 'movesort') {
  343. if($_GET['tosort'] != 0) {
  344. if(!C::t('forum_threadtype')->fetch($_GET['tosort'])) {
  345. cpmsg('threads_move_invalid', '', 'error');
  346. }
  347. }
  348. C::t('forum_thread')->update($tidsarray, array('sortid'=>$_GET['tosort']));
  349. $cpmsg = cplang('threads_succeed');
  350. } elseif($optype == 'delete') {
  351. require_once libfile('function/delete');
  352. deletethread($tidsarray, !$_GET['donotupdatemember'], !$_GET['donotupdatemember']);
  353. if($_G['setting']['globalstick']) {
  354. updatecache('globalstick');
  355. }
  356. foreach(explode(',', $_GET['fids']) as $fid) {
  357. updateforumcount(intval($fid));
  358. }
  359. $log_handler = Cloud::loadClass('Cloud_Service_SearchHelper');
  360. foreach($_GET['tidarray'] as $tid) {
  361. $log_handler->myThreadLog('delete', array('tid' => $tid));
  362. }
  363. $cpmsg = cplang('threads_succeed');
  364. } elseif($optype == 'deleteattach') {
  365. require_once libfile('function/delete');
  366. deleteattach($tidsarray, 'tid');
  367. C::t('forum_thread')->update($tidsarray, array('attachment'=>0));
  368. loadcache('posttableids');
  369. $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
  370. foreach($posttableids as $id) {
  371. C::t('forum_post')->update_by_tid($id, $tidsarray, array('attachment' => '0'));
  372. }
  373. $cpmsg = cplang('threads_succeed');
  374. } elseif($optype == 'stick') {
  375. C::t('forum_thread')->update($tidsarray, array('displayorder'=>$_GET['stick_level']));
  376. $my_act = $_GET['stick_level'] ? 'sticky' : 'update';
  377. $log_handler = Cloud::loadClass('Cloud_Service_SearchHelper');
  378. foreach($_GET['tidarray'] as $tid) {
  379. $log_handler->myThreadLog($my_act, array('tid' => $tid));
  380. }
  381. if($_G['setting']['globalstick']) {
  382. updatecache('globalstick');
  383. }
  384. $cpmsg = cplang('threads_succeed');
  385. } elseif($optype == 'adddigest') {
  386. foreach(C::t('forum_thread')->fetch_all_by_tid($tidsarray) as $thread) {
  387. if($_GET['digest_level'] == $thread['digest']) continue;
  388. $extsql = array();
  389. if($_GET['digest_level'] > 0 && $thread['digest'] == 0) {
  390. $extsql = array('digestposts' => 1);
  391. }
  392. if($_GET['digest_level'] == 0 && $thread['digest'] > 0) {
  393. $extsql = array('digestposts' => -1);
  394. }
  395. updatecreditbyaction('digest', $thread['authorid'], $extsql, '', $_GET['digest_level'] - $thread['digest'], 1, $thread['fid']);
  396. }
  397. C::t('forum_thread')->update($tidsarray, array('digest'=>$_GET['digest_level']));
  398. $my_act = $_GET['digest_level'] ? 'digest' : 'update';
  399. $log_handler = Cloud::loadClass('Cloud_Service_SearchHelper');
  400. foreach($_GET['tidarray'] as $tid) {
  401. $log_handler->myThreadLog($my_act, array('tid' => $tid));
  402. }
  403. $cpmsg = cplang('threads_succeed');
  404. } elseif($optype == 'addstatus') {
  405. C::t('forum_thread')->update($tidsarray, array('closed'=>$_GET['status']));
  406. $my_opt = $_GET['status'] ? 'close' : 'open';
  407. $log_handler = Cloud::loadClass('Cloud_Service_SearchHelper');
  408. foreach($_GET['tidarray'] as $tid) {
  409. $log_handler->myThreadLog($my_opt, array('tid' => $tid));
  410. }
  411. $cpmsg = cplang('threads_succeed');
  412. } elseif($operation == 'forumstick') {
  413. shownav('topic', 'threads_forumstick');
  414. loadcache(array('forums', 'grouptype'));
  415. $forumstickthreads = C::t('common_setting')->fetch('forumstickthreads', true);
  416. if(!submitcheck('forumsticksubmit')) {
  417. showsubmenu('threads_forumstick', array(
  418. array('admin', 'threads&operation=forumstick', !$do),
  419. array('add', 'threads&operation=forumstick&do=add', $do == 'add'),
  420. ));
  421. showtips('threads_forumstick_tips');
  422. if(!$do) {
  423. showformheader('threads&operation=forumstick');
  424. showtableheader('admin', 'fixpadding');
  425. showsubtitle(array('', 'subject', 'threads_forumstick_forum', 'threads_forumstick_group', 'edit'));
  426. if(is_array($forumstickthreads)) {
  427. foreach($forumstickthreads as $k => $v) {
  428. $forumnames = array();
  429. foreach($v['forums'] as $forum_id){
  430. if($_G['cache']['forums'][$forum_id]['name']) {
  431. $forumnames[] = $name = $_G['cache']['forums'][$forum_id]['name'];
  432. } elseif($_G['cache']['grouptype']['first'][$forum_id]['name']) {
  433. $grouptypes[] = $name = $_G['cache']['grouptype']['first'][$forum_id]['name'];
  434. } elseif($_G['cache']['grouptype']['second'][$forum_id]['name']) {
  435. $grouptypes[] = $name = $_G['cache']['grouptype']['second'][$forum_id]['name'];
  436. }
  437. }
  438. showtablerow('', array('class="td25"'), array(
  439. "<input type=\"checkbox\" class=\"checkbox\" name=\"delete[]\" value=\"$k\">",
  440. "<a href=\"forum.php?mod=viewthread&tid=$v[tid]\" target=\"_blank\">$v[subject]</a>",
  441. implode(', ', $forumnames),
  442. implode(', ', $grouptypes),
  443. "<a href=\"".ADMINSCRIPT."?action=threads&operation=forumstick&do=edit&id=$k\">$lang[threads_forumstick_targets_change]</a>",
  444. ));
  445. }
  446. }
  447. showsubmit('forumsticksubmit', 'submit', 'del');
  448. showtablefooter();
  449. showformfooter();
  450. } elseif($do == 'add') {
  451. require_once libfile('function/forumlist');
  452. showformheader('threads&operation=forumstick&do=add');
  453. showtableheader('add', 'fixpadding');
  454. showsetting('threads_forumstick_threadurl', 'forumstick_url', '', 'text');
  455. $targetsselect = '<select name="forumsticktargets[]" size="10" multiple="multiple">'.forumselect(FALSE, 0, 0, TRUE).'</select>';
  456. require_once libfile('function/group');
  457. $groupselect = '<select name="forumsticktargets[]" size="10" multiple="multiple">'.get_groupselect(0, 0, 0).'</select>';
  458. showsetting('threads_forumstick_targets', '', '', $targetsselect);
  459. showsetting('threads_forumstick_targetgroups', '', '', $groupselect);
  460. echo '<input type="hidden" value="add" name="do" />';
  461. showsubmit('forumsticksubmit', 'submit');
  462. showtablefooter();
  463. showformfooter();
  464. } elseif($do == 'edit') {
  465. require_once libfile('function/forumlist');
  466. showformheader("threads&operation=forumstick&do=edit&id={$_GET['id']}");
  467. showtableheader('edit', 'fixpadding');
  468. $targetsselect = '<select name="forumsticktargets[]" size="10" multiple="multiple">'.forumselect(FALSE, 0, 0, TRUE).'</select>';
  469. require_once libfile('function/group');
  470. $groupselect = '<select name="forumsticktargets[]" size="10" multiple="multiple">'.get_groupselect(0, 0, 0).'</select>';
  471. foreach($forumstickthreads[$_GET['id']]['forums'] as $target) {
  472. $targetsselect = preg_replace("/(\<option value=\"$target\")([^\>]*)(\>)/", "\\1 \\2 selected=\"selected\" \\3", $targetsselect);
  473. $groupselect = preg_replace("/(\<option value=\"$target\")([^\>]*)(\>)/", "\\1 \\2 selected=\"selected\" \\3", $groupselect);
  474. }
  475. showsetting('threads_forumstick_targets', '', '', $targetsselect);
  476. showsetting('threads_forumstick_targetgroups', '', '', $groupselect);
  477. echo '<input type="hidden" value="edit" name="do" />';
  478. echo "<input type=\"hidden\" value=\"{$_GET['id']}\" name=\"id\" />";
  479. showsubmit('forumsticksubmit', 'submit');
  480. showtablefooter();
  481. showformfooter();
  482. }
  483. } else {
  484. if(!$do) {
  485. $do = 'del';
  486. }
  487. if($do == 'del') {
  488. if(!empty($_GET['delete']) && is_array($_GET['delete'])) {
  489. $del_tids = array();
  490. foreach($_GET['delete'] as $del_tid){
  491. unset($forumstickthreads[$del_tid]);
  492. $del_tids[] = $del_tid;
  493. }
  494. if($del_tids) {
  495. C::t('forum_thread')->update($del_tids, array('displayorder'=>0));
  496. }
  497. } else {
  498. cpmsg('threads_forumstick_del_nochoice', '', 'error');
  499. }
  500. } elseif($do == 'add') {
  501. $_GET['forumstick_url'] = rawurldecode($_GET['forumstick_url']);
  502. if(preg_match('/tid=(\d+)/i', $_GET['forumstick_url'], $matches)) {
  503. $forumstick_tid = $matches[1];
  504. } elseif(in_array('forum_viewthread', $_G['setting']['rewritestatus']) && $_G['setting']['rewriterule']['forum_viewthread']) {
  505. preg_match_all('/(\{tid\})|(\{page\})|(\{prevpage\})/', $_G['setting']['rewriterule']['forum_viewthread'], $matches);
  506. $matches = $matches[0];
  507. $tidpos = array_search('{tid}', $matches);
  508. if($tidpos === false) {
  509. cpmsg('threads_forumstick_url_invalid', "action=threads&operation=forumstick&do=add", 'error');
  510. }
  511. $tidpos = $tidpos + 1;
  512. $rewriterule = str_replace(
  513. array('\\', '(', ')', '[', ']', '.', '*', '?', '+'),
  514. array('\\\\', '\(', '\)', '\[', '\]', '\.', '\*', '\?', '\+'),
  515. $_G['setting']['rewriterule']['forum_viewthread']
  516. );
  517. $rewriterule = str_replace(array('{tid}', '{page}', '{prevpage}'), '(\d+?)', $rewriterule);
  518. $rewriterule = str_replace(array('{', '}'), array('\{', '\}'), $rewriterule);
  519. preg_match("/$rewriterule/i", $_GET['forumstick_url'], $match_result);
  520. $forumstick_tid = $match_result[$tidpos];
  521. } elseif(in_array('all_script', $_G['setting']['rewritestatus']) && $_G['setting']['rewriterule']['all_script']) {
  522. preg_match_all('/(\{script\})|(\{param\})/', $_G['setting']['rewriterule']['all_script'], $matches);
  523. $matches = $matches[0];
  524. $parampos = array_search('{param}', $matches);
  525. if($parampos === false) {
  526. cpmsg('threads_forumstick_url_invalid', "action=threads&operation=forumstick&do=add", 'error');
  527. }
  528. $parampos = $parampos + 1;
  529. $rewriterule = str_replace(
  530. array('\\', '(', ')', '[', ']', '.', '*', '?', '+'),
  531. array('\\\\', '\(', '\)', '\[', '\]', '\.', '\*', '\?', '\+'),
  532. $_G['setting']['rewriterule']['all_script']
  533. );
  534. $rewriterule = str_replace(array('{script}', '{param}'), '([\w\d\-=]+?)', $rewriterule);
  535. $rewriterule = str_replace(array('{', '}'), array('\{', '\}'), $rewriterule);
  536. $rewriterule = "/\\/$rewriterule/i";
  537. preg_match($rewriterule, $_GET['forumstick_url'], $match_result);
  538. $param = $match_result[$parampos];
  539. if(preg_match('/viewthread-tid-(\d+)/i', $param, $tidmatch)) {
  540. $forumstick_tid = $tidmatch[1];
  541. } else {
  542. cpmsg('threads_forumstick_url_invalid', "action=threads&operation=forumstick&do=add", 'error');
  543. }
  544. } else {
  545. cpmsg('threads_forumstick_url_invalid', "action=threads&operation=forumstick&do=add", 'error');
  546. }
  547. if(empty($_GET['forumsticktargets'])) {
  548. cpmsg('threads_forumstick_targets_empty', "action=threads&operation=forumstick&do=add", 'error');
  549. }
  550. $stickthread = C::t('forum_thread')->fetch($forumstick_tid);
  551. $stickthread_tmp = array(
  552. 'subject' => $stickthread['subject'],
  553. 'tid' => $forumstick_tid,
  554. 'forums' => $_GET['forumsticktargets'],
  555. );
  556. $forumstickthreads[$forumstick_tid] = $stickthread_tmp;
  557. C::t('forum_thread')->update($forumstick_tid, array('displayorder'=>4));
  558. } elseif($do == 'edit') {
  559. if(empty($_GET['forumsticktargets'])) {
  560. cpmsg('threads_forumstick_targets_empty', "action=threads&operation=forumstick&do=edit&id={$_GET['id']}", 'error');
  561. }
  562. $forumstickthreads[$_GET['id']]['forums'] = $_GET['forumsticktargets'];
  563. C::t('forum_thread')->update($forumstick_tid, array('displayorder'=>4));
  564. }
  565. C::t('common_setting')->update('forumstickthreads', $forumstickthreads);
  566. updatecache(array('forumstick', 'setting'));
  567. cpmsg('threads_forumstick_'.$do.'_succeed', "action=threads&operation=forumstick", 'succeed');
  568. }
  569. }
  570. $_GET['tids'] && deletethreadcaches($_GET['tids']);
  571. $cpmsg = $cpmsg ? "alert('$cpmsg');" : '';
  572. echo '<script type="text/JavaScript">'.$cpmsg.'if(parent.$(\'threadforum\')) parent.$(\'threadforum\').searchsubmit.click();</script>';
  573. }
  574. function delete_position($select) {
  575. if(empty($select) || !is_array($select)) {
  576. cpmsg('select_thread_empty', '', 'error');
  577. }
  578. $tids = dimplode($select);
  579. C::t('forum_postposition')->delete_by_tid($select);
  580. C::t('forum_thread')->update_status_by_tid($tids, '1111111111111110', '&');
  581. }
  582. ?>