]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribers.php
Add IdentiCurse to notice sources
[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         $subscribers->free();
104
105         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
106                           $this->page, 'subscribers',
107                           array('nickname' => $this->user->nickname));
108     }
109
110     function showEmptyListMessage()
111     {
112         if (common_logged_in()) {
113             $current_user = common_current_user();
114             if ($this->user->id === $current_user->id) {
115                 // TRANS: Subscriber list text when the logged in user has no subscribers.
116                 $message = _('You have no subscribers. Try subscribing to people you know and they might return the favor.');
117             } else {
118                 // TRANS: Subscriber list text when looking at the subscribers for a of a user other
119                 // TRANS: than the logged in user that has no subscribers. %s is the user nickname.
120                 $message = sprintf(_('%s has no subscribers. Want to be the first?'), $this->user->nickname);
121             }
122         }
123         else {
124             // TRANS: Subscriber list text when looking at the subscribers for a of a user that has none
125             // TRANS: as an anonymous user. %s is the user nickname.
126             // TRANS: This message contains a Markdown URL. The link description is between
127             // TRANS: square brackets, and the link between parentheses. Do not separate "]("
128             // TRANS: and do not change the URL part.
129             $message = sprintf(_('%s has no subscribers. Why not [register an account](%%%%action.register%%%%) and be the first?'), $this->user->nickname);
130         }
131
132         $this->elementStart('div', 'guide');
133         $this->raw(common_markup_to_html($message));
134         $this->elementEnd('div');
135     }
136
137     function showSections()
138     {
139         parent::showSections();
140         $cloud = new SubscribersPeopleTagCloudSection($this);
141         $cloud->show();
142
143         $cloud2 = new SubscribersPeopleSelfTagCloudSection($this);
144         $cloud2->show();
145     }
146 }
147
148 class SubscribersList extends SubscriptionList
149 {
150     function newListItem($profile)
151     {
152         return new SubscribersListItem($profile, $this->owner, $this->action);
153     }
154 }
155
156 class SubscribersListItem extends SubscriptionListItem
157 {
158     function showActions()
159     {
160         $this->startActions();
161         if (Event::handle('StartProfileListItemActionElements', array($this))) {
162             $this->showSubscribeButton();
163             // Relevant code!
164             $this->showBlockForm();
165             Event::handle('EndProfileListItemActionElements', array($this));
166         }
167         $this->endActions();
168     }
169
170     function showBlockForm()
171     {
172         $user = common_current_user();
173
174         if (!empty($user) && $this->owner->id == $user->id) {
175             $returnto = array('action' => 'subscribers',
176                               'nickname' => $this->owner->nickname);
177             $page = $this->out->arg('page');
178             if ($page) {
179                 $returnto['param-page'] = $page;
180             }
181             $bf = new BlockForm($this->out, $this->profile, $returnto);
182             $bf->show();
183         }
184     }
185
186     function linkAttributes()
187     {
188         $aAttrs = parent::linkAttributes();
189
190         if (common_config('nofollow', 'subscribers')) {
191             $aAttrs['rel'] .= ' nofollow';
192         }
193
194         return $aAttrs;
195     }
196
197     function homepageAttributes()
198     {
199         $aAttrs = parent::linkAttributes();
200
201         if (common_config('nofollow', 'subscribers')) {
202             $aAttrs['rel'] = 'nofollow';
203         }
204
205         return $aAttrs;
206     }
207 }