示例#1
0
function light_draw_thread_list($mode = ALL_DISCUSSIONS, $folder = false, $page = 1)
{
    $webtag = get_webtag();
    forum_check_webtag_available($webtag);
    $error_msg_array = array();
    $available_views = thread_list_available_views();
    $visible_threads_array = array();
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return;
    }
    light_thread_list_draw_top($mode, $folder);
    switch ($mode) {
        case UNREAD_DISCUSSIONS:
            list($thread_info, $folder_order, $thread_count) = threads_get_unread($_SESSION['UID'], $folder, $page);
            break;
        case UNREAD_DISCUSSIONS_TO_ME:
            list($thread_info, $folder_order, $thread_count) = threads_get_unread_to_me($_SESSION['UID'], $folder, $page);
            break;
        case TODAYS_DISCUSSIONS:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_days($_SESSION['UID'], $folder, $page, 1);
            break;
        case UNREAD_TODAY:
            list($thread_info, $folder_order, $thread_count) = threads_get_unread_by_days($_SESSION['UID'], $folder, $page);
            break;
        case TWO_DAYS_BACK:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_days($_SESSION['UID'], $folder, $page, 2);
            break;
        case SEVEN_DAYS_BACK:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_days($_SESSION['UID'], $folder, $page, 7);
            break;
        case HIGH_INTEREST:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_interest($_SESSION['UID'], $folder, $page, THREAD_INTERESTED);
            break;
        case UNREAD_HIGH_INTEREST:
            list($thread_info, $folder_order, $thread_count) = threads_get_unread_by_interest($_SESSION['UID'], $folder, $page, THREAD_INTERESTED);
            break;
        case RECENTLY_SEEN:
            list($thread_info, $folder_order, $thread_count) = threads_get_recently_viewed($_SESSION['UID'], $folder, $page);
            break;
        case IGNORED_THREADS:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_interest($_SESSION['UID'], $folder, $page, THREAD_IGNORED);
            break;
        case BY_IGNORED_USERS:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_relationship($_SESSION['UID'], $folder, $page, USER_IGNORED_COMPLETELY);
            break;
        case SUBSCRIBED_TO:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_interest($_SESSION['UID'], $folder, $page, THREAD_SUBSCRIBED);
            break;
        case STARTED_BY_FRIEND:
            list($thread_info, $folder_order, $thread_count) = threads_get_by_relationship($_SESSION['UID'], $folder, $page, USER_FRIEND);
            break;
        case UNREAD_STARTED_BY_FRIEND:
            list($thread_info, $folder_order, $thread_count) = threads_get_unread_by_relationship($_SESSION['UID'], $folder, $page, USER_FRIEND);
            break;
        case STARTED_BY_ME:
            list($thread_info, $folder_order, $thread_count) = threads_get_started_by_me($_SESSION['UID'], $folder, $page);
            break;
        case POLL_THREADS:
            list($thread_info, $folder_order, $thread_count) = threads_get_polls($_SESSION['UID'], $folder, $page);
            break;
        case STICKY_THREADS:
            list($thread_info, $folder_order, $thread_count) = threads_get_sticky($_SESSION['UID'], $folder, $page);
            break;
        case MOST_UNREAD_POSTS:
            list($thread_info, $folder_order, $thread_count) = threads_get_longest_unread($_SESSION['UID'], $folder, $page);
            break;
        case DELETED_THREADS:
            list($thread_info, $folder_order, $thread_count) = threads_get_deleted($_SESSION['UID'], $folder, $page);
            break;
        default:
            list($thread_info, $folder_order, $thread_count) = threads_get_all($_SESSION['UID'], $folder, $page);
            break;
    }
    // Now, the actual bit that displays the threads...
    // Get folder FIDs and titles
    if (!($folder_info = threads_get_folders())) {
        light_html_display_error_msg(gettext("There are no folders available."));
        return;
    }
    // Get total number of messages for each folder
    $folder_msgs = threads_get_folder_msgs();
    // Check that the folder order is a valid array.
    if (!is_array($folder_order)) {
        $folder_order = array();
    }
    // Check the folder display order.
    if (isset($_SESSION['THREADS_BY_FOLDER']) && $_SESSION['THREADS_BY_FOLDER'] == 'Y') {
        $folder_order = array_keys($folder_info);
    }
    // Check for a message to display and re-order the thread list.
    if (isset($_REQUEST['msg']) && validate_msg($_REQUEST['msg'])) {
        list($selected_tid) = explode('.', $_REQUEST['msg']);
        if (($thread = thread_get($selected_tid)) !== false) {
            if (!isset($thread['RELATIONSHIP'])) {
                $thread['RELATIONSHIP'] = 0;
            }
            // Check the folder display order / user is a guest.
            if (!isset($_SESSION['THREADS_BY_FOLDER']) || $_SESSION['THREADS_BY_FOLDER'] != 'Y' || !session::logged_in()) {
                // Remove the folder from the list of folders.
                if (in_array($thread['FID'], $folder_order)) {
                    array_splice($folder_order, array_search($thread['FID'], $folder_order), 1);
                }
                // Re-add it at the top of the list.
                array_unshift($folder_order, $thread['FID']);
            }
            // Check $thread_info is an array.
            if (!is_array($thread_info)) {
                $thread_info = array();
            }
            // Check to see if the thread is already in the list.
            // If it is remove it, otherwise take the last thread
            // off the list so we always only have 50 threads on display.
            if (isset($thread_info[$selected_tid])) {
                unset($thread_info[$selected_tid]);
            } else {
                $thread_info = array_slice($thread_info, 0, 50, true);
            }
            // Add the requested thread to the top of the list of threads.
            array_unshift($thread_info, $thread);
        }
    }
    // Check for a specified folder and move it to the top of the thread list.
    if (isset($folder) && is_numeric($folder)) {
        if (in_array($folder, $folder_order)) {
            array_splice($folder_order, array_search($folder, $folder_order), 1);
        }
        array_unshift($folder_order, $folder);
    }
    if ($_SESSION['UID'] > 0) {
        // Array to hold our ignored folders in.
        $ignored_folders = array();
        // Loop through the list of folders and check their status.
        // If they're ignored and not already set to be on display
        // they need to be added to $ignored_folders so that they
        // appear at the bottom of the thread list.
        foreach ($folder_info as $fid => $folder_data) {
            if (!in_array($fid, $folder_order) && !in_array($fid, $ignored_folders)) {
                if ($folder_data['INTEREST'] != FOLDER_IGNORED || isset($folder) && $folder == $fid) {
                    array_push($folder_order, $fid);
                } else {
                    array_push($ignored_folders, $fid);
                }
            }
        }
        // Append ignored folders onto the end of the folder list.
        // This will make them appear at the bottom of the thread list.
        $folder_order = array_merge($folder_order, $ignored_folders);
    } else {
        foreach ($folder_info as $fid => $folder_data) {
            if (!in_array($fid, $folder_order)) {
                $folder_order[] = $fid;
            }
        }
    }
    // If no threads are returned, say something to that effect
    if (isset($_REQUEST['mark_read_success'])) {
        light_html_display_success_msg(gettext("Successfully marked selected threads as read"));
    } else {
        if (!is_array($thread_info)) {
            if (is_numeric($folder) && ($folder_title = folder_get_title($folder))) {
                $all_discussions_link = sprintf("<a href=\"lthread_list.php?webtag={$webtag}&amp;folder={$folder}&amp;mode=0\">%s</a>", gettext("click here"));
                light_html_display_warning_msg(sprintf(gettext("No &quot;%s&quot; in &quot;%s&quot; folder. Please select another folder, or %s for all threads."), $available_views[$mode], $folder_title, $all_discussions_link));
            } else {
                $all_discussions_link = sprintf("<a href=\"lthread_list.php?webtag={$webtag}&amp;mode=0\">%s</a>", gettext("click here"));
                light_html_display_warning_msg(sprintf(gettext("No &quot;%s&quot; available. Please %s for all threads."), $available_views[$mode], $all_discussions_link));
            }
        } else {
            if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
                light_html_display_error_array($error_msg_array);
            } else {
                if (is_numeric($folder) && ($folder_title = folder_get_title($folder))) {
                    $all_folders_link = sprintf("<a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}\">%s</a>", gettext("click here"));
                    light_html_display_warning_msg(sprintf(gettext("Viewing &quot;%s&quot; in &quot;%s&quot; only. To view threads in all folders %s."), $available_views[$mode], $folder_title, $all_folders_link));
                }
            }
        }
    }
    if ($page > 1 && !is_numeric($folder)) {
        echo "<div class=\"thread_pagination\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;page=", $page - 1, "\">", gettext("Previous 50 threads"), "</a></div>\n";
    }
    // Unread cut-off
    $thread_unread_cutoff = threads_get_unread_cutoff();
    // Iterate through the information we've just got and display it in the right order
    foreach ($folder_order as $folder_number) {
        if (isset($folder_info[$folder_number]) && is_array($folder_info[$folder_number])) {
            echo "<div class=\"folder\">\n";
            echo "  <h3>", html_style_image('folder'), "<a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder_number}\">", word_filter_add_ob_tags($folder_info[$folder_number]['TITLE'], true), "</a></h3>";
            echo "  <div class=\"folder_inner\">\n";
            if (!session::logged_in() || $folder_info[$folder_number]['INTEREST'] > FOLDER_IGNORED || $mode == UNREAD_DISCUSSIONS_TO_ME || isset($folder) && $folder == $folder_number) {
                if (is_array($thread_info)) {
                    echo "  <div class=\"folder_info\">";
                    if (isset($folder_msgs[$folder_number])) {
                        echo $folder_msgs[$folder_number];
                    } else {
                        echo "0";
                    }
                    echo " ", gettext("threads"), "";
                    if (is_null($folder_info[$folder_number]['STATUS']) || $folder_info[$folder_number]['STATUS'] & USER_PERM_THREAD_CREATE) {
                        if ($folder_info[$folder_number]['ALLOWED_TYPES'] & FOLDER_ALLOW_NORMAL_THREAD) {
                            echo "<span><a href=\"lpost.php?webtag={$webtag}&amp;fid={$folder_number}\">", gettext("Post New"), "</a></span>";
                        }
                    }
                    echo "  </div>\n";
                    if ($page > 1 && is_numeric($folder) && $folder_number == $folder) {
                        echo "<div class=\"folder_pagination\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder}&amp;page=", $page - 1, "\">", gettext("Previous 50 threads"), "</a></div>\n";
                    }
                    $folder_list_start = false;
                    $folder_list_end = false;
                    foreach ($thread_info as $thread) {
                        if (!in_array($thread['TID'], $visible_threads_array)) {
                            $visible_threads_array[] = $thread['TID'];
                        }
                        if ($thread['FID'] == $folder_number) {
                            if ($folder_list_start === false) {
                                echo "<ul>\n";
                                $folder_list_start = true;
                            }
                            echo "<li>";
                            if (!session::logged_in() || ($thread['LAST_READ'] == 0 || $thread['LAST_READ'] < $thread['LENGTH']) && $thread['MODIFIED'] > $thread_unread_cutoff) {
                                $new_posts = $thread['LENGTH'] - $thread['LAST_READ'];
                                if ($new_posts == $thread['LENGTH']) {
                                    $number = "[{$thread['LENGTH']}&nbsp;new]";
                                } else {
                                    $number = "[{$new_posts}&nbsp;new&nbsp;of&nbsp;{$thread['LENGTH']}]";
                                }
                                $latest_post = $thread['LAST_READ'] + 1;
                            } else {
                                $number = "[{$thread['LENGTH']}]";
                                $latest_post = 1;
                            }
                            // work out how long ago the thread was posted and format the time to display
                            $thread_time = format_date_time($thread['MODIFIED']);
                            echo "<span class=\"thread_icon\">", html_style_image('bullet'), "</span>";
                            echo "<span class=\"thread_title\">";
                            echo "<a href=\"lmessages.php?webtag={$webtag}&amp;msg={$thread['TID']}.{$latest_post}\" ";
                            echo "title=\"", sprintf(gettext("Thread #%s Started by %s. Viewed %s"), $thread['TID'], word_filter_add_ob_tags(format_user_name($thread['LOGON'], $thread['NICKNAME']), true), $thread['VIEWCOUNT'] == 1 ? gettext("1 time") : sprintf(gettext("%d times"), $thread['VIEWCOUNT'])), "\">";
                            echo word_filter_add_ob_tags($thread['TITLE'], true), "</a> ";
                            echo "<span class=\"thread_detail\">";
                            if (isset($thread['INTEREST']) && $thread['INTEREST'] == THREAD_INTERESTED) {
                                echo html_style_image('high_interest', gettext("High Interest"));
                            }
                            if (isset($thread['INTEREST']) && $thread['INTEREST'] == THREAD_SUBSCRIBED) {
                                echo html_style_image('subscribe', gettext("Subscribed"));
                            }
                            if (isset($thread['POLL_FLAG']) && $thread['POLL_FLAG'] == 'Y') {
                                echo html_style_image('poll', gettext("Poll"));
                            }
                            if (isset($thread['STICKY']) && $thread['STICKY'] == 'Y') {
                                echo html_style_image('sticky', gettext("Sticky"));
                            }
                            if (isset($thread['RELATIONSHIP']) && $thread['RELATIONSHIP'] & USER_FRIEND) {
                                echo html_style_image('friend', gettext("Friend"));
                            }
                            if (isset($thread['TRACK_TYPE']) && $thread['TRACK_TYPE'] == THREAD_TYPE_SPLIT) {
                                echo html_style_image('split_thread', gettext("Thread has been split"));
                            }
                            if (isset($thread['TRACK_TYPE']) && $thread['TRACK_TYPE'] == THREAD_TYPE_MERGE) {
                                echo html_style_image('merge_thread', gettext("Thread has been merged"));
                            }
                            if (isset($thread['ATTACHMENT_COUNT']) && $thread['ATTACHMENT_COUNT'] > 0) {
                                echo html_style_image('attach', gettext("Attachment"));
                            }
                            echo "<span class=\"thread_length\">{$number}</span>";
                            echo "</span>";
                            echo "</span>";
                            echo "<span class=\"thread_time\">{$thread_time}</span>";
                            echo "</li>\n";
                        }
                    }
                    if ($folder_list_end === false && $folder_list_start === true) {
                        echo "</ul>\n";
                    }
                    if (is_numeric($folder) && $folder_number == $folder && $thread_count >= 50) {
                        echo "<div class=\"folder_pagination\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder}&amp;page=", $page + 1, "\">", gettext("Next 50 threads"), "</a></div>\n";
                    }
                } else {
                    if ($folder_info[$folder_number]['INTEREST'] != FOLDER_IGNORED) {
                        echo "<div class=\"folder_info\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder_number}\">";
                        if (isset($folder_msgs[$folder_number])) {
                            echo $folder_msgs[$folder_number];
                        } else {
                            echo "0";
                        }
                        echo " ", gettext("threads"), "</a>";
                        if ($folder_info[$folder_number]['ALLOWED_TYPES'] & FOLDER_ALLOW_NORMAL_THREAD) {
                            echo "<span><a href=\"lpost.php?webtag={$webtag}&amp;fid={$folder_number}\">", gettext("Post New"), "</a></span>";
                        }
                        echo "</div>\n";
                    }
                }
            }
            echo "  </div>\n";
            echo "</div>\n";
            if (is_array($thread_info)) {
                reset($thread_info);
            }
        }
    }
    if (!is_numeric($folder) && $thread_count >= 50) {
        echo "<div class=\"thread_pagination\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;page=", $page + 1, "\">", gettext("Next 50 threads"), "</a></div>\n";
    }
    if (session::logged_in()) {
        echo "<div id=\"thread_mark_read\">\n";
        echo "<h3>", gettext("Mark as Read"), "</h3>\n";
        echo "<form accept-charset=\"utf-8\" name=\"f_mark\" method=\"post\" action=\"lthread_list.php\">\n";
        echo "  ", form_csrf_token_field(), "\n";
        echo form_input_hidden("webtag", htmlentities_array($webtag)), "\n";
        echo form_input_hidden("mode", htmlentities_array($mode)), "\n";
        echo form_input_hidden("page", htmlentities_array($page)), "\n";
        echo form_input_hidden("mark_read_confirm", 'N'), "\n";
        $labels = array(gettext("All Discussions"), gettext("Next 50 discussions"));
        $selected_option = THREAD_MARK_READ_ALL;
        if (sizeof($visible_threads_array) > 0) {
            $labels[] = gettext("Visible discussions");
            $selected_option = THREAD_MARK_READ_VISIBLE;
            $visible_threads = implode(',', array_filter($visible_threads_array, 'is_numeric'));
            echo form_input_hidden("mark_read_threads", htmlentities_array($visible_threads)), "\n";
        }
        if (isset($_GET['folder']) && is_numeric($_GET['folder'])) {
            echo form_input_hidden('folder', htmlentities_array($folder)), "\n";
            $labels[] = gettext("Selected folder");
            $selected_option = THREAD_MARK_READ_FOLDER;
        }
        echo "<ul>\n";
        echo "<li>", light_form_dropdown_array("mark_read_type", $labels, $selected_option), "</li>\n";
        echo "<li class=\"right_col\">", light_form_submit("mark_read_submit", gettext("Go!")), "</li>\n";
        echo "</ul>\n";
        echo "</form>\n";
        echo "</div>\n";
    }
}
        list($thread_info, $folder_order, $thread_count) = threads_get_unread_by_relationship($_SESSION['UID'], $folder, $page, USER_FRIEND);
        break;
    case STARTED_BY_ME:
        list($thread_info, $folder_order, $thread_count) = threads_get_started_by_me($_SESSION['UID'], $folder, $page);
        break;
    case POLL_THREADS:
        list($thread_info, $folder_order, $thread_count) = threads_get_polls($_SESSION['UID'], $folder, $page);
        break;
    case STICKY_THREADS:
        list($thread_info, $folder_order, $thread_count) = threads_get_sticky($_SESSION['UID'], $folder, $page);
        break;
    case MOST_UNREAD_POSTS:
        list($thread_info, $folder_order, $thread_count) = threads_get_longest_unread($_SESSION['UID'], $folder, $page);
        break;
    case DELETED_THREADS:
        list($thread_info, $folder_order, $thread_count) = threads_get_deleted($_SESSION['UID'], $folder, $page);
        break;
    default:
        list($thread_info, $folder_order, $thread_count) = threads_get_all($_SESSION['UID'], $folder, $page);
        break;
}
// Now, the actual bit that displays the threads...
// Get folder FIDs and titles
if (!($folder_info = threads_get_folders())) {
    html_draw_error(gettext("There are no folders available."));
}
// Get total number of messages for each folder
$folder_msgs = threads_get_folder_msgs();
// Check that the folder order is a valid array.
if (!is_array($folder_order)) {
    $folder_order = array();
示例#3
0
        list($thread_info, $folder_order, $thread_count) = threads_get_unread_by_relationship($uid, $folder, $page, USER_FRIEND);
        break;
    case STARTED_BY_ME:
        list($thread_info, $folder_order, $thread_count) = threads_get_started_by_me($uid, $folder, $page);
        break;
    case POLL_THREADS:
        list($thread_info, $folder_order, $thread_count) = threads_get_polls($uid, $folder, $page);
        break;
    case STICKY_THREADS:
        list($thread_info, $folder_order, $thread_count) = threads_get_sticky($uid, $folder, $page);
        break;
    case MOST_UNREAD_POSTS:
        list($thread_info, $folder_order, $thread_count) = threads_get_longest_unread($uid, $folder, $page);
        break;
    case DELETED_THREADS:
        list($thread_info, $folder_order, $thread_count) = threads_get_deleted($uid, $folder, $page);
        break;
    default:
        list($thread_info, $folder_order, $thread_count) = threads_get_all($uid, $folder, $page);
        break;
}
// Now, the actual bit that displays the threads...
// Get folder FIDs and titles
if (!($folder_info = threads_get_folders())) {
    html_draw_error(gettext("There are no folders available."));
}
// Get total number of messages for each folder
$folder_msgs = threads_get_folder_msgs();
// Check that the folder order is a valid array.
if (!is_array($folder_order)) {
    $folder_order = array();
示例#4
0
function light_draw_thread_list($mode = ALL_DISCUSSIONS, $folder = false, $page = 1)
{
    $webtag = get_webtag();
    $error_msg_array = array();
    $available_views = thread_list_available_views();
    $visible_threads_array = array();
    if (($uid = session::get_value('UID')) === false) {
        return;
    }
    echo "<div id=\"thread_view\">\n";
    echo "<form accept-charset=\"utf-8\" name=\"f_mode\" method=\"get\" action=\"lthread_list.php\">\n";
    echo form_input_hidden("webtag", htmlentities_array($webtag));
    if (is_numeric($folder) && in_array($folder, folder_get_available_array())) {
        echo form_input_hidden('folder', htmlentities_array($folder)), "\n";
    }
    echo "<ul>\n";
    echo "<li>", light_threads_draw_discussions_dropdown($mode), "</li>\n";
    echo "<li class=\"right_col\">", light_form_submit("go", gettext("Go!")), "</li>\n";
    echo "</ul>\n";
    echo "</form>\n";
    echo "</div>\n";
    // Get the right threads for whichever mode is selected
    switch ($mode) {
        case UNREAD_DISCUSSIONS:
            list($thread_info, $folder_order) = threads_get_unread($uid, $folder, $page);
            break;
        case UNREAD_DISCUSSIONS_TO_ME:
            list($thread_info, $folder_order) = threads_get_unread_to_me($uid, $folder, $page);
            break;
        case TODAYS_DISCUSSIONS:
            list($thread_info, $folder_order) = threads_get_by_days($uid, $folder, $page, 1);
            break;
        case UNREAD_TODAY:
            list($thread_info, $folder_order) = threads_get_unread_by_days($uid, $folder, $page);
            break;
        case TWO_DAYS_BACK:
            list($thread_info, $folder_order) = threads_get_by_days($uid, $folder, $page, 2);
            break;
        case SEVEN_DAYS_BACK:
            list($thread_info, $folder_order) = threads_get_by_days($uid, $folder, $page, 7);
            break;
        case HIGH_INTEREST:
            list($thread_info, $folder_order) = threads_get_by_interest($uid, $folder, $page, 1);
            break;
        case UNREAD_HIGH_INTEREST:
            list($thread_info, $folder_order) = threads_get_unread_by_interest($uid, $folder, $page, 1);
            break;
        case RECENTLY_SEEN:
            list($thread_info, $folder_order) = threads_get_recently_viewed($uid, $folder, $page);
            break;
        case IGNORED_THREADS:
            list($thread_info, $folder_order) = threads_get_by_interest($uid, $folder, $page, -1);
            break;
        case BY_IGNORED_USERS:
            list($thread_info, $folder_order) = threads_get_by_relationship($uid, $folder, $page, USER_IGNORED_COMPLETELY);
            break;
        case SUBSCRIBED_TO:
            list($thread_info, $folder_order) = threads_get_by_interest($uid, $folder, $page, 2);
            break;
        case STARTED_BY_FRIEND:
            list($thread_info, $folder_order) = threads_get_by_relationship($uid, $folder, $page, USER_FRIEND);
            break;
        case UNREAD_STARTED_BY_FRIEND:
            list($thread_info, $folder_order) = threads_get_unread_by_relationship($uid, $folder, $page, USER_FRIEND);
            break;
        case STARTED_BY_ME:
            list($thread_info, $folder_order) = threads_get_started_by_me($uid, $folder, $page);
            break;
        case POLL_THREADS:
            list($thread_info, $folder_order) = threads_get_polls($uid, $folder, $page);
            break;
        case STICKY_THREADS:
            list($thread_info, $folder_order) = threads_get_sticky($uid, $folder, $page);
            break;
        case MOST_UNREAD_POSTS:
            list($thread_info, $folder_order) = threads_get_longest_unread($uid, $folder, $page);
            break;
        case DELETED_THREADS:
            list($thread_info, $folder_order) = threads_get_deleted($uid, $folder, $page);
            break;
        default:
            list($thread_info, $folder_order) = threads_get_all($uid, $folder, $page);
            break;
    }
    // Now, the actual bit that displays the threads...
    // Get folder FIDs and titles
    if (!($folder_info = threads_get_folders())) {
        light_html_display_error_msg(gettext("There are no folders available."));
        return;
    }
    // Get total number of messages for each folder
    $folder_msgs = threads_get_folder_msgs();
    // Check that the folder order is a valid array.
    // While we're here we can also check to see how the user
    // has decided to display the thread list.
    if (!is_array($folder_order) || session::get_value('THREADS_BY_FOLDER') == 'Y') {
        $folder_order = array_keys($folder_info);
    }
    // Sort the folders and threads correctly as per the URL query for the TID
    if (isset($_GET['msg']) && validate_msg($_GET['msg'])) {
        list($tid) = explode('.', $_GET['msg']);
        if ($thread = thread_get($tid)) {
            if (!isset($thread['RELATIONSHIP'])) {
                $thread['RELATIONSHIP'] = 0;
            }
            if (session::get_value('THREADS_BY_FOLDER') == 'N' || !session::logged_in()) {
                if (in_array($thread['FID'], $folder_order)) {
                    array_splice($folder_order, array_search($thread['FID'], $folder_order), 1);
                }
                array_unshift($folder_order, $thread['FID']);
            }
            if (!is_array($thread_info)) {
                $thread_info = array();
            }
            if (isset($thread_info[$tid])) {
                unset($thread_info[$tid]);
            } else {
                array_pop($thread_info);
            }
            array_unshift($thread_info, $thread);
        }
    }
    // Work out if any folders have no messages and add them.
    // Seperate them by INTEREST level
    if (session::get_value('UID') > 0) {
        if (isset($_GET['msg']) && validate_msg($_GET['msg'])) {
            list($tid) = explode('.', $_GET['msg']);
            if ($thread = thread_get($tid)) {
                $selected_folder = $thread['FID'];
            }
        } else {
            if (isset($_GET['folder'])) {
                $selected_folder = $_GET['folder'];
            } else {
                $selected_folder = 0;
            }
        }
        $ignored_folders = array();
        while (list($fid, $folder_data) = each($folder_info)) {
            if ($folder_data['INTEREST'] == FOLDER_NOINTEREST || isset($selected_folder) && $selected_folder == $fid) {
                if (!in_array($fid, $folder_order) && !in_array($fid, $ignored_folders)) {
                    $folder_order[] = $fid;
                }
            } else {
                if (!in_array($fid, $folder_order) && !in_array($fid, $ignored_folders)) {
                    $ignored_folders[] = $fid;
                }
            }
        }
        // Append ignored folders onto the end of the folder list.
        // This will make them appear at the bottom of the thread list.
        $folder_order = array_merge($folder_order, $ignored_folders);
    } else {
        while (list($fid, $folder_data) = each($folder_info)) {
            if (!in_array($fid, $folder_order)) {
                $folder_order[] = $fid;
            }
        }
    }
    // If no threads are returned, say something to that effect
    if (isset($_REQUEST['mark_read_success'])) {
        light_html_display_success_msg(gettext("Successfully marked selected threads as read"), '100%', 'left');
    } else {
        if (!is_array($thread_info)) {
            if (is_numeric($folder) && ($folder_title = folder_get_title($folder))) {
                $all_discussions_link = sprintf("<a href=\"lthread_list.php?webtag={$webtag}&amp;folder={$folder}&amp;mode=0\">%s</a>", gettext("click here"));
                light_html_display_warning_msg(sprintf(gettext("No &quot;%s&quot; in &quot;%s&quot; folder. Please select another folder, or %s for all threads."), $available_views[$mode], $folder_title, $all_discussions_link), '100%', 'left');
            } else {
                $all_discussions_link = sprintf("<a href=\"lthread_list.php?webtag={$webtag}&amp;mode=0\">%s</a>", gettext("click here"));
                light_html_display_warning_msg(sprintf(gettext("No &quot;%s&quot; available. Please %s for all threads."), $available_views[$mode], $all_discussions_link), '100%', 'left');
            }
        } else {
            if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
                light_html_display_error_array($error_msg_array, '100%', 'left');
            } else {
                if (is_numeric($folder) && ($folder_title = folder_get_title($folder))) {
                    $all_folders_link = sprintf("<a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}\">%s</a>", gettext("click here"));
                    light_html_display_warning_msg(sprintf(gettext("Viewing &quot;%s&quot; in &quot;%s&quot; only. To view threads in all folders %s."), $available_views[$mode], $folder_title, $all_folders_link), '100%', 'left');
                }
            }
        }
    }
    if ($page > 1 && !is_numeric($folder)) {
        echo "<div class=\"thread_pagination\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;page=", $page - 1, "\">", gettext("Previous 50 threads"), "</a></div>\n";
    }
    // Iterate through the information we've just got and display it in the right order
    foreach ($folder_order as $folder_number) {
        if (isset($folder_info[$folder_number]) && is_array($folder_info[$folder_number])) {
            echo "<div class=\"folder\">\n";
            echo "  <h3><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder_number}\">", word_filter_add_ob_tags($folder_info[$folder_number]['TITLE'], true), "</a></h3>";
            echo "  <div class=\"folder_inner\">\n";
            if (!session::logged_in() || $folder_info[$folder_number]['INTEREST'] > FOLDER_IGNORED || $mode == UNREAD_DISCUSSIONS_TO_ME || isset($selected_folder) && $selected_folder == $folder_number) {
                if (is_array($thread_info)) {
                    echo "  <div class=\"folder_info\">";
                    if (isset($folder_msgs[$folder_number])) {
                        echo $folder_msgs[$folder_number];
                    } else {
                        echo "0";
                    }
                    echo " ", gettext("threads"), "";
                    if (is_null($folder_info[$folder_number]['STATUS']) || $folder_info[$folder_number]['STATUS'] & USER_PERM_THREAD_CREATE) {
                        if ($folder_info[$folder_number]['ALLOWED_TYPES'] & FOLDER_ALLOW_NORMAL_THREAD) {
                            echo "<span><a href=\"lpost.php?webtag={$webtag}&amp;fid={$folder_number}\">", gettext("Post New"), "</a></span>";
                        }
                    }
                    echo "  </div>\n";
                    if ($page > 1 && is_numeric($folder) && $folder_number == $folder) {
                        echo "<div class=\"folder_navigation\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder}&amp;page=", $page - 1, "\">", gettext("Previous 50 threads"), "</a></div>\n";
                    }
                    $folder_list_start = false;
                    $folder_list_end = false;
                    foreach ($thread_info as $thread) {
                        if (!in_array($thread['TID'], $visible_threads_array)) {
                            $visible_threads_array[] = $thread['TID'];
                        }
                        if ($thread['FID'] == $folder_number) {
                            if ($folder_list_start === false) {
                                echo "<ul>\n";
                                $folder_list_start = true;
                            }
                            echo "<li>\n";
                            if ($thread['LAST_READ'] == 0) {
                                $number = "[{$thread['LENGTH']}&nbsp;new]";
                                $latest_post = 1;
                            } else {
                                if ($thread['LAST_READ'] < $thread['LENGTH']) {
                                    $new_posts = $thread['LENGTH'] - $thread['LAST_READ'];
                                    $number = "[{$new_posts}&nbsp;new&nbsp;of&nbsp;{$thread['LENGTH']}]";
                                    $latest_post = $thread['LAST_READ'] + 1;
                                } else {
                                    $number = "[{$thread['LENGTH']}]";
                                    $latest_post = 1;
                                }
                            }
                            // work out how long ago the thread was posted and format the time to display
                            $thread_time = format_time($thread['MODIFIED']);
                            echo "<span class=\"thread_title\">";
                            echo "<a href=\"lmessages.php?webtag={$webtag}&amp;msg={$thread['TID']}.{$latest_post}\" ";
                            echo "title=\"", sprintf(gettext("Thread #%s Started by %s. Viewed %s"), $thread['TID'], word_filter_add_ob_tags(format_user_name($thread['LOGON'], $thread['NICKNAME']), true), $thread['VIEWCOUNT'] == 1 ? gettext("1 time") : sprintf(gettext("%d times"), $thread['VIEWCOUNT'])), "\">";
                            echo word_filter_add_ob_tags($thread['TITLE'], true), "</a> ";
                            echo "<span class=\"thread_detail\">";
                            if (isset($thread['INTEREST']) && $thread['INTEREST'] == THREAD_INTERESTED) {
                                echo "<span class=\"thread_high_interest\" title=\"", gettext("High Interest"), "\">[H]</span>";
                            }
                            if (isset($thread['INTEREST']) && $thread['INTEREST'] == THREAD_SUBSCRIBED) {
                                echo "<span class=\"thread_subscribed\" title=\"", gettext("Subscribed"), "\">[S]</span>";
                            }
                            if (isset($thread['POLL_FLAG']) && $thread['POLL_FLAG'] == 'Y') {
                                echo "<span class=\"thread_poll\" title=\"", gettext("Poll"), "\">[P]</span>";
                            }
                            if (isset($thread['STICKY']) && $thread['STICKY'] == 'Y') {
                                echo "<span class=\"thread_sticky\" title=\"", gettext("Sticky"), "\">[ST]</span>";
                            }
                            if (isset($thread['RELATIONSHIP']) && $thread['RELATIONSHIP'] & USER_FRIEND) {
                                echo "<span class=\"thread_friend\" title=\"", gettext("Friend"), "\">[F]</span>";
                            }
                            if (isset($thread['TRACK_TYPE']) && $thread['TRACK_TYPE'] == THREAD_TYPE_SPLIT) {
                                echo "<span class=\"thread_split\" title=\"", gettext("Thread has been split"), "\">[TS]</span>";
                            }
                            if (isset($thread['TRACK_TYPE']) && $thread['TRACK_TYPE'] == THREAD_TYPE_MERGE) {
                                echo "<span class=\"thread_merge\" title=\"", gettext("Thread has been merged"), "\">[TM]</span>";
                            }
                            if (isset($thread['AID']) && is_md5($thread['AID'])) {
                                echo "<span class=\"thread_attachment\" title=\"", gettext("Attachment"), "\">[A]</span>";
                            }
                            echo "<span class=\"thread_length\">{$number}</span>";
                            echo "</span>";
                            echo "</span>";
                            echo "<span class=\"thread_time\">{$thread_time}</span>";
                            echo "</li>\n";
                        }
                    }
                    if ($folder_list_end === false && $folder_list_start === true) {
                        echo "</ul>\n";
                        $folder_list_end = true;
                    }
                    if (is_numeric($folder) && $folder_number == $folder) {
                        echo "<div class=\"folder_pagination\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder}&amp;page=", $page + 1, "\">", gettext("Next 50 threads"), "</a></div>\n";
                    }
                } else {
                    if ($folder_info[$folder_number]['INTEREST'] != -1) {
                        echo "<div class=\"folder_info\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;folder={$folder_number}\">";
                        if (isset($folder_msgs[$folder_number])) {
                            echo $folder_msgs[$folder_number];
                        } else {
                            echo "0";
                        }
                        echo " ", gettext("threads"), "</a>";
                        if ($folder_info[$folder_number]['ALLOWED_TYPES'] & FOLDER_ALLOW_NORMAL_THREAD) {
                            echo "<span><a href=\"lpost.php?webtag={$webtag}&amp;fid={$folder_number}\">", gettext("Post New"), "</a></span>";
                        }
                        echo "</div>\n";
                    }
                }
            }
            echo "  </div>\n";
            echo "</div>\n";
            if (is_array($thread_info)) {
                reset($thread_info);
            }
        }
    }
    if ($mode == ALL_DISCUSSIONS && !isset($folder)) {
        echo "<div class=\"thread_pagination\"><a href=\"lthread_list.php?webtag={$webtag}&amp;mode={$mode}&amp;page=", $page + 1, "\">", gettext("Next 50 threads"), "</a></div>\n";
    }
    if (session::logged_in()) {
        echo "<div id=\"thread_mark_read\">\n";
        echo "<h3>", gettext("Mark as Read"), "</h3>\n";
        echo "<form accept-charset=\"utf-8\" name=\"f_mark\" method=\"post\" action=\"lthread_list.php\">\n";
        echo form_input_hidden("webtag", htmlentities_array($webtag)), "\n";
        echo form_input_hidden("mode", htmlentities_array($mode)), "\n";
        echo form_input_hidden("page", htmlentities_array($page)), "\n";
        echo form_input_hidden("mark_read_confirm", 'N'), "\n";
        $labels = array(gettext("All Discussions"), gettext("Next 50 discussions"));
        $selected_option = THREAD_MARK_READ_ALL;
        if (sizeof($visible_threads_array) > 0) {
            $labels[] = gettext("Visible discussions");
            $selected_option = THREAD_MARK_READ_VISIBLE;
            $visible_threads = implode(',', array_filter($visible_threads_array, 'is_numeric'));
            echo form_input_hidden("mark_read_threads", htmlentities_array($visible_threads)), "\n";
        }
        if (isset($_GET['folder']) && is_numeric($_GET['folder'])) {
            echo form_input_hidden('folder', htmlentities_array($folder)), "\n";
            $labels[] = gettext("Selected folder");
            $selected_option = THREAD_MARK_READ_FOLDER;
        }
        echo "<ul>\n";
        echo "<li>", light_form_dropdown_array("mark_read_type", $labels, $selected_option), "</li>\n";
        echo "<li class=\"right_col\">", light_form_submit("mark_read_submit", gettext("Go!")), "</li>\n";
        echo "</ul>\n";
        echo "</form>\n";
        echo "</div>\n";
    }
}