messageform.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Form for posting a direct 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 Form
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @author Sarven Capadisli <csarven@status.net>
  26. * @copyright 2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Form for posting a direct message
  33. *
  34. * @category Form
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @author Sarven Capadisli <csarven@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. * @see HTMLOutputter
  42. */
  43. class MessageForm extends Form
  44. {
  45. /**
  46. * User to send a direct message to
  47. */
  48. var $to = null;
  49. /**
  50. * Pre-filled content of the form
  51. */
  52. var $content = null;
  53. /**
  54. * Constructor
  55. *
  56. * @param HTMLOutputter $out output channel
  57. * @param User $to user to send a message to
  58. * @param string $content content to pre-fill
  59. */
  60. function __construct($out=null, $to=null, $content=null)
  61. {
  62. parent::__construct($out);
  63. $this->to = $to;
  64. $this->content = $content;
  65. }
  66. /**
  67. * ID of the form
  68. *
  69. * @return string ID of the form
  70. */
  71. function id()
  72. {
  73. return 'form_notice-direct';
  74. }
  75. /**
  76. * Class of the form
  77. *
  78. * @return string class of the form
  79. */
  80. function formClass()
  81. {
  82. return 'form_notice ajax-notice';
  83. }
  84. /**
  85. * Action of the form
  86. *
  87. * @return string URL of the action
  88. */
  89. function action()
  90. {
  91. return common_local_url('newmessage');
  92. }
  93. /**
  94. * Legend of the Form
  95. *
  96. * @return void
  97. */
  98. function formLegend()
  99. {
  100. // TRANS: Form legend for direct notice.
  101. $this->out->element('legend', null, _('Send a direct notice'));
  102. }
  103. /**
  104. * Data elements
  105. *
  106. * @return void
  107. */
  108. function formData()
  109. {
  110. $user = common_current_user();
  111. $mutual_users = $user->mutuallySubscribedUsers();
  112. $mutual = array();
  113. // TRANS: Label entry in drop-down selection box in direct-message inbox/outbox.
  114. // TRANS: This is the default entry in the drop-down box, doubling as instructions
  115. // TRANS: and a brake against accidental submissions with the first user in the list.
  116. $mutual[0] = _('Select recipient:');
  117. while ($mutual_users->fetch()) {
  118. if ($mutual_users->id != $user->id) {
  119. $mutual[$mutual_users->id] = $mutual_users->nickname;
  120. }
  121. }
  122. $mutual_users->free();
  123. unset($mutual_users);
  124. if (count($mutual) == 1) {
  125. // TRANS: Entry in drop-down selection box in direct-message inbox/outbox when no one is available to message.
  126. $mutual[0] = _('No mutual subscribers.');
  127. }
  128. // TRANS: Dropdown label in direct notice form.
  129. $this->out->dropdown('to', _('To'), $mutual, null, false,
  130. ($this->to) ? $this->to->id : null);
  131. $this->out->element('textarea', array('class' => 'notice_data-text',
  132. 'cols' => 35,
  133. 'rows' => 4,
  134. 'name' => 'content'),
  135. ($this->content) ? $this->content : '');
  136. $contentLimit = Message::maxContent();
  137. if ($contentLimit > 0) {
  138. $this->out->element('span',
  139. array('class' => 'count'),
  140. $contentLimit);
  141. }
  142. }
  143. /**
  144. * Action elements
  145. *
  146. * @return void
  147. */
  148. function formActions()
  149. {
  150. $this->out->element('input', array('id' => 'notice_action-submit',
  151. 'class' => 'submit',
  152. 'name' => 'message_send',
  153. 'type' => 'submit',
  154. // TRANS: Button text for sending a direct notice.
  155. 'value' => _m('Send button for sending notice', 'Send')));
  156. }
  157. /**
  158. * Show the form
  159. *
  160. * Uses a recipe to output the form.
  161. *
  162. * @return void
  163. * @see Widget::show()
  164. */
  165. function show()
  166. {
  167. $this->elementStart('div', 'input_forms');
  168. $this->elementStart(
  169. 'div',
  170. array(
  171. 'id' => 'input_form_direct',
  172. 'class' => 'input_form current nonav'
  173. )
  174. );
  175. parent::show();
  176. $this->elementEnd('div');
  177. $this->elementEnd('div');
  178. }
  179. }