keep unread flags

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

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.

Rating:

Excellent!
72
75%
Very Good
16
17%
Good
4
4%
Fair
0
No votes
Poor
4
4%
 
Total votes: 96

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

Re: Keep Read MOD with 2.0.21

Post by asinshesq »

_RAAF_Furball wrote: I notice that the first post in this Topic states that this Keep Read MOD has only been tested to V 2.0.6...


You notice incorrectly ;)

The version of the mod in the first post of this topic is 2.0.6. That has nothing to do with the version of phpbb it was tested on or works on. In fact, it was validated on phpbb2.0.21 and continues to work fine on phpbb2.0.22 (though I haven't yet tried to install it a new on a phpbb2.0.22 board so the instructions may or may not need some tweaking for 2.0.22...I'll check that some time in the next few days, but if you can still find all the code it asks for it will work fine on phpbb2.0.22).
_RAAF_Furball
Registered User
Posts: 12
Joined: Sun Jan 23, 2005 3:06 pm
Location: Australia
Contact:

Re: Keep Read MOD with 2.0.21

Post by _RAAF_Furball »

asinshesq wrote: it was validated on phpbb2.0.21
ah hah ...... thnx for that.
Actually, since I couldn't see any phpbb version listed, I wrongly assumed that the version # mentioned, referred to phpbb, not MOD. :roll:

Pls point me to where I can see "it was validated on phpbb2.0.21."

This gives a clue:
"This MOD has only been tested by the phpBB MOD Team with the phpBB version in the topic title. It may not work in any other versions of phpBB",

but I'll be buggered if I can find it in the topic title - or anywhere else for that matter. Wot am I missing? :oops:

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

Re: Keep Read MOD with 2.0.21

Post by asinshesq »

_RAAF_Furball wrote: ...Actually, since I couldn't see any phpbb version listed, I wrongly assumed that the version # mentioned, referred to phpbb, not MOD. :roll:

Pls point me to where I can see "it was validated on phpbb2.0.21."

This gives a clue:
"This MOD has only been tested by the phpBB MOD Team with the phpBB version in the topic title. It may not work in any other versions of phpBB",

but I'll be buggered if I can find it in the topic title - or anywhere else for that matter. Wot am I missing? :oops: ...

You're not missing anything. The 'style' of how mods get announced in the topic title and first topic post changed in august 2006 (when the most recent version of this mod was validated) so that they no longer include the phpbb version on which it was tested in the topic title, but they hadn't at that time gotten around to fixing that text that still says the version is in the topic title. The reason they got rid of the version of phpbb on which a mod has been tested from the topic title was that people incorrectly assumed the mod would only work on that phpbb version.
_RAAF_Furball
Registered User
Posts: 12
Joined: Sun Jan 23, 2005 3:06 pm
Location: Australia
Contact:

Post by _RAAF_Furball »


ah - now I understand - thank you!
colin_bb
Registered User
Posts: 104
Joined: Tue Feb 14, 2006 8:40 pm

Re: Keep Read MOD with 2.0.21

Post by colin_bb »

asinshesq wrote:
_RAAF_Furball wrote:In fact, it was validated on phpbb2.0.21 and continues to work fine on phpbb2.0.22 (though I haven't yet tried to install it a new on a phpbb2.0.22 board so the instructions may or may not need some tweaking for 2.0.22...


I just tried to install this with easymod in a vanilla forum (2.22) and easymod threw up several critical errors in non-template files.

I'll install this mod and give feedback when the above has been sorted. 8)
DivErTido
Registered User
Posts: 642
Joined: Fri Aug 08, 2003 10:11 pm
Contact:

Post by DivErTido »

Can someone help me?
I need to do this:

Code: Select all

# 
#-----[ OPEN ]--------------------------------------------- 
# 
viewtopic.php

#
#-----[ FIND ]---------------------------------------------
# Line 44
	$post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
}


$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;

#
#-----[ AFTER, ADD ]---------------------------------------------
#
$start = ($start < 0) ? 0 : $start;
And in my viewtopic.php I have this:

Code: Select all

	$post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
}


if(!$HTTP_GET_VARS['start']) {
    $start='0';
} else{
    $start=(intval($HTTP_GET_VARS['start']) == $HTTP_GET_VARS['start']) ? (intval($HTTP_GET_VARS['start'])) : ('all');
};

//START MOD Keep_unread_2
$mode = ( isset($HTTP_GET_VARS['mode']) ) ? htmlspecialchars( $HTTP_GET_VARS['mode'] ) : '';

if ( !empty($post_id) )
{ //added topic_last_post_id, p.post_time to sql
	$sql = "SELECT t.forum_id, t.topic_id, t.topic_last_post_id, p.post_time
		FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
		WHERE t.topic_id = p.topic_id
		AND t.topic_moved_id = 0
		AND p.post_id = $post_id";
}
else if ( !empty($topic_id) )
{
	$sql = "SELECT t.forum_id, t.topic_id, t.topic_last_post_id
		FROM " . TOPICS_TABLE . " t
		WHERE t.topic_moved_id = 0
		AND t.topic_id = $topic_id";
}
else
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
if ( !$result = $db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}
if ( !$row = $db->sql_fetchrow($result) )
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
$forum_id = $row['forum_id'];
$topic_id = $row['topic_id'];
$post_time = $row['post_time'];
$topic_last_post_id = $row['topic_last_post_id'];
//END MOD Keep_unread_2
Where I put the new line?
Is there any problem if I puit after this line?

Code: Select all

$start=(intval($HTTP_GET_VARS['start']) == $HTTP_GET_VARS['start']) ? (intval($HTTP_GET_VARS['start'])) : ('all');
Please sorry for my poor english...
P.S. Please sorry for my poor english...
Legendas Divx
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

DivErTido wrote: Can someone help me?
I need to do this...

Where I put the new line?
Is there any problem if I puit after this line?...

That new line is from the upgrade from 2.0.21 to 2.0.22 code changes script, correct? I'm not sure why you are asking in this topic, since the keep unread mod does not change the lines the upgrade is looking for (you must have another mod on your board that changed those line). But looking at what you have posted, it seems to be fine to stick the new line where you suggest. That will make sure that $start is never negative.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: Keep Read MOD with 2.0.21

Post by asinshesq »

colin_bb wrote: I just tried to install this with easymod in a vanilla forum (2.22) and easymod threw up several critical errors in non-template files.


Try again ;)

Seriously, I just used easymod to install keep unread 2.0.6 on an absolutely clean phpbb2.0.22 board and it installed without any errors and without the need to do any modification to the mod script. So it looks to me like the current version of this mod not only works fine with phpbb2.0.22 but also installs fine (with easymod) on a clean phpbb2.0.22 board.

Colin_bb, what lines does easymod tell you it can't find?
colin_bb
Registered User
Posts: 104
Joined: Tue Feb 14, 2006 8:40 pm

Post by colin_bb »

I got this error from easymod:

Code: Select all

Critical Error

FIND FAILED: In file [search.php] could not find:

if ( $search_id == 'newposts' ) 
{ 
if ( $userdata['session_logged_in'] ) 
{ 
$sql = "SELECT post_id 
FROM " . POSTS_TABLE . " 
WHERE post_time >= " . $userdata['user_lastvisit']; 
} 
else 
{ 
redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true)); 
} 
$show_results = 'topics'; 
$sort_by = 0; 
$sort_dir = 'DESC'; 
} 
MOD script line #564 
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

colin_bb wrote: I got this error from easymod:

Code: Select all

Critical Error

FIND FAILED: In file [search.php] could not find:

if ( $search_id == 'newposts' ) 
{ 
if ( $userdata['session_logged_in'] ) 
{ 
$sql = "SELECT post_id 
FROM " . POSTS_TABLE . " 
WHERE post_time >= " . $userdata['user_lastvisit']; 
} 
else 
{ 
redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true)); 
} 
$show_results = 'topics'; 
$sort_by = 0; 
$sort_dir = 'DESC'; 
} 
MOD script line #564 

Take a look at lines 184-200 of the search.php file that comes with a clean phpbb2.0.22 and you will see exactly those lines. Sounds to me like you do not have phpbb2.0.22 where you think you do.
colin_bb
Registered User
Posts: 104
Joined: Tue Feb 14, 2006 8:40 pm

Post by colin_bb »

:oops:

i've just realised i installed save posts as drafts mod before i installed this.

sorry, i take back my previous comments. Thanks for making me realise this and avoiding further confusion.

The code that it is looking for:

Code: Select all

if ( $search_id == 'newposts' )
			{
				if ( $userdata['session_logged_in'] )
				{
					$sql = "SELECT post_id
						FROM " . POSTS_TABLE . "
						WHERE post_time >= " . $userdata['user_lastvisit'];
				}
				else
				{
					redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
				}

				$show_results = 'topics';
				$sort_by = 0;
				$sort_dir = 'DESC';
			}
The code that i have in search.php:

Code: Select all

if ( $search_id == 'newposts' )
			{
				if ( $userdata['session_logged_in'] )
				{
					$sql = "SELECT post_id 
						FROM " . POSTS_TABLE . " 
						WHERE post_time >= " . $userdata['user_lastvisit'] . " AND post_draft = 0";
						// start mod save posts as drafts (and end mod too)...added constraint in the preceding line that post_draft be 0 so that draftws wouldn't get included

				}
				else
				{
					redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
				}

				$show_results = 'topics';
				$sort_by = 0;
				$sort_dir = 'DESC';
			}
Note that the sql is calling for saved posts, which is the difference that easymod was halting on.

Is there anyway to make this mod work in conjunction with save_posts_as_drafts_1-0-25 mod?

I thought of modifying the sql statement (from this mod) to the following:

Code: Select all

if ( $search_id == 'newposts' )
			{
				//START MOD Keep_unread_2
				$list_unreads = implode(',', array_keys(list_new_unreads($dummy, $toggle_unreads_link)));
				$sql = "SELECT post_id, topic_id, forum_id, post_time
					FROM " . POSTS_TABLE . "
					WHERE ";//post_time >= " . $userdata['user_lastvisit'] ;
				$sql .= ($list_unreads != '')	? " topic_id IN (" . $list_unreads . ")" : " topic_id=-1";
				//END MOD Keep_unread_2
				$sql.=  "AND post_draft = 0";
				$show_results = 'topics';
				$sort_by = 0;
				$sort_dir = 'DESC';
			}
(note the appended sql line).
Do you think that would work?
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

Note: version 2.0.6 of this mod works fine on a clean phpbb2.0.22 board.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

Ok, colin_bb, for your board, since it has save posts as drafts installed you'll need to tweak the regular code a bit. This should do the job (but people who do not have my save posts as drafts mod installed should NOT be making this change).

Change this:

Code: Select all

#-----[ OPEN ]------------------------------------------------
#
search.php

#
#-----[ FIND ]------------------------------------------------
#
			if ( $search_id == 'newposts' )
			{
				if ( $userdata['session_logged_in'] )
				{
					$sql = "SELECT post_id
						FROM " . POSTS_TABLE . "
						WHERE post_time >= " . $userdata['user_lastvisit'];
				}
				else
				{
					redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
				}

				$show_results = 'topics';
				$sort_by = 0;
				$sort_dir = 'DESC';
			}

#
#-----[ REPLACE WITH ]----------------------------------------
#
			if ( $search_id == 'newposts' )
			{
				//START MOD Keep_unread_2
				$list_unreads = implode(',', array_keys(list_new_unreads($dummy, $toggle_unreads_link)));
				$sql = "SELECT post_id, topic_id, forum_id, post_time
					FROM " . POSTS_TABLE . "
					WHERE ";//post_time >= " . $userdata['user_lastvisit'] ;
				$sql .= ($list_unreads != '')	? " topic_id IN (" . $list_unreads . ")" : " topic_id=-1";
				//END MOD Keep_unread_2
				$show_results = 'topics';
				$sort_by = 0;
				$sort_dir = 'DESC';
			}
to this:

Code: Select all

#-----[ OPEN ]------------------------------------------------
#
search.php

#
#-----[ FIND ]------------------------------------------------
#
			if ( $search_id == 'newposts' )
			{
				if ( $userdata['session_logged_in'] )
				{
					$sql = "SELECT post_id 
						FROM " . POSTS_TABLE . " 
						WHERE post_time >= " . $userdata['user_lastvisit'] . " AND post_draft = 0";
						// start mod save posts as drafts (and end mod too)...added constraint in the preceding line that post_draft be 0 so that draftws wouldn't get included

				}
				else
				{
					redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=newposts", true));
				}

				$show_results = 'topics';
				$sort_by = 0;
				$sort_dir = 'DESC';
			}

#
#-----[ REPLACE WITH ]----------------------------------------
#
			if ( $search_id == 'newposts' )
			{
				//START MOD Keep_unread_2
				$list_unreads = implode(',', array_keys(list_new_unreads($dummy, $toggle_unreads_link)));
				$sql = "SELECT post_id, topic_id, forum_id, post_time
					FROM " . POSTS_TABLE . "
					WHERE post_draft = 0 AND ";//post_time >= " . $userdata['user_lastvisit'] ;
				$sql .= ($list_unreads != '')	? " topic_id IN (" . $list_unreads . ")" : " topic_id=-1";
				//END MOD Keep_unread_2
				$show_results = 'topics';
				$sort_by = 0;
				$sort_dir = 'DESC';
			}
colin_bb
Registered User
Posts: 104
Joined: Tue Feb 14, 2006 8:40 pm

Post by colin_bb »

Thanks, but now i'm getting this error in easymod :x

Code: Select all

Critical Error

FIND FAILED: In file [viewtopic.php] could not find:

if (!$topic_id && !$post_id) 
{ 
message_die(GENERAL_MESSAGE, 'Topic_post_not_exist'); 
} 
// 
// Find topic id if user requested a newer 
// or older topic 
// 
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) ) 
{ 
if ( $HTTP_GET_VARS['view'] == 'newest' ) 
{ 
if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) ) 
{ 
$session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid']; 
if (!preg_match('/^[A-Za-z0-9]*$/', $session_id)) 
{ 
$session_id = ''; 
} 
if ( $session_id ) 
{ 
$sql = "SELECT p.post_id 
FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u 
WHERE s.session_id = '$session_id' 
AND u.user_id = s.session_user_id 
AND p.topic_id = $topic_id 
AND p.post_time >= u.user_lastvisit 
ORDER BY p.post_time ASC 
LIMIT 1"; 
if ( !($result = $db->sql_query($sql)) ) 
{ 
message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql); 
} 
if ( !($row = $db->sql_fetchrow($result)) ) 
{ 
message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit'); 
} 
$post_id = $row['post_id']; 
if (isset($HTTP_GET_VARS['sid'])) 
{ 
redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id"); 
} 
else 
{ 
redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id"); 
} 
} 
} 
redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true)); 
} 

MOD script line #1022
Heres the relevant section in the mod installation file:

Code: Select all

#
#-----[ OPEN ]------------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------------
#
if (!$topic_id && !$post_id)
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}

//
// Find topic id if user requested a newer
// or older topic
//
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{
	if ( $HTTP_GET_VARS['view'] == 'newest' )
	{
		if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
		{
			$session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];

			if (!preg_match('/^[A-Za-z0-9]*$/', $session_id)) 
			{
				$session_id = '';
			}

			if ( $session_id )
			{
				$sql = "SELECT p.post_id
					FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
					WHERE s.session_id = '$session_id'
						AND u.user_id = s.session_user_id
						AND p.topic_id = $topic_id
						AND p.post_time >= u.user_lastvisit
					ORDER BY p.post_time ASC
					LIMIT 1";
				if ( !($result = $db->sql_query($sql)) )
				{
					message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
				}

				if ( !($row = $db->sql_fetchrow($result)) )
				{
					message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
				}

				$post_id = $row['post_id'];

				if (isset($HTTP_GET_VARS['sid']))
				{
					redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id");
				}
				else
				{
					redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id");
				}
			}
		}

		redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
	}

#
#-----[ REPLACE WITH ]------------------------------------------
#
//START MOD Keep_unread_2
$mode = ( isset($HTTP_GET_VARS['mode']) ) ? htmlspecialchars( $HTTP_GET_VARS['mode'] ) : '';

if ( !empty($post_id) )
{ //added topic_last_post_id, p.post_time to sql
	$sql = "SELECT t.forum_id, t.topic_id, t.topic_last_post_id, p.post_time
		FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
		WHERE t.topic_id = p.topic_id
		AND t.topic_moved_id = 0
		AND p.post_id = $post_id";
}
else if ( !empty($topic_id) )
{
	$sql = "SELECT t.forum_id, t.topic_id, t.topic_last_post_id
		FROM " . TOPICS_TABLE . " t
		WHERE t.topic_moved_id = 0
		AND t.topic_id = $topic_id";
}
else
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
if ( !$result = $db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}
if ( !$row = $db->sql_fetchrow($result) )
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
$forum_id = $row['forum_id'];
$topic_id = $row['topic_id'];
$post_time = $row['post_time'];
$topic_last_post_id = $row['topic_last_post_id'];
//END MOD Keep_unread_2

//
// Start session management
//
$userdata = session_pagestart($user_ip, $forum_id);
init_userprefs($userdata);
//
// End session management
//

//START MOD Keep_unread_2 * Keep topic unread from given post onwards
if ($mode == 'unread')
{
	$board_config['tracking_unreads'][$topic_id] = $post_time-1; //testing for ">" only later on
	write_cookies($userdata);
	$message = $lang['keep_unread_done'] . '<br /><br />' .
	sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a> ') . '<br /><br />' .
	sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a> ');
	message_die(GENERAL_MESSAGE, $message);
}
$topic_last_read = topic_last_read($forum_id, $topic_id);
//END MOD Keep_unread_2

//
// Find topic id if user requested a newer
// or older topic
//
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{
	if ( $HTTP_GET_VARS['view'] == 'newest' )
	{ // read the first unread post in this topic
		$sql = "SELECT p.post_id, t.topic_last_post_id
			FROM (" . TOPICS_TABLE . " t
			LEFT JOIN " . POSTS_TABLE . " p ON p.topic_id = t.topic_id AND p.post_time > $topic_last_read)
			WHERE t.topic_id = $topic_id
			AND t.topic_moved_id = 0
			ORDER BY p.post_time";
		if ( !$result = $db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
		}

		if ( !($row = $db->sql_fetchrow($result)) )
		{
			message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
		}
		$post_id = empty($row['post_id']) ? $row['topic_last_post_id'] : $row['post_id'];
		redirect(append_sid("./viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
	}
And the relevant section of my viewtopic.php:

Code: Select all

if (!$topic_id && !$post_id)
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}

//
// Find topic id if user requested a newer
// or older topic
//
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{
	if ( $HTTP_GET_VARS['view'] == 'newest' )
	{
		if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
		{
			$session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];

			if (!preg_match('/^[A-Za-z0-9]*$/', $session_id)) 
			{
				$session_id = '';
			}

			if ( $session_id )
			{
				$sql = "SELECT p.post_id
					FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
					WHERE s.session_id = '$session_id'
						AND u.user_id = s.session_user_id
						AND p.topic_id = $topic_id
						AND p.post_time >= u.user_lastvisit
						AND p.post_draft = 0
					ORDER BY p.post_time ASC
					LIMIT 1";
// start mod save posts as drafts (and end mod too): added an AND constraint in the foregoing sql definition that post_draft be zero (i.e. that the post not just be a draft)

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

				if ( !($row = $db->sql_fetchrow($result)) )
				{
					message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
				}

				$post_id = $row['post_id'];

				if (isset($HTTP_GET_VARS['sid']))
				{
					redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id");
				}
				else
				{
					redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id");
				}
			}
		}

		redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
	}
Again, the query above has a reference to the drafts:

Code: Select all

$sql = "SELECT p.post_id
					FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
					WHERE s.session_id = '$session_id'
						AND u.user_id = s.session_user_id
						AND p.topic_id = $topic_id
						AND p.post_time >= u.user_lastvisit
						AND p.post_draft = 0
					ORDER BY p.post_time ASC
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

colin_bb wrote: Thanks, but now i'm getting this error in easymod...

What ever happened to 'we'll leave that as an exercise for the student'? ;)

The following only applies for people who are installing this mod in a board that has my save posts as drafts mod installed...other people can ignore this

It's the same thing throughout, so you'll have to keep making the same change throughout...adding in the AND post_draft = 0 line (or in places where the field names come with p. in front, AND p.post_draft = 0). In the case you just posted, you need to do this:

Code: Select all

#
#-----[ OPEN ]------------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------------
#
if (!$topic_id && !$post_id)
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}

//
// Find topic id if user requested a newer
// or older topic
//
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{
	if ( $HTTP_GET_VARS['view'] == 'newest' )
	{
		if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
		{
			$session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];

			if (!preg_match('/^[A-Za-z0-9]*$/', $session_id)) 
			{
				$session_id = '';
			}

			if ( $session_id )
			{
				$sql = "SELECT p.post_id
					FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s,  " . USERS_TABLE . " u
					WHERE s.session_id = '$session_id'
						AND u.user_id = s.session_user_id
						AND p.topic_id = $topic_id
						AND p.post_time >= u.user_lastvisit
						AND p.post_draft = 0
					ORDER BY p.post_time ASC
					LIMIT 1";
// start mod save posts as drafts (and end mod too): added an AND constraint in the foregoing sql definition that post_draft be zero (i.e. that the post not just be a draft)

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

				if ( !($row = $db->sql_fetchrow($result)) )
				{
					message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
				}

				$post_id = $row['post_id'];

				if (isset($HTTP_GET_VARS['sid']))
				{
					redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id");
				}
				else
				{
					redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id");
				}
			}
		}

		redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
	}

#
#-----[ REPLACE WITH ]------------------------------------------
#
//START MOD Keep_unread_2
$mode = ( isset($HTTP_GET_VARS['mode']) ) ? htmlspecialchars( $HTTP_GET_VARS['mode'] ) : '';

if ( !empty($post_id) )
{ //added topic_last_post_id, p.post_time to sql
	$sql = "SELECT t.forum_id, t.topic_id, t.topic_last_post_id, p.post_time
		FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
		WHERE t.topic_id = p.topic_id
		AND t.topic_moved_id = 0
		AND p.post_id = $post_id
		AND p.post_draft= 0";
}
else if ( !empty($topic_id) )
{
	$sql = "SELECT t.forum_id, t.topic_id, t.topic_last_post_id
		FROM " . TOPICS_TABLE . " t
		WHERE t.topic_moved_id = 0
		AND t.topic_first_post_id > 0
		AND t.topic_id = $topic_id";
}
else
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
if ( !$result = $db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}
if ( !$row = $db->sql_fetchrow($result) )
{
	message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
$forum_id = $row['forum_id'];
$topic_id = $row['topic_id'];
$post_time = $row['post_time'];
$topic_last_post_id = $row['topic_last_post_id'];
//END MOD Keep_unread_2

//
// Start session management
//
$userdata = session_pagestart($user_ip, $forum_id);
init_userprefs($userdata);
//
// End session management
//

//START MOD Keep_unread_2 * Keep topic unread from given post onwards
if ($mode == 'unread')
{
	$board_config['tracking_unreads'][$topic_id] = $post_time-1; //testing for ">" only later on
	write_cookies($userdata);
	$message = $lang['keep_unread_done'] . '<br /><br />' .
	sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a> ') . '<br /><br />' .
	sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a> ');
	message_die(GENERAL_MESSAGE, $message);
}
$topic_last_read = topic_last_read($forum_id, $topic_id);
//END MOD Keep_unread_2

//
// Find topic id if user requested a newer
// or older topic
//
if ( isset($HTTP_GET_VARS['view']) && empty($HTTP_GET_VARS[POST_POST_URL]) )
{
	if ( $HTTP_GET_VARS['view'] == 'newest' )
	{ // read the first unread post in this topic
		$sql = "SELECT p.post_id, t.topic_last_post_id
			FROM (" . TOPICS_TABLE . " t
			LEFT JOIN " . POSTS_TABLE . " p ON p.topic_id = t.topic_id AND p.post_time > $topic_last_read)
			WHERE t.topic_id = $topic_id
			AND t.topic_moved_id = 0
			AND p.post_draft = 0
			ORDER BY p.post_time";
		if ( !$result = $db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
		}

		if ( !($row = $db->sql_fetchrow($result)) )
		{
			message_die(GENERAL_MESSAGE, 'No_new_posts_last_visit');
		}
		$post_id = empty($row['post_id']) ? $row['topic_last_post_id'] : $row['post_id'];
		redirect(append_sid("./viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id", true));
	}
Post Reply

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

cron