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