]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagged.php
Some better context for notices as arrays
[quix0rs-gnu-social.git] / actions / peopletagged.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of people tagged by the user with a tag
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    Shashi Gowda <connect2shashi@gmail.com>
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 people tagged by the user with a tag
38  *
39  * @category Peopletag
40  * @package  StatusNet
41  * @author   Shashi Gowda <connect2shashi@gmail.com>
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 PeopletaggedAction 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 when referring to 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 when referring to 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: Title for list of people listed by the user.
112             // TRANS: %1$s is a list, %2$s is a username.
113             return sprintf(_('People listed in %1$s by %2$s'),
114                            $this->peopletag->tag, $this->tagger->nickname);
115         } else {
116             // TRANS: Title for list of people listed by the user.
117             // TRANS: %1$s is a list, %2$s is a username, %2$s is a page number.
118             return sprintf(_('People listed in %1$s by %2$s, page %3$d'),
119                            $this->peopletag->tag, $this->user->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, $this->peopletag);
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->getTagged($offset, $limit);
148
149         if ($subs) {
150             $subscriber_list = new PeopletagMemberList($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, 'peopletagged',
158                           array('tagger' => $this->tagger->nickname,
159                                 'tag'    => $this->peopletag->tag));
160     }
161 }
162
163 class PeopletagMemberList 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 PeopletagMemberListItem($profile, $this->peopletag, $this->action);
177     }
178 }
179
180 class PeopletagMemberListItem 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 membership 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             // TODO: Untag button
207             Event::handle('EndProfileListItemActionElements', array($this));
208         }
209         $this->endActions();
210     }
211
212     function linkAttributes()
213     {
214         // tagging people is healthy page-rank flow.
215         return parent::linkAttributes();
216     }
217
218     /**
219      * Fetch necessary return-to arguments for the profile forms
220      * to return to this list when they're done.
221      *
222      * @return array
223      */
224     protected function returnToArgs()
225     {
226         $args = array('action' => 'peopletagged',
227                       'tag' => $this->peopletag->tag,
228                       'tagger' => $this->profile->nickname);
229         $page = $this->out->arg('page');
230         if ($page) {
231             $args['param-page'] = $page;
232         }
233         return $args;
234     }
235 }