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 /* This file currently only contains one function to collect the data needed to
|
Chris@76
|
18 show a list of boards for the board index and the message index.
|
Chris@76
|
19
|
Chris@76
|
20 array getBoardIndex(array boardIndexOptions)
|
Chris@76
|
21 - Fetches a list of boards and (optional) categories including
|
Chris@76
|
22 statistical information, child boards and moderators.
|
Chris@76
|
23 - Used by both the board index (main data) and the message index (child
|
Chris@76
|
24 boards).
|
Chris@76
|
25 - Depending on the include_categories setting returns an associative
|
Chris@76
|
26 array with categories->boards->child_boards or an associative array
|
Chris@76
|
27 with boards->child_boards.
|
Chris@76
|
28 */
|
Chris@76
|
29
|
Chris@76
|
30 function getBoardIndex($boardIndexOptions)
|
Chris@76
|
31 {
|
Chris@76
|
32 global $smcFunc, $scripturl, $user_info, $modSettings, $txt;
|
Chris@76
|
33 global $settings, $context;
|
Chris@76
|
34
|
Chris@76
|
35 // For performance, track the latest post while going through the boards.
|
Chris@76
|
36 if (!empty($boardIndexOptions['set_latest_post']))
|
Chris@76
|
37 $latest_post = array(
|
Chris@76
|
38 'timestamp' => 0,
|
Chris@76
|
39 'ref' => 0,
|
Chris@76
|
40 );
|
Chris@76
|
41
|
Chris@76
|
42 // Find all boards and categories, as well as related information. This will be sorted by the natural order of boards and categories, which we control.
|
Chris@76
|
43 $result_boards = $smcFunc['db_query']('boardindex_fetch_boards', '
|
Chris@76
|
44 SELECT' . ($boardIndexOptions['include_categories'] ? '
|
Chris@76
|
45 c.id_cat, c.name AS cat_name,' : '') . '
|
Chris@76
|
46 b.id_board, b.name AS board_name, b.description,
|
Chris@76
|
47 CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect,
|
Chris@76
|
48 b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent,
|
Chris@76
|
49 IFNULL(m.poster_time, 0) AS poster_time, IFNULL(mem.member_name, m.poster_name) AS poster_name,
|
Chris@76
|
50 m.subject, m.id_topic, IFNULL(mem.real_name, m.poster_name) AS real_name,
|
Chris@76
|
51 ' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : '
|
Chris@76
|
52 (IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read, IFNULL(lb.id_msg, -1) + 1 AS new_from,' . ($boardIndexOptions['include_categories'] ? '
|
Chris@76
|
53 c.can_collapse, IFNULL(cc.id_member, 0) AS is_collapsed,' : '')) . '
|
Chris@76
|
54 IFNULL(mem.id_member, 0) AS id_member, m.id_msg,
|
Chris@76
|
55 IFNULL(mods_mem.id_member, 0) AS id_moderator, mods_mem.real_name AS mod_real_name
|
Chris@76
|
56 FROM {db_prefix}boards AS b' . ($boardIndexOptions['include_categories'] ? '
|
Chris@76
|
57 LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . '
|
Chris@76
|
58 LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg)
|
Chris@76
|
59 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . ($user_info['is_guest'] ? '' : '
|
Chris@76
|
60 LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})' . ($boardIndexOptions['include_categories'] ? '
|
Chris@76
|
61 LEFT JOIN {db_prefix}collapsed_categories AS cc ON (cc.id_cat = c.id_cat AND cc.id_member = {int:current_member})' : '')) . '
|
Chris@76
|
62 LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board)
|
Chris@76
|
63 LEFT JOIN {db_prefix}members AS mods_mem ON (mods_mem.id_member = mods.id_member)
|
Chris@76
|
64 WHERE {query_see_board}' . (empty($boardIndexOptions['countChildPosts']) ? (empty($boardIndexOptions['base_level']) ? '' : '
|
Chris@76
|
65 AND b.child_level >= {int:child_level}') : '
|
Chris@76
|
66 AND b.child_level BETWEEN ' . $boardIndexOptions['base_level'] . ' AND ' . ($boardIndexOptions['base_level'] + 1)),
|
Chris@76
|
67 array(
|
Chris@76
|
68 'current_member' => $user_info['id'],
|
Chris@76
|
69 'child_level' => $boardIndexOptions['base_level'],
|
Chris@76
|
70 'blank_string' => '',
|
Chris@76
|
71 )
|
Chris@76
|
72 );
|
Chris@76
|
73
|
Chris@76
|
74 // Start with an empty array.
|
Chris@76
|
75 if ($boardIndexOptions['include_categories'])
|
Chris@76
|
76 $categories = array();
|
Chris@76
|
77 else
|
Chris@76
|
78 $this_category = array();
|
Chris@76
|
79
|
Chris@76
|
80 // Run through the categories and boards (or only boards)....
|
Chris@76
|
81 while ($row_board = $smcFunc['db_fetch_assoc']($result_boards))
|
Chris@76
|
82 {
|
Chris@76
|
83 // Perhaps we are ignoring this board?
|
Chris@76
|
84 $ignoreThisBoard = in_array($row_board['id_board'], $user_info['ignoreboards']);
|
Chris@76
|
85 $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
|
Chris@76
|
86
|
Chris@76
|
87 if ($boardIndexOptions['include_categories'])
|
Chris@76
|
88 {
|
Chris@76
|
89 // Haven't set this category yet.
|
Chris@76
|
90 if (empty($categories[$row_board['id_cat']]))
|
Chris@76
|
91 {
|
Chris@76
|
92 $categories[$row_board['id_cat']] = array(
|
Chris@76
|
93 'id' => $row_board['id_cat'],
|
Chris@76
|
94 'name' => $row_board['cat_name'],
|
Chris@76
|
95 'is_collapsed' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1 && $row_board['is_collapsed'] > 0,
|
Chris@76
|
96 'can_collapse' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1,
|
Chris@76
|
97 'collapse_href' => isset($row_board['can_collapse']) ? $scripturl . '?action=collapse;c=' . $row_board['id_cat'] . ';sa=' . ($row_board['is_collapsed'] > 0 ? 'expand;' : 'collapse;') . $context['session_var'] . '=' . $context['session_id'] . '#c' . $row_board['id_cat'] : '',
|
Chris@76
|
98 'collapse_image' => isset($row_board['can_collapse']) ? '<img src="' . $settings['images_url'] . '/' . $context['theme_variant_url'] . ($row_board['is_collapsed'] > 0 ? 'expand.gif" alt="+"' : 'collapse.gif" alt="-"') . ' />' : '',
|
Chris@76
|
99 'href' => $scripturl . '#c' . $row_board['id_cat'],
|
Chris@76
|
100 'boards' => array(),
|
Chris@76
|
101 'new' => false
|
Chris@76
|
102 );
|
Chris@76
|
103 $categories[$row_board['id_cat']]['link'] = '<a id="c' . $row_board['id_cat'] . '"></a>' . ($categories[$row_board['id_cat']]['can_collapse'] ? '<a href="' . $categories[$row_board['id_cat']]['collapse_href'] . '">' . $row_board['cat_name'] . '</a>' : $row_board['cat_name']);
|
Chris@76
|
104 }
|
Chris@76
|
105
|
Chris@76
|
106 // If this board has new posts in it (and isn't the recycle bin!) then the category is new.
|
Chris@76
|
107 if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
|
Chris@76
|
108 $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
|
Chris@76
|
109
|
Chris@76
|
110 // Avoid showing category unread link where it only has redirection boards.
|
Chris@76
|
111 $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
|
Chris@76
|
112
|
Chris@76
|
113 // Collapsed category - don't do any of this.
|
Chris@76
|
114 if ($categories[$row_board['id_cat']]['is_collapsed'])
|
Chris@76
|
115 continue;
|
Chris@76
|
116
|
Chris@76
|
117 // Let's save some typing. Climbing the array might be slower, anyhow.
|
Chris@76
|
118 $this_category = &$categories[$row_board['id_cat']]['boards'];
|
Chris@76
|
119 }
|
Chris@76
|
120
|
Chris@76
|
121 // This is a parent board.
|
Chris@76
|
122 if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
|
Chris@76
|
123 {
|
Chris@76
|
124 // Is this a new board, or just another moderator?
|
Chris@76
|
125 if (!isset($this_category[$row_board['id_board']]))
|
Chris@76
|
126 {
|
Chris@76
|
127 // Not a child.
|
Chris@76
|
128 $isChild = false;
|
Chris@76
|
129
|
Chris@76
|
130 $this_category[$row_board['id_board']] = array(
|
Chris@76
|
131 'new' => empty($row_board['is_read']),
|
Chris@76
|
132 'id' => $row_board['id_board'],
|
Chris@76
|
133 'name' => $row_board['board_name'],
|
Chris@76
|
134 'description' => $row_board['description'],
|
Chris@76
|
135 'moderators' => array(),
|
Chris@76
|
136 'link_moderators' => array(),
|
Chris@76
|
137 'children' => array(),
|
Chris@76
|
138 'link_children' => array(),
|
Chris@76
|
139 'children_new' => false,
|
Chris@76
|
140 'topics' => $row_board['num_topics'],
|
Chris@76
|
141 'posts' => $row_board['num_posts'],
|
Chris@76
|
142 'is_redirect' => $row_board['is_redirect'],
|
Chris@76
|
143 'unapproved_topics' => $row_board['unapproved_topics'],
|
Chris@76
|
144 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'],
|
Chris@76
|
145 'can_approve_posts' => !empty($user_info['mod_cache']['ap']) && ($user_info['mod_cache']['ap'] == array(0) || in_array($row_board['id_board'], $user_info['mod_cache']['ap'])),
|
Chris@76
|
146 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0',
|
Chris@76
|
147 'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>'
|
Chris@76
|
148 );
|
Chris@76
|
149 }
|
Chris@76
|
150 if (!empty($row_board['id_moderator']))
|
Chris@76
|
151 {
|
Chris@76
|
152 $this_category[$row_board['id_board']]['moderators'][$row_board['id_moderator']] = array(
|
Chris@76
|
153 'id' => $row_board['id_moderator'],
|
Chris@76
|
154 'name' => $row_board['mod_real_name'],
|
Chris@76
|
155 'href' => $scripturl . '?action=profile;u=' . $row_board['id_moderator'],
|
Chris@76
|
156 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_board['id_moderator'] . '" title="' . $txt['board_moderator'] . '">' . $row_board['mod_real_name'] . '</a>'
|
Chris@76
|
157 );
|
Chris@76
|
158 $this_category[$row_board['id_board']]['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row_board['id_moderator'] . '" title="' . $txt['board_moderator'] . '">' . $row_board['mod_real_name'] . '</a>';
|
Chris@76
|
159 }
|
Chris@76
|
160 }
|
Chris@76
|
161 // Found a child board.... make sure we've found its parent and the child hasn't been set already.
|
Chris@76
|
162 elseif (isset($this_category[$row_board['id_parent']]['children']) && !isset($this_category[$row_board['id_parent']]['children'][$row_board['id_board']]))
|
Chris@76
|
163 {
|
Chris@76
|
164 // A valid child!
|
Chris@76
|
165 $isChild = true;
|
Chris@76
|
166
|
Chris@76
|
167 $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array(
|
Chris@76
|
168 'id' => $row_board['id_board'],
|
Chris@76
|
169 'name' => $row_board['board_name'],
|
Chris@76
|
170 'description' => $row_board['description'],
|
Chris@76
|
171 'new' => empty($row_board['is_read']) && $row_board['poster_name'] != '',
|
Chris@76
|
172 'topics' => $row_board['num_topics'],
|
Chris@76
|
173 'posts' => $row_board['num_posts'],
|
Chris@76
|
174 'is_redirect' => $row_board['is_redirect'],
|
Chris@76
|
175 'unapproved_topics' => $row_board['unapproved_topics'],
|
Chris@76
|
176 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'],
|
Chris@76
|
177 'can_approve_posts' => !empty($user_info['mod_cache']['ap']) && ($user_info['mod_cache']['ap'] == array(0) || in_array($row_board['id_board'], $user_info['mod_cache']['ap'])),
|
Chris@76
|
178 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0',
|
Chris@76
|
179 'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>'
|
Chris@76
|
180 );
|
Chris@76
|
181
|
Chris@76
|
182 // Counting child board posts is... slow :/.
|
Chris@76
|
183 if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect'])
|
Chris@76
|
184 {
|
Chris@76
|
185 $this_category[$row_board['id_parent']]['posts'] += $row_board['num_posts'];
|
Chris@76
|
186 $this_category[$row_board['id_parent']]['topics'] += $row_board['num_topics'];
|
Chris@76
|
187 }
|
Chris@76
|
188
|
Chris@76
|
189 // Does this board contain new boards?
|
Chris@76
|
190 $this_category[$row_board['id_parent']]['children_new'] |= empty($row_board['is_read']);
|
Chris@76
|
191
|
Chris@76
|
192 // This is easier to use in many cases for the theme....
|
Chris@76
|
193 $this_category[$row_board['id_parent']]['link_children'][] = &$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['link'];
|
Chris@76
|
194 }
|
Chris@76
|
195 // Child of a child... just add it on...
|
Chris@76
|
196 elseif (!empty($boardIndexOptions['countChildPosts']))
|
Chris@76
|
197 {
|
Chris@76
|
198 if (!isset($parent_map))
|
Chris@76
|
199 $parent_map = array();
|
Chris@76
|
200
|
Chris@76
|
201 if (!isset($parent_map[$row_board['id_parent']]))
|
Chris@76
|
202 foreach ($this_category as $id => $board)
|
Chris@76
|
203 {
|
Chris@76
|
204 if (!isset($board['children'][$row_board['id_parent']]))
|
Chris@76
|
205 continue;
|
Chris@76
|
206
|
Chris@76
|
207 $parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
|
Chris@76
|
208 $parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
|
Chris@76
|
209
|
Chris@76
|
210 break;
|
Chris@76
|
211 }
|
Chris@76
|
212
|
Chris@76
|
213 if (isset($parent_map[$row_board['id_parent']]) && !$row_board['is_redirect'])
|
Chris@76
|
214 {
|
Chris@76
|
215 $parent_map[$row_board['id_parent']][0]['posts'] += $row_board['num_posts'];
|
Chris@76
|
216 $parent_map[$row_board['id_parent']][0]['topics'] += $row_board['num_topics'];
|
Chris@76
|
217 $parent_map[$row_board['id_parent']][1]['posts'] += $row_board['num_posts'];
|
Chris@76
|
218 $parent_map[$row_board['id_parent']][1]['topics'] += $row_board['num_topics'];
|
Chris@76
|
219
|
Chris@76
|
220 continue;
|
Chris@76
|
221 }
|
Chris@76
|
222
|
Chris@76
|
223 continue;
|
Chris@76
|
224 }
|
Chris@76
|
225 // Found a child of a child - skip.
|
Chris@76
|
226 else
|
Chris@76
|
227 continue;
|
Chris@76
|
228
|
Chris@76
|
229 // Prepare the subject, and make sure it's not too long.
|
Chris@76
|
230 censorText($row_board['subject']);
|
Chris@76
|
231 $row_board['short_subject'] = shorten_subject($row_board['subject'], 24);
|
Chris@76
|
232 $this_last_post = array(
|
Chris@76
|
233 'id' => $row_board['id_msg'],
|
Chris@76
|
234 'time' => $row_board['poster_time'] > 0 ? timeformat($row_board['poster_time']) : $txt['not_applicable'],
|
Chris@76
|
235 'timestamp' => forum_time(true, $row_board['poster_time']),
|
Chris@76
|
236 'subject' => $row_board['short_subject'],
|
Chris@76
|
237 'member' => array(
|
Chris@76
|
238 'id' => $row_board['id_member'],
|
Chris@76
|
239 'username' => $row_board['poster_name'] != '' ? $row_board['poster_name'] : $txt['not_applicable'],
|
Chris@76
|
240 'name' => $row_board['real_name'],
|
Chris@76
|
241 'href' => $row_board['poster_name'] != '' && !empty($row_board['id_member']) ? $scripturl . '?action=profile;u=' . $row_board['id_member'] : '',
|
Chris@76
|
242 'link' => $row_board['poster_name'] != '' ? (!empty($row_board['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row_board['id_member'] . '">' . $row_board['real_name'] . '</a>' : $row_board['real_name']) : $txt['not_applicable'],
|
Chris@76
|
243 ),
|
Chris@76
|
244 'start' => 'msg' . $row_board['new_from'],
|
Chris@76
|
245 'topic' => $row_board['id_topic']
|
Chris@76
|
246 );
|
Chris@76
|
247
|
Chris@76
|
248 // Provide the href and link.
|
Chris@76
|
249 if ($row_board['subject'] != '')
|
Chris@76
|
250 {
|
Chris@76
|
251 $this_last_post['href'] = $scripturl . '?topic=' . $row_board['id_topic'] . '.msg' . ($user_info['is_guest'] ? $row_board['id_msg'] : $row_board['new_from']) . (empty($row_board['is_read']) ? ';boardseen' : '') . '#new';
|
Chris@76
|
252 $this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>';
|
Chris@76
|
253 }
|
Chris@76
|
254 else
|
Chris@76
|
255 {
|
Chris@76
|
256 $this_last_post['href'] = '';
|
Chris@76
|
257 $this_last_post['link'] = $txt['not_applicable'];
|
Chris@76
|
258 }
|
Chris@76
|
259
|
Chris@76
|
260 // Set the last post in the parent board.
|
Chris@76
|
261 if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])))
|
Chris@76
|
262 $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
|
Chris@76
|
263 // Just in the child...?
|
Chris@76
|
264 if ($isChild)
|
Chris@76
|
265 {
|
Chris@76
|
266 $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
|
Chris@76
|
267
|
Chris@76
|
268 // If there are no posts in this board, it really can't be new...
|
Chris@76
|
269 $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
|
Chris@76
|
270 }
|
Chris@76
|
271 // No last post for this board? It's not new then, is it..?
|
Chris@76
|
272 elseif ($row_board['poster_name'] == '')
|
Chris@76
|
273 $this_category[$row_board['id_board']]['new'] = false;
|
Chris@76
|
274
|
Chris@76
|
275 // Determine a global most recent topic.
|
Chris@76
|
276 if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
|
Chris@76
|
277 $latest_post = array(
|
Chris@76
|
278 'timestamp' => $row_board['poster_time'],
|
Chris@76
|
279 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
|
Chris@76
|
280 );
|
Chris@76
|
281 }
|
Chris@76
|
282 $smcFunc['db_free_result']($result_boards);
|
Chris@76
|
283
|
Chris@76
|
284 // By now we should know the most recent post...if we wanna know it that is.
|
Chris@76
|
285 if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
|
Chris@76
|
286 $context['latest_post'] = $latest_post['ref'];
|
Chris@76
|
287
|
Chris@76
|
288 return $boardIndexOptions['include_categories'] ? $categories : $this_category;
|
Chris@76
|
289 }
|
Chris@76
|
290
|
Chris@76
|
291 ?> |