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 $nickname = common_canonical_nickname($this->arg('nickname'));
39 $user = User::staticGet('nickname', $nickname);
42 $this->no_such_user();
46 $profile = $user->getProfile();
49 $this->server_error(_('User without matching profile in system.'));
53 $page = $this->arg('page');
59 $display = $this->arg('display');
65 $tag = $this->arg('tag');
67 common_show_header($profile->nickname . ": " . $this->gallery_type(),
69 array($this, 'show_top'));
71 $this->display_links($profile, $page, $display);
72 $this->show_tags_dropdown($profile);
74 $this->show_gallery($profile, $page, $display, $tag);
78 function no_such_user() {
79 $this->client_error(_('No such user.'));
82 function show_tags_dropdown($profile) {
83 $tag = $this->trimmed('tag');
84 list($lst, $usr) = $this->fields();
85 $tags = $this->get_all_tags($profile, $lst, $usr);
87 foreach ($tags as $t) {
91 common_element('a', array('href' => common_local_url($this->trimmed('action'),
92 array('nickname' => $profile->nickname))),
94 common_element_start('form', array('name' => 'bytag', 'id' => 'bytag'));
95 common_dropdown('tag', _('Tag'), $content,
96 _('Choose a tag to narrow list'), FALSE, $tag);
97 common_submit('go', _('Go'));
98 common_element_end('form');
102 function show_top($profile) {
103 common_element('div', 'instructions',
104 $this->get_instructions($profile));
107 function show_gallery($profile, $page, $display='list', $tag=NULL) {
109 $other = new Profile();
111 list($lst, $usr) = $this->fields();
113 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
115 $offset = ($page-1)*$per_page;
116 $limit = $per_page + 1;
118 if (common_config('db','type') == 'pgsql') {
119 $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
121 $lim = ' LIMIT ' . $offset . ', ' . $limit;
124 # XXX: memcached results
125 # FIXME: SQL injection on $tag
127 $other->query('SELECT profile.* ' .
128 'FROM profile JOIN subscription ' .
129 'ON profile.id = subscription.' . $lst . ' ' .
130 (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') .
131 'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
132 'AND subscriber != subscribed ' .
133 (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') .
134 'ORDER BY subscription.created DESC, profile.id DESC ' .
137 if ($display == 'list') {
138 $profile_list = new ProfileList($other, $profile, $this->trimmed('action'));
139 $cnt = $profile_list->show_list();
141 $cnt = $this->icon_list($other);
144 # For building the pagination URLs
146 $args = array('nickname' => $profile->nickname);
148 if ($display != 'list') {
149 $args['display'] = $display;
152 common_pagination($page > 1,
155 $this->trimmed('action'),
159 function icon_list($other) {
161 common_element_start('ul', $this->div_class());
165 while ($other->fetch()) {
169 if ($cnt > AVATARS_PER_PAGE) {
173 common_element_start('li');
175 common_element_start('a', array('title' => ($other->fullname) ?
178 'href' => $other->profileurl,
179 'class' => 'subscription'));
180 $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
181 common_element('img',
183 (($avatar) ? common_avatar_display_url($avatar) :
184 common_default_avatar(AVATAR_STREAM_SIZE)),
185 'width' => AVATAR_STREAM_SIZE,
186 'height' => AVATAR_STREAM_SIZE,
187 'class' => 'avatar stream',
188 'alt' => ($other->fullname) ?
191 common_element_end('a');
193 # XXX: subscribe form here
195 common_element_end('li');
198 common_element_end('ul');
203 function gallery_type() {
207 function get_instructions(&$profile) {
215 function div_class() {
219 function display_links($profile, $page, $display) {
221 common_element_start('p');
225 common_element('span', NULL, _('List'));
227 common_element('a', array('href' => common_local_url($this->trimmed('action'),
228 array('display' => 'icons',
229 'nickname' => $profile->nickname,
230 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)))),
234 common_element('a', array('href' => common_local_url($this->trimmed('action'),
235 array('nickname' => $profile->nickname,
236 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)))),
239 common_element('span', NULL, _('Icons'));
243 common_element_end('p');
246 # Get list of tags we tagged other users with
248 function get_all_tags($profile, $lst, $usr) {
249 $profile_tag = new Notice_tag();
250 $profile_tag->query('SELECT DISTINCT(tag) ' .
251 'FROM profile_tag, subscription ' .
252 'WHERE tagger = ' . $profile->id . ' ' .
253 'AND ' . $usr . ' = ' . $profile->id . ' ' .
254 'AND ' . $lst . ' = tagged ' .
255 'AND tagger != tagged');
257 while ($profile_tag->fetch()) {
258 $tags[] = $profile_tag->tag;
260 $profile_tag->free();