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')) { exit(1); }
24 define('AVATARS_PER_PAGE', 80);
26 class GalleryAction extends Action {
28 function is_readonly() {
32 function handle($args) {
33 parent::handle($args);
34 $nickname = common_canonical_nickname($this->arg('nickname'));
36 $user = User::staticGet('nickname', $nickname);
39 $this->no_such_user();
43 $profile = $user->getProfile();
46 $this->server_error(_('User without matching profile in system.'));
50 $page = $this->arg('page');
54 common_show_header($profile->nickname . ": " . $this->gallery_type(),
56 array($this, 'show_top'));
57 $this->show_gallery($profile, $page);
61 function no_such_user() {
62 $this->client_error(_('No such user.'));
65 function show_top($profile) {
66 common_element('div', 'instructions',
67 $this->get_instructions($profile));
70 function show_gallery($profile, $page) {
72 $subs = new Subscription();
74 $this->define_subs($subs, $profile);
76 $subs->orderBy('created DESC');
78 # We ask for an extra one to know if we need to do another page
80 $subs->limit((($page-1)*AVATARS_PER_PAGE), AVATARS_PER_PAGE + 1);
82 $subs_count = $subs->find();
84 if ($subs_count == 0) {
85 common_element('p', _('Nobody to show!'));
89 common_element_start('ul', $this->div_class());
91 for ($idx = 0; $idx < min($subs_count, AVATARS_PER_PAGE); $idx++) {
93 $result = $subs->fetch();
96 common_debug('Ran out of subscribers too early.', __FILE__);
100 $other_id = $this->get_other($subs);
101 $other = Profile::staticGet($other_id);
104 common_log(LOG_WARNING, 'No matching profile for ' . $other_id);
108 common_element_start('li');
110 common_element_start('a', array('title' => ($other->fullname) ?
113 'href' => $other->profileurl,
114 'class' => 'subscription'));
115 $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
116 common_element('img',
118 (($avatar) ? common_avatar_display_url($avatar) :
119 common_default_avatar(AVATAR_STREAM_SIZE)),
120 'width' => AVATAR_STREAM_SIZE,
121 'height' => AVATAR_STREAM_SIZE,
122 'class' => 'avatar stream',
123 'alt' => ($other->fullname) ?
126 common_element_end('a');
128 # XXX: subscribe form here
130 common_element_end('li');
133 common_element_end('ul');
135 common_pagination($page > 1,
136 $subs_count > AVATARS_PER_PAGE,
138 $this->trimmed('action'),
139 array('nickname' => $profile->nickname));
142 function gallery_type() {
146 function get_instructions(&$profile) {
150 function define_subs(&$subs, &$profile) {
154 function get_other(&$subs) {
158 function div_class() {