PublicLinks.php 4.6 KB

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