Avatar CP issues ... must finish the gallery (item 28 on my list ...)

git-svn-id: file:///svn/phpbb/trunk@4597 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-10-13 21:24:03 +00:00
parent 88787be77f
commit eedef95186
2 changed files with 39 additions and 27 deletions

View file

@ -246,7 +246,7 @@ function avatar_delete()
return false; return false;
} }
function avatar_remote(&$data) function avatar_remote($data, &$error)
{ {
global $config, $db, $user, $phpbb_root_path; global $config, $db, $user, $phpbb_root_path;
@ -257,7 +257,8 @@ function avatar_remote(&$data)
if (!preg_match('#^(http[s]?)|(ftp)://(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}:?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $data['remotelink'])) if (!preg_match('#^(http[s]?)|(ftp)://(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}:?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $data['remotelink']))
{ {
return $user->lang['AVATAR_URL_INVALID']; $error[] = $user->lang['AVATAR_URL_INVALID'];
return false;
} }
if ((!($data['width'] || $data['height']) || $data['remotelink'] != $user->data['user_avatar']) && ($config['avatar_max_width'] || $config['avatar_max_height'])) if ((!($data['width'] || $data['height']) || $data['remotelink'] != $user->data['user_avatar']) && ($config['avatar_max_width'] || $config['avatar_max_height']))
@ -266,29 +267,32 @@ function avatar_remote(&$data)
if (!$width || !$height) if (!$width || !$height)
{ {
return $user->lang['AVATAR_NO_SIZE']; $error[] = $user->lang['AVATAR_NO_SIZE'];
return false;
} }
else if ($width > $config['avatar_max_width'] || $height > $config['avatar_max_height']) else if ($width > $config['avatar_max_width'] || $height > $config['avatar_max_height'])
{ {
return sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_max_width'], $config['avatar_max_height']); $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_max_width'], $config['avatar_max_height']);
}
$data['width'] = &$width;
$data['height'] = &$height;
}
else if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
{
return sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_max_width'], $config['avatar_max_height']);
}
// Set type
$data['filename'] = &$data['remotelink'];
$data['type'] = AVATAR_REMOTE;
return false; return false;
} }
function avatar_upload(&$data) $data['width'] = $width;
$data['height'] = $height;
}
else if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
{
$error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_max_width'], $config['avatar_max_height']);
return false;
}
// Set type
$data['filename'] = $data['remotelink'];
$data['type'] = AVATAR_REMOTE;
return data;
}
function avatar_upload($data, &$error)
{ {
global $config, $db, $user; global $config, $db, $user;
@ -306,14 +310,16 @@ function avatar_upload(&$data)
} }
else else
{ {
return $user->lang['AVATAR_NOT_UPLOADED']; $error[] = $user->lang['AVATAR_NOT_UPLOADED'];
return false;
} }
} }
else if (preg_match('#^(http://).*?\.(jpg|jpeg|gif|png)$#i', $data['uploadurl'], $match)) else if (preg_match('#^(http://).*?\.(jpg|jpeg|gif|png)$#i', $data['uploadurl'], $match))
{ {
if (empty($match[2])) if (empty($match[2]))
{ {
return $user->lang['AVATAR_URL_INVALID']; $error[] = $user->lang['AVATAR_URL_INVALID'];
return false;
} }
$url = parse_url($data['uploadurl']); $url = parse_url($data['uploadurl']);
@ -328,7 +334,8 @@ function avatar_upload(&$data)
if (!($fsock = @fsockopen($host, $port, $errno, $errstr))) if (!($fsock = @fsockopen($host, $port, $errno, $errstr)))
{ {
return $user->lang['AVATAR_NOT_UPLOADED']; $error[] = $user->lang['AVATAR_NOT_UPLOADED'];
return false;
} }
fputs($fsock, 'GET /' . $filename . " HTTP/1.1\r\n"); fputs($fsock, 'GET /' . $filename . " HTTP/1.1\r\n");
@ -345,7 +352,8 @@ function avatar_upload(&$data)
if (empty($avatar_data)) if (empty($avatar_data))
{ {
return $user->lang['AVATAR_NOT_UPLOADED']; $error[] = $user->lang['AVATAR_NOT_UPLOADED'];
return false;
} }
unset($url_ary); unset($url_ary);
@ -354,7 +362,8 @@ function avatar_upload(&$data)
if (!($fp = @fopen($filename, 'wb'))) if (!($fp = @fopen($filename, 'wb')))
{ {
return $user->lang['AVATAR_NOT_UPLOADED'];; $error[] = $user->lang['AVATAR_NOT_UPLOADED'];
return false;
} }
$filesize = fwrite($fp, $avatar_data); $filesize = fwrite($fp, $avatar_data);
fclose($fp); fclose($fp);
@ -363,7 +372,8 @@ function avatar_upload(&$data)
if (!$filesize) if (!$filesize)
{ {
unlink($filename); unlink($filename);
return $user->lang['AVATAR_NOT_UPLOADED']; $error[] = $user->lang['AVATAR_NOT_UPLOADED'];
return false;
} }
$php_move = 'copy'; $php_move = 'copy';
@ -380,13 +390,14 @@ function avatar_upload(&$data)
$bad_chars = array(' ', '/', ':', '*', '?', '"', '<', '>', '|'); $bad_chars = array(' ', '/', ':', '*', '?', '"', '<', '>', '|');
$data['filename'] = $user->data['user_id'] . '_' . str_replace($bad_chars, '_', $realname) . '.' . $filetype; $data['filename'] = $user->data['user_id'] . '_' . str_replace($bad_chars, '_', $realname) . '.' . $filetype;
$data['width'] = &$width; $data['width'] = $width;
$data['height'] = &$height; $data['height'] = $height;
if(!$php_move($filename, $phpbb_root_path . $config['avatar_path'] . '/' . $data['filename'])) if(!$php_move($filename, $phpbb_root_path . $config['avatar_path'] . '/' . $data['filename']))
{ {
@unlink($filename); @unlink($filename);
return $user->lang['AVATAR_NOT_UPLOADED']; $error[] = $user->lang['AVATAR_NOT_UPLOADED'];
return false;
} }
@unlink($filename); @unlink($filename);
@ -394,13 +405,14 @@ function avatar_upload(&$data)
if (!$filesize || $filesize > $config['avatar_filesize']) if (!$filesize || $filesize > $config['avatar_filesize'])
{ {
@unlink($phpbb_root_path . $config['avatar_path'] . '/' . $data['filename']); @unlink($phpbb_root_path . $config['avatar_path'] . '/' . $data['filename']);
return sprintf($user->lang['AVATAR_WRONG_FILESIZE'], $config['avatar_filesize']); $error[] = sprintf($user->lang['AVATAR_WRONG_FILESIZE'], $config['avatar_filesize']);
return false;
} }
// Set type // Set type
$data['type'] = AVATAR_UPLOAD; $data['type'] = AVATAR_UPLOAD;
return false; return $data;
} }
// Generates an alphanumeric random string of given length // Generates an alphanumeric random string of given length

View file

@ -359,7 +359,7 @@ class ucp_profile extends module
case 'avatar': case 'avatar':
// Can we upload? // Can we upload?
$can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || @ini_get('file_uploads') == 'On')) ? true : false; $can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
if ($submit) if ($submit)
{ {
@ -376,7 +376,7 @@ class ucp_profile extends module
} }
$var_ary = array( $var_ary = array(
'uploadurl' => array('string', false, 5, 255), 'uploadurl' => array('string', true, 5, 255),
'remotelink' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255),
'width' => array('string', true, 1, 3), 'width' => array('string', true, 1, 3),
'height' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3),
@ -388,15 +388,15 @@ class ucp_profile extends module
{ {
if (!empty($_FILES['uploadfile']['tmp_name']) && $can_upload) if (!empty($_FILES['uploadfile']['tmp_name']) && $can_upload)
{ {
$error = avatar_upload($data); $data = avatar_upload($data, $error);
} }
else if ($data['uploadurl'] && $can_upload) else if ($data['uploadurl'] && $can_upload)
{ {
$error = avatar_upload($uploadurl); $data = avatar_upload($data, $error);
} }
else if ($data['remotelink'] && $auth->acl_get('u_chgavatar') && $config['allow_avatar_remote']) else if ($data['remotelink'] && $auth->acl_get('u_chgavatar') && $config['allow_avatar_remote'])
{ {
$error = avatar_remote($data); $data = avatar_remote($data, $error);
} }
else if ($delete && $auth->acl_get('u_chgavatar')) else if ($delete && $auth->acl_get('u_chgavatar'))
{ {
@ -456,7 +456,7 @@ class ucp_profile extends module
} }
$template->assign_vars(array( $template->assign_vars(array(
'ERROR' => ($error) ? $error : '', 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
'AVATAR' => $avatar_img, 'AVATAR' => $avatar_img,
'AVATAR_SIZE' => $config['avatar_filesize'], 'AVATAR_SIZE' => $config['avatar_filesize'],