Subs-Recent.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /* !!!
  15. */
  16. // Get the latest posts of a forum.
  17. function getLastPosts($latestPostOptions)
  18. {
  19. global $scripturl, $txt, $user_info, $modSettings, $smcFunc, $context;
  20. // Find all the posts. Newer ones will have higher IDs. (assuming the last 20 * number are accessable...)
  21. // !!!SLOW This query is now slow, NEEDS to be fixed. Maybe break into two?
  22. $request = $smcFunc['db_query']('substring', '
  23. SELECT
  24. m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg,
  25. IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_board, b.name AS board_name,
  26. SUBSTRING(m.body, 1, 385) AS body, m.smileys_enabled
  27. FROM {db_prefix}messages AS m
  28. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
  29. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
  30. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  31. WHERE m.id_msg >= {int:likely_max_msg}' .
  32. (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
  33. AND b.id_board != {int:recycle_board}' : '') . '
  34. AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
  35. AND t.approved = {int:is_approved}
  36. AND m.approved = {int:is_approved}' : '') . '
  37. ORDER BY m.id_msg DESC
  38. LIMIT ' . $latestPostOptions['number_posts'],
  39. array(
  40. 'likely_max_msg' => max(0, $modSettings['maxMsgID'] - 50 * $latestPostOptions['number_posts']),
  41. 'recycle_board' => $modSettings['recycle_board'],
  42. 'is_approved' => 1,
  43. )
  44. );
  45. $posts = array();
  46. while ($row = $smcFunc['db_fetch_assoc']($request))
  47. {
  48. // Censor the subject and post for the preview ;).
  49. censorText($row['subject']);
  50. censorText($row['body']);
  51. $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => '&#10;')));
  52. if ($smcFunc['strlen']($row['body']) > 128)
  53. $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
  54. // Build the array.
  55. $posts[] = array(
  56. 'board' => array(
  57. 'id' => $row['id_board'],
  58. 'name' => $row['board_name'],
  59. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  60. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
  61. ),
  62. 'topic' => $row['id_topic'],
  63. 'poster' => array(
  64. 'id' => $row['id_member'],
  65. 'name' => $row['poster_name'],
  66. 'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
  67. 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
  68. ),
  69. 'subject' => $row['subject'],
  70. 'short_subject' => shorten_subject($row['subject'], 24),
  71. 'preview' => $row['body'],
  72. 'time' => timeformat($row['poster_time']),
  73. 'timestamp' => forum_time(true, $row['poster_time']),
  74. 'raw_timestamp' => $row['poster_time'],
  75. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#msg' . $row['id_msg'],
  76. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>'
  77. );
  78. }
  79. $smcFunc['db_free_result']($request);
  80. return $posts;
  81. }
  82. // Callback-function for the cache for getLastPosts().
  83. function cache_getLastPosts($latestPostOptions)
  84. {
  85. return array(
  86. 'data' => getLastPosts($latestPostOptions),
  87. 'expires' => time() + 60,
  88. 'post_retri_eval' => '
  89. foreach ($cache_block[\'data\'] as $k => $post)
  90. {
  91. $cache_block[\'data\'][$k][\'time\'] = timeformat($post[\'raw_timestamp\']);
  92. $cache_block[\'data\'][$k][\'timestamp\'] = forum_time(true, $post[\'raw_timestamp\']);
  93. }',
  94. );
  95. }
  96. ?>