]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagsforuser.php
people tag actions
[quix0rs-gnu-social.git] / actions / peopletagsforuser.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * People tags for a user
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  Personal
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/peopletaglist.php';
35
36 class PeopletagsforuserAction extends OwnerDesignAction
37 {
38     var $page = null;
39     var $tagged = null;
40
41     function isReadOnly($args)
42     {
43         return true;
44     }
45
46     function title()
47     {
48         if ($this->page == 1) {
49             return sprintf(_("People tags for %s"), $this->tagged->nickname);
50         } else {
51             return sprintf(_("People tags for %s, page %d"), $this->tagged->nickname, $this->page);
52         }
53     }
54
55     function prepare($args)
56     {
57         parent::prepare($args);
58
59         $nickname_arg = $this->arg('nickname');
60         $nickname = common_canonical_nickname($nickname_arg);
61
62         // Permanent redirect on non-canonical nickname
63
64         if ($nickname_arg != $nickname) {
65             $args = array('nickname' => $nickname);
66             if ($this->arg('page') && $this->arg('page') != 1) {
67                 $args['page'] = $this->arg['page'];
68             }
69             common_redirect(common_local_url('peopletagsforuser', $args), 301);
70             return false;
71         }
72
73         $this->user = User::staticGet('nickname', $nickname);
74
75         if (!$this->user) {
76             $this->clientError(_('No such user.'), 404);
77             return false;
78         }
79
80         $this->tagged = $this->user->getProfile();
81
82         if (!$this->tagged) {
83             $this->serverError(_('User has no profile.'));
84             return false;
85         }
86
87         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
88
89         return true;
90     }
91
92     function handle($args)
93     {
94         parent::handle($args);
95         $this->showPage();
96     }
97
98     function showLocalNav()
99     {
100         $nav = new PersonalGroupNav($this);
101         $nav->show();
102     }
103
104     function showAnonymousMessage()
105     {
106         $notice =
107           sprintf(_('These are people tags for **%s**. ' .
108                     'People tags are how you sort similar ' .
109                     'people on %%%%site.name%%%%, a [micro-blogging]' .
110                     '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
111                     'based on the Free Software [StatusNet](http://status.net/) tool. ' .
112                     'You can easily keep track of what they ' .
113                     'are doing by subscribing to the tag\'s timeline.' ), $this->tagged->nickname);
114         $this->elementStart('div', array('id' => 'anon_notice'));
115         $this->raw(common_markup_to_html($notice));
116         $this->elementEnd('div');
117     }
118
119     function showPageNotice()
120     {
121         $this->elementStart('dl', 'filter_tags');
122         $this->elementStart('dd', array('id' => 'filter_tags_for',
123                                          'class' => 'child_1'));
124
125         $user = common_current_user();
126         $text = ($this->tagged->id == @$user->id) ? _('People tags by you') :
127                 sprintf(_('People tags by %s'), $this->tagged->nickname);
128         $this->element('a',
129                        array('href' =>
130                              common_local_url('peopletagsbyuser',
131                                               array('nickname' => $this->tagged->nickname))),
132                            $text);
133         $this->elementEnd('dd');
134         $this->elementEnd('dl');
135     }
136
137
138     function showContent()
139     {
140         #TODO: controls here.
141
142         $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
143         $limit  = PEOPLETAGS_PER_PAGE + 1;
144
145         $ptags = $this->tagged->getOtherTags(common_current_user(), $offset, $limit);
146
147         $pl = new PeopletagList($ptags, $this);
148         $cnt = $pl->show();
149
150         if ($cnt == 0) {
151             $this->showEmptyListMessage();
152         }
153         $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
154                           $this->page, 'peopletagsforuser', array('nickname' => $this->tagged->id));
155     }
156
157     function showEmptyListMessage()
158     {
159         $message = sprintf(_('%s has not been [tagged](%%%%doc.tags%%%%) by anyone yet.'), $this->tagged->nickname);
160         $this->elementStart('div', 'guide');
161         $this->raw(common_markup_to_html($message));
162         $this->elementEnd('div');
163     }
164
165     function showSections()
166     {
167         #TODO: tags with most subscribers
168         #TODO: tags with most "members"
169     }
170 }