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