diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 7df2b0a60b..46b5513e1c 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -246,7 +246,7 @@ function avatar_delete() return false; } -function avatar_remote(&$data) +function avatar_remote($data, &$error) { 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'])) { - 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'])) @@ -266,29 +267,32 @@ function avatar_remote(&$data) 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']) { - 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']); + return false; } - $data['width'] = &$width; - $data['height'] = &$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']); + $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_max_width'], $config['avatar_max_height']); + return false; } // Set type - $data['filename'] = &$data['remotelink']; + $data['filename'] = $data['remotelink']; $data['type'] = AVATAR_REMOTE; - return false; + return data; } -function avatar_upload(&$data) +function avatar_upload($data, &$error) { global $config, $db, $user; @@ -306,14 +310,16 @@ function avatar_upload(&$data) } 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)) { if (empty($match[2])) { - return $user->lang['AVATAR_URL_INVALID']; + $error[] = $user->lang['AVATAR_URL_INVALID']; + return false; } $url = parse_url($data['uploadurl']); @@ -328,7 +334,8 @@ function avatar_upload(&$data) 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"); @@ -345,7 +352,8 @@ function avatar_upload(&$data) if (empty($avatar_data)) { - return $user->lang['AVATAR_NOT_UPLOADED']; + $error[] = $user->lang['AVATAR_NOT_UPLOADED']; + return false; } unset($url_ary); @@ -354,7 +362,8 @@ function avatar_upload(&$data) if (!($fp = @fopen($filename, 'wb'))) { - return $user->lang['AVATAR_NOT_UPLOADED'];; + $error[] = $user->lang['AVATAR_NOT_UPLOADED']; + return false; } $filesize = fwrite($fp, $avatar_data); fclose($fp); @@ -363,7 +372,8 @@ function avatar_upload(&$data) if (!$filesize) { unlink($filename); - return $user->lang['AVATAR_NOT_UPLOADED']; + $error[] = $user->lang['AVATAR_NOT_UPLOADED']; + return false; } $php_move = 'copy'; @@ -380,13 +390,14 @@ function avatar_upload(&$data) $bad_chars = array(' ', '/', ':', '*', '?', '"', '<', '>', '|'); $data['filename'] = $user->data['user_id'] . '_' . str_replace($bad_chars, '_', $realname) . '.' . $filetype; - $data['width'] = &$width; - $data['height'] = &$height; + $data['width'] = $width; + $data['height'] = $height; if(!$php_move($filename, $phpbb_root_path . $config['avatar_path'] . '/' . $data['filename'])) { @unlink($filename); - return $user->lang['AVATAR_NOT_UPLOADED']; + $error[] = $user->lang['AVATAR_NOT_UPLOADED']; + return false; } @unlink($filename); @@ -394,13 +405,14 @@ function avatar_upload(&$data) if (!$filesize || $filesize > $config['avatar_filesize']) { @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 $data['type'] = AVATAR_UPLOAD; - return false; + return $data; } // Generates an alphanumeric random string of given length diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 8457b50bda..367c0dd6d5 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -359,7 +359,7 @@ class ucp_profile extends module case 'avatar': // 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) { @@ -376,7 +376,7 @@ class ucp_profile extends module } $var_ary = array( - 'uploadurl' => array('string', false, 5, 255), + 'uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => 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) { - $error = avatar_upload($data); + $data = avatar_upload($data, $error); } 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']) { - $error = avatar_remote($data); + $data = avatar_remote($data, $error); } else if ($delete && $auth->acl_get('u_chgavatar')) { @@ -456,7 +456,7 @@ class ucp_profile extends module } $template->assign_vars(array( - 'ERROR' => ($error) ? $error : '', + 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', 'AVATAR' => $avatar_img, 'AVATAR_SIZE' => $config['avatar_filesize'],