#!/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~
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 "showlogin") {
ShowLogin();
#We need to call exit here because ShowLogin doesn't call it.
exit;
} elsif($cgi->param("func") eq "login") {
my $rval = Login();
if($rval eq "true") {
WriteMessage("Welcome back $Username, you have been logged in.");
} elsif($rval eq "false") {
ShowLogin("You entered an incorrect password.");
exit;
}
} elsif($cgi->param("func") eq "logout") {
Logout();
} elsif($cgi->param("func") eq "showregister") {
ShowRegister();
#We need to call exit here because ShowRegister doesn't call it.
exit;
} 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();
#We need to call exit here to stop from displaying what's down below.
exit;
} elsif($cgi->param("func") eq "search") {
$SearchLink = "func=search&searchterm=".$cgi->param("searchterm")."&searchfield=".$cgi->param("searchfield")."&searchtype=".$cgi->param("searchtype");
if($cgi->param("searchterm")) {
require $ScriptPath.$slash."categories.cgi";
require $ScriptPath.$slash."media.cgi";
#initialize media
ReadCategories();
$searchterm = DecodeURL($cgi->param("searchterm"));
ReadMedia(-1, $searchterm, $cgi->param("searchfield"));
if(!@MediaList) {
FatalError(qq~Found 0 Results for '$searchterm'~);
}
ShowGallery();
} else {
ShowSearchForm();
}
#We need to call exit here because ShowGallery doesn't call it.
exit;
} 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();
#We need to call exit here to stop from displaying what's down below.
exit;
} 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[17]/ && $UserProfile[17] ne "" && $Username ne "") ||
($CategoryList[$CategoryIndex]->{USERS} =~ /$Username/ && $Username ne "")) {
$granted = "true";
}
} else {
$granted = "true";
}
if($granted eq "true" && GoodStartDate($CategoryList[$CategoryIndex]->{STARTDATE}) && GoodEndDate($CategoryList[$CategoryIndex]->{ENDDATE})) {
ShowMedia();
} else {
if($Username eq "" || $LoggedIn eq "false") {
ShowLogin("This is a restricted category, please login first.");
exit;
}
FatalError("You do not have permission to access this category.
");
}
} elsif($CategoryIndex < 0) {
require $ScriptPath.$slash."categories.cgi";
ReadCategories();
ShowCategoryListing();
} elsif($cgi->param("func") eq "plugin") {
#Run Plugins
$PluginName = $cgi->param("plugin");
$PluginCall = $cgi->param("call");
#if($PluginName eq "") {
# eval { require "$ScriptPath/plugins.cgi"; };
# LoadPlugins();
# if(@Plugins_Submit) {
# RunPlugins([@Plugins_Submit]);
# }
#} else {
eval { require $ScriptPath.$slash.$PluginName; };
if($@) { FatalError("Unable to include the specified plugin: $PluginName
Reason: $@"); }
eval { &$PluginCall(); };
#}
} 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[17]/ && $UserProfile[17] ne "" && $Username ne "") ||
($CategoryList[$CategoryIndex]->{USERS} =~ /$Username/ && $Username ne "")) {
$granted = "true";
}
} else {
$granted = "true";
}
if($granted eq "true" && GoodStartDate($CategoryList[$CategoryIndex]->{STARTDATE}) && GoodEndDate($CategoryList[$CategoryIndex]->{ENDDATE})) {
ReadMedia($CategoryIndex);
$CategoryPath = $MediaPath.$CategoryPath;
ShowGallery();
} else {
if($Username eq "" || $LoggedIn eq "false") {
ShowLogin("This is a restricted category, please login first.");
exit;
}
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 "") { $CategoryID = int($cgi->param("Category")); if(!@CategoryList) { require $ScriptPath.$slash."categories.cgi"; ReadCategories(); } $CategoryIndex = -1; for(my $counter = 0; $counter < @CategoryList; $counter++) { if($CategoryList[$counter]->{CATID} eq $CategoryID) { $CategoryIndex = $counter; } } if($CategoryIndex < 0) { $Category = "NONE"; } } else { $CategoryIndex = -1; if($cgi->param("func") eq "search") { $Category = "Search Results"; } else { $Category = "NONE"; } } } ######################################################################################## sub CategoryTree { if($cgi->param("searchterm")) { return; } if(!@CatTree) { BuildCatTree($CategoryIndex); } my($html) = qq~
|
~; for(my($counter) = 0; $counter < @CatTree; $counter++) { if ($CatTree[$counter]->{VISIBLE} eq "true" && GoodStartDate($CatTree[$counter]->{STARTDATE}) && GoodEndDate($CatTree[$counter]->{ENDDATE})) { for(my($index) = 0; $index < $CatTree[$counter]->{DEPTH}; $index++) { $html = $html." "; } if($CatTree[$counter]->{INDEX} == $cgi->param("Category")) { $html = $html.qq~ ~; } else { $html = $html.qq~ ~; } } } $html = $html.qq~ |
| Sub Categories: | |||
|
~;
if($counter == @SubCats - 1 && @SubCats % 2 == 1) {
$html = $html.qq~~; } if($counter % 2 == 1) { $html = $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~ |
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~| Prev $CategoryName $CategoryList[$previndex]->{NAME} | ~;
$width = "33%";
} else {
$width = "100%";
}
$PageNav = $PageNav.qq();
if($TotalPages >= $Page) {
$PageNav .= qq(Jump To Page: ); } else { $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~ Next $CategoryName $CategoryList[$nextindex]->{NAME} | ~;
}
$PageNav = $PageNav."
| Previous $PrevName | ~;
$PageNav = $PageNav.qq(Thumbnails | ); $PageNav = $PageNav.qq~Next $NextName | ~;
$PageNav = $PageNav."
| $CategoryName Listing: |
| Sorry, no categories exist yet. | ||
~;
if($CategoryList[$counter]->{IMAGE} ne "") {
$catimg = qq~
| ";
if($catcount % 2 == 1){
$html = $html."
No pictures available | );
$html = $html.qq(
);
$html = $html.qq(
| \n);
$stop = 1;
} else {
$html = $html.qq(\n\n); $html = $html.ThumbHTML($Index); $html = $html.qq( | \n); } } $html = $html.qq(
| ); $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}/$ShowData[$counter]/g; } } $ImageDisplayFormat = $ImageDisplayFormat.qq( |