We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

profilelist.php 10.1 KB
Newer Older
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
4
 *
5 6 7 8 9
 * Widget to show a list of profiles
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
10 11 12 13 14 15 16 17 18 19 20
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * 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('STATUSNET') && !defined('LACONICA')) {
31 32 33 34
    exit(1);
}

require_once INSTALLDIR.'/lib/widget.php';
Shashi Gowda's avatar
Shashi Gowda committed
35
require_once INSTALLDIR.'/lib/peopletags.php';
36

37 38 39 40
/**
 * Widget to show a list of profiles
 *
 * @category Public
41
 * @package  StatusNet
42 43
 * @author   Zach Copley <zach@status.net>
 * @author   Evan Prodromou <evan@status.net>
44
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45
 * @link     http://status.net/
46 47 48 49
 */
class ProfileList extends Widget
{
    /** Current profile, profile query. */
Evan Prodromou's avatar
Evan Prodromou committed
50
    var $profile = null;
51
    /** Action object using us. */
Evan Prodromou's avatar
Evan Prodromou committed
52
    var $action = null;
53

54
    function __construct($profile, $action=null)
55
    {
56 57
        parent::__construct($action);

58 59 60 61
        $this->profile = $profile;
        $this->action = $action;
    }

62
    function show()
63
    {
64 65 66 67 68 69 70 71 72
        $cnt = 0;

        if (Event::handle('StartProfileList', array($this))) {
            $this->startList();
            $cnt = $this->showProfiles();
            $this->endList();
            Event::handle('EndProfileList', array($this));
        }

Evan Prodromou's avatar
Evan Prodromou committed
73
        return $cnt;
74 75 76
    }

    function startList()
77
    {
78
        $this->out->elementStart('ul', 'profiles xoxo');
79
    }
80

81 82 83 84 85 86 87
    function endList()
    {
        $this->out->elementEnd('ul');
    }

    function showProfiles()
    {
88 89 90 91 92 93 94
        $cnt = 0;

        while ($this->profile->fetch()) {
            $cnt++;
            if($cnt > PROFILES_PER_PAGE) {
                break;
            }
95 96
            $pli = $this->newListItem($this->profile);
            $pli->show();
97 98 99 100 101
        }

        return $cnt;
    }

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    function newListItem($profile)
    {
        return new ProfileListItem($this->profile, $this->action);
    }
}

class ProfileListItem extends Widget
{
    /** Current profile. */
    var $profile = null;
    /** Action object using us. */
    var $action = null;

    function __construct($profile, $action)
    {
        parent::__construct($action);

        $this->profile = $profile;
        $this->action  = $action;
    }

    function show()
    {
125 126 127 128 129 130 131 132 133 134 135 136 137
        if (Event::handle('StartProfileListItem', array($this))) {
            $this->startItem();
            if (Event::handle('StartProfileListItemProfile', array($this))) {
                $this->showProfile();
                Event::handle('EndProfileListItemProfile', array($this));
            }
            if (Event::handle('StartProfileListItemActions', array($this))) {
                $this->showActions();
                Event::handle('EndProfileListItemActions', array($this));
            }
            $this->endItem();
            Event::handle('EndProfileListItem', array($this));
        }
138 139 140
    }

    function startItem()
141
    {
142
        $this->out->elementStart('li', array('class' => 'profile hentry',
sarven's avatar
sarven committed
143
                                             'id' => 'profile-' . $this->profile->id));
144
    }
145

146 147 148
    function showProfile()
    {
        $this->startProfile();
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
        if (Event::handle('StartProfileListItemProfileElements', array($this))) {
            if (Event::handle('StartProfileListItemAvatar', array($this))) {
                $this->showAvatar();
                Event::handle('EndProfileListItemAvatar', array($this));
            }
            if (Event::handle('StartProfileListItemFullName', array($this))) {
                $this->showFullName();
                Event::handle('EndProfileListItemFullName', array($this));
            }
            if (Event::handle('StartProfileListItemLocation', array($this))) {
                $this->showLocation();
                Event::handle('EndProfileListItemLocation', array($this));
            }
            if (Event::handle('StartProfileListItemHomepage', array($this))) {
                $this->showHomepage();
                Event::handle('EndProfileListItemHomepage', array($this));
            }
            if (Event::handle('StartProfileListItemBio', array($this))) {
                $this->showBio();
                Event::handle('EndProfileListItemBio', array($this));
            }
Shashi Gowda's avatar
Shashi Gowda committed
170 171 172 173
            if (Event::handle('StartProfileListItemTags', array($this))) {
                $this->showTags();
                Event::handle('EndProfileListItemTags', array($this));
            }
174 175
            Event::handle('EndProfileListItemProfileElements', array($this));
        }
176 177
        $this->endProfile();
    }
178

179 180
    function startProfile()
    {
181
        $this->out->elementStart('div', 'entity_profile vcard entry-content');
182
    }
183

184 185
    function showAvatar()
    {
186
        $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
187 188
        $aAttrs = $this->linkAttributes();
        $this->out->elementStart('a', $aAttrs);
189
        $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
Evan Prodromou's avatar
Evan Prodromou committed
190 191 192 193 194 195
                                         'class' => 'photo avatar',
                                         'width' => AVATAR_STREAM_SIZE,
                                         'height' => AVATAR_STREAM_SIZE,
                                         'alt' =>
                                         ($this->profile->fullname) ? $this->profile->fullname :
                                         $this->profile->nickname));
196
        $this->out->text(' ');
197
        $hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
sarven's avatar
sarven committed
198
        $this->out->elementStart('span', $hasFN);
199
        $this->out->raw($this->highlight($this->profile->nickname));
sarven's avatar
sarven committed
200
        $this->out->elementEnd('span');
201
        $this->out->elementEnd('a');
202
    }
Evan Prodromou's avatar
Evan Prodromou committed
203

204 205
    function showFullName()
    {
206
        if (!empty($this->profile->fullname)) {
207
            $this->out->text(' ');
sarven's avatar
sarven committed
208
            $this->out->elementStart('span', 'fn');
209 210
            $this->out->raw($this->highlight($this->profile->fullname));
            $this->out->elementEnd('span');
211
        }
212 213 214 215
    }

    function showLocation()
    {
216
        if (!empty($this->profile->location)) {
217
            $this->out->text(' ');
218
            $this->out->elementStart('span', 'label');
219
            $this->out->raw($this->highlight($this->profile->location));
220
            $this->out->elementEnd('span');
221
        }
222 223 224 225
    }

    function showHomepage()
    {
226
        if (!empty($this->profile->homepage)) {
227
            $this->out->text(' ');
228 229
            $aAttrs = $this->homepageAttributes();
            $this->out->elementStart('a', $aAttrs);
230 231
            $this->out->raw($this->highlight($this->profile->homepage));
            $this->out->elementEnd('a');
232
        }
233 234 235 236
    }

    function showBio()
    {
237
        if (!empty($this->profile->bio)) {
238
            $this->out->elementStart('p', 'note');
239
            $this->out->raw($this->highlight($this->profile->bio));
240
            $this->out->elementEnd('p');
241
        }
242
    }
243

Shashi Gowda's avatar
Shashi Gowda committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257
    function showTags()
    {
        $user = common_current_user();
        if (!empty($user)) {
            if ($user->id == $this->profile->id) {
                $tags = new SelftagsWidget($this->out, $user, $this->profile);
                $tags->show();
            } else if ($user->getProfile()->canTag($this->profile)) {
                $tags = new PeopletagsWidget($this->out, $user, $this->profile);
                $tags->show();
            }
        }
    }

258 259
    function endProfile()
    {
sarven's avatar
sarven committed
260
        $this->out->elementEnd('div');
261
    }
sarven's avatar
sarven committed
262

263 264 265
    function showActions()
    {
        $this->startActions();
266 267 268 269
        if (Event::handle('StartProfileListItemActionElements', array($this))) {
            $this->showSubscribeButton();
            Event::handle('EndProfileListItemActionElements', array($this));
        }
270 271
        $this->endActions();
    }
Evan Prodromou's avatar
Evan Prodromou committed
272

273 274 275
    function startActions()
    {
        $this->out->elementStart('div', 'entity_actions');
Evan Prodromou's avatar
Evan Prodromou committed
276
        $this->out->elementStart('ul');
277
    }
Evan Prodromou's avatar
Evan Prodromou committed
278

279 280
    function showSubscribeButton()
    {
281 282 283
        // Is this a logged-in user, looking at someone else's
        // profile?

284 285
        $user = common_current_user();

286
        if (!empty($user) && $this->profile->id != $user->id) {
287 288 289 290 291
            $this->out->elementStart('li', 'entity_subscribe');
            if ($user->isSubscribed($this->profile)) {
                $usf = new UnsubscribeForm($this->out, $this->profile);
                $usf->show();
            } else {
292
                if (Event::handle('StartShowProfileListSubscribeButton', array($this))) {
293 294
                    $sf = new SubscribeForm($this->out, $this->profile);
                    $sf->show();
295
                    Event::handle('EndShowProfileListSubscribeButton', array($this));
296
                }
sarven's avatar
sarven committed
297
            }
298
            $this->out->elementEnd('li');
sarven's avatar
sarven committed
299
        }
300
    }
sarven's avatar
sarven committed
301

302 303
    function endActions()
    {
Evan Prodromou's avatar
Evan Prodromou committed
304
        $this->out->elementEnd('ul');
Evan Prodromou's avatar
Evan Prodromou committed
305
        $this->out->elementEnd('div');
306
    }
307

308
    function endItem()
309
    {
310
        $this->out->elementEnd('li');
311 312
    }

313 314
    function highlight($text)
    {
315 316
        return htmlspecialchars($text);
    }
317 318 319 320 321 322 323

    function linkAttributes()
    {
        return array('href' => $this->profile->profileurl,
                     'class' => 'url entry-title',
                     'rel' => 'contact');
    }
324 325 326 327 328 329

    function homepageAttributes()
    {
        return array('href' => $this->profile->homepage,
                     'class' => 'url');
    }
sarven's avatar
sarven committed
330
}