Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-09-23 18:48:48 +0300
committerJulius Härtl <jus@bitgrid.net>2020-09-24 09:22:07 +0300
commitaa95b3d71bdf91d607f3a70f336db09312f2e1fe (patch)
tree2412618c68f17f78a1a532610da4cc3b6360e082 /apps/theming/lib/Controller
parentf62e880a6cfc3d826f0c106fdd46bb801b847378 (diff)
Add occ command to set theming values
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/lib/Controller')
-rw-r--r--apps/theming/lib/Controller/ThemingController.php64
1 files changed, 4 insertions, 60 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php
index 3ef5f0de506..56570794247 100644
--- a/apps/theming/lib/Controller/ThemingController.php
+++ b/apps/theming/lib/Controller/ThemingController.php
@@ -214,9 +214,6 @@ class ThemingController extends Controller {
* @throws NotPermittedException
*/
public function uploadImage(): DataResponse {
- // logo / background
- // new: favicon logo-header
- //
$key = $this->request->getParam('key');
$image = $this->request->getUploadedFile('image');
$error = null;
@@ -249,23 +246,14 @@ class ThemingController extends Controller {
);
}
- $name = '';
try {
- $folder = $this->appData->getFolder('images');
- } catch (NotFoundException $e) {
- $folder = $this->appData->newFolder('images');
- }
-
- $this->imageManager->delete($key);
-
- $target = $folder->newFile($key);
- $supportedFormats = $this->getSupportedUploadImageFormats($key);
- $detectedMimeType = mime_content_type($image['tmp_name']);
- if (!in_array($image['type'], $supportedFormats) || !in_array($detectedMimeType, $supportedFormats)) {
+ $mime = $this->imageManager->updateImage($key, $image['tmp_name']);
+ $this->themingDefaults->set($key . 'Mime', $mime);
+ } catch (\Exception $e) {
return new DataResponse(
[
'data' => [
- 'message' => $this->l10n->t('Unsupported image type'),
+ 'message' => $e->getMessage()
],
'status' => 'failure',
],
@@ -273,28 +261,7 @@ class ThemingController extends Controller {
);
}
- if ($key === 'background' && strpos($detectedMimeType, 'image/svg') === false) {
- // Optimize the image since some people may upload images that will be
- // either to big or are not progressive rendering.
- $newImage = @imagecreatefromstring(file_get_contents($image['tmp_name'], 'r'));
-
- $tmpFile = $this->tempManager->getTemporaryFile();
- $newWidth = imagesx($newImage) < 4096 ? imagesx($newImage) : 4096;
- $newHeight = imagesy($newImage) / (imagesx($newImage) / $newWidth);
- $outputImage = imagescale($newImage, $newWidth, $newHeight);
-
- imageinterlace($outputImage, 1);
- imagejpeg($outputImage, $tmpFile, 75);
- imagedestroy($outputImage);
-
- $target->putContent(file_get_contents($tmpFile, 'r'));
- } else {
- $target->putContent(file_get_contents($image['tmp_name'], 'r'));
- }
$name = $image['name'];
-
- $this->themingDefaults->set($key.'Mime', $image['type']);
-
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
return new DataResponse(
@@ -312,24 +279,6 @@ class ThemingController extends Controller {
}
/**
- * Returns a list of supported mime types for image uploads.
- * "favicon" images are only allowed to be SVG when imagemagick with SVG support is available.
- *
- * @param string $key The image key, e.g. "favicon"
- * @return array
- */
- private function getSupportedUploadImageFormats(string $key): array {
- $supportedFormats = ['image/jpeg', 'image/png', 'image/gif',];
-
- if ($key !== 'favicon' || $this->imageManager->shouldReplaceIcons() === true) {
- $supportedFormats[] = 'image/svg+xml';
- $supportedFormats[] = 'image/svg';
- }
-
- return $supportedFormats;
- }
-
- /**
* Revert setting to default value
*
* @param string $setting setting which should be reverted
@@ -341,11 +290,6 @@ class ThemingController extends Controller {
// reprocess server scss for preview
$cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/css-variables.scss', 'core');
- if (strpos($setting, 'Mime') !== -1) {
- $imageKey = str_replace('Mime', '', $setting);
- $this->imageManager->delete($imageKey);
- }
-
return new DataResponse(
[
'data' =>