Problem med profile photo mod

Frågor kring MODdar (modifikationer) för phpBB 2.0.x.

Moderatorer: Moderatorgrupp, Supportgrupp

Joakim
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 319
Blev medlem: 2003-10-19 18:26
Svar: 0

Problem med profile photo mod

Inlägg av Joakim »

Jag får detta meddelandet när jag försöker lägga upp en bild:

Kod: Markera allt

Warning: copy(./images/photos/0a01140b4394b274b4f19.jpg) [function.copy]: failed to open stream: Permission denied in D:\InetPub\domain.se\forum\profilephoto_mod.php on line 221 

Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\domain.se\forum\profilephoto_mod.php:221) in D:\InetPub\domain.se\forum\includes\page_header.php on line 519 

Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\domain.se\forum\profilephoto_mod.php:221) in D:\InetPub\domain.se\forum\includes\page_header.php on line 521 

Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\domain.se\forum\profilephoto_mod.php:221) in D:\InetPub\domain.se\forum\includes\page_header.php on line 522 
CHMOD är 777 (dubbelkollat)

Någon annan idé vad det kan vara ?
Feel the Force !
windsurf.se
Användarens profilbild
Holger
Support - Ledare
Support - Ledare
Inlägg: 6571
Blev medlem: 2004-06-09 09:32
Svar: 1

Inlägg av Holger »

Gjorde du ändringar i page_header.php?

Dubbelkolla att du ej har tomma tecken efter ?> i alla filer som du redigerat!
Holger Gremminger
Ingen support via PM!
Joakim
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 319
Blev medlem: 2003-10-19 18:26
Svar: 0

Inlägg av Joakim »

Inga ändringar i page_header och filerna kollade utan resultat :/
Feel the Force !
windsurf.se
Användarens profilbild
Holger
Support - Ledare
Support - Ledare
Inlägg: 6571
Blev medlem: 2004-06-09 09:32
Svar: 1

Inlägg av Holger »

Då är det helt klart så att mappen photos inte har rätt rättigheter ... konstigt!
Holger Gremminger
Ingen support via PM!
Joakim
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 319
Blev medlem: 2003-10-19 18:26
Svar: 0

Inlägg av Joakim »

Provade att skapa en ny mapp och styrde den dit istället utan resultat...
Feel the Force !
windsurf.se
Användarens profilbild
Holger
Support - Ledare
Support - Ledare
Inlägg: 6571
Blev medlem: 2004-06-09 09:32
Svar: 1

Inlägg av Holger »

Kan du ta och lägga upp modd-beskrivningen här?
Holger Gremminger
Ingen support via PM!
Joakim
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 319
Blev medlem: 2003-10-19 18:26
Svar: 0

Inlägg av Joakim »

Kod: Markera allt

#############################################################################
## Mod Title:   Profile Photo Mod 
## Mod Version: 2.0.2
## Author:      Acyd Burn < acyd.burn@gmx.de > - Meik Sievertsen - http://www.opentools.de/
##
## Description: 
##		This Mod adds the ability to let your users attach photos to their profile.
##
## Revision History:
##
##		2002-06-02 - Version 2.0.2
##			- made phpBB 2.0.x compatible
##
##		2002-03-21 - Version 2.0.1
##			- complete rewrite of this mod for rc-4. :)
##			- bugfixes
##
##		2002-03-07 - initial version 2.0.0
##
## Installation Level:  intermediate
## Installation Time:   5-10 Minutes
## Files To Edit:       profile.php, admin/admin_board.php, includes/usercp_register.php, 
##			templates/subSilver/profile_add_body.tpl, templates/subSilver/profile_view_body.tpl,
##			templates/subSilver/admin/board_config_body.tpl
## Included Files:      3 (+1 temporary file for installation)
## 
#############################################################################
## This MOD is released under the GPL License. 
## Intellectual Property is retained by the MOD Author(s) listed above 
#############################################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/downloads/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/downloads/ 
#############################################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
#############################################################################
## 
## Author Note: 
## 
## This Mod adds some rows to the users table and to the config table
##
## At the moment, english, german and french are supported. If the Mod can not
## find the appropiate language file, english is used by default.
##
##
#############################################################################

#
# First of all, copy all files to their respective location
#

# These are: 
#	/profilephoto_mod.php
#	/mod_table_inst.php	(you can delete it after installation)
#
#	/templates/subSilver/profile_photo_box.tpl
#
#	/language/lang_XX/lang_profilephoto.php
#

Now we want to create the rows in the database, therefore we execute mod_table_inst.php (http://www.yoursite.com/phpBB2/mod_table_inst.php)
Contact me if you have questions about this.

Now you have to alter existing files, read the instructions carefully and make sure you find all lines.

#
# Changes to already existing files
#

# 
#-----[ OPEN ]--------------------------------------------- 
# 
./profile.php

# 
#-----[ FIND ]---------------------------------------------
# 
include($phpbb_root_path . 'common.'.$phpEx);

# 
#-----[ AFTER, ADD ]---------------------------------------
# 
include($phpbb_root_path . 'profilephoto_mod.'.$phpEx);

# 
#-----[ FIND ]---------------------------------------------
# 
// End page specific functions
// ---------------------------

# 
#-----[ AFTER, ADD ]---------------------------------------
# 
$profilephoto_mod->execute_mod();

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

# 
#-----[ FIND ]---------------------------------------------
# 
$template->set_filenames(array(
	"body" => "admin/board_config_body.tpl")
);

# 
#-----[ AFTER, ADD ]---------------------------------------
# 
//
// Profile Photo Mod
//
if ( !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_profilephoto.'.$phpEx) )
{
	include($phpbb_root_path . 'language/lang_english/lang_profilephoto.'.$phpEx);
}
else
{
	include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_profilephoto.' . $phpEx);
}

$photo_remote_yes = ( $new['allow_photo_remote'] ) ? 'checked="checked"' : '';
$photo_remote_no = ( !$new['allow_photo_remote'] ) ? 'checked="checked"' : '';
$photo_upload_yes = ( $new['allow_photo_upload'] ) ? 'checked="checked"' : '';
$photo_upload_no = ( !$new['allow_photo_upload'] ) ? 'checked="checked"' : '';

$template->assign_vars(array(
	'L_PROFLE_PHOTO_SETTINGS' => $lang['Profile_photo_settings'],
	'L_ALLOW_PHOTO_REMOTE' => $lang['Allow_photo_remote'],
	'L_ALLOW_PHOTO_REMOTE_EXPLAIN' => $lang['Allow_photo_remote_explain'],
	'L_ALLOW_PHOTO_UPLOAD' => $lang['Allow_photo_upload'],
	'L_PHOTO_MAX_FILESIZE' => $lang['Photo_max_filesize'],
	'L_PHOTO_MAX_FILESIZE_EXPLAIN' => $lang['Photo_max_filesize_explain'],
	'L_MAX_PHOTO_SIZE' => $lang['Max_photo_size'],
	'L_PHOTO_STORAGE_PATH' => $lang['Photo_storage_path'],
	'L_PHOTO_STORAGE_PATH_EXPLAIN' => $lang['Photo_storage_path_explain'],

	'PHOTO_REMOTE_YES' => $photo_remote_yes,
	'PHOTO_REMOTE_NO' => $photo_remote_no,
	'PHOTO_UPLOAD_YES' => $photo_upload_yes,
	'PHOTO_UPLOAD_NO' => $photo_upload_no,
	'PHOTO_FILESIZE' => $new['photo_filesize'],
	'PHOTO_MAX_HEIGHT' => $new['photo_max_height'],
	'PHOTO_MAX_WIDTH' => $new['photo_max_width'],
	'PHOTO_PATH' => $new['photo_path'])
);

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

# 
#-----[ FIND ]---------------------------------------------
# 
$error = FALSE;

# 
#-----[ REPLACE WITH ]-------------------------------------
# 
// $error = FALSE;

# 
#-----[ FIND ]---------------------------------------------
# 
				message_die(GENERAL_ERROR, 'Could not insert data into users table', '', __LINE__, __FILE__, $sql);
			}

# 
#-----[ AFTER, ADD ]---------------------------------------
# 
			$profilephoto_mod->photo_insert($mode);

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

# 
#-----[ FIND ]---------------------------------------------
# 
<input type="hidden" name="MAX_FILE_SIZE" value="{AVATAR_SIZE}" />

# 
#-----[ REPLACE WITH ]-------------------------------------
# 
<!--<input type="hidden" name="MAX_FILE_SIZE" value="{AVATAR_SIZE}" />-->

# 
#-----[ FIND ]---------------------------------------------
# 
	<!-- END switch_avatar_block -->

# 
#-----[ AFTER, ADD ]---------------------------------------
# 
	{PHOTO_BOX}

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

# 
#-----[ FIND ]---------------------------------------------
# 
		  //--></script><noscript>{ICQ_IMG}</noscript></td>
		</tr>
	  </table>
	</td>
  </tr>

# 
#-----[ AFTER, ADD ]---------------------------------------
# 
  <tr> 
	<td class="catLeft" align="center" width="40%" height="28" colspan="2"><b><span class="gen">{L_PHOTO}</span></b></td>
  <tr> 
	<td align="center" colspan="2" class="row1">{PHOTO_IMG}</td>
  </tr>

# 
#-----[ OPEN ]--------------------------------------------- 
# 
./templates/subSilver/admin/board_config_body.tpl

# 
#-----[ FIND ]---------------------------------------------
# 
		<td class="row2"><input type="text" size="20" maxlength="255" name="avatar_gallery_path" value="{AVATAR_GALLERY_PATH}" /></td>
	</tr>

# 
#-----[ AFTER, ADD ]---------------------------------------
# 
	<tr>
	  <th class="thHead" colspan="2">{L_PROFLE_PHOTO_SETTINGS}</th>
	</tr>
	<tr>
		<td class="row1">{L_ALLOW_PHOTO_REMOTE} <br /><span class="gensmall">{L_ALLOW_PHOTO_REMOTE_EXPLAIN}</span></td>
		<td class="row2"><input type="radio" name="allow_photo_remote" value="1" {PHOTO_REMOTE_YES} /> {L_YES}&nbsp;&nbsp;<input type="radio" name="allow_photo_remote" value="0" {PHOTO_REMOTE_NO} /> {L_NO}</td>
	</tr>
	<tr>
		<td class="row1">{L_ALLOW_PHOTO_UPLOAD}</td>
		<td class="row2"><input type="radio" name="allow_photo_upload" value="1" {PHOTO_UPLOAD_YES} /> {L_YES}&nbsp;&nbsp;<input type="radio" name="allow_photo_upload" value="0" {PHOTO_UPLOAD_NO} /> {L_NO}</td>
	</tr>
	<tr>
		<td class="row1">{L_PHOTO_MAX_FILESIZE}<br /><span class="gensmall">{L_PHOTO_MAX_FILESIZE_EXPLAIN}</span></td>
		<td class="row2"><input type="text" size="4" maxlength="10" name="photo_filesize" value="{PHOTO_FILESIZE}" /> Bytes</td>
	</tr>
	<tr>
		<td class="row1">{L_MAX_PHOTO_SIZE} <br />
			<span class="gensmall">{L_MAX_AVATAR_SIZE_EXPLAIN}</span>
		</td>
		<td class="row2"><input type="text" size="3" maxlength="4" name="photo_max_height" value="{PHOTO_MAX_HEIGHT}" /> x <input type="text" size="3" maxlength="4" name="photo_max_width" value="{PHOTO_MAX_WIDTH}"></td>
	</tr>
	<tr>
		<td class="row1">{L_PHOTO_STORAGE_PATH} <br /><span class="gensmall">{L_PHOTO_STORAGE_PATH_EXPLAIN}</span></td>
		<td class="row2"><input type="text" size="20" maxlength="255" name="photo_path" value="{PHOTO_PATH}" /></td>
	</tr>

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

You'll have to create the directory for your photos (like the avatar directory) and chmod 
it to 777 (or change the owner to you httpd-servers owner) to upload photos.
if you have only plain ftp-access change the 'Attribute' of your photo-directory to rwxrwxrwx.
the default path is 'images/photos'.

# EoM
Feel the Force !
windsurf.se
Användarens profilbild
Holger
Support - Ledare
Support - Ledare
Inlägg: 6571
Blev medlem: 2004-06-09 09:32
Svar: 1

Inlägg av Holger »

Lägg upp profilephoto_mod.php här ...
Holger Gremminger
Ingen support via PM!
Joakim
Extra aktiv medlem
Extra aktiv medlem
Inlägg: 319
Blev medlem: 2003-10-19 18:26
Svar: 0

Inlägg av Joakim »

Kod: Markera allt

<?php
/***************************************************************************
 *						   profilephoto_mod.php
 *                            -------------------
 *   begin                : Sunday, Mar 07, 2002
 *   copyright            : (C) 2002 Meik Sievertsen
 *   email                : acyd.burn@gmx.de
 *
 *   $Id: profilephoto_mod.php,v 2.0.2 2002/06/02 meik Exp $
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

if ( !defined('IN_PHPBB') )
{
	die('Hacking attempt');
	exit;
}

//
// Functions
//
function user_photo_delete($photo_type, $photo_file)
{
	global $board_config, $userdata;

	if ( $photo_type == USER_AVATAR_UPLOAD && $photo_file != '' )
	{
		if ( @file_exists('./' . $board_config['photo_path'] . '/' . $photo_file) )
		{
			@unlink('./' . $board_config['photo_path'] . '/' . $photo_file);
		}
	}

	return " user_photo = '', user_photo_type = " . USER_AVATAR_NONE;
}

function check_photoimage_type(&$type, &$error, &$error_msg)
{
	global $lang;

	switch( $type )
	{
		case 'jpeg':
		case 'pjpeg':
		case 'jpg':
			return '.jpg';
			break;
		case 'gif':
			return '.gif';
			break;
		case 'png':
			return '.png';
			break;
		default:
			$error = true;
			$error_msg = (!empty($error_msg)) ? $error_msg . '<br />' . $lang['Photo_filetype'] : $lang['Photo_filetype'];
			break;
	}

	return false;
}

function user_photo_url($mode, &$error, &$error_msg, $photo_filename)
{
	if ( !preg_match('#^http:\/\/#i', $photo_filename) )
	{
		$photo_filename = 'http://' . $photo_filename;
	}

	if ( !preg_match('#^(http:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/[^\"]*?\.(gif|jpg|jpeg|png)$)#is', $photo_filename) )
	{
		$error = true;
		$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Wrong_remote_photo_format'] : $lang['Wrong_remote_photo_format'];
		return;
	}

	return ( $mode == 'editprofile' ) ? " user_photo = '" . str_replace("\'", "''", $photo_filename) . "', user_photo_type = " . USER_AVATAR_REMOTE : '';

}

function user_photo_upload($mode, $photo_mode, &$current_photo, &$current_type, &$error, &$error_msg, $photo_filename, $photo_realname, $photo_filesize, $photo_filetype)
{
	global $board_config, $user_ip, $db, $lang;

	$ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';

	if ( $photo_mode == 'remote' && preg_match('/^(http:\/\/)?([\w\-\.]+)\:?([0-9]*)\/(.*)$/', $photo_filename, $url_ary) )
	{
		if ( empty($url_ary[4]) )
		{
			$error = true;
			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Incomplete_URL'] : $lang['Incomplete_URL'];
			return;
		}

		$base_get = '/' . $url_ary[4];
		$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;

		if ( !($fsock = @fsockopen($url_ary[2], $port, $errno, $errstr)) )
		{
			$error = true;
			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['No_connection_URL'] : $lang['No_connection_URL'];
			return;
		}

		@fputs($fsock, "GET $base_get HTTP/1.1\r\n");
		@fputs($fsock, "HOST: " . $url_ary[2] . "\r\n");
		@fputs($fsock, "Connection: close\r\n\r\n");

		unset($photo_data);
		while( !@feof($fsock) )
		{
			$photo_data .= @fread($fsock, $board_config['photo_filesize']);
		}
		@fclose($fsock);

		if ( !preg_match('/Content-Length\: ([0-9]+)[^\/ ][\s]+/i', $photo_data, $file_data1) || !preg_match('/Content-Type\: image\/[x\-]*([a-z]+)[\s]+/i', $photo_data, $file_data2) )
		{
			$error = true;
			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['File_no_data'] : $lang['File_no_data'];
			return;
		}

		$photo_filesize = $file_data1[1]; 
		$photo_filetype = $file_data2[1]; 

		if ( !$error && $photo_filesize > 0 && $photo_filesize < $board_config['photo_filesize'] )
		{
			$photo_data = substr($photo_data, strlen($photo_data) - $photo_filesize, $photo_filesize);

			$tmp_path = ( !@$ini_val('safe_mode') ) ? '/tmp' : './' . $board_config['photo_path'] . '/tmp';
			$tmp_filename = tempnam($tmp_path, uniqid($user_ip) . '-');

			$fptr = @fopen($tmp_filename, 'wb');
			$bytes_written = @fwrite($fptr, $photo_data, $photo_filesize);
			@fclose($fptr);

			if ( $bytes_written != $photo_filesize )
			{
				@unlink($tmp_filename);
				message_die(GENERAL_ERROR, 'Could not write photo file to local storage. Please contact the board administrator with this message', '', __LINE__, __FILE__);
			}

			list($width, $height) = @getimagesize($tmp_filename);
		}
		else
		{
			$l_photo_size = sprintf($lang['Photo_filesize'], round($board_config['photo_filesize'] / 1024));

			$error = true;
			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_photo_size : $l_photo_size;
		}
	}
	else if ( $photo_mode == 'local' && file_exists($photo_filename) && preg_match('/\.(jpg|jpeg|gif|png)$/i', $photo_realname) )
	{
		if ( $photo_filesize <= $board_config['photo_filesize'] && $photo_filesize > 0 )
		{
			preg_match('#image\/[x\-]*([a-z]+)#', $photo_filetype, $photo_filetype);
			$photo_filetype = $photo_filetype[1];
		}
		else
		{
			$l_photo_size = sprintf($lang['Photo_filesize'], round($board_config['photo_filesize'] / 1024));

			$error = true;
			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_photo_size : $l_photo_size;
			return;
		}

		list($width, $height) = @getimagesize($photo_filename);
	}

	if ( !($imgtype = check_photoimage_type($photo_filetype, $error, $error_msg)) )
	{
		return;
	}

	if ( $width <= $board_config['photo_max_width'] && $height <= $board_config['photo_max_height'] )
	{
		$new_filename = uniqid($user_ip) . $imgtype;

		if ( $mode == 'editprofile' && $current_type == USER_AVATAR_UPLOAD && $current_photo != '' )
		{
			if ( file_exists('./' . $board_config['photo_path'] . '/' . $current_photo) )
			{
				@unlink('./' . $board_config['photo_path'] . '/' . $current_photo);
			}
		}

		if( $photo_mode == 'remote' )
		{
			@copy($tmp_filename, './' . $board_config['photo_path'] . "/$new_filename");
			@unlink($tmp_filename);
		}
		else
		{
			if ( @$ini_val('open_basedir') != '' )
			{
				if ( @phpversion() < '4.0.3' )
				{
					message_die(GENERAL_ERROR, 'open_basedir is set and your PHP version does not allow move_uploaded_file', '', __LINE__, __FILE__);
				}

				$move_file = 'move_uploaded_file';
			}
			else
			{
				$move_file = 'copy';
			}

			$move_file($photo_filename, './' . $board_config['photo_path'] . "/$new_filename");
		}

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

		$photo_sql = " user_photo = '$new_filename', user_photo_type = " . USER_AVATAR_UPLOAD;
	}
	else
	{
		$l_photo_size = sprintf($lang['Photo_imagesize'], $board_config['photo_max_width'], $board_config['photo_max_height']);

		$error = true;
		$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_photo_size : $l_photo_size;
	}

	return $photo_sql;
}


class profilephoto
{

	var $photo_sql = '';

	function execute_mod()
	{
		global $HTTP_POST_VARS, $HTTP_GET_VARS, $mode, $userdata;

		if ( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
		{
			$mode = ( isset($HTTP_GET_VARS['mode']) ) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];

			if ( $mode == 'viewprofile' )
			{
				$this->perform_viewprofile();
				return;
			}
			else if ( $mode == 'editprofile' || $mode == 'register' )
			{
				if ( !$userdata['session_logged_in'] && $mode == 'editprofile' )
				{
					return;
				}

				$this->perform_register();
				return;
			}
		}
		else
		{
			return;
		}
	}

	function perform_viewprofile()
	{
		global $HTTP_GET_VARS, $lang, $board_config, $phpbb_root_path, $phpEx, $template;
		
		if ( !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_profilephoto.'.$phpEx) )
		{
			include($phpbb_root_path . 'language/lang_english/lang_profilephoto.'.$phpEx);
		}
		else
		{
			include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_profilephoto.' . $phpEx);
		}

		if ( empty($HTTP_GET_VARS[POST_USERS_URL]) || $HTTP_GET_VARS[POST_USERS_URL] == ANONYMOUS )
		{
			message_die(GENERAL_MESSAGE, $lang['No_user_id_specified']);
		}
		$profiledata = get_userdata(intval($HTTP_GET_VARS[POST_USERS_URL]));

		$photo_img = '';
		if ( $profiledata['user_photo_type'] )
		{
			switch( $profiledata['user_photo_type'] )
			{
				case USER_AVATAR_UPLOAD:
					$photo_img = ( $board_config['allow_photo_upload'] ) ? '<img src="' . $board_config['photo_path'] . '/' . $profiledata['user_photo'] . '" alt="" border="0" />' : '';
					break;
				case USER_AVATAR_REMOTE:
					$photo_img = ( $board_config['allow_photo_remote'] ) ? '<img src="' . $profiledata['user_photo'] . '" alt="" border="0" />' : '';
					break;
			}
		}

		$template->assign_vars(array(
			'L_PHOTO' => $lang['Profile_photo'],
			'PHOTO_IMG' => $photo_img)
		);
	
	}

	function perform_register()
	{
		global $phpbb_root_path, $board_config, $phpEx, $mode, $HTTP_POST_VARS, $userdata, $error, $error_msg, $lang, $new_user_id, $id, $user_id, $template, $db, $HTTP_POST_FILES;

		if ( !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_profilephoto.'.$phpEx) )
		{
			include($phpbb_root_path . 'language/lang_english/lang_profilephoto.'.$phpEx);
		}
		else
		{
			include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_profilephoto.' . $phpEx);
		}

		if ( isset($HTTP_POST_VARS['submit']) || $mode == 'register' )
		{
			if ( $mode == 'editprofile' )
			{
				$user_id = intval($HTTP_POST_VARS['user_id']);
			}

			$user_photo_upload = ( !empty($HTTP_POST_VARS['photourl']) ) ? trim($HTTP_POST_VARS['photourl']) : ( ( $HTTP_POST_FILES['photo']['tmp_name'] != 'none') ? $HTTP_POST_FILES['photo']['tmp_name'] : '' );

			$user_photo_remoteurl = ( !empty($HTTP_POST_VARS['photoremoteurl']) ) ? trim($HTTP_POST_VARS['photoremoteurl']) : '';

			$user_photo_name = ( !empty($HTTP_POST_FILES['photo']['name']) ) ? $HTTP_POST_FILES['photo']['name'] : '';
			$user_photo_size = ( !empty($HTTP_POST_FILES['photo']['size']) ) ? $HTTP_POST_FILES['photo']['size'] : 0;
			$user_photo_filetype = ( !empty($HTTP_POST_FILES['photo']['type']) ) ? $HTTP_POST_FILES['photo']['type'] : '';
			$user_photo_url = ( !empty($HTTP_POST_VARS['photourl']) ) ? trim($HTTP_POST_VARS['photourl']) : '';

			$user_photo = ( empty($user_photo_loc) && $mode == 'editprofile' ) ? $userdata['user_photo'] : '';
			$user_photo_type = ( empty($user_photo_loc) && $mode == 'editprofile' ) ? $userdata['user_photo_type'] : '';
		}

		if ( isset($HTTP_POST_VARS['submit']) )
		{

			$error = FALSE;

			if ( isset($HTTP_POST_VARS['photodel']) && $mode == 'editprofile' )
			{
				$this->photo_sql = user_photo_delete($userdata['user_photo_type'], $userdata['user_photo']);
			}
			else if ( ( !empty($user_photo_upload) || !empty($user_photo_name) ) && $board_config['allow_photo_upload'] )
			{
		
				if ( !empty($user_photo_upload) )
				{
					$photo_mode = ( !empty($user_photo_name) ) ? 'local' : 'remote';
					$this->photo_sql = user_photo_upload($mode, $photo_mode, $userdata['user_photo'], $userdata['user_photo_type'], $error, $error_msg, $user_photo_upload, $user_photo_name, $user_photo_size, $user_photo_filetype);
				}
				else if ( !empty($user_photo_name) )
				{
					$l_photo_size = sprintf($lang['Photo_filesize'], round($board_config['photo_filesize'] / 1024));

					$error = true;
					$error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $l_avatar_size;
				}
			}
			else if ( $user_photo_remoteurl != '' && $board_config['allow_photo_remote'] )
			{
				$this->photo_sql = user_photo_url($mode, $error, $error_msg, $user_photo_remoteurl);
			}

			if ( !$error )
			{
				if ( $this->photo_sql == '' )
				{
					$this->photo_sql = ( $mode == 'editprofile' ) ? '' : " user_photo = '', user_photo_type = " . USER_AVATAR_NONE;
				}

				if ($this->photo_sql != '')
				{
					if ( $mode == 'editprofile' )
					{
						$sql = "UPDATE " . USERS_TABLE . "
						SET " . $this->photo_sql . "
						WHERE user_id = $user_id";
						
						if ( !($result = $db->sql_query($sql)) )
						{
							message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
						}
					}
				}
			}
		}

		if ( $mode == 'editprofile' )
		{
			$user_photo = $userdata['user_photo'];
			$user_photo_type = $userdata['user_photo_type'];
		}

		$s_hidden_fields = '';

		$photo_img = '';
		if ( $user_photo_type )
		{
			switch( $user_photo_type )
			{
				case USER_AVATAR_UPLOAD:
					$photo_img = ( $board_config['allow_photo_upload'] ) ? '<img src="' . $board_config['photo_path'] . '/' . $user_photo . '" alt="" />' : '';
					break;
				case USER_AVATAR_REMOTE:
					$photo_img = ( $board_config['allow_photo_remote'] ) ? '<img src="' . $user_photo . '" alt="" />' : '';
					break;
			}
		}

		if ( !empty($user_photo_local) )
		{
			$s_hidden_fields .= '<input type="hidden" name="photolocal" value="' . $user_photo_local . '" />';
		}

		$template->set_filenames(array(
			'photobox' => 'profile_photo_box.tpl')
		);

		//
		// Let's do an overall check for settings/versions which would prevent
		// us from doing file uploads....
		//
		$ini_val = ( phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
		$form_enctype = ( @$ini_val('file_uploads') == '0' || strtolower(@$ini_val('file_uploads') == 'off') || phpversion() == '4.0.4pl1' || !$board_config['allow_photo_upload'] || ( phpversion() < '4.0.3' && @$ini_val('open_basedir') != '' ) ) ? '' : 'enctype="multipart/form-data"';

		$template->assign_vars(array(
			'ALLOW_PHOTO' => $board_config['allow_photo_upload'],
			'PHOTO' => $photo_img,
			'PHOTO_SIZE' => $board_config['photo_filesize'],
				
			'L_PHOTO_PANEL' => $lang['Photo_panel'],
			'L_PHOTO_EXPLAIN' => sprintf($lang['Photo_explain'], $board_config['photo_max_width'], $board_config['photo_max_height'], (round($board_config['photo_filesize'] / 1024))),
			'L_UPLOAD_PHOTO_FILE' => $lang['Upload_photo_file'],
			'L_UPLOAD_PHOTO_URL' => $lang['Upload_photo_url'],
			'L_UPLOAD_PHOTO_URL_EXPLAIN' => $lang['Upload_photo_url_explain'],
			'L_LINK_REMOTE_PHOTO' => $lang['Link_remote_photo'],
			'L_LINK_REMOTE_PHOTO_EXPLAIN' => $lang['Link_remote_photo_explain'],
			'L_DELETE_PHOTO' => $lang['Delete_Image'],
			'L_CURRENT_IMAGE' => $lang['Current_Image'],

			'S_ALLOW_PHOTO_UPLOAD' => $board_config['allow_photo_upload'],
			'S_ALLOW_PHOTO_REMOTE' => $board_config['allow_photo_remote'],
			'S_PHOTO_HIDDEN_FIELDS' => $s_hidden_fields)
		);

		//
		// This is another cheat using the block_var capability
		// of the templates to 'fake' an IF...ELSE...ENDIF solution
		// it works well :)
		//
		if ( $board_config['allow_photo_upload'] || $board_config['allow_photo_remote'] ) 
		{
			$template->assign_block_vars('switch_photo_block', array() );

			if ( $board_config['allow_photo_upload'] && file_exists('./' . $board_config['photo_path']) )
			{
				if ( $form_enctype != '' )
				{
					$template->assign_block_vars('switch_photo_block.switch_photo_local_upload', array() );
				}
				$template->assign_block_vars('switch_photo_block.switch_photo_remote_upload', array() );
			}

			if ( $board_config['allow_photo_remote'] )
			{
				$template->assign_block_vars('switch_photo_block.switch_photo_remote_link', array() );
			}

		}

		$template->assign_var_from_handle('PHOTO_BOX', 'photobox');
	}

	function photo_insert($mode)
	{
		global $error, $error_msg, $HTTP_POST_VARS, $userdata, $board_config, $lang, $user_id, $db;

		if ( ( $mode != 'editprofile' ) && ($this->photo_sql != '') )
		{
			$sql = "UPDATE " . USERS_TABLE . "
				SET " . $this->photo_sql . "
				WHERE user_id = $user_id";

			//
			// WE ARE IN A TRANSACTION HERE
			//
			if (!$result = $db->sql_query($sql))
			{
				message_die(GENERAL_ERROR, "Couldn't insert data into users table", "", __LINE__, __FILE__, $sql);
			}
		}
	}

}

$profilephoto_mod = new profilephoto();

?>
Feel the Force !
windsurf.se
Skriv svar

Vilka är online

Användare som besöker denna kategori: 1 och 0 gäst