]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
Merge branch '1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / lib / profilelist.php
1 <?php
2
3 /**
4  * StatusNet, 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   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 require_once INSTALLDIR.'/lib/peopletags.php';
37
38 /**
39  * Widget to show a list of profiles
40  *
41  * @category Public
42  * @package  StatusNet
43  * @author   Zach Copley <zach@status.net>
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 ProfileList extends Widget
50 {
51     /** Current profile, profile query. */
52     var $profile = null;
53     /** Action object using us. */
54     var $action = null;
55
56     function __construct($profile, $action=null)
57     {
58         parent::__construct($action);
59
60         $this->profile = $profile;
61         $this->action = $action;
62     }
63
64     function show()
65     {
66         $cnt = 0;
67
68         if (Event::handle('StartProfileList', array($this))) {
69             $this->startList();
70             $cnt = $this->showProfiles();
71             $this->endList();
72             Event::handle('EndProfileList', array($this));
73         }
74
75         return $cnt;
76     }
77
78     function startList()
79     {
80         $this->out->elementStart('ul', 'profiles xoxo');
81     }
82
83     function endList()
84     {
85         $this->out->elementEnd('ul');
86     }
87
88     function showProfiles()
89     {
90         $cnt = 0;
91
92         while ($this->profile->fetch()) {
93             $cnt++;
94             if($cnt > PROFILES_PER_PAGE) {
95                 break;
96             }
97             $pli = $this->newListItem($this->profile);
98             $pli->show();
99         }
100
101         return $cnt;
102     }
103
104     function newListItem($profile)
105     {
106         return new ProfileListItem($this->profile, $this->action);
107     }
108 }
109
110 class ProfileListItem extends Widget
111 {
112     /** Current profile. */
113     var $profile = null;
114     /** Action object using us. */
115     var $action = null;
116
117     function __construct($profile, $action)
118     {
119         parent::__construct($action);
120
121         $this->profile = $profile;
122         $this->action  = $action;
123     }
124
125     function show()
126     {
127         if (Event::handle('StartProfileListItem', array($this))) {
128             $this->startItem();
129             if (Event::handle('StartProfileListItemProfile', array($this))) {
130                 $this->showProfile();
131                 Event::handle('EndProfileListItemProfile', array($this));
132             }
133             if (Event::handle('StartProfileListItemActions', array($this))) {
134                 $this->showActions();
135                 Event::handle('EndProfileListItemActions', array($this));
136             }
137             $this->endItem();
138             Event::handle('EndProfileListItem', array($this));
139         }
140     }
141
142     function startItem()
143     {
144         $this->out->elementStart('li', array('class' => 'profile hentry',
145                                              'id' => 'profile-' . $this->profile->id));
146     }
147
148     function showProfile()
149     {
150         $this->startProfile();
151         if (Event::handle('StartProfileListItemProfileElements', array($this))) {
152             if (Event::handle('StartProfileListItemAvatar', array($this))) {
153                 $this->showAvatar();
154                 Event::handle('EndProfileListItemAvatar', array($this));
155             }
156             if (Event::handle('StartProfileListItemFullName', array($this))) {
157                 $this->showFullName();
158                 Event::handle('EndProfileListItemFullName', array($this));
159             }
160             if (Event::handle('StartProfileListItemLocation', array($this))) {
161                 $this->showLocation();
162                 Event::handle('EndProfileListItemLocation', array($this));
163             }
164             if (Event::handle('StartProfileListItemHomepage', array($this))) {
165                 $this->showHomepage();
166                 Event::handle('EndProfileListItemHomepage', array($this));
167             }
168             if (Event::handle('StartProfileListItemBio', array($this))) {
169                 $this->showBio();
170                 Event::handle('EndProfileListItemBio', array($this));
171             }
172             if (Event::handle('StartProfileListItemTags', array($this))) {
173                 $this->showTags();
174                 Event::handle('EndProfileListItemTags', array($this));
175             }
176             Event::handle('EndProfileListItemProfileElements', array($this));
177         }
178         $this->endProfile();
179     }
180
181     function startProfile()
182     {
183         $this->out->elementStart('div', 'entity_profile vcard entry-content');
184     }
185
186     function showAvatar()
187     {
188         $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
189         $aAttrs = $this->linkAttributes();
190         $this->out->elementStart('a', $aAttrs);
191         $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
192                                          'class' => 'photo avatar',
193                                          'width' => AVATAR_STREAM_SIZE,
194                                          'height' => AVATAR_STREAM_SIZE,
195                                          'alt' =>
196                                          ($this->profile->fullname) ? $this->profile->fullname :
197                                          $this->profile->nickname));
198         $this->out->text(' ');
199         $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
200         $this->out->elementStart('span', $hasFN);
201         $this->out->raw($this->highlight($this->profile->nickname));
202         $this->out->elementEnd('span');
203         $this->out->elementEnd('a');
204     }
205
206     function showFullName()
207     {
208         if (!empty($this->profile->fullname)) {
209             $this->out->text(' ');
210             $this->out->elementStart('span', 'fn');
211             $this->out->raw($this->highlight($this->profile->fullname));
212             $this->out->elementEnd('span');
213         }
214     }
215
216     function showLocation()
217     {
218         if (!empty($this->profile->location)) {
219             $this->out->text(' ');
220             $this->out->elementStart('span', 'label');
221             $this->out->raw($this->highlight($this->profile->location));
222             $this->out->elementEnd('span');
223         }
224     }
225
226     function showHomepage()
227     {
228         if (!empty($this->profile->homepage)) {
229             $this->out->text(' ');
230             $aAttrs = $this->homepageAttributes();
231             $this->out->elementStart('a', $aAttrs);
232             $this->out->raw($this->highlight($this->profile->homepage));
233             $this->out->elementEnd('a');
234         }
235     }
236
237     function showBio()
238     {
239         if (!empty($this->profile->bio)) {
240             $this->out->elementStart('p', 'note');
241             $this->out->raw($this->highlight($this->profile->bio));
242             $this->out->elementEnd('p');
243         }
244     }
245
246     function showTags()
247     {
248         $user = common_current_user();
249         if (!empty($user)) {
250             if ($user->id == $this->profile->id) {
251                 $tags = new SelftagsWidget($this->out, $user, $this->profile);
252                 $tags->show();
253             } else if ($user->getProfile()->canTag($this->profile)) {
254                 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
255                 $tags->show();
256             }
257         }
258     }
259
260     function endProfile()
261     {
262         $this->out->elementEnd('div');
263     }
264
265     function showActions()
266     {
267         $this->startActions();
268         if (Event::handle('StartProfileListItemActionElements', array($this))) {
269             $this->showSubscribeButton();
270             Event::handle('EndProfileListItemActionElements', array($this));
271         }
272         $this->endActions();
273     }
274
275     function startActions()
276     {
277         $this->out->elementStart('div', 'entity_actions');
278         $this->out->elementStart('ul');
279     }
280
281     function showSubscribeButton()
282     {
283         // Is this a logged-in user, looking at someone else's
284         // profile?
285
286         $user = common_current_user();
287
288         if (!empty($user) && $this->profile->id != $user->id) {
289             $this->out->elementStart('li', 'entity_subscribe');
290             if ($user->isSubscribed($this->profile)) {
291                 $usf = new UnsubscribeForm($this->out, $this->profile);
292                 $usf->show();
293             } else {
294                 // We can't initiate sub for a remote OMB profile.
295                 $remote = Remote_profile::staticGet('id', $this->profile->id);
296                 if (empty($remote)) {
297                     $sf = new SubscribeForm($this->out, $this->profile);
298                     $sf->show();
299                 }
300             }
301             $this->out->elementEnd('li');
302         }
303     }
304
305     function endActions()
306     {
307         $this->out->elementEnd('ul');
308         $this->out->elementEnd('div');
309     }
310
311     function endItem()
312     {
313         $this->out->elementEnd('li');
314     }
315
316     function highlight($text)
317     {
318         return htmlspecialchars($text);
319     }
320
321     function linkAttributes()
322     {
323         return array('href' => $this->profile->profileurl,
324                      'class' => 'url entry-title',
325                      'rel' => 'contact');
326     }
327
328     function homepageAttributes()
329     {
330         return array('href' => $this->profile->homepage,
331                      'class' => 'url');
332     }
333 }