From 11b9a0c95d76c98ded13d12630c9004ec63afb67 Mon Sep 17 00:00:00 2001 From: Ludovic Arnaud Date: Wed, 9 Apr 2003 21:26:25 +0000 Subject: [PATCH] Moved back gen_sorting() to mcp.php git-svn-id: file:///svn/phpbb/trunk@3792 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 167 +---------------------------------- phpBB/viewforum.php | 17 +++- 2 files changed, 18 insertions(+), 166 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3802f27d6d..fd9ae37841 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -212,169 +212,6 @@ function gen_forum_rules($mode, &$forum_id) return; } -function gen_sorting($mode, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE') -{ - global $db, $user, $auth, $template; - - $sort_days = (!empty($_REQUEST['st'])) ? max(intval($_REQUEST['st']), 0) : 0; - $sort_key = (!empty($_REQUEST['sk'])) ? htmlspecialchars($_REQUEST['sk']) : 't'; - $sort_dir = (!empty($_REQUEST['sd'])) ? htmlspecialchars($_REQUEST['sd']) : 'd'; - $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); - $min_time = ($sort_days) ? time() - ($sort_days * 86400) : 0; - - switch ($mode) - { - case 'viewforum': - $type = 'topics'; - $sql = 'SELECT COUNT(topic_id) AS total - FROM ' . TOPICS_TABLE . " - $where_sql forum_id = $forum_id - AND topic_type <> " . POST_ANNOUNCE . " - AND topic_last_post_time >= $min_time"; - - if (!$auth->acl_get('m_approve', $forum_id)) - { - $sql .= 'AND topic_approved = 1'; - } - break; - - case 'viewtopic': - $type = 'posts'; - $sql = 'SELECT COUNT(post_id) AS total - FROM ' . POSTS_TABLE . " - $where_sql topic_id = $topic_id - AND post_time >= $min_time"; - - if (!$auth->acl_get('m_approve', $forum_id)) - { - $sql .= 'AND post_approved = 1'; - } - break; - - case 'unapproved': - $type = 'posts'; - $sql = 'SELECT COUNT(post_id) AS total - FROM ' . POSTS_TABLE . " - $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_approve'))) . ') - AND post_approved = 0 - AND post_time >= ' . $min_time; - break; - - case 'reports': - $type = 'reports'; - $sql = 'SELECT COUNT(report_id) AS total - FROM ' . REPORTS_TABLE . " - $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_'))) . ') - AND report_time >= ' . $min_time; - break; - - case 'viewlogs': - $type = 'logs'; - $sql = 'SELECT COUNT(log_id) AS total - FROM ' . LOG_MOD_TABLE . " - $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_'))) . ') - AND log_time >= ' . $min_time; - break; - - default: - trigger_error(":: DEBUG ::

Unkown mode '$mode' in gen_sorting()"); - } - - switch ($type) - { - case 'topics': - $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); - $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); - - $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views'); - $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : ''; - break; - - case 'posts': - $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); - $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); - $sort_by_sql = array('a' => 'u.username', 't' => 'p.post_time', 's' => 'p.post_subject'); - $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : ''; - break; - - case 'reports': - $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); - $sort_by_text = array('r' => $user->lang['REPORTER'], 't' => $user->lang['REPORT_TIME']); - $sort_by_sql = array('r' => 'u.username', 't' => 'r.report_time'); - $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : ''; - break; - - case 'logs': - $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); - $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']); - - $sort_by_sql = array('u' => 'l.user_id', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation'); - $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : ''; - break; - } - - $s_limit_days = ''; - - $s_sort_key = ''; - - $s_sort_dir = ''; - - $template->assign_vars(array( - 'S_SELECT_SORT_DIR' => $s_sort_dir, - 'S_SELECT_SORT_KEY' => $s_sort_key, - 'S_SELECT_SORT_DAYS'=> $s_limit_days - )); - - if (empty($sort_by_sql[$sort_key])) - { - trigger_error('Error in gen_sorting :: no $sort_by_sql for "' . $sort_key . '"'); - } - - $return_vars = array( - 'sort_order_sql' => $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'), - 'limit_time_sql' => $limit_time_sql, - 'sort_days' => $sort_days, - 'sort_key' => $sort_key, - 'sort_dir' => $sort_dir, - 'min_time' => $min_time - ); - - if ($sort_days) - { - $result = $db->sql_query($sql); - $return_vars['total'] = ($row = $db->sql_fetchrow($result)) ? $row['total'] : 0; - } - else - { - $return_vars['total'] = -1; - } - - // Experimental: set vars in the global scope directly instead of extracting them or whatever - foreach ($return_vars as $varname => $value) - { - $GLOBALS[$varname] = $value; - } -// return $return_vars; -} - function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir) { global $user; @@ -1129,6 +966,10 @@ function msg_handler($errno, $msg_text, $errfile, $errline) { $db->sql_close(); } + if (isset($cache)) + { + $cache->unload(); + } if (!defined('HEADER_INC')) { diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 461086c8e2..d729a4b0f4 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -173,9 +173,14 @@ if ($forum_data['forum_postable']) $censors = array(); obtain_word_list($censors); - // Topic ordering options - gen_sorting('viewforum', $forum_id); + $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); + + $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); + $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views'); + + $s_limit_days = $s_sort_key = $s_sort_dir = ''; + gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir); // Limit topics to certain time frame, obtain correct topic count if ($sort_days) @@ -194,13 +199,16 @@ if ($forum_data['forum_postable']) } } + // Select the sort order + $sort_order_sql = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); + // Basic pagewide vars $post_alt = (intval($forum_data['forum_status']) == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'POST_NEW_TOPIC'; $template->assign_vars(array( 'PAGINATION' => generate_pagination("viewforum.$phpEx$SID&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir", $topics_count, $config['topics_per_page'], $start), 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), - 'TOTAL_TOPICS' => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count), + 'TOTAL_TOPICS' => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count), 'MOD_CP' => ($auth->acl_gets('m_', $forum_id)) ? sprintf($user->lang['MCP'], '', '') : '', 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : $user->lang['NONE'], @@ -222,6 +230,9 @@ if ($forum_data['forum_postable']) 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'], 'S_IS_POSTABLE' => TRUE, + 'S_SELECT_SORT_DIR' => $s_sort_dir, + 'S_SELECT_SORT_KEY' => $s_sort_key, + 'S_SELECT_SORT_DAYS'=> $s_limit_days, 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false, 'S_WATCH_FORUM' => $s_watching_forum, 'S_FORUM_ACTION' => 'viewforum.' . $phpEx . $SID . '&f=' . $forum_id . "&start=$start",