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