subscriptions.php 6.07 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Evan Prodromou's avatar
Evan Prodromou committed
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
Evan Prodromou's avatar
Evan Prodromou committed
4
 *
5
 * List of a user's subscriptions
Evan Prodromou's avatar
Evan Prodromou committed
6 7 8 9
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
Evan Prodromou's avatar
Evan Prodromou committed
10 11 12
 * 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.
Evan Prodromou's avatar
Evan Prodromou committed
13
 *
Evan Prodromou's avatar
Evan Prodromou committed
14 15 16 17
 * 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.
Evan Prodromou's avatar
Evan Prodromou committed
18
 *
Evan Prodromou's avatar
Evan Prodromou committed
19 20
 * 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/>.
Evan Prodromou's avatar
Evan Prodromou committed
21
 *
22
 * @category  Social
23
 * @package   StatusNet
24 25
 * @author    Evan Prodromou <evan@status.net>
 * @author    Sarven Capadisli <csarven@status.net>
26
 * @copyright 2008-2009 StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
27
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28
 * @link      http://status.net/
Evan Prodromou's avatar
Evan Prodromou committed
29 30
 */

31
if (!defined('GNUSOCIAL')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
32 33

/**
34
 * A list of the user's subscriptions
Evan Prodromou's avatar
Evan Prodromou committed
35
 *
36
 * @category Social
37
 * @package  StatusNet
38
 * @author   Evan Prodromou <evan@status.net>
Evan Prodromou's avatar
Evan Prodromou committed
39
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40
 * @link     http://status.net/
Evan Prodromou's avatar
Evan Prodromou committed
41
 */
42
class SubscriptionsAction extends GalleryAction
43
{
Evan Prodromou's avatar
Evan Prodromou committed
44
    function title()
45
    {
Evan Prodromou's avatar
Evan Prodromou committed
46
        if ($this->page == 1) {
47 48
            // TRANS: Header for subscriptions overview for a user (first page).
            // TRANS: %s is a user nickname.
49
            return sprintf(_('%s subscriptions'), $this->target->getNickname());
Evan Prodromou's avatar
Evan Prodromou committed
50
        } else {
51 52
            // TRANS: Header for subscriptions overview for a user (not first page).
            // TRANS: %1$s is a user nickname, %2$d is the page number.
53
            return sprintf(_('%1$s subscriptions, page %2$d'),
54
                           $this->target->getNickname(),
Evan Prodromou's avatar
Evan Prodromou committed
55 56
                           $this->page);
        }
57
    }
58

Evan Prodromou's avatar
Evan Prodromou committed
59
    function showPageNotice()
60
    {
61
        if ($this->scoped instanceof Profile && $this->scoped->sameAs($this->getTarget())) {
Evan Prodromou's avatar
Evan Prodromou committed
62
            $this->element('p', null,
63 64
                           // TRANS: Page notice for page with an overview of all subscriptions
                           // TRANS: of the logged in user's own profile.
Evan Prodromou's avatar
Evan Prodromou committed
65 66 67 68
                           _('These are the people whose notices '.
                             'you listen to.'));
        } else {
            $this->element('p', null,
69 70
                           // TRANS: Page notice for page with an overview of all subscriptions of a user other
                           // TRANS: than the logged in user. %s is the user nickname.
Evan Prodromou's avatar
Evan Prodromou committed
71 72
                           sprintf(_('These are the people whose '.
                                     'notices %s listens to.'),
73
                                   $this->target->getNickname()));
Evan Prodromou's avatar
Evan Prodromou committed
74
        }
75
    }
76

77
    function getAllTags()
78
    {
79
        return $this->getTags('subscribed', 'subscriber');
Evan Prodromou's avatar
Evan Prodromou committed
80 81 82 83
    }

    function showContent()
    {
84 85
        if (Event::handle('StartShowSubscriptionsContent', array($this))) {
            parent::showContent();
86

87 88
            $offset = ($this->page-1) * PROFILES_PER_PAGE;
            $limit =  PROFILES_PER_PAGE + 1;
Evan Prodromou's avatar
Evan Prodromou committed
89

90
            $cnt = 0;
91

92
            if ($this->tag) {
93
                $subscriptions = $this->target->getTaggedSubscriptions($this->tag, $offset, $limit);
94
            } else {
95
                $subscriptions = $this->target->getSubscribed($offset, $limit);
96
            }
Evan Prodromou's avatar
Evan Prodromou committed
97

98
            if ($subscriptions) {
99
                $subscriptions_list = new SubscriptionsList($subscriptions, $this->target, $this);
100 101 102 103
                $cnt = $subscriptions_list->show();
                if (0 == $cnt) {
                    $this->showEmptyListMessage();
                }
104
            }
Evan Prodromou's avatar
Evan Prodromou committed
105

106 107
            $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
                              $this->page, 'subscriptions',
108
                              array('nickname' => $this->target->getNickname()));
109 110 111 112


            Event::handle('EndShowSubscriptionsContent', array($this));
        }
113
    }
114

115 116 117 118 119 120
    function showScripts()
    {
        parent::showScripts();
        $this->autofocus('tag');
    }

121 122
    function showEmptyListMessage()
    {
123
        if ($this->scoped instanceof Profile && $this->target->id === $this->scoped->id) {
124 125 126 127 128 129
                // TRANS: Subscription list text when the logged in user has no subscriptions.
                // TRANS: This message contains Markdown URLs. The link description is between
                // TRANS: square brackets, and the link between parentheses. Do not separate "]("
                // TRANS: and do not change the URL part.
                $message = _('You\'re not listening to anyone\'s notices right now, try subscribing to people you know. '.
                             'Try [people search](%%action.peoplesearch%%), look for members in groups you\'re interested '.
130
                             'in and in our [featured users](%%action.featured%%).');
131
        } else {
132 133
            // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
            // TRANS: as an anonymous user. %s is the user nickname.
134
            $message = sprintf(_('%s is not listening to anyone.'), $this->target->getNickname());
135 136 137 138 139 140
        }

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

142 143 144 145 146 147 148 149 150
    /**
     * Link to feeds of subscriptions
     *
     * @return array of Feed objects
     */
    function getFeeds()
    {
        return array(new Feed(Feed::ATOM,
                              common_local_url('AtomPubSubscriptionFeed',
151
                                               array('subscriber' => $this->target->id)),
152
                              // TRANS: Atom feed title. %s is a profile nickname.
153
                              sprintf(_('Subscription feed for %s (Atom)'),
154
                                      $this->target->getNickname())));
155
    }
156
}