From d899717d2c51807485f59f8de0cf9b4d65bd2359 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Mon, 31 Aug 2015 09:21:41 +0200 Subject: [PATCH] Fixed admin logo upload --- protected/humhub/libs/LogoImage.php | 15 ++++++++------- .../humhub/modules/admin/views/setting/design.php | 4 +++- resources/admin/uploadLogo.js | 4 +--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/protected/humhub/libs/LogoImage.php b/protected/humhub/libs/LogoImage.php index b119641565..98d19a8515 100644 --- a/protected/humhub/libs/LogoImage.php +++ b/protected/humhub/libs/LogoImage.php @@ -3,6 +3,8 @@ namespace humhub\libs; use Yii; +use yii\web\UploadedFile; +use yii\helpers\Url; class LogoImage { @@ -19,7 +21,7 @@ class LogoImage public function __construct() { - + } /** @@ -33,13 +35,12 @@ class LogoImage $path = ""; // Workaround for absolute urls in console applications (Cron) - if (Yii::app() instanceof CConsoleApplication) { - $path = Yii::app()->request->getBaseUrl(); + if (Yii::$app->request->isConsoleRequest) { + $path = Url::base(true); } else { - $path = Yii::app()->getBaseUrl(true); + $path = Url::base(); } - if (file_exists($this->getPath())) { $path .= '/uploads/' . $this->folder_images . '/logo.png'; } @@ -82,9 +83,9 @@ class LogoImage public function setNew(UploadedFile $file) { $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())))); } /** diff --git a/protected/humhub/modules/admin/views/setting/design.php b/protected/humhub/modules/admin/views/setting/design.php index 54d9354f95..e138cbb524 100644 --- a/protected/humhub/modules/admin/views/setting/design.php +++ b/protected/humhub/modules/admin/views/setting/design.php @@ -4,6 +4,8 @@ use humhub\compat\CActiveForm; use humhub\compat\CHtml; use humhub\models\Setting; use yii\helpers\Url; + +$this->registerJsFile('@web/resources/admin/uploadLogo.js'); ?>
'', 'cssClass' => 'btn btn-danger btn-sm', 'style' => $logo->hasImage() ? '' : 'display: none;', - 'linkHref' => Url::toRoute("/admin/setting/deleteLogoImage"), + 'linkHref' => Url::toRoute("/admin/setting/delete-logo-image"), 'confirmJS' => 'function(jsonResp) { resetLogoImage(jsonResp); }' )); ?> diff --git a/resources/admin/uploadLogo.js b/resources/admin/uploadLogo.js index 51c92034c5..5fd266a820 100644 --- a/resources/admin/uploadLogo.js +++ b/resources/admin/uploadLogo.js @@ -1,6 +1,4 @@ -function resetLogoImage(jsonResp) { - - json = jQuery.parseJSON(jsonResp); +function resetLogoImage(json) { $('#deleteLinkPost_modal_logoimagedelete').hide(); $('#logo-image').attr('src', ''); $('#img-logo').hide();