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

subscriptions.php 6.58 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
 */

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

/**
36
 * A list of the user's subscriptions
Evan Prodromou's avatar
Evan Prodromou committed
37
 *
38
 * @category Social
39
 * @package  StatusNet
40
 * @author   Evan Prodromou <evan@status.net>
Evan Prodromou's avatar
Evan Prodromou committed
41
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42
 * @link     http://status.net/
Evan Prodromou's avatar
Evan Prodromou committed
43
 */
Evan Prodromou's avatar
Evan Prodromou committed
44

Evan Prodromou's avatar
Evan Prodromou committed
45
if (!defined('STATUSNET')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
46

47
class SubscriptionsAction extends GalleryAction
48
{
Evan Prodromou's avatar
Evan Prodromou committed
49
    function title()
50
    {
Evan Prodromou's avatar
Evan Prodromou committed
51 52 53 54 55 56 57
        if ($this->page == 1) {
            return sprintf(_('%s subscriptions'), $this->user->nickname);
        } else {
            return sprintf(_('%s subscriptions, page %d'),
                           $this->user->nickname,
                           $this->page);
        }
58
    }
59

Evan Prodromou's avatar
Evan Prodromou committed
60
    function showPageNotice()
61
    {
Evan Prodromou's avatar
Evan Prodromou committed
62 63 64 65 66 67 68 69 70 71 72
        $user =& common_current_user();
        if ($user && ($user->id == $this->profile->id)) {
            $this->element('p', null,
                           _('These are the people whose notices '.
                             'you listen to.'));
        } else {
            $this->element('p', null,
                           sprintf(_('These are the people whose '.
                                     'notices %s listens to.'),
                                   $this->profile->nickname));
        }
73
    }
74

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

    function showContent()
    {
82 83
        parent::showContent();

Evan Prodromou's avatar
Evan Prodromou committed
84 85 86
        $offset = ($this->page-1) * PROFILES_PER_PAGE;
        $limit =  PROFILES_PER_PAGE + 1;

87 88
        $cnt = 0;

89 90 91 92 93
        if ($this->tag) {
            $subscriptions = $this->user->getTaggedSubscriptions($this->tag, $offset, $limit);
        } else {
            $subscriptions = $this->user->getSubscriptions($offset, $limit);
        }
Evan Prodromou's avatar
Evan Prodromou committed
94

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

        $subscriptions->free();

        $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
                          $this->page, 'subscriptions',
                          array('nickname' => $this->user->nickname));
108
    }
109 110 111 112 113 114 115 116

    function showEmptyListMessage()
    {
        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->user->id === $current_user->id) {
                $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 in and in our [featured users](%%action.featured%%). If you\'re a [Twitter user](%%action.twittersettings%%), you can automatically subscribe to people you already follow there.');
            } else {
117
                $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
118 119 120
            }
        }
        else {
121
            $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
122 123 124 125 126 127
        }

        $this->elementStart('div', 'guide');
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }
128 129 130 131 132 133 134 135 136 137

    function showSections()
    {
        parent::showSections();
        $cloud = new SubscriptionsPeopleTagCloudSection($this);
        $cloud->show();

        $cloud2 = new SubscriptionsPeopleSelfTagCloudSection($this);
        $cloud2->show();
    }
138 139
}

140 141 142
// XXX SubscriptionsList and SubscriptionList are dangerously close

class SubscriptionsList extends SubscriptionList
143
{
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    function newListItem($profile)
    {
        return new SubscriptionsListItem($profile, $this->owner, $this->action);
    }
}

class SubscriptionsListItem extends SubscriptionListItem
{
    function showProfile()
    {
        $this->startProfile();
        $this->showAvatar();
        $this->showFullName();
        $this->showLocation();
        $this->showHomepage();
        $this->showBio();
        $this->showTags();
        // Relevant portion!
162 163 164 165
        $cur = common_current_user();
        if (!empty($cur) && $cur->id == $this->owner->id) {
            $this->showOwnerControls();
        }
166 167 168 169
        $this->endProfile();
    }

    function showOwnerControls()
170
    {
171
        $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
172
                                           'subscribed' => $this->profile->id));
173 174 175 176
        if (!$sub) {
            return;
        }

177 178 179 180
        if (!common_config('xmpp', 'enabled') && !common_config('sms', 'enabled')) {
            return;
        }

181
        $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id,
Evan Prodromou's avatar
Evan Prodromou committed
182
                                          'method' => 'post',
183
                                          'class' => 'form_subscription_edit',
Evan Prodromou's avatar
Evan Prodromou committed
184
                                          'action' => common_local_url('subedit')));
185
        $this->out->hidden('token', common_session_token());
186
        $this->out->hidden('profile', $this->profile->id);
187 188 189 190 191 192 193 194 195 196
        if (common_config('xmpp', 'enabled')) {
            $this->out->checkbox('jabber', _('Jabber'), $sub->jabber);
        } else {
            $this->out->hidden('jabber', $sub->jabber);
        }
        if (common_config('sms', 'enabled')) {
            $this->out->checkbox('sms', _('SMS'), $sub->sms);
        } else {
            $this->out->hidden('sms', $sub->sms);
        }
197 198
        $this->out->submit('save', _('Save'));
        $this->out->elementEnd('form');
199 200
        return;
    }
201
}