git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

peopletag.php 5.07 KB
Newer Older
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
4
 *
Siebrand Mazeland's avatar
Siebrand Mazeland committed
5
 * Lists by a user
6 7 8 9
 *
 * 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
 * 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.
 *
Shashi Gowda's avatar
Shashi Gowda committed
19 20
 * PHP version 5
 *
21 22
 * 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/>.
23
 *
Shashi Gowda's avatar
Shashi Gowda committed
24
 * @category  Personal
25
 * @package   StatusNet
26 27
 * @author    Evan Prodromou <evan@status.net>
 * @author    Zach Copley <zach@status.net>
Shashi Gowda's avatar
Shashi Gowda committed
28
 * @author    Shashi Gowda <connect2shashi@gmail.com>
29
 * @copyright 2009 StatusNet, Inc.
30
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31
 * @link      http://status.net/
32 33
 */

34
if (!defined('STATUSNET') && !defined('LACONICA')) {
35 36
    exit(1);
}
37

Shashi Gowda's avatar
Shashi Gowda committed
38 39 40
require_once INSTALLDIR.'/lib/peopletaglist.php';
// cache 3 pages
define('PEOPLETAG_CACHE_WINDOW', PEOPLETAGS_PER_PAGE*3 + 1);
41

42 43
class PeopletagAction extends Action
{
44
    var $page = null;
Shashi Gowda's avatar
Shashi Gowda committed
45
    var $tag = null;
46

Shashi Gowda's avatar
Shashi Gowda committed
47
    function isReadOnly($args)
48
    {
49 50 51
        return true;
    }

Shashi Gowda's avatar
Shashi Gowda committed
52
    function title()
53
    {
Shashi Gowda's avatar
Shashi Gowda committed
54
        if ($this->page == 1) {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
55 56 57
            // TRANS: Title for list page.
            // TRANS: %s is a list.
            return sprintf(_('Public list %s'), $this->tag);
Shashi Gowda's avatar
Shashi Gowda committed
58
        } else {
Siebrand Mazeland's avatar
Siebrand Mazeland committed
59 60 61
            // TRANS: Title for list page.
            // TRANS: %1$s is a list, %2$d is a page number.
            return sprintf(_('Public list %1$s, page %2$d'), $this->tag, $this->page);
Shashi Gowda's avatar
Shashi Gowda committed
62
        }
63
    }
64

Shashi Gowda's avatar
Shashi Gowda committed
65
    function prepare($args)
66
    {
Shashi Gowda's avatar
Shashi Gowda committed
67 68
        parent::prepare($args);
        $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
69

Shashi Gowda's avatar
Shashi Gowda committed
70 71
        $tag_arg = $this->arg('tag');
        $tag = common_canonical_tag($tag_arg);
72

Shashi Gowda's avatar
Shashi Gowda committed
73
        // Permanent redirect on non-canonical nickname
74

Shashi Gowda's avatar
Shashi Gowda committed
75 76 77 78 79 80
        if ($tag_arg != $tag) {
            $args = array('tag' => $nickname);
            if ($this->page && $this->page != 1) {
                $args['page'] = $this->page;
            }
            common_redirect(common_local_url('peopletag', $args), 301);
81
        }
Shashi Gowda's avatar
Shashi Gowda committed
82
        $this->tag = $tag;
83

Shashi Gowda's avatar
Shashi Gowda committed
84
        return true;
85
    }
86

Shashi Gowda's avatar
Shashi Gowda committed
87
    function handle($args)
88
    {
Shashi Gowda's avatar
Shashi Gowda committed
89 90
        parent::handle($args);
        $this->showPage();
91
    }
92

Shashi Gowda's avatar
Shashi Gowda committed
93 94 95 96 97
    function showLocalNav()
    {
        $nav = new PublicGroupNav($this);
        $nav->show();
    }
98

Shashi Gowda's avatar
Shashi Gowda committed
99
    function showAnonymousMessage()
100
    {
Shashi Gowda's avatar
Shashi Gowda committed
101
        $notice =
Siebrand Mazeland's avatar
Siebrand Mazeland committed
102
          // TRANS: Message for anonymous users on list page.
103
          // TRANS: This message contains Markdown links in the form [description](link).
Siebrand Mazeland's avatar
Siebrand Mazeland committed
104
          _('Lists are how you sort similar ' .
Shashi Gowda's avatar
Shashi Gowda committed
105 106 107 108
            'people on %%site.name%%, a [micro-blogging]' .
            '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
            'You can then easily keep track of what they ' .
Siebrand Mazeland's avatar
Siebrand Mazeland committed
109
            'are doing by subscribing to the list\'s timeline.' );
Shashi Gowda's avatar
Shashi Gowda committed
110 111 112
        $this->elementStart('div', array('id' => 'anon_notice'));
        $this->raw(common_markup_to_html($notice));
        $this->elementEnd('div');
113 114
    }

Shashi Gowda's avatar
Shashi Gowda committed
115
    function showContent()
116
    {
Shashi Gowda's avatar
Shashi Gowda committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
        $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
        $limit  = PEOPLETAGS_PER_PAGE + 1;

        $ptags = new Profile_list();
        $ptags->tag = $this->tag;

        $user = common_current_user();

        if (empty($user)) {
            $ckey = sprintf('profile_list:tag:%s', $this->tag);
            $ptags->private = false;
            $ptags->orderBy('profile_list.modified DESC');

            $c = Cache::instance();
            if ($offset+$limit <= PEOPLETAG_CACHE_WINDOW && !empty($c)) {
                $cached_ptags = Profile_list::getCached($ckey, $offset, $limit);
                if ($cached_ptags === false) {
                    $ptags->limit(0, PEOPLETAG_CACHE_WINDOW);
                    $ptags->find();

                    Profile_list::setCache($ckey, $ptags, $offset, $limit);
                } else {
                    $ptags = clone($cached_ptags);
                }
            } else {
                $ptags->limit($offset, $limit);
                $ptags->find();
            }
        } else {
            $ptags->whereAdd('(profile_list.private = false OR (' .
                             ' profile_list.tagger =' . $user->id .
148
                             ' AND profile_list.private = true) )');
149

Shashi Gowda's avatar
Shashi Gowda committed
150 151
            $ptags->orderBy('profile_list.modified DESC');
            $ptags->find();
152 153
        }

Shashi Gowda's avatar
Shashi Gowda committed
154 155 156 157 158
        $pl = new PeopletagList($ptags, $this);
        $cnt = $pl->show();

        $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
                          $this->page, 'peopletag', array('tag' => $this->tag));
159 160
    }

Shashi Gowda's avatar
Shashi Gowda committed
161
    function showSections()
162 163 164
    {
    }
}