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