]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagsforuser.php
Merge branch '1.0.x' into testing
[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-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/peopletaglist.php';
35
36 class PeopletagsforuserAction extends Action
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             // TRANS: Page title. %s is a tagged user's nickname.
50             return sprintf(_('Lists with %s in them'), $this->tagged->nickname);
51         } else {
52             // TRANS: Page title. %1$s is a tagged user's nickname, %2$s is a page number.
53             return sprintf(_('Lists with %1$s, page %2$d'), $this->tagged->nickname, $this->page);
54         }
55     }
56
57     function prepare($args)
58     {
59         parent::prepare($args);
60
61         $nickname_arg = $this->arg('nickname');
62         $nickname = common_canonical_nickname($nickname_arg);
63
64         // Permanent redirect on non-canonical nickname
65
66         if ($nickname_arg != $nickname) {
67             $args = array('nickname' => $nickname);
68             if ($this->arg('page') && $this->arg('page') != 1) {
69                 $args['page'] = $this->arg['page'];
70             }
71             common_redirect(common_local_url('peopletagsforuser', $args), 301);
72             return false;
73         }
74
75         $this->user = User::staticGet('nickname', $nickname);
76
77         if (!$this->user) {
78             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
79             $this->clientError(_('No such user.'), 404);
80             return false;
81         }
82
83         $this->tagged = $this->user->getProfile();
84
85         if (!$this->tagged) {
86             // TRANS: Error message displayed when referring to a user without a profile.
87             $this->serverError(_('User has no profile.'));
88             return false;
89         }
90
91         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
92
93         return true;
94     }
95
96     function handle($args)
97     {
98         parent::handle($args);
99         $this->showPage();
100     }
101
102     function showAnonymousMessage()
103     {
104         $notice =
105           // TRANS: Message displayed for anonymous users on page that displays lists for a user.
106           // TRANS: This message contains Markdown links in the form [description](links).
107           // TRANS: %s is a tagger nickname.
108           sprintf(_('These are lists for **%s**. ' .
109                     'lists are how you sort similar ' .
110                     'people on %%%%site.name%%%%, a [micro-blogging]' .
111                     '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
112                     'based on the Free Software [StatusNet](http://status.net/) tool. ' .
113                     'You can easily keep track of what they ' .
114                     'are doing by subscribing to the tag\'s timeline.' ), $this->tagged->nickname);
115         $this->elementStart('div', array('id' => 'anon_notice'));
116         $this->raw(common_markup_to_html($notice));
117         $this->elementEnd('div');
118     }
119
120     function showContent()
121     {
122         #TODO: controls here.
123
124         $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
125         $limit  = PEOPLETAGS_PER_PAGE + 1;
126
127         $ptags = $this->tagged->getOtherTags(common_current_user(), $offset, $limit);
128
129         $pl = new PeopletagList($ptags, $this);
130         $cnt = $pl->show();
131
132         if ($cnt == 0) {
133             $this->showEmptyListMessage();
134         }
135         $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
136                           $this->page, 'peopletagsforuser', array('nickname' => $this->tagged->id));
137     }
138
139     function showEmptyListMessage()
140     {
141         // TRANS: Message displayed on page that displays lists a user was added to when there are none.
142         // TRANS: This message contains Markdown links in the form [description](links).
143         // TRANS: %s is a user nickname.
144         $message = sprintf(_('%s has not been [listed](%%%%doc.lists%%%%) by anyone yet.'), $this->tagged->nickname);
145         $this->elementStart('div', 'guide');
146         $this->raw(common_markup_to_html($message));
147         $this->elementEnd('div');
148     }
149
150     function showObjectNav()
151     {
152         $nav = new PeopletagNav($this, $this->tagged);
153         $nav->show();
154     }
155
156     function showProfileBlock()
157     {
158         $block = new AccountProfileBlock($this, $this->tagged);
159         $block->show();
160     }
161
162     function showSections()
163     {
164         #TODO: tags with most subscribers
165         #TODO: tags with most "members"
166     }
167 }