1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-11 11:13:59 +02:00

- updated topic tracking code

- additional changes (mostly bugfixes)
- bart, if you update your user table with the user_lastmark field, set it to the user_lastvisit value ;)
- and last but not least, introducing some bugs in ucp main front (regarding topic tracking)


git-svn-id: file:///svn/phpbb/trunk@5272 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2005-10-19 18:00:10 +00:00
parent 719763dec2
commit b873b37607
26 changed files with 1204 additions and 724 deletions

View File

@@ -65,7 +65,7 @@ class cache extends acm
*/
function obtain_word_list(&$censors)
{
global $db, $user;
global $config, $user, $db;
if (!$user->optionget('viewcensors') && $config['allow_nocensors'])
{
@@ -101,14 +101,14 @@ class cache extends acm
*/
function obtain_icons(&$icons)
{
global $db;
if ($this->exists('icons'))
{
$icons = $this->get('icons');
}
else
{
global $db;
// Topic icons
$sql = 'SELECT *
FROM ' . ICONS_TABLE . '
@@ -136,14 +136,14 @@ class cache extends acm
*/
function obtain_ranks(&$ranks)
{
global $db;
if ($this->exists('ranks'))
{
$ranks = $this->get('ranks');
}
else
{
global $db;
$sql = 'SELECT *
FROM ' . RANKS_TABLE . '
ORDER BY rank_min DESC';
@@ -181,14 +181,14 @@ class cache extends acm
*/
function obtain_attach_extensions(&$extensions, $forum_id = false)
{
global $db;
if ($this->exists('extensions'))
if ($this->exists('_extensions'))
{
$extensions = $this->get('extensions');
$extensions = $this->get('_extensions');
}
else
{
global $db;
// The rule is to only allow those extensions defined. ;)
$sql = 'SELECT e.extension, g.*
FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
@@ -220,7 +220,7 @@ class cache extends acm
}
$db->sql_freeresult($result);
$this->put('extensions', $extensions);
$this->put('_extensions', $extensions);
}
if ($forum_id !== false)
@@ -265,14 +265,14 @@ class cache extends acm
*/
function obtain_bots(&$bots)
{
global $db;
if ($this->exists('bots'))
{
$bots = $this->get('bots');
}
else
{
global $db;
switch (SQL_LAYER)
{
case 'mssql':

View File

@@ -169,8 +169,9 @@ define('STYLES_TPLDATA_TABLE', $table_prefix.'styles_template_data');
define('STYLES_CSS_TABLE', $table_prefix.'styles_theme');
define('STYLES_IMAGE_TABLE', $table_prefix.'styles_imageset');
define('TOPICS_TABLE', $table_prefix.'topics');
define('TOPICS_TRACK_TABLE', $table_prefix.'topics_marking');
define('TOPICS_POSTED_TABLE', $table_prefix.'topics_posted');
define('TOPICS_WATCH_TABLE', $table_prefix.'topics_watch');
define('TOPICS_TRACK_TABLE', $table_prefix.'topics_marking');
define('USER_GROUP_TABLE', $table_prefix.'user_group');
define('USERS_TABLE', $table_prefix.'users');
define('USERS_PASSWD_TABLE', $table_prefix.'users_passwd');

View File

@@ -160,7 +160,7 @@ class dbal_firebird extends dbal
}
else
{
return ($this->query_result) ? true : false;
return false; //($this->query_result) ? true : false;
}
}

View File

@@ -473,196 +473,419 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat
}
/**
* Marks a topic or form as read
* Marks a topic/forum as read
* Marks a topic as posted to
*/
function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0)
{
global $config, $db, $user;
if (!$user->data['is_registered'])
global $db, $user, $config;
if ($mode == 'all')
{
return;
}
if (!is_array($forum_id))
{
$forum_id = array($forum_id);
}
// Default tracking type
$type = TRACK_NORMAL;
$current_time = ($marktime) ? $marktime : time();
$topic_id = (int) $topic_id;
switch ($mode)
{
case 'mark':
if ($config['load_db_lastread'])
if ($forum_id === false || !sizeof($forum_id))
{
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$sql = 'SELECT forum_id
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND forum_id IN (' . implode(', ', array_map('intval', $forum_id)) . ')';
$result = $db->sql_query($sql);
$sql_update = array();
while ($row = $db->sql_fetchrow($result))
{
$sql_update[] = $row['forum_id'];
}
$db->sql_freeresult($result);
if (sizeof($sql_update))
{
$sql = 'UPDATE ' . FORUMS_TRACK_TABLE . "
SET mark_time = $current_time
WHERE user_id = " . $user->data['user_id'] . '
AND forum_id IN (' . implode(', ', $sql_update) . ')';
$db->sql_query($sql);
$sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND forum_id IN (' . implode(', ', $sql_update) . ')
AND mark_type = ' . TRACK_NORMAL;
$db->sql_query($sql);
}
if ($sql_insert = array_diff($forum_id, $sql_update))
{
foreach ($sql_insert as $forum_id)
{
$sql = '';
switch (SQL_LAYER)
{
case 'mysql':
$sql .= (($sql != '') ? ', ' : '') . '(' . $user->data['user_id'] . ", $forum_id, $current_time)";
$sql = 'VALUES ' . $sql;
break;
case 'mysql4':
case 'mysqli':
case 'mssql':
case 'mssql_odbc':
case 'sqlite':
$sql .= (($sql != '') ? ' UNION ALL ' : '') . ' SELECT ' . $user->data['user_id'] . ", $forum_id, $current_time";
break;
default:
$sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . ' (user_id, forum_id, mark_time)
VALUES (' . $user->data['user_id'] . ", $forum_id, $current_time)";
$db->sql_query($sql);
$sql = '';
}
if ($sql)
{
$sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . " (user_id, forum_id, mark_time) $sql";
$db->sql_query($sql);
}
$sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . '
WHERE user_id = ' . $user->data['user_id'] . '
AND forum_id = ' . $forum_id . '
AND mark_type = ' . TRACK_NORMAL;
$db->sql_query($sql);
}
}
unset($sql_update);
unset($sql_insert);
// Mark all forums read (index page)
$db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}");
$db->sql_query('DELETE FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}");
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}");
}
else
{
$tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
foreach ($forum_id as $f_id)
{
unset($tracking[$f_id]);
$tracking[$f_id][0] = base_convert($current_time - $config['board_startdate'], 10, 36);
}
unset($tracking['tf']);
unset($tracking['t']);
unset($tracking['f']);
$tracking['l'] = base_convert(time() - $config['board_startdate'], 10, 36);
$user->set_cookie('track', serialize($tracking), time() + 31536000);
unset($tracking);
}
break;
case 'post':
// Mark a topic as read and mark it as a topic where the user has made a post.
$type = TRACK_POSTED;
case 'topic':
if (!isset($type))
{
$type = TRACK_NORMAL;
}
}
$forum_id = (int) $forum_id[0];
return;
}
else if ($mode == 'topics')
{
// Mark all topics in forums read
if (!is_array($forum_id))
{
$forum_id = array($forum_id);
}
/// Mark a topic as read
if ($config['load_db_lastread'] || ($config['load_db_track'] && $type == TRACK_POSTED))
// Add 0 to forums array to mark global announcements correctly
$forum_id[] = 0;
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . "
WHERE user_id = {$user->data['user_id']}
AND forum_id IN (" . implode(', ', $forum_id) . ")");
$sql = 'SELECT forum_id
FROM ' . FORUMS_TRACK_TABLE . "
WHERE user_id = {$user->data['user_id']}
AND forum_id IN (" . implode(', ', $forum_id) . ')';
$result = $db->sql_query($sql);
$sql_update = array();
while ($row = $db->sql_fetchrow($result))
{
$track_type = ($type == TRACK_POSTED) ? ', mark_type = ' . $type : '';
$sql = 'UPDATE ' . TOPICS_TRACK_TABLE . "
SET forum_id = $forum_id, mark_time = $current_time $track_type
WHERE topic_id = $topic_id
AND user_id = {$user->data['user_id']}
AND mark_time < $current_time";
if (!$db->sql_query($sql) || !$db->sql_affectedrows())
$sql_update[] = $row['forum_id'];
}
$db->sql_freeresult($result);
if (sizeof($sql_update))
{
$sql = 'UPDATE ' . FORUMS_TRACK_TABLE . '
SET mark_time = ' . time() . "
WHERE user_id = {$user->data['user_id']}
AND forum_id IN (" . implode(', ', $sql_update) . ')';
$db->sql_query($sql);
}
if ($sql_insert = array_diff($forum_id, $sql_update))
{
$sql_ary = array();
foreach ($sql_insert as $f_id)
{
$db->sql_return_on_error(true);
$sql_ary = array(
'user_id' => $user->data['user_id'],
'topic_id' => $topic_id,
'forum_id' => $forum_id,
'mark_type' => $type,
'mark_time' => $current_time
$sql_ary[] = array(
'user_id' => $user->data['user_id'],
'forum_id' => $f_id,
'mark_time' => time()
);
$db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$db->sql_return_on_error(false);
}
if (sizeof($sql_ary))
{
$db->sql_query('INSERT INTO ' . FORUMS_TRACK_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
}
}
}
else
{
$tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
foreach ($forum_id as $f_id)
{
$topic_ids36 = (isset($tracking['tf'][$f_id])) ? $tracking['tf'][$f_id] : array();
unset($tracking['tf'][$f_id]);
foreach ($topic_ids36 as $topic_id36)
{
unset($tracking['t'][$topic_id36]);
}
unset($tracking['f'][$f_id]);
$tracking['f'][$f_id] = base_convert(time() - $config['board_startdate'], 10, 36);
}
$user->set_cookie('track', serialize($tracking), time() + 31536000);
unset($tracking);
}
return;
}
else if ($mode == 'topic')
{
if ($topic_id === false || $forum_id === false)
{
return;
}
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$sql = 'UPDATE ' . TOPICS_TRACK_TABLE . '
SET mark_time = ' . (($post_time) ? $post_time : time()) . "
WHERE user_id = {$user->data['user_id']}
AND topic_id = $topic_id";
$db->sql_query($sql);
// insert row
if (!$db->sql_affectedrows())
{
$db->sql_return_on_error(true);
$sql_ary = array(
'user_id' => $user->data['user_id'],
'topic_id' => $topic_id,
'forum_id' => (int) $forum_id,
'mark_time' => ($post_time) ? $post_time : time(),
);
$db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$db->sql_return_on_error(false);
}
}
else
{
$tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
$topic_id36 = base_convert($topic_id, 10, 36);
if (!isset($tracking['t'][$topic_id36]))
{
$tracking['tf'][$forum_id][$topic_id36] = true;
}
if (!$config['load_db_lastread'])
{
$tracking = array();
if (isset($_COOKIE[$config['cookie_name'] . '_track']))
{
$tracking = unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track']));
$post_time = ($post_time) ? $post_time : time();
$tracking['t'][$topic_id36] = base_convert($post_time - $config['board_startdate'], 10, 36);
// If the cookie grows larger than 2000 characters we will remove
// the smallest value
if (strlen($_COOKIE[$config['cookie_name'] . '_track']) > 2000)
// If the cookie grows larger than 5000 characters we will remove the smallest value
if (isset($_COOKIE[$config['cookie_name'] . '_track']) && strlen($_COOKIE[$config['cookie_name'] . '_track']) > 5000)
{
// echo 'Cookie grown too large' . print_r($tracking, true);
$min_value = min($tracking['t']);
$m_tkey = array_search($min_value, $t_ary);
unset($tracking['t'][$m_tkey]);
foreach ($tracking['tf'] as $f_id => $topic_id_ary)
{
if (in_array($m_tkey, array_keys($topic_id_ary)))
{
foreach ($tracking as $f => $t_ary)
{
if (!isset($m_value) || min($t_ary) < $m_value)
{
$m_value = min($t_ary);
$m_tkey = array_search($m_value, $t_ary);
$m_fkey = $f;
}
}
unset($tracking[$m_fkey][$m_tkey]);
unset($tracking['tf'][$f_id][$m_tkey]);
break;
}
}
if (isset($tracking[$forum_id]) && base_convert($tracking[$forum_id][0], 36, 10) < $current_time)
{
$tracking[$forum_id][base_convert($topic_id, 10, 36)] = base_convert($current_time - $config['board_startdate'], 10, 36);
$user->set_cookie('track', serialize($tracking), time() + 31536000);
}
else if (!isset($tracking[$forum_id]))
{
$tracking[$forum_id][0] = base_convert($current_time - $config['board_startdate'], 10, 36);
$user->set_cookie('track', serialize($tracking), time() + 31536000);
}
unset($tracking);
}
break;
$user->set_cookie('track', serialize($tracking), time() + 31536000);
}
return;
}
else if ($mode == 'post')
{
if ($topic_id === false)
{
return;
}
$db->sql_return_on_error(true);
$sql_ary = array(
'user_id' => $user->data['user_id'],
'topic_id' => $topic_id,
'topic_posted' => 1
);
$db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$db->sql_return_on_error(false);
return;
}
}
/**
* Get topic tracking info by using already fetched info
*/
function get_topic_tracking($forum_id, $topic_ids, &$rowset, $forum_mark_time, $global_announce_list = false)
{
global $config, $user;
$last_read = array();
if (!is_array($topic_ids))
{
$topic_ids = array($topic_ids);
}
foreach ($topic_ids as $topic_id)
{
if (!empty($rowset[$topic_id]['mark_time']))
{
$last_read[$topic_id] = $rowset[$topic_id]['mark_time'];
}
}
$topic_ids = array_diff($topic_ids, array_keys($last_read));
if (sizeof($topic_ids))
{
$mark_time = array();
// Get global announcement info
if ($global_announce_list && sizeof($global_announce_list))
{
if (!isset($forum_mark_time[0]))
{
global $db;
$sql = 'SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . "
WHERE user_id = {$user->data['user_id']}
AND forum_id = 0";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row)
{
$mark_time[0] = $row['mark_time'];
}
}
else
{
if ($forum_mark_time[0] !== false)
{
$mark_time[0] = $forum_mark_time[0];
}
}
}
if (!empty($forum_mark_time[$forum_id]) && $forum_mark_time[$forum_id] !== false)
{
$mark_time[$forum_id] = $forum_mark_time[$forum_id];
}
$user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $user->data['user_lastmark'];
foreach ($topic_ids as $topic_id)
{
if ($global_announce_list && isset($global_announce_list[$topic_id]))
{
$last_read[$topic_id] = (isset($mark_time[0])) ? $mark_time[0] : $user_lastmark;
}
else
{
$last_read[$topic_id] = $user_lastmark;
}
}
}
return $last_read;
}
/**
* Get topic tracking info from db (for cookie based tracking only this function is used)
*/
function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_list = false)
{
global $config, $user;
$last_read = array();
if (!is_array($topic_ids))
{
$topic_ids = array($topic_ids);
}
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
global $db;
$sql = 'SELECT topic_id, mark_time
FROM ' . TOPICS_TRACK_TABLE . "
WHERE user_id = {$user->data['user_id']}
AND topic_id IN (" . implode(', ', $topic_ids) . ")";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$last_read[$row['topic_id']] = $row['mark_time'];
}
$db->sql_freeresult($result);
$topic_ids = array_diff($topic_ids, array_keys($last_read));
if (sizeof($topic_ids))
{
$sql = 'SELECT forum_id, mark_time
FROM ' . FORUMS_TRACK_TABLE . "
WHERE user_id = {$user->data['user_id']}
AND forum_id " .
(($global_announce_list && sizeof($global_announce_list)) ? "IN (0, $forum_id)" : "= $forum_id");
$result = $db->sql_query($sql);
$mark_time = array();
while ($row = $db->sql_fetchrow($result))
{
$mark_time[$row['forum_id']] = $row['mark_time'];
}
$db->sql_freeresult($result);
$user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $user->data['user_lastmark'];
foreach ($topic_ids as $topic_id)
{
if ($global_announce_list && isset($global_announce_list[$topic_id]))
{
$last_read[$topic_id] = (isset($mark_time[0])) ? $mark_time[0] : $user_lastmark;
}
else
{
$last_read[$topic_id] = $user_lastmark;
}
}
}
}
else
{
global $tracking_topics;
if (!isset($tracking_topics) || !sizeof($tracking_topics))
{
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
}
if (!$user->data['is_registered'])
{
$user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
}
else
{
$user_lastmark = $user->data['user_lastmark'];
}
foreach ($topic_ids as $topic_id)
{
$topic_id36 = base_convert($topic_id, 10, 36);
if (isset($tracking_topics['t'][$topic_id36]))
{
$last_read[$topic_id] = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate'];
}
}
$topic_ids = array_diff($topic_ids, array_keys($last_read));
if (sizeof($topic_ids))
{
$mark_time = array();
if ($global_announce_list && sizeof($global_announce_list))
{
if (isset($tracking_topics['f'][0]))
{
$mark_time[0] = base_convert($tracking_topics['f'][0], 36, 10) + $config['board_startdate'];
}
}
if (isset($tracking_topics['f'][$forum_id]))
{
$mark_time[$forum_id] = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'];
}
$user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $user_lastmark;
foreach ($topic_ids as $topic_id)
{
if ($global_announce_list && isset($global_announce_list[$topic_id]))
{
$last_read[$topic_id] = (isset($mark_time[0])) ? $mark_time[0] : $user_lastmark;
}
else
{
$last_read[$topic_id] = $user_lastmark;
}
}
}
}
return $last_read;
}
/**
@@ -877,7 +1100,14 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo
// generate activation key
$confirm_key = gen_rand_string(10);
page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]);
if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
{
adm_page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]);
}
else
{
page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]);
}
$template->set_filenames(array(
'body' => $html_body)
@@ -908,7 +1138,14 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo
WHERE user_id = " . $user->data['user_id'];
$db->sql_query($sql);
page_footer();
if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
{
adm_page_footer();
}
else
{
page_footer();
}
}
/**
@@ -1292,11 +1529,12 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
{
if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
{
adm_page_header('', '', false);
// adm_page_header('', '', false);
adm_page_header('');
}
else
{
page_header();
page_header('');
}
}
@@ -1304,26 +1542,19 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
$msg_title = (!isset($msg_title)) ? $user->lang['INFORMATION'] : ((!empty($user->lang[$msg_title])) ? $user->lang[$msg_title] : $msg_title);
$display_header = (!isset($display_header)) ? false : (bool) $display_header;
if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
{
adm_page_message($msg_title, $msg_text, $display_header);
adm_page_footer();
}
else
{
$template->set_filenames(array(
'body' => 'message_body.html')
);
$template->set_filenames(array(
'body' => 'message_body.html')
);
$template->assign_vars(array(
'MESSAGE_TITLE' => $msg_title,
'MESSAGE_TEXT' => $msg_text)
);
$template->assign_vars(array(
'MESSAGE_TITLE' => $msg_title,
'MESSAGE_TEXT' => $msg_text)
);
// We do not want the cron script to be called on error messages
define('IN_CRON', true);
page_footer();
// We do not want the cron script to be called on error messages
define('IN_CRON', true);
page_footer();
}
exit;
break;
}
@@ -1700,6 +1931,14 @@ function page_footer()
// Tidy some table rows every week
$cron_type = 'tidy_database';
}
/**
* @todo add session garbage collection
else if (time() - $config['session_gc'] > $config['session_last_gc'])
{
$cron_type = 'tidy_sessions';
}
*/
if ($cron_type)
{

View File

@@ -11,7 +11,7 @@
/**
* Recalculate Binary Tree
*/
function recalc_btree($sql_id, $sql_table)
function recalc_btree($sql_id, $sql_table, $module_class = '')
{
global $db;
@@ -25,8 +25,29 @@ function recalc_btree($sql_id, $sql_table)
return;
}
$sql_where = ($module_class) ? " WHERE module_class = '" . $db->sql_escape($module_class) . "'" : ' WHERE 1 ';
// Reset to minimum possible left and right id
$sql = "SELECT MIN(left_id) as min_left_id, MIN(right_id) as min_right_id
FROM $sql_table
$sql_where";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$substract = (int) (min($row['min_left_id'], $row['min_right_id']) - 1);
if ($substract > 0)
{
$sql = "UPDATE $sql_table
SET left_id = left_id - $substract, right_id = right_id - $substract
$sql_where";
$db->sql_query($sql);
}
$sql = "SELECT $sql_id, parent_id, left_id, right_id
FROM $sql_table
$sql_where
ORDER BY left_id ASC, parent_id ASC, $sql_id ASC";
$f_result = $db->sql_query($sql);
@@ -36,7 +57,8 @@ function recalc_btree($sql_id, $sql_table)
{
$sql = "SELECT left_id, right_id
FROM $sql_table
WHERE $sql_id = {$item_data['parent_id']}";
$sql_where
AND $sql_id = {$item_data['parent_id']}";
$result = $db->sql_query($sql);
if (!$row = $db->sql_fetchrow($result))
@@ -48,12 +70,14 @@ function recalc_btree($sql_id, $sql_table)
$sql = "UPDATE $sql_table
SET left_id = left_id + 2, right_id = right_id + 2
WHERE left_id > {$row['right_id']}";
$sql_where
AND left_id > {$row['right_id']}";
$db->sql_query($sql);
$sql = "UPDATE $sql_table
SET right_id = right_id + 2
WHERE {$row['left_id']} BETWEEN left_id AND right_id";
$sql_where
AND {$row['left_id']} BETWEEN left_id AND right_id";
$db->sql_query($sql);
$item_data['left_id'] = $row['right_id'];
@@ -62,7 +86,8 @@ function recalc_btree($sql_id, $sql_table)
else
{
$sql = "SELECT MAX(right_id) AS right_id
FROM $sql_table";
FROM $sql_table
$sql_where";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
@@ -450,7 +475,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = TRUE)
$db->sql_transaction('begin');
$table_ary = array(TOPICS_TRACK_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE);
$table_ary = array(TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE);
foreach ($table_ary as $table)
{
$sql = "DELETE FROM $table
@@ -2335,13 +2360,13 @@ function update_post_information($type, $ids)
}
/**
* Tidy topic tracking tables
* Tidy database
* Removes all tracking rows older than 6 months, including mark_posted informations
*/
function tidy_database()
{
global $db;
/*
$remove_date = time() - (3 * 62 * 24 * 3600);
$sql = 'DELETE FROM ' . FORUMS_TRACK_TABLE . '
@@ -2351,7 +2376,7 @@ function tidy_database()
$sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . '
WHERE mark_time < ' . $remove_date;
$db->sql_query($sql);
*/
set_config('database_last_gc', time(), true);
}

View File

@@ -11,18 +11,30 @@
/**
* Display Forums
*/
function display_forums($root_data = '', $display_moderators = TRUE)
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
{
global $config, $db, $template, $auth, $user, $phpEx, $SID, $forum_moderators, $phpbb_root_path;
global $db, $auth, $user, $template;
global $phpbb_root_path, $phpEx, $SID, $config;
// Get posted/get info
$forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
$parent_id = $visible_forums = 0;
$sql_from = $lastread_select = '';
// Mark forums read?
$mark_read = request_var('mark', '');
$forum_id_ary = $active_forum_ary = $forum_rows = $subforums = $forum_moderators = $mark_forums = array();
$visible_forums = 0;
if ($mark_read == 'all')
{
$mark_read = '';
}
if (!$root_data)
{
if ($mark_read == 'forums')
{
$mark_read = 'all';
}
$root_data = array('forum_id' => 0);
$sql_where = '';
}
@@ -34,17 +46,9 @@ function display_forums($root_data = '', $display_moderators = TRUE)
// Display list of active topics for this category?
$show_active = (isset($root_data['forum_flags']) && $root_data['forum_flags'] & 16) ? true : false;
if ($config['load_db_lastread'] && $user->data['is_registered'])
if ($config['load_db_track'] && $user->data['is_registered'])
{
switch (SQL_LAYER)
{
case 'oracle':
break;
default:
$sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))';
break;
}
$sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))';
$lastread_select = ', ft.mark_time ';
}
else
@@ -53,6 +57,11 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$lastread_select = $sql_lastread = '';
$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array();
if (!$user->data['is_registered'])
{
$user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0;
}
}
$sql = "SELECT f.* $lastread_select
@@ -61,20 +70,29 @@ function display_forums($root_data = '', $display_moderators = TRUE)
ORDER BY f.left_id";
$result = $db->sql_query($sql);
$forum_tracking_info = array();
$branch_root_id = $root_data['forum_id'];
$forum_ids = array($root_data['forum_id']);
while ($row = $db->sql_fetchrow($result))
{
if ($mark_read == 'forums' && $user->data['is_registered'])
{
if ($auth->acl_get('f_list', $row['forum_id']))
{
$forum_id_ary[] = $row['forum_id'];
}
$forum_id = $row['forum_id'];
// Mark forums read?
if ($mark_read == 'forums' || $mark_read == 'all')
{
if ($auth->acl_get('f_list', $forum_id))
{
$forum_ids[] = $forum_id;
continue;
}
}
// Category with no members
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
{
continue;
}
// Skip branch
if (isset($right_id))
{
if ($row['left_id'] < $right_id)
@@ -84,14 +102,6 @@ function display_forums($root_data = '', $display_moderators = TRUE)
unset($right_id);
}
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
{
// Non-postable forum with no subforums: don't display
continue;
}
$forum_id = $row['forum_id'];
if (!$auth->acl_get('f_list', $forum_id))
{
// if the user does not have permissions to list this forum, skip everything until next branch
@@ -99,8 +109,17 @@ function display_forums($root_data = '', $display_moderators = TRUE)
continue;
}
$forum_ids[] = $forum_id;
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
$forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
}
else
{
$forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'] : $user->data['user_lastmark'];
}
// Display active topics from this forum?
if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & 16))
{
@@ -110,24 +129,26 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$active_forum_ary['forum_posts'] += $row['forum_posts'];
}
//
if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
{
// Direct child
// Direct child of current branch
$parent_id = $forum_id;
$forum_rows[$forum_id] = $row;
$forum_ids[] = $forum_id;
if (!$row['parent_id'] && $row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
{
$branch_root_id = $forum_id;
}
$forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
$forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
}
elseif ($row['forum_type'] != FORUM_CAT)
else if ($row['forum_type'] != FORUM_CAT)
{
$subforums[$parent_id]['display'] = ($row['display_on_index']) ? true : false;;
$subforums[$parent_id]['name'][$forum_id] = $row['forum_name'];
$subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
$subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
$subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
$forum_rows[$parent_id]['forum_topics'] += ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
// Do not list redirects in LINK Forums as Posts.
@@ -136,7 +157,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
}
if (isset($forum_rows[$parent_id]) && $row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
{
$forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
$forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
@@ -150,113 +171,104 @@ function display_forums($root_data = '', $display_moderators = TRUE)
}
}
if (!isset($row['mark_time']))
{
$row['mark_time'] = 0;
}
$forum_ids_moderator[$parent_id] = $forum_rows[$parent_id]['forum_id_last_post'];
$mark_time_forum = ($config['load_db_lastread']) ? $row['mark_time'] : ((isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0);
if ($mark_time_forum < $row['forum_last_post_time'] && $user->data['is_registered'])
{
$forum_unread[$parent_id] = true;
}
}
$db->sql_freeresult($result);
// Handle marking posts
if ($mark_read == 'forums')
if ($mark_read == 'forums' || $mark_read == 'all')
{
markread('mark', $forum_id_ary);
$redirect = (!empty($_SERVER['REQUEST_URI'])) ? preg_replace('#^(.*?)&(amp;)?mark=.*$#', '\1', htmlspecialchars($_SERVER['REQUEST_URI'])) : "index.$phpEx$SID";
meta_refresh(3, $redirect);
$message = (strpos($redirect, 'viewforum') !== false) ? 'RETURN_FORUM' : 'RETURN_INDEX';
$message = $user->lang['FORUMS_MARKED'] . '<br /><br />' . sprintf($user->lang[$message], '<a href="' . $redirect . '">', '</a> ');
if ($mark_read == 'all')
{
markread('all');
$message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
}
else
{
markread('topics', $forum_ids);
$message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
}
meta_refresh(3, $redirect);
$message = $user->lang['FORUMS_MARKED'] . '<br /><br />' . $message;
trigger_error($message);
}
// Grab moderators ... if necessary
if ($display_moderators)
{
get_moderators($forum_moderators, $forum_ids);
if ($return_moderators)
{
$forum_ids_moderator[] = $root_data['forum_id'];
}
get_moderators($forum_moderators, $forum_ids_moderator);
}
// Loop through the forums
$root_id = $root_data['forum_id'];
foreach ($forum_rows as $row)
{
if ($row['parent_id'] == $root_id && !$row['parent_id'])
{
if ($row['forum_type'] == FORUM_CAT)
{
$hold = $row;
continue;
}
else
{
unset($hold);
}
}
else if (!empty($hold))
// Empty category
if (!$row['parent_id'] && $row['forum_type'] == FORUM_CAT)
{
$template->assign_block_vars('forumrow', array(
'S_IS_CAT' => TRUE,
'FORUM_ID' => $hold['forum_id'],
'FORUM_NAME' => $hold['forum_name'],
'FORUM_DESC' => $hold['forum_desc'],
'U_VIEWFORUM' => "viewforum.$phpEx$SID&amp;f=" . $hold['forum_id'])
'S_IS_CAT' => true,
'FORUM_ID' => $row['forum_id'],
'FORUM_NAME' => $row['forum_name'],
'FORUM_DESC' => $row['forum_desc'],
'U_VIEWFORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=" . $row['forum_id'])
);
unset($hold);
continue;
}
$visible_forums++;
$forum_id = $row['forum_id'];
$subforums_list = $l_subforums = '';
$forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
$folder_image = $folder_alt = $subforums_list = $l_subforums = '';
// Generate list of subforums if we need to
if (isset($subforums[$forum_id]))
{
if ($subforums[$forum_id]['display'])
foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
{
$alist = array();
foreach ($subforums[$forum_id]['name'] as $sub_forum_id => $subforum_name)
// Update unread information if needed
if (!$forum_unread)
{
if (!empty($subforum_name))
{
$alist[$sub_forum_id] = $subforum_name;
}
$forum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
}
if (sizeof($alist))
if ($subforum_row['display'] && $subforum_row['name'])
{
$links = array();
foreach ($alist as $subforum_id => $subforum_name)
{
$links[] = '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $subforum_id . '">' . $subforum_name . '</a>';
}
$subforums_list = implode(', ', $links);
$l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
$subforums_list .= ($subforums_list == '') ? '' : ', ';
$subforums_list .= '<a href="' . $phpbb_root_path . "viewforum.$phpEx$SID&amp;f=$subforum_id\">{$subforum_row['name']}</a>";
}
else
{
unset($subforums[$forum_id][$subforum_id]);
}
}
$folder_image = (!empty($forum_unread[$forum_id])) ? 'sub_forum_new' : 'sub_forum';
$l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
$folder_image = ($forum_unread) ? 'sub_forum_new' : 'sub_forum';
}
else
{
switch ($row['forum_type'])
{
case FORUM_POST:
$folder_image = (!empty($forum_unread[$forum_id])) ? 'forum_new' : 'forum';
break;
$folder_image = ($forum_unread) ? 'forum_new' : 'forum';
break;
case FORUM_LINK:
$folder_image = 'forum_link';
break;
break;
}
}
@@ -268,7 +280,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
}
else
{
$folder_alt = (!empty($forum_unread[$forum_id])) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
$folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
}
// Create last post link information, if appropriate
@@ -277,9 +289,9 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$last_post_time = $user->format_date($row['forum_last_post_time']);
$last_poster = ($row['forum_last_poster_name'] != '') ? $row['forum_last_poster_name'] : $user->lang['GUEST'];
$last_poster_url = ($row['forum_last_poster_id'] == ANONYMOUS) ? '' : "memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=" . $row['forum_last_poster_id'];
$last_poster_url = ($row['forum_last_poster_id'] == ANONYMOUS) ? '' : "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['forum_last_poster_id']}";
$last_post_url = "viewtopic.$phpEx$SID&amp;f=" . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id'] . '#' . $row['forum_last_post_id'];
$last_post_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=" . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id'] . '#' . $row['forum_last_post_id'];
}
else
{
@@ -299,40 +311,44 @@ function display_forums($root_data = '', $display_moderators = TRUE)
$template->assign_block_vars('forumrow', array(
'S_IS_CAT' => false,
'S_IS_LINK' => ($row['forum_type'] != FORUM_LINK) ? false : true,
'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false,
'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'),
'FORUM_ID' => $row['forum_id'],
'FORUM_FOLDER_IMG' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $folder_alt . '" />' : $user->img($folder_image, $folder_alt),
'FORUM_ID' => $row['forum_id'],
'FORUM_NAME' => $row['forum_name'],
'FORUM_DESC' => $row['forum_desc'],
'TOPICS' => $row['forum_topics'],
$l_post_click_count => $post_click_count,
'FORUM_FOLDER_IMG' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['folder_alt'] . '" />' : $user->img($folder_image, $folder_alt),
'FORUM_FOLDER_IMG_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : $user->img($folder_image, $folder_alt, false, '', 'src'),
'FORUM_NAME' => $row['forum_name'],
'FORUM_DESC' => $row['forum_desc'],
$l_post_click_count => $post_click_count,
'TOPICS' => $row['forum_topics'],
'LAST_POST_TIME' => $last_post_time,
'LAST_POSTER' => $last_poster,
'MODERATORS' => $moderators_list,
'SUBFORUMS' => $subforums_list,
'SUBFORUMS' => $subforums_list,
'LAST_POST_TIME' => $last_post_time,
'LAST_POSTER' => $last_poster,
'MODERATORS' => $moderators_list,
'L_SUBFORUM_STR' => $l_subforums,
'L_MODERATOR_STR' => $l_moderator,
'L_FORUM_FOLDER_ALT'=> $folder_alt,
'L_MODERATOR_STR' => $l_moderator,
'U_VIEWFORUM' => ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1) ? "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f={$row['forum_id']}" : $row['forum_link'],
'U_LAST_POSTER' => $last_poster_url,
'U_LAST_POST' => $last_post_url,
'U_VIEWFORUM' => ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1) ? "viewforum.$phpEx$SID&amp;f=" . $row['forum_id'] : $row['forum_link'])
)
);
}
$template->assign_vars(array(
'U_MARK_FORUMS' => "viewforum.$phpEx$SID&amp;f=" . $root_data['forum_id'] . '&amp;mark=forums',
'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'])
'U_MARK_FORUMS' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=" . $root_data['forum_id'] . '&amp;mark=forums',
'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'),
)
);
if ($return_moderators)
{
return array($active_forum_ary, $forum_moderators);
}
return $active_forum_ary;
}
@@ -509,33 +525,33 @@ function topic_generate_pagination($replies, $url)
*/
function get_moderators(&$forum_moderators, $forum_id = false)
{
global $config, $template, $db, $phpEx, $SID;
global $config, $template, $db, $phpbb_root_path, $phpEx, $SID;
// Have we disabled the display of moderators? If so, then return
// from whence we came ...
if (empty($config['load_moderators']))
if (!$config['load_moderators'])
{
return;
}
if (!empty($forum_id) && is_array($forum_id))
if ($forum_id !== false && is_array($forum_id))
{
$forum_sql = 'AND forum_id IN (' . implode(', ', $forum_id) . ')';
}
else
{
$forum_sql = ($forum_id) ? 'AND forum_id = ' . $forum_id : '';
$forum_sql = ($forum_id !== false) ? 'AND forum_id = ' . $forum_id : '';
}
$sql = 'SELECT *
FROM ' . MODERATOR_TABLE . "
WHERE display_on_index = 1
$forum_sql";
$result = $db->sql_query($sql);
$result = $db->sql_query($sql, 3600);
while ($row = $db->sql_fetchrow($result))
{
$forum_moderators[$row['forum_id']][] = (!empty($row['user_id'])) ? '<a href="memberlist.' . $phpEx . $SID . '&amp;mode=viewprofile&amp;u=' . $row['user_id'] . '">' . $row['username'] . '</a>' : '<a href="memberlist.' . $phpEx . $SID . '&amp;mode=group&amp;g=' . $row['group_id'] . '">' . $row['groupname'] . '</a>';
$forum_moderators[$row['forum_id']][] = (!empty($row['user_id'])) ? '<a href="' . $phpbb_root_path . "memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=" . $row['user_id'] . '">' . $row['username'] . '</a>' : '<a href="' . $phpbb_root_path . "memberlist.$phpEx$SID&amp;mode=group&amp;g=" . $row['group_id'] . '">' . $row['groupname'] . '</a>';
}
$db->sql_freeresult($result);
@@ -568,12 +584,11 @@ function gen_forum_auth_level($mode, $forum_id)
/**
* Generate topic status
*/
function topic_status(&$topic_row, $replies, $mark_time_topic, $mark_time_forum, &$folder_img, &$folder_alt, &$topic_type)
function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
{
global $user, $config;
$folder = $folder_new = '';
$unread_topic = false;
if ($topic_row['topic_status'] == ITEM_MOVED)
{
@@ -619,34 +634,11 @@ function topic_status(&$topic_row, $replies, $mark_time_topic, $mark_time_forum,
$folder_new = 'folder_locked_new';
}
if ($user->data['is_registered'])
{
$unread_topic = $new_votes = true;
if ($mark_time_topic >= $topic_row['topic_last_post_time'] || $mark_time_forum >= $topic_row['topic_last_post_time']) //|| ($topic_row['topic_last_post_time'] == $topic_row['poll_last_vote'] && $replies))
{
$unread_topic = false;
}
/*
if ($topic_row['poll_start'] && ($mark_time_topic >= $topic_row['poll_last_vote'] || $mark_time_forum >= $topic_row['poll_last_vote']))
{
$new_votes = false;
}
*/
}
else
{
$unread_topic = false;
//$unread_topic = $new_votes = false;
}
// $folder_new .= ($new_votes) ? '_vote' : '';
$folder_img = ($unread_topic) ? $folder_new : $folder;
$folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
// Posted image?
if (!empty($topic_row['mark_type']))
if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
{
$folder_img .= '_posted';
}
@@ -656,8 +648,6 @@ function topic_status(&$topic_row, $replies, $mark_time_topic, $mark_time_forum,
{
$topic_type .= $user->lang['VIEW_TOPIC_POLL'];
}
return $unread_topic;
}
/**

View File

@@ -105,7 +105,11 @@ class p_master
foreach ($this->module_cache['modules'] as $row)
{
// Authorisation is required ... not authed, skip
/**
* Authorisation is required ... not authed, skip
* @todo implement $this->is_module_id
* @todo put in seperate method for authentication
*/
if ($row['module_auth'])
{
$is_auth = false;
@@ -141,7 +145,7 @@ class p_master
$right = $row['right_id'];
$module_data = array(
$this->module_ary[$i] = array(
'depth' => $depth,
'id' => (int) $row['module_id'],
@@ -151,15 +155,13 @@ class p_master
'name' => (string) $row['module_name'],
'mode' => (string) $row['module_mode'],
'lang' => (function_exists($row['module_name'])) ? $row['module_name']($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : ucfirst(str_replace('_', ' ', strtolower($row['module_langname'])))),
'lang' => (function_exists($row['module_name'])) ? $row['module_name']($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']),
'langname' => $row['module_langname'],
'left' => $row['left_id'],
'right' => $row['right_id'],
);
$this->module_ary[$i] = $module_data;
$i++;
}
@@ -274,9 +276,7 @@ class p_master
function assign_tpl_vars($module_url)
{
global $template, $db;
$parents = $this->module_cache['parents'];
global $template;
$current_padding = $current_depth = 0;
$linear_offset = 'l_block1';
@@ -305,13 +305,13 @@ class p_master
}
// Only output a categories items if it's currently selected
if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($parents)) || $itep_ary['parent'] == $this->p_parent)))
if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($this->module_cache['parents'])) || $itep_ary['parent'] == $this->p_parent)))
{
$use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset;
$tpl_ary = array(
'L_TITLE' => $itep_ary['lang'],
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($parents)) || $itep_ary['id'] == $this->p_id) ? true : false,
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($this->module_cache['parents'])) || $itep_ary['id'] == $this->p_id) ? true : false,
'U_TITLE' => $module_url . '&amp;i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&amp;mode=' . $itep_ary['mode'])
);
@@ -320,7 +320,7 @@ class p_master
$tpl_ary = array(
'L_TITLE' => $itep_ary['lang'],
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($parents)) || $itep_ary['id'] == $this->p_id) ? true : false,
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($this->module_cache['parents'])) || $itep_ary['id'] == $this->p_id) ? true : false,
'U_TITLE' => $module_url . '&amp;i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&amp;mode=' . $itep_ary['mode'])
);

View File

@@ -66,7 +66,7 @@ function user_get_id_name(&$user_id_ary, &$username_ary)
*/
function user_update_name($old_name, $new_name)
{
global $config, $db;
global $config, $db, $cache;
$update_ary = array(
FORUMS_TABLE => array('forum_last_poster_name'),
@@ -176,7 +176,7 @@ function user_delete($mode, $user_id)
break;
}
$table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, FORUMS_TRACK_TABLE);
$table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE);
foreach ($table_ary as $table)
{

View File

@@ -43,8 +43,6 @@ class session
$this->time_now = time();
$this->browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : '';
// $this->page = (!empty($_SERVER['REQUEST_URI'])) ? preg_replace('#/?' . preg_quote($config['script_path'], '#') . '/?([a-z]+?\.' . $phpEx . '\?)sid=[a-z0-9]*(.*?)$#i', '\1\2', $_SERVER['REQUEST_URI']) . ((isset($_POST['f'])) ? 'f=' . intval($_POST['f']) : '') : '';
$this->page = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] . ((isset($_POST['f'])) ? 'f=' . intval($_POST['f']) : '') : '';
$sid = substr($this->page, strpos($this->page, 'sid='), 36);
$this->page = str_replace(array('/' . $config['script_path'] . '/', (strlen($sid) == 36 && strpos($sid, '&') === false) ? $sid : 'sid='), '', $this->page);
@@ -175,8 +173,7 @@ class session
foreach ($active_bots as $row)
{
// if ($row['bot_agent'] && preg_match('#' . preg_quote($row['bot_agent'], '#') . '#i', $this->browser))
if ($row['bot_agent'] && strpos($this->browser, $row['bot_agent']) !== false)
if ($row['bot_agent'] && strpos(strtolower($this->browser), strtolower($row['bot_agent'])) !== false)
{
$bot = $row['user_id'];
}
@@ -270,7 +267,7 @@ class session
$this->data = array_merge($sdata, $this->data);
unset($sdata);
$this->session_id = $this->data['session_id'];
}
}
$db->sql_freeresult($result);
$this->data['session_last_visit'] = (isset($this->data['session_time']) && $this->data['session_time']) ? $this->data['session_time'] : (($this->data['user_lastvisit']) ? $this->data['user_lastvisit'] : time());
@@ -440,11 +437,18 @@ class session
* data before those sessions are destroyed. In addition this method
* removes autologin key information that is older than an admin defined
* limit.
*
* @todo add to cron
*/
function session_gc()
{
global $db, $config;
if (!$this->time_now)
{
$this->time_now = time();
}
switch (SQL_LAYER)
{
case 'mysql4':
@@ -531,6 +535,13 @@ class session
break;
}
if (!empty($config['max_autologin_time']))
{
$sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
WHERE last_login < ' . (time() - (86400 * (int) $config['max_autologin_time']));
$db->sql_query($sql);
}
return;
}
@@ -611,7 +622,7 @@ class session
if ($this->data['user_id'] != ANONYMOUS)
{
$this->session_kill();
}
}
// Determine which message to output
$till_date = (!empty($ban_row['ban_end'])) ? $this->format_date($ban_row['ban_end']) : '';
$message = (!empty($ban_row['ban_end'])) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM';
@@ -666,25 +677,6 @@ class session
return false;
}
/**
* Remove stale login keys
*
* @private
*/
function tidy_login_keys()
{
global $config, $db;
if (!empty($config['max_autologin_time']))
{
$sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
WHERE last_login < ' . (time() - (86400 * (int) $config['max_autologin_time']));
$db->sql_query($sql);
}
return false;
}
}

View File

@@ -32,6 +32,7 @@ class ucp_main
$user->add_lang('memberlist');
/*
if ($config['load_db_lastread'] || $config['load_db_track'])
{
if ($config['load_db_lastread'])
@@ -75,6 +76,23 @@ class ucp_main
{
$forum_check = (isset($tracking_topics[0][0])) ? base_convert($tracking_topics[0][0], 36, 10) + $config['board_startdate'] : 0;
}
*/
$sql_from = TOPICS_TABLE . ' t ';
$sql_select = '';
if ($config['load_db_track'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
AND tp.user_id = ' . $user->data['user_id'] . ')';
$sql_select .= ', tp.topic_posted';
}
if ($config['load_db_lastread'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
AND tt.user_id = ' . $user->data['user_id'] . ')';
$sql_select .= ', tt.mark_time';
}
$topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
$folder = 'folder_announce';
@@ -108,11 +126,25 @@ class ucp_main
ORDER BY t.topic_last_post_time DESC';
$result = $db->sql_query($sql);
$topic_list = $rowset = array();
while ($row = $db->sql_fetchrow($result))
{
$topic_list[] = $row['topic_id'];
$rowset[$row['topic_id']] = $row;
}
$db->sql_freeresult($result);
$topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, array(0 => false), $topic_list);
foreach ($topic_list as $topic_id)
{
$row = &$rowset[$topic_id];
$forum_id = $row['forum_id'];
$topic_id = $row['topic_id'];
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
if ($row['topic_status'] == ITEM_LOCKED)
{
$topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
@@ -120,38 +152,20 @@ class ucp_main
$folder_new = 'folder_locked_new';
}
$unread_topic = true;
if ($config['load_db_lastread'])
{
$topic_check = $row['mark_time'];
}
else
{
$topic_id36 = base_convert($topic_id, 10, 36);
$topic_check = (isset($tracking_topics[0][$topic_id36])) ? base_convert($tracking_topics[0][$topic_id36], 36, 10) + $config['board_startdate'] : 0;
}
if ($topic_check >= $row['topic_last_post_time'] || $forum_check >= $row['topic_last_post_time'])
{
$unread_topic = false;
}
$newest_post_img = ($unread_topic) ? "<a href=\"viewtopic.$phpEx$SID&amp;f=$g_forum_id&amp;t=$topic_id&amp;view=unread#unread\">" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : '';
$newest_post_img = ($unread_topic) ? "<a href=\"{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=$g_forum_id&amp;t=$topic_id&amp;view=unread#unread\">" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : '';
$folder_img = ($unread_topic) ? $folder_new : $folder;
$folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
// Posted image?
if (!empty($row['mark_type']))
if (!empty($row['topic_posted']) && $row['topic_posted'])
{
$folder_img .= '_posted';
}
$view_topic_url = "viewtopic.$phpEx$SID&amp;f=$g_forum_id&amp;t=$topic_id";
$view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=$g_forum_id&amp;t=$topic_id";
$last_post_img = "<a href=\"{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=$g_forum_id&amp;t=$topic_id&amp;p=" . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'] . '">' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . '</a>';
$last_post_img = "<a href=\"viewtopic.$phpEx$SID&amp;f=$g_forum_id&amp;t=$topic_id&amp;p=" . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'] . '">' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . '</a>';
$last_post_author = ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : "<a href=\"memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=" . $row['topic_last_poster_id'] . '">' . $row['topic_last_poster_name'] . '</a>';
$last_post_author = ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : "<a href=\"{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=" . $row['topic_last_poster_id'] . '">' . $row['topic_last_poster_name'] . '</a>';
$template->assign_block_vars('topicrow', array(
'FORUM_ID' => $forum_id,
@@ -166,12 +180,11 @@ class ucp_main
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', '') : '',
'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false,
'S_USER_POSTED' => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
'U_VIEW_TOPIC' => $view_topic_url)
);
}
$db->sql_freeresult($result);
$post_count_ary = $auth->acl_getf('f_postcount');
@@ -328,15 +341,7 @@ class ucp_main
if ($config['load_db_lastread'])
{
switch (SQL_LAYER)
{
case 'oracle':
break;
default:
$sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))';
break;
}
$sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))';
$lastread_select = ', ft.mark_time ';
}
else
@@ -358,14 +363,17 @@ class ucp_main
{
$forum_id = $row['forum_id'];
$unread_forum = false;
$forum_check = (!$config['load_db_lastread']) ? $tracking_topics[$forum_id][0] : $row['mark_time'];
if ($forum_check < $row['forum_last_post_time'])
if ($config['load_db_lastread'])
{
$unread_forum = true;
$forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
}
else
{
$forum_check = (isset($tracking_topics['f'][$forum_id])) ? base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'] : $user->data['user_lastmark'];
}
$unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
// Which folder should we display?
if ($row['forum_status'] == ITEM_LOCKED)
{
@@ -429,12 +437,35 @@ class ucp_main
);
}
/*
$sql_from = ($config['load_db_lastread'] || $config['load_db_track']) ? '(' . TOPICS_TABLE . ' t LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . '))' : TOPICS_TABLE . ' t';
$sql_f_tracking = ($config['load_db_lastread']) ? 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id'] . ')' : '';
$sql_t_select = ($config['load_db_lastread'] || $config['load_db_track']) ? ', tt.mark_type, tt.mark_time' : '';
$sql_f_select = ($config['load_db_lastread']) ? ', ft.mark_time AS forum_mark_time' : '';
*/
$sql_f_tracking = ($config['load_db_lastread']) ? 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id'] . ')' : '';
$sql_f_select = ($config['load_db_lastread']) ? ', ft.mark_time AS forum_mark_time' : '';
$sql_from = TOPICS_TABLE . ' t';
$sql_t_select = '';
if ($config['load_db_track'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
AND tp.user_id = ' . $user->data['user_id'] . ')';
$sql_t_select .= ', tp.topic_posted';
}
if ($config['load_db_lastread'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
AND tt.user_id = ' . $user->data['user_id'] . ')';
$sql_t_select .= ', tt.mark_time';
}
$sql = "SELECT t.* $sql_f_select $sql_t_select
FROM $sql_from $sql_f_tracking, " . TOPICS_WATCH_TABLE . ' tw
WHERE tw.user_id = ' . $user->data['user_id'] . '
@@ -442,24 +473,32 @@ class ucp_main
ORDER BY t.topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
$topic_list = $global_announce_list = $rowset = array();
while ($row = $db->sql_fetchrow($result))
{
$topic_id = $row['topic_id'];
$forum_id = $row['forum_id'];
if ($config['load_db_lastread'])
{
$mark_time_topic = ($user->data['is_registered']) ? $row['mark_time'] : 0;
$mark_time_forum = $row['forum_mark_time'];
}
else
{
$topic_id36 = base_convert($topic_id, 10, 36);
$forum_id36 = ($row['topic_type'] == POST_GLOBAL) ? 0 : $forum_id;
$mark_time_topic = (isset($tracking_topics[$forum_id36][$topic_id36])) ? base_convert($tracking_topics[$forum_id36][$topic_id36], 36, 10) + $config['board_startdate'] : 0;
$topic_list[] = $row['topic_id'];
$rowset[$row['topic_id']] = $row;
$mark_time_forum = (isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0;
if ($row['topic_type'] == POST_GLOBAL)
{
$global_announce_list[] = $row['topic_id'];
}
}
$db->sql_freeresult($result);
/**
* @todo get_topic_tracking able to fetch from multiple forums
*/
$topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, array(0 => false), $global_announce_list);
foreach ($topic_list as $topic_id)
{
$row = &$rowset[$topic_id];
$forum_id = $row['forum_id'];
$topic_id = $row['topic_id'];
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
// Replies
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
@@ -471,7 +510,7 @@ class ucp_main
// Get folder img, topic status/type related informations
$folder_img = $folder_alt = $topic_type = '';
$unread_topic = topic_status($row, $replies, $mark_time_topic, $mark_time_forum, $folder_img, $folder_alt, $topic_type);
topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
$newest_post_img = ($unread_topic) ? "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=$topic_id&amp;view=unread#unread\">" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : '';
@@ -502,7 +541,7 @@ class ucp_main
'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
'S_TOPIC_TYPE' => $row['topic_type'],
'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false,
'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
'S_UNREAD_TOPIC' => $unread_topic,
'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'],

View File

@@ -245,6 +245,7 @@ class ucp_register
'user_actkey' => $user_actkey,
'user_ip' => $user->ip,
'user_regdate' => time(),
'user_lastmark' => time(),
);
$sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);