summaryrefslogtreecommitdiffstats
path: root/apps/theming/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/theming/lib')
-rw-r--r--apps/theming/lib/Capabilities.php15
-rw-r--r--apps/theming/lib/Controller/IconController.php50
-rw-r--r--apps/theming/lib/IconBuilder.php52
-rw-r--r--apps/theming/lib/Util.php27
4 files changed, 94 insertions, 50 deletions
diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php
index 2a9e9a3c6cf..6e098940ff1 100644
--- a/apps/theming/lib/Capabilities.php
+++ b/apps/theming/lib/Capabilities.php
@@ -24,6 +24,7 @@
namespace OCA\Theming;
use OCP\Capabilities\ICapability;
+use OCP\IConfig;
use OCP\IURLGenerator;
/**
@@ -36,17 +37,21 @@ class Capabilities implements ICapability {
/** @var ThemingDefaults */
protected $theming;
-
/** @var IURLGenerator */
protected $url;
+ /** @var IConfig */
+ protected $config;
+
/**
* @param ThemingDefaults $theming
* @param IURLGenerator $url
+ * @param IConfig $config
*/
- public function __construct(ThemingDefaults $theming, IURLGenerator $url) {
+ public function __construct(ThemingDefaults $theming, IURLGenerator $url, IConfig $config) {
$this->theming = $theming;
$this->url = $url;
+ $this->config = $config;
}
/**
@@ -55,6 +60,8 @@ class Capabilities implements ICapability {
* @return array
*/
public function getCapabilities() {
+ $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
+
return [
'theming' => [
'name' => $this->theming->getName(),
@@ -62,7 +69,9 @@ class Capabilities implements ICapability {
'slogan' => $this->theming->getSlogan(),
'color' => $this->theming->getColorPrimary(),
'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
- 'background' => $this->url->getAbsoluteURL($this->theming->getBackground()),
+ 'background' => $backgroundLogo === 'backgroundColor' ?
+ $this->theming->getColorPrimary() :
+ $this->url->getAbsoluteURL($this->theming->getBackground()),
],
];
}
diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php
index 7c4e209d0df..5532a08c83c 100644
--- a/apps/theming/lib/Controller/IconController.php
+++ b/apps/theming/lib/Controller/IconController.php
@@ -22,6 +22,7 @@
*/
namespace OCA\Theming\Controller;
+use OC\IntegrityCheck\Helpers\FileAccessHelper;
use OCA\Theming\IconBuilder;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
@@ -29,6 +30,7 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
+use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\NotFoundException;
use OCP\IRequest;
@@ -48,6 +50,8 @@ class IconController extends Controller {
private $iconBuilder;
/** @var ImageManager */
private $imageManager;
+ /** @var FileAccessHelper */
+ private $fileAccessHelper;
/**
* IconController constructor.
@@ -69,7 +73,8 @@ class IconController extends Controller {
ITimeFactory $timeFactory,
IConfig $config,
IconBuilder $iconBuilder,
- ImageManager $imageManager
+ ImageManager $imageManager,
+ FileAccessHelper $fileAccessHelper
) {
parent::__construct($appName, $request);
@@ -79,6 +84,7 @@ class IconController extends Controller {
$this->config = $config;
$this->iconBuilder = $iconBuilder;
$this->imageManager = $imageManager;
+ $this->fileAccessHelper = $fileAccessHelper;
}
/**
@@ -120,9 +126,10 @@ class IconController extends Controller {
* @NoCSRFRequired
*
* @param $app string app name
- * @return FileDisplayResponse|NotFoundResponse
+ * @return FileDisplayResponse|DataDisplayResponse
*/
public function getFavicon($app = "core") {
+ $response = null;
if ($this->themingDefaults->shouldReplaceIcons()) {
try {
$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
@@ -132,16 +139,19 @@ class IconController extends Controller {
}
if ($iconFile !== false) {
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
- $response->cacheFor(86400);
- $expires = new \DateTime();
- $expires->setTimestamp($this->timeFactory->getTime());
- $expires->add(new \DateInterval('PT24H'));
- $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
- $response->addHeader('Pragma', 'cache');
- return $response;
}
}
- return new NotFoundResponse();
+ if($response === null) {
+ $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
+ $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
+ }
+ $response->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
+ $response->addHeader('Pragma', 'cache');
+ return $response;
}
/**
@@ -154,6 +164,7 @@ class IconController extends Controller {
* @return FileDisplayResponse|NotFoundResponse
*/
public function getTouchIcon($app = "core") {
+ $response = null;
if ($this->themingDefaults->shouldReplaceIcons()) {
try {
$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
@@ -163,15 +174,18 @@ class IconController extends Controller {
}
if ($iconFile !== false) {
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
- $response->cacheFor(86400);
- $expires = new \DateTime();
- $expires->setTimestamp($this->timeFactory->getTime());
- $expires->add(new \DateInterval('PT24H'));
- $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
- $response->addHeader('Pragma', 'cache');
- return $response;
}
}
- return new NotFoundResponse();
+ if($response === null) {
+ $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
+ $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
+ }
+ $response->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
+ $response->addHeader('Pragma', 'cache');
+ return $response;
}
}
diff --git a/apps/theming/lib/IconBuilder.php b/apps/theming/lib/IconBuilder.php
index 7db24c4a2b0..4383ccc7cd9 100644
--- a/apps/theming/lib/IconBuilder.php
+++ b/apps/theming/lib/IconBuilder.php
@@ -26,6 +26,7 @@ namespace OCA\Theming;
use Imagick;
use ImagickPixel;
use OCP\App\AppPathNotFoundException;
+use OCP\Files\SimpleFS\ISimpleFile;
class IconBuilder {
/** @var ThemingDefaults */
@@ -52,14 +53,18 @@ class IconBuilder {
* @return string|false image blob
*/
public function getFavicon($app) {
- $icon = $this->renderAppIcon($app, 32);
- if($icon === false) {
+ try {
+ $icon = $this->renderAppIcon($app, 32);
+ if ($icon === false) {
+ return false;
+ }
+ $icon->setImageFormat("png24");
+ $data = $icon->getImageBlob();
+ $icon->destroy();
+ return $data;
+ } catch (\ImagickException $e) {
return false;
}
- $icon->setImageFormat("png24");
- $data = $icon->getImageBlob();
- $icon->destroy();
- return $data;
}
/**
@@ -67,14 +72,18 @@ class IconBuilder {
* @return string|false image blob
*/
public function getTouchIcon($app) {
- $icon = $this->renderAppIcon($app, 512);
- if($icon === false) {
+ try {
+ $icon = $this->renderAppIcon($app, 512);
+ if ($icon === false) {
+ return false;
+ }
+ $icon->setImageFormat("png24");
+ $data = $icon->getImageBlob();
+ $icon->destroy();
+ return $data;
+ } catch (\ImagickException $e) {
return false;
}
- $icon->setImageFormat("png24");
- $data = $icon->getImageBlob();
- $icon->destroy();
- return $data;
}
/**
@@ -86,19 +95,23 @@ class IconBuilder {
* @return Imagick|false
*/
public function renderAppIcon($app, $size) {
- try {
- $appIcon = $this->util->getAppIcon($app);
- $appIconContent = file_get_contents($appIcon);
- } catch (AppPathNotFoundException $e) {
+ $appIcon = $this->util->getAppIcon($app);
+ if($appIcon === false) {
return false;
}
+ if ($appIcon instanceof ISimpleFile) {
+ $appIconContent = $appIcon->getContent();
+ $mime = $appIcon->getMimeType();
+ } else {
+ $appIconContent = file_get_contents($appIcon);
+ $mime = mime_content_type($appIcon);
+ }
- if($appIconContent === false) {
+ if($appIconContent === false || $appIconContent === "") {
return false;
}
$color = $this->themingDefaults->getColorPrimary();
- $mime = mime_content_type($appIcon);
// generate background image with rounded corners
$background = '<?xml version="1.0" encoding="UTF-8"?>' .
@@ -136,10 +149,9 @@ class IconBuilder {
} else {
$appIconFile = new Imagick();
$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
- $appIconFile->readImageBlob(file_get_contents($appIcon));
+ $appIconFile->readImageBlob($appIconContent);
$appIconFile->scaleImage(512, 512, true);
}
-
// offset for icon positioning
$border_w = (int)($appIconFile->getImageWidth() * 0.05);
$border_h = (int)($appIconFile->getImageHeight() * 0.05);
diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php
index 5c9ccb3baa6..286756a4849 100644
--- a/apps/theming/lib/Util.php
+++ b/apps/theming/lib/Util.php
@@ -25,6 +25,9 @@ namespace OCA\Theming;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
+use OCP\Files\IAppData;
+use OCP\Files\NotFoundException;
+use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\Files\IRootFolder;
@@ -33,23 +36,23 @@ class Util {
/** @var IConfig */
private $config;
- /** @var IRootFolder */
- private $rootFolder;
-
/** @var IAppManager */
private $appManager;
+ /** @var IAppData */
+ private $appData;
+
/**
* Util constructor.
*
* @param IConfig $config
- * @param IRootFolder $rootFolder
* @param IAppManager $appManager
+ * @param IAppData $appData
*/
- public function __construct(IConfig $config, IRootFolder $rootFolder, IAppManager $appManager) {
+ public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData) {
$this->config = $config;
- $this->rootFolder = $rootFolder;
$this->appManager = $appManager;
+ $this->appData = $appData;
}
/**
@@ -111,7 +114,7 @@ class Util {
/**
* @param $app string app name
- * @return string path to app icon / logo
+ * @return string|ISimpleFile path to app icon / file of logo
*/
public function getAppIcon($app) {
$app = str_replace(array('\0', '/', '\\', '..'), '', $app);
@@ -127,8 +130,14 @@ class Util {
}
} catch (AppPathNotFoundException $e) {}
- if($this->config->getAppValue('theming', 'logoMime', '') !== '' && $this->rootFolder->nodeExists('/themedinstancelogo')) {
- return $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/themedinstancelogo';
+ if ($this->config->getAppValue('theming', 'logoMime', '') !== '') {
+ $logoFile = null;
+ try {
+ $folder = $this->appData->getFolder('images');
+ if ($folder !== null) {
+ return $folder->getFile('logo');
+ }
+ } catch (NotFoundException $e) {}
}
return \OC::$SERVERROOT . '/core/img/logo.svg';
}