Skip to content
Snippets Groups Projects
Commit 715e3c29 authored by Ron Lucke's avatar Ron Lucke Committed by David Siegfried
Browse files

AvatarController hat verwaisten Code

Closes #4666

Merge request studip/studip!3484
parent 84365367
No related branches found
No related tags found
No related merge requests found
<?php
/**
* AvatarController - Administration of all avatar related settings
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @author Thomas Hackl <thomas.hackl@uni-passau.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 4.2
*/
class AvatarController extends AuthenticatedController
{
/**
* Display the avatar information of a user, course or institute
* @param string $type object type: 'user', 'course' or 'institute'
* @param string $id ID of the object this avatar belongs to
*/
public function update_action($type, $id)
{
// Check for permission to save a new avatar.
if ($type == 'user') {
PageLayout::setHelpKeyword('Basis.HomepageBild');
PageLayout::setTitle(_('Profilbild ändern'));
$has_perm = $GLOBALS['perm']->have_profile_perm('user', $id);
$class = Avatar::class;
$this->cancel_link = $this->url_for('profile', ['username' => User::find($id)->username]);
} else if ($type == 'institute') {
PageLayout::setTitle(Context::getHeaderLine() . ' - ' . _('Einrichtungsbild ändern'));
$has_perm = $GLOBALS['perm']->have_studip_perm('admin', $id);
$class = InstituteAvatar::class;
$this->cancel_link = $this->url_for('institute/basicdata/index', ['cid' => $id]);
} else {
PageLayout::setTitle(Context::getHeaderLine() . ' - ' . _('Veranstaltungsbild ändern'));
$has_perm = $GLOBALS['perm']->have_studip_perm('tutor', $id);
$course = Course::find($id);
if ($course->isStudygroup()) {
$class = 'StudygroupAvatar';
$this->cancel_link = $this->url_for('course/studygroup/edit?cid=' . $id);
} else {
$class = CourseAvatar::class;
$this->cancel_link = $this->url_for('course/management?cid=' . $id);
}
}
if (!$has_perm) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, das Bild zu ändern.'));
}
if ($type === 'user') {
Navigation::activateItem('/profile/index');
} else if ($type === 'institute') {
Navigation::activateItem('/admin/institute/details');
} else {
Navigation::activateItem('/course/admin/avatar');
if ($GLOBALS['perm']->have_studip_perm('admin', $id)) {
$widget = new CourseManagementSelectWidget();
Sidebar::get()->addWidget($widget);
}
}
$avatar = $class::getAvatar($id);
$this->avatar = $avatar->getURL($class::NORMAL);
$this->customized = $avatar->is_customized();
$this->type = $type;
$this->id = $id;
}
/**
* Upload a new avatar or removes the current avatar.
* Sends an information email to the user if the action was not invoked by himself.
* @param string $type object type: 'user', 'course' or 'institute'
* @param string $id ID of the object this avatar belongs to
*/
public function upload_action($type, $id)
{
CSRFProtection::verifyUnsafeRequest();
// Check for permission to save a new avatar.
if ($type == 'user') {
$has_perm = $GLOBALS['perm']->have_profile_perm('user', $id);
$class = Avatar::class;
$redirect = 'profile?username=' . User::find($id)->username;
} else if ($type == 'institute') {
$has_perm = $GLOBALS['perm']->have_studip_perm('admin', $id);
$class = InstituteAvatar::class;
$redirect = 'institute/basicdata/index';
} else {
$has_perm = $GLOBALS['perm']->have_studip_perm('tutor', $id);
$course = Course::find($id);
if ($course->isStudygroup()) {
$class = 'StudygroupAvatar';
$redirect = 'course/studygroup/edit/?cid=' . $id;
} else {
$class = CourseAvatar::class;
$redirect = 'course/management';
}
}
if (!$has_perm) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, das Bild zu ändern.'));
}
if (Request::submitted('reset')) {
$class::getAvatar($id)->reset();
if ($type == 'user') {
Visibility::removePrivacySetting('picture', $id);
}
PageLayout::postSuccess(_('Bild gelöscht.'));
} elseif (Request::submitted('upload')) {
try {
// Get the Base64-encoded data from cropper.
$imgdata = Request::get('cropped-image');
// Extract actual image data (prepended by mime type and meta data)
list($type, $imgdata) = explode(';', $imgdata);
list(, $imgdata) = explode(',', $imgdata);
$imgdata = base64_decode($imgdata);
// Write data to file.
$filename = $GLOBALS['TMP_PATH'] . '/avatar-' . $id . '.png';
file_put_contents($filename, $imgdata);
// Use new image file for avatar creation.
$class::getAvatar($id)->createFrom($filename);
NotificationCenter::postNotification('AvatarDidUpload', $id);
$message = _('Die Bilddatei wurde erfolgreich hochgeladen. '
.'Eventuell sehen Sie das neue Bild erst, nachdem Sie diese Seite '
.'neu geladen haben (in den meisten Browsern F5 drücken).');
PageLayout::postSuccess($message);
// Send message to user if necessary.
if ($type == 'user') {
setTempLanguage($id);
$this->postPrivateMessage(_("Ein neues Bild wurde hochgeladen.\n"));
restoreLanguage();
Visibility::addPrivacySetting(_('Eigenes Bild'), 'picture', 'commondata', 1, $id);
}
unlink($filename);
} catch (Exception $e) {
PageLayout::postError($e->getMessage());
}
}
$this->relocate($redirect);
}
/**
* Deletes a custom avatar.
* @param string $type object type: 'user', 'course' or 'institute'
* @param string $id ID of the object this avatar belongs to
*/
public function delete_action($type, $id)
{
// Check for permission to delete avatar.
if ($type == 'user') {
$has_perm = $GLOBALS['perm']->have_profile_perm('user', $id);
$class = 'Avatar';
$redirect = 'profile';
} else if ($type == 'institute') {
$has_perm = $GLOBALS['perm']->have_studip_perm('admin', $id);
$class = 'InstituteAvatar';
$redirect = 'institute/basicdata/index';
} else {
$has_perm = $GLOBALS['perm']->have_studip_perm('tutor', $id);
$course = Course::find($id);
if ($course->isStudygroup()) {
$class = 'StudygroupAvatar';
$redirect = 'course/studygroup/edit/?cid=' . $id;
} else {
$class = 'CourseAvatar';
$redirect = 'course/management';
}
}
if (!$has_perm) {
throw new AccessDeniedException(_('Sie haben keine Berechtigung, das Bild zu ändern.'));
}
$class::getAvatar($id)->reset();
PageLayout::postMessage(MessageBox::success(_('Das Bild wurde gelöscht.')));
$this->relocate($redirect);
}
}
...@@ -56,8 +56,8 @@ class BlubberController extends AuthenticatedController ...@@ -56,8 +56,8 @@ class BlubberController extends AuthenticatedController
sprintf( sprintf(
_('Wollen Sie ein Avatar-Bild nutzen? %sLaden Sie jetzt ein Bild hoch%s.'), _('Wollen Sie ein Avatar-Bild nutzen? %sLaden Sie jetzt ein Bild hoch%s.'),
'<a href="' . '<a href="' .
URLHelper::getLink('dispatch.php/avatar/update/user/' . $GLOBALS['user']->id) . URLHelper::getLink('dispatch.php/settings/avatar/') .
'" data-dialog>', '" >',
'</a>' '</a>'
) )
); );
......
...@@ -55,8 +55,8 @@ class Course_MessengerController extends AuthenticatedController ...@@ -55,8 +55,8 @@ class Course_MessengerController extends AuthenticatedController
sprintf( sprintf(
_('Wollen Sie ein Avatar-Bild nutzen? %sLaden Sie jetzt ein Bild hoch%s.'), _('Wollen Sie ein Avatar-Bild nutzen? %sLaden Sie jetzt ein Bild hoch%s.'),
'<a href="' . '<a href="' .
URLHelper::getURL('dispatch.php/avatar/update/user/' . $GLOBALS['user']->id) . URLHelper::getURL('dispatch.php/settings/avatar/') .
'" data-dialog>', '" >',
'</a>' '</a>'
) )
); );
......
<?php
final class UpdateHelpContent extends Migration
{
public function description()
{
return 'Update route for avatar help content';
}
protected function up()
{
DBManager::get()->exec(
"UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar' WHERE `help_content`.`content_id` = 'abfb5d03de288d02df436f9a8bb96d9d'"
);
DBManager::get()->exec(
"UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar' WHERE `help_content`.`content_id` = '5fab81bbd1e19949f304df08ea21ca1b'"
);
}
protected function down()
{
DBManager::get()->exec(
"UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar/update' WHERE `help_content`.`content_id` = 'abfb5d03de288d02df436f9a8bb96d9d'"
);
DBManager::get()->exec(
"UPDATE `help_content` SET `route` = 'dispatch.php/course/avatar/update' WHERE `help_content`.`content_id` = '5fab81bbd1e19949f304df08ea21ca1b'"
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment