Warning: this is a long, detailed and off-topic post. If you are not curious about the pros and cons of adding back the original "view posts since last visit" function to a board that has keep unread installed, or about the code to add that function back, skip this post!
Merlin and I have spent a fair bit of time reverse engineering exactly how an unmodded phpbb's "View posts since last visit" function works and writing code to add that function back to a board that has keep unread installed. (Actually, writing the code to re-install the function itself took no time at all since we just need to replace a small bit of code that keep unread takes out, but reverse engineering how the old function actually works took some doing.)
Anyway, Merlin and I both remain convinced that adding this function back to a board that has keep unread installed will confuse users, that this function (in a clean phpbb board) works erratically, and that there are better ways than this function for users to get what they think they want. Specifically:
- If people don't like the list of unread posts that the keep unread mod supplies because it includes unread posts that the user has already decided he will never read, those users should be told that they can get rid of those old unread posts in the list by clicking the mark all forums read link that appears at the bottom left side of the index page
- If people want a list of posts in the last ___ hours or days or weeks (a time specified by the user), consider adding the following mod that is based on a mod Niels Chr. (at
http://mods.db9.dk) did a while back. The mod adds a dropdown menu at the bottom of the index page that allows the user to ask for a list of all posts in the last 15 minutes, 30 minutes, 45 minutes, 1 hour, 2 hours, 6 hours, 12 hours, 1 day. 7 days or one month. The code for that mod (as modified slightly by me to streamline it and change it to match a subsequent change to phpbb) is as follows:
Code: Select all
mod based on Niels Chr mod that adds a dropdown menu at the bottom of the index page allowing users to ask for a list of all posts in the last ___ hours or days:
#
#-----[ OPEN ]------------------------------------------------
#
search.php
#
#-----[ FIND ]------------------------------------------------
#
$search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : '';
#
#-----[ REPLACE WITH ]----------------------------------------
#
// Start replacement - Search back MOD
$search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : (($HTTP_POST_VARS['search_id'])? $HTTP_POST_VARS['search_id']:'');
// End replacement - Search back MOD
#
#-----[ FIND ]------------------------------------------------
#
$search_time = time() - ( ( ( !empty($HTTP_POST_VARS['search_time']) ) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']) ) * 86400 );
#
#-----[ REPLACE WITH ]----------------------------------------
#
// Start replacement - Search back MOD
$search_time = time() - ( ( ( !empty($HTTP_POST_VARS['search_time']) ) ? intval($HTTP_POST_VARS['search_time']) : intval($HTTP_GET_VARS['search_time']) ) * 60 );
// End replacement - Search back MOD
#
#-----[ FIND ]------------------------------------------------
#
WHERE post_time >= " . $userdata['user_lastvisit'];
#
#-----[ REPLACE WITH ]----------------------------------------
#
WHERE post_time >= " . (($search_time)? $search_time." AND post_time >= ":'' ).$userdata['user_lastvisit'];
#
#-----[ FIND ]------------------------------------------------
#
if( ( strpos($search_author, '%') !== false ) && ( strlen(str_replace('%', '', $search_author)) < $board_config['search_min_chars'] ) )
{
$search_author = '';
}
#
#-----[ REPLACE WITH ]----------------------------------------
#
/* mod for search back ... comment out the next three lines so that they don't mess up the search back in time mod
if( ( strpos($search_author, '%') !== false ) && ( strlen(str_replace('%', '', $search_author)) < $board_config['search_min_chars'] ) )
{
$search_author = '';
}
*/
#
#-----[ FIND ]------------------------------------------------
#
if( ( strpos($search_author, '%') !== false ) && ( strlen(str_replace('%', '', $search_author)) < $board_config['search_min_chars'] ) )
{
$search_author = '';
}
#
#-----[ REPLACE WITH ]----------------------------------------
#
/* mod for search back ... comment out the next three lines so that they don't mess up the search back in time mod
if( ( strpos($search_author, '%') !== false ) && ( strlen(str_replace('%', '', $search_author)) < $board_config['search_min_chars'] ) )
{
$search_author = '';
}
*/
#
#-----[ FIND ]------------------------------------------------
#
$previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
$previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
#
#-----[ REPLACE WITH ]----------------------------------------
#
// Start replacement - Search back MOD
$previous_days = array(0,15,30,60,120,360,720,1440,10080,20160,43200,129600,259200,524160);
$previous_days_text = array($lang['All_Posts'],
$lang['15_min'],$lang['30_min'],$lang['1_Hour'],$lang['2_Hour'],$lang['6_Hour'],$lang['12_Hour'],
$lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
// End replacement - Search back MOD
#
#-----[ OPEN ]------------------------------------------------
#
includes/page_header.php
#
#-----[ FIND ]------------------------------------------------
#
//
// The following assigns all _common_ variables that may be used at any point
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
// Start add - Search back MOD
$Select_time='<select name="search_time" size="1" onchange="SetLastVisit();" class="gensmall">
<option value="1" SELECTED> '.$lang['Select_time'].' </option>
<option value="15"> '.$lang['15_min'].'</option>
<option value="30"> '.$lang['30_min'].'</option>
<option value="45"> '.$lang['45_min'].'</option>
<option value="60"> '.$lang['1_Hour'].'</option>
<option value="120"> '.$lang['2_Hour'].'</option>
<option value="360"> '.$lang['6_Hour'].'</option>
<option value="720"> '.$lang['12_Hour'].'</option>
<option value="1440"> '.$lang['1_Day'].'</option>
<option value="10080"> '.$lang['7_Days'].'</option>
<option value="43200"> '.$lang['1_Month'].'</option>
</select>
<input type="hidden" name="search_author" value="*">
<input type="hidden" name="show_results" value="posts">';
// End add - Search back MOD
#
#-----[ FIND ]------------------------------------------------
#
'PAGE_TITLE' => $page_title,
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Start add - Search back MOD
'SELECT_TIME' => $Select_time,
// End add - Search back MOD
#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------------
#
?>
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
// Start add - Search back MOD
$lang['Select_time'] = 'View posts from last (select time)';
$lang['15_min'] = '15 min';
$lang['30_min'] = '30 min';
$lang['45_min'] = '45 min';
$lang['1_Hour'] = '1 Hour';
$lang['2_Hour'] = '2 Hours';
$lang['6_Hour'] = '6 Hours';
$lang['12_Hour'] = '12 Hours';
// End add - Search back MOD
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/index_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<table width="100%" cellspacing="0" cellpadding="2" border="0" align="center">
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
<!-- Start add - Search back MOD -->
<script language="javascript">
<!--
function SetLastVisit()
{
if (!document.LastVisitFrm.search_time.options[0].selected)
{
document.LastVisitFrm.submit();
}
return true;
}
//-->
</script>
<!-- End add - Search back MOD -->
#
#-----[ FIND ]------------------------------------------------
#
<td align="right"><span class="gensmall">{S_TIMEZONE}</span></td>
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
<!-- Start add - Search back MOD -->
<td align="center" class="gensmall">
<form name="LastVisitFrm" action="search.php" method="post">
{SELECT_TIME}
</td>
</form>
<!-- End add - Search back MOD -->
#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------------
#
# EoM
However, for people who still insist on adding back the 'view posts since last visit' function, I spell out the code changes below. But before spelling out those changes, I'll try to explain what happens in an unmodded phpbb board when a user clicks the "View posts since last visit" link. Obviously, the user sees a list of all topics that have been posted to since the user's 'last visit'. But the problem is in how 'last visit' is defined.
Here's a simple explanation of the problem: when a user navigates to the forum for a new visit, the list can be both over- and under-inclusive. It can in some cases:
- include posts that the user actually already read in his last visit
- not include some posts made towards the end of the prior visit that the user has never seen.
And here's a fuller explanation:
'Last visit' is supposed to mean the last time the user was active on the forum before the current session. But the way phpbb keeps track of 'last visit' and current session results in behavior that many users will not expect:
- The session generally only closes out if a user physically closes his browser (navigating away does NOT close out the session). So, suppose a user goes to the site in the evening, views 10 posts, navigates away (to google.com or some other site), leaves the browser open and goes to bed, and then in the morning goes back to the site with the same open browser. 'Last visit' will be stale and the list the user sees when he clicks the "view posts since last visit" link will inappropriately include the posts he already saw the night before. And if the user is in the habit of leaving on his computer and leaving the browser open perpetually, the list will grow longer and longer, including more and more posts he has already seen days or weeks ago. So for this feature to be even a little bit useful the user would have to be careful to close his browser when done with a session.
- When a session restarts, last visit gets updated to the last time the user navigated to or refreshed a phpbb page before the restart. That means if posts get made during a session and the user doesn't check the list at the very end of his session, the user may not see those posts during that session and they will not appear in the list the next time he goes to the forum. Instead, those posts will fall through the cracks.
- There is a lag of up to 60 seconds built into phpbb before session times get updated. So, suppose someone makes a post 59 seconds before a user signs off and the user reads that post and at the very end refreshes his browser to assure that everything is 'up to date'. That post may still show up in the list the next time he signs on since depending on the exact timing the 'last visit' time may pre-date the post.
- In some browsers (e.g. IE), a new session commences when a new occurance of the browser opens even if the old occurrance of the browser is still open. This can result in 'last visit' getting updated to a time close to the current time, and as a result the uesr suddenly loses everything in the list for no apparant reason. For example, suppose a user goes to the site with IE, is faced with a long list of posts since the last visit and reads the first post. Now suppose he opens a second occurance of IE and goes to the site. That resets 'last visit' to the last time he clicked on the forum with the first browser. And that means that the entire list of posts since real 'last visit' gets unexpectedly wiped out before he has a chance to read the other posts.
FInally, for completeness before setting forth the code for how to add back the "view posts since last visit" function, here is a technical explanation of exactly how phpbb keeps track of 'user_lastvisit':
1. The function session_begin() (in includes/sessions.php) gets called every time a user logs in anew or closes his browser and some time later navigates to the site. Session_begin():
- changes the user's user_lastvisit field in the db to become his old db user_session_time (which is generally the last time he went to or refreshed a phpbb page or within 60 seconds before that last time)
- updates the user's user_session_time field in the db to equal current_time()
- sets a cookie for the session that expires whenever the browser is closed.
2. The function session_pagestart() (also in includes/sessions.php) gets called every time a user goes to or refreshes a regular phpbb page, Session_pagestart() checks cookies to see if the user is part of an active session.
- If, according to the cookies, the user is part of an active session, and if the existing user_session_time is more than 60 seconds old, the user_session_time in the db gets updated (but nothing happens to the user_lastvisit).
- If, according to the cookies, the user is part of an active session, but the existing user_session_time is no more than 60 seconds old, nothing happens to user_lastvisit or user_session_time fields in the db (raising the possibility that a user could see posts in the last 60 seconds before he closes his browser that are inappropriately coutned as made since the last visit when the uesr next goes back to the site).
- If, according to the cookies, the user is not part of an active session, session_pagestart() (described above) gets called, and as a result the user_lastvisit in the db is reset to the last user_session_time in the db (i.e. the last time the user went to or refreshed a phpbb page or within 60 seconds before that last time) and user_session_time is reset to current time().
This should generally work as expected except:
- a user who never closes his browser will have an ever growing list of posts since his user_last_visit never gets reset (there is a 60 day limit on this in the code somewhere but 60 days is a lot of posts since the 'last visit'!)
- the lag of up to 60 seconds in updating user_session_time creates the possibility that a user who closes his browser and then goes back to the site will, when he clicks to 'view posts since last visit', see posts in the list that he has already read (i.e. posts that were posted within 60 seconds of the last time the user_session_time was updated)
- a user who opens multiple occurances of certain browsers like IE (without closing any occurances) triggers an updating of user_lastvisit (as though each occurance has its own cookies) and that can result in the posts since last visit list being unexpectedly wiped out (I think this happens because a second occurance of IE apparantly does not share cookies with the first and thus when a user opens up a second occurance of IE that occurance has no _sid cookie indicating an active session already going).
Below, I set forth three alternative sets of code changes, to give you three different options for adding back this function. If you decide to install one of these alternatives on your board, we suggest you come up with a standard disclaimer that will explain to users that this function is erratic and nonintuitive and that it may not be a good idea to use it.
FIRST ALTERNATIVE
This adds back the view posts since last visit function but no link.
To get to the list of posts since last visit, users navigate their
browsers to http://[domain]/search.php?search_id=newposts&classic=1
They can save that link as a browser favorite to make it easier to use.
Here's the code:
Code: Select all
#
#-----[ OPEN ]------------------------------------------------
#
search.php
#
#-----[ FIND ]------------------------------------------------
#
if ( $search_id == 'newposts' )
#
#-----[ REPLACE WITH ]----------------------------------------
#
//START MOD Keep_unread_2
if ( $search_id == 'newposts' && isset($HTTP_GET_VARS['classic']) )
{
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';
}
else if ( $search_id == 'newposts' )
#
#-----[ FIND ]------------------------------------------------
#
//Don't add post if you've read it and you want new posts only
if ( ($search_id == 'newposts') )
#
#-----[ REPLACE WITH ]----------------------------------------
#
//Don't add post if you've read it and you want unread posts only
if ( ($search_id == 'newposts') && !isset($HTTP_GET_VARS['classic']) )
SECOND ALTERNATIVE
This adds back the view posts since last visit function,
and also adds a link on the index page
(right under the view unread posts link) for any user who chooses
that option in his profile. Here's the code:
Code: Select all
#
#-----[ SQL ]-------------------------------------------------
#
ALTER TABLE phpbb_users ADD user_show_classic_newpost_link TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL;
#
#-----[ OPEN ]------------------------------------------------
#
search.php
#
#-----[ FIND ]------------------------------------------------
#
if ( $search_id == 'newposts' )
#
#-----[ REPLACE WITH ]----------------------------------------
#
//START MOD Keep_unread_2
if ( $search_id == 'newposts' && isset($HTTP_GET_VARS['classic']) )
{
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';
}
else if ( $search_id == 'newposts' )
#
#-----[ FIND ]------------------------------------------------
#
//Don't add post if you've read it and you want new posts only
if ( ($search_id == 'newposts') )
#
#-----[ REPLACE WITH ]----------------------------------------
#
//Don't add post if you've read it and you want unread posts only
if ( ($search_id == 'newposts') && !isset($HTTP_GET_VARS['classic']) )
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_users.php
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = ( isset( $HTTP_POST_VARS['allowsmilies']) ) ? intval( $HTTP_POST_VARS['allowsmilies'] ) : $board_config['allow_smilies'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = ( isset($HTTP_POST_VARS['show_classic_newpost_link']) ) ? intval( $HTTP_POST_VARS['show_classic_newpost_link'] ) : 0;
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
SET " . $username_sql .
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
user_allowsmile = $allowsmilies,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------------
#
user_show_classic_newpost_link = $show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = $this_userdata['user_allowsmile'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = $this_userdata['user_show_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
#
$s_hidden_fields .= '<input type="hidden" name="allowsmilies" value="' . $allowsmilies . '" />';
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$s_hidden_fields .= '<input type="hidden" name="show_classic_newpost_link" value="' . $show_classic_newpost_link . '" />';
#
#-----[ FIND ]------------------------------------------------
#
'ALWAYS_ALLOW_SMILIES_NO' => (!$allowsmilies) ? 'checked="checked"' : '',
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'SHOW_CLASSIC_NEWPOST_LINK_YES' => ( $show_classic_newpost_link ) ? 'checked="checked"' : '',
'SHOW_CLASSIC_NEWPOST_LINK_NO' => ( !$show_classic_newpost_link ) ? 'checked="checked"' : '',
#
#-----[ FIND ]------------------------------------------------
#
'L_ALWAYS_ALLOW_SMILIES' => $lang['Always_smile'],
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'L_SHOW_CLASSIC_NEWPOST_LINK' => $lang['Show_classic_newpost_link'],
#
#-----[ OPEN ]------------------------------------------------
#
includes/page_header.php
#
#-----[ FIND ]------------------------------------------------
#
//START MOD Keep_unread_2
#
#-----[ AFTER, ADD ]------------------------------------------------
#
// check to see if the user has opted to include a link for posts since last visit and if so, set flag
if ($userdata['user_show_classic_newpost_link'])
{
$template->assign_block_vars('switch_show_classic_newpost_link', array());
}
#
#-----[ FIND ]------------------------------------------------
#
'L_SEARCH_NEW' => ($new_unreads) ? $lang['View_unread_posts'] : $lang['No_unread_posts'],
#
#-----[ AFTER, ADD ]----------------------------------------
#
'L_SEARCH_CLASSIC_NEW' => $lang['Search_classic_new'],
#
#-----[ FIND ]------------------------------------------------
#
'U_SEARCH_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts'),
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'U_SEARCH_CLASSIC_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts&classic=1'),
#
#-----[ OPEN ]------------------------------------------------
#
includes/usercp_register.php
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = ( isset($HTTP_POST_VARS['allowsmilies']) ) ? ( ($HTTP_POST_VARS['allowsmilies']) ? TRUE : 0 ) : 0$board_config['allow_smilies'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = ( isset($HTTP_POST_VARS['show_classic_newpost_link']) ) ? ( ($HTTP_POST_VARS['show_classic_newpost_link']) ? TRUE : 0 ) : 0;
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = ( isset($HTTP_POST_VARS['allowsmilies']) ) ? ( ($HTTP_POST_VARS['allowsmilies']) ? TRUE : 0 ) : $userdata['user_allowsmile'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = ( isset($HTTP_POST_VARS['show_classic_newpost_link']) ) ? ( ($HTTP_POST_VARS['show_classic_newpost_link']) ? TRUE : 0 ) : $userdata['user_show_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
SET " . $username_sql . $
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
user_allowsmile = $allowsmilies,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------------
#
user_show_classic_newpost_link = $show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
$sql = "INSERT INTO " . USERS_TABLE
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
user_allowsmile,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------------
#
user_show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
VALUES ($user_id, '"
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
$allowsmilies,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = $userdata['user_allowsmile'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = $userdata['user_show_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
#
'ALWAYS_ALLOW_SMILIES_NO' => ( !$allowsmilies ) ? 'checked="checked"' : '',
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'SHOW_CLASSIC_NEWPOST_LINK_YES' => ( $show_classic_newpost_link ) ? 'checked="checked"' : '',
'SHOW_CLASSIC_NEWPOST_LINK_NO' => ( !$show_classic_newpost_link ) ? 'checked="checked"' : '',
#
#-----[ FIND ]------------------------------------------------
#
'L_ALWAYS_ALLOW_SMILIES' => $lang['Always_smile'],
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'L_SHOW_CLASSIC_NEWPOST_LINK' => $lang['Show_classic_newpost_link'],
#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------------
#
$lang['Search_new'] = 'View unread posts';
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$lang['Search_classic_new'] = 'View posts since last visit';
$lang['Show_classic_newpost_link'] = 'Add link for posts since last visit (not recommended)';
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/index_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br /><a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br />
#
#-----[ REPLACE WITH ]-----------------------------------------
#
<a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br />
<!-- BEGIN switch_show_classic_newpost_link -->
<a href="{U_SEARCH_CLASSIC_NEW}" class="gensmall">{L_SEARCH_CLASSIC_NEW}</a><br />
<!-- END switch_show_classic_newpost_link -->
<a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br />
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/profile_add_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<tr>
<td class="row1"><span class="gen">{L_BOARD_LANGUAGE}:</span></td>
#
#-----[ BEFORE, ADD ]------------------------------------------------
#
<tr>
<td class="row1"><span class="gen">{L_SHOW_CLASSIC_NEWPOST_LINK}:</span></td>
<td class="row2">
<input type="radio" name="show_classic_newpost_link" value="1" {SHOW_CLASSIC_NEWPOST_LINK_YES} />
<span class="gen">{L_YES}</span>
<input type="radio" name="show_classic_newpost_link" value="0" {SHOW_CLASSIC_NEWPOST_LINK_NO} />
<span class="gen">{L_NO}</span></td>
</tr>
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/user_edit_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<tr>
<td class="row1"><span class="gen">{L_BOARD_LANGUAGE}</span></td>
#
#-----[ BEFORE, ADD]------------------------------------------------
#
<tr>
<td class="row1"><span class="gen">{L_SHOW_CLASSIC_NEWPOST_LINK}</span></td>
<td class="row2">
<input type="radio" name="show_classic_newpost_link" value="1" {SHOW_CLASSIC_NEWPOST_LINK_YES} />
<span class="gen">{L_YES}</span>
<input type="radio" name="show_classic_newpost_link" value="0" {SHOW_CLASSIC_NEWPOST_LINK_NO} />
<span class="gen">{L_NO}</span></td>
</tr>
THIRD ALTERNATIVE
This adds back the view posts since last visit function,
and also adds a link on the index page
(right under the view unread posts link) for any user who chooses
that option in his profile. However, it only allows users to select
that option if the admin has choosen to activate the feature
in the config page of the ACP. Here's the code:
Code: Select all
#
#-----[ SQL ]-------------------------------------------------
#
INSERT INTO phpbb_config (config_name,config_value) VALUES ('allow_classic_newpost_link',0);
ALTER TABLE phpbb_users ADD user_show_classic_newpost_link TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL;
#
#-----[ OPEN ]------------------------------------------------
#
search.php
#
#-----[ FIND ]------------------------------------------------
#
if ( $search_id == 'newposts' )
#
#-----[ REPLACE WITH ]----------------------------------------
#
//START MOD Keep_unread_2
if ( $search_id == 'newposts' && isset($HTTP_GET_VARS['classic']) )
{
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';
}
else if ( $search_id == 'newposts' )
#
#-----[ FIND ]------------------------------------------------
#
//Don't add post if you've read it and you want new posts only
if ( ($search_id == 'newposts') )
#
#-----[ REPLACE WITH ]----------------------------------------
#
//Don't add post if you've read it and you want unread posts only
if ( ($search_id == 'newposts') && !isset($HTTP_GET_VARS['classic']) )
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_board.php
#
#-----[ FIND ]------------------------------------------------
#
$smile_no = ( !$new['allow_smilies'] ) ? "checked=\"checked\"" : "";
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$allow_classic_newpost_link_yes = ( $new['allow_classic_newpost_link'] ) ? "checked=\"checked\"" : "";
$allow_classic_newpost_link_no = ( !$new['allow_classic_newpost_link'] ) ? "checked=\"checked\"" : "";
#
#-----[ FIND ]------------------------------------------------
#
"L_ALLOW_SMILIES" => $lang['Allow_smilies'],
#
#-----[ AFTER, ADD ]------------------------------------------------
#
"L_ALLOW_CLASSIC_NEWPOST_LINK" => $lang['Allow_classic_newpost_link'],
#
#-----[ FIND ]------------------------------------------------
#
"SMILE_NO" => $smile_no,
#
#-----[ AFTER, ADD ]------------------------------------------------
#
"ALLOW_CLASSIC_NEWPOST_LINK_YES" => $allow_classic_newpost_link_yes,
"ALLOW_CLASSIC_NEWPOST_LINK_NO" => $allow_classic_newpost_link_no,
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_users.php
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = ( isset( $HTTP_POST_VARS['allowsmilies']) ) ? intval( $HTTP_POST_VARS['allowsmilies'] ) : $board_config['allow_smilies'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = ( isset($HTTP_POST_VARS['show_classic_newpost_link']) ) ? intval( $HTTP_POST_VARS['show_classic_newpost_link'] ) : $board_config['allow_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
SET " . $username_sql .
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
user_allowsmile = $allowsmilies,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------------
#
user_show_classic_newpost_link = $show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = $this_userdata['user_allowsmile'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = $this_userdata['user_show_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
#
$s_hidden_fields .= '<input type="hidden" name="allowsmilies" value="' . $allowsmilies . '" />';
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$s_hidden_fields .= '<input type="hidden" name="show_classic_newpost_link" value="' . $show_classic_newpost_link . '" />';
#
#-----[ FIND ]------------------------------------------------
#
$template->set_filenames(array(
"body" => "admin/user_edit_body.tpl")
);
#
#-----[ AFTER, ADD ]------------------------------------------------
#
if ( $board_config['allow_classic_newpost_link'] )
{
$template->assign_block_vars('switch_show_classic_newpost_option', array());
}
#
#-----[ FIND ]------------------------------------------------
#
'ALWAYS_ALLOW_SMILIES_NO' => (!$allowsmilies) ? 'checked="checked"' : '',
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'SHOW_CLASSIC_NEWPOST_LINK_YES' => ( $show_classic_newpost_link ) ? 'checked="checked"' : '',
'SHOW_CLASSIC_NEWPOST_LINK_NO' => ( !$show_classic_newpost_link ) ? 'checked="checked"' : '',
#
#-----[ FIND ]------------------------------------------------
#
'L_ALWAYS_ALLOW_SMILIES' => $lang['Always_smile'],
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'L_SHOW_CLASSIC_NEWPOST_LINK' => $lang['Show_classic_newpost_link'],
#
#-----[ OPEN ]------------------------------------------------
#
includes/page_header.php
#
#-----[ FIND ]------------------------------------------------
#
//START MOD Keep_unread_2
#
#-----[ AFTER, ADD ]------------------------------------------------
#
// check to see if the user has opted to include a link for posts since last visit and if so, set flag
if ($userdata['user_show_classic_newpost_link'] && $board_config['allow_classic_newpost_link'])
{
$template->assign_block_vars('switch_show_classic_newpost_link', array());
}
#
#-----[ FIND ]------------------------------------------------
#
'L_SEARCH_NEW' => ($new_unreads) ? $lang['View_unread_posts'] : $lang['No_unread_posts'],
#
#-----[ AFTER, ADD ]----------------------------------------
#
'L_SEARCH_CLASSIC_NEW' => $lang['Search_classic_new'],
#
#-----[ FIND ]------------------------------------------------
#
'U_SEARCH_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts'),
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'U_SEARCH_CLASSIC_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts&classic=1'),
#
#-----[ OPEN ]------------------------------------------------
#
includes/usercp_register.php
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = ( isset($HTTP_POST_VARS['allowsmilies']) ) ? ( ($HTTP_POST_VARS['allowsmilies']) ? TRUE : 0 ) : $board_config['allow_smilies'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = ( isset($HTTP_POST_VARS['show_classic_newpost_link']) ) ? ( ($HTTP_POST_VARS['show_classic_newpost_link']) ? TRUE : 0 ) : $board_config['allow_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = ( isset($HTTP_POST_VARS['allowsmilies']) ) ? ( ($HTTP_POST_VARS['allowsmilies']) ? TRUE : 0 ) : $userdata['user_allowsmile'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = ( isset($HTTP_POST_VARS['show_classic_newpost_link']) ) ? ( ($HTTP_POST_VARS['show_classic_newpost_link']) ? TRUE : 0 ) : $userdata['user_show_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
SET " . $username_sql . $
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
user_allowsmile = $allowsmilies,
#
#-----[ IN-LINE AFTER, FIND ]------------------------------------------------
#
user_show_classic_newpost_link = $show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
$sql = "INSERT INTO " . USERS_TABLE
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
user_allowsmile,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------------
#
user_show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
# note: actual line is longer
VALUES ($user_id, '"
#
#-----[ IN-LINE FIND ]------------------------------------------------
#
$allowsmilies,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link,
#
#-----[ FIND ]------------------------------------------------
#
$allowsmilies = $userdata['user_allowsmile'];
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$show_classic_newpost_link = $userdata['user_show_classic_newpost_link'];
#
#-----[ FIND ]------------------------------------------------
#
$template->set_filenames(array(
'body' => 'profile_add_body.tpl')
);
#
#-----[ AFTER, ADD ]------------------------------------------------
#
if ( $board_config['allow_classic_newpost_link'] )
{
$template->assign_block_vars('switch_show_classic_newpost_option', array());
}
#
#-----[ FIND ]------------------------------------------------
#
'ALWAYS_ALLOW_SMILIES_NO' => ( !$allowsmilies ) ? 'checked="checked"' : '',
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'SHOW_CLASSIC_NEWPOST_LINK_YES' => ( $show_classic_newpost_link ) ? 'checked="checked"' : '',
'SHOW_CLASSIC_NEWPOST_LINK_NO' => ( !$show_classic_newpost_link ) ? 'checked="checked"' : '',
#
#-----[ FIND ]------------------------------------------------
#
'L_ALWAYS_ALLOW_SMILIES' => $lang['Always_smile'],
#
#-----[ AFTER, ADD ]------------------------------------------------
#
'L_SHOW_CLASSIC_NEWPOST_LINK' => $lang['Show_classic_newpost_link'],
#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_admin.php
#
#-----[ FIND ]------------------------------------------------
#
$lang['Allow_smilies'] = 'Allow Smilies';
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$lang['Allow_classic_newpost_link'] = 'Allow users to add link for posts since last visit (not recommended)';
#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------------
#
$lang['Search_new'] = 'View unread posts';
#
#-----[ AFTER, ADD ]------------------------------------------------
#
$lang['Search_classic_new'] = 'View posts since last visit';
$lang['Show_classic_newpost_link'] = 'Add link for posts since last visit (not recommended)';
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/index_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br /><a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br />
#
#-----[ REPLACE WITH ]-----------------------------------------
#
<a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br />
<!-- BEGIN switch_show_classic_newpost_link -->
<a href="{U_SEARCH_CLASSIC_NEW}" class="gensmall">{L_SEARCH_CLASSIC_NEW}</a><br />
<!-- END switch_show_classic_newpost_link -->
<a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br />
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/profile_add_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<tr>
<td class="row1"><span class="gen">{L_BOARD_LANGUAGE}:</span></td>
#
#-----[ BEFORE, ADD ]------------------------------------------------
#
<!-- BEGIN switch_show_classic_newpost_option -->
<tr>
<td class="row1"><span class="gen">{L_SHOW_CLASSIC_NEWPOST_LINK}:</span></td>
<td class="row2">
<input type="radio" name="show_classic_newpost_link" value="1" {SHOW_CLASSIC_NEWPOST_LINK_YES} />
<span class="gen">{L_YES}</span>
<input type="radio" name="show_classic_newpost_link" value="0" {SHOW_CLASSIC_NEWPOST_LINK_NO} />
<span class="gen">{L_NO}</span></td>
</tr>
<!-- END switch_show_classic_newpost_option -->
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/board_config_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<tr>
<td class="row1">{L_ALLOW_SMILIES}</td>
<td class="row2"><input type="radio" name="allow_smilies" value="1" {SMILE_YES} /> {L_YES} <input type="radio" name="allow_smilies" value="0" {SMILE_NO} /> {L_NO}</td>
</tr>
#
#-----[ AFTER, ADD ]------------------------------------------------
#
<tr>
<td class="row1">{L_ALLOW_CLASSIC_NEWPOST_LINK}</td>
<td class="row2"><input type="radio" name="allow_classic_newpost_link" value="1" {ALLOW_CLASSIC_NEWPOST_LINK_YES} /> {L_YES} <input type="radio" name="allow_classic_newpost_link" value="0" {ALLOW_CLASSIC_NEWPOST_LINK_NO} /> {L_NO}</td>
</tr>
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/user_edit_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
<tr>
<td class="row1"><span class="gen">{L_BOARD_LANGUAGE}</span></td>
#
#-----[ BEFORE, ADD]------------------------------------------------
#
<!-- BEGIN switch_show_classic_newpost_option -->
<tr>
<td class="row1"><span class="gen">{L_SHOW_CLASSIC_NEWPOST_LINK}</span></td>
<td class="row2">
<input type="radio" name="show_classic_newpost_link" value="1" {SHOW_CLASSIC_NEWPOST_LINK_YES} />
<span class="gen">{L_YES}</span>
<input type="radio" name="show_classic_newpost_link" value="0" {SHOW_CLASSIC_NEWPOST_LINK_NO} />
<span class="gen">{L_NO}</span></td>
</tr>
<!-- END switch_show_classic_newpost_option -->