############################################################## 
## MOD Title: Move Avatar Gallery Outside phpBB Root Path 
## MOD Author: Thoul < tempshad@hotmail.com >
## MOD Description: Store avatars outside the phpBB folder. 
## MOD Version: 1.2.0
## 
## Installation Level: Moderate
## Installation Time: 5-15 Minutes 
## Files To Edit: includes/usercp_register.php, 
##                     includes/usercp_avatar.php,
##                     admin/admin_users.php,
##                     admin/index.php
## Included Files: root_avatars_subdomain.txt, docroot_test.php
############################################################## 
## Author's Notes: 
## This MOD allows you to move the Avatar Gallery directory outside of the phpBB
## Root Path. This is useful if you have more than one phpBB installation or an 
## existing site structure that you don't want to completely rearrange. I keep my 
## avatars in /images/avatars/ instead of /phpBB/images/avatars/.
##
## This MOD uses the $DOCUMENT_ROOT variable, with the assumption that the directory 
## your avatars will be found in is somewhere under the root directory, e.g., 
## root/images/avatars/. If your forums are on a subdomain of your site (e.g., your 
## site is www.a.com, and your forums are on forum.a.com), you should use this MOD 
## as described in root_avatars_subdomain.txt.
##
## In addition to editing the files below, be sure to do the following:
##	1) In the phpBB Adminstration Control Panel, go to the General Admin section's 
##		Configuration page. Set the Avatar Storage Path and Avatar Gallery Path 
##		values to the directory where the avatars will be kept. These will need to 
##		begin with a / (e.g., /images/avatars/. NOT images/avatars/) because 
##		$DOCUMENT_ROOT's value does not end with a /.
##	2) Put the avatars there. ;)
## 
## Version History:
##	1.2.0 - Updated for phpBB 2.0.4.
##	1.1.1 - Updated for phpBB 2.0.3.
##	1.0.0 - Original release.
## 
## This MOD is released under the GPL License. 
## Intellectual Property is retained by the MOD Author(s) listed above.
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To 
## This MOD 
############################################################## 

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

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

if ( $board_config['allow_avatar_upload'] && file_exists(@phpbb_realpath('./' . $board_config['avatar_path'])) )

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

if ( $board_config['allow_avatar_upload'] && file_exists(@phpbb_realpath('./' . $board_config['avatar_path'])) )

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

if ( $board_config['allow_avatar_upload'] && file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_path'])) )

//
// MOD: -END-
//

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

			if ( $board_config['allow_avatar_local'] && file_exists(@phpbb_realpath('./' . $board_config['avatar_gallery_path'])) )
# 
#-----[ REPLACE WITH ]------------------------------------------ 
# 

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

			if ( $board_config['allow_avatar_local'] && file_exists(@phpbb_realpath('./' . $board_config['avatar_gallery_path'])) )

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

			if ( $board_config['allow_avatar_local'] && file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_gallery_path'])) )

//
// MOD: -END-
//

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

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

	global $board_config, $userdata;

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

	global $board_config, $userdata;

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

	global $board_config, $userdata, $DOCUMENT_ROOT;

//
// MOD: -END-
//

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

		if ( @file_exists(@phpbb_realpath('./' . $board_config['avatar_path'] . '/' . $avatar_file)) )

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

		if ( @file_exists(@phpbb_realpath('./' . $board_config['avatar_path'] . '/' . $avatar_file)) )

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

		if ( @file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_path'] . '/' . $avatar_file)) )

//
// MOD: -END-
//

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

	global $board_config, $db, $lang;

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

	global $board_config, $db, $lang;

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

	global $board_config, $db, $lang, $DOCUMENT_ROOT;

//
// MOD: -END-
//

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

			$tmp_path = ( !@$ini_val('safe_mode') ) ? '/tmp' : './' . $board_config['avatar_path'] . '/tmp';

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

			$tmp_path = ( !@$ini_val('safe_mode') ) ? '/tmp' : './' . $board_config['avatar_path'] . '/tmp';

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

			$tmp_path = ( !@$ini_val('safe_mode') ) ? '/tmp' : $DOCUMENT_ROOT . $board_config['avatar_path'] . '/tmp';

//
// MOD: -END-
//

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

			if ( file_exists(@phpbb_realpath('./' . $board_config['avatar_path'] . '/' . $current_avatar)) )
			{
				@unlink('./' . $board_config['avatar_path'] . '/' . $current_avatar);
			}

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

			if ( file_exists(@phpbb_realpath('./' . $board_config['avatar_path'] . '/' . $current_avatar)) )
			{
				@unlink('./' . $board_config['avatar_path'] . '/' . $current_avatar);
			}

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

			if ( file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_path'] . '/' . $current_avatar)) )
			{
				@unlink($DOCUMENT_ROOT . $board_config['avatar_path'] . '/' . $current_avatar);
			}

//
// MOD: -END-
//

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

			@copy($tmp_filename, './' . $board_config['avatar_path'] . "/$new_filename");

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

			@copy($tmp_filename, './' . $board_config['avatar_path'] . "/$new_filename");

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

			@copy($tmp_filename, $DOCUMENT_ROOT . $board_config['avatar_path'] . "/$new_filename");

//
// MOD: -END-
//

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

			$move_file($avatar_filename, './' . $board_config['avatar_path'] . "/$new_filename");
		}

		@chmod('./' . $board_config['avatar_path'] . "/$new_filename", 0777);

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

			$move_file($avatar_filename, './' . $board_config['avatar_path'] . "/$new_filename");
		}

		@chmod('./' . $board_config['avatar_path'] . "/$new_filename", 0777);

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

			$move_file($avatar_filename, $DOCUMENT_ROOT . $board_config['avatar_path'] . "/$new_filename");
		}

		@chmod($DOCUMENT_ROOT . $board_config['avatar_path'] . "/$new_filename", 0777);

//
// MOD: -END-
//

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

	global $board_config, $db, $template, $lang, $images, $theme;
	global $phpbb_root_path, $phpEx;

	$dir = @opendir($board_config['avatar_gallery_path']);

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

	global $board_config, $db, $template, $lang, $images, $theme;
	global $phpbb_root_path, $phpEx;

	$dir = @opendir($board_config['avatar_gallery_path']);

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

	global $board_config, $db, $template, $lang, $images, $theme;
	global $phpbb_root_path, $DOCUMENT_ROOT, $phpEx;

	$dir = @opendir($DOCUMENT_ROOT . $board_config['avatar_gallery_path']);

//
// MOD: -END-
//

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

		if( $file != '.' && $file != '..' && !is_file($board_config['avatar_gallery_path'] . '/' . $file) && !is_link($board_config['avatar_gallery_path'] . '/' . $file) )
		{
			$sub_dir = @opendir($board_config['avatar_gallery_path'] . '/' . $file);

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

		if( $file != '.' && $file != '..' && !is_file($board_config['avatar_gallery_path'] . '/' . $file) && !is_link($board_config['avatar_gallery_path'] . '/' . $file) )
		{
			$sub_dir = @opendir($board_config['avatar_gallery_path'] . '/' . $file);

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

		if( $file != '.' && $file != '..' && !is_file($DOCUMENT_ROOT . $board_config['avatar_gallery_path'] . '/' . $file) && !is_link($DOCUMENT_ROOT . $board_config['avatar_gallery_path'] . '/' . $file) )
		{
			$sub_dir = @opendir($DOCUMENT_ROOT . $board_config['avatar_gallery_path'] . '/' . $file);

//
// MOD: -END-
//

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

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

				if( @file_exists(@phpbb_realpath("./" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
				{
					@unlink("./" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']);
				}

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

				if( @file_exists(@phpbb_realpath("./" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
				{
					@unlink("./" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']);
				}

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

				if( @file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
				{
					@unlink($DOCUMENT_ROOT . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']);
				}

//
// MOD: -END-
//

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

									if( @file_exists(@phpbb_realpath("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
									{
										@unlink("./../" . $board_config['avatar_path'] . "/". $this_userdata['user_avatar']);
									}
								}
								@copy($user_avatar_loc, "./../" . $board_config['avatar_path'] . "/$avatar_filename");

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

									if( @file_exists(@phpbb_realpath("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
									{
										@unlink("./../" . $board_config['avatar_path'] . "/". $this_userdata['user_avatar']);
									}
								}
								@copy($user_avatar_loc, "./../" . $board_config['avatar_path'] . "/$avatar_filename");

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

									if( @file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
									{
										@unlink($DOCUMENT_ROOT . $board_config['avatar_path'] . "/". $this_userdata['user_avatar']);
									}
								}
								@copy($user_avatar_loc, $DOCUMENT_ROOT . $board_config['avatar_path'] . "/$avatar_filename");

//
// MOD: -END-
//

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

											if( file_exists(@phpbb_realpath("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
											{
												@unlink("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']);
											}
										}
										@copy($tmp_filename, "./../" . $board_config['avatar_path'] . "/$avatar_filename");

# 
#-----[ REPLACE WITH ]------------------------------------------ 
# 
/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

											if( file_exists(@phpbb_realpath("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
											{
												@unlink("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']);
											}
										}
										@copy($tmp_filename, "./../" . $board_config['avatar_path'] . "/$avatar_filename");

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

											if( file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) )
											{
												@unlink($DOCUMENT_ROOT . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']);
											}
										}
										@copy($tmp_filename, $DOCUMENT_ROOT . $board_config['avatar_path'] . "/$avatar_filename");

//
// MOD: -END-
//

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

			$dir = @opendir("../" . $board_config['avatar_gallery_path']);

			$avatar_images = array();
			while( $file = @readdir($dir) )
			{
				if( $file != "." && $file != ".." && !is_file(phpbb_realpath("./../" . $board_config['avatar_gallery_path'] . "/" . $file)) && !is_link(phpbb_realpath("./../" . $board_config['avatar_gallery_path'] . "/" . $file)) )
				{
					$sub_dir = @opendir("../" . $board_config['avatar_gallery_path'] . "/" . $file);

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

			$dir = @opendir("../" . $board_config['avatar_gallery_path']);

			$avatar_images = array();
			while( $file = @readdir($dir) )
			{
				if( $file != "." && $file != ".." && !is_file(phpbb_realpath("./../" . $board_config['avatar_gallery_path'] . "/" . $file)) && !is_link(phpbb_realpath("./../" . $board_config['avatar_gallery_path'] . "/" . $file)) )
				{
					$sub_dir = @opendir("../" . $board_config['avatar_gallery_path'] . "/" . $file);

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

			$dir = @opendir($DOCUMENT_ROOT . $board_config['avatar_gallery_path']);

			$avatar_images = array();
			while( $file = @readdir($dir) )
			{
				if( $file != "." && $file != ".." && !is_file(phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_gallery_path'] . "/" . $file)) && !is_link(phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_gallery_path'] . "/" . $file)) )
				{
					$sub_dir = @opendir($DOCUMENT_ROOT . $board_config['avatar_gallery_path'] . "/" . $file);

//
// MOD: -END-
//

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

						"AVATAR_IMAGE" => "../" . $board_config['avatar_gallery_path'] . "/" . $avatar_images[$category][$i][$j])

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

						"AVATAR_IMAGE" => "../" . $board_config['avatar_gallery_path'] . "/" . $avatar_images[$category][$i][$j])

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

						"AVATAR_IMAGE" => $board_config['avatar_gallery_path'] . "/" . $avatar_images[$category][$i][$j])

//
// MOD: -END-
//


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

				case USER_AVATAR_UPLOAD:
					$avatar = '<img src="../' . $board_config['avatar_path'] . '/' . $user_avatar . '" alt="" />';
					break;
				case USER_AVATAR_REMOTE:
					$avatar = '<img src="' . $user_avatar . '" alt="" />';
					break;
				case USER_AVATAR_GALLERY:
					$avatar = '<img src="../' . $board_config['avatar_gallery_path'] . '/' . $user_avatar . '" alt="" />';
					break;

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

				case USER_AVATAR_UPLOAD:
					$avatar = '<img src="../' . $board_config['avatar_path'] . '/' . $user_avatar . '" alt="" />';
					break;
				case USER_AVATAR_REMOTE:
					$avatar = '<img src="' . $user_avatar . '" alt="" />';
					break;
				case USER_AVATAR_GALLERY:
					$avatar = '<img src="../' . $board_config['avatar_gallery_path'] . '/' . $user_avatar . '" alt="" />';
					break;

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

				case USER_AVATAR_UPLOAD:
					$avatar = '<img src="' . $board_config['avatar_path'] . '/' . $user_avatar . '" alt="" />';
					break;
				case USER_AVATAR_REMOTE:
					$avatar = '<img src="' . $user_avatar . '" alt="" />';
					break;
				case USER_AVATAR_GALLERY:
					$avatar = '<img src="' . $board_config['avatar_gallery_path'] . '/' . $user_avatar . '" alt="" />';
					break;

//
// MOD: -END-
//

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

		if( file_exists(@phpbb_realpath('./../' . $board_config['avatar_path'])) && ($board_config['allow_avatar_upload'] == TRUE) )
		{
			if ( $form_enctype != '' )
			{
				$template->assign_block_vars('avatar_local_upload', array() );
			}
			$template->assign_block_vars('avatar_remote_upload', array() );
		}

		if( file_exists(@phpbb_realpath('./../' . $board_config['avatar_gallery_path'])) && ($board_config['allow_avatar_local'] == TRUE) )

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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

		if( file_exists(@phpbb_realpath('./../' . $board_config['avatar_path'])) && ($board_config['allow_avatar_upload'] == TRUE) )
		{
			if ( $form_enctype != '' )
			{
				$template->assign_block_vars('avatar_local_upload', array() );
			}
			$template->assign_block_vars('avatar_remote_upload', array() );
		}

		if( file_exists(@phpbb_realpath('./../' . $board_config['avatar_gallery_path'])) && ($board_config['allow_avatar_local'] == TRUE) )

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

		if( file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_path'])) && ($board_config['allow_avatar_upload'] == TRUE) )
		{
			if ( $form_enctype != '' )
			{
				$template->assign_block_vars('avatar_local_upload', array() );
			}
			$template->assign_block_vars('avatar_remote_upload', array() );
		}

		if( file_exists(@phpbb_realpath($DOCUMENT_ROOT . $board_config['avatar_gallery_path'])) && ($board_config['allow_avatar_local'] == TRUE) )

//
// MOD: -END-
//

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

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

	if ($avatar_dir = @opendir($phpbb_root_path . $board_config['avatar_path']))
	{
		while( $file = @readdir($avatar_dir) )
		{
			if( $file != "." && $file != ".." )
			{
				$avatar_dir_size += @filesize($phpbb_root_path . $board_config['avatar_path'] . "/" . $file);
			}
		}
		@closedir($avatar_dir);


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

/* Original phpBB code - commented out for Avatar Gallery Outside phpBB

	if ($avatar_dir = @opendir($phpbb_root_path . $board_config['avatar_path']))
	{
		while( $file = @readdir($avatar_dir) )
		{
			if( $file != "." && $file != ".." )
			{
				$avatar_dir_size += @filesize($phpbb_root_path . $board_config['avatar_path'] . "/" . $file);
			}
		}
		@closedir($avatar_dir);

*/
//
// MOD:  Avatar Gallery Outside phpBB
//

	if ($avatar_dir = @opendir($DOCUMENT_ROOT . $board_config['avatar_path']))
	{
		while( $file = @readdir($avatar_dir) )
		{
			if( $file != "." && $file != ".." )
			{
				$avatar_dir_size += @filesize($DOCUMENT_ROOT . $board_config['avatar_path'] . "/" . $file);
			}
		}
		@closedir($avatar_dir);

//
// MOD: -END-
//

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