CoreNotifier.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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 OC\Core\Notification;
  28. use OCP\IURLGenerator;
  29. use OCP\L10N\IFactory;
  30. use OCP\Notification\INotification;
  31. use OCP\Notification\INotifier;
  32. class CoreNotifier implements INotifier {
  33. /** @var IFactory */
  34. private $l10nFactory;
  35. /** @var IURLGenerator */
  36. private $url;
  37. public function __construct(IFactory $factory, IURLGenerator $url) {
  38. $this->l10nFactory = $factory;
  39. $this->url = $url;
  40. }
  41. /**
  42. * Identifier of the notifier, only use [a-z0-9_]
  43. *
  44. * @return string
  45. * @since 17.0.0
  46. */
  47. public function getID(): string {
  48. return 'core';
  49. }
  50. /**
  51. * Human readable name describing the notifier
  52. *
  53. * @return string
  54. * @since 17.0.0
  55. */
  56. public function getName(): string {
  57. return $this->l10nFactory->get('core')->t('Nextcloud Server');
  58. }
  59. public function prepare(INotification $notification, string $languageCode): INotification {
  60. if ($notification->getApp() !== 'core') {
  61. throw new \InvalidArgumentException();
  62. }
  63. $l = $this->l10nFactory->get('core', $languageCode);
  64. if ($notification->getSubject() === 'repair_exposing_links') {
  65. $notification->setParsedSubject($l->t('Some of your link shares have been removed'));
  66. $notification->setParsedMessage($l->t('Due to a security bug we had to remove some of your link shares. Please see the link for more information.'));
  67. $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003');
  68. return $notification;
  69. }
  70. if ($notification->getSubject() === 'user_limit_reached') {
  71. $notification->setParsedSubject($l->t('The user limit of this instance is reached.'));
  72. $notification->setParsedMessage($l->t('Enter your subscription key to increase the user limit. For more information about Nextcloud Enterprise see our website.'));
  73. $notification->setLink('https://nextcloud.com/enterprise/');
  74. $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/contacts.svg')));
  75. return $notification;
  76. }
  77. throw new \InvalidArgumentException('Invalid subject');
  78. }
  79. }