]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagsubscribers.php
Merge branch '1.0.x' into testing
[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         $tagger_arg = $this->arg('tagger');
62         $tag_arg = $this->arg('tag');
63         $tagger = common_canonical_nickname($tagger_arg);
64         $tag = common_canonical_tag($tag_arg);
65
66         // Permanent redirect on non-canonical nickname
67
68         if ($tagger_arg != $tagger || $tag_arg != $tag) {
69             $args = array('tagger' => $nickname, 'tag' => $tag);
70             if ($this->page != 1) {
71                 $args['page'] = $this->page;
72             }
73             common_redirect(common_local_url('peopletagged', $args), 301);
74             return false;
75         }
76
77         if (!$tagger) {
78             // TRANS: Client error displayed when a tagger is expected but not provided.
79             $this->clientError(_('No tagger.'), 404);
80             return false;
81         }
82
83         $user = User::staticGet('nickname', $tagger);
84
85         if (!$user) {
86             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
87             $this->clientError(_('No such user.'), 404);
88             return false;
89         }
90
91         $this->tagger = $user->getProfile();
92         $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
93
94         if (!$this->peopletag) {
95             // TRANS: Client error displayed trying to reference a non-existing list.
96             $this->clientError(_('No such list.'), 404);
97             return false;
98         }
99
100         return true;
101     }
102
103     function title()
104     {
105         if ($this->page == 1) {
106             // TRANS: Page title for list of list subscribers.
107             // TRANS: %1$s is a list, %2$s is a user nickname.
108             return sprintf(_('Subscribers to list %1$s by %2$s'),
109                            $this->peopletag->tag, $this->tagger->nickname);
110         } else {
111             // TRANS: Page title for list of list subscribers.
112             // TRANS: %1$s is a list, %2$s is a user nickname, %3$d is a page number.
113             return sprintf(_('Subscribers to list %1$s by %2$s, page %3$d'),
114                            $this->peopletag->tag, $this->tagger->nickname,
115                            $this->page);
116         }
117     }
118
119     function handle($args)
120     {
121         parent::handle($args);
122         $this->showPage();
123     }
124
125     function showPageNotice()
126     {
127     }
128
129     function showLocalNav()
130     {
131         $nav = new PeopletagGroupNav($this);
132         $nav->show();
133     }
134
135     function showContent()
136     {
137         $offset = ($this->page-1) * PROFILES_PER_PAGE;
138         $limit =  PROFILES_PER_PAGE + 1;
139
140         $cnt = 0;
141
142         $subs = $this->peopletag->getSubscribers($offset, $limit);
143
144         if ($subs) {
145             $subscriber_list = new PeopletagSubscriberList($subs, $this->peopletag, $this);
146             $cnt = $subscriber_list->show();
147         }
148
149         $subs->free();
150
151         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
152                           $this->page, 'peopletagsubscribers',
153                           array('tagger' => $this->tagger->nickname,
154                                 'tag'    => $this->peopletag->tag));
155     }
156 }
157
158 class PeopletagSubscriberList extends ProfileList
159 {
160     var $peopletag = null;
161
162     function __construct($profile, $peopletag, $action)
163     {
164         parent::__construct($profile, $action);
165
166         $this->peopletag = $peopletag;
167     }
168
169     function newListItem($profile)
170     {
171         return new PeopletagSubscriberListItem($profile, $this->peopletag, $this->action);
172     }
173 }
174
175 class PeopletagSubscriberListItem extends ProfileListItem
176 {
177     var $peopletag = null;
178
179     function __construct($profile, $peopletag, $action)
180     {
181         parent::__construct($profile, $action);
182
183         $this->peopletag = $peopletag;
184     }
185
186     function showFullName()
187     {
188         parent::showFullName();
189         if ($this->profile->id == $this->peopletag->tagger) {
190             $this->out->text(' ');
191             // TRANS: Addition in tag subscribers list for creator of a tag.
192             $this->out->element('span', 'role', _('Creator'));
193         }
194     }
195
196     function showActions()
197     {
198         $this->startActions();
199         if (Event::handle('StartProfileListItemActionElements', array($this))) {
200             $this->showSubscribeButton();
201             Event::handle('EndProfileListItemActionElements', array($this));
202         }
203         $this->endActions();
204     }
205
206     function linkAttributes()
207     {
208         $aAttrs = parent::linkAttributes();
209
210         if (common_config('nofollow', 'members')) {
211             $aAttrs['rel'] .= ' nofollow';
212         }
213
214         return $aAttrs;
215     }
216
217     function homepageAttributes()
218     {
219         $aAttrs = parent::linkAttributes();
220
221         if (common_config('nofollow', 'members')) {
222             $aAttrs['rel'] = 'nofollow';
223         }
224
225         return $aAttrs;
226     }
227
228     /**
229      * Fetch necessary return-to arguments for the profile forms
230      * to return to this list when they're done.
231      *
232      * @return array
233      */
234     protected function returnToArgs()
235     {
236         $args = array('action' => 'peopletagsubscribers',
237                       'tag' => $this->peopletag->tag,
238                       'tagger' => $this->profile->nickname);
239         $page = $this->out->arg('page');
240         if ($page) {
241             $args['param-page'] = $page;
242         }
243         return $args;
244     }
245 }