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'));
68 $this->show_gallery($profile, $page, $display);
72 function no_such_user() {
73 $this->client_error(_('No such user.'));
76 function show_top($profile) {
77 common_element('div', 'instructions',
78 $this->get_instructions($profile));
81 function show_gallery($profile, $page, $display='list') {
83 $other = new Profile();
85 list($lst, $usr) = $this->fields();
87 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
89 $offset = ($page-1)*$per_page;
90 $limit = $per_page + 1;
92 if (common_config('db','type') == 'pgsql') {
93 $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
95 $lim = ' LIMIT ' . $offset . ', ' . $limit;
98 # XXX: memcached results
100 $cnt = $other->query('SELECT profile.* ' .
101 'FROM profile JOIN subscription ' .
102 'ON profile.id = subscription.' . $lst . ' ' .
103 'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
104 'AND subscriber != subscribed ' .
105 'ORDER BY subscription.created DESC ' .
109 common_element('p', NULL, _('Nobody to show!'));
113 if ($display == 'list') {
114 $profile_list = new ProfileList($other);
115 $profile_list->show_list();
117 $this->icon_list($profile, $cnt);
120 common_pagination($page > 1,
123 $this->trimmed('action'),
124 array('nickname' => $profile->nickname));
127 function icon_list($other, $subs_count) {
129 common_element_start('ul', $this->div_class());
131 for ($idx = 0; $idx < min($subs_count, AVATARS_PER_PAGE); $idx++) {
135 common_element_start('li');
137 common_element_start('a', array('title' => ($other->fullname) ?
140 'href' => $other->profileurl,
141 'class' => 'subscription'));
142 $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
143 common_element('img',
145 (($avatar) ? common_avatar_display_url($avatar) :
146 common_default_avatar(AVATAR_STREAM_SIZE)),
147 'width' => AVATAR_STREAM_SIZE,
148 'height' => AVATAR_STREAM_SIZE,
149 'class' => 'avatar stream',
150 'alt' => ($other->fullname) ?
153 common_element_end('a');
155 # XXX: subscribe form here
157 common_element_end('li');
160 common_element_end('ul');
163 function gallery_type() {
167 function get_instructions(&$profile) {
175 function div_class() {