]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagsubscribers.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / actions / peopletagsubscribers.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of peopletag 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  Group
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2011 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once(INSTALLDIR.'/lib/profilelist.php');
35
36 /**
37  * List of peopletag subscribers
38  *
39  * @category Peopletag
40  * @package  StatusNet
41  * @author   Evan Prodromou <evan@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45 class PeopletagsubscribersAction extends Action
46 {
47     var $page = null;
48     var $peopletag = null;
49     var $tagger = null;
50
51     function isReadOnly($args)
52     {
53         return true;
54     }
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
60
61         if (common_config('singleuser', 'enabled')) {
62             $tagger_arg = User::singleUserNickname();
63         } else {
64             $tagger_arg = $this->arg('tagger');
65         }
66
67         $tag_arg = $this->arg('tag');
68         $tagger = common_canonical_nickname($tagger_arg);
69         $tag = common_canonical_tag($tag_arg);
70
71         // Permanent redirect on non-canonical nickname
72
73         if ($tagger_arg != $tagger || $tag_arg != $tag) {
74             $args = array('tagger' => $nickname, 'tag' => $tag);
75             if ($this->page != 1) {
76                 $args['page'] = $this->page;
77             }
78             common_redirect(common_local_url('peopletagged', $args), 301);
79         }
80
81         if (!$tagger) {
82             // TRANS: Client error displayed when a tagger is expected but not provided.
83             $this->clientError(_('No tagger.'), 404);
84         }
85
86         $user = User::getKV('nickname', $tagger);
87
88         if (!$user) {
89             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
90             $this->clientError(_('No such user.'), 404);
91         }
92
93         $this->tagger = $user->getProfile();
94         $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
95
96         if (!$this->peopletag) {
97             // TRANS: Client error displayed trying to reference a non-existing list.
98             $this->clientError(_('No such list.'), 404);
99         }
100
101         return true;
102     }
103
104     function title()
105     {
106         if ($this->page == 1) {
107             // TRANS: Page title for list of list subscribers.
108             // TRANS: %1$s is a list, %2$s is a user nickname.
109             return sprintf(_('Subscribers to list %1$s by %2$s'),
110                            $this->peopletag->tag, $this->tagger->nickname);
111         } else {
112             // TRANS: Page title for list of list subscribers.
113             // TRANS: %1$s is a list, %2$s is a user nickname, %3$d is a page number.
114             return sprintf(_('Subscribers to list %1$s by %2$s, page %3$d'),
115                            $this->peopletag->tag, $this->tagger->nickname,
116                            $this->page);
117         }
118     }
119
120     function handle($args)
121     {
122         parent::handle($args);
123         $this->showPage();
124     }
125
126     function showPageNotice()
127     {
128     }
129
130     function showLocalNav()
131     {
132         $nav = new PeopletagGroupNav($this);
133         $nav->show();
134     }
135
136     function showContent()
137     {
138         $offset = ($this->page-1) * PROFILES_PER_PAGE;
139         $limit =  PROFILES_PER_PAGE + 1;
140
141         $cnt = 0;
142
143         $subs = $this->peopletag->getSubscribers($offset, $limit);
144
145         if ($subs) {
146             $subscriber_list = new PeopletagSubscriberList($subs, $this->peopletag, $this);
147             $cnt = $subscriber_list->show();
148         }
149
150         $subs->free();
151
152         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
153                           $this->page, 'peopletagsubscribers',
154                           array('tagger' => $this->tagger->nickname,
155                                 'tag'    => $this->peopletag->tag));
156     }
157 }
158
159 class PeopletagSubscriberList extends ProfileList
160 {
161     var $peopletag = null;
162
163     function __construct($profile, $peopletag, $action)
164     {
165         parent::__construct($profile, $action);
166
167         $this->peopletag = $peopletag;
168     }
169
170     function newListItem($profile)
171     {
172         return new PeopletagSubscriberListItem($profile, $this->peopletag, $this->action);
173     }
174 }
175
176 class PeopletagSubscriberListItem extends ProfileListItem
177 {
178     var $peopletag = null;
179
180     function __construct($profile, $peopletag, $action)
181     {
182         parent::__construct($profile, $action);
183
184         $this->peopletag = $peopletag;
185     }
186
187     function showFullName()
188     {
189         parent::showFullName();
190         if ($this->profile->id == $this->peopletag->tagger) {
191             $this->out->text(' ');
192             // TRANS: Addition in tag subscribers list for creator of a tag.
193             $this->out->element('span', 'role', _('Creator'));
194         }
195     }
196
197     function showActions()
198     {
199         $this->startActions();
200         if (Event::handle('StartProfileListItemActionElements', array($this))) {
201             $this->showSubscribeButton();
202             Event::handle('EndProfileListItemActionElements', array($this));
203         }
204         $this->endActions();
205     }
206
207     function linkAttributes()
208     {
209         $aAttrs = parent::linkAttributes();
210
211         if (common_config('nofollow', 'members')) {
212             $aAttrs['rel'] .= ' nofollow';
213         }
214
215         return $aAttrs;
216     }
217
218     function homepageAttributes()
219     {
220         $aAttrs = parent::linkAttributes();
221
222         if (common_config('nofollow', 'members')) {
223             $aAttrs['rel'] = 'nofollow';
224         }
225
226         return $aAttrs;
227     }
228
229     /**
230      * Fetch necessary return-to arguments for the profile forms
231      * to return to this list when they're done.
232      *
233      * @return array
234      */
235     protected function returnToArgs()
236     {
237         $args = array('action' => 'peopletagsubscribers',
238                       'tag' => $this->peopletag->tag,
239                       'tagger' => $this->profile->nickname);
240         $page = $this->out->arg('page');
241         if ($page) {
242             $args['param-page'] = $page;
243         }
244         return $args;
245     }
246 }