]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/gallery.php
links to different display options for subscriptions
[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
69                 $this->display_links($page, $display);
70                 
71                 $this->show_gallery($profile, $page, $display);
72                 common_show_footer();
73         }
74
75         function no_such_user() {
76                 $this->client_error(_('No such user.'));
77         }
78
79         function show_top($profile) {
80                 common_element('div', 'instructions',
81                                            $this->get_instructions($profile));
82         }
83
84         function show_gallery($profile, $page, $display='list') {
85
86                 $other = new Profile();
87                 
88                 list($lst, $usr) = $this->fields();
89
90                 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
91
92                 $offset = ($page-1)*$per_page;
93                 $limit = $per_page + 1;
94                 
95                 if (common_config('db','type') == 'pgsql') {
96                         $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
97                 } else {
98                         $lim = ' LIMIT ' . $offset . ', ' . $limit;
99                 }
100
101                 # XXX: memcached results
102                 
103                 $other->query('SELECT profile.* ' .
104                                           'FROM profile JOIN subscription ' .
105                                           'ON profile.id = subscription.' . $lst . ' ' .
106                                           'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
107                                           'AND subscriber != subscribed ' .
108                                           'ORDER BY subscription.created DESC ' . 
109                                           $lim);
110                 
111                 if ($display == 'list') {
112                         $profile_list = new ProfileList($other);
113                         $cnt = $profile_list->show_list();
114                 } else {
115                         $cnt = $this->icon_list($other);
116                 }
117
118                 # For building the pagination URLs
119                 
120                 $args = array('nickname' => $profile->nickname);
121                 
122                 if ($display != 'list') {
123                         $args['display'] = $display;
124                 }
125                 
126                 common_pagination($page > 1,
127                                                   $cnt > $per_page,
128                                                   $page,
129                                                   $this->trimmed('action'),
130                                                   $args);
131         }
132
133         function icon_list($other) {
134                 
135                 common_element_start('ul', $this->div_class());
136
137                 $cnt = 0;
138                 
139                 while ($other->fetch()) {
140
141                         $cnt++;
142                         
143                         if ($cnt > AVATARS_PER_PAGE) {
144                                 break;
145                         }
146                         
147                         common_element_start('li');
148
149                         common_element_start('a', array('title' => ($other->fullname) ?
150                                                                                         $other->fullname :
151                                                                                         $other->nickname,
152                                                                                         'href' => $other->profileurl,
153                                                                                         'class' => 'subscription'));
154                         $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
155                         common_element('img',
156                                                    array('src' =>
157                                                                  (($avatar) ? common_avatar_display_url($avatar) :
158                                                                   common_default_avatar(AVATAR_STREAM_SIZE)),
159                                                                  'width' => AVATAR_STREAM_SIZE,
160                                                                  'height' => AVATAR_STREAM_SIZE,
161                                                                  'class' => 'avatar stream',
162                                                                  'alt' => ($other->fullname) ?
163                                                                  $other->fullname :
164                                                                  $other->nickname));
165                         common_element_end('a');
166
167                         # XXX: subscribe form here
168
169                         common_element_end('li');
170                 }
171                         
172                 common_element_end('ul');
173                 
174                 return $cnt;
175         }
176         
177         function gallery_type() {
178                 return NULL;
179         }
180
181         function get_instructions(&$profile) {
182                 return NULL;
183         }
184
185         function fields() {
186                 return NULL;
187         }
188
189         function div_class() {
190                 return '';
191         }
192         
193         function display_links($page, $display) {
194                 
195                 common_element_start('p');
196                 
197                 switch ($display) {
198                  case 'list':
199                         common_element('span', NULL, _('List'));
200                         common_text(' | ');
201                         common_element('a', array('href' => common_local_url($this->trimmed('action'),
202                                                                                                                                  array('display' => 'icons',
203                                                                                                                                            'page' => floor(($page * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)))),
204                                                    _('Icons'));
205                         break;
206                  default:
207                         common_element('a', array('href' => common_local_url($this->trimmed('action'),
208                                                                                                                                  array('page' => floor(($page * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)))),
209                                                    _('List'));
210                         common_text(' | ');
211                         common_element('span', NULL, _('Icons'));
212                         break;
213                 }
214                 
215                 common_element_end('p');
216         }
217 }