Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/index.php,v $
15
  $Revision: 1.17 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
// Check if standalone is installed in a portal like phpNuke (added by DJMaze)
21
$DIR=preg_split("/[\/\\\]/",dirname($_SERVER['PATH_TRANSLATED']));
22
if ($DIR[count($DIR)-2] == "modules") {
23
    echo "<html><body><h1>ERROR</h1>You installed the standalone Coppermine into your Nuke portal.<br>".
24
         "Please download and install a CPG Port: <a href=\"http://sourceforge.net/project/showfiles.php?group_id=89658\">CPG for PostNuke OR CPG for PHPnuke</a></body></html>";
25
    die();
26
} // end check
27
define('IN_COPPERMINE', true);
28
define('INDEX_PHP', true);
29
 
30
require('include/init.inc.php');
31
if ($CONFIG['enable_smilies']) include("include/smilies.inc.php");
32
/**
33
 * Local functions definition
34
 */
35
function html_albummenu($id)
36
{
37
    global $template_album_admin_menu, $lang_album_admin_menu;
38
 
39
    static $template = '';
40
 
41
    if ($template == '') {
42
        $params = array('{CONFIRM_DELETE}' => $lang_album_admin_menu['confirm_delete'],
43
            '{DELETE}' => $lang_album_admin_menu['delete'],
44
            '{MODIFY}' => $lang_album_admin_menu['modify'],
45
            '{EDIT_PICS}' => $lang_album_admin_menu['edit_pics'],
46
            );
47
 
48
        $template = template_eval($template_album_admin_menu, $params);
49
    }
50
 
51
    $params = array('{ALBUM_ID}' => $id,
52
        );
53
 
54
    return template_eval($template, $params);
55
}
56
 
57
function get_subcat_data($parent, &$cat_data, &$album_set_array, $level, $ident = '')
58
{
59
    global $CONFIG, $HIDE_USER_CAT, $FORBIDDEN_SET,$cpg_show_private_album;
60
 
61
    $album_filter='';
62
    $pic_filter='';
63
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
64
        $album_filter = ' and '.str_replace('p.','a.',$FORBIDDEN_SET);
65
        $pic_filter = ' and '.str_replace('p.',$CONFIG['TABLE_PICTURES'].'.',$FORBIDDEN_SET);
66
    }
67
 
68
    $result = db_query("SELECT cid, name, description, thumb FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent'  ORDER BY pos");
69
 
70
    if (mysql_num_rows($result) > 0) {
71
        $rowset = db_fetch_rowset($result);
72
        foreach ($rowset as $subcat) {
73
            if ($subcat['cid'] == USER_GAL_CAT) {
74
                $sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category>=" . FIRST_USER_CAT.$album_filter;
75
                $result = db_query($sql);
76
                $album_count = mysql_num_rows($result);
77
                while ($row = mysql_fetch_array($result)) {
78
                    $album_set_array[] = $row['aid'];
79
                } // while
80
                mysql_free_result($result);
81
 
82
                $result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']} as p, {$CONFIG['TABLE_ALBUMS']} as a WHERE p.aid = a.aid AND category >= " . FIRST_USER_CAT.$album_filter);
83
                $nbEnr = mysql_fetch_array($result);
84
                $pic_count = $nbEnr[0];
85
 
86
                $subcat['description'] = preg_replace("/<br.*?>[\r\n]*/i", '<br />' . $ident , bb_decode($subcat['description']));
87
                $link = $ident . "<a href=\"index.php?cat={$subcat['cid']}\">{$subcat['name']}</a>";
88
                if ($album_count) {
89
                    $cat_data[] = array($link, $ident . $subcat['description'], $album_count, $pic_count);
90
                    $HIDE_USER_CAT = 0;
91
                } else {
92
                    $HIDE_USER_CAT = 1;
93
                }
94
            } else {
95
                                $unaliased_album_filter = str_replace('a.','',$album_filter);
96
                $result = db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']}".$unaliased_album_filter);
97
                $album_count = mysql_num_rows($result);
98
                while ($row = mysql_fetch_array($result)) {
99
                    $album_set_array[] = $row['aid'];
100
                } // while
101
                mysql_free_result($result);
102
 
103
                $result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']} as p, {$CONFIG['TABLE_ALBUMS']} as a WHERE p.aid = a.aid AND category = {$subcat['cid']}".$album_filter);
104
                $nbEnr = mysql_fetch_array($result);
105
                mysql_free_result($result);
106
                $pic_count = $nbEnr[0];
107
                if ($subcat['thumb']>0) {
108
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight ".
109
                        "FROM {$CONFIG['TABLE_PICTURES']} ".
110
                        "WHERE pid='{$subcat['thumb']}'".$pic_filter;
111
                    $result = db_query($sql);
112
                    if (mysql_num_rows($result)) {
113
                        $picture = mysql_fetch_array($result);
114
                        mysql_free_result($result);
115
                        $pic_url =  get_pic_url($picture, 'thumb');
116
                        if (!is_image($picture['filename'])) {
117
                                $image_info = getimagesize($pic_url);
118
                                $picture['pwidth'] = $image_info[0];
119
                                $picture['pheight'] = $image_info[1];
120
                        }
121
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
122
                        $user_thumb = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"\">";
123
                        $user_thumb = "<a href=\"index.php?cat={$subcat['cid']}\">".$user_thumb."</a>";
124
                    }
125
                }else{
126
                    $user_thumb ="";
127
                }
128
                $subcat['name'] = $subcat['name'];
129
                $subcat['description'] = preg_replace("/<br.*?>[\r\n]*/i", '<br />', bb_decode($subcat['description']));
130
                $link = "<a href=\"index.php?cat={$subcat['cid']}\">{$subcat['name']}</a>";
131
                $user_thumb = $ident.$user_thumb;
132
                if ($pic_count == 0 && $album_count == 0) {
133
                                        $user_thumb = $ident;
134
                    $cat_data[] = array($link, $subcat['description'],'cat_thumb' =>$user_thumb);
135
                } else {
136
                    // Check if you need to show subcat_level
137
                    if ($level == $CONFIG['subcat_level']) {
138
                        $cat_albums = list_cat_albums($subcat['cid']);
139
                    } else {
140
                        $cat_albums = '';
141
                    }
142
                    $cat_data[] = array($link, $subcat['description'], $album_count, $pic_count, 'cat_albums' => $cat_albums,'cat_thumb' =>$user_thumb);
143
                }
144
            }
145
 
146
            if ($level > 1) get_subcat_data($subcat['cid'], $cat_data, $album_set_array, $level -1, $ident . "</td><td><img src=\"images/spacer.gif\" width=\"20\" height=\"1\"></td><td>");
147
        }
148
    }
149
}
150
// List all categories
151
function get_cat_list(&$breadcrumb, &$cat_data, &$statistics)
152
{
153
    global $HTTP_GET_VARS, $CONFIG, $ALBUM_SET, $CURRENT_CAT_NAME, $BREADCRUMB_TEXT, $STATS_IN_ALB_LIST, $FORBIDDEN_SET;
154
    global $HIDE_USER_CAT,$cpg_show_private_album;
155
    global $cat;
156
    global $lang_list_categories, $lang_errors;
157
 
158
    // Build the breadcrumb
159
    breadcrumb($cat, $breadcrumb, $BREADCRUMB_TEXT);
160
    // Build the category list
161
    $cat_data = array();
162
    $album_set_array = array();
163
    get_subcat_data($cat, $cat_data, $album_set_array, $CONFIG['subcat_level']);
164
 
165
    $album_filter='';
166
    $pic_filter='';
167
    $cat = (int) $cat;
168
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
169
        $album_filter = ' and '.str_replace('p.','a.',$FORBIDDEN_SET);
170
        $pic_filter = ' and '.$FORBIDDEN_SET;
171
    }
172
 
173
    // Add the albums in the current category to the album set
174
    //if ($cat) {
175
        if ($cat == USER_GAL_CAT) {
176
            $sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category >= " . FIRST_USER_CAT.$album_filter;
177
            $result = db_query($sql);
178
        } else {
179
            $sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '$cat'".$album_filter;
180
            $result = db_query($sql);
181
        }
182
        while ($row = mysql_fetch_array($result)) {
183
            $album_set_array[] = $row['aid'];
184
        } // while
185
        mysql_free_result($result);
186
    //}
187
    if (count($album_set_array)&&$cat) {
188
        $set = '';
189
        foreach ($album_set_array as $album) $set .= $album . ',';
190
        $set = substr($set, 0, -1);
191
        $current_album_set = "AND aid IN ($set) ";
192
        $ALBUM_SET .= $current_album_set;
193
    } elseif ($cat) {
194
        $current_album_set = "AND aid IN (-1) ";
195
        $ALBUM_SET .= $current_album_set;
196
    }
197
    // Gather gallery statistics
198
    if ($cat == 0) {
199
        $result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE 1".$album_filter);
200
        $nbEnr = mysql_fetch_array($result);
201
        $album_count = $nbEnr[0];
202
        mysql_free_result($result);
203
 
204
        $sql = "SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']} as p ".
205
                'LEFT JOIN '.$CONFIG['TABLE_ALBUMS'].' as a '.
206
                'ON a.aid=p.aid '.
207
                'WHERE 1'.$pic_filter;
208
        $result = db_query($sql);
209
        $nbEnr = mysql_fetch_array($result);
210
        $picture_count = $nbEnr[0];
211
        mysql_free_result($result);
212
 
213
        $sql = "SELECT count(*) FROM {$CONFIG['TABLE_COMMENTS']} as c ".
214
                'LEFT JOIN '.$CONFIG['TABLE_PICTURES'].' as p '.
215
                'ON c.pid=p.pid '.
216
                'LEFT JOIN '.$CONFIG['TABLE_ALBUMS'].' as a '.
217
                'ON a.aid=p.aid '.
218
                'WHERE 1'.$pic_filter;
219
        $result = db_query($sql);
220
        $nbEnr = mysql_fetch_array($result);
221
        $comment_count = $nbEnr[0];
222
        mysql_free_result($result);
223
 
224
        $sql = "SELECT count(*) FROM {$CONFIG['TABLE_CATEGORIES']} WHERE 1";
225
        $result = db_query($sql);
226
        $nbEnr = mysql_fetch_array($result);
227
        $cat_count = $nbEnr[0] - $HIDE_USER_CAT;
228
        mysql_free_result($result);
229
 
230
        $sql = "SELECT sum(hits) FROM {$CONFIG['TABLE_PICTURES']} as p ".
231
                'LEFT JOIN '.$CONFIG['TABLE_ALBUMS'].' as a '.
232
                'ON p.aid=a.aid '.
233
                'WHERE 1'.$pic_filter;
234
        $result = db_query($sql);
235
        $nbEnr = mysql_fetch_array($result);
236
        $hit_count = (int)$nbEnr[0];
237
        mysql_free_result($result);
238
 
239
        if (count($cat_data)) {
240
            $statistics = strtr($lang_list_categories['stat1'], array('[pictures]' => $picture_count,
241
                    '[albums]' => $album_count,
242
                    '[cat]' => $cat_count,
243
                    '[comments]' => $comment_count,
244
                    '[views]' => $hit_count));
245
        } else {
246
            $STATS_IN_ALB_LIST = true;
247
            $statistics = strtr($lang_list_categories['stat3'], array('[pictures]' => $picture_count,
248
                    '[albums]' => $album_count,
249
                    '[comments]' => $comment_count,
250
                    '[views]' => $hit_count));
251
        }
252
    } elseif ($cat >= FIRST_USER_CAT && $ALBUM_SET) {
253
        $result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} WHERE 1 $current_album_set");
254
        $nbEnr = mysql_fetch_array($result);
255
        $album_count = $nbEnr[0];
256
        mysql_free_result($result);
257
 
258
        $result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1 $current_album_set");
259
        $nbEnr = mysql_fetch_array($result);
260
        $picture_count = $nbEnr[0];
261
        mysql_free_result($result);
262
 
263
        $result = db_query("SELECT sum(hits) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1 $current_album_set");
264
        $nbEnr = mysql_fetch_array($result);
265
        $hit_count = (int)$nbEnr[0];
266
        mysql_free_result($result);
267
 
268
        $statistics = strtr($lang_list_categories['stat2'], array('[pictures]' => $picture_count,
269
                '[albums]' => $album_count,
270
                '[views]' => $hit_count));
271
    } else {
272
        $statistics = '';
273
    }
274
}
275
 
276
function list_users()
277
{
278
    global $CONFIG, $PAGE, $FORBIDDEN_SET;
279
    global $lang_list_users, $lang_errors, $template_user_list_info_box, $cpg_show_private_album;
280
 
281
    if (defined('UDB_INTEGRATION')) {
282
        $result = udb_list_users_query($user_count);
283
    } else {
284
//        $sql = "SELECT user_id," . "        user_name," . "        COUNT(DISTINCT a.aid) as alb_count," . "        COUNT(DISTINCT pid) as pic_count," . "        MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_USERS']} AS u " . "INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON category = " . FIRST_USER_CAT . " + user_id " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' " . "$FORBIDDEN_SET " . "GROUP BY user_id " . "ORDER BY user_name ";
285
// Fixed correct album count DJMaze
286
        $sql = "SELECT user_id, " .
287
               "user_name, " .
288
               "COUNT(DISTINCT a.aid) as alb_count, " .
289
               "COUNT(DISTINCT pid) as pic_count, " .
290
               "MAX(pid) as thumb_pid " .
291
               "FROM {$CONFIG['TABLE_USERS']} AS u " .
292
               "INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON category = " . FIRST_USER_CAT . " + user_id " .
293
               "LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON (p.aid = a.aid AND approved = 'YES') ";
294
        if ($FORBIDDEN_SET != "") $sql .= "WHERE $FORBIDDEN_SET ";
295
        $sql .= "GROUP BY user_id " .
296
                "ORDER BY user_name";
297
 
298
        $result = db_query($sql);
299
 
300
        $user_count = mysql_num_rows($result);
301
    }
302
 
303
    if (!$user_count) {
304
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', '100%');
305
        mysql_free_result($result);
306
        return;
307
    }
308
 
309
    $user_per_page = $CONFIG['thumbcols'] * $CONFIG['thumbrows'];
310
    $totalPages = ceil($user_count / $user_per_page);
311
    if ($PAGE > $totalPages) $PAGE = 1;
312
    $lower_limit = ($PAGE-1) * $user_per_page;
313
    $upper_limit = min($user_count, $PAGE * $user_per_page);
314
    $row_count = $upper_limit - $lower_limit;
315
 
316
    if (defined('UDB_INTEGRATION')) {
317
        $rowset = udb_list_users_retrieve_data($result, $lower_limit, $row_count);
318
    } else {
319
        $rowset = array();
320
        $i = 0;
321
        mysql_data_seek($result, $lower_limit);
322
        while (($row = mysql_fetch_array($result)) && ($i++ < $row_count)) $rowset[] = $row;
323
        mysql_free_result($result);
324
    }
325
 
326
    $user_list = array();
327
    foreach ($rowset as $user) {
328
        $user_thumb = '<img src="images/nopic.jpg" class="image" border="0" />';
329
        $user_pic_count = $user['pic_count'];
330
        $user_thumb_pid = $user['thumb_pid'];
331
        $user_album_count = $user['alb_count'];
332
 
333
        if ($user_pic_count) {
334
 
335
                        if ($CONFIG['show_private']){
336
                                $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
337
                                $user_thumb = "<img src=\"images/private.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
338
                        }
339
            $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='$user_thumb_pid'";
340
            $result = db_query($sql);
341
 
342
            if (mysql_num_rows($result)) {
343
                $picture = mysql_fetch_array($result);
344
                mysql_free_result($result);
345
                $pic_url =  get_pic_url($picture, 'thumb');
346
                if (!is_image($picture['filename'])) {
347
                        $image_info = getimagesize($pic_url);
348
                        $picture['pwidth'] = $image_info[0];
349
                        $picture['pheight'] = $image_info[1];
350
                }
351
                $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
352
                    $user_thumb = "<img src=\"" . get_pic_url($picture, 'thumb') . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"\">";
353
 
354
            }
355
 
356
                }
357
        $albums_txt = sprintf($lang_list_users['n_albums'], $user_album_count);
358
        $pictures_txt = sprintf($lang_list_users['n_pics'], $user_pic_count);
359
 
360
        $params = array('{USER_NAME}' => $user['user_name'],
361
            '{USER_ID}' => $user['user_id'],
362
            '{ALBUMS}' => $albums_txt,
363
            '{PICTURES}' => $pictures_txt,
364
            );
365
        $caption = template_eval($template_user_list_info_box, $params);
366
 
367
        $user_list[] = array('cat' => FIRST_USER_CAT + $user['user_id'],
368
            'image' => $user_thumb,
369
            'caption' => $caption,
370
            );
371
    }
372
    theme_display_thumbnails($user_list, $user_count, '', '', 1, $PAGE, $totalPages, false, true, 'user');
373
}
374
// List all albums
375
function list_albums()
376
{
377
    global $CONFIG, $USER, $USER_DATA, $PAGE, $lastup_date_fmt,$FORBIDDEN_SET;
378
    global $cat;
379
    global $lang_list_albums, $lang_errors,$cpg_show_private_album;
380
 
381
    $alb_per_page = $CONFIG['albums_per_page'];
382
    $maxTab = $CONFIG['max_tabs'];
383
 
384
    $album_filter='';
385
    $pic_filter='';
386
    $pic_subquery='';
387
 
388
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
389
        $album_filter = ' and '.str_replace('p.','a.',$FORBIDDEN_SET);
390
        $pic_filter = ' and '.$FORBIDDEN_SET;
391
    }
392
 
393
 
394
    $result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '$cat'".$album_filter);
395
    $nbEnr = mysql_fetch_array($result);
396
    $nbAlb = $nbEnr[0];
397
    mysql_free_result($result);
398
 
399
    if (!$nbAlb) return;
400
 
401
    $totalPages = ceil($nbAlb / $alb_per_page);
402
 
403
    if ($PAGE > $totalPages) $PAGE = 1;
404
    $lower_limit = ($PAGE-1) * $alb_per_page;
405
    $upper_limit = min($nbAlb, $PAGE * $alb_per_page);
406
    $limit = "LIMIT " . $lower_limit . "," . ($upper_limit - $lower_limit);
407
 
408
    $sql = 'SELECT a.aid, a.title, a.description, visibility, filepath, '.
409
           'filename, url_prefix, pwidth, pheight '.
410
           'FROM '.$CONFIG['TABLE_ALBUMS'].' as a '.
411
           'LEFT JOIN '.$CONFIG['TABLE_PICTURES'].' as p '.
412
           'ON a.thumb=p.pid '.
413
           'WHERE category='.$cat.$album_filter.
414
           ' ORDER BY a.pos '.
415
           $limit;
416
 
417
 
418
    $alb_thumbs_q = db_query($sql);
419
    $alb_thumbs = db_fetch_rowset($alb_thumbs_q);
420
    mysql_free_result($alb_thumbs_q);
421
 
422
    $disp_album_count = count($alb_thumbs);
423
    $album_set = '';
424
    foreach($alb_thumbs as $value) {
425
        $album_set .= $value['aid'] . ', ';
426
    }
427
    $album_set = '(' . substr($album_set, 0, -2) . ')';
428
 
429
    $sql = "SELECT aid, count(pid) as pic_count, max(pid) as last_pid, max(ctime) as last_upload ".
430
           "FROM {$CONFIG['TABLE_PICTURES']} ".
431
           "WHERE aid IN $album_set AND approved = 'YES' ".
432
           "GROUP BY aid";
433
    $alb_stats_q = db_query($sql);
434
    $alb_stats = db_fetch_rowset($alb_stats_q);
435
    mysql_free_result($alb_stats_q);
436
 
437
    foreach($alb_stats as $key => $value) {
438
        $cross_ref[$value['aid']] = &$alb_stats[$key];
439
    }
440
 
441
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
442
        $alb_thumb = &$alb_thumbs[$alb_idx];
443
        $aid = $alb_thumb['aid'];
444
 
445
        if (isset($cross_ref[$aid])) {
446
            $alb_stat = $cross_ref[$aid];
447
            $count = $alb_stat['pic_count'];
448
        } else {
449
            $alb_stat = array();
450
            $count = 0;
451
        }
452
        // Inserts a thumbnail if the album contains 1 or more images
453
 
454
        $visibility = $alb_thumb['visibility'];
455
        if ($visibility == '0' || $visibility == (FIRST_USER_CAT + USER_ID) || in_array($visibility, $USER_DATA['groups']) || $USER_DATA['can_see_all_albums'] || $CONFIG['allow_private_albums']==0) {
456
            if ($count > 0) {
457
                if ($alb_thumb['filename']) {
458
                    $picture = &$alb_thumb;
459
                } else {
460
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight ".
461
                           "FROM {$CONFIG['TABLE_PICTURES']} ".
462
                           "WHERE pid='{$alb_stat['last_pid']}'";
463
                    $result = db_query($sql);
464
                    $picture = mysql_fetch_array($result);
465
                    mysql_free_result($result);
466
                }
467
                $pic_url =  get_pic_url($picture, 'thumb');
468
                if (!is_image($picture['filename'])) {
469
                        $image_info = getimagesize($pic_url);
470
                        $picture['pwidth'] = $image_info[0];
471
                        $picture['pheight'] = $image_info[1];
472
                }
473
                $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
474
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\">";
475
            } else { // Inserts an empty thumbnail if the album contains 0 images
476
                $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
477
 
478
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/nopic.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
479
            }
480
        } elseif ($CONFIG['show_private']) {
481
            $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
482
            $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/private.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
483
 
484
        }
485
        // Prepare everything
486
 
487
        if ($visibility == '0' || $visibility == (FIRST_USER_CAT + USER_ID) || in_array($visibility, $USER_DATA['groups']) || $USER_DATA['can_see_all_albums'] || $CONFIG['allow_private_albums']==0) {
488
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
489
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
490
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
491
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
492
            $alb_list[$alb_idx]['pic_count'] = $count;
493
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
494
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
495
            $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : ' ';
496
        } elseif ($CONFIG['show_private']) { // uncomment this else block to show private album description
497
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
498
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
499
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
500
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
501
            $alb_list[$alb_idx]['pic_count'] = $count;
502
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
503
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
504
            $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : ' ';
505
        }
506
    }
507
 
508
    theme_display_album_list($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
509
}
510
 
511
/**
512
 */
513
// List category albums
514
// This has been added to list the category albums largely a repetition of code elsewhere
515
// Redone for a cleaner approach
516
function list_cat_albums($cat = 0)
517
{
518
    global $CONFIG, $USER, $lastup_date_fmt, $HTTP_GET_VARS, $USER_DATA, $FORBIDDEN_SET;
519
    global $lang_list_albums, $lang_errors,$cpg_show_private_album;
520
    $PAGE = 1;
521
    if ($cat == 0) {
522
        return '';
523
    }
524
 
525
    $alb_per_page = $CONFIG['albums_per_page'];
526
    $maxTab = $CONFIG['max_tabs'];
527
 
528
    $album_filter='';
529
    $pic_filter='';
530
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
531
        $album_filter = ' and '.str_replace('p.','a.',$FORBIDDEN_SET);
532
        $pic_filter = ' and '.$FORBIDDEN_SET;
533
    }
534
 
535
    $sql = "SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '$cat'".$album_filter;
536
    $result = db_query($sql);
537
    $nbEnr = mysql_fetch_array($result);
538
    $nbAlb = $nbEnr[0];
539
    mysql_free_result($result);
540
 
541
    if ($nbAlb == 0) {
542
        return;
543
    }
544
 
545
    $totalPages = ceil($nbAlb / $alb_per_page);
546
 
547
    if ($PAGE > $totalPages) $PAGE = 1;
548
    $lower_limit = ($PAGE-1) * $alb_per_page;
549
    $upper_limit = min($nbAlb, $PAGE * $alb_per_page);
550
    $limit = "LIMIT " . $lower_limit . "," . ($upper_limit - $lower_limit);
551
 
552
 
553
    /*
554
    $sql = "SELECT a.aid, a.title, a.description, visibility, filepath, ".
555
           "filename, url_prefix, pwidth, pheight ".
556
           "FROM {$CONFIG['TABLE_ALBUMS']} as a ".
557
           "LEFT JOIN {$CONFIG['TABLE_PICTURES']} as p ON thumb=pid ".
558
           "WHERE category = $cat ORDER BY a.pos ".$limit;
559
 
560
    */
561
    $sql = 'SELECT a.aid, a.title, a.description, visibility, filepath, '.
562
           'filename, url_prefix, pwidth, pheight '.
563
           'FROM '.$CONFIG['TABLE_ALBUMS'].' as a '.
564
           'LEFT JOIN '.$CONFIG['TABLE_PICTURES'].' as p '.
565
           'ON a.thumb=p.pid '.
566
           'WHERE category='.$cat.$album_filter.
567
           ' ORDER BY a.pos '.
568
           $limit;
569
 
570
    $alb_thumbs_q = db_query($sql);
571
    $alb_thumbs = db_fetch_rowset($alb_thumbs_q);
572
    mysql_free_result($alb_thumbs_q);
573
 
574
    $disp_album_count = count($alb_thumbs);
575
    $album_set = '';
576
    foreach($alb_thumbs as $value) {
577
        $album_set .= $value['aid'] . ', ';
578
    }
579
    $album_set = '(' . substr($album_set, 0, -2) . ')';
580
 
581
    $sql = "SELECT aid, count(pid) as pic_count, max(pid) as last_pid, max(ctime) as last_upload ".
582
           "FROM {$CONFIG['TABLE_PICTURES']} ".
583
           "WHERE aid IN $album_set AND approved = 'YES' ".
584
           "GROUP BY aid";
585
    $alb_stats_q = db_query($sql);
586
    $alb_stats = db_fetch_rowset($alb_stats_q);
587
    mysql_free_result($alb_stats_q);
588
 
589
    foreach($alb_stats as $key => $value) {
590
        $cross_ref[$value['aid']] = &$alb_stats[$key];
591
    }
592
 
593
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
594
        $alb_thumb = &$alb_thumbs[$alb_idx];
595
        $aid = $alb_thumb['aid'];
596
 
597
        if (isset($cross_ref[$aid])) {
598
            $alb_stat = $cross_ref[$aid];
599
            $count = $alb_stat['pic_count'];
600
        } else {
601
            $alb_stat = array();
602
            $count = 0;
603
        }
604
        // Inserts a thumbnail if the album contains 1 or more images
605
        $visibility = $alb_thumb['visibility'];
606
        if ($visibility == '0' || $visibility == (FIRST_USER_CAT + USER_ID) || in_array($visibility, $USER_DATA['groups']) || $USER_DATA['can_see_all_albums'] || $CONFIG['allow_private_albums']==0) { // test for visibility
607
            if ($count > 0) { // Inserts a thumbnail if the album contains 1 or more images
608
                if ($alb_thumb['filename']) {
609
                    $picture = &$alb_thumb;
610
                } else {
611
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='{$alb_stat['last_pid']}'";
612
                    $result = db_query($sql);
613
                    $picture = mysql_fetch_array($result);
614
                    mysql_free_result($result);
615
                }
616
                $pic_url =  get_pic_url($picture, 'thumb');
617
                if (!is_image($picture['filename'])) {
618
                        $image_info = getimagesize($pic_url);
619
                        $picture['pwidth'] = $image_info[0];
620
                        $picture['pheight'] = $image_info[1];
621
                }
622
                $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
623
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\">";
624
            } else { // Inserts an empty thumbnail if the album contains 0 images
625
                $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
626
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/nopic.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
627
            }
628
        } elseif ($CONFIG['show_private']) {
629
            $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
630
            $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/private.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
631
        }
632
        // Prepare everything
633
        if ($visibility == '0' || $visibility == (FIRST_USER_CAT + USER_ID) || in_array($visibility, $USER_DATA['groups']) || $USER_DATA['can_see_all_albums']) {
634
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
635
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
636
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
637
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
638
            $alb_list[$alb_idx]['pic_count'] = $count;
639
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
640
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
641
            $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : '';
642
        } elseif ($CONFIG['show_private']) { // uncomment this else block to show private album description
643
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
644
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
645
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
646
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
647
            $alb_list[$alb_idx]['pic_count'] = $count;
648
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
649
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
650
            $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : '';
651
        }
652
    }
653
    ob_start();
654
    theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
655
    $cat_albums = ob_get_contents();
656
    ob_end_clean();
657
    return $cat_albums;
658
}
659
 
660
/**
661
 */
662
/**
663
 * Main code
664
 */
665
 
666
if (isset($HTTP_GET_VARS['page'])) {
667
    $PAGE = max((int)$HTTP_GET_VARS['page'], 1);
668
    $USER['lap'] = $PAGE;
669
} elseif (isset($USER['lap'])) {
670
    $PAGE = max((int)$USER['lap'], 1);
671
} else {
672
    $PAGE = 1;
673
}
674
 
675
if (isset($HTTP_GET_VARS['cat'])) {
676
    $cat = (int)$HTTP_GET_VARS['cat'];
677
}
678
// Gather data for categories
679
$breadcrumb = '';
680
$cat_data = array();
681
$statistics = '';
682
$STATS_IN_ALB_LIST = false;
683
$cpg_show_private_album = ($CONFIG['allow_private_albums'])?($CONFIG['show_private']):(true);
684
 
685
get_cat_list($breadcrumb, $cat_data, $statistics);
686
 
687
pageheader($BREADCRUMB_TEXT ? $BREADCRUMB_TEXT : $lang_index_php['welcome']);
688
 
689
$elements = preg_split("|/|", $CONFIG['main_page_layout'], -1, PREG_SPLIT_NO_EMPTY);
690
foreach ($elements as $element) {
691
    if (preg_match("/(\w+),*(\d+)*/", $element, $matches)) switch ($matches[1]) {
692
            case 'breadcrumb':
693
                // Added breadcrumb as a separate listable block from config
694
                if (($breadcrumb != '' || count($cat_data) > 0) && $cat !=0 ) theme_display_breadcrumb($breadcrumb, $cat_data);
695
                break;
696
 
697
            case 'catlist':
698
                if ($breadcrumb != '' || count($cat_data) > 0) theme_display_cat_list($breadcrumb, $cat_data, $statistics);
699
                if (isset($cat) && $cat == USER_GAL_CAT) list_users();
700
                flush();
701
                break;
702
 
703
            case 'alblist':
704
                list_albums();
705
                flush();
706
                break;
707
 
708
            case 'random':
709
                display_thumbnails('random', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
710
                flush();
711
                break;
712
 
713
            case 'lastup':
714
                display_thumbnails('lastup', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
715
                flush();
716
                break;
717
            case 'lastalb':
718
                display_thumbnails('lastalb', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
719
                break;
720
 
721
            case 'topn':
722
                display_thumbnails('topn', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
723
                flush();
724
                break;
725
 
726
            case 'toprated':
727
                display_thumbnails('toprated', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
728
                flush();
729
                break;
730
 
731
            case 'lastcom':
732
                display_thumbnails('lastcom', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
733
                flush();
734
                break;
735
 
736
            case 'lasthits':
737
                display_thumbnails('lasthits', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
738
                flush();
739
                break;
740
 
741
            case 'anycontent':
742
                if ($cat == 0) {
743
                    include('anycontent.php');
744
                }
745
                flush();
746
                break;
747
        }
748
    }
749
 
750
    pagefooter();
751
    ob_end_flush();
752
    // Speed-up the random image query by 'keying' the image table
753
    if (time() - $CONFIG['randpos_interval'] > 86400) {
754
        $result = db_query("SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE 1");
755
        $nbEnr = mysql_fetch_array($result);
756
        mysql_free_result($result);
757
        $pic_count = $nbEnr[0];
758
        $granularity = floor($pic_count / RANDPOS_MAX_PIC);
759
        $result = db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET randpos = ROUND(RAND()*$granularity) WHERE 1");
760
        $result = db_query("UPDATE {$CONFIG['TABLE_CONFIG']} SET value = '" . time() . "' WHERE name = 'randpos_interval'");
761
    }
762
 
763
    ?>