-
Notifications
You must be signed in to change notification settings - Fork 2
/
pview.class.php
1683 lines (1601 loc) · 56.1 KB
/
pview.class.php
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
<?php
/*
+---------------------------------------------------------------+
| e107 website system
| http://e107.org
|
| PView Gallery by R.F. Carter
| ronald.fuchs@hhweb.de
+---------------------------------------------------------------+
*/
// Include plugin language file, check first for site's preferred language
if (file_exists(e_PLUGIN . "pviewgallery/languages/" . e_LANGUAGE . ".php")){
include_once(e_PLUGIN."pviewgallery/languages/".e_LANGUAGE.".php");
}
else
{
include_once(e_PLUGIN . "pviewgallery/languages/German.php");
}
// globals!!!!!!!!!!!!!!!
$ImageSort = "name";
$SortOrder ="";
$outStat_Totals = array();
$applImages = array();
class PView {
private $pref = array();
private $userImgCount = array();
function __construct()
{
$sql = e107::getDb();
$tmp = $sql->retrieve('pview_config', 'configName,configValue',"configName !=''", true);
foreach($tmp as $row)
{
$key = $row['configName'];
$this->pref[$key] = $row['configValue'];
}
// get user image counts.
$tmp = $sql->retrieve("pview_image", "imageId,uploaderUserId", "WHERE uploaderUserId !=''", true);
foreach($tmp as $row)
{
$key = $row['uploaderUserId'];
if(!isset($this->userImgCount[$key]))
{
$this->userImgCount[$key] = 0;
}
if ($this -> getPermission("image",$row['imageId'],"View"))
{
$this->userImgCount[$key]++;
}
}
}
function getSortArray() {
// returns array with sortstring as key and Wording as value, used for sorting-select box
$sortArray = array('name'=>LAN_IMAGE_9,'albumId'=>LAN_ADMIN_156,'uploaderUserId'=>LAN_ADMIN_157,'uploadDate'=>LAN_ADMIN_158,'cat'=>LAN_IMAGE_45,'views'=>LAN_ADMIN_159,'commentscount'=>LAN_ADMIN_110,'ratingvalue'=>LAN_IMAGE_3);
return $sortArray;
}
function getUserData($userid) {
// returns user data for nested functions, normally use Shortcodes
global $sql;
$sql->db_Select("user", "user_class,user_name,user_admin,user_email,user_image,user_signature", "WHERE user_id='$userid'", "nowhere");
if ($UserData = $sql -> db_Fetch()) {
return $UserData;
} else {
$UserData = array('user_class' => '255', 'user_name' => LAN_IMAGE_35, 'user_admin' => '0');
return $UserData;
}
}
function getUserclasses() {
// returns a 2D array of all userclasses (userclass_names)
global $sql;
$UserClasses = array();
$sql->db_Select("userclass_classes", "userclass_name, userclass_id","", "nowhere");
while ($UserClass = $sql -> db_Fetch())
{
array_push ($UserClasses, $UserClass);
}
return $UserClasses;
}
function getPView_config($pv_config)
{
// returns preference values
if(isset($this->pref[$pv_config]))
{
return $this->pref[$pv_config];
}
/*
$conf_SQL = new db;
if(!$conf_SQL->db_Select("pview_config", "configValue", "WHERE configName='$pv_config'", "nowhere"))
{
}
list($ConfigValue) = $conf_SQL -> db_Fetch();
return $ConfigValue;*/
}
function getPath() {
// returns the way from rootgallery to destination for all views (used in tablerender call)
$Appl = $this -> getAppl();
global $tp;
if ($Appl[0] == "gallery") {
if ($Appl[1] == "0") {
$out_Path = $tp -> toHTML($this -> getPView_config("pview_name"));
} else {
$out_Path = "<a href='pviewgallery.php'>".$tp -> toHTML($this -> getPView_config("pview_name"))."</a>: ".$tp -> toHTML($this -> getGalleryName());
}
}
if ($Appl[0] == "album") {
$ParentsArray = array();
$AlbumData = $this -> getAlbumData($Appl[1]);
$isParent = $this -> getParentAlbum($Appl[1]);
while ($isParent) {
$AlbumData = $this -> getAlbumData($isParent);
array_push ($ParentsArray,"<a href='pviewgallery.php?album=".$isParent."'>".$tp -> toHTML($AlbumData['name'])."</a>");
$isParent = $this -> getParentAlbum($isParent);
}
if ($AlbumData['galleryId']) {
array_push ($ParentsArray, "<a href='pviewgallery.php?gallery=".$AlbumData['galleryId']."'>".$tp -> toHTML($this -> getGalleryName($AlbumData['galleryId']))."</a>");
}
array_push ($ParentsArray, "<a href='pviewgallery.php'>".$tp -> toHTML($this -> getPView_config("pview_name"))."</a>");
krsort($ParentsArray);
foreach ($ParentsArray as $dataset) {
$out_Path .= $dataset.": ";
}
}
if ($Appl[0] == "image") {
$ParentsArray = array();
$ImageAlbum = $this -> getImageAlbum($Appl[1]);
$AlbumData = $this -> getAlbumData($ImageAlbum);
$isParent = $this -> getParentAlbum($ImageAlbum);
array_push ($ParentsArray,"<a href='pviewgallery.php?album=".$ImageAlbum."'>".$tp -> toHTML($AlbumData['name'])."</a>");
while ($isParent) {
$AlbumData = $this -> getAlbumData($isParent);
array_push ($ParentsArray,"<a href='pviewgallery.php?album=".$isParent."'>".$tp -> toHTML($AlbumData['name'])."</a>");
$isParent = $this -> getParentAlbum($isParent);
}
if ($AlbumData['galleryId']) {
array_push ($ParentsArray, "<a href='pviewgallery.php?gallery=".$AlbumData['galleryId']."'>".$tp -> toHTML($this -> getGalleryName($AlbumData['galleryId']))."</a>");
}
array_push ($ParentsArray, "<a href='pviewgallery.php'>".$tp -> toHTML($this -> getPView_config("pview_name"))."</a>");
krsort($ParentsArray);
foreach ($ParentsArray as $dataset) {
$out_Path .= $dataset.": ";
}
}
if ($Appl[0] == "cat") {
if ($Appl[1] == "list"){
$out_Path .= "<a href='pviewgallery.php'>".$tp -> toHTML($this -> getPView_config("pview_name"))."</a>: ".LAN_ADMIN_151;
} else {
$catData = $this->getCatData($Appl[1]);
$out_Path .= "<a href='pviewgallery.php'>".$tp -> toHTML($this -> getPView_config("pview_name"))."</a>: <a href='pviewgallery.php?cat=list'>".LAN_ADMIN_151."</a>: ".$catData['name'];
}
}
if ($Appl[0] == "user") {
if ($Appl[1] == "list"){
$out_Path .= "<a href='pviewgallery.php'>".$tp -> toHTML($this -> getPView_config("pview_name"))."</a>: ".LAN_ADMIN_153;
} else {
$userData = $this->getUserData($Appl[1]);
$out_Path .= "<a href='pviewgallery.php'>".$tp -> toHTML($this -> getPView_config("pview_name"))."</a>: <a href='pviewgallery.php?user=list'>".LAN_ADMIN_153."</a>: ".$userData['user_name'];
}
}
return $out_Path;
}
function getParentAlbum($albumid) {
// returns parent album Id
$parentAlbum = $this -> getAlbumData($albumid);
return $parentAlbum['parentAlbumId'];
}
function getPermission($object,$objectid,$request) {
// returns true or false, DO NOT EDIT THIS FUNCTION!!!
// $object: gallerie, album, image, config
// $objectid: Id / configName
// $request: Edit, View, CreateAlbum, Upload
global $sql2;
//Admins have ALL rights in admin Mode
if (ADMIN && $this -> getPView_config("admin_Mode")) { return 1;}
//-------------------------------------------------------------------------------------
//objects in deactivated gallerytypes (MAIN or USER) will handled as: NO PERMISSION (also Admins in normal Mode)
if ($object == "gallery" && $objectid == "0" && !$this -> getGalleryActive("0")) { return 0;}
if ($object == "gallery" && $objectid <> "0" && !$this -> getPView_config("member_galleries")) { return 0;}
//usergallery active?
if ($object == "gallery" && $objectid <> "0" && !ADMIN && USERID <> $objectid && !$this -> getGalleryActive($objectid)) { return 0;}
if ($object == "album") {
$sql2->db_Select("pview_album", "*", "WHERE albumId='$objectid'", "nowhere");
$tmp_AlbumData = $sql2 -> db_Fetch();
if ($tmp_AlbumData['galleryId'] == "0" && !$this -> getGalleryActive("0")) { return 0;}
if ($tmp_AlbumData['galleryId'] <> "0" && !$this -> getPView_config("member_galleries")) { return 0;}
//corresponding usergallery active?
if ($tmp_AlbumData['galleryId'] <> "0" && !ADMIN && USERID <> $tmp_AlbumData['galleryId'] && !$this -> getGalleryActive($tmp_AlbumData['galleryId'])) { return 0;}
}
if ($object == "image") {
$sql2->db_Select("pview_image", "*", "WHERE imageId='$objectid'", "nowhere");
$tmp_ImageData = $sql2 -> db_Fetch();
$tmp_ImageData = $tmp_ImageData['albumId'];
$sql2->db_Select("pview_album", "*", "WHERE albumId='$tmp_ImageData'", "nowhere");
$tmp_AlbumData = $sql2 -> db_Fetch();
if ($tmp_AlbumData['galleryId'] == "0" && !$this -> getGalleryActive("0")) { return 0;}
if ($tmp_AlbumData['galleryId'] <> "0" && !$this -> getPView_config("member_galleries")) { return 0;}
//corresponding usergallery active?
if ($tmp_AlbumData['galleryId'] <> "0" && !ADMIN && USERID <> $tmp_AlbumData['galleryId'] && !$this -> getGalleryActive($tmp_AlbumData['galleryId'])) { return 0;}
}
//-------------------------------------------------------------------------------------
//Admins have all other rights
if (ADMIN) { return 1;}
//-------------------------------------------------------------------------------------
//Owners of usergalleryobjects have all other rights
if (USERID <> 0){ //since e107 v7.12 guest has USERID=0
if ($object == "gallery" && USERID == $objectid) { return 1;}
if ($object == "album") {
$sql2->db_Select("pview_album", "*", "WHERE albumId='$objectid'", "nowhere");
$tmp_AlbumData = $sql2 -> db_Fetch();
if (USERID == $tmp_AlbumData['galleryId']) { return 1;}
}
if ($object == "image") {
$sql2->db_Select("pview_image", "*", "WHERE imageId='$objectid'", "nowhere");
$tmp_ImageData = $sql2 -> db_Fetch();
$tmp_ImageData = $tmp_ImageData['albumId'];
$sql2->db_Select("pview_album", "*", "WHERE albumId='$tmp_ImageData'", "nowhere");
$tmp_AlbumData = $sql2 -> db_Fetch();
if (USERID == $tmp_AlbumData['galleryId']) { return 1;}
}
}
//-------------------------------------------------------------------------------------
//Image specials: approved?; album permView, where image is located
if ($object == "image") {
$sql2->db_Select("pview_image", "approved,albumId", "WHERE imageId='$objectid'", "nowhere");
list($approved,$albumId) = $sql2 -> db_Fetch();
//if image not approved: return false
if (!$approved) { return 0;}
//if parentalbum have no "View" Permission: return false
if (!$this->getPermissionRequest("album",strval($albumId),"View")){ return 0 ;}
}
// call normal permRequest function
return $this->getPermissionRequest($object,$objectid,$request);
}
function getPermissionRequest($object,$objectid,$request) {
// returns true or false, DO NOT EDIT THIS FUNCTION!!!
// $object: gallerie, album, image, config
// $objectid: Id / configName
// $request: Edit, View, CreateAlbum, Upload
//prepare sql variables
if ($object == "config") { //config based Permission
$objectTable = "pview_".$object;
$requestField = "configValue";
$objectField = "configName";
} else { // object based Permission
$objectTable = "pview_".$object;
$requestField = "perm".$request;
$objectField = $object."Id";
}
//-------------------------------------------------------------------------------------
//Main Database Request
$perm_SQL = new db;
$perm_SQL->db_Select("$objectTable", "$requestField", "WHERE $objectField='$objectid'", "nowhere");
list($Perm) = $perm_SQL -> db_Fetch();
//if result NULL: return false
if (!$Perm) { return 0;}
//if result ALL: return true
if ($Perm == "ALL") { return 1;}
//if result MEMBER: USER?: true/false
if ($Perm == "MEMBER") {
if (USER) {
return 1;
} else {
return 0;
}
}
//if other result: push PermArray , push UserclassArray, compare all with all: if one of them true: return true
if (!USERCLASS) { return 0;}
$PermArray = array();
$UserClassArray = array();
$PermArray = explode ( ',', $Perm );
$UserClassArray= explode ( ',', USERCLASS );
foreach ($UserClassArray as $UserClass) {
if (in_array ($UserClass,$PermArray)) { return 1;}
}
//default:
return 0;
}
function getNoPerm($appl) {
// returns a forbidden message with a back button
switch ($appl) {
case "gallery":
$applText = LAN_GALLERY_5;
break;
case "album":
$applText = LAN_ALBUM_5;
break;
case "image":
$applText = LAN_IMAGE_5;
break;
default:
$applText = LAN_IMAGE_36;
break;
}
$out_Message = "<div style='padding:10px;'>".$applText."</div>";
$out_Message.= "<div style='padding:10px;'><a href='javascript:history.back();'>".LAN_IMAGE_37."</div></a>";
return $out_Message;
}
function getAppl() {
// returns array for many functions
$pv_Appl = array ("gallery","0"); //default
if ($_GET['album']) {
$pv_Appl = array ("album",$_GET['album']);
}
if ($_GET['gallery']) {
if ($_GET['gallery'] <> "classic"){
$pv_Appl = array ("gallery",$_GET['gallery']);
}
}
if ($_GET['image']) {
$pv_Appl = array ("image",$_GET['image']);
}
if ($_GET['user']) {
$pv_Appl = array ("user",$_GET['user']);
}
if ($_GET['cat']) {
$pv_Appl = array ("cat",$_GET['cat']);
}
return $pv_Appl;
}
function sc_Replace($tmpText) {
// returns HTML with Shortcodes replaced
$Template = new Template;
global $tp;
global $outStat_Totals;
$Appl = $this -> getAppl();
// Gallery
if ($Appl[0] == "gallery") {
$tmpText = ereg_replace("{pv_MemberGalleryName}",$tp -> toHTML($this -> getPView_config("usergallery_name")),$tmpText);
$tmpText = ereg_replace("{pv_MainGalleryName}",$tp -> toHTML($this -> getGalleryName("0")),$tmpText);
$tmpText = ereg_replace("{pv_MainGalleryMenu}",$Template -> getGalleryMenu("main"),$tmpText);
$tmpText = ereg_replace("{pv_UserGalleryMenu}",$Template -> getGalleryMenu("user"),$tmpText);
$tmpText = ereg_replace("{pv_RootalbumCount}",$this -> getRootAlbumsCount(),$tmpText);
$tmpText = ereg_replace("{pv_UserGalleryCount}",$this -> getUserGalleryCount(),$tmpText);
$tmpText = ereg_replace("{pv_UserGalleryName}",$tp -> toHTML($this -> getGalleryName()),$tmpText);
$tmpText = ereg_replace("{pv_UserGalleries}",$Template -> getUserGalleries(),$tmpText);
$tmpText = ereg_replace("{pv_RootAlbums}",$Template -> getAllAlbums('root'),$tmpText);
$tmpText = ereg_replace("{pv_sumImg}",$tp -> toHTML($outStat_Totals['imgCount']),$tmpText);
$tmpText = ereg_replace("{pv_sumRating}",$tp -> toHTML($outStat_Totals['aRating']),$tmpText);
$tmpText = ereg_replace("{pv_sumViews}",$tp -> toHTML($outStat_Totals['viewsCount']),$tmpText);
$tmpText = ereg_replace("{pv_sumComm}",$tp -> toHTML($outStat_Totals['commCount']),$tmpText);
$tmpText = ereg_replace("{pv_sumAlbum}",$tp -> toHTML($outStat_Totals['albumCount']),$tmpText);
$tmpText = ereg_replace("{pv_sumCat}",$tp -> toHTML($outStat_Totals['catCount']),$tmpText);
$tmpText = ereg_replace("{pv_sumUploader}",$tp -> toHTML($outStat_Totals['uploaderCount']),$tmpText);
$tmpText = ereg_replace("{pv_sumGal}",$tp -> toHTML($outStat_Totals['galCount']),$tmpText);
$tmpText = ereg_replace("{pv_ratedImgs}",$tp -> toHTML($outStat_Totals['ratedImgs']),$tmpText);
$tmpText = ereg_replace("{pv_commImgs}",$tp -> toHTML($this->getStatistic_CommImgs()),$tmpText);
$tmpText = ereg_replace("{pv_viewedImgs}",$tp -> toHTML($this->getStatistic_ViewedImgs()),$tmpText);
$tmpText = ereg_replace("{pv_imgNoUser}",$tp -> toHTML($this->getNoUserImages()),$tmpText);
$tmpText = ereg_replace("{pv_CommUser}",$tp -> toHTML(count($this -> getStatistic_Comm())),$tmpText);
}
// Album
if ($Appl[0] == "album") {
$tmpText = ereg_replace("{pv_AlbumName}",$tp -> toHTML($this -> getAlbumName()),$tmpText);
$tmpText = ereg_replace("{pv_AlbumImageCount}",$this -> getAlbumImageCount(),$tmpText);
$tmpText = ereg_replace("{pv_SubAlbumCount}",$this -> getSubAlbumsCount(),$tmpText);
$tmpText = ereg_replace("{pv_AlbumMenu}",$Template -> getAlbumMenu(),$tmpText);
$tmpText = ereg_replace("{pv_SubAlbums}",$Template -> getAllAlbums('sub'),$tmpText);
$tmpText = ereg_replace("{pv_AlbumImages}",$Template -> getAllImages(),$tmpText);
$tmpText = ereg_replace("{pv_Pages}",$Template -> getPages(),$tmpText);
}
//Image
if ($Appl[0] == "image") {
$tmpText = ereg_replace("{pv_ImageName}",$tp -> toHTML($this -> getImageName()),$tmpText);
$tmpText = ereg_replace("{pv_ImageMenu}",$Template -> getImageMenu(),$tmpText);
$tmpText = ereg_replace("{pv_ResizeImage}",$this -> getResizeImage(),$tmpText);
$tmpText = ereg_replace("{pv_ImageData}",$Template -> getImageInfo(),$tmpText);
$tmpText = ereg_replace("{pv_NavMenu}",$Template -> getNavMenu('album'),$tmpText);
$tmpText = ereg_replace("{pv_CommentCount}",$this -> getCommentsCount(),$tmpText);
$tmpText = ereg_replace("{pv_Comments}",$Template -> getComments(),$tmpText);
$tmpText = ereg_replace("{pv_AddComment}",$Template -> getButton_addComment(),$tmpText);
$tmpText = ereg_replace("{pv_RatingResult}",$Template -> getRating(),$tmpText);
$tmpText = ereg_replace("{pv_RatingRate}",$Template -> getRate(),$tmpText);
}
// Category
if ($Appl[0] == "cat") {
$tmpText = ereg_replace("{pv_CatImages}",$Template -> getAllImages(),$tmpText);
$tmpText = ereg_replace("{pv_CatName}",$tp -> toHTML($this -> getCatName()),$tmpText);
$tmpText = ereg_replace("{pv_CatImageCount}",$this -> getCatImageCount($Appl[1]),$tmpText);
$tmpText = ereg_replace("{pv_CatMenu}",$Template -> getCatMenu(),$tmpText);
$tmpText = ereg_replace("{pv_CatList}",$Template -> getAllCats(),$tmpText);
$tmpText = ereg_replace("{pv_Pages}",$Template -> getPages(),$tmpText);
}
// User
if ($Appl[0] == "user") {
$tmpText = ereg_replace("{pv_UserImages}",$Template -> getAllImages(),$tmpText);
$tmpText = ereg_replace("{pv_UserName}",$tp -> toHTML($this -> getUserName()),$tmpText);
$tmpText = ereg_replace("{pv_UserImageCount}",$this -> getUserImageCount($Appl[1]),$tmpText);
$tmpText = ereg_replace("{pv_UserMenu}",$Template -> getUserMenu(),$tmpText);
$tmpText = ereg_replace("{pv_Pages}",$Template -> getPages(),$tmpText); }
return $tmpText;
}
function getGalleryAlbumCount($galleryid,$ignorePerm) {
// returns count of albums in gallery
$Appl = $this -> getAppl();
if ($Appl[0] == "gallery" && !$galleryid) {
$galleryid = $Appl [1];
}
$Count = 0;
global $sql;
$sql->db_Select("pview_album", "*", "WHERE galleryId='$galleryid' && parentAlbumId='0'", "nowhere");
while ($AlbumCount = $sql -> db_Fetch()) {
// PERMISSION!!!
if ($this -> getPermission("image",$AlbumCount['albumId'],"View") OR $ignorePerm) {
$Count++;
}
}
return strval ($Count);
}
function getGalleryAlbums($galleryid) {
// returns a 2D array of albums in called gallery
global $sql;
$galleryAlbums = array();
$sql->db_Select("pview_album", "*", "WHERE galleryId='$galleryid'", "nowhere");
while ($galleryAlbum = $sql -> db_Fetch()) {
array_push($galleryAlbums,$galleryAlbum);
}
return $galleryAlbums;
}
function getStatistic_Albums($mode) {
// returns a 2D array of albums for statistic, $mode: latest/random
global $sql;
$statAlbums = array();
if ($mode == "random") {
$arg = "ORDER BY RAND()";
} else {
$arg = "ORDER BY albumId DESC";
}
$sql->db_Select("pview_album", "*", $arg, "nowhere");
while ($statAlbum = $sql -> db_Fetch()) {
if ($this -> getPermission("album",$statAlbum['albumId'],"View")){
array_push($statAlbums,$statAlbum);
}
}
return $statAlbums;
}
function getStatistic_UserGals($mode = "latest") {
// returns a 2D array of usergalleries for statistic, $mode: latest/random
global $sql;
$statGals = array();
if ($mode == "random") {
$arg = "WHERE galleryId<>'0' ORDER BY RAND()";
} else {
$arg = "WHERE galleryId<>'0' ORDER BY galleryId DESC ";
}
// list main gallery first
if ($this -> getPermission("gallery","0","View")){
$mainGal = array("galleryId"=>"classic","name"=>$this->getGalleryName("0")); // important for link in gallery view
array_push($statGals,$mainGal);
}
$sql->db_Select("pview_gallery", "*", $arg, "nowhere");
while ($statUserGal = $sql -> db_Fetch()) {
if ($this -> getPermission("gallery",$statUserGal['galleryId'],"View")){
array_push($statGals,$statUserGal);
}
}
return $statGals;
}
function getStatistic_Cats($mode = "latest") {
// returns a 2D array of categories for statistic, $mode: latest/random
global $sql;
$statCats = array();
if ($mode == "random") {
$arg = "ORDER BY RAND()";
} else {
$arg = "ORDER BY catId DESC";
}
$sql->db_Select("pview_cat", "*", $arg, "nowhere");
while ($statCat = $sql -> db_Fetch()) {
array_push($statCats,$statCat);
}
return $statCats;
}
function getStatistic_Uploader() {
// returns a array of uploader for statistic, key is userId
$u_SQL = new db;
$userArray = array();
$u_SQL -> db_Select("user", "user_id","", "nowhere");
while($userTmp = $u_SQL -> db_Fetch()) {
if ($userImagesCount = $this->getUserImageCount($userTmp['user_id'])){
$userArray[$userTmp['user_id']] = $userImagesCount;
}
}
arsort($userArray);
return $userArray;
}
function getStatistic_Comm() {
// returns a array of user commented images for statistic, key is userId
$c_SQL = new db;
$userArray = array();
$c_SQL -> db_Select("user", "user_id","", "nowhere");
while($userTmp = $c_SQL -> db_Fetch()) {
if ($userCommCount = $this->getUserCommCount($userTmp['user_id'])){
$userArray[$userTmp['user_id']] = $userCommCount;
}
}
arsort($userArray);
return $userArray;
}
function getUserCommCount($userid) {
// returns count of comments as string
$Count = 0;
global $sql;
$sql->db_Select("pview_comment", "*", "WHERE commente107userId='$userid'", "nowhere");
while ($CommCount = $sql -> db_Fetch()) {
// PERMISSION!!!
if ($this -> getPermission("image",$CommCount['commentImageId'],"View")) {
$Count++;
}
}
return strval($Count);
}
function getStatistic_CommImgs() {
// returns count of commented images
global $applImages;
$allImgs = $applImages;
//$allImgs = $this->getApplImages();
$statCommImgs = 0;
foreach ($allImgs as $dataset){
if ($dataset['commentscount']){
$statCommImgs++;
}
}
return strval($statCommImgs);
}
function getStatistic_ViewedImgs() {
// returns count of commented images
global $applImages;
$allImgs = $applImages;
//$allImgs = $this->getApplImages();
$statViewedImgs = 0;
foreach ($allImgs as $dataset){
if ($dataset['views']){
$statViewedImgs++;
}
}
return strval($statViewedImgs);
}
function getRootAlbumsCount() {
// returns count of rootalbums for gallery view as string
$Appl = $this -> getAppl();
if ($Appl[0] == "gallery") {
$galleryid = $Appl [1];
}
$Count = 0;
global $sql;
$sql->db_Select("pview_album", "*", "WHERE galleryId='$galleryid'&&parentAlbumId=0", "nowhere");
while ($AlbumCount = $sql -> db_Fetch())
{
// PERMISSION!!!
if ($this -> getPermission("album",$AlbumCount['albumId'],"View")) {
$Count++;
}
}
return strval ($Count);
}
function getUserGalleryCount () {
// returns count of usergalleries for gallery view as string
$Count = 0;
global $sql;
$sql->db_Select("pview_gallery", "*", "WHERE galleryId<>0", "nowhere");
while ($GalleryCount = $sql -> db_Fetch())
{
// PERMISSION!!!
if ($this -> getPermission("gallery",$GalleryCount['galleryId'],"View")) {
$Count++;
}
}
return strval ($Count);
}
function getGalleryImageCount($galleryId) {
// returns count of images in selected gallery
$allImagesCount = 0;
$galAlbums = $this->getGalleryAlbums($galleryId);
foreach($galAlbums as $dataset) {
$allImagesCount = $allImagesCount + $this->getAlbumImageCount($dataset['albumId']);
}
return $allImagesCount;
}
function getAlbumImageCount($albumid,$ignorePerm) {
// returns count of images in album for album- and gallery view as string
$Appl = $this -> getAppl();
if ($Appl[0] == "album" && !$albumid) {
$albumid = $Appl [1];
}
$Count = 0;
global $sql;
$sql->db_Select("pview_image", "*", "WHERE albumId='$albumid'", "nowhere");
while ($ImageCount = $sql -> db_Fetch())
{
// PERMISSION!!!
if ($this -> getPermission("image",$ImageCount['imageId'],"View") OR $ignorePerm) {
$Count++;
}
}
return strval ($Count);
}
function getCatImageCount($catid) {
// returns count of images in cat view as string
$Count = 0;
global $sql;
$sql->db_Select("pview_image", "*", "WHERE cat='$catid'", "nowhere");
while ($ImageCount = $sql -> db_Fetch())
{
// PERMISSION!!!
if ($this -> getPermission("image",$ImageCount['imageId'],"View")) {
$Count++;
}
}
return strval ($Count);
}
function getUserImageCount($userid)
{
// returns count of images in user view as string
if(isset($this->userImgCount[$userid]))
{
return (string) $this->userImgCount[$userid];
}
return null;
/*$Count = 0;
global $sql;
$sql->db_Select("pview_image", "*", "WHERE uploaderUserId='$userid'", "nowhere");
while ($ImageCount = $sql -> db_Fetch())
{
// PERMISSION!!!
if ($this -> getPermission("image",$ImageCount['imageId'],"View")) {
$Count++;
}
}
return strval ($Count);*/
}
function getSubAlbumsCount($albumid,$ignorePerm) {
// returns count of subalbums for album- and gallery view as string
$Appl = $this -> getAppl();
if ($Appl[0] == "album" && !$albumid) {
$albumid = $Appl [1];
}
$Count = 0;
global $sql;
$sql->db_Select("pview_album", "*", "WHERE parentAlbumId='$albumid'", "nowhere");
while ($AlbumCount = $sql -> db_Fetch())
{
// PERMISSION!!!
if ($this -> getPermission("album",$AlbumCount['albumId'],"View") OR $ignorePerm) {
$Count++;
}
}
return strval ($Count);
}
function getAllGalleryData () {
// returns a 2D array of all galleries data
global $sql;
$out_GalleryData = array();
$sql->db_Select("pview_gallery", "*", "", "nowhere");
while ($GalleryData = $sql -> db_Fetch())
{
// PERMISSION???
array_push ($out_GalleryData, $GalleryData);
}
return $out_GalleryData;
}
function getGalleryActive($galleryid) {
// returns true if gallery is active
$gal_SQL = new db;
$gal_SQL -> db_Select("pview_gallery", "active", "WHERE galleryId='$galleryid'", "nowhere");
list($galActive) = $gal_SQL -> db_Fetch();
return $galActive;
}
function getRootAlbumData ($galleryid) {
// returns a 2D array of rootalbums data
$Appl = $this -> getAppl();
if ($Appl[0] == "gallery" && !$galleryid) {
$galleryid = $Appl [1];
}
global $sql;
$out_RootAlbum = array();
$sql->db_Select("pview_album", "*", "WHERE galleryId='$galleryid'&&parentAlbumId=0", "nowhere");
while ($RootAlbum = $sql -> db_Fetch())
{
array_push ($out_RootAlbum, $RootAlbum);
}
return $out_RootAlbum;
}
function getSubAlbumData () {
// returns a 2D array of subalbums data
$Appl = $this -> getAppl();
if ($Appl[0] == "album") {
$albumid = $Appl [1];
}
global $sql;
$out_SubAlbum = array();
$sql->db_Select("pview_album", "*", "WHERE parentAlbumId='$albumid'", "nowhere");
while ($SubAlbum = $sql -> db_Fetch())
{
// PERMISSION???
array_push ($out_SubAlbum, $SubAlbum);
}
return $out_SubAlbum;
}
function getAlbumData($albumid) {
// returns array of album data
global $sql;
$sql->db_Select("pview_album", "*", "WHERE albumId='$albumid'", "nowhere");
return $sql -> db_Fetch();
}
function getGalleryData($galleryid) {
// returns array of gallery data
global $sql;
$sql->db_Select("pview_gallery", "*", "WHERE galleryId='$galleryid'", "nowhere");
return $sql -> db_Fetch();
}
function getGalleryName($galleryid) {
// returns gallery name
$Appl = $this -> getAppl();
if ($Appl[0] == "gallery" && !$galleryid) {
$galleryid = $Appl [1];
}
$GalleryData = $this -> getGalleryData($galleryid);
return $GalleryData['name'];
}
function getAlbumImage($albumid) {
// returns albumimage file or alternate file
$Appl = $this -> getAppl();
if ($Appl[0] == "album" && !$albumid) {
$albumid = $Appl [1];
}
$AlbumData = $this -> getAlbumData($albumid);
if (!$AlbumData['albumImage']) {
$out_AlbumImage = SITEURLBASE.e_PLUGIN_ABS."pviewgallery/templates/".$this -> getPView_config("template")."/images/nopicture.png";
//$out_AlbumImage = e_PLUGIN."pviewgallery/templates/".$this -> getPView_config("template")."/images/nopicture.png";
} else {
$out_AlbumImage = SITEURLBASE.e_PLUGIN_ABS."pviewgallery/gallery/album".$albumid."/". $AlbumData['albumImage'];
//$out_AlbumImage = e_PLUGIN."pviewgallery/gallery/album".$albumid."/". $AlbumData['albumImage'];
}
return $out_AlbumImage;
}
function getAlbumName($albumid) {
// returns album name
$Appl = $this -> getAppl();
if ($Appl[0] == "album" && !$albumid) {
$albumid = $Appl [1];
}
$AlbumData = $this -> getAlbumData($albumid);
return $AlbumData['name'];
}
function getImageName($imageid) {
// returns image name
$Appl = $this -> getAppl();
if ($Appl[0] == "image" && !$imageid) {
$imageid = $Appl [1];
}
$ImageData = $this -> getImageData($imageid);
return $ImageData['name'];
}
function getCatName($catid) {
// returns category name
$Appl = $this -> getAppl();
if ($Appl[0] == "cat" && !$catid) {
$catid = $Appl [1];
}
$catData = $this->getCatData($catid);
return $catData['name'];
}
function getUserName($userid) {
// returns user name
$Appl = $this -> getAppl();
if ($Appl[0] == "user" && !$userid) {
$userid = $Appl [1];
}
$userData = $this->getUserData($userid);
return $userData['user_name'];
}
function getResizeImage() {
// returns resized image file OR thumbnail as fallback
$Appl = $this -> getAppl();
return "<a href='javascript:showImage();'><img src='".$this -> getResizePath($Appl[1])."'></a>";
}
function getImageData($imageid) {
// returns array of image data
global $sql;
$sql->db_Select("pview_image", "*", "WHERE imageId='$imageid'", "nowhere");
return $sql -> db_Fetch();
}
function getImageAlbum($imageid) {
// returns album Id of image, used to inherit album permission to image
$Appl = $this -> getAppl();
if ($Appl[0] == "image" && !$imageid) {
$imageid = $Appl [1];
}
$ImageAlbum = $this -> getImageData($imageid);
return $ImageAlbum['albumId'];
}
function getApplImages(){
// returns a 2D array of images data, acc. to selected view, incl. rating and commentscount for sorting
$Appl = $this -> getAppl();
$i_SQL = new db;
$out_Images = array();
$Image = array();
global $ImageSort;
if ($Appl[0] == "image") {
$imageData = $this->getImageData($Appl[1]);
if (isset($_GET['view'])){
if ($_GET['view'] == "cat"){
$arg = "WHERE cat=".$imageData['cat'];
$ImageSort = $this->getPView_config("cat_sort");
}
if ($_GET['view'] == "user"){
$arg = "WHERE uploaderUserId=".$imageData['uploaderUserId'];
$ImageSort = $this->getPView_config("user_sort");
}
if ($_GET['view'] == "album" OR $_GET['view'] == ""){
$arg = "WHERE albumId=".$imageData['albumId'];
$ImageSort = $this->getPView_config("album_sort");
}
// check viewer sorting and overwrite default!!!
if (isset($_SESSION['pv_'.$_GET['view'].'_sort']) && $this->getPView_config('viewer_sort')) {
$ImageSort = $_SESSION['pv_'.$_GET['view'].'_sort'];
}
} else {
$arg = "WHERE albumId=".$imageData['albumId'];
$ImageSort = $this->getPView_config("album_sort");
}
// check viewer sorting and overwrite default!!!
if (isset($_SESSION['pv_album_sort']) && $this->getPView_config('viewer_sort')) {
$ImageSort = $_SESSION['pv_album_sort'];
}
}
if ($Appl[0] == "album") {
$arg = "WHERE albumId=".$Appl[1];
$ImageSort = $this->getPView_config("album_sort");
// check viewer sorting and overwrite default!!!
if (isset($_SESSION['pv_album_sort']) && $this->getPView_config('viewer_sort')) {
$ImageSort = $_SESSION['pv_album_sort'];
}
}
if ($Appl[0] == "cat") {
$arg = "WHERE cat=".$Appl[1];
$ImageSort = $this->getPView_config("cat_sort");
// check viewer sorting and overwrite default!!!
if (isset($_SESSION['pv_cat_sort']) && $this->getPView_config('viewer_sort')) {
$ImageSort = $_SESSION['pv_cat_sort'];
}
}
if ($Appl[0] == "user") {
$arg = "WHERE uploaderUserId=".$Appl[1];
$ImageSort = $this->getPView_config("user_sort");
// check viewer sorting and overwrite default!!!
if (isset($_SESSION['pv_user_sort']) && $this->getPView_config('viewer_sort')) {
$ImageSort = $_SESSION['pv_user_sort'];
}
}
$i_SQL->db_Select("pview_image","*",$arg." ORDER BY imageId ASC","nowhere");
while ($Image = $i_SQL -> db_Fetch()) {
// PERMISSION!!!
if ($this -> getPermission("image",$Image['imageId'],"View")){
$rating = $this -> getRatingData($Image['imageId']);
$Image['ratingvalue'] = $rating['value'];
$Image['commentscount'] = $this -> getCommentsCount($Image['imageId']);
array_push ($out_Images, $Image);
}
}
return $out_Images;
}
function imagepicker($type,$curImageId,$albumId) {
// returns imageId of requested image for image view (navigation menu)
global $sql;
switch ($type) {
case "first":
if ($this -> getPView_config('album_dir') == "ASC"){
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId' ORDER BY uploadDate LIMIT 1", "nowhere");
} else {
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId' ORDER BY uploadDate DESC LIMIT 1", "nowhere");
}
break;
case "prev":
if ($this -> getPView_config('album_dir') == "ASC"){
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId'&& imageId<'$curImageId' ORDER BY uploadDate DESC LIMIT 1", "nowhere");
} else {
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId'&& imageId>'$curImageId' ORDER BY uploadDate LIMIT 1", "nowhere");
}
break;
case "next":
if ($this -> getPView_config('album_dir') == "ASC"){
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId'&& imageId>'$curImageId' ORDER BY uploadDate LIMIT 1", "nowhere");
} else {
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId'&& imageId<'$curImageId' ORDER BY uploadDate DESC LIMIT 1", "nowhere");
}
break;
case "last":
if ($this -> getPView_config('album_dir') == "ASC"){
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId' ORDER BY uploadDate DESC LIMIT 1", "nowhere");
} else {
$sql->db_Select("pview_image", "imageId", "WHERE albumId='$albumId' ORDER BY uploadDate LIMIT 1", "nowhere");
}
break;
}
$ImageRequest = $sql -> db_Fetch();
return $ImageRequest['imageId'];
}
function setImageViews($imageid) {
// no return, increases image views
global $sql;
$curViews = $this -> getImageData($imageid);
$actViews = $curViews['views'] + 1;
$sql->db_Update("pview_image", "views=".$actViews." WHERE imageId='".$imageid."'");
}
function getCommentsCount($imageid) {
// returns total count of comments for this image
$Appl = $this -> getAppl();
if ($Appl[0] == "image" && !$imageid) {
$imageid = $Appl [1];
}
global $sql;
$Count = 0;
$sql->db_Select("pview_comment", "*", "WHERE commentImageId='$imageid'", "nowhere");
while ($CommentsCount = $sql -> db_Fetch()) {
$Count++;
}
return strval($Count);
}
function getCommentsData($imageid) {
// returns a 2D array of comment data
$Appl = $this -> getAppl();
if ($Appl[0] == "image" && !$imageid) {
$imageid = $Appl [1];
}
global $sql;
$out_CommentsData = array();
$sql->db_Select("pview_comment", "*", "WHERE commentImageId='$imageid' ORDER BY commentDate", "nowhere");
while ($CommentData = $sql -> db_Fetch()) {
array_push ($out_CommentsData, $CommentData);
}
return $out_CommentsData;
}
function getUserRated($imageid) {
// returns true if user has rated this image
$Appl = $this -> getAppl();
if ($Appl[0] == "image" && !$imageid) {
$imageid = $Appl [1];
}
global $sql;
$userid = USERID;
$sql->db_Select("pview_rating", "ratingValue", "WHERE ratingImageId='$imageid' && rating107userId='$userid'", "nowhere");
if ($sql -> db_Fetch()) { return 1;}
return 0;
}
function getRatingData($imageid) {
// returns rating result and rating count
$Appl = $this -> getAppl();
if ($Appl[0] == "image" && !$imageid) {
$imageid = $Appl [1];