Recent.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. <?php
  2. /**
  3. * Find and retrieve information about recently posted topics, messages, and the like.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2012 Simple Machines contributors
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('Hacking attempt...');
  16. /**
  17. * Get the latest post made on the system
  18. *
  19. * - respects approved, recycled, and board permissions
  20. * - @todo is this even used anywhere?
  21. *
  22. * @return array
  23. */
  24. function getLastPost()
  25. {
  26. global $user_info, $scripturl, $modSettings, $smcFunc;
  27. // Find it by the board - better to order by board than sort the entire messages table.
  28. $request = $smcFunc['db_query']('substring', '
  29. SELECT ml.poster_time, ml.subject, ml.id_topic, ml.poster_name, SUBSTRING(ml.body, 1, 385) AS body,
  30. ml.smileys_enabled
  31. FROM {db_prefix}boards AS b
  32. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = b.id_last_msg)
  33. WHERE {query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  34. AND b.id_board != {int:recycle_board}' : '') . '
  35. AND ml.approved = {int:is_approved}
  36. ORDER BY b.id_msg_updated DESC
  37. LIMIT 1',
  38. array(
  39. 'recycle_board' => $modSettings['recycle_board'],
  40. 'is_approved' => 1,
  41. )
  42. );
  43. if ($smcFunc['db_num_rows']($request) == 0)
  44. return array();
  45. $row = $smcFunc['db_fetch_assoc']($request);
  46. $smcFunc['db_free_result']($request);
  47. // Censor the subject and post...
  48. censorText($row['subject']);
  49. censorText($row['body']);
  50. $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br />' => '&#10;')));
  51. if ($smcFunc['strlen']($row['body']) > 128)
  52. $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
  53. // Send the data.
  54. return array(
  55. 'topic' => $row['id_topic'],
  56. 'subject' => $row['subject'],
  57. 'short_subject' => shorten_subject($row['subject'], 24),
  58. 'preview' => $row['body'],
  59. 'time' => timeformat($row['poster_time']),
  60. 'timestamp' => forum_time(true, $row['poster_time']),
  61. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.new;topicseen#new',
  62. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.new;topicseen#new">' . $row['subject'] . '</a>'
  63. );
  64. }
  65. /**
  66. * Find the ten most recent posts.
  67. */
  68. function RecentPosts()
  69. {
  70. global $txt, $scripturl, $user_info, $context, $modSettings, $sourcedir, $board, $smcFunc;
  71. loadTemplate('Recent');
  72. $context['page_title'] = $txt['recent_posts'];
  73. if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95)
  74. $_REQUEST['start'] = 95;
  75. $query_parameters = array();
  76. if (!empty($_REQUEST['c']) && empty($board))
  77. {
  78. $_REQUEST['c'] = explode(',', $_REQUEST['c']);
  79. foreach ($_REQUEST['c'] as $i => $c)
  80. $_REQUEST['c'][$i] = (int) $c;
  81. if (count($_REQUEST['c']) == 1)
  82. {
  83. $request = $smcFunc['db_query']('', '
  84. SELECT name
  85. FROM {db_prefix}categories
  86. WHERE id_cat = {int:id_cat}
  87. LIMIT 1',
  88. array(
  89. 'id_cat' => $_REQUEST['c'][0],
  90. )
  91. );
  92. list ($name) = $smcFunc['db_fetch_row']($request);
  93. $smcFunc['db_free_result']($request);
  94. if (empty($name))
  95. fatal_lang_error('no_access', false);
  96. $context['linktree'][] = array(
  97. 'url' => $scripturl . '#c' . (int) $_REQUEST['c'],
  98. 'name' => $name
  99. );
  100. }
  101. $request = $smcFunc['db_query']('', '
  102. SELECT b.id_board, b.num_posts
  103. FROM {db_prefix}boards AS b
  104. WHERE b.id_cat IN ({array_int:category_list})
  105. AND {query_see_board}',
  106. array(
  107. 'category_list' => $_REQUEST['c'],
  108. )
  109. );
  110. $total_cat_posts = 0;
  111. $boards = array();
  112. while ($row = $smcFunc['db_fetch_assoc']($request))
  113. {
  114. $boards[] = $row['id_board'];
  115. $total_cat_posts += $row['num_posts'];
  116. }
  117. $smcFunc['db_free_result']($request);
  118. if (empty($boards))
  119. fatal_lang_error('error_no_boards_selected');
  120. $query_this_board = 'b.id_board IN ({array_int:boards})';
  121. $query_parameters['boards'] = $boards;
  122. // If this category has a significant number of posts in it...
  123. if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
  124. {
  125. $query_this_board .= '
  126. AND m.id_msg >= {int:max_id_msg}';
  127. $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 400 - $_REQUEST['start'] * 7);
  128. }
  129. $context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false);
  130. }
  131. elseif (!empty($_REQUEST['boards']))
  132. {
  133. $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
  134. foreach ($_REQUEST['boards'] as $i => $b)
  135. $_REQUEST['boards'][$i] = (int) $b;
  136. $request = $smcFunc['db_query']('', '
  137. SELECT b.id_board, b.num_posts
  138. FROM {db_prefix}boards AS b
  139. WHERE b.id_board IN ({array_int:board_list})
  140. AND {query_see_board}
  141. LIMIT {int:limit}',
  142. array(
  143. 'board_list' => $_REQUEST['boards'],
  144. 'limit' => count($_REQUEST['boards']),
  145. )
  146. );
  147. $total_posts = 0;
  148. $boards = array();
  149. while ($row = $smcFunc['db_fetch_assoc']($request))
  150. {
  151. $boards[] = $row['id_board'];
  152. $total_posts += $row['num_posts'];
  153. }
  154. $smcFunc['db_free_result']($request);
  155. if (empty($boards))
  156. fatal_lang_error('error_no_boards_selected');
  157. $query_this_board = 'b.id_board IN ({array_int:boards})';
  158. $query_parameters['boards'] = $boards;
  159. // If these boards have a significant number of posts in them...
  160. if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
  161. {
  162. $query_this_board .= '
  163. AND m.id_msg >= {int:max_id_msg}';
  164. $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 500 - $_REQUEST['start'] * 9);
  165. }
  166. $context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false);
  167. }
  168. elseif (!empty($board))
  169. {
  170. $request = $smcFunc['db_query']('', '
  171. SELECT num_posts
  172. FROM {db_prefix}boards
  173. WHERE id_board = {int:current_board}
  174. LIMIT 1',
  175. array(
  176. 'current_board' => $board,
  177. )
  178. );
  179. list ($total_posts) = $smcFunc['db_fetch_row']($request);
  180. $smcFunc['db_free_result']($request);
  181. $query_this_board = 'b.id_board = {int:board}';
  182. $query_parameters['board'] = $board;
  183. // If this board has a significant number of posts in it...
  184. if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
  185. {
  186. $query_this_board .= '
  187. AND m.id_msg >= {int:max_id_msg}';
  188. $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 600 - $_REQUEST['start'] * 10);
  189. }
  190. $context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true);
  191. }
  192. else
  193. {
  194. $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  195. AND b.id_board != {int:recycle_board}' : ''). '
  196. AND m.id_msg >= {int:max_id_msg}';
  197. $query_parameters['max_id_msg'] = max(0, $modSettings['maxMsgID'] - 100 - $_REQUEST['start'] * 6);
  198. $query_parameters['recycle_board'] = $modSettings['recycle_board'];
  199. // @todo This isn't accurate because we ignore the recycle bin.
  200. $context['page_index'] = constructPageIndex($scripturl . '?action=recent', $_REQUEST['start'], min(100, $modSettings['totalMessages']), 10, false);
  201. }
  202. $context['linktree'][] = array(
  203. 'url' => $scripturl . '?action=recent' . (empty($board) ? (empty($_REQUEST['c']) ? '' : ';c=' . (int) $_REQUEST['c']) : ';board=' . $board . '.0'),
  204. 'name' => $context['page_title']
  205. );
  206. $key = 'recent-' . $user_info['id'] . '-' . md5(serialize(array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start'];
  207. if (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null)
  208. {
  209. $done = false;
  210. while (!$done)
  211. {
  212. // Find the 10 most recent messages they can *view*.
  213. // @todo SLOW This query is really slow still, probably?
  214. $request = $smcFunc['db_query']('', '
  215. SELECT m.id_msg
  216. FROM {db_prefix}messages AS m
  217. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  218. WHERE ' . $query_this_board . '
  219. AND m.approved = {int:is_approved}
  220. ORDER BY m.id_msg DESC
  221. LIMIT {int:offset}, {int:limit}',
  222. array_merge($query_parameters, array(
  223. 'is_approved' => 1,
  224. 'offset' => $_REQUEST['start'],
  225. 'limit' => 10,
  226. ))
  227. );
  228. // If we don't have 10 results, try again with an unoptimized version covering all rows, and cache the result.
  229. if (isset($query_parameters['max_id_msg']) && $smcFunc['db_num_rows']($request) < 10)
  230. {
  231. $smcFunc['db_free_result']($request);
  232. $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board);
  233. $cache_results = true;
  234. unset($query_parameters['max_id_msg']);
  235. }
  236. else
  237. $done = true;
  238. }
  239. $messages = array();
  240. while ($row = $smcFunc['db_fetch_assoc']($request))
  241. $messages[] = $row['id_msg'];
  242. $smcFunc['db_free_result']($request);
  243. if (!empty($cache_results))
  244. cache_put_data($key, $messages, 120);
  245. }
  246. // Nothing here... Or at least, nothing you can see...
  247. if (empty($messages))
  248. {
  249. $context['posts'] = array();
  250. return;
  251. }
  252. // Get all the most recent posts.
  253. $request = $smcFunc['db_query']('', '
  254. SELECT
  255. m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
  256. b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m2.id_member AS id_first_member,
  257. IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name, t.id_first_msg,
  258. IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
  259. FROM {db_prefix}messages AS m
  260. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  261. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  262. INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  263. INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg)
  264. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  265. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)
  266. WHERE m.id_msg IN ({array_int:message_list})
  267. ORDER BY m.id_msg DESC
  268. LIMIT ' . count($messages),
  269. array(
  270. 'message_list' => $messages,
  271. )
  272. );
  273. $counter = $_REQUEST['start'] + 1;
  274. $context['posts'] = array();
  275. $board_ids = array('own' => array(), 'any' => array());
  276. while ($row = $smcFunc['db_fetch_assoc']($request))
  277. {
  278. // Censor everything.
  279. censorText($row['body']);
  280. censorText($row['subject']);
  281. // BBC-atize the message.
  282. $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
  283. // And build the array.
  284. $context['posts'][$row['id_msg']] = array(
  285. 'id' => $row['id_msg'],
  286. 'counter' => $counter++,
  287. 'alternate' => $counter % 2,
  288. 'category' => array(
  289. 'id' => $row['id_cat'],
  290. 'name' => $row['cname'],
  291. 'href' => $scripturl . '#c' . $row['id_cat'],
  292. 'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cname'] . '</a>'
  293. ),
  294. 'board' => array(
  295. 'id' => $row['id_board'],
  296. 'name' => $row['bname'],
  297. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  298. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'
  299. ),
  300. 'topic' => $row['id_topic'],
  301. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  302. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>',
  303. 'start' => $row['num_replies'],
  304. 'subject' => $row['subject'],
  305. 'time' => timeformat($row['poster_time']),
  306. 'timestamp' => forum_time(true, $row['poster_time']),
  307. 'first_poster' => array(
  308. 'id' => $row['id_first_member'],
  309. 'name' => $row['first_poster_name'],
  310. 'href' => empty($row['id_first_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_first_member'],
  311. 'link' => empty($row['id_first_member']) ? $row['first_poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '">' . $row['first_poster_name'] . '</a>'
  312. ),
  313. 'poster' => array(
  314. 'id' => $row['id_member'],
  315. 'name' => $row['poster_name'],
  316. 'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
  317. 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
  318. ),
  319. 'message' => $row['body'],
  320. 'can_reply' => false,
  321. 'can_mark_notify' => false,
  322. 'can_delete' => false,
  323. 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
  324. );
  325. if ($user_info['id'] == $row['id_first_member'])
  326. $board_ids['own'][$row['id_board']][] = $row['id_msg'];
  327. $board_ids['any'][$row['id_board']][] = $row['id_msg'];
  328. }
  329. $smcFunc['db_free_result']($request);
  330. // There might be - and are - different permissions between any and own.
  331. $permissions = array(
  332. 'own' => array(
  333. 'post_reply_own' => 'can_reply',
  334. 'delete_own' => 'can_delete',
  335. ),
  336. 'any' => array(
  337. 'post_reply_any' => 'can_reply',
  338. 'mark_any_notify' => 'can_mark_notify',
  339. 'delete_any' => 'can_delete',
  340. )
  341. );
  342. // Now go through all the permissions, looking for boards they can do it on.
  343. foreach ($permissions as $type => $list)
  344. {
  345. foreach ($list as $permission => $allowed)
  346. {
  347. // They can do it on these boards...
  348. $boards = boardsAllowedTo($permission);
  349. // If 0 is the only thing in the array, they can do it everywhere!
  350. if (!empty($boards) && $boards[0] == 0)
  351. $boards = array_keys($board_ids[$type]);
  352. // Go through the boards, and look for posts they can do this on.
  353. foreach ($boards as $board_id)
  354. {
  355. // Hmm, they have permission, but there are no topics from that board on this page.
  356. if (!isset($board_ids[$type][$board_id]))
  357. continue;
  358. // Okay, looks like they can do it for these posts.
  359. foreach ($board_ids[$type][$board_id] as $counter)
  360. if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
  361. $context['posts'][$counter][$allowed] = true;
  362. }
  363. }
  364. }
  365. $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
  366. foreach ($context['posts'] as $counter => $dummy)
  367. {
  368. // Some posts - the first posts - can't just be deleted.
  369. $context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
  370. // And some cannot be quoted...
  371. $context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
  372. }
  373. }
  374. /**
  375. * Find unread topics and replies.
  376. */
  377. function UnreadTopics()
  378. {
  379. global $board, $txt, $scripturl, $sourcedir;
  380. global $user_info, $context, $settings, $modSettings, $smcFunc, $options;
  381. // Guests can't have unread things, we don't know anything about them.
  382. is_not_guest();
  383. // Prefetching + lots of MySQL work = bad mojo.
  384. if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
  385. {
  386. ob_end_clean();
  387. header('HTTP/1.1 403 Forbidden');
  388. die;
  389. }
  390. $context['showCheckboxes'] = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $settings['show_mark_read'];
  391. $context['showing_all_topics'] = isset($_GET['all']);
  392. $context['start'] = (int) $_REQUEST['start'];
  393. $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) && !WIRELESS ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
  394. if ($_REQUEST['action'] == 'unread')
  395. $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
  396. else
  397. $context['page_title'] = $txt['unread_replies'];
  398. if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread'])
  399. fatal_lang_error('loadavg_allunread_disabled', false);
  400. elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies'])
  401. fatal_lang_error('loadavg_unreadreplies_disabled', false);
  402. elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread'])
  403. fatal_lang_error('loadavg_unread_disabled', false);
  404. // Parameters for the main query.
  405. $query_parameters = array();
  406. // Are we specifying any specific board?
  407. if (isset($_REQUEST['children']) && (!empty($board) || !empty($_REQUEST['boards'])))
  408. {
  409. $boards = array();
  410. if (!empty($_REQUEST['boards']))
  411. {
  412. $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
  413. foreach ($_REQUEST['boards'] as $b)
  414. $boards[] = (int) $b;
  415. }
  416. if (!empty($board))
  417. $boards[] = (int) $board;
  418. // The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them
  419. $request = $smcFunc['db_query']('', '
  420. SELECT b.id_board, b.id_parent
  421. FROM {db_prefix}boards AS b
  422. WHERE {query_wanna_see_board}
  423. AND b.child_level > {int:no_child}
  424. AND b.id_board NOT IN ({array_int:boards})
  425. ORDER BY child_level ASC
  426. ',
  427. array(
  428. 'no_child' => 0,
  429. 'boards' => $boards,
  430. )
  431. );
  432. while ($row = $smcFunc['db_fetch_assoc']($request))
  433. if (in_array($row['id_parent'], $boards))
  434. $boards[] = $row['id_board'];
  435. $smcFunc['db_free_result']($request);
  436. if (empty($boards))
  437. fatal_lang_error('error_no_boards_selected');
  438. $query_this_board = 'id_board IN ({array_int:boards})';
  439. $query_parameters['boards'] = $boards;
  440. $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d';
  441. }
  442. elseif (!empty($board))
  443. {
  444. $query_this_board = 'id_board = {int:board}';
  445. $query_parameters['board'] = $board;
  446. $context['querystring_board_limits'] = ';board=' . $board . '.%1$d';
  447. }
  448. elseif (!empty($_REQUEST['boards']))
  449. {
  450. $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
  451. foreach ($_REQUEST['boards'] as $i => $b)
  452. $_REQUEST['boards'][$i] = (int) $b;
  453. $request = $smcFunc['db_query']('', '
  454. SELECT b.id_board
  455. FROM {db_prefix}boards AS b
  456. WHERE {query_see_board}
  457. AND b.id_board IN ({array_int:board_list})',
  458. array(
  459. 'board_list' => $_REQUEST['boards'],
  460. )
  461. );
  462. $boards = array();
  463. while ($row = $smcFunc['db_fetch_assoc']($request))
  464. $boards[] = $row['id_board'];
  465. $smcFunc['db_free_result']($request);
  466. if (empty($boards))
  467. fatal_lang_error('error_no_boards_selected');
  468. $query_this_board = 'id_board IN ({array_int:boards})';
  469. $query_parameters['boards'] = $boards;
  470. $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d';
  471. }
  472. elseif (!empty($_REQUEST['c']))
  473. {
  474. $_REQUEST['c'] = explode(',', $_REQUEST['c']);
  475. foreach ($_REQUEST['c'] as $i => $c)
  476. $_REQUEST['c'][$i] = (int) $c;
  477. $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
  478. $request = $smcFunc['db_query']('', '
  479. SELECT b.id_board
  480. FROM {db_prefix}boards AS b
  481. WHERE ' . $user_info[$see_board] . '
  482. AND b.id_cat IN ({array_int:id_cat})',
  483. array(
  484. 'id_cat' => $_REQUEST['c'],
  485. )
  486. );
  487. $boards = array();
  488. while ($row = $smcFunc['db_fetch_assoc']($request))
  489. $boards[] = $row['id_board'];
  490. $smcFunc['db_free_result']($request);
  491. if (empty($boards))
  492. fatal_lang_error('error_no_boards_selected');
  493. $query_this_board = 'id_board IN ({array_int:boards})';
  494. $query_parameters['boards'] = $boards;
  495. $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d';
  496. }
  497. else
  498. {
  499. $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
  500. // Don't bother to show deleted posts!
  501. $request = $smcFunc['db_query']('', '
  502. SELECT b.id_board
  503. FROM {db_prefix}boards AS b
  504. WHERE ' . $user_info[$see_board] . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  505. AND b.id_board != {int:recycle_board}' : ''),
  506. array(
  507. 'recycle_board' => (int) $modSettings['recycle_board'],
  508. )
  509. );
  510. $boards = array();
  511. while ($row = $smcFunc['db_fetch_assoc']($request))
  512. $boards[] = $row['id_board'];
  513. $smcFunc['db_free_result']($request);
  514. if (empty($boards))
  515. fatal_lang_error('error_no_boards_selected');
  516. $query_this_board = 'id_board IN ({array_int:boards})';
  517. $query_parameters['boards'] = $boards;
  518. $context['querystring_board_limits'] = ';start=%1$d';
  519. $context['no_board_limits'] = true;
  520. }
  521. $sort_methods = array(
  522. 'subject' => 'ms.subject',
  523. 'starter' => 'IFNULL(mems.real_name, ms.poster_name)',
  524. 'replies' => 't.num_replies',
  525. 'views' => 't.num_views',
  526. 'first_post' => 't.id_topic',
  527. 'last_post' => 't.id_last_msg'
  528. );
  529. // The default is the most logical: newest first.
  530. if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']]))
  531. {
  532. $context['sort_by'] = 'last_post';
  533. $_REQUEST['sort'] = 't.id_last_msg';
  534. $ascending = isset($_REQUEST['asc']);
  535. $context['querystring_sort_limits'] = $ascending ? ';asc' : '';
  536. }
  537. // But, for other methods the default sort is ascending.
  538. else
  539. {
  540. $context['sort_by'] = $_REQUEST['sort'];
  541. $_REQUEST['sort'] = $sort_methods[$_REQUEST['sort']];
  542. $ascending = !isset($_REQUEST['desc']);
  543. $context['querystring_sort_limits'] = ';sort=' . $context['sort_by'] . ($ascending ? '' : ';desc');
  544. }
  545. $context['sort_direction'] = $ascending ? 'up' : 'down';
  546. if (!empty($_REQUEST['c']) && is_array($_REQUEST['c']) && count($_REQUEST['c']) == 1)
  547. {
  548. $request = $smcFunc['db_query']('', '
  549. SELECT name
  550. FROM {db_prefix}categories
  551. WHERE id_cat = {int:id_cat}
  552. LIMIT 1',
  553. array(
  554. 'id_cat' => (int) $_REQUEST['c'][0],
  555. )
  556. );
  557. list ($name) = $smcFunc['db_fetch_row']($request);
  558. $smcFunc['db_free_result']($request);
  559. $context['linktree'][] = array(
  560. 'url' => $scripturl . '#c' . (int) $_REQUEST['c'][0],
  561. 'name' => $name
  562. );
  563. }
  564. $context['linktree'][] = array(
  565. 'url' => $scripturl . '?action=' . $_REQUEST['action'] . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'],
  566. 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies']
  567. );
  568. if ($context['showing_all_topics'])
  569. $context['linktree'][] = array(
  570. 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'],
  571. 'name' => $txt['unread_topics_all']
  572. );
  573. else
  574. $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits']));
  575. if (WIRELESS)
  576. $context['sub_template'] = WIRELESS_PROTOCOL . '_recent';
  577. else
  578. {
  579. loadTemplate('Recent');
  580. $context['sub_template'] = $_REQUEST['action'] == 'unread' ? 'unread' : 'replies';
  581. }
  582. // Setup the default topic icons... for checking they exist and the like ;)
  583. $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'poll', 'moved', 'recycled', 'wireless', 'clip');
  584. $context['icon_sources'] = array();
  585. foreach ($stable_icons as $icon)
  586. $context['icon_sources'][$icon] = 'images_url';
  587. $is_topics = $_REQUEST['action'] == 'unread';
  588. // This part is the same for each query.
  589. $select_clause = '
  590. ms.subject AS first_subject, ms.poster_time AS first_poster_time, ms.id_topic, t.id_board, b.name AS bname,
  591. t.num_replies, t.num_views, ms.id_member AS id_first_member, ml.id_member AS id_last_member,
  592. ml.poster_time AS last_poster_time, IFNULL(mems.real_name, ms.poster_name) AS first_poster_name,
  593. IFNULL(meml.real_name, ml.poster_name) AS last_poster_name, ml.subject AS last_subject,
  594. ml.icon AS last_icon, ms.icon AS first_icon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS last_modified_time,
  595. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, SUBSTRING(ml.body, 1, 385) AS last_body,
  596. SUBSTRING(ms.body, 1, 385) AS first_body, ml.smileys_enabled AS last_smileys, ms.smileys_enabled AS first_smileys, t.id_first_msg, t.id_last_msg';
  597. if ($context['showing_all_topics'])
  598. {
  599. if (!empty($board))
  600. {
  601. $request = $smcFunc['db_query']('', '
  602. SELECT MIN(id_msg)
  603. FROM {db_prefix}log_mark_read
  604. WHERE id_member = {int:current_member}
  605. AND id_board = {int:current_board}',
  606. array(
  607. 'current_board' => $board,
  608. 'current_member' => $user_info['id'],
  609. )
  610. );
  611. list ($earliest_msg) = $smcFunc['db_fetch_row']($request);
  612. $smcFunc['db_free_result']($request);
  613. }
  614. else
  615. {
  616. $request = $smcFunc['db_query']('', '
  617. SELECT MIN(lmr.id_msg)
  618. FROM {db_prefix}boards AS b
  619. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})
  620. WHERE {query_see_board}',
  621. array(
  622. 'current_member' => $user_info['id'],
  623. )
  624. );
  625. list ($earliest_msg) = $smcFunc['db_fetch_row']($request);
  626. $smcFunc['db_free_result']($request);
  627. }
  628. // This is needed in case of topics marked unread.
  629. if (empty($earliest_msg))
  630. $earliest_msg = 0;
  631. else
  632. {
  633. // Using caching, when possible, to ignore the below slow query.
  634. if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time())
  635. $earliest_msg2 = $_SESSION['cached_log_time'][1];
  636. else
  637. {
  638. // This query is pretty slow, but it's needed to ensure nothing crucial is ignored.
  639. $request = $smcFunc['db_query']('', '
  640. SELECT MIN(id_msg)
  641. FROM {db_prefix}log_topics
  642. WHERE id_member = {int:current_member}',
  643. array(
  644. 'current_member' => $user_info['id'],
  645. )
  646. );
  647. list ($earliest_msg2) = $smcFunc['db_fetch_row']($request);
  648. $smcFunc['db_free_result']($request);
  649. // In theory this could be zero, if the first ever post is unread, so fudge it ;)
  650. if ($earliest_msg2 == 0)
  651. $earliest_msg2 = -1;
  652. $_SESSION['cached_log_time'] = array(time(), $earliest_msg2);
  653. }
  654. $earliest_msg = min($earliest_msg2, $earliest_msg);
  655. }
  656. }
  657. // @todo Add modified_time in for log_time check?
  658. if ($modSettings['totalMessages'] > 100000 && $context['showing_all_topics'])
  659. {
  660. $smcFunc['db_query']('', '
  661. DROP TABLE IF EXISTS {db_prefix}log_topics_unread',
  662. array(
  663. )
  664. );
  665. // Let's copy things out of the log_topics table, to reduce searching.
  666. $have_temp_table = $smcFunc['db_query']('', '
  667. CREATE TEMPORARY TABLE {db_prefix}log_topics_unread (
  668. PRIMARY KEY (id_topic)
  669. )
  670. SELECT lt.id_topic, lt.id_msg
  671. FROM {db_prefix}topics AS t
  672. INNER JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic)
  673. WHERE lt.id_member = {int:current_member}
  674. AND t.' . $query_this_board . (empty($earliest_msg) ? '' : '
  675. AND t.id_last_msg > {int:earliest_msg}') . ($modSettings['postmod_active'] ? '
  676. AND t.approved = {int:is_approved}' : ''),
  677. array_merge($query_parameters, array(
  678. 'current_member' => $user_info['id'],
  679. 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0,
  680. 'is_approved' => 1,
  681. 'db_error_skip' => true,
  682. ))
  683. ) !== false;
  684. }
  685. else
  686. $have_temp_table = false;
  687. if ($context['showing_all_topics'] && $have_temp_table)
  688. {
  689. $request = $smcFunc['db_query']('', '
  690. SELECT COUNT(*), MIN(t.id_last_msg)
  691. FROM {db_prefix}topics AS t
  692. LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)
  693. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  694. WHERE t.' . $query_this_board . (!empty($earliest_msg) ? '
  695. AND t.id_last_msg > {int:earliest_msg}' : '') . '
  696. AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? '
  697. AND t.approved = {int:is_approved}' : ''),
  698. array_merge($query_parameters, array(
  699. 'current_member' => $user_info['id'],
  700. 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0,
  701. 'is_approved' => 1,
  702. ))
  703. );
  704. list ($num_topics, $min_message) = $smcFunc['db_fetch_row']($request);
  705. $smcFunc['db_free_result']($request);
  706. // Make sure the starting place makes sense and construct the page index.
  707. $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true);
  708. $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page'];
  709. $context['links'] = array(
  710. 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'] : '',
  711. 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  712. 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  713. 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], floor(($num_topics - 1) / $context['topics_per_page']) * $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  714. 'up' => $scripturl,
  715. );
  716. $context['page_info'] = array(
  717. 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1,
  718. 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1
  719. );
  720. if ($num_topics == 0)
  721. {
  722. // Mark the boards as read if there are no unread topics!
  723. require_once($sourcedir . '/Subs-Boards.php');
  724. markBoardsRead(empty($boards) ? $board : $boards);
  725. $context['topics'] = array();
  726. if ($context['querystring_board_limits'] == ';start=%1$d')
  727. $context['querystring_board_limits'] = '';
  728. else
  729. $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
  730. return;
  731. }
  732. else
  733. $min_message = (int) $min_message;
  734. $request = $smcFunc['db_query']('substring', '
  735. SELECT ' . $select_clause . '
  736. FROM {db_prefix}messages AS ms
  737. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ms.id_topic AND t.id_first_msg = ms.id_msg)
  738. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  739. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = ms.id_board)
  740. LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
  741. LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
  742. LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)
  743. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  744. WHERE b.' . $query_this_board . '
  745. AND t.id_last_msg >= {int:min_message}
  746. AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? '
  747. AND ms.approved = {int:is_approved}' : '') . '
  748. ORDER BY {raw:sort}
  749. LIMIT {int:offset}, {int:limit}',
  750. array_merge($query_parameters, array(
  751. 'current_member' => $user_info['id'],
  752. 'min_message' => $min_message,
  753. 'is_approved' => 1,
  754. 'sort' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'),
  755. 'offset' => $_REQUEST['start'],
  756. 'limit' => $context['topics_per_page'],
  757. ))
  758. );
  759. }
  760. elseif ($is_topics)
  761. {
  762. $request = $smcFunc['db_query']('', '
  763. SELECT COUNT(*), MIN(t.id_last_msg)
  764. FROM {db_prefix}topics AS t' . (!empty($have_temp_table) ? '
  765. LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : '
  766. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . '
  767. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  768. WHERE t.' . $query_this_board . ($context['showing_all_topics'] && !empty($earliest_msg) ? '
  769. AND t.id_last_msg > {int:earliest_msg}' : (!$context['showing_all_topics'] && empty($_SESSION['first_login']) ? '
  770. AND t.id_last_msg > {int:id_msg_last_visit}' : '')) . '
  771. AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? '
  772. AND t.approved = {int:is_approved}' : ''),
  773. array_merge($query_parameters, array(
  774. 'current_member' => $user_info['id'],
  775. 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0,
  776. 'id_msg_last_visit' => $_SESSION['id_msg_last_visit'],
  777. 'is_approved' => 1,
  778. ))
  779. );
  780. list ($num_topics, $min_message) = $smcFunc['db_fetch_row']($request);
  781. $smcFunc['db_free_result']($request);
  782. // Make sure the starting place makes sense and construct the page index.
  783. $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true);
  784. $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page'];
  785. $context['links'] = array(
  786. 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'] : '',
  787. 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  788. 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  789. 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], floor(($num_topics - 1) / $context['topics_per_page']) * $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  790. 'up' => $scripturl,
  791. );
  792. $context['page_info'] = array(
  793. 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1,
  794. 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1
  795. );
  796. if ($num_topics == 0)
  797. {
  798. // Is this an all topics query?
  799. if ($context['showing_all_topics'])
  800. {
  801. // Since there are no unread topics, mark the boards as read!
  802. require_once($sourcedir . '/Subs-Boards.php');
  803. markBoardsRead(empty($boards) ? $board : $boards);
  804. }
  805. $context['topics'] = array();
  806. if ($context['querystring_board_limits'] == ';start=%d')
  807. $context['querystring_board_limits'] = '';
  808. else
  809. $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
  810. return;
  811. }
  812. else
  813. $min_message = (int) $min_message;
  814. $request = $smcFunc['db_query']('substring', '
  815. SELECT ' . $select_clause . '
  816. FROM {db_prefix}messages AS ms
  817. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ms.id_topic AND t.id_first_msg = ms.id_msg)
  818. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  819. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  820. LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
  821. LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' . (!empty($have_temp_table) ? '
  822. LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : '
  823. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . '
  824. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  825. WHERE t.' . $query_this_board . '
  826. AND t.id_last_msg >= {int:min_message}
  827. AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < ml.id_msg' . ($modSettings['postmod_active'] ? '
  828. AND ms.approved = {int:is_approved}' : '') . '
  829. ORDER BY {raw:order}
  830. LIMIT {int:offset}, {int:limit}',
  831. array_merge($query_parameters, array(
  832. 'current_member' => $user_info['id'],
  833. 'min_message' => $min_message,
  834. 'is_approved' => 1,
  835. 'order' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'),
  836. 'offset' => $_REQUEST['start'],
  837. 'limit' => $context['topics_per_page'],
  838. ))
  839. );
  840. }
  841. else
  842. {
  843. if ($modSettings['totalMessages'] > 100000)
  844. {
  845. $smcFunc['db_query']('', '
  846. DROP TABLE IF EXISTS {db_prefix}topics_posted_in',
  847. array(
  848. )
  849. );
  850. $smcFunc['db_query']('', '
  851. DROP TABLE IF EXISTS {db_prefix}log_topics_posted_in',
  852. array(
  853. )
  854. );
  855. $sortKey_joins = array(
  856. 'ms.subject' => '
  857. INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)',
  858. 'IFNULL(mems.real_name, ms.poster_name)' => '
  859. INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
  860. LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)',
  861. );
  862. // The main benefit of this temporary table is not that it's faster; it's that it avoids locks later.
  863. $have_temp_table = $smcFunc['db_query']('', '
  864. CREATE TEMPORARY TABLE {db_prefix}topics_posted_in (
  865. id_topic mediumint(8) unsigned NOT NULL default {string:string_zero},
  866. id_board smallint(5) unsigned NOT NULL default {string:string_zero},
  867. id_last_msg int(10) unsigned NOT NULL default {string:string_zero},
  868. id_msg int(10) unsigned NOT NULL default {string:string_zero},
  869. PRIMARY KEY (id_topic)
  870. )
  871. SELECT t.id_topic, t.id_board, t.id_last_msg, IFNULL(lmr.id_msg, 0) AS id_msg' . (!in_array($_REQUEST['sort'], array('t.id_last_msg', 't.id_topic')) ? ', ' . $_REQUEST['sort'] . ' AS sort_key' : '') . '
  872. FROM {db_prefix}messages AS m
  873. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  874. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})' . (isset($sortKey_joins[$_REQUEST['sort']]) ? $sortKey_joins[$_REQUEST['sort']] : '') . '
  875. WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
  876. AND t.id_board = {int:current_board}' : '') . ($modSettings['postmod_active'] ? '
  877. AND t.approved = {int:is_approved}' : '') . '
  878. GROUP BY m.id_topic',
  879. array(
  880. 'current_board' => $board,
  881. 'current_member' => $user_info['id'],
  882. 'is_approved' => 1,
  883. 'string_zero' => '0',
  884. 'db_error_skip' => true,
  885. )
  886. ) !== false;
  887. // If that worked, create a sample of the log_topics table too.
  888. if ($have_temp_table)
  889. $have_temp_table = $smcFunc['db_query']('', '
  890. CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in (
  891. PRIMARY KEY (id_topic)
  892. )
  893. SELECT lt.id_topic, lt.id_msg
  894. FROM {db_prefix}log_topics AS lt
  895. INNER JOIN {db_prefix}topics_posted_in AS pi ON (pi.id_topic = lt.id_topic)
  896. WHERE lt.id_member = {int:current_member}',
  897. array(
  898. 'current_member' => $user_info['id'],
  899. 'db_error_skip' => true,
  900. )
  901. ) !== false;
  902. }
  903. if (!empty($have_temp_table))
  904. {
  905. $request = $smcFunc['db_query']('', '
  906. SELECT COUNT(*)
  907. FROM {db_prefix}topics_posted_in AS pi
  908. LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = pi.id_topic)
  909. WHERE pi.' . $query_this_board . '
  910. AND IFNULL(lt.id_msg, pi.id_msg) < pi.id_last_msg',
  911. array_merge($query_parameters, array(
  912. ))
  913. );
  914. list ($num_topics) = $smcFunc['db_fetch_row']($request);
  915. $smcFunc['db_free_result']($request);
  916. }
  917. else
  918. {
  919. $request = $smcFunc['db_query']('unread_fetch_topic_count', '
  920. SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg)
  921. FROM {db_prefix}topics AS t
  922. INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic)
  923. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  924. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  925. WHERE t.' . $query_this_board . '
  926. AND m.id_member = {int:current_member}
  927. AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? '
  928. AND t.approved = {int:is_approved}' : ''),
  929. array_merge($query_parameters, array(
  930. 'current_member' => $user_info['id'],
  931. 'is_approved' => 1,
  932. ))
  933. );
  934. list ($num_topics, $min_message) = $smcFunc['db_fetch_row']($request);
  935. $smcFunc['db_free_result']($request);
  936. }
  937. // Make sure the starting place makes sense and construct the page index.
  938. $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true);
  939. $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page'];
  940. $context['links'] = array(
  941. 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'] : '',
  942. 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  943. 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  944. 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], floor(($num_topics - 1) / $context['topics_per_page']) * $context['topics_per_page']) . $context['querystring_sort_limits'] : '',
  945. 'up' => $scripturl,
  946. );
  947. $context['page_info'] = array(
  948. 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1,
  949. 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1
  950. );
  951. if ($num_topics == 0)
  952. {
  953. $context['topics'] = array();
  954. if ($context['querystring_board_limits'] == ';start=%d')
  955. $context['querystring_board_limits'] = '';
  956. else
  957. $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
  958. return;
  959. }
  960. if (!empty($have_temp_table))
  961. $request = $smcFunc['db_query']('', '
  962. SELECT t.id_topic
  963. FROM {db_prefix}topics_posted_in AS t
  964. LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic)
  965. WHERE t.' . $query_this_board . '
  966. AND IFNULL(lt.id_msg, t.id_msg) < t.id_last_msg
  967. ORDER BY {raw:order}
  968. LIMIT {int:offset}, {int:limit}',
  969. array_merge($query_parameters, array(
  970. 'order' => (in_array($_REQUEST['sort'], array('t.id_last_msg', 't.id_topic')) ? $_REQUEST['sort'] : 't.sort_key') . ($ascending ? '' : ' DESC'),
  971. 'offset' => $_REQUEST['start'],
  972. 'limit' => $context['topics_per_page'],
  973. ))
  974. );
  975. else
  976. $request = $smcFunc['db_query']('unread_replies', '
  977. SELECT DISTINCT t.id_topic
  978. FROM {db_prefix}topics AS t
  979. INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : '
  980. INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)') . (strpos($_REQUEST['sort'], 'mems.') === false ? '' : '
  981. LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)') . '
  982. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  983. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  984. WHERE t.' . $query_this_board . '
  985. AND t.id_last_msg >= {int:min_message}
  986. AND (IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0))) < t.id_last_msg
  987. AND t.approved = {int:is_approved}
  988. ORDER BY {raw:order}
  989. LIMIT {int:offset}, {int:limit}',
  990. array_merge($query_parameters, array(
  991. 'current_member' => $user_info['id'],
  992. 'min_message' => (int) $min_message,
  993. 'is_approved' => 1,
  994. 'order' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'),
  995. 'offset' => $_REQUEST['start'],
  996. 'limit' => $context['topics_per_page'],
  997. 'sort' => $_REQUEST['sort'],
  998. ))
  999. );
  1000. $topics = array();
  1001. while ($row = $smcFunc['db_fetch_assoc']($request))
  1002. $topics[] = $row['id_topic'];
  1003. $smcFunc['db_free_result']($request);
  1004. // Sanity... where have you gone?
  1005. if (empty($topics))
  1006. {
  1007. $context['topics'] = array();
  1008. if ($context['querystring_board_limits'] == ';start=%d')
  1009. $context['querystring_board_limits'] = '';
  1010. else
  1011. $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
  1012. return;
  1013. }
  1014. $request = $smcFunc['db_query']('substring', '
  1015. SELECT ' . $select_clause . '
  1016. FROM {db_prefix}topics AS t
  1017. INNER JOIN {db_prefix}messages AS ms ON (ms.id_topic = t.id_topic AND ms.id_msg = t.id_first_msg)
  1018. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  1019. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  1020. LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
  1021. LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
  1022. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  1023. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  1024. WHERE t.id_topic IN ({array_int:topic_list})
  1025. ORDER BY ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '
  1026. LIMIT ' . count($topics),
  1027. array(
  1028. 'current_member' => $user_info['id'],
  1029. 'topic_list' => $topics,
  1030. )
  1031. );
  1032. }
  1033. $context['topics'] = array();
  1034. $topic_ids = array();
  1035. while ($row = $smcFunc['db_fetch_assoc']($request))
  1036. {
  1037. if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
  1038. continue;
  1039. $topic_ids[] = $row['id_topic'];
  1040. if (!empty($settings['message_index_preview']))
  1041. {
  1042. // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise.
  1043. $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br />' => '&#10;')));
  1044. if ($smcFunc['strlen']($row['first_body']) > 128)
  1045. $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
  1046. $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br />' => '&#10;')));
  1047. if ($smcFunc['strlen']($row['last_body']) > 128)
  1048. $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
  1049. // Censor the subject and message preview.
  1050. censorText($row['first_subject']);
  1051. censorText($row['first_body']);
  1052. // Don't censor them twice!
  1053. if ($row['id_first_msg'] == $row['id_last_msg'])
  1054. {
  1055. $row['last_subject'] = $row['first_subject'];
  1056. $row['last_body'] = $row['first_body'];
  1057. }
  1058. else
  1059. {
  1060. censorText($row['last_subject']);
  1061. censorText($row['last_body']);
  1062. }
  1063. }
  1064. else
  1065. {
  1066. $row['first_body'] = '';
  1067. $row['last_body'] = '';
  1068. censorText($row['first_subject']);
  1069. if ($row['id_first_msg'] == $row['id_last_msg'])
  1070. $row['last_subject'] = $row['first_subject'];
  1071. else
  1072. censorText($row['last_subject']);
  1073. }
  1074. // Decide how many pages the topic should have.
  1075. $topic_length = $row['num_replies'] + 1;
  1076. $messages_per_page = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) && !WIRELESS ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
  1077. if ($topic_length > $messages_per_page)
  1078. {
  1079. $tmppages = array();
  1080. $tmpa = 1;
  1081. for ($tmpb = 0; $tmpb < $topic_length; $tmpb += $messages_per_page)
  1082. {
  1083. $tmppages[] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . $tmpb . ';topicseen">' . $tmpa . '</a>';
  1084. $tmpa++;
  1085. }
  1086. // Show links to all the pages?
  1087. if (count($tmppages) <= 5)
  1088. $pages = '&#171; ' . implode(' ', $tmppages);
  1089. // Or skip a few?
  1090. else
  1091. $pages = '&#171; ' . $tmppages[0] . ' ' . $tmppages[1] . ' ... ' . $tmppages[count($tmppages) - 2] . ' ' . $tmppages[count($tmppages) - 1];
  1092. if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
  1093. $pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
  1094. $pages .= ' &#187;';
  1095. }
  1096. else
  1097. $pages = '';
  1098. // We need to check the topic icons exist... you can never be too sure!
  1099. if (!empty($modSettings['messageIconChecks_enable']))
  1100. {
  1101. // First icon first... as you'd expect.
  1102. if (!isset($context['icon_sources'][$row['first_icon']]))
  1103. $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
  1104. // Last icon... last... duh.
  1105. if (!isset($context['icon_sources'][$row['last_icon']]))
  1106. $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
  1107. }
  1108. // And build the array.
  1109. $context['topics'][$row['id_topic']] = array(
  1110. 'id' => $row['id_topic'],
  1111. 'first_post' => array(
  1112. 'id' => $row['id_first_msg'],
  1113. 'member' => array(
  1114. 'name' => $row['first_poster_name'],
  1115. 'id' => $row['id_first_member'],
  1116. 'href' => $scripturl . '?action=profile;u=' . $row['id_first_member'],
  1117. 'link' => !empty($row['id_first_member']) ? '<a class="preview" href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '" title="' . $txt['profile_of'] . ' ' . $row['first_poster_name'] . '">' . $row['first_poster_name'] . '</a>' : $row['first_poster_name']
  1118. ),
  1119. 'time' => timeformat($row['first_poster_time']),
  1120. 'timestamp' => forum_time(true, $row['first_poster_time']),
  1121. 'subject' => $row['first_subject'],
  1122. 'preview' => $row['first_body'],
  1123. 'icon' => $row['first_icon'],
  1124. 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png',
  1125. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen',
  1126. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['first_subject'] . '</a>'
  1127. ),
  1128. 'last_post' => array(
  1129. 'id' => $row['id_last_msg'],
  1130. 'member' => array(
  1131. 'name' => $row['last_poster_name'],
  1132. 'id' => $row['id_last_member'],
  1133. 'href' => $scripturl . '?action=profile;u=' . $row['id_last_member'],
  1134. 'link' => !empty($row['id_last_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_last_member'] . '">' . $row['last_poster_name'] . '</a>' : $row['last_poster_name']
  1135. ),
  1136. 'time' => timeformat($row['last_poster_time']),
  1137. 'timestamp' => forum_time(true, $row['last_poster_time']),
  1138. 'subject' => $row['last_subject'],
  1139. 'preview' => $row['last_body'],
  1140. 'icon' => $row['last_icon'],
  1141. 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.png',
  1142. 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'],
  1143. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '" rel="nofollow">' . $row['last_subject'] . '</a>'
  1144. ),
  1145. 'new_from' => $row['new_from'],
  1146. 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new',
  1147. 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'),
  1148. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '" rel="nofollow">' . $row['first_subject'] . '</a>',
  1149. 'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['is_sticky']),
  1150. 'is_locked' => !empty($row['locked']),
  1151. 'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
  1152. 'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
  1153. 'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
  1154. 'is_posted_in' => false,
  1155. 'icon' => $row['first_icon'],
  1156. 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png',
  1157. 'subject' => $row['first_subject'],
  1158. 'pages' => $pages,
  1159. 'replies' => comma_format($row['num_replies']),
  1160. 'views' => comma_format($row['num_views']),
  1161. 'board' => array(
  1162. 'id' => $row['id_board'],
  1163. 'name' => $row['bname'],
  1164. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  1165. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'
  1166. )
  1167. );
  1168. $context['topics'][$row['id_topic']]['first_post']['started_by'] = sprintf($txt['topic_started_by'], $context['topics'][$row['id_topic']]['first_post']['member']['link'], $context['topics'][$row['id_topic']]['board']['link']);
  1169. determineTopicClass($context['topics'][$row['id_topic']]);
  1170. }
  1171. $smcFunc['db_free_result']($request);
  1172. if ($is_topics && !empty($modSettings['enableParticipation']) && !empty($topic_ids))
  1173. {
  1174. $result = $smcFunc['db_query']('', '
  1175. SELECT id_topic
  1176. FROM {db_prefix}messages
  1177. WHERE id_topic IN ({array_int:topic_list})
  1178. AND id_member = {int:current_member}
  1179. GROUP BY id_topic
  1180. LIMIT {int:limit}',
  1181. array(
  1182. 'current_member' => $user_info['id'],
  1183. 'topic_list' => $topic_ids,
  1184. 'limit' => count($topic_ids),
  1185. )
  1186. );
  1187. while ($row = $smcFunc['db_fetch_assoc']($result))
  1188. {
  1189. if (empty($context['topics'][$row['id_topic']]['is_posted_in']))
  1190. {
  1191. $context['topics'][$row['id_topic']]['is_posted_in'] = true;
  1192. $context['topics'][$row['id_topic']]['class'] = 'my_' . $context['topics'][$row['id_topic']]['class'];
  1193. }
  1194. }
  1195. $smcFunc['db_free_result']($result);
  1196. }
  1197. $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
  1198. $context['topics_to_mark'] = implode('-', $topic_ids);
  1199. if ($settings['show_mark_read'])
  1200. {
  1201. // Build the recent button array.
  1202. if ($is_topics)
  1203. {
  1204. $context['recent_buttons'] = array(
  1205. 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']),
  1206. );
  1207. if ($context['showCheckboxes'])
  1208. $context['recent_buttons']['markselectread'] = array(
  1209. 'text' => 'quick_mod_markread',
  1210. 'image' => 'markselectedread.png',
  1211. 'lang' => true,
  1212. 'url' => 'javascript:document.quickModForm.submit();',
  1213. );
  1214. if (!empty($context['topics']) && !$context['showing_all_topics'])
  1215. $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'lang' => true, 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
  1216. }
  1217. elseif (!$is_topics && isset($context['topics_to_mark']))
  1218. {
  1219. $context['recent_buttons'] = array(
  1220. 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']),
  1221. );
  1222. if ($context['showCheckboxes'])
  1223. $context['recent_buttons']['markselectread'] = array(
  1224. 'text' => 'quick_mod_markread',
  1225. 'image' => 'markselectedread.png',
  1226. 'lang' => true,
  1227. 'url' => 'javascript:document.quickModForm.submit();',
  1228. );
  1229. }
  1230. // Allow mods to add additional buttons here
  1231. call_integration_hook('integrate_recent_buttons');
  1232. }
  1233. // Allow helpdesks and bug trackers and what not to add their own unread data (just add a template_layer to show custom stuff in the template!)
  1234. call_integration_hook('integrate_unread_list');
  1235. }
  1236. ?>