groups.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Latest groups information
  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 Sarven Capadisli <csarven@status.net>
  26. * @copyright 2008-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('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. require_once INSTALLDIR.'/lib/grouplist.php';
  34. /**
  35. * Latest groups
  36. *
  37. * Show the latest groups on the site
  38. *
  39. * @category Personal
  40. * @package StatusNet
  41. * @author Evan Prodromou <evan@status.net>
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  43. * @link http://status.net/
  44. */
  45. class GroupsAction extends Action
  46. {
  47. var $page = null;
  48. var $profile = null;
  49. function isReadOnly($args)
  50. {
  51. return true;
  52. }
  53. function title()
  54. {
  55. if ($this->page == 1) {
  56. // TRANS: Title for first page of the groups list.
  57. return _m('TITLE',"Groups");
  58. } else {
  59. // TRANS: Title for all but the first page of the groups list.
  60. // TRANS: %d is the page number.
  61. return sprintf(_m('TITLE',"Groups, page %d"), $this->page);
  62. }
  63. }
  64. function prepare(array $args = array())
  65. {
  66. parent::prepare($args);
  67. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  68. return true;
  69. }
  70. function handle()
  71. {
  72. parent::handle();
  73. $this->showPage();
  74. }
  75. function showPageNotice()
  76. {
  77. $notice =
  78. // TRANS: Page notice of group list. %%%%site.name%%%% is the StatusNet site name,
  79. // TRANS: %%%%action.groupsearch%%%% and %%%%action.newgroup%%%% are URLs. Do not change them.
  80. // TRANS: This message contains Markdown links in the form [link text](link).
  81. sprintf(_('%%%%site.name%%%% groups let you find and talk with ' .
  82. 'people of similar interests. After you join a group ' .
  83. 'you can send messages to all other members using the ' .
  84. 'syntax "!groupname". Don\'t see a group you like? Try ' .
  85. '[searching for one](%%%%action.groupsearch%%%%) or ' .
  86. '[start your own](%%%%action.newgroup%%%%)!'));
  87. $this->elementStart('div', 'instructions');
  88. $this->raw(common_markup_to_html($notice));
  89. $this->elementEnd('div');
  90. }
  91. function showContent()
  92. {
  93. if (common_logged_in()) {
  94. $this->elementStart('p', array('id' => 'new_group'));
  95. $this->element('a', array('href' => common_local_url('newgroup'),
  96. 'class' => 'more'),
  97. // TRANS: Link to create a new group on the group list page.
  98. _('Create a new group'));
  99. $this->elementEnd('p');
  100. }
  101. $offset = ($this->page-1) * GROUPS_PER_PAGE;
  102. $limit = GROUPS_PER_PAGE + 1;
  103. $qry = 'SELECT user_group.* '.
  104. 'from user_group join local_group on user_group.id = local_group.group_id '.
  105. 'order by user_group.created desc '.
  106. 'limit ' . $limit . ' offset ' . $offset;
  107. $groups = new User_group();
  108. $cnt = 0;
  109. $groups->query($qry);
  110. $gl = new GroupList($groups, null, $this);
  111. $cnt = $gl->show();
  112. $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
  113. $this->page, 'groups');
  114. }
  115. function showSections()
  116. {
  117. $gbp = new GroupsByPostsSection($this);
  118. $gbp->show();
  119. $gbm = new GroupsByMembersSection($this);
  120. $gbm->show();
  121. }
  122. }