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.

DirectEditingService.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. * @author Tobias Kaminsky <tobias@kaminsky.me>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files\Service;
  25. use OCP\DirectEditing\ACreateEmpty;
  26. use OCP\DirectEditing\ACreateFromTemplate;
  27. use OCP\DirectEditing\IEditor;
  28. use OCP\DirectEditing\IManager;
  29. use OCP\DirectEditing\RegisterDirectEditorEvent;
  30. use OCP\EventDispatcher\IEventDispatcher;
  31. class DirectEditingService {
  32. /** @var IManager */
  33. private $directEditingManager;
  34. /** @var IEventDispatcher */
  35. private $eventDispatcher;
  36. public function __construct(IEventDispatcher $eventDispatcher, IManager $directEditingManager) {
  37. $this->directEditingManager = $directEditingManager;
  38. $this->eventDispatcher = $eventDispatcher;
  39. }
  40. public function getDirectEditingETag(): string {
  41. return \md5(\json_encode($this->getDirectEditingCapabilitites()));
  42. }
  43. public function getDirectEditingCapabilitites(): array {
  44. $this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
  45. $capabilities = [
  46. 'editors' => [],
  47. 'creators' => []
  48. ];
  49. if (!$this->directEditingManager->isEnabled()) {
  50. return $capabilities;
  51. }
  52. /**
  53. * @var string $id
  54. * @var IEditor $editor
  55. */
  56. foreach ($this->directEditingManager->getEditors() as $id => $editor) {
  57. $capabilities['editors'][$id] = [
  58. 'id' => $editor->getId(),
  59. 'name' => $editor->getName(),
  60. 'mimetypes' => $editor->getMimetypes(),
  61. 'optionalMimetypes' => $editor->getMimetypesOptional(),
  62. 'secure' => $editor->isSecure(),
  63. ];
  64. /** @var ACreateEmpty|ACreateFromTemplate $creator */
  65. foreach ($editor->getCreators() as $creator) {
  66. $id = $creator->getId();
  67. $capabilities['creators'][$id] = [
  68. 'id' => $id,
  69. 'editor' => $editor->getId(),
  70. 'name' => $creator->getName(),
  71. 'extension' => $creator->getExtension(),
  72. 'templates' => $creator instanceof ACreateFromTemplate,
  73. 'mimetype' => $creator->getMimetype()
  74. ];
  75. }
  76. }
  77. return $capabilities;
  78. }
  79. }