}
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
$response->cacheFor(86400);
- $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
+ $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 FileDisplayResponse|DataDisplayResponse
*/
public function getFavicon($app = "core") {
- $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
- if($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) {
- $icon = $this->iconBuilder->getFavicon($app);
- $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
- }
if ($this->themingDefaults->shouldReplaceIcons()) {
+ $iconFile = $this->imageManager->getCachedImage('favIcon-' . $app);
+ if($iconFile === null) {
+ $icon = $this->iconBuilder->getFavicon($app);
+ $iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
+ }
$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');
} else {
$response = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND);
+ $response->cacheFor(0);
+ $response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
}
- $response->cacheFor(86400);
- $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
- $response->addHeader('Pragma', 'cache');
return $response;
}
* @return FileDisplayResponse|DataDisplayResponse
*/
public function getTouchIcon($app = "core") {
- $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
- if ($iconFile === null && $this->themingDefaults->shouldReplaceIcons()) {
- $icon = $this->iconBuilder->getTouchIcon($app);
- $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
- }
if ($this->themingDefaults->shouldReplaceIcons()) {
+ $iconFile = $this->imageManager->getCachedImage('touchIcon-' . $app);
+ if ($iconFile === null) {
+ $icon = $this->iconBuilder->getTouchIcon($app);
+ $iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
+ }
$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');
} else {
$response = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND);
+ $response->cacheFor(0);
+ $response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
}
- $response->cacheFor(86400);
- $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
- $response->addHeader('Pragma', 'cache');
return $response;
}
}
\ No newline at end of file
if($mime === "image/svg+xml" || substr($appIconContent, 0, 4) === "<svg") {
if(substr($appIconContent, 0, 5) !== "<?xml") {
$svg = "<?xml version=\"1.0\"?>".$appIconContent;
+ } else {
+ $svg = $appIconContent;
}
$tmp = new Imagick();
$tmp->readImageBlob($svg);
return $svg;
}
-}
\ No newline at end of file
+}
namespace OCA\Theming;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
private $urlGenerator;
/** @var IRootFolder */
private $rootFolder;
+ /** @var ICacheFactory */
+ private $cacheFactory;
/** @var string */
private $name;
/** @var string */
IL10N $l,
IURLGenerator $urlGenerator,
\OC_Defaults $defaults,
- IRootFolder $rootFolder
+ IRootFolder $rootFolder,
+ ICacheFactory $cacheFactory
) {
parent::__construct();
$this->config = $config;
$this->l = $l;
$this->urlGenerator = $urlGenerator;
$this->rootFolder = $rootFolder;
+ $this->cacheFactory = $cacheFactory;
$this->name = $defaults->getName();
$this->url = $defaults->getBaseUrl();
* @return bool
*/
public function shouldReplaceIcons() {
+ $cache = $this->cacheFactory->create('theming');
+ if($cache->hasKey('shouldReplaceIcons')) {
+ return (bool)$cache->get('shouldReplaceIcons');
+ }
+ $value = false;
if(extension_loaded('imagick')) {
$checkImagick = new \Imagick();
if (count($checkImagick->queryFormats('SVG')) >= 1) {
- return true;
+ $value = true;
}
$checkImagick->clear();
}
- return false;
+ $cache->set('shouldReplaceIcons', $value);
+ return $value;
}
/**
->willReturn($file);
$expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
$expected->cacheFor(86400);
- $expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC2822));
$expected->addHeader('Pragma', 'cache');
@$this->assertEquals($expected, $this->iconController->getThemedIcon('core', 'filetypes/folder.svg'));
$expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
$expected->cacheFor(86400);
- $expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC2822));
$expected->addHeader('Pragma', 'cache');
$this->assertEquals($expected, $this->iconController->getFavicon());
}
->method('shouldReplaceIcons')
->willReturn(false);
$expected = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND);
- $expected->cacheFor(86400);
- $expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
- $expected->addHeader('Pragma', 'cache');
+ $expected->cacheFor(0);
+ $expected->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
$this->assertEquals($expected, $this->iconController->getFavicon());
}
$expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'image/png']);
$expected->cacheFor(86400);
- $expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC2822));
$expected->addHeader('Pragma', 'cache');
$this->assertEquals($expected, $this->iconController->getTouchIcon());
}
->method('shouldReplaceIcons')
->willReturn(false);
$expected = new DataDisplayResponse(null, Http::STATUS_NOT_FOUND);
- $expected->cacheFor(86400);
- $expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
- $expected->addHeader('Pragma', 'cache');
+ $expected->cacheFor(0);
+ $expected->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
$this->assertEquals($expected, $this->iconController->getTouchIcon());
}
namespace OCA\Theming\Tests;
use OCA\Theming\ThemingDefaults;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
private $template;
/** @var IRootFolder */
private $rootFolder;
+ /** @var ICacheFactory */
+ private $cacheFactory;
public function setUp() {
parent::setUp();
$this->rootFolder = $this->getMockBuilder(IRootFolder::class)
->disableOriginalConstructor()
->getMock();
+ $this->cacheFactory = $this->getMockBuilder(ICacheFactory::class)->getMock();
$this->defaults = $this->getMockBuilder(\OC_Defaults::class)
->disableOriginalConstructor()
->getMock();
$this->l10n,
$this->urlGenerator,
$this->defaults,
- $this->rootFolder
+ $this->rootFolder,
+ $this->cacheFactory
);
}
$c->getL10N('theming'),
$c->getURLGenerator(),
new \OC_Defaults(),
- $c->getLazyRootFolder()
+ $c->getLazyRootFolder(),
+ $c->getMemCacheFactory()
);
}
return new \OC_Defaults();