1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-31 05:37:59 +01:00

viewforum queries update + a couple of bugfixes.

git-svn-id: file:///svn/phpbb/trunk@3007 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Ludovic Arnaud 2002-11-05 04:50:55 +00:00
parent 5b73ad4cbd
commit bc6e36ef4f
12 changed files with 225 additions and 111 deletions

View File

@ -222,6 +222,13 @@ switch ($mode)
{
move_forum($forum_id, $parent_id);
}
elseif ($row['forum_name'] != $_POST['forum_name'])
{
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET forum_parents = ""
WHERE left_id > ' . $row['left_id'] . ' AND right_id < ' . $row['right_id'];
$db->sql_query($sql);
}
$sql = array(
'forum_name' => (!empty($_POST['forum_name'])) ? $_POST['forum_name'] : $row['forum_name'],
@ -904,7 +911,7 @@ function move_forum($from_id, $to_id)
// Resync parents
//
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET right_id = right_id - $diff
SET right_id = right_id - $diff, forum_parents = ''
WHERE left_id < " . $from_data['right_id'] . " AND right_id > " . $from_data['right_id'];
$db->sql_query($sql);
@ -912,7 +919,7 @@ function move_forum($from_id, $to_id)
// Resync righthand side of tree
//
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET left_id = left_id - $diff, right_id = right_id - $diff
SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
WHERE left_id > " . $from_data['right_id'];
$db->sql_query($sql);
@ -924,7 +931,7 @@ function move_forum($from_id, $to_id)
// Resync new parents
//
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET right_id = right_id + $diff
SET right_id = right_id + $diff, forum_parents = ''
WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
AND forum_id NOT IN (' . implode(', ', $moved_ids) . ')';
$db->sql_query($sql);
@ -933,7 +940,7 @@ function move_forum($from_id, $to_id)
// Resync the righthand side of the tree
//
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET left_id = left_id + $diff, right_id = right_id + $diff
SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
WHERE left_id > " . $to_data['right_id'] . '
AND forum_id NOT IN (' . implode(', ', $moved_ids) . ')';
$db->sql_query($sql);
@ -960,7 +967,7 @@ function move_forum($from_id, $to_id)
}
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET left_id = left_id $diff, right_id = right_id $diff
SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
WHERE forum_id IN (" . implode(', ', $moved_ids) . ')';
$db->sql_query($sql);
}

View File

@ -226,7 +226,7 @@ class sql_db
}
elseif (is_string($var))
{
$values[] = "'" . str_replace('\\\'', '\'\'', $var) . "'";
$values[] = "'" . sql_quote($var) . "'";
}
else
{
@ -247,7 +247,7 @@ class sql_db
}
elseif (is_string($var))
{
$values[] = "$key = '" . str_replace('\\\'', '\'\'', $var) . "'";
$values[] = "$key = '" . sql_quote($var) . "'";
}
else
{

View File

@ -77,7 +77,7 @@ foreach ($forum_rows as $row)
{
$last_post = $user->format_date($forum_last_post_time) . '<br />';
$last_post .= ($forum_last_poster_id == ANONYMOUS) ? (($forum_last_poster_name != '') ? $forum_last_poster_name . ' ' : $user->lang['Guest'] . ' ') : '<a href="profile.' . $phpEx . $SID . '&amp;mode=viewprofile&amp;u=' . $forum_last_poster_id . '">' . $username . '</a> ';
$last_post .= ($forum_last_poster_id == ANONYMOUS) ? (($forum_last_poster_name != '') ? $forum_last_poster_name . ' ' : $user->lang['Guest'] . ' ') : '<a href="profile.' . $phpEx . $SID . '&amp;mode=viewprofile&amp;u=' . $forum_last_poster_id . '">' . $forum_last_poster_name . '</a> ';
$last_post .= '<a href="viewtopic.' . $phpEx . $SID . '&amp;f=' . $forum_id . '&amp;p=' . $forum_last_post_id . '#' . $forum_last_post_id . '">' . $user->img('goto_post_latest', 'View_latest_post') . '</a>';
}

View File

@ -19,6 +19,11 @@
*
***************************************************************************/
function sql_addslashes($msg)
{
return str_replace("'", "''", str_replace('\\', '\\\\', $msg));
}
function sql_quote($msg)
{
return str_replace("\'", "''", $msg);
@ -394,7 +399,7 @@ function tz_select($default, $select_name = 'timezone')
}
// Topic and forum watching common code
function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $match_id)
function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $match_id, $notify_status = 'unset')
{
global $template, $db, $user, $phpEx, $SID, $start;
@ -407,13 +412,25 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat
{
$can_watch = TRUE;
$sql = "SELECT notify_status
FROM " . $table_sql . "
WHERE $where_sql = $match_id
AND user_id = $user_id";
$result = $db->sql_query($sql);
if ($notify_status == 'unset')
{
$sql = "SELECT notify_status
FROM $table_sql
WHERE $where_sql = $match_id
AND user_id = $user_id";
$result = $db->sql_query($sql);
if ( $row = $db->sql_fetchrow($result) )
if ($row = $db->sql_fetchrow($result))
{
$notify_status = $row['notify_status'];
}
else
{
$notify_status = NULL;
}
}
if (!is_null($notify_status))
{
if ( isset($_GET['unwatch']) )
{
@ -438,7 +455,7 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat
{
$is_watching = TRUE;
if ( $row['notify_status'] )
if ($notify_status)
{
$sql = "UPDATE " . $table_sql . "
SET notify_status = 0

View File

@ -288,6 +288,13 @@ if (isset($_POST['submit']))
else
{
$username_sql = "username = '" . sql_quote($username) . "', ";
if ($mode != 'register')
{
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET forum_last_poster_name = '" . sql_quote($username) . "'
WHERE forum_last_poster_id = " . $user_id;
$db->sql_query($sql);
}
}
}
}
@ -359,7 +366,6 @@ if (isset($_POST['submit']))
'user_dateformat' => $user_dateformat,
'user_lang' => $user_lang,
'user_style' => $user_style,
'user_level' => 0,
'user_allow_pm' => 1,
'user_active' => $user_active,
'user_actkey' => $user_actkey
@ -367,7 +373,15 @@ if (isset($_POST['submit']))
if ($mode == 'editprofile')
{
$db->sql_query_array('UPDATE ' . USERS_TABLE . ' SET WHERE user_id = ' . $user_id, &$sql_ary);
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user_id);
if ($config['newest_user_id'] == $user_id)
{
$sql = 'UPDATE ' . CONFIG_TABLE . "
SET config_value = '" . sql_quote($username) . "'
WHERE config_name = 'newest_username'";
$db->sql_query($sql);
}
if ( !$user_active )
{

View File

@ -109,6 +109,8 @@ if ($cat_id == 0)
LEFT JOIN ' . USERS_TABLE . ' u ON f.forum_last_poster_id = u.user_id
ORDER BY f.left_id';
}
$sql = 'SELECT * FROM ' . FORUMS_TABLE . ' ORDER BY left_id';
}
else
{

View File

@ -80,7 +80,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_base_dn', '')
INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_uid', '');
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('record_online_users', '0', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('record_online_date', '0', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('newest_user_id', '1', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('newest_user_id', '2', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('newest_username', '', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('num_users', '1', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('num_posts', '1', 1);

View File

@ -113,6 +113,7 @@ CREATE TABLE phpbb_forums (
parent_id smallint(5) UNSIGNED NOT NULL,
left_id smallint(5) UNSIGNED NOT NULL,
right_id smallint(5) UNSIGNED NOT NULL,
forum_parents text,
forum_name varchar(150) NOT NULL,
forum_desc text,
forum_style tinyint(4) UNSIGNED,

View File

@ -19,6 +19,10 @@
*
***************************************************************************/
// Grab all data
extract($_GET);
extract($_POST);
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
@ -31,10 +35,6 @@ $user->setup();
$auth->acl($user->data);
// End session management
// Grab all data
extract($_GET);
extract($_POST);
// Was cancel pressed? If so then redirect to the appropriate page
if ( !empty($cancel) )
{
@ -398,7 +398,7 @@ if (isset($post))
'forum_last_post_id' => intval($post_id),
'forum_last_post_time' => $current_time,
'forum_last_poster_id' => intval($user->data['user_id']),
'forum_last_poster_name'=> ($username != '') ? $username : '',
'forum_last_poster_name'=> ($user->data['user_id'] == ANONYMOUS) ? $username : $user->data['username'],
);
$sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $forum_sql) . ', forum_posts = forum_posts + 1' . $forum_topics_sql . ' WHERE forum_id = ' . intval($forum_id);
$db->sql_query($sql);

View File

@ -135,8 +135,7 @@ if ( $search_keywords != '' || $search_author != '' || $search_id )
}
else
{
header("Location: login.$phpEx?redirect=search.$phpEx&search_id=newposts", true);
exit;
redirect("login.$phpEx?redirect=search.$phpEx&search_id=newposts");
}
$show_results = 'topics';
@ -153,8 +152,7 @@ if ( $search_keywords != '' || $search_author != '' || $search_id )
}
else
{
header("Location: login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true);
exit;
redirect("login.$phpEx?redirect=search.$phpEx&search_id=egosearch");
}
$show_results = 'topics';

View File

@ -33,24 +33,8 @@ if (preg_match('/^c([0-9]+)$/', $_POST['f'], $m))
include($phpbb_root_path . 'common.'.$phpEx);
// Start initial var setup
if (isset($_GET['f']) || isset($_POST['f']))
{
$forum_id = (isset($_GET['f'])) ? intval($_GET['f']) : intval($_POST['f']);
}
else
{
$forum_id = '';
}
if (isset($_GET['mark']) || isset($_POST['mark']))
{
$mark_read = (isset($_POST['mark'])) ? $_POST['mark'] : $_GET['mark'];
}
else
{
$mark_read = '';
}
$mark_read = (!empty($_REQUEST['mark'])) ? $_REQUEST['mark'] : '';
$forum_id = (!empty($_REQUEST['f'])) ? intval($_REQUEST['f']) : 0;
$start = (isset($_GET['start'])) ? intval($_GET['start']) : 0;
// End initial var setup
@ -59,100 +43,176 @@ $user->start();
// Check if the user has actually sent a forum ID with his/her request
// If not give them a nice error page.
if (empty($forum_id))
if (!$forum_id)
{
trigger_error('Forum_not_exist');
}
if (!$forum_branch = get_forum_branch($forum_id))
if ($user->data['user_id'] == ANONYMOUS)
{
$sql = 'SELECT * FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $forum_id;
}
else
{
switch (SQL_LAYER)
{
//TODO
case 'oracle':
break;
default:
$sql = 'SELECT f.*, fw.notify_status
FROM ' . FORUMS_TABLE . ' f
LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON fw.user_id = ' . $user->data['user_id'] . ' AND f.forum_id = fw.forum_id
WHERE f.forum_id = ' . $forum_id;
}
}
$result = $db->sql_query($sql);
if (!$forum_data = $db->sql_fetchrow($result))
{
trigger_error('Forum_not_exist');
}
// Configure style, language, etc.
$user->setup(false, $forum_branch['forum_style']);
$user->setup(false, $forum_data['forum_style']);
$auth->acl($user->data, $forum_id);
// Auth check
if (!$auth->acl_gets('f_read', 'm_', 'a_', $forum_id))
{
if (!$user->data['user_id'] != ANONYMOUS)
if ($user->data['user_id'] == ANONYMOUS)
{
redirect("login.$phpEx$SID&redirect=viewforum.$phpEx&f=$forum_id" . ((isset($start)) ? "&start=$start" : ''));
}
trigger_error($user->lang['Sorry_auth_read']);
trigger_error('Sorry_auth_read');
}
// End of auth check
// Build subforums list if applicable
//$forum_data = array();
//$s_has_subforums = forum_nav_links($forum_id, $forum_data);
$type = 'parent';
$forum_rows = array();
foreach ($forum_branch as $row)
// Get forum parents
$forum_parents = array();
if ($forum_data['parent_id'] > 0)
{
if ($type == 'parent')
if (empty($forum_data['forum_parents']))
{
if ($row['forum_status'] == ITEM_CATEGORY)
{
$link = 'index.' . $phpEx . $SID . '&amp;c=' . $row['forum_id'];
}
else
{
$link = 'viewforum.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'];
}
$sql = 'SELECT forum_id, forum_name
FROM ' . FORUMS_TABLE . '
WHERE left_id < ' . $forum_data['left_id'] . '
AND right_id > ' . $forum_data['right_id'] . '
ORDER BY left_id ASC';
$template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $row['forum_name'],
'U_VIEW_FORUM' => $link
));
if ($row['forum_id'] == $forum_id)
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$branch_root_id = 0;
$forum_data = $row;
$type = 'child';
$forum_parents[$row['forum_id']] = $row['forum_name'];
}
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET forum_parents = '" . sql_addslashes(serialize($forum_parents)) . "'
WHERE parent_id = " . $forum_data['parent_id'];
$db->sql_query($sql);
}
else
{
if ($row['parent_id'] == $forum_data['forum_id'])
$forum_parents = unserialize($forum_data['forum_parents']);
}
}
// Build navigation links
foreach ($forum_parents as $parent_forum_id => $parent_name)
{
$template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $parent_name,
'U_VIEW_FORUM' => 'viewforum.' . $phpEx . $SID . '&amp;f=' . $parent_forum_id
));
}
$template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $forum_data['forum_name'],
'U_VIEW_FORUM' => 'viewforum.' . $phpEx . $SID . '&amp;f=' . $forum_id
));
// Get forum children
if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
{
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE left_id > ' . $forum_data['left_id'] . ' AND left_id < ' . $forum_data['right_id'] . '
ORDER BY left_id ASC';
$result = $db->sql_query($sql);
$type = 'parent';
$forum_rows = array();
while ($row = $db->sql_fetchrow($result))
{
/*
if ($type == 'parent')
{
// Root-level forum
$forum_rows[] = $row;
$parent_id = $row['forum_id'];
if ($row['forum_status'] == ITEM_CATEGORY)
{
$branch_root_id = $row['forum_id'];
$link = 'index.' . $phpEx . $SID . '&amp;c=' . $row['forum_id'];
}
else
{
$s_has_subforums = TRUE;
$link = 'viewforum.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'];
}
}
elseif ($row['parent_id'] == $branch_root_id)
{
// Forum directly under a category
$forum_rows[] = $row;
$parent_id = $row['forum_id'];
if ($row['forum_status'] != ITEM_CATEGORY)
$template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $row['forum_name'],
'U_VIEW_FORUM' => $link
));
if ($row['forum_id'] == $forum_id)
{
$s_has_subforums = TRUE;
$branch_root_id = 0;
$forum_data = $row;
$type = 'child';
}
}
elseif ($row['forum_status'] != ITEM_CATEGORY)
else
{
// Subforum
if ($auth->acl_get('f_list', $row['forum_id']))
*/
if ($row['parent_id'] == $forum_data['forum_id'])
{
$subforums[$parent_id][] = $row;
// Root-level forum
$forum_rows[] = $row;
$parent_id = $row['forum_id'];
if ($row['forum_status'] == ITEM_CATEGORY)
{
$branch_root_id = $row['forum_id'];
}
else
{
$s_has_subforums = TRUE;
}
}
elseif ($row['parent_id'] == $branch_root_id)
{
// Forum directly under a category
$forum_rows[] = $row;
$parent_id = $row['forum_id'];
if ($row['forum_status'] != ITEM_CATEGORY)
{
$s_has_subforums = TRUE;
}
}
elseif ($row['forum_status'] != ITEM_CATEGORY)
{
// Subforum
if ($auth->acl_get('f_list', $row['forum_id']))
{
$subforums[$parent_id][] = $row;
}
}
/*
}
*/
}
$db->sql_freeresult();
}
// Topic read tracking cookie info
@ -192,7 +252,8 @@ if ($auth->acl_gets('m_prune', 'a_', $forum_id) && $config['prune_enable'])
// Forum rules, subscription info and word censors
$s_watching_forum = '';
$s_watching_forum_img = '';
watch_topic_forum('forum', $s_watching_forum, $s_watching_forum_img, $user->data['user_id'], $forum_id);
$notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
watch_topic_forum('forum', $s_watching_forum, $s_watching_forum_img, $user->data['user_id'], $forum_id, $notify_status);
$s_forum_rules = '';
get_forum_rules('forum', $s_forum_rules, $forum_id);
@ -324,18 +385,6 @@ $template->assign_vars(array(
'U_MARK_READ' => 'viewforum.' . $phpEx . $SID . '&amp;f=' . $forum_id . '&amp;mark=topics')
);
// Do we have subforums? if so, let's include this harmless file
if ($s_has_subforums)
{
$template->assign_vars(array(
'S_HAS_SUBFORUM' => TRUE,
'L_SUBFORUM' => (count($forum_rows) == 1) ? $user->lang['Subforum'] : $user->lang['Subforums']
));
$root_id = $forum_id;
include($phpbb_root_path . 'includes/forums_display.' . $phpEx);
}
// Topic icons
$sql = "SELECT *
FROM " . ICONS_TABLE . "
@ -552,6 +601,18 @@ $nav_links['up'] = array(
'title' => sprintf($user->lang['Forum_Index'], $config['sitename'])
);
// Do we have subforums? if so, let's include this harmless file
if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
{
$template->assign_vars(array(
'S_HAS_SUBFORUM' => TRUE,
'L_SUBFORUM' => (count($forum_rows) == 1) ? $user->lang['Subforum'] : $user->lang['Subforums']
));
$root_id = $forum_id;
include($phpbb_root_path . 'includes/forums_display.' . $phpEx);
}
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->set_filenames(array(

View File

@ -137,17 +137,31 @@ if ($user->data['user_id'] != ANONYMOUS)
// page the post is on and the correct display of viewtopic)
$join_sql_table = (!$post_id) ? '' : ', ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . ' p2 ';
$join_sql = (!$post_id) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND p.post_approved = " . TRUE . " AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_approved = " . TRUE . " AND p2.post_id <= $post_id";
$count_sql = (!$post_id) ? '' : ", COUNT(p2.post_id) AS prev_posts";
$extra_fields = (!$post_id) ? '' : ", COUNT(p2.post_id) AS prev_posts";
$order_sql = (!$post_id) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, f.forum_name, f.forum_status, f.forum_id, f.forum_style ORDER BY p.post_id ASC";
$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_status, f.forum_id, f.forum_style" . $count_sql . "
if ($user->data['user_id'] != ANONYMOUS)
{
switch (SQL_LAYER)
{
//TODO
case 'oracle':
break;
default:
$extra_fields .= ', tw.notify_status';
$join_sql_table .= ' LEFT JOIN ' . TOPICS_WATCH_TABLE . ' tw ON tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id';
}
}
$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_status, f.forum_id, f.forum_style" . $extra_fields . "
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
WHERE $join_sql
AND f.forum_id = t.forum_id
$order_sql";
$result = $db->sql_query($sql);
if (!(extract($db->sql_fetchrow($result))))
if (!extract($db->sql_fetchrow($result)))
{
trigger_error('Topic_post_not_exist');
}
@ -178,7 +192,7 @@ if (!empty($post_id))
$s_watching_topic = '';
$s_watching_topic_img = '';
watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $topic_id);
watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $topic_id, $notify_status);
// Post ordering options
$previous_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']);