]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
temp debug logging hack for subscriber list early cutoff bug - we can see a cut off...
[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         $log = strtolower(get_class($this)) == 'subscriberslist' && $this->owner->nickname == 'petercook';
90         $cnt = 0;
91
92         if ($log) common_log(LOG_INFO, "subbug: starting with {$this->profile->N}");
93         while ($this->profile->fetch()) {
94             $cnt++;
95             if($cnt > PROFILES_PER_PAGE) {
96                 if ($log) common_log(LOG_INFO, "subbug: breaking at $cnt");
97                 break;
98             }
99             if ($log) common_log(LOG_INFO, "subbug: showing at $cnt");
100             $pli = $this->newListItem($this->profile);
101             $pli->show();
102         }
103         if ($log) common_log(LOG_INFO, "subbug: ended at $cnt");
104
105         return $cnt;
106     }
107
108     function newListItem($profile)
109     {
110         return new ProfileListItem($this->profile, $this->action);
111     }
112 }
113
114 class ProfileListItem extends Widget
115 {
116     /** Current profile. */
117     var $profile = null;
118     /** Action object using us. */
119     var $action = null;
120
121     function __construct($profile, $action)
122     {
123         parent::__construct($action);
124
125         $this->profile = $profile;
126         $this->action  = $action;
127     }
128
129     function show()
130     {
131         if (Event::handle('StartProfileListItem', array($this))) {
132             $this->startItem();
133             if (Event::handle('StartProfileListItemProfile', array($this))) {
134                 $this->showProfile();
135                 Event::handle('EndProfileListItemProfile', array($this));
136             }
137             if (Event::handle('StartProfileListItemActions', array($this))) {
138                 $this->showActions();
139                 Event::handle('EndProfileListItemActions', array($this));
140             }
141             $this->endItem();
142             Event::handle('EndProfileListItem', array($this));
143         }
144     }
145
146     function startItem()
147     {
148         $this->out->elementStart('li', array('class' => 'profile hentry',
149                                              'id' => 'profile-' . $this->profile->id));
150     }
151
152     function showProfile()
153     {
154         $this->startProfile();
155         if (Event::handle('StartProfileListItemProfileElements', array($this))) {
156             if (Event::handle('StartProfileListItemAvatar', array($this))) {
157                 $this->showAvatar();
158                 Event::handle('EndProfileListItemAvatar', array($this));
159             }
160             if (Event::handle('StartProfileListItemFullName', array($this))) {
161                 $this->showFullName();
162                 Event::handle('EndProfileListItemFullName', array($this));
163             }
164             if (Event::handle('StartProfileListItemLocation', array($this))) {
165                 $this->showLocation();
166                 Event::handle('EndProfileListItemLocation', array($this));
167             }
168             if (Event::handle('StartProfileListItemHomepage', array($this))) {
169                 $this->showHomepage();
170                 Event::handle('EndProfileListItemHomepage', array($this));
171             }
172             if (Event::handle('StartProfileListItemBio', array($this))) {
173                 $this->showBio();
174                 Event::handle('EndProfileListItemBio', 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         $this->out->elementStart('a', array('href' => $this->profile->profileurl,
190                                             'class' => 'url entry-title',
191                                             'rel' => 'contact'));
192         $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
193                                          'class' => 'photo avatar',
194                                          'width' => AVATAR_STREAM_SIZE,
195                                          'height' => AVATAR_STREAM_SIZE,
196                                          'alt' =>
197                                          ($this->profile->fullname) ? $this->profile->fullname :
198                                          $this->profile->nickname));
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->elementStart('span', 'fn');
210             $this->out->raw($this->highlight($this->profile->fullname));
211             $this->out->elementEnd('span');
212         }
213     }
214
215     function showLocation()
216     {
217         if (!empty($this->profile->location)) {
218             $this->out->elementStart('span', 'location');
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->elementStart('a', array('href' => $this->profile->homepage,
228                                                 'class' => 'url'));
229             $this->out->raw($this->highlight($this->profile->homepage));
230             $this->out->elementEnd('a');
231         }
232     }
233
234     function showBio()
235     {
236         if (!empty($this->profile->bio)) {
237             $this->out->elementStart('p', 'note');
238             $this->out->raw($this->highlight($this->profile->bio));
239             $this->out->elementEnd('p');
240         }
241     }
242
243     function endProfile()
244     {
245         $this->out->elementEnd('div');
246     }
247
248     function showActions()
249     {
250         $this->startActions();
251         if (Event::handle('StartProfileListItemActionElements', array($this))) {
252             $this->showSubscribeButton();
253             Event::handle('EndProfileListItemActionElements', array($this));
254         }
255         $this->endActions();
256     }
257
258     function startActions()
259     {
260         $this->out->elementStart('div', 'entity_actions');
261         $this->out->elementStart('ul');
262     }
263
264     function showSubscribeButton()
265     {
266         // Is this a logged-in user, looking at someone else's
267         // profile?
268
269         $user = common_current_user();
270
271         if (!empty($user) && $this->profile->id != $user->id) {
272             $this->out->elementStart('li', 'entity_subscribe');
273             if ($user->isSubscribed($this->profile)) {
274                 $usf = new UnsubscribeForm($this->out, $this->profile);
275                 $usf->show();
276             } else {
277                 // Is it a local user? can't remote sub from a list
278                 // XXX: make that possible!
279                 $other = User::staticGet('id', $this->profile->id);
280                 if (!empty($other)) {
281                     $sf = new SubscribeForm($this->out, $this->profile);
282                     $sf->show();
283                 }
284             }
285             $this->out->elementEnd('li');
286         }
287     }
288
289     function endActions()
290     {
291         $this->out->elementEnd('ul');
292         $this->out->elementEnd('div');
293     }
294
295     function endItem()
296     {
297         $this->out->elementEnd('li');
298     }
299
300     function highlight($text)
301     {
302         return htmlspecialchars($text);
303     }
304 }