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