Skip to content

Commit

Permalink
switch to new fancy nc20 bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Mar 9, 2021
1 parent c3f71a3 commit 0d823d9
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 2.3.3
- Remove usage of deprecated methods

## 2.3.2
- Compatible with Nextcloud 21

Expand Down
7 changes: 0 additions & 7 deletions appinfo/app.php

This file was deleted.

4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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>
42 changes: 14 additions & 28 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,30 @@

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 {
}
}
47 changes: 47 additions & 0 deletions lib/Listener/CSPListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Robin Appelman <[email protected]>
*
* @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);
}
}
36 changes: 36 additions & 0 deletions lib/Listener/ScriptListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Robin Appelman <[email protected]>
*
* @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');
}
}

0 comments on commit 0d823d9

Please sign in to comment.