#!/usr/bin/perl ############################################################## # # This code is copyright iKing Networks 2000, 2001. # # iKing Networks offers no warranties on this script. # The user of the script is solely responsible for # any problems caused by installation of the script or use # of the script. # # All copyright notices regarding Arcadia scripts and iKing # Networks must remain intact on the scripts and in the HTML # for the scripts. # # http://www.ikingnet.com # ############################################################### # gallery.cgi #If you are on a Windows or other such server that runs scripts #in a directory other than the one they reside in, modify this #variable to the full path to uig.cfg. (Do not include a trailing #slash, / or \\) $UigPath = ""; #Modify this if you are on an old version of windows $slash = "/"; # 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'}"; }else{ # this one for unix type $windows = "false"; $dpath = "$ENV{'SCRIPT_FILENAME'}"; } push (@INC, "$dpath"); eval { # load required files if($UigPath eq "") { require 'uig.cfg'; } else { require $UigPath.$slash."uig.cfg"; } push(@INC, "$ScriptPath"); require $ScriptPath.$slash."display.cgi"; require $ScriptPath.$slash."uiglib.cgi"; require $ScriptPath.$slash."memory.cgi"; }; if ($@) { print "Content-type: text/html\n\n"; print qq~Image Arcadia Error Image Arcadia failed to Load.

Error including the required files:
~; print qq~$@~; print qq~~; exit; } use CGI; use CGI::Carp qw(fatalsToBrowser); $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(); #PrintHeader(); #print $cgi->dump(); if($cgi->param("func") eq "show") { require $ScriptPath.$slash."categories.cgi"; require $ScriptPath.$slash."media.cgi"; ReadCategories(); $Category = $CategoryList[$CategoryIndex]->{NAME}; ShowMedia(); } 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}; ReadMedia($CategoryIndex); $CategoryPath = $MediaPath.$CategoryPath; ShowGallery(); } ######################################################################################## 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 "") { $CategoryID = int($cgi->param("Category")); if(!@CategoryList) { require $ScriptPath.$slash."categories.cgi"; ReadCategories(); } $CategoryIndex = GetCategoryIndex($CategoryID); if($CategoryIndex < 0) { $Category = "NONE"; } } else { $CategoryIndex = -1; } } ######################################################################################## sub CategoryTree { if($cgi->param("searchterm")) { return; } if(!@CatTree) { BuildCatTree($CategoryIndex); } 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(); } if(@SubCats <= 0) { return; } 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} ~; if(GetDaysOld($SubCats[$counter]->{LASTMODIFIED}) <= $NewPeriodLength) { $html .= qq~ New ~; } $html .= qq~
$SubCats[$counter]->{DESC}
~; if($SubCats[$counter]->{SUBS} <= 0) { $html .= qq~ ($SubCats[$counter]->{COUNT} Images) ~; } else { $html .= qq~ ($SubCats[$counter]->{SUBS} Sub-Categories, $SubCats[$counter]->{COUNT} Images) ~; } $html .= qq~
 
~; 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; $filename = (split(/\//, $filename))[-1]; if(!@CatInline) { BuildCatInline($CategoryIndex); } my($html) = qq~

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

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


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

Go Back to $SiteTitle

~; } ######################################################################################## sub PageNavigation { my($previd, $nextid, $html, $previndex, $nextindex); $previndex = $CategoryIndex - 1; $previd = $CategoryList[$previndex]->{CATID}; if($CategoryIndex == @CategoryList - 1) { $nextindex = 0; } else { $nextindex = $CategoryIndex + 1; } $nextid = $CategoryList[$nextindex]->{CATID}; my $PageNav = qq~ ~; if($cgi->param("searchterm") eq "") { $PageNav = $PageNav.qq~ ~; $width = "33%"; } else { $width = "100%"; } $PageNav = $PageNav.qq(); } ##### if($Page > 1 && $TotalPages > 1) { if($SearchLink) { $PageNav = $PageNav."<< "; } else { $PageNav = $PageNav."<< "; } } if($Page < 1) { $PageNav = $PageNav."No Pages Exist!"; } #### for($j = 1; $j <= $TotalPages; $j++) { if($j == $Page) { $PageNav = $PageNav."[".$j."]"; } else { if($SearchLink) { $PageNav = $PageNav."[".$j."]"; } else { $PageNav = $PageNav."[".$j."]"; } } } #### if($Page < $TotalPages) { if($SearchLink) { $PageNav = $PageNav." >>"; } else { $PageNav = $PageNav." >>"; } } ##### $PageNav = $PageNav.""; 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 $PrevName = (split(/\//, $MediaList[$prev][$FILENAME]))[-1]; my $NextName = (split(/\//, $MediaList[$next][$FILENAME]))[-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) { if($catcount % 2 == 0) { $html = $html.""; } $html = $html.qq~"; 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} ~; if(GetDaysOld($CategoryList[$counter]->{LASTMODIFIED}) <= $NewPeriodLength) { $html .= qq~ New ~; } $html .= qq~
~; if($CategoryList[$counter]->{SUBS} <= 0) { $html .= qq~ $CategoryList[$counter]->{DESC}
($CategoryList[$counter]->{COUNT} Images)
~; } else { $html .= qq~ $CategoryList[$counter]->{DESC}
($CategoryList[$counter]->{SUBS} Sub-Categories, $CategoryList[$counter]->{COUNT} Images)
~; } $html .= qq~
~; $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 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; my $catindex = -1; for(my $counter = 0; $counter < @CategoryList; $counter++) { if($MediaList[$index][$CATID] eq $CategoryList[$counter]->{CATID}) { $catindex = $counter; last; } } if($MediaList[$index][$FILENAME] eq "") { return ""; } if ($MediaList[$index][$THUMBNAME] eq "") { #the thumbname is not present, check using prefix and filename $imagesrc = $MediaPath.$CategoryList[$catindex]->{PATH}."thumbs$slash".$thumbprefix.$MediaList[$index][$FILENAME]; if (-e "$imagesrc") { #thumb exists $imagesrc = $MediaUrl.$CategoryList[$catindex]->{PATH}."thumbs/".$thumbprefix.$MediaList[$index][$FILENAME]; } else { #does not exist, use a default my $ext = GetFileExt($MediaList[$index][$FILENAME]); if(-e $SkinPath."/ico-".$ext.".gif") { $imagesrc = $SkinUrl."/ico-".$ext.".gif"; } elsif(-e $SkinPath."/ico-".$ext.".jpg") { $imagesrc = $SkinUrl."/ico-".$ext.".jpg"; } else { $imagesrc = $SkinUrl."/notfound.gif"; } } } else { #thumb is present see if exists in dir $imagesrc = $MediaPath.$CategoryList[$catindex]->{PATH}."thumbs$slash".$MediaList[$index][$THUMBNAME]; if (-e "$imagesrc") { #thumb exists $imagesrc = $MediaUrl.$CategoryList[$catindex]->{PATH}."thumbs/".$MediaList[$index][$THUMBNAME]; } else { #does not exist, use a default my $ext = GetFileExt($MediaList[$index][$FILENAME]); if(-e $SkinPath."/ico-".$ext.".gif") { $imagesrc = $SkinUrl."/ico-".$ext.".gif"; } elsif(-e $SkinPath."/ico-".$ext.".jpg") { $imagesrc = $SkinUrl."/ico-".$ext.".jpg"; } else { $imagesrc = $SkinUrl."/ico-notfound.gif"; } } } ReadFileTypes(); if($MediaList[$index][$TYPE] eq "Unknown") { #if the file was added before its file type, lets see if we can correct that... $MediaList[$index][$TYPE] = AssignType($MediaList[$index][$FILENAME]); } $OpenFileIn = $FileOpen{$MediaList[$index][$TYPE]}; if($OpenFileIn eq "samewindow") { $link = qq~ {CATID}&Page=$Page> ~; } elsif($OpenFileIn eq "newwindow") { $link = qq~ {CATID}&Page=$Page target="_new"> ~; } elsif($OpenFileIn eq "download") { $MediaLink = $MediaUrl.$CategoryList[$catindex]->{PATH}."media/".$MediaList[$index][$FILENAME]; $link = qq~ ~; } else { $link = qq~ {CATID}&Page=$Page> ~; } $ThumbDisplayFormat = "\n\n".$ThumbDisplay; $ThumbDisplayFormat =~ s//$MediaList[$index][$FILESIZE]/g; if($MediaList[$index][$FILENAME] ne "") { my $DisplayName; my @temp = split(/\//, $MediaList[$index][$FILENAME]); $DisplayName = $temp[-1]; $ThumbDisplayFormat =~ s//$DisplayName/g; } if($MediaList[$index][$TYPE] ne "") { $ThumbDisplayFormat =~ s//$MediaList[$index][$TYPE]/g; } if($MediaList[$index][$DATE] ne "") { my $tempdate = NormalDateTime($MediaList[$index][$DATE]); $ThumbDisplayFormat =~ s//$tempdate/g; } if($MediaList[$index][$COPYRIGHT] ne "") { $ThumbDisplayFormat =~ s//$MediaList[$index][$COPYRIGHT]/g; } if($MediaList[$index][$AUTHOR] ne "") { $ThumbDisplayFormat =~ s//$MediaList[$index][$AUTHOR]/g; } if($MediaList[$index][$DOWNLOADS] ne "") { $ThumbDisplayFormat =~ s//$MediaList[$index][$DOWNLOADS]/g; } if($MediaList[$index][$DESCRIPTION] ne "") { $ThumbDisplayFormat =~ s//$MediaList[$index][$DESCRIPTION]/g; } if($MediaList[$index][$USER] ne "") { $ThumbDisplayFormat =~ s//$MediaList[$index][$USER]/g; } if($MediaList[$index][$IP] ne "") { $ThumbDisplayFormat =~ s//$MediaList[$index][$IP]/g; } for(my $counter = $FILENAME; $counter < @MediaFormat; $counter++) { if($MediaFormat[$counter]->{KEYWORD} ne "") { $ThumbDisplayFormat =~ s/$MediaFormat[$counter]->{KEYWORD}/$MediaList[$index][$counter]/g; } } $ThumbDisplayFormat =~ s//$link/g; return $ThumbDisplayFormat."\n\n"; } ######################################################################################## sub FullsizeHtml { my $DisplayName = $ShowData[$FILENAME]; if($ShowData[$FILENAME] =~ /^http:\/\//) { $baseimglink = $ShowData[$FILENAME]; my @temp = split(/\//, $ShowData[$FILENAME]); $DisplayName = $temp[-1]; } else { $baseimglink = "$MediaUrl$CategoryList[$CategoryIndex]->{PATH}media$slash$ShowData[$FILENAME]"; } ReadFileTypes(); if($ShowData[$TYPE] eq "Unknown") { $ShowData[$TYPE] = AssignType($ShowData[$FILENAME]); } if($FileCode{"$ShowData[$TYPE]"} ne "") { $code = $FileCode{"$ShowData[$TYPE]"}; } else { $code = $FileCode{"Image/GIF"}; } $code =~ s//$baseimglink/g; #Old code to just replace width #$code =~ s//width=\"$ShowData[$WIDTH]\"/g; #Old Code to replace height #$code =~ s//height=\"$ShowData[$HEIGHT]\"/g; #This new way replaces the with a attr parameter #it also allows the setting of a default attr if none is found. # Ex: is replaced with width="640" if width DNE. while($code =~ /^(.*?)(.*)$/) { my $line = $1; my(@default) = split(/=/, $2); if($ShowData[$WIDTH] ne "") { $code = $line."width=\"$ShowData[$WIDTH]\"".$3; } elsif($default[1] ne "") { #we have a default width... $code = $line."width=\"$default[1]\"".$3; } else { #no width at all, leave blank... $code = $line.$3; } } while($code =~ /^(.*?)(.*)$/) { my $line = $1; my(@default) = split(/=/, $2); if($ShowData[$HEIGHT] ne "") { $code = $line."height=\"$ShowData[$HEIGHT]\"".$3; } elsif($default[1] ne "") { #we have a default width... $code = $line."height=\"$default[1]\"".$3; } else { #no width at all, leave blank... $code = $line.$3; } } $ImageDisplayFormat = qq(\n
); $ImageDisplayFormat = $ImageDisplayFormat.$ImageDisplay; $ImageDisplayFormat =~ s//$code/g; $ImageDisplayFormat =~ s//$DisplayName/g; $ImageDisplayFormat =~ s//$ShowData[$FILESIZE]/g; $ImageDisplayFormat =~ s//$ShowData[$TYPE]/g; if($ShowData[$DATE] ne "") { my $tempdate = NormalDateTime($ShowData[$DATE]); $ImageDisplayFormat =~ s//$tempdate/g; } if($ShowData[$COPYRIGHT] ne "") { $ImageDisplayFormat =~ s//$ShowData[$COPYRIGHT]/g; } if($ShowData[$AUTHOR] ne "") { $ImageDisplayFormat =~ s//$ShowData[$AUTHOR]/g; } $ImageDisplayFormat =~ s//$ShowData[$DOWNLOADS]/g; if($ShowData[$DESCRIPTION] ne "") { $ImageDisplayFormat =~ s//$ShowData[$DESCRIPTION]/g; } if($ShowData[$USER] ne "") { $ImageDisplayFormat =~ s//$ShowData[$USER]/g; } if($ShowData[$IP] ne "") { $ImageDisplayFormat =~ s//$ShowData[$IP]/g; } for(my $counter = 0; $counter < @MediaFormat; $counter++) { if($MediaFormat[$counter]->{KEYWORD} ne "") { $ImageDisplayFormat =~ s/$MediaFormat[$counter]->{KEYWORD}/$MediaList[$index][$counter]/g; } } $ImageDisplayFormat = $ImageDisplayFormat.qq(
); return $ImageDisplayFormat; }