diff options
author | Julius Haertl <jus@bitgrid.net> | 2017-02-09 10:55:28 +0100 |
---|---|---|
committer | Julius Haertl <jus@bitgrid.net> | 2017-02-16 15:13:38 +0100 |
commit | 6a9d5d60dc13bd43604cf30b3d9fe90364038c45 (patch) | |
tree | 457982648f4231f322e0ea9a2c8e085bb78a0784 /apps | |
parent | cdc48d301e3d4b8ad77e5e279f240ac1d441f252 (diff) | |
download | nextcloud-server-6a9d5d60dc13bd43604cf30b3d9fe90364038c45.tar.gz nextcloud-server-6a9d5d60dc13bd43604cf30b3d9fe90364038c45.zip |
Move theming images to AppData
Signed-off-by: Julius Haertl <jus@bitgrid.net>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 60 | ||||
-rw-r--r-- | apps/theming/lib/ImageManager.php | 2 |
2 files changed, 36 insertions, 26 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 24ac1c7d8d5..19999d1362d 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -33,10 +33,10 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDownloadResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\NotFoundResponse; -use OCP\AppFramework\Http\StreamResponse; +use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\File; -use OCP\Files\IRootFolder; +use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IL10N; @@ -62,10 +62,10 @@ class ThemingController extends Controller { private $l; /** @var IConfig */ private $config; - /** @var IRootFolder */ - private $rootFolder; /** @var ITempManager */ private $tempManager; + /** @var IAppData */ + private $appData; /** * ThemingController constructor. @@ -77,8 +77,8 @@ class ThemingController extends Controller { * @param Util $util * @param ITimeFactory $timeFactory * @param IL10N $l - * @param IRootFolder $rootFolder * @param ITempManager $tempManager + * @param IAppData $appData */ public function __construct( $appName, @@ -88,8 +88,8 @@ class ThemingController extends Controller { Util $util, ITimeFactory $timeFactory, IL10N $l, - IRootFolder $rootFolder, - ITempManager $tempManager + ITempManager $tempManager, + IAppData $appData ) { parent::__construct($appName, $request); @@ -98,8 +98,8 @@ class ThemingController extends Controller { $this->timeFactory = $timeFactory; $this->l = $l; $this->config = $config; - $this->rootFolder = $rootFolder; $this->tempManager = $tempManager; + $this->appData = $appData; } /** @@ -183,16 +183,22 @@ class ThemingController extends Controller { Http::STATUS_UNPROCESSABLE_ENTITY ); } + $name = ''; + try { + $folder = $this->appData->getFolder('images'); + } catch (NotFoundException $e) { + $folder = $this->appData->newFolder('images'); + } + if(!empty($newLogo)) { - $target = $this->rootFolder->newFile('themedinstancelogo'); - stream_copy_to_stream(fopen($newLogo['tmp_name'], 'r'), $target->fopen('w')); + $target = $folder->newFile('logo'); + $target->putContent(file_get_contents($newLogo['tmp_name'], 'r')); $this->template->set('logoMime', $newLogo['type']); $name = $newLogo['name']; } if(!empty($newBackgroundLogo)) { - $target = $this->rootFolder->newFile('themedbackgroundlogo'); - + $target = $folder->newFile('background'); $image = @imagecreatefromstring(file_get_contents($newBackgroundLogo['tmp_name'], 'r')); if($image === false) { return new DataResponse( @@ -219,7 +225,7 @@ class ThemingController extends Controller { imagejpeg($image, $tmpFile, 75); imagedestroy($image); - stream_copy_to_stream(fopen($tmpFile, 'r'), $target->fopen('w')); + $target->putContent(file_get_contents($tmpFile, 'r')); $this->template->set('backgroundMime', $newBackgroundLogo['type']); $name = $newBackgroundLogo['name']; } @@ -260,22 +266,24 @@ class ThemingController extends Controller { * @PublicPage * @NoCSRFRequired * - * @return StreamResponse|NotFoundResponse + * @return Http\FileDisplayResponse|NotFoundResponse */ public function getLogo() { try { /** @var File $file */ - $file = $this->rootFolder->get('themedinstancelogo'); + $file = $this->appData->getFolder('images')->getFile('logo'); } catch (NotFoundException $e) { return new NotFoundResponse(); } - $response = new Http\StreamResponse($file->fopen('r')); + $response = new FileDisplayResponse($file); $response->cacheFor(3600); - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); - $response->addHeader('Content-Disposition', 'attachment'); - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', '')); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); $response->addHeader('Pragma', 'cache'); + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', '')); return $response; } @@ -283,22 +291,24 @@ class ThemingController extends Controller { * @PublicPage * @NoCSRFRequired * - * @return StreamResponse|NotFoundResponse + * @return FileDisplayResponse|NotFoundResponse */ public function getLoginBackground() { try { /** @var File $file */ - $file = $this->rootFolder->get('themedbackgroundlogo'); + $file = $this->appData->getFolder('images')->getFile('background'); } catch (NotFoundException $e) { return new NotFoundResponse(); } - $response = new StreamResponse($file->fopen('r')); + $response = new FileDisplayResponse($file); $response->cacheFor(3600); - $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); - $response->addHeader('Content-Disposition', 'attachment'); - $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', '')); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC2822)); $response->addHeader('Pragma', 'cache'); + $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', '')); return $response; } diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php index 4cd43e02054..88e456a2969 100644 --- a/apps/theming/lib/ImageManager.php +++ b/apps/theming/lib/ImageManager.php @@ -104,7 +104,7 @@ class ImageManager { $currentFolder = $this->getCacheFolder(); $folders = $this->appData->getDirectoryListing(); foreach ($folders as $folder) { - if ($folder->getName() !== $currentFolder->getName()) { + if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) { $folder->delete(); } } |