newmessage.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Handler for posting new messages
  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. * @author Zach Copley <zach@status.net>
  26. * @author Sarven Capadisli <csarven@status.net>
  27. * @copyright 2008-2009 StatusNet, Inc.
  28. * @copyright 2013 Free Software Foundation, Inc.
  29. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  30. * @link http://status.net/
  31. */
  32. if (!defined('GNUSOCIAL')) { exit(1); }
  33. /**
  34. * Action for posting new direct messages
  35. *
  36. * @category Personal
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @author Zach Copley <zach@status.net>
  40. * @author Sarven Capadisli <csarven@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  42. * @link http://status.net/
  43. */
  44. class NewmessageAction extends FormAction
  45. {
  46. var $content = null;
  47. var $to = null;
  48. var $other = null;
  49. protected $form = 'Message'; // will become MessageForm later
  50. /**
  51. * Title of the page
  52. *
  53. * Note that this usually doesn't get called unless something went wrong
  54. *
  55. * @return string page title
  56. */
  57. function title()
  58. {
  59. // TRANS: Page title for new direct message page.
  60. return _('New message');
  61. }
  62. protected function doPreparation()
  63. {
  64. $this->content = $this->trimmed('content');
  65. $this->to = $this->trimmed('to');
  66. if ($this->to) {
  67. $this->other = Profile::getKV('id', $this->to);
  68. if (!$this->other instanceof Profile) {
  69. // TRANS: Client error displayed trying to send a direct message to a non-existing user.
  70. $this->clientError(_('No such user.'), 404);
  71. }
  72. if (!$this->other->isLocal()) {
  73. // TRANS: Explains that current federation does not support direct, private messages yet.
  74. $this->clientError(_('You cannot send direct messages to federated users yet.'));
  75. }
  76. if (!$this->scoped->mutuallySubscribed($this->other)) {
  77. // TRANS: Client error displayed trying to send a direct message to a user while sender and
  78. // TRANS: receiver are not subscribed to each other.
  79. $this->clientError(_('You cannot send a message to this user.'), 404);
  80. }
  81. }
  82. return true;
  83. }
  84. protected function doPost()
  85. {
  86. assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
  87. if (empty($this->content)) {
  88. // TRANS: Form validator error displayed trying to send a direct message without content.
  89. $this->clientError(_('No content!'));
  90. }
  91. $content_shortened = $this->scoped->shortenLinks($this->content);
  92. if (Message::contentTooLong($content_shortened)) {
  93. // TRANS: Form validation error displayed when message content is too long.
  94. // TRANS: %d is the maximum number of characters for a message.
  95. $this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
  96. 'That\'s too long. Maximum message size is %d characters.',
  97. Message::maxContent()),
  98. Message::maxContent()));
  99. }
  100. if (!$this->other instanceof Profile) {
  101. // TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
  102. $this->clientError(_('No recipient specified.'));
  103. } else if (!$this->scoped->mutuallySubscribed($this->other)) {
  104. // TRANS: Client error displayed trying to send a direct message to a user while sender and
  105. // TRANS: receiver are not subscribed to each other.
  106. $this->clientError(_('You cannot send a message to this user.'), 404);
  107. } else if ($this->scoped->id == $this->other->id) {
  108. // TRANS: Client error displayed trying to send a direct message to self.
  109. $this->clientError(_('Do not send a message to yourself; ' .
  110. 'just say it to yourself quietly instead.'), 403);
  111. }
  112. $message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
  113. $message->notify();
  114. if (GNUsocial::isAjax()) {
  115. // TRANS: Confirmation text after sending a direct message.
  116. // TRANS: %s is the direct message recipient.
  117. return sprintf(_('Direct message to %s sent.'), $this->other->getNickname());
  118. }
  119. $url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
  120. common_redirect($url, 303);
  121. }
  122. function showNoticeForm()
  123. {
  124. // Just don't show a NoticeForm
  125. }
  126. }