admincp_threadsplit.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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_threadsplit.php 29236 2012-03-30 05:34:47Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. @set_time_limit(0);
  12. define('IN_DEBUG', false);
  13. define('MAX_THREADS_MOVE', 100);
  14. cpheader();
  15. $topicperpage = 50;
  16. if(empty($operation)) {
  17. $operation = 'manage';
  18. }
  19. $settings = C::t('common_setting')->fetch_all(array('threadtableids', 'threadtable_info'), true);
  20. $threadtableids = $settings['threadtableids'] ? $settings['threadtableids'] : array();
  21. $threadtable_info = $settings['threadtable_info'] ? $settings['threadtable_info'] : array();
  22. if($operation == 'manage') {
  23. shownav('founder', 'nav_threadsplit');
  24. if(!submitcheck('threadsplit_update_submit')) {
  25. showsubmenu('nav_threadsplit', array(
  26. array('nav_threadsplit_manage', 'threadsplit&operation=manage', 1),
  27. array('nav_threadsplit_move', 'threadsplit&operation=move', 0),
  28. ));
  29. showtips('threadsplit_manage_tips');
  30. showformheader('threadsplit&operation=manage');
  31. showtableheader('threadsplit_manage_table_orig');
  32. $thread_table_orig = C::t('forum_thread')->gettablestatus();
  33. showsubtitle(array('threadsplit_manage_tablename', 'threadsplit_manage_threadcount', 'threadsplit_manage_datalength', 'threadsplit_manage_indexlength', 'threadsplit_manage_table_createtime', 'threadsplit_manage_table_memo', ''));
  34. showtablerow('', array(), array($thread_table_orig['Name'], $thread_table_orig['Rows'], $thread_table_orig['Data_length'], $thread_table_orig['Index_length'], $thread_table_orig['Create_time'], "<input type=\"text\" class=\"txt\" name=\"memo[0]\" value=\"{$threadtable_info[0]['memo']}\" />", ''));
  35. showtableheader('threadsplit_manage_table_archive');
  36. showsubtitle(array('threadsplit_manage_tablename', 'threadsplit_manage_dislayname', 'threadsplit_manage_threadcount', 'threadsplit_manage_datalength', 'threadsplit_manage_indexlength', 'threadsplit_manage_table_createtime', 'threadsplit_manage_table_memo', ''));
  37. foreach($threadtableids as $tableid) {
  38. if(!$tableid) {
  39. continue;
  40. }
  41. $tablename = "forum_thread_$tableid";
  42. $table_info = C::t('forum_thread')->gettablestatus($tableid);
  43. showtablerow('', array(), array($table_info['Name'], "<input type=\"text\" class=\"txt\" name=\"displayname[$tableid]\" value=\"{$threadtable_info[$tableid]['displayname']}\" />", $table_info['Rows'], $table_info['Data_length'], $table_info['Index_length'], $table_info['Create_time'], "<input type=\"text\" class=\"txt\" name=\"memo[$tableid]\" value=\"{$threadtable_info[$tableid]['memo']}\" />", "<a href=\"?action=threadsplit&operation=droptable&tableid=$tableid\">{$lang['delete']}</a>"));
  44. }
  45. showtablefooter();
  46. showsubmit('threadsplit_update_submit', 'threadsplit_manage_update', '', '<a href="?action=threadsplit&operation=addnewtable" style="border-style: solid; border-width: 1px;" class="btn">'.$lang['threadsplit_manage_table_add'].'</a>&nbsp;<a href="?action=threadsplit&operation=forumarchive" style="border-style: solid; border-width: 1px;" class="btn">'.$lang['threadsplit_manage_forum_update'].'</a>');
  47. showformfooter();
  48. } else {
  49. $threadtable_info = array();
  50. $_GET['memo'] = !empty($_GET['memo']) ? $_GET['memo'] : array();
  51. $_GET['displayname'] = !empty($_GET['displayname']) ? $_GET['displayname'] : array();
  52. foreach(array_keys($_GET['memo']) as $tableid) {
  53. $threadtable_info[$tableid]['memo'] = $_GET['memo'][$tableid];
  54. }
  55. foreach(array_keys($_GET['displayname']) as $tableid) {
  56. $threadtable_info[$tableid]['displayname'] = $_GET['displayname'][$tableid];
  57. }
  58. C::t('common_setting')->update('threadtable_info', $threadtable_info);
  59. savecache('threadtable_info', $threadtable_info);
  60. update_threadtableids();
  61. updatecache('setting');
  62. cpmsg('threadsplit_manage_update_succeed', 'action=threadsplit&operation=manage', 'succeed');
  63. }
  64. } elseif($operation == 'addnewtable') {
  65. if(empty($threadtableids)) {
  66. $maxtableid = 0;
  67. } else {
  68. $maxtableid = max($threadtableids);
  69. }
  70. C::t('forum_thread')->create_table($maxtableid + 1);
  71. update_threadtableids();
  72. updatecache('setting');
  73. cpmsg('threadsplit_table_create_succeed', 'action=threadsplit&operation=manage', 'succeed');
  74. } elseif($operation == 'droptable') {
  75. $tableid = intval($_GET['tableid']);
  76. $tablename = "forum_thread_$tableid";
  77. $table_info = C::t('forum_thread')->gettablestatus($tableid);
  78. if(!$tableid || !$table_info) {
  79. cpmsg('threadsplit_table_no_exists', 'action=threadsplit&operation=manage', 'error');
  80. }
  81. if($table_info['Rows'] > 0) {
  82. cpmsg('threadsplit_drop_table_no_empty_error', 'action=threadsplit&operation=manage', 'error');
  83. }
  84. C::t('forum_thread')->drop_table($tableid);
  85. unset($threadtable_info[$tableid]);
  86. update_threadtableids();
  87. C::t('common_setting')->update('threadtable_info', $threadtable_info);
  88. savecache('threadtable_info', $threadtable_info);
  89. updatecache('setting');
  90. cpmsg('threadsplit_drop_table_succeed', 'action=threadsplit&operation=manage', 'succeed');
  91. } elseif($operation == 'move') {
  92. if(!$_G['setting']['bbclosed'] && !IN_DEBUG) {
  93. cpmsg('threadsplit_forum_must_be_closed', 'action=threadsplit&operation=manage', 'error');
  94. }
  95. require_once libfile('function/forumlist');
  96. $tableselect = '<select name="sourcetableid">';
  97. foreach($threadtableids as $tableid) {
  98. $selected = $_GET['sourcetableid'] == $tableid ? 'selected="selected"' : '';
  99. $tableselect .= "<option value=\"$tableid\" $selected>".C::t('forum_thread')->get_table_name($tableid)."</option>";
  100. }
  101. $tableselect .= '</select>';
  102. $forumselect = '<select name="inforum"><option value="all">&nbsp;&nbsp;> '.$lang['all'].'</option>'.
  103. '<option value="">&nbsp;</option>'.forumselect(FALSE, 0, 0, TRUE).'</select>';
  104. if(isset($_GET['inforum'])) {
  105. $forumselect = preg_replace("/(\<option value=\"{$_GET['inforum']}\")(\>)/", "\\1 selected=\"selected\" \\2", $forumselect);
  106. }
  107. $typeselect = $sortselect = '';
  108. $query = C::t('forum_threadtype')->fetch_all_for_order();
  109. foreach($query as $type) {
  110. if($type['special']) {
  111. $sortselect .= '<option value="'.$type['typeid'].'">&nbsp;&nbsp;> '.$type['name'].'</option>';
  112. } else {
  113. $typeselect .= '<option value="'.$type['typeid'].'">&nbsp;&nbsp;> '.$type['name'].'</option>';
  114. }
  115. }
  116. if(isset($_GET['insort'])) {
  117. $sortselect = preg_replace("/(\<option value=\"{$_GET['insort']}\")(\>)/", "\\1 selected=\"selected\" \\2", $sortselect);
  118. }
  119. if(isset($_GET['intype'])) {
  120. $typeselect = preg_replace("/(\<option value=\"{$_GET['intype']}\")(\>)/", "\\1 selected=\"selected\" \\2", $typeselect);
  121. }
  122. echo <<<EOT
  123. <script src="static/js/calendar.js"></script>
  124. <script type="text/JavaScript">
  125. function page(number) {
  126. $('threadform').page.value=number;
  127. $('threadform').threadsplit_move_search.click();
  128. }
  129. </script>
  130. EOT;
  131. shownav('founder', 'nav_threadsplit');
  132. if(!submitcheck('threadsplit_move_submit') && !$_GET['moving']) {
  133. showsubmenu('nav_threadsplit', array(
  134. array('nav_threadsplit_manage', 'threadsplit&operation=manage', 0),
  135. array('nav_threadsplit_move', 'threadsplit&operation=move', 1),
  136. ));
  137. showtips('threadsplit_move_tips');
  138. showtagheader('div', 'threadsearch', !submitcheck('threadsplit_move_search'));
  139. showformheader('threadsplit&operation=move', '', 'threadform');
  140. showhiddenfields(array('page' => $_GET['page']));
  141. showtableheader();
  142. showsetting('threads_search_detail', 'detail', $_GET['detail'], 'radio');
  143. showsetting('threads_search_sourcetable', '', '', $tableselect);
  144. showsetting('threads_search_forum', '', '', $forumselect);
  145. showsetting('threadsplit_move_tidrange', array('tidmin', 'tidmax'), array($_GET['tidmin'], $_GET['tidmax']), 'range');
  146. showsetting('threads_search_noreplyday', 'noreplydays', isset($_GET['noreplydays']) ? $_GET['noreplydays'] : 365, 'text');
  147. showtagheader('tbody', 'advanceoption');
  148. showsetting('threads_search_time', array('starttime', 'endtime'), array($_GET['starttime'], $_GET['endtime']), 'daterange');
  149. showsetting('threads_search_type', '', '', '<select name="intype"><option value="all">&nbsp;&nbsp;> '.$lang['all'].'</option><option value="">&nbsp;</option><option value="0">&nbsp;&nbsp;> '.$lang['threads_search_type_none'].'</option>'.$typeselect.'</select>');
  150. 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>');
  151. showsetting('threads_search_viewrange', array('viewsmore', 'viewsless'), array($_GET['viewsmore'], $_GET['viewsless']), 'range');
  152. showsetting('threads_search_replyrange', array('repliesmore', 'repliesless'), array($_GET['repliesmore'], $_GET['repliesless']), 'range');
  153. showsetting('threads_search_readpermmore', 'readpermmore', $_GET['readpermmore'], 'text');
  154. showsetting('threads_search_pricemore', 'pricemore', $_GET['pricemore'], 'text');
  155. showsetting('threads_search_keyword', 'keywords', $_GET['keywords'], 'text');
  156. showsetting('threads_search_user', 'users', $_GET['users'], 'text');
  157. showsetting('threads_search_type', array('specialthread', array(
  158. array(0, cplang('unlimited'), array('showspecial' => 'none')),
  159. array(1, cplang('threads_search_include_yes'), array('showspecial' => '')),
  160. array(2, cplang('threads_search_include_no'), array('showspecial' => '')),
  161. ), TRUE), isset($_GET['specialthread']) ? $_GET['specialthread'] : 2, 'mradio');
  162. showtablerow('id="showspecial" style="display:'.($_GET['specialthread'] || !isset($_GET['specialthread']) ? '' : 'none').'"', 'class="sub" colspan="2"', mcheckbox('special', array(
  163. 1 => cplang('thread_poll'),
  164. 2 => cplang('thread_trade'),
  165. 3 => cplang('thread_reward'),
  166. 4 => cplang('thread_activity'),
  167. 5 => cplang('thread_debate')
  168. ), $_GET['special'] ? $_GET['special'] : array(1,2,3,4,5)));
  169. showsetting('threads_search_sticky', array('sticky', array(
  170. array(0, cplang('unlimited')),
  171. array(1, cplang('threads_search_include_yes')),
  172. array(2, cplang('threads_search_include_no')),
  173. ), TRUE), isset($_GET['sticky']) ? $_GET['sticky'] : 2, 'mradio');
  174. showsetting('threads_search_digest', array('digest', array(
  175. array(0, cplang('unlimited')),
  176. array(1, cplang('threads_search_include_yes')),
  177. array(2, cplang('threads_search_include_no')),
  178. ), TRUE), isset($_GET['digest']) ? $_GET['digest'] : 2, 'mradio');
  179. showsetting('threads_search_attach', array('attach', array(
  180. array(0, cplang('unlimited')),
  181. array(1, cplang('threads_search_include_yes')),
  182. array(2, cplang('threads_search_include_no')),
  183. ), TRUE), isset($_GET['attach']) ? $_GET['attach'] : 0, 'mradio');
  184. showsetting('threads_rate', array('rate', array(
  185. array(0, cplang('unlimited')),
  186. array(1, cplang('threads_search_include_yes')),
  187. array(2, cplang('threads_search_include_no')),
  188. ), TRUE), isset($_GET['rate']) ? $_GET['rate'] : 2, 'mradio');
  189. showsetting('threads_highlight', array('highlight', array(
  190. array(0, cplang('unlimited')),
  191. array(1, cplang('threads_search_include_yes')),
  192. array(2, cplang('threads_search_include_no')),
  193. ), TRUE), isset($_GET['highlight']) ? $_GET['highlight'] : 2, 'mradio');
  194. showtagfooter('tbody');
  195. showsubmit('threadsplit_move_search', 'submit', '', 'more_options');
  196. showtablefooter();
  197. showformfooter();
  198. showtagfooter('div');
  199. if(submitcheck('threadsplit_move_search')) {
  200. $searchurladd = array();
  201. $conditions = array(
  202. 'sourcetableid' => $_GET['sourcetableid'],
  203. 'inforum' => $_GET['inforum'],
  204. 'tidmin' => $_GET['tidmin'],
  205. 'tidmax' => $_GET['tidmax'],
  206. 'starttime' => $_GET['starttime'],
  207. 'endtime' => $_GET['endtime'],
  208. 'keywords' => $_GET['keywords'],
  209. 'users' => $_GET['users'],
  210. 'intype' => $_GET['intype'],
  211. 'insort' => $_GET['insort'],
  212. 'viewsmore' => $_GET['viewsmore'],
  213. 'viewsless' => $_GET['viewsless'],
  214. 'repliesmore' => $_GET['repliesmore'],
  215. 'repliesless' => $_GET['repliesless'],
  216. 'readpermmore' => $_GET['readpermmore'],
  217. 'pricemore' => $_GET['pricemore'],
  218. 'noreplydays' => $_GET['noreplydays'],
  219. 'specialthread' => $_GET['specialthread'],
  220. 'special' => $_GET['special'],
  221. 'sticky' => $_GET['sticky'],
  222. 'digest' => $_GET['digest'],
  223. 'attach' => $_GET['attach'],
  224. 'rate' => $_GET['rate'],
  225. 'highlight' => $_GET['highlight'],
  226. );
  227. if($_GET['detail']) {
  228. $pagetmp = $page;
  229. $threadlist = threadsplit_search_threads($conditions, ($pagetmp - 1) * $topicperpage, $topicperpage);
  230. } else {
  231. $threadtomove = threadsplit_search_threads($conditions, null, null, TRUE);
  232. }
  233. $fids = array();
  234. $tids = '0';
  235. if($_GET['detail']) {
  236. $threads = '';
  237. foreach($threadlist as $thread) {
  238. $fids[] = $thread['fid'];
  239. $thread['lastpost'] = dgmdate($thread['lastpost']);
  240. $threads .= showtablerow('', array('class="td25"', '', '', '', '', ''), array(
  241. "<input class=\"checkbox\" type=\"checkbox\" name=\"tidarray[]\" value=\"$thread[tid]\" checked=\"checked\" />",
  242. "<a href=\"forum.php?mod=viewthread&tid=$thread[tid]\" target=\"_blank\">$thread[subject]</a>",
  243. "<a href=\"forum.php?mod=forumdisplay&fid=$thread[fid]\" target=\"_blank\">{$_G['cache'][forums][$thread[fid]][name]}</a>",
  244. "<a href=\"home.php?mod=space&uid=$thread[authorid]\" target=\"_blank\">$thread[author]</a>",
  245. $thread['replies'],
  246. $thread['views']
  247. ), TRUE);
  248. }
  249. $multi = multi($threadcount, $topicperpage, $page, ADMINSCRIPT."?action=threadsplit&amp;operation=move");
  250. $multi = preg_replace("/href=\"".ADMINSCRIPT."\?action=threadsplit&amp;operation=move&amp;page=(\d+)\"/", "href=\"javascript:page(\\1)\"", $multi);
  251. $multi = str_replace("window.location='".ADMINSCRIPT."?action=threadsplit&amp;operation=move&amp;page='+this.value", "page(this.value)", $multi);
  252. } else {
  253. foreach($threadlist as $thread) {
  254. $fids[] = $thread['fid'];
  255. $tids .= ','.$thread['tid'];
  256. }
  257. $multi = '';
  258. }
  259. $fids = implode(',', array_unique($fids));
  260. showtagheader('div', 'threadlist', TRUE);
  261. showformheader("threadsplit&operation=move&sourcetableid={$_GET['sourcetableid']}&threadtomove=".$threadtomove);
  262. showhiddenfields($_GET['detail'] ? array('fids' => $fids) : array('conditions' => serialize($conditions)));
  263. showtableheader(cplang('threads_result').' '.$threadcount.' <a href="###" onclick="$(\'threadlist\').style.display=\'none\';$(\'threadsearch\').style.display=\'\';" class="act lightlink normal">'.cplang('research').'</a>', 'nobottom');
  264. showsubtitle(array('', 'threadsplit_move_to', 'threadsplit_manage_threadcount', 'threadsplit_manage_datalength', 'threadsplit_manage_indexlength', 'threadsplit_manage_table_createtime', 'threadsplit_manage_table_memo'));
  265. if(!$threadcount) {
  266. showtablerow('', 'colspan="3"', cplang('threads_thread_nonexistence'));
  267. } else {
  268. $threadtable_orig = C::t('forum_thread')->gettablestatus();
  269. $tableid = 0;
  270. showtablerow('', array('class="td25"'), array("<input class=\"radio\" ".($_GET['sourcetableid'] == '0' ? 'disabled="disabled"' : '')." type=\"radio\" name=\"tableid\" value=\"0\" />", $threadtable_orig['Name'], $threadtable_orig['Rows'], $threadtable_orig['Data_length'], $threadtable_orig['Index_length'], $threadtable_orig['Create_time'], $threadtable_info[0]['memo']));
  271. foreach($threadtableids as $tableid) {
  272. if($tableid) {
  273. $tablename = "forum_thread_$tableid";
  274. $tablestatus = C::t('forum_thread')->gettablestatus($tableid);
  275. showtablerow('', array(), array("<input class=\"radio\" ".($_GET['sourcetableid'] == $tableid ? 'disabled="disabled"' : '')." type=\"radio\" name=\"tableid\" value=\"$tableid\" />", $tablestatus['Name'].($threadtable_info[$tableid]['displayname'] ? " (".dhtmlspecialchars($threadtable_info[$tableid]['displayname']).")" : ''), $tablestatus['Rows'], $tablestatus['Data_length'], $tablestatus['Index_length'], $tablestatus['Create_time'], $threadtable_info[$tableid]['memo']));
  276. }
  277. }
  278. if($_GET['detail']) {
  279. showtablefooter();
  280. showtableheader('threads_list', 'notop');
  281. showsubtitle(array('', 'subject', 'forum', 'author', 'threads_replies', 'threads_views'));
  282. echo $threads;
  283. }
  284. }
  285. showtablefooter();
  286. if($threadcount) {
  287. showtableheader('');
  288. showsetting('threadsplit_move_threads_per_time', 'threads_per_time', 200, 'text');
  289. showtablefooter();
  290. showsubmit('threadsplit_move_submit', 'submit', $_GET['detail'] ? '<input name="chkall" id="chkall" type="checkbox" class="checkbox" checked="checked" onclick="checkAll(\'prefix\', this.form, \'tidarray\', \'chkall\')" /><label for="chkall">'.cplang('select_all').'</label>' : '', '', $multi);
  291. }
  292. showformfooter();
  293. showtagfooter('div');
  294. }
  295. } else {
  296. if(!isset($_GET['tableid'])) {
  297. cpmsg('threadsplit_no_target_table', '', 'error');
  298. }
  299. $continue = false;
  300. $tidsarray = !empty($_GET['tidarray']) ? $_GET['tidarray'] : array();
  301. if(empty($tidsarray) && !empty($_GET['conditions'])) {
  302. $conditions = dunserialize($_GET['conditions']);
  303. $max_threads_move = intval($_GET['threads_per_time']) ? intval($_GET['threads_per_time']) : MAX_THREADS_MOVE;
  304. $threadlist = threadsplit_search_threads($conditions, 0, $max_threads_move);
  305. foreach($threadlist as $thread) {
  306. $tidsarray[] = $thread['tid'];
  307. $continue = TRUE;
  308. }
  309. }
  310. if(empty($tidsarray[0])) {
  311. array_shift($tidsarray);
  312. }
  313. if(!empty($tidsarray)) {
  314. $continue = true;
  315. }
  316. if($_GET['tableid'] == $_GET['sourcetableid']) {
  317. cpmsg('threadsplit_move_source_target_no_same', 'action=threadsplit&operation=move', 'error');
  318. }
  319. if($continue) {
  320. $threadtable_target = $_GET['tableid'] ? $_GET['tableid'] : 0;
  321. $threadtable_source = $_GET['sourcetableid'] ? $_GET['sourcetableid'] : 0;
  322. C::t('forum_thread')->move_thread_by_tid($tidsarray, $threadtable_source, $threadtable_target);
  323. C::t('forum_forumrecommend')->delete($tidsarray);
  324. $completed = intval($_GET['completed']) + count($tidsarray);
  325. $nextstep = $step + 1;
  326. cpmsg('threadsplit_moving', "action=threadsplit&operation=move&{$_GET['urladd']}&tableid={$_GET['tableid']}&completed=$completed&sourcetableid={$_GET['sourcetableid']}&threadtomove={$_GET['threadtomove']}&step=$nextstep&moving=1", 'loadingform', array('count' => $completed, 'total' => intval($_GET['threadtomove']), 'threads_per_time' => $_GET['threads_per_time'], 'conditions' => dhtmlspecialchars($_GET['conditions'])));
  327. }
  328. cpmsg('threadsplit_move_succeed', "action=threadsplit&operation=forumarchive", 'succeed');
  329. }
  330. } elseif($operation == 'forumarchive') {
  331. $step = intval($_GET['step']);
  332. $continue = false;
  333. if(isset($threadtableids[$step])) {
  334. $continue = true;
  335. }
  336. if($continue) {
  337. $threadtableid = $threadtableids[$step];
  338. C::t('forum_forum_threadtable')->update_by_threadtableid($threadtableid, array('threads' => '0', 'posts' => '0'));
  339. $threadtable = $threadtableid ? $threadtableid : 0;
  340. foreach(C::t('forum_thread')->count_group_by_fid($threadtable) as $row) {
  341. C::t('forum_forum_threadtable')->insert(array(
  342. 'fid' => $row['fid'],
  343. 'threadtableid' => $threadtableid,
  344. 'threads' => $row['threads'],
  345. 'posts' => $row['posts'],
  346. ), false, true);
  347. if($row['threads'] > 0) {
  348. C::t('forum_forum')->update($row['fid'], array('archive' => '1'));
  349. }
  350. }
  351. $nextstep = $step + 1;
  352. cpmsg('threadsplit_manage_forum_processing', "action=threadsplit&operation=forumarchive&step=$nextstep", 'loading', array('table' => DB::table($threadtable)));
  353. } else {
  354. C::t('forum_forum_threadtable')->delete_none_threads();
  355. $fids = array('0');
  356. foreach(C::t('forum_forum_threadtable')->range() as $row) {
  357. $fids[] = $row['fid'];
  358. }
  359. C::t('forum_forum')->update_archive($fids);
  360. cpmsg('threadsplit_manage_forum_complete', 'action=threadsplit&operation=manage', 'succeed');
  361. }
  362. }
  363. function threadsplit_search_threads($conditions, $offset = null, $length = null, $onlycount = FALSE) {
  364. global $_G, $searchurladd, $page, $threadcount;
  365. if($conditions) {
  366. $conditions = daddslashes($conditions);
  367. }
  368. $sql = '';
  369. $threadlist = array();
  370. $sql = C::t('forum_thread')->search_condition($conditions, 't');
  371. $searchurladd = C::t('forum_thread')->get_url_param();
  372. if($sql || $conditions['sourcetableid']) {
  373. $conditions['isgroup'] = 0;
  374. $tableid = $conditions['sourcetableid'] ? $conditions['sourcetableid'] : 0;
  375. $threadcount = C::t('forum_thread')->count_search($conditions, $tableid, 't');
  376. if(isset($offset) && isset($length)) {
  377. $sql .= " LIMIT $offset, $length";
  378. }
  379. if($onlycount) {
  380. return $threadcount;
  381. }
  382. if($threadcount) {
  383. foreach(C::t('forum_thread')->fetch_all_search($conditions, $tableid, $offset, $length) as $thread) {
  384. $thread['lastpost'] = dgmdate($thread['lastpost']);
  385. $threadlist[] = $thread;
  386. }
  387. }
  388. }
  389. return $threadlist;
  390. }
  391. function update_threadtableids() {
  392. $threadtableids = C::t('forum_thread')->fetch_thread_table_ids();
  393. C::t('common_setting')->update('threadtableids', $threadtableids);
  394. savecache('threadtableids', $threadtableids);
  395. }
  396. ?>