]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletag.php
move opening brace of class declaration to next line
[quix0rs-gnu-social.git] / actions / peopletag.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/profilelist.php');
23
24 class PeopletagAction extends Action
25 {
26     
27     function handle($args)
28     {
29
30         parent::handle($args);
31
32         $tag = $this->trimmed('tag');
33         
34         if (!common_valid_profile_tag($tag)) {
35             $this->client_error(sprintf(_('Not a valid people tag: %s'), $tag));
36             return;
37         }
38
39         $page = $this->trimmed('page');
40         
41         if (!$page) {
42             $page = 1;
43         }
44         
45         # Looks like we're good; show the header
46
47         common_show_header(sprintf(_('Users self-tagged with %s - page %d'), $tag, $page),
48                            null, $tag, array($this, 'show_top'));
49
50         $this->show_people($tag, $page);
51
52         common_show_footer();
53     }
54
55     function show_people($tag, $page)
56     {
57         
58         $profile = new Profile();
59
60         $offset = ($page-1)*PROFILES_PER_PAGE;
61         $limit = PROFILES_PER_PAGE + 1;
62         
63         if (common_config('db','type') == 'pgsql') {
64             $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
65         } else {
66             $lim = ' LIMIT ' . $offset . ', ' . $limit;
67         }
68
69         # XXX: memcached this
70         
71         $profile->query(sprintf('SELECT profile.* ' .
72                                 'FROM profile JOIN profile_tag ' .
73                                 'ON profile.id = profile_tag.tagger ' .
74                                 'WHERE profile_tag.tagger = profile_tag.tagged ' .
75                                 'AND tag = "%s" ' .
76                                 'ORDER BY profile_tag.modified DESC ' . 
77                                 $lim, $tag));
78
79         $pl = new ProfileList($profile);
80         $cnt = $pl->show_list();
81         
82         common_pagination($page > 1,
83                           $cnt > PROFILES_PER_PAGE,
84                           $page,
85                           $this->trimmed('action'),
86                           array('tag' => $tag));
87     }
88     
89     function show_top($tag)
90     {
91         $instr = sprintf(_('These are users who have tagged themselves "%s" ' .
92                            'to show a common interest, characteristic, hobby or job.'), $tag);
93         common_element_start('div', 'instructions');
94         common_element_start('p');
95         common_text($instr);
96         common_element_end('p');
97         common_element_end('div');
98     }
99
100     function get_title()
101     {
102         return null;
103     }
104
105     function show_header($arr)
106     {
107         return;
108     }
109 }