<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="modx.prosilver.en.xsl"?><!--For security purposes, please check: http://www.phpbb.com/mods/ for the latest version of this MOD. Although MODs are checked before being allowed in the MODs Database there is no guarantee that there are no security problems within the MOD. No support will be given for MODs not found within the MODs Database which can be found at http://www.phpbb.com/mods/-->
<mod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phpbb.com/mods/xml/modx-1.2.1.xsd">
	<header>
		<license>http://opensource.org/licenses/gpl-license.php GNU General Public License v2</license>
		<title lang="en">View or mark unread posts</title>
		<description lang="en">Adds a 'View unread posts' or 'You have no unread posts' link on the index page (and, for subsilver2, each other page).  Also adds a 'Mark post as unread' link at the bottom of each post and a mark pm as unread link at the bottom of each private message as well as a folder in the private messages part of the UCP for unread pms. </description>
		<author-notes lang="en">I have included extensive author notes in a separate file called author_notes.txt that appears in the contrib/readme_files folder.  Please read that because it gives lots of information about how to customize this mod and answers lots of questions.  Also note that if you have installed the preserve global unread flags mod, you should use the alternate functions_view_or_mark_unread_posts.php file that appears in the contrib/alternate_file folder</author-notes>
		<author-group>
			<author>
				<realname>Alan</realname>
				<username>asinshesq</username>
			</author>
		</author-group>
		<mod-version>1.0.5c</mod-version>
		<installation>
			<level>easy</level>
			<time>1200</time>
			<target-version>3.0.4</target-version>
		</installation>
		<history>
			<entry>
				<date>2008-12-29</date>
				<rev-version>1.0.5c</rev-version>
				<changelog lang="en">
					<change>cleaned up the code in the mark_post_unread() function (should speed up the db queries) and re-wrote the unread_tracking_info.txt file that appears in the readme folder (if you already have 1.0.5 or 1.0.5a installed you just need to replace functions_view_or_mark_unread_posts.php and re-do the changes to viewtopic that the install.xml file tells you to make)</change>
				</changelog>
			</entry>		
			<entry>
				<date>2008-12-24</date>
				<rev-version>1.0.5b</rev-version>
				<changelog lang="en">
					<change>revised code to deal with global announcements more dependibly and revised various readme and notes files (if you already have 1.0.5 or 1.0.5a installed you just need to replace functions_view_or_mark_unread_posts.php and re-do the changes to viewtopic that the install.xml file tells you to make)</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-12-10</date>
				<rev-version>1.0.5a</rev-version>
				<changelog lang="en">
					<change>added changes to dovetail with phpbb3.0.3 changes</change>
					<change>fixed bug that caused unreads to show up in unread box even if user is over the pm limit and the unread pm should really only appear in the hold box</change>
					<change>fixed bug that prevented a forum from being shown as unread on the index page if the only unread post in the forum is the latest post in the forum</change>
					<change>fixed bug that sometimes caused the link not to toggle to "View your unread posts" when the user is in viewforum for a category or forum that has subforums</change>
					<change>added code to supress 'move to unreadbox' entry in pm dropdown menu</change>
					<change>re-did code in functions_view_or_mark_unread_posts.php to properly deal with unread global announcments (but note that this will take an extra query so people with huge boards who want to save a query should read the author's notes carefully)</change>
					<change>Note: all changes from version 1.0.4 to 1.0.5a have been posted on the phpbb.com topic for this mod on or before December 10, 2008.  If you have already made these changes you do not need to upgrade your mod installation other than as set forth in the entry for version 1.0.5b above, but for people who have not made these changes I include an upgrade_1-0-4_to_1-0-5b mod in the contrib folder</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-02-04</date>
				<rev-version>1.0.4</rev-version>
				<changelog lang="en">
					<change>fixed bug that caused unreadbox to display instead of other mailboxes</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-02-03</date>
				<rev-version>1.0.3</rev-version>
				<changelog lang="en">
					<change>added an 'Unread messages' folder that appears right under the 'Sentmessages' folder in the private messages area of the UCP</change>
					<change>because there is now a unread pm folder, got rid of code that assigned a url to a link for viewing pms that could be added in other parts of the forum</change>
					<change>added link in search results that appears only when viewing the unread post list and that allows user to mark all forums read (thanks to moifest for the idea)</change>
					<change> added code so that, when a user's browser navigates to the unread post search list but the user is not logged in, the user gets redirected to a login screen with a message saying the user can only view the list of unread posts if he is logged in (thanks to ChriZathens for the idea and some of the code)</change>
					<change>fixed bug that could lead to odd behavior when a user used mark post unread feature in different forums</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-01-27</date>
				<rev-version>1.0.2</rev-version>
				<changelog lang="en">
					<change>added a line in functions_view_or_mark_unread_posts.php to update the unread pm count immediately after a user marks a pm unread (rather than waiting for the regular updating that phpbb3 would do later on)</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-12-25</date>
				<rev-version>1.0.1</rev-version>
				<changelog lang="en">
					<change>fixed bug that would, in determining whether the link should read 'view unread posts' or 'you have no unread posts', ignore unread posts in subforums</change>
					<change>added feature to mark pms unread and to list all unread pms</change>
					<change>made other small changes required for validation</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-09-15</date>
				<rev-version>1.0.0</rev-version>
				<changelog lang="en">
					<change>updated instructions to reflect the deletion of the bugfix change in version 0.0.4</change>
					<change>converted mod script to modx, submitted mod to moddb for validation</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-07-04</date>
				<rev-version>0.0.4</rev-version>
				<changelog lang="en">
					<change>deleted a RC1 bugfix change that has now been fixed in RC2</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-06-12</date>
				<rev-version>0.0.3</rev-version>
				<changelog lang="en">
					<change>fixed small bug that would generate non-fatal php notices when using phpbb in debug mode</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-06-04</date>
				<rev-version>0.0.2</rev-version>
				<changelog lang="en">
					<change>fixed toggling of link text ('View unread posts' to 'You have no unread posts')></change>
				</changelog>
			</entry>
			<entry>
				<date>2007-05-31</date>
				<rev-version>0.0.1</rev-version>
				<changelog lang="en">
					<change>initial version</change>
				</changelog>
			</entry>
		</history>
		<link-group>
		    <link type="template" lang="en" href="contrib/subsilver2.xml">Additional instructions for changes to subsilver2</link>
		    <link type="contrib" lang="en" href="contrib/upgrade_scripts/upgrade_1-0-4_to_1-0-5c.xml">Instructions for upgrading from version 1.0.4 to 1.0.5c</link>
		</link-group>
	</header>
	<action-group>
		<copy>
			<file from="root/includes/functions_view_or_mark_unread_posts.php" to="includes/functions_view_or_mark_unread_posts.php"/>
		</copy>
		<open src="common.php">
			<edit>
				<find><![CDATA[require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);]]></find>
				<action type="after-add"><![CDATA[// start mod view or mark unread posts
require($phpbb_root_path . 'includes/functions_view_or_mark_unread_posts.' . $phpEx);
// end mod view or mark unread posts]]></action>
			</edit>
		</open>
		<open src="search.php">
			<edit>
				<find><![CDATA[			case 'egosearch':]]></find>
				<action type="before-add"><![CDATA[			// start mod view or mark unread posts
			case 'unread':
				$sql = unread_list_sql($l_search_title, $show_results, $sort_key, $sort_dir, $sort_by_sql, $sql_sort, $limit_days, $sort_by_text, $sort_days, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $m_approve_fid_sql, $ex_fid_ary, $field);
			break;
			// end mod view or mark unread posts]]></action>
			</edit>
		</open>
		<open src="viewtopic.php">
			<edit>
				<find><![CDATA[$hilit_words	= request_var('hilit', '', true);]]></find>
				<action type="after-add"><![CDATA[// start mod view or mark unread posts
$unread_post_id	= request_var('mu', 0);
if ($unread_post_id)
{
	mark_unread_post($unread_post_id, $forum_id);
}
// end mod view or mark unread posts]]></action>
			</edit>
			<edit>
				<find><![CDATA[		'U_DELETE']]></find>
				<action type="after-add"><![CDATA[		// start mod view or mark unread posts
		'U_MARK_UNREAD'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'mu=' . $row['post_id'] . '&amp;f=' . $forum_id),
		// end mod  view or mark unread posts]]></action>
			</edit>
		</open>
		<open src="includes/constants.php">
			<edit>
				<find><![CDATA[// Private messaging - Do NOT change these values]]></find>
				<action type="after-add"><![CDATA[// start mod view or mark unread posts (and end mod too)...added the next line
define('PRIVMSGS_UNREADBOX', -5);]]></action>
			</edit>
		</open>
		<open src="includes/functions.php">
			<edit>
				<find><![CDATA[	// The following assigns all _common_ variables that may be used at any point in a template.]]></find>
				<action type="before-add"><![CDATA[	// start mod view or mark unread posts
	if ($config['load_db_lastread'] && $user->data['is_registered'])
	{
		$u_search_unread = append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=unread');
		$s_exists_unreads = check_unread_posts();
		$s_inc_unread_link = true;
	}
	else
	{
		$u_search_unread = $s_exists_unreads = $s_inc_unread_link = false;
	}
	// end mod view or mark unread posts]]></action>
			</edit>
			<edit>
				<find><![CDATA[		'U_SEARCH_UNANSWERED']]></find>
				<action type="after-add"><![CDATA[		// start mod view or mark unread posts
		'U_SEARCH_UNREAD'		=> $u_search_unread,
		'S_EXISTS_UNREADS'		=> $s_exists_unreads,
		'S_INC_UNREAD_LINK'		=> $s_inc_unread_link,
		// end mod view or mark unread posts]]></action>
			</edit>
		</open>
		<open src="includes/functions_display.php">
			<edit>
				<find><![CDATA[	foreach ($forum_rows as $row)]]></find>
				<action type="before-add"><![CDATA[	// start mod view or mark unread post
	// initialize the flag $exists_unread to signal that we have already checked unreads in functions_display()
	// so that when check_unread_posts() is called in the future it can skip the sql query and give the
	// answer that there are none (this gets reset to '1' later on in functions_display() if there are unreads),
	// but do NOT initialize if the user is on viewforum since the test for unreads may give false negatives in that context
	if (!$sql_where)
	{
		global $exists_unreads;
		$exists_unreads = -1;
	}
	// end mod view or mark unread posts]]></action>
			</edit>
			<edit>
				<find><![CDATA[		// Which folder should we display?]]></find>
				<action type="before-add"><![CDATA[		// start mod view or mark unread posts
		if ($forum_unread)
		{
			// if there are any unread topics, set $exists_unreads flag to 1 so that
			// when check_unreads_flag() is called in the future it can skip the sql query
			// and give the answer that there are unread posts'
			$exists_unreads = 1;
		}
		// end mod view or mark unread posts]]></action>
			</edit>
		</open>
		<open src="includes/functions_privmsgs.php">
			<edit>
				<find><![CDATA[	while ($row = $db->sql_fetchrow($result))
	{
		$num_messages[(int) $row['folder_id']] = $row['num_messages'];
		$num_unread[(int) $row['folder_id']] = $row['num_unread'];
	}]]></find>
				<action type="replace-with"><![CDATA[	// start mod view or mark unread posts
	// edited the block below to keep track of $total_board_unreads
	$total_board_unreads = 0;
	while ($row = $db->sql_fetchrow($result))
	{
		$num_messages[(int) $row['folder_id']] = $row['num_messages'];
		$num_unread[(int) $row['folder_id']] = $row['num_unread'];
		$total_board_unreads += $row['num_unread'];
	}
	// end mod view or mark unread posts]]></action>
			</edit>
			<edit>
				<find><![CDATA[	// Define Folder Array for template designers (and for making custom folders usable by the template too)
	foreach ($folder as $f_id => $folder_ary)
	{
		$folder_id_name = ($f_id == PRIVMSGS_INBOX) ? 'inbox' : (($f_id == PRIVMSGS_OUTBOX) ? 'outbox' : 'sentbox');]]></find>
				<action type="replace-with"><![CDATA[	// start mod view or mark unread posts
	$folder[PRIVMSGS_UNREADBOX] = array(
		'folder_name'		=> $user->lang['UNREAD_MESSAGES'],
		'num_messages'		=> $total_board_unreads,
		'unread_messages'	=> $total_board_unreads
	);
	//end mod view or mark unread posts

	// Define Folder Array for template designers (and for making custom folders usable by the template too)
	foreach ($folder as $f_id => $folder_ary)
	{
		// start mod view or mark unread posts (and end mod too)...added reference to unreads in next line
		$folder_id_name = ($f_id == PRIVMSGS_INBOX) ? 'inbox' : (($f_id == PRIVMSGS_OUTBOX) ? 'outbox' : (($f_id == PRIVMSGS_UNREADBOX) ? 'unreadbox' : 'sentbox'));]]></action>
			</edit>
		</open>
		<open src="includes/ucp/ucp_pm.php">
			<edit>
				<find><![CDATA[		if (!in_array($folder_specified, array('inbox', 'outbox', 'sentbox')))
		{
			$folder_specified = (int) $folder_specified;
		}
		else
		{
			$folder_specified = ($folder_specified == 'inbox') ? PRIVMSGS_INBOX : (($folder_specified == 'outbox') ? PRIVMSGS_OUTBOX : PRIVMSGS_SENTBOX);
		}]]></find>
				<action type="replace-with"><![CDATA[		// start mod view or mark unread posts
		$msg_id = request_var('mu', 0);
		if ($msg_id)
		{
			mark_unread_pm($msg_id);
		}

		// the block below is in regular phpbb3 but I added refences to unreadbox
		if (!in_array($folder_specified, array('inbox', 'outbox', 'unreadbox', 'sentbox')))
		{
			$folder_specified = (int) $folder_specified;
		}
		else
		{
			$folder_specified = ($folder_specified == 'inbox') ? PRIVMSGS_INBOX : (($folder_specified == 'outbox') ? PRIVMSGS_OUTBOX : (($folder_specified == 'unreadbox') ? PRIVMSGS_UNREADBOX : PRIVMSGS_SENTBOX));
		}
		// end mod view or mark unread posts]]></action>
			</edit>
			<edit>
				<find><![CDATA[					$s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';]]></find>
				<action type="replace-with"><![CDATA[					// start mod view or mark unread posts (and end mod too)...added reference to unreadbox in next line to supress move to unread box entry in dropdown menu
					$s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX && $f_id != PRIVMSGS_UNREADBOX) ? $option : '';]]></action>
			</edit>
			<edit>
				<find><![CDATA[					'U_INBOX'				=> $this->u_action . '&amp;folder=inbox',]]></find>
				<action type="after-add"><![CDATA[					'U_MARK_UNREAD'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;f=' . $folder_id . '&amp;mu=' . $msg_id),
					// start mod view or mark unread posts (and end mod too)...added the preceding line about marking unread pms]]></action>
			</edit>
		</open>
		<open src="includes/ucp/ucp_pm_viewfolder.php">
			<edit>
				<find><![CDATA[				if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id)]]></find>
				<action type="replace-with"><![CDATA[				// start mod view or mark unread posts (and end mod too)...added reference to unreadbox in next line to supress move to unread box entry in dropdown menu
				if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id || $f_id == PRIVMSGS_UNREADBOX)]]></action>
			</edit>
			<edit>
				<find><![CDATA[				$view_message_url =]]></find>
				<inline-edit>
					<inline-find><![CDATA[$folder_id]]></inline-find>
					<inline-action type="replace-with"><![CDATA[" . $row['folder_id'] . "]]></inline-action>
				</inline-edit>
				<action type="after-add"><![CDATA[				// start mod view or mark unread posts (and end mod too)...changed $folder_id to $row['folder_id']
				// since items in the 'unread box' actually come from different folders]]></action>
			</edit>
			<edit>
				<find><![CDATA[	$folder_sql = 't.folder_id = ' . (int) $folder_id;]]></find>
				<action type="replace-with"><![CDATA[	// start mod view or mark unread posts (and end mod too)...added test for unreads in next line
	$folder_sql = ($folder_id == PRIVMSGS_UNREADBOX) ? '((t.pm_new = 1 OR t.pm_unread = 1) AND t.folder_id != ' . PRIVMSGS_HOLD_BOX . ')' : 't.folder_id = ' . (int) $folder_id;]]></action>
			</edit>
		</open>
		<open src="language/en/common.php">
			<edit>
				<find><![CDATA[	'datetime'			=> array(]]></find>
				<action type="before-add"><![CDATA[	// start mod view or mark unread posts
	'LOGIN_EXPLAIN_VIEWUNREADS'	=> 'You must be logged in to view your unread post list',
	'MARK_PM_UNREAD'			=> 'Mark pm as unread',
	'MARK_POST_UNREAD'			=> 'Mark post as unread',
	'NO_UNREADS'				=> 'You have no unread posts',
	'PM_MARKED_UNREAD'			=> 'Private message marked as unread',
	'POST_MARKED_UNREAD'		=> 'Post marked as unread',
	'RETURN_INBOX'				=> 'Return to pm inbox',
	'VIEW_UNREAD_PMS'			=> 'View unread pms',
	'VIEW_UNREADS'				=> 'View unread posts',
	// end mod view or mark unread posts]]></action>
			</edit>
		</open>
		<open src="styles/prosilver/template/index_body.html">
			<edit>
				<find><![CDATA[		<li><a href="{U_SEARCH_UNANSWERED}">{L_SEARCH_UNANSWERED}</a><!-- IF S_USER_LOGGED_IN --> &bull; <a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a><!-- ENDIF --> &bull; <a href="{U_SEARCH_ACTIVE_TOPICS}">{L_SEARCH_ACTIVE_TOPICS}</a></li>]]></find>
				<inline-edit>
					<inline-find><![CDATA[<a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a>]]></inline-find>
					<inline-action type="after-add"><![CDATA[<!-- IF S_INC_UNREAD_LINK --><!-- IF S_EXISTS_UNREADS --> &bull; <a href="{U_SEARCH_UNREAD}">{L_VIEW_UNREADS}</a><!-- ELSE --> &bull; <a href="{U_SEARCH_UNREAD}">{L_NO_UNREADS}</a><!-- ENDIF --><!-- ENDIF -->]]></inline-action>
				</inline-edit>
				<action type="after-add"><![CDATA[		<!-- start mod view or mark unread posts (and end mod too) ... added unread references in the preceding line -->]]></action>
			</edit>
		</open>
		<open src="styles/prosilver/template/search_results.html">
			<edit>
				<find><![CDATA[	<p><a class="{S_CONTENT_FLOW_BEGIN}" href="{U_SEARCH}" title="{L_SEARCH_ADV}">{L_RETURN_TO_SEARCH_ADV}</a></p>]]></find>
				<inline-edit>
					<inline-find><![CDATA[</p>]]></inline-find>
					<inline-action type="before-add"><![CDATA[<!-- IF S_SHOW_MARK_FORUMS_LINK --><br /><a class="{S_CONTENT_FLOW_BEGIN}" href="{U_MARK_FORUMS}" title="{L_MARK_FORUMS_READ}">{L_MARK_FORUMS_READ}</a><!-- ENDIF -->]]></inline-action>
				</inline-edit>
			</edit>
		</open>
		<open src="styles/prosilver/template/ucp_pm_viewmessage.html">
			<edit>
				<find><![CDATA[	<div class="back2top"><a href="#top" class="top" title="{L_BACK_TO_TOP}">{L_BACK_TO_TOP}</a></div>]]></find>
				<inline-edit>
					<inline-find><![CDATA[{L_BACK_TO_TOP}</a>]]></inline-find>
					<inline-action type="after-add"><![CDATA[<a href="{U_MARK_UNREAD}" class="post" title="{L_MARK_PM_UNREAD}">{L_MARK_PM_UNREAD}</a>]]></inline-action>
				</inline-edit>
				<action type="after-add"><![CDATA[	<!-- start mod view or mark unread posts (and end mod too) ... added mark_pm_unread references in the preceding line -->]]></action>
			</edit>
		</open>
		<open src="styles/prosilver/template/viewtopic_body.html">
			<edit>
				<find><![CDATA[		<div class="back2top"><a href="#wrap" class="top" title="{L_BACK_TO_TOP}">{L_BACK_TO_TOP}</a></div>]]></find>
				<inline-edit>
					<inline-find><![CDATA[{L_BACK_TO_TOP}</a>]]></inline-find>
					<inline-action type="after-add"><![CDATA[<!-- IF S_INC_UNREAD_LINK --><a href="{postrow.U_MARK_UNREAD}" class="post" title="{L_MARK_POST_UNREAD}">{L_MARK_POST_UNREAD}</a><!-- ENDIF -->]]></inline-action>
				</inline-edit>
				<action type="after-add"><![CDATA[		<!-- start mod view or mark unread posts (and end mod too) ... added preceding line -->]]></action>
			</edit>
		</open>
		<diy-instructions lang="en">Go into the ACP styles section and click 'refresh' (and confirm) for
prosilver's templates.</diy-instructions>
	</action-group>
</mod>