############################################################## 
## MOD Title: Cached Generation
## MOD Author: Doobdee < n/a > ( n/a ) http://www.doobdee.net 
## MOD Author: CyberAlien < n/a > ( n/a ) http://www.phpbbstyles.com 
## MOD Description: This caches SQL queries, adds SQL queries counter and page generation time
## MOD Version: 1.2.2 
## Installation Level: Advanced 
## Installation Time: 60 Minutes 
## Files To Edit:common.php
##		     index.php
##		     viewforum.php
##		     groupcp.php
##		     modcp.php
##		     includes/auth.php
##		     includes/functions.php
##		     includes/functions_post.php
##		     includes/sessions.php
##		     db/mysql.php
##		     db/mysql4.php
##		     admin/page_footer_admin.php
##		     lang/lang_eng/lang_main.php
##		     includes/page_tail.php
##		     templates/subSilver/overall_footer.php
## Included Files: admin/xs_cached_generation.cfg
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
############################################################## 
## 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/ 
############################################################## 
## Author Notes: This MOD caches SQL queries, so page is much faster.
##		     It also ads SQL queries counter, and page generation time
##		     which is shown in overall_footer.tpl of your selected
##		     style.
##
## eXtreme Styles: For those of you who have XS MOD a built in version
##			 checker is included.  Just click "Check for updates button"
############################################################## 
## MOD History: 
## 
##   2005-09-23 - Beta 1.2.0 
##      - Initial release of mod ;) This is BETA stage..
##
##   2005-09-25 - Beta 1.2.1 
##      - An unknown variable snuck in to viewforum.php.  Replaced with SQL querie..
##
##   2005-10-06 - RELEASE CANDIDATE ONE - RC 1
##      - Fixed error in mysql.php
##	  - Added missing sql_freeresult() in functions.php
##	  - Included eXtreme Styles Update Checker
##
##   2005-10-15 - RELEASE CANDIDATE TWO - RC 2
##      - Re-wrote page generation time function
##	  - Added clear_cache() in groupcp.php
##	  - Added clear_cache('posts_') in modcp.php
##
##   2005-10-15 - 1.2.2
##      - Updated MOD instructions to be compatible with phpBB 2.0.18
##      - Re-written some MOD syntax for easier installation.
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################

# 
#-----[ DIY INSTRUCTIONS ]------------------------------------------ 
#
Create a cache/ directory in your phpBB root folder and CHMOD to 777.

# 
#-----[ COPY ]------------------------------------------ 
# Upload this if you have extreme styles MOD installed.
copy admin/xs_cached_generation.cfg to admin/xs_cached_generation.cfg

# 
#-----[ OPEN ]------------------------------------------ 
#
common.php

# 
#-----[ FIND ]------------------------------------------ 
#
//  
// Define some basic configuration arrays this also prevents 

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
function microtime_float()  
{  
   list($usec, $sec) = explode(" ", microtime());  
   return ((float)$usec + (float)$sec);  
}  
 
$GLOBALS['page_gen_start'] = microtime_float(); 

# 
#-----[ FIND ]------------------------------------------ 
#
	FROM " . CONFIG_TABLE;
if( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	FROM " . CONFIG_TABLE;
if( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ OPEN ]------------------------------------------ 
#
index.php

# 
#-----[ FIND ]------------------------------------------ 
#
	ORDER BY c.cat_order";
if( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	ORDER BY c.cat_order";
if( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ FIND ]------------------------------------------ 
#
			break;
	}
	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
			break;
	}
	if ( !($result = $db->sql_query($sql, false, 'posts_')) )

# 
#-----[ FIND ]------------------------------------------ 
#
		ORDER BY aa.forum_id, u.user_id";
	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
		ORDER BY aa.forum_id, u.user_id";
	if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ FIND ]------------------------------------------ 
#
		ORDER BY aa.forum_id, g.group_id";
	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
		ORDER BY aa.forum_id, g.group_id";
	if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ OPEN ]------------------------------------------ 
#
viewforum.php

# 
#-----[ FIND ]------------------------------------------ 
#
		WHERE forum_id = $forum_id";
	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
		WHERE forum_id = $forum_id";
	if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ FIND ]------------------------------------------ 
#
			WHERE forum_id = $forum_id";
		if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
			WHERE forum_id = $forum_id";
		if ( !($result = $db->sql_query($sql, false, 'posts_')) )

# 
#-----[ FIND ]------------------------------------------ 
#
	GROUP BY u.user_id, u.username  
	ORDER BY u.user_id";
if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	GROUP BY u.user_id, u.username  
	ORDER BY u.user_id";
if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ FIND ]------------------------------------------ 
#
	GROUP BY g.group_id, g.group_name  
	ORDER BY g.group_id";
if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	GROUP BY g.group_id, g.group_name  
	ORDER BY g.group_id";
if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ FIND ]------------------------------------------ 
#
			AND p.post_time >= $min_topic_time"; 

	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
			AND p.post_time >= $min_topic_time"; 

	if ( !($result = $db->sql_query($sql, false, 'posts_')) )

# 
#-----[ FIND ]------------------------------------------ 
#
	ORDER BY t.topic_last_post_id DESC ";
if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	ORDER BY t.topic_last_post_id DESC ";
if ( !($result = $db->sql_query($sql, false, 'posts_')) )

# 
#-----[ FIND ]------------------------------------------ 
#
$topic_rowset = array();

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
$cached1 = $db->cached;

# 
#-----[ FIND ]------------------------------------------ 
#
	LIMIT $start, ".$board_config['topics_per_page'];
if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	LIMIT $start, ".$board_config['topics_per_page'];
if ( !($result = $db->sql_query($sql, false, 'posts_')) )

# 
#-----[ FIND ]------------------------------------------ 
#
$total_topics = 0;

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
$cached2 = $db->cached;

# 
#-----[ FIND ]------------------------------------------ 
#
//
// Total topics ...
//

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#

if($cached1 || $cached2)
{
	$update_list = array();
	for($i=0; $i<count($topic_rowset); $i++)
	{
		$update_list[] = $topic_rowset[$i]['topic_id'];
	}
	if(count($update_list))
	{
		$sql = "SELECT topic_id, topic_views FROM " . TOPICS_TABLE . " WHERE topic_id IN (" . implode(', ', $update_list) . ")";
		$list = array();
		$result = $db->sql_query($sql);
		while( $row = $db->sql_fetchrow($result) )
		{
			$list[$row['topic_id']] = $row['topic_views'];
		}
		$db->sql_freeresult($result);
		for($i=0; $i<count($topic_rowset); $i++)
		{
			if(isset($list[$topic_rowset[$i]['topic_id']]))
			{
				$topic_rowset[$i]['topic_views'] = $list[$topic_rowset[$i]['topic_id']];
			}
		}
		unset($list);
	}
}

# 
#-----[ OPEN ]------------------------------------------ 
#
groupcp.php

# 
#-----[ FIND ]------------------------------------------ 
#
	$message = $lang['Group_type_updated'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');


#  
#-----[ AFTER, ADD ]------------------------------------------  
#  
	$db->clear_cache();

# 
#-----[ FIND ]------------------------------------------ 
#
	$message = $lang['Group_joined'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');

#  
#-----[ AFTER, ADD ]------------------------------------------  
#  
	$db->clear_cache();

# 
#-----[ FIND ]------------------------------------------ 
#
		$message = $lang['Unsub_success'] . '<br /><br />' . sprintf($lang['Click_return_group'], '<a href="' . append_sid("groupcp.$phpEx?" . POST_GROUPS_URL . "=$group_id") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');

#  
#-----[ AFTER, ADD ]------------------------------------------  
#  
		$db->clear_cache();

# 
#-----[ FIND ]------------------------------------------ 
#
						message_die(GENERAL_ERROR, 'Could not update user group table', '', __LINE__, __FILE__, $sql);
					}

#  
#-----[ AFTER, ADD ]------------------------------------------  
#
					$db->clear_cache();

# 
#-----[ OPEN ]------------------------------------------ 
#
modcp.php

# 
#-----[ FIND ]------------------------------------------ 
#
			message_die(GENERAL_MESSAGE, $lang['Topics_Removed'] . '<br /><br />' . $l_redirect);

#  
#-----[ BEFORE, ADD ]------------------------------------------  
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				$message = $lang['Topics_Moved'] . '<br /><br />';

#  
#-----[ AFTER, ADD ]------------------------------------------  
#
				$db->clear_cache('posts_');
# 
#-----[ FIND ]------------------------------------------ 
#
		message_die(GENERAL_MESSAGE, $lang['Topics_Locked'] . '<br /><br />' . $message);

#  
#-----[ BEFORE, ADD ]------------------------------------------  
#
		$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		message_die(GENERAL_MESSAGE, $lang['Topics_Unlocked'] . '<br /><br />' . $message);

#  
#-----[ BEFORE, ADD ]------------------------------------------  
#
		$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				$message = $lang['Topic_split'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');

#  
#-----[ AFTER, ADD ]------------------------------------------  
#
				$db->clear_cache('posts_');

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

# 
#-----[ FIND ]------------------------------------------ 
#
				AND a.group_id = ug.group_id
				$forum_match_sql";
		if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
				AND a.group_id = ug.group_id
				$forum_match_sql";
		if ( !($result = $db->sql_query($sql, false, true)) )

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

# 
#-----[ FIND ]------------------------------------------ 
#
				FROM " . FORUMS_TABLE;
			break;
	}

	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
				FROM " . FORUMS_TABLE;
			break;
	}

	if ( !($result = $db->sql_query($sql, false, 'posts_')) )

#  
#-----[ FIND ]------------------------------------------  
#  
   $row = $db->sql_fetchrow($result);  
 
#  
#-----[ AFTER, ADD ]------------------------------------------  
#  
   $db->sql_freeresult($result);  

# 
#-----[ FIND ]------------------------------------------ 
#
		ORDER BY c.cat_order";
	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
		ORDER BY c.cat_order";
	if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ FIND ]------------------------------------------ 
#
			ORDER BY cat_id, forum_order";
		if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#

			ORDER BY cat_id, forum_order";
		if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ FIND ]------------------------------------------ 
#
		FROM  " . WORDS_TABLE;
	if( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
		FROM  " . WORDS_TABLE;
	if( !($result = $db->sql_query($sql, false, true)) )

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

# 
#-----[ FIND ]------------------------------------------ 
#
				FROM " . BANLIST_TABLE;
			if (!($result = $db->sql_query($sql)))

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
				FROM " . BANLIST_TABLE;
			if (!($result = $db->sql_query($sql, false, true)))

# 
#-----[ FIND ]------------------------------------------ 
#
		ORDER BY smilies_id";
	if ($result = $db->sql_query($sql))

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
		ORDER BY smilies_id";
	if ($result = $db->sql_query($sql, false, true))

# 
#-----[ FIND ]------------------------------------------ 
#
	if (!$db->sql_query($sql, BEGIN_TRANSACTION))
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
	$sql = ($mode != 'editpost') ? "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($post_id, '$post_subject', '$bbcode_uid', '$post_message')" : "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '$post_message',  bbcode_uid = '$bbcode_uid', post_subject = '$post_subject' WHERE post_id = $post_id";
	if (!$db->sql_query($sql))
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		$sql = (!$post_data['has_poll']) ? "INSERT INTO " . VOTE_DESC_TABLE . " (topic_id, vote_text, vote_start, vote_length) VALUES ($topic_id, '$poll_title', $current_time, " . ($poll_length * 86400) . ")" : "UPDATE " . VOTE_DESC_TABLE . " SET vote_text = '$poll_title', vote_length = " . ($poll_length * 86400) . " WHERE topic_id = $topic_id";
		if (!$db->sql_query($sql))
		{
# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				ORDER BY vote_option_id ASC";
			if (!($result = $db->sql_query($sql)))
			{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
				$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				$sql = ($mode != "editpost" || !isset($old_poll_result[$option_id])) ? "INSERT INTO " . VOTE_RESULTS_TABLE . " (vote_id, vote_option_id, vote_option_text, vote_result) VALUES ($poll_id, $poll_option_id, '$option_text', $poll_result)" : "UPDATE " . VOTE_RESULTS_TABLE . " SET vote_option_text = '$option_text', vote_result = $poll_result WHERE vote_option_id = $option_id AND vote_id = $poll_id";
				if (!$db->sql_query($sql))
				{
# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
					$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
					AND vote_id = $poll_id";
			if (!$db->sql_query($sql))
			{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
				$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
					AND u.user_id = tw.user_id";
		if (!($result = $db->sql_query($sql)))
		{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
	$message = $lang['Stored'] . '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
	$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
					WHERE topic_id = $topic_id";
				if (!($result = $db->sql_query($sql)))
				{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
					$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
					WHERE forum_id = $forum_id"; 
				if (!($result = $db->sql_query($sql)))
				{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
					$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				WHERE topic_id = $topic_id";
			if (!($result = $db->sql_query($sql)))
			{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
				$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		WHERE forum_id = $forum_id";
	if (!$db->sql_query($sql))
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
			WHERE topic_id = $topic_id";
		if (!$db->sql_query($sql))
		{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
			WHERE user_id = $user_id";
		if (!$db->sql_query($sql, END_TRANSACTION))
		{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');


# 
#-----[ FIND ]------------------------------------------ 
#
	return;
}

//
// Delete a post/poll
//

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
	$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		$sql = "DELETE FROM " . POSTS_TABLE . " 
			WHERE post_id = $post_id";
		if (!$db->sql_query($sql))
		{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		$sql = "DELETE FROM " . POSTS_TEXT_TABLE . " 
			WHERE post_id = $post_id";
		if (!$db->sql_query($sql))
		{


# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
						OR topic_moved_id = $topic_id";
				if (!$db->sql_query($sql))
				{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
					$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
					WHERE topic_id = $topic_id";
				if (!$db->sql_query($sql))
				{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
					$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		$sql = "DELETE FROM " . VOTE_DESC_TABLE . " 
			WHERE topic_id = $topic_id";
		if (!$db->sql_query($sql))
		{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " 
			WHERE vote_id = $poll_id";
		if (!$db->sql_query($sql))
		{
# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
		$sql = "DELETE FROM " . VOTE_USERS_TABLE . " 
			WHERE vote_id = $poll_id";
		if (!$db->sql_query($sql))
		{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
	$message .=  '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
	$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				message_die(GENERAL_ERROR, 'Could not obtain banlist', '', __LINE__, __FILE__, $sql);

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
				$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				AND user_id = " . $userdata['user_id'];
		if (!($result = $db->sql_query($sql)))
		{
# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				WHERE topic_id = $topic_id
					AND user_id = " . $userdata['user_id'];
			if (!$db->sql_query($sql))
			{
# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
				$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
				VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
			if (!$db->sql_query($sql))
			{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
				$db->clear_cache('posts_');

# 
#-----[ FIND ]------------------------------------------ 
#
}

//
// Fill smiley templates (or just the variables) with smileys
// Either in a window or inline
//

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
	$db->clear_cache('posts_');


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

# 
#-----[ FIND ]------------------------------------------ 
#
			OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'";
	}
	if ( !($result = $db->sql_query($sql)) )

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
			OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'";
	}
	if ( !($result = $db->sql_query($sql, false, true)) )

# 
#-----[ OPEN ]------------------------------------------ 
#
# 
mysql.php

# 
#-----[ FIND ]------------------------------------------ 
#
	var $num_queries = 0;

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
	var $caching = false;
	var $cached = false;
	var $cache = array();

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_query($query = "", $transaction = FALSE)

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	function sql_query($query = "", $transaction = FALSE, $cache = false)

# 
#-----[ FIND ]------------------------------------------ 
#
		// Remove any pre-existing queries
		unset($this->query_result);

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		// Check cache
		$this->caching = false;
		$this->cache = array();
		$this->cached = false;
		if($query !== '' && $cache)
		{
			global $phpbb_root_path;
			$hash = md5($query);
			if(strlen($cache))
			{
				$hash = $cache . $hash;
			}
			$filename = $phpbb_root_path . 'cache/sql_' . $hash . '.php';
			if(@file_exists($filename))
			{
				$set = array();
				include($filename);
				$this->cache = $set;
				$this->cached = true;
				$this->caching = false;
				return 'cache';
			}
//			echo 'cache is missing: ', $filename, '<br />';
			$this->caching = $hash;
		}
		// not cached
//		echo 'sql: ', htmlspecialchars($query), '<br />';

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_numrows($query_id = 0)
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache' && $this->cached)
		{
			return count($this->cache);
		}

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_fetchrow($query_id = 0)
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache' && $this->cached)
		{
			return count($this->cache) ? array_shift($this->cache) : false;
		}

# 
#-----[ FIND ]------------------------------------------ 
#
		if($query_id)
		{
			$this->row[$query_id] = @mysql_fetch_array($query_id);


# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			if($this->caching)
			{
				if($this->row[$query_id] === false)
				{
					$this->write_cache();
				}
				$this->cache[] = $this->row[$query_id];
			}

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_fetchrowset($query_id = 0)
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache' && $this->cached)
		{
			return $this->cache;
		}

# 
#-----[ FIND ]------------------------------------------ 
#
			unset($this->row[$query_id]);
			while($this->rowset[$query_id] = @mysql_fetch_array($query_id))
			{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
				if($this->caching)
				{
					if($this->row[$query_id] === false)
					{
						$this->write_cache();
					}
					$this->cache[] = $this->row[$query_id];
				}

# 
#-----[ FIND ]------------------------------------------ 
#
				$result[] = $this->rowset[$query_id];
			}

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			if($this->caching)
			{
				$this->write_cache();
			}

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_freeresult($query_id = 0){

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache')
		{
			$this->caching = false;
			$this->cached = false;
			$this->cache = array();
		}
		if($this->caching)
		{
			$this->write_cache();
		}

# 
#-----[ FIND ]------------------------------------------ 
#
} // class sql_db

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
	function write_cache()
	{
		if(!$this->caching)
		{
			return;
		}
		global $phpbb_root_path;
		$f = fopen($phpbb_root_path . 'cache/sql_' . $this->caching . '.php', 'w');
		$data = var_export($this->cache, true);
		@fputs($f, '<?php $set = ' . $data . '; ?>');
		@fclose($f);
		@chmod($phpbb_root_path . 'cache/sql_' . $this->caching . '.php', 0777);
		$this->caching = false;
		$this->cached = false;
		$this->cache = array();
	}

	function clear_cache($prefix = '')
	{
		global $phpbb_root_path;
		$this->caching = false;
		$this->cached = false;
		$this->cache = array();
		$prefix = 'sql_' . $prefix;
		$prefix_len = strlen($prefix);
		$res = opendir($phpbb_root_path . 'cache');
		if($res)
		{
			while(($file = readdir($res)) !== false)
			{
				if(substr($file, 0, $prefix_len) === $prefix)
				{
					@unlink($phpbb_root_path . 'cache/' . $file);
				}
			}
		}
		@closedir($res);
	}

# 
#-----[ OPEN ]------------------------------------------ 
#
# 
mysql4.php

# 
#-----[ FIND ]------------------------------------------ 
#
	var $num_queries = 0;

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
	var $caching = false;
	var $cached = false;
	var $cache = array();

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_query($query = "", $transaction = FALSE)

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
	function sql_query($query = "", $transaction = FALSE, $cache = false)

# 
#-----[ FIND ]------------------------------------------ 
#
		// Remove any pre-existing queries
		unset($this->query_result);

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		// Check cache
		$this->caching = false;
		$this->cache = array();
		$this->cached = false;
		if($query !== '' && $cache)
		{
			global $phpbb_root_path;
			$hash = md5($query);
			if(strlen($cache))
			{
				$hash = $cache . $hash;
			}
			$filename = $phpbb_root_path . 'cache/sql_' . $hash . '.php';
			if(@file_exists($filename))
			{
				$set = array();
				include($filename);
				$this->cache = $set;
				$this->cached = true;
				$this->caching = false;
				return 'cache';
			}
//			echo 'cache is missing: ', $filename, '<br />';
			$this->caching = $hash;
		}
		// not cached
//		echo 'sql: ', htmlspecialchars($query), '<br />';

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_numrows($query_id = 0)
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache' && $this->cached)
		{
			return count($this->cache);
		}

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_fetchrow($query_id = 0)
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache' && $this->cached)
		{
			return count($this->cache) ? array_shift($this->cache) : false;
		}

# 
#-----[ FIND ]------------------------------------------ 
#
		if( $query_id )
		{
			$this->row[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC);

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			if($this->caching)
			{
				if($this->row[$query_id] === false)
				{
					$this->write_cache();
				}
				$this->cache[] = $this->row[$query_id];
			}

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_fetchrowset($query_id = 0)
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache' && $this->cached)
		{
			return $this->cache;
		}

# 
#-----[ FIND ]------------------------------------------ 
#
			unset($this->row[$query_id]);
			while($this->rowset[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC))
			{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
				if($this->caching)
				{
					if($this->row[$query_id] === false)
					{
						$this->write_cache();
					}
					$this->cache[] = $this->row[$query_id];
				}

# 
#-----[ FIND ]------------------------------------------ 
#
				$result[] = $this->rowset[$query_id];
			}

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
			if($this->caching)
			{
				$this->write_cache();
			}

# 
#-----[ FIND ]------------------------------------------ 
#
	function sql_freeresult($query_id = 0)
	{

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
		if($query_id === 'cache')
		{
			$this->caching = false;
			$this->cached = false;
			$this->cache = array();
		}
		if($this->caching)
		{
			$this->write_cache();
		}

# 
#-----[ FIND ]------------------------------------------ 
#
			mysql_free_result($query_id);

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
			@mysql_free_result($query_id);

# 
#-----[ FIND ]------------------------------------------ 
#
} // class sql_db

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
	function write_cache()
	{
		if(!$this->caching)
		{
			return;
		}
		global $phpbb_root_path;
		$f = fopen($phpbb_root_path . 'cache/sql_' . $this->caching . '.php', 'w');
		$data = var_export($this->cache, true);
		@fputs($f, '<?php $set = ' . $data . '; ?>');
		@fclose($f);
		@chmod($phpbb_root_path . 'cache/sql_' . $this->caching . '.php', 0777);
		$this->caching = false;
		$this->cached = false;
		$this->cache = array();
	}

	function clear_cache($prefix = '')
	{
		global $phpbb_root_path;
		$this->caching = false;
		$this->cached = false;
		$this->cache = array();
		$prefix = 'sql_' . $prefix;
		$prefix_len = strlen($prefix);
		$res = opendir($phpbb_root_path . 'cache');
		if($res)
		{
			while(($file = readdir($res)) !== false)
			{
				if(substr($file, 0, $prefix_len) === $prefix)
				{
					@unlink($phpbb_root_path . 'cache/' . $file);
				}
			}
		}
		@closedir($res);
	}

# 
#-----[ OPEN ]------------------------------------------ 
#
admin/page_footer_admin.php

# 
#-----[ FIND ]------------------------------------------ 
#
$db->sql_close();

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
$db->clear_cache();

# 
#-----[ OPEN ]------------------------------------------ 
#
language/lang_english/lang_main.php

# 
#-----[ FIND ]------------------------------------------ 
#
//
// That's all, Folks!
// -------------------------------------------------

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
//
// Cached generation
//
$lang['debug_generation'] = 'Debug: page generation = %s seconds,';
$lang['sql_queries'] = 'sql queries = %s';

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

# 
#-----[ FIND ]------------------------------------------ 
#
	'overall_footer' => ( empty($gen_simple_header) ) ? 'overall_footer.tpl' : 'simple_footer.tpl')
);

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
//
// Cached Generation
//
$page_gen_time = sprintf('%.5f', microtime_float() - $GLOBALS['page_gen_start']);

# 
#-----[ FIND ]------------------------------------------ 
#
$template->assign_vars(array(

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
	// Cached Generation	
	'PAGE_GENERATION' => sprintf($lang['debug_generation'], $page_gen_time),
	'MYSQL_QUERIES' => sprintf($lang['sql_queries'], $db->num_queries),

# 
#-----[ OPEN ]------------------------------------------ 
#
templates/subSilver/overall_footer.tpl

# 
#-----[ FIND ]------------------------------------------ 
#
Powered by <a href="http://www.phpbb.com/" target="_phpbb" class="copyright">phpBB</a> &copy; 2001, 2005 phpBB Group<br />{TRANSLATION_INFO}</span></div>

# 
#-----[ IN-LINE FIND ]------------------------------------------ 
#
{TRANSLATION_INFO}

# 
#-----[ IN-LINE AFTER, ADD ]------------------------------------------ 
#
<br />{PAGE_GENERATION}&nbsp;{MYSQL_QUERIES}

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM