annotate forum/Sources/Subs-Recent.php @ 85:6d7b61434be7 website

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