function draw_index_threads_list($limit = 30, $thread_object_name = 'thread.php') { global $luna_user, $luna_config, $db, $start_from, $id, $sort_by, $start_from, $db_type, $cur_thread, $tracked_threads; // Retrieve a list of thread IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data $result = $db->query('SELECT t.id, t.moved_to FROM ' . $db->prefix . 'threads AS t LEFT JOIN ' . $db->prefix . 'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=' . $luna_user['g_id'] . ') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL ORDER BY last_comment DESC LIMIT ' . $limit) or error('Unable to fetch thread IDs', __FILE__, __LINE__, $db->error()); // If there are threads in this forum if ($db->num_rows($result)) { $thread_ids = array(); for ($i = 0; $cur_thread_id = $db->result($result, $i); $i++) { $thread_ids[] = $cur_thread_id; } // Fetch list of threads to display on this page $sql_soft = NULL; if ($luna_user['is_guest'] || $luna_config['o_has_commented'] == '0') { if (!$luna_user['g_soft_delete_view']) { $sql_soft = 'soft = 0 AND '; } $sql = 'SELECT id, commenter, subject, commented, last_comment, last_comment_id, last_commenter, last_commenter_id, num_views, num_replies, closed, pinned, important, moved_to, soft, solved AS answer, forum_id FROM ' . $db->prefix . 'threads WHERE ' . $sql_soft . 'id IN(' . implode(',', $thread_ids) . ') ORDER BY last_comment DESC'; } else { if (!$luna_user['g_soft_delete_view']) { $sql_soft = 't.soft = 0 AND '; } $sql = 'SELECT p.commenter_id AS has_commented, t.id, t.subject, t.commenter, t.commented, t.last_comment, t.last_comment_id, t.last_commenter, t.last_commenter_id, t.num_views, t.num_replies, t.closed, t.pinned, t.important, t.moved_to, t.soft, t.solved AS answer, t.forum_id FROM ' . $db->prefix . 'threads AS t LEFT JOIN ' . $db->prefix . 'comments AS p ON t.id=p.thread_id AND p.commenter_id=' . $luna_user['id'] . ' WHERE ' . $sql_soft . 't.id IN(' . implode(',', $thread_ids) . ') GROUP BY t.id' . ($db_type == 'pgsql' ? ', t.subject, t.commenter, t.commented, t.last_comment, t.last_comment_id, t.last_commenter, t.num_views, t.num_replies, t.closed, t.pinned, t.moved_to, p.commenter_id' : '') . ' ORDER BY t.last_comment DESC'; } $result = $db->query($sql) or error('Unable to fetch thread list', __FILE__, __LINE__, $db->error()); // Load cached forums if (file_exists(LUNA_CACHE_DIR . 'cache_forums.php')) { include LUNA_CACHE_DIR . 'cache_forums.php'; } if (!defined('LUNA_LIST_LOADED')) { if (!defined('LUNA_CACHE_FUNCTIONS_LOADED')) { require LUNA_ROOT . 'include/cache.php'; } generate_forum_cache(); require LUNA_CACHE_DIR . 'cache_forums.php'; } $thread_count = 0; while ($cur_thread = $db->fetch_assoc($result)) { ++$thread_count; $status_text = array(); $item_status = $thread_count % 2 == 0 ? 'roweven' : 'rowodd'; $icon_type = 'icon'; if (luna_strlen($cur_thread['subject']) > 53) { $subject = utf8_substr($cur_thread['subject'], 0, 50) . '...'; } else { $subject = luna_htmlspecialchars($cur_thread['subject']); } $last_comment_date = '<a href="thread.php?pid=' . $cur_thread['last_comment_id'] . '#p' . $cur_thread['last_comment_id'] . '">' . format_time($cur_thread['last_comment']) . '</a>'; if (is_null($cur_thread['moved_to'])) { $thread_id = $cur_thread['id']; if ($luna_user['g_view_users'] == '1' && $cur_thread['last_commenter_id'] > '1') { $last_commenter = '<span class="byuser">' . __('by', 'luna') . ' <a href="profile.php?id=' . $cur_thread['last_commenter_id'] . '">' . luna_htmlspecialchars($cur_thread['last_commenter']) . '</a></span>'; } else { $last_commenter = '<span class="byuser">' . __('by', 'luna') . ' ' . luna_htmlspecialchars($cur_thread['last_commenter']) . '</span>'; } foreach ($luna_forums as $cur_forum) { if ($cur_thread['forum_id'] == $cur_forum['id']) { $forum_name = luna_htmlspecialchars($cur_forum['forum_name']); $forum_color = $cur_forum['color']; if ($cur_forum['icon'] != NULL) { $faicon = '<span class="fa fa-fw fa-' . $cur_forum['icon'] . '"></span> '; } else { $faicon = ''; } } } $forum_name = '<span class="byuser">' . __('in', 'luna') . ' <a class="label label-default" href="viewforum.php?id=' . $cur_thread['forum_id'] . '" style="background: ' . $forum_color . ';">' . $faicon . '<span class="hidden-xs hidden-sm">' . $forum_name . '</span></a></span>'; } else { $last_commenter = ''; $thread_id = $cur_thread['moved_to']; } if ($luna_config['o_censoring'] == '1') { $cur_thread['subject'] = censor_words($cur_thread['subject']); } if ($cur_thread['pinned'] == '1') { $item_status .= ' pinned-item'; $status_text[] = '<span class="label label-warning"><span class="fa fa-fw fa-thumb-tack"></span></span>'; } if ($cur_thread['important']) { $item_status .= ' important-item'; $status_text[] = '<span class="label label-primary"><span class="fa fa-fw fa-map-marker"></span></span>'; } if (isset($cur_thread['answer'])) { $item_status .= ' solved-item'; $status_text[] = '<span class="label label-success"><span class="fa fa-fw fa-check"></span></span>'; } $url = 'thread.php?id=' . $thread_id; $by = '<span class="byuser">' . __('by', 'luna') . ' ' . luna_htmlspecialchars($cur_thread['commenter']) . '</span>'; if ($cur_thread['moved_to'] != 0) { $status_text[] = '<span class="label label-info"><span class="fa fa-fw fa-arrows-alt"></span></span>'; $item_status .= ' moved-item'; } elseif ($cur_thread['closed'] == '1') { $status_text[] = '<span class="label label-danger"><span class="fa fa-fw fa-lock"></span></span>'; $item_status .= ' closed-item'; } if (!$luna_user['is_guest'] && $luna_config['o_has_commented'] == '1') { if ($cur_thread['has_commented'] == $luna_user['id']) { $item_status .= ' commented-item'; } } if (!$luna_user['is_guest'] && $cur_thread['last_comment'] > $luna_user['last_visit'] && (!isset($tracked_threads['threads'][$cur_thread['id']]) || $tracked_threads['threads'][$cur_thread['id']] < $cur_thread['last_comment']) && (!isset($tracked_threads['forums'][$id]) || $tracked_threads['forums'][$id] < $cur_thread['last_comment']) && is_null($cur_thread['moved_to'])) { $item_status .= ' new-item'; $icon_type = 'icon icon-new'; $status_text[] = '<a href="thread.php?id=' . $cur_thread['id'] . '&action=new" title="' . __('Go to the first new comment in the thread.', 'luna') . '" class="label label-default label-new"><span class="fa fa-fw fa-bell"></span></a>'; } $subject_status = implode(' ', $status_text); $num_pages_thread = ceil(($cur_thread['num_replies'] + 1) / $luna_user['disp_comments']); if ($num_pages_thread > 1) { $subject_multipage = '<span class="inline-pagination"> ' . simple_paginate($num_pages_thread, -1, 'thread.php?id=' . $cur_thread['id']) . '</span>'; } else { $subject_multipage = null; } $replies_label = _n('reply', 'replies', $cur_thread['num_replies'], 'luna'); $views_label = _n('view', 'views', $cur_thread['num_views'], 'luna'); require get_view_path($thread_object_name); } } else { echo '<h3 class="nothing">' . __('The board is empty, select a forum and create a thread to begin.', 'luna') . '</h3>'; } }
} } // Regenerate the forum cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FORUM_ROOT . 'include/cache.php'; } generate_forum_cache(); redirect('backstage/board.php?saved=true'); } elseif (isset($_POST['revert_perms'])) { confirm_referrer('backstage/board.php'); $db->query('DELETE FROM ' . $db->prefix . 'forum_perms WHERE forum_id=' . $forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error()); // Regenerate the forum cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FORUM_ROOT . 'include/cache.php'; } generate_forum_cache(); redirect('backstage/board.php?edit_forum=' . $forum_id); } // Fetch forum info $result = $db->query('SELECT id, forum_name, forum_desc, parent_id, num_topics, sort_by, cat_id, icon, color, solved FROM ' . $db->prefix . 'forums WHERE id=' . $forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error()); if (!$db->num_rows($result)) { message_backstage(__('Bad request. The link you followed is incorrect, outdated or you are simply not allowed to hang around here.', 'luna'), false, '404 Not Found'); } $cur_forum = $db->fetch_assoc($result); $parent_forums = array(); $result = $db->query('SELECT DISTINCT parent_id FROM ' . $db->prefix . 'forums WHERE parent_id != 0'); while ($r = $db->fetch_row($result)) { $parent_forums[] = $r[0]; } $cur_index = 7; $page_title = array(luna_htmlspecialchars($luna_config['o_board_title']), __('Admin', 'luna'), __('Forums', 'luna'));