mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-24 03:54:10 +01:00
[ticket/8796] Make function markread obey the $post_time argument
Also do a little cleanup of the markread function PHPBB3-8796
This commit is contained in:
parent
7bf598954c
commit
815cc4a9a3
@ -1280,6 +1280,10 @@ function phpbb_timezone_select($user, $default = '', $truncate = false)
|
|||||||
* Marks a topic/forum as read
|
* Marks a topic/forum as read
|
||||||
* Marks a topic as posted to
|
* Marks a topic as posted to
|
||||||
*
|
*
|
||||||
|
* @param string $mode (all, topics, topic, post)
|
||||||
|
* @param int|bool $forum_id Used in all, topics, and topic mode
|
||||||
|
* @param int|bool $topic_id Used in topic and post mode
|
||||||
|
* @param int $post_time 0 means current time(), otherwise to set a specific mark time
|
||||||
* @param int $user_id can only be used with $mode == 'post'
|
* @param int $user_id can only be used with $mode == 'post'
|
||||||
*/
|
*/
|
||||||
function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $user_id = 0)
|
function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $user_id = 0)
|
||||||
@ -1287,6 +1291,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
global $db, $user, $config;
|
global $db, $user, $config;
|
||||||
global $request;
|
global $request;
|
||||||
|
|
||||||
|
$post_time = ($post_time === 0) ? time() : (int) $post_time;
|
||||||
|
|
||||||
if ($mode == 'all')
|
if ($mode == 'all')
|
||||||
{
|
{
|
||||||
if ($forum_id === false || !sizeof($forum_id))
|
if ($forum_id === false || !sizeof($forum_id))
|
||||||
@ -1294,9 +1300,22 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
if ($config['load_db_lastread'] && $user->data['is_registered'])
|
if ($config['load_db_lastread'] && $user->data['is_registered'])
|
||||||
{
|
{
|
||||||
// Mark all forums read (index page)
|
// Mark all forums read (index page)
|
||||||
$db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}");
|
$tables = array(TOPICS_TRACK_TABLE, FORUMS_TRACK_TABLE);
|
||||||
$db->sql_query('DELETE FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}");
|
foreach ($tables as $table)
|
||||||
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}");
|
{
|
||||||
|
$sql = 'DELETE FROM ' . $table . "
|
||||||
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < . $post_time";
|
||||||
|
$db->sql_query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'UPDATE ' . USERS_TABLE . "
|
||||||
|
SET user_lastmark = $post_time
|
||||||
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < $post_time";
|
||||||
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
$user->data['user_lastmark'] = $post_time;
|
||||||
}
|
}
|
||||||
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
|
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
|
||||||
{
|
{
|
||||||
@ -1306,16 +1325,22 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
unset($tracking_topics['tf']);
|
unset($tracking_topics['tf']);
|
||||||
unset($tracking_topics['t']);
|
unset($tracking_topics['t']);
|
||||||
unset($tracking_topics['f']);
|
unset($tracking_topics['f']);
|
||||||
$tracking_topics['l'] = base_convert(time() - $config['board_startdate'], 10, 36);
|
$tracking_topics['l'] = base_convert($post_time - $config['board_startdate'], 10, 36);
|
||||||
|
|
||||||
$user->set_cookie('track', tracking_serialize($tracking_topics), time() + 31536000);
|
$user->set_cookie('track', tracking_serialize($tracking_topics), $post_time + 31536000);
|
||||||
$request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking_topics), phpbb_request_interface::COOKIE);
|
$request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking_topics), phpbb_request_interface::COOKIE);
|
||||||
|
|
||||||
unset($tracking_topics);
|
unset($tracking_topics);
|
||||||
|
|
||||||
if ($user->data['is_registered'])
|
if ($user->data['is_registered'])
|
||||||
{
|
{
|
||||||
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}");
|
$sql = 'UPDATE ' . USERS_TABLE . "
|
||||||
|
SET user_lastmark = $post_time
|
||||||
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < $post_time";
|
||||||
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
$user->data['user_lastmark'] = $post_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1337,12 +1362,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
{
|
{
|
||||||
$sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . "
|
$sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . "
|
||||||
WHERE user_id = {$user->data['user_id']}
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < $post_time
|
||||||
AND " . $db->sql_in_set('forum_id', $forum_id);
|
AND " . $db->sql_in_set('forum_id', $forum_id);
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
$sql = 'SELECT forum_id
|
$sql = 'SELECT forum_id
|
||||||
FROM ' . FORUMS_TRACK_TABLE . "
|
FROM ' . FORUMS_TRACK_TABLE . "
|
||||||
WHERE user_id = {$user->data['user_id']}
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < $post_time
|
||||||
AND " . $db->sql_in_set('forum_id', $forum_id);
|
AND " . $db->sql_in_set('forum_id', $forum_id);
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
@ -1355,9 +1382,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
|
|
||||||
if (sizeof($sql_update))
|
if (sizeof($sql_update))
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE ' . FORUMS_TRACK_TABLE . '
|
$sql = 'UPDATE ' . FORUMS_TRACK_TABLE . "
|
||||||
SET mark_time = ' . time() . "
|
SET mark_time = $post_time
|
||||||
WHERE user_id = {$user->data['user_id']}
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < $post_time
|
||||||
AND " . $db->sql_in_set('forum_id', $sql_update);
|
AND " . $db->sql_in_set('forum_id', $sql_update);
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
}
|
}
|
||||||
@ -1370,7 +1398,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
$sql_ary[] = array(
|
$sql_ary[] = array(
|
||||||
'user_id' => (int) $user->data['user_id'],
|
'user_id' => (int) $user->data['user_id'],
|
||||||
'forum_id' => (int) $f_id,
|
'forum_id' => (int) $f_id,
|
||||||
'mark_time' => time()
|
'mark_time' => $post_time,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1401,7 +1429,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
unset($tracking['f'][$f_id]);
|
unset($tracking['f'][$f_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tracking['f'][$f_id] = base_convert(time() - $config['board_startdate'], 10, 36);
|
$tracking['f'][$f_id] = base_convert($post_time - $config['board_startdate'], 10, 36);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($tracking['tf']) && empty($tracking['tf']))
|
if (isset($tracking['tf']) && empty($tracking['tf']))
|
||||||
@ -1409,7 +1437,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
unset($tracking['tf']);
|
unset($tracking['tf']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->set_cookie('track', tracking_serialize($tracking), time() + 31536000);
|
$user->set_cookie('track', tracking_serialize($tracking), $post_time + 31536000);
|
||||||
$request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking), phpbb_request_interface::COOKIE);
|
$request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking), phpbb_request_interface::COOKIE);
|
||||||
|
|
||||||
unset($tracking);
|
unset($tracking);
|
||||||
@ -1426,9 +1454,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
|
|
||||||
if ($config['load_db_lastread'] && $user->data['is_registered'])
|
if ($config['load_db_lastread'] && $user->data['is_registered'])
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE ' . TOPICS_TRACK_TABLE . '
|
$sql = 'UPDATE ' . TOPICS_TRACK_TABLE . "
|
||||||
SET mark_time = ' . (($post_time) ? $post_time : time()) . "
|
SET mark_time = $post_time
|
||||||
WHERE user_id = {$user->data['user_id']}
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < $post_time
|
||||||
AND topic_id = $topic_id";
|
AND topic_id = $topic_id";
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
@ -1441,7 +1470,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
'user_id' => (int) $user->data['user_id'],
|
'user_id' => (int) $user->data['user_id'],
|
||||||
'topic_id' => (int) $topic_id,
|
'topic_id' => (int) $topic_id,
|
||||||
'forum_id' => (int) $forum_id,
|
'forum_id' => (int) $forum_id,
|
||||||
'mark_time' => ($post_time) ? (int) $post_time : time(),
|
'mark_time' => $post_time,
|
||||||
);
|
);
|
||||||
|
|
||||||
$db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
$db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
||||||
@ -1461,7 +1490,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
$tracking['tf'][$forum_id][$topic_id36] = true;
|
$tracking['tf'][$forum_id][$topic_id36] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_time = ($post_time) ? $post_time : time();
|
|
||||||
$tracking['t'][$topic_id36] = base_convert($post_time - $config['board_startdate'], 10, 36);
|
$tracking['t'][$topic_id36] = base_convert($post_time - $config['board_startdate'], 10, 36);
|
||||||
|
|
||||||
// If the cookie grows larger than 10000 characters we will remove the smallest value
|
// If the cookie grows larger than 10000 characters we will remove the smallest value
|
||||||
@ -1496,8 +1524,13 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
|
|
||||||
if ($user->data['is_registered'])
|
if ($user->data['is_registered'])
|
||||||
{
|
{
|
||||||
$user->data['user_lastmark'] = intval(base_convert(max($time_keys) + $config['board_startdate'], 36, 10));
|
$sql = 'UPDATE ' . USERS_TABLE . "
|
||||||
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . $user->data['user_lastmark'] . " WHERE user_id = {$user->data['user_id']}");
|
SET user_lastmark = $post_time
|
||||||
|
WHERE user_id = {$user->data['user_id']}
|
||||||
|
AND mark_time < $post_time";
|
||||||
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
$user->data['user_lastmark'] = $post_time;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1505,7 +1538,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->set_cookie('track', tracking_serialize($tracking), time() + 31536000);
|
$user->set_cookie('track', tracking_serialize($tracking), $post_time + 31536000);
|
||||||
$request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking), phpbb_request_interface::COOKIE);
|
$request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking), phpbb_request_interface::COOKIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1527,7 +1560,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
|
|||||||
$sql_ary = array(
|
$sql_ary = array(
|
||||||
'user_id' => (int) $use_user_id,
|
'user_id' => (int) $use_user_id,
|
||||||
'topic_id' => (int) $topic_id,
|
'topic_id' => (int) $topic_id,
|
||||||
'topic_posted' => 1
|
'topic_posted' => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
$db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
$db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user