PublicLinks.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files_Sharing\Activity\Providers;
  25. use OCP\Activity\IEvent;
  26. class PublicLinks extends Base {
  27. public const SUBJECT_SHARED_LINK_SELF = 'shared_link_self';
  28. public const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by';
  29. public const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self';
  30. public const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by';
  31. public const SUBJECT_LINK_EXPIRED = 'link_expired';
  32. public const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired';
  33. /**
  34. * @param IEvent $event
  35. * @return IEvent
  36. * @throws \InvalidArgumentException
  37. * @since 11.0.0
  38. */
  39. public function parseShortVersion(IEvent $event) {
  40. $parsedParameters = $this->getParsedParameters($event);
  41. if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) {
  42. $subject = $this->l->t('Shared as public link');
  43. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) {
  44. $subject = $this->l->t('Removed public link');
  45. } elseif ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) {
  46. $subject = $this->l->t('Public link expired');
  47. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) {
  48. $subject = $this->l->t('{actor} shared as public link');
  49. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) {
  50. $subject = $this->l->t('{actor} removed public link');
  51. } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) {
  52. $subject = $this->l->t('Public link of {actor} expired');
  53. } else {
  54. throw new \InvalidArgumentException();
  55. }
  56. if ($this->activityManager->getRequirePNG()) {
  57. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  58. } else {
  59. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  60. }
  61. $this->setSubjects($event, $subject, $parsedParameters);
  62. return $event;
  63. }
  64. /**
  65. * @param IEvent $event
  66. * @param IEvent|null $previousEvent
  67. * @return IEvent
  68. * @throws \InvalidArgumentException
  69. * @since 11.0.0
  70. */
  71. public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) {
  72. $parsedParameters = $this->getParsedParameters($event);
  73. if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) {
  74. $subject = $this->l->t('You shared {file} as public link');
  75. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) {
  76. $subject = $this->l->t('You removed public link for {file}');
  77. } elseif ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) {
  78. $subject = $this->l->t('Public link expired for {file}');
  79. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) {
  80. $subject = $this->l->t('{actor} shared {file} as public link');
  81. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) {
  82. $subject = $this->l->t('{actor} removed public link for {file}');
  83. } elseif ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) {
  84. $subject = $this->l->t('Public link of {actor} for {file} expired');
  85. } else {
  86. throw new \InvalidArgumentException();
  87. }
  88. if ($this->activityManager->getRequirePNG()) {
  89. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  90. } else {
  91. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  92. }
  93. $this->setSubjects($event, $subject, $parsedParameters);
  94. return $event;
  95. }
  96. protected function getParsedParameters(IEvent $event) {
  97. $subject = $event->getSubject();
  98. $parameters = $event->getSubjectParameters();
  99. switch ($subject) {
  100. case self::SUBJECT_SHARED_LINK_SELF:
  101. case self::SUBJECT_UNSHARED_LINK_SELF:
  102. case self::SUBJECT_LINK_EXPIRED:
  103. return [
  104. 'file' => $this->getFile($parameters[0], $event),
  105. ];
  106. case self::SUBJECT_RESHARED_LINK_BY:
  107. case self::SUBJECT_UNSHARED_LINK_BY:
  108. case self::SUBJECT_LINK_BY_EXPIRED:
  109. return [
  110. 'file' => $this->getFile($parameters[0], $event),
  111. 'actor' => $this->getUser($parameters[1]),
  112. ];
  113. }
  114. return [];
  115. }
  116. }