]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribers.php
ad522a4bae63372b0632f302ec794a329ba88735
[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         $cloud = new SubscribersPeopleTagCloudSection($this);
139         $cloud->show();
140
141         $cloud2 = new SubscribersPeopleSelfTagCloudSection($this);
142         $cloud2->show();
143     }
144 }
145
146 class SubscribersList extends SubscriptionList
147 {
148     function newListItem($profile)
149     {
150         return new SubscribersListItem($profile, $this->owner, $this->action);
151     }
152 }
153
154 class SubscribersListItem extends SubscriptionListItem
155 {
156     function showActions()
157     {
158         $this->startActions();
159         if (Event::handle('StartProfileListItemActionElements', array($this))) {
160             $this->showSubscribeButton();
161             // Relevant code!
162             $this->showBlockForm();
163             Event::handle('EndProfileListItemActionElements', array($this));
164         }
165         $this->endActions();
166     }
167
168     function showBlockForm()
169     {
170         $user = common_current_user();
171
172         if (!empty($user) && $this->owner->id == $user->id) {
173             $returnto = array('action' => 'subscribers',
174                               'nickname' => $this->owner->nickname);
175             $page = $this->out->arg('page');
176             if ($page) {
177                 $returnto['param-page'] = $page;
178             }
179             $bf = new BlockForm($this->out, $this->profile, $returnto);
180             $bf->show();
181         }
182     }
183
184     function linkAttributes()
185     {
186         $aAttrs = parent::linkAttributes();
187
188         if (common_config('nofollow', 'subscribers')) {
189             $aAttrs['rel'] .= ' nofollow';
190         }
191
192         return $aAttrs;
193     }
194
195     function homepageAttributes()
196     {
197         $aAttrs = parent::linkAttributes();
198
199         if (common_config('nofollow', 'subscribers')) {
200             $aAttrs['rel'] = 'nofollow';
201         }
202
203         return $aAttrs;
204     }
205 }