You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Application.php 6.0KB

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