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