4 * Laconica - a distributed open-source microblogging tool
5 * Copyright (C) 2008, Controlez-Vous, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 if (!defined('LACONICA')) { exit(1); }
23 require_once(INSTALLDIR.'/lib/profilelist.php');
27 define('AVATARS_PER_PAGE', 80);
29 class GalleryAction extends Action {
31 function is_readonly() {
35 function handle($args) {
36 parent::handle($args);
38 # Post from the tag dropdown; redirect to a GET
40 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
41 common_redirect($this->self_url(), 307);
44 $nickname = common_canonical_nickname($this->arg('nickname'));
45 $user = User::staticGet('nickname', $nickname);
48 $this->no_such_user();
52 $profile = $user->getProfile();
55 $this->server_error(_('User without matching profile in system.'));
59 $page = $this->arg('page');
65 $display = $this->arg('display');
71 $tag = $this->arg('tag');
73 common_show_header($profile->nickname . ": " . $this->gallery_type(),
75 array($this, 'show_top'));
77 $this->display_links($profile, $page, $display);
78 $this->show_tags_dropdown($profile);
80 $this->show_gallery($profile, $page, $display, $tag);
84 function no_such_user() {
85 $this->client_error(_('No such user.'));
88 function show_tags_dropdown($profile) {
89 $tag = $this->trimmed('tag');
90 list($lst, $usr) = $this->fields();
91 $tags = $this->get_all_tags($profile, $lst, $usr);
93 foreach ($tags as $t) {
97 common_element_start('dl', array('id'=>'filter_tags'));
98 common_element('dt', null, _('Filter tags'));
99 common_element_start('dd');
100 common_element_start('ul');
101 common_element_start('li', array('id'=>'filter_tags_all', 'class'=>'child_1'));
102 common_element('a', array('href' => common_local_url($this->trimmed('action'),
103 array('nickname' => $profile->nickname))),
105 common_element_end('li');
106 common_element_start('li', array('id'=>'filter_tags_item'));
107 common_element_start('form', array('name' => 'bytag', 'id' => 'bytag', 'method' => 'post'));
108 common_dropdown('tag', _('Tag'), $content,
109 _('Choose a tag to narrow list'), FALSE, $tag);
110 common_submit('go', _('Go'));
111 common_element_end('form');
112 common_element_end('li');
113 common_element_end('ul');
114 common_element_end('dd');
115 common_element_end('dl');
119 function show_top($profile) {
120 common_element('div', 'instructions',
121 $this->get_instructions($profile));
124 function show_gallery($profile, $page, $display='list', $tag=NULL) {
126 $other = new Profile();
128 list($lst, $usr) = $this->fields();
130 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
132 $offset = ($page-1)*$per_page;
133 $limit = $per_page + 1;
135 if (common_config('db','type') == 'pgsql') {
136 $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
138 $lim = ' LIMIT ' . $offset . ', ' . $limit;
141 # XXX: memcached results
142 # FIXME: SQL injection on $tag
144 $other->query('SELECT profile.* ' .
145 'FROM profile JOIN subscription ' .
146 'ON profile.id = subscription.' . $lst . ' ' .
147 (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') .
148 'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
149 'AND subscriber != subscribed ' .
150 (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') .
151 'ORDER BY subscription.created DESC, profile.id DESC ' .
154 if ($display == 'list') {
155 $cls = $this->profile_list_class();
156 $profile_list = new $cls($other, $profile, $this->trimmed('action'));
157 $cnt = $profile_list->show_list();
159 $cnt = $this->icon_list($other);
162 # For building the pagination URLs
164 $args = array('nickname' => $profile->nickname);
166 if ($display != 'list') {
167 $args['display'] = $display;
170 common_pagination($page > 1,
173 $this->trimmed('action'),
177 function profile_list_class() {
178 return 'ProfileList';
181 function icon_list($other) {
183 common_element_start('ul', $this->div_class());
187 while ($other->fetch()) {
191 if ($cnt > AVATARS_PER_PAGE) {
195 common_element_start('li');
197 common_element_start('a', array('title' => ($other->fullname) ?
200 'href' => $other->profileurl,
201 'class' => 'subscription'));
202 $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
203 common_element('img',
205 (($avatar) ? common_avatar_display_url($avatar) :
206 common_default_avatar(AVATAR_STREAM_SIZE)),
207 'width' => AVATAR_STREAM_SIZE,
208 'height' => AVATAR_STREAM_SIZE,
209 'class' => 'avatar stream',
210 'alt' => ($other->fullname) ?
213 common_element_end('a');
215 # XXX: subscribe form here
217 common_element_end('li');
220 common_element_end('ul');
225 function gallery_type() {
229 function get_instructions(&$profile) {
237 function div_class() {
241 function display_links($profile, $page, $display) {
242 $tag = $this->trimmed('tag');
244 common_element_start('dl', array('id'=>'subscriptions_nav'));
245 common_element('dt', null, _('Subscriptions navigation'));
246 common_element_start('dd');
247 common_element_start('ul', array('class'=>'nav'));
251 common_element('li', array('class'=>'child_1'), _('List'));
252 common_element_start('li');
253 $url_args = array('display' => 'icons',
254 'nickname' => $profile->nickname,
255 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE));
257 $url_args['tag'] = $tag;
259 $url = common_local_url($this->trimmed('action'), $url_args);
260 common_element('a', array('href' => $url),
262 common_element_end('li');
265 common_element_start('li', array('class'=>'child_1'));
266 $url_args = array('nickname' => $profile->nickname,
267 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE));
269 $url_args['tag'] = $tag;
271 $url = common_local_url($this->trimmed('action'), $url_args);
272 common_element('a', array('href' => $url),
274 common_element_end('li');
275 common_element('li', NULL, _('Icons'));
279 common_element_end('ul');
280 common_element_end('dd');
281 common_element_end('dl');
284 # Get list of tags we tagged other users with
286 function get_all_tags($profile, $lst, $usr) {
287 $profile_tag = new Notice_tag();
288 $profile_tag->query('SELECT DISTINCT(tag) ' .
289 'FROM profile_tag, subscription ' .
290 'WHERE tagger = ' . $profile->id . ' ' .
291 'AND ' . $usr . ' = ' . $profile->id . ' ' .
292 'AND ' . $lst . ' = tagged ' .
293 'AND tagger != tagged');
295 while ($profile_tag->fetch()) {
296 $tags[] = $profile_tag->tag;
298 $profile_tag->free();