@@ -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']; |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | // Set the last post in the root board |
| 370 | 370 | if (!$isChild && !empty($row_board['poster_time']) |
| 371 | - && ( empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
|
| 371 | + && (empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
|
| 372 | 372 | || $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']) |
| 373 | 373 | ) |
| 374 | 374 | ) |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | if ($boardIndexOptions['include_categories']) |
| 399 | 399 | foreach ($categories as &$category) |
| 400 | 400 | { |
| 401 | - foreach ($category['boards'] as &$board ) |
|
| 401 | + foreach ($category['boards'] as &$board) |
|
| 402 | 402 | { |
| 403 | 403 | if (!empty($moderators[$board['id']])) |
| 404 | 404 | { |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | else |
| 423 | - foreach ($this_category as &$board ) |
|
| 423 | + foreach ($this_category as &$board) |
|
| 424 | 424 | { |
| 425 | 425 | if (!empty($moderators[$board['id']])) |
| 426 | 426 | { |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | $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']); |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - unset($category,$board); |
|
| 444 | + unset($category, $board); |
|
| 445 | 445 | |
| 446 | 446 | if ($boardIndexOptions['include_categories']) |
| 447 | 447 | sortCategories($categories); |
@@ -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,20 +350,20 @@ 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'] != '') |
| 353 | 363 | { |
| 354 | 364 | $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'; |
| 355 | 365 | $this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>'; |
| 356 | - } |
|
| 357 | - else |
|
| 366 | + } else |
|
| 358 | 367 | { |
| 359 | 368 | $this_last_post['href'] = ''; |
| 360 | 369 | $this_last_post['link'] = $txt['not_applicable']; |
@@ -363,27 +372,31 @@ discard block |
||
| 363 | 372 | |
| 364 | 373 | // Set the last post in the parent board. |
| 365 | 374 | if ($isChild && !empty($row_board['poster_time']) |
| 366 | - && $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) |
|
| 367 | - $this_category[$row_board['id_parent']]['last_post'] = $this_last_post; |
|
| 375 | + && $row_boards[$row_board['id_parent']]['poster_time'] < $row_board['poster_time']) { |
|
| 376 | + $this_category[$row_board['id_parent']]['last_post'] = $this_last_post; |
|
| 377 | + } |
|
| 368 | 378 | |
| 369 | 379 | // Set the last post in the root board |
| 370 | 380 | if (!$isChild && !empty($row_board['poster_time']) |
| 371 | 381 | && ( empty($this_category[$row_board['id_board']]['last_post']['timestamp']) |
| 372 | 382 | || $this_category[$row_board['id_board']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']) |
| 373 | 383 | ) |
| 374 | - ) |
|
| 375 | - $this_category[$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 384 | + ) { |
|
| 385 | + $this_category[$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 386 | + } |
|
| 376 | 387 | |
| 377 | 388 | // Just in the child...? |
| 378 | - if ($isChild) |
|
| 379 | - $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 389 | + if ($isChild) { |
|
| 390 | + $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
| 391 | + } |
|
| 380 | 392 | |
| 381 | 393 | // Determine a global most recent topic. |
| 382 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
|
| 383 | - $latest_post = array( |
|
| 394 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) { |
|
| 395 | + $latest_post = array( |
|
| 384 | 396 | 'timestamp' => $row_board['poster_time'], |
| 385 | 397 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], |
| 386 | 398 | ); |
| 399 | + } |
|
| 387 | 400 | } |
| 388 | 401 | |
| 389 | 402 | /* The board's and children's 'last_post's have: |
@@ -395,16 +408,18 @@ discard block |
||
| 395 | 408 | $boards = array_unique($boards); |
| 396 | 409 | $moderators = getBoardModerators($boards); |
| 397 | 410 | $groups = getBoardModeratorGroups($boards); |
| 398 | - if ($boardIndexOptions['include_categories']) |
|
| 399 | - foreach ($categories as &$category) |
|
| 411 | + if ($boardIndexOptions['include_categories']) { |
|
| 412 | + foreach ($categories as &$category) |
|
| 400 | 413 | { |
| 401 | 414 | foreach ($category['boards'] as &$board ) |
| 402 | 415 | { |
| 403 | 416 | if (!empty($moderators[$board['id']])) |
| 404 | 417 | { |
| 405 | 418 | $board['moderators'] = $moderators[$board['id']]; |
| 406 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 407 | - $board['link_moderators'][] = $moderator['link']; |
|
| 419 | + } |
|
| 420 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 421 | + $board['link_moderators'][] = $moderator['link']; |
|
| 422 | + } |
|
| 408 | 423 | } |
| 409 | 424 | if (!empty($groups[$board['id']])) |
| 410 | 425 | { |
@@ -415,18 +430,20 @@ discard block |
||
| 415 | 430 | $board['link_moderator_groups'][] = $group['link']; |
| 416 | 431 | } |
| 417 | 432 | } |
| 418 | - if (!empty($board['last_post'])) |
|
| 419 | - $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']); |
|
| 433 | + if (!empty($board['last_post'])) { |
|
| 434 | + $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']); |
|
| 435 | + } |
|
| 420 | 436 | } |
| 421 | - } |
|
| 422 | - else |
|
| 423 | - foreach ($this_category as &$board ) |
|
| 437 | + } else { |
|
| 438 | + foreach ($this_category as &$board ) |
|
| 424 | 439 | { |
| 425 | 440 | if (!empty($moderators[$board['id']])) |
| 426 | 441 | { |
| 427 | 442 | $board['moderators'] = $moderators[$board['id']]; |
| 428 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 429 | - $board['link_moderators'][] = $moderator['link']; |
|
| 443 | + } |
|
| 444 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 445 | + $board['link_moderators'][] = $moderator['link']; |
|
| 446 | + } |
|
| 430 | 447 | } |
| 431 | 448 | if (!empty($groups[$board['id']])) |
| 432 | 449 | { |
@@ -437,26 +454,30 @@ discard block |
||
| 437 | 454 | $board['link_moderator_groups'][] = $group['link']; |
| 438 | 455 | } |
| 439 | 456 | } |
| 440 | - if (!empty($board['last_post'])) |
|
| 441 | - $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']); |
|
| 457 | + if (!empty($board['last_post'])) { |
|
| 458 | + $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']); |
|
| 459 | + } |
|
| 442 | 460 | } |
| 443 | 461 | |
| 444 | 462 | unset($category,$board); |
| 445 | 463 | |
| 446 | - if ($boardIndexOptions['include_categories']) |
|
| 447 | - sortCategories($categories); |
|
| 448 | - else |
|
| 449 | - sortBoards($this_category); |
|
| 464 | + if ($boardIndexOptions['include_categories']) { |
|
| 465 | + sortCategories($categories); |
|
| 466 | + } else { |
|
| 467 | + sortBoards($this_category); |
|
| 468 | + } |
|
| 450 | 469 | |
| 451 | 470 | // By now we should know the most recent post...if we wanna know it that is. |
| 452 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) |
|
| 453 | - $context['latest_post'] = $latest_post['ref']; |
|
| 471 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) { |
|
| 472 | + $context['latest_post'] = $latest_post['ref']; |
|
| 473 | + } |
|
| 454 | 474 | |
| 455 | 475 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
| 456 | - if ($boardIndexOptions['include_categories']) |
|
| 457 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 458 | - else |
|
| 459 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 476 | + if ($boardIndexOptions['include_categories']) { |
|
| 477 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 478 | + } else { |
|
| 479 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 480 | + } |
|
| 460 | 481 | |
| 461 | 482 | return $boardIndexOptions['include_categories'] ? $categories : $this_category; |
| 462 | 483 | } |