(file) Return to usercp_avatar.php CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / phpBB2 / includes

  1 rizwank 1.1 <?php
  2             /***************************************************************************
  3              *                             usercp_avatar.php
  4              *                            -------------------
  5              *   begin                : Saturday, Feb 13, 2001
  6              *   copyright            : (C) 2001 The phpBB Group
  7              *   email                : support@phpbb.com
  8              *
  9              *   $Id: usercp_avatar.php,v 1.8.2.16 2002/12/21 19:09:57 psotfx Exp $
 10              *
 11              *
 12              ***************************************************************************/
 13             
 14             /***************************************************************************
 15              *
 16              *   This program is free software; you can redistribute it and/or modify
 17              *   it under the terms of the GNU General Public License as published by
 18              *   the Free Software Foundation; either version 2 of the License, or
 19              *   (at your option) any later version.
 20              *
 21              *
 22 rizwank 1.1  ***************************************************************************/
 23             
 24             function check_image_type(&$type, &$error, &$error_msg)
 25             {
 26             	global $lang;
 27             
 28             	switch( $type )
 29             	{
 30             		case 'jpeg':
 31             		case 'pjpeg':
 32             		case 'jpg':
 33             			return '.jpg';
 34             			break;
 35             		case 'gif':
 36             			return '.gif';
 37             			break;
 38             		case 'png':
 39             			return '.png';
 40             			break;
 41             		default:
 42             			$error = true;
 43 rizwank 1.1 			$error_msg = (!empty($error_msg)) ? $error_msg . '<br />' . $lang['Avatar_filetype'] : $lang['Avatar_filetype'];
 44             			break;
 45             	}
 46             
 47             	return false;
 48             }
 49             
 50             function user_avatar_delete($avatar_type, $avatar_file)
 51             {
 52             	global $board_config, $userdata;
 53             
 54             	if ( $avatar_type == USER_AVATAR_UPLOAD && $avatar_file != '' )
 55             	{
 56             		if ( @file_exists(@phpbb_realpath('./' . $board_config['avatar_path'] . '/' . $avatar_file)) )
 57             		{
 58             			@unlink('./' . $board_config['avatar_path'] . '/' . $avatar_file);
 59             		}
 60             	}
 61             
 62             	return ", user_avatar = '', user_avatar_type = " . USER_AVATAR_NONE;
 63             }
 64 rizwank 1.1 
 65             function user_avatar_gallery($mode, &$error, &$error_msg, $avatar_filename)
 66             {
 67             	global $board_config;
 68             	if ( file_exists(@phpbb_realpath($board_config['avatar_gallery_path'] . '/' . $avatar_filename)) && ($mode == 'editprofile') )
 69             	{
 70             		$return = ", user_avatar = '" . str_replace("\'", "''", $avatar_filename) . "', user_avatar_type = " . USER_AVATAR_GALLERY;
 71             	}
 72             	else
 73             	{
 74             		$return = '';
 75             	}
 76             	return $return;
 77             }
 78             
 79             function user_avatar_url($mode, &$error, &$error_msg, $avatar_filename)
 80             {
 81             	if ( !preg_match('#^(http)|(ftp):\/\/#i', $avatar_filename) )
 82             	{
 83             		$avatar_filename = 'http://' . $avatar_filename;
 84             	}
 85 rizwank 1.1 
 86             	if ( !preg_match('#^((http)|(ftp):\/\/[\w\-]+?\.([\w\-]+\.)+[\w]+(:[0-9]+)*\/.*?\.(gif|jpg|jpeg|png)$)#is', $avatar_filename) )
 87             	{
 88             		$error = true;
 89             		$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Wrong_remote_avatar_format'] : $lang['Wrong_remote_avatar_format'];
 90             		return;
 91             	}
 92             
 93             	return ( $mode == 'editprofile' ) ? ", user_avatar = '" . str_replace("\'", "''", $avatar_filename) . "', user_avatar_type = " . USER_AVATAR_REMOTE : '';
 94             
 95             }
 96             
 97             function user_avatar_upload($mode, $avatar_mode, &$current_avatar, &$current_type, &$error, &$error_msg, $avatar_filename, $avatar_realname, $avatar_filesize, $avatar_filetype)
 98             {
 99             	global $board_config, $db, $lang;
100             
101             	$ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';
102             
103             	if ( $avatar_mode == 'remote' && preg_match('/^(http:\/\/)?([\w\-\.]+)\:?([0-9]*)\/(.*)$/', $avatar_filename, $url_ary) )
104             	{
105             		if ( empty($url_ary[4]) )
106 rizwank 1.1 		{
107             			$error = true;
108             			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Incomplete_URL'] : $lang['Incomplete_URL'];
109             			return;
110             		}
111             
112             		$base_get = '/' . $url_ary[4];
113             		$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;
114             
115             		if ( !($fsock = @fsockopen($url_ary[2], $port, $errno, $errstr)) )
116             		{
117             			$error = true;
118             			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['No_connection_URL'] : $lang['No_connection_URL'];
119             			return;
120             		}
121             
122             		@fputs($fsock, "GET $base_get HTTP/1.1\r\n");
123             		@fputs($fsock, "HOST: " . $url_ary[2] . "\r\n");
124             		@fputs($fsock, "Connection: close\r\n\r\n");
125             
126             		unset($avatar_data);
127 rizwank 1.1 		while( !@feof($fsock) )
128             		{
129             			$avatar_data .= @fread($fsock, $board_config['avatar_filesize']);
130             		}
131             		@fclose($fsock);
132             
133             		if (!preg_match('#Content-Length\: ([0-9]+)[^ /][\s]+#i', $avatar_data, $file_data1) || !preg_match('#Content-Type\: image/[x\-]*([a-z]+)[\s]+#i', $avatar_data, $file_data2))
134             		{
135             			$error = true;
136             			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['File_no_data'] : $lang['File_no_data'];
137             			return;
138             		}
139             
140             		$avatar_filesize = $file_data1[1]; 
141             		$avatar_filetype = $file_data2[1]; 
142             
143             		if ( !$error && $avatar_filesize > 0 && $avatar_filesize < $board_config['avatar_filesize'] )
144             		{
145             			$avatar_data = substr($avatar_data, strlen($avatar_data) - $avatar_filesize, $avatar_filesize);
146             
147             			$tmp_path = ( !@$ini_val('safe_mode') ) ? '/tmp' : './' . $board_config['avatar_path'] . '/tmp';
148 rizwank 1.1 			$tmp_filename = tempnam($tmp_path, uniqid(rand()) . '-');
149             
150             			$fptr = @fopen($tmp_filename, 'wb');
151             			$bytes_written = @fwrite($fptr, $avatar_data, $avatar_filesize);
152             			@fclose($fptr);
153             
154             			if ( $bytes_written != $avatar_filesize )
155             			{
156             				@unlink($tmp_filename);
157             				message_die(GENERAL_ERROR, 'Could not write avatar file to local storage. Please contact the board administrator with this message', '', __LINE__, __FILE__);
158             			}
159             
160             			list($width, $height) = @getimagesize($tmp_filename);
161             		}
162             		else
163             		{
164             			$l_avatar_size = sprintf($lang['Avatar_filesize'], round($board_config['avatar_filesize'] / 1024));
165             
166             			$error = true;
167             			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_avatar_size : $l_avatar_size;
168             		}
169 rizwank 1.1 	}
170             	else if ( ( file_exists(@phpbb_realpath($avatar_filename)) ) && preg_match('/\.(jpg|jpeg|gif|png)$/i', $avatar_realname) )
171             	{
172             		if ( $avatar_filesize <= $board_config['avatar_filesize'] && $avatar_filesize > 0 )
173             		{
174             			preg_match('#image\/[x\-]*([a-z]+)#', $avatar_filetype, $avatar_filetype);
175             			$avatar_filetype = $avatar_filetype[1];
176             		}
177             		else
178             		{
179             			$l_avatar_size = sprintf($lang['Avatar_filesize'], round($board_config['avatar_filesize'] / 1024));
180             
181             			$error = true;
182             			$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_avatar_size : $l_avatar_size;
183             			return;
184             		}
185             
186             		list($width, $height) = @getimagesize($avatar_filename);
187             	}
188             
189             	if ( !($imgtype = check_image_type($avatar_filetype, $error, $error_msg)) )
190 rizwank 1.1 	{
191             		return;
192             	}
193             
194             	if ( $width <= $board_config['avatar_max_width'] && $height <= $board_config['avatar_max_height'] )
195             	{
196             		$new_filename = uniqid(rand()) . $imgtype;
197             
198             		if ( $mode == 'editprofile' && $current_type == USER_AVATAR_UPLOAD && $current_avatar != '' )
199             		{
200             			if ( file_exists(@phpbb_realpath('./' . $board_config['avatar_path'] . '/' . $current_avatar)) )
201             			{
202             				@unlink('./' . $board_config['avatar_path'] . '/' . $current_avatar);
203             			}
204             		}
205             
206             		if( $avatar_mode == 'remote' )
207             		{
208             			@copy($tmp_filename, './' . $board_config['avatar_path'] . "/$new_filename");
209             			@unlink($tmp_filename);
210             		}
211 rizwank 1.1 		else
212             		{
213             			if ( @$ini_val('open_basedir') != '' )
214             			{
215             				if ( @phpversion() < '4.0.3' )
216             				{
217             					message_die(GENERAL_ERROR, 'open_basedir is set and your PHP version does not allow move_uploaded_file', '', __LINE__, __FILE__);
218             				}
219             
220             				$move_file = 'move_uploaded_file';
221             			}
222             			else
223             			{
224             				$move_file = 'copy';
225             			}
226             
227             			$move_file($avatar_filename, './' . $board_config['avatar_path'] . "/$new_filename");
228             		}
229             
230             		@chmod('./' . $board_config['avatar_path'] . "/$new_filename", 0777);
231             
232 rizwank 1.1 		$avatar_sql = ( $mode == 'editprofile' ) ? ", user_avatar = '$new_filename', user_avatar_type = " . USER_AVATAR_UPLOAD : "'$new_filename', " . USER_AVATAR_UPLOAD;
233             	}
234             	else
235             	{
236             		$l_avatar_size = sprintf($lang['Avatar_imagesize'], $board_config['avatar_max_width'], $board_config['avatar_max_height']);
237             
238             		$error = true;
239             		$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_avatar_size : $l_avatar_size;
240             	}
241             
242             	return $avatar_sql;
243             }
244             
245             function display_avatar_gallery($mode, &$category, &$user_id, &$email, &$current_email, &$coppa, &$username, &$email, &$new_password, &$cur_password, &$password_confirm, &$icq, &$aim, &$msn, &$yim, &$website, &$location, &$occupation, &$interests, &$signature, &$viewemail, &$notifypm, &$popuppm, &$notifyreply, &$attachsig, &$allowhtml, &$allowbbcode, &$allowsmilies, &$hideonline, &$style, &$language, &$timezone, &$dateformat, &$session_id)
246             {
247             	global $board_config, $db, $template, $lang, $images, $theme;
248             	global $phpbb_root_path, $phpEx;
249             
250             	$dir = @opendir($board_config['avatar_gallery_path']);
251             
252             	$avatar_images = array();
253 rizwank 1.1 	while( $file = @readdir($dir) )
254             	{
255             		if( $file != '.' && $file != '..' && !is_file($board_config['avatar_gallery_path'] . '/' . $file) && !is_link($board_config['avatar_gallery_path'] . '/' . $file) )
256             		{
257             			$sub_dir = @opendir($board_config['avatar_gallery_path'] . '/' . $file);
258             
259             			$avatar_row_count = 0;
260             			$avatar_col_count = 0;
261             			while( $sub_file = @readdir($sub_dir) )
262             			{
263             				if( preg_match('/(\.gif$|\.png$|\.jpg|\.jpeg)$/is', $sub_file) )
264             				{
265             					$avatar_images[$file][$avatar_row_count][$avatar_col_count] = $file . '/' . $sub_file; 
266             					$avatar_name[$file][$avatar_row_count][$avatar_col_count] = ucfirst(str_replace("_", " ", preg_replace('/^(.*)\..*$/', '\1', $sub_file)));
267             
268             					$avatar_col_count++;
269             					if( $avatar_col_count == 5 )
270             					{
271             						$avatar_row_count++;
272             						$avatar_col_count = 0;
273             					}
274 rizwank 1.1 				}
275             			}
276             		}
277             	}
278             
279             	@closedir($dir);
280             
281             	@ksort($avatar_images);
282             	@reset($avatar_images);
283             
284             	if( empty($category) )
285             	{
286             		list($category, ) = each($avatar_images);
287             	}
288             	@reset($avatar_images);
289             
290             	$s_categories = '<select name="avatarcategory">';
291             	while( list($key) = each($avatar_images) )
292             	{
293             		$selected = ( $key == $category ) ? ' selected="selected"' : '';
294             		if( count($avatar_images[$key]) )
295 rizwank 1.1 		{
296             			$s_categories .= '<option value="' . $key . '"' . $selected . '>' . ucfirst($key) . '</option>';
297             		}
298             	}
299             	$s_categories .= '</select>';
300             
301             	$s_colspan = 0;
302             	for($i = 0; $i < count($avatar_images[$category]); $i++)
303             	{
304             		$template->assign_block_vars("avatar_row", array());
305             
306             		$s_colspan = max($s_colspan, count($avatar_images[$category][$i]));
307             
308             		for($j = 0; $j < count($avatar_images[$category][$i]); $j++)
309             		{
310             			$template->assign_block_vars('avatar_row.avatar_column', array(
311             				"AVATAR_IMAGE" => $board_config['avatar_gallery_path'] . '/' . $avatar_images[$category][$i][$j], 
312             				"AVATAR_NAME" => $avatar_name[$category][$i][$j])
313             			);
314             
315             			$template->assign_block_vars('avatar_row.avatar_option_column', array(
316 rizwank 1.1 				"S_OPTIONS_AVATAR" => $avatar_images[$category][$i][$j])
317             			);
318             		}
319             	}
320             
321             	$params = array('coppa', 'user_id', 'username', 'email', 'current_email', 'cur_password', 'new_password', 'password_confirm', 'icq', 'aim', 'msn', 'yim', 'website', 'location', 'occupation', 'interests', 'signature', 'viewemail', 'notifypm', 'popuppm', 'notifyreply', 'attachsig', 'allowhtml', 'allowbbcode', 'allowsmilies', 'hideonline', 'style', 'language', 'timezone', 'dateformat');
322             
323             	$s_hidden_vars = '<input type="hidden" name="sid" value="' . $session_id . '" /><input type="hidden" name="agreed" value="true" />';
324             
325             	for($i = 0; $i < count($params); $i++)
326             	{
327             		$s_hidden_vars .= '<input type="hidden" name="' . $params[$i] . '" value="' . str_replace('"', '&quot;', $$params[$i]) . '" />';
328             	}
329             	
330             	$template->assign_vars(array(
331             		'L_AVATAR_GALLERY' => $lang['Avatar_gallery'], 
332             		'L_SELECT_AVATAR' => $lang['Select_avatar'], 
333             		'L_RETURN_PROFILE' => $lang['Return_profile'], 
334             		'L_CATEGORY' => $lang['Select_category'], 
335             
336             		'S_CATEGORY_SELECT' => $s_categories, 
337 rizwank 1.1 		'S_COLSPAN' => $s_colspan, 
338             		'S_PROFILE_ACTION' => append_sid("profile.$phpEx?mode=$mode"), 
339             		'S_HIDDEN_FIELDS' => $s_hidden_vars)
340             	);
341             
342             	return;
343             }
344             
345             ?>

Rizwan Kassim
Powered by
ViewCVS 0.9.2