summaryrefslogtreecommitdiffstats
path: root/apps/theming/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2017-05-14 23:52:14 +0200
committerJulius Härtl <jus@bitgrid.net>2017-05-17 10:14:37 +0200
commitd3865b60964bb4161c2ac47b91efbd0f9d7aa358 (patch)
treeb7e1fe4cf2bb07336cda345923ad489ba4b72b62 /apps/theming/lib
parent443cbdc73931c0deec5bc01634ec9b512486d769 (diff)
downloadnextcloud-server-d3865b60964bb4161c2ac47b91efbd0f9d7aa358.tar.gz
nextcloud-server-d3865b60964bb4161c2ac47b91efbd0f9d7aa358.zip
Use appdata logo when generating icons
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/lib')
-rw-r--r--apps/theming/lib/IconBuilder.php20
-rw-r--r--apps/theming/lib/Util.php27
2 files changed, 30 insertions, 17 deletions
diff --git a/apps/theming/lib/IconBuilder.php b/apps/theming/lib/IconBuilder.php
index 7db24c4a2b0..42a7031f405 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 */
@@ -86,19 +87,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 +141,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';
}