diff --git a/includes/theme.inc b/includes/theme.inc
index 4e97888a687..87ed363e6e9 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -242,13 +242,14 @@ function theme_links($links, $delimiter = ' | ') {
* @param $title
* The title text is displayed when the image is hovered in some popular browsers.
* @param $attr
- * Attributes placed in the img tag.
- * This parameter overrides the default auto-detection of width and height.
+ * Attributes placed in the img tag.
+ * @param $getsize
+ * If set to true, the image's dimension are fetched and added as width/height attributes.
* @return
* A string containing the image tag.
*/
-function theme_image($path, $alt = NULL, $title = NULL, $attr = NULL) {
- if (isset($attr) || (file_exists($path) && (list($width, $height, $type, $attr) = getimagesize($path)))) {
+function theme_image($path, $alt = '', $title = '', $attr = '', $getsize = true) {
+ if (!$getsize || (file_exists($path) && (list($width, $height, $type, $attr) = @getimagesize($path)))) {
return "
";
}
}
diff --git a/modules/user.module b/modules/user.module
index a0b678a3bf3..27188ad3948 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -183,7 +183,7 @@ function user_validate_picture($file, &$edit, $user) {
// Check that uploaded file is an image, with a maximum file size
// and maximum height/width.
$extension = strtolower(strrchr($file->filename, '.'));
- $size = getimagesize($file->filepath);
+ $size = @getimagesize($file->filepath);
list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
if ((!in_array($size[2], array(1, 2, 3))) || (!in_array($extension, array('.gif', '.jpg', '.png', '.jpeg')))) {
@@ -196,7 +196,7 @@ function user_validate_picture($file, &$edit, $user) {
form_set_error('picture', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
}
else if ($file = file_save_upload('picture', variable_get('user_picture_path', 'pictures') . FILE_SEPARATOR .'picture-'. $user->uid . $extension, 1)) {
- $edit['picture'] = $file->path;
+ $edit['picture'] = $file->filepath;
}
else {
form_set_error('picture', t("Failed to upload the picture image; the %directory directory doesn't exist.", array('%directory' => ''. variable_get('user_picture_path', 'pictures') .'')));
@@ -352,7 +352,7 @@ function user_perm() {
*/
function user_file_download($file) {
if (strpos($file, variable_get('user_picture_path', 'pictures') . FILE_SEPARATOR . 'picture-') === 0) {
- list($width, $height, $type, $attr) = getimagesize(file_create_path($file));
+ list($width, $height, $type, $attr) = @getimagesize(file_create_path($file));
$types = array(
IMAGETYPE_GIF => 'image/gif',
IMAGETYPE_JPEG => 'image/jpeg',
@@ -547,7 +547,7 @@ function theme_user_picture($account) {
if ($picture) {
$alt = t('%user\'s picture', array('%user' => $account->name ? $account->name : t(variable_get('anonymous', 'Anonymous'))));
- $picture = theme('image', $picture, $alt, $alt);
+ $picture = theme('image', $picture, $alt, $alt, '', false);
if ($account->uid) {
$picture = l($picture, "user/$account->uid", array('title' => t('View user profile.')));
}
@@ -998,8 +998,9 @@ function user_edit_form($uid, $edit) {
// Picture/avatar:
if (variable_get('user_pictures', 0)) {
$group = '';
- if (file_exists($edit['picture'])) {
- $group .= theme('image', file_create_url($edit['picture']));
+ if ($edit['picture'] && ($picture = theme_user_picture(array2object($edit)))) {
+ $group .= $picture;
+ $group .= form_checkbox(t('Delete picture'), 'picture_delete', 1, 0, t('Check this box to delete your current picture.'));
}
$group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
$data[] = array('title' => t('Picture'), 'data' => $group, 'weight' => 1);
@@ -1036,6 +1037,14 @@ function user_edit_validate($uid, &$edit) {
$user = user_load(array('uid' => $uid));
user_validate_picture($file, $edit, $user);
}
+ // Delete picture if requested, and if no replacement picture was given.
+ else if ($edit['picture_delete']) {
+ $user = user_load(array('uid' => $uid));
+ if ($user->picture && file_exists($user->picture)) {
+ file_delete($user->picture);
+ }
+ $edit['picture'] = '';
+ }
// If required, check that proposed passwords match. If so, add the new password to $edit.
if ($edit['pass1']) {
diff --git a/modules/user/user.module b/modules/user/user.module
index a0b678a3bf3..27188ad3948 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -183,7 +183,7 @@ function user_validate_picture($file, &$edit, $user) {
// Check that uploaded file is an image, with a maximum file size
// and maximum height/width.
$extension = strtolower(strrchr($file->filename, '.'));
- $size = getimagesize($file->filepath);
+ $size = @getimagesize($file->filepath);
list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
if ((!in_array($size[2], array(1, 2, 3))) || (!in_array($extension, array('.gif', '.jpg', '.png', '.jpeg')))) {
@@ -196,7 +196,7 @@ function user_validate_picture($file, &$edit, $user) {
form_set_error('picture', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
}
else if ($file = file_save_upload('picture', variable_get('user_picture_path', 'pictures') . FILE_SEPARATOR .'picture-'. $user->uid . $extension, 1)) {
- $edit['picture'] = $file->path;
+ $edit['picture'] = $file->filepath;
}
else {
form_set_error('picture', t("Failed to upload the picture image; the %directory directory doesn't exist.", array('%directory' => ''. variable_get('user_picture_path', 'pictures') .'')));
@@ -352,7 +352,7 @@ function user_perm() {
*/
function user_file_download($file) {
if (strpos($file, variable_get('user_picture_path', 'pictures') . FILE_SEPARATOR . 'picture-') === 0) {
- list($width, $height, $type, $attr) = getimagesize(file_create_path($file));
+ list($width, $height, $type, $attr) = @getimagesize(file_create_path($file));
$types = array(
IMAGETYPE_GIF => 'image/gif',
IMAGETYPE_JPEG => 'image/jpeg',
@@ -547,7 +547,7 @@ function theme_user_picture($account) {
if ($picture) {
$alt = t('%user\'s picture', array('%user' => $account->name ? $account->name : t(variable_get('anonymous', 'Anonymous'))));
- $picture = theme('image', $picture, $alt, $alt);
+ $picture = theme('image', $picture, $alt, $alt, '', false);
if ($account->uid) {
$picture = l($picture, "user/$account->uid", array('title' => t('View user profile.')));
}
@@ -998,8 +998,9 @@ function user_edit_form($uid, $edit) {
// Picture/avatar:
if (variable_get('user_pictures', 0)) {
$group = '';
- if (file_exists($edit['picture'])) {
- $group .= theme('image', file_create_url($edit['picture']));
+ if ($edit['picture'] && ($picture = theme_user_picture(array2object($edit)))) {
+ $group .= $picture;
+ $group .= form_checkbox(t('Delete picture'), 'picture_delete', 1, 0, t('Check this box to delete your current picture.'));
}
$group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
$data[] = array('title' => t('Picture'), 'data' => $group, 'weight' => 1);
@@ -1036,6 +1037,14 @@ function user_edit_validate($uid, &$edit) {
$user = user_load(array('uid' => $uid));
user_validate_picture($file, $edit, $user);
}
+ // Delete picture if requested, and if no replacement picture was given.
+ else if ($edit['picture_delete']) {
+ $user = user_load(array('uid' => $uid));
+ if ($user->picture && file_exists($user->picture)) {
+ file_delete($user->picture);
+ }
+ $edit['picture'] = '';
+ }
// If required, check that proposed passwords match. If so, add the new password to $edit.
if ($edit['pass1']) {