parasolx wrote:where should i put this code? and how to make it shows the number of topic in the template?
I intended to leave that to you to work out
If you want the view unread posts link at the top of index (for prosilver) and at the top of every page (for subsilver2) to read something like "View your unread posts (3 unread post(s) in 2 topic(s)) you can do the following (but
please remember that on larger boards doing this may weigh things down so use only if you don't experience too much of a performance drag):
Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
includes/functions_view_or_mark_unread_posts.php
#
#-----[ FIND ]------------------------------------------
#
?>
#
#-----[ BEFORE, ADD ]------------------------------------------
#
/**
* checks and returns the number of posts the user has not read.
* Takes a single parameter, which is an array of forum_ids identifying the forums in which the
* function will check for unreads. If no parameter is passed to the forum, checks
* in all forums as well as in forum_id 0 (globals).
*/
function check_post_unread_count($forum_ids = array())
{
global $db, $auth, $user;
if (!$forum_ids)
{
// $forum_ids was not passed to the function, so include forum_id 0 (globals)
// in the list and then look up and include all other forums the user is authorized to read
$forum_ids[] = 0;
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if ($auth->acl_get('f_read', $row['forum_id']))
{
$forum_ids[] = $row['forum_id'];
}
}
$db->sql_freeresult($result);
}
// now count the posts with post time after each of the relevant times
$sql = 'SELECT COUNT(p.post_id) as count
FROM ' . POSTS_TABLE . ' p
LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (p.forum_id = ft.forum_id AND ft.user_id = ' . $user->data['user_id'] . ')
LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (p.topic_id = tt.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')
WHERE
(
p.post_time > tt.mark_time
OR (tt.mark_time IS NULL AND p.post_time > ft.mark_time)
OR (ft.mark_time IS NULL AND p.post_time > ' . $user->data['user_lastmark'] . ')
)
AND ' . $db->sql_in_set('p.forum_id', $forum_ids);
$result = $db->sql_query($sql);
$unread_post_count = $db->sql_fetchfield('count', false, $result);
$db->sql_freeresult($result);
return $unread_post_count;
}
/**
* checks and returns the number of topics that include posts the user has not read.
* Takes a single parameter, which is an array of forum_ids identifying the forums in which the
* function will check for unreads. If no parameter is passed to the function, checks
* in all forums as well as in forum_id 0 (globals).
*/
function check_topic_unread_count($forum_ids = array())
{
global $db, $auth, $user;
if (!$forum_ids)
{
// $forum_ids was not passed to the function, so include forum_id 0 (globals)
// in the list and then look up and include all other forums the user is authorized to read
$forum_ids[] = 0;
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if ($auth->acl_get('f_read', $row['forum_id']))
{
$forum_ids[] = $row['forum_id'];
}
}
$db->sql_freeresult($result);
}
// now count the topics with topic_last_post_time after each of the relevant times
$sql = 'SELECT COUNT(t.topic_id) as count
FROM ' . TOPICS_TABLE . ' t
LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (t.forum_id = ft.forum_id AND ft.user_id = ' . $user->data['user_id'] . ')
LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (t.topic_id = tt.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')
WHERE
(
t.topic_last_post_time > tt.mark_time
OR (tt.mark_time IS NULL AND t.topic_last_post_time > ft.mark_time)
OR (ft.mark_time IS NULL AND t.topic_last_post_time > ' . $user->data['user_lastmark'] . ')
)
AND ' . $db->sql_in_set('t.forum_id', $forum_ids);
$result = $db->sql_query($sql);
$unread_topic_count = $db->sql_fetchfield('count', false, $result);
$db->sql_freeresult($result);
return $unread_topic_count;
}
#
#-----[ OPEN ]------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
'S_INC_UNREAD_LINK' => $s_inc_unread_link,
#
#-----[ AFTER, ADD ]------------------------------------------
#
'NUMBER_UNREAD_POSTS' => check_post_unread_count(),
'NUMBER_UNREAD_TOPICS' => check_topic_unread_count(),
#
#-----[ OPEN ]------------------------------------------
#
language/en/common.php
#
#-----[ FIND ]------------------------------------------
#
'RETURN_INBOX' => 'Return to pm inbox',
#
#-----[ AFTER, ADD ]------------------------------------------
#
'UNREAD_POSTS' => ' unread post(s) in ',
'UNREAD_TOPICS' => ' topic(s)',
// end mod view or mark unread posts
#
#-----[ OPEN ]------------------------------------------
#
styles/prosilver/template/index_body.html
#
#-----[ FIND ]------------------------------------------
#
<!-- IF S_INC_UNREAD_LINK --><!-- IF S_EXISTS_UNREADS --> • <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS}</a><!-- ELSE --> • <a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF --><!-- ENDIF -->
REPLACE WITH
<!-- IF S_INC_UNREAD_LINK --><!-- IF S_EXISTS_UNREADS --> • <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS} ({NUMBER_UNREAD_POSTS}{L_UNREAD_POSTS}{NUMBER_UNREAD_TOPICS}{L_UNREAD_TOPICS})</a><!-- ELSE --> • <a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF --><!-- ENDIF -->
#
#-----[ OPEN ]------------------------------------------
#
styles/subsilver2/template/overall_header.html
#
#-----[ FIND ]------------------------------------------
# note: actual line is much longer
<span style="float: {S_CONTENT_FLOW_END};"><a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}
#
#-----[ IN-LINE FIND ]------------------------------------------
#
<!-- IF S_INC_UNREAD_LINK --><!-- IF S_EXISTS_UNREADS --> | <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS}</a>
#
#-----[ IN-LINE REPLACE WITH ]------------------------------------------
#
<!-- IF S_INC_UNREAD_LINK --><!-- IF S_EXISTS_UNREADS --> | <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS} ({NUMBER_UNREAD_POSTS}{L_UNREAD_POSTS}{NUMBER_UNREAD_TOPICS}{L_UNREAD_TOPICS})</a>
If you don't want both the unread posts and the unread topics you can leave the irrelevant parts out. And you can tinker further to distinguish between a single versus multiple unread posts and unread topics (where the text would read, for example, 1 unread post in 1 topic (and 2 unread posts in 2 topics) rather than using the awkward 'post(s)' and 'topic(s)' formulation. Or, you might want to just show the number of topics in parenthesis without any text like this: View your unread posts(4). But I leave those details to you to work out