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