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