X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Favatarsettings.php;h=52dc2e42496aa1b8c27ef47bc232b76a6dcf279d;hb=3dd734b2c3ea49c55467cfbfd4b3a5fb38456e87;hp=54baef88fb34263bf4eae4110b283dd8da56d3cc;hpb=be5d113fc684fcbe41b8374c62bfeb0f267216b7;p=quix0rs-gnu-social.git diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php index 54baef88fb..52dc2e4249 100644 --- a/actions/avatarsettings.php +++ b/actions/avatarsettings.php @@ -28,7 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } @@ -103,7 +103,7 @@ class AvatarsettingsAction extends AccountSettingsAction if (!$profile) { common_log_db_error($user, 'SELECT', __FILE__); - $this->serverError(_('User without matching profile')); + $this->serverError(_('User without matching profile.')); return; } @@ -118,53 +118,56 @@ class AvatarsettingsAction extends AccountSettingsAction $this->elementStart('fieldset'); $this->element('legend', null, _('Avatar settings')); $this->hidden('token', common_session_token()); - - $this->elementStart('ul', 'form_data'); - if ($original) { - $this->elementStart('li', array('id' => 'avatar_original', - 'class' => 'avatar_view')); - $this->element('h2', null, _("Original")); - $this->elementStart('div', array('id'=>'avatar_original_view')); - $this->element('img', array('src' => $original->url, - 'width' => $original->width, - 'height' => $original->height, - 'alt' => $user->nickname)); - $this->elementEnd('div'); + + if (Event::handle('StartAvatarFormData', array($this))) { + $this->elementStart('ul', 'form_data'); + if ($original) { + $this->elementStart('li', array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Original")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => $original->url, + 'width' => $original->width, + 'height' => $original->height, + 'alt' => $user->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + } + + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); + + if ($avatar) { + $this->elementStart('li', array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Preview")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => $original->url, + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $user->nickname)); + $this->elementEnd('div'); + $this->submit('delete', _('Delete')); + $this->elementEnd('li'); + } + + $this->elementStart('li', array ('id' => 'settings_attach')); + $this->element('input', array('name' => 'avatarfile', + 'type' => 'file', + 'id' => 'avatarfile')); + $this->element('input', array('name' => 'MAX_FILE_SIZE', + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => ImageFile::maxFileSizeInt())); $this->elementEnd('li'); - } - - $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); + $this->elementEnd('ul'); - if ($avatar) { - $this->elementStart('li', array('id' => 'avatar_preview', - 'class' => 'avatar_view')); - $this->element('h2', null, _("Preview")); - $this->elementStart('div', array('id'=>'avatar_preview_view')); - $this->element('img', array('src' => $original->url, - 'width' => AVATAR_PROFILE_SIZE, - 'height' => AVATAR_PROFILE_SIZE, - 'alt' => $user->nickname)); - $this->elementEnd('div'); - $this->submit('delete', _('Delete')); + $this->elementStart('ul', 'form_actions'); + $this->elementStart('li'); + $this->submit('upload', _('Upload')); $this->elementEnd('li'); + $this->elementEnd('ul'); } - - $this->elementStart('li', array ('id' => 'settings_attach')); - $this->element('input', array('name' => 'avatarfile', - 'type' => 'file', - 'id' => 'avatarfile')); - $this->element('input', array('name' => 'MAX_FILE_SIZE', - 'type' => 'hidden', - 'id' => 'MAX_FILE_SIZE', - 'value' => ImageFile::maxFileSizeInt())); - $this->elementEnd('li'); - $this->elementEnd('ul'); - - $this->elementStart('ul', 'form_actions'); - $this->elementStart('li'); - $this->submit('upload', _('Upload')); - $this->elementEnd('li'); - $this->elementEnd('ul'); + Event::handle('EndAvatarFormData', array($this)); $this->elementEnd('fieldset'); $this->elementEnd('form'); @@ -179,7 +182,7 @@ class AvatarsettingsAction extends AccountSettingsAction if (!$profile) { common_log_db_error($user, 'SELECT', __FILE__); - $this->serverError(_('User without matching profile')); + $this->serverError(_('User without matching profile.')); return; } @@ -244,23 +247,40 @@ class AvatarsettingsAction extends AccountSettingsAction function handlePost() { + // Workaround for PHP returning empty $_POST and $_FILES when POST + // length > post_max_size in php.ini + + if (empty($_FILES) + && empty($_POST) + && ($_SERVER['CONTENT_LENGTH'] > 0) + ) { + $msg = _('The server was unable to handle that much POST ' . + 'data (%s bytes) due to its current configuration.'); + + $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); + return; + } + // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { - $this->show_form(_('There was a problem with your session token. '. + $this->showForm(_('There was a problem with your session token. '. 'Try again, please.')); return; } - - if ($this->arg('upload')) { - $this->uploadAvatar(); - } else if ($this->arg('crop')) { - $this->cropAvatar(); - } else if ($this->arg('delete')) { - $this->deleteAvatar(); - } else { - $this->showForm(_('Unexpected form submission.')); + + if (Event::handle('StartAvatarSaveForm', array($this))) { + if ($this->arg('upload')) { + $this->uploadAvatar(); + } else if ($this->arg('crop')) { + $this->cropAvatar(); + } else if ($this->arg('delete')) { + $this->deleteAvatar(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + Event::handle('EndAvatarSaveForm', array($this)); } } @@ -281,6 +301,10 @@ class AvatarsettingsAction extends AccountSettingsAction $this->showForm($e->getMessage()); return; } + if ($imagefile === null) { + $this->showForm(_('No file uploaded.')); + return; + } $cur = common_current_user(); @@ -362,13 +386,13 @@ class AvatarsettingsAction extends AccountSettingsAction $profile = $user->getProfile(); $avatar = $profile->getOriginalAvatar(); - $avatar->delete(); + if($avatar) $avatar->delete(); $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); - $avatar->delete(); + if($avatar) $avatar->delete(); $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); - $avatar->delete(); + if($avatar) $avatar->delete(); $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); - $avatar->delete(); + if($avatar) $avatar->delete(); $this->showForm(_('Avatar deleted.'), true); } @@ -396,8 +420,10 @@ class AvatarsettingsAction extends AccountSettingsAction parent::showScripts(); if ($this->mode == 'crop') { - $this->script('js/jcrop/jquery.Jcrop.min.js'); - $this->script('js/jcrop/jquery.Jcrop.go.js'); + $this->script('jcrop/jquery.Jcrop.min.js'); + $this->script('jcrop/jquery.Jcrop.go.js'); } + + $this->autofocus('avatarfile'); } }