showgroup.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Group main page
  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 Group
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @author Sarven Capadisli <csarven@status.net>
  26. * @copyright 2008-2011 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('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. require_once INSTALLDIR.'/lib/noticelist.php';
  34. require_once INSTALLDIR.'/lib/feedlist.php';
  35. /**
  36. * Group main page
  37. *
  38. * @category Group
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@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 ShowgroupAction extends GroupAction
  45. {
  46. /** page we're viewing. */
  47. var $page = null;
  48. var $userProfile = null;
  49. var $notice = null;
  50. /**
  51. * Is this page read-only?
  52. *
  53. * @return boolean true
  54. */
  55. function isReadOnly($args)
  56. {
  57. return true;
  58. }
  59. /**
  60. * Title of the page
  61. *
  62. * @return string page title, with page number
  63. */
  64. function title()
  65. {
  66. $base = $this->group->getFancyName();
  67. if ($this->page == 1) {
  68. // TRANS: Page title for first group page. %s is a group name.
  69. return sprintf(_('%s group'), $base);
  70. } else {
  71. // TRANS: Page title for any but first group page.
  72. // TRANS: %1$s is a group name, $2$s is a page number.
  73. return sprintf(_('%1$s group, page %2$d'),
  74. $base,
  75. $this->page);
  76. }
  77. }
  78. /**
  79. * Prepare the action
  80. *
  81. * Reads and validates arguments and instantiates the attributes.
  82. *
  83. * @param array $args $_REQUEST args
  84. *
  85. * @return boolean success flag
  86. */
  87. protected function prepare(array $args=array())
  88. {
  89. parent::prepare($args);
  90. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  91. $this->userProfile = Profile::current();
  92. $user = common_current_user();
  93. if (!empty($user) && $user->streamModeOnly()) {
  94. $stream = new GroupNoticeStream($this->group, $this->userProfile);
  95. } else {
  96. $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile);
  97. }
  98. $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  99. NOTICES_PER_PAGE + 1);
  100. common_set_returnto($this->selfUrl());
  101. return true;
  102. }
  103. /**
  104. * Handle the request
  105. *
  106. * Shows a profile for the group, some controls, and a list of
  107. * group notices.
  108. *
  109. * @return void
  110. */
  111. protected function handle()
  112. {
  113. parent::handle();
  114. $this->showPage();
  115. }
  116. /**
  117. * Show the page content
  118. *
  119. * Shows a group profile and a list of group notices
  120. */
  121. function showContent()
  122. {
  123. $this->showGroupNotices();
  124. }
  125. /**
  126. * Show the group notices
  127. *
  128. * @return void
  129. */
  130. function showGroupNotices()
  131. {
  132. $user = common_current_user();
  133. if (!empty($user) && $user->streamModeOnly()) {
  134. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  135. } else {
  136. $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
  137. }
  138. $cnt = $nl->show();
  139. $this->pagination($this->page > 1,
  140. $cnt > NOTICES_PER_PAGE,
  141. $this->page,
  142. 'showgroup',
  143. array('nickname' => $this->group->nickname));
  144. }
  145. /**
  146. * Get a list of the feeds for this page
  147. *
  148. * @return void
  149. */
  150. function getFeeds()
  151. {
  152. $url =
  153. common_local_url('grouprss',
  154. array('nickname' => $this->group->nickname));
  155. return array(new Feed(Feed::JSON,
  156. common_local_url('ApiTimelineGroup',
  157. array('format' => 'as',
  158. 'id' => $this->group->id)),
  159. // TRANS: Tooltip for feed link. %s is a group nickname.
  160. sprintf(_('Notice feed for %s group (Activity Streams JSON)'),
  161. $this->group->nickname)),
  162. new Feed(Feed::RSS1,
  163. common_local_url('grouprss',
  164. array('nickname' => $this->group->nickname)),
  165. // TRANS: Tooltip for feed link. %s is a group nickname.
  166. sprintf(_('Notice feed for %s group (RSS 1.0)'),
  167. $this->group->nickname)),
  168. new Feed(Feed::RSS2,
  169. common_local_url('ApiTimelineGroup',
  170. array('format' => 'rss',
  171. 'id' => $this->group->id)),
  172. // TRANS: Tooltip for feed link. %s is a group nickname.
  173. sprintf(_('Notice feed for %s group (RSS 2.0)'),
  174. $this->group->nickname)),
  175. new Feed(Feed::ATOM,
  176. common_local_url('ApiTimelineGroup',
  177. array('format' => 'atom',
  178. 'id' => $this->group->id)),
  179. // TRANS: Tooltip for feed link. %s is a group nickname.
  180. sprintf(_('Notice feed for %s group (Atom)'),
  181. $this->group->nickname)),
  182. new Feed(Feed::FOAF,
  183. common_local_url('foafgroup',
  184. array('nickname' => $this->group->nickname)),
  185. // TRANS: Tooltip for feed link. %s is a group nickname.
  186. sprintf(_('FOAF for %s group'),
  187. $this->group->nickname)));
  188. }
  189. function showAnonymousMessage()
  190. {
  191. if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
  192. // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
  193. // TRANS: %s is the group name, %%%%site.name%%%% is the site name,
  194. // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
  195. // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
  196. $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  197. 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
  198. 'short messages about their life and interests. '.
  199. '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
  200. $this->group->getBestName());
  201. } else {
  202. // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
  203. // TRANS: %s is the group name, %%%%site.name%%%% is the site name,
  204. // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
  205. $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  206. 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
  207. 'short messages about their life and interests.'),
  208. $this->group->getBestName());
  209. }
  210. $this->elementStart('div', array('id' => 'anon_notice'));
  211. $this->raw(common_markup_to_html($m));
  212. $this->elementEnd('div');
  213. }
  214. function extraHead()
  215. {
  216. if ($this->page != 1) {
  217. $this->element('link', array('rel' => 'canonical',
  218. 'href' => $this->group->homeUrl()));
  219. }
  220. }
  221. }