1
0

HelpController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Kate Döen <kate.doeen@nextcloud.com>
  12. *
  13. * @license GNU AGPL version 3 or any later version
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License as
  17. * published by the Free Software Foundation, either version 3 of the
  18. * License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. namespace OCA\Settings\Controller;
  30. use OCP\AppFramework\Controller;
  31. use OCP\AppFramework\Http\Attribute\OpenAPI;
  32. use OCP\AppFramework\Http\ContentSecurityPolicy;
  33. use OCP\AppFramework\Http\TemplateResponse;
  34. use OCP\IAppConfig;
  35. use OCP\IConfig;
  36. use OCP\IGroupManager;
  37. use OCP\IL10N;
  38. use OCP\INavigationManager;
  39. use OCP\IRequest;
  40. use OCP\IURLGenerator;
  41. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  42. class HelpController extends Controller {
  43. /** @var INavigationManager */
  44. private $navigationManager;
  45. /** @var IURLGenerator */
  46. private $urlGenerator;
  47. /** @var IGroupManager */
  48. private $groupManager;
  49. /** @var IL10N */
  50. private $l10n;
  51. /** @var string */
  52. private $userId;
  53. /** @var IConfig */
  54. private $config;
  55. /** @var IAppConfig */
  56. private $appConfig;
  57. public function __construct(
  58. string $appName,
  59. IRequest $request,
  60. INavigationManager $navigationManager,
  61. IURLGenerator $urlGenerator,
  62. ?string $userId,
  63. IGroupManager $groupManager,
  64. IL10N $l10n,
  65. IConfig $config,
  66. IAppConfig $appConfig,
  67. ) {
  68. parent::__construct($appName, $request);
  69. $this->navigationManager = $navigationManager;
  70. $this->urlGenerator = $urlGenerator;
  71. $this->userId = $userId;
  72. $this->groupManager = $groupManager;
  73. $this->l10n = $l10n;
  74. $this->config = $config;
  75. $this->appConfig = $appConfig;
  76. }
  77. /**
  78. * @return TemplateResponse
  79. *
  80. * @NoCSRFRequired
  81. * @NoAdminRequired
  82. * @NoSubAdminRequired
  83. */
  84. public function help(string $mode = 'user'): TemplateResponse {
  85. $this->navigationManager->setActiveEntry('help');
  86. $pageTitle = $this->l10n->t('Administrator documentation');
  87. if ($mode !== 'admin') {
  88. $pageTitle = $this->l10n->t('User documentation');
  89. $mode = 'user';
  90. }
  91. $documentationUrl = $this->urlGenerator->getAbsoluteURL(
  92. $this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
  93. );
  94. $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
  95. $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);
  96. $knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
  97. if (!$knowledgebaseEmbedded) {
  98. $pageTitle = $this->l10n->t('Nextcloud help overview');
  99. $urlUserDocs = $this->urlGenerator->linkToDocs('user');
  100. $urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
  101. }
  102. $legalNoticeUrl = $this->appConfig->getValueString('theming', 'imprintUrl');
  103. $privacyUrl = $this->appConfig->getValueString('theming', 'privacyUrl');
  104. $response = new TemplateResponse('settings', 'help', [
  105. 'admin' => $this->groupManager->isAdmin($this->userId),
  106. 'url' => $documentationUrl,
  107. 'urlUserDocs' => $urlUserDocs,
  108. 'urlAdminDocs' => $urlAdminDocs,
  109. 'mode' => $mode,
  110. 'pageTitle' => $pageTitle,
  111. 'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
  112. 'legalNoticeUrl' => $legalNoticeUrl,
  113. 'privacyUrl' => $privacyUrl,
  114. ]);
  115. $policy = new ContentSecurityPolicy();
  116. $policy->addAllowedFrameDomain('\'self\'');
  117. $response->setContentSecurityPolicy($policy);
  118. return $response;
  119. }
  120. }