groups.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Latest groups information
  18. *
  19. * @category Personal
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @author Sarven Capadisli <csarven@status.net>
  23. * @copyright 2008-2009 StatusNet, Inc.
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. require_once INSTALLDIR . '/lib/groups/grouplist.php';
  28. /**
  29. * Latest groups
  30. *
  31. * Show the latest groups on the site
  32. *
  33. * @category Personal
  34. * @package GNUsocial
  35. * @author Evan Prodromou <evan@status.net>
  36. * @copyright 2008-2009 StatusNet, Inc.
  37. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  38. */
  39. class GroupsAction extends Action
  40. {
  41. public $page = null;
  42. public $profile = null;
  43. public function isReadOnly($args)
  44. {
  45. return true;
  46. }
  47. public function title()
  48. {
  49. if ($this->page == 1) {
  50. // TRANS: Title for first page of the groups list.
  51. return _m('TITLE', 'Groups');
  52. } else {
  53. // TRANS: Title for all but the first page of the groups list.
  54. // TRANS: %d is the page number.
  55. return sprintf(_m('TITLE', 'Groups, page %d'), $this->page);
  56. }
  57. }
  58. public function prepare(array $args = [])
  59. {
  60. parent::prepare($args);
  61. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  62. return true;
  63. }
  64. public function handle()
  65. {
  66. parent::handle();
  67. $this->showPage();
  68. }
  69. public function showPageNotice()
  70. {
  71. $notice =
  72. // TRANS: Page notice of group list. %%%%site.name%%%% is the StatusNet site name,
  73. // TRANS: %%%%action.groupsearch%%%% and %%%%action.newgroup%%%% are URLs. Do not change them.
  74. // TRANS: This message contains Markdown links in the form [link text](link).
  75. sprintf(_('%%%%site.name%%%% groups let you find and talk with ' .
  76. 'people of similar interests. After you join a group ' .
  77. 'you can send messages to all other members using the ' .
  78. 'syntax "!groupname". Don\'t see a group you like? Try ' .
  79. '[searching for one](%%%%action.groupsearch%%%%) or ' .
  80. '[start your own](%%%%action.newgroup%%%%)!'));
  81. $this->elementStart('div', 'instructions');
  82. $this->raw(common_markup_to_html($notice));
  83. $this->elementEnd('div');
  84. }
  85. public function showContent()
  86. {
  87. if (common_logged_in()) {
  88. $this->elementStart('p', ['id' => 'new_group']);
  89. $this->element(
  90. 'a',
  91. [
  92. 'href' => common_local_url('newgroup'),
  93. 'class' => 'more',
  94. ],
  95. // TRANS: Link to create a new group on the group list page.
  96. _('Create a new group')
  97. );
  98. $this->elementEnd('p');
  99. }
  100. $offset = ($this->page-1) * GROUPS_PER_PAGE;
  101. $limit = GROUPS_PER_PAGE + 1;
  102. $groups = new User_group();
  103. $groups->selectAdd();
  104. $groups->selectAdd('user_group.*');
  105. $groups->joinAdd(['id', 'local_group:group_id']);
  106. $groups->orderBy('user_group.created DESC, user_group.id DESC');
  107. $groups->limit($offset, $limit);
  108. $groups->find();
  109. $gl = new GroupList($groups, null, $this);
  110. $cnt = $gl->show();
  111. $this->pagination(
  112. $this->page > 1,
  113. $cnt > GROUPS_PER_PAGE,
  114. $this->page,
  115. 'groups'
  116. );
  117. }
  118. public function showSections()
  119. {
  120. $gbp = new GroupsByPostsSection($this);
  121. $gbp->show();
  122. $gbm = new GroupsByMembersSection($this);
  123. $gbm->show();
  124. }
  125. }