Page 6 of 9

Re: New post count on index

Posted: Tue Feb 26, 2008 10:47 pm
by CVinde
Please tell when you find a solution :)

Re: New post count on index

Posted: Thu Feb 28, 2008 2:37 am
by Nick-Harper
I would also like to know when there is a fix :)

Re: New post count on index

Posted: Fri Mar 28, 2008 11:26 pm
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++;
		}
	}
}

Re: New post count on index

Posted: Sun Mar 30, 2008 11:59 pm
by demetris20
i cant find the correct line for index body tpl for the fisubsilver2 theme
can anyone help???

Re: New post count on index

Posted: Mon Mar 31, 2008 6:17 pm
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]

Re: New post count on index

Posted: Tue Apr 01, 2008 2:14 pm
by demetris20
demetris20 wrote:i cant find the correct line for index body tpl for the fisubsilver2 theme
can anyone help???
anyone???

Re: New post count on index

Posted: Fri Apr 11, 2008 11:58 am
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

Re: New post count on index

Posted: Mon Apr 14, 2008 3:46 pm
by Sascha Mueller
Is this mod ready for phpBB 3.0.1 ?

Re: New post count on index

Posted: Mon Apr 14, 2008 5:53 pm
by ham1299
Sascha Mueller wrote:Is this mod ready for phpBB 3.0.1 ?
Again, it's working for me. ;)

Re: New post count on index

Posted: Mon Apr 14, 2008 6:03 pm
by Sascha Mueller
ham1299 wrote:
Sascha Mueller wrote:Is this mod ready for phpBB 3.0.1 ?
Again, it's working for me. ;)
Thx. :)

Re: New post count on index

Posted: Mon Apr 14, 2008 7:27 pm
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?

Re: New post count on index

Posted: Tue Apr 15, 2008 12:15 am
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

Re: New post count on index

Posted: Wed Apr 16, 2008 6:19 pm
by Rhine_
when viewing a forum or a topic it just shows view new posts()
how do I fix that?

Re: New post count on index

Posted: Thu Apr 17, 2008 12:02 am
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:

Re: New post count on index

Posted: Wed Apr 23, 2008 8:17 pm
by Luchtzak
This mod slows down my page with 0.7 seconds, it has to run through 206000 messages !!