]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
75053b7a42c6cdb90014b15f026ece5b848a5c9e
[quix0rs-gnu-social.git] / lib / profilelist.php
1 <?php
2
3 /**
4  * Laconica, the distributed open-source microblogging tool
5  *
6  * Widget to show a list of profiles
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   Laconica
25  * @author    Evan Prodromou <evan@controlyourself.ca>
26  * @copyright 2008-2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/widget.php';
36
37 /**
38  * Widget to show a list of profiles
39  *
40  * @category Public
41  * @package  Laconica
42  * @author   Zach Copley <zach@controlyourself.ca>
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://laconi.ca/
46  */
47
48 class ProfileList extends Widget
49 {
50     /** Current profile, profile query. */
51     var $profile = null;
52     /** Owner of this list */
53     var $owner = null;
54     /** Action object using us. */
55     var $action = null;
56
57     function __construct($profile, $owner=null, $action=null)
58     {
59         parent::__construct($action);
60
61         $this->profile = $profile;
62         $this->owner = $owner;
63         $this->action = $action;
64     }
65
66     function show()
67     {
68
69         $this->out->elementStart('ul', 'profiles');
70
71         $cnt = 0;
72
73         while ($this->profile->fetch()) {
74             $cnt++;
75             if($cnt > PROFILES_PER_PAGE) {
76                 break;
77             }
78             $this->showProfile();
79         }
80
81         $this->out->elementEnd('ul');
82
83         return $cnt;
84     }
85
86     function showProfile()
87     {
88         $this->out->elementStart('li', array('class' => 'profile',
89                                              'id' => 'profile-' . $this->profile->id));
90
91         $user = common_current_user();
92
93         $this->out->elementStart('div', 'entity_profile vcard');
94
95         $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
96         $this->out->elementStart('a', array('href' => $this->profile->profileurl,
97                                             'class' => 'url'));
98         $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
99                                          'class' => 'photo avatar',
100                                          'width' => AVATAR_STREAM_SIZE,
101                                          'height' => AVATAR_STREAM_SIZE,
102                                          'alt' =>
103                                          ($this->profile->fullname) ? $this->profile->fullname :
104                                          $this->profile->nickname));
105         $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname';
106         $this->out->elementStart('span', $hasFN);
107         $this->out->raw($this->highlight($this->profile->nickname));
108         $this->out->elementEnd('span');
109         $this->out->elementEnd('a');
110
111         if ($this->profile->fullname !== '') {
112             $this->out->elementStart('dl', 'entity_fn');
113             $this->out->element('dt', null, 'Full name');
114             $this->out->elementStart('dd');
115             $this->out->elementStart('span', 'fn');
116             $this->out->raw($this->highlight($this->profile->fullname));
117             $this->out->elementEnd('span');
118             $this->out->elementEnd('dd');
119             $this->out->elementEnd('dl');
120         }
121         if ($this->profile->location !== '') {
122             $this->out->elementStart('dl', 'entity_location');
123             $this->out->element('dt', null, _('Location'));
124             $this->out->elementStart('dd', 'label');
125             $this->out->raw($this->highlight($this->profile->location));
126             $this->out->elementEnd('dd');
127             $this->out->elementEnd('dl');
128         }
129         if ($this->profile->homepage !== '') {
130             $this->out->elementStart('dl', 'entity_url');
131             $this->out->element('dt', null, _('URL'));
132             $this->out->elementStart('dd');
133             $this->out->elementStart('a', array('href' => $this->profile->homepage,
134                                                 'class' => 'url'));
135             $this->out->raw($this->highlight($this->profile->homepage));
136             $this->out->elementEnd('a');
137             $this->out->elementEnd('dd');
138             $this->out->elementEnd('dl');
139         }
140         if ($this->profile->bio !== '') {
141             $this->out->elementStart('dl', 'entity_note');
142             $this->out->element('dt', null, _('Note'));
143             $this->out->elementStart('dd', 'note');
144             $this->out->raw($this->highlight($this->profile->bio));
145             $this->out->elementEnd('dd');
146             $this->out->elementEnd('dl');
147         }
148
149         # If we're on a list with an owner (subscriptions or subscribers)...
150
151         if ($this->owner) {
152             # Get tags
153             $tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
154
155             $this->out->elementStart('dl', 'entity_tags');
156             $this->out->elementStart('dt');
157             if ($user->id == $this->owner->id) {
158                 $this->out->element('a', array('href' => common_local_url('tagother',
159                                                                           array('id' => $this->profile->id))),
160                                     _('Tags'));
161             } else {
162                 $this->out->text(_('Tags'));
163             }
164             $this->out->elementEnd('dt');
165             $this->out->elementStart('dd');
166             if ($tags) {
167                 $this->out->elementStart('ul', 'tags xoxo');
168                 foreach ($tags as $tag) {
169                     $this->out->elementStart('li');
170                     $this->out->element('span', 'mark_hash', '#');
171                     $this->out->element('a', array('rel' => 'tag',
172                                                    'href' => common_local_url($this->action->trimmed('action'),
173                                                                               array('nickname' => $this->owner->nickname,
174                                                                                     'tag' => $tag))),
175                                         $tag);
176                     $this->out->elementEnd('li');
177                 }
178                 $this->out->elementEnd('ul');
179             } else {
180                 $this->out->text(_('(none)'));
181             }
182             $this->out->elementEnd('dd');
183             $this->out->elementEnd('dl');
184         }
185
186         if ($user && $user->id == $this->owner->id) {
187             $this->showOwnerControls($this->profile);
188         }
189
190         $this->out->elementEnd('div');
191
192         $this->out->elementStart('div', 'entity_actions');
193
194         $this->out->elementStart('ul');
195
196         if ($user && $user->id != $this->profile->id) {
197             # XXX: special-case for user looking at own
198             # subscriptions page
199             $this->out->elementStart('li', 'entity_subscribe');
200             if ($user->isSubscribed($this->profile)) {
201                 $usf = new UnsubscribeForm($this->out, $this->profile);
202                 $usf->show();
203             } else {
204                 $sf = new SubscribeForm($this->out, $this->profile);
205                 $sf->show();
206             }
207             $this->out->elementEnd('li');
208             $this->out->elementStart('li', 'entity_block');
209             if ($user && $user->id == $this->owner->id) {
210                 $this->showBlockForm();
211             }
212             $this->out->elementEnd('li');
213         }
214
215         $this->out->elementEnd('ul');
216
217         $this->out->elementEnd('div');
218
219         $this->out->elementEnd('li');
220     }
221
222     /* Override this in subclasses. */
223
224     function showOwnerControls($profile)
225     {
226         return;
227     }
228
229     function highlight($text)
230     {
231         return htmlspecialchars($text);
232     }
233
234     function showBlockForm()
235     {
236     }
237 }