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