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