]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
define LACONICA and accept LACONICA for backwards compatibility
[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         $this->startList();
66         $cnt = $this->showProfiles();
67         $this->endList();
68         return $cnt;
69     }
70
71     function startList()
72     {
73         $this->out->elementStart('ul', 'profiles');
74     }
75
76     function endList()
77     {
78         $this->out->elementEnd('ul');
79     }
80
81     function showProfiles()
82     {
83         $cnt = 0;
84
85         while ($this->profile->fetch()) {
86             $cnt++;
87             if($cnt > PROFILES_PER_PAGE) {
88                 break;
89             }
90             $pli = $this->newListItem($this->profile);
91             $pli->show();
92         }
93
94         return $cnt;
95     }
96
97     function newListItem($profile)
98     {
99         return new ProfileListItem($this->profile, $this->action);
100     }
101 }
102
103 class ProfileListItem extends Widget
104 {
105     /** Current profile. */
106     var $profile = null;
107     /** Action object using us. */
108     var $action = null;
109
110     function __construct($profile, $action)
111     {
112         parent::__construct($action);
113
114         $this->profile = $profile;
115         $this->action  = $action;
116     }
117
118     function show()
119     {
120         $this->startItem();
121         $this->showProfile();
122         $this->showActions();
123         $this->endItem();
124     }
125
126     function startItem()
127     {
128         $this->out->elementStart('li', array('class' => 'profile',
129                                              'id' => 'profile-' . $this->profile->id));
130     }
131
132     function showProfile()
133     {
134         $this->startProfile();
135         $this->showAvatar();
136         $this->showFullName();
137         $this->showLocation();
138         $this->showHomepage();
139         $this->showBio();
140         $this->endProfile();
141     }
142
143     function startProfile()
144     {
145         $this->out->elementStart('div', 'entity_profile vcard');
146     }
147
148     function showAvatar()
149     {
150         $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
151         $this->out->elementStart('a', array('href' => $this->profile->profileurl,
152                                             'class' => 'url'));
153         $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
154                                          'class' => 'photo avatar',
155                                          'width' => AVATAR_STREAM_SIZE,
156                                          'height' => AVATAR_STREAM_SIZE,
157                                          'alt' =>
158                                          ($this->profile->fullname) ? $this->profile->fullname :
159                                          $this->profile->nickname));
160         $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname';
161         $this->out->elementStart('span', $hasFN);
162         $this->out->raw($this->highlight($this->profile->nickname));
163         $this->out->elementEnd('span');
164         $this->out->elementEnd('a');
165     }
166
167     function showFullName()
168     {
169         if (!empty($this->profile->fullname)) {
170             $this->out->elementStart('dl', 'entity_fn');
171             $this->out->element('dt', null, 'Full name');
172             $this->out->elementStart('dd');
173             $this->out->elementStart('span', 'fn');
174             $this->out->raw($this->highlight($this->profile->fullname));
175             $this->out->elementEnd('span');
176             $this->out->elementEnd('dd');
177             $this->out->elementEnd('dl');
178         }
179     }
180
181     function showLocation()
182     {
183         if (!empty($this->profile->location)) {
184             $this->out->elementStart('dl', 'entity_location');
185             $this->out->element('dt', null, _('Location'));
186             $this->out->elementStart('dd', 'label');
187             $this->out->raw($this->highlight($this->profile->location));
188             $this->out->elementEnd('dd');
189             $this->out->elementEnd('dl');
190         }
191     }
192
193     function showHomepage()
194     {
195         if (!empty($this->profile->homepage)) {
196             $this->out->elementStart('dl', 'entity_url');
197             $this->out->element('dt', null, _('URL'));
198             $this->out->elementStart('dd');
199             $this->out->elementStart('a', array('href' => $this->profile->homepage,
200                                                 'class' => 'url'));
201             $this->out->raw($this->highlight($this->profile->homepage));
202             $this->out->elementEnd('a');
203             $this->out->elementEnd('dd');
204             $this->out->elementEnd('dl');
205         }
206     }
207
208     function showBio()
209     {
210         if (!empty($this->profile->bio)) {
211             $this->out->elementStart('dl', 'entity_note');
212             $this->out->element('dt', null, _('Note'));
213             $this->out->elementStart('dd', 'note');
214             $this->out->raw($this->highlight($this->profile->bio));
215             $this->out->elementEnd('dd');
216             $this->out->elementEnd('dl');
217         }
218     }
219
220     function endProfile()
221     {
222         $this->out->elementEnd('div');
223     }
224
225     function showActions()
226     {
227         $this->startActions();
228         $this->showSubscribeButton();
229         $this->endActions();
230     }
231
232     function startActions()
233     {
234         $this->out->elementStart('div', 'entity_actions');
235         $this->out->elementStart('ul');
236     }
237
238     function showSubscribeButton()
239     {
240         // Is this a logged-in user, looking at someone else's
241         // profile?
242
243         $user = common_current_user();
244
245         if (!empty($user) && $this->profile->id != $user->id) {
246             $this->out->elementStart('li', 'entity_subscribe');
247             if ($user->isSubscribed($this->profile)) {
248                 $usf = new UnsubscribeForm($this->out, $this->profile);
249                 $usf->show();
250             } else {
251                 // Is it a local user? can't remote sub from a list
252                 // XXX: make that possible!
253                 $other = User::staticGet('id', $this->profile->id);
254                 if (!empty($other)) {
255                     $sf = new SubscribeForm($this->out, $this->profile);
256                     $sf->show();
257                 }
258             }
259             $this->out->elementEnd('li');
260         }
261     }
262
263     function endActions()
264     {
265         $this->out->elementEnd('ul');
266         $this->out->elementEnd('div');
267     }
268
269     function endItem()
270     {
271         $this->out->elementEnd('li');
272     }
273
274     function highlight($text)
275     {
276         return htmlspecialchars($text);
277     }
278 }