]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletag.php
people tag actions
[quix0rs-gnu-social.git] / actions / peopletag.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * People tags 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($args)
48     {
49         return true;
50     }
51
52     function title()
53     {
54         if ($this->page == 1) {
55             return sprintf(_("Public people tag %s"), $this->tag);
56         } else {
57             return sprintf(_("Public people tag %s, page %d"), $this->tag, $this->page);
58         }
59     }
60
61     function prepare($args)
62     {
63         parent::prepare($args);
64         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
65
66         $tag_arg = $this->arg('tag');
67         $tag = common_canonical_tag($tag_arg);
68
69         // Permanent redirect on non-canonical nickname
70
71         if ($tag_arg != $tag) {
72             $args = array('tag' => $nickname);
73             if ($this->page && $this->page != 1) {
74                 $args['page'] = $this->page;
75             }
76             common_redirect(common_local_url('peopletag', $args), 301);
77             return false;
78         }
79         $this->tag = $tag;
80
81         return true;
82     }
83
84     function handle($args)
85     {
86         parent::handle($args);
87         $this->showPage();
88     }
89
90     function showLocalNav()
91     {
92         $nav = new PublicGroupNav($this);
93         $nav->show();
94     }
95
96     function showAnonymousMessage()
97     {
98         $notice =
99           _('People tags are how you sort similar ' .
100             'people on %%site.name%%, a [micro-blogging]' .
101             '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
102             'based on the Free Software [StatusNet](http://status.net/) tool. ' .
103             'You can then easily keep track of what they ' .
104             'are doing by subscribing to the tag\'s timeline.' );
105         $this->elementStart('div', array('id' => 'anon_notice'));
106         $this->raw(common_markup_to_html($notice));
107         $this->elementEnd('div');
108     }
109
110     function showContent()
111     {
112         $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
113         $limit  = PEOPLETAGS_PER_PAGE + 1;
114
115         $ptags = new Profile_list();
116         $ptags->tag = $this->tag;
117
118         $user = common_current_user();
119
120         if (empty($user)) {
121             $ckey = sprintf('profile_list:tag:%s', $this->tag);
122             $ptags->private = false;
123             $ptags->orderBy('profile_list.modified DESC');
124
125             $c = Cache::instance();
126             if ($offset+$limit <= PEOPLETAG_CACHE_WINDOW && !empty($c)) {
127                 $cached_ptags = Profile_list::getCached($ckey, $offset, $limit);
128                 if ($cached_ptags === false) {
129                     $ptags->limit(0, PEOPLETAG_CACHE_WINDOW);
130                     $ptags->find();
131
132                     Profile_list::setCache($ckey, $ptags, $offset, $limit);
133                 } else {
134                     $ptags = clone($cached_ptags);
135                 }
136             } else {
137                 $ptags->limit($offset, $limit);
138                 $ptags->find();
139             }
140         } else {
141             $ptags->whereAdd('(profile_list.private = false OR (' .
142                              ' profile_list.tagger =' . $user->id .
143                              ' AND profile_list.private = true) )');    
144
145             $ptags->orderBy('profile_list.modified DESC');
146             $ptags->find();
147         }
148
149         $pl = new PeopletagList($ptags, $this);
150         $cnt = $pl->show();
151
152         $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
153                           $this->page, 'peopletag', array('tag' => $this->tag));
154     }
155
156     function showSections()
157     {
158     }
159 }