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.

180 lines
5.9 KiB

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