2009-01-16 22:29:13 +00:00
|
|
|
<?php
|
2020-06-20 13:49:37 +01:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-01-16 22:29:13 +00:00
|
|
|
/**
|
|
|
|
* Upload an avatar
|
|
|
|
*
|
|
|
|
* @category Settings
|
2020-06-20 13:49:37 +01:00
|
|
|
* @package GNUsocial
|
|
|
|
*
|
2009-08-25 23:19:04 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Zach Copley <zach@status.net>
|
2020-06-20 13:49:37 +01:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
* @copyright 2008-2009, 2020 Free Software Foundation http://fsf.org
|
2009-01-16 22:29:13 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
defined('GNUSOCIAL') || die;
|
2009-02-05 00:32:15 +00:00
|
|
|
|
2009-01-16 22:29:13 +00:00
|
|
|
/**
|
|
|
|
* Upload an avatar
|
|
|
|
*
|
2009-01-21 20:33:37 +00:00
|
|
|
* We use jCrop plugin for jQuery to crop the image after upload.
|
2009-01-16 22:29:13 +00:00
|
|
|
*
|
|
|
|
* @category Settings
|
2009-08-25 23:12:20 +01:00
|
|
|
* @package StatusNet
|
2020-06-20 13:49:37 +01:00
|
|
|
*
|
2009-08-25 23:19:04 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @author Sarven Capadisli <csarven@status.net>
|
2009-01-16 22:29:13 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2020-06-20 13:49:37 +01:00
|
|
|
*
|
|
|
|
* @see http://status.net/
|
2009-01-16 22:29:13 +00:00
|
|
|
*/
|
2011-01-23 17:35:35 +00:00
|
|
|
class AvatarsettingsAction extends SettingsAction
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
2020-06-20 13:49:37 +01:00
|
|
|
public $mode;
|
|
|
|
public $imagefile;
|
|
|
|
public $filename;
|
2009-01-23 05:16:55 +00:00
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
public function prepare(array $args = [])
|
2016-06-04 15:52:49 +01:00
|
|
|
{
|
|
|
|
$avatarpath = Avatar::path('');
|
|
|
|
|
|
|
|
if (!is_writable($avatarpath)) {
|
2020-06-20 13:49:37 +01:00
|
|
|
throw new Exception(_m("The administrator of your site needs to
|
2016-06-04 15:52:49 +01:00
|
|
|
add write permissions on the avatar upload folder before
|
|
|
|
you're able to set one."));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::prepare($args);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-16 22:29:13 +00:00
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
2020-06-20 13:49:37 +01:00
|
|
|
* @throws Exception
|
|
|
|
*
|
2009-01-16 22:29:13 +00:00
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
public function title()
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Title for avatar upload page.
|
2020-06-20 13:49:37 +01:00
|
|
|
return _m('Avatar');
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
2020-06-20 13:49:37 +01:00
|
|
|
* @return string instructions for use
|
|
|
|
* @throws Exception
|
|
|
|
*
|
2009-01-16 22:29:13 +00:00
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
public function getInstructions()
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Instruction for avatar upload page.
|
|
|
|
// TRANS: %s is the maximum file size, for example "500b", "10kB" or "2MB".
|
2020-06-20 13:49:37 +01:00
|
|
|
return sprintf(
|
|
|
|
_m('You can upload your personal avatar. The maximum file size is %s.'),
|
|
|
|
ImageFile::maxFileSize()
|
|
|
|
);
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content area of the page
|
|
|
|
*
|
2015-07-16 18:21:12 +01:00
|
|
|
* Shows a form for uploading an avatar. Currently overrides FormAction's showContent
|
|
|
|
* since we haven't made classes out of AvatarCropForm and AvatarUploadForm.
|
2009-01-16 22:29:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
public function showContent()
|
2009-01-23 05:16:55 +00:00
|
|
|
{
|
|
|
|
if ($this->mode == 'crop') {
|
|
|
|
$this->showCropForm();
|
|
|
|
} else {
|
|
|
|
$this->showUploadForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
public function showUploadForm()
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->elementStart('form', ['enctype' => 'multipart/form-data',
|
|
|
|
'method' => 'post',
|
|
|
|
'id' => 'form_settings_avatar',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' => common_local_url('avatarsettings'),]);
|
2009-01-21 20:33:37 +00:00
|
|
|
$this->elementStart('fieldset');
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Avatar upload page form legend.
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->element('legend', null, _m('Avatar settings'));
|
2009-01-16 22:29:13 +00:00
|
|
|
$this->hidden('token', common_session_token());
|
2010-10-30 23:58:35 +01:00
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
if (Event::handle('StartAvatarFormData', [$this])) {
|
2009-12-10 03:31:07 +00:00
|
|
|
$this->elementStart('ul', 'form_data');
|
2013-09-30 21:13:37 +01:00
|
|
|
try {
|
2016-03-05 00:03:48 +00:00
|
|
|
$original = Avatar::getUploaded($this->scoped);
|
2013-09-30 21:13:37 +01:00
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->elementStart('li', ['id' => 'avatar_original',
|
|
|
|
'class' => 'avatar_view',]);
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Header on avatar upload page for thumbnail of originally uploaded avatar (h2).
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->element('h2', null, _m('Original'));
|
|
|
|
$this->elementStart('div', ['id' => 'avatar_original_view']);
|
|
|
|
$this->element('img', ['src' => $original->displayUrl(),
|
|
|
|
'width' => $original->width,
|
|
|
|
'height' => $original->height,
|
|
|
|
'alt' => $this->scoped->getNickname(),]);
|
2009-12-10 03:31:07 +00:00
|
|
|
$this->elementEnd('div');
|
|
|
|
$this->elementEnd('li');
|
2013-10-06 14:54:06 +01:00
|
|
|
} catch (NoAvatarException $e) {
|
2013-09-30 21:13:37 +01:00
|
|
|
// No original avatar found!
|
2009-12-10 03:31:07 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 10:37:59 +01:00
|
|
|
try {
|
2016-03-05 00:03:48 +00:00
|
|
|
$avatar = $this->scoped->getAvatar(AVATAR_PROFILE_SIZE);
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->elementStart('li', ['id' => 'avatar_preview',
|
|
|
|
'class' => 'avatar_view',]);
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Header on avatar upload page for thumbnail of to be used rendition of uploaded avatar (h2).
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->element('h2', null, _m('Preview'));
|
|
|
|
$this->elementStart('div', ['id' => 'avatar_preview_view']);
|
|
|
|
$this->element('img', ['src' => $avatar->displayUrl(),
|
|
|
|
'width' => AVATAR_PROFILE_SIZE,
|
|
|
|
'height' => AVATAR_PROFILE_SIZE,
|
|
|
|
'alt' => $this->scoped->getNickname(),]);
|
2009-12-10 03:31:07 +00:00
|
|
|
$this->elementEnd('div');
|
2011-04-14 16:47:55 +01:00
|
|
|
if (!empty($avatar->filename)) {
|
|
|
|
// TRANS: Button on avatar upload page to delete current avatar.
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->submit('delete', _m('BUTTON', 'Delete'));
|
2011-04-14 16:47:55 +01:00
|
|
|
}
|
2009-12-10 03:31:07 +00:00
|
|
|
$this->elementEnd('li');
|
2013-10-06 14:54:06 +01:00
|
|
|
} catch (NoAvatarException $e) {
|
2013-10-01 10:37:59 +01:00
|
|
|
// No previously uploaded avatar to preview.
|
2009-12-10 03:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->elementStart('li', ['id' => 'settings_attach']);
|
|
|
|
$this->element('input', ['name' => 'MAX_FILE_SIZE',
|
|
|
|
'type' => 'hidden',
|
|
|
|
'id' => 'MAX_FILE_SIZE',
|
|
|
|
'value' => ImageFile::maxFileSizeInt(),]);
|
|
|
|
$this->element('input', ['name' => 'avatarfile',
|
|
|
|
'type' => 'file',
|
|
|
|
'id' => 'avatarfile',]);
|
2009-01-21 20:33:37 +00:00
|
|
|
$this->elementEnd('li');
|
2009-12-10 03:31:07 +00:00
|
|
|
$this->elementEnd('ul');
|
2009-01-16 22:29:13 +00:00
|
|
|
|
2009-12-10 03:31:07 +00:00
|
|
|
$this->elementStart('ul', 'form_actions');
|
|
|
|
$this->elementStart('li');
|
2020-06-20 13:49:37 +01:00
|
|
|
// TRANS: Button on avatar upload page to upload an avatar.
|
|
|
|
$this->submit('upload', _m('BUTTON', 'Upload'));
|
2009-01-23 06:14:56 +00:00
|
|
|
$this->elementEnd('li');
|
2009-12-10 03:31:07 +00:00
|
|
|
$this->elementEnd('ul');
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
2020-06-20 13:49:37 +01:00
|
|
|
Event::handle('EndAvatarFormData', [$this]);
|
2009-01-21 20:33:37 +00:00
|
|
|
|
|
|
|
$this->elementEnd('fieldset');
|
2009-01-16 22:29:13 +00:00
|
|
|
$this->elementEnd('form');
|
|
|
|
}
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
public function showCropForm()
|
2009-01-23 05:16:55 +00:00
|
|
|
{
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->elementStart('form', ['method' => 'post',
|
|
|
|
'id' => 'form_settings_avatar',
|
|
|
|
'class' => 'form_settings',
|
|
|
|
'action' => common_local_url('avatarsettings'),]);
|
2009-01-23 05:16:55 +00:00
|
|
|
$this->elementStart('fieldset');
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Avatar upload page crop form legend.
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->element('legend', null, _m('Avatar settings'));
|
2009-01-23 05:16:55 +00:00
|
|
|
$this->hidden('token', common_session_token());
|
|
|
|
|
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->elementStart(
|
|
|
|
'li',
|
|
|
|
['id' => 'avatar_original',
|
|
|
|
'class' => 'avatar_view',]
|
|
|
|
);
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Header on avatar upload crop form for thumbnail of originally uploaded avatar (h2).
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->element('h2', null, _m('Original'));
|
|
|
|
$this->elementStart('div', ['id' => 'avatar_original_view']);
|
|
|
|
$this->element('img', ['src' => Avatar::url($this->filedata['filename']),
|
|
|
|
'width' => $this->filedata['width'],
|
|
|
|
'height' => $this->filedata['height'],
|
|
|
|
'alt' => $this->scoped->getNickname(),]);
|
2009-01-23 05:16:55 +00:00
|
|
|
$this->elementEnd('div');
|
|
|
|
$this->elementEnd('li');
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->elementStart(
|
|
|
|
'li',
|
|
|
|
['id' => 'avatar_preview',
|
|
|
|
'class' => 'avatar_view',]
|
|
|
|
);
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Header on avatar upload crop form for thumbnail of to be used rendition of uploaded avatar (h2).
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->element('h2', null, _m('Preview'));
|
|
|
|
$this->elementStart('div', ['id' => 'avatar_preview_view']);
|
|
|
|
$this->element('img', ['src' => Avatar::url($this->filedata['filename']),
|
|
|
|
'width' => AVATAR_PROFILE_SIZE,
|
|
|
|
'height' => AVATAR_PROFILE_SIZE,
|
|
|
|
'alt' => $this->scoped->getNickname(),]);
|
2009-01-23 05:16:55 +00:00
|
|
|
$this->elementEnd('div');
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
foreach (['avatar_crop_x', 'avatar_crop_y',
|
|
|
|
'avatar_crop_w', 'avatar_crop_h',] as $crop_info) {
|
|
|
|
$this->element('input', ['name' => $crop_info,
|
|
|
|
'type' => 'hidden',
|
|
|
|
'id' => $crop_info,]);
|
2009-01-23 05:16:55 +00:00
|
|
|
}
|
2010-10-30 23:58:35 +01:00
|
|
|
|
|
|
|
// TRANS: Button on avatar upload crop form to confirm a selected crop as avatar.
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->submit('crop', _m('BUTTON', 'Crop'));
|
2009-01-23 05:16:55 +00:00
|
|
|
|
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementEnd('ul');
|
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
$this->elementEnd('form');
|
|
|
|
}
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @throws NoResultException
|
|
|
|
* @throws NoUploadedMediaException
|
|
|
|
* @throws ServerException
|
|
|
|
* @throws UnsupportedMediaException
|
|
|
|
* @throws UseFileAsThumbnailException
|
|
|
|
* @throws Exception
|
|
|
|
*
|
|
|
|
* @throws ClientException
|
|
|
|
*/
|
2015-07-16 18:21:12 +01:00
|
|
|
protected function doPost()
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
2020-06-20 13:49:37 +01:00
|
|
|
if (Event::handle('StartAvatarSaveForm', [$this])) {
|
2015-07-16 18:21:12 +01:00
|
|
|
if ($this->trimmed('upload')) {
|
|
|
|
return $this->uploadAvatar();
|
2020-06-20 13:49:37 +01:00
|
|
|
} elseif ($this->trimmed('crop')) {
|
2015-07-16 18:21:12 +01:00
|
|
|
return $this->cropAvatar();
|
2020-06-20 13:49:37 +01:00
|
|
|
} elseif ($this->trimmed('delete')) {
|
2015-07-16 18:21:12 +01:00
|
|
|
return $this->deleteAvatar();
|
|
|
|
} else {
|
|
|
|
// TRANS: Unexpected validation error on avatar upload form.
|
2020-06-20 13:49:37 +01:00
|
|
|
throw new ClientException(_m('Unexpected form submission.'));
|
2015-07-16 18:21:12 +01:00
|
|
|
}
|
2020-06-20 13:49:37 +01:00
|
|
|
Event::handle('EndAvatarSaveForm', [$this]);
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an image upload
|
|
|
|
*
|
|
|
|
* Does all the magic for handling an image upload, and crops the
|
|
|
|
* image by default.
|
|
|
|
*
|
2020-06-20 13:49:37 +01:00
|
|
|
* @return string
|
|
|
|
* @throws NoResultException
|
|
|
|
* @throws NoUploadedMediaException
|
|
|
|
* @throws ServerException
|
|
|
|
* @throws UnsupportedMediaException
|
|
|
|
* @throws UseFileAsThumbnailException
|
|
|
|
*
|
|
|
|
* @throws ClientException
|
2009-01-16 22:29:13 +00:00
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
public function uploadAvatar(): string
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
2015-07-16 18:21:12 +01:00
|
|
|
// ImageFile throws exception if something goes wrong, which we'll
|
|
|
|
// pick up and show as an error message above the form.
|
|
|
|
$imagefile = ImageFile::fromUpload('avatarfile');
|
2009-01-16 22:29:13 +00:00
|
|
|
|
2011-01-24 20:22:47 +00:00
|
|
|
$type = $imagefile->preferredType();
|
2020-06-20 13:49:37 +01:00
|
|
|
$filename = Avatar::filename(
|
|
|
|
$this->scoped->getID(),
|
|
|
|
image_type_to_extension($type),
|
|
|
|
null,
|
|
|
|
'tmp' . common_timestamp()
|
|
|
|
);
|
2009-01-16 22:29:13 +00:00
|
|
|
|
2009-02-06 08:13:08 +00:00
|
|
|
$filepath = Avatar::path($filename);
|
2014-06-17 10:50:42 +01:00
|
|
|
$imagefile = $imagefile->copyTo($filepath);
|
2009-01-23 05:16:55 +00:00
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$filedata = [
|
|
|
|
'filename' => $filename,
|
|
|
|
'filepath' => $filepath,
|
|
|
|
'width' => $imagefile->width,
|
|
|
|
'height' => $imagefile->height,
|
|
|
|
'type' => $type,
|
|
|
|
];
|
2009-01-23 05:16:55 +00:00
|
|
|
|
|
|
|
$_SESSION['FILEDATA'] = $filedata;
|
|
|
|
|
|
|
|
$this->filedata = $filedata;
|
|
|
|
|
|
|
|
$this->mode = 'crop';
|
|
|
|
|
2011-02-16 23:39:53 +00:00
|
|
|
// TRANS: Avatar upload form instruction after uploading a file.
|
2020-06-20 13:49:37 +01:00
|
|
|
return _m('Pick a square area of the image to be your avatar.');
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the results of jcrop.
|
|
|
|
*
|
2020-06-20 13:49:37 +01:00
|
|
|
* @return string
|
|
|
|
* @throws NoResultException
|
|
|
|
* @throws ServerException
|
|
|
|
* @throws UnsupportedMediaException
|
|
|
|
*
|
|
|
|
* @throws ClientException
|
2009-01-16 22:29:13 +00:00
|
|
|
*/
|
2013-10-01 10:37:59 +01:00
|
|
|
public function cropAvatar()
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
2009-01-23 05:16:55 +00:00
|
|
|
$filedata = $_SESSION['FILEDATA'];
|
|
|
|
|
2015-07-16 18:21:12 +01:00
|
|
|
if (empty($filedata)) {
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Server error displayed if an avatar upload went wrong somehow server side.
|
2020-06-20 13:49:37 +01:00
|
|
|
throw new ServerException(_m('Lost our file data.'));
|
2009-01-23 05:16:55 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$file_d = min($filedata['width'], $filedata['height']);
|
2009-03-04 05:11:18 +00:00
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x') : 0;
|
|
|
|
$dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y') : 0;
|
|
|
|
$dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w') : $file_d;
|
|
|
|
$dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $file_d;
|
|
|
|
$size = (int)(min($dest_w, $dest_h, common_config('avatar', 'maxsize')));
|
2015-03-12 19:47:07 +00:00
|
|
|
|
2020-06-20 13:49:37 +01:00
|
|
|
$box = ['width' => $size, 'height' => $size,
|
|
|
|
'x' => $dest_x, 'y' => $dest_y,
|
|
|
|
'w' => $dest_w, 'h' => $dest_h,];
|
2009-01-23 05:16:55 +00:00
|
|
|
|
2015-03-10 23:20:48 +00:00
|
|
|
$imagefile = new ImageFile(null, $filedata['filepath']);
|
2020-06-20 13:49:37 +01:00
|
|
|
$filename = Avatar::filename(
|
|
|
|
$this->scoped->getID(),
|
|
|
|
image_type_to_extension($imagefile->preferredType()),
|
|
|
|
$size,
|
|
|
|
common_timestamp()
|
|
|
|
);
|
2015-03-12 19:47:07 +00:00
|
|
|
try {
|
|
|
|
$imagefile->resizeTo(Avatar::path($filename), $box);
|
|
|
|
} catch (UseFileAsThumbnailException $e) {
|
2020-06-20 13:49:37 +01:00
|
|
|
common_debug('Using uploaded avatar directly without resizing, copying it to: ' . $filename);
|
2015-03-12 19:47:07 +00:00
|
|
|
if (!copy($filedata['filepath'], Avatar::path($filename))) {
|
2020-06-20 13:49:37 +01:00
|
|
|
common_debug('Tried to copy image file ' . $filedata['filepath'] . ' to destination ' . Avatar::path($filename));
|
2015-03-12 19:47:07 +00:00
|
|
|
throw new ServerException('Could not copy file to destination.');
|
|
|
|
}
|
|
|
|
}
|
2009-01-23 05:16:55 +00:00
|
|
|
|
2015-07-16 18:21:12 +01:00
|
|
|
if ($this->scoped->setOriginal($filename)) {
|
2009-02-05 00:32:15 +00:00
|
|
|
@unlink($filedata['filepath']);
|
2009-01-23 05:16:55 +00:00
|
|
|
unset($_SESSION['FILEDATA']);
|
|
|
|
$this->mode = 'upload';
|
2010-10-31 00:26:39 +01:00
|
|
|
// TRANS: Success message for having updated a user avatar.
|
2020-06-20 13:49:37 +01:00
|
|
|
return _m('Avatar updated.');
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
2015-07-16 18:21:12 +01:00
|
|
|
|
|
|
|
// TRANS: Error displayed on the avatar upload page if the avatar could not be updated for an unknown reason.
|
2020-06-20 13:49:37 +01:00
|
|
|
throw new ServerException(_m('Failed updating avatar.'));
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
2010-10-30 23:58:35 +01:00
|
|
|
|
2009-02-10 01:17:56 +00:00
|
|
|
/**
|
|
|
|
* Get rid of the current avatar.
|
|
|
|
*
|
2020-06-20 13:49:37 +01:00
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
|
|
|
*
|
2009-02-10 01:17:56 +00:00
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
public function deleteAvatar()
|
2009-02-10 01:17:56 +00:00
|
|
|
{
|
2015-07-16 18:21:12 +01:00
|
|
|
Avatar::deleteFromProfile($this->scoped);
|
2009-02-10 01:17:56 +00:00
|
|
|
|
2010-10-30 23:58:35 +01:00
|
|
|
// TRANS: Success message for deleting a user avatar.
|
2020-06-20 13:49:37 +01:00
|
|
|
return _m('Avatar deleted.');
|
2009-02-10 01:17:56 +00:00
|
|
|
}
|
2009-01-16 22:29:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the jCrop stylesheet
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
public function showStylesheets()
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
|
|
|
parent::showStylesheets();
|
2020-06-20 13:49:37 +01:00
|
|
|
$this->cssLink('js/extlib/jquery-jcrop/css/jcrop.css', 'base', 'screen, projection, tv');
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the jCrop scripts
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-06-20 13:49:37 +01:00
|
|
|
public function showScripts()
|
2009-01-16 22:29:13 +00:00
|
|
|
{
|
|
|
|
parent::showScripts();
|
|
|
|
|
2009-02-05 21:34:38 +00:00
|
|
|
if ($this->mode == 'crop') {
|
2013-09-14 11:31:53 +01:00
|
|
|
$this->script('extlib/jquery-jcrop/jcrop.js');
|
|
|
|
$this->script('jcrop.go.js');
|
2009-02-05 21:34:38 +00:00
|
|
|
}
|
2009-09-03 20:42:50 +01:00
|
|
|
|
|
|
|
$this->autofocus('avatarfile');
|
2009-01-16 22:29:13 +00:00
|
|
|
}
|
|
|
|
}
|