showgroupmessage.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Show a single group message
  7. *
  8. * PHP version 5
  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 published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (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. * @category GroupPrivateMessage
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Show a single private group message
  37. *
  38. * @category GroupPrivateMessage
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2011 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class ShowgroupmessageAction extends Action
  46. {
  47. var $gm;
  48. var $group;
  49. var $sender;
  50. var $user;
  51. /**
  52. * For initializing members of the class.
  53. *
  54. * @param array $argarray misc. arguments
  55. *
  56. * @return boolean true
  57. */
  58. function prepare($argarray)
  59. {
  60. parent::prepare($argarray);
  61. $this->user = common_current_user();
  62. if (empty($this->user)) {
  63. // TRANS: Client exception thrown when trying to view group private messages without being logged in.
  64. throw new ClientException(_m('Only logged-in users can view private messages.'),
  65. 403);
  66. }
  67. $id = $this->trimmed('id');
  68. $this->gm = Group_message::getKV('id', $id);
  69. if (empty($this->gm)) {
  70. // TRANS: Client exception thrown when trying to view a non-existing group private message.
  71. throw new ClientException(_m('No such message.'), 404);
  72. }
  73. $this->group = User_group::getKV('id', $this->gm->to_group);
  74. if (empty($this->group)) {
  75. // TRANS: Server exception thrown when trying to view group private messages for a non-exsting group.
  76. throw new ServerException(_m('Group not found.'));
  77. }
  78. if (!$this->user->isMember($this->group)) {
  79. // TRANS: Client exception thrown when trying to view a group private message without being a group member.
  80. throw new ClientException(_m('Cannot read message.'), 403);
  81. }
  82. $this->sender = Profile::getKV('id', $this->gm->from_profile);
  83. if (empty($this->sender)) {
  84. // TRANS: Server exception thrown when trying to view a group private message without a sender.
  85. throw new ServerException(_m('No sender found.'));
  86. }
  87. return true;
  88. }
  89. /**
  90. * Handler method
  91. *
  92. * @param array $argarray is ignored since it's now passed in in prepare()
  93. *
  94. * @return void
  95. */
  96. function handle($argarray=null)
  97. {
  98. $this->showPage();
  99. }
  100. /**
  101. * Title of the page
  102. */
  103. function title()
  104. {
  105. // TRANS: Title for private group message.
  106. // TRANS: %1$s is the sender name, %2$s is the group name, %3$s is a timestamp.
  107. return sprintf(_m('Message from %1$s to group %2$s on %3$s'),
  108. $this->sender->nickname,
  109. $this->group->nickname,
  110. common_exact_date($this->gm->created));
  111. }
  112. /**
  113. * Show the content area.
  114. */
  115. function showContent()
  116. {
  117. $this->elementStart('ul', 'notices messages');
  118. $gmli = new GroupMessageListItem($this, $this->gm);
  119. $gmli->show();
  120. $this->elementEnd('ul');
  121. }
  122. /**
  123. * Return true if read only.
  124. *
  125. * MAY override
  126. *
  127. * @param array $args other arguments
  128. *
  129. * @return boolean is read only action?
  130. */
  131. function isReadOnly($args)
  132. {
  133. return true;
  134. }
  135. /**
  136. * Return last modified, if applicable.
  137. *
  138. * MAY override
  139. *
  140. * @return string last modified http header
  141. */
  142. function lastModified()
  143. {
  144. return max(strtotime($this->group->modified),
  145. strtotime($this->sender->modified),
  146. strtotime($this->gm->modified));
  147. }
  148. /**
  149. * Return etag, if applicable.
  150. *
  151. * MAY override
  152. *
  153. * @return string etag http header
  154. */
  155. function etag()
  156. {
  157. try {
  158. $avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
  159. $avtime = strtotime($avatar->modified);
  160. } catch (Exception $e) {
  161. $avtime = 0;
  162. }
  163. return 'W/"' . implode(':', array($this->arg('action'),
  164. common_user_cache_hash(),
  165. common_language(),
  166. $this->gm->id,
  167. strtotime($this->sender->modified),
  168. strtotime($this->group->modified),
  169. $avtime)) . '"';
  170. }
  171. }