]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
Merge commit 'refs/merge-requests/157' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / lib / profilelist.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Widget to show a list of profiles
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Public
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/widget.php';
35 require_once INSTALLDIR.'/lib/peopletags.php';
36
37 /**
38  * Widget to show a list of profiles
39  *
40  * @category Public
41  * @package  StatusNet
42  * @author   Zach Copley <zach@status.net>
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47 class ProfileList extends Widget
48 {
49     /** Current profile, profile query. */
50     var $profile = null;
51     /** Action object using us. */
52     var $action = null;
53
54     function __construct($profile, $action=null)
55     {
56         parent::__construct($action);
57
58         $this->profile = $profile;
59         $this->action = $action;
60     }
61
62     function show()
63     {
64         $cnt = 0;
65
66         if (Event::handle('StartProfileList', array($this))) {
67             $this->startList();
68             $cnt = $this->showProfiles();
69             $this->endList();
70             Event::handle('EndProfileList', array($this));
71         }
72
73         return $cnt;
74     }
75
76     function startList()
77     {
78         $this->out->elementStart('ul', 'profiles xoxo');
79     }
80
81     function endList()
82     {
83         $this->out->elementEnd('ul');
84     }
85
86     function showProfiles()
87     {
88         $cnt = 0;
89
90         while ($this->profile->fetch()) {
91             $cnt++;
92             if($cnt > PROFILES_PER_PAGE) {
93                 break;
94             }
95             $pli = $this->newListItem($this->profile);
96             $pli->show();
97         }
98
99         return $cnt;
100     }
101
102     function newListItem($profile)
103     {
104         return new ProfileListItem($this->profile, $this->action);
105     }
106 }
107
108 class ProfileListItem extends Widget
109 {
110     /** Current profile. */
111     var $profile = null;
112     /** Action object using us. */
113     var $action = null;
114
115     function __construct($profile, $action)
116     {
117         parent::__construct($action);
118
119         $this->profile = $profile;
120         $this->action  = $action;
121     }
122
123     function show()
124     {
125         if (Event::handle('StartProfileListItem', array($this))) {
126             $this->startItem();
127             if (Event::handle('StartProfileListItemProfile', array($this))) {
128                 $this->showProfile();
129                 Event::handle('EndProfileListItemProfile', array($this));
130             }
131             if (Event::handle('StartProfileListItemActions', array($this))) {
132                 $this->showActions();
133                 Event::handle('EndProfileListItemActions', array($this));
134             }
135             $this->endItem();
136             Event::handle('EndProfileListItem', array($this));
137         }
138     }
139
140     function startItem()
141     {
142         $this->out->elementStart('li', array('class' => 'profile hentry',
143                                              'id' => 'profile-' . $this->profile->id));
144     }
145
146     function showProfile()
147     {
148         $this->startProfile();
149         if (Event::handle('StartProfileListItemProfileElements', array($this))) {
150             if (Event::handle('StartProfileListItemAvatar', array($this))) {
151                 $this->showAvatar();
152                 Event::handle('EndProfileListItemAvatar', array($this));
153             }
154             if (Event::handle('StartProfileListItemFullName', array($this))) {
155                 $this->showFullName();
156                 Event::handle('EndProfileListItemFullName', array($this));
157             }
158             if (Event::handle('StartProfileListItemLocation', array($this))) {
159                 $this->showLocation();
160                 Event::handle('EndProfileListItemLocation', array($this));
161             }
162             if (Event::handle('StartProfileListItemHomepage', array($this))) {
163                 $this->showHomepage();
164                 Event::handle('EndProfileListItemHomepage', array($this));
165             }
166             if (Event::handle('StartProfileListItemBio', array($this))) {
167                 $this->showBio();
168                 Event::handle('EndProfileListItemBio', array($this));
169             }
170             if (Event::handle('StartProfileListItemTags', array($this))) {
171                 $this->showTags();
172                 Event::handle('EndProfileListItemTags', array($this));
173             }
174             Event::handle('EndProfileListItemProfileElements', array($this));
175         }
176         $this->endProfile();
177     }
178
179     function startProfile()
180     {
181         $this->out->elementStart('div', 'entity_profile vcard entry-content');
182     }
183
184     function showAvatar()
185     {
186         $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
187         $aAttrs = $this->linkAttributes();
188         $this->out->elementStart('a', $aAttrs);
189         $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
190                                          'class' => 'photo avatar',
191                                          'width' => AVATAR_STREAM_SIZE,
192                                          'height' => AVATAR_STREAM_SIZE,
193                                          'alt' =>
194                                          ($this->profile->fullname) ? $this->profile->fullname :
195                                          $this->profile->nickname));
196         $this->out->text(' ');
197         $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
198         $this->out->elementStart('span', $hasFN);
199         $this->out->raw($this->highlight($this->profile->nickname));
200         $this->out->elementEnd('span');
201         $this->out->elementEnd('a');
202     }
203
204     function showFullName()
205     {
206         if (!empty($this->profile->fullname)) {
207             $this->out->text(' ');
208             $this->out->elementStart('span', 'fn');
209             $this->out->raw($this->highlight($this->profile->fullname));
210             $this->out->elementEnd('span');
211         }
212     }
213
214     function showLocation()
215     {
216         if (!empty($this->profile->location)) {
217             $this->out->text(' ');
218             $this->out->elementStart('span', 'label');
219             $this->out->raw($this->highlight($this->profile->location));
220             $this->out->elementEnd('span');
221         }
222     }
223
224     function showHomepage()
225     {
226         if (!empty($this->profile->homepage)) {
227             $this->out->text(' ');
228             $aAttrs = $this->homepageAttributes();
229             $this->out->elementStart('a', $aAttrs);
230             $this->out->raw($this->highlight($this->profile->homepage));
231             $this->out->elementEnd('a');
232         }
233     }
234
235     function showBio()
236     {
237         if (!empty($this->profile->bio)) {
238             $this->out->elementStart('p', 'note');
239             $this->out->raw($this->highlight($this->profile->bio));
240             $this->out->elementEnd('p');
241         }
242     }
243
244     function showTags()
245     {
246         $user = common_current_user();
247         if (!empty($user)) {
248             if ($user->id == $this->profile->id) {
249                 $tags = new SelftagsWidget($this->out, $user, $this->profile);
250                 $tags->show();
251             } else if ($user->getProfile()->canTag($this->profile)) {
252                 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
253                 $tags->show();
254             }
255         }
256     }
257
258     function endProfile()
259     {
260         $this->out->elementEnd('div');
261     }
262
263     function showActions()
264     {
265         $this->startActions();
266         if (Event::handle('StartProfileListItemActionElements', array($this))) {
267             $this->showSubscribeButton();
268             Event::handle('EndProfileListItemActionElements', array($this));
269         }
270         $this->endActions();
271     }
272
273     function startActions()
274     {
275         $this->out->elementStart('div', 'entity_actions');
276         $this->out->elementStart('ul');
277     }
278
279     function showSubscribeButton()
280     {
281         // Is this a logged-in user, looking at someone else's
282         // profile?
283
284         $user = common_current_user();
285
286         if (!empty($user) && $this->profile->id != $user->id) {
287             $this->out->elementStart('li', 'entity_subscribe');
288             if ($user->isSubscribed($this->profile)) {
289                 $usf = new UnsubscribeForm($this->out, $this->profile);
290                 $usf->show();
291             } else {
292                 // We can't initiate sub for a remote OMB profile.
293                 $remote = Remote_profile::staticGet('id', $this->profile->id);
294                 if (empty($remote)) {
295                     $sf = new SubscribeForm($this->out, $this->profile);
296                     $sf->show();
297                 }
298             }
299             $this->out->elementEnd('li');
300         }
301     }
302
303     function endActions()
304     {
305         $this->out->elementEnd('ul');
306         $this->out->elementEnd('div');
307     }
308
309     function endItem()
310     {
311         $this->out->elementEnd('li');
312     }
313
314     function highlight($text)
315     {
316         return htmlspecialchars($text);
317     }
318
319     function linkAttributes()
320     {
321         return array('href' => $this->profile->profileurl,
322                      'class' => 'url entry-title',
323                      'rel' => 'contact');
324     }
325
326     function homepageAttributes()
327     {
328         return array('href' => $this->profile->homepage,
329                      'class' => 'url');
330     }
331 }