Application.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author John Molakvoæ <skjnldsv@protonmail.com>
  10. * @author Julius Härtl <jus@bitgrid.net>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <robin@icewind.nl>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. * @author Tobias Kaminsky <tobias@kaminsky.me>
  15. * @author Vincent Petry <vincent@nextcloud.com>
  16. *
  17. * @license AGPL-3.0
  18. *
  19. * This code is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU Affero General Public License, version 3,
  21. * as published by the Free Software Foundation.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License, version 3,
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>
  30. *
  31. */
  32. namespace OCA\Files\AppInfo;
  33. use Closure;
  34. use OC\Search\Provider\File;
  35. use OCA\Files\Capabilities;
  36. use OCA\Files\Collaboration\Resources\Listener;
  37. use OCA\Files\Collaboration\Resources\ResourceProvider;
  38. use OCA\Files\Controller\ApiController;
  39. use OCA\Files\DirectEditingCapabilities;
  40. use OCA\Files\Event\LoadSearchPlugins;
  41. use OCA\Files\Event\LoadSidebar;
  42. use OCA\Files\Listener\LoadSearchPluginsListener;
  43. use OCA\Files\Listener\LoadSidebarListener;
  44. use OCA\Files\Listener\RenderReferenceEventListener;
  45. use OCA\Files\Listener\SyncLivePhotosListener;
  46. use OCA\Files\Notification\Notifier;
  47. use OCA\Files\Search\FilesSearchProvider;
  48. use OCA\Files\Service\TagService;
  49. use OCA\Files\Service\UserConfig;
  50. use OCA\Files\Service\ViewConfig;
  51. use OCP\Activity\IManager as IActivityManager;
  52. use OCP\AppFramework\App;
  53. use OCP\AppFramework\Bootstrap\IBootContext;
  54. use OCP\AppFramework\Bootstrap\IBootstrap;
  55. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  56. use OCP\Collaboration\Reference\RenderReferenceEvent;
  57. use OCP\Collaboration\Resources\IProviderManager;
  58. use OCP\EventDispatcher\IEventDispatcher;
  59. use OCP\Files\Cache\CacheEntryRemovedEvent;
  60. use OCP\Files\Events\Node\BeforeNodeCopiedEvent;
  61. use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
  62. use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
  63. use OCP\Files\Events\Node\NodeCopiedEvent;
  64. use OCP\IConfig;
  65. use OCP\IPreview;
  66. use OCP\IRequest;
  67. use OCP\ISearch;
  68. use OCP\IServerContainer;
  69. use OCP\ITagManager;
  70. use OCP\IUserSession;
  71. use OCP\Share\IManager as IShareManager;
  72. use OCP\Util;
  73. use Psr\Container\ContainerInterface;
  74. class Application extends App implements IBootstrap {
  75. public const APP_ID = 'files';
  76. public function __construct(array $urlParams = []) {
  77. parent::__construct(self::APP_ID, $urlParams);
  78. }
  79. public function register(IRegistrationContext $context): void {
  80. /**
  81. * Controllers
  82. */
  83. $context->registerService('APIController', function (ContainerInterface $c) {
  84. /** @var IServerContainer $server */
  85. $server = $c->get(IServerContainer::class);
  86. return new ApiController(
  87. $c->get('AppName'),
  88. $c->get(IRequest::class),
  89. $c->get(IUserSession::class),
  90. $c->get(TagService::class),
  91. $c->get(IPreview::class),
  92. $c->get(IShareManager::class),
  93. $c->get(IConfig::class),
  94. $server->getUserFolder(),
  95. $c->get(UserConfig::class),
  96. $c->get(ViewConfig::class),
  97. );
  98. });
  99. /**
  100. * Services
  101. */
  102. $context->registerService(TagService::class, function (ContainerInterface $c) {
  103. /** @var IServerContainer $server */
  104. $server = $c->get(IServerContainer::class);
  105. return new TagService(
  106. $c->get(IUserSession::class),
  107. $c->get(IActivityManager::class),
  108. $c->get(ITagManager::class)->load(self::APP_ID),
  109. $server->getUserFolder(),
  110. $c->get(IEventDispatcher::class),
  111. );
  112. });
  113. /*
  114. * Register capabilities
  115. */
  116. $context->registerCapability(Capabilities::class);
  117. $context->registerCapability(DirectEditingCapabilities::class);
  118. $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
  119. $context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);
  120. $context->registerEventListener(BeforeNodeRenamedEvent::class, SyncLivePhotosListener::class);
  121. $context->registerEventListener(BeforeNodeDeletedEvent::class, SyncLivePhotosListener::class);
  122. $context->registerEventListener(CacheEntryRemovedEvent::class, SyncLivePhotosListener::class);
  123. $context->registerEventListener(BeforeNodeCopiedEvent::class, SyncLivePhotosListener::class);
  124. $context->registerEventListener(NodeCopiedEvent::class, SyncLivePhotosListener::class);
  125. $context->registerEventListener(LoadSearchPlugins::class, LoadSearchPluginsListener::class);
  126. $context->registerSearchProvider(FilesSearchProvider::class);
  127. $context->registerNotifierService(Notifier::class);
  128. }
  129. public function boot(IBootContext $context): void {
  130. $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
  131. $context->injectFn([Listener::class, 'register']);
  132. $context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider']));
  133. $this->registerTemplates();
  134. $this->registerHooks();
  135. }
  136. private function registerCollaboration(IProviderManager $providerManager): void {
  137. $providerManager->registerResourceProvider(ResourceProvider::class);
  138. }
  139. private function registerSearchProvider(ISearch $search): void {
  140. $search->registerProvider(File::class, ['apps' => ['files']]);
  141. }
  142. private function registerTemplates(): void {
  143. $templateManager = \OC_Helper::getFileTemplateManager();
  144. $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp');
  145. $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
  146. $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
  147. }
  148. private function registerHooks(): void {
  149. Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
  150. }
  151. }