]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletag.php
* L10n updates: consistent puctuation
[quix0rs-gnu-social.git] / actions / peopletag.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Action for showing profiles self-tagged with a given tag
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  Action
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Zach Copley <zach@status.net>
26  * @copyright 2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/profilelist.php';
36
37 /**
38  * This class outputs a paginated list of profiles self-tagged with a given tag
39  *
40  * @category Output
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Zach Copley <zach@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  *
47  * @see      Action
48  */
49
50 class PeopletagAction extends Action
51 {
52
53     var $tag  = null;
54     var $page = null;
55
56     /**
57      * For initializing members of the class.
58      *
59      * @param array $argarray misc. arguments
60      *
61      * @return boolean true
62      */
63     function prepare($argarray)
64     {
65         parent::prepare($argarray);
66
67         $this->tag = $this->trimmed('tag');
68
69         if (!common_valid_profile_tag($this->tag)) {
70             $this->clientError(sprintf(_('Not a valid people tag: %s'),
71                 $this->tag));
72             return;
73         }
74
75         $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
76
77         common_set_returnto($this->selfUrl());
78
79         return true;
80     }
81
82     /**
83      * Handler method
84      *
85      * @param array $argarray is ignored since it's now passed in in prepare()
86      *
87      * @return boolean is read only action?
88      */
89     function handle($argarray)
90     {
91         parent::handle($argarray);
92         $this->showPage();
93     }
94
95     /**
96      * Whips up a query to get a list of profiles based on the provided
97      * people tag and page, initalizes a ProfileList widget, and displays
98      * it to the user.
99      *
100      * @return nothing
101      */
102     function showContent()
103     {
104
105         $profile = new Profile();
106
107         $offset = ($this->page - 1) * PROFILES_PER_PAGE;
108         $limit  = PROFILES_PER_PAGE + 1;
109
110         if (common_config('db', 'type') == 'pgsql') {
111             $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
112         } else {
113             $lim = ' LIMIT ' . $offset . ', ' . $limit;
114         }
115
116         // XXX: memcached this
117
118         $qry =  'SELECT profile.* ' .
119                 'FROM profile JOIN profile_tag ' .
120                 'ON profile.id = profile_tag.tagger ' .
121                 'WHERE profile_tag.tagger = profile_tag.tagged ' .
122                 "AND tag = '%s' " .
123                 'ORDER BY profile_tag.modified DESC%s';
124
125         $profile->query(sprintf($qry, $this->tag, $lim));
126
127         $pl  = new ProfileList($profile, $this);
128         $cnt = $pl->show();
129
130         $this->pagination($this->page > 1,
131                           $cnt > PROFILES_PER_PAGE,
132                           $this->page,
133                           'peopletag',
134                           array('tag' => $this->tag));
135     }
136
137     /**
138      * Returns the page title
139      *
140      * @return string page title
141      */
142     function title()
143     {
144         return sprintf(_('Users self-tagged with %1$s - page %2$d'),
145             $this->tag, $this->page);
146     }
147
148 }