Application.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
  4. *
  5. * @author Alexey Pyltsyn <lex61rus@gmail.com>
  6. * @author Janis Köhr <janis.koehr@novatec-gmbh.de>
  7. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Accessibility\AppInfo;
  27. use OCP\AppFramework\App;
  28. use OCP\IConfig;
  29. use OCP\IURLGenerator;
  30. use OCP\IUserSession;
  31. class Application extends App {
  32. /** @var string */
  33. public const APP_NAME = 'accessibility';
  34. /** @var IConfig */
  35. private $config;
  36. /** @var IUserSession */
  37. private $userSession;
  38. /** @var IURLGenerator */
  39. private $urlGenerator;
  40. public function __construct() {
  41. parent::__construct(self::APP_NAME);
  42. $this->config = \OC::$server->getConfig();
  43. $this->userSession = \OC::$server->getUserSession();
  44. $this->urlGenerator = \OC::$server->getURLGenerator();
  45. }
  46. public function injectCss() {
  47. // Inject the fake css on all pages if enabled and user is logged
  48. $loggedUser = $this->userSession->getUser();
  49. if (!is_null($loggedUser)) {
  50. $userValues = $this->config->getUserKeys($loggedUser->getUID(), self::APP_NAME);
  51. // we want to check if any theme or font is enabled.
  52. if (count($userValues) > 0) {
  53. $hash = $this->config->getUserValue($loggedUser->getUID(), self::APP_NAME, 'icons-css', md5(implode('-', $userValues)));
  54. $linkToCSS = $this->urlGenerator->linkToRoute(self::APP_NAME . '.accessibility.getCss', ['md5' => $hash]);
  55. \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]);
  56. }
  57. }
  58. }
  59. public function injectJavascript() {
  60. $linkToJs = $this->urlGenerator->linkToRoute(
  61. self::APP_NAME . '.accessibility.getJavascript',
  62. [
  63. 'v' => \OC::$server->getConfig()->getAppValue('accessibility', 'cachebuster', '0'),
  64. ]
  65. );
  66. \OCP\Util::addHeader(
  67. 'script',
  68. [
  69. 'src' => $linkToJs,
  70. 'nonce' => \OC::$server->getContentSecurityPolicyNonceManager()->getNonce()
  71. ],
  72. ''
  73. );
  74. }
  75. }