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-08-12 00:25:41 +03:00
|
|
|
use OCA\Theming\Template;
|
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\DataResponse;
|
|
|
|
use OCP\AppFramework\Http\DataDisplayResponse;
|
|
|
|
use OCP\AppFramework\Http\StreamResponse;
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\Files\IRootFolder;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCA\Theming\Util;
|
|
|
|
|
|
|
|
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;
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l;
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
/** @var IRootFolder */
|
|
|
|
private $rootFolder;
|
2016-08-30 10:03:06 +03:00
|
|
|
/** @var IconBuilder */
|
|
|
|
private $iconBuilder;
|
2016-08-29 12:53:44 +03:00
|
|
|
|
2016-08-12 00:25:41 +03:00
|
|
|
/**
|
|
|
|
* IconController constructor.
|
|
|
|
*
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IConfig $config
|
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
|
|
|
|
* @param IL10N $l
|
|
|
|
* @param IRootFolder $rootFolder
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
|
|
|
IConfig $config,
|
2016-08-25 17:18:54 +03:00
|
|
|
ThemingDefaults $themingDefaults,
|
2016-08-12 00:25:41 +03:00
|
|
|
Util $util,
|
|
|
|
ITimeFactory $timeFactory,
|
|
|
|
IL10N $l,
|
|
|
|
IRootFolder $rootFolder
|
|
|
|
) {
|
|
|
|
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;
|
|
|
|
$this->l = $l;
|
|
|
|
$this->config = $config;
|
|
|
|
$this->rootFolder = $rootFolder;
|
2016-08-30 10:03:06 +03:00
|
|
|
if(extension_loaded('imagick')) {
|
|
|
|
$this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util);
|
|
|
|
}
|
2016-08-12 00:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param $app app name
|
2016-08-30 10:03:06 +03:00
|
|
|
* @param $image image file name (svg required)
|
2016-08-12 00:25:41 +03:00
|
|
|
* @return StreamResponse|DataResponse
|
|
|
|
*/
|
|
|
|
public function getThemedIcon($app, $image) {
|
2016-08-29 12:53:44 +03:00
|
|
|
$image = $this->util->getAppImage($app, $image);
|
2016-08-12 00:25:41 +03:00
|
|
|
$svg = file_get_contents($image);
|
2016-08-25 17:18:54 +03:00
|
|
|
$color = $this->util->elementColor($this->themingDefaults->getMailHeaderColor());
|
2016-08-29 12:53:44 +03:00
|
|
|
$svg = $this->util->colorizeSvg($svg, $color);
|
2016-08-16 11:30:56 +03:00
|
|
|
$response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
|
|
|
|
$response->cacheFor(86400);
|
|
|
|
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
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
|
|
|
|
*
|
|
|
|
* @param $app app name
|
|
|
|
* @return StreamResponse|DataResponse
|
|
|
|
*/
|
2016-08-14 13:53:16 +03:00
|
|
|
public function getFavicon($app="core") {
|
2016-08-30 10:03:06 +03:00
|
|
|
if($this->themingDefaults->shouldReplaceIcons()) {
|
|
|
|
$icon = $this->iconBuilder->getFavicon($app);
|
|
|
|
$response = new DataDisplayResponse($icon, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
|
|
|
|
$response->cacheFor(86400);
|
|
|
|
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
|
|
|
$response->addHeader('Pragma', 'cache');
|
|
|
|
return $response;
|
|
|
|
} else {
|
|
|
|
$response = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND);
|
|
|
|
$response->cacheFor(86400);
|
|
|
|
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param $app app name
|
|
|
|
* @return StreamResponse|DataResponse
|
|
|
|
*/
|
2016-08-14 13:53:16 +03:00
|
|
|
public function getTouchIcon($app="core") {
|
2016-08-30 10:03:06 +03:00
|
|
|
if($this->themingDefaults->shouldReplaceIcons()) {
|
|
|
|
$icon = $this->iconBuilder->getTouchIcon($app);
|
|
|
|
$response = new DataDisplayResponse($icon, Http::STATUS_OK, ['Content-Type' => 'image/png']);
|
|
|
|
$response->cacheFor(86400);
|
|
|
|
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
|
|
|
$response->addHeader('Pragma', 'cache');
|
|
|
|
return $response;
|
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);
|
|
|
|
$response->cacheFor(86400);
|
|
|
|
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
|
|
|
return $response;
|
2016-08-12 00:25:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|