aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/lib/Controller/IconController.php
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-02-26 13:54:00 +0100
committerJulius Härtl <jus@bitgrid.net>2018-04-19 20:14:38 +0200
commit272b392cacdf34d2166105c91b0a06de3e51ed06 (patch)
tree6df721b89919f811ff60b225622a23211ef11aff /apps/theming/lib/Controller/IconController.php
parent0bae516c66efe9004d0a8ff504e0deb0069fc9d9 (diff)
downloadnextcloud-server-272b392cacdf34d2166105c91b0a06de3e51ed06.tar.gz
nextcloud-server-272b392cacdf34d2166105c91b0a06de3e51ed06.zip
Move to more generic image handling and add extra images
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/lib/Controller/IconController.php')
-rw-r--r--apps/theming/lib/Controller/IconController.php46
1 files changed, 25 insertions, 21 deletions
diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php
index 7a5f76de6b6..61df7b0b353 100644
--- a/apps/theming/lib/Controller/IconController.php
+++ b/apps/theming/lib/Controller/IconController.php
@@ -33,21 +33,16 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\DataDisplayResponse;
+use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\NotFoundException;
use OCP\IRequest;
-use OCA\Theming\Util;
-use OCP\IConfig;
class IconController extends Controller {
/** @var ThemingDefaults */
private $themingDefaults;
- /** @var Util */
- private $util;
/** @var ITimeFactory */
private $timeFactory;
- /** @var IConfig */
- private $config;
/** @var IconBuilder */
private $iconBuilder;
/** @var ImageManager */
@@ -61,19 +56,16 @@ class IconController extends Controller {
* @param string $appName
* @param IRequest $request
* @param ThemingDefaults $themingDefaults
- * @param Util $util
* @param ITimeFactory $timeFactory
- * @param IConfig $config
* @param IconBuilder $iconBuilder
* @param ImageManager $imageManager
+ * @param FileAccessHelper $fileAccessHelper
*/
public function __construct(
$appName,
IRequest $request,
ThemingDefaults $themingDefaults,
- Util $util,
ITimeFactory $timeFactory,
- IConfig $config,
IconBuilder $iconBuilder,
ImageManager $imageManager,
FileAccessHelper $fileAccessHelper
@@ -81,9 +73,7 @@ class IconController extends Controller {
parent::__construct($appName, $request);
$this->themingDefaults = $themingDefaults;
- $this->util = $util;
$this->timeFactory = $timeFactory;
- $this->config = $config;
$this->iconBuilder = $iconBuilder;
$this->imageManager = $imageManager;
$this->fileAccessHelper = $fileAccessHelper;
@@ -96,16 +86,17 @@ class IconController extends Controller {
* @param $app string app name
* @param $image string image file name (svg required)
* @return FileDisplayResponse|NotFoundResponse
+ * @throws \Exception
*/
- public function getThemedIcon($app, $image) {
+ public function getThemedIcon(string $app, string $image): Response {
try {
- $iconFile = $this->imageManager->getCachedImage("icon-" . $app . '-' . str_replace("/","_",$image));
+ $iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image));
} catch (NotFoundException $exception) {
$icon = $this->iconBuilder->colorSvg($app, $image);
- if ($icon === false || $icon === "") {
+ if ($icon === false || $icon === '') {
return new NotFoundResponse();
}
- $iconFile = $this->imageManager->setCachedImage("icon-" . $app . '-' . str_replace("/","_",$image), $icon);
+ $iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon);
}
if ($iconFile !== false) {
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
@@ -116,9 +107,9 @@ class IconController extends Controller {
$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
$response->addHeader('Pragma', 'cache');
return $response;
- } else {
- return new NotFoundResponse();
}
+
+ return new NotFoundResponse();
}
/**
@@ -129,10 +120,17 @@ class IconController extends Controller {
*
* @param $app string app name
* @return FileDisplayResponse|DataDisplayResponse
+ * @throws \Exception
*/
- public function getFavicon($app = "core") {
+ public function getFavicon(string $app = 'core'): Response {
$response = null;
- if ($this->themingDefaults->shouldReplaceIcons()) {
+ $iconFile = null;
+ try {
+ $iconFile = $this->imageManager->getImage('favicon');
+ $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
+ } catch (NotFoundException $e) {
+ }
+ if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) {
try {
$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
} catch (NotFoundException $exception) {
@@ -164,9 +162,15 @@ class IconController extends Controller {
*
* @param $app string app name
* @return FileDisplayResponse|NotFoundResponse
+ * @throws \Exception
*/
- public function getTouchIcon($app = "core") {
+ public function getTouchIcon(string $app = 'core'): Response {
$response = null;
+ try {
+ $iconFile = $this->imageManager->getImage('favicon');
+ $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
+ } catch (NotFoundException $e) {
+ }
if ($this->themingDefaults->shouldReplaceIcons()) {
try {
$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);