3 * StatusNet, the distributed open-source microblogging tool
5 * List of a user's subscriptions
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
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/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
36 * A list of the user's subscriptions
40 * @author Evan Prodromou <evan@status.net>
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/
44 class SubscriptionsAction extends GalleryAction
48 if ($this->page == 1) {
49 // TRANS: Header for subscriptions overview for a user (first page).
50 // TRANS: %s is a user nickname.
51 return sprintf(_('%s subscriptions'), $this->user->nickname);
53 // TRANS: Header for subscriptions overview for a user (not first page).
54 // TRANS: %1$s is a user nickname, %2$d is the page number.
55 return sprintf(_('%1$s subscriptions, page %2$d'),
56 $this->user->nickname,
61 function showPageNotice()
63 $user = common_current_user();
64 if ($user && ($user->id == $this->profile->id)) {
65 $this->element('p', null,
66 // TRANS: Page notice for page with an overview of all subscriptions
67 // TRANS: of the logged in user's own profile.
68 _('These are the people whose notices '.
71 $this->element('p', null,
72 // TRANS: Page notice for page with an overview of all subscriptions of a user other
73 // TRANS: than the logged in user. %s is the user nickname.
74 sprintf(_('These are the people whose '.
75 'notices %s listens to.'),
76 $this->profile->nickname));
82 return $this->getTags('subscribed', 'subscriber');
85 function showContent()
87 if (Event::handle('StartShowSubscriptionsContent', array($this))) {
88 parent::showContent();
90 $offset = ($this->page-1) * PROFILES_PER_PAGE;
91 $limit = PROFILES_PER_PAGE + 1;
96 $subscriptions = $this->user->getTaggedSubscriptions($this->tag, $offset, $limit);
98 $subscriptions = $this->user->getSubscriptions($offset, $limit);
101 if ($subscriptions) {
102 $subscriptions_list = new SubscriptionsList($subscriptions, $this->user, $this);
103 $cnt = $subscriptions_list->show();
105 $this->showEmptyListMessage();
109 $subscriptions->free();
111 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
112 $this->page, 'subscriptions',
113 array('nickname' => $this->user->nickname));
116 Event::handle('EndShowSubscriptionsContent', array($this));
120 function showScripts()
122 parent::showScripts();
123 $this->autofocus('tag');
126 function showEmptyListMessage()
128 if (common_logged_in()) {
129 $current_user = common_current_user();
130 if ($this->user->id === $current_user->id) {
131 // TRANS: Subscription list text when the logged in user has no subscriptions.
132 // TRANS: This message contains Markdown URLs. The link description is between
133 // TRANS: square brackets, and the link between parentheses. Do not separate "]("
134 // TRANS: and do not change the URL part.
135 $message = _('You\'re not listening to anyone\'s notices right now, try subscribing to people you know. '.
136 'Try [people search](%%action.peoplesearch%%), look for members in groups you\'re interested '.
137 'in and in our [featured users](%%action.featured%%). '.
138 'If you\'re a [Twitter user](%%action.twittersettings%%), you can automatically subscribe to '.
139 'people you already follow there.');
141 // TRANS: Subscription list text when looking at the subscriptions for a of a user other
142 // TRANS: than the logged in user that has no subscriptions. %s is the user nickname.
143 $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
147 // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
148 // TRANS: as an anonymous user. %s is the user nickname.
149 $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
152 $this->elementStart('div', 'guide');
153 $this->raw(common_markup_to_html($message));
154 $this->elementEnd('div');
157 function showSections()
159 parent::showSections();
160 $cloud = new SubscriptionsPeopleTagCloudSection($this);
163 $cloud2 = new SubscriptionsPeopleSelfTagCloudSection($this);
168 * Link to feeds of subscriptions
170 * @return array of Feed objects
175 return array(new Feed(Feed::ATOM,
176 common_local_url('AtomPubSubscriptionFeed',
177 array('subscriber' => $this->profile->id)),
178 sprintf(_('Subscription feed for %s (Atom)'),
179 $this->profile->nickname)));
184 // XXX SubscriptionsList and SubscriptionList are dangerously close
186 class SubscriptionsList extends SubscriptionList
188 function newListItem($profile)
190 return new SubscriptionsListItem($profile, $this->owner, $this->action);
194 class SubscriptionsListItem extends SubscriptionListItem
196 function showProfile()
198 $this->startProfile();
200 $this->showFullName();
201 $this->showLocation();
202 $this->showHomepage();
206 $cur = common_current_user();
207 if (!empty($cur) && $cur->id == $this->owner->id) {
208 $this->showOwnerControls();
213 function showOwnerControls()
215 $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
216 'subscribed' => $this->profile->id));
221 if (!common_config('xmpp', 'enabled') && !common_config('sms', 'enabled')) {
225 $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id,
227 'class' => 'form_subscription_edit',
228 'action' => common_local_url('subedit')));
229 $this->out->hidden('token', common_session_token());
230 $this->out->hidden('profile', $this->profile->id);
231 if (common_config('xmpp', 'enabled')) {
232 $attrs = array('name' => 'jabber',
233 'type' => 'checkbox',
234 'class' => 'checkbox',
235 'id' => 'jabber-'.$this->profile->id);
237 $attrs['checked'] = 'checked';
240 $this->out->element('input', $attrs);
241 // TRANS: Checkbox label for enabling Jabber messages for a profile in a subscriptions list.
242 $this->out->element('label', array('for' => 'jabber-'.$this->profile->id), _('Jabber'));
244 $this->out->hidden('jabber', $sub->jabber);
246 if (common_config('sms', 'enabled')) {
247 $attrs = array('name' => 'sms',
248 'type' => 'checkbox',
249 'class' => 'checkbox',
250 'id' => 'sms-'.$this->profile->id);
252 $attrs['checked'] = 'checked';
255 $this->out->element('input', $attrs);
256 // TRANS: Checkbox label for enabling SMS messages for a profile in a subscriptions list.
257 $this->out->element('label', array('for' => 'sms-'.$this->profile->id), _('SMS'));
259 $this->out->hidden('sms', $sub->sms);
261 // TRANS: Save button for settings for a profile in a subscriptions list.
262 $this->out->submit('save', _m('BUTTON','Save'));
263 $this->out->elementEnd('form');