groupinbox.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * List of private messages to this group
  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 list of private messages to this group
  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 GroupinboxAction extends GroupAction
  46. {
  47. var $gm;
  48. /**
  49. * For initializing members of the class.
  50. *
  51. * @param array $args misc. arguments
  52. *
  53. * @return boolean true
  54. * @throws ClientException
  55. * @throws NicknameException
  56. */
  57. function prepare(array $args = [])
  58. {
  59. parent::prepare($args);
  60. $cur = common_current_user();
  61. if (empty($cur)) {
  62. // TRANS: Client exception thrown when trying to view group inbox while not logged in.
  63. throw new ClientException(_m('Only for logged-in users.'), 403);
  64. }
  65. $nicknameArg = $this->trimmed('nickname');
  66. $nickname = common_canonical_nickname($nicknameArg);
  67. if ($nickname != $nicknameArg) {
  68. $url = common_local_url('groupinbox', array('nickname' => $nickname));
  69. common_redirect($url);
  70. }
  71. $localGroup = Local_group::getKV('nickname', $nickname);
  72. if (empty($localGroup)) {
  73. // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
  74. throw new ClientException(_m('No such group.'), 404);
  75. }
  76. $this->group = User_group::getKV('id', $localGroup->group_id);
  77. if (empty($this->group)) {
  78. // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
  79. throw new ClientException(_m('No such group.'), 404);
  80. }
  81. if (!$cur->isMember($this->group)) {
  82. // TRANS: Client exception thrown when trying to view group inbox while not a member.
  83. throw new ClientException(_m('Only for members.'), 403);
  84. }
  85. $this->page = $this->trimmed('page');
  86. if (!$this->page) {
  87. $this->page = 1;
  88. }
  89. $this->gm = Group_message::forGroup($this->group,
  90. ($this->page - 1) * MESSAGES_PER_PAGE,
  91. MESSAGES_PER_PAGE + 1);
  92. return true;
  93. }
  94. function showLocalNav()
  95. {
  96. $nav = new GroupNav($this, $this->group);
  97. $nav->show();
  98. }
  99. function showNoticeForm()
  100. {
  101. $form = new GroupMessageForm($this, $this->group);
  102. $form->show();
  103. }
  104. function showContent()
  105. {
  106. $gml = new GroupMessageList($this, $this->gm);
  107. $cnt = $gml->show();
  108. if ($cnt == 0) {
  109. // TRANS: Text of group inbox if no private messages were sent to it.
  110. $this->element('p', 'guide', _m('This group has not received any private messages.'));
  111. }
  112. $this->pagination($this->page > 1,
  113. $cnt > MESSAGES_PER_PAGE,
  114. $this->page,
  115. 'groupinbox',
  116. array('nickname' => $this->group->nickname));
  117. }
  118. /**
  119. * Handler method
  120. *
  121. * @return void
  122. */
  123. function handle()
  124. {
  125. $this->showPage();
  126. }
  127. /**
  128. * Return true if read only.
  129. *
  130. * MAY override
  131. *
  132. * @param array $args other arguments
  133. *
  134. * @return boolean is read only action?
  135. */
  136. function isReadOnly($args)
  137. {
  138. return true;
  139. }
  140. /**
  141. * Title of the page
  142. *
  143. * @return string page title, with page number
  144. */
  145. function title()
  146. {
  147. $base = $this->group->getFancyName();
  148. if ($this->page == 1) {
  149. // TRANS: Title of inbox for group %s.
  150. return sprintf(_m('%s group inbox'), $base);
  151. } else {
  152. // TRANS: Page title for any but first group page.
  153. // TRANS: %1$s is a group name, $2$s is a page number.
  154. return sprintf(_m('%1$s group inbox, page %2$d'),
  155. $base,
  156. $this->page);
  157. }
  158. }
  159. /**
  160. * Show the page notice
  161. *
  162. * Shows instructions for the page
  163. *
  164. * @return void
  165. */
  166. function showPageNotice()
  167. {
  168. $instr = $this->getInstructions();
  169. $output = common_markup_to_html($instr);
  170. $this->elementStart('div', 'instructions');
  171. $this->raw($output);
  172. $this->elementEnd('div');
  173. }
  174. /**
  175. * Instructions for using this page
  176. *
  177. * @return string localised instructions for using the page
  178. */
  179. function getInstructions()
  180. {
  181. // TRANS: Instructions for user inbox page.
  182. return _m('This is the group inbox, which lists all incoming private messages for this group.');
  183. }
  184. }