3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) {
24 require_once INSTALLDIR.'/lib/profilelist.php';
28 define('AVATARS_PER_PAGE', 80);
30 class GalleryAction extends Action
32 function is_readonly()
37 function handle($args)
39 parent::handle($args);
41 // Post from the tag dropdown; redirect to a GET
43 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
44 common_redirect($this->self_url(), 307);
47 $nickname = common_canonical_nickname($this->arg('nickname'));
49 $user = User::staticGet('nickname', $nickname);
52 $this->no_such_user();
56 $profile = $user->getProfile();
59 $this->server_error(_('User without matching profile in system.'));
63 $page = $this->arg('page');
69 $display = $this->arg('display');
75 $tag = $this->arg('tag');
77 common_show_header($profile->nickname . ": " . $this->gallery_type(),
79 array($this, 'show_top'));
81 $this->display_links($profile, $page, $display);
82 $this->show_tags_dropdown($profile);
84 $this->show_gallery($profile, $page, $display, $tag);
88 function no_such_user()
90 $this->client_error(_('No such user.'));
93 function show_tags_dropdown($profile)
95 $tag = $this->trimmed('tag');
97 list($lst, $usr) = $this->fields();
99 $tags = $this->get_all_tags($profile, $lst, $usr);
103 foreach ($tags as $t) {
107 common_element_start('dl', array('id'=>'filter_tags'));
108 common_element('dt', null, _('Filter tags'));
109 common_element_start('dd');
110 common_element_start('ul');
111 common_element_start('li', array('id' => 'filter_tags_all',
112 'class' => 'child_1'));
115 common_local_url($this->trimmed('action'),
117 $profile->nickname))),
119 common_element_end('li');
120 common_element_start('li', array('id'=>'filter_tags_item'));
121 common_element_start('form', array('name' => 'bytag',
123 'method' => 'post'));
124 common_dropdown('tag', _('Tag'), $content,
125 _('Choose a tag to narrow list'), false, $tag);
126 common_submit('go', _('Go'));
127 common_element_end('form');
128 common_element_end('li');
129 common_element_end('ul');
130 common_element_end('dd');
131 common_element_end('dl');
135 function show_top($profile)
137 common_element('div', 'instructions',
138 $this->get_instructions($profile));
144 // action => array('prompt', 'title', $args)
145 $action = $this->trimmed('action');
146 $nickname = $this->trimmed('nickname');
149 array('subscriptions' =>
150 array( _('Subscriptions'),
152 array('nickname' => $nickname)),
157 array('nickname' => $nickname)),
159 $this->nav_menu($menu);
162 function show_gallery($profile, $page, $display='list', $tag=null)
164 $other = new Profile();
166 list($lst, $usr) = $this->fields();
168 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
170 $offset = ($page-1)*$per_page;
171 $limit = $per_page + 1;
173 if (common_config('db', 'type') == 'pgsql') {
174 $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
176 $lim = ' LIMIT ' . $offset . ', ' . $limit;
179 // XXX: memcached results
180 // FIXME: SQL injection on $tag
182 $other->query('SELECT profile.* ' .
183 'FROM profile JOIN subscription ' .
184 'ON profile.id = subscription.' . $lst . ' ' .
185 (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') .
186 'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
187 'AND subscriber != subscribed ' .
188 (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') .
189 'ORDER BY subscription.created DESC, profile.id DESC ' .
192 if ($display == 'list') {
193 $cls = $this->profile_list_class();
194 $profile_list = new $cls($other, $profile, $this->trimmed('action'));
195 $cnt = $profile_list->show_list();
197 $cnt = $this->icon_list($other);
200 // For building the pagination URLs
202 $args = array('nickname' => $profile->nickname);
204 if ($display != 'list') {
205 $args['display'] = $display;
208 common_pagination($page > 1,
211 $this->trimmed('action'),
215 function profile_list_class()
217 return 'ProfileList';
220 function icon_list($other)
222 common_element_start('ul', $this->div_class());
226 while ($other->fetch()) {
230 if ($cnt > AVATARS_PER_PAGE) {
234 common_element_start('li');
236 common_element_start('a', array('title' => ($other->fullname) ?
239 'href' => $other->profileurl,
240 'class' => 'subscription'));
241 $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
242 common_element('img',
244 (($avatar) ? common_avatar_display_url($avatar) :
245 common_default_avatar(AVATAR_STREAM_SIZE)),
246 'width' => AVATAR_STREAM_SIZE,
247 'height' => AVATAR_STREAM_SIZE,
248 'class' => 'avatar stream',
249 'alt' => ($other->fullname) ?
252 common_element_end('a');
254 // XXX: subscribe form here
256 common_element_end('li');
259 common_element_end('ul');
264 function gallery_type()
269 function get_instructions(&$profile)
284 function display_links($profile, $page, $display)
286 $tag = $this->trimmed('tag');
288 common_element_start('dl', array('id'=>'subscriptions_nav'));
289 common_element('dt', null, _('Subscriptions navigation'));
290 common_element_start('dd');
291 common_element_start('ul', array('class'=>'nav'));
295 common_element('li', array('class'=>'child_1'), _('List'));
296 common_element_start('li');
297 $url_args = array('display' => 'icons',
298 'nickname' => $profile->nickname,
299 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE));
301 $url_args['tag'] = $tag;
303 $url = common_local_url($this->trimmed('action'), $url_args);
304 common_element('a', array('href' => $url),
306 common_element_end('li');
309 common_element_start('li', array('class'=>'child_1'));
310 $url_args = array('nickname' => $profile->nickname,
311 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE));
313 $url_args['tag'] = $tag;
315 $url = common_local_url($this->trimmed('action'), $url_args);
316 common_element('a', array('href' => $url),
318 common_element_end('li');
319 common_element('li', null, _('Icons'));
323 common_element_end('ul');
324 common_element_end('dd');
325 common_element_end('dl');
328 // Get list of tags we tagged other users with
330 function get_all_tags($profile, $lst, $usr)
332 $profile_tag = new Notice_tag();
333 $profile_tag->query('SELECT DISTINCT(tag) ' .
334 'FROM profile_tag, subscription ' .
335 'WHERE tagger = ' . $profile->id . ' ' .
336 'AND ' . $usr . ' = ' . $profile->id . ' ' .
337 'AND ' . $lst . ' = tagged ' .
338 'AND tagger != tagged');
340 while ($profile_tag->fetch()) {
341 $tags[] = $profile_tag->tag;
343 $profile_tag->free();