]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/grouplist.php
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[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         $hasFN = ($this->group->fullname) ? 'nickname' : 'fn org nickname';
109         $this->out->elementStart('span', $hasFN);
110         $this->out->raw($this->highlight($this->group->nickname));
111         $this->out->elementEnd('span');
112         $this->out->elementEnd('a');
113
114         if ($this->group->fullname) {
115             $this->out->elementStart('span', 'fn org');
116             $this->out->raw($this->highlight($this->group->fullname));
117             $this->out->elementEnd('span');
118         }
119         if ($this->group->location) {
120             $this->out->elementStart('span', 'label');
121             $this->out->raw($this->highlight($this->group->location));
122             $this->out->elementEnd('span');
123         }
124         if ($this->group->homepage) {
125             $this->out->elementStart('a', array('href' => $this->group->homepage,
126                                                 'class' => 'url'));
127             $this->out->raw($this->highlight($this->group->homepage));
128             $this->out->elementEnd('a');
129         }
130         if ($this->group->description) {
131             $this->out->elementStart('p', 'note');
132             $this->out->raw($this->highlight($this->group->description));
133             $this->out->elementEnd('p');
134         }
135
136         # If we're on a list with an owner (subscriptions or subscribers)...
137
138         if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) {
139             $this->showOwnerControls();
140         }
141
142         $this->out->elementEnd('div');
143
144         if ($user) {
145             $this->out->elementStart('div', 'entity_actions');
146             $this->out->elementStart('ul');
147             $this->out->elementStart('li', 'entity_subscribe');
148             # XXX: special-case for user looking at own
149             # subscriptions page
150             if ($user->isMember($this->group)) {
151                 $lf = new LeaveForm($this->out, $this->group);
152                 $lf->show();
153             } else if (!Group_block::isBlocked($this->group, $user->getProfile())) {
154                 $jf = new JoinForm($this->out, $this->group);
155                 $jf->show();
156             }
157             $this->out->elementEnd('li');
158             $this->out->elementEnd('ul');
159             $this->out->elementEnd('div');
160         }
161
162         $this->out->elementEnd('li');
163     }
164
165     /* Override this in subclasses. */
166
167     function showOwnerControls()
168     {
169         return;
170     }
171
172     function highlight($text)
173     {
174         return htmlspecialchars($text);
175     }
176 }