From: Diogo Cordeiro Date: Sat, 27 Apr 2019 16:39:42 +0000 (+0100) Subject: Make group edit and logo great again by XRevan86 X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d75b5d2f4acbce64ac752bdddf7ccaf39b7ff834;p=quix0rs-gnu-social.git Make group edit and logo great again by XRevan86 --- diff --git a/actions/editgroup.php b/actions/editgroup.php index cca00ea6b9..131fdf3250 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -29,7 +29,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA') && !defined('GNUSOCIAL')) { exit(1); } @@ -42,24 +42,63 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @package StatusNet * @author Evan Prodromou * @author Zach Copley + * @author Alexei Sorokin * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ class EditgroupAction extends GroupAction { - var $msg; + public $message = null; + public $success = null; + protected $canPost = true; - function title() + public function title() { // TRANS: Title for form to edit a group. %s is a group nickname. return sprintf(_('Edit %s group'), $this->group->nickname); } + public function showContent() + { + $form = new GroupEditForm($this, $this->group); + $form->show(); + } + + public function showPageNoticeBlock() + { + parent::showPageNoticeBlock(); + + if ($this->message) { + $this->element( + 'p', + ($this->success) ? 'success' : 'error', + $this->message + ); + } else { + $this->element( + 'p', + 'instructions', + // TRANS: Form instructions for group edit form. + _('Use this form to edit the group.') + ); + } + } + + public function showScripts() + { + parent::showScripts(); + $this->autofocus('fullname'); + } + /** * Prepare to run + * @param array $args + * @return bool + * @throws ClientException + * @throws NicknameException */ - protected function prepare(array $args=array()) + protected function prepare(array $args = []) { parent::prepare($args); @@ -74,7 +113,7 @@ class EditgroupAction extends GroupAction // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { - $args = array('nickname' => $nickname); + $args = ['nickname' => $nickname]; common_redirect(common_local_url('editgroup', $args), 301); } @@ -109,85 +148,42 @@ class EditgroupAction extends GroupAction return true; } - /** - * Handle the request - * - * On GET, show the form. On POST, try to save the group. - * - * @return void - */ - protected function handle() - { - parent::handle(); - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $this->trySave(); - } else { - $this->showForm(); - } - } - - function showForm($msg=null) + protected function handlePost() { - $this->msg = $msg; - $this->showPage(); - } + parent::handlePost(); - function showContent() - { - $form = new GroupEditForm($this, $this->group); - $form->show(); - } - - function showPageNotice() - { - if ($this->msg) { - $this->element('p', 'error', $this->msg); - } else { - $this->element('p', 'instructions', - // TRANS: Form instructions for group edit form. - _('Use this form to edit the group.')); - } - } - - function showScripts() - { - parent::showScripts(); - $this->autofocus('fullname'); - } - - function trySave() - { $cur = common_current_user(); if (!$cur->isAdmin($this->group)) { // TRANS: Client error displayed trying to edit a group while not being a group admin. $this->clientError(_('You must be an admin to edit the group.'), 403); } - if (Event::handle('StartGroupSaveForm', array($this))) { + if (Event::handle('StartGroupSaveForm', [$this])) { // $nickname will only be set if this changenick value is true. + $nickname = null; if (common_config('profile', 'changenick') == true) { try { $nickname = Nickname::normalize($this->trimmed('newnickname'), true); } catch (NicknameTakenException $e) { // Abort only if the nickname is occupied by _another_ group if ($e->profile->id != $this->group->profile_id) { - $this->showForm($e->getMessage()); + $this->setMessage($e->getMessage(), true); return; } $nickname = Nickname::normalize($this->trimmed('newnickname')); // without in-use check this time } catch (NicknameException $e) { - $this->showForm($e->getMessage()); + $this->setMessage($e->getMessage(), true); return; } } - $fullname = $this->trimmed('fullname'); - $homepage = $this->trimmed('homepage'); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); $description = $this->trimmed('description'); - $location = $this->trimmed('location'); + $location = $this->trimmed('location'); $aliasstring = $this->trimmed('aliases'); - $private = $this->boolean('private'); + $private = $this->boolean('private'); if ($private) { $force_scope = 1; @@ -198,42 +194,51 @@ class EditgroupAction extends GroupAction } if (!is_null($homepage) && (strlen($homepage) > 0) && - !common_valid_http_url($homepage)) { + !common_valid_http_url($homepage)) { // TRANS: Group edit form validation error. - $this->showForm(_('Homepage is not a valid URL.')); + $this->setMessage(_('Homepage is not a valid URL.'), true); return; - } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { + } elseif (!is_null($fullname) && mb_strlen($fullname) > 255) { // TRANS: Group edit form validation error. - $this->showForm(_('Full name is too long (maximum 255 characters).')); + $this->setMessage(_('Full name is too long (maximum 255 characters).'), true); return; - } else if (User_group::descriptionTooLong($description)) { - $this->showForm(sprintf( - // TRANS: Group edit form validation error. - _m('Description is too long (maximum %d character).', - 'Description is too long (maximum %d characters).', - User_group::maxDescription()), - User_group::maxDescription())); + } elseif (User_group::descriptionTooLong($description)) { + $this->setMessage(sprintf( + // TRANS: Group edit form validation error. + _m( + 'Description is too long (maximum %d character).', + 'Description is too long (maximum %d characters).', + User_group::maxDescription() + ), + User_group::maxDescription() + ), true); return; - } else if (!is_null($location) && mb_strlen($location) > 255) { + } elseif (!is_null($location) && mb_strlen($location) > 255) { // TRANS: Group edit form validation error. - $this->showForm(_('Location is too long (maximum 255 characters).')); + $this->setMessage(_('Location is too long (maximum 255 characters).'), true); return; } if (!empty($aliasstring)) { - $aliases = array_map(array('Nickname', 'normalize'), - array_unique(preg_split('/[\s,]+/', $aliasstring))); + $aliases = array_map( + ['Nickname', 'normalize'], + array_unique(preg_split('/[\s,]+/', $aliasstring)) + ); } else { - $aliases = array(); + $aliases = []; } if (count($aliases) > common_config('group', 'maxaliases')) { // TRANS: Group edit form validation error. // TRANS: %d is the maximum number of allowed aliases. - $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', - 'Too many aliases! Maximum %d allowed.', - common_config('group', 'maxaliases')), - common_config('group', 'maxaliases'))); + $this->setMessage(sprintf( + _m( + 'Too many aliases! Maximum %d allowed.', + 'Too many aliases! Maximum %d allowed.', + common_config('group', 'maxaliases') + ), + common_config('group', 'maxaliases') + ), true); return; } @@ -242,15 +247,15 @@ class EditgroupAction extends GroupAction $orig = clone($this->group); if (common_config('profile', 'changenick') == true && $this->group->nickname !== $nickname) { - assert(Nickname::normalize($nickname)===$nickname); - common_debug("Changing group nickname from '{$profile->nickname}' to '{$nickname}'."); + assert(Nickname::normalize($nickname) === $nickname); + common_debug("Changing group nickname from '{$this->group->nickname}' to '{$nickname}'."); $this->group->nickname = $nickname; - $this->group->mainpage = common_local_url('showgroup', array('nickname' => $this->group->nickname)); + $this->group->mainpage = common_local_url('showgroup', ['nickname' => $this->group->nickname]); } - $this->group->fullname = $fullname; - $this->group->homepage = $homepage; + $this->group->fullname = $fullname; + $this->group->homepage = $homepage; $this->group->description = $description; - $this->group->location = $location; + $this->group->location = $location; $this->group->join_policy = $join_policy; $this->group->force_scope = $force_scope; @@ -271,14 +276,20 @@ class EditgroupAction extends GroupAction $this->group->query('COMMIT'); - Event::handle('EndGroupSaveForm', array($this)); - } + Event::handle('EndGroupSaveForm', [$this]); - if ($this->group->nickname != $orig->nickname) { - common_redirect(common_local_url('editgroup', array('nickname' => $this->group->nickname)), 303); - } else { - // TRANS: Group edit form success message. - $this->showForm(_('Options saved.')); + if ($this->group->nickname != $orig->nickname) { + common_redirect(common_local_url('editgroup', ['nickname' => $this->group->nickname]), 303); + } } + + // TRANS: Group edit form success message. + $this->setMessage(_('Options saved.')); + } + + public function setMessage($msg, $error = false) + { + $this->message = $msg; + $this->success = !$error; } } diff --git a/actions/grouplogo.php b/actions/grouplogo.php index e3906847d3..c6fa671720 100644 --- a/actions/grouplogo.php +++ b/actions/grouplogo.php @@ -28,7 +28,9 @@ * @link http://status.net/ */ -if (!defined('GNUSOCIAL')) { exit(1); } +if (!defined('GNUSOCIAL')) { + exit(1); +} /** * Upload an avatar @@ -40,111 +42,30 @@ if (!defined('GNUSOCIAL')) { exit(1); } * @author Evan Prodromou * @author Zach Copley * @author Sarven Capadisli + * @author Alexei Sorokin * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ class GrouplogoAction extends GroupAction { - var $mode = null; - var $imagefile = null; - var $filename = null; - var $msg = null; - var $success = null; - - /** - * Prepare to run - */ - protected function prepare(array $args=array()) - { - parent::prepare($args); - - if (!common_logged_in()) { - // TRANS: Client error displayed when trying to create a group while not logged in. - $this->clientError(_('You must be logged in to create a group.')); - } - - $nickname_arg = $this->trimmed('nickname'); - $nickname = common_canonical_nickname($nickname_arg); - - // Permanent redirect on non-canonical nickname - - if ($nickname_arg != $nickname) { - $args = array('nickname' => $nickname); - common_redirect(common_local_url('grouplogo', $args), 301); - } - - if (!$nickname) { - // TRANS: Client error displayed when trying to change group logo settings without providing a nickname. - $this->clientError(_('No nickname.'), 404); - } - - $groupid = $this->trimmed('groupid'); - - if ($groupid) { - $this->group = User_group::getKV('id', $groupid); - } else { - $local = Local_group::getKV('nickname', $nickname); - if ($local) { - $this->group = User_group::getKV('id', $local->group_id); - } - } - - if (!$this->group) { - // TRANS: Client error displayed when trying to update logo settings for a non-existing group. - $this->clientError(_('No such group.'), 404); - } - - $cur = common_current_user(); - - if (!$cur->isAdmin($this->group)) { - // TRANS: Client error displayed when trying to change group logo settings while not being a group admin. - $this->clientError(_('You must be an admin to edit the group.'), 403); - } - - return true; - } - - protected function handle() - { - parent::handle(); - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $this->handlePost(); - } else { - $this->showForm(); - } - } - - function showForm($msg = null, $success = false) - { - $this->msg = $msg; - $this->success = $success; - - $this->showPage(); - } + public $mode = null; + public $imagefile = null; + public $filename = null; + public $message = null; + public $success = null; + protected $canPost = true; /** * Title of the page * * @return string Title of the page */ - function title() + public function title() { // TRANS: Title for group logo settings page. return _('Group logo'); } - /** - * Instructions for use - * - * @return instructions for use - */ - function getInstructions() - { - // TRANS: Instructions for group logo page. - // TRANS: %s is the maximum file size for that site. - return sprintf(_('You can upload a logo image for your group. The maximum file size is %s.'), ImageFile::maxFileSize()); - } - /** * Content area of the page * @@ -152,7 +73,7 @@ class GrouplogoAction extends GroupAction * * @return void */ - function showContent() + public function showContent() { if ($this->mode == 'crop') { $this->showCropForm(); @@ -161,7 +82,69 @@ class GrouplogoAction extends GroupAction } } - function showUploadForm() + public function showCropForm() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_avatar', + 'class' => 'form_settings', + 'action' => + common_local_url( + 'grouplogo', + array('nickname' => $this->group->nickname) + ))); + $this->elementStart('fieldset'); + // TRANS: Legend for group logo settings fieldset. + $this->element('legend', null, _('Avatar settings')); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + + $this->elementStart( + 'li', + array('id' => 'avatar_original', + 'class' => 'avatar_view') + ); + // TRANS: Header for originally uploaded file before a crop on the group logo page. + $this->element('h2', null, _('Original')); + $this->elementStart('div', array('id' => 'avatar_original_view')); + $this->element('img', array('src' => Avatar::url($this->filedata['filename']), + 'width' => $this->filedata['width'], + 'height' => $this->filedata['height'], + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + + $this->elementStart( + 'li', + array('id' => 'avatar_preview', + 'class' => 'avatar_view') + ); + // TRANS: Header for the cropped group logo on the group logo page. + $this->element('h2', null, _('Preview')); + $this->elementStart('div', array('id' => 'avatar_preview_view')); + $this->element('img', array('src' => Avatar::url($this->filedata['filename']), + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + + foreach (array('avatar_crop_x', 'avatar_crop_y', + 'avatar_crop_w', 'avatar_crop_h') as $crop_info) { + $this->element('input', array('name' => $crop_info, + 'type' => 'hidden', + 'id' => $crop_info)); + } + + // TRANS: Button text for cropping an uploaded group logo. + $this->submit('crop', _('Crop')); + + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + public function showUploadForm() { $user = common_current_user(); @@ -176,12 +159,14 @@ class GrouplogoAction extends GroupAction $original = $this->group->original_logo; $this->elementStart('form', array('enctype' => 'multipart/form-data', - 'method' => 'post', - 'id' => 'form_settings_avatar', - 'class' => 'form_settings', - 'action' => - common_local_url('grouplogo', - array('nickname' => $this->group->nickname)))); + 'method' => 'post', + 'id' => 'form_settings_avatar', + 'class' => 'form_settings', + 'action' => + common_local_url( + 'grouplogo', + array('nickname' => $this->group->nickname) + ))); $this->elementStart('fieldset'); // TRANS: Group logo form legend. $this->element('legend', null, _('Group logo')); @@ -190,26 +175,26 @@ class GrouplogoAction extends GroupAction $this->elementStart('ul', 'form_data'); if ($original) { $this->elementStart('li', array('id' => 'avatar_original', - 'class' => 'avatar_view')); + 'class' => 'avatar_view')); // TRANS: Uploaded original file in group logo form. $this->element('h2', null, _('Original')); - $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->elementStart('div', array('id' => 'avatar_original_view')); $this->element('img', array('src' => $this->group->original_logo, - 'alt' => $this->group->nickname)); + 'alt' => $this->group->nickname)); $this->elementEnd('div'); $this->elementEnd('li'); } if ($this->group->homepage_logo) { $this->elementStart('li', array('id' => 'avatar_preview', - 'class' => 'avatar_view')); + 'class' => 'avatar_view')); // TRANS: Header for preview of to be displayed group logo. $this->element('h2', null, _('Preview')); - $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->elementStart('div', array('id' => 'avatar_preview_view')); $this->element('img', array('src' => $this->group->homepage_logo, - 'width' => AVATAR_PROFILE_SIZE, - 'height' => AVATAR_PROFILE_SIZE, - 'alt' => $this->group->nickname)); + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); $this->elementEnd('div'); if (!empty($this->group->homepage_logo)) { // TRANS: Button on group logo upload page to delete current group logo. @@ -218,14 +203,14 @@ class GrouplogoAction extends GroupAction $this->elementEnd('li'); } - $this->elementStart('li', array ('id' => 'settings_attach')); + $this->elementStart('li', array('id' => 'settings_attach')); $this->element('input', array('name' => 'MAX_FILE_SIZE', - 'type' => 'hidden', - 'id' => 'MAX_FILE_SIZE', - 'value' => ImageFile::maxFileSizeInt())); + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => ImageFile::maxFileSizeInt())); $this->element('input', array('name' => 'avatarfile', - 'type' => 'file', - 'id' => 'avatarfile')); + 'type' => 'file', + 'id' => 'avatarfile')); $this->elementEnd('li'); $this->elementEnd('ul'); @@ -240,60 +225,121 @@ class GrouplogoAction extends GroupAction $this->elementEnd('form'); } - function showCropForm() + public function showPageNoticeBlock() { - $this->elementStart('form', array('method' => 'post', - 'id' => 'form_settings_avatar', - 'class' => 'form_settings', - 'action' => - common_local_url('grouplogo', - array('nickname' => $this->group->nickname)))); - $this->elementStart('fieldset'); - // TRANS: Legend for group logo settings fieldset. - $this->element('legend', null, _('Avatar settings')); - $this->hidden('token', common_session_token()); + parent::showPageNoticeBlock(); + + if ($this->message) { + $this->element( + 'div', + ($this->success) ? 'success' : 'error', + $this->message + ); + } else { + $inst = $this->getInstructions(); + $output = common_markup_to_html($inst); - $this->elementStart('ul', 'form_data'); + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + } - $this->elementStart('li', - array('id' => 'avatar_original', - 'class' => 'avatar_view')); - // TRANS: Header for originally uploaded file before a crop on the group logo page. - $this->element('h2', null, _('Original')); - $this->elementStart('div', array('id'=>'avatar_original_view')); - $this->element('img', array('src' => Avatar::url($this->filedata['filename']), - 'width' => $this->filedata['width'], - 'height' => $this->filedata['height'], - 'alt' => $this->group->nickname)); - $this->elementEnd('div'); - $this->elementEnd('li'); + /** + * Instructions for use + * + * @return string instructions for use + */ + public function getInstructions() + { + // TRANS: Instructions for group logo page. + // TRANS: %s is the maximum file size for that site. + return sprintf(_('You can upload a logo image for your group. The maximum file size is %s.'), ImageFile::maxFileSize()); + } - $this->elementStart('li', - array('id' => 'avatar_preview', - 'class' => 'avatar_view')); - // TRANS: Header for the cropped group logo on the group logo page. - $this->element('h2', null, _('Preview')); - $this->elementStart('div', array('id'=>'avatar_preview_view')); - $this->element('img', array('src' => Avatar::url($this->filedata['filename']), - 'width' => AVATAR_PROFILE_SIZE, - 'height' => AVATAR_PROFILE_SIZE, - 'alt' => $this->group->nickname)); - $this->elementEnd('div'); + /** + * Add the jCrop stylesheet + * + * @return void + */ + public function showStylesheets() + { + parent::showStylesheets(); + $this->cssLink('js/extlib/jquery-jcrop/css/jcrop.css', 'base', 'screen, projection, tv'); + } - foreach (array('avatar_crop_x', 'avatar_crop_y', - 'avatar_crop_w', 'avatar_crop_h') as $crop_info) { - $this->element('input', array('name' => $crop_info, - 'type' => 'hidden', - 'id' => $crop_info)); + /** + * Add the jCrop scripts + * + * @return void + */ + public function showScripts() + { + parent::showScripts(); + + if ($this->mode == 'crop') { + $this->script('extlib/jquery-jcrop/jcrop.js'); + $this->script('jcrop.go.js'); } - // TRANS: Button text for cropping an uploaded group logo. - $this->submit('crop', _('Crop')); + $this->autofocus('avatarfile'); + } - $this->elementEnd('li'); - $this->elementEnd('ul'); - $this->elementEnd('fieldset'); - $this->elementEnd('form'); + /** + * Prepare to run + * @param array $args + * @return bool + * @throws ClientException + * @throws NicknameException + */ + protected function prepare(array $args = []) + { + parent::prepare($args); + + if (!common_logged_in()) { + // TRANS: Client error displayed when trying to create a group while not logged in. + $this->clientError(_('You must be logged in to create a group.')); + } + + $nickname_arg = $this->trimmed('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + common_redirect(common_local_url('grouplogo', $args), 301); + } + + if (!$nickname) { + // TRANS: Client error displayed when trying to change group logo settings without providing a nickname. + $this->clientError(_('No nickname.'), 404); + } + + $groupid = $this->trimmed('groupid'); + + if ($groupid) { + $this->group = User_group::getKV('id', $groupid); + } else { + $local = Local_group::getKV('nickname', $nickname); + if ($local) { + $this->group = User_group::getKV('id', $local->group_id); + } + } + + if (!$this->group) { + // TRANS: Client error displayed when trying to update logo settings for a non-existing group. + $this->clientError(_('No such group.'), 404); + } + + $cur = common_current_user(); + + if (!$cur->isAdmin($this->group)) { + // TRANS: Client error displayed when trying to change group logo settings while not being a group admin. + $this->clientError(_('You must be an admin to edit the group.'), 403); + } + + return true; } /** @@ -302,28 +348,24 @@ class GrouplogoAction extends GroupAction * We mux on the button name to figure out what the user actually wanted. * * @return void + * @throws ClientException + * @throws NoResultException + * @throws UnsupportedMediaException + * @throws UseFileAsThumbnailException */ - function handlePost() + protected function handlePost() { - // CSRF protection - - $token = $this->trimmed('token'); - if (!$token || $token != common_session_token()) { - // TRANS: Form validation error message. - $this->show_form(_('There was a problem with your session token. '. - 'Try again, please.')); - return; - } + parent::handlePost(); if ($this->arg('upload')) { $this->uploadLogo(); - } else if ($this->arg('crop')) { + } elseif ($this->arg('crop')) { $this->cropLogo(); - } else if ($this->arg('delete')) { + } elseif ($this->arg('delete')) { $this->deleteLogo(); } else { // TRANS: Form validation error message when an unsupported argument is used. - $this->showForm(_('Unexpected form submission.')); + $this->setMessage(_('Unexpected form submission.'), true); } } @@ -335,30 +377,32 @@ class GrouplogoAction extends GroupAction * * @return void */ - function uploadLogo() + public function uploadLogo() { try { $imagefile = ImageFile::fromUpload('avatarfile'); } catch (Exception $e) { - $this->showForm($e->getMessage()); + $this->setMessage($e->getMessage(), true); return; } $type = $imagefile->preferredType(); - $filename = Avatar::filename($this->group->id, - image_type_to_extension($type), - null, - 'group-temp-'.common_timestamp()); + $filename = Avatar::filename( + $this->group->id, + image_type_to_extension($type), + null, + 'group-temp-' . common_timestamp() + ); $filepath = Avatar::path($filename); $imagefile->copyTo($filepath); $filedata = array('filename' => $filename, - 'filepath' => $filepath, - 'width' => $imagefile->width, - 'height' => $imagefile->height, - 'type' => $type); + 'filepath' => $filepath, + 'width' => $imagefile->width, + 'height' => $imagefile->height, + 'type' => $type); $_SESSION['FILEDATA'] = $filedata; @@ -367,16 +411,24 @@ class GrouplogoAction extends GroupAction $this->mode = 'crop'; // TRANS: Form instructions on the group logo page. - $this->showForm(_('Pick a square area of the image to be the logo.'), - true); + $this->setMessage(_('Pick a square area of the image to be the logo.')); + } + + public function setMessage($msg, $error = false) + { + $this->message = $msg; + $this->success = !$error; } /** * Handle the results of jcrop. * * @return void + * @throws NoResultException + * @throws UnsupportedMediaException + * @throws UseFileAsThumbnailException */ - function cropLogo() + public function cropLogo() { $filedata = $_SESSION['FILEDATA']; @@ -386,20 +438,24 @@ class GrouplogoAction extends GroupAction } // If image is not being cropped assume pos & dimentions of original - $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'):$filedata['width']; - $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h'):$filedata['height']; + $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') : $filedata['width']; + $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h') : $filedata['height']; $size = min($dest_w, $dest_h, common_config('avatar', 'maxsize')); $box = array('width' => $size, 'height' => $size, - 'x' => $dest_x, 'y' => $dest_y, - 'w' => $dest_w, 'h' => $dest_h); + 'x' => $dest_x, 'y' => $dest_y, + 'w' => $dest_w, 'h' => $dest_h); $profile = $this->group->getProfile(); $imagefile = new ImageFile(null, $filedata['filepath']); - $filename = Avatar::filename($profile->getID(), image_type_to_extension($imagefile->preferredType()), - $size, common_timestamp()); + $filename = Avatar::filename( + $profile->getID(), + image_type_to_extension($imagefile->preferredType()), + $size, + common_timestamp() + ); $imagefile->resizeTo(Avatar::path($filename), $box); @@ -408,10 +464,10 @@ class GrouplogoAction extends GroupAction unset($_SESSION['FILEDATA']); $this->mode = 'upload'; // TRANS: Form success message after updating a group logo. - $this->showForm(_('Logo updated.'), true); + $this->setMessage(_('Logo updated.')); } else { // TRANS: Form failure message after failing to update a group logo. - $this->showForm(_('Failed updating logo.')); + $this->setMessage(_('Failed updating logo.'), true); } } @@ -420,7 +476,7 @@ class GrouplogoAction extends GroupAction * * @return void */ - function deleteLogo() + public function deleteLogo() { $orig = clone($this->group); Avatar::deleteFromProfile($this->group->getProfile()); @@ -428,56 +484,13 @@ class GrouplogoAction extends GroupAction @unlink(Avatar::path(basename($this->group->homepage_logo))); @unlink(Avatar::path(basename($this->group->stream_logo))); @unlink(Avatar::path(basename($this->group->mini_logo))); - $this->group->original_logo=User_group::defaultLogo(AVATAR_PROFILE_SIZE); - $this->group->homepage_logo=User_group::defaultLogo(AVATAR_PROFILE_SIZE); - $this->group->stream_logo=User_group::defaultLogo(AVATAR_STREAM_SIZE); - $this->group->mini_logo=User_group::defaultLogo(AVATAR_MINI_SIZE); + $this->group->original_logo = User_group::defaultLogo(AVATAR_PROFILE_SIZE); + $this->group->homepage_logo = User_group::defaultLogo(AVATAR_PROFILE_SIZE); + $this->group->stream_logo = User_group::defaultLogo(AVATAR_STREAM_SIZE); + $this->group->mini_logo = User_group::defaultLogo(AVATAR_MINI_SIZE); $this->group->update($orig); // TRANS: Success message for deleting the group logo. - $this->showForm(_('Logo deleted.')); - } - - function showPageNotice() - { - if ($this->msg) { - $this->element('div', ($this->success) ? 'success' : 'error', - $this->msg); - } else { - $inst = $this->getInstructions(); - $output = common_markup_to_html($inst); - - $this->elementStart('div', 'instructions'); - $this->raw($output); - $this->elementEnd('div'); - } - } - - /** - * Add the jCrop stylesheet - * - * @return void - */ - function showStylesheets() - { - parent::showStylesheets(); - $this->cssLink('js/extlib/jquery-jcrop/css/jcrop.css','base','screen, projection, tv'); - } - - /** - * Add the jCrop scripts - * - * @return void - */ - function showScripts() - { - parent::showScripts(); - - if ($this->mode == 'crop') { - $this->script('extlib/jquery-jcrop/jcrop.js'); - $this->script('jcrop.go.js'); - } - - $this->autofocus('avatarfile'); + $this->setMessage(_('Logo deleted.')); } }