]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/grouplist.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / lib / grouplist.php
1 <?php
2
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Widget to show a list of groups
7  *
8  * PHP version 5
9  *
10  * LICENCE: 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  Public
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@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/widget.php';
36
37 define('GROUPS_PER_PAGE', 20);
38
39 /**
40  * Widget to show a list of groups
41  *
42  * @category Public
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
49 class GroupList extends Widget
50 {
51     /** Current group, group query. */
52     var $group = null;
53     /** Owner of this list */
54     var $owner = null;
55     /** Action object using us. */
56     var $action = null;
57
58     function __construct($group, $owner=null, $action=null)
59     {
60         parent::__construct($action);
61
62         $this->group = $group;
63         $this->owner = $owner;
64         $this->action = $action;
65     }
66
67     function show()
68     {
69         $this->out->elementStart('ul', 'profiles groups xoxo');
70
71         $cnt = 0;
72
73         while ($this->group->fetch()) {
74             $cnt++;
75             if($cnt > GROUPS_PER_PAGE) {
76                 break;
77             }
78             $this->showgroup();
79         }
80
81         $this->out->elementEnd('ul');
82
83         return $cnt;
84     }
85
86     function showGroup()
87     {
88         $this->out->elementStart('li', array('class' => 'profile hentry',
89                                              'id' => 'group-' . $this->group->id));
90
91         $user = common_current_user();
92
93         $this->out->elementStart('div', 'entity_profile vcard entry-content');
94
95         $logo = ($this->group->stream_logo) ?
96           $this->group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
97
98         $this->out->elementStart('a', array('href' => $this->group->homeUrl(),
99                                             'class' => 'url entry-title',
100                                             'rel' => 'contact group'));
101         $this->out->element('img', array('src' => $logo,
102                                          'class' => 'photo avatar',
103                                          'width' => AVATAR_STREAM_SIZE,
104                                          'height' => AVATAR_STREAM_SIZE,
105                                          'alt' =>
106                                          ($this->group->fullname) ? $this->group->fullname :
107                                          $this->group->nickname));
108         $this->out->text(' ');
109         $hasFN = ($this->group->fullname) ? 'nickname' : 'fn org nickname';
110         $this->out->elementStart('span', $hasFN);
111         $this->out->raw($this->highlight($this->group->nickname));
112         $this->out->elementEnd('span');
113         $this->out->elementEnd('a');
114
115         if ($this->group->fullname) {
116             $this->out->text(' ');
117             $this->out->elementStart('span', 'fn org');
118             $this->out->raw($this->highlight($this->group->fullname));
119             $this->out->elementEnd('span');
120         }
121         if ($this->group->location) {
122             $this->out->text(' ');
123             $this->out->elementStart('span', 'label');
124             $this->out->raw($this->highlight($this->group->location));
125             $this->out->elementEnd('span');
126         }
127         if ($this->group->homepage) {
128             $this->out->text(' ');
129             $this->out->elementStart('a', array('href' => $this->group->homepage,
130                                                 'class' => 'url'));
131             $this->out->raw($this->highlight($this->group->homepage));
132             $this->out->elementEnd('a');
133         }
134         if ($this->group->description) {
135             $this->out->elementStart('p', 'note');
136             $this->out->raw($this->highlight($this->group->description));
137             $this->out->elementEnd('p');
138         }
139
140         # If we're on a list with an owner (subscriptions or subscribers)...
141
142         if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
143             $this->showOwnerControls();
144         }
145
146         $this->out->elementEnd('div');
147
148         if ($user) {
149             $this->out->elementStart('div', 'entity_actions');
150             $this->out->elementStart('ul');
151             $this->out->elementStart('li', 'entity_subscribe');
152             # XXX: special-case for user looking at own
153             # subscriptions page
154             if ($user->isMember($this->group)) {
155                 $lf = new LeaveForm($this->out, $this->group);
156                 $lf->show();
157             } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
158                 $jf = new JoinForm($this->out, $this->group);
159                 $jf->show();
160             }
161             $this->out->elementEnd('li');
162             $this->out->elementEnd('ul');
163             $this->out->elementEnd('div');
164         }
165
166         $this->out->elementEnd('li');
167     }
168
169     /* Override this in subclasses. */
170
171     function showOwnerControls()
172     {
173         return;
174     }
175
176     function highlight($text)
177     {
178         return htmlspecialchars($text);
179     }
180 }