modification.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. <?xml version="1.0"?>
  2. <!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
  3. <modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
  4. <id>cooliojazz:RecentPosts</id>
  5. <version>0.1</version>
  6. <file name="$sourcedir/../index.php">
  7. <operation>
  8. <search position="replace"><![CDATA[array('Recent.php', 'RecentPosts')]]></search>
  9. <add><![CDATA[array('Recent.php', 'RecentPosts2')]]></add>
  10. </operation>
  11. </file>
  12. <file name="$sourcedir/Recent.php">
  13. <operation>
  14. <search position="end" />
  15. <add><![CDATA[
  16. // Find unread topics and replies.
  17. function RecentPosts2() {
  18. global $board, $txt, $scripturl, $sourcedir, $user_info, $context, $settings, $modSettings, $smcFunc, $options;
  19. // Prefetching + lots of MySQL work = bad mojo.
  20. if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
  21. ob_end_clean();
  22. header('HTTP/1.1 403 Forbidden');
  23. die;
  24. }
  25. $context['start'] = (int)$_REQUEST['start'];
  26. $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) && !WIRELESS ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
  27. $context['page_title'] = $txt['recent_posts'];
  28. if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread'])
  29. fatal_lang_error('loadavg_allunread_disabled', false);
  30. elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies'])
  31. fatal_lang_error('loadavg_unreadreplies_disabled', false);
  32. elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread'])
  33. fatal_lang_error('loadavg_unread_disabled', false);
  34. // Parameters for the main query.
  35. $query_parameters = array();
  36. // Are we specifying any specific board?
  37. if (isset($_REQUEST['children']) && (!empty($board) || !empty($_REQUEST['boards']))) {
  38. $boards = array();
  39. if (!empty($_REQUEST['boards'])) {
  40. $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
  41. foreach ($_REQUEST['boards'] as $b) $boards[] = (int)$b;
  42. }
  43. if (!empty($board)) $boards[] = (int)$board;
  44. // 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
  45. $request = $smcFunc['db_query']('', '
  46. SELECT b.id_board, b.id_parent
  47. FROM {db_prefix}boards AS b
  48. WHERE {query_wanna_see_board}
  49. AND b.child_level > {int:no_child}
  50. AND b.id_board NOT IN ({array_int:boards})
  51. ORDER BY child_level ASC
  52. ',
  53. array(
  54. 'no_child' => 0,
  55. 'boards' => $boards,
  56. )
  57. );
  58. while ($row = $smcFunc['db_fetch_assoc']($request)) {
  59. if (in_array($row['id_parent'], $boards)) $boards[] = $row['id_board'];
  60. }
  61. $smcFunc['db_free_result']($request);
  62. if (empty($boards)) fatal_lang_error('error_no_boards_selected');
  63. $query_this_board = 'id_board IN ({array_int:boards})';
  64. $query_parameters['boards'] = $boards;
  65. $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d';
  66. } elseif (!empty($board)) {
  67. $query_this_board = 'id_board = {int:board}';
  68. $query_parameters['board'] = $board;
  69. $context['querystring_board_limits'] = ';board=' . $board . '.%1$d';
  70. } elseif (!empty($_REQUEST['boards'])) {
  71. $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
  72. foreach ($_REQUEST['boards'] as $i => $b) $_REQUEST['boards'][$i] = (int) $b;
  73. $request = $smcFunc['db_query']('', '
  74. SELECT b.id_board
  75. FROM {db_prefix}boards AS b
  76. WHERE {query_see_board}
  77. AND b.id_board IN ({array_int:board_list})',
  78. array(
  79. 'board_list' => $_REQUEST['boards'],
  80. )
  81. );
  82. $boards = array();
  83. while ($row = $smcFunc['db_fetch_assoc']($request)) $boards[] = $row['id_board'];
  84. $smcFunc['db_free_result']($request);
  85. if (empty($boards)) fatal_lang_error('error_no_boards_selected');
  86. $query_this_board = 'id_board IN ({array_int:boards})';
  87. $query_parameters['boards'] = $boards;
  88. $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d';
  89. } elseif (!empty($_REQUEST['c'])) {
  90. $_REQUEST['c'] = explode(',', $_REQUEST['c']);
  91. foreach ($_REQUEST['c'] as $i => $c)
  92. $_REQUEST['c'][$i] = (int) $c;
  93. $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
  94. $request = $smcFunc['db_query']('', '
  95. SELECT b.id_board
  96. FROM {db_prefix}boards AS b
  97. WHERE ' . $user_info[$see_board] . '
  98. AND b.id_cat IN ({array_int:id_cat})',
  99. array(
  100. 'id_cat' => $_REQUEST['c'],
  101. )
  102. );
  103. $boards = array();
  104. while ($row = $smcFunc['db_fetch_assoc']($request))
  105. $boards[] = $row['id_board'];
  106. $smcFunc['db_free_result']($request);
  107. if (empty($boards))
  108. fatal_lang_error('error_no_boards_selected');
  109. $query_this_board = 'id_board IN ({array_int:boards})';
  110. $query_parameters['boards'] = $boards;
  111. $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d';
  112. } else {
  113. $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
  114. // Don't bother to show deleted posts!
  115. $request = $smcFunc['db_query']('', '
  116. SELECT b.id_board
  117. FROM {db_prefix}boards AS b
  118. WHERE ' . $user_info[$see_board] . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  119. AND b.id_board != {int:recycle_board}' : ''),
  120. array(
  121. 'recycle_board' => (int) $modSettings['recycle_board'],
  122. )
  123. );
  124. $boards = array();
  125. while ($row = $smcFunc['db_fetch_assoc']($request)) $boards[] = $row['id_board'];
  126. $smcFunc['db_free_result']($request);
  127. if (empty($boards)) fatal_lang_error('error_no_boards_selected');
  128. $query_this_board = 'id_board IN ({array_int:boards})';
  129. $query_parameters['boards'] = $boards;
  130. $context['querystring_board_limits'] = ';start=%1$d';
  131. $context['no_board_limits'] = true;
  132. }
  133. $sort_methods = array(
  134. 'subject' => 'ms.subject',
  135. 'starter' => 'IFNULL(mems.real_name, ms.poster_name)',
  136. 'replies' => 't.num_replies',
  137. 'views' => 't.num_views',
  138. 'first_post' => 't.id_topic',
  139. 'last_post' => 't.id_last_msg'
  140. );
  141. // The default is the most logical: newest first.
  142. if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) {
  143. $context['sort_by'] = 'last_post';
  144. $_REQUEST['sort'] = 't.id_last_msg';
  145. $ascending = isset($_REQUEST['asc']);
  146. $context['querystring_sort_limits'] = $ascending ? ';asc' : '';
  147. } else {
  148. // But, for other methods the default sort is ascending.
  149. $context['sort_by'] = $_REQUEST['sort'];
  150. $_REQUEST['sort'] = $sort_methods[$_REQUEST['sort']];
  151. $ascending = !isset($_REQUEST['desc']);
  152. $context['querystring_sort_limits'] = ';sort=' . $context['sort_by'] . ($ascending ? '' : ';desc');
  153. }
  154. $context['sort_direction'] = $ascending ? 'up' : 'down';
  155. if (!empty($_REQUEST['c']) && is_array($_REQUEST['c']) && count($_REQUEST['c']) == 1) {
  156. $request = $smcFunc['db_query']('', '
  157. SELECT name
  158. FROM {db_prefix}categories
  159. WHERE id_cat = {int:id_cat}
  160. LIMIT 1',
  161. array(
  162. 'id_cat' => (int) $_REQUEST['c'][0],
  163. )
  164. );
  165. list ($name) = $smcFunc['db_fetch_row']($request);
  166. $smcFunc['db_free_result']($request);
  167. $context['linktree'][] = array(
  168. 'url' => $scripturl . '#c' . (int) $_REQUEST['c'][0],
  169. 'name' => $name
  170. );
  171. }
  172. $context['linktree'][] = array(
  173. 'url' => $scripturl . '?action=' . $_REQUEST['action'] . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'],
  174. 'name' => $_REQUEST['action'] == 'recent3' ? $txt['unread_topics_visit'] : $txt['unread_replies']
  175. );
  176. if ($context['showing_all_topics'])
  177. $context['linktree'][] = array(
  178. 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'],
  179. 'name' => $txt['unread_topics_all']
  180. );
  181. else
  182. $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']));
  183. if (WIRELESS)
  184. $context['sub_template'] = WIRELESS_PROTOCOL . '_recent';
  185. else {
  186. loadTemplate('Recent');
  187. $context['sub_template'] = 'recent';
  188. }
  189. // Setup the default topic icons... for checking they exist and the like ;)
  190. $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless', 'clip');
  191. $context['icon_sources'] = array();
  192. foreach ($stable_icons as $icon) $context['icon_sources'][$icon] = 'images_url';
  193. // This part is the same for each query.
  194. $select_clause = '
  195. ms.subject AS first_subject, ms.poster_time AS first_poster_time, ms.id_topic, t.id_board, b.name AS bname,
  196. t.num_replies, t.num_views, ms.id_member AS id_first_member, ml.id_member AS id_last_member,
  197. ml.poster_time AS last_poster_time, IFNULL(mems.real_name, ms.poster_name) AS first_poster_name,
  198. IFNULL(meml.real_name, ml.poster_name) AS last_poster_name, ml.subject AS last_subject,
  199. 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,
  200. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, SUBSTRING(ml.body, 1, 385) AS last_body,
  201. 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';
  202. if ($context['showing_all_topics']) {
  203. if (!empty($board)) {
  204. $request = $smcFunc['db_query']('', '
  205. SELECT MIN(id_msg)
  206. FROM {db_prefix}log_mark_read
  207. WHERE id_member = {int:current_member}
  208. AND id_board = {int:current_board}',
  209. array(
  210. 'current_board' => $board,
  211. 'current_member' => $user_info['id'],
  212. )
  213. );
  214. list ($earliest_msg) = $smcFunc['db_fetch_row']($request);
  215. $smcFunc['db_free_result']($request);
  216. } else {
  217. $request = $smcFunc['db_query']('', '
  218. SELECT MIN(lmr.id_msg)
  219. FROM {db_prefix}boards AS b
  220. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})
  221. WHERE {query_see_board}',
  222. array(
  223. 'current_member' => $user_info['id'],
  224. )
  225. );
  226. list ($earliest_msg) = $smcFunc['db_fetch_row']($request);
  227. $smcFunc['db_free_result']($request);
  228. }
  229. // This is needed in case of topics marked unread.
  230. if (empty($earliest_msg)) {
  231. $earliest_msg = 0;
  232. } else {
  233. // Using caching, when possible, to ignore the below slow query.
  234. if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time())
  235. $earliest_msg2 = $_SESSION['cached_log_time'][1];
  236. else
  237. {
  238. // This query is pretty slow, but it's needed to ensure nothing crucial is ignored.
  239. $request = $smcFunc['db_query']('', '
  240. SELECT MIN(id_msg)
  241. FROM {db_prefix}log_topics
  242. WHERE id_member = {int:current_member}',
  243. array(
  244. 'current_member' => $user_info['id'],
  245. )
  246. );
  247. list ($earliest_msg2) = $smcFunc['db_fetch_row']($request);
  248. $smcFunc['db_free_result']($request);
  249. // In theory this could be zero, if the first ever post is unread, so fudge it ;)
  250. if ($earliest_msg2 == 0)
  251. $earliest_msg2 = -1;
  252. $_SESSION['cached_log_time'] = array(time(), $earliest_msg2);
  253. }
  254. $earliest_msg = min($earliest_msg2, $earliest_msg);
  255. }
  256. }
  257. // !!! Add modified_time in for log_time check?
  258. if ($modSettings['totalMessages'] > 100000) {
  259. $smcFunc['db_query']('', '
  260. DROP TABLE IF EXISTS {db_prefix}log_topics_unread',
  261. array(
  262. )
  263. );
  264. // Let's copy things out of the log_topics table, to reduce searching.
  265. $have_temp_table = $smcFunc['db_query']('', '
  266. CREATE TEMPORARY TABLE {db_prefix}log_topics_unread (PRIMARY KEY (id_topic))
  267. SELECT lt.id_topic, lt.id_msg
  268. FROM {db_prefix}topics AS t
  269. INNER JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic)
  270. WHERE lt.id_member = {int:current_member}
  271. AND t.' . $query_this_board . ($modSettings['postmod_active'] ? '
  272. AND t.approved = {int:is_approved}' : ''),
  273. array_merge($query_parameters, array(
  274. 'current_member' => $user_info['id'],
  275. 'is_approved' => 1,
  276. 'db_error_skip' => true,
  277. ))
  278. ) !== false;
  279. echo "have_temp_table = $have_temp_table";
  280. } else {
  281. $have_temp_table = false;
  282. }
  283. $request = $smcFunc['db_query']('', '
  284. SELECT COUNT(*), MIN(t.id_last_msg)
  285. FROM {db_prefix}topics AS t' . (!empty($have_temp_table) ? '
  286. LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : '
  287. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . '
  288. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  289. WHERE t.' . $query_this_board . ($modSettings['postmod_active'] ? '
  290. AND t.approved = {int:is_approved}' : ''),
  291. array_merge($query_parameters, array(
  292. 'current_member' => $user_info['id'],
  293. 'is_approved' => 1,
  294. ))
  295. );
  296. list($num_topics, $min_message) = $smcFunc['db_fetch_row']($request);
  297. $smcFunc['db_free_result']($request);
  298. // Make sure the starting place makes sense and construct the page index.
  299. $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);
  300. $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page'];
  301. $context['links'] = array(
  302. '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'] : '',
  303. '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'] : '',
  304. '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'] : '',
  305. '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'] : '',
  306. 'up' => $scripturl,
  307. );
  308. $context['page_info'] = array(
  309. 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1,
  310. 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1
  311. );
  312. $request = $smcFunc['db_query']('substring', '
  313. SELECT ' . $select_clause . '
  314. FROM {db_prefix}messages AS ms
  315. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ms.id_topic AND t.id_first_msg = ms.id_msg)
  316. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  317. LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  318. LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
  319. LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' . (!empty($have_temp_table) ? '
  320. LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : '
  321. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . '
  322. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
  323. WHERE t.' . $query_this_board . ($modSettings['postmod_active'] ? '
  324. AND ms.approved = {int:is_approved}' : '') . '
  325. ORDER BY {raw:order}
  326. LIMIT {int:offset}, {int:limit}',
  327. array_merge($query_parameters, array(
  328. 'current_member' => $user_info['id'],
  329. 'is_approved' => 1,
  330. 'order' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'),
  331. 'offset' => $_REQUEST['start'],
  332. 'limit' => $context['topics_per_page'],
  333. ))
  334. );
  335. $context['topics'] = array();
  336. $topic_ids = array();
  337. while ($row = $smcFunc['db_fetch_assoc']($request)) {
  338. if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') continue;
  339. $topic_ids[] = $row['id_topic'];
  340. if (!empty($settings['message_index_preview'])) {
  341. // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise.
  342. $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br />' => '&#10;')));
  343. if ($smcFunc['strlen']($row['first_body']) > 128)
  344. $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
  345. $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br />' => '&#10;')));
  346. if ($smcFunc['strlen']($row['last_body']) > 128)
  347. $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
  348. // Censor the subject and message preview.
  349. censorText($row['first_subject']);
  350. censorText($row['first_body']);
  351. // Don't censor them twice!
  352. if ($row['id_first_msg'] == $row['id_last_msg']) {
  353. $row['last_subject'] = $row['first_subject'];
  354. $row['last_body'] = $row['first_body'];
  355. } else {
  356. censorText($row['last_subject']);
  357. censorText($row['last_body']);
  358. }
  359. } else {
  360. $row['first_body'] = '';
  361. $row['last_body'] = '';
  362. censorText($row['first_subject']);
  363. if ($row['id_first_msg'] == $row['id_last_msg'])
  364. $row['last_subject'] = $row['first_subject'];
  365. else
  366. censorText($row['last_subject']);
  367. }
  368. // Decide how many pages the topic should have.
  369. $topic_length = $row['num_replies'] + 1;
  370. $messages_per_page = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) && !WIRELESS ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
  371. if ($topic_length > $messages_per_page)
  372. {
  373. $tmppages = array();
  374. $tmpa = 1;
  375. for ($tmpb = 0; $tmpb < $topic_length; $tmpb += $messages_per_page)
  376. {
  377. $tmppages[] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . $tmpb . ';topicseen">' . $tmpa . '</a>';
  378. $tmpa++;
  379. }
  380. // Show links to all the pages?
  381. if (count($tmppages) <= 5)
  382. $pages = '&#171; ' . implode(' ', $tmppages);
  383. // Or skip a few?
  384. else
  385. $pages = '&#171; ' . $tmppages[0] . ' ' . $tmppages[1] . ' ... ' . $tmppages[count($tmppages) - 2] . ' ' . $tmppages[count($tmppages) - 1];
  386. if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
  387. $pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
  388. $pages .= ' &#187;';
  389. } else {
  390. $pages = '';
  391. }
  392. // We need to check the topic icons exist... you can never be too sure!
  393. if (empty($modSettings['messageIconChecks_disable'])) {
  394. // First icon first... as you'd expect.
  395. if (!isset($context['icon_sources'][$row['first_icon']]))
  396. $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.gif') ? 'images_url' : 'default_images_url';
  397. // Last icon... last... duh.
  398. if (!isset($context['icon_sources'][$row['last_icon']]))
  399. $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.gif') ? 'images_url' : 'default_images_url';
  400. }
  401. // And build the array.
  402. $context['topics'][$row['id_topic']] = array(
  403. 'id' => $row['id_topic'],
  404. 'first_post' => array(
  405. 'id' => $row['id_first_msg'],
  406. 'member' => array(
  407. 'name' => $row['first_poster_name'],
  408. 'id' => $row['id_first_member'],
  409. 'href' => $scripturl . '?action=profile;u=' . $row['id_first_member'],
  410. 'link' => !empty($row['id_first_member']) ? '<a 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']
  411. ),
  412. 'time' => timeformat($row['first_poster_time']),
  413. 'timestamp' => forum_time(true, $row['first_poster_time']),
  414. 'subject' => $row['first_subject'],
  415. 'preview' => $row['first_body'],
  416. 'icon' => $row['first_icon'],
  417. 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.gif',
  418. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen',
  419. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['first_subject'] . '</a>'
  420. ),
  421. 'last_post' => array(
  422. 'id' => $row['id_last_msg'],
  423. 'member' => array(
  424. 'name' => $row['last_poster_name'],
  425. 'id' => $row['id_last_member'],
  426. 'href' => $scripturl . '?action=profile;u=' . $row['id_last_member'],
  427. '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']
  428. ),
  429. 'time' => timeformat($row['last_poster_time']),
  430. 'timestamp' => forum_time(true, $row['last_poster_time']),
  431. 'subject' => $row['last_subject'],
  432. 'preview' => $row['last_body'],
  433. 'icon' => $row['last_icon'],
  434. 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.gif',
  435. 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'],
  436. '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>'
  437. ),
  438. 'new_from' => $row['new_from'],
  439. 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new',
  440. 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'),
  441. '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>',
  442. 'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['is_sticky']),
  443. 'is_locked' => !empty($row['locked']),
  444. 'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
  445. 'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
  446. 'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
  447. 'is_posted_in' => false,
  448. 'icon' => $row['first_icon'],
  449. 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.gif',
  450. 'subject' => $row['first_subject'],
  451. 'pages' => $pages,
  452. 'replies' => comma_format($row['num_replies']),
  453. 'views' => comma_format($row['num_views']),
  454. 'board' => array(
  455. 'id' => $row['id_board'],
  456. 'name' => $row['bname'],
  457. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  458. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'
  459. )
  460. );
  461. determineTopicClass($context['topics'][$row['id_topic']]);
  462. }
  463. $smcFunc['db_free_result']($request);
  464. if ($is_topics && !empty($modSettings['enableParticipation']) && !empty($topic_ids)) {
  465. $result = $smcFunc['db_query']('', '
  466. SELECT id_topic
  467. FROM {db_prefix}messages
  468. WHERE id_topic IN ({array_int:topic_list})
  469. AND id_member = {int:current_member}
  470. GROUP BY id_topic
  471. LIMIT {int:limit}',
  472. array(
  473. 'current_member' => $user_info['id'],
  474. 'topic_list' => $topic_ids,
  475. 'limit' => count($topic_ids),
  476. )
  477. );
  478. while ($row = $smcFunc['db_fetch_assoc']($result)) {
  479. if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) {
  480. $context['topics'][$row['id_topic']]['is_posted_in'] = true;
  481. $context['topics'][$row['id_topic']]['class'] = 'my_' . $context['topics'][$row['id_topic']]['class'];
  482. }
  483. }
  484. $smcFunc['db_free_result']($result);
  485. }
  486. $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
  487. $context['topics_to_mark'] = implode('-', $topic_ids);
  488. }
  489. ]]></add>
  490. </operation>
  491. </file>
  492. <file name="$themedir/Recent.template.php">
  493. <operation>
  494. <search position="end" />
  495. <add><![CDATA[
  496. function template_recent() {
  497. global $context, $settings, $options, $txt, $scripturl, $modSettings;
  498. echo '
  499. <div id="recent" class="main_content">';
  500. $showCheckboxes = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $settings['show_mark_read'];
  501. if ($showCheckboxes)
  502. echo '
  503. <form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="quickModForm" id="quickModForm" style="margin: 0;">
  504. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
  505. <input type="hidden" name="qaction" value="markread" />
  506. <input type="hidden" name="redirect_url" value="action=unread', (!empty($context['showing_all_topics']) ? ';all' : ''), $context['querystring_board_limits'], '" />';
  507. if ($settings['show_mark_read'])
  508. {
  509. // Generate the button strip.
  510. $mark_read = array(
  511. 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.gif', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']),
  512. );
  513. if ($showCheckboxes)
  514. $mark_read['markselectread'] = array(
  515. 'text' => 'quick_mod_markread',
  516. 'image' => 'markselectedread.gif',
  517. 'lang' => true,
  518. 'url' => 'javascript:document.quickModForm.submit();',
  519. );
  520. }
  521. if (!empty($context['topics']))
  522. {
  523. echo '
  524. <div class="pagesection">';
  525. if (!empty($mark_read) && !empty($settings['use_tabs']))
  526. template_button_strip($mark_read, 'right');
  527. echo '
  528. <span>', $txt['pages'], ': ', $context['page_index'], '</span>
  529. </div>';
  530. echo '
  531. <div class="tborder topic_table" id="unread">
  532. <table class="table_grid" cellspacing="0">
  533. <thead>
  534. <tr class="catbg">
  535. <th scope="col" class="first_th" width="8%" colspan="2">&nbsp;</th>
  536. <th scope="col">
  537. <a href="', $scripturl, '?action=unread', $context['showing_all_topics'] ? ';all' : '', $context['querystring_board_limits'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a>
  538. </th>
  539. <th scope="col" width="14%" align="center">
  540. <a href="', $scripturl, '?action=unread', $context['showing_all_topics'] ? ';all' : '', $context['querystring_board_limits'], ';sort=replies', $context['sort_by'] == 'replies' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['replies'], $context['sort_by'] == 'replies' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a>
  541. </th>';
  542. // Show a "select all" box for quick moderation?
  543. if ($showCheckboxes)
  544. echo '
  545. <th scope="col" width="22%">
  546. <a href="', $scripturl, '?action=unread', $context['showing_all_topics'] ? ';all' : '', $context['querystring_board_limits'], ';sort=last_post', $context['sort_by'] == 'last_post' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['last_post'], $context['sort_by'] == 'last_post' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a>
  547. </th>
  548. <th class="last_th">
  549. <input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');" class="input_check" />
  550. </th>';
  551. else
  552. echo '
  553. <th scope="col" class="smalltext last_th" width="22%">
  554. <a href="', $scripturl, '?action=unread', $context['showing_all_topics'] ? ';all' : '', $context['querystring_board_limits'], ';sort=last_post', $context['sort_by'] == 'last_post' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['last_post'], $context['sort_by'] == 'last_post' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a>
  555. </th>';
  556. echo '
  557. </tr>
  558. </thead>
  559. <tbody>';
  560. foreach ($context['topics'] as $topic)
  561. {
  562. // Calculate the color class of the topic.
  563. $color_class = '';
  564. if (strpos($topic['class'], 'sticky') !== false)
  565. $color_class = 'stickybg';
  566. if (strpos($topic['class'], 'locked') !== false)
  567. $color_class .= 'lockedbg';
  568. $color_class2 = !empty($color_class) ? $color_class . '2' : '';
  569. echo '
  570. <tr>
  571. <td class="', $color_class, ' icon1 windowbg">
  572. <img src="', $settings['images_url'], '/topic/', $topic['class'], '.gif" alt="" />
  573. </td>
  574. <td class="', $color_class, ' icon2 windowbg">
  575. <img src="', $topic['first_post']['icon_url'], '" alt="" />
  576. </td>
  577. <td class="subject ', $color_class2, ' windowbg2">
  578. <div>
  579. ', $topic['is_sticky'] ? '<strong>' : '', '<span id="msg_' . $topic['first_post']['id'] . '">', $topic['first_post']['link'], '</span>', $topic['is_sticky'] ? '</strong>' : '', '
  580. ', ($topic['new_from'] <= $topic['last_post']['id'] ? '
  581. <a href="' . $topic['new_href'] . '" id="newicon' . $topic['first_post']['id'] . '"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>
  582. ' : ''), '
  583. <p>
  584. ', $txt['started_by'], ' <strong>', $topic['first_post']['member']['link'], '</strong>
  585. ', $txt['in'], ' <em>', $topic['board']['link'], '</em>
  586. <small id="pages', $topic['first_post']['id'], '">', $topic['pages'], '</small>
  587. </p>
  588. </div>
  589. </td>
  590. <td class="', $color_class, ' stats windowbg">
  591. ', $topic['replies'], ' ', $txt['replies'], '
  592. <br />
  593. ', $topic['views'], ' ', $txt['views'], '
  594. </td>
  595. <td class="', $color_class2, ' lastpost windowbg2">
  596. <a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" style="float: right;" /></a>
  597. ', $topic['last_post']['time'], '<br />
  598. ', $txt['by'], ' ', $topic['last_post']['member']['link'], '
  599. </td>';
  600. if ($showCheckboxes)
  601. echo '
  602. <td class="windowbg2" valign="middle" align="center">
  603. <input type="checkbox" name="topics[]" value="', $topic['id'], '" class="input_check" />
  604. </td>';
  605. echo '
  606. </tr>';
  607. }
  608. if (!empty($context['topics']) && !$context['showing_all_topics'])
  609. $mark_read['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.gif', 'lang' => true, 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
  610. if (empty($settings['use_tabs']) && !empty($mark_read))
  611. echo '
  612. <tr class="catbg">
  613. <td colspan="', $showCheckboxes ? '6' : '5', '" align="right">
  614. ', template_button_strip($mark_read, 'top'), '
  615. </td>
  616. </tr>';
  617. if (empty($context['topics']))
  618. echo '
  619. <tr style="display: none;"><td></td></tr>';
  620. echo '
  621. </tbody>
  622. </table>
  623. </div>
  624. <div class="pagesection" id="readbuttons">';
  625. if (!empty($settings['use_tabs']) && !empty($mark_read))
  626. template_button_strip($mark_read, 'right');
  627. echo '
  628. <span>', $txt['pages'], ': ', $context['page_index'], '</span>
  629. </div>';
  630. } else {
  631. echo '
  632. <div class="cat_bar">
  633. <h3 class="catbg centertext">
  634. ', $context['showing_all_topics'] ? $txt['msg_alert_none'] : $txt['unread_topics_visit_none'], '
  635. </h3>
  636. </div>';
  637. }
  638. if ($showCheckboxes)
  639. echo '
  640. </form>';
  641. echo '
  642. <div class="description " id="topic_icons">
  643. <p class="smalltext floatleft">
  644. ', !empty($modSettings['enableParticipation']) ? '
  645. <img src="' . $settings['images_url'] . '/topic/my_normal_post.gif" alt="" align="middle" /> ' . $txt['participation_caption'] . '<br />' : '', '
  646. <img src="', $settings['images_url'], '/topic/normal_post.gif" alt="" align="middle" /> ', $txt['normal_topic'], '<br />
  647. <img src="', $settings['images_url'], '/topic/hot_post.gif" alt="" align="middle" /> ', sprintf($txt['hot_topics'], $modSettings['hotTopicPosts']), '<br />
  648. <img src="', $settings['images_url'], '/topic/veryhot_post.gif" alt="" align="middle" /> ', sprintf($txt['very_hot_topics'], $modSettings['hotTopicVeryPosts']), '
  649. </p>
  650. <p class="smalltext para2">
  651. <img src="', $settings['images_url'], '/icons/quick_lock.gif" alt="" align="middle" /> ', $txt['locked_topic'], '<br />', ($modSettings['enableStickyTopics'] == '1' ? '
  652. <img src="' . $settings['images_url'] . '/icons/quick_sticky.gif" alt="" align="middle" /> ' . $txt['sticky_topic'] . '<br />' : ''), ($modSettings['pollMode'] == '1' ? '
  653. <img src="' . $settings['images_url'] . '/topic/normal_poll.gif" alt="" align="middle" /> ' . $txt['poll'] : ''), '
  654. </p>
  655. </div>
  656. </div>';
  657. }
  658. ]]></add>
  659. </operation>
  660. </file>
  661. </modification>