]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagged.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[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-2009 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
46 class PeopletaggedAction extends OwnerDesignAction
47 {
48     var $page = null;
49     var $peopletag = null;
50     var $tagger = null;
51
52     function isReadOnly($args)
53     {
54         return true;
55     }
56
57     function prepare($args)
58     {
59         parent::prepare($args);
60         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
61
62         $tagger_arg = $this->arg('tagger');
63         $tag_arg = $this->arg('tag');
64         $tagger = common_canonical_nickname($tagger_arg);
65         $tag = common_canonical_tag($tag_arg);
66
67         // Permanent redirect on non-canonical nickname
68
69         if ($tagger_arg != $tagger || $tag_arg != $tag) {
70             $args = array('tagger' => $nickname, 'tag' => $tag);
71             if ($this->page != 1) {
72                 $args['page'] = $this->page;
73             }
74             common_redirect(common_local_url('peopletagged', $args), 301);
75             return false;
76         }
77
78         if (!$tagger) {
79             $this->clientError(_('No tagger.'), 404);
80             return false;
81         }
82
83         $user = User::staticGet('nickname', $tagger);
84
85         if (!$user) {
86             $this->clientError(_('No such user.'), 404);
87             return false;
88         }
89
90         $this->tagger = $user->getProfile();
91         $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
92
93         if (!$this->peopletag) {
94             $this->clientError(_('No such peopletag.'), 404);
95             return false;
96         }
97
98         return true;
99     }
100
101     function title()
102     {
103         if ($this->page == 1) {
104             return sprintf(_('People tagged %s by %s'),
105                            $this->peopletag->tag, $this->tagger->nickname);
106         } else {
107             return sprintf(_('People tagged %s by %s, page %d'),
108                            $this->peopletag->tag, $this->user->nickname,
109                            $this->page);
110         }
111     }
112
113     function handle($args)
114     {
115         parent::handle($args);
116         $this->showPage();
117     }
118
119     function showPageNotice()
120     {
121     }
122
123     function showLocalNav()
124     {
125         $nav = new PeopletagGroupNav($this, $this->peopletag);
126         $nav->show();
127     }
128
129     function showContent()
130     {
131         $offset = ($this->page-1) * PROFILES_PER_PAGE;
132         $limit =  PROFILES_PER_PAGE + 1;
133
134         $cnt = 0;
135
136         $subs = $this->peopletag->getTagged($offset, $limit);
137
138         if ($subs) {
139             $subscriber_list = new PeopletagMemberList($subs, $this->peopletag, $this);
140             $cnt = $subscriber_list->show();
141         }
142
143         $subs->free();
144
145         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
146                           $this->page, 'peopletagged',
147                           array('tagger' => $this->tagger->nickname,
148                                 'tag'    => $this->peopletag->tag));
149     }
150 }
151
152 class PeopletagMemberList extends ProfileList
153 {
154     var $peopletag = null;
155
156     function __construct($profile, $peopletag, $action)
157     {
158         parent::__construct($profile, $action);
159
160         $this->peopletag = $peopletag;
161     }
162
163     function newListItem($profile)
164     {
165         return new PeopletagMemberListItem($profile, $this->peopletag, $this->action);
166     }
167 }
168
169 class PeopletagMemberListItem extends ProfileListItem
170 {
171     var $peopletag = null;
172
173     function __construct($profile, $peopletag, $action)
174     {
175         parent::__construct($profile, $action);
176
177         $this->peopletag = $peopletag;
178     }
179
180     function showFullName()
181     {
182         parent::showFullName();
183         if ($this->profile->id == $this->peopletag->tagger) {
184             $this->out->text(' ');
185             $this->out->element('span', 'role', _('Creator'));
186         }
187     }
188
189     function showActions()
190     {
191         $this->startActions();
192         if (Event::handle('StartProfileListItemActionElements', array($this))) {
193             $this->showSubscribeButton();
194             // TODO: Untag button
195             Event::handle('EndProfileListItemActionElements', array($this));
196         }
197         $this->endActions();
198     }
199
200     function linkAttributes()
201     {
202         // tagging people is healthy page-rank flow.
203         return parent::linkAttributes();
204     }
205
206     /**
207      * Fetch necessary return-to arguments for the profile forms
208      * to return to this list when they're done.
209      * 
210      * @return array
211      */
212     protected function returnToArgs()
213     {
214         $args = array('action' => 'peopletagged',
215                       'tag' => $this->peopletag->tag,
216                       'tagger' => $this->profile->nickname);
217         $page = $this->out->arg('page');
218         if ($page) {
219             $args['param-page'] = $page;
220         }
221         return $args;
222     }
223 }