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 common_show_header($profile->nickname . ": " . $this->gallery_type(),
67 array($this, 'show_top'));
69 $this->display_links($page, $display);
71 $this->show_gallery($profile, $page, $display);
75 function no_such_user() {
76 $this->client_error(_('No such user.'));
79 function show_top($profile) {
80 common_element('div', 'instructions',
81 $this->get_instructions($profile));
84 function show_gallery($profile, $page, $display='list') {
86 $other = new Profile();
88 list($lst, $usr) = $this->fields();
90 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
92 $offset = ($page-1)*$per_page;
93 $limit = $per_page + 1;
95 if (common_config('db','type') == 'pgsql') {
96 $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
98 $lim = ' LIMIT ' . $offset . ', ' . $limit;
101 # XXX: memcached results
103 $other->query('SELECT profile.* ' .
104 'FROM profile JOIN subscription ' .
105 'ON profile.id = subscription.' . $lst . ' ' .
106 'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
107 'AND subscriber != subscribed ' .
108 'ORDER BY subscription.created DESC ' .
111 if ($display == 'list') {
112 $profile_list = new ProfileList($other);
113 $cnt = $profile_list->show_list();
115 $cnt = $this->icon_list($other);
118 # For building the pagination URLs
120 $args = array('nickname' => $profile->nickname);
122 if ($display != 'list') {
123 $args['display'] = $display;
126 common_pagination($page > 1,
129 $this->trimmed('action'),
133 function icon_list($other) {
135 common_element_start('ul', $this->div_class());
139 while ($other->fetch()) {
143 if ($cnt > AVATARS_PER_PAGE) {
147 common_element_start('li');
149 common_element_start('a', array('title' => ($other->fullname) ?
152 'href' => $other->profileurl,
153 'class' => 'subscription'));
154 $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
155 common_element('img',
157 (($avatar) ? common_avatar_display_url($avatar) :
158 common_default_avatar(AVATAR_STREAM_SIZE)),
159 'width' => AVATAR_STREAM_SIZE,
160 'height' => AVATAR_STREAM_SIZE,
161 'class' => 'avatar stream',
162 'alt' => ($other->fullname) ?
165 common_element_end('a');
167 # XXX: subscribe form here
169 common_element_end('li');
172 common_element_end('ul');
177 function gallery_type() {
181 function get_instructions(&$profile) {
189 function div_class() {
193 function display_links($page, $display) {
195 common_element_start('p');
199 common_element('span', NULL, _('List'));
201 common_element('a', array('href' => common_local_url($this->trimmed('action'),
202 array('display' => 'icons',
203 'page' => floor(($page * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)))),
207 common_element('a', array('href' => common_local_url($this->trimmed('action'),
208 array('page' => floor(($page * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)))),
211 common_element('span', NULL, _('Icons'));
215 common_element_end('p');