]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribers.php
parent::handlePost() in CancelsubscriptionAction
[quix0rs-gnu-social.git] / actions / subscribers.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List a user's subscribers
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  * List a user's subscribers
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 SubscribersAction extends GalleryAction
45 {
46     function title()
47     {
48         if ($this->page == 1) {
49             // TRANS: Header for list of subscribers for a user (first page).
50             // TRANS: %s is the user's nickname.
51             return sprintf(_('%s subscribers'), $this->user->nickname);
52         } else {
53             // TRANS: Header for list of subscribers for a user (not first page).
54             // TRANS: %1$s is the user's nickname, $2$d is the page number.
55             return sprintf(_('%1$s subscribers, 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 subscribers
67                            // TRANS: of the logged in user's own profile.
68                            _('These are the people who listen to '.
69                              'your notices.'));
70         } else {
71             $this->element('p', null,
72                            // TRANS: Page notice for page with an overview of all subscribers of a user other
73                            // TRANS: than the logged in user. %s is the user nickname.
74                            sprintf(_('These are the people who '.
75                                      'listen to %s\'s notices.'),
76                                    $this->profile->nickname));
77         }
78     }
79
80     function showContent()
81     {
82         parent::showContent();
83
84         $offset = ($this->page-1) * PROFILES_PER_PAGE;
85         $limit =  PROFILES_PER_PAGE + 1;
86
87         $cnt = 0;
88
89         if ($this->tag) {
90             $subscribers = $this->user->getTaggedSubscribers($this->tag, $offset, $limit);
91         } else {
92             $subscribers = $this->user->getSubscribers($offset, $limit);
93         }
94
95         if ($subscribers) {
96             $subscribers_list = new SubscribersList($subscribers, $this->user, $this);
97             $cnt = $subscribers_list->show();
98             if (0 == $cnt) {
99                 $this->showEmptyListMessage();
100             }
101         }
102
103         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
104                           $this->page, 'subscribers',
105                           array('nickname' => $this->user->nickname));
106     }
107
108     function showEmptyListMessage()
109     {
110         if (common_logged_in()) {
111             $current_user = common_current_user();
112             if ($this->user->id === $current_user->id) {
113                 // TRANS: Subscriber list text when the logged in user has no subscribers.
114                 $message = _('You have no subscribers. Try subscribing to people you know and they might return the favor.');
115             } else {
116                 // TRANS: Subscriber list text when looking at the subscribers for a of a user other
117                 // TRANS: than the logged in user that has no subscribers. %s is the user nickname.
118                 $message = sprintf(_('%s has no subscribers. Want to be the first?'), $this->user->nickname);
119             }
120         }
121         else {
122             // TRANS: Subscriber list text when looking at the subscribers for a of a user that has none
123             // TRANS: as an anonymous user. %s is the user nickname.
124             // TRANS: This message contains a Markdown URL. The link description is between
125             // TRANS: square brackets, and the link between parentheses. Do not separate "]("
126             // TRANS: and do not change the URL part.
127             $message = sprintf(_('%s has no subscribers. Why not [register an account](%%%%action.register%%%%) and be the first?'), $this->user->nickname);
128         }
129
130         $this->elementStart('div', 'guide');
131         $this->raw(common_markup_to_html($message));
132         $this->elementEnd('div');
133     }
134
135     function showSections()
136     {
137         parent::showSections();
138     }
139 }
140
141 class SubscribersList extends SubscriptionList
142 {
143     function newListItem($profile)
144     {
145         return new SubscribersListItem($profile, $this->owner, $this->action);
146     }
147 }
148
149 class SubscribersListItem extends SubscriptionListItem
150 {
151     function showActions()
152     {
153         $this->startActions();
154         if (Event::handle('StartProfileListItemActionElements', array($this))) {
155             $this->showSubscribeButton();
156             // Relevant code!
157             $this->showBlockForm();
158             Event::handle('EndProfileListItemActionElements', array($this));
159         }
160         $this->endActions();
161     }
162
163     function showBlockForm()
164     {
165         $user = common_current_user();
166
167         if (!empty($user) && $this->owner->id == $user->id) {
168             $returnto = array('action' => 'subscribers',
169                               'nickname' => $this->owner->nickname);
170             $page = $this->out->arg('page');
171             if ($page) {
172                 $returnto['param-page'] = $page;
173             }
174             $bf = new BlockForm($this->out, $this->profile, $returnto);
175             $bf->show();
176         }
177     }
178
179     function linkAttributes()
180     {
181         $aAttrs = parent::linkAttributes();
182
183         if (common_config('nofollow', 'subscribers')) {
184             $aAttrs['rel'] .= ' nofollow';
185         }
186
187         return $aAttrs;
188     }
189
190     function homepageAttributes()
191     {
192         $aAttrs = parent::linkAttributes();
193
194         if (common_config('nofollow', 'subscribers')) {
195             $aAttrs['rel'] = 'nofollow';
196         }
197
198         return $aAttrs;
199     }
200 }