]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/gallery.php
twiddle some parens in imsettings for gettext
[quix0rs-gnu-social.git] / lib / gallery.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 # 10x8
23
24 define('AVATARS_PER_PAGE', 80);
25
26 class GalleryAction extends Action {
27
28         function handle($args) {
29                 parent::handle($args);
30                 $nickname = $this->arg('nickname');
31                 $profile = Profile::staticGet('nickname', $nickname);
32                 if (!$profile) {
33                         $this->no_such_user();
34                         return;
35                 }
36                 $user = User::staticGet($profile->id);
37                 if (!$user) {
38                         $this->no_such_user();
39                         return;
40                 }
41                 $page = $this->arg('page');
42                 if (!$page) {
43                         $page = 1;
44                 }
45                 common_show_header($profile->nickname . ": " . $this->gallery_type(),
46                                                    NULL, $profile,
47                                                    array($this, 'show_top'));
48                 $this->show_gallery($profile, $page);
49                 common_show_footer();
50         }
51
52         function no_such_user() {
53                 $this->client_error(_('No such user.'));
54         }
55
56         function show_top($profile) {
57                 common_element('div', 'instructions',
58                                            $this->get_instructions($profile));
59         }
60
61         function show_gallery($profile, $page) {
62
63                 $subs = new Subscription();
64
65                 $this->define_subs($subs, $profile);
66
67                 $subs->orderBy('created DESC');
68
69                 # We ask for an extra one to know if we need to do another page
70
71                 $subs->limit((($page-1)*AVATARS_PER_PAGE), AVATARS_PER_PAGE + 1);
72
73                 $subs_count = $subs->find();
74
75                 if ($subs_count == 0) {
76                         common_element('p', _('Nobody to show!'));
77                         return;
78                 }
79
80                 common_element_start('ul', $this->div_class());
81
82                 for ($idx = 0; $idx < min($subs_count, AVATARS_PER_PAGE); $idx++) {
83
84                         $result = $subs->fetch();
85
86                         if (!$result) {
87                                 common_debug('Ran out of subscribers too early.', __FILE__);
88                                 break;
89                         }
90
91                         $other = Profile::staticGet($this->get_other($subs));
92
93                         common_element_start('li');
94
95                         common_element_start('a', array('title' => ($other->fullname) ?
96                                                                                         $other->fullname :
97                                                                                         $other->nickname,
98                                                                                         'href' => $other->profileurl,
99                                                                                         'class' => 'subscription'));
100                         $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
101                         common_element('img',
102                                                    array('src' =>
103                                                                  (($avatar) ? common_avatar_display_url($avatar) :
104                                                                   common_default_avatar(AVATAR_STREAM_SIZE)),
105                                                                  'width' => AVATAR_STREAM_SIZE,
106                                                                  'height' => AVATAR_STREAM_SIZE,
107                                                                  'class' => 'avatar stream',
108                                                                  'alt' => ($other->fullname) ?
109                                                                  $other->fullname :
110                                                                  $other->nickname));
111                         common_element_end('a');
112
113                         # XXX: subscribe form here
114
115                         common_element_end('li');
116                 }
117
118                 common_element_end('ul');
119
120                 common_pagination($page > 1,
121                                                   $subs_count > AVATARS_PER_PAGE,
122                                                   $page,
123                                                   $this->trimmed('action'),
124                                                   array('nickname' => $profile->nickname));
125         }
126
127         function gallery_type() {
128                 return NULL;
129         }
130
131         function get_instructions(&$profile) {
132                 return NULL;
133         }
134
135         function define_subs(&$subs, &$profile) {
136                 return;
137         }
138
139         function get_other(&$subs) {
140                 return NULL;
141         }
142
143         function div_class() {
144                 return '';
145         }
146 }