]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscriptions.php
Remove missing twittersettings page from subscriptions helper
[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->user->nickname);
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->user->nickname,
57                            $this->page);
58         }
59     }
60
61     function showPageNotice()
62     {
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 '.
69                              'you listen to.'));
70         } else {
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));
77         }
78     }
79
80     function getAllTags()
81     {
82         return $this->getTags('subscribed', 'subscriber');
83     }
84
85     function showContent()
86     {
87         if (Event::handle('StartShowSubscriptionsContent', array($this))) {
88             parent::showContent();
89
90             $offset = ($this->page-1) * PROFILES_PER_PAGE;
91             $limit =  PROFILES_PER_PAGE + 1;
92
93             $cnt = 0;
94
95             if ($this->tag) {
96                 $subscriptions = $this->user->getTaggedSubscriptions($this->tag, $offset, $limit);
97             } else {
98                 $subscriptions = $this->user->getSubscriptions($offset, $limit);
99             }
100
101             if ($subscriptions) {
102                 $subscriptions_list = new SubscriptionsList($subscriptions, $this->user, $this);
103                 $cnt = $subscriptions_list->show();
104                 if (0 == $cnt) {
105                     $this->showEmptyListMessage();
106                 }
107             }
108
109             $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
110                               $this->page, 'subscriptions',
111                               array('nickname' => $this->user->nickname));
112
113
114             Event::handle('EndShowSubscriptionsContent', array($this));
115         }
116     }
117
118     function showScripts()
119     {
120         parent::showScripts();
121         $this->autofocus('tag');
122     }
123
124     function showEmptyListMessage()
125     {
126         if (common_logged_in()) {
127             $current_user = common_current_user();
128             if ($this->user->id === $current_user->id) {
129                 // TRANS: Subscription list text when the logged in user has no subscriptions.
130                 // TRANS: This message contains Markdown URLs. The link description is between
131                 // TRANS: square brackets, and the link between parentheses. Do not separate "]("
132                 // TRANS: and do not change the URL part.
133                 $message = _('You\'re not listening to anyone\'s notices right now, try subscribing to people you know. '.
134                              'Try [people search](%%action.peoplesearch%%), look for members in groups you\'re interested '.
135                              'in and in our [featured users](%%action.featured%%).');
136             } else {
137                 // TRANS: Subscription list text when looking at the subscriptions for a of a user other
138                 // TRANS: than the logged in user that has no subscriptions. %s is the user nickname.
139                 $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
140             }
141         }
142         else {
143             // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
144             // TRANS: as an anonymous user. %s is the user nickname.
145             $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
146         }
147
148         $this->elementStart('div', 'guide');
149         $this->raw(common_markup_to_html($message));
150         $this->elementEnd('div');
151     }
152
153     /**
154      * Link to feeds of subscriptions
155      *
156      * @return array of Feed objects
157      */
158     function getFeeds()
159     {
160         return array(new Feed(Feed::ATOM,
161                               common_local_url('AtomPubSubscriptionFeed',
162                                                array('subscriber' => $this->profile->id)),
163                               // TRANS: Atom feed title. %s is a profile nickname.
164                               sprintf(_('Subscription feed for %s (Atom)'),
165                                       $this->profile->nickname)));
166     }
167 }
168
169 // XXX SubscriptionsList and SubscriptionList are dangerously close
170
171 class SubscriptionsList extends SubscriptionList
172 {
173     function newListItem($profile)
174     {
175         return new SubscriptionsListItem($profile, $this->owner, $this->action);
176     }
177 }
178
179 class SubscriptionsListItem extends SubscriptionListItem
180 {
181     function showProfile()
182     {
183         $this->startProfile();
184         $this->showAvatar();
185         $this->showFullName();
186         $this->showLocation();
187         $this->showHomepage();
188         $this->showBio();
189         $this->showTags();
190         // Relevant portion!
191         $cur = common_current_user();
192         if (!empty($cur) && $cur->id == $this->owner->id) {
193             $this->showOwnerControls();
194         }
195         $this->endProfile();
196     }
197
198     function showOwnerControls()
199     {
200         $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
201                                            'subscribed' => $this->profile->id));
202         if (!$sub) {
203             return;
204         }
205
206         $transports = array();
207         Event::handle('GetImTransports', array(&$transports));
208         if (!$transports && !common_config('sms', 'enabled')) {
209             return;
210         }
211
212         $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id,
213                                           'method' => 'post',
214                                           'class' => 'form_subscription_edit',
215                                           'action' => common_local_url('subedit')));
216         $this->out->hidden('token', common_session_token());
217         $this->out->hidden('profile', $this->profile->id);
218         if ($transports) {
219             $attrs = array('name' => 'jabber',
220                            'type' => 'checkbox',
221                            'class' => 'checkbox',
222                            'id' => 'jabber-'.$this->profile->id);
223             if ($sub->jabber) {
224                 $attrs['checked'] = 'checked';
225             }
226
227             $this->out->element('input', $attrs);
228             // TRANS: Checkbox label for enabling IM messages for a profile in a subscriptions list.
229             $this->out->element('label', array('for' => 'jabber-'.$this->profile->id), _m('LABEL','IM'));
230         } else {
231             $this->out->hidden('jabber', $sub->jabber);
232         }
233         if (common_config('sms', 'enabled')) {
234             $attrs = array('name' => 'sms',
235                            'type' => 'checkbox',
236                            'class' => 'checkbox',
237                            'id' => 'sms-'.$this->profile->id);
238             if ($sub->sms) {
239                 $attrs['checked'] = 'checked';
240             }
241
242             $this->out->element('input', $attrs);
243             // TRANS: Checkbox label for enabling SMS messages for a profile in a subscriptions list.
244             $this->out->element('label', array('for' => 'sms-'.$this->profile->id), _('SMS'));
245         } else {
246             $this->out->hidden('sms', $sub->sms);
247         }
248         // TRANS: Save button for settings for a profile in a subscriptions list.
249         $this->out->submit('save', _m('BUTTON','Save'));
250         $this->out->elementEnd('form');
251         return;
252     }
253 }