showmessage.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Show a single message
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: 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 published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (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. * @category Personal
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Show a single message
  34. *
  35. * @category Personal
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class ShowmessageAction extends Action
  42. {
  43. /**
  44. * Message object to show
  45. */
  46. var $message = null;
  47. /**
  48. * The current user
  49. */
  50. var $user = null;
  51. /**
  52. * Load attributes based on database arguments
  53. *
  54. * Loads all the DB stuff
  55. *
  56. * @param array $args $_REQUEST array
  57. *
  58. * @return success flag
  59. */
  60. function prepare($args)
  61. {
  62. parent::prepare($args);
  63. $this->page = 1;
  64. $id = $this->trimmed('message');
  65. $this->message = Message::getKV('id', $id);
  66. if (!$this->message) {
  67. // TRANS: Client error displayed requesting a single message that does not exist.
  68. $this->clientError(_('No such message.'), 404);
  69. }
  70. $this->user = common_current_user();
  71. if (empty($this->user) ||
  72. ($this->user->id != $this->message->from_profile &&
  73. $this->user->id != $this->message->to_profile)) {
  74. // TRANS: Client error displayed requesting a single direct message the requesting user was not a party in.
  75. throw new ClientException(_('Only the sender and recipient ' .
  76. 'may read this message.'), 403);
  77. }
  78. return true;
  79. }
  80. function handle($args)
  81. {
  82. $this->showPage();
  83. }
  84. function title()
  85. {
  86. if ($this->user->id == $this->message->from_profile) {
  87. $to = $this->message->getTo();
  88. // @todo FIXME: Might be nice if the timestamp could be localised.
  89. // TRANS: Page title for single direct message display when viewing user is the sender.
  90. // TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
  91. return sprintf(_('Message to %1$s on %2$s'),
  92. $to->nickname,
  93. common_exact_date($this->message->created));
  94. } else if ($this->user->id == $this->message->to_profile) {
  95. $from = $this->message->getFrom();
  96. // @todo FIXME: Might be nice if the timestamp could be localised.
  97. // TRANS: Page title for single message display.
  98. // TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
  99. return sprintf(_('Message from %1$s on %2$s'),
  100. $from->nickname,
  101. common_exact_date($this->message->created));
  102. }
  103. }
  104. function showContent()
  105. {
  106. $this->elementStart('ul', 'notices messages');
  107. $ml = new ShowMessageListItem($this, $this->message, $this->user);
  108. $ml->show();
  109. $this->elementEnd('ul');
  110. }
  111. function isReadOnly($args)
  112. {
  113. return true;
  114. }
  115. /**
  116. * Don't show aside
  117. *
  118. * @return void
  119. */
  120. function showAside() {
  121. }
  122. }
  123. class ShowMessageListItem extends MessageListItem
  124. {
  125. var $user;
  126. function __construct($out, $message, $user)
  127. {
  128. parent::__construct($out, $message);
  129. $this->user = $user;
  130. }
  131. function getMessageProfile()
  132. {
  133. if ($this->user->id == $this->message->from_profile) {
  134. return $this->message->getTo();
  135. } else if ($this->user->id == $this->message->to_profile) {
  136. return $this->message->getFrom();
  137. } else {
  138. // This shouldn't happen
  139. return null;
  140. }
  141. }
  142. }