]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/selftag.php
Leding tabs to spaces.
[quix0rs-gnu-social.git] / actions / selftag.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 /**
36  * This class outputs a paginated list of profiles self-tagged with a given tag
37  *
38  * @category Output
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  *
45  * @see      Action
46  */
47 class SelftagAction extends Action
48 {
49
50     var $tag  = null;
51     var $page = null;
52
53     /**
54      * For initializing members of the class.
55      *
56      * @param array $argarray misc. arguments
57      *
58      * @return boolean true
59      */
60     function prepare($argarray)
61     {
62         parent::prepare($argarray);
63
64         $this->tag = $this->trimmed('tag');
65
66         if (!common_valid_profile_tag($this->tag)) {
67             // TRANS: Client error displayed when trying to tag a profile with an invalid tag.
68             // TRANS: %s is the invalid tag.
69             $this->clientError(sprintf(_('Not a valid people tag: %s.'),
70                 $this->tag));
71             return;
72         }
73
74         $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
75
76         common_set_returnto($this->selfUrl());
77
78         return true;
79     }
80
81     /**
82      * Handler method
83      *
84      * @param array $argarray is ignored since it's now passed in in prepare()
85      *
86      * @return boolean is read only action?
87      */
88     function handle($argarray)
89     {
90         parent::handle($argarray);
91         $this->showPage();
92     }
93
94     /**
95      * Whips up a query to get a list of profiles based on the provided
96      * people tag and page, initalizes a ProfileList widget, and displays
97      * it to the user.
98      *
99      * @return nothing
100      */
101     function showContent()
102     {
103
104         $profile = new Profile();
105
106         $offset = ($this->page - 1) * PROFILES_PER_PAGE;
107         $limit  = PROFILES_PER_PAGE + 1;
108
109         if (common_config('db', 'type') == 'pgsql') {
110             $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
111         } else {
112             $lim = ' LIMIT ' . $offset . ', ' . $limit;
113         }
114
115         // XXX: memcached this
116
117         $qry =  'SELECT profile.* ' .
118                 'FROM profile JOIN ( profile_tag, profile_list ) ' .
119                 'ON profile.id = profile_tag.tagger ' .
120                 'AND profile_tag.tagger = profile_list.tagger ' .
121                 'AND profile_list.tag = profile_tag.tag ' .
122                 'WHERE profile_tag.tagger = profile_tag.tagged ' .
123                 "AND profile_tag.tag = '%s' ";
124
125         $user = common_current_user();
126         if (empty($user)) {
127             $qry .= 'AND profile_list.private = false ';
128         } else {
129             $qry .= 'AND (profile_list.tagger = ' . $user->id .
130                     ' OR profile_list.private = false) ';
131         }
132
133         $qry .= 'ORDER BY profile_tag.modified DESC%s';
134
135         $profile->query(sprintf($qry, $this->tag, $lim));
136
137         $ptl = new SelfTagProfileList($profile, $this); // pass the ammunition
138         $cnt = $ptl->show();
139
140         $this->pagination($this->page > 1,
141                           $cnt > PROFILES_PER_PAGE,
142                           $this->page,
143                           'selftag',
144                           array('tag' => $this->tag));
145     }
146
147     /**
148      * Returns the page title
149      *
150      * @return string page title
151      */
152     function title()
153     {
154         return sprintf(_('Users self-tagged with %1$s - page %2$d'),
155             $this->tag, $this->page);
156     }
157
158 }
159
160 class SelfTagProfileList extends ProfileList
161 {
162     function newListItem($profile)
163     {
164         return new SelfTagProfileListItem($profile, $this->action);
165     }
166 }
167
168 class SelfTagProfileListItem extends ProfileListItem
169 {
170     function linkAttributes()
171     {
172         $aAttrs = parent::linkAttributes();
173
174         if (common_config('nofollow', 'selftag')) {
175             $aAttrs['rel'] .= ' nofollow';
176         }
177
178         return $aAttrs;
179     }
180
181     function homepageAttributes()
182     {
183         $aAttrs = parent::linkAttributes();
184
185         if (common_config('nofollow', 'selftag')) {
186             $aAttrs['rel'] = 'nofollow';
187         }
188
189         return $aAttrs;
190     }
191
192     function showTags()
193     {
194         $selftags = new SelfTagsWidget($this->out, $this->profile, $this->profile);
195         $selftags->show();
196
197         $user = common_current_user();
198
199         if (!empty($user) && $user->id != $this->profile->id &&
200                 $user->getProfile()->canTag($this->profile)) {
201             $yourtags = new PeopleTagsWidget($this->out, $user, $this->profile);
202             $yourtags->show();
203         }
204     }
205 }