]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - _darcs/pristine/lib/gallery.php
add standard directories
[quix0rs-gnu-social.git] / _darcs / pristine / 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                 # Post from the tag dropdown; redirect to a GET
39
40                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
41                     common_redirect($this->self_url(), 307);
42                 }
43
44                 $nickname = common_canonical_nickname($this->arg('nickname'));
45                 $user = User::staticGet('nickname', $nickname);
46
47                 if (!$user) {
48                         $this->no_such_user();
49                         return;
50                 }
51
52                 $profile = $user->getProfile();
53
54                 if (!$profile) {
55                         $this->server_error(_('User without matching profile in system.'));
56                         return;
57                 }
58
59                 $page = $this->arg('page');
60
61                 if (!$page) {
62                         $page = 1;
63                 }
64
65                 $display = $this->arg('display');
66
67                 if (!$display) {
68                         $display = 'list';
69                 }
70
71                 $tag = $this->arg('tag');
72
73                 common_show_header($profile->nickname . ": " . $this->gallery_type(),
74                                                    NULL, $profile,
75                                                    array($this, 'show_top'));
76
77                 $this->display_links($profile, $page, $display);
78                 $this->show_tags_dropdown($profile);
79
80                 $this->show_gallery($profile, $page, $display, $tag);
81                 common_show_footer();
82         }
83
84         function no_such_user() {
85                 $this->client_error(_('No such user.'));
86         }
87
88         function show_tags_dropdown($profile) {
89                 $tag = $this->trimmed('tag');
90                 list($lst, $usr) = $this->fields();
91                 $tags = $this->get_all_tags($profile, $lst, $usr);
92                 $content = array();
93                 foreach ($tags as $t) {
94                         $content[$t] = $t;
95                 }
96                 if ($tags) {
97                         common_element_start('dl', array('id'=>'filter_tags'));
98                         common_element('dt', null, _('Filter tags'));
99                         common_element_start('dd');
100                         common_element_start('ul');
101                         common_element_start('li', array('id'=>'filter_tags_all', 'class'=>'child_1'));
102                         common_element('a', array('href' => common_local_url($this->trimmed('action'),
103                                                                                                                                  array('nickname' => $profile->nickname))),
104                                                    _('All'));
105                         common_element_end('li');
106                         common_element_start('li', array('id'=>'filter_tags_item'));
107                         common_element_start('form', array('name' => 'bytag', 'id' => 'bytag', 'method' => 'post'));
108                         common_dropdown('tag', _('Tag'), $content,
109                                                         _('Choose a tag to narrow list'), FALSE, $tag);
110                         common_submit('go', _('Go'));
111                         common_element_end('form');
112                         common_element_end('li');
113                         common_element_end('ul');
114                         common_element_end('dd');
115                         common_element_end('dl');
116                 }
117         }
118
119         function show_top($profile) {
120                 common_element('div', 'instructions',
121                                            $this->get_instructions($profile));
122         $this->show_menu();
123         }
124
125     function show_menu() {
126                 # action => array('prompt', 'title', $args)
127                 $action = $this->trimmed('action');
128                 $nickname = $this->trimmed('nickname');
129                 $menu =
130                   array('subscriptions' =>
131                                 array( _('Subscriptions'),
132                                            _('Subscriptions'),
133                       array('nickname' => $nickname)),
134                                 'subscribers' =>
135                                 array(
136                                           _('Subscribers'),
137                                           _('Subscribers'),
138                       array('nickname' => $nickname)),
139                                 );
140                 $this->nav_menu($menu);
141         }
142
143         function show_gallery($profile, $page, $display='list', $tag=NULL) {
144
145                 $other = new Profile();
146
147                 list($lst, $usr) = $this->fields();
148
149                 $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE;
150
151                 $offset = ($page-1)*$per_page;
152                 $limit = $per_page + 1;
153
154                 if (common_config('db','type') == 'pgsql') {
155                         $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
156                 } else {
157                         $lim = ' LIMIT ' . $offset . ', ' . $limit;
158                 }
159
160                 # XXX: memcached results
161                 # FIXME: SQL injection on $tag
162
163                 $other->query('SELECT profile.* ' .
164                                           'FROM profile JOIN subscription ' .
165                                           'ON profile.id = subscription.' . $lst . ' ' .
166                                           (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') .
167                                           'WHERE ' . $usr . ' = ' . $profile->id . ' ' .
168                                           'AND subscriber != subscribed ' .
169                                           (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') .
170                                           'ORDER BY subscription.created DESC, profile.id DESC ' .
171                                           $lim);
172
173                 if ($display == 'list') {
174             $cls = $this->profile_list_class();
175                         $profile_list = new $cls($other, $profile, $this->trimmed('action'));
176                         $cnt = $profile_list->show_list();
177                 } else {
178                         $cnt = $this->icon_list($other);
179                 }
180
181                 # For building the pagination URLs
182
183                 $args = array('nickname' => $profile->nickname);
184
185                 if ($display != 'list') {
186                         $args['display'] = $display;
187                 }
188
189                 common_pagination($page > 1,
190                                                   $cnt > $per_page,
191                                                   $page,
192                                                   $this->trimmed('action'),
193                                                   $args);
194         }
195
196     function profile_list_class() {
197         return 'ProfileList';
198     }
199
200         function icon_list($other) {
201
202                 common_element_start('ul', $this->div_class());
203
204                 $cnt = 0;
205
206                 while ($other->fetch()) {
207
208                         $cnt++;
209
210                         if ($cnt > AVATARS_PER_PAGE) {
211                                 break;
212                         }
213
214                         common_element_start('li');
215
216                         common_element_start('a', array('title' => ($other->fullname) ?
217                                                                                         $other->fullname :
218                                                                                         $other->nickname,
219                                                                                         'href' => $other->profileurl,
220                                                                                         'class' => 'subscription'));
221                         $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
222                         common_element('img',
223                                                    array('src' =>
224                                                                  (($avatar) ? common_avatar_display_url($avatar) :
225                                                                   common_default_avatar(AVATAR_STREAM_SIZE)),
226                                                                  'width' => AVATAR_STREAM_SIZE,
227                                                                  'height' => AVATAR_STREAM_SIZE,
228                                                                  'class' => 'avatar stream',
229                                                                  'alt' => ($other->fullname) ?
230                                                                  $other->fullname :
231                                                                  $other->nickname));
232                         common_element_end('a');
233
234                         # XXX: subscribe form here
235
236                         common_element_end('li');
237                 }
238
239                 common_element_end('ul');
240
241                 return $cnt;
242         }
243
244         function gallery_type() {
245                 return NULL;
246         }
247
248         function get_instructions(&$profile) {
249                 return NULL;
250         }
251
252         function fields() {
253                 return NULL;
254         }
255
256         function div_class() {
257                 return '';
258         }
259
260         function display_links($profile, $page, $display) {
261                 $tag = $this->trimmed('tag');
262
263                 common_element_start('dl', array('id'=>'subscriptions_nav'));
264                 common_element('dt', null, _('Subscriptions navigation'));
265                 common_element_start('dd');
266                 common_element_start('ul', array('class'=>'nav'));
267
268                 switch ($display) {
269                  case 'list':
270                         common_element('li', array('class'=>'child_1'), _('List'));
271                         common_element_start('li');
272                         $url_args = array('display' => 'icons',
273                                                           'nickname' => $profile->nickname,
274                                                           'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE));
275                         if ($tag) {
276                                 $url_args['tag'] = $tag;
277                         }
278                         $url = common_local_url($this->trimmed('action'), $url_args);
279                         common_element('a', array('href' => $url),
280                                                    _('Icons'));
281                         common_element_end('li');
282                         break;
283                  default:
284                         common_element_start('li', array('class'=>'child_1'));
285                         $url_args = array('nickname' => $profile->nickname,
286                                                           'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE));
287                         if ($tag) {
288                                 $url_args['tag'] = $tag;
289                         }
290                         $url = common_local_url($this->trimmed('action'), $url_args);
291                         common_element('a', array('href' => $url),
292                                                    _('List'));
293                         common_element_end('li');
294                         common_element('li', NULL, _('Icons'));
295                         break;
296                 }
297
298                 common_element_end('ul');
299                 common_element_end('dd');
300                 common_element_end('dl');
301         }
302
303         # Get list of tags we tagged other users with
304
305         function get_all_tags($profile, $lst, $usr) {
306                 $profile_tag = new Notice_tag();
307                 $profile_tag->query('SELECT DISTINCT(tag) ' .
308                                                         'FROM profile_tag, subscription ' .
309                                                         'WHERE tagger = ' . $profile->id . ' ' .
310                                                         'AND ' . $usr . ' = ' . $profile->id . ' ' .
311                                                         'AND ' . $lst . ' = tagged ' .
312                                                         'AND tagger != tagged');
313                 $tags = array();
314                 while ($profile_tag->fetch()) {
315                         $tags[] = $profile_tag->tag;
316                 }
317                 $profile_tag->free();
318                 return $tags;
319         }
320 }