PublicLinks.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Files_Sharing\Activity\Providers;
  7. use OCP\Activity\IEvent;
  8. class PublicLinks extends Base {
  9. public const SUBJECT_SHARED_LINK_SELF = 'shared_link_self';
  10. public const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by';
  11. public const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self';
  12. public const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by';
  13. public const SUBJECT_LINK_EXPIRED = 'link_expired';
  14. public const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired';
  15. /**
  16. * @param IEvent $event
  17. * @return IEvent
  18. * @throws \InvalidArgumentException
  19. * @since 11.0.0
  20. */
  21. public function parseShortVersion(IEvent $event) {
  22. $parsedParameters = $this->getParsedParameters($event);
  23. if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) {
  24. $subject = $this->l->t('Shared as public link');
  25. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) {
  26. $subject = $this->l->t('Removed public link');
  27. } elseif ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) {
  28. $subject = $this->l->t('Public link expired');
  29. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) {
  30. $subject = $this->l->t('{actor} shared as public link');
  31. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) {
  32. $subject = $this->l->t('{actor} removed public link');
  33. } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) {
  34. $subject = $this->l->t('Public link of {actor} expired');
  35. } else {
  36. throw new \InvalidArgumentException();
  37. }
  38. if ($this->activityManager->getRequirePNG()) {
  39. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  40. } else {
  41. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  42. }
  43. $this->setSubjects($event, $subject, $parsedParameters);
  44. return $event;
  45. }
  46. /**
  47. * @param IEvent $event
  48. * @param IEvent|null $previousEvent
  49. * @return IEvent
  50. * @throws \InvalidArgumentException
  51. * @since 11.0.0
  52. */
  53. public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
  54. $parsedParameters = $this->getParsedParameters($event);
  55. if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) {
  56. $subject = $this->l->t('You shared {file} as public link');
  57. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) {
  58. $subject = $this->l->t('You removed public link for {file}');
  59. } elseif ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) {
  60. $subject = $this->l->t('Public link expired for {file}');
  61. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) {
  62. $subject = $this->l->t('{actor} shared {file} as public link');
  63. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) {
  64. $subject = $this->l->t('{actor} removed public link for {file}');
  65. } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) {
  66. $subject = $this->l->t('Public link of {actor} for {file} expired');
  67. } else {
  68. throw new \InvalidArgumentException();
  69. }
  70. if ($this->activityManager->getRequirePNG()) {
  71. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  72. } else {
  73. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  74. }
  75. $this->setSubjects($event, $subject, $parsedParameters);
  76. return $event;
  77. }
  78. protected function getParsedParameters(IEvent $event) {
  79. $subject = $event->getSubject();
  80. $parameters = $event->getSubjectParameters();
  81. switch ($subject) {
  82. case self::SUBJECT_SHARED_LINK_SELF:
  83. case self::SUBJECT_UNSHARED_LINK_SELF:
  84. case self::SUBJECT_LINK_EXPIRED:
  85. return [
  86. 'file' => $this->getFile($parameters[0], $event),
  87. ];
  88. case self::SUBJECT_RESHARED_LINK_BY:
  89. case self::SUBJECT_UNSHARED_LINK_BY:
  90. case self::SUBJECT_LINK_BY_EXPIRED:
  91. return [
  92. 'file' => $this->getFile($parameters[0], $event),
  93. 'actor' => $this->getUser($parameters[1]),
  94. ];
  95. }
  96. return [];
  97. }
  98. }