showprofiletag.php 14.3 KB
Newer Older
Shashi Gowda's avatar
Shashi Gowda committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
<?php
/**
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2008, 2009, StatusNet, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * 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/>.
 *
 * @category Actions
 * @package  Actions
 * @license  GNU Affero General Public License http://www.gnu.org/licenses/
 * @link     http://status.net
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

require_once INSTALLDIR.'/lib/profileminilist.php';
require_once INSTALLDIR.'/lib/peopletaglist.php';
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR.'/lib/feedlist.php';

class ShowprofiletagAction extends Action
{
Shashi Gowda's avatar
Shashi Gowda committed
36
    var $notice, $tagger, $peopletag, $userProfile;
Shashi Gowda's avatar
Shashi Gowda committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

    function isReadOnly($args)
    {
        return true;
    }

    function prepare($args)
    {
        parent::prepare($args);

        $tagger_arg = $this->arg('tagger');
        $tag_arg = $this->arg('tag');
        $tagger = common_canonical_nickname($tagger_arg);
        $tag = common_canonical_tag($tag_arg);

        // Permanent redirect on non-canonical nickname

        if ($tagger_arg != $tagger || $tag_arg != $tag) {
            $args = array('tagger' => $nickname, 'tag' => $tag);
            if ($this->page != 1) {
                $args['page'] = $this->page;
            }
            common_redirect(common_local_url('showprofiletag', $args), 301);
            return false;
        }

        if (!$tagger) {
64
            // TRANS: Client error displayed when a tagger is expected but not provided.
Shashi Gowda's avatar
Shashi Gowda committed
65 66 67 68 69 70 71
            $this->clientError(_('No tagger.'), 404);
            return false;
        }

        $user = User::staticGet('nickname', $tagger);

        if (!$user) {
72
            // TRANS: Client error displayed trying to perform an action related to a non-existing user.
Shashi Gowda's avatar
Shashi Gowda committed
73 74 75 76 77 78 79 80 81 82 83 84
            $this->clientError(_('No such user.'), 404);
            return false;
        }

        $this->tagger = $user->getProfile();
        $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));

        $current = common_current_user();
        $can_see = !empty($this->peopletag) && (!$this->peopletag->private ||
                   ($this->peopletag->private && $this->peopletag->tagger === $current->id));

        if (!$can_see) {
85 86
            // TRANS: Client error displayed trying to reference a non-existing people tag.
            $this->clientError(_('No such people tag.'), 404);
Shashi Gowda's avatar
Shashi Gowda committed
87 88 89 90
            return false;
        }

        $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
Shashi Gowda's avatar
Shashi Gowda committed
91 92 93 94 95 96
        $this->userProfile = Profile::current();

        $stream = new PeopletagNoticeStream($this->peopletag, $this->userProfile);

        $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
                                            NOTICES_PER_PAGE + 1);
Shashi Gowda's avatar
Shashi Gowda committed
97 98

        if ($this->page > 1 && $this->notice->N == 0) {
99
            // TRANS: Server error when page not found (404).
Shashi Gowda's avatar
Shashi Gowda committed
100 101 102 103 104 105 106 107 108 109 110
            $this->serverError(_('No such page.'), $code = 404);
        }

        return true;
    }

    function handle($args)
    {
        parent::handle($args);

        if (!$this->peopletag) {
111
            // TRANS: Client error displayed trying to perform an action related to a non-existing user.
Shashi Gowda's avatar
Shashi Gowda committed
112 113 114 115 116 117 118 119 120 121 122
            $this->clientError(_('No such user.'));
            return;
        }

        $this->showPage();
    }

    function title()
    {
        if ($this->page > 1) {
            if($this->peopletag->private) {
123 124
                // TRANS: Title for private people tag timeline.
                // TRANS: %1$s is a people tag, %2$s is a page number.
125
                return sprintf(_('Private timeline for %1$s list by you, page %2$d'),
Shashi Gowda's avatar
Shashi Gowda committed
126 127 128 129 130
                                $this->peopletag->tag, $this->page);
            }

            $current = common_current_user();
            if (!empty($current) && $current->id == $this->peopletag->tagger) {
131 132
                // TRANS: Title for public people tag timeline where the viewer is the tagger.
                // TRANS: %1$s is a people tag, %2$s is a page number.
133
                return sprintf(_('Timeline for %1$s list by you, page %2$d'),
Shashi Gowda's avatar
Shashi Gowda committed
134 135 136
                                $this->peopletag->tag, $this->page);
            }

137 138
            // TRANS: Title for private people tag timeline.
            // TRANS: %1$s is a people tag, %2$s is the tagger's nickname, %3$d is a page number.
139
            return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'),
Shashi Gowda's avatar
Shashi Gowda committed
140 141 142 143 144 145
                                $this->peopletag->tag,
                                $this->tagger->nickname,
                                $this->page
                          );
        } else {
            if($this->peopletag->private) {
146 147
                // TRANS: Title for private people tag timeline.
                // TRANS: %s is a people tag.
148
                return sprintf(_('Private timeline of %s list by you'),
149
                                $this->peopletag->tag);
Shashi Gowda's avatar
Shashi Gowda committed
150 151 152 153
            }

            $current = common_current_user();
            if (!empty($current) && $current->id == $this->peopletag->tagger) {
154 155
                // TRANS: Title for public people tag timeline where the viewer is the tagger.
                // TRANS: %s is a people tag.
156
                return sprintf(_('Timeline for %s list by you'),
157
                                $this->peopletag->tag);
Shashi Gowda's avatar
Shashi Gowda committed
158 159
            }

160 161
            // TRANS: Title for private people tag timeline.
            // TRANS: %1$s is a people tag, %2$s is the tagger's nickname.
162
            return sprintf(_('Timeline for %1$s list by %2$s'),
Shashi Gowda's avatar
Shashi Gowda committed
163
                                $this->peopletag->tag,
164
                                $this->tagger->nickname
Shashi Gowda's avatar
Shashi Gowda committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
                          );
        }
    }

    function getFeeds()
    {
        #XXX: make these actually work
        return array(new Feed(Feed::RSS2,
                common_local_url(
                    'ApiTimelineList', array(
                        'user' => $this->tagger->id,
                        'id' => $this->peopletag->id,
                        'format' => 'rss'
                    )
                ),
180 181
                // TRANS: Feed title.
                // TRANS: %s is tagger's nickname.
Shashi Gowda's avatar
Shashi Gowda committed
182 183 184 185 186 187 188 189 190
                sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->tagger->nickname)),
            new Feed(Feed::ATOM,
                common_local_url(
                    'ApiTimelineList', array(
                        'user' => $this->tagger->id,
                        'id' => $this->peopletag->id,
                        'format' => 'atom'
                    )
                ),
191 192
                // TRANS: Feed title.
                // TRANS: %1$s is a people tag, %2$s is tagger's nickname.
193
                sprintf(_('Feed for %1$s list by %2$s (Atom)'),
Shashi Gowda's avatar
Shashi Gowda committed
194 195 196 197 198 199
                            $this->peopletag->tag, $this->tagger->nickname
                       )
              )
        );
    }

200
    function showObjectNav()
Shashi Gowda's avatar
Shashi Gowda committed
201 202 203 204 205 206 207
    {
        $nav = new PeopletagGroupNav($this);
        $nav->show();
    }

    function showEmptyListMessage()
    {
208 209
        // TRANS: Empty list message for people tag timeline.
        // TRANS: %1$s is a people tag, %2$s is a tagger's nickname.
210
        $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
211 212
                           $this->peopletag->tag,
                           $this->tagger->nickname) . ' ';
Shashi Gowda's avatar
Shashi Gowda committed
213 214 215 216

        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->tagger->id == $current_user->id) {
217
                // TRANS: Additional empty list message for people tag timeline for currently logged in user tagged tags.
Shashi Gowda's avatar
Shashi Gowda committed
218 219 220
                $message .= _('Try tagging more people.');
            }
        } else {
221 222 223
            // TRANS: Additional empty list message for people tag timeline.
            // TRANS: This message contains Markdown links in the form [description](link).
            $message .= _('Why not [register an account](%%%%action.register%%%%) and start following this timeline!');
Shashi Gowda's avatar
Shashi Gowda committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
        }

        $this->elementStart('div', 'guide');
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }

    function showContent()
    {
        $this->showPeopletag();
        $this->showNotices();
    }

    function showPeopletag()
    {
        $cur = common_current_user();
        $tag = new Peopletag($this->peopletag, $cur, $this);
        $tag->show();
    }

    function showNotices()
    {
        if (Event::handle('StartShowProfileTagContent', array($this))) {
Shashi Gowda's avatar
Shashi Gowda committed
247
            $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
Shashi Gowda's avatar
Shashi Gowda committed
248 249 250 251 252 253 254

            $cnt = $nl->show();

            if (0 == $cnt) {
                $this->showEmptyListMessage();
            }

Shashi Gowda's avatar
Shashi Gowda committed
255 256 257 258 259 260
            $this->pagination($this->page > 1,
                              $cnt > NOTICES_PER_PAGE,
                              $this->page,
                              'showprofiletag',
                              array('tag' => $this->peopletag->tag,
                                    'tagger' => $this->tagger->nickname)
Shashi Gowda's avatar
Shashi Gowda committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
            );

            Event::handle('EndShowProfileTagContent', array($this));
        }
    }

    function showSections()
    {
        $this->showTagged();
        if (!$this->peopletag->private) {
            $this->showSubscribers();
        }
        # $this->showStatistics();
    }

    function showPageTitle()
    {
        $this->element('h1', null, $this->title());
    }

    function showTagged()
    {
        $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);

        $this->elementStart('div', array('id' => 'entity_tagged',
                                         'class' => 'section'));
        if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
            $title = '';

            $current = common_current_user();
            if(!empty($current) && $this->peopletag->tagger == $current->id) {
292 293
                // TRANS: Header on show profile tag page.
                // TRANS: %s is a people tag.
294
                $title =  sprintf(_('Listed'), $this->peopletag->tag);
Shashi Gowda's avatar
Shashi Gowda committed
295
            } else {
296 297
                // TRANS: Header on show profile tag page.
                // TRANS: %1$s is a people tag, %2$s is a tagger's nickname.
298
                $title = sprintf(_('Listed'),
Shashi Gowda's avatar
Shashi Gowda committed
299 300 301 302 303 304 305 306 307 308 309 310
                                $this->peopletag->tag,
                                $this->tagger->nickname);
            }

            $this->element('h2', null, $title);

            $cnt = 0;

            if (!empty($profile)) {
                $pml = new ProfileMiniList($profile, $this);
                $cnt = $pml->show();
                if ($cnt == 0) {
311
                    // TRANS: Content of "People tagged x by a user" if there are no tagged users.
Shashi Gowda's avatar
Shashi Gowda committed
312 313 314 315 316 317 318 319 320 321
                    $this->element('p', null, _('(None)'));
                }
            }

            if ($cnt > PROFILES_PER_MINILIST) {
                $this->elementStart('p');
                $this->element('a', array('href' => common_local_url('taggedprofiles',
                                                                     array('nickname' => $this->tagger->nickname,
                                                                           'profiletag' => $this->peopletag->tag)),
                                          'class' => 'more'),
322 323
                               // TRANS: Link for more "People tagged x by a user"
                               // TRANS: if there are more than the mini list's maximum.
Shashi Gowda's avatar
Shashi Gowda committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
                               _('Show all'));
                $this->elementEnd('p');
            }

            Event::handle('EndShowTaggedProfilesMiniList', array($this));
        }
        $this->elementEnd('div');
    }

    function showSubscribers()
    {
        $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);

        $this->elementStart('div', array('id' => 'entity_subscribers',
                                         'class' => 'section'));
        if (Event::handle('StartShowProfileTagSubscribersMiniList', array($this))) {
340
            // TRANS: Header for tag subscribers.
Shashi Gowda's avatar
Shashi Gowda committed
341 342 343 344 345 346 347 348
            $this->element('h2', null, _('Subscribers'));

            $cnt = 0;

            if (!empty($profile)) {
                $pml = new ProfileMiniList($profile, $this);
                $cnt = $pml->show();
                if ($cnt == 0) {
349
                    // TRANS: Content of "People following tag x" if there are no subscribed users.
Shashi Gowda's avatar
Shashi Gowda committed
350 351 352 353 354 355 356 357 358 359
                    $this->element('p', null, _('(None)'));
                }
            }

            if ($cnt > PROFILES_PER_MINILIST) {
                $this->elementStart('p');
                $this->element('a', array('href' => common_local_url('profiletagsubscribers',
                                                                     array('nickname' => $this->tagger->nickname,
                                                                           'profiletag' => $this->peopletag->tag)),
                                          'class' => 'more'),
360 361
                               // TRANS: Link for more "People following tag x"
                               // TRANS: if there are more than the mini list's maximum.
Shashi Gowda's avatar
Shashi Gowda committed
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
                               _('All subscribers'));
                $this->elementEnd('p');
            }

            Event::handle('EndShowProfileTagSubscribersMiniList', array($this));
        }
        $this->elementEnd('div');
    }
}

class Peopletag extends PeopletagListItem
{
    function showStart()
    {
        $mode = $this->peopletag->private ? 'private' : 'public';
        $this->out->elementStart('div', array('class' => 'hentry peopletag peopletag-profile mode-'.$mode,
                                             'id' => 'peopletag-' . $this->peopletag->id));
    }

    function showEnd()
    {
        $this->out->elementEnd('div');
    }

    function showAvatar()
    {
        parent::showAvatar(AVATAR_PROFILE_SIZE);
    }
}