]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/gallery.php
d870b8a5691293ff4be27fd63e87760d5c5d9b57
[quix0rs-gnu-social.git] / lib / gallery.php
1 <?php
2
3 /*
4  * Laconica - a distributed open-source microblogging tool
5  * Copyright (C) 2008, Controlez-Vous, Inc.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 if (!defined('LACONICA')) { exit(1); }
22
23 require_once(INSTALLDIR.'/lib/profilelist.php');
24
25 # 10x8
26
27 define('AVATARS_PER_PAGE', 80);
28
29 class GalleryAction extends Action {
30
31         function is_readonly() {
32                 return true;
33         }
34
35         function handle($args) {
36                 parent::handle($args);
37                 
38                 $nickname = common_canonical_nickname($this->arg('nickname'));
39                 $user = User::staticGet('nickname', $nickname);
40
41                 if (!$user) {
42                         $this->no_such_user();
43                         return;
44                 }
45
46                 $profile = $user->getProfile();
47
48                 if (!$profile) {
49                         $this->server_error(_('User without matching profile in system.'));
50                         return;
51                 }
52
53                 $page = $this->arg('page');
54                 
55                 if (!$page) {
56                         $page = 1;
57                 }
58
59                 $display = $this->arg('display');
60                 
61                 if (!$display) {
62                         $display = 'list';
63                 }
64                 
65                 common_show_header($profile->nickname . ": " . $this->gallery_type(),
66                                                    NULL, $profile,
67                                                    array($this, 'show_top'));
68                 $this->show_gallery($profile, $page, $display);
69                 common_show_footer();
70         }
71
72         function no_such_user() {
73                 $this->client_error(_('No such user.'));
74         }
75
76         function show_top($profile) {
77                 common_element('div', 'instructions',
78                                            $this->get_instructions($profile));
79         }
80
81         function show_gallery($profile, $page, $display='list') {
82
83                 $other = new Profile();
84                 
85                 list($lst, $usr) = $this->fields();
86
87                 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
88
89                 $offset = ($page-1)*$per_page;
90                 $limit = $per_page + 1;
91                 
92                 if (common_config('db','type') == 'pgsql') {
93                         $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
94                 } else {
95                         $lim = ' LIMIT ' . $offset . ', ' . $limit;
96                 }
97
98                 # XXX: memcached results
99                 
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 ' . 
106                                                          $lim);
107                 
108                 if ($cnt == 0) {
109                         common_element('p', _('Nobody to show!'));
110                         return;
111                 }
112
113                 if ($display == 'list') {
114                         $profile_list = new ProfileList($other);
115                         $profile_list->show_list();
116                 } else {
117                         $this->icon_list($profile, $cnt);
118                 }
119                 
120                 common_pagination($page > 1,
121                                                   $cnt > $per_page,
122                                                   $page,
123                                                   $this->trimmed('action'),
124                                                   array('nickname' => $profile->nickname));
125         }
126
127         function icon_list($other, $subs_count) {
128                 
129                 common_element_start('ul', $this->div_class());
130                 
131                 for ($idx = 0; $idx < min($subs_count, AVATARS_PER_PAGE); $idx++) {
132
133                         $other->fetch();
134
135                         common_element_start('li');
136
137                         common_element_start('a', array('title' => ($other->fullname) ?
138                                                                                         $other->fullname :
139                                                                                         $other->nickname,
140                                                                                         'href' => $other->profileurl,
141                                                                                         'class' => 'subscription'));
142                         $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
143                         common_element('img',
144                                                    array('src' =>
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) ?
151                                                                  $other->fullname :
152                                                                  $other->nickname));
153                         common_element_end('a');
154
155                         # XXX: subscribe form here
156
157                         common_element_end('li');
158                 }
159                         
160                 common_element_end('ul');
161         }
162         
163         function gallery_type() {
164                 return NULL;
165         }
166
167         function get_instructions(&$profile) {
168                 return NULL;
169         }
170
171         function fields() {
172                 return NULL;
173         }
174
175         function div_class() {
176                 return '';
177         }
178 }