@@ -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,8 +86,9 @@ 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 | $_REQUEST['start'] = (int) $_REQUEST['start']; |
90 | 94 | |
@@ -92,8 +96,9 @@ discard block |
||
92 | 96 | if (!empty($_REQUEST['c']) && empty($board)) |
93 | 97 | { |
94 | 98 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
95 | - foreach ($_REQUEST['c'] as $i => $c) |
|
96 | - $_REQUEST['c'][$i] = (int) $c; |
|
99 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
100 | + $_REQUEST['c'][$i] = (int) $c; |
|
101 | + } |
|
97 | 102 | |
98 | 103 | if (count($_REQUEST['c']) == 1) |
99 | 104 | { |
@@ -109,8 +114,9 @@ discard block |
||
109 | 114 | list ($name) = $smcFunc['db_fetch_row']($request); |
110 | 115 | $smcFunc['db_free_result']($request); |
111 | 116 | |
112 | - if (empty($name)) |
|
113 | - fatal_lang_error('no_access', false); |
|
117 | + if (empty($name)) { |
|
118 | + fatal_lang_error('no_access', false); |
|
119 | + } |
|
114 | 120 | |
115 | 121 | $context['linktree'][] = array( |
116 | 122 | 'url' => $scripturl . '#c' . (int) $_REQUEST['c'], |
@@ -142,8 +148,9 @@ discard block |
||
142 | 148 | } |
143 | 149 | $smcFunc['db_free_result']($request); |
144 | 150 | |
145 | - if (empty($boards)) |
|
146 | - fatal_lang_error('error_no_boards_selected'); |
|
151 | + if (empty($boards)) { |
|
152 | + fatal_lang_error('error_no_boards_selected'); |
|
153 | + } |
|
147 | 154 | |
148 | 155 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
149 | 156 | $query_parameters['boards'] = $boards; |
@@ -157,12 +164,12 @@ discard block |
||
157 | 164 | } |
158 | 165 | |
159 | 166 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false); |
160 | - } |
|
161 | - elseif (!empty($_REQUEST['boards'])) |
|
167 | + } elseif (!empty($_REQUEST['boards'])) |
|
162 | 168 | { |
163 | 169 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
164 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
165 | - $_REQUEST['boards'][$i] = (int) $b; |
|
170 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
171 | + $_REQUEST['boards'][$i] = (int) $b; |
|
172 | + } |
|
166 | 173 | |
167 | 174 | $request = $smcFunc['db_query']('', ' |
168 | 175 | SELECT b.id_board, b.num_posts |
@@ -186,8 +193,9 @@ discard block |
||
186 | 193 | } |
187 | 194 | $smcFunc['db_free_result']($request); |
188 | 195 | |
189 | - if (empty($boards)) |
|
190 | - fatal_lang_error('error_no_boards_selected'); |
|
196 | + if (empty($boards)) { |
|
197 | + fatal_lang_error('error_no_boards_selected'); |
|
198 | + } |
|
191 | 199 | |
192 | 200 | $query_this_board = 'b.id_board IN ({array_int:boards})'; |
193 | 201 | $query_parameters['boards'] = $boards; |
@@ -201,8 +209,7 @@ discard block |
||
201 | 209 | } |
202 | 210 | |
203 | 211 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false); |
204 | - } |
|
205 | - elseif (!empty($board)) |
|
212 | + } elseif (!empty($board)) |
|
206 | 213 | { |
207 | 214 | $request = $smcFunc['db_query']('', ' |
208 | 215 | SELECT num_posts, redirect |
@@ -235,8 +242,7 @@ discard block |
||
235 | 242 | } |
236 | 243 | |
237 | 244 | $context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true); |
238 | - } |
|
239 | - else |
|
245 | + } else |
|
240 | 246 | { |
241 | 247 | $query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
242 | 248 | AND b.id_board != {int:recycle_board}' : ''). ' |
@@ -271,8 +277,9 @@ discard block |
||
271 | 277 | ); |
272 | 278 | |
273 | 279 | // If you selected a redirection board, don't try getting posts for it... |
274 | - if ($context['is_redirect']) |
|
275 | - $messages = 0; |
|
280 | + if ($context['is_redirect']) { |
|
281 | + $messages = 0; |
|
282 | + } |
|
276 | 283 | |
277 | 284 | $key = 'recent-' . $user_info['id'] . '-' . md5($smcFunc['json_encode'](array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start']; |
278 | 285 | if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null)) |
@@ -303,16 +310,18 @@ discard block |
||
303 | 310 | $query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board); |
304 | 311 | $cache_results = true; |
305 | 312 | unset($query_parameters['max_id_msg']); |
313 | + } else { |
|
314 | + $done = true; |
|
306 | 315 | } |
307 | - else |
|
308 | - $done = true; |
|
309 | 316 | } |
310 | 317 | $messages = array(); |
311 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
312 | - $messages[] = $row['id_msg']; |
|
318 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
319 | + $messages[] = $row['id_msg']; |
|
320 | + } |
|
313 | 321 | $smcFunc['db_free_result']($request); |
314 | - if (!empty($cache_results)) |
|
315 | - cache_put_data($key, $messages, 120); |
|
322 | + if (!empty($cache_results)) { |
|
323 | + cache_put_data($key, $messages, 120); |
|
324 | + } |
|
316 | 325 | } |
317 | 326 | |
318 | 327 | // Nothing here... Or at least, nothing you can see... |
@@ -399,8 +408,9 @@ discard block |
||
399 | 408 | 'css_class' => 'windowbg', |
400 | 409 | ); |
401 | 410 | |
402 | - if ($user_info['id'] == $row['id_first_member']) |
|
403 | - $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
411 | + if ($user_info['id'] == $row['id_first_member']) { |
|
412 | + $board_ids['own'][$row['id_board']][] = $row['id_msg']; |
|
413 | + } |
|
404 | 414 | $board_ids['any'][$row['id_board']][] = $row['id_msg']; |
405 | 415 | } |
406 | 416 | $smcFunc['db_free_result']($request); |
@@ -426,20 +436,23 @@ discard block |
||
426 | 436 | $boards = boardsAllowedTo($permission); |
427 | 437 | |
428 | 438 | // If 0 is the only thing in the array, they can do it everywhere! |
429 | - if (!empty($boards) && $boards[0] == 0) |
|
430 | - $boards = array_keys($board_ids[$type]); |
|
439 | + if (!empty($boards) && $boards[0] == 0) { |
|
440 | + $boards = array_keys($board_ids[$type]); |
|
441 | + } |
|
431 | 442 | |
432 | 443 | // Go through the boards, and look for posts they can do this on. |
433 | 444 | foreach ($boards as $board_id) |
434 | 445 | { |
435 | 446 | // Hmm, they have permission, but there are no topics from that board on this page. |
436 | - if (!isset($board_ids[$type][$board_id])) |
|
437 | - continue; |
|
447 | + if (!isset($board_ids[$type][$board_id])) { |
|
448 | + continue; |
|
449 | + } |
|
438 | 450 | |
439 | 451 | // Okay, looks like they can do it for these posts. |
440 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
441 | - if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
452 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
453 | + if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id']) |
|
442 | 454 | $context['posts'][$counter][$allowed] = true; |
455 | + } |
|
443 | 456 | } |
444 | 457 | } |
445 | 458 | } |
@@ -482,17 +495,19 @@ discard block |
||
482 | 495 | $context['showing_all_topics'] = isset($_GET['all']); |
483 | 496 | $context['start'] = (int) $_REQUEST['start']; |
484 | 497 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
485 | - if ($_REQUEST['action'] == 'unread') |
|
486 | - $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
487 | - else |
|
488 | - $context['page_title'] = $txt['unread_replies']; |
|
498 | + if ($_REQUEST['action'] == 'unread') { |
|
499 | + $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
|
500 | + } else { |
|
501 | + $context['page_title'] = $txt['unread_replies']; |
|
502 | + } |
|
489 | 503 | |
490 | - if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) |
|
491 | - fatal_lang_error('loadavg_allunread_disabled', false); |
|
492 | - elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) |
|
493 | - fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
494 | - elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) |
|
495 | - fatal_lang_error('loadavg_unread_disabled', false); |
|
504 | + if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) { |
|
505 | + fatal_lang_error('loadavg_allunread_disabled', false); |
|
506 | + } elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) { |
|
507 | + fatal_lang_error('loadavg_unreadreplies_disabled', false); |
|
508 | + } elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) { |
|
509 | + fatal_lang_error('loadavg_unread_disabled', false); |
|
510 | + } |
|
496 | 511 | |
497 | 512 | // Parameters for the main query. |
498 | 513 | $query_parameters = array(); |
@@ -505,12 +520,14 @@ discard block |
||
505 | 520 | if (!empty($_REQUEST['boards'])) |
506 | 521 | { |
507 | 522 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
508 | - foreach ($_REQUEST['boards'] as $b) |
|
509 | - $boards[] = (int) $b; |
|
523 | + foreach ($_REQUEST['boards'] as $b) { |
|
524 | + $boards[] = (int) $b; |
|
525 | + } |
|
510 | 526 | } |
511 | 527 | |
512 | - if (!empty($board)) |
|
513 | - $boards[] = (int) $board; |
|
528 | + if (!empty($board)) { |
|
529 | + $boards[] = (int) $board; |
|
530 | + } |
|
514 | 531 | |
515 | 532 | // 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 |
516 | 533 | $request = $smcFunc['db_query']('', ' |
@@ -527,30 +544,31 @@ discard block |
||
527 | 544 | ) |
528 | 545 | ); |
529 | 546 | |
530 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
531 | - if (in_array($row['id_parent'], $boards)) |
|
547 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
548 | + if (in_array($row['id_parent'], $boards)) |
|
532 | 549 | $boards[] = $row['id_board']; |
550 | + } |
|
533 | 551 | |
534 | 552 | $smcFunc['db_free_result']($request); |
535 | 553 | |
536 | - if (empty($boards)) |
|
537 | - fatal_lang_error('error_no_boards_selected'); |
|
554 | + if (empty($boards)) { |
|
555 | + fatal_lang_error('error_no_boards_selected'); |
|
556 | + } |
|
538 | 557 | |
539 | 558 | $query_this_board = 'id_board IN ({array_int:boards})'; |
540 | 559 | $query_parameters['boards'] = $boards; |
541 | 560 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d'; |
542 | - } |
|
543 | - elseif (!empty($board)) |
|
561 | + } elseif (!empty($board)) |
|
544 | 562 | { |
545 | 563 | $query_this_board = 'id_board = {int:board}'; |
546 | 564 | $query_parameters['board'] = $board; |
547 | 565 | $context['querystring_board_limits'] = ';board=' . $board . '.%1$d'; |
548 | - } |
|
549 | - elseif (!empty($_REQUEST['boards'])) |
|
566 | + } elseif (!empty($_REQUEST['boards'])) |
|
550 | 567 | { |
551 | 568 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
552 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
553 | - $_REQUEST['boards'][$i] = (int) $b; |
|
569 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
570 | + $_REQUEST['boards'][$i] = (int) $b; |
|
571 | + } |
|
554 | 572 | |
555 | 573 | $request = $smcFunc['db_query']('', ' |
556 | 574 | SELECT b.id_board |
@@ -562,22 +580,24 @@ discard block |
||
562 | 580 | ) |
563 | 581 | ); |
564 | 582 | $boards = array(); |
565 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
566 | - $boards[] = $row['id_board']; |
|
583 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
584 | + $boards[] = $row['id_board']; |
|
585 | + } |
|
567 | 586 | $smcFunc['db_free_result']($request); |
568 | 587 | |
569 | - if (empty($boards)) |
|
570 | - fatal_lang_error('error_no_boards_selected'); |
|
588 | + if (empty($boards)) { |
|
589 | + fatal_lang_error('error_no_boards_selected'); |
|
590 | + } |
|
571 | 591 | |
572 | 592 | $query_this_board = 'id_board IN ({array_int:boards})'; |
573 | 593 | $query_parameters['boards'] = $boards; |
574 | 594 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d'; |
575 | - } |
|
576 | - elseif (!empty($_REQUEST['c'])) |
|
595 | + } elseif (!empty($_REQUEST['c'])) |
|
577 | 596 | { |
578 | 597 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
579 | - foreach ($_REQUEST['c'] as $i => $c) |
|
580 | - $_REQUEST['c'][$i] = (int) $c; |
|
598 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
599 | + $_REQUEST['c'][$i] = (int) $c; |
|
600 | + } |
|
581 | 601 | |
582 | 602 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
583 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -590,18 +610,19 @@ discard block |
||
590 | 610 | ) |
591 | 611 | ); |
592 | 612 | $boards = array(); |
593 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
594 | - $boards[] = $row['id_board']; |
|
613 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
614 | + $boards[] = $row['id_board']; |
|
615 | + } |
|
595 | 616 | $smcFunc['db_free_result']($request); |
596 | 617 | |
597 | - if (empty($boards)) |
|
598 | - fatal_lang_error('error_no_boards_selected'); |
|
618 | + if (empty($boards)) { |
|
619 | + fatal_lang_error('error_no_boards_selected'); |
|
620 | + } |
|
599 | 621 | |
600 | 622 | $query_this_board = 'id_board IN ({array_int:boards})'; |
601 | 623 | $query_parameters['boards'] = $boards; |
602 | 624 | $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d'; |
603 | - } |
|
604 | - else |
|
625 | + } else |
|
605 | 626 | { |
606 | 627 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
607 | 628 | // Don't bother to show deleted posts! |
@@ -615,12 +636,14 @@ discard block |
||
615 | 636 | ) |
616 | 637 | ); |
617 | 638 | $boards = array(); |
618 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
619 | - $boards[] = $row['id_board']; |
|
639 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
640 | + $boards[] = $row['id_board']; |
|
641 | + } |
|
620 | 642 | $smcFunc['db_free_result']($request); |
621 | 643 | |
622 | - if (empty($boards)) |
|
623 | - fatal_lang_error('error_no_boards_available', false); |
|
644 | + if (empty($boards)) { |
|
645 | + fatal_lang_error('error_no_boards_available', false); |
|
646 | + } |
|
624 | 647 | |
625 | 648 | $query_this_board = 'id_board IN ({array_int:boards})'; |
626 | 649 | $query_parameters['boards'] = $boards; |
@@ -682,13 +705,14 @@ discard block |
||
682 | 705 | 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies'] |
683 | 706 | ); |
684 | 707 | |
685 | - if ($context['showing_all_topics']) |
|
686 | - $context['linktree'][] = array( |
|
708 | + if ($context['showing_all_topics']) { |
|
709 | + $context['linktree'][] = array( |
|
687 | 710 | 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], |
688 | 711 | 'name' => $txt['unread_topics_all'] |
689 | 712 | ); |
690 | - else |
|
691 | - $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 | + } else { |
|
714 | + $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'])); |
|
715 | + } |
|
692 | 716 | |
693 | 717 | loadTemplate('Recent'); |
694 | 718 | loadTemplate('MessageIndex'); |
@@ -696,8 +720,9 @@ discard block |
||
696 | 720 | |
697 | 721 | // Setup the default topic icons... for checking they exist and the like ;) |
698 | 722 | $context['icon_sources'] = array(); |
699 | - foreach ($context['stable_icons'] as $icon) |
|
700 | - $context['icon_sources'][$icon] = 'images_url'; |
|
723 | + foreach ($context['stable_icons'] as $icon) { |
|
724 | + $context['icon_sources'][$icon] = 'images_url'; |
|
725 | + } |
|
701 | 726 | |
702 | 727 | $is_topics = $_REQUEST['action'] == 'unread'; |
703 | 728 | |
@@ -727,8 +752,7 @@ discard block |
||
727 | 752 | ); |
728 | 753 | list ($earliest_msg) = $smcFunc['db_fetch_row']($request); |
729 | 754 | $smcFunc['db_free_result']($request); |
730 | - } |
|
731 | - else |
|
755 | + } else |
|
732 | 756 | { |
733 | 757 | $request = $smcFunc['db_query']('', ' |
734 | 758 | SELECT MIN(lmr.id_msg) |
@@ -744,14 +768,14 @@ discard block |
||
744 | 768 | } |
745 | 769 | |
746 | 770 | // This is needed in case of topics marked unread. |
747 | - if (empty($earliest_msg)) |
|
748 | - $earliest_msg = 0; |
|
749 | - else |
|
771 | + if (empty($earliest_msg)) { |
|
772 | + $earliest_msg = 0; |
|
773 | + } else |
|
750 | 774 | { |
751 | 775 | // Using caching, when possible, to ignore the below slow query. |
752 | - if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) |
|
753 | - $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
754 | - else |
|
776 | + if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) { |
|
777 | + $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
|
778 | + } else |
|
755 | 779 | { |
756 | 780 | // This query is pretty slow, but it's needed to ensure nothing crucial is ignored. |
757 | 781 | $request = $smcFunc['db_query']('', ' |
@@ -766,8 +790,9 @@ discard block |
||
766 | 790 | $smcFunc['db_free_result']($request); |
767 | 791 | |
768 | 792 | // In theory this could be zero, if the first ever post is unread, so fudge it ;) |
769 | - if ($earliest_msg2 == 0) |
|
770 | - $earliest_msg2 = -1; |
|
793 | + if ($earliest_msg2 == 0) { |
|
794 | + $earliest_msg2 = -1; |
|
795 | + } |
|
771 | 796 | |
772 | 797 | $_SESSION['cached_log_time'] = array(time(), $earliest_msg2); |
773 | 798 | } |
@@ -805,9 +830,9 @@ discard block |
||
805 | 830 | 'db_error_skip' => true, |
806 | 831 | )) |
807 | 832 | ) !== false; |
833 | + } else { |
|
834 | + $have_temp_table = false; |
|
808 | 835 | } |
809 | - else |
|
810 | - $have_temp_table = false; |
|
811 | 836 | |
812 | 837 | if ($context['showing_all_topics'] && $have_temp_table) |
813 | 838 | { |
@@ -853,14 +878,15 @@ discard block |
||
853 | 878 | |
854 | 879 | $context['topics'] = array(); |
855 | 880 | $context['no_topic_listing'] = true; |
856 | - if ($context['querystring_board_limits'] == ';start=%1$d') |
|
857 | - $context['querystring_board_limits'] = ''; |
|
858 | - else |
|
859 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
881 | + if ($context['querystring_board_limits'] == ';start=%1$d') { |
|
882 | + $context['querystring_board_limits'] = ''; |
|
883 | + } else { |
|
884 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
885 | + } |
|
860 | 886 | return; |
887 | + } else { |
|
888 | + $min_message = (int) $min_message; |
|
861 | 889 | } |
862 | - else |
|
863 | - $min_message = (int) $min_message; |
|
864 | 890 | |
865 | 891 | $request = $smcFunc['db_query']('substring', ' |
866 | 892 | SELECT ' . $select_clause . ' |
@@ -889,8 +915,7 @@ discard block |
||
889 | 915 | 'limit' => $context['topics_per_page'], |
890 | 916 | )) |
891 | 917 | ); |
892 | - } |
|
893 | - elseif ($is_topics) |
|
918 | + } elseif ($is_topics) |
|
894 | 919 | { |
895 | 920 | $request = $smcFunc['db_query']('', ' |
896 | 921 | SELECT COUNT(*), MIN(t.id_last_msg) |
@@ -941,14 +966,15 @@ discard block |
||
941 | 966 | |
942 | 967 | $context['topics'] = array(); |
943 | 968 | $context['no_topic_listing'] = true; |
944 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
945 | - $context['querystring_board_limits'] = ''; |
|
946 | - else |
|
947 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
969 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
970 | + $context['querystring_board_limits'] = ''; |
|
971 | + } else { |
|
972 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
973 | + } |
|
948 | 974 | return; |
975 | + } else { |
|
976 | + $min_message = (int) $min_message; |
|
949 | 977 | } |
950 | - else |
|
951 | - $min_message = (int) $min_message; |
|
952 | 978 | |
953 | 979 | $request = $smcFunc['db_query']('substring', ' |
954 | 980 | SELECT ' . $select_clause . ' |
@@ -978,8 +1004,7 @@ discard block |
||
978 | 1004 | 'limit' => $context['topics_per_page'], |
979 | 1005 | )) |
980 | 1006 | ); |
981 | - } |
|
982 | - else |
|
1007 | + } else |
|
983 | 1008 | { |
984 | 1009 | if ($modSettings['totalMessages'] > 100000) |
985 | 1010 | { |
@@ -1031,8 +1056,8 @@ discard block |
||
1031 | 1056 | ) !== false; |
1032 | 1057 | |
1033 | 1058 | // If that worked, create a sample of the log_topics table too. |
1034 | - if ($have_temp_table) |
|
1035 | - $have_temp_table = $smcFunc['db_query']('', ' |
|
1059 | + if ($have_temp_table) { |
|
1060 | + $have_temp_table = $smcFunc['db_query']('', ' |
|
1036 | 1061 | CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in ( |
1037 | 1062 | PRIMARY KEY (id_topic) |
1038 | 1063 | ) |
@@ -1045,6 +1070,7 @@ discard block |
||
1045 | 1070 | 'db_error_skip' => true, |
1046 | 1071 | ) |
1047 | 1072 | ) !== false; |
1073 | + } |
|
1048 | 1074 | } |
1049 | 1075 | |
1050 | 1076 | if (!empty($have_temp_table)) |
@@ -1060,8 +1086,7 @@ discard block |
||
1060 | 1086 | ); |
1061 | 1087 | list ($num_topics) = $smcFunc['db_fetch_row']($request); |
1062 | 1088 | $smcFunc['db_free_result']($request); |
1063 | - } |
|
1064 | - else |
|
1089 | + } else |
|
1065 | 1090 | { |
1066 | 1091 | $request = $smcFunc['db_query']('unread_fetch_topic_count', ' |
1067 | 1092 | SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg) |
@@ -1102,15 +1127,16 @@ discard block |
||
1102 | 1127 | { |
1103 | 1128 | $context['topics'] = array(); |
1104 | 1129 | $context['no_topic_listing'] = true; |
1105 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
1106 | - $context['querystring_board_limits'] = ''; |
|
1107 | - else |
|
1108 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1130 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
1131 | + $context['querystring_board_limits'] = ''; |
|
1132 | + } else { |
|
1133 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1134 | + } |
|
1109 | 1135 | return; |
1110 | 1136 | } |
1111 | 1137 | |
1112 | - if (!empty($have_temp_table)) |
|
1113 | - $request = $smcFunc['db_query']('', ' |
|
1138 | + if (!empty($have_temp_table)) { |
|
1139 | + $request = $smcFunc['db_query']('', ' |
|
1114 | 1140 | SELECT t.id_topic |
1115 | 1141 | FROM {db_prefix}topics_posted_in AS t |
1116 | 1142 | LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic) |
@@ -1124,8 +1150,8 @@ discard block |
||
1124 | 1150 | 'limit' => $context['topics_per_page'], |
1125 | 1151 | )) |
1126 | 1152 | ); |
1127 | - else |
|
1128 | - $request = $smcFunc['db_query']('', ' |
|
1153 | + } else { |
|
1154 | + $request = $smcFunc['db_query']('', ' |
|
1129 | 1155 | SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].' |
1130 | 1156 | FROM {db_prefix}topics AS t |
1131 | 1157 | 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 ? '' : ' |
@@ -1149,10 +1175,12 @@ discard block |
||
1149 | 1175 | 'sort' => $_REQUEST['sort'], |
1150 | 1176 | )) |
1151 | 1177 | ); |
1178 | + } |
|
1152 | 1179 | |
1153 | 1180 | $topics = array(); |
1154 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1155 | - $topics[] = $row['id_topic']; |
|
1181 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1182 | + $topics[] = $row['id_topic']; |
|
1183 | + } |
|
1156 | 1184 | $smcFunc['db_free_result']($request); |
1157 | 1185 | |
1158 | 1186 | // Sanity... where have you gone? |
@@ -1160,10 +1188,11 @@ discard block |
||
1160 | 1188 | { |
1161 | 1189 | $context['topics'] = array(); |
1162 | 1190 | $context['no_topic_listing'] = true; |
1163 | - if ($context['querystring_board_limits'] == ';start=%d') |
|
1164 | - $context['querystring_board_limits'] = ''; |
|
1165 | - else |
|
1166 | - $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1191 | + if ($context['querystring_board_limits'] == ';start=%d') { |
|
1192 | + $context['querystring_board_limits'] = ''; |
|
1193 | + } else { |
|
1194 | + $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
|
1195 | + } |
|
1167 | 1196 | return; |
1168 | 1197 | } |
1169 | 1198 | |
@@ -1197,8 +1226,9 @@ discard block |
||
1197 | 1226 | |
1198 | 1227 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1199 | 1228 | { |
1200 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
1201 | - continue; |
|
1229 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
1230 | + continue; |
|
1231 | + } |
|
1202 | 1232 | |
1203 | 1233 | $topic_ids[] = $row['id_topic']; |
1204 | 1234 | |
@@ -1206,11 +1236,13 @@ discard block |
||
1206 | 1236 | { |
1207 | 1237 | // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. |
1208 | 1238 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
1209 | - if ($smcFunc['strlen']($row['first_body']) > 128) |
|
1210 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
1239 | + if ($smcFunc['strlen']($row['first_body']) > 128) { |
|
1240 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
|
1241 | + } |
|
1211 | 1242 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
1212 | - if ($smcFunc['strlen']($row['last_body']) > 128) |
|
1213 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
1243 | + if ($smcFunc['strlen']($row['last_body']) > 128) { |
|
1244 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
|
1245 | + } |
|
1214 | 1246 | |
1215 | 1247 | // Censor the subject and message preview. |
1216 | 1248 | censorText($row['first_subject']); |
@@ -1221,23 +1253,22 @@ discard block |
||
1221 | 1253 | { |
1222 | 1254 | $row['last_subject'] = $row['first_subject']; |
1223 | 1255 | $row['last_body'] = $row['first_body']; |
1224 | - } |
|
1225 | - else |
|
1256 | + } else |
|
1226 | 1257 | { |
1227 | 1258 | censorText($row['last_subject']); |
1228 | 1259 | censorText($row['last_body']); |
1229 | 1260 | } |
1230 | - } |
|
1231 | - else |
|
1261 | + } else |
|
1232 | 1262 | { |
1233 | 1263 | $row['first_body'] = ''; |
1234 | 1264 | $row['last_body'] = ''; |
1235 | 1265 | censorText($row['first_subject']); |
1236 | 1266 | |
1237 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
1238 | - $row['last_subject'] = $row['first_subject']; |
|
1239 | - else |
|
1240 | - censorText($row['last_subject']); |
|
1267 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
1268 | + $row['last_subject'] = $row['first_subject']; |
|
1269 | + } else { |
|
1270 | + censorText($row['last_subject']); |
|
1271 | + } |
|
1241 | 1272 | } |
1242 | 1273 | |
1243 | 1274 | // Decide how many pages the topic should have. |
@@ -1249,29 +1280,32 @@ discard block |
||
1249 | 1280 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false); |
1250 | 1281 | |
1251 | 1282 | // If we can use all, show all. |
1252 | - if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) |
|
1253 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
1283 | + if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) { |
|
1284 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
1285 | + } |
|
1286 | + } else { |
|
1287 | + $pages = ''; |
|
1254 | 1288 | } |
1255 | 1289 | |
1256 | - else |
|
1257 | - $pages = ''; |
|
1258 | - |
|
1259 | 1290 | // We need to check the topic icons exist... you can never be too sure! |
1260 | 1291 | if (!empty($modSettings['messageIconChecks_enable'])) |
1261 | 1292 | { |
1262 | 1293 | // First icon first... as you'd expect. |
1263 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
1264 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1294 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
1295 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1296 | + } |
|
1265 | 1297 | // Last icon... last... duh. |
1266 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
1267 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1268 | - } |
|
1269 | - else |
|
1298 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
1299 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1300 | + } |
|
1301 | + } else |
|
1270 | 1302 | { |
1271 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
1272 | - $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
1273 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
1274 | - $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
1303 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
1304 | + $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
1305 | + } |
|
1306 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
1307 | + $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
1308 | + } |
|
1275 | 1309 | } |
1276 | 1310 | |
1277 | 1311 | // Force the recycling icon if appropriate |
@@ -1285,12 +1319,14 @@ discard block |
||
1285 | 1319 | $colorClass = 'windowbg'; |
1286 | 1320 | |
1287 | 1321 | // Sticky topics should get a different color, too. |
1288 | - if ($row['is_sticky']) |
|
1289 | - $colorClass .= ' sticky'; |
|
1322 | + if ($row['is_sticky']) { |
|
1323 | + $colorClass .= ' sticky'; |
|
1324 | + } |
|
1290 | 1325 | |
1291 | 1326 | // Locked topics get special treatment as well. |
1292 | - if ($row['locked']) |
|
1293 | - $colorClass .= ' locked'; |
|
1327 | + if ($row['locked']) { |
|
1328 | + $colorClass .= ' locked'; |
|
1329 | + } |
|
1294 | 1330 | |
1295 | 1331 | // And build the array. |
1296 | 1332 | $context['topics'][$row['id_topic']] = array( |
@@ -1387,8 +1423,9 @@ discard block |
||
1387 | 1423 | ); |
1388 | 1424 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1389 | 1425 | { |
1390 | - if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) |
|
1391 | - $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
1426 | + if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) { |
|
1427 | + $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
1428 | + } |
|
1392 | 1429 | } |
1393 | 1430 | $smcFunc['db_free_result']($result); |
1394 | 1431 | } |
@@ -1403,28 +1440,30 @@ discard block |
||
1403 | 1440 | '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']), |
1404 | 1441 | ); |
1405 | 1442 | |
1406 | - if ($context['showCheckboxes']) |
|
1407 | - $context['recent_buttons']['markselectread'] = array( |
|
1443 | + if ($context['showCheckboxes']) { |
|
1444 | + $context['recent_buttons']['markselectread'] = array( |
|
1408 | 1445 | 'text' => 'quick_mod_markread', |
1409 | 1446 | 'image' => 'markselectedread.png', |
1410 | 1447 | 'url' => 'javascript:document.quickModForm.submit();', |
1411 | 1448 | ); |
1449 | + } |
|
1412 | 1450 | |
1413 | - if (!empty($context['topics']) && !$context['showing_all_topics']) |
|
1414 | - $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
1415 | - } |
|
1416 | - elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
1451 | + if (!empty($context['topics']) && !$context['showing_all_topics']) { |
|
1452 | + $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
|
1453 | + } |
|
1454 | + } elseif (!$is_topics && isset($context['topics_to_mark'])) |
|
1417 | 1455 | { |
1418 | 1456 | $context['recent_buttons'] = array( |
1419 | 1457 | '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']), |
1420 | 1458 | ); |
1421 | 1459 | |
1422 | - if ($context['showCheckboxes']) |
|
1423 | - $context['recent_buttons']['markselectread'] = array( |
|
1460 | + if ($context['showCheckboxes']) { |
|
1461 | + $context['recent_buttons']['markselectread'] = array( |
|
1424 | 1462 | 'text' => 'quick_mod_markread', |
1425 | 1463 | 'image' => 'markselectedread.png', |
1426 | 1464 | 'url' => 'javascript:document.quickModForm.submit();', |
1427 | 1465 | ); |
1466 | + } |
|
1428 | 1467 | } |
1429 | 1468 | |
1430 | 1469 | // Allow mods to add additional buttons here |