]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletag.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / peopletag.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Lists by 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  * PHP version 5
20  *
21  * You should have received a copy of the GNU Affero General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * @category  Personal
25  * @package   StatusNet
26  * @author    Evan Prodromou <evan@status.net>
27  * @author    Zach Copley <zach@status.net>
28  * @author    Shashi Gowda <connect2shashi@gmail.com>
29  * @copyright 2009 StatusNet, Inc.
30  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31  * @link      http://status.net/
32  */
33
34 if (!defined('STATUSNET') && !defined('LACONICA')) {
35     exit(1);
36 }
37
38 require_once INSTALLDIR.'/lib/peopletaglist.php';
39 // cache 3 pages
40 define('PEOPLETAG_CACHE_WINDOW', PEOPLETAGS_PER_PAGE*3 + 1);
41
42 class PeopletagAction extends Action
43 {
44     var $page = null;
45     var $tag = null;
46
47     function isReadOnly(array $args=array())
48     {
49         return true;
50     }
51
52     function title()
53     {
54         if ($this->page == 1) {
55             // TRANS: Title for list page.
56             // TRANS: %s is a list.
57             return sprintf(_('Public list %s'), $this->tag);
58         } else {
59             // TRANS: Title for list page.
60             // TRANS: %1$s is a list, %2$d is a page number.
61             return sprintf(_('Public list %1$s, page %2$d'), $this->tag, $this->page);
62         }
63     }
64
65     function prepare(array $args=array())
66     {
67         parent::prepare($args);
68         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
69
70         $tag_arg = $this->arg('tag');
71         $tag = common_canonical_tag($tag_arg);
72
73         // Permanent redirect on non-canonical nickname
74
75         if ($tag_arg != $tag) {
76             $args = array('tag' => $nickname);
77             if ($this->page && $this->page != 1) {
78                 $args['page'] = $this->page;
79             }
80             common_redirect(common_local_url('peopletag', $args), 301);
81         }
82         $this->tag = $tag;
83
84         return true;
85     }
86
87     function handle(array $args=array())
88     {
89         parent::handle($args);
90         $this->showPage();
91     }
92
93     function showLocalNav()
94     {
95         $nav = new PublicGroupNav($this);
96         $nav->show();
97     }
98
99     function showAnonymousMessage()
100     {
101         $notice =
102           // TRANS: Message for anonymous users on list page.
103           // TRANS: This message contains Markdown links in the form [description](link).
104           _('Lists are how you sort similar ' .
105             'people on %%site.name%%, a [micro-blogging]' .
106             '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
107             'based on the Free Software [StatusNet](http://status.net/) tool. ' .
108             'You can then easily keep track of what they ' .
109             'are doing by subscribing to the list\'s timeline.' );
110         $this->elementStart('div', array('id' => 'anon_notice'));
111         $this->raw(common_markup_to_html($notice));
112         $this->elementEnd('div');
113     }
114
115     function showContent()
116     {
117         $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
118         $limit  = PEOPLETAGS_PER_PAGE + 1;
119
120         $ptags = new Profile_list();
121         $ptags->tag = $this->tag;
122
123         $user = common_current_user();
124
125         if (empty($user)) {
126             $ckey = sprintf('profile_list:tag:%s', $this->tag);
127             $ptags->private = false;
128             $ptags->orderBy('profile_list.modified DESC');
129
130             $c = Cache::instance();
131             if ($offset+$limit <= PEOPLETAG_CACHE_WINDOW && !empty($c)) {
132                 $cached_ptags = Profile_list::getCached($ckey, $offset, $limit);
133                 if ($cached_ptags === false) {
134                     $ptags->limit(0, PEOPLETAG_CACHE_WINDOW);
135                     $ptags->find();
136
137                     Profile_list::setCache($ckey, $ptags, $offset, $limit);
138                 } else {
139                     $ptags = clone($cached_ptags);
140                 }
141             } else {
142                 $ptags->limit($offset, $limit);
143                 $ptags->find();
144             }
145         } else {
146             $ptags->whereAdd('(profile_list.private = false OR (' .
147                              ' profile_list.tagger =' . $user->id .
148                              ' AND profile_list.private = true) )');
149
150             $ptags->orderBy('profile_list.modified DESC');
151             $ptags->find();
152         }
153
154         $pl = new PeopletagList($ptags, $this);
155         $cnt = $pl->show();
156
157         $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
158                           $this->page, 'peopletag', array('tag' => $this->tag));
159     }
160
161     function showSections()
162     {
163     }
164 }