Пример #1
0
function threads_get_user_subscriptions($interest_type = THREAD_NOINTEREST, $page = 1)
{
    if (!($db = db::get())) {
        return false;
    }
    if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) {
        return false;
    }
    if (!is_numeric($interest_type)) {
        $interest_type = THREAD_NOINTEREST;
    }
    if (!is_numeric($page)) {
        $page = 1;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    $offset = calculate_page_offset($page, 20);
    $thread_subscriptions_array = array();
    if ($interest_type != THREAD_NOINTEREST) {
        $sql = "SELECT SQL_CALC_FOUND_ROWS THREAD.TID, ";
        $sql .= "TRIM(CONCAT_WS(' ', COALESCE(FOLDER.PREFIX, ''), THREAD.TITLE)) AS TITLE, ";
        $sql .= "USER_THREAD.INTEREST FROM `{$table_prefix}THREAD` THREAD ";
        $sql .= "LEFT JOIN `{$table_prefix}FOLDER` FOLDER ON (FOLDER.FID = THREAD.FID) ";
        $sql .= "LEFT JOIN `{$table_prefix}USER_THREAD` USER_THREAD ON (USER_THREAD.TID = THREAD.TID ";
        $sql .= "AND USER_THREAD.UID = '{$_SESSION['UID']}') WHERE USER_THREAD.INTEREST = '{$interest_type}' ";
        $sql .= "ORDER BY THREAD.MODIFIED DESC LIMIT {$offset}, 20";
    } else {
        $sql = "SELECT SQL_CALC_FOUND_ROWS THREAD.TID, ";
        $sql .= "TRIM(CONCAT_WS(' ', COALESCE(FOLDER.PREFIX, ''), THREAD.TITLE)) AS TITLE, ";
        $sql .= "USER_THREAD.INTEREST FROM `{$table_prefix}THREAD` THREAD ";
        $sql .= "LEFT JOIN `{$table_prefix}FOLDER` FOLDER ON (FOLDER.FID = THREAD.FID) ";
        $sql .= "LEFT JOIN `{$table_prefix}USER_THREAD` USER_THREAD ON (USER_THREAD.TID = THREAD.TID ";
        $sql .= "AND USER_THREAD.UID = '{$_SESSION['UID']}') ORDER BY THREAD.MODIFIED DESC ";
        $sql .= "LIMIT {$offset}, 20";
    }
    if (!($result = $db->query($sql))) {
        return false;
    }
    $sql = "SELECT FOUND_ROWS() AS ROW_COUNT";
    if (!($result_count = $db->query($sql))) {
        return false;
    }
    list($thread_subscriptions_count) = $result_count->fetch_row();
    if ($result->num_rows == 0 && $thread_subscriptions_count > 0 && $page > 1) {
        return threads_get_user_subscriptions($interest_type, $page - 1);
    }
    while (($thread_data_array = $result->fetch_assoc()) !== null) {
        $thread_subscriptions_array[] = $thread_data_array;
    }
    return array('thread_count' => $thread_subscriptions_count, 'thread_array' => $thread_subscriptions_array);
}
    if (isset($_GET['search_keyword']) && strlen(trim($_GET['search_keyword'])) > 0) {
        $search_keyword = trim($_GET['search_keyword']);
    } else {
        $search_keyword = '';
    }
}
if (isset($_POST['clear'])) {
    $search_keyword = "";
}
$uid = session::get_value('UID');
$header_text_array = array(THREAD_IGNORED => gettext("Ignored Threads"), THREAD_INTERESTED => gettext("High Interest Threads"), THREAD_SUBSCRIBED => gettext("Subscribed Threads"));
$interest_level_array = array(THREAD_IGNORED => gettext("Ignored"), THREAD_INTERESTED => gettext("Interested"), THREAD_SUBSCRIBED => gettext("Subscribe"));
if (isset($search_keyword) && strlen(trim($search_keyword)) > 0) {
    $thread_subscriptions = threads_search_user_subscriptions($search_keyword, $view, $page);
} else {
    $thread_subscriptions = threads_get_user_subscriptions($view, $page);
}
html_draw_top(sprintf('title=%s', gettext("My Controls - Thread Subscriptions")), 'edit_subscriptions.js', 'class=window_title');
echo "<h1>", gettext("Thread Subscriptions"), "<img src=\"", html_style_image('separator.png'), "\" alt=\"\" border=\"0\" />{$header_text_array[$view]}</h1>\n";
if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
    html_display_error_array($error_msg_array, '600', 'left');
} else {
    if (isset($_GET['updated'])) {
        html_display_success_msg(gettext("Thread interests updated successfully"), '600', 'left');
    } else {
        if (sizeof($thread_subscriptions['thread_array']) < 1) {
            if (isset($search_keyword) && strlen(trim($search_keyword)) > 0) {
                html_display_warning_msg(gettext("Search Returned No Results"), '600', 'left');
            } else {
                if ($view == THREAD_IGNORED) {
                    html_display_warning_msg(gettext("You are not ignoring any threads."), '600', 'left');