]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelist.php
Remove comparison with member variable of null variable, cleaned code a bit.
[quix0rs-gnu-social.git] / lib / profilelist.php
1 <?php
2
3 /**
4  * Laconica, 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   Laconica
25  * @author    Evan Prodromou <evan@controlyourself.ca>
26  * @copyright 2008-2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!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  Laconica
42  * @author   Zach Copley <zach@controlyourself.ca>
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://laconi.ca/
46  */
47
48 class ProfileList extends Widget
49 {
50     /** Current profile, profile query. */
51     var $profile = null;
52     /** Owner of this list */
53     var $owner = null;
54     /** Action object using us. */
55     var $action = null;
56
57     function __construct($profile, $owner=null, $action=null)
58     {
59         parent::__construct($action);
60
61         $this->profile = $profile;
62         $this->owner = $owner;
63         $this->action = $action;
64     }
65
66     function show()
67     {
68
69         $this->out->elementStart('ul', 'profiles');
70
71         $cnt = 0;
72
73         while ($this->profile->fetch()) {
74             $cnt++;
75             if($cnt > PROFILES_PER_PAGE) {
76                 break;
77             }
78             $this->showProfile();
79         }
80
81         $this->out->elementEnd('ul');
82
83         return $cnt;
84     }
85
86     function showProfile()
87     {
88         $this->out->elementStart('li', array('class' => 'profile',
89                                              'id' => 'profile-' . $this->profile->id));
90
91         $user = common_current_user();
92         $is_own = !is_null($user) && ($user->id === $this->user->id);
93
94         $this->out->elementStart('div', 'entity_profile vcard');
95
96         $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
97         $this->out->elementStart('a', array('href' => $this->profile->profileurl,
98                                             'class' => 'url'));
99         $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
100                                          'class' => 'photo avatar',
101                                          'width' => AVATAR_STREAM_SIZE,
102                                          'height' => AVATAR_STREAM_SIZE,
103                                          'alt' =>
104                                          ($this->profile->fullname) ? $this->profile->fullname :
105                                          $this->profile->nickname));
106         $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname';
107         $this->out->elementStart('span', $hasFN);
108         $this->out->raw($this->highlight($this->profile->nickname));
109         $this->out->elementEnd('span');
110         $this->out->elementEnd('a');
111
112         if ($this->profile->fullname !== '') {
113             $this->out->elementStart('dl', 'entity_fn');
114             $this->out->element('dt', null, 'Full name');
115             $this->out->elementStart('dd');
116             $this->out->elementStart('span', 'fn');
117             $this->out->raw($this->highlight($this->profile->fullname));
118             $this->out->elementEnd('span');
119             $this->out->elementEnd('dd');
120             $this->out->elementEnd('dl');
121         }
122         if ($this->profile->location !== '') {
123             $this->out->elementStart('dl', 'entity_location');
124             $this->out->element('dt', null, _('Location'));
125             $this->out->elementStart('dd', 'label');
126             $this->out->raw($this->highlight($this->profile->location));
127             $this->out->elementEnd('dd');
128             $this->out->elementEnd('dl');
129         }
130         if ($this->profile->homepage !== '') {
131             $this->out->elementStart('dl', 'entity_url');
132             $this->out->element('dt', null, _('URL'));
133             $this->out->elementStart('dd');
134             $this->out->elementStart('a', array('href' => $this->profile->homepage,
135                                                 'class' => 'url'));
136             $this->out->raw($this->highlight($this->profile->homepage));
137             $this->out->elementEnd('a');
138             $this->out->elementEnd('dd');
139             $this->out->elementEnd('dl');
140         }
141         if ($this->profile->bio !== '') {
142             $this->out->elementStart('dl', 'entity_note');
143             $this->out->element('dt', null, _('Note'));
144             $this->out->elementStart('dd', 'note');
145             $this->out->raw($this->highlight($this->profile->bio));
146             $this->out->elementEnd('dd');
147             $this->out->elementEnd('dl');
148         }
149
150         # If we're on a list with an owner (subscriptions or subscribers)...
151
152         if ($this->owner) {
153             # Get tags
154             $tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
155
156             $this->out->elementStart('dl', 'entity_tags');
157             $this->out->elementStart('dt');
158             if ($is_own) {
159                 $this->out->element('a', array('href' => common_local_url('tagother',
160                                                                           array('id' => $this->profile->id))),
161                                     _('Tags'));
162             } else {
163                 $this->out->text(_('Tags'));
164             }
165             $this->out->elementEnd('dt');
166             $this->out->elementStart('dd');
167             if ($tags) {
168                 $this->out->elementStart('ul', 'tags xoxo');
169                 foreach ($tags as $tag) {
170                     $this->out->elementStart('li');
171                     $this->out->element('span', 'mark_hash', '#');
172                     $this->out->element('a', array('rel' => 'tag',
173                                                    'href' => common_local_url($this->action->trimmed('action'),
174                                                                               array('nickname' => $this->owner->nickname,
175                                                                                     'tag' => $tag))),
176                                         $tag);
177                     $this->out->elementEnd('li');
178                 }
179                 $this->out->elementEnd('ul');
180             } else {
181                 $this->out->text(_('(none)'));
182             }
183             $this->out->elementEnd('dd');
184             $this->out->elementEnd('dl');
185         }
186
187         if ($is_own) {
188             $this->showOwnerControls($this->profile);
189         }
190
191         $this->out->elementEnd('div');
192
193         $this->out->elementStart('div', 'entity_actions');
194
195         $this->out->elementStart('ul');
196
197         if (!$is_own) {
198             # XXX: special-case for user looking at own
199             # subscriptions page
200             $this->out->elementStart('li', 'entity_subscribe');
201             if (!is_null($user) && $user->isSubscribed($this->profile)) {
202                 $usf = new UnsubscribeForm($this->out, $this->profile);
203                 $usf->show();
204             } else {
205                 $sf = new SubscribeForm($this->out, $this->profile);
206                 $sf->show();
207             }
208             $this->out->elementEnd('li');
209             $this->out->elementStart('li', 'entity_block');
210             $this->out->elementEnd('li');
211         }
212
213         $this->out->elementEnd('ul');
214
215         $this->out->elementEnd('div');
216
217         $this->out->elementEnd('li');
218     }
219
220     /* Override this in subclasses. */
221
222     function showOwnerControls($profile)
223     {
224         return;
225     }
226
227     function highlight($text)
228     {
229         return htmlspecialchars($text);
230     }
231
232     function showBlockForm()
233     {
234     }
235 }