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