]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscriptions.php
Added more checked type-hints.
[quix0rs-gnu-social.git] / actions / subscriptions.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of a user's subscriptions
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Social
23  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * A list of the user's subscriptions
37  *
38  * @category Social
39  * @package  StatusNet
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/
43  */
44 class SubscriptionsAction extends GalleryAction
45 {
46     function title()
47     {
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->target->getNickname());
52         } else {
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->target->getNickname(),
57                            $this->page);
58         }
59     }
60
61     function showPageNotice()
62     {
63         if ($this->scoped instanceof Profile && $this->scoped->id === $this->target->id) {
64             $this->element('p', null,
65                            // TRANS: Page notice for page with an overview of all subscriptions
66                            // TRANS: of the logged in user's own profile.
67                            _('These are the people whose notices '.
68                              'you listen to.'));
69         } else {
70             $this->element('p', null,
71                            // TRANS: Page notice for page with an overview of all subscriptions of a user other
72                            // TRANS: than the logged in user. %s is the user nickname.
73                            sprintf(_('These are the people whose '.
74                                      'notices %s listens to.'),
75                                    $this->target->getNickname()));
76         }
77     }
78
79     function getAllTags()
80     {
81         return $this->getTags('subscribed', 'subscriber');
82     }
83
84     function showContent()
85     {
86         if (Event::handle('StartShowSubscriptionsContent', array($this))) {
87             parent::showContent();
88
89             $offset = ($this->page-1) * PROFILES_PER_PAGE;
90             $limit =  PROFILES_PER_PAGE + 1;
91
92             $cnt = 0;
93
94             if ($this->tag) {
95                 $subscriptions = $this->target->getTaggedSubscriptions($this->tag, $offset, $limit);
96             } else {
97                 $subscriptions = $this->target->getSubscribed($offset, $limit);
98             }
99
100             if ($subscriptions) {
101                 $subscriptions_list = new SubscriptionsList($subscriptions, $this->target, $this);
102                 $cnt = $subscriptions_list->show();
103                 if (0 == $cnt) {
104                     $this->showEmptyListMessage();
105                 }
106             }
107
108             $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
109                               $this->page, 'subscriptions',
110                               array('nickname' => $this->target->getNickname()));
111
112
113             Event::handle('EndShowSubscriptionsContent', array($this));
114         }
115     }
116
117     function showScripts()
118     {
119         parent::showScripts();
120         $this->autofocus('tag');
121     }
122
123     function showEmptyListMessage()
124     {
125         if ($this->scoped instanceof Profile && $this->target->id === $this->scoped->id) {
126                 // TRANS: Subscription list text when the logged in user has no subscriptions.
127                 // TRANS: This message contains Markdown URLs. The link description is between
128                 // TRANS: square brackets, and the link between parentheses. Do not separate "]("
129                 // TRANS: and do not change the URL part.
130                 $message = _('You\'re not listening to anyone\'s notices right now, try subscribing to people you know. '.
131                              'Try [people search](%%action.peoplesearch%%), look for members in groups you\'re interested '.
132                              'in and in our [featured users](%%action.featured%%).');
133         } else {
134             // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
135             // TRANS: as an anonymous user. %s is the user nickname.
136             $message = sprintf(_('%s is not listening to anyone.'), $this->target->getNickname());
137         }
138
139         $this->elementStart('div', 'guide');
140         $this->raw(common_markup_to_html($message));
141         $this->elementEnd('div');
142     }
143
144     /**
145      * Link to feeds of subscriptions
146      *
147      * @return array of Feed objects
148      */
149     function getFeeds()
150     {
151         return array(new Feed(Feed::ATOM,
152                               common_local_url('AtomPubSubscriptionFeed',
153                                                array('subscriber' => $this->target->id)),
154                               // TRANS: Atom feed title. %s is a profile nickname.
155                               sprintf(_('Subscription feed for %s (Atom)'),
156                                       $this->target->getNickname())));
157     }
158 }
159
160 // XXX SubscriptionsList and SubscriptionList are dangerously close
161
162 class SubscriptionsList extends SubscriptionList
163 {
164     function newListItem(Profile $profile)
165     {
166         return new SubscriptionsListItem($profile, $this->owner, $this->action);
167     }
168 }
169
170 class SubscriptionsListItem extends SubscriptionListItem
171 {
172     function showOwnerControls()
173     {
174         $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
175                                            'subscribed' => $this->profile->id));
176         if (!$sub) {
177             return;
178         }
179
180         $transports = array();
181         Event::handle('GetImTransports', array(&$transports));
182         if (!$transports && !common_config('sms', 'enabled')) {
183             return;
184         }
185
186         $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id,
187                                           'method' => 'post',
188                                           'class' => 'form_subscription_edit',
189                                           'action' => common_local_url('subedit')));
190         $this->out->hidden('token', common_session_token());
191         $this->out->hidden('profile', $this->profile->id);
192         if ($transports) {
193             $attrs = array('name' => 'jabber',
194                            'type' => 'checkbox',
195                            'class' => 'checkbox',
196                            'id' => 'jabber-'.$this->profile->id);
197             if ($sub->jabber) {
198                 $attrs['checked'] = 'checked';
199             }
200
201             $this->out->element('input', $attrs);
202             // TRANS: Checkbox label for enabling IM messages for a profile in a subscriptions list.
203             $this->out->element('label', array('for' => 'jabber-'.$this->profile->id), _m('LABEL','IM'));
204         } else {
205             $this->out->hidden('jabber', $sub->jabber);
206         }
207         if (common_config('sms', 'enabled')) {
208             $attrs = array('name' => 'sms',
209                            'type' => 'checkbox',
210                            'class' => 'checkbox',
211                            'id' => 'sms-'.$this->profile->id);
212             if ($sub->sms) {
213                 $attrs['checked'] = 'checked';
214             }
215
216             $this->out->element('input', $attrs);
217             // TRANS: Checkbox label for enabling SMS messages for a profile in a subscriptions list.
218             $this->out->element('label', array('for' => 'sms-'.$this->profile->id), _('SMS'));
219         } else {
220             $this->out->hidden('sms', $sub->sms);
221         }
222         // TRANS: Save button for settings for a profile in a subscriptions list.
223         $this->out->submit('save', _m('BUTTON','Save'));
224         $this->out->elementEnd('form');
225     }
226 }