diff options
author | Robin Appelman <robin@icewind.nl> | 2021-03-09 18:10:07 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-03-09 18:15:15 +0300 |
commit | 0d823d974c467bde57e3f69bd216430b56311613 (patch) | |
tree | 1ee843a6842c11b58099ac7be5295b3a1b07ff94 | |
parent | c3f71a35ae06bbc833f7126b3ef1d2b48ef77e45 (diff) |
switch to new fancy nc20 bootstrap
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | appinfo/app.php | 7 | ||||
-rw-r--r-- | appinfo/info.xml | 4 | ||||
-rw-r--r-- | lib/AppInfo/Application.php | 42 | ||||
-rw-r--r-- | lib/Listener/CSPListener.php | 47 | ||||
-rw-r--r-- | lib/Listener/ScriptListener.php | 36 |
6 files changed, 102 insertions, 37 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c43fb..288c2c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 2.3.3 +- Remove usage of deprecated methods + ## 2.3.2 - Compatible with Nextcloud 21 diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index 6c92aa5..0000000 --- a/appinfo/app.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -use OCA\FilesMarkdown\AppInfo\Application; -/** @var Application $app */ -$app = \OC::$server->query(Application::class); -$app->register(); - diff --git a/appinfo/info.xml b/appinfo/info.xml index fa56aa5..2f7ef77 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -7,7 +7,7 @@ <description><![CDATA[Markdown Editor extends the Nextcloud text editor with a live preview for markdown files. A full list of features can be found [in the README](https://github.com/icewind1991/files_markdown)]]></description> - <version>2.3.2</version> + <version>2.3.3</version> <licence>agpl</licence> <author>Robin Appelman</author> @@ -44,6 +44,6 @@ A full list of features can be found [in the README](https://github.com/icewind1 </screenshot> <dependencies> - <nextcloud min-version="19" max-version="21"/> + <nextcloud min-version="20" max-version="21"/> </dependencies> </info> diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 377ac4b..ad5b0a3 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -29,44 +29,30 @@ namespace OCA\FilesMarkdown\AppInfo; use OC\Security\CSP\ContentSecurityPolicy; use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; +use OCA\FilesMarkdown\Listener\CSPListener; +use OCA\FilesMarkdown\Listener\ScriptListener; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Security\CSP\AddContentSecurityPolicyEvent; use OCP\Util; -class Application extends App { +class Application extends App implements IBootstrap { public const APP_ID = 'files_markdown'; public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); } - public function register() { - $server = $this->getContainer()->getServer(); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $server->query(IEventDispatcher::class); - - $dispatcher->addListener(LoadAdditionalScriptsEvent::class, function () use ($server) { - $policy = new ContentSecurityPolicy(); - $policy->setAllowedImageDomains(['*']); - $frameDomains = $policy->getAllowedFrameDomains(); - $frameDomains[] = 'www.youtube.com'; - $frameDomains[] = 'prezi.com'; - $frameDomains[] = 'player.vimeo.com'; - $frameDomains[] = 'vine.co'; - $policy->setAllowedFrameDomains($frameDomains); - $server->getContentSecurityPolicyManager()->addDefaultPolicy($policy); - - //load the required files - Util::addscript('files_markdown', '../build/editor'); - Util::addStyle('files_markdown', '../build/styles'); - Util::addStyle('files_markdown', 'preview'); - }); + public function register(IRegistrationContext $context): void { + $context->registerEventListener(LoadAdditionalScriptsEvent::class, ScriptListener::class); + $context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, CSPListener::class); + } - $dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () { - Util::addScript('files_markdown', '../build/editor'); - Util::addStyle('files_markdown', '../build/styles'); - Util::addStyle('files_markdown', 'preview'); - }); + public function boot(IBootContext $context): void { } } diff --git a/lib/Listener/CSPListener.php b/lib/Listener/CSPListener.php new file mode 100644 index 0000000..92fbe1b --- /dev/null +++ b/lib/Listener/CSPListener.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl> + * + * @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\FilesMarkdown\Listener; + + +use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Security\CSP\AddContentSecurityPolicyEvent; + +class CSPListener implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof AddContentSecurityPolicyEvent)) { + return; + } + + $policy = new ContentSecurityPolicy(); + $policy->addAllowedImageDomain('*'); + $policy->addAllowedFrameDomain('prezi.com'); + $policy->addAllowedFrameDomain('player.vimeo.com'); + $policy->addAllowedFrameDomain('vine.co'); + $policy->addAllowedFrameDomain('www.youtube.com'); + + $event->addPolicy($policy); + } +} diff --git a/lib/Listener/ScriptListener.php b/lib/Listener/ScriptListener.php new file mode 100644 index 0000000..ed40d29 --- /dev/null +++ b/lib/Listener/ScriptListener.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl> + * + * @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\FilesMarkdown\Listener; + +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class ScriptListener implements IEventListener { + public function handle(Event $event): void { + Util::addscript('files_markdown', '../build/editor'); + Util::addStyle('files_markdown', '../build/styles'); + Util::addStyle('files_markdown', 'preview'); + } +} |