]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/gallery.php
6d21b8310f49c2c53d0a4ba2124a2510f9378171
[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                 common_element_start('div', $this->div_class());
72
73                 $idx = 0;
74
75                 while ($subs->fetch()) {
76                         
77                         $idx++;
78
79                         $other = Profile::staticGet($subs->subscribed);
80                         
81                         common_element_start('a', array('title' => ($other->fullname) ?
82                                                                                         $other->fullname :
83                                                                                         $other->nickname,
84                                                                                         'href' => $other->profileurl,
85                                                                                         'class' => 'subscription'));
86                         $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
87                         common_element('img', 
88                                                    array('src' => 
89                                                                  (($avatar) ? $avatar->url : 
90                                                                   common_default_avatar(AVATAR_STREAM_SIZE)),
91                                                                  'width' => AVATAR_STREAM_SIZE,
92                                                                  'height' => AVATAR_STREAM_SIZE,
93                                                                  'class' => 'avatar stream',
94                                                                  'alt' => ($other->fullname) ?
95                                                                  $other->fullname :
96                                                                  $other->nickname));
97                         common_element_end('a');
98
99                         # XXX: subscribe form here
100
101                         if ($idx == AVATARS_PER_PAGE) {
102                                 break;
103                         }
104                 }
105
106                 common_element_end('div');
107                 
108                 common_pagination($page > 1, 
109                                                   $subs_count > AVATARS_PER_PAGE,
110                                                   $page, 
111                                                   $this->trimmed('action'), 
112                                                   array('nickname' => $profile->nickname));
113         }
114         
115         function gallery_type() {
116                 return NULL;
117         }
118
119         function get_instructions(&$profile) {
120                 return NULL;
121         }
122
123         function define_subs(&$subs, &$profile) {
124                 return;
125         }
126         
127         function div_class() {
128                 return '';
129         }
130 }