@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Get the latest post made on the system |
@@ -44,8 +45,9 @@ discard block |
||
44 | 45 | 'is_approved' => 1, |
45 | 46 | ) |
46 | 47 | ); |
47 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
48 | - return array(); |
|
48 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
49 | + return array(); |
|
50 | + } |
|
49 | 51 | $row = $smcFunc['db_fetch_assoc']($request); |
50 | 52 | $smcFunc['db_free_result']($request); |
51 | 53 | |
@@ -54,8 +56,9 @@ discard block |
||
54 | 56 | censorText($row['body']); |
55 | 57 | |
56 | 58 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br>' => ' '))); |
57 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
58 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
59 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
60 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
61 | + } |
|
59 | 62 | |
60 | 63 | // Send the data. |
61 | 64 | return array( |
@@ -83,15 +86,17 @@ discard block |
||
83 | 86 | |
84 | 87 | $context['is_redirect'] = false; |
85 | 88 | |
86 | - if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) |
|
87 | - $_REQUEST['start'] = 95; |
|
89 | + if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) { |
|
90 | + $_REQUEST['start'] = 95; |
|
91 | + } |
|
88 | 92 | |
89 | 93 | $query_parameters = array(); |
90 | 94 | if (!empty($_REQUEST['c']) && empty($board)) |
91 | 95 | { |
92 | 96 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
93 | - foreach ($_REQUEST['c'] as $i => $c) |
|
94 | - $_REQUEST['c'][$i] = (int) $c; |
|
97 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
98 | + $_REQUEST['c'][$i] = (int) $c; |
|
99 | + } |
|
95 | 100 | |
96 | 101 | if (count($_REQUEST['c']) == 1) |
97 | 102 | { |
@@ -107,8 +112,9 @@ discard block |
||
107 | 112 | list ($name) = $smcFunc['db_fetch_row']($request); |
108 | 113 | $smcFunc['db_free_result']($request); |
109 | 114 | |
110 | - if (empty($name)) |
|
111 | - fatal_lang_error('no_access', false); |
|
115 | + if (empty($name)) { |
|
116 | + fatal_lang_error('no_access', false); |
|
117 | + } |
|
112 | 118 | |
113 | 119 | $context['linktree'][] = array( |
114 | 120 | 'url' => $scripturl . '#c' . (int) $_REQUEST['c'], |
@@ -140,8 +146,9 @@ discard block |
||
140 | 146 | } |
141 | 147 | $smcFunc['db_free_result']($request); |
142 | 148 | |
143 | - if (empty($boards)) |
|
144 | - fatal_lang_error('error_no_boards_selected'); |
|
149 | + if (empty($boards)) { |
|
150 | + fatal_lang_error('error_no_boards_selected'); |
|
151 | + } |
|
145 | 152 | |
146 | 153 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
147 | 154 | $query_parameters['boards'] = $boards; |
@@ -155,12 +162,12 @@ discard block |
||
155 | 162 | } |
156 | 163 | |
157 | 164 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false); |
158 | - } |
|
159 | - elseif (!empty($_REQUEST['boards'])) |
|
165 | + } elseif (!empty($_REQUEST['boards'])) |
|
160 | 166 | { |
161 | 167 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
162 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
163 | - $_REQUEST['boards'][$i] = (int) $b; |
|
168 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
169 | + $_REQUEST['boards'][$i] = (int) $b; |
|
170 | + } |
|
164 | 171 | |
165 | 172 | $request = $smcFunc['db_query']('', ' |
166 | 173 | SELECT b.id_board, b.num_posts |
@@ -184,8 +191,9 @@ discard block |
||
184 | 191 | } |
185 | 192 | $smcFunc['db_free_result']($request); |
186 | 193 | |
187 | - if (empty($boards)) |
|
188 | - fatal_lang_error('error_no_boards_selected'); |
|
194 | + if (empty($boards)) { |
|
195 | + fatal_lang_error('error_no_boards_selected'); |
|
196 | + } |
|
189 | 197 | |
190 | 198 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
191 | 199 | $query_parameters['boards'] = $boards; |
@@ -199,8 +207,7 @@ discard block |
||
199 | 207 | } |
200 | 208 | |
201 | 209 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false); |
202 | - } |
|
203 | - elseif (!empty($board)) |
|
210 | + } elseif (!empty($board)) |
|
204 | 211 | { |
205 | 212 | $request = $smcFunc['db_query']('', ' |
206 | 213 | SELECT num_posts, redirect |
@@ -233,8 +240,7 @@ discard block |
||
233 | 240 | } |
234 | 241 | |
235 | 242 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true); |
236 | - } |
|
237 | - else |
|
243 | + } else |
|
238 | 244 | { |
239 | 245 | $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
240 | 246 | AND b.id_board != {int:recycle_board}' : ''). ' |
@@ -269,8 +275,9 @@ discard block |
||
269 | 275 | ); |
270 | 276 | |
271 | 277 | // If you selected a redirection board, don't try getting posts for it... |
272 | - if ($context['is_redirect']) |
|
273 | - $messages = 0; |
|
278 | + if ($context['is_redirect']) { |
|
279 | + $messages = 0; |
|
280 | + } |
|
274 | 281 | |
275 | 282 | $key = 'recent-' . $user_info['id'] . '-' . md5($smcFunc['json_encode'](array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start']; |
276 | 283 | if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null)) |
@@ -301,16 +308,18 @@ discard block |
||
301 | 308 | $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board); |
302 | 309 | $cache_results = true; |
303 | 310 | unset($query_parameters['max_id_msg']); |
311 | + } else { |
|
312 | + $done = true; |
|
304 | 313 | } |
305 | - else |
|
306 | - $done = true; |
|
307 | 314 | } |
308 | 315 | $messages = array(); |
309 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
310 | - $messages[] = $row['id_msg']; |
|
316 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
317 | + $messages[] = $row['id_msg']; |
|
318 | + } |
|
311 | 319 | $smcFunc['db_free_result']($request); |
312 | - if (!empty($cache_results)) |
|
313 | - cache_put_data($key, $messages, 120); |
|
320 | + if (!empty($cache_results)) { |
|
321 | + cache_put_data($key, $messages, 120); |
|
322 | + } |
|
314 | 323 | } |
315 | 324 | |
316 | 325 | // Nothing here... Or at least, nothing you can see... |
@@ -397,8 +406,9 @@ discard block |
||
397 | 406 | 'css_class' => 'windowbg', |
398 | 407 | ); |
399 | 408 | |
400 | - if ($user_info['id'] == $row['id_first_member']) |
|
401 | - $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
409 | + if ($user_info['id'] == $row['id_first_member']) { |
|
410 | + $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
411 | + } |
|
402 | 412 | $board_ids['any'][$row['id_board']][] = $row['id_msg']; |
403 | 413 | } |
404 | 414 | $smcFunc['db_free_result']($request); |
@@ -424,20 +434,23 @@ discard block |
||
424 | 434 | $boards = boardsAllowedTo($permission); |
425 | 435 | |
426 | 436 | // If 0 is the only thing in the array, they can do it everywhere! |
427 | - if (!empty($boards) && $boards[0] == 0) |
|
428 | - $boards = array_keys($board_ids[$type]); |
|
437 | + if (!empty($boards) && $boards[0] == 0) { |
|
438 | + $boards = array_keys($board_ids[$type]); |
|
439 | + } |
|
429 | 440 | |
430 | 441 | // Go through the boards, and look for posts they can do this on. |
431 | 442 | foreach ($boards as $board_id) |
432 | 443 | { |
433 | 444 | // Hmm, they have permission, but there are no topics from that board on this page. |
434 | - if (!isset($board_ids[$type][$board_id])) |
|
435 | - continue; |
|
445 | + if (!isset($board_ids[$type][$board_id])) { |
|
446 | + continue; |
|
447 | + } |
|
436 | 448 | |
437 | 449 | // Okay, looks like they can do it for these posts. |
438 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
439 | - if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
450 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
451 | + if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
440 | 452 | $context['posts'][$counter][$allowed] = true; |
453 | + } |
|
441 | 454 | } |
442 | 455 | } |
443 | 456 | } |
@@ -480,17 +493,19 @@ discard block |
||
480 | 493 | $context['showing_all_topics'] = isset($_GET['all']); |
481 | 494 | $context['start'] = (int) $_REQUEST['start']; |
482 | 495 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
483 | - if ($_REQUEST['action'] == 'unread') |
|
484 | - $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
485 | - else |
|
486 | - $context['page_title'] = $txt['unread_replies']; |
|
496 | + if ($_REQUEST['action'] == 'unread') { |
|
497 | + $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
498 | + } else { |
|
499 | + $context['page_title'] = $txt['unread_replies']; |
|
500 | + } |
|
487 | 501 | |
488 | - if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) |
|
489 | - fatal_lang_error('loadavg_allunread_disabled', false); |
|
490 | - elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) |
|
491 | - fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
492 | - elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) |
|
493 | - fatal_lang_error('loadavg_unread_disabled', false); |
|
502 | + if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) { |
|
503 | + fatal_lang_error('loadavg_allunread_disabled', false); |
|
504 | + } elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) { |
|
505 | + fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
506 | + } elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) { |
|
507 | + fatal_lang_error('loadavg_unread_disabled', false); |
|
508 | + } |
|
494 | 509 | |
495 | 510 | // Parameters for the main query. |
496 | 511 | $query_parameters = array(); |
@@ -503,12 +518,14 @@ discard block |
||
503 | 518 | if (!empty($_REQUEST['boards'])) |
504 | 519 | { |
505 | 520 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
506 | - foreach ($_REQUEST['boards'] as $b) |
|
507 | - $boards[] = (int) $b; |
|
521 | + foreach ($_REQUEST['boards'] as $b) { |
|
522 | + $boards[] = (int) $b; |
|
523 | + } |
|
508 | 524 | } |
509 | 525 | |
510 | - if (!empty($board)) |
|
511 | - $boards[] = (int) $board; |
|
526 | + if (!empty($board)) { |
|
527 | + $boards[] = (int) $board; |
|
528 | + } |
|
512 | 529 | |
513 | 530 | // The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them |
514 | 531 | $request = $smcFunc['db_query']('', ' |
@@ -525,30 +542,31 @@ discard block |
||
525 | 542 | ) |
526 | 543 | ); |
527 | 544 | |
528 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
529 | - if (in_array($row['id_parent'], $boards)) |
|
545 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
546 | + if (in_array($row['id_parent'], $boards)) |
|
530 | 547 | $boards[] = $row['id_board']; |
548 | + } |
|
531 | 549 | |
532 | 550 | $smcFunc['db_free_result']($request); |
533 | 551 | |
534 | - if (empty($boards)) |
|
535 | - fatal_lang_error('error_no_boards_selected'); |
|
552 | + if (empty($boards)) { |
|
553 | + fatal_lang_error('error_no_boards_selected'); |
|
554 | + } |
|
536 | 555 | |
537 | 556 | $query_this_board = 'id_board IN ({array_int:boards})'; |
538 | 557 | $query_parameters['boards'] = $boards; |
539 | 558 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d'; |
540 | - } |
|
541 | - elseif (!empty($board)) |
|
559 | + } elseif (!empty($board)) |
|
542 | 560 | { |
543 | 561 | $query_this_board = 'id_board = {int:board}'; |
544 | 562 | $query_parameters['board'] = $board; |
545 | 563 | $context['querystring_board_limits'] = ';board=' . $board . '.%1$d'; |
546 | - } |
|
547 | - elseif (!empty($_REQUEST['boards'])) |
|
564 | + } elseif (!empty($_REQUEST['boards'])) |
|
548 | 565 | { |
549 | 566 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
550 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
551 | - $_REQUEST['boards'][$i] = (int) $b; |
|
567 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
568 | + $_REQUEST['boards'][$i] = (int) $b; |
|
569 | + } |
|
552 | 570 | |
553 | 571 | $request = $smcFunc['db_query']('', ' |
554 | 572 | SELECT b.id_board |
@@ -560,22 +578,24 @@ discard block |
||
560 | 578 | ) |
561 | 579 | ); |
562 | 580 | $boards = array(); |
563 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
564 | - $boards[] = $row['id_board']; |
|
581 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
582 | + $boards[] = $row['id_board']; |
|
583 | + } |
|
565 | 584 | $smcFunc['db_free_result']($request); |
566 | 585 | |
567 | - if (empty($boards)) |
|
568 | - fatal_lang_error('error_no_boards_selected'); |
|
586 | + if (empty($boards)) { |
|
587 | + fatal_lang_error('error_no_boards_selected'); |
|
588 | + } |
|
569 | 589 | |
570 | 590 | $query_this_board = 'id_board IN ({array_int:boards})'; |
571 | 591 | $query_parameters['boards'] = $boards; |
572 | 592 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d'; |
573 | - } |
|
574 | - elseif (!empty($_REQUEST['c'])) |
|
593 | + } elseif (!empty($_REQUEST['c'])) |
|
575 | 594 | { |
576 | 595 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
577 | - foreach ($_REQUEST['c'] as $i => $c) |
|
578 | - $_REQUEST['c'][$i] = (int) $c; |
|
596 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
597 | + $_REQUEST['c'][$i] = (int) $c; |
|
598 | + } |
|
579 | 599 | |
580 | 600 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
581 | 601 | $request = $smcFunc['db_query']('', ' |
@@ -588,18 +608,19 @@ discard block |
||
588 | 608 | ) |
589 | 609 | ); |
590 | 610 | $boards = array(); |
591 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
592 | - $boards[] = $row['id_board']; |
|
611 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
612 | + $boards[] = $row['id_board']; |
|
613 | + } |
|
593 | 614 | $smcFunc['db_free_result']($request); |
594 | 615 | |
595 | - if (empty($boards)) |
|
596 | - fatal_lang_error('error_no_boards_selected'); |
|
616 | + if (empty($boards)) { |
|
617 | + fatal_lang_error('error_no_boards_selected'); |
|
618 | + } |
|
597 | 619 | |
598 | 620 | $query_this_board = 'id_board IN ({array_int:boards})'; |
599 | 621 | $query_parameters['boards'] = $boards; |
600 | 622 | $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d'; |
601 | - } |
|
602 | - else |
|
623 | + } else |
|
603 | 624 | { |
604 | 625 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
605 | 626 | // Don't bother to show deleted posts! |
@@ -613,12 +634,14 @@ discard block |
||
613 | 634 | ) |
614 | 635 | ); |
615 | 636 | $boards = array(); |
616 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
617 | - $boards[] = $row['id_board']; |
|
637 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
638 | + $boards[] = $row['id_board']; |
|
639 | + } |
|
618 | 640 | $smcFunc['db_free_result']($request); |
619 | 641 | |
620 | - if (empty($boards)) |
|
621 | - fatal_lang_error('error_no_boards_available', false); |
|
642 | + if (empty($boards)) { |
|
643 | + fatal_lang_error('error_no_boards_available', false); |
|
644 | + } |
|
622 | 645 | |
623 | 646 | $query_this_board = 'id_board IN ({array_int:boards})'; |
624 | 647 | $query_parameters['boards'] = $boards; |
@@ -680,13 +703,14 @@ discard block |
||
680 | 703 | 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies'] |
681 | 704 | ); |
682 | 705 | |
683 | - if ($context['showing_all_topics']) |
|
684 | - $context['linktree'][] = array( |
|
706 | + if ($context['showing_all_topics']) { |
|
707 | + $context['linktree'][] = array( |
|
685 | 708 | 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], |
686 | 709 | 'name' => $txt['unread_topics_all'] |
687 | 710 | ); |
688 | - else |
|
689 | - $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
711 | + } else { |
|
712 | + $txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
|
713 | + } |
|
690 | 714 | |
691 | 715 | loadTemplate('Recent'); |
692 | 716 | loadTemplate('MessageIndex'); |
@@ -694,8 +718,9 @@ discard block |
||
694 | 718 | |
695 | 719 | // Setup the default topic icons... for checking they exist and the like ;) |
696 | 720 | $context['icon_sources'] = array(); |
697 | - foreach ($context['stable_icons'] as $icon) |
|
698 | - $context['icon_sources'][$icon] = 'images_url'; |
|
721 | + foreach ($context['stable_icons'] as $icon) { |
|
722 | + $context['icon_sources'][$icon] = 'images_url'; |
|
723 | + } |
|
699 | 724 | |
700 | 725 | $is_topics = $_REQUEST['action'] == 'unread'; |
701 | 726 | |
@@ -725,8 +750,7 @@ discard block |
||
725 | 750 | ); |
726 | 751 | list ($earliest_msg) = $smcFunc['db_fetch_row']($request); |
727 | 752 | $smcFunc['db_free_result']($request); |
728 | - } |
|
729 | - else |
|
753 | + } else |
|
730 | 754 | { |
731 | 755 | $request = $smcFunc['db_query']('', ' |
732 | 756 | SELECT MIN(lmr.id_msg) |
@@ -742,14 +766,14 @@ discard block |
||
742 | 766 | } |
743 | 767 | |
744 | 768 | // This is needed in case of topics marked unread. |
745 | - if (empty($earliest_msg)) |
|
746 | - $earliest_msg = 0; |
|
747 | - else |
|
769 | + if (empty($earliest_msg)) { |
|
770 | + $earliest_msg = 0; |
|
771 | + } else |
|
748 | 772 | { |
749 | 773 | // Using caching, when possible, to ignore the below slow query. |
750 | - if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) |
|
751 | - $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
752 | - else |
|
774 | + if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) { |
|
775 | + $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
776 | + } else |
|
753 | 777 | { |
754 | 778 | // This query is pretty slow, but it's needed to ensure nothing crucial is ignored. |
755 | 779 | $request = $smcFunc['db_query']('', ' |
@@ -764,8 +788,9 @@ discard block |
||
764 | 788 | $smcFunc['db_free_result']($request); |
765 | 789 | |
766 | 790 | // In theory this could be zero, if the first ever post is unread, so fudge it ;) |
767 | - if ($earliest_msg2 == 0) |
|
768 | - $earliest_msg2 = -1; |
|
791 | + if ($earliest_msg2 == 0) { |
|
792 | + $earliest_msg2 = -1; |
|
793 | + } |
|
769 | 794 | |
770 | 795 | $_SESSION['cached_log_time'] = array(time(), $earliest_msg2); |
771 | 796 | } |
@@ -803,9 +828,9 @@ discard block |
||
803 | 828 | 'db_error_skip' => true, |
804 | 829 | )) |
805 | 830 | ) !== false; |
831 | + } else { |
|
832 | + $have_temp_table = false; |
|
806 | 833 | } |
807 | - else |
|
808 | - $have_temp_table = false; |
|
809 | 834 | |
810 | 835 | if ($context['showing_all_topics'] && $have_temp_table) |
811 | 836 | { |
@@ -851,14 +876,15 @@ discard block |
||
851 | 876 | |
852 | 877 | $context['topics'] = array(); |
853 | 878 | $context['no_topic_listing'] = true; |
854 | - if ($context['querystring_board_limits'] == ';start=%1$d') |
|
855 | - $context['querystring_board_limits'] = ''; |
|
856 | - else |
|
857 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
879 | + if ($context['querystring_board_limits'] == ';start=%1$d') { |
|
880 | + $context['querystring_board_limits'] = ''; |
|
881 | + } else { |
|
882 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
883 | + } |
|
858 | 884 | return; |
885 | + } else { |
|
886 | + $min_message = (int) $min_message; |
|
859 | 887 | } |
860 | - else |
|
861 | - $min_message = (int) $min_message; |
|
862 | 888 | |
863 | 889 | $request = $smcFunc['db_query']('substring', ' |
864 | 890 | SELECT ' . $select_clause . ' |
@@ -887,8 +913,7 @@ discard block |
||
887 | 913 | 'limit' => $context['topics_per_page'], |
888 | 914 | )) |
889 | 915 | ); |
890 | - } |
|
891 | - elseif ($is_topics) |
|
916 | + } elseif ($is_topics) |
|
892 | 917 | { |
893 | 918 | $request = $smcFunc['db_query']('', ' |
894 | 919 | SELECT COUNT(*), MIN(t.id_last_msg) |
@@ -939,14 +964,15 @@ discard block |
||
939 | 964 | |
940 | 965 | $context['topics'] = array(); |
941 | 966 | $context['no_topic_listing'] = true; |
942 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
943 | - $context['querystring_board_limits'] = ''; |
|
944 | - else |
|
945 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
967 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
968 | + $context['querystring_board_limits'] = ''; |
|
969 | + } else { |
|
970 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
971 | + } |
|
946 | 972 | return; |
973 | + } else { |
|
974 | + $min_message = (int) $min_message; |
|
947 | 975 | } |
948 | - else |
|
949 | - $min_message = (int) $min_message; |
|
950 | 976 | |
951 | 977 | $request = $smcFunc['db_query']('substring', ' |
952 | 978 | SELECT ' . $select_clause . ' |
@@ -976,8 +1002,7 @@ discard block |
||
976 | 1002 | 'limit' => $context['topics_per_page'], |
977 | 1003 | )) |
978 | 1004 | ); |
979 | - } |
|
980 | - else |
|
1005 | + } else |
|
981 | 1006 | { |
982 | 1007 | if ($modSettings['totalMessages'] > 100000) |
983 | 1008 | { |
@@ -1029,8 +1054,8 @@ discard block |
||
1029 | 1054 | ) !== false; |
1030 | 1055 | |
1031 | 1056 | // If that worked, create a sample of the log_topics table too. |
1032 | - if ($have_temp_table) |
|
1033 | - $have_temp_table = $smcFunc['db_query']('', ' |
|
1057 | + if ($have_temp_table) { |
|
1058 | + $have_temp_table = $smcFunc['db_query']('', ' |
|
1034 | 1059 | CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in ( |
1035 | 1060 | PRIMARY KEY (id_topic) |
1036 | 1061 | ) |
@@ -1043,6 +1068,7 @@ discard block |
||
1043 | 1068 | 'db_error_skip' => true, |
1044 | 1069 | ) |
1045 | 1070 | ) !== false; |
1071 | + } |
|
1046 | 1072 | } |
1047 | 1073 | |
1048 | 1074 | if (!empty($have_temp_table)) |
@@ -1058,8 +1084,7 @@ discard block |
||
1058 | 1084 | ); |
1059 | 1085 | list ($num_topics) = $smcFunc['db_fetch_row']($request); |
1060 | 1086 | $smcFunc['db_free_result']($request); |
1061 | - } |
|
1062 | - else |
|
1087 | + } else |
|
1063 | 1088 | { |
1064 | 1089 | $request = $smcFunc['db_query']('unread_fetch_topic_count', ' |
1065 | 1090 | SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg) |
@@ -1100,15 +1125,16 @@ discard block |
||
1100 | 1125 | { |
1101 | 1126 | $context['topics'] = array(); |
1102 | 1127 | $context['no_topic_listing'] = true; |
1103 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
1104 | - $context['querystring_board_limits'] = ''; |
|
1105 | - else |
|
1106 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1128 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
1129 | + $context['querystring_board_limits'] = ''; |
|
1130 | + } else { |
|
1131 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1132 | + } |
|
1107 | 1133 | return; |
1108 | 1134 | } |
1109 | 1135 | |
1110 | - if (!empty($have_temp_table)) |
|
1111 | - $request = $smcFunc['db_query']('', ' |
|
1136 | + if (!empty($have_temp_table)) { |
|
1137 | + $request = $smcFunc['db_query']('', ' |
|
1112 | 1138 | SELECT t.id_topic |
1113 | 1139 | FROM {db_prefix}topics_posted_in AS t |
1114 | 1140 | LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic) |
@@ -1122,8 +1148,8 @@ discard block |
||
1122 | 1148 | 'limit' => $context['topics_per_page'], |
1123 | 1149 | )) |
1124 | 1150 | ); |
1125 | - else |
|
1126 | - $request = $smcFunc['db_query']('', ' |
|
1151 | + } else { |
|
1152 | + $request = $smcFunc['db_query']('', ' |
|
1127 | 1153 | SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].' |
1128 | 1154 | FROM {db_prefix}topics AS t |
1129 | 1155 | INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : ' |
@@ -1147,10 +1173,12 @@ discard block |
||
1147 | 1173 | 'sort' => $_REQUEST['sort'], |
1148 | 1174 | )) |
1149 | 1175 | ); |
1176 | + } |
|
1150 | 1177 | |
1151 | 1178 | $topics = array(); |
1152 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1153 | - $topics[] = $row['id_topic']; |
|
1179 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1180 | + $topics[] = $row['id_topic']; |
|
1181 | + } |
|
1154 | 1182 | $smcFunc['db_free_result']($request); |
1155 | 1183 | |
1156 | 1184 | // Sanity... where have you gone? |
@@ -1158,10 +1186,11 @@ discard block |
||
1158 | 1186 | { |
1159 | 1187 | $context['topics'] = array(); |
1160 | 1188 | $context['no_topic_listing'] = true; |
1161 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
1162 | - $context['querystring_board_limits'] = ''; |
|
1163 | - else |
|
1164 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1189 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
1190 | + $context['querystring_board_limits'] = ''; |
|
1191 | + } else { |
|
1192 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1193 | + } |
|
1165 | 1194 | return; |
1166 | 1195 | } |
1167 | 1196 | |
@@ -1195,8 +1224,9 @@ discard block |
||
1195 | 1224 | |
1196 | 1225 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1197 | 1226 | { |
1198 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
1199 | - continue; |
|
1227 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
1228 | + continue; |
|
1229 | + } |
|
1200 | 1230 | |
1201 | 1231 | $topic_ids[] = $row['id_topic']; |
1202 | 1232 | |
@@ -1204,11 +1234,13 @@ discard block |
||
1204 | 1234 | { |
1205 | 1235 | // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. |
1206 | 1236 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
1207 | - if ($smcFunc['strlen']($row['first_body']) > 128) |
|
1208 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
1237 | + if ($smcFunc['strlen']($row['first_body']) > 128) { |
|
1238 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
1239 | + } |
|
1209 | 1240 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
1210 | - if ($smcFunc['strlen']($row['last_body']) > 128) |
|
1211 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
1241 | + if ($smcFunc['strlen']($row['last_body']) > 128) { |
|
1242 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
1243 | + } |
|
1212 | 1244 | |
1213 | 1245 | // Censor the subject and message preview. |
1214 | 1246 | censorText($row['first_subject']); |
@@ -1219,23 +1251,22 @@ discard block |
||
1219 | 1251 | { |
1220 | 1252 | $row['last_subject'] = $row['first_subject']; |
1221 | 1253 | $row['last_body'] = $row['first_body']; |
1222 | - } |
|
1223 | - else |
|
1254 | + } else |
|
1224 | 1255 | { |
1225 | 1256 | censorText($row['last_subject']); |
1226 | 1257 | censorText($row['last_body']); |
1227 | 1258 | } |
1228 | - } |
|
1229 | - else |
|
1259 | + } else |
|
1230 | 1260 | { |
1231 | 1261 | $row['first_body'] = ''; |
1232 | 1262 | $row['last_body'] = ''; |
1233 | 1263 | censorText($row['first_subject']); |
1234 | 1264 | |
1235 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
1236 | - $row['last_subject'] = $row['first_subject']; |
|
1237 | - else |
|
1238 | - censorText($row['last_subject']); |
|
1265 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
1266 | + $row['last_subject'] = $row['first_subject']; |
|
1267 | + } else { |
|
1268 | + censorText($row['last_subject']); |
|
1269 | + } |
|
1239 | 1270 | } |
1240 | 1271 | |
1241 | 1272 | // Decide how many pages the topic should have. |
@@ -1247,22 +1278,24 @@ discard block |
||
1247 | 1278 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false); |
1248 | 1279 | |
1249 | 1280 | // If we can use all, show all. |
1250 | - if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) |
|
1251 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
1281 | + if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) { |
|
1282 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
1283 | + } |
|
1284 | + } else { |
|
1285 | + $pages = ''; |
|
1252 | 1286 | } |
1253 | 1287 | |
1254 | - else |
|
1255 | - $pages = ''; |
|
1256 | - |
|
1257 | 1288 | // We need to check the topic icons exist... you can never be too sure! |
1258 | 1289 | if (!empty($modSettings['messageIconChecks_enable'])) |
1259 | 1290 | { |
1260 | 1291 | // First icon first... as you'd expect. |
1261 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
1262 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1292 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
1293 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1294 | + } |
|
1263 | 1295 | // Last icon... last... duh. |
1264 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
1265 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1296 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
1297 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1298 | + } |
|
1266 | 1299 | } |
1267 | 1300 | |
1268 | 1301 | // Force the recycling icon if appropriate |
@@ -1276,12 +1309,14 @@ discard block |
||
1276 | 1309 | $colorClass = 'windowbg'; |
1277 | 1310 | |
1278 | 1311 | // Sticky topics should get a different color, too. |
1279 | - if ($row['is_sticky']) |
|
1280 | - $colorClass .= ' sticky'; |
|
1312 | + if ($row['is_sticky']) { |
|
1313 | + $colorClass .= ' sticky'; |
|
1314 | + } |
|
1281 | 1315 | |
1282 | 1316 | // Locked topics get special treatment as well. |
1283 | - if ($row['locked']) |
|
1284 | - $colorClass .= ' locked'; |
|
1317 | + if ($row['locked']) { |
|
1318 | + $colorClass .= ' locked'; |
|
1319 | + } |
|
1285 | 1320 | |
1286 | 1321 | // And build the array. |
1287 | 1322 | $context['topics'][$row['id_topic']] = array( |
@@ -1378,8 +1413,9 @@ discard block |
||
1378 | 1413 | ); |
1379 | 1414 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1380 | 1415 | { |
1381 | - if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) |
|
1382 | - $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
1416 | + if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) { |
|
1417 | + $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
1418 | + } |
|
1383 | 1419 | } |
1384 | 1420 | $smcFunc['db_free_result']($result); |
1385 | 1421 | } |
@@ -1394,28 +1430,30 @@ discard block |
||
1394 | 1430 | 'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']), |
1395 | 1431 | ); |
1396 | 1432 | |
1397 | - if ($context['showCheckboxes']) |
|
1398 | - $context['recent_buttons']['markselectread'] = array( |
|
1433 | + if ($context['showCheckboxes']) { |
|
1434 | + $context['recent_buttons']['markselectread'] = array( |
|
1399 | 1435 | 'text' => 'quick_mod_markread', |
1400 | 1436 | 'image' => 'markselectedread.png', |
1401 | 1437 | 'url' => 'javascript:document.quickModForm.submit();', |
1402 | 1438 | ); |
1439 | + } |
|
1403 | 1440 | |
1404 | - if (!empty($context['topics']) && !$context['showing_all_topics']) |
|
1405 | - $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
1406 | - } |
|
1407 | - elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
1441 | + if (!empty($context['topics']) && !$context['showing_all_topics']) { |
|
1442 | + $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
1443 | + } |
|
1444 | + } elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
1408 | 1445 | { |
1409 | 1446 | $context['recent_buttons'] = array( |
1410 | 1447 | 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']), |
1411 | 1448 | ); |
1412 | 1449 | |
1413 | - if ($context['showCheckboxes']) |
|
1414 | - $context['recent_buttons']['markselectread'] = array( |
|
1450 | + if ($context['showCheckboxes']) { |
|
1451 | + $context['recent_buttons']['markselectread'] = array( |
|
1415 | 1452 | 'text' => 'quick_mod_markread', |
1416 | 1453 | 'image' => 'markselectedread.png', |
1417 | 1454 | 'url' => 'javascript:document.quickModForm.submit();', |
1418 | 1455 | ); |
1456 | + } |
|
1419 | 1457 | } |
1420 | 1458 | |
1421 | 1459 | // Allow mods to add additional buttons here |