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