##############################################################
## MOD Title: 		phpBB SEO Zro dupilcate MAJ 0.4.6 => 0.4.6
## 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.4 => 0.4.6.
## 			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: 	5 Minutes
## Files To Edit: 	5
##			index.php,
##			memberlist.php,
##			phpbb_seo/phpbb_seo_class.php,
##			viewforum.php,
##			viewtopic.php.
##
## Included Files: n/a
##############################################################
## Author Notes:
## _____________
##
## Voici les instructions de mise  jour : phpBB3 SEO Mod Zro dupilcate 0.4.4 => 0.4.6
##
##############################################################
## MOD History:
##
##	2008-11-22 - 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.

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

index.php

#
#-----[ FIND ]------------------------------------------
#
$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),
);
#
#-----[ REPLACE WITH ]------------------------------------------
#
$keep_mark = in_array($seo_mark, array('topics', 'topic', '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),
	'hash' => array('val' => request_var('hash', ''), 'keep' => $keep_mark),
);
#
#-----[ OPEN ]------------------------------------------
#

memberlist.php

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

// What do you want to do today? ... oops, I think that line is taken ...
switch ($mode)
{
		case 'leaders':

#
#-----[ AFTER, ADD ]------------------------------------------
#

		// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
		$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
			'mode' => array('val' => 'leaders', '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 ( 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
#
#-----[ REPLACE WITH ]------------------------------------------
# Nothing => delete !!

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

		$pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
		$sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $sort_params));

#
#-----[ AFTER, ADD ]------------------------------------------
#

		// www.phpBB-SEO.com SEO TOOLKIT BEGIN - Zero dupe
		if ($mode == 'group') {
			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_chk_dupe("{$phpbb_root_path}memberlist.$phpEx?" . implode('&amp;', $params) . '&amp;start=' . $phpbb_seo->seo_opt['zero_dupe']['start']);
		}
		// www.phpBB-SEO.com SEO TOOLKIT END - Zero dupe

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

phpbb_seo/phpbb_seo_class.php

#
#-----[ 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'] || 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 ( empty($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

#
#-----[ 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 false;
		}
		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_handler();
	}
	/**
	* 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 ( empty($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 = '', $path = '') {
		global $auth, $user, $_SID, $phpbb_root_path;
		static $global_defs;
		if (empty($this->seo_opt['req_file']) || (!$this->seo_opt['rewrite_usermsg'] && $this->seo_opt['req_file'] == 'search') ) {
			return false;
		}
		$path = empty($path) ? $phpbb_root_path : $path;
		$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($path);
		} 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($path = '')
	* build expected url
	*/
	function expected_url($path = '') {
		global $phpbb_root_path, $phpEx;
		$path = empty($path) ? $phpbb_root_path : $path;
		$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($path . $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 ]------------------------------------------
#

viewforum.php

#
#-----[ FIND ]------------------------------------------
#
$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),
);
#
#-----[ REPLACE WITH ]------------------------------------------
#
$keep_mark = in_array($mark_read, array('topics', 'topic', 'forums', 'all')) ? (boolean) ($user->data['is_registered'] || $config['load_anon_lastread']) : false;
$keep_hash = (boolean) ($keep_watch || $keep_unwatch || $keep_mark);
$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
	'uid' => array('val' => request_var('uid', 0), 'keep' => $keep_hash),
	'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),
	'hash' => array('val' => request_var('hash', ''), 'keep' => $keep_hash),
);
#
#-----[ OPEN ]------------------------------------------
#

viewtopic.php

#
#-----[ FIND ]------------------------------------------
#
	$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) : false),
		'hilit' => array('val' => (($highlight_match) ? $highlight : ''), 'keep' => (boolean) !(!$user->data['is_registered'] && $phpbb_seo->seo_opt['rem_hilit'])),
	);
#
#-----[ REPLACE WITH ]------------------------------------------
#
	$keep_hash = (boolean) ($keep_watch || $keep_unwatch || $seo_bookmark);
	$phpbb_seo->seo_opt['zero_dupe']['redir_def'] = array(
		'uid' => array('val' => request_var('uid', 0), 'keep' => $keep_hash),
		'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),
		'hash' => array('val' => request_var('hash', ''), 'keep' => $keep_hash),
		'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) : ($view == 'viewpoll' ? true : false)),
		'hilit' => array('val' => (($highlight_match) ? $highlight : ''), 'keep' => (boolean) !(!$user->data['is_registered'] && $phpbb_seo->seo_opt['rem_hilit'])),
	);
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
