View or mark unread posts

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in the Customisations Database.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTICE: This forum is only for the announcement of new releases and/or updates of MODs. Any MOD support should be obtained through the Customisations Database in the support area designated for each MOD.

A direct link to support for each MOD is in the first post of the respective topic.
Locked
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: View or mark unread posts

Post by asinshesq » Fri Dec 26, 2008 8:10 pm

asinshesq wrote:Please do not use the upgrade from 1.0..4 to 1.0.5b script that I included in my latest upload...I found a few mistakes in the update script for viewtopic.php, functions_display.php and the subsilver style changes that I need to clean up first. But the basic 1.0.5b install seems to be stable and working fine.
I just uploaded a new package that is still version 1.0.5b but that has the upgrade script corrected, so anyone who wants to give this a try is more than welcome. The download link is in this post: http://www.phpbb.com/community/viewtopi ... 5#p8021335

I plan to submit this for validation in about a week once people have had a chance to report any issues they may have with it.

ulong
Registered User
Posts: 59
Joined: Fri Nov 14, 2008 12:22 pm

Re: View or mark unread posts

Post by ulong » Fri Dec 26, 2008 8:23 pm

asinshesq wrote:
ulong wrote:where can i find in database unread posts?
It's the entry in the users table called 'user_unread_privmsg', so you never need to do a sql query for it. Instead, just use $user->data['user_unread_privmsg']. But note that there is already a message that overall_header.php sends to the template that includes the number of unread pms. That message gets assigned in functions.php and is in {PRIVATE_MESSAGE_INFO_UNREAD}

Prosilver doesn't use that message but subsilver2 does...if you switch to subsilver2 you will see a link in the header that reads like this: "xx new messages, yy unread messages" where xx and yy are numbers.

You can use that in prosilver by adding {PRIVATE_MESSAGE_INFO_UNREAD} in the html somewhere...take a look at how subsilver2 does it in overall_header.html.
You are really helpfull :)
Fast answers with full description, great! :)

But... i was writing about posts, not private msgs :P
I still want to make "View unread posts [xx]", but im really newbie in php/sql... :)

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: View or mark unread posts

Post by asinshesq » Sat Dec 27, 2008 2:05 am

ulong wrote:I still want to make "View unread posts [xx]", but im really newbie in php/sql... :)
I still think this is not a good idea, as I said in my first post in this topic. But if you want to give it a try and see how much it does or doesn't weigh down your board, I just wrote two functions that will count unread posts and topics with unread posts. Here they are, but note that I haven't tested them extensively so they may not be perfect: [code replaced by this post: http://www.phpbb.com/community/viewtopi ... 5#p8265455 ]
Last edited by asinshesq on Fri Jan 02, 2009 6:09 pm, edited 1 time in total.

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: View or mark unread posts

Post by asinshesq » Sat Dec 27, 2008 1:44 pm

A few posts ago I included a link to a new version 1.0.5b (stable but not yet formally validated). If you installed version 1.0.5b in the last few days before the time of this post and you used the xml file rather than the text instructions, please check the second change that you made to viewtopic.php. The new line you added should read like this:

Code: Select all

'U_MARK_UNREAD'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'mu=' . $row['post_id'] . '&f=' . $forum_id),
The key thing to confirm is that you used & rather than & just before the f=. The xml file incorrectly showed just & there but it should read &

I've uploaded a corrected version so anyone downloading the mod after this post can ignore this post.

net83it
Registered User
Posts: 500
Joined: Sun Jan 15, 2006 2:42 pm
Location: Sicily
Contact:

Re: View or mark unread posts

Post by net83it » Sat Dec 27, 2008 2:05 pm

thank you for the correction. i've just did it

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: View or mark unread posts

Post by asinshesq » Tue Dec 30, 2008 2:53 am

Ok, I just uploaded what I hope is the final version before I submit another round for validation. You can find version 1.0.5c here: http://www.phpbb.com/community/viewtopi ... 5#p8021335

Here's the changelog since version 1.0.4 (the last version validated):
## 2008-12-29 - Version 1.0.5c
## cleaned up the code in the mark_post_unread() function (should speed up the db queries)
## and re-wrote the unread_tracking_info.txt file that appears in the readme folder
## (if you already have 1.0.5 or 1.0.5a installed you just need to replace functions_view_or_mark_unread_posts.php
## and re-do the changes to viewtopic that the install.xml file tells you to make)
##
## 2008-12-24 - Version 1.0.5b
## revised code to deal with global announcements more dependibly
## and revised various readme and notes files (if you already
## have 1.0.5 or 1.0.5a installed you just need to replace functions_view_or_mark_unread_posts.php
## and re-do the changes to viewtopic that the install.xml file tells you to make)
##
## 2008-12-10 - Version 1.0.5a
## added changes to dovetail with phpbb3.0.3 changes
##
## fixed bug that caused unreads to show up in unread box even if
## user is over the pm limit and the unread pm should really
## only appear in the hold box
##
## fixed bug that prevented a forum from being shown as unread on
## the index page if the only unread post in the forum is the
## latest post in the forum
##
## fixed bug that sometimes caused the link not to toggle to
## "View your unread posts" when the user is in viewforum for a
## category or forum that has subforums
##
## added code to supress 'move to unreadbox' entry in pm dropdown menu
##
## re-did code in functions_view_or_mark_unread_posts.php to properly
## deal with unread global announcments (but note that this will take
## an extra query so people with huge boards who want to save a query
## should read the authors notes carefully)
##
## Note: all changes from version 1.0.4 to 1.0.5a have been posted
## on the phpbb.com topic for this mod on or before December 10, 2008.
## If you have already made these changes you do not need to upgrade
## your mod installation other than as set forth in the entry for
## version 1.0.5b above, but for people who have not made these changes
## I include an upgrade_1-0-4_to_1-0-5b mod in the contrib folder
Please let me know if you try this and how it goes...I'm planning ot submit for validation sometime towards the end of this week.

For those of you interested in the technical side of things, I've re-written and expanded the technical_notes.txt file that explains how phpbb3 keeps track of unreads and how this mod works. You can find that file under the readme_files folder in the download.

net83it
Registered User
Posts: 500
Joined: Sun Jan 15, 2006 2:42 pm
Location: Sicily
Contact:

Re: View or mark unread posts

Post by net83it » Tue Dec 30, 2008 5:33 pm

asinshesq wrote:Ok, I just uploaded what I hope is the final version before I submit another round for validation. You can find version 1.0.5c here: http://www.phpbb.com/community/viewtopi ... 5#p8021335

Here's the changelog since version 1.0.4 (the last version validated):
## 2008-12-29 - Version 1.0.5c
## cleaned up the code in the mark_post_unread() function (should speed up the db queries)
## and re-wrote the unread_tracking_info.txt file that appears in the readme folder
## (if you already have 1.0.5 or 1.0.5a installed you just need to replace functions_view_or_mark_unread_posts.php
## and re-do the changes to viewtopic that the install.xml file tells you to make)
i have 1.0.5b installed. what i have to do to upgrade to 1.0.5c?

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: View or mark unread posts

Post by asinshesq » Tue Dec 30, 2008 5:49 pm

net83it wrote:...i have 1.0.5b installed. what i have to do to upgrade to 1.0.5c?
Just replace functions_view_or_mark_unread_posts.php with the new one and you'll be current. Thank you very much for testing this. Please let me know if you run into any issues, since I'm planning on submitting the new version for validation at the end of this week.

net83it
Registered User
Posts: 500
Joined: Sun Jan 15, 2006 2:42 pm
Location: Sicily
Contact:

Re: View or mark unread posts

Post by net83it » Tue Dec 30, 2008 6:45 pm

many thanks to you!
i'm running this mod from the 26th and i didn't notice anything wrong till now! :)

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: View or mark unread posts

Post by asinshesq » Wed Dec 31, 2008 2:28 am

Thanks. I went ahead and submitted version 1.0.5c for validation. So in about a month the new version will (hopefully) be validated.

User avatar
parasolx
Registered User
Posts: 146
Joined: Wed Apr 23, 2008 8:52 am
Location: Malaysia
Name: Hadafi

Re: View or mark unread posts

Post by parasolx » Fri Jan 02, 2009 4:47 pm

perfect... this modx make my users in the forum easily to know which the topic have new post, rather than they need to scroll down looking for 32 forum with 20 subforum.

right now i wanna to test the counting of the total unread topic only cause i find that my user wouldn't wanna to know how many post they didn't read yet. for me also.. i just wanna to know how many topic that contain unread post that i not read yet.

any result i will post here.

User avatar
parasolx
Registered User
Posts: 146
Joined: Wed Apr 23, 2008 8:52 am
Location: Malaysia
Name: Hadafi

Re: View or mark unread posts

Post by parasolx » Fri Jan 02, 2009 5:03 pm

asinshesq wrote:
ulong wrote:I still want to make "View unread posts [xx]", but im really newbie in php/sql... :)
I still think this is not a good idea, as I said in my first post in this topic. But if you want to give it a try and see how much it does or doesn't weigh down your board, I just wrote two functions that will count unread posts and topics with unread posts. Here they are, but note that I haven't tested them extensively so they may not be perfect:

Code: Select all

/**
* 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;
}
where should i put this code? and how to make it shows the number of topic in the template?

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

adding number of unread posts or topics to link text

Post by asinshesq » Fri Jan 02, 2009 5:53 pm

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 --> &bull; <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS}</a><!-- ELSE --> &bull; <a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF --><!-- ENDIF -->

REPLACE WITH
<!-- IF S_INC_UNREAD_LINK --><!-- IF S_EXISTS_UNREADS --> &bull; <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS}&nbsp;({NUMBER_UNREAD_POSTS}{L_UNREAD_POSTS}{NUMBER_UNREAD_TOPICS}{L_UNREAD_TOPICS})</a><!-- ELSE --> &bull; <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}&nbsp;({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 ;)

User avatar
Savigny
Registered User
Posts: 7
Joined: Sun Mar 23, 2008 1:42 am

Re: View or mark unread posts

Post by Savigny » Fri Jan 02, 2009 9:58 pm

Happy New Year :mrgreen: !

It works great (esp. the mod itself, of course ;) ): Thank you for it!

But what do I have do change, if I want to view the "view unread posts link" at the top of every page in proSilver, too (and not only in subSilver)?

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

placing link in the prosilver header

Post by asinshesq » Fri Jan 02, 2009 10:33 pm

Savigny wrote:But what do I have do change, if I want to view the "view unread posts link" at the top of every page in proSilver, too (and not only in subSilver)?
Depends where you want it. You'll need to experiment, but if you want the "View your unread posts" link to appear on every prosilver page in the header (not just on the index page), one possibility is this:

Code: Select all

OPEN
style/proxilver/templates/overall_header.html

FIND
					<a href="{U_SEARCH_SELF}">{L_SEARCH_SELF}</a>

AFTER, ADD
					<!-- IF S_EXISTS_UNREADS --> &bull; <a href="{U_SEARCH_UNREAD}">{L_SEARCH_UNREAD}</a><!-- ELSE --> &bull; <a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF -->
In tinkering with this, note that &bull; is code for a bullet point so if you don't want a bullet point you should leave that out. If you want to skip a line before or after the link you are adding, <br /> is the code for a skipped line. Finally, note that you would presumably want to undo the change the mod otherwise has you make to style/prosilver/template/index_body.html so that you don't end up with two links that are identical on the index page.

[edit - fix code in light of change in phpbb3.0.6]
Last edited by asinshesq on Mon Mar 08, 2010 3:42 pm, edited 2 times in total.

Locked

Return to “[3.0.x] MOD Database Releases”