@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | $smcFunc['db_free_result']($result_boards); |
| 136 | 136 | |
| 137 | 137 | // Run through the categories and boards (or only boards).... |
| 138 | - for (reset($row_boards); key($row_boards)!==null; next($row_boards)) |
|
| 138 | + for (reset($row_boards); key($row_boards) !== null; next($row_boards)) |
|
| 139 | 139 | { |
| 140 | 140 | $row_board = current($row_boards); |
| 141 | 141 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | $row_boards[$row_board['id_parent']]['id_msg'] = $row_board['id_msg']; |
| 304 | 304 | $row_boards[$row_board['id_parent']]['subject'] = $row_board['subject']; |
| 305 | 305 | $row_boards[$row_board['id_parent']]['poster_time'] = $row_board['poster_time']; |
| 306 | - $row_boards[$row_board['id_parent']]['short_subject'] = (!empty($row_board['short_subject']) ? $row_board['short_subject'] : '') ; |
|
| 306 | + $row_boards[$row_board['id_parent']]['short_subject'] = (!empty($row_board['short_subject']) ? $row_board['short_subject'] : ''); |
|
| 307 | 307 | $row_boards[$row_board['id_parent']]['poster_name'] = $row_board['poster_name']; |
| 308 | 308 | $row_boards[$row_board['id_parent']]['real_name'] = $row_board['real_name']; |
| 309 | 309 | $row_boards[$row_board['id_parent']]['id_member'] = $row_board['id_member']; |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | // Set the last post in the root board |
| 375 | 375 | if (!$isChild && !empty($row_board['poster_time']) |
| 376 | - && ( empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
|
| 376 | + && (empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
|
| 377 | 377 | || $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']) |
| 378 | 378 | ) |
| 379 | 379 | ) |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Fetches a list of boards and (optional) categories including |
@@ -37,19 +38,21 @@ discard block |
||
| 37 | 38 | require_once($sourcedir . '/Subs-Boards.php'); |
| 38 | 39 | |
| 39 | 40 | // For performance, track the latest post while going through the boards. |
| 40 | - if (!empty($boardIndexOptions['set_latest_post'])) |
|
| 41 | - $latest_post = array( |
|
| 41 | + if (!empty($boardIndexOptions['set_latest_post'])) { |
|
| 42 | + $latest_post = array( |
|
| 42 | 43 | 'timestamp' => 0, |
| 43 | 44 | 'ref' => 0, |
| 44 | 45 | ); |
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | // This setting is not allowed to be empty |
| 47 | - if (empty($modSettings['boardindex_max_depth'])) |
|
| 48 | - $modSettings['boardindex_max_depth'] = 1; |
|
| 49 | + if (empty($modSettings['boardindex_max_depth'])) { |
|
| 50 | + $modSettings['boardindex_max_depth'] = 1; |
|
| 51 | + } |
|
| 49 | 52 | |
| 50 | 53 | // 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. |
| 51 | - if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) |
|
| 52 | - $result_boards = $smcFunc['db_query']('', ' |
|
| 54 | + if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) { |
|
| 55 | + $result_boards = $smcFunc['db_query']('', ' |
|
| 53 | 56 | WITH RECURSIVE |
| 54 | 57 | 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) |
| 55 | 58 | as |
@@ -91,8 +94,8 @@ discard block |
||
| 91 | 94 | 'id_parent' => $boardIndexOptions['parent_id'], |
| 92 | 95 | ) |
| 93 | 96 | ); |
| 94 | - else |
|
| 95 | - $result_boards = $smcFunc['db_query']('', ' |
|
| 97 | + } else { |
|
| 98 | + $result_boards = $smcFunc['db_query']('', ' |
|
| 96 | 99 | SELECT' . ($boardIndexOptions['include_categories'] ? ' |
| 97 | 100 | c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . ' |
| 98 | 101 | b.id_board, b.name AS board_name, b.description, |
@@ -120,18 +123,21 @@ discard block |
||
| 120 | 123 | 'blank_string' => '', |
| 121 | 124 | ) |
| 122 | 125 | ); |
| 126 | + } |
|
| 123 | 127 | |
| 124 | 128 | // Start with an empty array. |
| 125 | - if ($boardIndexOptions['include_categories']) |
|
| 126 | - $categories = array(); |
|
| 127 | - else |
|
| 128 | - $this_category = array(); |
|
| 129 | + if ($boardIndexOptions['include_categories']) { |
|
| 130 | + $categories = array(); |
|
| 131 | + } else { |
|
| 132 | + $this_category = array(); |
|
| 133 | + } |
|
| 129 | 134 | $boards = array(); |
| 130 | 135 | |
| 131 | 136 | // Children can affect parents, so we need to gather all the boards first and then process them after. |
| 132 | 137 | $row_boards = array(); |
| 133 | - while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) |
|
| 134 | - $row_boards[$row_board['id_board']] = $row_board; |
|
| 138 | + while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) { |
|
| 139 | + $row_boards[$row_board['id_board']] = $row_board; |
|
| 140 | + } |
|
| 135 | 141 | $smcFunc['db_free_result']($result_boards); |
| 136 | 142 | |
| 137 | 143 | // Run through the categories and boards (or only boards).... |
@@ -144,8 +150,9 @@ discard block |
||
| 144 | 150 | $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; |
| 145 | 151 | |
| 146 | 152 | // Add parent boards to the $boards list later used to fetch moderators |
| 147 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) |
|
| 148 | - $boards[] = $row_board['id_board']; |
|
| 153 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) { |
|
| 154 | + $boards[] = $row_board['id_board']; |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | 157 | if ($boardIndexOptions['include_categories']) |
| 151 | 158 | { |
@@ -167,8 +174,9 @@ discard block |
||
| 167 | 174 | } |
| 168 | 175 | |
| 169 | 176 | // If this board has new posts in it (and isn't the recycle bin!) then the category is new. |
| 170 | - if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) |
|
| 171 | - $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
| 177 | + if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) { |
|
| 178 | + $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
| 179 | + } |
|
| 172 | 180 | |
| 173 | 181 | // Avoid showing category unread link where it only has redirection boards. |
| 174 | 182 | $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; |
@@ -187,8 +195,9 @@ discard block |
||
| 187 | 195 | $isChild = false; |
| 188 | 196 | |
| 189 | 197 | // We might or might not have already added this board, so... |
| 190 | - if (!isset($this_category[$row_board['id_board']])) |
|
| 191 | - $this_category[$row_board['id_board']] = array(); |
|
| 198 | + if (!isset($this_category[$row_board['id_board']])) { |
|
| 199 | + $this_category[$row_board['id_board']] = array(); |
|
| 200 | + } |
|
| 192 | 201 | |
| 193 | 202 | $this_category[$row_board['id_board']] += array( |
| 194 | 203 | 'new' => empty($row_board['is_read']), |
@@ -221,14 +230,12 @@ discard block |
||
| 221 | 230 | { |
| 222 | 231 | $this_category[$row_board['id_board']]['board_class'] = 'redirect'; |
| 223 | 232 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board']; |
| 224 | - } |
|
| 225 | - elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
| 233 | + } elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
| 226 | 234 | { |
| 227 | 235 | // If we're showing to guests, we want to give them the idea that something interesting is going on! |
| 228 | 236 | $this_category[$row_board['id_board']]['board_class'] = 'on'; |
| 229 | 237 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts']; |
| 230 | - } |
|
| 231 | - else |
|
| 238 | + } else |
|
| 232 | 239 | { |
| 233 | 240 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts']; |
| 234 | 241 | } |
@@ -240,12 +247,13 @@ discard block |
||
| 240 | 247 | $isChild = true; |
| 241 | 248 | |
| 242 | 249 | // Ensure the parent has at least the most important info defined |
| 243 | - if (!isset($this_category[$row_board['id_parent']])) |
|
| 244 | - $this_category[$row_board['id_parent']] = array( |
|
| 250 | + if (!isset($this_category[$row_board['id_parent']])) { |
|
| 251 | + $this_category[$row_board['id_parent']] = array( |
|
| 245 | 252 | 'children' => array(), |
| 246 | 253 | 'children_new' => false, |
| 247 | 254 | 'board_class' => 'off', |
| 248 | 255 | ); |
| 256 | + } |
|
| 249 | 257 | |
| 250 | 258 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array( |
| 251 | 259 | 'id' => $row_board['id_board'], |
@@ -289,8 +297,9 @@ discard block |
||
| 289 | 297 | // Propagate some values to the parent board |
| 290 | 298 | if (isset($row_boards[$row_board['id_parent']])) |
| 291 | 299 | { |
| 292 | - if (empty($row_board['is_read'])) |
|
| 293 | - $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
| 300 | + if (empty($row_board['is_read'])) { |
|
| 301 | + $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
| 302 | + } |
|
| 294 | 303 | |
| 295 | 304 | if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect']) |
| 296 | 305 | { |
@@ -341,12 +350,13 @@ discard block |
||
| 341 | 350 | 'topic' => $row_board['id_topic'] |
| 342 | 351 | ); |
| 343 | 352 | |
| 344 | - if (!empty($settings['avatars_on_boardIndex'])) |
|
| 345 | - $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
| 353 | + if (!empty($settings['avatars_on_boardIndex'])) { |
|
| 354 | + $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
| 346 | 355 | 'avatar' => $row_board['avatar'], |
| 347 | 356 | 'email' => $row_board['email_address'], |
| 348 | 357 | 'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '', |
| 349 | 358 | )); |
| 359 | + } |
|
| 350 | 360 | |
| 351 | 361 | // Provide the href and link. |
| 352 | 362 | if ($row_board['subject'] != '') |
@@ -358,8 +368,7 @@ discard block |
||
| 358 | 368 | link, href, subject, start (where they should go for the first unread post.), |
| 359 | 369 | and member. (which has id, name, link, href, username in it.) */ |
| 360 | 370 | $this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']); |
| 361 | - } |
|
| 362 | - else |
|
| 371 | + } else |
|
| 363 | 372 | { |
| 364 | 373 | $this_last_post['href'] = ''; |
| 365 | 374 | $this_last_post['link'] = $txt['not_applicable']; |
@@ -368,27 +377,31 @@ discard block |
||
| 368 | 377 | |
| 369 | 378 | // Set the last post in the parent board. |
| 370 | 379 | if ($isChild && !empty($row_board['poster_time']) |
| 371 | - && $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) |
|
| 372 | - $this_category[$row_board['id_parent']]['last_post'] = $this_last_post; |
|
| 380 | + && $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) { |
|
| 381 | + $this_category[$row_board['id_parent']]['last_post'] = $this_last_post; |
|
| 382 | + } |
|
| 373 | 383 | |
| 374 | 384 | // Set the last post in the root board |
| 375 | 385 | if (!$isChild && !empty($row_board['poster_time']) |
| 376 | 386 | && ( empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
| 377 | 387 | || $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']) |
| 378 | 388 | ) |
| 379 | - ) |
|
| 380 | - $this_category[$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 389 | + ) { |
|
| 390 | + $this_category[$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 391 | + } |
|
| 381 | 392 | |
| 382 | 393 | // Just in the child...? |
| 383 | - if ($isChild) |
|
| 384 | - $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 394 | + if ($isChild) { |
|
| 395 | + $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 396 | + } |
|
| 385 | 397 | |
| 386 | 398 | // Determine a global most recent topic. |
| 387 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
|
| 388 | - $latest_post = array( |
|
| 399 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) { |
|
| 400 | + $latest_post = array( |
|
| 389 | 401 | 'timestamp' => $row_board['poster_time'], |
| 390 | 402 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], |
| 391 | 403 | ); |
| 404 | + } |
|
| 392 | 405 | } |
| 393 | 406 | |
| 394 | 407 | // Fetch the board's moderators and moderator groups |
@@ -404,8 +417,9 @@ discard block |
||
| 404 | 417 | if (!empty($moderators[$board['id']])) |
| 405 | 418 | { |
| 406 | 419 | $categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']]; |
| 407 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 408 | - $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
| 420 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 421 | + $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
| 422 | + } |
|
| 409 | 423 | } |
| 410 | 424 | if (!empty($groups[$board['id']])) |
| 411 | 425 | { |
@@ -418,16 +432,16 @@ discard block |
||
| 418 | 432 | } |
| 419 | 433 | } |
| 420 | 434 | } |
| 421 | - } |
|
| 422 | - else |
|
| 435 | + } else |
|
| 423 | 436 | { |
| 424 | 437 | foreach ($this_category as $k => $board) |
| 425 | 438 | { |
| 426 | 439 | if (!empty($moderators[$board['id']])) |
| 427 | 440 | { |
| 428 | 441 | $this_category[$k]['moderators'] = $moderators[$board['id']]; |
| 429 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 430 | - $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
| 442 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 443 | + $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
| 444 | + } |
|
| 431 | 445 | } |
| 432 | 446 | if (!empty($groups[$board['id']])) |
| 433 | 447 | { |
@@ -441,20 +455,23 @@ discard block |
||
| 441 | 455 | } |
| 442 | 456 | } |
| 443 | 457 | |
| 444 | - if ($boardIndexOptions['include_categories']) |
|
| 445 | - sortCategories($categories); |
|
| 446 | - else |
|
| 447 | - sortBoards($this_category); |
|
| 458 | + if ($boardIndexOptions['include_categories']) { |
|
| 459 | + sortCategories($categories); |
|
| 460 | + } else { |
|
| 461 | + sortBoards($this_category); |
|
| 462 | + } |
|
| 448 | 463 | |
| 449 | 464 | // By now we should know the most recent post...if we wanna know it that is. |
| 450 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) |
|
| 451 | - $context['latest_post'] = $latest_post['ref']; |
|
| 465 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) { |
|
| 466 | + $context['latest_post'] = $latest_post['ref']; |
|
| 467 | + } |
|
| 452 | 468 | |
| 453 | 469 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
| 454 | - if ($boardIndexOptions['include_categories']) |
|
| 455 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 456 | - else |
|
| 457 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 470 | + if ($boardIndexOptions['include_categories']) { |
|
| 471 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 472 | + } else { |
|
| 473 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 474 | + } |
|
| 458 | 475 | |
| 459 | 476 | return $boardIndexOptions['include_categories'] ? $categories : $this_category; |
| 460 | 477 | } |