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