Conditions | 193 |
Paths | 0 |
Total Lines | 977 |
Code Lines | 555 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
497 | function UnreadTopics() |
||
498 | { |
||
499 | global $board, $txt, $scripturl, $sourcedir; |
||
500 | global $user_info, $context, $settings, $modSettings, $smcFunc, $options; |
||
501 | |||
502 | // Guests can't have unread things, we don't know anything about them. |
||
503 | is_not_guest(); |
||
504 | |||
505 | // Prefetching + lots of MySQL work = bad mojo. |
||
506 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
||
507 | { |
||
508 | ob_end_clean(); |
||
509 | send_http_status(403); |
||
510 | die; |
||
511 | } |
||
512 | |||
513 | $context['showCheckboxes'] = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1; |
||
514 | |||
515 | $context['showing_all_topics'] = isset($_GET['all']); |
||
516 | $context['start'] = (int) $_REQUEST['start']; |
||
517 | $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
||
518 | if ($_REQUEST['action'] == 'unread') |
||
519 | $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit']; |
||
520 | else |
||
521 | $context['page_title'] = $txt['unread_replies']; |
||
522 | |||
523 | if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) |
||
524 | fatal_lang_error('loadavg_allunread_disabled', false); |
||
525 | elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) |
||
526 | fatal_lang_error('loadavg_unreadreplies_disabled', false); |
||
527 | elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) |
||
528 | fatal_lang_error('loadavg_unread_disabled', false); |
||
529 | |||
530 | // Parameters for the main query. |
||
531 | $query_parameters = array(); |
||
532 | |||
533 | // Are we specifying any specific board? |
||
534 | if (isset($_REQUEST['children']) && (!empty($board) || !empty($_REQUEST['boards']))) |
||
535 | { |
||
536 | $boards = array(); |
||
537 | |||
538 | if (!empty($_REQUEST['boards'])) |
||
539 | { |
||
540 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
||
541 | foreach ($_REQUEST['boards'] as $b) |
||
542 | $boards[] = (int) $b; |
||
543 | } |
||
544 | |||
545 | if (!empty($board)) |
||
546 | $boards[] = (int) $board; |
||
547 | |||
548 | // 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 |
||
549 | $request = $smcFunc['db_query']('', ' |
||
550 | SELECT b.id_board, b.id_parent |
||
551 | FROM {db_prefix}boards AS b |
||
552 | WHERE {query_wanna_see_board} |
||
553 | AND b.child_level > {int:no_child} |
||
554 | AND b.id_board NOT IN ({array_int:boards}) |
||
555 | ORDER BY child_level ASC', |
||
556 | array( |
||
557 | 'no_child' => 0, |
||
558 | 'boards' => $boards, |
||
559 | ) |
||
560 | ); |
||
561 | |||
562 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
563 | if (in_array($row['id_parent'], $boards)) |
||
564 | $boards[] = $row['id_board']; |
||
565 | |||
566 | $smcFunc['db_free_result']($request); |
||
567 | |||
568 | if (empty($boards)) |
||
569 | fatal_lang_error('error_no_boards_selected'); |
||
570 | |||
571 | $query_this_board = 'id_board IN ({array_int:boards})'; |
||
572 | $query_parameters['boards'] = $boards; |
||
573 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d'; |
||
574 | } |
||
575 | elseif (!empty($board)) |
||
576 | { |
||
577 | $query_this_board = 'id_board = {int:board}'; |
||
578 | $query_parameters['board'] = $board; |
||
579 | $context['querystring_board_limits'] = ';board=' . $board . '.%1$d'; |
||
580 | } |
||
581 | elseif (!empty($_REQUEST['boards'])) |
||
582 | { |
||
583 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
||
584 | foreach ($_REQUEST['boards'] as $i => $b) |
||
585 | $_REQUEST['boards'][$i] = (int) $b; |
||
586 | |||
587 | $request = $smcFunc['db_query']('', ' |
||
588 | SELECT b.id_board |
||
589 | FROM {db_prefix}boards AS b |
||
590 | WHERE {query_see_board} |
||
591 | AND b.id_board IN ({array_int:board_list})', |
||
592 | array( |
||
593 | 'board_list' => $_REQUEST['boards'], |
||
594 | ) |
||
595 | ); |
||
596 | $boards = array(); |
||
597 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
598 | $boards[] = $row['id_board']; |
||
599 | $smcFunc['db_free_result']($request); |
||
600 | |||
601 | if (empty($boards)) |
||
602 | fatal_lang_error('error_no_boards_selected'); |
||
603 | |||
604 | $query_this_board = 'id_board IN ({array_int:boards})'; |
||
605 | $query_parameters['boards'] = $boards; |
||
606 | $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d'; |
||
607 | } |
||
608 | elseif (!empty($_REQUEST['c'])) |
||
609 | { |
||
610 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
||
611 | foreach ($_REQUEST['c'] as $i => $c) |
||
612 | $_REQUEST['c'][$i] = (int) $c; |
||
613 | |||
614 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
||
615 | |||
616 | $request = $smcFunc['db_query']('', ' |
||
617 | SELECT b.id_board |
||
618 | FROM {db_prefix}boards AS b |
||
619 | WHERE ' . $user_info[$see_board] . ' |
||
620 | AND b.id_cat IN ({array_int:id_cat})', |
||
621 | array( |
||
622 | 'id_cat' => $_REQUEST['c'], |
||
623 | ) |
||
624 | ); |
||
625 | $boards = array(); |
||
626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
627 | $boards[] = $row['id_board']; |
||
628 | $smcFunc['db_free_result']($request); |
||
629 | |||
630 | if (empty($boards)) |
||
631 | fatal_lang_error('error_no_boards_selected'); |
||
632 | |||
633 | $query_this_board = 'id_board IN ({array_int:boards})'; |
||
634 | $query_parameters['boards'] = $boards; |
||
635 | $context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d'; |
||
636 | } |
||
637 | else |
||
638 | { |
||
639 | $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board'; |
||
640 | // Don't bother to show deleted posts! |
||
641 | $request = $smcFunc['db_query']('', ' |
||
642 | SELECT b.id_board |
||
643 | FROM {db_prefix}boards AS b |
||
644 | WHERE ' . $user_info[$see_board] . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
||
645 | AND b.id_board != {int:recycle_board}' : ''), |
||
646 | array( |
||
647 | 'recycle_board' => (int) $modSettings['recycle_board'], |
||
648 | ) |
||
649 | ); |
||
650 | $boards = array(); |
||
651 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
652 | $boards[] = $row['id_board']; |
||
653 | $smcFunc['db_free_result']($request); |
||
654 | |||
655 | if (empty($boards)) |
||
656 | fatal_lang_error('error_no_boards_available', false); |
||
657 | |||
658 | $query_this_board = 'id_board IN ({array_int:boards})'; |
||
659 | $query_parameters['boards'] = $boards; |
||
660 | $context['querystring_board_limits'] = ';start=%1$d'; |
||
661 | $context['no_board_limits'] = true; |
||
662 | } |
||
663 | |||
664 | $sort_methods = array( |
||
665 | 'subject' => 'ms.subject', |
||
666 | 'starter' => 'COALESCE(mems.real_name, ms.poster_name)', |
||
667 | 'replies' => 't.num_replies', |
||
668 | 'views' => 't.num_views', |
||
669 | 'first_post' => 't.id_topic', |
||
670 | 'last_post' => 't.id_last_msg' |
||
671 | ); |
||
672 | |||
673 | // The default is the most logical: newest first. |
||
674 | if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) |
||
675 | { |
||
676 | $context['sort_by'] = 'last_post'; |
||
677 | $_REQUEST['sort'] = 't.id_last_msg'; |
||
678 | $ascending = isset($_REQUEST['asc']); |
||
679 | |||
680 | $context['querystring_sort_limits'] = $ascending ? ';asc' : ''; |
||
681 | } |
||
682 | // But, for other methods the default sort is ascending. |
||
683 | else |
||
684 | { |
||
685 | $context['sort_by'] = $_REQUEST['sort']; |
||
686 | $_REQUEST['sort'] = $sort_methods[$_REQUEST['sort']]; |
||
687 | $ascending = !isset($_REQUEST['desc']); |
||
688 | |||
689 | $context['querystring_sort_limits'] = ';sort=' . $context['sort_by'] . ($ascending ? '' : ';desc'); |
||
690 | } |
||
691 | $context['sort_direction'] = $ascending ? 'up' : 'down'; |
||
692 | |||
693 | if (!empty($_REQUEST['c']) && is_array($_REQUEST['c']) && count($_REQUEST['c']) == 1) |
||
694 | { |
||
695 | $request = $smcFunc['db_query']('', ' |
||
696 | SELECT name |
||
697 | FROM {db_prefix}categories |
||
698 | WHERE id_cat = {int:id_cat} |
||
699 | LIMIT 1', |
||
700 | array( |
||
701 | 'id_cat' => (int) $_REQUEST['c'][0], |
||
702 | ) |
||
703 | ); |
||
704 | list ($name) = $smcFunc['db_fetch_row']($request); |
||
705 | $smcFunc['db_free_result']($request); |
||
706 | |||
707 | $context['linktree'][] = array( |
||
708 | 'url' => $scripturl . '#c' . (int) $_REQUEST['c'][0], |
||
709 | 'name' => $name |
||
710 | ); |
||
711 | } |
||
712 | |||
713 | $context['linktree'][] = array( |
||
714 | 'url' => $scripturl . '?action=' . $_REQUEST['action'] . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], |
||
715 | 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies'] |
||
716 | ); |
||
717 | |||
718 | if ($context['showing_all_topics']) |
||
719 | $context['linktree'][] = array( |
||
720 | 'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], |
||
721 | 'name' => $txt['unread_topics_all'] |
||
722 | ); |
||
723 | else |
||
724 | $txt['unread_topics_visit_none'] = strtr(sprintf($txt['unread_topics_visit_none'], $scripturl), array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'])); |
||
725 | |||
726 | loadTemplate('Recent'); |
||
727 | loadTemplate('MessageIndex'); |
||
728 | $context['sub_template'] = $_REQUEST['action'] == 'unread' ? 'unread' : 'replies'; |
||
729 | |||
730 | // Setup the default topic icons... for checking they exist and the like ;) |
||
731 | $context['icon_sources'] = array(); |
||
732 | foreach ($context['stable_icons'] as $icon) |
||
733 | $context['icon_sources'][$icon] = 'images_url'; |
||
734 | |||
735 | $is_topics = $_REQUEST['action'] == 'unread'; |
||
736 | |||
737 | // This part is the same for each query. |
||
738 | $select_clause = ' |
||
739 | ms.subject AS first_subject, ms.poster_time AS first_poster_time, ms.id_topic, t.id_board, b.name AS bname, |
||
740 | t.num_replies, t.num_views, ms.id_member AS id_first_member, ml.id_member AS id_last_member,' . (!empty($settings['avatars_on_indexes']) ? ' meml.avatar, meml.email_address, mems.avatar AS first_poster_avatar, mems.email_address AS first_poster_email, COALESCE(af.id_attach, 0) AS first_poster_id_attach, af.filename AS first_poster_filename, af.attachment_type AS first_poster_attach_type, COALESCE(al.id_attach, 0) AS last_poster_id_attach, al.filename AS last_poster_filename, al.attachment_type AS last_poster_attach_type,' : '') . ' |
||
741 | ml.poster_time AS last_poster_time, COALESCE(mems.real_name, ms.poster_name) AS first_poster_name, |
||
742 | COALESCE(meml.real_name, ml.poster_name) AS last_poster_name, ml.subject AS last_subject, |
||
743 | ml.icon AS last_icon, ms.icon AS first_icon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS last_modified_time, |
||
744 | COALESCE(lt.id_msg, lmr.id_msg, -1) + 1 AS new_from, SUBSTRING(ml.body, 1, 385) AS last_body, |
||
745 | SUBSTRING(ms.body, 1, 385) AS first_body, ml.smileys_enabled AS last_smileys, ms.smileys_enabled AS first_smileys, t.id_first_msg, t.id_last_msg'; |
||
746 | |||
747 | if ($context['showing_all_topics']) |
||
748 | { |
||
749 | if (!empty($board)) |
||
750 | { |
||
751 | $request = $smcFunc['db_query']('', ' |
||
752 | SELECT MIN(id_msg) |
||
753 | FROM {db_prefix}log_mark_read |
||
754 | WHERE id_member = {int:current_member} |
||
755 | AND id_board = {int:current_board}', |
||
756 | array( |
||
757 | 'current_board' => $board, |
||
758 | 'current_member' => $user_info['id'], |
||
759 | ) |
||
760 | ); |
||
761 | list ($earliest_msg) = $smcFunc['db_fetch_row']($request); |
||
762 | $smcFunc['db_free_result']($request); |
||
763 | } |
||
764 | else |
||
765 | { |
||
766 | $request = $smcFunc['db_query']('', ' |
||
767 | SELECT MIN(lmr.id_msg) |
||
768 | FROM {db_prefix}boards AS b |
||
769 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member}) |
||
770 | WHERE {query_see_board}', |
||
771 | array( |
||
772 | 'current_member' => $user_info['id'], |
||
773 | ) |
||
774 | ); |
||
775 | list ($earliest_msg) = $smcFunc['db_fetch_row']($request); |
||
776 | $smcFunc['db_free_result']($request); |
||
777 | } |
||
778 | |||
779 | // This is needed in case of topics marked unread. |
||
780 | if (empty($earliest_msg)) |
||
781 | $earliest_msg = 0; |
||
782 | else |
||
783 | { |
||
784 | // Using caching, when possible, to ignore the below slow query. |
||
785 | if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) |
||
786 | $earliest_msg2 = $_SESSION['cached_log_time'][1]; |
||
787 | else |
||
788 | { |
||
789 | // This query is pretty slow, but it's needed to ensure nothing crucial is ignored. |
||
790 | $request = $smcFunc['db_query']('', ' |
||
791 | SELECT MIN(id_msg) |
||
792 | FROM {db_prefix}log_topics |
||
793 | WHERE id_member = {int:current_member}', |
||
794 | array( |
||
795 | 'current_member' => $user_info['id'], |
||
796 | ) |
||
797 | ); |
||
798 | list ($earliest_msg2) = $smcFunc['db_fetch_row']($request); |
||
799 | $smcFunc['db_free_result']($request); |
||
800 | |||
801 | // In theory this could be zero, if the first ever post is unread, so fudge it ;) |
||
802 | if ($earliest_msg2 == 0) |
||
803 | $earliest_msg2 = -1; |
||
804 | |||
805 | $_SESSION['cached_log_time'] = array(time(), $earliest_msg2); |
||
806 | } |
||
807 | |||
808 | $earliest_msg = min($earliest_msg2, $earliest_msg); |
||
809 | } |
||
810 | } |
||
811 | |||
812 | // @todo Add modified_time in for log_time check? |
||
813 | |||
814 | if ($modSettings['totalMessages'] > 100000 && $context['showing_all_topics']) |
||
815 | { |
||
816 | $smcFunc['db_query']('', ' |
||
817 | DROP TABLE IF EXISTS {db_prefix}log_topics_unread', |
||
818 | array( |
||
819 | ) |
||
820 | ); |
||
821 | |||
822 | // Let's copy things out of the log_topics table, to reduce searching. |
||
823 | $have_temp_table = $smcFunc['db_query']('', ' |
||
824 | CREATE TEMPORARY TABLE {db_prefix}log_topics_unread ( |
||
825 | PRIMARY KEY (id_topic) |
||
826 | ) |
||
827 | SELECT lt.id_topic, lt.id_msg |
||
828 | FROM {db_prefix}topics AS t |
||
829 | INNER JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic) |
||
830 | WHERE lt.id_member = {int:current_member} |
||
831 | AND t.' . $query_this_board . (empty($earliest_msg) ? '' : ' |
||
832 | AND t.id_last_msg > {int:earliest_msg}') . ($modSettings['postmod_active'] ? ' |
||
833 | AND t.approved = {int:is_approved}' : '') . ' AND lt.unwatched != 1', |
||
834 | array_merge($query_parameters, array( |
||
835 | 'current_member' => $user_info['id'], |
||
836 | 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0, |
||
837 | 'is_approved' => 1, |
||
838 | 'db_error_skip' => true, |
||
839 | )) |
||
840 | ) !== false; |
||
841 | } |
||
842 | else |
||
843 | $have_temp_table = false; |
||
844 | |||
845 | if ($context['showing_all_topics'] && $have_temp_table) |
||
846 | { |
||
847 | $request = $smcFunc['db_query']('', ' |
||
848 | SELECT COUNT(*), MIN(t.id_last_msg) |
||
849 | FROM {db_prefix}topics AS t |
||
850 | LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic) |
||
851 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member}) |
||
852 | WHERE t.' . $query_this_board . (!empty($earliest_msg) ? ' |
||
853 | AND t.id_last_msg > {int:earliest_msg}' : '') . ' |
||
854 | AND COALESCE(lt.id_msg, lmr.id_msg, 0) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' |
||
855 | AND t.approved = {int:is_approved}' : ''), |
||
856 | array_merge($query_parameters, array( |
||
857 | 'current_member' => $user_info['id'], |
||
858 | 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0, |
||
859 | 'is_approved' => 1, |
||
860 | )) |
||
861 | ); |
||
862 | list ($num_topics, $min_message) = $smcFunc['db_fetch_row']($request); |
||
863 | $smcFunc['db_free_result']($request); |
||
864 | |||
865 | // Make sure the starting place makes sense and construct the page index. |
||
866 | $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true); |
||
867 | $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page']; |
||
868 | |||
869 | $context['links'] = array( |
||
870 | 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'] : '', |
||
871 | 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
872 | 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
873 | 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], floor(($num_topics - 1) / $context['topics_per_page']) * $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
874 | 'up' => $scripturl, |
||
875 | ); |
||
876 | $context['page_info'] = array( |
||
877 | 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, |
||
878 | 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1 |
||
879 | ); |
||
880 | |||
881 | if ($num_topics == 0) |
||
882 | { |
||
883 | // Mark the boards as read if there are no unread topics! |
||
884 | require_once($sourcedir . '/Subs-Boards.php'); |
||
885 | markBoardsRead(empty($boards) ? $board : $boards); |
||
886 | |||
887 | $context['topics'] = array(); |
||
888 | $context['no_topic_listing'] = true; |
||
889 | if ($context['querystring_board_limits'] == ';start=%1$d') |
||
890 | $context['querystring_board_limits'] = ''; |
||
891 | else |
||
892 | $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
||
893 | return; |
||
894 | } |
||
895 | else |
||
896 | $min_message = (int) $min_message; |
||
897 | |||
898 | $request = $smcFunc['db_query']('substring', ' |
||
899 | SELECT ' . $select_clause . ' |
||
900 | FROM {db_prefix}messages AS ms |
||
901 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ms.id_topic AND t.id_first_msg = ms.id_msg) |
||
902 | INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) |
||
903 | LEFT JOIN {db_prefix}boards AS b ON (b.id_board = ms.id_board) |
||
904 | LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member) |
||
905 | LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' . (!empty($settings['avatars_on_indexes']) ? ' |
||
906 | LEFT JOIN {db_prefix}attachments AS af ON (af.id_member = mems.id_member) |
||
907 | LEFT JOIN {db_prefix}attachments AS al ON (al.id_member = meml.id_member)' : '') . ' |
||
908 | LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic) |
||
909 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member}) |
||
910 | WHERE b.' . $query_this_board . ' |
||
911 | AND t.id_last_msg >= {int:min_message} |
||
912 | AND COALESCE(lt.id_msg, lmr.id_msg, 0) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' |
||
913 | AND ms.approved = {int:is_approved}' : '') . ' |
||
914 | ORDER BY {raw:sort} |
||
915 | LIMIT {int:offset}, {int:limit}', |
||
916 | array_merge($query_parameters, array( |
||
917 | 'current_member' => $user_info['id'], |
||
918 | 'min_message' => $min_message, |
||
919 | 'is_approved' => 1, |
||
920 | 'sort' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'), |
||
921 | 'offset' => $_REQUEST['start'], |
||
922 | 'limit' => $context['topics_per_page'], |
||
923 | )) |
||
924 | ); |
||
925 | } |
||
926 | elseif ($is_topics) |
||
927 | { |
||
928 | $request = $smcFunc['db_query']('', ' |
||
929 | SELECT COUNT(*), MIN(t.id_last_msg) |
||
930 | FROM {db_prefix}topics AS t' . (!empty($have_temp_table) ? ' |
||
931 | LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : ' |
||
932 | LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . ' |
||
933 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member}) |
||
934 | WHERE t.' . $query_this_board . ($context['showing_all_topics'] && !empty($earliest_msg) ? ' |
||
935 | AND t.id_last_msg > {int:earliest_msg}' : (!$context['showing_all_topics'] && empty($_SESSION['first_login']) ? ' |
||
936 | AND t.id_last_msg > {int:id_msg_last_visit}' : '')) . ' |
||
937 | AND COALESCE(lt.id_msg, lmr.id_msg, 0) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' |
||
938 | AND t.approved = {int:is_approved}' : '') . ' |
||
939 | AND COALESCE(lt.unwatched, 0) != 1', |
||
940 | array_merge($query_parameters, array( |
||
941 | 'current_member' => $user_info['id'], |
||
942 | 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0, |
||
943 | 'id_msg_last_visit' => $_SESSION['id_msg_last_visit'], |
||
944 | 'is_approved' => 1, |
||
945 | )) |
||
946 | ); |
||
947 | list ($num_topics, $min_message) = $smcFunc['db_fetch_row']($request); |
||
948 | $smcFunc['db_free_result']($request); |
||
949 | |||
950 | // Make sure the starting place makes sense and construct the page index. |
||
951 | $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true); |
||
952 | $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page']; |
||
953 | |||
954 | $context['links'] = array( |
||
955 | 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'] : '', |
||
956 | 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
957 | 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
958 | 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], floor(($num_topics - 1) / $context['topics_per_page']) * $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
959 | 'up' => $scripturl, |
||
960 | ); |
||
961 | $context['page_info'] = array( |
||
962 | 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, |
||
963 | 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1 |
||
964 | ); |
||
965 | |||
966 | if ($num_topics == 0) |
||
967 | { |
||
968 | // Is this an all topics query? |
||
969 | if ($context['showing_all_topics']) |
||
970 | { |
||
971 | // Since there are no unread topics, mark the boards as read! |
||
972 | require_once($sourcedir . '/Subs-Boards.php'); |
||
973 | markBoardsRead(empty($boards) ? $board : $boards); |
||
974 | } |
||
975 | |||
976 | $context['topics'] = array(); |
||
977 | $context['no_topic_listing'] = true; |
||
978 | if ($context['querystring_board_limits'] == ';start=%d') |
||
979 | $context['querystring_board_limits'] = ''; |
||
980 | else |
||
981 | $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
||
982 | return; |
||
983 | } |
||
984 | else |
||
985 | $min_message = (int) $min_message; |
||
986 | |||
987 | $request = $smcFunc['db_query']('substring', ' |
||
988 | SELECT ' . $select_clause . ' |
||
989 | FROM {db_prefix}messages AS ms |
||
990 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ms.id_topic AND t.id_first_msg = ms.id_msg) |
||
991 | INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) |
||
992 | LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) |
||
993 | LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member) |
||
994 | LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' . (!empty($settings['avatars_on_indexes']) ? ' |
||
995 | LEFT JOIN {db_prefix}attachments AS af ON (af.id_member = mems.id_member) |
||
996 | LEFT JOIN {db_prefix}attachments AS al ON (al.id_member = meml.id_member)' : '') . '' . (!empty($have_temp_table) ? ' |
||
997 | LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : ' |
||
998 | LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . ' |
||
999 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member}) |
||
1000 | WHERE t.' . $query_this_board . ' |
||
1001 | AND t.id_last_msg >= {int:min_message} |
||
1002 | AND COALESCE(lt.id_msg, lmr.id_msg, 0) < ml.id_msg' . ($modSettings['postmod_active'] ? ' |
||
1003 | AND ms.approved = {int:is_approved}' : '') . ' |
||
1004 | AND COALESCE(lt.unwatched, 0) != 1 |
||
1005 | ORDER BY {raw:order} |
||
1006 | LIMIT {int:offset}, {int:limit}', |
||
1007 | array_merge($query_parameters, array( |
||
1008 | 'current_member' => $user_info['id'], |
||
1009 | 'min_message' => $min_message, |
||
1010 | 'is_approved' => 1, |
||
1011 | 'order' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'), |
||
1012 | 'offset' => $_REQUEST['start'], |
||
1013 | 'limit' => $context['topics_per_page'], |
||
1014 | )) |
||
1015 | ); |
||
1016 | } |
||
1017 | else |
||
1018 | { |
||
1019 | if ($modSettings['totalMessages'] > 100000) |
||
1020 | { |
||
1021 | $smcFunc['db_query']('', ' |
||
1022 | DROP TABLE IF EXISTS {db_prefix}topics_posted_in', |
||
1023 | array( |
||
1024 | ) |
||
1025 | ); |
||
1026 | |||
1027 | $smcFunc['db_query']('', ' |
||
1028 | DROP TABLE IF EXISTS {db_prefix}log_topics_posted_in', |
||
1029 | array( |
||
1030 | ) |
||
1031 | ); |
||
1032 | |||
1033 | $sortKey_joins = array( |
||
1034 | 'ms.subject' => ' |
||
1035 | INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)', |
||
1036 | 'COALESCE(mems.real_name, ms.poster_name)' => ' |
||
1037 | INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg) |
||
1038 | LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)', |
||
1039 | ); |
||
1040 | |||
1041 | // The main benefit of this temporary table is not that it's faster; it's that it avoids locks later. |
||
1042 | $have_temp_table = $smcFunc['db_query']('', ' |
||
1043 | CREATE TEMPORARY TABLE {db_prefix}topics_posted_in ( |
||
1044 | id_topic mediumint(8) unsigned NOT NULL default {string:string_zero}, |
||
1045 | id_board smallint(5) unsigned NOT NULL default {string:string_zero}, |
||
1046 | id_last_msg int(10) unsigned NOT NULL default {string:string_zero}, |
||
1047 | id_msg int(10) unsigned NOT NULL default {string:string_zero}, |
||
1048 | PRIMARY KEY (id_topic) |
||
1049 | ) |
||
1050 | SELECT t.id_topic, t.id_board, t.id_last_msg, COALESCE(lmr.id_msg, 0) AS id_msg' . (!in_array($_REQUEST['sort'], array('t.id_last_msg', 't.id_topic')) ? ', ' . $_REQUEST['sort'] . ' AS sort_key' : '') . ' |
||
1051 | FROM {db_prefix}messages AS m |
||
1052 | INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) |
||
1053 | LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic) |
||
1054 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})' . (isset($sortKey_joins[$_REQUEST['sort']]) ? $sortKey_joins[$_REQUEST['sort']] : '') . ' |
||
1055 | WHERE m.id_member = {int:current_member}' . (!empty($board) ? ' |
||
1056 | AND t.id_board = {int:current_board}' : '') . ($modSettings['postmod_active'] ? ' |
||
1057 | AND t.approved = {int:is_approved}' : '') . ' |
||
1058 | GROUP BY m.id_topic', |
||
1059 | array( |
||
1060 | 'current_board' => $board, |
||
1061 | 'current_member' => $user_info['id'], |
||
1062 | 'is_approved' => 1, |
||
1063 | 'string_zero' => '0', |
||
1064 | 'db_error_skip' => true, |
||
1065 | ) |
||
1066 | ) !== false; |
||
1067 | |||
1068 | // If that worked, create a sample of the log_topics table too. |
||
1069 | if ($have_temp_table) |
||
1070 | $have_temp_table = $smcFunc['db_query']('', ' |
||
1071 | CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in ( |
||
1072 | PRIMARY KEY (id_topic) |
||
1073 | ) |
||
1074 | SELECT lt.id_topic, lt.id_msg |
||
1075 | FROM {db_prefix}log_topics AS lt |
||
1076 | INNER JOIN {db_prefix}topics_posted_in AS pi ON (pi.id_topic = lt.id_topic) |
||
1077 | WHERE lt.id_member = {int:current_member}', |
||
1078 | array( |
||
1079 | 'current_member' => $user_info['id'], |
||
1080 | 'db_error_skip' => true, |
||
1081 | ) |
||
1082 | ) !== false; |
||
1083 | } |
||
1084 | |||
1085 | if (!empty($have_temp_table)) |
||
1086 | { |
||
1087 | $request = $smcFunc['db_query']('', ' |
||
1088 | SELECT COUNT(*) |
||
1089 | FROM {db_prefix}topics_posted_in AS pi |
||
1090 | LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = pi.id_topic) |
||
1091 | WHERE pi.' . $query_this_board . ' |
||
1092 | AND COALESCE(lt.id_msg, pi.id_msg) < pi.id_last_msg', |
||
1093 | array_merge($query_parameters, array( |
||
1094 | )) |
||
1095 | ); |
||
1096 | list ($num_topics) = $smcFunc['db_fetch_row']($request); |
||
1097 | $smcFunc['db_free_result']($request); |
||
1098 | } |
||
1099 | else |
||
1100 | { |
||
1101 | $request = $smcFunc['db_query']('unread_fetch_topic_count', ' |
||
1102 | SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg) |
||
1103 | FROM {db_prefix}topics AS t |
||
1104 | INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic) |
||
1105 | LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) |
||
1106 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member}) |
||
1107 | WHERE t.' . $query_this_board . ' |
||
1108 | AND m.id_member = {int:current_member} |
||
1109 | AND COALESCE(lt.id_msg, lmr.id_msg, 0) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' |
||
1110 | AND t.approved = {int:is_approved}' : '') . ' |
||
1111 | AND COALESCE(lt.unwatched, 0) != 1', |
||
1112 | array_merge($query_parameters, array( |
||
1113 | 'current_member' => $user_info['id'], |
||
1114 | 'is_approved' => 1, |
||
1115 | )) |
||
1116 | ); |
||
1117 | list ($num_topics, $min_message) = $smcFunc['db_fetch_row']($request); |
||
1118 | $smcFunc['db_free_result']($request); |
||
1119 | } |
||
1120 | |||
1121 | // Make sure the starting place makes sense and construct the page index. |
||
1122 | $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true); |
||
1123 | $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page']; |
||
1124 | |||
1125 | $context['links'] = array( |
||
1126 | 'first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'] : '', |
||
1127 | 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
1128 | 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
1129 | 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], floor(($num_topics - 1) / $context['topics_per_page']) * $context['topics_per_page']) . $context['querystring_sort_limits'] : '', |
||
1130 | 'up' => $scripturl, |
||
1131 | ); |
||
1132 | $context['page_info'] = array( |
||
1133 | 'current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, |
||
1134 | 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1 |
||
1135 | ); |
||
1136 | |||
1137 | if ($num_topics == 0) |
||
1138 | { |
||
1139 | $context['topics'] = array(); |
||
1140 | $context['no_topic_listing'] = true; |
||
1141 | if ($context['querystring_board_limits'] == ';start=%d') |
||
1142 | $context['querystring_board_limits'] = ''; |
||
1143 | else |
||
1144 | $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
||
1145 | return; |
||
1146 | } |
||
1147 | |||
1148 | if (!empty($have_temp_table)) |
||
1149 | $request = $smcFunc['db_query']('', ' |
||
1150 | SELECT t.id_topic |
||
1151 | FROM {db_prefix}topics_posted_in AS t |
||
1152 | LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic) |
||
1153 | WHERE t.' . $query_this_board . ' |
||
1154 | AND COALESCE(lt.id_msg, t.id_msg) < t.id_last_msg |
||
1155 | ORDER BY {raw:order} |
||
1156 | LIMIT {int:offset}, {int:limit}', |
||
1157 | array_merge($query_parameters, array( |
||
1158 | 'order' => (in_array($_REQUEST['sort'], array('t.id_last_msg', 't.id_topic')) ? $_REQUEST['sort'] : 't.sort_key') . ($ascending ? '' : ' DESC'), |
||
1159 | 'offset' => $_REQUEST['start'], |
||
1160 | 'limit' => $context['topics_per_page'], |
||
1161 | )) |
||
1162 | ); |
||
1163 | else |
||
1164 | $request = $smcFunc['db_query']('', ' |
||
1165 | SELECT DISTINCT t.id_topic,' . $_REQUEST['sort'] . ' |
||
1166 | FROM {db_prefix}topics AS t |
||
1167 | 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 ? '' : ' |
||
1168 | INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)') . (strpos($_REQUEST['sort'], 'mems.') === false ? '' : ' |
||
1169 | LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)') . ' |
||
1170 | LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) |
||
1171 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member}) |
||
1172 | WHERE t.' . $query_this_board . ' |
||
1173 | AND t.id_last_msg >= {int:min_message} |
||
1174 | AND (COALESCE(lt.id_msg, lmr.id_msg, 0)) < t.id_last_msg |
||
1175 | AND t.approved = {int:is_approved} |
||
1176 | AND COALESCE(lt.unwatched, 0) != 1 |
||
1177 | ORDER BY {raw:order} |
||
1178 | LIMIT {int:offset}, {int:limit}', |
||
1179 | array_merge($query_parameters, array( |
||
1180 | 'current_member' => $user_info['id'], |
||
1181 | 'min_message' => (int) $min_message, |
||
1182 | 'is_approved' => 1, |
||
1183 | 'order' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'), |
||
1184 | 'offset' => $_REQUEST['start'], |
||
1185 | 'limit' => $context['topics_per_page'], |
||
1186 | 'sort' => $_REQUEST['sort'], |
||
1187 | )) |
||
1188 | ); |
||
1189 | |||
1190 | $topics = array(); |
||
1191 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1192 | $topics[] = $row['id_topic']; |
||
1193 | $smcFunc['db_free_result']($request); |
||
1194 | |||
1195 | // Sanity... where have you gone? |
||
1196 | if (empty($topics)) |
||
1197 | { |
||
1198 | $context['topics'] = array(); |
||
1199 | $context['no_topic_listing'] = true; |
||
1200 | if ($context['querystring_board_limits'] == ';start=%d') |
||
1201 | $context['querystring_board_limits'] = ''; |
||
1202 | else |
||
1203 | $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
||
1204 | return; |
||
1205 | } |
||
1206 | |||
1207 | $request = $smcFunc['db_query']('substring', ' |
||
1208 | SELECT ' . $select_clause . ' |
||
1209 | FROM {db_prefix}topics AS t |
||
1210 | INNER JOIN {db_prefix}messages AS ms ON (ms.id_topic = t.id_topic AND ms.id_msg = t.id_first_msg) |
||
1211 | INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg) |
||
1212 | INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) |
||
1213 | LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member) |
||
1214 | LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' . (!empty($settings['avatars_on_indexes']) ? ' |
||
1215 | LEFT JOIN {db_prefix}attachments AS af ON (af.id_member = mems.id_member) |
||
1216 | LEFT JOIN {db_prefix}attachments AS al ON (al.id_member = meml.id_member)' : '') . ' |
||
1217 | LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member}) |
||
1218 | LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member}) |
||
1219 | WHERE t.id_topic IN ({array_int:topic_list}) |
||
1220 | ORDER BY {raw:sort}' . ($ascending ? '' : ' DESC') . ' |
||
1221 | LIMIT {int:limit}', |
||
1222 | array( |
||
1223 | 'current_member' => $user_info['id'], |
||
1224 | 'topic_list' => $topics, |
||
1225 | 'sort' => $_REQUEST['sort'], |
||
1226 | 'limit' => count($topics), |
||
1227 | ) |
||
1228 | ); |
||
1229 | } |
||
1230 | |||
1231 | $context['topics'] = array(); |
||
1232 | $topic_ids = array(); |
||
1233 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? $modSettings['recycle_board'] : 0; |
||
1234 | |||
1235 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1236 | { |
||
1237 | if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
||
1238 | continue; |
||
1239 | |||
1240 | $topic_ids[] = $row['id_topic']; |
||
1241 | |||
1242 | if (!empty($modSettings['preview_characters'])) |
||
1243 | { |
||
1244 | // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise. |
||
1245 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
||
1246 | if ($smcFunc['strlen']($row['first_body']) > 128) |
||
1247 | $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...'; |
||
1248 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
||
1249 | if ($smcFunc['strlen']($row['last_body']) > 128) |
||
1250 | $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...'; |
||
1251 | |||
1252 | // Censor the subject and message preview. |
||
1253 | censorText($row['first_subject']); |
||
1254 | censorText($row['first_body']); |
||
1255 | |||
1256 | // Don't censor them twice! |
||
1257 | if ($row['id_first_msg'] == $row['id_last_msg']) |
||
1258 | { |
||
1259 | $row['last_subject'] = $row['first_subject']; |
||
1260 | $row['last_body'] = $row['first_body']; |
||
1261 | } |
||
1262 | else |
||
1263 | { |
||
1264 | censorText($row['last_subject']); |
||
1265 | censorText($row['last_body']); |
||
1266 | } |
||
1267 | } |
||
1268 | else |
||
1269 | { |
||
1270 | $row['first_body'] = ''; |
||
1271 | $row['last_body'] = ''; |
||
1272 | censorText($row['first_subject']); |
||
1273 | |||
1274 | if ($row['id_first_msg'] == $row['id_last_msg']) |
||
1275 | $row['last_subject'] = $row['first_subject']; |
||
1276 | else |
||
1277 | censorText($row['last_subject']); |
||
1278 | } |
||
1279 | |||
1280 | // Decide how many pages the topic should have. |
||
1281 | $topic_length = $row['num_replies'] + 1; |
||
1282 | $messages_per_page = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
||
1283 | if ($topic_length > $messages_per_page) |
||
1284 | { |
||
1285 | $start = -1; |
||
1286 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false); |
||
1287 | |||
1288 | // If we can use all, show all. |
||
1289 | if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) |
||
1290 | $pages .= sprintf(strtr($settings['page_index']['page'], array('{URL}' => $scripturl . '?topic=' . $row['id_topic'] . '.0;all')), '', $txt['all']); |
||
1291 | } |
||
1292 | |||
1293 | else |
||
1294 | $pages = ''; |
||
1295 | |||
1296 | // We need to check the topic icons exist... you can never be too sure! |
||
1297 | if (!empty($modSettings['messageIconChecks_enable'])) |
||
1298 | { |
||
1299 | // First icon first... as you'd expect. |
||
1300 | if (!isset($context['icon_sources'][$row['first_icon']])) |
||
1301 | $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
||
1302 | // Last icon... last... duh. |
||
1303 | if (!isset($context['icon_sources'][$row['last_icon']])) |
||
1304 | $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
||
1305 | } |
||
1306 | else |
||
1307 | { |
||
1308 | if (!isset($context['icon_sources'][$row['first_icon']])) |
||
1309 | $context['icon_sources'][$row['first_icon']] = 'images_url'; |
||
1310 | if (!isset($context['icon_sources'][$row['last_icon']])) |
||
1311 | $context['icon_sources'][$row['last_icon']] = 'images_url'; |
||
1312 | } |
||
1313 | |||
1314 | // Force the recycling icon if appropriate |
||
1315 | if ($recycle_board == $row['id_board']) |
||
1316 | { |
||
1317 | $row['first_icon'] = 'recycled'; |
||
1318 | $row['last_icon'] = 'recycled'; |
||
1319 | } |
||
1320 | |||
1321 | // Reference the main color class. |
||
1322 | $colorClass = 'windowbg'; |
||
1323 | |||
1324 | // Sticky topics should get a different color, too. |
||
1325 | if ($row['is_sticky']) |
||
1326 | $colorClass .= ' sticky'; |
||
1327 | |||
1328 | // Locked topics get special treatment as well. |
||
1329 | if ($row['locked']) |
||
1330 | $colorClass .= ' locked'; |
||
1331 | |||
1332 | // And build the array. |
||
1333 | $context['topics'][$row['id_topic']] = array( |
||
1334 | 'id' => $row['id_topic'], |
||
1335 | 'first_post' => array( |
||
1336 | 'id' => $row['id_first_msg'], |
||
1337 | 'member' => array( |
||
1338 | 'name' => $row['first_poster_name'], |
||
1339 | 'id' => $row['id_first_member'], |
||
1340 | 'href' => $scripturl . '?action=profile;u=' . $row['id_first_member'], |
||
1341 | 'link' => !empty($row['id_first_member']) ? '<a class="preview" href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '" title="' . sprintf($txt['view_profile_of_username'], $row['first_poster_name']) . '">' . $row['first_poster_name'] . '</a>' : $row['first_poster_name'] |
||
1342 | ), |
||
1343 | 'time' => timeformat($row['first_poster_time']), |
||
1344 | 'timestamp' => $row['first_poster_time'], |
||
1345 | 'subject' => $row['first_subject'], |
||
1346 | 'preview' => $row['first_body'], |
||
1347 | 'icon' => $row['first_icon'], |
||
1348 | 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', |
||
1349 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen', |
||
1350 | 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['first_subject'] . '</a>' |
||
1351 | ), |
||
1352 | 'last_post' => array( |
||
1353 | 'id' => $row['id_last_msg'], |
||
1354 | 'member' => array( |
||
1355 | 'name' => $row['last_poster_name'], |
||
1356 | 'id' => $row['id_last_member'], |
||
1357 | 'href' => $scripturl . '?action=profile;u=' . $row['id_last_member'], |
||
1358 | 'link' => !empty($row['id_last_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_last_member'] . '">' . $row['last_poster_name'] . '</a>' : $row['last_poster_name'] |
||
1359 | ), |
||
1360 | 'time' => timeformat($row['last_poster_time']), |
||
1361 | 'timestamp' => $row['last_poster_time'], |
||
1362 | 'subject' => $row['last_subject'], |
||
1363 | 'preview' => $row['last_body'], |
||
1364 | 'icon' => $row['last_icon'], |
||
1365 | 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.png', |
||
1366 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'], |
||
1367 | 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '" rel="nofollow">' . $row['last_subject'] . '</a>' |
||
1368 | ), |
||
1369 | 'new_from' => $row['new_from'], |
||
1370 | 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new', |
||
1371 | 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'), |
||
1372 | 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '" rel="nofollow">' . $row['first_subject'] . '</a>', |
||
1373 | 'is_sticky' => !empty($row['is_sticky']), |
||
1374 | 'is_locked' => !empty($row['locked']), |
||
1375 | 'css_class' => $colorClass, |
||
1376 | 'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0, |
||
1377 | 'is_posted_in' => false, |
||
1378 | 'icon' => $row['first_icon'], |
||
1379 | 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', |
||
1380 | 'subject' => $row['first_subject'], |
||
1381 | 'pages' => $pages, |
||
1382 | 'replies' => comma_format($row['num_replies']), |
||
1383 | 'views' => comma_format($row['num_views']), |
||
1384 | 'board' => array( |
||
1385 | 'id' => $row['id_board'], |
||
1386 | 'name' => $row['bname'], |
||
1387 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
||
1388 | 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>' |
||
1389 | ) |
||
1390 | ); |
||
1391 | if (!empty($settings['avatars_on_indexes'])) |
||
1392 | { |
||
1393 | $context['topics'][$row['id_topic']]['last_post']['member']['avatar'] = set_avatar_data(array( |
||
1394 | 'avatar' => $row['avatar'], |
||
1395 | 'email' => $row['email_address'], |
||
1396 | 'filename' => $row['last_poster_filename'], |
||
1397 | )); |
||
1398 | |||
1399 | $context['topics'][$row['id_topic']]['first_post']['member']['avatar'] = set_avatar_data(array( |
||
1400 | 'avatar' => $row['first_poster_avatar'], |
||
1401 | 'email' => $row['first_poster_email'], |
||
1402 | 'filename' => $row['first_poster_filename'], |
||
1403 | )); |
||
1404 | } |
||
1405 | |||
1406 | $context['topics'][$row['id_topic']]['first_post']['started_by'] = sprintf($txt['topic_started_by'], $context['topics'][$row['id_topic']]['first_post']['member']['link'], $context['topics'][$row['id_topic']]['board']['link']); |
||
1407 | } |
||
1408 | $smcFunc['db_free_result']($request); |
||
1409 | |||
1410 | if ($is_topics && !empty($modSettings['enableParticipation']) && !empty($topic_ids)) |
||
1411 | { |
||
1412 | $result = $smcFunc['db_query']('', ' |
||
1413 | SELECT id_topic |
||
1414 | FROM {db_prefix}messages |
||
1415 | WHERE id_topic IN ({array_int:topic_list}) |
||
1416 | AND id_member = {int:current_member} |
||
1417 | GROUP BY id_topic |
||
1418 | LIMIT {int:limit}', |
||
1419 | array( |
||
1420 | 'current_member' => $user_info['id'], |
||
1421 | 'topic_list' => $topic_ids, |
||
1422 | 'limit' => count($topic_ids), |
||
1423 | ) |
||
1424 | ); |
||
1425 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
1426 | { |
||
1427 | if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) |
||
1428 | $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
||
1429 | } |
||
1430 | $smcFunc['db_free_result']($result); |
||
1431 | } |
||
1432 | |||
1433 | $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']); |
||
1434 | $context['topics_to_mark'] = implode('-', $topic_ids); |
||
1435 | |||
1436 | // Build the recent button array. |
||
1437 | if ($is_topics) |
||
1438 | { |
||
1439 | $context['recent_buttons'] = array( |
||
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']), |
||
1441 | ); |
||
1442 | |||
1443 | if ($context['showCheckboxes']) |
||
1444 | $context['recent_buttons']['markselectread'] = array( |
||
1445 | 'text' => 'quick_mod_markread', |
||
1446 | 'image' => 'markselectedread.png', |
||
1447 | 'url' => 'javascript:document.quickModForm.submit();', |
||
1448 | ); |
||
1449 | |||
1450 | if (!empty($context['topics']) && !$context['showing_all_topics']) |
||
1451 | $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true); |
||
1452 | } |
||
1453 | elseif (!$is_topics && isset($context['topics_to_mark'])) |
||
1454 | { |
||
1455 | $context['recent_buttons'] = array( |
||
1456 | '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']), |
||
1457 | ); |
||
1458 | |||
1459 | if ($context['showCheckboxes']) |
||
1460 | $context['recent_buttons']['markselectread'] = array( |
||
1461 | 'text' => 'quick_mod_markread', |
||
1462 | 'image' => 'markselectedread.png', |
||
1463 | 'url' => 'javascript:document.quickModForm.submit();', |
||
1464 | ); |
||
1465 | } |
||
1466 | |||
1467 | // Allow mods to add additional buttons here |
||
1468 | call_integration_hook('integrate_recent_buttons'); |
||
1469 | |||
1470 | $context['no_topic_listing'] = empty($context['topics']); |
||
1471 | |||
1472 | // Allow helpdesks and bug trackers and what not to add their own unread data (just add a template_layer to show custom stuff in the template!) |
||
1473 | call_integration_hook('integrate_unread_list'); |
||
1474 | } |
||
1476 | ?> |