]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelistitem.php
Merge branch 'nightly' into deletenotice_form_fix
[quix0rs-gnu-social.git] / lib / profilelistitem.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Widget to show a list of profiles
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Public
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('GNUSOCIAL')) { exit(1); }
31
32 class ProfileListItem extends Widget
33 {
34     /** Current profile. */
35     protected $target = null;
36     var $profile = null;
37     /** Action object using us. */
38     var $action = null;
39
40     function __construct(Profile $target, HTMLOutputter $action)
41     {
42         parent::__construct($action);
43
44         $this->target = $target;
45         $this->profile = $this->target;
46         $this->action  = $action;
47     }
48
49     function getTarget()
50     {
51         return $this->target;
52     }
53
54     function show()
55     {
56         if (Event::handle('StartProfileListItem', array($this))) {
57             $this->startItem();
58             if (Event::handle('StartProfileListItemProfile', array($this))) {
59                 $this->showProfile();
60                 Event::handle('EndProfileListItemProfile', array($this));
61             }
62             if (Event::handle('StartProfileListItemActions', array($this))) {
63                 $this->showActions();
64                 Event::handle('EndProfileListItemActions', array($this));
65             }
66             $this->endItem();
67             Event::handle('EndProfileListItem', array($this));
68         }
69     }
70
71     function startItem()
72     {
73         $this->out->elementStart('li', array('class' => 'profile',
74                                              'id' => 'profile-' . $this->profile->id));
75     }
76
77     function showProfile()
78     {
79         $this->startProfile();
80         if (Event::handle('StartProfileListItemProfileElements', array($this))) {
81             if (Event::handle('StartProfileListItemAvatar', array($this))) {
82                 $aAttrs = $this->linkAttributes();
83                 $this->out->elementStart('a', $aAttrs);
84                 $this->showAvatar($this->profile);
85                 $this->out->elementEnd('a');
86                 Event::handle('EndProfileListItemAvatar', array($this));
87             }
88             if (Event::handle('StartProfileListItemNickname', array($this))) {
89                 $this->showNickname();
90                 Event::handle('EndProfileListItemNickname', array($this));
91             }
92             if (Event::handle('StartProfileListItemFullName', array($this))) {
93                 $this->showFullName();
94                 Event::handle('EndProfileListItemFullName', array($this));
95             }
96             if (Event::handle('StartProfileListItemLocation', array($this))) {
97                 $this->showLocation();
98                 Event::handle('EndProfileListItemLocation', array($this));
99             }
100             if (Event::handle('StartProfileListItemHomepage', array($this))) {
101                 $this->showHomepage();
102                 Event::handle('EndProfileListItemHomepage', array($this));
103             }
104             if (Event::handle('StartProfileListItemBio', array($this))) {
105                 $this->showBio();
106                 Event::handle('EndProfileListItemBio', array($this));
107             }
108             if (Event::handle('StartProfileListItemTags', array($this))) {
109                 $this->showTags();
110                 Event::handle('EndProfileListItemTags', array($this));
111             }
112             Event::handle('EndProfileListItemProfileElements', array($this));
113         }
114         $this->endProfile();
115     }
116
117     function startProfile()
118     {
119         $this->out->elementStart('div', 'entity_profile h-card');
120     }
121
122     function showNickname()
123     {
124         $this->out->element('a', array('href'=>$this->profile->getUrl(),
125                                        'class'=>'p-nickname'),
126                             $this->profile->getNickname());
127     }
128
129     function showFullName()
130     {
131         if (!empty($this->profile->fullname)) {
132             $this->out->element('span', 'p-name', $this->profile->fullname);
133         }
134     }
135
136     function showLocation()
137     {
138         if (!empty($this->profile->location)) {
139             $this->out->element('span', 'label p-locality', $this->profile->location);
140         }
141     }
142
143     function showHomepage()
144     {
145         if (!empty($this->profile->homepage)) {
146             $this->out->text(' ');
147             $aAttrs = $this->homepageAttributes();
148             $this->out->elementStart('a', $aAttrs);
149             $this->out->raw($this->highlight($this->profile->homepage));
150             $this->out->elementEnd('a');
151         }
152     }
153
154     function showBio()
155     {
156         if (!empty($this->profile->bio)) {
157             $this->out->elementStart('p', 'note');
158             $this->out->raw($this->highlight($this->profile->bio));
159             $this->out->elementEnd('p');
160         }
161     }
162
163     function showTags()
164     {
165         $user = common_current_user();
166         if (!empty($user)) {
167             if ($user->id == $this->profile->id) {
168                 $tags = new SelftagsWidget($this->out, $user, $this->profile);
169                 $tags->show();
170             } else if ($user->getProfile()->canTag($this->profile)) {
171                 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
172                 $tags->show();
173             }
174         }
175     }
176
177     function endProfile()
178     {
179         $this->out->elementEnd('div');
180     }
181
182     function showActions()
183     {
184         $this->startActions();
185         if (Event::handle('StartProfileListItemActionElements', array($this))) {
186             $this->showSubscribeButton();
187             Event::handle('EndProfileListItemActionElements', array($this));
188         }
189         $this->endActions();
190     }
191
192     function startActions()
193     {
194         $this->out->elementStart('div', 'entity_actions');
195         $this->out->elementStart('ul');
196     }
197
198     function showSubscribeButton()
199     {
200         // Is this a logged-in user, looking at someone else's
201         // profile?
202
203         $user = common_current_user();
204
205         if (!empty($user) && $this->profile->id != $user->id) {
206             $this->out->elementStart('li', 'entity_subscribe');
207             if ($user->isSubscribed($this->profile)) {
208                 $usf = new UnsubscribeForm($this->out, $this->profile);
209                 $usf->show();
210             } else {
211                 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
212                     $sf = new SubscribeForm($this->out, $this->profile);
213                     $sf->show();
214                     Event::handle('EndShowProfileListSubscribeButton', array($this));
215                 }
216             }
217             $this->out->elementEnd('li');
218         }
219     }
220
221     function endActions()
222     {
223         $this->out->elementEnd('ul');
224         $this->out->elementEnd('div');
225     }
226
227     function endItem()
228     {
229         $this->out->elementEnd('li');
230     }
231
232     function highlight($text)
233     {
234         return htmlspecialchars($text);
235     }
236
237     function linkAttributes()
238     {
239         return array('href' => $this->profile->profileurl,
240                      'class' => 'u-url',
241                      'rel' => 'contact');
242     }
243
244     function homepageAttributes()
245     {
246         return array('href' => $this->profile->homepage,
247                      'class' => 'u-url');
248     }
249 }