Personal.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Jos Poortvliet <jos@opensuse.org>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Carl Schwan <carl@carlschwan.eu>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\FederatedFileSharing\Settings;
  28. use OCA\FederatedFileSharing\FederatedShareProvider;
  29. use OCP\AppFramework\Http\TemplateResponse;
  30. use OCP\AppFramework\Services\IInitialState;
  31. use OCP\IL10N;
  32. use OCP\IUserSession;
  33. use OCP\IURLGenerator;
  34. use OCP\Settings\ISettings;
  35. class Personal implements ISettings {
  36. private FederatedShareProvider $federatedShareProvider;
  37. private IUserSession $userSession;
  38. private IL10N $l;
  39. private \OC_Defaults $defaults;
  40. private IInitialState $initialState;
  41. private IURLGenerator $urlGenerator;
  42. public function __construct(
  43. FederatedShareProvider $federatedShareProvider, #
  44. IUserSession $userSession,
  45. IL10N $l,
  46. \OC_Defaults $defaults,
  47. IInitialState $initialState,
  48. IURLGenerator $urlGenerator
  49. ) {
  50. $this->federatedShareProvider = $federatedShareProvider;
  51. $this->userSession = $userSession;
  52. $this->l = $l;
  53. $this->defaults = $defaults;
  54. $this->initialState = $initialState;
  55. $this->urlGenerator = $urlGenerator;
  56. }
  57. /**
  58. * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
  59. * @since 9.1
  60. */
  61. public function getForm() {
  62. $cloudID = $this->userSession->getUser()->getCloudId();
  63. $url = 'https://nextcloud.com/sharing#' . $cloudID;
  64. $parameters = [
  65. 'message_with_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID, see %s', [$url]),
  66. 'message_without_URL' => $this->l->t('Share with me through my #Nextcloud Federated Cloud ID', [$cloudID]),
  67. 'logoPath' => $this->defaults->getLogo(),
  68. 'reference' => $url,
  69. 'cloudId' => $cloudID,
  70. 'color' => $this->defaults->getColorPrimary(),
  71. 'textColor' => "#ffffff",
  72. ];
  73. $this->initialState->provideInitialState('color', $this->defaults->getColorPrimary());
  74. $this->initialState->provideInitialState('textColor', '#fffff');
  75. $this->initialState->provideInitialState('logoPath', $this->defaults->getLogo());
  76. $this->initialState->provideInitialState('reference', $url);
  77. $this->initialState->provideInitialState('cloudId', $cloudID);
  78. $this->initialState->provideInitialState('docUrlFederated', $this->urlGenerator->linkToDocs('user-sharing-federated'));
  79. return new TemplateResponse('federatedfilesharing', 'settings-personal', $parameters, '');
  80. }
  81. /**
  82. * @return string the section ID, e.g. 'sharing'
  83. * @since 9.1
  84. */
  85. public function getSection() {
  86. if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() ||
  87. $this->federatedShareProvider->isIncomingServer2serverGroupShareEnabled()) {
  88. return 'sharing';
  89. }
  90. return null;
  91. }
  92. /**
  93. * @return int whether the form should be rather on the top or bottom of
  94. * the admin section. The forms are arranged in ascending order of the
  95. * priority values. It is required to return a value between 0 and 100.
  96. *
  97. * E.g.: 70
  98. * @since 9.1
  99. */
  100. public function getPriority() {
  101. return 40;
  102. }
  103. }