]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilelistitem.php
6fe7b99c7b3a967515815df5a3e1bde0c425fa04
[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     // FIXME: Directory plugin sends a User_group here, but should send a Profile and handle User_group specifics itself
41     function __construct($target, HTMLOutputter $action)
42     {
43         parent::__construct($action);
44
45         $this->target = $target;
46         $this->profile = $this->target;
47         $this->action  = $action;
48     }
49
50     function getTarget()
51     {
52         return $this->target;
53     }
54
55     function show()
56     {
57         if (Event::handle('StartProfileListItem', array($this))) {
58             $this->startItem();
59             if (Event::handle('StartProfileListItemProfile', array($this))) {
60                 $this->showProfile();
61                 Event::handle('EndProfileListItemProfile', array($this));
62             }
63             if (Event::handle('StartProfileListItemActions', array($this))) {
64                 $this->showActions();
65                 Event::handle('EndProfileListItemActions', array($this));
66             }
67             $this->endItem();
68             Event::handle('EndProfileListItem', array($this));
69         }
70     }
71
72     function startItem()
73     {
74         $this->out->elementStart('li', array('class' => 'profile',
75                                              'id' => 'profile-' . $this->profile->id));
76     }
77
78     function showProfile()
79     {
80         $this->startProfile();
81         if (Event::handle('StartProfileListItemProfileElements', array($this))) {
82             if (Event::handle('StartProfileListItemAvatar', array($this))) {
83                 $aAttrs = $this->linkAttributes();
84                 $this->out->elementStart('a', $aAttrs);
85                 $this->showAvatar($this->profile);
86                 $this->out->elementEnd('a');
87                 Event::handle('EndProfileListItemAvatar', array($this));
88             }
89             if (Event::handle('StartProfileListItemNickname', array($this))) {
90                 $this->showNickname();
91                 Event::handle('EndProfileListItemNickname', array($this));
92             }
93             if (Event::handle('StartProfileListItemFullName', array($this))) {
94                 $this->showFullName();
95                 Event::handle('EndProfileListItemFullName', array($this));
96             }
97             if (Event::handle('StartProfileListItemLocation', array($this))) {
98                 $this->showLocation();
99                 Event::handle('EndProfileListItemLocation', array($this));
100             }
101             if (Event::handle('StartProfileListItemHomepage', array($this))) {
102                 $this->showHomepage();
103                 Event::handle('EndProfileListItemHomepage', array($this));
104             }
105             if (Event::handle('StartProfileListItemBio', array($this))) {
106                 $this->showBio();
107                 Event::handle('EndProfileListItemBio', array($this));
108             }
109             if (Event::handle('StartProfileListItemTags', array($this))) {
110                 $this->showTags();
111                 Event::handle('EndProfileListItemTags', array($this));
112             }
113             Event::handle('EndProfileListItemProfileElements', array($this));
114         }
115         $this->endProfile();
116     }
117
118     function startProfile()
119     {
120         $this->out->elementStart('div', 'entity_profile h-card');
121     }
122
123     function showNickname()
124     {
125         $this->out->element('a', array('href'=>$this->profile->getUrl(),
126                                        'class'=>'p-nickname'),
127                             $this->profile->getNickname());
128     }
129
130     function showFullName()
131     {
132         if (!empty($this->profile->fullname)) {
133             $this->out->element('span', 'p-name', $this->profile->fullname);
134         }
135     }
136
137     function showLocation()
138     {
139         if (!empty($this->profile->location)) {
140             $this->out->element('span', 'label p-locality', $this->profile->location);
141         }
142     }
143
144     function showHomepage()
145     {
146         if (!empty($this->profile->homepage)) {
147             $this->out->text(' ');
148             $aAttrs = $this->homepageAttributes();
149             $this->out->elementStart('a', $aAttrs);
150             $this->out->raw($this->highlight($this->profile->homepage));
151             $this->out->elementEnd('a');
152         }
153     }
154
155     function showBio()
156     {
157         if (!empty($this->profile->bio)) {
158             $this->out->elementStart('p', 'note');
159             $this->out->raw($this->highlight($this->profile->bio));
160             $this->out->elementEnd('p');
161         }
162     }
163
164     function showTags()
165     {
166         $user = common_current_user();
167         if (!empty($user)) {
168             if ($user->id == $this->profile->id) {
169                 $tags = new SelftagsWidget($this->out, $user, $this->profile);
170                 $tags->show();
171             } else if ($user->getProfile()->canTag($this->profile)) {
172                 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
173                 $tags->show();
174             }
175         }
176     }
177
178     function endProfile()
179     {
180         $this->out->elementEnd('div');
181     }
182
183     function showActions()
184     {
185         $this->startActions();
186         if (Event::handle('StartProfileListItemActionElements', array($this))) {
187             $this->showSubscribeButton();
188             Event::handle('EndProfileListItemActionElements', array($this));
189         }
190         $this->endActions();
191     }
192
193     function startActions()
194     {
195         $this->out->elementStart('div', 'entity_actions');
196         $this->out->elementStart('ul');
197     }
198
199     function showSubscribeButton()
200     {
201         // Is this a logged-in user, looking at someone else's
202         // profile?
203
204         $user = common_current_user();
205
206         if (!empty($user) && $this->profile->id != $user->id) {
207             $this->out->elementStart('li', 'entity_subscribe');
208             if ($user->isSubscribed($this->profile)) {
209                 $usf = new UnsubscribeForm($this->out, $this->profile);
210                 $usf->show();
211             } else {
212                 if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
213                     $sf = new SubscribeForm($this->out, $this->profile);
214                     $sf->show();
215                     Event::handle('EndShowProfileListSubscribeButton', array($this));
216                 }
217             }
218             $this->out->elementEnd('li');
219         }
220     }
221
222     function endActions()
223     {
224         $this->out->elementEnd('ul');
225         $this->out->elementEnd('div');
226     }
227
228     function endItem()
229     {
230         $this->out->elementEnd('li');
231     }
232
233     function highlight($text)
234     {
235         return htmlspecialchars($text);
236     }
237
238     function linkAttributes()
239     {
240         return array('href' => $this->profile->profileurl,
241                      'class' => 'u-url',
242                      'rel' => 'contact');
243     }
244
245     function homepageAttributes()
246     {
247         return array('href' => $this->profile->homepage,
248                      'class' => 'u-url');
249     }
250 }