##############################################################
## MOD Title: 		phpBB SEO Zro dupilcate MAJ 0.4.0 => 0.4.2
## MOD Author: 		dcz <n/a> http://www.phpbb-seo.com/
## MOD Description: 	Ceci est la procdure de mise  jour du MOD phpBB SEO Zro dupilcate pour la transition version 0.4.0 => 0.4.2.
## 			Rendez-vous sur http://www.phpbb-seo.com/forums/zero-duplicate-phpbb3/zero-duplicate-phpbb3-seo-vt1502.html
## 			pour toujours obtenir la dernire version ou de l'aide pour ce MOD.
##
## MOD Version: 	1.0
##
## Installation Level: 	(Eazy)
## Installation Time: 	4 Minutes
## Files To Edit: 	(2)
##			memberlist.php,
##			search.php.
##
## Included Files: n/a
##############################################################
## Author Notes:
## _____________
##
## Voici les instructions de mise  jour : phpBB3 SEO Mod Zro dupilcate 0.4.0 => 0.4.2
##
##############################################################
## MOD History:
##
##	2008-04-14 - 1.0
##		- First version released
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################


#
#-----[ DIY INSTRUCTIONS ]--------------------------------------------------
#

_____________________________________________
>>>> INSTALLATION POUR VOTRE FORUM <<<<<
_____________________________________________

La procdure d'installation qui suit est trs simple et ne devrait pas poser de problmes.
Elle est requise avec les mod rewrite phpBB SEO 0.4.2 stable.
 
#
#-----[ OPEN ]------------------------------------------
#

index.php

#
#-----[ FIND ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
$phpbb_seo->page_url = $phpbb_seo->seo_path['phpbb_urlR'] . $phpbb_seo->seo_static['index'] . $phpbb_seo->seo_ext['index'] . (!empty($_SID) ? '?sid=' . $_SID : '');
if ( $user->data['is_registered'] ) {
	$phpbb_seo->seo_cond( !isset($_GET['explain']) );
	$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'mark=') === FALSE));
} 
if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
	if ( !$user->data['is_registered'] ) {
		$phpbb_seo->seo_cond( isset($_GET['explain']), false, 'do' );
		$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'mark=') !== FALSE), false, 'do');
	}
	if ( !empty($phpbb_seo->seo_static['index']) ) {
		$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], $phpbb_seo->seo_static['index']) === FALSE), false, 'do');
	} else {
		$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'index.' . $phpEx) !== FALSE), false, 'do' );
	}
}
$phpbb_seo->seo_chk_dupe($phpbb_seo->seo_path['uri'], $phpbb_seo->page_url);
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
$seo_mark = request_var('mark', '');
$keep_mark = in_array($seo_mark, array('topics', 'forums', 'all')) ? (boolean) ($user->data['is_registered'] || $config['load_anon_lastread']) : false;
$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
	'mark' => array('val' => $seo_mark, 'keep' => $keep_mark),
);
if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
	if ( !empty($phpbb_seo->seo_static['index']) ) {
		$phpbb_seo->set_cond( (boolean) (utf8_strpos($phpbb_seo->seo_path['uri'], $phpbb_seo->seo_static['index']) === false), 'do_redir', (empty($_GET) || (!empty($seo_mark) && !$keep_mark)));
	} else {
		$phpbb_seo->set_cond( (boolean) (utf8_strpos($phpbb_seo->seo_path['uri'], "index.$phpEx") !== false), 'do_redir', (empty($_GET) || (!empty($seo_mark) && !$keep_mark)));
	}
}
$phpbb_seo->seo_chk_dupe();
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe

#
#-----[ OPEN ]------------------------------------------
#

memberlist.php

#
#-----[ FIND ]------------------------------------------
#
		// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
		if ( $user->data['is_registered'] ) {
			$phpbb_seo->seo_cond( !isset($_GET['explain']) );
		}
		if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
			if ( !$user->data['is_registered'] ) {
				$phpbb_seo->seo_cond( isset($_GET['explain']), false, 'do' );
			}
		}
		$phpbb_seo->page_url = str_replace('&amp;', '&', append_sid("memberlist.$phpEx?mode=viewprofile&u=$user_id" . (!empty($_SID) ? '&amp;sid=' . $_SID : '')));
		$phpbb_seo->seo_chk_dupe(urldecode(urldecode($phpbb_seo->seo_path['uri'])), urldecode(urldecode($phpbb_seo->page_url)));
		// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
		// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
		$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
			'mode' => array('val' => 'viewprofile', 'keep' => true),
			'u' => array('val' => $user_id, 'keep' => true, 'force' => true),
		);
		$phpbb_seo->seo_chk_dupe();
		// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ FIND ]------------------------------------------
#
			// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
			if ( $user->data['is_registered'] ) {
				$phpbb_seo->seo_cond( !isset($_GET['explain']) );
			}
			if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
				if ( !$user->data['is_registered'] ) {
					$phpbb_seo->seo_cond( isset($_GET['explain']), false, 'do' );
				}
			}
			if ( empty($phpbb_seo->seo_url['group'][$group_row['group_id']]) ) {
				$phpbb_seo->seo_url['group'][$group_row['group_id']] = $phpbb_seo->format_url($group_row['group_name'], $phpbb_seo->seo_static['group']);
			}
			$phpbb_seo->page_url = str_replace('&amp;', '&', append_sid("memberlist.$phpEx?mode=group&g=" . $group_row['group_id'] . '&amp;start=' . $start . (!empty($_SID) ? '&amp;sid=' . $_SID : '')));
			$phpbb_seo->seo_chk_dupe($phpbb_seo->seo_path['uri'], $phpbb_seo->page_url);
			// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
			// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
			if ( empty($phpbb_seo->seo_url['group'][$group_row['group_id']]) ) {
				$phpbb_seo->seo_url['group'][$group_row['group_id']] = $phpbb_seo->format_url($group_row['group_name'], $phpbb_seo->seo_static['group']);
			}
			$phpbb_seo->seo_opt['zero_dupe']['start'] = $phpbb_seo->seo_chk_start( $start, $config['topics_per_page'] );
			$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
				'mode' => array('val' => 'group', 'keep' => true),
				'g' => array('val' => (int) $group_row['group_id'], 'keep' => true),
				'start' => array('val' => $phpbb_seo->seo_opt['zero_dupe']['start'], 'keep' => true),
			);
			$phpbb_seo->seo_chk_dupe();
			// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ OPEN ]------------------------------------------
#

phpbb_seo/phpbb_seo_class.php

#
#-----[ FIND ]------------------------------------------
#
		// --> Zero Dupe
		$this->seo_opt['zero_dupe'] = array( 'on' => false, // Activate or not the redirections : true / false
			'strict' => false, // strict compare, == VS strpos() : true / false
			'post_redir' => 'guest', // Redirect post urls if not valid ? : guest / all / post / off
		);
		$this->cache_config['dynamic_options']['zero_dupe'] = $this->seo_opt['zero_dupe']; // Do not change
		$this->seo_opt['zero_dupe']['do_redir'] = false; // do not change
		$this->seo_opt['zero_dupe']['bool_redir'] = true; // do not change
		$this->seo_opt['zero_dupe']['do_redir_post'] = false; // do not change
		$this->seo_opt['zero_dupe']['start'] = 0; // do not change
		// <-- Zero Dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
		// --> Zero Dupe
		$this->seo_opt['zero_dupe'] = array( 'on' => false, // Activate or not the redirections : true / false
			'strict' => false, // strict compare, == VS strpos() : true / false
			'post_redir' => 'guest', // Redirect post urls if not valid ? : guest / all / post / off
		);
		$this->cache_config['dynamic_options']['zero_dupe'] = $this->seo_opt['zero_dupe']; // Do not change
		$this->seo_opt['zero_dupe']['do_redir'] = false; // do not change
		$this->seo_opt['zero_dupe']['go_redir'] = true; // do not change
		$this->seo_opt['zero_dupe']['do_redir_post'] = false; // do not change
		$this->seo_opt['zero_dupe']['start'] = 0; // do not change
		$this->seo_opt['zero_dupe']['redir_def'] = array(); // do not change
		// <-- Zero Dupe

#
#-----[ FIND ]------------------------------------------
#
	// --> Zero Duplicate
	/**
	* Custom HTTP 301 redirections.
	* To kill duplicates
	*/
	function seo_redirect($url, $header = '301 Moved Permanently', $code = 301, $replace = TRUE) {
		global $db;
		if (!$this->seo_opt['zero_dupe']['on']) {
			return;
		}
		garbage_collection();
		$url = str_replace('&amp;', '&', $url);
		// Make sure no linebreaks are there... to prevent http response splitting for PHP < 4.4.2
		if (strpos(urldecode($url), "\n") !== false || strpos(urldecode($url), "\r") !== false || strpos($url, ';') !== false) {
			trigger_error('Tried to redirect to potentially insecure url.', E_USER_ERROR);
		}
		$http = 'HTTP/1.1 ';
		header($http . $header, $replace, $code);
		header('Location: ' . $url);
		exit();
	}
	/**
	 * Helps out grabbing boolean vars
	 *
	*/
	function seo_cond($bool = false, $and = true, $do = 'bool') {
		static $been_here = false;
		if ( !$been_here ) {
			$this->seo_opt['zero_dupe'][$do . '_redir'] = $bool;
			$been_here = true;
		} elseif ( $and ) {
			$this->seo_opt['zero_dupe'][$do . '_redir'] = ($bool && $this->seo_opt['zero_dupe'][$do . '_redir']);
		} else {
			$this->seo_opt['zero_dupe'][$do . '_redir'] = ($bool || $this->seo_opt['zero_dupe'][$do . '_redir']);
		}
		return;
	}
	/**
	* Set the do_redir_post option right
	*/
	function set_do_redir_post() {
		global $user;
		switch ($this->seo_opt['zero_dupe']['post_redir']) {
			case 'guest':
				if (  !$user->data['is_registered'] ) {
					$this->seo_opt['zero_dupe']['do_redir_post'] = TRUE;
				}
				break;
			case 'all':
				$this->seo_opt['zero_dupe']['do_redir_post'] = TRUE;
				break;
			case 'off':
				// Do not redirect
				$this->seo_opt['zero_dupe']['do_redir'] = FALSE;
				$this->seo_opt['zero_dupe']['bool_redir'] = FALSE;
				$this->seo_opt['zero_dupe']['do_redir_post'] = FALSE;
				break;
			default:
				$this->seo_opt['zero_dupe']['do_redir_post'] = FALSE;
				break;	
		}
		return $this->seo_opt['zero_dupe']['do_redir_post'];
	}
	/**
	* Returns false if the uri sent does not match (fully) the 
	* attended url
	*/
	function seo_chk_dupe($uri = '', $url = '') {
		if ($this->seo_opt['zero_dupe']['do_redir']) {
			$this->seo_redirect($this->page_url);
		}
		if ($this->seo_opt['zero_dupe']['strict']) {
			return $this->seo_opt['zero_dupe']['bool_redir'] && ( ($uri != $url) ? $this->seo_redirect($this->page_url) : false );
		} else {
			return $this->seo_opt['zero_dupe']['bool_redir'] && ( (utf8_strpos( $uri, $url ) === false  ) ? $this->seo_redirect($this->page_url) : false );
		}
	}
	/**
	* check start var consistency
	* and return our best guess for $start, eg the first valid page 
	* parameter according to pagination settings being lower
	* than the one sent.
	*/
	function seo_chk_start($start = 0, $limit = 0) {
		if ($limit > 0) {
			$start = ( is_int( $start/$limit ) ) ? intval($start) : intval($start/$limit)*$limit;
		}
		if ( $start > 0  ) {
			$this->start = $this->seo_delim['start'] . intval($start);
			return $start;
		}
		$this->start = '';
		return 0;
	}
	// <-- Zero Duplicate
#
#-----[ REPLACE WITH ]------------------------------------------
#
	// --> Zero Duplicate
	/**
	* Custom HTTP 301 redirections.
	* To kill duplicates
	*/
	function seo_redirect($url, $header = '301 Moved Permanently', $code = 301, $replace = TRUE) {
		global $db;
		if (!$this->seo_opt['zero_dupe']['on'] || headers_sent()) {
			return;
		}
		garbage_collection();
		$url = str_replace('&amp;', '&', $url);
		// Make sure no linebreaks are there... to prevent http response splitting for PHP < 4.4.2
		if (strpos(urldecode($url), "\n") !== false || strpos(urldecode($url), "\r") !== false || strpos($url, ';') !== false) {
			trigger_error('Tried to redirect to potentially insecure url.', E_USER_ERROR);
		}
		$http = 'HTTP/1.1 ';
		header($http . $header, $replace, $code);
		header('Location: ' . $url);
		exit();
	}
	/**
	* Set the do_redir_post option right
	*/
	function set_do_redir_post() {
		global $user;
		switch ($this->seo_opt['zero_dupe']['post_redir']) {
			case 'guest':
				if (  !$user->data['is_registered'] ) {
					$this->seo_opt['zero_dupe']['do_redir_post'] = true;
				}
				break;
			case 'all':
				$this->seo_opt['zero_dupe']['do_redir_post'] = true;
				break;
			case 'off': // Do not redirect
				$this->seo_opt['zero_dupe']['do_redir'] = false;
				$this->seo_opt['zero_dupe']['go_redir'] = false;
				$this->seo_opt['zero_dupe']['do_redir_post'] = false;
				break;
			default:
				$this->seo_opt['zero_dupe']['do_redir_post'] = false;
				break;	
		}
		return $this->seo_opt['zero_dupe']['do_redir_post'];
	}
	/**
	* Redirects if the uri sent does not match (fully) the 
	* attended url
	*/
	function seo_chk_dupe($url = '', $uri = '') {
		global $auth, $user, $_SID;
		static $global_defs;
		if (empty($this->seo_opt['req_file']) || (!$this->seo_opt['rewrite_usermsg'] && $this->seo_opt['req_file'] == 'search') ) {
			return false;
		}
		$uri = !empty($uri) ? $uri : $this->seo_path['uri'];
		$reg = !empty($user->data['is_registered']) ? true : false;
		if (empty($global_defs)) {
			$global_defs = array(
				'sid' => array('val' => $_SID, 'keep' => $reg ? (boolean) !empty($_SID) :  (boolean) ( !empty($_SID) ? ($this->seo_opt['rem_sid'] ? false : true) : false)),
				'explain' => array('val' => 1, 'keep' => $reg ? (boolean) ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) : false),
			);
		}
		$this->seo_opt['zero_dupe']['redir_def'] = array_merge($this->seo_opt['zero_dupe']['redir_def'], $global_defs);
		$this->set_cond(!empty($_REQUEST['sid']) && ($_REQUEST['sid'] != $user->session_id || (!$reg && $this->seo_opt['rem_sid'])), 'do_redir');
		if (empty($url)) {;
			$url = $this->expected_url();
		} else {
			$url = str_replace('&amp;', '&', append_sid($url, false, true, 0));
			if (!empty($_SID) && $global_defs['sid']['keep']) {
				$url .=  (utf8_strpos( $url, '?' ) !== false ? '&' : '?') . 'sid=' . $_SID;
			}
			if (isset($_REQUEST['explain']) && $global_defs['explain']['keep']) {
				$url .= (utf8_strpos( $url, '?' ) !== false ? '&' : '?') . 'explain=1';
			}
		}
		$url = str_replace( '%26', '&', urldecode($url));
		if ($this->seo_opt['zero_dupe']['do_redir']) {
			$this->seo_redirect($url);
		} elseif ($this->seo_opt['zero_dupe']['strict']) {
			return $this->seo_opt['zero_dupe']['go_redir'] && ( ($uri != $url) ? $this->seo_redirect($url) : false );
		} else {
			return $this->seo_opt['zero_dupe']['go_redir'] && ( (utf8_strpos( $uri, $url ) === false) ? $this->seo_redirect($url) : false );
		}
	}
	/**
	* expected_url()
	* build expected url
	*/
	function expected_url() {
		global $phpEx;
		$params = array();
		foreach ($this->seo_opt['zero_dupe']['redir_def'] as $get => $def) {
			if ((isset($_REQUEST[$get]) && $def['keep']) || !empty($def['force'])) {
				$params[$get] = $def['val'];
			}
		}
		$this->page_url = append_sid($this->seo_opt['req_file'] . ".$phpEx", $params, false, 0);
		return $this->page_url;
	}
	/**
	* set_cond($bool, $type = 'bool_redir', $or = true)
	* Helps out grabbing boolean vars
	*/
	function set_cond($bool, $type = 'do_redir', $or = true) {
		if ( $or ) {
			$this->seo_opt['zero_dupe'][$type] = (boolean) ($bool || $this->seo_opt['zero_dupe'][$type]);
		} else {
			$this->seo_opt['zero_dupe'][$type] = (boolean) ($bool && $this->seo_opt['zero_dupe'][$type]);
		}
		return;
	}
	/**
	* check start var consistency
	* and return our best guess for $start, eg the first valid page 
	* parameter according to pagination settings being lower
	* than the one sent.
	*/
	function seo_chk_start($start = 0, $limit = 0) {
		if ($limit > 0) {
			$start = is_int($start/$limit) ? $start : intval($start/$limit)*$limit;
		}
		if ( $start >= 1 ) {
			$this->start = $this->seo_delim['start'] . (int) $start;
			return (int) $start;
		}
		$this->start = '';
		return 0;
	}
	// <-- Zero Duplicate
#
#-----[ OPEN ]------------------------------------------
#

search.php

#
#-----[ FIND ]------------------------------------------
#
			case 'active_topics':
				$l_search_title = $user->lang['SEARCH_ACTIVE_TOPICS'];
				$show_results = 'topics';
				$sort_key = 't';
				$sort_dir = 'd';
				$sort_days = request_var('st', 7);
#
#-----[ AFTER, ADD ]------------------------------------------
#
				// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
				$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
					'search_id' => array('val' => 'active_topics', 'keep' => true),
					'st' => array('val' => $sort_days, 'keep' => (boolean) ($sort_days != 7) ),
					'start' => array('val' => $phpbb_seo->seo_chk_start( $start, $config['topics_per_page'] ), 'keep' => true),
				);
				$phpbb_seo->seo_chk_dupe();
				// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ FIND ]------------------------------------------
#
			case 'unanswered':
				$l_search_title = $user->lang['SEARCH_UNANSWERED'];
				$show_results = request_var('sr', 'topics');
				$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
#
#-----[ AFTER, ADD ]------------------------------------------
#
				// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
				$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
					'sr' => array('val' => $show_results, 'keep' => (boolean) ($show_results == 'posts') ),
					'st' => array('val' => $sort_days, 'keep' => true),
					'sk' => array('val' => $sort_key, 'keep' => true),
					'sd' => array('val' => $sort_dir, 'keep' => true),
					'search_id' => array('val' => 'unanswered', 'keep' => true),
					'start' => array('val' => $phpbb_seo->seo_chk_start( $start, ($show_results == 'posts' ? $config['posts_per_page'] : $config['topics_per_page']) ), 'keep' => true),
				);
				$phpbb_seo->seo_chk_dupe();
				// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ FIND ]------------------------------------------
#
			case 'newposts':
				$l_search_title = $user->lang['SEARCH_NEW'];
				// force sorting
				$show_results = (request_var('sr', 'topics') == 'posts') ? 'posts' : 'topics';
#
#-----[ AFTER, ADD ]------------------------------------------
#
				// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
				$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
					'search_id' => array('val' => 'newposts', 'keep' => true),
					'sr' => array('val' => $show_results, 'keep' => (boolean) ($show_results == 'posts') ),
					'start' => array('val' => $phpbb_seo->seo_chk_start( $start, $config['topics_per_page'] ), 'keep' => true),
				);
				$phpbb_seo->seo_chk_dupe();
				// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ FIND ]------------------------------------------
#
		// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
		$seo_search_params = (!empty($u_search) ? '?' . $u_search . '&amp;': '?') .  'start=' .  $phpbb_seo->seo_chk_start( $start, $per_page );
		$phpbb_seo->page_url = str_replace('&amp;', '&', append_sid(  "{$phpbb_root_path}search.$phpEx$seo_search_params") );
		if ( $user->data['is_registered'] ) {
			$phpbb_seo->seo_cond( !isset($_GET['explain']) );
		}
		if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
			if ( !$user->data['is_registered'] ) {
				$phpbb_seo->seo_cond( isset($_GET['explain']), false, 'do' );
			}
		}
		if (!$submit) {
			$phpbb_seo->seo_chk_dupe(urldecode(urldecode($phpbb_seo->seo_path['uri'])), urldecode(urldecode($phpbb_seo->page_url)));
		}
		// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
		// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
		if (!$submit) {
			$seo_search_params = (!empty($u_search) ? '?' . $u_search . '&amp;': '?') .  'start=' .  $phpbb_seo->seo_chk_start( $start, $per_page );
			$phpbb_seo->seo_chk_dupe("{$phpbb_root_path}search.$phpEx$seo_search_params");
		}
		// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe
#
#-----[ OPEN ]------------------------------------------
#

viewforum.php

#
#-----[ FIND ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
if ($forum_data['forum_topics_per_page']) {
	$config['topics_per_page'] = $forum_data['forum_topics_per_page'];
}
$phpbb_seo->seo_opt['zero_dupe']['start'] = $phpbb_seo->seo_chk_start( $start, $config['topics_per_page'] );
$phpbb_seo->page_url = str_replace('&amp;', '&', append_sid("viewforum.$phpEx", "f=$forum_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir&amp;start=" . $phpbb_seo->seo_opt['zero_dupe']['start'] . (!empty($_SID) ? '&amp;sid=' . $_SID : '')));
if ( $user->data['is_registered'] ) {
	$phpbb_seo->seo_cond( !isset($_GET['explain']) || $mark_read != 'topics' || $mark_read != 'forums');
	$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'watch=') === FALSE) );
	$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'mark=') === FALSE) );
}
if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
	if ( !$user->data['is_registered'] ) {
		$phpbb_seo->seo_cond( isset($_GET['explain']) || $mark_read == 'topics' || $mark_read == 'forums', false, 'do' );
		$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'watch=') !== FALSE), false, 'do');
		$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'mark=') !== FALSE), false, 'do');
	}
}
$phpbb_seo->seo_chk_dupe($phpbb_seo->seo_path['uri'], $phpbb_seo->page_url);
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
if ($forum_data['forum_topics_per_page']) {
	$config['topics_per_page'] = $forum_data['forum_topics_per_page'];
}
$phpbb_seo->seo_opt['zero_dupe']['start'] = $phpbb_seo->seo_chk_start( $start, $config['topics_per_page'] );
$seo_watch = request_var('watch', '');
$seo_unwatch = request_var('unwatch', '');
$keep_watch = (boolean) ($seo_watch == 'forum' && $user->data['is_registered']);
$keep_unwatch = (boolean) ($seo_unwatch == 'forum' && $user->data['is_registered']);
$keep_mark = in_array($mark_read, array('topics', 'forums', 'all')) ? (boolean) ($user->data['is_registered'] || $config['load_anon_lastread']) : false;
$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
	'f' => array('val' => $forum_id, 'keep' => true, 'force' => true),
	'st' => array('val' => $sort_days, 'keep' => true),
	'sk' => array('val' => $sort_key, 'keep' => true),
	'sd' => array('val' => $sort_dir, 'keep' => true),
	'mark' => array('val' => $mark_read, 'keep' => $keep_mark),
	'watch' => array('val' => $seo_watch, 'keep' => $keep_watch),
	'unwatch' => array('val' => $seo_unwatch, 'keep' => $keep_unwatch),
	'start' => array('val' => $phpbb_seo->seo_opt['zero_dupe']['start'], 'keep' => true),
);
$phpbb_seo->seo_chk_dupe();
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
#
#-----[ FIND ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
if ($start != $phpbb_seo->seo_opt['zero_dupe']['start']) {
	$phpbb_seo->seo_redirect(str_replace('&amp;', '&', append_sid("viewforum.$phpEx", "f=$forum_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir&amp;start=$start" . (!empty($_SID) ? '&amp;sid=' . $_SID : ''))));
}
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
if ($start != $phpbb_seo->seo_opt['zero_dupe']['start']) {
	$phpbb_seo->seo_opt['zero_dupe']['redir_def']['start'] = array('val' => $start, 'keep' => true);
	$phpbb_seo->seo_chk_dupe();
}
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
#
#-----[ OPEN ]------------------------------------------
#

viewtopic.php

#
#-----[ FIND ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
$phpbb_seo->seo_opt['zero_dupe']['start'] = $phpbb_seo->seo_chk_start( $start, $config['posts_per_page'] );
if ( $user->data['is_registered'] ) {
	$phpbb_seo->seo_cond( !isset($_GET['explain']) );
	if ($config['allow_bookmarks'] ) {
		$phpbb_seo->seo_cond( !isset($_GET['bookmark']) );
	}
	$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'watch=') === FALSE) );
	$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'view=print') === FALSE) );
}
if ( !$phpbb_seo->seo_opt['zero_dupe']['strict'] ) { // strict mode is here a bit faster
	if ( !$user->data['is_registered'] ) {
		$phpbb_seo->seo_cond( isset($_GET['explain']) || isset($_GET['bookmark']), false, 'do' );
		$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'watch=') !== FALSE), false, 'do');
		$phpbb_seo->seo_cond( (utf8_strpos($phpbb_seo->seo_path['uri'], 'view=print') !== FALSE), false, 'do');
	}
}
if ( $post_id && !$phpbb_seo->set_do_redir_post() ) {
	$phpbb_seo->page_url = $phpbb_seo->seo_path['phpbb_urlR'] . $phpbb_seo->seo_static['post'] . $post_id . $phpbb_seo->seo_ext['topic'];
} else {
	$phpbb_seo->page_url = str_replace('&amp;', '&', append_sid("viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;start=" . $phpbb_seo->seo_opt['zero_dupe']['start'] . "&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir" . (($highlight_match) ? "&amp;hilit=$highlight" : '') . (!empty($_SID) ? '&amp;sid=' . $_SID : ''))) . (($post_id) ? '#p' . $post_id : '');
}
$phpbb_seo->seo_chk_dupe($phpbb_seo->seo_path['uri'], $phpbb_seo->page_url);
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
#
#-----[ REPLACE WITH ]------------------------------------------
#
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
$phpbb_seo->seo_opt['zero_dupe']['start'] = $phpbb_seo->seo_chk_start( $start, $config['posts_per_page'] );
if ( $post_id && !$phpbb_seo->set_do_redir_post()) {
	$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
		'p' => array('val' => $post_id, 'keep' => true),
		'hilit' => array('val' => (($highlight_match) ? $highlight : ''), 'keep' => !empty($highlight)),
	);
} else {
	$seo_watch = request_var('watch', '');
	$seo_unwatch = request_var('unwatch', '');
	$seo_bookmark = request_var('bookmark', 0);
	$keep_watch = (boolean) ($seo_watch == 'topic' && $user->data['is_registered']);
	$keep_unwatch = (boolean) ($seo_unwatch == 'topic' && $user->data['is_registered']);
	$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
		'f' => array('val' => $forum_id, 'keep' => true, 'force' => true),
		't' => array('val' => $topic_id, 'keep' => true, 'force' => true),
		'p' => array('val' => $post_id, 'keep' =>  ($view == 'show' ? true : false)),
		'watch' => array('val' => $seo_watch, 'keep' => $keep_watch),
		'unwatch' => array('val' => $seo_unwatch, 'keep' => $keep_unwatch),
		'bookmark' => array('val' => $seo_bookmark, 'keep' => (boolean) ($user->data['is_registered'] && $config['allow_bookmarks'] && $seo_bookmark)),
		'start' => array('val' => $phpbb_seo->seo_opt['zero_dupe']['start'], 'keep' => true, 'force' => true),
		'st' => array('val' => $sort_days, 'keep' => true),
		'sk' => array('val' => $sort_key, 'keep' => true),
		'sd' => array('val' => $sort_dir, 'keep' => true),
		'view' => array('val' => $view, 'keep' => $view == 'print' ? (boolean) $auth->acl_get('f_print', $forum_id) : true),
		'hilit' => array('val' => (($highlight_match) ? $highlight : ''), 'keep' => (boolean) !(!$user->data['is_registered'] && $phpbb_seo->seo_opt['rem_hilit'])),
	);
}
$phpbb_seo->seo_chk_dupe();
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
