#!/usr/local/bin/perl # gallery.cgi #$StartTime = time(); #For debugging purposes # flush the buffers $|=1; # find if it is a windows operating system my($dpath); my($windows); if ( ($^O eq 'MSWin32') || defined($ENV{'OS'}) ) { # this one for windows $windows = "true"; $dpath= "$ENV{'PATH_TRANSLATED'}"; $dpath =~ s/\\$GalleryCgi$//g; $slash = '\\'; }else{ # this one for unix type $windows = "false"; $dpath = "$ENV{'SCRIPT_FILENAME'}"; $dpath =~ s/\/$GalleryCgi$//g; $slash = '/'; } push (@INC, "$dpath"); eval { # load required files require 'uig.cfg'; push(@INC, "$ScriptPath"); require $ScriptPath.$slash."uiglib.cgi"; require $ScriptPath.$slash."memory.cgi"; require $ScriptPath.$slash."display.cgi"; }; if ($@) { print qq~ Content-type: text/html\n\n Error including the required files:
~; print "$@\n\n"; exit; } use CGI; $cgi = new CGI; #eval use_named_parameters to work with both old and new versions of CGI.pm eval '$cgi->use_named_parameters'; #read cookie $CookieData = $cgi->cookie("$CookieName"); if ($CookieData){ CrumbleCookie(); } InitFromParameters(); LoadProfile(); if($cgi->param("func") eq "showlogin") { ShowLogin(); } elsif($cgi->param("func") eq "login") { my $rval = Login(); if($rval eq "true") { WriteMessage(" $Username, you have been logged in."); } elsif($rval eq "false") { ShowLogin("You entered an incorrect password."); } } elsif($cgi->param("func") eq "logout") { Logout(); } elsif($cgi->param("func") eq "showregister") { ShowRegister(); } elsif($cgi->param("func") eq "register") { Register(); } elsif($cgi->param("func") eq "setsort") { $SortBy = $cgi->param("sort"); SetCookie(PrepareCookie()); } elsif($cgi->param("func") eq "showsort") { ShowSortOptions(); } elsif($cgi->param("func") eq "search") { if($cgi->param("searchterm")) { require $ScriptPath.$slash."categories.cgi"; require $ScriptPath.$slash."media.cgi"; #initialize media ReadCategories(); $searchterm = DecodeURL($cgi->param("searchterm")); ReadMedia($cgi->param("Category"), $searchterm, $cgi->param("searchfield")); if(!@MediaList) { FatalError(qq~Found 0 Results for '$searchterm'~); } ShowGallery(); } else { ShowSearchForm(); } } elsif($cgi->param("func") eq "showupload") { require $ScriptPath.$slash."categories.cgi"; require $ScriptPath.$slash."media.cgi"; #initialize media ReadCategories(); $CategoryPath = $MediaPath.$CategoryList[$CategoryIndex]->{PATH}."imagedata.cgi"; $CategoryPath = $MediaPath.$CategoryPath; $Category = $CategoryList[$CategoryIndex]->{NAME}; ShowUpload(); } elsif($cgi->param("func") eq "upload") { require $ScriptPath.$slash."categories.cgi"; require $ScriptPath.$slash."media.cgi"; require $ScriptPath.$slash."plugins.cgi"; if(!$Username || $Username eq "Guest") { Login(); } ReadCategories(); ReadMedia($CategoryIndex); $CategoryPath = $MediaPath.$CategoryPath; $Category = $CategoryList[$CategoryIndex]->{NAME}; LoadPlugins(); Upload(); } if($cgi->param("func") eq "show") { require $ScriptPath.$slash."categories.cgi"; require $ScriptPath.$slash."media.cgi"; ReadCategories(); $Category = $CategoryList[$CategoryIndex]->{NAME}; $granted = "false"; if($CategoryList[$CategoryIndex]->{PROTECTED} eq "true") { if(($CategoryList[$CategoryIndex]->{GROUPS} =~ /$UserProfile[16]/ && $UserProfile[16] ne "" && $Username ne "") || ($CategoryList[$CategoryIndex]->{USERS} =~ /$Username/ && $Username ne "")) { $granted = "true"; } } else { $granted = "true"; } if($granted eq "true") { ShowMedia(); } else { if($Username eq "" || $LoggedIn eq "false") { ShowLogin("This is a restricted category, please login first."); } FatalError("You do not have permission to access this category.

"); } } elsif($CategoryIndex < 0) { require $ScriptPath.$slash."categories.cgi"; ReadCategories(); ShowCategoryListing(); } else { #Category is set and nothing else needs to be done so show gallery require $ScriptPath.$slash."categories.cgi"; require $ScriptPath.$slash."media.cgi"; #initialize media ReadCategories(); $Category = $CategoryList[$CategoryIndex]->{NAME}; $granted = "false"; if($CategoryList[$CategoryIndex]->{PROTECTED} eq "true") { if(($CategoryList[$CategoryIndex]->{GROUPS} =~ /$UserProfile[16]/ && $UserProfile[16] ne "" && $Username ne "") || ($CategoryList[$CategoryIndex]->{USERS} =~ /$Username/ && $Username ne "")) { $granted = "true"; } } else { $granted = "true"; } if($granted eq "true") { ReadMedia($CategoryIndex); $CategoryPath = $MediaPath.$CategoryPath; ShowGallery(); } else { if($Username eq "" || $LoggedIn eq "false") { ShowLogin("This is a restricted category, please login first."); } FatalError("You do not have permission to access this category.

"); } } ######################################################################################## sub InitFromParameters { if($SortBy ne "") { } elsif($cgi->param("selectedsort") ne "") { $SortBy = $cgi->param("selectedsort"); } elsif($cgi->param("sort") ne "") { $SortBy = $cgi->param("sort"); } else { $SortBy = $DefaultSort; } if($cgi->param("Page") ne "") { $Page = $cgi->param("Page"); } else { $Page = 1; } if($cgi->param("Category") ne "") { $CategoryIndex = int($cgi->param("Category")); if($CategoryIndex < 0) { $Category = "NONE"; } } else { $CategoryIndex = -1; $Category = "NONE"; } } ######################################################################################## sub CategoryTree { if($cgi->param("searchterm")) { return; } if(!@CatTree) { BuildCatTree($cgi->param("Category")); } my($html) = qq~
$GalleryTitle
~; for(my($counter) = 0; $counter < @CatTree; $counter++) { for(my($index) = 0; $index < $CatTree[$counter]->{DEPTH}; $index++) { $html = $html."  "; } if($CatTree[$counter]->{INDEX} == $cgi->param("Category")) { $html = $html.qq~ $CatTree[$counter]->{NAME}
~; } else { $html = $html.qq~ $CatTree[$counter]->{NAME}
~; } } $html = $html.qq~
~; return $html; } sub SubCategoryList { if($cgi->param("searchterm")) { return; } if(!@SubCats) { FindSubCategories(); } my($html) = qq~ ~; for($counter = 0; $counter < @SubCats; $counter++) { if($counter % 2 == 0) { $html = $html.qq~~; } if($SubCats[$counter]->{IMAGE} ne "") { $catimg = qq~ ~; } else { $catimg = ""; } $html = $html.qq~ ~; if($counter == @SubCats - 1 && @SubCats % 2 == 1) { $html = $html.qq~~; } if($counter % 2 == 1) { $html = $html.qq~~; } } $html = $html.qq~
Sub Categories:
$catimg $SubCats[$counter]->{NAME}
$SubCats[$counter]->{DESC}
($SubCats[$counter]->{SUBS} Sub-Categories, $SubCats[$counter]->{COUNT} Images)
 
~; return $html; } ######################################################################################## sub PageStats { if($cgi->param("func") eq "show") { return; } if($TotalPages == 0) { $PageStats = "$NumPictures entries
Page $Page of 1"; } else { $PageStats = "$NumPictures entries
Page $Page of $TotalPages"; } my($html); $html = qq~ $PageStats ~; return $html; } ######################################################################################## sub CategoryInline { my $filename = shift; if($cgi->param("searchterm") ne "") { $SearchDisplay = "Search Results for '".$cgi->param("searchterm")."'"; } elsif(!@CatInline) { BuildCatInline($cgi->param("Category")); } my($html) = qq~

Top ~; if($SearchDisplay) { $html = $html."> $SearchDisplay"; } else { for(my($counter) = 0; $counter < @CatInline; $counter++) { if(($filename eq "" && $CatInline[$counter]->{INDEX} == $cgi->param("Category")) || $CatInline[$counter] eq "Search Results") { $html = $html."> $CatInline[$counter]->{NAME} "; } else { $html = $html.qq~> $CatInline[$counter]->{NAME} ~; } } if($filename) { $html = $html.qq~ > $filename~; } } $html = $html.qq~

~; return $html; } ######################################################################################## sub SortDropBox { my($html) = qq~

Sort images by:
~; return $html; } ######################################################################################## sub CategoryDropBox { if(!@CategoryList) { require $ScriptPath.$slash."categories.cgi"; ReadCategories(); } my($html) = qq~

Jump To:
 
~; return $html; } ######################################################################################## sub SearchBox { my($html) = qq~
Search:
~; return $html; } ######################################################################################## ######################################################################################## sub NavBack { my($html) = qq~

Go Back to $SiteTitle

~; } ######################################################################################## sub PageNavigation { my($prev, $next, $html); $prev = $CategoryIndex - 1; if($CategoryIndex == @CategoryList - 1) { $next = 0; } else { $next = $CategoryIndex + 1; } my $PageNav = qq~ ~; if($cgi->param("searchterm") eq "") { $PageNav = $PageNav.qq~ ~; $width = "33%"; } else { $width = "100%"; } $PageNav = $PageNav.qq("; if($cgi->param("searchterm") eq "") { $PageNav = $PageNav.qq~ ~; } $PageNav = $PageNav.""; $html = qq~ $PageNav ~; return $html; } sub ShowNavigation { $prev = $MediaIndex - 1; if($MediaIndex == @MediaList - 1) { $next = 0; } else { $next = $MediaIndex + 1; } my $PageNav = qq~ ~; $PageNav = $PageNav.qq~ ~; $PageNav = $PageNav.qq(); $PageNav = $PageNav.qq~ ~; $PageNav = $PageNav.""; $html = qq~ $PageNav ~; return $html; } ######################################################################################## sub MediaField { my($index) = shift; my($field) = shift; return $MediaList[$index][$field]; } ######################################################################################## sub CategoryTable { my($html); $html = qq~
$CategoryName Listing:
~; if(@CategoryList == 0) { $html = $html.qq~ ~; } my($catcount) = 0; for($counter = 0; $counter < @CategoryList; $counter++) { if($CategoryList[$counter]->{DEPTH} == 0 && $CategoryList[$counter]->{VISIBLE} eq "true" && GoodStartDate($CategoryList[$counter]->{STARTDATE}) && GoodEndDate($CategoryList[$counter]->{ENDDATE})) { if($catcount % 2 == 0) { $html = $html.""; } $html = $html.""; if($catcount % 2 == 1){ $html = $html.""; } $catcount++; } } $html = $html.qq~
Sorry, no categories exist yet.
"; if($CategoryList[$counter]->{IMAGE} ne "") { $catimg = qq~~; } else { $catimg = ""; } $html = $html.qq~ $catimg $CategoryList[$counter]->{NAME}
$CategoryList[$counter]->{DESC}
($CategoryList[$counter]->{SUBS} Sub-Categories, $CategoryList[$counter]->{COUNT} Images)
~; $html = $html."
~; return $html; } sub ThumbTable { my($html); if($NumPictures == 0) { if(!@SubCats) { FindSubCategories(); } if(!@SubCats) { $html = qq(\n); $html = $html.qq(); $html = $html.qq(

No pictures available

); } } else { $start = $Index; $width = 100 / $PageColumns; $maxindex = $PicsOnPage + $Index; my($counter); my($stop) = 0; $html = $html.qq(); for($rowcounter = 0, $imgcount = 0; $rowcounter < $PageRows; $rowcounter++) { if($imgcount >= $PicsOnPage) { last; } $html = $html.qq(\n); for($colcounter = 0; $colcounter < $PageColumns; $colcounter++, $imgcount++, $Index++) { if($imgcount >= $PicsOnPage) { #stop trying to print images, fill the remaining columns, then get the fuck outta here. $html = $html.qq(\n\n); $stop = 1; } else { $html = $html.qq(\n\n); } } $html = $html.qq(\n); if($stop == 1) { last; } } $html = $html.qq(
); $html = $html.qq(
 ); $html = $html.qq(
); $html = $html.qq(
); $html = $html.qq(
\n); $html = $html.ThumbHTML($Index); $html = $html.qq(
\n); } return $html; } ######################################################################################## sub ThumbHTML { my($index) = shift; if($MediaList[$index][$FILENAME] eq "") { return ""; } if ($MediaList[$index][$THUMBNAME] eq "NODATA") { #the thumbname is not present, check using prefix and filename $imagesrc = $MediaPath.$CategoryList[$MediaList[$index][$CATINDEX]]->{PATH}."thumbs$slash".$thumbprefix.$MediaList[$index][$FILENAME]; if (-e "$imagesrc") { #thumb exists $imagesrc = $MediaUrl.$CategoryList[$MediaList[$index][$CATINDEX]]->{PATH}."thumbs/".$thumbprefix.$MediaList[$index][$FILENAME]; } else { #does not exist, use a default $baseimglink = "$MediaUrl$CategoryList[$CategoryIndex]->{PATH}media$slash$MediaList[$index][$FILENAME]"; $imagesrc = $baseimglink; } } else { #thumb is present see if exists in dir $imagesrc = $MediaPath.$CategoryList[$MediaList[$index][$CATINDEX]]->{PATH}."thumbs$slash".$MediaList[$index][$THUMBNAME]; if (-e "$imagesrc") { #thumb exists $imagesrc = $MediaUrl.$CategoryList[$MediaList[$index][$CATINDEX]]->{PATH}."thumbs/".$MediaList[$index][$THUMBNAME]; } else { #does not exist, use a default $baseimglink = "$MediaUrl$CategoryList[$CategoryIndex]->{PATH}media$slash$MediaList[$index][$FILENAME]"; $imagesrc = $baseimglink; } } ReadFileTypes(); $OpenFileIn = $FileOpen{$MediaList[$index][$TYPE]}; if($OpenFileIn eq "samewindow") { $link = qq~ ~; } elsif($OpenFileIn eq "newwindow") { $link = qq~ ~; } elsif($OpenFileIn eq "download") { $MediaLink = $MediaUrl.$CategoryList[$MediaList[$index][$CATINDEX]]->{PATH}."/media/".$MediaList[$index][$FILENAME]; $link = qq~ ~; } else { $link = qq~ ~; } $ThumbDisplayFormat = "\n\n".$ThumbDisplay; if($MediaList[$index][$FILENAME] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$FILENAME]/g; } if($MediaList[$index][$TYPE] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$TYPE]/g; } if($MediaList[$index][$DATE] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$DATE]/g; } if($MediaList[$index][$COPYRIGHT] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$COPYRIGHT]/g; } if($MediaList[$index][$AUTHOR] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$AUTHOR]/g; } if($MediaList[$index][$DOWNLOADS] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$DOWNLOADS]/g; } if($MediaList[$index][$DESCRIPTION] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$DESCRIPTION]/g; } if($MediaList[$index][$USER] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$USER]/g; } if($MediaList[$index][$IP] ne "NODATA") { $ThumbDisplayFormat =~ s//$MediaList[$index][$IP]/g; } $ThumbDisplayFormat =~ s//$link/g; return $ThumbDisplayFormat."\n\n"; } ######################################################################################## sub FullsizeHtml { $baseimglink = "$MediaUrl$CategoryList[$CategoryIndex]->{PATH}media$slash$ShowData[$FILENAME]"; ReadFileTypes(); if($FileCode{"$ShowData[$TYPE]"} ne "") { $code = $FileCode{"$ShowData[$TYPE]"}; } else { $code = $FileCode{"Image/GIF"}; } $code =~ s//$baseimglink/g; $ImageDisplayFormat = qq(\n
); $ImageDisplayFormat = $ImageDisplayFormat.$ImageDisplay; $ImageDisplayFormat =~ s//$code/g; $ImageDisplayFormat =~ s//$ShowData[$FILENAME]/g; #$ImageDisplayFormat =~ s//$ $ImageDisplayFormat =~ s//$ShowData[$TYPE]/g; if($ShowData[$DATE] ne "NODATA") { $ImageDisplayFormat =~ s//$ShowData[$DATE]/g; } if($ShowData[$COPYRIGHT] ne "NODATA") { $ImageDisplayFormat =~ s//$ShowData[$COPYRIGHT]/g; } if($ShowData[$AUTHOR] ne "NODATA") { $ImageDisplayFormat =~ s//$ShowData[$AUTHOR]/g; } $ImageDisplayFormat =~ s//$ShowData[$DOWNLOADS]/g; if($ShowData[$DESCRIPTION] ne "NODATA") { $ImageDisplayFormat =~ s//$ShowData[$DESCRIPTION]/g; } if($ShowData[$USER] ne "NODATA") { $ImageDisplayFormat =~ s//$ShowData[$USER]/g; } if($ShowData[$IP] ne "NODATA") { $ImageDisplayFormat =~ s//$ShowData[$IP]/g; } $ImageDisplayFormat = $ImageDisplayFormat.qq(
); return $ImageDisplayFormat; }