New post count on index

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
CVinde
Registered User
Posts: 6
Joined: Tue Feb 26, 2008 9:52 pm

Re: New post count on index

Post by CVinde »

Please tell when you find a solution :)
Nick-Harper
Registered User
Posts: 56
Joined: Mon Feb 25, 2008 1:39 pm

Re: New post count on index

Post by Nick-Harper »

I would also like to know when there is a fix :)
Image
User avatar
dJomp
Registered User
Posts: 22
Joined: Mon Nov 24, 2003 2:45 pm
Location: York, UK
Contact:

Re: New post count on index

Post by dJomp »

Here's some PHP to count the number of new posts.

I make no claims that this is efficient in any way... but it works as far as I know! I have what is probably considered to be a quiet board, maybe 100 posts per day, so it's not too much work for my server.

I'm sure there's a way of doing most of this in a hugely clever SQL query, but that's not my forte! Maybe this will help someone towards a better solution...

The total unread posts will be in $postcount at the end.

Code: Select all

$postcount = 0;

$forumTrackQuery = $db->sql_query('SELECT * FROM '.FORUMS_TRACK_TABLE.' WHERE user_id = '.$user->data['user_id'].' AND mark_time >= '.$user->data['user_lastvisit']);
while ($forum = $db->sql_fetchrow($forumTrackQuery))
	$forumTrack[$forum['forum_id']] = $forum['mark_time'];

$topicTrackQuery = $db->sql_query('SELECT * FROM '.TOPICS_TRACK_TABLE.' WHERE user_id = '.$user->data['user_id'].' AND mark_time >= '.$user->data['user_lastvisit']);
while ($topic = $db->sql_fetchrow($topicTrackQuery))
	$topicTrack[$topic['topic_id']] = $topic['mark_time'];

// Only limited to save the size of the result being too huge
$sql = 'SELECT topic_id, forum_id, post_time, poster_id FROM '.POSTS_TABLE.' WHERE post_time >= '.$user->data['user_lastvisit'].' ORDER BY post_time';

if ($result = $db->sql_query($sql))
{
	while ($one = $db->sql_fetchrow($result))
	{
		// Check we are allowed to view this post (in the forum)
		// And check it's not our own post - no point counting those really
		if (
			$auth->acl_gets('f_list', 'f_read', $one['forum_id'])
				&& 
			($user->data['user_id'] != $one['poster_id'])
			)
		{
			$topic_last_read = max($user->data['user_lastvisit'], $user->data['user_lastmark']);

			if (isset($forumTrack[$one['forum_id']]))
				$topic_last_read = max($topic_last_read, $forumTrack[$one['forum_id']]);

			if (isset($topicTrack[$one['topic_id']]))
				$topic_last_read = max($topic_last_read, $topicTrack[$one['topic_id']]);

			if ($one['post_time'] > $topic_last_read)
				$postcount++;
		}
	}
}
demetris20
Registered User
Posts: 214
Joined: Tue Aug 15, 2006 12:35 pm

Re: New post count on index

Post by demetris20 »

i cant find the correct line for index body tpl for the fisubsilver2 theme
can anyone help???
User avatar
dJomp
Registered User
Posts: 22
Joined: Mon Nov 24, 2003 2:45 pm
Location: York, UK
Contact:

Re: New post count on index

Post by dJomp »

dJomp wrote:Here's some PHP to count the number of new posts.
That was new posts since last visit. However I think phpBB3 now flags topics between sessions?

So if you want a total unread count, get rid of user_lastvisit and replace with user_lastmark:

Code: Select all

$postcount = 0;

$forumTrackQuery = $db->sql_query('SELECT * FROM '.FORUMS_TRACK_TABLE.' WHERE user_id = '.$user->data['user_id'].' AND mark_time >= '.$user->data['user_lastmark']);
while ($forum = $db->sql_fetchrow($forumTrackQuery))
	$forumTrack[$forum['forum_id']] = $forum['mark_time'];

$topicTrackQuery = $db->sql_query('SELECT * FROM '.TOPICS_TRACK_TABLE.' WHERE user_id = '.$user->data['user_id'].' AND mark_time >= '.$user->data['user_lastmark']);
while ($topic = $db->sql_fetchrow($topicTrackQuery))
	$topicTrack[$topic['topic_id']] = $topic['mark_time'];

// Only limited to save the size of the result being too huge
$sql = 'SELECT topic_id, forum_id, post_time, poster_id FROM '.POSTS_TABLE.' WHERE post_time >= '.$user->data['user_lastmark'].' ORDER BY post_time';

if ($result = $db->sql_query($sql))
{
	while ($one = $db->sql_fetchrow($result))
	{
		// Check we are allowed to view this post (in the forum)
		// And check it's not our own post - no point counting those really
		if (
			$auth->acl_gets('f_list', 'f_read', $one['forum_id'])
				&& 
			($user->data['user_id'] != $one['poster_id'])
			)
		{
			$topic_last_read = $user->data['user_lastmark'];

			if (isset($forumTrack[$one['forum_id']]))
				$topic_last_read = max($topic_last_read, $forumTrack[$one['forum_id']]);

			if (isset($topicTrack[$one['topic_id']]))
				$topic_last_read = max($topic_last_read, $topicTrack[$one['topic_id']]);

			if ($one['post_time'] > $topic_last_read)
				$postcount++;
		}
	}
}
[/quote]
demetris20
Registered User
Posts: 214
Joined: Tue Aug 15, 2006 12:35 pm

Re: New post count on index

Post by demetris20 »

demetris20 wrote:i cant find the correct line for index body tpl for the fisubsilver2 theme
can anyone help???
anyone???
demetris20
Registered User
Posts: 214
Joined: Tue Aug 15, 2006 12:35 pm

Re: New post count on index

Post by demetris20 »

demetris20 wrote:
demetris20 wrote:i cant find the correct line for index body tpl for the fisubsilver2 theme
can anyone help???
anyone???
can anyone help me
Sascha Mueller
Registered User
Posts: 95
Joined: Tue Mar 28, 2006 8:11 pm
Contact:

Re: New post count on index

Post by Sascha Mueller »

Is this mod ready for phpBB 3.0.1 ?
Please excuse my bad English, I'm German!
ham1299
Registered User
Posts: 613
Joined: Mon Sep 11, 2006 2:12 am
Location: USA
Contact:

Re: New post count on index

Post by ham1299 »

Sascha Mueller wrote:Is this mod ready for phpBB 3.0.1 ?
Again, it's working for me. ;)
Heather
Sascha Mueller
Registered User
Posts: 95
Joined: Tue Mar 28, 2006 8:11 pm
Contact:

Re: New post count on index

Post by Sascha Mueller »

ham1299 wrote:
Sascha Mueller wrote:Is this mod ready for phpBB 3.0.1 ?
Again, it's working for me. ;)
Thx. :)
Please excuse my bad English, I'm German!
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: New post count on index

Post by LiquidSpark »

demetris20 wrote:
demetris20 wrote:
demetris20 wrote:i cant find the correct line for index body tpl for the fisubsilver2 theme
can anyone help???
anyone???
can anyone help me
Aren't we using the index.php file in the root directory?
ham1299
Registered User
Posts: 613
Joined: Mon Sep 11, 2006 2:12 am
Location: USA
Contact:

Re: New post count on index

Post by ham1299 »

Sascha Mueller wrote:
ham1299 wrote:
Sascha Mueller wrote:Is this mod ready for phpBB 3.0.1 ?
Again, it's working for me. ;)
Thx. :)
You're welcome! :D
Heather
Rhine_
Registered User
Posts: 127
Joined: Sat Mar 15, 2008 4:45 pm

Re: New post count on index

Post by Rhine_ »

when viewing a forum or a topic it just shows view new posts()
how do I fix that?
Oggster
Registered User
Posts: 74
Joined: Mon Mar 17, 2008 12:31 am

Re: New post count on index

Post by Oggster »

lefty74 wrote:you could try
open includes/functions.php

FIND

Code: Select all

		// The following assigns all _common_ variables that may be used at any point in a template.
BEFORE, ADD

Code: Select all

$sql = 'SELECT COUNT(post_id) as count
    FROM ' . POSTS_TABLE . ' 
		WHERE post_time > ' . $user->data['user_lastvisit'] . '
    AND poster_id != ' . $user->data['user_id'];

$result = $db->sql_query($sql);
$post_count = $db->sql_fetchfield('count', false, $result);
$db->sql_freeresult($result);  
FIND

Code: Select all

		'SITENAME'						=> $config['sitename'],
BEFORE, ADD

Code: Select all

		'NEW_POST_COUNT' => $post_count ,
and then delete the parts referred to in the mod in the index.php page



I just wanted to mention I am running fisubice2 and I tried to get this method
to work but with 100 users online this crippled my forum big time!
Is there a non lethal method? Thanks :mrgreen:
Luchtzak
Registered User
Posts: 273
Joined: Sat Jul 20, 2002 7:13 pm
Contact:

Re: New post count on index

Post by Luchtzak »

This mod slows down my page with 0.7 seconds, it has to run through 206000 messages !!
Locked

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