Conditions | 125 |
Paths | 0 |
Total Lines | 538 |
Code Lines | 314 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
33 | function getBoardIndex($board_index_options) |
||
34 | { |
||
35 | global $smcFunc, $scripturl, $user_info, $modSettings, $txt; |
||
36 | global $settings, $options, $context, $sourcedir; |
||
37 | |||
38 | require_once($sourcedir . '/Subs-Boards.php'); |
||
39 | |||
40 | // For performance, track the latest post while going through the boards. |
||
41 | if (!empty($board_index_options['set_latest_post'])) |
||
42 | $latest_post = array( |
||
43 | 'timestamp' => 0, |
||
44 | 'ref' => 0 |
||
45 | ); |
||
46 | |||
47 | // This setting is not allowed to be empty |
||
48 | if (empty($modSettings['boardindex_max_depth'])) |
||
49 | $modSettings['boardindex_max_depth'] = 1; |
||
50 | |||
51 | $board_index_selects = array( |
||
52 | 'b.id_board', |
||
53 | 'b.name AS board_name', |
||
54 | 'b.description', |
||
55 | 'CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect', |
||
56 | 'b.num_posts', |
||
57 | 'b.num_topics', |
||
58 | 'b.unapproved_posts', |
||
59 | 'b.unapproved_topics', |
||
60 | 'b.id_parent', |
||
61 | 'b.id_cat' |
||
62 | ); |
||
63 | |||
64 | $board_index_parameters = array( |
||
65 | 'current_member' => $user_info['id'], |
||
66 | 'child_level' => $board_index_options['base_level'], |
||
67 | 'max_child_level' => $board_index_options['base_level'] + $modSettings['boardindex_max_depth'], |
||
68 | 'blank_string' => '' |
||
69 | ); |
||
70 | |||
71 | call_integration_hook('integrate_pre_boardindex', array(&$board_index_selects, &$board_index_parameters)); |
||
72 | |||
73 | // 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. |
||
74 | if ($board_index_options['parent_id'] != 0 && $smcFunc['db_cte_support']()) |
||
75 | $result_boards = $smcFunc['db_query']('', ' |
||
76 | WITH RECURSIVE |
||
77 | boards_cte (child_level, id_board, name, description, redirect, num_posts, num_topics, unapproved_posts, unapproved_topics, id_parent, id_msg_updated, id_cat, id_last_msg, board_order) |
||
78 | AS |
||
79 | ( |
||
80 | SELECT b.child_level, b.id_board, b.name, b.description, b.redirect, b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, b.id_msg_updated, b.id_cat, b.id_last_msg, b.board_order |
||
81 | FROM {db_prefix}boards AS b |
||
82 | WHERE {query_see_board} AND b.id_board = {int:id_parent} |
||
83 | UNION ALL |
||
84 | SELECT b.child_level, b.id_board, b.name, b.description, b.redirect, b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, b.id_msg_updated, b.id_cat, b.id_last_msg, b.board_order |
||
85 | FROM {db_prefix}boards AS b |
||
86 | JOIN boards_cte AS bc ON (b.id_parent = bc.id_board) |
||
87 | WHERE {query_see_board} |
||
88 | AND b.child_level BETWEEN {int:child_level} AND {int:max_child_level} |
||
89 | ) |
||
90 | SELECT' . ($board_index_options['include_categories'] ? ' |
||
91 | c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . ' |
||
92 | ' . (!empty($board_index_selects) ? implode(', ', $board_index_selects) : '') . ', |
||
93 | COALESCE(m.poster_time, 0) AS poster_time, COALESCE(mem.member_name, m.poster_name) AS poster_name, |
||
94 | m.subject, m.id_topic, COALESCE(mem.real_name, m.poster_name) AS real_name, |
||
95 | ' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : ' |
||
96 | (CASE WHEN COALESCE(lb.id_msg, 0) >= b.id_last_msg THEN 1 ELSE 0 END) AS is_read, COALESCE(lb.id_msg, -1) + 1 AS new_from,' . ($board_index_options['include_categories'] ? ' |
||
97 | c.can_collapse,' : '')) . ' |
||
98 | COALESCE(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . (!empty($settings['avatars_on_boardIndex']) ? ', mem.email_address, mem.avatar, COALESCE(am.id_attach, 0) AS member_id_attach, am.filename AS member_filename, am.attachment_type AS member_attach_type' : '') . ' |
||
99 | FROM boards_cte AS b' . ($board_index_options['include_categories'] ? ' |
||
100 | LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . ' |
||
101 | LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg) |
||
102 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!empty($settings['avatars_on_boardIndex']) ? ' |
||
103 | LEFT JOIN {db_prefix}attachments AS am ON (am.id_member = m.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : ' |
||
104 | LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})') . ' |
||
105 | WHERE b.id_parent != 0 |
||
106 | ORDER BY ' . (!empty($board_index_options['include_categories']) ? 'c.cat_order, ' : '') . 'b.child_level DESC, b.board_order DESC', |
||
107 | array_merge($board_index_parameters, array( |
||
108 | 'id_parent' => $board_index_options['parent_id'] |
||
109 | )) |
||
110 | ); |
||
111 | else |
||
112 | $result_boards = $smcFunc['db_query']('', ' |
||
113 | SELECT' . ($board_index_options['include_categories'] ? ' |
||
114 | c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . ' |
||
115 | ' . (!empty($board_index_selects) ? implode(', ', $board_index_selects) : '') . ', |
||
116 | COALESCE(m.poster_time, 0) AS poster_time, COALESCE(mem.member_name, m.poster_name) AS poster_name, |
||
117 | m.subject, m.id_topic, COALESCE(mem.real_name, m.poster_name) AS real_name, |
||
118 | ' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : ' |
||
119 | (CASE WHEN COALESCE(lb.id_msg, 0) >= b.id_last_msg THEN 1 ELSE 0 END) AS is_read, COALESCE(lb.id_msg, -1) + 1 AS new_from,' . ($board_index_options['include_categories'] ? ' |
||
120 | c.can_collapse,' : '')) . ' |
||
121 | COALESCE(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . (!empty($settings['avatars_on_boardIndex']) ? ', mem.email_address, mem.avatar, COALESCE(am.id_attach, 0) AS member_id_attach, am.filename AS member_filename, am.attachment_type AS member_attach_type' : '') . ' |
||
122 | FROM {db_prefix}boards AS b' . ($board_index_options['include_categories'] ? ' |
||
123 | LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . ' |
||
124 | LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg) |
||
125 | LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!empty($settings['avatars_on_boardIndex']) ? ' |
||
126 | LEFT JOIN {db_prefix}attachments AS am ON (am.id_member = m.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : ' |
||
127 | LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})') . ' |
||
128 | WHERE {query_see_board} |
||
129 | AND b.child_level BETWEEN {int:child_level} AND {int:max_child_level} |
||
130 | ORDER BY ' . (!empty($board_index_options['include_categories']) ? 'c.cat_order, ' : '') . 'b.child_level DESC, b.board_order DESC', |
||
131 | $board_index_parameters |
||
132 | ); |
||
133 | |||
134 | // Start with an empty array. |
||
135 | $categories = array(); |
||
136 | $this_category = array(); |
||
137 | $parsed_categories_description = array(); |
||
138 | $to_parse_categories_description = array(); |
||
139 | |||
140 | if ($board_index_options['include_categories']) |
||
141 | { |
||
142 | require_once $sourcedir . '/Subs-Categories.php'; |
||
143 | |||
144 | $parsed_categories_description = getCategoriesParsedDescription(); |
||
145 | } |
||
146 | |||
147 | $boards = array(); |
||
148 | |||
149 | // Children can affect parents, so we need to gather all the boards first and then process them after. |
||
150 | $row_boards = array(); |
||
151 | |||
152 | foreach ($smcFunc['db_fetch_all']($result_boards) as $row) |
||
153 | $row_boards[$row['id_board']] = $row; |
||
154 | |||
155 | $smcFunc['db_free_result']($result_boards); |
||
156 | |||
157 | // Run through the categories and boards (or only boards).... |
||
158 | // Done like this so the modified values can be used. |
||
159 | for (reset($row_boards); key($row_boards) !== null; next($row_boards)) |
||
160 | { |
||
161 | $row_board = current($row_boards); |
||
162 | |||
163 | // Perhaps we are ignoring this board? |
||
164 | $ignoreThisBoard = in_array($row_board['id_board'], $user_info['ignoreboards']); |
||
165 | $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; |
||
166 | |||
167 | // Add parent boards to the $boards list later used to fetch moderators |
||
168 | if ($row_board['id_parent'] == $board_index_options['parent_id']) |
||
169 | $boards[] = $row_board['id_board']; |
||
170 | |||
171 | if ($board_index_options['include_categories']) |
||
172 | { |
||
173 | // Haven't set this category yet. |
||
174 | if (empty($categories[$row_board['id_cat']])) |
||
175 | { |
||
176 | $category_description = $row_board['cat_desc']; |
||
177 | |||
178 | if (isset($parsed_categories_description[$row_board['id_cat']])) |
||
179 | $category_description = $parsed_categories_description[$row_board['id_cat']]; |
||
180 | |||
181 | else |
||
182 | $to_parse_categories_description[$row_board['id_cat']] = $row_board['cat_desc']; |
||
183 | |||
184 | $categories[$row_board['id_cat']] = array( |
||
185 | 'id' => $row_board['id_cat'], |
||
186 | 'name' => $row_board['cat_name'], |
||
187 | 'description' => $category_description, |
||
188 | 'is_collapsed' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1 && |
||
189 | !empty($options['collapse_category_' . $row_board['id_cat']]), |
||
190 | 'can_collapse' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1, |
||
191 | 'href' => $scripturl . '#c' . $row_board['id_cat'], |
||
192 | 'boards' => array(), |
||
193 | 'new' => false, |
||
194 | 'css_class' => '' |
||
195 | ); |
||
196 | |||
197 | $categories[$row_board['id_cat']]['link'] = '<a id="c' . $row_board['id_cat'] . '"></a>' . (!$context['user']['is_guest'] ? |
||
198 | '<a href="' . $scripturl . '?action=unread;c=' . $row_board['id_cat'] . '" title="' . sprintf($txt['new_posts_in_category'], $row_board['cat_name']) . '">' . $row_board['cat_name'] . '</a>' : |
||
199 | $row_board['cat_name']); |
||
200 | |||
201 | } |
||
202 | |||
203 | // If this board has new posts in it (and isn't the recycle bin!) then the category is new. |
||
204 | if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) |
||
205 | $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
||
206 | |||
207 | // Avoid showing category unread link where it only has redirection boards. |
||
208 | $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; |
||
209 | |||
210 | // Let's save some typing. Climbing the array might be slower, anyhow. |
||
211 | $this_category = &$categories[$row_board['id_cat']]['boards']; |
||
212 | } |
||
213 | |||
214 | if (empty($boards_parsed_data)) |
||
215 | $boards_parsed_data = getBoardsParsedDescription($row_board['id_cat']); |
||
216 | |||
217 | if (empty($to_parse_boards_info)) |
||
218 | $to_parse_boards_info = array(); |
||
219 | |||
220 | if (empty($to_parse_boards_info[$row_board['id_cat']])) |
||
221 | $to_parse_boards_info[$row_board['id_cat']] = array(); |
||
222 | |||
223 | // This is a parent board. |
||
224 | if ($row_board['id_parent'] == $board_index_options['parent_id']) |
||
225 | { |
||
226 | // Is this a new board, or just another moderator? |
||
227 | if (!isset($this_category[$row_board['id_board']]['type'])) |
||
228 | { |
||
229 | // Not a child. |
||
230 | $isChild = false; |
||
231 | |||
232 | // We might or might not have already added this board, so... |
||
233 | if (!isset($this_category[$row_board['id_board']])) |
||
234 | $this_category[$row_board['id_board']] = array(); |
||
235 | |||
236 | if (isset($boards_parsed_data[$row_board['id_board']])) |
||
237 | $row_board['description'] = $boards_parsed_data[$row_board['id_board']]; |
||
238 | |||
239 | else |
||
240 | $to_parse_boards_info[$row_board['id_cat']][$row_board['id_board']] = $row_board['description']; |
||
241 | |||
242 | $this_category[$row_board['id_board']] += array( |
||
243 | 'id_cat' => $row_board['id_cat'], |
||
244 | 'new' => empty($row_board['is_read']), |
||
245 | 'id' => $row_board['id_board'], |
||
246 | 'type' => $row_board['is_redirect'] ? 'redirect' : 'board', |
||
247 | 'name' => $row_board['board_name'], |
||
248 | 'description' => $row_board['description'], |
||
249 | 'moderators' => array(), |
||
250 | 'moderator_groups' => array(), |
||
251 | 'link_moderators' => array(), |
||
252 | 'link_moderator_groups' => array(), |
||
253 | 'children' => array(), |
||
254 | 'link_children' => array(), |
||
255 | 'children_new' => false, |
||
256 | 'topics' => $row_board['num_topics'], |
||
257 | 'posts' => $row_board['num_posts'], |
||
258 | 'is_redirect' => $row_board['is_redirect'], |
||
259 | 'unapproved_topics' => $row_board['unapproved_topics'], |
||
260 | 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], |
||
261 | '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'])), |
||
262 | 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0', |
||
263 | 'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>', |
||
264 | 'board_class' => 'off', |
||
265 | 'css_class' => '' |
||
266 | ); |
||
267 | |||
268 | call_integration_hook('integrate_boardindex_board', array(&$this_category, $row_board)); |
||
269 | |||
270 | // We can do some of the figuring-out-what-icon now. |
||
271 | // For certain types of thing we also set up what the tooltip is. |
||
272 | if ($this_category[$row_board['id_board']]['is_redirect']) |
||
273 | { |
||
274 | $this_category[$row_board['id_board']]['board_class'] = 'redirect'; |
||
275 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board']; |
||
276 | } |
||
277 | elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
||
278 | { |
||
279 | // If we're showing to guests, we want to give them the idea that something interesting is going on! |
||
280 | $this_category[$row_board['id_board']]['board_class'] = 'on'; |
||
281 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts']; |
||
282 | } |
||
283 | |||
284 | else |
||
285 | { |
||
286 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts']; |
||
287 | } |
||
288 | } |
||
289 | } |
||
290 | |||
291 | // This is a child board. |
||
292 | elseif (isset($row_boards[$row_board['id_parent']]['id_parent']) && $row_boards[$row_board['id_parent']]['id_parent'] == $board_index_options['parent_id']) |
||
293 | { |
||
294 | $isChild = true; |
||
295 | |||
296 | // Ensure the parent has at least the most important info defined |
||
297 | if (!isset($this_category[$row_board['id_parent']])) |
||
298 | $this_category[$row_board['id_parent']] = array( |
||
299 | 'children' => array(), |
||
300 | 'children_new' => false, |
||
301 | 'board_class' => 'off' |
||
302 | ); |
||
303 | |||
304 | if (isset($boards_parsed_data[$row_board['id_board']])) |
||
305 | $row_board['description'] = $boards_parsed_data[$row_board['id_board']]; |
||
306 | |||
307 | else |
||
308 | $to_parse_boards_info[$row_board['id_cat']][$row_board['id_board']] = $row_board['description']; |
||
309 | |||
310 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array( |
||
311 | 'id' => $row_board['id_board'], |
||
312 | 'id_cat' => $row_board['id_cat'], |
||
313 | 'name' => $row_board['board_name'], |
||
314 | 'description' => $row_board['description'], |
||
315 | 'short_description' => shorten_subject($row_board['description'], 128), |
||
316 | 'new' => empty($row_board['is_read']), |
||
317 | 'topics' => $row_board['num_topics'], |
||
318 | 'posts' => $row_board['num_posts'], |
||
319 | 'is_redirect' => $row_board['is_redirect'], |
||
320 | 'unapproved_topics' => $row_board['unapproved_topics'], |
||
321 | 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], |
||
322 | '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'])), |
||
323 | 'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0', |
||
324 | 'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>' |
||
325 | ); |
||
326 | |||
327 | // Counting child board posts in the parent's totals? |
||
328 | if (!empty($board_index_options['countChildPosts']) && !$row_board['is_redirect']) |
||
329 | { |
||
330 | $row_boards[$row_board['id_parent']]['num_posts'] += $row_board['num_posts']; |
||
331 | $row_boards[$row_board['id_parent']]['num_topics'] += $row_board['num_topics']; |
||
332 | } |
||
333 | |||
334 | // Does this board contain new boards? |
||
335 | $this_category[$row_board['id_parent']]['children_new'] |= empty($row_board['is_read']); |
||
336 | |||
337 | // Update the icon if appropriate |
||
338 | if ($this_category[$row_board['id_parent']]['children_new'] && $this_category[$row_board['id_parent']]['board_class'] == 'off') |
||
339 | { |
||
340 | $this_category[$row_board['id_parent']]['board_class'] = 'on2'; |
||
341 | $this_category[$row_board['id_parent']]['board_tooltip'] = $txt['new_posts']; |
||
342 | } |
||
343 | |||
344 | // This is easier to use in many cases for the theme.... |
||
345 | $this_category[$row_board['id_parent']]['link_children'][] = &$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['link']; |
||
346 | } |
||
347 | |||
348 | // A further descendent (grandchild, great-grandchild, etc.) |
||
349 | else |
||
350 | { |
||
351 | // Propagate some values to the parent board |
||
352 | if (isset($row_boards[$row_board['id_parent']])) |
||
353 | { |
||
354 | if (empty($row_board['is_read'])) |
||
355 | $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
||
356 | |||
357 | if (!empty($board_index_options['countChildPosts']) && !$row_board['is_redirect']) |
||
358 | { |
||
359 | $row_boards[$row_board['id_parent']]['num_posts'] += $row_board['num_posts']; |
||
360 | $row_boards[$row_board['id_parent']]['num_topics'] += $row_board['num_topics']; |
||
361 | } |
||
362 | |||
363 | if ($row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) |
||
364 | { |
||
365 | $row_boards[$row_board['id_parent']]['id_msg'] = $row_board['id_msg']; |
||
366 | $row_boards[$row_board['id_parent']]['subject'] = $row_board['subject']; |
||
367 | $row_boards[$row_board['id_parent']]['poster_time'] = $row_board['poster_time']; |
||
368 | $row_boards[$row_board['id_parent']]['short_subject'] = (!empty($row_board['short_subject']) ? $row_board['short_subject'] : ''); |
||
369 | $row_boards[$row_board['id_parent']]['poster_name'] = $row_board['poster_name']; |
||
370 | $row_boards[$row_board['id_parent']]['real_name'] = $row_board['real_name']; |
||
371 | $row_boards[$row_board['id_parent']]['id_member'] = $row_board['id_member']; |
||
372 | $row_boards[$row_board['id_parent']]['id_topic'] = $row_board['id_topic']; |
||
373 | $row_boards[$row_board['id_parent']]['new_from'] = $row_board['new_from']; |
||
374 | |||
375 | if (!empty($settings['avatars_on_boardIndex'])) |
||
376 | { |
||
377 | $row_boards[$row_board['id_parent']]['avatar'] = $row_board['avatar']; |
||
378 | $row_boards[$row_board['id_parent']]['email_address'] = $row_board['email_address']; |
||
379 | $row_boards[$row_board['id_parent']]['member_filename'] = !empty($row_board['member_filename']) ? $row_board['member_filename'] : ''; |
||
380 | } |
||
381 | } |
||
382 | } |
||
383 | |||
384 | continue; |
||
385 | } |
||
386 | |||
387 | // Prepare the subject, and make sure it's not too long. |
||
388 | censorText($row_board['subject']); |
||
389 | $row_board['short_subject'] = shorten_subject($row_board['subject'], 24); |
||
390 | $this_last_post = array( |
||
391 | 'id' => $row_board['id_msg'], |
||
392 | 'time' => $row_board['poster_time'], |
||
393 | 'timestamp' => $row_board['poster_time'], |
||
394 | 'subject' => $row_board['short_subject'], |
||
395 | 'member' => array( |
||
396 | 'id' => $row_board['id_member'], |
||
397 | 'username' => $row_board['poster_name'] != '' ? $row_board['poster_name'] : $txt['not_applicable'], |
||
398 | 'name' => $row_board['real_name'], |
||
399 | 'href' => $row_board['poster_name'] != '' && !empty($row_board['id_member']) ? $scripturl . '?action=profile;u=' . $row_board['id_member'] : '', |
||
400 | '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'], |
||
401 | ), |
||
402 | 'start' => 'msg' . $row_board['new_from'], |
||
403 | 'topic' => $row_board['id_topic'] |
||
404 | ); |
||
405 | |||
406 | if (!empty($settings['avatars_on_boardIndex'])) |
||
407 | $this_last_post['member']['avatar'] = set_avatar_data(array( |
||
408 | 'avatar' => $row_board['avatar'], |
||
409 | 'email' => $row_board['email_address'], |
||
410 | 'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '' |
||
411 | )); |
||
412 | |||
413 | // Provide the href and link. |
||
414 | if ($row_board['subject'] != '') |
||
415 | { |
||
416 | $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'; |
||
417 | $this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>'; |
||
418 | } |
||
419 | |||
420 | else |
||
421 | { |
||
422 | $this_last_post['href'] = ''; |
||
423 | $this_last_post['link'] = $txt['not_applicable']; |
||
424 | $this_last_post['last_post_message'] = ''; |
||
425 | } |
||
426 | |||
427 | // Set the last post in the parent board. |
||
428 | if ($isChild && !empty($row_board['poster_time']) |
||
|
|||
429 | && $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time'] |
||
430 | && (empty($this_category[$row_board['id_parent']]['last_post']) |
||
431 | || $this_category[$row_board['id_parent']]['last_post']['timestamp'] < $this_last_post['timestamp'])) |
||
432 | $this_category[$row_board['id_parent']]['last_post'] = $this_last_post; |
||
433 | |||
434 | // Set the last post in the root board |
||
435 | if (!$isChild && !empty($row_board['poster_time']) |
||
436 | && (empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
||
437 | || $this_category[$row_board['id_board']]['last_post']['timestamp'] < $row_board['poster_time'] |
||
438 | ) |
||
439 | ) |
||
440 | $this_category[$row_board['id_board']]['last_post'] = $this_last_post; |
||
441 | |||
442 | // Just in the child...? |
||
443 | if ($isChild) |
||
444 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
||
445 | |||
446 | // Determine a global most recent topic. |
||
447 | if (!empty($board_index_options['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
||
448 | $latest_post = array( |
||
449 | 'timestamp' => $row_board['poster_time'], |
||
450 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] |
||
451 | ); |
||
452 | } |
||
453 | |||
454 | // There are some categories still unparsed. |
||
455 | $to_parse_categories_description = array_filter($to_parse_categories_description); |
||
456 | |||
457 | if (!empty($to_parse_categories_description)) |
||
458 | { |
||
459 | $already_parsed_categories = setCategoryParsedDescription($to_parse_categories_description); |
||
460 | |||
461 | foreach ($to_parse_categories_description as $category_id => $category_description) |
||
462 | $categories[$category_id]['description'] = $already_parsed_categories[$category_id]; |
||
463 | } |
||
464 | |||
465 | // Some boards didn't get their info cached, it is done on a per category basis. |
||
466 | $boards_parsed_data_by_cat_id = array(); |
||
467 | |||
468 | if (!empty($to_parse_boards_info)) |
||
469 | foreach ($to_parse_boards_info as $unparsed_category_id => $board_unparsed_description) |
||
470 | { |
||
471 | if (empty($board_unparsed_description)) |
||
472 | continue; |
||
473 | |||
474 | $boards_parsed_data_by_cat_id[$unparsed_category_id] = setBoardParsedDescription( |
||
475 | $unparsed_category_id, |
||
476 | $board_unparsed_description |
||
477 | ); |
||
478 | } |
||
479 | |||
480 | /* The board's and children's 'last_post's have: |
||
481 | time, timestamp (a number that represents the time.), id (of the post), topic (topic id.), |
||
482 | link, href, subject, start (where they should go for the first unread post.), |
||
483 | and member. (which has id, name, link, href, username in it.) |
||
484 | timeformat is a pricy call do it only for thos how get shown */ |
||
485 | // Fetch the board's moderators and moderator groups |
||
486 | $boards = array_unique($boards); |
||
487 | $moderators = getBoardModerators($boards); |
||
488 | $groups = getBoardModeratorGroups($boards); |
||
489 | if ($board_index_options['include_categories']) |
||
490 | foreach ($categories as &$category) |
||
491 | { |
||
492 | foreach ($category['boards'] as &$board) |
||
493 | { |
||
494 | if (isset($boards_parsed_data_by_cat_id[$category['id']][$board['id']])) |
||
495 | $board['description'] = $boards_parsed_data_by_cat_id[$category['id']][$board['id']]; |
||
496 | |||
497 | if (!empty($moderators[$board['id']])) |
||
498 | { |
||
499 | $board['moderators'] = $moderators[$board['id']]; |
||
500 | foreach ($moderators[$board['id']] as $moderator) |
||
501 | $board['link_moderators'][] = $moderator['link']; |
||
502 | } |
||
503 | if (!empty($groups[$board['id']])) |
||
504 | { |
||
505 | $board['moderator_groups'] = $groups[$board['id']]; |
||
506 | foreach ($groups[$board['id']] as $group) |
||
507 | { |
||
508 | $board['link_moderators'][] = $group['link']; |
||
509 | $board['link_moderator_groups'][] = $group['link']; |
||
510 | } |
||
511 | } |
||
512 | if (!empty($board['last_post'])) |
||
513 | $board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']); |
||
514 | } |
||
515 | } |
||
516 | |||
517 | else |
||
518 | foreach ($this_category as &$board) |
||
519 | { |
||
520 | if (isset($boards_parsed_data_by_cat_id[$board['id_cat']][$board['id']])) |
||
521 | { |
||
522 | $board['description'] = $boards_parsed_data_by_cat_id[$board['id_cat']][$board['id']]; |
||
523 | |||
524 | if (isset($board['children'])) |
||
525 | foreach ($board['children'] as &$child_board) |
||
526 | $child_board['description'] = $boards_parsed_data_by_cat_id[$child_board['id_cat']][$child_board['id']]; |
||
527 | } |
||
528 | |||
529 | if (!empty($moderators[$board['id']])) |
||
530 | { |
||
531 | $board['moderators'] = $moderators[$board['id']]; |
||
532 | foreach ($moderators[$board['id']] as $moderator) |
||
533 | $board['link_moderators'][] = $moderator['link']; |
||
534 | } |
||
535 | if (!empty($groups[$board['id']])) |
||
536 | { |
||
537 | $board['moderator_groups'] = $groups[$board['id']]; |
||
538 | foreach ($groups[$board['id']] as $group) |
||
539 | { |
||
540 | $board['link_moderators'][] = $group['link']; |
||
541 | $board['link_moderator_groups'][] = $group['link']; |
||
542 | } |
||
543 | } |
||
544 | if (!empty($board['last_post'])) |
||
545 | $board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']); |
||
546 | } |
||
547 | |||
548 | unset($category, $board); |
||
549 | |||
550 | if ($board_index_options['include_categories']) |
||
551 | sortCategories($categories); |
||
552 | |||
553 | else |
||
554 | sortBoards($this_category); |
||
555 | |||
556 | // By now we should know the most recent post...if we wanna know it that is. |
||
557 | if (!empty($board_index_options['set_latest_post']) && !empty($latest_post['ref'])) |
||
558 | { |
||
559 | $latest_post['ref']['time'] = timeformat($latest_post['ref']['time']); |
||
560 | $context['latest_post'] = $latest_post['ref']; |
||
561 | } |
||
562 | |||
563 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
||
564 | if ($board_index_options['include_categories']) |
||
565 | call_integration_hook('integrate_getboardtree', array($board_index_options, &$categories)); |
||
566 | |||
567 | else |
||
568 | call_integration_hook('integrate_getboardtree', array($board_index_options, &$this_category)); |
||
569 | |||
570 | return $board_index_options['include_categories'] ? $categories : $this_category; |
||
571 | } |
||
573 | ?> |