Menu

[r8659]: / trunk / cpg1.5.x / index.php  Maximize  Restore  History

Download this file

1213 lines (1037 with data), 55.5 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2014 Coppermine Dev Team
v1.0 originally written by Gregory Demar
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3
as published by the Free Software Foundation.
********************************************
Coppermine version: 1.5.27
$HeadURL$
$Revision$
**********************************************/
/**
* Unless this is true most things wont work - protection against direct execution of inc files
*/
define('IN_COPPERMINE', true);
define('INDEX_PHP', true);
define('RESTRICTED_PRIV', true);
require('include/init.inc.php');
// garbage collection: when the admin is logged in, old messages that failed to display for whatever reason are being removed to keep the temp_messages table clean
if (GALLERY_ADMIN_MODE) {
cpgCleanTempMessage();
}
/**
* Clean up GPC and other Globals here
*/
if ($superCage->get->keyExists('page')) {
$page = $superCage->get->getInt('page');
}
if ($superCage->get->testInt('cat')) {
$cat = $superCage->get->getInt('cat');
}
$tmpFile = ''; // initialize
if ($superCage->get->keyExists('file')) {
/**
* There can be only alphanumerals in a plugin's folder name. There mustn't be any dots or other special
* chars in it.
* The only exception is the hypen (-) and underscore (_)
* Examples for folder names: "myplugin" = OK, "my_plugin" = OK, "my plugin" = BAD, "m&uuml;_plugin" = BAD
* Files the plugin is meant to include can only contain one single dot that separates the actual filename
* from the php-extension
* Same restrictions apply as for the folder name (only alphanumerals, hyphen and underscore)
*/
if ($matched = $superCage->get->getMatched('file', "/^([a-zA-Z0-9_\-]+)(\/{0,1}?)([a-zA-Z0-9_\-]+)$/")) {
$tmpFile = $matched[0];
}
}
if ($tmpFile != 'codebase' && $tmpFile != 'configuration') {
$file = $tmpFile;
} else {
$file = '';
}
if ($file) {
$path = './plugins/'.$file.'.php';
$file = false;
// Don't include the codebase and credits files
if (file_exists($path)) {
// Check if the plugin is installed
$path_parts = pathinfo($tmpFile);
foreach($CPG_PLUGINS as $key => $value) {
if ($value->fullpath == './plugins/'.$path_parts['dirname']) {
// Include the code from the plugin
include_once($path);
$file = true;
break;
}
}
}
} else {
$file = false;
}
if (!$file) {
if (!USER_ID && $CONFIG['allow_unlogged_access'] == 0) {
// Anonymous access to site is not allowed, so need to redirect to login page
// First try to set cookie so login page doesn't show 'cookie_warning' even when no problem
$data = base64_encode(serialize($USER));
if (CPG_COOKIES_ALLOWED) {
setcookie($CONFIG['cookie_name'].'_data', $data, time() + (CPG_DAY*30), $CONFIG['cookie_path']);
}
// Now redirect to login page
$redirect = 'login.php';
header("Location: $redirect");
exit();
}
if ($CONFIG['enable_smilies']) {
include("include/smilies.inc.php");
}
}
/**
* Local functions definition
*/
/**
* html_albummenu2()
*
* This function draws the links for moderator menu of Albums
*
* @param integer $id ID of the album for which the links are being drawn
* @return string The evaluated template block with links
**/
function html_albummenu2($id)
{
global $lang_album_admin_menu;
/**
* This template variable can be defined in theme.php of respective theme.
* This is done here for simplicity.
*/
$template_album_moderator_menu = <<<EOT
<div class="buttonlist align_right">
<ul>
<li>
<a href="editpics.php?album={ALBUM_ID}"><span class="last">{EDIT_PICS}</span></a>
</li>
</ul>
</div>
<div class="clearer"></div>
EOT;
static $template = '';
if ($template == '') {
$params = array(
'{EDIT_PICS}' => cpg_fetch_icon('edit', 1) . $lang_album_admin_menu['edit_pics'],
);
$template = template_eval($template_album_moderator_menu, $params);
}
$params = array(
'{ALBUM_ID}' => $id,
);
return template_eval($template, $params);
}
/**
* html_albummenu()
*
* This function draws the links for admin menu of Albums
*
* @param integer $id ID of the album for which the links are being drawn
* @return string The evaluated template block with links
**/
function html_albummenu($id)
{
global $template_album_admin_menu, $lang_album_admin_menu;
static $template = '';
if ($template == '') {
list($timestamp, $form_token) = getFormToken();
$params = array(
'{CONFIRM_DELETE}' => $lang_album_admin_menu['confirm_delete'],
'{DELETE}' => cpg_fetch_icon('delete', 1) . $lang_album_admin_menu['delete'],
'{MODIFY}' => cpg_fetch_icon('modifyalb', 1) . $lang_album_admin_menu['modify'],
'{EDIT_PICS}' => cpg_fetch_icon('edit', 1) . $lang_album_admin_menu['edit_pics'],
'{FORM_TOKEN}' => $form_token,
'{TIMESTAMP}' => $timestamp
);
$template = template_eval($template_album_admin_menu, $params);
}
$params = array(
'{ALBUM_ID}' => $id,
);
return template_eval($template, $params);
}
/**
* html_albummenu3()
*
* This function draws the links for admin menu of Albums when pics can't be edited
*
* @param integer $id ID of the album for which the links are being drawn
* @return string The evaluated template block with links
**/
function html_albummenu3($id)
{
global $lang_album_admin_menu;
/**
* This template variable can be defined in theme.php of respective theme.
* This is done here for simplicity.
*/
$template_album_admin_no_pic_edit_menu = <<<EOT
<div class="buttonlist align_right">
<ul>
<li>
<a href="delete.php?id={ALBUM_ID}&amp;what=album&amp;form_token={FORM_TOKEN}&amp;timestamp={TIMESTAMP}" onclick="return confirm('{CONFIRM_DELETE}');"><span>{DELETE}</span></a>
</li>
<li>
<a href="modifyalb.php?album={ALBUM_ID}"><span>{MODIFY}</span></a>
</li>
</ul>
</div>
<div class="clearer"></div>
EOT;
static $template = '';
if ($template == '') {
list($timestamp, $form_token) = getFormToken();
$params = array(
'{CONFIRM_DELETE}' => $lang_album_admin_menu['confirm_delete'],
'{DELETE}' => cpg_fetch_icon('delete', 1) . $lang_album_admin_menu['delete'],
'{MODIFY}' => cpg_fetch_icon('modifyalb', 1) . $lang_album_admin_menu['modify'],
'{FORM_TOKEN}' => $form_token,
'{TIMESTAMP}' => $timestamp
);
$template = template_eval($template_album_admin_no_pic_edit_menu, $params);
}
$params = array(
'{ALBUM_ID}' => $id,
);
return template_eval($template, $params);
}
/**
* get_subcat_data()
*
* Get the data about the sub categories which are going to be shown on the index page, this function is called recursively
*
* @param integer $parent Parent Category
* @param array $cat_data
* @return void
**/
function get_subcat_data(&$cat_data)
{
global $CONFIG, $HIDE_USER_CAT, $cpg_show_private_album;
global $lft, $rgt, $RESTRICTEDWHERE, $CURRENT_CAT_DEPTH, $FORBIDDEN_SET_DATA, $PAGE;
$indent = "</td><td><img src=\"images/spacer.gif\" width=\"20\" height=\"1\" border=\"0\" alt=\"\" /></td><td>";
// TODO: support private album icon data
// just ignore the restriction and let the display code handle things
// there can be no subcategories in user galleries, so don't even bother
if ($CURRENT_CAT_DEPTH == -1) {
return false;
}
function cpg_get_last_visible_cid($categories, $lft) {
global $CONFIG, $CURRENT_CAT_DEPTH;
static $lft_cid_map = array();
if (array_key_exists($lft, $lft_cid_map)) {
return $lft_cid_map[$lft];
}
foreach ($categories as $cid => $cat) {
if ($cat['details']['level'] == $CURRENT_CAT_DEPTH + $CONFIG['subcat_level'] && $lft > $cat['details']['lft'] && $lft < $cat['details']['rgt']) {
$lft_cid_map[$lft] = $cid;
return $cid;
}
}
}
$categories = array();
$forbidden_set = (!$CONFIG['show_private'] && $FORBIDDEN_SET_DATA) ? "AND r.aid NOT IN (" . implode(', ', $FORBIDDEN_SET_DATA) . ")" : "";
$lft_rgt = $rgt ? "AND lft BETWEEN $lft AND $rgt" : "";
//TODO: optimize this for when first level album thumbs are disabled
// all we need then is a count
// collect info about all normal categories
// restrict to 'subcat_level' categories deeper than current depth
$sql = "SELECT cid, lft, rgt, name, description, thumb, depth AS level, '0' AS alb_count
FROM {$CONFIG['TABLE_CATEGORIES']}
WHERE depth BETWEEN $CURRENT_CAT_DEPTH + 1 AND $CURRENT_CAT_DEPTH + {$CONFIG['subcat_level']}
$lft_rgt
ORDER BY lft";
$result = cpg_db_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$categories[$row['cid']]['details'] = $row;
if ($row['cid'] == USER_GAL_CAT) {
// collect stats for albums in the user galleries category
// all we need here is the total number of albums and pictures
$sql = "SELECT COUNT(DISTINCT(p.aid)) AS alb_count, COUNT(*) AS pic_count
FROM {$CONFIG['TABLE_ALBUMS']} AS r
INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = r.aid
WHERE r.category > " . FIRST_USER_CAT . "
AND approved = 'YES'
$forbidden_set";
$result2 = cpg_db_query($sql);
$row2 = mysql_fetch_assoc($result2);
mysql_free_result($result2);
$categories[$row['cid']]['details']['alb_count'] = $row2['alb_count'];
$categories[$row['cid']]['subalbums'][0]['pic_count'] = $row2['pic_count'];
}
} // while
mysql_free_result($result);
// collect album info and album counts
$sql = "SELECT aid, title, r.description, keyword, alb_hits, category, visibility, r.thumb, r.owner, depth AS level, lft, '0' AS pic_count
FROM {$CONFIG['TABLE_CATEGORIES']} AS c
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.category = c.cid
WHERE c.depth >= $CURRENT_CAT_DEPTH + 1
$forbidden_set
$lft_rgt
ORDER BY r.pos, r.aid";
$result = cpg_db_query($sql);
while ($row = mysql_fetch_assoc($result)) {
if ($row['level'] > $CURRENT_CAT_DEPTH + $CONFIG['subcat_level']) {
// add album count for invisible sub-categories to last visible category
$categories[cpg_get_last_visible_cid($categories, $row['lft'])]['details']['alb_count']++;
} else {
$categories[$row['category']]['subalbums'][$row['aid']] = $row;
$categories[$row['category']]['details']['alb_count']++;
}
}
mysql_free_result($result);
// album stats for regular albums
$sql = "SELECT c.cid, r.aid, COUNT(pid) AS pic_count, MAX(pid) AS last_pid, MAX(ctime) AS last_upload, depth AS level, lft
FROM {$CONFIG['TABLE_CATEGORIES']} AS c
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.category = c.cid
INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = r.aid
WHERE c.depth >= $CURRENT_CAT_DEPTH + 1
AND approved = 'YES'
$forbidden_set
GROUP BY r.aid
ORDER BY NULL";
$result = cpg_db_query($sql);
while ($row = mysql_fetch_assoc($result)) {
if ($row['level'] > $CURRENT_CAT_DEPTH + $CONFIG['subcat_level']) {
// add picture count for invisible sub-categories to last visible category
$categories[cpg_get_last_visible_cid($categories, $row['lft'])]['subalbums'][$row['aid']]['pic_count'] += $row['pic_count'];
} else {
$categories[$row['cid']]['subalbums'][$row['aid']]['pic_count'] = $row['pic_count'];
$categories[$row['cid']]['subalbums'][$row['aid']]['last_pid'] = $row['last_pid'];
$categories[$row['cid']]['subalbums'][$row['aid']]['last_upload'] = $row['last_upload'];
}
}
mysql_free_result($result);
foreach ($categories as $cid => $cat) {
$level = $cat['details']['level'] - $CURRENT_CAT_DEPTH;
if ($level == 0) {
continue;
}
$album_count = $cat['details']['alb_count'];
$pic_count = 0;
if (!empty($cat['subalbums'])) {
foreach ($cat['subalbums'] as $alb) {
$pic_count += $alb['pic_count'];
}
}
if (!empty($cat['subalbums'])) {
$cat['subalbums'] = array_slice_preserve_keys($cat['subalbums'], 0, $CONFIG['albums_per_page'], true);
}
$cat['details']['description'] = preg_replace("/<br.*?>[\r\n]*/i", '<br />', bb_decode($cat['details']['description']));
if ($cat['details']['thumb'] > 0) {
$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE pid = {$cat['details']['thumb']} $FORBIDDEN_SET";
$result = cpg_db_query($sql);
if (mysql_num_rows($result)) {
$picture = mysql_fetch_assoc($result);
mysql_free_result($result);
$pic_url = get_pic_url($picture, 'thumb');
if (!is_image($picture['filename'])) {
$image_info = getimagesize(urldecode($pic_url));
$picture['pwidth'] = $image_info[0];
$picture['pheight'] = $image_info[1];
}
$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
$user_thumb = "<img src=\"" . $pic_url . "\" class=\"image thumbnail\" {$image_size['geom']} border=\"0\" alt=\"\" />";
$user_thumb = "<a href=\"index.php?cat={$cid}\">" . $user_thumb . "</a>";
} else {
$user_thumb = "";
}
} else {
$user_thumb = "";
}
$link = "<a href=\"index.php?cat={$cid}\">{$cat['details']['name']}</a>";
$user_thumb = str_repeat($indent, $level-1) . $user_thumb;
if ($cid == USER_GAL_CAT && $pic_count == 0) {
$HIDE_USER_CAT = 1;
} elseif ($pic_count == 0 && $album_count == 0) {
$user_thumb = str_repeat($indent, $level-1);
$cat_data[] = array($link, $cat['details']['description'], 'cat_thumb' => $user_thumb);
} else {
// Check if you need to show first level album thumbnails
if ($CONFIG['first_level'] && $cid != USER_GAL_CAT && $level <= $CONFIG['subcat_level']) {
$cat_albums = list_cat_albums($cid, $cat);
} else {
$cat_albums = '';
}
$cat_data[] = array($link, $cat['details']['description'], $album_count, $pic_count, 'cat_albums' => $cat_albums, 'cat_thumb' => $user_thumb);
}
} // foreach categories
} // function get_subcat_data
/**
* get_cat_list()
*
* List all categories
*
* @param string $breadcrumb
* @param array $cat_data
* @param string $statistics
* @return void
**/
function get_cat_list(&$breadcrumb, &$cat_data, &$statistics)
{
global $CONFIG, $BREADCRUMB_TEXT, $STATS_IN_ALB_LIST, $FORBIDDEN_SET;
global $HIDE_USER_CAT, $cpg_show_private_album;
global $cat;
global $lang_list_categories;
// Build the breadcrumb
breadcrumb($cat, $breadcrumb, $BREADCRUMB_TEXT);
// Build the category list
$cat_data = array();
get_subcat_data($cat_data);
$album_filter = '';
$pic_filter = '';
$cat = (int) $cat;
if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
$album_filter = ' ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
$pic_filter = $FORBIDDEN_SET;
}
// Gather gallery statistics - start
if ($CONFIG['display_stats_on_index'] != 0) {
if ($cat == 0) {
$result = cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_ALBUMS']} AS a WHERE 1 " . $album_filter);
$nbEnr = mysql_fetch_row($result);
$album_count = $nbEnr[0];
mysql_free_result($result);
$sql = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']}";
if ($pic_filter) {
$sql .= " AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE approved = 'YES' $pic_filter";
} else {
$sql .= " WHERE approved = 'YES'";
}
$result = cpg_db_query($sql);
$nbEnr = mysql_fetch_row($result);
$picture_count = $nbEnr[0];
mysql_free_result($result);
$sql = "SELECT COUNT(*) FROM {$CONFIG['TABLE_COMMENTS']}";
if ($pic_filter) {
$sql .= " AS c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.pid = c.pid INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE 1 $pic_filter";
}
if ($CONFIG['comment_approval']) {
if ($pic_filter) {
$sql .= " AND approval = 'YES'";
} else {
$sql .= " WHERE approval = 'YES'";
}
}
$result = cpg_db_query($sql);
$nbEnr = mysql_fetch_row($result);
$comment_count = $nbEnr[0];
mysql_free_result($result);
$sql = "SELECT COUNT(*) FROM {$CONFIG['TABLE_CATEGORIES']}";
$result = cpg_db_query($sql);
$nbEnr = mysql_fetch_row($result);
$cat_count = $nbEnr[0] - $HIDE_USER_CAT;
mysql_free_result($result);
$sql = "SELECT SUM(hits) FROM {$CONFIG['TABLE_PICTURES']}";
if ($pic_filter) {
$sql .= " AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE approved = 'YES' $pic_filter";
} else {
$sql .= " WHERE approved = 'YES'";
}
$result = cpg_db_query($sql);
$nbEnr = mysql_fetch_row($result);
$hit_count = (int)$nbEnr[0];
mysql_free_result($result);
if (count($cat_data)) {
$statistics = strtr($lang_list_categories['stat1'], array(
'[pictures]' => '<strong>' . cpg_float2decimal($picture_count) . '</strong>',
'[albums]' => '<strong>' . cpg_float2decimal($album_count) . '</strong>',
'[cat]' => '<strong>' . cpg_float2decimal($cat_count) . '</strong>',
'[comments]' => '<strong>' . cpg_float2decimal($comment_count) . '</strong>',
'[views]' => '<strong>' . cpg_float2decimal($hit_count) . '</strong>',
));
} else {
$STATS_IN_ALB_LIST = true;
$statistics = strtr($lang_list_categories['stat3'], array(
'[pictures]' => '<strong>' . cpg_float2decimal($picture_count) . '</strong>',
'[albums]' => '<strong>' . cpg_float2decimal($album_count) . '</strong>',
'[comments]' => '<strong>' . cpg_float2decimal($comment_count) . '</strong>',
'[views]' => '<strong>' . cpg_float2decimal($hit_count) . '</strong>',
));
}
} else {
$statistics = '';
}
} else { // Gather gallery statistics - end
$statistics = '';
}
}
/**
* list_users()
*
* Get a list of users galleries
*/
function list_users()
{
global $CONFIG, $PAGE;
global $lang_list_users, $template_user_list_info_box, $cpg_udb;
$user_count = 0;
$rowset = $cpg_udb->list_users_query($user_count);
if (!$rowset) {
msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
return;
}
$user_per_page = $CONFIG['thumbcols'] * $CONFIG['thumbrows'];
$totalPages = ceil($user_count / $user_per_page);
$user_list = array();
foreach ($rowset as $user) {
$cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $user['user_id']);
$user_thumb = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
$user_pic_count = $user['pic_count'];
$user_thumb_pid = $user['gallery_pid'] ? $user['gallery_pid'] : $user['thumb_pid'];
$user_album_count = $user['alb_count'];
if ($user_pic_count) {
$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='$user_thumb_pid' AND approved='YES'";
$result = cpg_db_query($sql);
if (mysql_num_rows($result)) {
$picture = mysql_fetch_assoc($result);
mysql_free_result($result);
$pic_url = get_pic_url($picture, 'thumb');
if (!is_image($picture['filename'])) {
$image_info = cpg_getimagesize(urldecode($pic_url));
$picture['pwidth'] = $image_info[0];
$picture['pheight'] = $image_info[1];
}
//thumb cropping
//$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
if (array_key_exists('system_icon', $picture) && ($picture['system_icon'] == true)) {
$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
} else {
$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
}
$user_thumb = "<img src=\"" . $pic_url . "\" class=\"image thumbnail\" {$image_size['geom']} border=\"0\" alt=\"\" />";
}
}
$albums_txt = sprintf($lang_list_users['n_albums'], $user_album_count);
$pictures_txt = sprintf($lang_list_users['n_pics'], $user_pic_count);
$params = CPGPluginAPI::filter('user_caption_params', array(
'{USER_NAME}' => $user['user_name'],
'{USER_ID}' => $user['user_id'],
'{ALBUMS}' => $albums_txt,
'{PICTURES}' => $pictures_txt,
));
$caption = template_eval($template_user_list_info_box, $params);
$user_list[] = array(
'cat' => FIRST_USER_CAT + $user['user_id'],
'image' => $user_thumb,
'caption' => $caption,
);
}
theme_display_thumbnails($user_list, $user_count, '', '', 1, $PAGE, $totalPages, false, true, 'user');
}
// End list_users()
/**
* list_albums()
*
* Get a list of albums
*/
function list_albums()
{
global $CONFIG, $USER_DATA, $PAGE, $lang_date, $FORBIDDEN_SET, $FORBIDDEN_SET_DATA;
global $cat;
global $lang_list_albums, $cpg_show_private_album;
$alb_per_page = $CONFIG['albums_per_page'];
$album_filter = '';
//unused code {SaWey}
/*
$maxTab = $CONFIG['max_tabs'];
$pic_filter = '';
$pic_subquery = '';
*/
if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
$album_filter = ' ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
//unused code {SaWey}
//$pic_filter = ' ' . $FORBIDDEN_SET;
}
if (USER_ADMIN_MODE && $cat == (USER_ID + FIRST_USER_CAT)) {
$result = cpg_db_query("SELECT count(aid) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE owner = '" . $USER_DATA['user_id'] . "' " . $album_filter);
} else {
$result = cpg_db_query("SELECT count(aid) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '$cat' " . $album_filter);
}
$nbEnr = mysql_fetch_row($result);
$nbAlb = $nbEnr[0];
mysql_free_result($result);
if (!$nbAlb) {
return;
}
$totalPages = ceil($nbAlb / $alb_per_page);
if ($PAGE > $totalPages) {
$PAGE = 1;
}
$lower_limit = ($PAGE-1) * $alb_per_page;
$upper_limit = min($nbAlb, $PAGE * $alb_per_page);
$limit = "LIMIT " . $lower_limit . "," . ($upper_limit - $lower_limit);
if (USER_ADMIN_MODE && $cat == (USER_ID + FIRST_USER_CAT)) {
$sql = 'SELECT a.aid, a.title, a.description, a.thumb, a.keyword, category, visibility, filepath, filename, url_prefix, pwidth, pheight, a.owner FROM ' . $CONFIG['TABLE_ALBUMS'] . ' AS a LEFT JOIN ' . $CONFIG['TABLE_PICTURES'] . ' AS p ON a.thumb=p.pid WHERE a.owner=' . $USER_DATA['user_id'] . $album_filter . ' ORDER BY a.category DESC , a.pos ' . $limit;
$alb_thumbs_q = cpg_db_query($sql);
$alb_thumbs = cpg_db_fetch_rowset($alb_thumbs_q);
mysql_free_result($alb_thumbs_q);
//query for the category names
$cat_name_sql = "SELECT CONCAT(a.title, '" . $lang_list_albums['from_category'] . "<i>', c.name, '</i>') AS cat_name FROM " . $CONFIG['TABLE_ALBUMS'] . " AS a LEFT JOIN " . $CONFIG['TABLE_CATEGORIES'] . " AS c ON a.category=c.cid WHERE a.owner=" . $USER_DATA['user_id'] . " ORDER BY a.category DESC , a.pos " . $limit;
$cat_name_q = cpg_db_query($cat_name_sql);
$cat_names = cpg_db_fetch_rowset($cat_name_q);
mysql_free_result($cat_name_q);
//replace names in $alb_thumbs array
foreach ($alb_thumbs as $key => $value) {
if ($cat_names[$key]['cat_name'] != '') {
$alb_thumbs[$key]['title'] = $cat_names[$key]['cat_name'];
}
$current_albums[] = $value['aid'];
}
//This query will fetch album stats and keywords for the albums
$sql = "SELECT a.aid, count( p.pid ) AS pic_count, max( p.pid ) AS last_pid, max( p.ctime ) AS last_upload, a.keyword, a.alb_hits"
." FROM {$CONFIG['TABLE_ALBUMS']} AS a "
." LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.aid = p.aid AND p.approved = 'YES' "
." WHERE a.owner = {$USER_DATA['user_id']} $album_filter AND a.aid IN (".implode(', ', $current_albums).") GROUP BY a.aid $limit";
$alb_stats_q = cpg_db_query($sql);
$alb_stats = cpg_db_fetch_rowset($alb_stats_q);
mysql_free_result($alb_stats_q);
} else {
$sort_array = array(
'ta' => "a.title ASC, a.aid ASC",
'td' => "a.title DESC, a.aid DESC",
'da' => "a.aid ASC",
'dd' => "a.aid DESC",
'pa' => "a.pos ASC, a.aid ASC",
'pd' => "a.pos DESC, a.aid DESC",
);
//$sort_code = isset($USER['sort'])? $USER['sort'] : $CONFIG['album_sort_order'];
//$sort_order = isset($sort_array[$sort_code]) ? $sort_array[$sort_code] : $sort_array[$CONFIG['album_sort_order']];
$sort_order = $sort_array[$CONFIG['album_sort_order']];
$sql = "SELECT a.aid, a.title, a.description, a.thumb, a.keyword, category, visibility, filepath, filename, url_prefix, pwidth, pheight, a.owner "
. " FROM {$CONFIG['TABLE_ALBUMS']} AS a "
. " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.thumb=p.pid "
. " WHERE a.category = $cat $album_filter "
. " ORDER BY $sort_order $limit";
$alb_thumbs_q = cpg_db_query($sql);
$alb_thumbs = cpg_db_fetch_rowset($alb_thumbs_q);
mysql_free_result($alb_thumbs_q);
//This query will fetch album stats and keywords for the albums
$sql = "SELECT a.aid, count( p.pid ) AS pic_count, max( p.pid ) AS last_pid, max( p.ctime ) AS last_upload, a.keyword, a.alb_hits"
. " FROM {$CONFIG['TABLE_ALBUMS']} AS a "
. " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.aid = p.aid AND p.approved = 'YES' "
. " WHERE a.category = $cat $album_filter GROUP BY a.aid "
. " ORDER BY $sort_order $limit";
$alb_stats_q = cpg_db_query($sql);
$alb_stats = cpg_db_fetch_rowset($alb_stats_q);
mysql_free_result($alb_stats_q);
}
$disp_album_count = count($alb_thumbs);
$approved = 'AND approved=\'YES\'';
$forbidden_set_string = ((count($FORBIDDEN_SET_DATA) > 0) ? ' AND aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')' : '');
$last_pids = array();
$last_pid_data = array();
foreach ($alb_stats as $key => $value) {
$cross_ref[$value['aid']] = &$alb_stats[$key];
if ($CONFIG['link_pic_count'] == 1 || $value['pic_count'] == 0) {
if (!empty($value['keyword'])) {
$keyword = ($value['keyword'] ? "AND (keywords like '%".addslashes($value['keyword'])."%' $forbidden_set_string )" : '');
$query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload "
." FROM {$CONFIG['TABLE_PICTURES']} "
." WHERE ((aid != '{$value['aid']}' $forbidden_set_string) $keyword) $approved";
$result = cpg_db_query($query);
$link_stat = mysql_fetch_assoc($result);
mysql_free_result($result);
$alb_stats[$key]['link_pic_count'] = $link_stat['link_pic_count'];
$alb_stats[$key]['last_pid'] = ($alb_stats[$key]['last_pid'] > $link_stat['link_last_pid']) ? $alb_stats[$key]['last_pid'] : $link_stat['link_last_pid'];
if ($CONFIG['link_last_upload'] && $link_stat['link_pic_count'] > 0) {
$alb_stats[$key]['last_upload'] = ($alb_stats[$key]['last_upload'] > $link_stat['link_last_upload']) ? $alb_stats[$key]['last_upload'] : $link_stat['link_last_upload'];
}
}
}
if ($alb_stats[$key]['last_pid']) {
$last_pids[] = $alb_stats[$key]['last_pid'];
}
}
if (count($last_pids)) {
$result = cpg_db_query("SELECT pid, filepath, filename, url_prefix, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} WHERE pid IN (".implode(',', $last_pids).")");
while ($row = mysql_fetch_assoc($result)) {
$last_pid_data[$row['pid']] = $row;
unset($last_pid_data[$row['pid']]['pid']);
}
mysql_free_result($result);
}
unset($last_pids);
for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
$alb_thumb = &$alb_thumbs[$alb_idx];
$aid = $alb_thumb['aid'];
if (isset($cross_ref[$aid])) {
$alb_stat = $cross_ref[$aid];
$count = $alb_stat['pic_count'];
$alb_hits = $alb_stat['alb_hits'];
} else {
$alb_stat = array();
$count = 0;
$alb_hits = 0;
}
// Inserts a thumbnail if the album contains 1 or more images
//unused code {SaWey}
//$visibility = $alb_thumb['visibility'];
$keyword = ($alb_thumb['keyword'] ? "OR (keywords like '%".addslashes($alb_thumb['keyword'])."%' $forbidden_set_string )" : '');
if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
if ($count > 0 || !empty($alb_stats[$alb_idx]['link_pic_count'])) {
if (!empty($alb_thumb['filename'])) {
$picture = &$alb_thumb;
} elseif ($alb_thumb['thumb'] < 0) {
$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight "
. "FROM {$CONFIG['TABLE_PICTURES']} "
. "WHERE ((aid = '{$alb_thumb['aid']}' $forbidden_set_string) $keyword) $approved "
. "ORDER BY RAND() LIMIT 0,1";
$result = cpg_db_query($sql);
$picture = mysql_fetch_assoc($result);
mysql_free_result($result);
} else {
$picture = $last_pid_data[$alb_stat['last_pid']];
}
$pic_url = get_pic_url($picture, 'thumb');
if (!is_image($picture['filename'])) {
$image_info = cpg_getimagesize(urldecode($pic_url));
$picture['pwidth'] = $image_info[0];
$picture['pheight'] = $image_info[1];
}
//thumb cropping
//$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
if (array_key_exists('system_icon', $picture) && ($picture['system_icon'] == true)) {
$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
} else {
$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
}
$alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image thumbnail\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
} else { // Inserts an empty thumbnail if the album contains 0 images
// $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
$cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $alb_thumb['category']);
$alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
}
} elseif ($CONFIG['show_private']) {
// $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
$cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $alb_thumb['category']);
$alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_privatepic_data['thumb'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
}
// Prepare everything
if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
$link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
$last_upload_date = ($count || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? localised_date($alb_stat['last_upload'], $lang_date['lastup']) : '';
$alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
$alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
$alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
$alb_list[$alb_idx]['pic_count'] = $count;
$alb_list[$alb_idx]['last_upl'] = $last_upload_date;
$alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
$alb_list[$alb_idx]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
if ($CONFIG['link_last_upload']) {
$alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "") . (($count || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
} else {
$alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
}
$alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat, $alb_thumb['owner']);
} elseif ($CONFIG['show_private']) { // uncomment this else block to show private album description
$link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
$last_upload_date = ($count || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? localised_date($alb_stat['last_upload'], $lang_date['lastup']) : '';
$alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
$alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
$alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
$alb_list[$alb_idx]['pic_count'] = $count;
$alb_list[$alb_idx]['last_upl'] = $last_upload_date;
$alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
$alb_list[$alb_idx]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
if ($CONFIG['link_last_upload']) {
$alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "") . (($count || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
} else {
$alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
}
$alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat, $alb_thumb['owner']);
}
}
theme_display_album_list($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
}
/**
* album_adm_menu()
*
* This has been added to keep the list_albums() function clean.
*
* @param integer $aid Album id
* @param integer $cat Category id
*
* @return html_albummenu($aid) Administration menu
*/
function album_adm_menu($aid, $cat, $owner)
{
global $CONFIG, $USER_DATA, $lang_album_admin_menu;
if (GALLERY_ADMIN_MODE) {
return html_albummenu($aid);
}
static $public_album_uploads = null;
if ($public_album_uploads === null) {
$public_album_uploads = array();
$result = cpg_db_query("SELECT a.aid FROM {$CONFIG['TABLE_ALBUMS']} AS a INNER JOIN {$CONFIG['TABLE_PICTURES']} as p ON p.aid = a.aid WHERE uploads = 'YES' AND category < ".FIRST_USER_CAT." AND (visibility = '0' OR visibility IN ".USER_GROUP_SET." OR alb_password != '') AND owner_id = ".USER_ID);
while ($row = mysql_fetch_assoc($result)) {
$public_album_uploads[] = $row['aid'];
}
mysql_free_result($result);
}
if (USER_ADMIN_MODE) {
if ($cat == USER_ID + FIRST_USER_CAT) {
return html_albummenu($aid);
}
if ($owner == USER_ID) {
if ($CONFIG['allow_user_edit_after_cat_close'] == 0) {
$result = cpg_db_query("SELECT DISTINCT alb.category FROM {$CONFIG['TABLE_ALBUMS']} AS alb INNER JOIN {$CONFIG['TABLE_CATMAP']} AS catm ON alb.category=catm.cid WHERE alb.owner = '" . $USER_DATA['user_id'] . "' AND alb.aid='$aid' AND catm.group_id IN (" . implode(', ', $USER_DATA['groups']) . ")");
$allowed_albums = cpg_db_fetch_rowset($result);
if (!$allowed_albums || ($allowed_albums[0]['category'] == '')) {
if ($CONFIG['users_can_edit_pics'] && in_array($aid, $public_album_uploads)) {
return html_albummenu2($aid);
} else {
return "<strong>" . $lang_album_admin_menu['cat_locked'] . "</strong>";
}
}
}
if (!$CONFIG['users_can_edit_pics']) {
return html_albummenu3($aid);
} else {
return html_albummenu($aid);
}
}
}
if (MODERATOR_MODE && in_array($aid, $USER_DATA['allowed_albums'])) {
return html_albummenu2($aid);
}
if (USER_CAN_UPLOAD_PICTURES && $CONFIG['users_can_edit_pics'] && in_array($aid, $public_album_uploads)) {
return html_albummenu2($aid);
}
return '';
} // function album_adm_menu
/**
* list_cat_albums()
*
* This has been added to list the albums in a category, used for showing first level albums, largely a repetition of code elsewhere
* Redone for a cleaner approach
* @param integer $cat Category id for which albums are needed
*/
function list_cat_albums($cat, $catdata)
{
global $CONFIG, $lang_date, $FORBIDDEN_SET_DATA;
global $lang_list_albums;
$PAGE = 1;
if ($cat == 0) {
return '';
}
$cat_owner_id = ($cat > 10000)?(10000 - $cat):(10001);
$cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $cat_owner_id);
$cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $cat_owner_id);
$alb_per_page = $CONFIG['albums_per_page'];
//unused code {SaWey}
/*$maxTab = $CONFIG['max_tabs'];
$album_filter = '';
$pic_filter = '';
if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
$album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
$pic_filter = ' and ' . $FORBIDDEN_SET;
}*/
$nbAlb = $catdata['details']['alb_count'];
if ($nbAlb == 0) {
return;
}
$totalPages = ceil($nbAlb / $alb_per_page);
$alb_list = array();
$approved = ' AND approved=\'YES\'';
$forbidden_set_string = ((count($FORBIDDEN_SET_DATA) > 0) ? ' AND aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')' : '');
$last_pids = array();
$last_pid_data = array();
foreach ($catdata['subalbums'] as $aid => $album) {
if ($CONFIG['link_pic_count'] == 1 || $album['pic_count'] == 0) {
if (!empty($album['keyword'])) {
$keyword = ($album['keyword'] ? "AND (keywords like '%".addslashes($album['keyword'])."%' $forbidden_set_string)" : '');
$query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload "
." FROM {$CONFIG['TABLE_PICTURES']} "
." WHERE ((aid != '$aid' $forbidden_set_string) $keyword) $approved";
$result = cpg_db_query($query);
$link_stat = mysql_fetch_assoc($result);
mysql_free_result($result);
$catdata['subalbums'][$aid]['link_pic_count'] = $link_stat['link_pic_count'];
$catdata['subalbums'][$aid]['last_pid'] = !empty($album['last_pid']) && ($album['last_pid'] > $link_stat['link_last_pid']) ? $album['last_pid'] : $link_stat['link_last_pid'];
if ($CONFIG['link_last_upload'] && $link_stat['link_pic_count'] > 0) {
$catdata['subalbums'][$aid]['last_upload'] = ($album['last_upload'] > $link_stat['link_last_upload']) ? $album['last_upload'] : $link_stat['link_last_upload'];
}
}
}
if ($catdata['subalbums'][$aid]['last_pid']) {
$last_pids[] = $catdata['subalbums'][$aid]['last_pid'];
}
if ($album['thumb'] > 0) {
$last_pids[] = $album['thumb'];
}
}
if (count($last_pids)) {
$result = cpg_db_query("SELECT pid, filepath, filename, url_prefix, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} WHERE pid IN (".implode(',', $last_pids).")");
while ($row = mysql_fetch_assoc($result)) {
$last_pid_data[$row['pid']] = $row;
unset($last_pid_data[$row['pid']]['pid']);
}
mysql_free_result($result);
}
unset($last_pids);
foreach ($catdata['subalbums'] as $aid => $album) {
// Inserts a thumbnail if the album contains 1 or more images
//unused code {SaWey}
//$visibility = $album['visibility'];
$keyword = ($album['keyword'] ? "OR (keywords like '%".addslashes($album['keyword'])."%' $forbidden_set_string)" : '');
if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) { //test for visibility
if ($album['pic_count'] > 0 || !empty($album['link_pic_count'])) {
if (!empty($last_pid_data[$album['thumb']]['filename'])) {
$picture = $last_pid_data[$album['thumb']];
} elseif ($album['thumb'] < 0) {
$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight "
. "FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid = '$aid' $forbidden_set_string) $keyword) $approved "
. "ORDER BY RAND() LIMIT 0,1";
$result = cpg_db_query($sql);
$picture = mysql_fetch_assoc($result);
mysql_free_result($result);
} else {
$picture = $last_pid_data[$album['last_pid']];
}
$pic_url = get_pic_url($picture, 'thumb');
if (!is_image($picture['filename'])) {
$image_info = cpg_getimagesize(urldecode($pic_url));
$picture['pwidth'] = $image_info[0];
$picture['pheight'] = $image_info[1];
}
//thumb cropping
if (array_key_exists('system_icon', $picture) && ($picture['system_icon'] == true)) {
$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
} else {
$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
}
$alb_list[$aid]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image thumbnail\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
} else { // Inserts an empty thumbnail if the album contains 0 images
// $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
$alb_list[$aid]['thumb_pic'] = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
}
} elseif ($CONFIG['show_private']) {
// $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
$alb_list[$aid]['thumb_pic'] = '<img src="' . $cpg_privatepic_data['thumb'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image thumbnail" border="0" alt="" />';
}
// Prepare everything
if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
$link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
$last_upload_date = ($album['pic_count'] || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
$alb_list[$aid]['aid'] = $aid;
$alb_list[$aid]['album_title'] = $album['title'];
$alb_list[$aid]['album_desc'] = bb_decode($album['description']);
$alb_list[$aid]['pic_count'] = $album['pic_count'];
$alb_list[$aid]['last_upl'] = $last_upload_date;
$alb_list[$aid]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $album['alb_hits']);
$alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . ($album['pic_count'] ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "");
if ($CONFIG['link_last_upload']) {
$alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "") . (($album['pic_count'] || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
} else {
$alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . ($album['pic_count'] ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "");
}
$alb_list[$aid]['album_adm_menu'] = album_adm_menu($aid, $cat, $album['owner']);
} elseif ($CONFIG['show_private']) { // show private album description
$link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
$last_upload_date = ($album['pic_count'] || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
$alb_list[$aid]['aid'] = $aid;
$alb_list[$aid]['album_title'] = $album['title'];
$alb_list[$aid]['album_desc'] = bb_decode($album['description']);
$alb_list[$aid]['pic_count'] = $album['pic_count'];
$alb_list[$aid]['last_upl'] = $last_upload_date;
$alb_list[$aid]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $album['alb_hits']);
if ($CONFIG['link_last_upload']) {
$alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "") . (($album['pic_count'] || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
} else {
$alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . ($album['pic_count'] ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0) ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "");
}
$alb_list[$aid]['album_adm_menu'] = album_adm_menu($aid, $cat, $album['owner']);
}
}
ob_start();
theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
$cat_albums = ob_get_contents();
ob_end_clean();
return $cat_albums;
} // function list_cat_albums
//
// Main code
//
if (!$file) {
/**
* See if $page has been passed in GET
*/
if (isset($page)) {
$PAGE = max($page, 1);
} else {
$PAGE = 1;
}
// Gather data for categories
$breadcrumb = '';
$cat_data = array();
$statistics = '';
$STATS_IN_ALB_LIST = false;
$cpg_show_private_album = $CONFIG['allow_private_albums'] ? $CONFIG['show_private'] : true;
if (isset($cat)) {
get_meta_album_set($cat);
} else {
get_meta_album_set(0);
}
get_cat_list($breadcrumb, $cat_data, $statistics);
pageheader($BREADCRUMB_TEXT ? $BREADCRUMB_TEXT : $lang_index_php['welcome']);
$elements = explode('/', $CONFIG['main_page_layout']);
$elements = CPGPluginAPI::filter('main_page_layout', $elements);
/**
* Loop through the $elements array to build the page using the parameters
* set in the config
*/
foreach ($elements as $element) {
if (preg_match("/(\w+),*(\d+)*/", $element, $matches)) {
if (!isset($matches[2])) { // added to fix notice about undefined index
$matches[2] = 0;
}
$matches = CPGPluginAPI::filter('plugin_block', $matches);
if (is_array($matches)) {
switch ($matches[1]) {
case 'breadcrumb':
// Added breadcrumb as a separate listable block from config
if (($breadcrumb != '' || count($cat_data) > 0) && $cat != 0) {
theme_display_breadcrumb($breadcrumb, $cat_data);
}
break;
case 'catlist':
if ($breadcrumb != '' || count($cat_data) > 0) {
theme_display_cat_list($breadcrumb, $cat_data, $statistics);
}
if (isset($cat) && $cat == USER_GAL_CAT) {
list_users();
}
break;
case 'alblist':
list_albums();
break;
case 'anycontent':
if ($cat == 0) {
ob_start();
/**
* Any php code or HTML can be put in this file and will be displayed
*/
include('anycontent.php');
$anycontent = CPGPluginAPI::filter('anycontent', ob_get_contents());
ob_end_clean();
echo $anycontent;
}
break;
default:
// all meta albums caught here
display_thumbnails($matches[1], $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
break;
}
}
}
}
pagefooter();
}
?>