showprofiletag.php 14 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
{
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) {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
85 86
            // TRANS: Client error displayed trying to reference a non-existing list.
            $this->clientError(_('No such list.'), 404);
Shashi Gowda's avatar
Shashi Gowda committed
87 88 89 90
            return false;
        }

        $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
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
                // TRANS: Title for private list timeline.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
124
                // TRANS: %1$s is a list, %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
                // TRANS: Title for public list timeline where the viewer is the tagger.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
132
                // TRANS: %1$s is a list, %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
            // TRANS: Title for private list timeline.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
138
            // TRANS: %1$s is a list, %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 list timeline.
                // TRANS: %s is a list.
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 list timeline where the viewer is the tagger.
                // TRANS: %s is a list.
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 list timeline.
            // TRANS: %1$s is a list, %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
                          );
        }
    }

    function getFeeds()
    {
        #XXX: make these actually work
172 173 174 175 176 177 178 179 180 181 182 183
        return array(new Feed(Feed::JSON,
                common_local_url(
                    'ApiTimelineList', array(
                        'user' => $this->tagger->id,
                        'id' => $this->peopletag->id,
                        'format' => 'as'
                    )
                ),
                // TRANS: Feed title.
                // TRANS: %s is tagger's nickname.
                sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->tagger->nickname)),
                new Feed(Feed::RSS2,
Shashi Gowda's avatar
Shashi Gowda committed
184 185 186 187 188 189 190
                common_local_url(
                    'ApiTimelineList', array(
                        'user' => $this->tagger->id,
                        'id' => $this->peopletag->id,
                        'format' => 'rss'
                    )
                ),
191 192
                // TRANS: Feed title.
                // TRANS: %s is tagger's nickname.
Shashi Gowda's avatar
Shashi Gowda committed
193 194 195 196 197 198 199 200 201
                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'
                    )
                ),
202
                // TRANS: Feed title.
203
                // TRANS: %1$s is a list, %2$s is tagger's nickname.
204
                sprintf(_('Feed for %1$s list by %2$s (Atom)'),
Shashi Gowda's avatar
Shashi Gowda committed
205 206 207 208 209 210
                            $this->peopletag->tag, $this->tagger->nickname
                       )
              )
        );
    }

211
    function showObjectNav()
Shashi Gowda's avatar
Shashi Gowda committed
212 213 214 215 216 217 218
    {
        $nav = new PeopletagGroupNav($this);
        $nav->show();
    }

    function showEmptyListMessage()
    {
219 220
        // TRANS: Empty list message for list timeline.
        // TRANS: %1$s is a list, %2$s is a tagger's nickname.
221
        $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
222 223
                           $this->peopletag->tag,
                           $this->tagger->nickname) . ' ';
Shashi Gowda's avatar
Shashi Gowda committed
224 225 226 227

        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->tagger->id == $current_user->id) {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
228
                // TRANS: Additional empty list message for list timeline for currently logged in user tagged tags.
Shashi Gowda's avatar
Shashi Gowda committed
229 230 231
                $message .= _('Try tagging more people.');
            }
        } else {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
232
            // TRANS: Additional empty list message for list timeline.
233 234
            // 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
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
        }

        $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))) {
258
            $nl = new NoticeList($this->notice, $this);
Shashi Gowda's avatar
Shashi Gowda committed
259 260 261 262 263 264 265

            $cnt = $nl->show();

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

266 267 268 269 270 271
            $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
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
            );

            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 = '';

301 302
            // TRANS: Header on show list page.
            $this->element('h2', null, _('Listed'));
Shashi Gowda's avatar
Shashi Gowda committed
303 304 305 306 307 308 309

            $cnt = 0;

            if (!empty($profile)) {
                $pml = new ProfileMiniList($profile, $this);
                $cnt = $pml->show();
                if ($cnt == 0) {
310
                    // TRANS: Content of "Listed" page if there are no listed users.
Shashi Gowda's avatar
Shashi Gowda committed
311 312 313 314 315 316 317 318 319 320
                    $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'),
321
                               // TRANS: Link for more "People in list x by a user"
322
                               // TRANS: if there are more than the mini list's maximum.
Shashi Gowda's avatar
Shashi Gowda committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
                               _('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))) {
339
            // TRANS: Header for tag subscribers.
Shashi Gowda's avatar
Shashi Gowda committed
340 341 342 343 344 345 346 347
            $this->element('h2', null, _('Subscribers'));

            $cnt = 0;

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