From d938bbcc9623e4038a281a34f41ea417539ea825 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 5 Oct 2020 11:10:54 -0100 Subject: [PATCH] compat nc20 Signed-off-by: Maxence Lange --- Makefile | 4 +- appinfo/app.php | 44 ----------- appinfo/autoload.php | 40 ---------- appinfo/info.xml | 2 +- composer.json | 18 +++-- js/circles.app.elements.js | 65 ++++++++-------- js/circles.app.navigation.js | 55 +++++++++++++- js/circles.app.results.members.js | 5 +- lib/AppInfo/Application.php | 121 ++++++++++++++++++------------ 9 files changed, 175 insertions(+), 179 deletions(-) delete mode 100644 appinfo/app.php delete mode 100644 appinfo/autoload.php diff --git a/Makefile b/Makefile index 750fef102..564e88583 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,10 @@ clean: rm -rf node_modules # composer packages -composer: +build-composer: composer install --prefer-dist -appstore: clean composer +appstore: clean build-composer mkdir -p $(sign_dir) rsync -a \ --exclude=/build \ diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index 041483b7f..000000000 --- a/appinfo/app.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @author Vinicius Cubas Brand - * - * @copyright 2017 - * @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 . - * - */ - - - -use OCA\Circles\AppInfo\Application; - - -require_once __DIR__ . '/autoload.php'; - - -/** @var Application $app */ -$app = \OC::$server->query(Application::class); - -$app->registerNavigation(); -$app->registerFilesNavigation(); -$app->registerFilesPlugin(); - - diff --git a/appinfo/autoload.php b/appinfo/autoload.php deleted file mode 100644 index 85e760ef2..000000000 --- a/appinfo/autoload.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * @copyright 2019 - * @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 . - * - */ - - -namespace OCA\Circles\AppInfo; - - -$composerDir = __DIR__ . '/../vendor/'; - -if (is_dir($composerDir) && file_exists($composerDir . 'autoload.php')) { - require_once $composerDir . 'autoload.php'; -} - diff --git a/appinfo/info.xml b/appinfo/info.xml index 88704b09e..d2459f9be 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -43,7 +43,7 @@ Users won't be able to find this Circle using Nextcloud search engine. https://github.com/nextcloud/circles.git https://raw.githubusercontent.com/nextcloud/circles/master/screenshots/0.12.0.png - + diff --git a/composer.json b/composer.json index 0a2f1f9aa..211b10a0c 100644 --- a/composer.json +++ b/composer.json @@ -3,22 +3,24 @@ "description": "circles", "minimum-stability": "stable", "license": "agpl", + "config": { + "vendor-dir": "composer/", + "optimize-autoloader": true, + "classmap-authoritative": true, + "autoloader-suffix": "Circles" + }, "authors": [ { "name": "Maxence Lange", "email": "maxence@nextcloud.com" } ], - "require": { - "daita/my-small-php-tools": "dev-master" - }, - "config": { - "optimize-autoloader": true - }, "autoload": { "psr-4": { - "UpdateServer\\": "src/", - "Tests\\": "tests/unit/" + "OCA\\Circles\\": "lib/" } + }, + "require": { + "daita/my-small-php-tools": "dev-master" } } diff --git a/js/circles.app.elements.js b/js/circles.app.elements.js index aca048710..ba919d13c 100644 --- a/js/circles.app.elements.js +++ b/js/circles.app.elements.js @@ -35,6 +35,7 @@ /** global: api */ /** global: define */ + var elements = { newTypeDefinition: null, @@ -342,7 +343,7 @@ var elements = { fillExactMembersSearch: function(source, exact) { curr.exactMemberSearchType = ''; $.each(exact, function(index, value) { - var details = escapeHTML(value.value.shareWith); + var details = nav.escapeHtml(value.value.shareWith); if (source === 'groups') { if (exact.length === 1) { curr.exactMemberSearchType = 'group'; @@ -352,7 +353,7 @@ var elements = { elements.membersSearchResult.append( ''); }); @@ -363,7 +364,7 @@ var elements = { $.each(partial, function(index, value) { var currSearch = elements.addMember.val().trim(); - var line = escapeHTML(value.label); + var line = nav.escapeHtml(value.label); if (source === 'groups') { if (currSearch.length > 0) { @@ -371,7 +372,7 @@ var elements = { } line += ' (group)'; } else { - line += ' (' + escapeHTML(value.value.shareWith) + ')'; + line += ' (' + nav.escapeHtml(value.value.shareWith) + ')'; if (currSearch.length > 0) { line = line.replace(new RegExp('(' + currSearch + ')', 'gi'), '$1'); } @@ -379,7 +380,7 @@ var elements = { elements.membersSearchResult.append( ''); + nav.escapeHtml(value.value.shareWith) + '">' + line + ''); }); }, @@ -395,8 +396,8 @@ var elements = { $.each(exact, function(index, value) { elements.groupsSearchResult.append( ''); + nav.escapeHtml(value.value.shareWith) + '">' + nav.escapeHtml(value.label) + ' (' + + nav.escapeHtml(value.value.shareWith) + ')'); }); }, @@ -406,14 +407,14 @@ var elements = { $.each(partial, function(index, value) { var currSearch = elements.addMember.val().trim(); - var line = escapeHTML(value.label) + ' (' + escapeHTML(value.value.shareWith) + ')'; + var line = nav.escapeHtml(value.label) + ' (' + nav.escapeHtml(value.value.shareWith) + ')'; if (currSearch.length > 0) { line = line.replace(new RegExp('(' + currSearch + ')', 'gi'), '$1'); } elements.groupsSearchResult.append( ''); + nav.escapeHtml(value.value.shareWith) + '">' + line + ''); }); }, @@ -432,12 +433,12 @@ var elements = { generateTmplCircle: function(entry) { var tmpl = $('#tmpl_circle').html(); - tmpl = tmpl.replace(/%title%/g, escapeHTML(entry.name)); - tmpl = tmpl.replace(/%type%/g, t('circles', escapeHTML(entry.type_string))); - tmpl = tmpl.replace(/%owner%/g, escapeHTML(entry.owner.display_name)); - tmpl = tmpl.replace(/%status%/g, t('circles', escapeHTML(entry.user.status))); - tmpl = tmpl.replace(/%level_string%/g, t('circles', escapeHTML(entry.user.level_string))); - tmpl = tmpl.replace(/%creation%/g, escapeHTML(entry.creation)); + tmpl = tmpl.replace(/%title%/g, nav.escapeHtml(entry.name)); + tmpl = tmpl.replace(/%type%/g, t('circles', nav.escapeHtml(entry.type_string))); + tmpl = tmpl.replace(/%owner%/g, nav.escapeHtml(entry.owner.display_name)); + tmpl = tmpl.replace(/%status%/g, t('circles', nav.escapeHtml(entry.user.status))); + tmpl = tmpl.replace(/%level_string%/g, t('circles', nav.escapeHtml(entry.user.level_string))); + tmpl = tmpl.replace(/%creation%/g, nav.escapeHtml(entry.creation)); return tmpl; }, @@ -446,9 +447,9 @@ var elements = { generateTmplMember: function(entry) { var tmpl = $('#tmpl_member').html(); - tmpl = tmpl.replace(/%username%/g, escapeHTML(entry.user_id)); - tmpl = tmpl.replace(/%instance%/g, escapeHTML(entry.instance)); - tmpl = tmpl.replace(/%type%/g, escapeHTML(entry.user_type)); + tmpl = tmpl.replace(/%username%/g, nav.escapeHtml(entry.user_id)); + tmpl = tmpl.replace(/%instance%/g, nav.escapeHtml(entry.instance)); + tmpl = tmpl.replace(/%type%/g, nav.escapeHtml(entry.user_type)); let displayName = entry.display_name; if (entry.cached_name !== '') { @@ -458,11 +459,11 @@ var elements = { displayName += ' (' + entry.instance + ')'; } - tmpl = tmpl.replace(/%displayname%/g, escapeHTML(displayName)); - tmpl = tmpl.replace(/%level%/g, escapeHTML(entry.level)); - tmpl = tmpl.replace(/%levelString%/g, escapeHTML(entry.level_string)); - tmpl = tmpl.replace(/%status%/g, escapeHTML(entry.status)); - tmpl = tmpl.replace(/%joined%/g, escapeHTML(entry.joined)); + tmpl = tmpl.replace(/%displayname%/g, nav.escapeHtml(displayName)); + tmpl = tmpl.replace(/%level%/g, nav.escapeHtml(entry.level)); + tmpl = tmpl.replace(/%levelString%/g, nav.escapeHtml(entry.level_string)); + tmpl = tmpl.replace(/%status%/g, nav.escapeHtml(entry.status)); + tmpl = tmpl.replace(/%joined%/g, nav.escapeHtml(entry.joined)); return tmpl; }, @@ -471,10 +472,10 @@ var elements = { generateTmplGroup: function(entry) { var tmpl = $('#tmpl_group').html(); - tmpl = tmpl.replace(/%groupid%/g, escapeHTML(entry.user_id)); - tmpl = tmpl.replace(/%level%/g, escapeHTML(entry.level)); - tmpl = tmpl.replace(/%levelString%/g, escapeHTML(entry.level_string)); -// tmpl = tmpl.replace(/%joined%/g, escapeHTML(entry.joined)); + tmpl = tmpl.replace(/%groupid%/g, nav.escapeHtml(entry.user_id)); + tmpl = tmpl.replace(/%level%/g, nav.escapeHtml(entry.level)); + tmpl = tmpl.replace(/%levelString%/g, nav.escapeHtml(entry.level_string)); +// tmpl = tmpl.replace(/%joined%/g, nav.escapeHtml(entry.joined)); return tmpl; }, @@ -483,11 +484,11 @@ var elements = { generateTmplLink: function(entry) { var tmpl = $('#tmpl_link').html(); - tmpl = tmpl.replace(/%id%/g, escapeHTML(entry.unique_id)); - tmpl = tmpl.replace(/%token%/g, escapeHTML(entry.token)); - tmpl = tmpl.replace(/%address%/g, escapeHTML(entry.address)); - tmpl = tmpl.replace(/%status%/g, escapeHTML(entry.status)); - tmpl = tmpl.replace(/%joined%/g, escapeHTML(entry.creation)); + tmpl = tmpl.replace(/%id%/g, nav.escapeHtml(entry.unique_id)); + tmpl = tmpl.replace(/%token%/g, nav.escapeHtml(entry.token)); + tmpl = tmpl.replace(/%address%/g, nav.escapeHtml(entry.address)); + tmpl = tmpl.replace(/%status%/g, nav.escapeHtml(entry.status)); + tmpl = tmpl.replace(/%joined%/g, nav.escapeHtml(entry.creation)); return tmpl; } diff --git a/js/circles.app.navigation.js b/js/circles.app.navigation.js index 387e377a4..eeeef211f 100644 --- a/js/circles.app.navigation.js +++ b/js/circles.app.navigation.js @@ -39,8 +39,58 @@ /** global: api */ /** global: define */ + + var nav = { + escapeHtml: function(string) { + var str = '' + string + var matchHtmlRegExp = /["'&<>]/ + var match = matchHtmlRegExp.exec(str) + + if (!match) { + return str + } + + var escape + var html = '' + var index = 0 + var lastIndex = 0 + + for (index = match.index; index < str.length; index++) { + switch (str.charCodeAt(index)) { + case 34: // " + escape = '"' + break + case 38: // & + escape = '&' + break + case 39: // ' + escape = ''' + break + case 60: // < + escape = '<' + break + case 62: // > + escape = '>' + break + default: + continue + } + + if (lastIndex !== index) { + html += str.substring(lastIndex, index) + } + + lastIndex = index + 1 + html += escape + } + + return lastIndex !== index + ? html + str.substring(lastIndex, index) + : html + }, + initNavigation: function() { this.initElementsAddMemberNavigation(); this.initElementsLinkCircleNavigation(); @@ -93,7 +143,8 @@ var nav = { t('circles', 'Please confirm'), function(e) { if (e === true) { - api.addMember(curr.circle, elements.addMember.val(), define.typeGroup, '', + api.addMember(curr.circle, elements.addMember.val(), define.typeGroup, + '', resultMembers.addMemberResult); } }); @@ -611,7 +662,7 @@ var nav = { elements.circleDetails.children('#type').text(t('circles', details.type_long_string)); if (details.description !== '') { elements.circleDesc.html( - escapeHTML(details.description).replace(/\n/g, ' 
')).show( + nav.escapeHtml(details.description).replace(/\n/g, ' 
')).show( define.animationSpeed); } else { elements.circleDesc.text('').hide(define.animationSpeed); diff --git a/js/circles.app.results.members.js b/js/circles.app.results.members.js index f58caf601..ab89a8f23 100644 --- a/js/circles.app.results.members.js +++ b/js/circles.app.results.members.js @@ -34,6 +34,7 @@ /** global: api */ + var resultMembers = { @@ -51,7 +52,7 @@ var resultMembers = { enhanceSearchResult: function(search, display) { - display = escapeHTML(display); + display = nav.escapeHtml(display); if (search.length > 0) { display = display.replace(new RegExp('(' + search + ')', 'gi'), '$1'); } @@ -108,7 +109,7 @@ var resultMembers = { var currSearch = response.search; $.each(response.result, function(index, value) { elements.membersSearchResult.append('' ) ; diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 45105df03..d55fd3997 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -1,4 +1,7 @@ container = $this->getContainer(); - $manager = OC::$server->getNotificationManager(); + /** + * @param IRegistrationContext $context + */ + public function register(IRegistrationContext $context): void { + } + + + /** + * @param IBootContext $context + * + * @throws \Throwable + */ + public function boot(IBootContext $context): void { + $manager = $context->getServerContainer() + ->getNotificationManager(); $manager->registerNotifierService(Notifier::class); - $this->configService = OC::$server->query(ConfigService::class); + $this->configService = $context->getAppContainer() + ->get(ConfigService::class); + + $context->injectFn(Closure::fromCallable([$this, 'registerMountProvider'])); + $context->injectFn(Closure::fromCallable([$this, 'registerHooks'])); + $context->injectFn(Closure::fromCallable([$this, 'registerDavHooks'])); - $this->registerMountProvider(); - $this->registerHooks(); - $this->registerDavHooks(); + $context->injectFn(Closure::fromCallable([$this, 'registerNavigation'])); + $context->injectFn(Closure::fromCallable([$this, 'registerFilesNavigation'])); + $context->injectFn(Closure::fromCallable([$this, 'registerFilesPlugin'])); } /** + * @param IServerContainer $container + * * @throws GSStatusException * @throws QueryException */ - public function registerMountProvider() { + public function registerMountProvider(IServerContainer $container) { if (!$this->configService->getGSStatus(ConfigService::GS_ENABLED)) { return; } - - $mountProviderCollection = \OC::$server->getMountProviderCollection(); + $mountProviderCollection = $container->getMountProviderCollection(); $mountProviderCollection->registerProvider($this->container->query(MountProvider::class)); } @@ -101,25 +132,41 @@ public function registerMountProvider() { * Register Hooks */ public function registerHooks() { - Util::connectHook( - 'OC_User', 'post_deleteUser', '\OCA\Circles\Hooks\UserHooks', 'onUserDeleted' - ); - Util::connectHook( - 'OC_User', 'post_deleteGroup', '\OCA\Circles\Hooks\UserHooks', 'onGroupDeleted' - ); + Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Circles\Hooks\UserHooks', 'onUserDeleted'); + Util::connectHook('OC_User', 'post_deleteGroup', '\OCA\Circles\Hooks\UserHooks', 'onGroupDeleted'); + } + + + public function registerDavHooks(IServerContainer $container) { +// /** @var ConfigService $configService */ +// +// $configService = OC::$server->query(ConfigService::class); + if (!$this->configService->isContactsBackend()) { + return; + } + + /** @var DavService $davService */ + $davService = $container->get(DavService::class); + + $event = OC::$server->getEventDispatcher(); + $event->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']); + $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']); + $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']); + $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']); } /** * Register Navigation elements + * + * @param IServerContainer $container */ - public function registerNavigation() { + public function registerNavigation(IServerContainer $container) { if (!$this->configService->stillFrontEnd()) { return; } - $appManager = $this->container->getServer() - ->getNavigationManager(); + $appManager = $container->getNavigationManager(); $appManager->add( function() { $urlGen = OC::$server->getURLGenerator(); @@ -135,11 +182,10 @@ function() { ]; } ); - } - public function registerFilesPlugin() { - $eventDispatcher = OC::$server->getEventDispatcher(); + public function registerFilesPlugin(IServerContainer $container) { + $eventDispatcher = $container->getEventDispatcher(); $eventDispatcher->addListener( 'OCA\Files::loadAdditionalScripts', function() { @@ -175,26 +221,5 @@ function() { } - public function registerDavHooks() { - try { - /** @var ConfigService $configService */ - $configService = OC::$server->query(ConfigService::class); - if (!$configService->isContactsBackend()) { - return; - } - - /** @var DavService $davService */ - $davService = OC::$server->query(DavService::class); - } catch (QueryException $e) { - return; - } - - $event = OC::$server->getEventDispatcher(); - $event->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']); - $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']); - $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']); - $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']); - } - }