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