diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/DirectViewController.php | 12 | ||||
-rw-r--r-- | lib/Controller/DocumentController.php | 16 | ||||
-rw-r--r-- | lib/Controller/TDocumentInitialState.php | 48 |
3 files changed, 61 insertions, 15 deletions
diff --git a/lib/Controller/DirectViewController.php b/lib/Controller/DirectViewController.php index b837d39e..514a7716 100644 --- a/lib/Controller/DirectViewController.php +++ b/lib/Controller/DirectViewController.php @@ -35,6 +35,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Services\IInitialState; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Node; @@ -44,6 +45,8 @@ use OCP\ILogger; use OCP\IRequest; class DirectViewController extends Controller { + use TDocumentInitialState; + /** @var IRootFolder */ private $rootFolder; @@ -68,12 +71,16 @@ class DirectViewController extends Controller { /** @var ILogger */ private $logger; + /** @var IInitialState */ + private $initialState; + public function __construct( $appName, IRequest $request, IRootFolder $rootFolder, TokenManager $tokenManager, DirectMapper $directMapper, + IInitialState $initialState, IConfig $config, AppConfig $appConfig, TemplateManager $templateManager, @@ -85,6 +92,7 @@ class DirectViewController extends Controller { $this->rootFolder = $rootFolder; $this->tokenManager = $tokenManager; $this->directMapper = $directMapper; + $this->initialState = $initialState; $this->config = $config; $this->appConfig = $appConfig; $this->templateManager = $templateManager; @@ -171,6 +179,7 @@ class DirectViewController extends Controller { 'direct' => true, ]; + $this->provideDocumentInitialState($wopi); $response = new TemplateResponse('richdocuments', 'documents', $params, 'base'); $policy = new ContentSecurityPolicy(); $policy->allowInlineScript(true); @@ -226,6 +235,7 @@ class DirectViewController extends Controller { $params['token'] = $token; $params['urlsrc'] = $urlSrc; + $this->provideDocumentInitialState($wopi); $response = new TemplateResponse('richdocuments', 'documents', $params, 'base'); $policy = new ContentSecurityPolicy(); $policy->allowInlineScript(true); @@ -235,7 +245,7 @@ class DirectViewController extends Controller { } } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $response = $this->renderErrorPage('Failed to open the requested file.'); + return $this->renderErrorPage('Failed to open the requested file.'); } return new TemplateResponse('core', '403', [], 'guest'); diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 1ed67f21..c946c66c 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -44,6 +44,8 @@ use OCP\Share\IManager; use OC\Files\Type\TemplateManager; class DocumentController extends Controller { + use TDocumentInitialState; + /** @var string */ private $uid; /** @var IL10N */ @@ -179,20 +181,6 @@ class DocumentController extends Controller { $response->setFeaturePolicy($featurePolicy); } - private function provideDocumentInitialState(Wopi $wopi) { - $this->initialState->provideInitialState('wopi', $wopi); - $this->initialState->provideInitialState('uiDefaults', [ - 'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'classic') - ]); - $logoSet = $this->config->getAppValue('theming', 'logoheaderMime', '') !== ''; - if (!$logoSet) { - $logoSet = $this->config->getAppValue('theming', 'logoMime', '') !== ''; - } - $this->initialState->provideInitialState('theming-customLogo', ($logoSet ? - \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getThemingDefaults()->getLogo()) - : false)); - } - /** * @NoAdminRequired * diff --git a/lib/Controller/TDocumentInitialState.php b/lib/Controller/TDocumentInitialState.php new file mode 100644 index 00000000..bfd1070f --- /dev/null +++ b/lib/Controller/TDocumentInitialState.php @@ -0,0 +1,48 @@ +<?php +/* + * @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <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/>. + * + */ + +declare(strict_types=1); + +namespace OCA\Richdocuments\Controller; + +use OCA\Richdocuments\AppInfo\Application; +use OCA\Richdocuments\Db\Wopi; + +trait TDocumentInitialState { + + private function provideDocumentInitialState(Wopi $wopi): void { + $this->initialState->provideInitialState('wopi', $wopi); + $this->initialState->provideInitialState('theme', $this->config->getAppValue(Application::APPNAME, 'theme', '')); + $this->initialState->provideInitialState('uiDefaults', [ + 'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'classic') + ]); + $logoSet = $this->config->getAppValue('theming', 'logoheaderMime', '') !== ''; + if (!$logoSet) { + $logoSet = $this->config->getAppValue('theming', 'logoMime', '') !== ''; + } + $this->initialState->provideInitialState('theming-customLogo', ($logoSet ? + \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getThemingDefaults()->getLogo()) + : false)); + } + +} |