]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add function to request SVG or regular fallback image 4734/head
authorLukas Reschke <lukas@statuscode.ch>
Mon, 8 May 2017 12:51:55 +0000 (14:51 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Mon, 8 May 2017 12:51:55 +0000 (14:51 +0200)
Fixes https://github.com/nextcloud/server/issues/4647

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
apps/theming/lib/ThemingDefaults.php
apps/theming/tests/ThemingDefaultsTest.php
lib/private/Mail/EMailTemplate.php
lib/private/legacy/defaults.php
lib/public/Defaults.php

index 9509fc11077b6ca7b6a2eda8654e24c49463b5ff..0824a36ccdce2da08d486664dea72c2652ca999a 100644 (file)
@@ -129,9 +129,10 @@ class ThemingDefaults extends \OC_Defaults {
        /**
         * Themed logo url
         *
+        * @param bool $useSvg Whether to point to the SVG image or a fallback
         * @return string
         */
-       public function getLogo() {
+       public function getLogo($useSvg = true) {
                $logo = $this->config->getAppValue('theming', 'logoMime', false);
 
                $logoExists = true;
@@ -144,7 +145,12 @@ class ThemingDefaults extends \OC_Defaults {
                $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');
 
                if(!$logo || !$logoExists) {
-                       return $this->urlGenerator->imagePath('core','logo.svg') . '?v=' . $cacheBusterCounter;
+                       if($useSvg) {
+                               $logo = $this->urlGenerator->imagePath('core', 'logo.svg');
+                       } else {
+                               $logo = $this->urlGenerator->imagePath('core', 'logo.png');
+                       }
+                       return $logo . '?v=' . $cacheBusterCounter;
                }
 
                return $this->urlGenerator->linkToRoute('theming.Theming.getLogo') . '?v=' . $cacheBusterCounter;
index e3acab78bb70bb0615c63b7be269d0c0afff8ea0..a7cb7790aa65b99f89c352e5f6c76772e4d3ed57 100644 (file)
@@ -431,7 +431,7 @@ class ThemingDefaultsTest extends TestCase {
                $this->assertEquals('custom-background?v=0', $this->template->getBackground());
        }
 
-       public function testGetLogoDefault() {
+       private function getLogoHelper($withName, $useSvg) {
                $this->appData->expects($this->once())
                        ->method('getFolder')
                        ->willThrowException(new NotFoundException());
@@ -452,9 +452,17 @@ class ThemingDefaultsTest extends TestCase {
                        ->willThrowException(new \Exception());
                $this->urlGenerator->expects($this->once())
                        ->method('imagePath')
-                       ->with('core', 'logo.svg')
+                       ->with('core', $withName)
                        ->willReturn('core-logo');
-               $this->assertEquals('core-logo?v=0', $this->template->getLogo());
+               $this->assertEquals('core-logo?v=0', $this->template->getLogo($useSvg));
+       }
+
+       public function testGetLogoDefaultWithSvg() {
+               $this->getLogoHelper('logo.svg', true);
+       }
+
+       public function testGetLogoDefaultWithoutSvg() {
+               $this->getLogoHelper('logo.png', false);
        }
 
        public function testGetLogoCustom() {
index 3442e8e943083c6fe3d8f13963f8f5ae63180e47..0ae79345e4cdb571f572121e029e9861a18eaf14 100644 (file)
@@ -357,7 +357,7 @@ EOF;
                }
                $this->headerAdded = true;
 
-               $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo());
+               $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
                $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
        }
 
index cc4991efd3e1c7485c2852fd24b44b395a7570bf..f6d72d9776d7088eee99584210d7d3171c484c11 100644 (file)
@@ -47,9 +47,8 @@ class OC_Defaults {
        private $defaultSlogan;
        private $defaultLogoClaim;
        private $defaultColorPrimary;
-       private $defaultLogoUrl;
 
-       function __construct() {
+       public function __construct() {
                $this->l = \OC::$server->getL10N('lib');
 
                $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
@@ -65,8 +64,6 @@ class OC_Defaults {
                $this->defaultSlogan = $this->l->t('a safe home for all your data');
                $this->defaultLogoClaim = '';
                $this->defaultColorPrimary = '#0082c9';
-               $this->defaultLogoUrl = \OC::$server->getURLGenerator()->imagePath('core','logo.svg');
-               $this->defaultLogoUrl .=  '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
 
                $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
                if (file_exists($themePath)) {
@@ -307,13 +304,19 @@ class OC_Defaults {
        /**
         * Themed logo url
         *
+        * @param bool $useSvg Whether to point to the SVG image or a fallback
         * @return string
         */
-       public function getLogo() {
+       public function getLogo($useSvg = true) {
                if ($this->themeExist('getLogo')) {
-                       return $this->theme->getLogo();
+                       return $this->theme->getLogo($useSvg);
                }
 
-               return $this->defaultLogoUrl;
+               if($useSvg) {
+                       $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo.svg');
+               } else {
+                       $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo.png');
+               }
+           return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
        }
 }
index dbde78bce68eb509b6fa062b30270f9d11eb4df6..543657694c57d22aef335be715b26bbcce25d209 100644 (file)
@@ -178,11 +178,12 @@ class Defaults {
        /**
         * Themed logo url
         *
+        * @param bool $useSvg Whether to point to the SVG image or a fallback
         * @return string
         * @since 12.0.0
         */
-       public function getLogo() {
-               return $this->defaults->getLogo();
+       public function getLogo($useSvg = true) {
+               return $this->defaults->getLogo($useSvg);
        }
 
        /**