2016-08-12 00:25:41 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Julius Haertl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @author Julius Haertl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
namespace OCA\Theming\Controller;
|
|
|
|
|
2016-08-30 10:03:06 +03:00
|
|
|
use OCA\Theming\IconBuilder;
|
2016-09-18 21:15:06 +03:00
|
|
|
use OCA\Theming\ImageManager;
|
2016-08-25 17:18:54 +03:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
2016-08-12 00:25:41 +03:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\DataDisplayResponse;
|
2016-09-18 21:15:06 +03:00
|
|
|
use OCP\AppFramework\Http\FileDisplayResponse;
|
2016-08-12 00:25:41 +03:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCA\Theming\Util;
|
2016-09-18 21:15:06 +03:00
|
|
|
use OCP\IConfig;
|
2016-08-12 00:25:41 +03:00
|
|
|
|
|
|
|
class IconController extends Controller {
|
2016-08-25 17:18:54 +03:00
|
|
|
/** @var ThemingDefaults */
|
|
|
|
private $themingDefaults;
|
2016-08-12 00:25:41 +03:00
|
|
|
/** @var Util */
|
|
|
|
private $util;
|
|
|
|
/** @var ITimeFactory */
|
|
|
|
private $timeFactory;
|
2016-09-18 21:15:06 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2016-08-30 10:03:06 +03:00
|
|
|
/** @var IconBuilder */
|
|
|
|
private $iconBuilder;
|
2016-09-18 21:15:06 +03:00
|
|
|
/** @var ImageManager */
|
|
|
|
private $imageManager;
|
2016-08-29 12:53:44 +03:00
|
|
|
|
2016-08-12 00:25:41 +03:00
|
|
|
/**
|
|
|
|
* IconController constructor.
|
|
|
|
*
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
2016-08-25 17:18:54 +03:00
|
|
|
* @param ThemingDefaults $themingDefaults
|
2016-08-12 00:25:41 +03:00
|
|
|
* @param Util $util
|
|
|
|
* @param ITimeFactory $timeFactory
|
2016-09-18 21:15:06 +03:00
|
|
|
* @param IConfig $config
|
2016-08-30 12:51:48 +03:00
|
|
|
* @param IconBuilder $iconBuilder
|
2016-09-18 21:15:06 +03:00
|
|
|
* @param ImageManager $imageManager
|
2016-08-12 00:25:41 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
2016-08-25 17:18:54 +03:00
|
|
|
ThemingDefaults $themingDefaults,
|
2016-08-12 00:25:41 +03:00
|
|
|
Util $util,
|
|
|
|
ITimeFactory $timeFactory,
|
2016-09-18 21:15:06 +03:00
|
|
|
IConfig $config,
|
|
|
|
IconBuilder $iconBuilder,
|
|
|
|
ImageManager $imageManager
|
2016-08-12 00:25:41 +03:00
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
2016-08-25 17:18:54 +03:00
|
|
|
$this->themingDefaults = $themingDefaults;
|
2016-08-12 00:25:41 +03:00
|
|
|
$this->util = $util;
|
|
|
|
$this->timeFactory = $timeFactory;
|
2016-09-18 21:15:06 +03:00
|
|
|
$this->config = $config;
|
2016-08-30 10:03:42 +03:00
|
|
|
$this->iconBuilder = $iconBuilder;
|
2016-09-18 21:15:06 +03:00
|
|
|
$this->imageManager = $imageManager;
|
2016-08-12 00:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
2016-08-30 12:51:48 +03:00
|
|
|
* @param $app string app name
|
|
|
|
* @param $image string image file name (svg required)
|
2016-09-18 21:15:06 +03:00
|
|
|
* @return FileDisplayResponse
|
2016-08-12 00:25:41 +03:00
|
|
|
*/
|
|
|
|
public function getThemedIcon($app, $image) {
|
2016-09-18 21:15:06 +03:00
|
|
|
$iconFile = $this->imageManager->getCachedImage("icon-" . $app . '-' . str_replace("/","_",$image));
|
|
|
|
if ($iconFile === null) {
|
|
|
|
$icon = $this->iconBuilder->colorSvg($app, $image);
|
|
|
|
$iconFile = $this->imageManager->setCachedImage("icon-" . $app . '-' . str_replace("/","_",$image), $icon);
|
|
|
|
}
|
|
|
|
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
|
2016-08-16 11:30:56 +03:00
|
|
|
$response->cacheFor(86400);
|
2016-10-14 15:57:58 +03:00
|
|
|
$expires = new \DateTime();
|
|
|
|
$expires->setTimestamp($this->timeFactory->getTime());
|
|
|
|
$expires->add(new \DateInterval('PT24H'));
|
|
|
|
$response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
|
2016-08-30 10:03:06 +03:00
|
|
|
$response->addHeader('Pragma', 'cache');
|
2016-08-16 11:30:56 +03:00
|
|
|
return $response;
|
2016-08-12 00:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a 32x32 favicon as png
|
|
|
|
*
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
2016-08-30 12:51:48 +03:00
|
|
|
* @param $app string app name
|
2016-09-18 21:15:06 +03:00
|
|
|
* @return FileDisplayResponse|DataDisplayResponse
|
2016-08-12 00:25:41 +03:00
|
|
|
*/
|
2016-09-18 21:15:06 +03:00
|
|
|
public function getFavicon($app = "core") {
|
|
|
|
if ($this->themingDefaults->shouldReplaceIcons()) {
|
2016-10-14 15:57:58 +03:00
|
|
|
$iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
|
|
|
|
if($iconFile === null) {
|
|
|
|
$icon = $this->iconBuilder->getFavicon($app);
|
|
|
|
$iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
|
|
|
|
}
|
2016-09-18 21:15:06 +03:00
|
|
|
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
|
2016-10-14 15:57:58 +03:00
|
|
|
$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');
|
2016-08-30 10:03:06 +03:00
|
|
|
} else {
|
|
|
|
$response = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND);
|
2016-10-14 15:57:58 +03:00
|
|
|
$response->cacheFor(0);
|
|
|
|
$response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
|
2016-08-30 10:03:06 +03:00
|
|
|
}
|
2016-08-30 10:03:42 +03:00
|
|
|
return $response;
|
2016-08-12 00:25:41 +03:00
|
|
|
}
|
|
|
|
|
2016-08-14 13:24:51 +03:00
|
|
|
/**
|
|
|
|
* Return a 512x512 icon for touch devices
|
|
|
|
*
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
2016-08-30 12:51:48 +03:00
|
|
|
* @param $app string app name
|
2016-09-18 21:15:06 +03:00
|
|
|
* @return FileDisplayResponse|DataDisplayResponse
|
2016-08-14 13:24:51 +03:00
|
|
|
*/
|
2016-09-18 21:15:06 +03:00
|
|
|
public function getTouchIcon($app = "core") {
|
|
|
|
if ($this->themingDefaults->shouldReplaceIcons()) {
|
2016-10-14 15:57:58 +03:00
|
|
|
$iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
|
|
|
|
if ($iconFile === null) {
|
|
|
|
$icon = $this->iconBuilder->getTouchIcon($app);
|
|
|
|
$iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
|
|
|
|
}
|
2016-09-18 21:15:06 +03:00
|
|
|
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
|
2016-10-14 15:57:58 +03:00
|
|
|
$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');
|
2016-08-14 13:24:51 +03:00
|
|
|
} else {
|
2016-08-30 10:03:06 +03:00
|
|
|
$response = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND);
|
2016-10-14 15:57:58 +03:00
|
|
|
$response->cacheFor(0);
|
|
|
|
$response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
|
2016-08-12 00:25:41 +03:00
|
|
|
}
|
2016-08-30 10:03:42 +03:00
|
|
|
return $response;
|
2016-08-12 00:25:41 +03:00
|
|
|
}
|
|
|
|
}
|