Application.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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\LoadAdditionalScriptsEvent;
  41. use OCA\Files\Event\LoadSidebar;
  42. use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
  43. use OCA\Files\Listener\LoadSidebarListener;
  44. use OCA\Files\Listener\RenderReferenceEventListener;
  45. use OCA\Files\Notification\Notifier;
  46. use OCA\Files\Search\FilesSearchProvider;
  47. use OCA\Files\Service\TagService;
  48. use OCA\Files\Service\UserConfig;
  49. use OCA\Files\Service\ViewConfig;
  50. use OCP\Activity\IManager as IActivityManager;
  51. use OCP\AppFramework\App;
  52. use OCP\AppFramework\Bootstrap\IBootContext;
  53. use OCP\AppFramework\Bootstrap\IBootstrap;
  54. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  55. use OCP\Collaboration\Reference\RenderReferenceEvent;
  56. use OCP\Collaboration\Resources\IProviderManager;
  57. use OCP\IConfig;
  58. use OCP\IL10N;
  59. use OCP\IPreview;
  60. use OCP\ISearch;
  61. use OCP\IRequest;
  62. use OCP\IServerContainer;
  63. use OCP\ITagManager;
  64. use OCP\IUserSession;
  65. use OCP\Share\IManager as IShareManager;
  66. use OCP\Util;
  67. use Psr\Container\ContainerInterface;
  68. class Application extends App implements IBootstrap {
  69. public const APP_ID = 'files';
  70. public function __construct(array $urlParams = []) {
  71. parent::__construct(self::APP_ID, $urlParams);
  72. }
  73. public function register(IRegistrationContext $context): void {
  74. /**
  75. * Controllers
  76. */
  77. $context->registerService('APIController', function (ContainerInterface $c) {
  78. /** @var IServerContainer $server */
  79. $server = $c->get(IServerContainer::class);
  80. return new ApiController(
  81. $c->get('AppName'),
  82. $c->get(IRequest::class),
  83. $c->get(IUserSession::class),
  84. $c->get(TagService::class),
  85. $c->get(IPreview::class),
  86. $c->get(IShareManager::class),
  87. $c->get(IConfig::class),
  88. $server->getUserFolder(),
  89. $c->get(UserConfig::class),
  90. $c->get(ViewConfig::class),
  91. );
  92. });
  93. /**
  94. * Services
  95. */
  96. $context->registerService(TagService::class, function (ContainerInterface $c) {
  97. /** @var IServerContainer $server */
  98. $server = $c->get(IServerContainer::class);
  99. return new TagService(
  100. $c->get(IUserSession::class),
  101. $c->get(IActivityManager::class),
  102. $c->get(ITagManager::class)->load(self::APP_ID),
  103. $server->getUserFolder(),
  104. $server->getEventDispatcher()
  105. );
  106. });
  107. /*
  108. * Register capabilities
  109. */
  110. $context->registerCapability(Capabilities::class);
  111. $context->registerCapability(DirectEditingCapabilities::class);
  112. $context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
  113. $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
  114. $context->registerEventListener(RenderReferenceEvent::class, RenderReferenceEventListener::class);
  115. $context->registerSearchProvider(FilesSearchProvider::class);
  116. $context->registerNotifierService(Notifier::class);
  117. }
  118. public function boot(IBootContext $context): void {
  119. $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
  120. $context->injectFn([Listener::class, 'register']);
  121. $context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider']));
  122. $this->registerTemplates();
  123. $context->injectFn(Closure::fromCallable([$this, 'registerNavigation']));
  124. $this->registerHooks();
  125. }
  126. private function registerCollaboration(IProviderManager $providerManager): void {
  127. $providerManager->registerResourceProvider(ResourceProvider::class);
  128. }
  129. private function registerSearchProvider(ISearch $search): void {
  130. $search->registerProvider(File::class, ['apps' => ['files']]);
  131. }
  132. private function registerTemplates(): void {
  133. $templateManager = \OC_Helper::getFileTemplateManager();
  134. $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp');
  135. $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
  136. $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
  137. }
  138. private function registerNavigation(IL10N $l10n): void {
  139. \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
  140. return [
  141. 'id' => 'files',
  142. 'appname' => 'files',
  143. 'script' => 'list.php',
  144. 'order' => 0,
  145. 'name' => $l10n->t('All files')
  146. ];
  147. });
  148. \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
  149. return [
  150. 'id' => 'recent',
  151. 'appname' => 'files',
  152. 'script' => 'recentlist.php',
  153. 'order' => 2,
  154. 'name' => $l10n->t('Recent')
  155. ];
  156. });
  157. \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
  158. return [
  159. 'id' => 'favorites',
  160. 'appname' => 'files',
  161. 'script' => 'simplelist.php',
  162. 'order' => 5,
  163. 'name' => $l10n->t('Favorites'),
  164. ];
  165. });
  166. }
  167. private function registerHooks(): void {
  168. Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
  169. }
  170. }