Fixed admin logo upload

This commit is contained in:
Lucas Bartholemy 2015-08-31 09:21:41 +02:00
parent 87885cea32
commit d899717d2c
3 changed files with 12 additions and 11 deletions

View File

@ -3,6 +3,8 @@
namespace humhub\libs; namespace humhub\libs;
use Yii; use Yii;
use yii\web\UploadedFile;
use yii\helpers\Url;
class LogoImage class LogoImage
{ {
@ -33,13 +35,12 @@ class LogoImage
$path = ""; $path = "";
// Workaround for absolute urls in console applications (Cron) // Workaround for absolute urls in console applications (Cron)
if (Yii::app() instanceof CConsoleApplication) { if (Yii::$app->request->isConsoleRequest) {
$path = Yii::app()->request->getBaseUrl(); $path = Url::base(true);
} else { } else {
$path = Yii::app()->getBaseUrl(true); $path = Url::base();
} }
if (file_exists($this->getPath())) { if (file_exists($this->getPath())) {
$path .= '/uploads/' . $this->folder_images . '/logo.png'; $path .= '/uploads/' . $this->folder_images . '/logo.png';
} }
@ -82,9 +83,9 @@ class LogoImage
public function setNew(UploadedFile $file) public function setNew(UploadedFile $file)
{ {
$this->delete(); $this->delete();
move_uploaded_file($file->getTempName(), $this->getPath()); move_uploaded_file($file->tempName, $this->getPath());
ImageConverter::Resize($this->getPath(), $this->getPath(), array('height' => $this->height, 'width' => 0, 'mode' => 'max', 'transparent' => ($file->getExtensionName() == 'png' && ImageConverter::checkTransparent($this->getPath())))); ImageConverter::Resize($this->getPath(), $this->getPath(), array('height' => $this->height, 'width' => 0, 'mode' => 'max', 'transparent' => ($file->getExtension() == 'png' && ImageConverter::checkTransparent($this->getPath()))));
} }
/** /**

View File

@ -4,6 +4,8 @@ use humhub\compat\CActiveForm;
use humhub\compat\CHtml; use humhub\compat\CHtml;
use humhub\models\Setting; use humhub\models\Setting;
use yii\helpers\Url; use yii\helpers\Url;
$this->registerJsFile('@web/resources/admin/uploadLogo.js');
?> ?>
<div class="panel panel-default"> <div class="panel panel-default">
<div <div
@ -67,7 +69,7 @@ use yii\helpers\Url;
'linkContent' => '<i class="fa fa-times"></i>', 'linkContent' => '<i class="fa fa-times"></i>',
'cssClass' => 'btn btn-danger btn-sm', 'cssClass' => 'btn btn-danger btn-sm',
'style' => $logo->hasImage() ? '' : 'display: none;', 'style' => $logo->hasImage() ? '' : 'display: none;',
'linkHref' => Url::toRoute("/admin/setting/deleteLogoImage"), 'linkHref' => Url::toRoute("/admin/setting/delete-logo-image"),
'confirmJS' => 'function(jsonResp) { resetLogoImage(jsonResp); }' 'confirmJS' => 'function(jsonResp) { resetLogoImage(jsonResp); }'
)); ));
?> ?>

View File

@ -1,6 +1,4 @@
function resetLogoImage(jsonResp) { function resetLogoImage(json) {
json = jQuery.parseJSON(jsonResp);
$('#deleteLinkPost_modal_logoimagedelete').hide(); $('#deleteLinkPost_modal_logoimagedelete').hide();
$('#logo-image').attr('src', ''); $('#logo-image').attr('src', '');
$('#img-logo').hide(); $('#img-logo').hide();