groupinbox.php 6.0 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 $argarray misc. arguments
  52. *
  53. * @return boolean true
  54. */
  55. function prepare($argarray)
  56. {
  57. parent::prepare($argarray);
  58. $cur = common_current_user();
  59. if (empty($cur)) {
  60. // TRANS: Client exception thrown when trying to view group inbox while not logged in.
  61. throw new ClientException(_m('Only for logged-in users.'), 403);
  62. }
  63. $nicknameArg = $this->trimmed('nickname');
  64. $nickname = common_canonical_nickname($nicknameArg);
  65. if ($nickname != $nicknameArg) {
  66. $url = common_local_url('groupinbox', array('nickname' => $nickname));
  67. common_redirect($url);
  68. }
  69. $localGroup = Local_group::getKV('nickname', $nickname);
  70. if (empty($localGroup)) {
  71. // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
  72. throw new ClientException(_m('No such group.'), 404);
  73. }
  74. $this->group = User_group::getKV('id', $localGroup->group_id);
  75. if (empty($this->group)) {
  76. // TRANS: Client exception thrown when trying to view group inbox for non-existing group.
  77. throw new ClientException(_m('No such group.'), 404);
  78. }
  79. if (!$cur->isMember($this->group)) {
  80. // TRANS: Client exception thrown when trying to view group inbox while not a member.
  81. throw new ClientException(_m('Only for members.'), 403);
  82. }
  83. $this->page = $this->trimmed('page');
  84. if (!$this->page) {
  85. $this->page = 1;
  86. }
  87. $this->gm = Group_message::forGroup($this->group,
  88. ($this->page - 1) * MESSAGES_PER_PAGE,
  89. MESSAGES_PER_PAGE + 1);
  90. return true;
  91. }
  92. function showLocalNav()
  93. {
  94. $nav = new GroupNav($this, $this->group);
  95. $nav->show();
  96. }
  97. function showNoticeForm()
  98. {
  99. $form = new GroupMessageForm($this, $this->group);
  100. $form->show();
  101. }
  102. function showContent()
  103. {
  104. $gml = new GroupMessageList($this, $this->gm);
  105. $cnt = $gml->show();
  106. if ($cnt == 0) {
  107. // TRANS: Text of group inbox if no private messages were sent to it.
  108. $this->element('p', 'guide', _m('This group has not received any private messages.'));
  109. }
  110. $this->pagination($this->page > 1,
  111. $cnt > MESSAGES_PER_PAGE,
  112. $this->page,
  113. 'groupinbox',
  114. array('nickname' => $this->group->nickname));
  115. }
  116. /**
  117. * Handler method
  118. *
  119. * @param array $argarray is ignored since it's now passed in in prepare()
  120. *
  121. * @return void
  122. */
  123. function handle($argarray=null)
  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. }