Page 68 of 133

Posted: Sat May 20, 2006 5:21 pm
by asinshesq
DrthVictor wrote: Seems like that did the trick. Thanks a lot!


You're welcome, and thanks for pointing the isue out in the first place.

new version of keep unread (2.0.4)

Posted: Sat May 20, 2006 7:52 pm
by asinshesq
New version of keep unread (version 2.0.4)

I just uploaded a new version of this mod which you can get here: [now replaced by more current version]

This version will install without changes on phpbb2.0.20. Here's the changelog:

Code: Select all

##   2006-05-20 - Version 2.0.4
##		- Changes to conform to phpbb2.0.20 changes (only relevant for the mod itself, 
##		  not the upgrade...but if you already have keep unread installed and
##		  are trying to upgrade phpbb from 2.0.19 to 2.0.20 and are stuck because of 
##		  this mod, see http://www.phpbb.com/phpBB/viewtopic.php?p=2082858#2082858 for help)
##		- Fixed bugs that would trigger an error for banned users and that would show 
##		  guests that there are unread posts in forums they are not authorized as guests
##		  to view on boards with mod to the mod to change view unread posts link installed
##		- Substantially optimized the queries for the mod to the mod to change view unread 
##		  posts link so that the code runs fewer queries to get to the same result
##		- Changed basic mod so that the link will now read "View unread posts" if there 
##		  are any and "You have no unread posts" if there aren't any
##		- Changed index_body.tpl to ensure that users would see the mark all forums read 
##		  link even if they are not logged in.
##		- Changed the author's notes to include links to posts showing how
##		  to make this mod compatible with the simple subforums mod, 
##		  the old version of categories hierarchy mod,
##		  the latest topics on index mod and the post sort order mod
##		- Changed author's notes to show how to add the number of topics with unread posts 
##		  to the link, and how to add a link to the page that shows a list of unread posts 
##		  that lets the user mark all posts read
##		- Changed the author's note about adding a text link for marking a post unread so that 
##		  the link appears on the far right in the same font as the 'Back to Top' link that
##		  appears on the far left
This new version is not yet validated. I plan to submitit for validation in about a week so I can pick up any sugggestions people might make before then.

If you are using the upgrade script, make sure to read the author's notes because you need to delete part of the script depending on whether you are using the mod to the mod that changes the text of the view unread posts link.

Posted: Sun May 21, 2006 6:54 am
by Merlin Sythove
Hi Alan,

Thanks for holding the fort whilst I went off gallivanting to a conference :D
Great work everyone for doing all the checking and reporting. I personally would not spend time on making a mod perfect so that it is considerate to banned users, but there you go :lol: Only goes to show that it is hard to think of, and check, all possible situations in advance!

Posted: Sun May 21, 2006 8:35 am
by net83it
Merlin Sythove wrote: I didn't search back this topic, but I made notes in my own index.php code. Here is how you can make an acceptable alternative:

open index.php
find

Code: Select all

list_new_unreads($forum_unreads);
Make sure that line looks like:

Code: Select all

$new_unreads = list_new_unreads($forum_unreads);
After it, add:

Code: Select all

  //New post count: new messages in XX topics!
if (count($new_unreads)) $lang['Search_new'] .= " (" . count($new_unreads)  . ")"; 
Now, whenever the text for the link is used, the text has the total of TOPICS with unread posts in them. You can adjust the text itself in /language/lang_english/lang_main.php.


i had to do one change to get it working on my forum with keep unread flags 2.04

open index.php
find

Code: Select all

list_new_unreads($forum_unreads);
Make sure that line looks like:

Code: Select all

$new_unreads = list_new_unreads($forum_unreads);
After it, add:

Code: Select all

  //New post count: new messages in XX topics!
if (count($new_unreads)) $lang['View_unread_posts'] .= " (" . count($new_unreads)  . ")"; 
i changed $lang['Search_new'] to $lang['View_unread_posts']

Posted: Sun May 21, 2006 9:08 am
by net83it
asinshesq wrote:
Rustyrek wrote:...The inconvenience of going back to the forum index to click on the "mark all forums read" link was too much, so I added that link to the search page....


Here's a quick and dirty fix that should give you a mark all forums read link on the search page only when you are in the search for unread topics page (I don't personally think it makes much sense to have that link on any other search page). I haven't tried this, but it should work. You may want to play with the placement of the link, but this should get you started...

Code: Select all

OPEN
search.php

FIND
		else
		{
			$template->set_filenames(array(
				'body' => 'search_results_topics.tpl')
			);
		}

REPLACE WITH
		else
		{
			$template->set_filenames(array(
				'body' => 'search_results_topics.tpl')
			);
			
			// mod that adds test for if this is a $newposts search and if so, adds a link to mark all forums read
			if($newposts)
			{
				$template->assign_vars(array(
					'L_MARK_FORUMS_READ' => $lang['Mark_all_forums'],
					'U_MARK_READ' => append_sid("index.$phpEx?mark=forums"))
				);
			}
			// end mod
		}

OPEN
templates/subSilver/search_results_topics.tpl

FIND
	<td align="left" valign="bottom"><span class="maintitle">{L_SEARCH_MATCHES}</span><br /></td>

REPLACE WITH
	<td align="left" valign="bottom"><span class="maintitle">{L_SEARCH_MATCHES}</span><br />
	<a href="{U_MARK_READ}" class="gensmall">{L_MARK_FORUMS_READ}</a><br /><br /></span><</td>


there is a very little error (in red)
<td align="left" valign="bottom"><span class="maintitle">{L_SEARCH_MATCHES}</span><br />
<a href="{U_MARK_READ}" class="gensmall">{L_MARK_FORUMS_READ}</a><br /><br /></span><</td>


however it doesn't work
it seem that the if statement isn't true
i also tried

Code: Select all

if( $search_id == 'newposts' )
but it still doesn't work

if i try

Code: Select all

echo $search_id;
i get a numeric value! 8O

add mark all forums read link when click 'View unread posts'

Posted: Sun May 21, 2006 12:44 pm
by asinshesq
Right, thats' the danger of writing code on the fly without tetsting it. The problem is that while $search_id begins its life with information about what the search is doing (e.g. 'newposts') it later on gets changed by the regular code in search.php. So we need to set a placeholder whenever the user is actually viewing unread posts (in this case I decided on '$keep_unread_list' as a placeholder that I then can later test).

Anyway, here's code I just tested that works fine on keep unread 2.0.4. This code gives the user a 'mark all forums read' link in the page whenever the user clicks the 'View unread posts' link:

Code: Select all

OPEN
search.php


FIND
				$list_unreads = implode(',', array_keys(list_new_unreads($dummy)));

BEFORE, ADD
				$keep_unread_list = true;

FIND
		else
		{
			$template->set_filenames(array(
				'body' => 'search_results_topics.tpl')
			);
		}

REPLACE WITH
		else
		{
			$template->set_filenames(array(
				'body' => 'search_results_topics.tpl')
			);
			
			// mod that adds test for if this is a $newposts search and if so, adds a link to mark all forums read
			if( isset($keep_unread_list) )
			{
				$template->assign_vars(array(
					'L_MARK_FORUMS_READ' => $lang['Mark_all_forums'],
					'U_MARK_READ' => append_sid("index.$phpEx?mark=forums"))
				);
			}
			// end mod
		}

OPEN
templates/subSilver/search_results_topics.tpl

FIND
	<td align="left" valign="bottom"><span class="maintitle">{L_SEARCH_MATCHES}</span><br /></td>

REPLACE WITH
	<td align="left" valign="bottom"><span class="maintitle">{L_SEARCH_MATCHES}</span><br />
	<a href="{U_MARK_READ}" class="gensmall">{L_MARK_FORUMS_READ}</a><br /><br /></span></td>

add number of topics with unread posts to link

Posted: Sun May 21, 2006 1:10 pm
by asinshesq
Thanks for all those changes, net83it. Above, I posted a clean and working version of the change you need to make if you want to add a 'mark all forums read' link to the page that comes up when the user clicks 'View unread posts'.

In this post, I'll restate Merlin's code that adds to the view unread posts link the number of topics that have unread posts in them (keep in mind that this is the number of topics with unread posts, not the number of unread posts).

Code: Select all

OPEN
index.php

FIND
$new_unreads = list_new_unreads($forum_unreads);

AFTER, ADD
// New post count: new messages in XX topics!
$lang['View_unread_posts'] .= " (" . count($new_unreads)  . ")";

adding number of new posts to index

Posted: Sun May 21, 2006 1:32 pm
by asinshesq
One last thing.
Some people wanna see how many new posts there were made since their last visit even when they read some. Is it difficult to get this information in the who's online box. (not clickable like normal)

It should look something like:

Our users have posted a total of 15575 articles, 8 since your last visit.


This really has nothing to do with this mod, but so that I have it all in one place, here's some Merlin code from an earlier post that should add to the index information about how many new posts there have been since the user's last visit (slightly corrected):

Code: Select all

OPEN
index.php

FIND
$new_unreads = list_new_unreads($forum_unreads); 

AFTER, ADD
// Get the total of new posts since last visit (last visit phpBB style)
	 $sql = "SELECT count(post_id) as total_new_posts FROM " . POSTS_TABLE . "				  
	 	WHERE post_time > " . $userdata['user_lastvisit'];
	 if ( !($result = $db->sql_query($sql)) )
	 {
	 	message_die(GENERAL_ERROR, 'Could not query new post information', '', __LINE__, __FILE__, $sql);
	 }
	 $row = $db->sql_fetchrow($result) ;
	 $total_new_posts = $row['total_new_posts'];

FIND
'TOTAL_POSTS' => sprintf($l_total_post_s, $total_posts),

REPLACE WITH
'TOTAL_POSTS' => sprintf($l_total_post_s, $total_posts, $total_new_posts),

OPEN
language/lang_english/lang_main.php

FIND
$lang['Posted_articles_total'] = 'Our users have posted a total of <b>%d</b> articles'; // Number of posts

REPLACE WITH
$lang['Posted_articles_total'] = 'Our users have posted a total of <b>%d</b> articles, <b>%d<b> since your last visit'; // Number of posts
And here's a ps from Merlin:
Ah, one PS: This last total of unread posts is only unread stuff that was made since your last visit. So if you read posts from your own list of unreads, as per this mod Keep Unread, and the post is dated before your last visit, your unread post total will NOT go down. This might confuse people. Please remember that giving a total of all unread POSTS (as opposed to topics) is very server-intensive and may slow your index page down unacceptably which is why I have not (and will not) spent time making it. In general you are better off specifying unread TOPICS only, as given in my post a few posts above this one.

sql optimization for really big boards...

Posted: Sun May 21, 2006 8:35 pm
by asinshesq
Once you upgrade to keep unread 2.0.4, here's an adaptation of the sql optimization code that Bigwebmaster psotedd earlier on that helps for really big boards with a huge amount of concurrent traffic: I'll give it a try for a while on my board and if it all works ok I may fold it into the basic mod unless anyone can think of a reason why that's not a good idea. (And Merlin, I'd appraeciate irt if you wold take a close look at my adaptation to make sure I haven't screwed up, since it's a bit different from the original one that Bigwebmaster did).

Code: Select all

#
#-----[ OPEN ]------------------------------------------------
#
includes/functions.php

#
#-----[ FIND ]------------------------------------------------
#
	$sql_unreads = $list_unreads ? " OR t.topic_id IN ($list_unreads)" : '';

#
#-----[ REPLACE WITH ]------------------------------------------------
#
	$new_unreads = array();
	$forum_unread = array();
	$sql_and = array();
	$sql_and[0] = " AND p.post_time > $tracking_time";
	if ($list_unreads)
	{
		$sql_and[1] = " AND t.topic_id IN ($list_unreads) AND (p.post_time <= $tracking_time)";
	}

#
#-----[ FIND ]------------------------------------------------
#
	$sql = "SELECT t.forum_id, t.topic_id, p.post_time
			FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
			WHERE p.post_id = t.topic_last_post_id
			AND (p.post_time > " . $tracking_time . " $sql_unreads)
			$check_auth_sql
			AND t.topic_moved_id = 0";

	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not query new topic information', '', __LINE__, __FILE__, $sql);
	}
	$new_unreads = array();
	$forum_unread = array();
	while( $topic_data = $db->sql_fetchrow($result) ) //Keep the valid unread topics
	{
		$id = $topic_data['topic_id'];
		$topic_last_read = topic_last_read($topic_data['forum_id'], $id);
		if ( $topic_data['post_time'] > $topic_last_read)
		{
			$new_unreads[$id] = $topic_last_read;
			$forum_unread[$topic_data['forum_id']]=true;
		}
	}

#
#-----[ REPLACE WITH ]------------------------------------------------
#
	for ( $i = 0; $i < count($sql_and); $i++)
	{
		$sql = "SELECT t.forum_id, t.topic_id, p.post_time
				FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
				WHERE p.post_id = t.topic_last_post_id
				$sql_and[$i]
				$check_auth_sql
				AND t.topic_moved_id = 0";

		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Could not query new topic information', '', __LINE__, __FILE__, $sql);
		}

		while( $topic_data = $db->sql_fetchrow($result) ) //Keep the valid unread topics
		{
			$id = $topic_data['topic_id'];
			$topic_last_read = topic_last_read($topic_data['forum_id'], $id);
			if ( $topic_data['post_time'] > $topic_last_read)
			{
				$new_unreads[$id] = $topic_last_read;
				$forum_unread[$topic_data['forum_id']]=true;
			}
		}
	}
Note that in the next round I will have some changes that avoid doubling up on the list_new_unreads queries when the user is in index.php.

[Note: I edited the code in this post at 7:30pm NY time on May 22 so if you installed it before then please reinstall it]

Posted: Mon May 22, 2006 9:06 am
by Merlin Sythove
I've inserted the double query version and timed it and I do indeed see a small difference. The combination query using OR takes 0.0479, and the two little queries combined take 0.0076, a factor 6 faster. Measurements may vary of course.

I'm not really sure if I'm looking at the right details, but on my forum the single query version has to examine 2600 rows for a match to the "topic_id IN (.....)". With the split version, the 2600 rows have been done in the very fast first query (0.0003 sec) and only 168 rows are left over for examining "topic_id IN (.....)" PLUS, they also get to use an index now, which wasn't used in the combined query.

Anyway, someone with more knowledge than myself may be able to figure it out, the result is that I DO see a small improvement even on my own board, so Alan, I will recommend we change the code permanently.

Posted: Mon May 22, 2006 10:07 am
by nwbasser
is this mod working out of the box on phpbb 2.0.20?

Posted: Mon May 22, 2006 11:13 am
by Merlin Sythove
Yes.

keep unread upgrade info...

Posted: Mon May 22, 2006 11:44 am
by asinshesq
nwbasser wrote: is this mod working out of the box on phpbb 2.0.20?

Merlin Sythove wrote: Yes


Errrr.....actually, no (at least the answer is no if you mean the validated version you get from the first post in this topic, which is 2.0.3c).

I have a new version 2.0.4 that works out of the box with phpbb2.0.20 and makes some other improvements. Scroll up to the top of this page and you'll see big red letters and a link to the newest version (2.0.4).

Note that I expect sometime in the next week or two to come out with one more version (which will be 2.0.5) once Merlin and I have agreed on a few more tweaks. When I do that I will of course provide an upgrade scipt, and the changes will be pretty easy anyway.

For people who are still on version 2.0.3c, I think it does make sense to upgrade to 2.0.4, and when we come out with 2.0.5 I do NOT plan on putting together a script that takes you from 2.0.3c all the way to 2.0.5 (you will need to upgrade from 2.0.3c to 2.0.4 and then from 2.0.4 to 2.0.5) so you will not be saving any effort by waiting.

Posted: Tue May 23, 2006 1:56 am
by nwbasser
Thanks for the reply asinshesq.
I think I'll wait for that new version you're working on.
Thanks for all the work you guys put into these mods!

Posted: Wed May 24, 2006 2:20 am
by WhataMack
I've tried a couple times tonight to install the 2.0.4 version of the mod on a completely new phpBB2 2.0.20 site (new and clean database, no mods, no posts except one I try to add to the "This is a test forum" forum, no users besides myself), and this error message comes back whenever I try to submit that post:

Code: Select all

phpBB : Critical Error 

Failed to update users table for unread topics

DEBUG MODE

SQL Error : 1054 Unknown column 'user_unread_topics' in 'field list'

UPDATE phpbb_users SET user_unread_topics = '0//1148436751//' WHERE user_id = 0

Line : 1106
File : functions.php
I've copied the "contrib/changed files" from the 2.0.4 release to the appropriate locations.

I can most likely wait until the 2.0.5 mod comes out to start putting this installation up, but thought I'd at least post this info in the meantime. Any ideas what's causing this?