<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="./contrib/xsl/modx.prosilver.en.xsl"?>
<!-- 
	NOTICE: Please open this file in your web browser. If presented with a security warning, you may safely tell it to allow the blocked content.
-->
<!--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">Prime Post Revisions</title>
		<description lang="en">Stores each revision of a post every time a post is edited. It will only make these past revisions viewable to those users who have the necessary permissions.</description>
	    <author-notes lang="en">This MOD works independent of which styles are used. Options can be configured from within the "includes/prime_post_revisions.php" file.

Creating, maintaining, and updating MODs requires a lot of time and effort, so if you like this MOD and have the desire to express your thanks through donations, that would be greatly appreciated. My Paypal ID is primehalo@gmail.com, or contact me for my mailing address. The suggested donation amount for this MOD is $10.00 (but any amount will help).</author-notes>
		<author-group>
			<author>
				<realname>Ken F. Innes IV</realname>
				<email>primehalo@gmail.com</email>
				<username>primehalo</username>
				<homepage><![CDATA[http://www.absoluteanime.com/admin/mods.htm#post_revisions]]></homepage>
			</author>
		</author-group>
		<mod-version>1.2.3</mod-version>
		<installation>
			<level>easy</level>
			<time>600</time>
			<target-version>3.0.2</target-version>
		</installation>
		<history>
			<entry>
				<date>2007-08-02</date>
				<rev-version>0.0.0</rev-version>
				<changelog lang="en">
					<change>Initial test release</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-08-15</date>
				<rev-version>0.0.1</rev-version>
				<changelog lang="en">
					<change>Removed the Quick-mod tools dropdown box from the post revisions page.</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-08-28</date>
				<rev-version>0.0.2</rev-version>
				<changelog lang="en">
					<change>Don't store a revision if neither the message nor the subject has changed (disregarding leading and trailing white-spaces).</change>
					<change>Fix a bug where, when viewing the post history, the links that were supposed to lead to back to the original post would instead lead back to the first post of the topic.</change>
					<change>Now when viewing the post history the page title contains the post subject and not the topic title.</change>
					<change>Removed two duplicate SQL queries that happened once for each post with a single SQL query that happens once per topic.</change>
					<change>Corrected a mistake with the installation instructions.</change>
					<change>Gave default values to ALL of the columns added by the SQL statement that's required during installation.</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-09-06</date>
				<rev-version>0.0.3</rev-version>
				<changelog lang="en">
					<change>Revised slightly so that a UNION of two SQL statements is no longer used.</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-10-22</date>
				<rev-version>0.0.3a</rev-version>
				<changelog lang="en">
					<change>Updated for compatibility with phpBB3.0.RC7.</change>
				</changelog>
			</entry>
			<entry>
				<date>2007-12-11</date>
				<rev-version>0.0.4</rev-version>
				<changelog lang="en">
					<change>Changed the storage type for the message from mediumtext to mediumblob, matching what the forum uses for messages.</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-06-24</date>
				<rev-version>1.0.0</rev-version>
				<changelog lang="en">
					<change>Moved a majority of the code to an external file, and inside of a class structure.</change>
					<change>Added the ability to delete individual revisions.</change>
					<change>Added the ability to set some options.</change>
					<change>Fixed a bug that prevented the "last edited by" information from being displayed.</change>
					<change>Repackaged for MODX 1.2.0.</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-07-11</date>
				<rev-version>1.0.0a</rev-version>
				<changelog lang="en">
					<change>Added a Dutch translation.</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-07-11</date>
				<rev-version>1.0.1</rev-version>
				<changelog lang="en">
					<change>Fixed a bug where occasionally an editor's name would be displayed as "Guest".</change>
					<change>Verified to work with phpBB 3.0.2 (as well as 3.0.1).</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-07-21</date>
				<rev-version>1.2.0</rev-version>
				<changelog lang="en">
					<change>Fixed a minor bug in an SQL statement.</change>
					<change>Added a language string for when a post has no subject.</change>
					<change>Added an option to delete all revisions (will not delete the actual post).</change>
					<change>Added an option to undo the most recent revision to the post.</change>
					<change>Correctly update the edit time, user, and reason when deleting a revision.</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-07-21</date>
				<rev-version>1.2.1</rev-version>
				<changelog lang="en">
					<change>Fixed a minor bug that would occasionally cease to display the link to undo the most recent revision.</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-07-22</date>
				<rev-version>1.2.1a</rev-version>
				<changelog lang="en">
					<change>Added a German translation.</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-07-23</date>
				<rev-version>1.2.2</rev-version>
				<changelog lang="en">
					<change>Fixed a bug that would, on rare occasions, cause a minor error to happen when viewing the post history.</change>
					<change>Some minor code optimization.</change>
				</changelog>
			</entry>
			<entry>
				<date>2008-09-24</date>
				<rev-version>1.2.3</rev-version>
				<changelog lang="en">
					<change>Fixed a bug that would cause a revision to be stored even when neither the subject nor message had been changed.</change>
				</changelog>
			</entry>
		</history>
		<link-group>
			<link type="language" href="./contrib/language nl.xml" lang="en">Dutch</link>
		</link-group>
	</header>
	<action-group>
		<sql><![CDATA[CREATE TABLE IF NOT EXISTS phpbb_post_revisions (
	post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
	post_subject varchar(100) DEFAULT '' NOT NULL,
	post_text mediumblob NOT NULL,
	bbcode_uid varchar(8) DEFAULT '' NOT NULL,
	post_edit_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
	post_edit_user mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
	post_edit_reason varchar(255) DEFAULT '' NOT NULL,
	KEY post_id (post_id)
);]]></sql>
		<copy>
			<file from="root/includes/prime_post_revisions.php" to="includes/prime_post_revisions.php" />
			<file from="root/language/en/mods/prime_post_revisions.php" to="language/en/mods/prime_post_revisions.php" />
		</copy>

		<open src="includes/constants.php">
			<edit>
				<find><![CDATA[define('POSTS_TABLE',				$table_prefix . 'posts');]]></find>
				<action type="after-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
define('POST_REVISIONS_TABLE',		$table_prefix . 'post_revisions');
//-- end: Prime Post Revisions ----------------------------------------------//]]></action>
			</edit>
		</open>


		<open src="includes/functions_admin.php">
			<edit>
				<find>	$table_ary = array(POSTS_TABLE, REPORTS_TABLE);</find>
				<action type="after-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
	$table_ary[] = POST_REVISIONS_TABLE; // To delete the post's edit history
//-- end: Prime Post Revisions ----------------------------------------------//]]></action>
			</edit>
		</open>


		<open src="posting.php">
			<edit>
				<find>				$data['topic_replies'] = $post_data['topic_replies'];</find>
				<action type="after-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
				include($phpbb_root_path . 'includes/prime_post_revisions.' . $phpEx);
				store_post_revision_info($data, $post_data);
//-- end: Prime Post Revisions ----------------------------------------------//]]></action>
			</edit>
		</open>

		<open src="viewtopic.php">
			<edit>
				<find><![CDATA[$max_post_time = 0;]]></find>
				<action type="after-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
include($phpbb_root_path . 'includes/prime_post_revisions.' . $phpEx);
$prime_post_revisions = new prime_post_revisions($post_list, $forum_id, $topic_id, $post_id);
//-- end: Prime Post Revisions ----------------------------------------------//]]></action>
			</edit>

			<edit>
				<find>// Posts are stored in the $rowset</find>
				<action type="before-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
$prime_post_revisions->get_revision_info($post_list, $result, $viewtopic_url, $viewtopic_title);
//-- end: Prime Post Revisions ----------------------------------------------//
]]></action>
			</edit>

			<edit>
				<find><![CDATA[// Posts are stored in the $rowset array while $attach_list, $user_cache
// and the global bbcode_bitfield are built
while ($row = $db->sql_fetchrow($result))
{
]]></find>
				<action type="after-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
	$prime_post_revisions->merge_revision_info($post_list, $result, $row);
//-- end: Prime Post Revisions ----------------------------------------------//
]]></action>
			</edit>

			<edit>
				<find>	// Editing information</find>
				<action type="before-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
	$prime_post_revisions->set_edit_count($row);
//-- end: Prime Post Revisions ----------------------------------------------//
]]></action>
			</edit>

			<edit>
				<find><![CDATA[		$l_edit_time_total = ($row['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];]]></find>
				<action type="before-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
		$prime_post_revisions->inject_user_data($row);
//-- end: Prime Post Revisions ----------------------------------------------//
]]></action>
			</edit>

			<edit>
				<find><![CDATA[	if (isset($cp_row['row']) && sizeof($cp_row['row']))]]></find>
				<action type="before-add"><![CDATA[//-- mod: Prime Post Revisions ----------------------------------------------//
	$prime_post_revisions->update_postrow($post_list, $i, $rowset, $postrow);
//-- end: Prime Post Revisions ----------------------------------------------//
]]></action>
			</edit>

			<edit>
				<find><![CDATA[page_header($user->lang['VIEW_TOPIC']]]></find>
				<action type="after-add"><![CDATA[
//-- mod: Prime Post Revisions ----------------------------------------------//
$prime_post_revisions->assign_template_variables($viewtopic_url, $viewtopic_title);
//-- end: Prime Post Revisions ----------------------------------------------//]]></action>
			</edit>
		</open>

		<diy-instructions lang="en">As an alternative to manually executing the SQL statements, you can use the included 
"db_install.php" (located in the contrib directory). Simply copy the file to the root
directory of your phpbb3 install, and point your web browser to the address. Make 
sure you are logged in as an administrator before you do this, and make sure to
delete the file once you're done.</diy-instructions>

	</action-group>
</mod>