2016-11-09 15:39:08 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016, John Molakvoæ (skjnldsv@protonmail.com)
|
|
|
|
*
|
|
|
|
* @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 OC\Core\Controller;
|
|
|
|
|
|
|
|
use OC\AppFramework\Utility\TimeFactory;
|
2016-11-22 14:08:53 +03:00
|
|
|
use OC\CssManager;
|
2016-11-09 15:39:08 +03:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\NotFoundResponse;
|
|
|
|
use OCP\AppFramework\Http\FileDisplayResponse;
|
2016-11-30 18:14:00 +03:00
|
|
|
use OCP\Files\IAppData;
|
2016-11-22 14:08:53 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
2016-11-09 15:39:08 +03:00
|
|
|
use OCP\IRequest;
|
2016-11-30 18:14:00 +03:00
|
|
|
use OCP\Notification\IApp;
|
2016-11-09 15:39:08 +03:00
|
|
|
|
|
|
|
class CssController extends Controller {
|
|
|
|
|
2016-11-30 18:14:00 +03:00
|
|
|
/** @var IAppData */
|
|
|
|
protected $appData;
|
2016-11-09 15:39:08 +03:00
|
|
|
|
|
|
|
/** @var TimeFactory */
|
|
|
|
protected $timeFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
2016-11-30 18:14:00 +03:00
|
|
|
* @param IAppData $appData
|
2016-11-09 15:39:08 +03:00
|
|
|
* @param TimeFactory $timeFactory
|
|
|
|
*/
|
2016-11-30 18:14:00 +03:00
|
|
|
public function __construct($appName, IRequest $request, IAppData $appData, TimeFactory $timeFactory) {
|
2016-11-09 15:39:08 +03:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
2016-11-30 18:14:00 +03:00
|
|
|
$this->appData = $appData;
|
2016-11-09 15:39:08 +03:00
|
|
|
$this->timeFactory = $timeFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-11-10 18:16:33 +03:00
|
|
|
* @PublicPage
|
2016-11-09 15:39:08 +03:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param string $fileName css filename with extension
|
2016-11-10 18:36:58 +03:00
|
|
|
* @param string $appName css folder name
|
2016-11-22 13:42:46 +03:00
|
|
|
* @return FileDisplayResponse|NotFoundResponse
|
2016-11-09 15:39:08 +03:00
|
|
|
*/
|
2016-11-10 18:36:58 +03:00
|
|
|
public function getCss($fileName, $appName) {
|
2016-11-09 15:39:08 +03:00
|
|
|
try {
|
2016-11-30 18:14:00 +03:00
|
|
|
$folder = $this->appData->getFolder($appName);
|
|
|
|
$cssFile = $folder->getFile($fileName);
|
2016-11-09 15:39:08 +03:00
|
|
|
} catch(NotFoundException $e) {
|
|
|
|
return new NotFoundResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cssFile !== false) {
|
|
|
|
$response = new FileDisplayResponse($cssFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
|
|
|
|
$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');
|
|
|
|
return $response;
|
|
|
|
}
|
2016-11-10 18:16:33 +03:00
|
|
|
return new NotFoundResponse();
|
2016-11-09 15:39:08 +03:00
|
|
|
}
|
|
|
|
}
|