#VERSION: 2.7.beta3c
#####################################################################
# This script is copyright (c)2002-2008 - 1001 Media Group. #
# Please do not distribute it without permission. #
#####################################################################
# __ __ #
# /\ \ /\ \ #
# ___ _____ ____\ \ \___ ___ _____\ \ \ #
# /'___\/\ '__`\ /',__\\ \ _ `\ / __`\/\ '__`\ \_\ #
# /\ \__/\ \ \L\ \/\__, `\\ \ \ \ \/\ \L\ \ \ \L\ \/_/_ #
# \ \____\\ \ ,__/\/\____/ \ \_\ \_\ \____/\ \ ,__/ /\_\ #
# \/____/ \ \ \/ \/___/ \/_/\/_/\/___/ \ \ \/ \/_/ #
# \ \_\ \ \_\ #
# \/_/ \/_/ #
# #
########### ports multiple CafePress stores to your server ##########
################ http://cgi.marty.net/scripts/cpshop/ ###############
#####################################################################
#####################################################################
#####################################################################
#####################################################################
#
# SUBROUTINES
#
#####################################################################
#####################################################################
#####################################################################
#####################################################################
sub prepare {
if (-e "${script_dir}cpdomain.txt") {
open(DOMAIN, "${script_dir}cpdomain.txt");
{ local $/; $cpdomain = ; }
close(DOMAIN);
$cpdomain =~ s/[^A-Za-z0-9\.]//g;
} else {
$cpdomain = "cafepress.com";
}
&debug;
&parseform;
&addtocart;
&genvars;
&predecision;
&uptodate;
$outputcachecrc = &crc32_calc($areainfo);
$outputcachefolder = substr($outputcachecrc,-2,2);
$outputcachefile = "$outputcachefolder/$main_script.oc.$outputcachecrc.data";
if (-d "${script_dir}cpoutput") {
unless (-d "${script_dir}$cpoutput/$outputcachefolder") {
mkdir("${script_dir}$cpoutput/$outputcachefolder");
}
}
if (-e "${script_dir}$cpoutput/$outputcachefile" && (-M "${script_dir}$cpoutput/$outputcachefile" < $expiretime)
&& !$nocache && (-e "${script_dir}$cpcache/$main_script.safe")) {
§ions("OUTPUT","${script_dir}$cpoutput/$outputcachefile");
$outputsidebarfolder = substr($OUTPUT{"sidebarid"},-2,2);
unless (-d "${script_dir}$cpoutput/$outputsidebarfolder") {
mkdir("${script_dir}$cpoutput/$outputsidebarfolder");
}
if ($OUTPUT{"sidebarid"} && (!-e "${script_dir}$cpoutput/$outputsidebarfolder/$main_script.oc." . $OUTPUT{"sidebarid"} . ".sb.data")) {
&decision;
&createhtml;
} else {
if ($OUTPUT{"sidebarid"}) {
open(SB,"<${script_dir}$cpoutput/$outputsidebarfolder/$main_script.oc." . $OUTPUT{"sidebarid"} . ".sb.data");
{ local $/; $sidebar = ; }
close(SB);
$sidebar =~ s/\[<\[pid]>]/$pid/g;
$sidebar =~ s/\[<\[xid]>]/$xid/g;
$sidebar =~ s/\[<\[tid]>]/$tid/g;
$sidebar =~ s/\[<\[cjpid]>]/$cjpid/g;
}
foreach $key(keys %OUTPUT) {
${$key} = $OUTPUT{$key};
${$key} =~ s/\[<\[pid]>]/$pid/g;
${$key} =~ s/\[<\[xid]>]/$xid/g;
${$key} =~ s/\[<\[tid]>]/$tid/g;
${$key} =~ s/\[<\[cjpid]>]/$cjpid/g;
}
if ($mypath) {
@mypath = split(/~mypath~/,$mypath);
foreach $mypathitem(@mypath) {
$INPATH{$mypathitem} = 1;
}
}
&get_filters($storeid);
}
} else {
&decision;
&createhtml;
}
}
sub gettemplate {
if ($productno) {
if ($FILTER{'prodtemplate'} && (($FILTER{'prodtemplate'} =~ /\.(htm|html|txt|tmpl|tpl|template)$/i) || ($FILTER{'prodtemplate'} =~ /template/i))) {
$template_to_use = $FILTER{'prodtemplate'};
$template_to_use =~ s/\.+/\./g;
} elsif ($productno && $inherited_prodtemplate && (($inherited_prodtemplate =~ /\.(htm|html|txt|tmpl|tpl|template)$/i) || ($inherited_prodtemplate =~ /template/i))) {
$template_to_use = $inherited_prodtemplate;
$template_to_use =~ s/\.+/\./g;
} elsif ($FILTER{'template'} && (($FILTER{'template'} =~ /\.(htm|html|txt|tmpl|tpl|template)$/i) || ($FILTER{'template'} =~ /template/i))) {
$template_to_use = $FILTER{'template'};
$template_to_use =~ s/\.+/\./g;
} elsif ($SECTION{'HTMLproducttemplate'} && (-e $SECTION{'HTMLproducttemplate'} || -e "${script_dir}$SECTION{'HTMLproducttemplate'}" || ($SECTION{'HTMLproducttemplate'} =~ /^(http|nocache):\/\//i))) {
$template_to_use = $SECTION{'HTMLproducttemplate'};
} elsif ($inherited_template && (($inherited_template =~ /\.(htm|html|txt|tmpl|tpl|template)$/i) || ($inherited_template =~ /template/i))) {
$template_to_use = $inherited_template;
$template_to_use =~ s/\.+/\./g;
} elsif ($SECTION{'HTMLtemplate'}) {
$template_to_use = $SECTION{'HTMLtemplate'};
}
} elsif ($storeid) {
if ($FILTER{'template'} && (($FILTER{'template'} =~ /\.(htm|html|txt|tmpl|tpl|template)$/i) || ($FILTER{'template'} =~ /template/i))) {
$template_to_use = $FILTER{'template'};
$template_to_use =~ s/\.+/\./g;
} elsif ($SECTION{'HTMLstoretemplate'} && (($number_of_stores > 1) || $areainfo) && (-e $SECTION{'HTMLstoretemplate'} || -e "${script_dir}$SECTION{'HTMLstoretemplate'}" || ($SECTION{'HTMLstoretemplate'} =~ /^(http|nocache):\/\//i))) {
$template_to_use = $SECTION{'HTMLstoretemplate'};
} elsif ($inherited_template && (($inherited_template =~ /\.(htm|html|txt|tmpl|tpl|template)$/i) || ($inherited_template =~ /template/i))) {
$template_to_use = $inherited_template;
$template_to_use =~ s/\.+/\./g;
} elsif ($SECTION{'HTMLtemplate'}) {
$template_to_use = $SECTION{'HTMLtemplate'};
}
} else {
if ($SECTION{'HTMLtemplate'}) {
$template_to_use = $SECTION{'HTMLtemplate'};
}
}
if ($template_to_use) {
if (-e "${script_dir}$template_to_use") {
$template_to_use = "${script_dir}$template_to_use";
}
if ($template_to_use =~ m|^http://|i) {
$getting_template = 1;
$html = &getit("",$template_to_use);
$getting_template = 0;
} elsif ($template_to_use =~ m|^nocache://|i) {
$getting_template = 1;
$template_to_use =~ s|^nocache://|http://|i;
$html = &getit("",$template_to_use,"nocache");
$getting_template = 0;
} elsif ($template_to_use && !-d $template_to_use) {
open(TEMPLATE,"<$template_to_use");
{ local $/; $html = ; }
close(TEMPLATE);
}
if (!$html) {
&badtemplate;
}
}
if (!$html) {
&dt;$dt=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;$html=$dt;
}
if ($SECTION{'GetHooks'} eq "yes") {
$html = gethooks($html);
$content = gethooks($content);
} else {
$html =~ s/<\[hook:\w+\]>//g;
$content =~ s/<\[hook:\w+\]>//g;
}
$html =~ s/\<\[content\]\>/<\[content\]>/;
$html =~ s/\<\[title\]\>/<\[title\]>/;
$html =~ s/\<\[pagetitle\]\>/<\[pagetitle\]>/;
$html =~ s/\<\[sidebar\]\>/<\[sidebar\]>/;
$html =~ s/\<\[breadcrumb\]\>/<\[breadcrumb\]>/;
$html =~ s/\<\[prev\]\>/<\[prev\]>/;
$html =~ s/\<\[prevname\]\>/<\[prevname\]>/;
$html =~ s/\<\[next\]\>/<\[next\]>/;
$html =~ s/\<\[nextname\]\>/<\[nextname\]>/;
$html =~ s/\<\[storeid\]\>/<\[storeid\]>/;
$html =~ s/\<\[productnumber\]\>/<\[productnumber\]>/;
$html =~ s/\<\[productno\]\>/<\[productno\]>/;
$html =~ s/\<\[productname\]\>/<\[productname\]>/;
$html =~ s/\<\[sectiondesc\]\>/<\[sectiondesc\]>/;
$html =~ s/\<\[storename\]\>/<\[storename\]>/;
$html =~ s/\<\[cpshop\]\>/<\[cpshop\]>/;
$html =~ s/\<\[cart\]\>/<\[cart\]>/;
$html =~ s/\<\[alias\]\>/<\[alias\]>/;
$html =~ s/\<\[keywords\]\>/<\[keywords\]>/;
$html =~ s/\<\[description\]\>/<\[description\]>/;
$html =~ s/\<\[pid\]\>/<\[pid\]>/;
$html =~ s/\<\[xid\]\>/<\[xid\]>/;
$html =~ s/\<\[tid\]\>/<\[tid\]>/;
$html =~ s/\<\[cjpid\]\>/<\[cjpid\]>/;
$html =~ s/<\[pagetitle\]>/$pagetitle/g;
$html =~ s/<\[breadcrumb\]>/$breadcrumb/g;
$html =~ s/<\[prev\]>/$prev/g;
$html =~ s/<\[prevname\]>/$prevname/g;
$html =~ s/<\[next\]>/$next/g;
$html =~ s/<\[nextname\]>/$nextname/g;
$html =~ s/<\[storeid\]>/$storeid/g;
$html =~ s/<\[productnumber\]>/$productnumber/g;
$html =~ s/<\[productno\]>/$productno/g;
$html =~ s/<\[productname\]>/$productname/g;
$html =~ s/<\[sectiondesc\]>/$sectiondesc/g;
$html =~ s/<\[storename\]>/$TITLE{$storeid}/g;
$html =~ s/<\[cpshop\]>/$main_script/g;
$html =~ s/<\[cart\]>/$cart/g;
$html =~ s/<\[alias\]>/$STORE_CRC{$storeid}/g;
$html =~ s/<\[sidebar\]>/$sidebar/g;
if ($storeid && $KEYS{$storeid}) {
$html =~ s/<\[keywords\]>/$KEYS{$storeid}/g;
} else {
$html =~ s/<\[keywords\]>/$SECTION{'DefaultKeywords'}/g;
}
if ($storeid && $DESC{$storeid}) {
$html =~ s/<\[description\]>/$DESC{$storeid}/g;
} else {
$html =~ s/<\[description\]>/$SECTION{'DefaultDescription'}/g;
}
$html =~ s/\[<\[pid]>]/$pid/g;
$html =~ s/\[<\[xid]>]/$xid/g;
$html =~ s/\[<\[tid]>]/$tid/g;
$html =~ s/\[<\[cjpid]>]/$cjpid/g;
#remove any unused tags
#$html =~ s/<\[title\]>/<\[\*title\*\]>/g;
#$html =~ s/<\[breadcrumb\]>/<\[\*breadcrumb\*\]>/g;
#$html =~ s/<\[content\]>/<\[\*content\*\]>/g;
#$html =~ s/<\[\w+\]>//g;
#$html =~ s/<\[\*title\*\]>/<\[title\]>/g;
#$html =~ s/<\[\*breadcrumb\*\]>/<\[breadcrumb\]>/g;
#$html =~ s/<\[\*content\*\]>/<\[content\]>/g;
}
sub gethooks {
#<[hook:cpfooter]>
#cphooks/cpshop.cgi.pno.5987654.footer.txt
#cphooks/cpshop.cgi.type.24.footer.txt
#cphooks/cpshop.cgi.sno.12345.footer.txt
#cphooks/cpshop.cgi.alias.myalias.footer.txt
#cphooks/cpshop.cgi.sid.buydotorg.footer.txt
#cphooks/cpshop.cgi.all.footer.txt
my $hookhtml = $_[0];
while ($hookhtml =~ /<\[hook:(\w+)\]>/) {
my $hookname = $1;
$hookcode = "";
$hookfile = "";
if (($target || $buildinggrid) && -e "${script_dir}cphooks/${main_script}.pno.$productnumber.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.pno.$productnumber.$hookname.txt";
} elsif (($target || $buildinggrid) && -e "${script_dir}cphooks/${main_script}.pno.$productno.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.pno.$productno.$hookname.txt";
} elsif (($target || $buildinggrid) && -e "${script_dir}cphooks/${main_script}.type.$producttypeno.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.type.$producttypeno.$hookname.txt";
} elsif (($target || $buildinggrid) && -e "${script_dir}cphooks/${main_script}.pno.all.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.pno.all.$hookname.txt";
} elsif ($sectionno && -e "${script_dir}cphooks/${main_script}.sno.$sectionno.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.sno.$sectionno.$hookname.txt";
} elsif ($target && $productsectionno && -e "${script_dir}cphooks/${main_script}.sno.$productsectionno.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.sno.$productsectionno.$hookname.txt";
} else {
$hookfile = "";
}
if (!$hookfile) {
foreach $key(keys %INPATH) {
my ($pathid,$pathno) = split(/\//,$key,2);
if (-e "${script_dir}cphooks/${main_script}.sno.$pathno.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.sno.$pathno.$hookname.txt";
last;
}
}
}
if (!$hookfile) {
if (-e "${script_dir}cphooks/${main_script}.alias.$STORE_CRC{$storeid}.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.alias.$STORE_CRC{$storeid}.$hookname.txt";
} elsif (-e "${script_dir}cphooks/${main_script}.sid.$realstoreid.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.sid.$realstoreid.$hookname.txt";
} elsif (-e "${script_dir}cphooks/${main_script}.all.$hookname.txt") {
$hookfile = "${script_dir}cphooks/${main_script}.all.$hookname.txt";
} else {
$hookfile = "";
}
}
if ($hookfile) {
open(HOOK,$hookfile);
{ local $/; $hookcode = ; }
close(HOOK);
}
$hookhtml =~ s/<\[hook:$hookname\]>/$hookcode/;
}
return $hookhtml;
}
sub badtemplate {
&texthtml;
print qq(cpshop is trying to use $template_to_use as your template, but isn\'t able to.
);
if ($template_to_use =~ m|^http://|i) {
print qq(The reason may be because that URL does not exist, or the server is not responding. Perhaps you misentered it?
);
} elsif (!-e $template_to_use) {
print qq(It appears that the file doesn\'t exist on your server. Perhaps you should double-check
that the path to the file is correct.
);
}
exit;
}
sub createhtml {
$temp_content = <<"ENDHTML";
$setcookie
ENDHTML
if (($number_of_stores > 1) && $storeid) {
$prev_storenumber = $STORE_NUMBER{$storeid} - 1;
if ($prev_storenumber < 0) {
$prev_storenumber = $number_of_stores - 1;
}
$next_storenumber = $STORE_NUMBER{$storeid} + 1;
if ($next_storenumber > ($number_of_stores - 1)) {
$next_storenumber = "0";
}
unless ($SECTION{'prevlink'}) {
$SECTION{'prevlink'} = $LANG{'prev design'};
}
unless ($SECTION{'nextlink'}) {
$SECTION{'nextlink'} = $LANG{'next design'};
}
$prev = qq(<< $SECTION{'prevlink'});
$prevname = qq(<< $TITLE{$idlist[$prev_storenumber]});
$next = qq($SECTION{'nextlink'} >>);
$nextname = qq($TITLE{$idlist[$next_storenumber]} >>);
if ($SECTION{'ShowPrevNextLinks'} eq "full") {
$show_prev = qq($prevname | );
$show_next = qq( | $nextname);
} elsif ($SECTION{'ShowPrevNextLinks'} ne "none") {
$show_prev = qq($prev | );
$show_next = qq( | $next);
}
}
if (($SECTION{'ShowLinkBar'} ne "no") && ( $SECTION{'cartlink'} || $SECTION{'morelink'} || $show_prev || $show_next )) {
$temp_content .= <<"ENDHTML";
| $fontstart
ENDHTML
if ($target || ($storeid && (($number_of_stores > 1) || $sectionno))) {
$temp_content .= <<"ENDHTML";
$show_prev $SECTION{'homelink'}
ENDHTML
if ($SECTION{'cartlink'}) {
$temp_content .= " | ";
}
}
if ($SECTION{'cartlink'}) {
$temp_content .= qq($cart);
}
if ($SECTION{'morelink'}) {
if ($SECTION{'cartlink'} || $target || ($storeid && ($number_of_stores > 1))) {
$temp_content .= " | ";
}
$temp_content .= qq( $SECTION{'morelink'} );
}
if ($target || $storeid) {
$temp_content .= <<"ENDHTML";
$show_next
ENDHTML
}
$temp_content .= <<"ENDHTML";
$fontend |
ENDHTML
}
# PAGE TYPE: PRODUCTDETAIL ######################################################################
if ($target) {
$temp_content .= <<"ENDHTML";
ENDHTML
if ($SECTION{'OrderFormOnRight'} eq "yes") {
$temp_content .= <<"ENDHTML";
ENDHTML
}
if ($SECTION{'zoomtext'}) {
$SECTION{'zoomtext'} = "$SECTION{'zoomtext'}\n";
}
if ($SECTION{'ShowStoreCaptionOnProduct'} eq "yes") {
$show_store_comment = " $COMMENT{$storeid}";
}
$mybreadcrumb = &getbreadcrumb("product");
if ($SECTION{'ShowBreadCrumb'} ne "no") {
$show_breadcrumb = $mybreadcrumb;
}
$temp_content .= <<"ENDHTML";
$fontstart
$show_breadcrumb$show_store_comment$SECTION{'zoomtext'}$fontend
ENDHTML
if ($SECTION{'ShowHorizontalLines'} ne "no") {
$temp_content .= <<"ENDHTML";
ENDHTML
}
# PAGE TYPE: FILE ################################################################################
} elsif (($STORE_TYPE{$storeid} eq "file") && $STORE_FILE{$storeid}) {
$mybreadcrumb = &getbreadcrumb("section");
&commonscripts;
if ($SECTION{'ShowBreadCrumb'} ne "no") {
$show_breadcrumb = $mybreadcrumb;
}
$temp_content .= <<"ENDHTML";
$commonscripts
$fontstart
$show_breadcrumb
$fontend
ENDHTML
if ($SECTION{'ShowHorizontalLines'} ne "no") {
$temp_content .= <<"ENDHTML";
ENDHTML
}
# PAGE TYPE: STOREID #############################################################################
} elsif ($storeid) {
if ($COMMENT{$storeid} && !$prodstore) {
$showstorecomment = "";
}
if ($storeid && ($number_of_stores == 1) && !$sectionno && ($STORE_TYPE{$storeid} eq "store")) {
$clickfor = "";
} elsif ($SECTION{'ThumbnailGreetingLevel'} eq "advanced") {
if ($hasproductthumbs && $hassectionthumbs) {
$clickfor = "$SECTION{'ThumbnailGreetingBoth'} ";
} elsif ($hasproductthumbs) {
$clickfor = "$SECTION{'ThumbnailGreetingProductsOnly'} ";
} elsif ($hassectionthumbs) {
$clickfor = "$SECTION{'ThumbnailGreetingSectionsOnly'} ";
}
} elsif ($SECTION{'clickfor'}) {
$clickfor = "$SECTION{'clickfor'} ";
}
if ($SECTIONINFO{'section_description'}) {
$sectiondesc = qq($SECTIONINFO{'section_description'} );
}
if ($SECTION{'ShowSectionDescriptions'} ne "no") {
$showsectiondesc = $sectiondesc;
}
$mybreadcrumb = &getbreadcrumb("section");
if ($SECTION{'ShowBreadCrumb'} ne "no") {
$show_breadcrumb = $mybreadcrumb;
}
$temp_content .= <<"ENDHTML";
$fontstart
$show_breadcrumb$showstorecomment$showsectiondesc$clickfor
$fontend
ENDHTML
if ($SECTION{'ShowHorizontalLines'} ne "no") {
$temp_content .= <<"ENDHTML";
ENDHTML
}
# PAGE TYPE: HOMEPAGE ###############################################################################
} else {
&loadsectiondata; #justincase
&commonscripts;
$mybreadcrumb = &getbreadcrumb("home");
if ($SECTION{'ShowBreadCrumb'} ne "no") {
$show_breadcrumb = $mybreadcrumb;
}
$temp_content .= <<"ENDHTML";
$commonscripts
$fontstart
$show_breadcrumb$SECTION{'greeting'}
$fontend
ENDHTML
if ($SECTION{'ShowHorizontalLines'} ne "no") {
$temp_content .= <<"ENDHTML";
ENDHTML
}
}
# END PAGE TYPES ####################################################################################
if ($storeid && ($number_of_stores == 1) && !$target && !$sectionno && ($STORE_TYPE{$storeid} eq "store") && ($HIDE{$storeid} ne "hide")) {
$temp_content .= $SECTION{'greeting'};
}
if ($SECTION{'MainInsertFile'} && -e $SECTION{'MainInsertFile'} && ($storeid && ($number_of_stores == 1) && !$target && !$sectionno) && ($HIDE{$storeid} ne "hide")) {
&getinsertfile;
}
$temp_content .= <<"ENDHTML";
$content
ENDHTML
if ($SECTION{'ShowHorizontalLines'} ne "no") {
$temp_content .= <<"ENDHTML";
ENDHTML
}
if ($SECTION{'OpenNewCreditWindow'} eq "yes") {
$credit_newwindow = " target=_blank";
}
($refer_storeid,$crap) = split(/\,/,$idlist[0]); $c = qq($fontstart$LANG{'powered by'} CafePress & cpshop$fontend);$c=q()if(-e"credit.hide"||-e"${script_dir}/credit.hide");
$temp_content .= <<"ENDHTML";
|
$c
ENDHTML
$content = qq(\n);
$content .= $temp_content;
# Process image replacement file: $main_script.images
$content = &swap_images($content);
if ($SECTION{'Maintenance'}) {
$content = qq($LANG{'Maintenance Message'});
}
&log;
$mypath = join "~mypath~", @mypath;
@outputkeys = qw(pagetitle breadcrumb content prev prevname next nextname
storeid productnumber productno producttypeno productname sectiondesc
cpshop cart sidebarid productsectionno sectionno realstoreid mypath);
if (-d "${script_dir}$cpoutput" && -w "${script_dir}$cpoutput") {
if (-e "${script_dir}$cpcache/$main_script.safe" && ((!-e "${script_dir}$cpcache/$main_script.loading.txt") || (-M "${script_dir}$cpcache/$main_script.loading.txt" > 0.5))) {
if ($sidebar) {
$sidebarid = &crc32_calc($sidebar);
$sidebarfolder = substr($sidebarid,-2,2);
unless (-d "${script_dir}$cpoutput/$sidebarfolder") {
mkdir("${script_dir}$cpcache/$sidebarfolder");
}
$outputcachesidebarfile = "$sidebarfolder/$main_script.oc.$sidebarid.sb.data";
open(SB,">${script_dir}$cpoutput/$outputcachesidebarfile");
print SB $sidebar;
close(SB);
}
open(OC,">${script_dir}$cpoutput/$outputcachefile");
foreach $outputkey(@outputkeys) {
print OC "<<>>\n";
print OC "$outputkey\n";
print OC ${$outputkey} . "\n";
}
close(OC);
}
if ($SECTION{'MaxOutputCacheSize'} > 0) {
opendir(CACHE,"${script_dir}$cpoutput");
@cachefolders = readdir(CACHE);
closedir(CACHE);
chomp @cachefolders;
foreach $cachefolder(@cachefolders) {
next unless (($cachefolder > 9) && ($cachefolder < 100));
opendir(CACHE,"${script_dir}$cpoutput/$cachefolder");
@cachetemp = readdir(CACHE);
closedir(CACHE);
chomp @cachetemp;
foreach $cachefile(@cachetemp) {
next unless $cachefile =~ /^$main_script\.oc/;
$OCFOLDER{$cachefile} = $cachefolder;
$OCFILESIZE{$cachefile} = -s "${script_dir}$cpoutput/$cachefolder/$cachefile";
$OCFILEDATE{$cachefile} = -M "${script_dir}$cpoutput/$cachefolder/$cachefile";
}
}
$maxocsize = $SECTION{'MaxOutputCacheSize'} * 1024 * 1000;
foreach $cachefile(sort { $OCFILEDATE{$b} <=> $OCFILEDATE{$a} } keys %OCFILEDATE) {
$ocsize += $OCFILESIZE{$cachefile};
if ($ocsize > $maxocsize) {
unlink("${script_dir}$cpoutput/$OCFOLDER{$cachefile}/$cachefile");
delete $OCFILESIZE{$cachefile};
}
}
}
}
foreach $outputkey(@outputkeys) {
${$outputkey} =~ s/\[<\[pid\]>\]/$pid/g;
${$outputkey} =~ s/\[<\[xid\]>\]/$xid/g;
${$outputkey} =~ s/\[<\[tid\]>\]/$tid/g;
${$outputkey} =~ s/\[<\[cjpid\]>\]/$cjpid/g;
}
} #### end sub createhtml
###############################################################################################################################################
###############################################################################################################################################
###############################################################################################################################################
###############################################################################################################################################
###############################################################################################################################################
sub swap_images {
my $data = $_[0];
if (!$swapped) {
if (-e "${script_dir}$main_script.images") {
open(FILE,"${script_dir}$main_script.images");
my @lines = ;
close(FILE);
chomp @lines;
foreach $line(@lines) {
next if $line =~ /^\#/;
next if $line =~ /^\s*$/;
$line =~ s/[\r\n]//g;
my ($id,$from,$to) = split(/\|\|\|\|/,$line,3);
next unless $id;
next unless $from;
$SWAP{$id} .= qq(\0$from||||$to);
}
if ($SWAP{'*'}) {
$swaplines = $SWAP{'*'};
}
if ($SWAP{$STORE_CRC{$storeid}}) {
$swaplines .= $SWAP{$STORE_CRC{$storeid}};
} elsif ($SWAP{$storeid}) {
$swaplines .= $SWAP{$storeid};
}
}
}
if ($swaplines) {
$swaplines =~ s/^\0//;
@swaplines = split(/\0/,$swaplines);
foreach $swapline(@swaplines) {
my ($from,$to) = split(/\|\|\|\|/,$swapline,2);
$data =~ s/$from/$to/g;
}
}
$swapped = 1;
return $data;
}
sub log {
my $ignoreme;
if ($SECTION{'IgnoreIPs'} && $ENV{'REMOTE_ADDR'}) {
$SECTION{'IgnoreIPs'} =~ s/[^\d\.\,]//g;
my @ignoreips = split(/\,/,$SECTION{'IgnoreIPs'});
my $ignoreip;
foreach $ignoreip(@ignoreips) {
if ($ENV{'REMOTE_ADDR'} =~ /^$ignoreip/) {
$ignoreme = 1;
}
last if $ignoreme;
}
}
if ($SECTION{'IgnoreBots'} eq "yes") {
if ($ENV{'HTTP_USER_AGENT'} =~ /^(msnbot|Slurp|CCV Search|Googlebot|gsa-crawler|ia_archiver|BusyBot|Gigabot|MJ12bot|PycURL|ScanAlert|exabot|singingfish|becomebot|converacrawler|twiceler|crawler|WebCopier)/i) {
$ignoreme = 1;
}
}
if (!$ignoreme && -d "${script_dir}cplogs" && -w "${script_dir}cplogs" && ($SECTION{'Logging'} ne "none")) {
my @time_array = localtime(time);
my $this_day = $time_array[3];
my $this_month = $time_array[4] + 1;
my $this_year = $time_array[5] + 1900;
if (length($this_month) == 1) {
$this_month = "0$this_month";
}
my $last_month = $this_month - 1;
my $last_year = $this_year;
if ($last_month == 0) {
$last_month = 12;
$last_year--;
}
if (length($last_month) == 1) {
$last_month = "0$last_month";
}
my $this_time = localtime(time);
my $this_log = "${script_dir}cplogs/$main_script.$this_year.$this_month.log";
# my $last_log = "${script_dir}cplogs/$main_script.$last_year.$last_month.log";
# Log Format:
# /cplogs/month.dat -> year|month|total_uniques|total_pageviews
# /cplogs/total.dat -> cumulative_uniques|cumulative_pageviews
# /cplogs/[year].[month].dat
# simple logging -> one character per pageview (H/h-home;T/t-thumb;P/p-product;O/o-other - caps=entry point)
# detail logging -> date|ip_address|storeid|productnumber|productname|referring_page_url
if ($ENV{'HTTP_REFERER'}) {
if ($ENV{'HTTP_REFERER'} !~ /$ENV{'HTTP_HOST'}/) {
$this_referer = $ENV{'HTTP_REFERER'};
$entry_point = 1;
}
} else {
$entry_point = 1;
$this_referer = "entry";
}
if ($target) {
$log_producttype = $producttype;
}
if ($STORE_ALIAS{$storeid}) {
$log_storeid = $STORE_ALIAS{$storeid};
} else {
$log_storeid = $storeid;
}
open(LOG,">>$this_log");
if ($SECTION{'Logging'} eq "detail") {
print LOG qq($this_year/$this_month/$this_day|$ENV{'REMOTE_ADDR'}|$log_storeid|$productno|$log_producttype|$this_referer\n);
} else {
if ($target) {
$log_letter = "p";
} elsif ($storeid) {
$log_letter = "t";
} else {
$log_letter = "h";
}
if ($entry_point) {
$log_letter =~ tr/a-z/A-Z/;
}
print LOG qq($log_letter\n);
}
}
}
sub getinsertfile {
open(MAINPAGE,"<$SECTION{'MainInsertFile'}");
{ local $/; $content = ; }
close(MAINPAGE);
}
sub makehome {
if (($storeurl ne $scripturl) && ($SECTION{'IncludeHome'} eq "no")) {
&setcookies(1);
print "Location: $storeurl\n\n";
exit;
}
if ($SECTION{'MainInsertFile'} && -e $SECTION{'MainInsertFile'}) {
&getinsertfile;
} else {
foreach $mystoreid(@idlist) {
next if $HIDE{$mystoreid} eq "hide";
push @homeidlist, $mystoreid;
}
@todolist = @homeidlist;
if ((($SECTION{'HomeTableMaxRows'} * $SECTION{'HomeCols'}) < @idlist) && ($SECTION{'HomeTableMaxRows'} > 0)) {
$homethumbstart = ($SECTION{'HomeTableMaxRows'} * $SECTION{'HomeCols'} * ($page - 1));
if ($homethumbstart <= @homeidlist) {
$totalpages = int(@homeidlist / ($SECTION{'HomeTableMaxRows'} * $SECTION{'HomeCols'}));
if ((@homeidlist / ($SECTION{'HomeTableMaxRows'} * $SECTION{'HomeCols'})) > $totalpages) {
$totalpages++;
}
@todolist = splice(@todolist,$homethumbstart,$SECTION{'HomeTableMaxRows'} * $SECTION{'HomeCols'});
$pagelinks = &get_page_links($page,$totalpages,"$scripturl$cleanurl-/-/-");
$pagelinks_top = qq(| $fontstart$pagelinks$fontend |
);
$pagelinks_bottom = qq(
| $fontstart$pagelinks$fontend |
);
}
}
$content = qq($pagelinks_top);
if ($SECTION{'HideGridTable'} eq "hide") {
$content .= $SECTION{'gridheader'};
} else {
$content .= qq();
}
if ($SECTION{'HomeTableRowsColumns'} eq "rows") {
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq(\n);
}
$colcounter = 0;
while(@todolist) {
$colcounter++;
#if (($colcounter % $SECTION{'HomeCols'} == 1) || ($SECTION{'HomeCols'} == 1)) {
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= "\n";
}
#}
$i = 0;
@proclist = ();
for ($i=0;$i<$SECTION{'HomeCols'};$i++) {
if (@todolist) {
push @proclist, shift(@todolist);
}
}
if ($hashomethumbs) {
for ($i=0;$i<@proclist;$i++) {
my $storeid = $proclist[$i];
$LINE{'linksrc'} = qq($scripturl$cleanurl$STORE_CRC{$storeid});
$LINE{'linkstarts'} = qq();
$LINE{'thumbnail'} = qq( );
$LINE{'thumbsrc'} = $HOMETHUMB{$storeid};
$LINE{'storename'} = $TITLE{$storeid};
$LINE{'linkends'} = qq();
$LINE{'storeid'} = $STORE_CRC{$storeid};
$LINE{'teaser'} = "";
$LINE{'parentsectionno'} = "";
$LINE{'alias'} = $STORE_CRC{$storeid};
$LINE{'sectionstoreid'} = "";
my $cell = $SECTION{'homecelltemplate'};
if ($SECTION{'GetHooks'} eq "yes") {
$buildinggrid = 1;
$cell = gethooks($cell);
$buildinggrid = 0;
} else {
$cell =~ s/<\[hook:\w+\]>//g;
}
if (!$HOMETHUMB{$storeid}) {
$cell =~ s/<\[thumbnail\]>//g;
}
$cell =~ s/<\[(.*?)\]>/$LINE{$1}/g;
my $dimensions = qq(height="$SECTION{'thumbheight'}" width="$SECTION{'thumbwidth'}");
$cell =~ s/height="150" width="150"/$dimensions/;
$content .= $cell;
}
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= " ";
}
} else {
for ($i=0;$i<@proclist;$i++) {
my $storeid = $proclist[$i];
$content .= qq();
$content .= qq($fontstart$TITLE{$storeid}$fontend);
$content .= qq( | );
}
}
}
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= " | \n";
}
} else {
if ($totalpages > 1) {
$local_number_of_stores = $SECTION{'HomeCols'} * $SECTION{'HomeTableMaxRows'};
} else {
$local_number_of_stores = $number_of_stores;
}
$number_per_column = $local_number_of_stores / $SECTION{'HomeCols'};
if ($local_number_of_stores % $SECTION{'HomeCols'}) {
$fixpoint = $local_number_of_stores % $SECTION{'HomeCols'};
$number_per_column = int($number_per_column) + 1;
}
$colcounter = 0;
while(($colcounter < $SECTION{'HomeCols'}) && @todolist) {
$colcounter++;
$idcounter = 0;
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq();
}
while($idcounter < $number_per_column) {
$idcounter++;
my $storeid = shift(@todolist);
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq();
}
if ($HOMETHUMB{$storeid} || ($SECTION{'HideGridTable'} eq "hide")) {
$LINE{'linksrc'} = qq($scripturl$cleanurl$STORE_CRC{$storeid});
$LINE{'linkstarts'} = qq();
$LINE{'thumbnail'} = qq( );
$LINE{'thumbsrc'} = $HOMETHUMB{$storeid};
$LINE{'storename'} = $TITLE{$storeid};
$LINE{'linkends'} = qq();
$LINE{'storeid'} = $STORE_CRC{$storeid};
$LINE{'teaser'} = "";
$LINE{'parentsectionno'} = "";
$LINE{'alias'} = $STORE_CRC{$storeid};
$LINE{'sectionstoreid'} = "";
my $cell = $SECTION{'homecelltemplate'};
if ($SECTION{'GetHooks'} eq "yes") {
$buildinggrid = 1;
$cell = gethooks($cell);
$buildinggrid = 0;
} else {
$cell =~ s/<\[hook:\w+\]>//g;
}
if (($SECTION{'HideGridTable'} eq "hide") && !$HOMETHUMB{$storeid}) {
$cell =~ s/<\[thumbnail\]>//g;
}
$cell =~ s/<\[(.*?)\]>/$LINE{$1}/g;
my $dimensions = qq(height="$SECTION{'thumbheight'}" width="$SECTION{'thumbwidth'}");
$cell =~ s/height="150" width="150"/$dimensions/;
$content .= $cell;
} else {
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq();
}
$content .= qq($fontstart$TITLE{$storeid}$fontend);
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq( | );
}
}
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq( \n);
}
}
$idcounter = 0;
if ($colcounter == $fixpoint) {
$number_per_column--;
}
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq( | );
}
if (@todolist) {
unless ($SECTION{'HideGridTable'} eq "hide") {
$content .= qq( | );
}
}
}
}
if ($SECTION{'HideGridTable'} eq "hide") {
$content .= $SECTION{'gridfooter'};
} else {
$content .= qq(
);
}
$content .= qq($pagelinks_bottom);
}
}
sub parseform {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} .= '\0' if (defined($FORM{$name}));
$FORM{$name} .= $value;
}
}
sub js {
print "Content-Type: application/x-javascript\n\n";
print <<"ENDJS";
function QueryString(key)
{
var value = null;
for (var i=0;i= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}
QueryString_Parse();
function validFormat(regex, str) {
return regex.test(str);
}
var loadit = QueryString("loadit");
if ((loadit == null) && (thisIsStore == 1)) {
if (window.name == "cartWin") {
window.close();
} else {
location="$storeurl";
}
}
ENDJS
exit;
}
sub cleanlines {
$var = $SECTION{'StoreIDs'};
$var =~ s/^\s+//;
$var =~ s/\s+$//;
$var =~ s/\[([^\,]+?)\]/cpfilter_$1/g;
my @var = split(/\s*\r?\n\s*/,$var);
my $line;
$noname_counter = "1";
foreach $line(@var) {
my($line1,$line2,$line3,$line4,$line5,$line6,$line7,$line8,$line9,$line10,$line11,$line12,$crap) = split(/\s*\|\|\|\|\s*/,$line,13);
next unless ($line1 || $line10 || $line11);
unless ($line2) {
$line2 = "Miscellaneous Stuff $noname_counter";
$noname_counter++;
}
$line3 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$line4 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$line5 =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if (!$line9) { $line9 = "store"; }
if ($line9 eq "file") {
$linekey = "cpfile:$line10";
$line1 = "cpfile:$line10";
} elsif ($line9 eq "url") {
$linekey = "cpurl:$line11";
$line1 = "cpurl:$line11";
} else {
$linekey = $line1;
}
$TITLE{$linekey} = $line2;
$COMMENT{$linekey} = $line3;
$KEYS{$linekey} = $line4;
$DESC{$linekey} = $line5;
$CODE{$linekey} = $line6;
if ($line7 ne "") {
$HOMETHUMB{$linekey} = $line7;
}
if ($line8 ne "") {
$HIDE{$linekey} = $line8;
}
if ($line9 eq "") {
$STORE_TYPE{$linekey} = "store";
$STORE_TYPE{$line6} = "store";
} else {
$STORE_TYPE{$linekey} = $line9;
$STORE_TYPE{$line6} = $line9;
}
if ($line10 ne "") {
$STORE_FILE{$linekey} = $line10;
}
if ($line11 ne "") {
$STORE_URL{$linekey} = $line11;
$STORE_URL{$line6} = $line11;
}
if ($line12 ne "") {
$STORE_MASK{$linekey} = $line12;
$STORE_MASK{$line6} = $line12;
}
$HTMLTITLE{$linekey} = $TITLE{$linekey};
$TITLE{$linekey} =~ s//$1/g;
$TITLE{$linekey} =~ s/<.*?>//g;
$TITLE{$linekey} =~ s|\"|\"|g;
$TITLE{$linekey} =~ s|<|\<|g;
$TITLE{$linekey} =~ s|>|\>|g;
if ($line6) {
$STORE_CRC_ID{$line6} = $linekey;
$STORE_CRC{$linekey} = $line6;
$STORE_ALIAS{$linekey} = $line6;
} else {
my $crc = &crc32_calc($linekey);
$STORE_CRC_ID{$crc} = $linekey;
$STORE_CRC{$linekey} = $crc;
}
push @idlist, $linekey;
}
}
sub getbreadcrumb {
my $bctype = $_[0];
my @breadcrumb;
$breadcrumb = "";
if ($bctype eq "product") {
unshift(@breadcrumb,qq($productname));
} elsif ($bctype eq "section") {
if ($realstoreid && $sectionno) {
unshift(@breadcrumb,qq($SNAMES{"$realstoreid/$sectionno"}));
unshift(@mypath, "$realstoreid/$sectionno");
$INPATH{"$realstoreid/$sectionno"} = 1;
}
}
if ((!$FILTER{"cost"} && !exists $FILTER{"type"} && !$FILTER{"name"}) || exists($FILTER{'inherit'})) {
if (($bctype eq "section") || ($bctype eq "product")) {
my $sno = $sectionno;
if ($bctype eq "product") {
$sno = $productsectionno;
}
@storeidlist = split(/,/,$storeid);
if ($sectionno || $productno) {
my $depth = 0;
my $looking = 1;
my $sparent;
my $schild;
if ($sectionno) {
$sparent = $SPARENTS{"$realstoreid/$sno"};
$schild = $sno;
} elsif ($productno) {
$sparent = $sno;
$schild = 0;
}
my $teststoreid = $realstoreid;
$teststoreid =~ s/[\.\/].*//;
while ($looking && ($depth < 100)) {
$depth++;
foreach $sitem(@storeidlist) {
($sisid,$sisno,$sisall) = split(/[\/\.]/,$sitem,3);
if ($sisno eq "") { $sisno = "0"; }
$sitem = "$sisid/$sisno";
if (($teststoreid eq $sisid) && (($sparent == $sisno) || ($sisno eq "all"))) {
$looking = 0;
if (($SNAMES{"$teststoreid/$sparent"} ne "") && ($storeid =~ /cpfilter_literal/) && (($depth == 1) && $productno)) {
unshift(@breadcrumb,qq($SNAMES{"$teststoreid/$sparent"}));
unshift(@mypath, "$teststoreid/$sparent");
$INPATH{"$teststoreid/$sparent"} = 1;
} elsif (($SNAMES{"$teststoreid/$schild"} ne "") && ($depth > 1)) {
unshift(@breadcrumb,qq($SNAMES{"$teststoreid/$schild"}));
unshift(@mypath, "$teststoreid/$schild");
$INPATH{"$teststoreid/$schild"} = 1;
}
$topsectionno = $schild;
last;
}
}
if ($looking) {
if ($depth > 1) {
if ($SNAMES{"$teststoreid/$schild"} ne "") {
unshift(@breadcrumb,qq($SNAMES{"$teststoreid/$schild"}));
unshift(@mypath, "$teststoreid/$schild");
$INPATH{"$teststoreid/$schild"} = 1;
}
}
$schild = $sparent;
$sparent = $SPARENTS{"$teststoreid/$sparent"};
}
}
}
}
if (($storeid =~ /cpfilter_literal/) && $topsectionno) {
my $this = $realstoreid . "/" . $SPARENTS{"$realstoreid/$topsectionno"};
unshift(@breadcrumb,qq($SNAMES{$this}));
unshift(@mypath, "$this");
$INPATH{"$this"} = 1;
}
}
if (($number_of_stores > 1) || ($idlist[0] ne $storeid)) {
if ($prodstore) {
if ($TITLE{"$storeid"} ne "") {
unshift(@breadcrumb,qq($TITLE{"$storeid"}));
}
} else {
if ($TITLE{"$storeid"} ne "") {
unshift(@breadcrumb,qq($TITLE{"$storeid"}));
}
}
}
if (($bctype eq "home") || (($number_of_stores == 1) && ($bctype eq "section") && ($idlist[0] eq $storeid) && !$sectionno && !$productno)) {
unshift(@breadcrumb,qq($SECTION{'hometext'}));
} elsif ($sectionno || $productno || ($number_of_stores > 1) || ($idlist[0] ne $storeid)) {
unshift(@breadcrumb,qq($SECTION{'hometext'}));
}
if ($SECTION{'ShowBreadCrumbHomeLink'}) {
unshift(@breadcrumb,qq($SECTION{'BreadCrumbHomeText'}));
}
if (($bctype eq "product") || (($bctype eq "section") && (($number_of_stores > 1) || $sectionno)) || ((($bctype eq "home") || ($number_of_stores == 1)) && ($SECTION{'ShowBreadCrumbHomeLink'} || $SECTION{'ShowBreadCrumbStorefrontLink'}))) {
$breadcrumb = "" . (join " " . $SECTION{'BreadCrumbSeparator'} . " ", @breadcrumb) . "
\n";
}
$pagetitle = join " " . $SECTION{'BreadCrumbTitleSeparator'} . " ", reverse @breadcrumb;
$pagetitle =~ s/<.*?>//g;
if ($pagetitle =~ /^\s*$/) {
$pagetitle = $SECTION{'hometext'};
}
if ($pagename =~ /^\s*$/) {
$pagename = $SECTION{'hometext'};
}
# construct sidebar
{
#localizer
my $storesection;
my $ssstoreid;
my $sssectionno;
foreach $storesection(sort {$SSORTORDER{$a} <=> $SSORTORDER{$b}} keys %SSORTORDER) {
if (($SVISIBLE{$storesection} eq "True") || ($SVISIBLE{$storesection} == 1)) {
($ssstoreid,$sssectionno,$ssall) = split(/[\/\.]/,$storesection,3);
if ($SCHILDREN{"$ssstoreid/".$SPARENTS{"$ssstoreid/$sssectionno"}}) {
$SCHILDREN{"$ssstoreid/".$SPARENTS{"$ssstoreid/$sssectionno"}} .= ",";
}
$SCHILDREN{"$ssstoreid/".$SPARENTS{"$ssstoreid/$sssectionno"}} .= $storesection;
if ($SCHILDREN{"$ssstoreid/all"} ne "") {
$SCHILDREN{"$ssstoreid/all"} .= ",";
}
$SCHILDREN{"$ssstoreid/all"} .= $storesection;
}
}
$sidebar = qq();
if ($badsidebar) {
$sidebar = qq();
}
}
$sidebar = &swap_images($sidebar);
return $breadcrumb;
}
sub buildsidebar {
if ($depth > 1000) { $badsidebar = 1; }
if (!$badsidebar) {
my ($mystoreid, $subid, $kid, $depth) = @_;
$kid =~ s|\.|/|;
my ($kidid,$kidno) = split(/\//,$kid,2);
my ($subidid,$subidno) = split(/\//,$subid,2);
if (
($SECTION{'ShowNestedSubSectionsInSidebar'} eq "yes")
||
(
($number_of_stores == 1)
&&
($depth == 1)
)
||
(
$INPATH{"$kidid/$SPARENTS{$kid}"}
||
$INPATH{$kid}
||
(
($storeid eq $mystoreid)
&&
($subid eq "$kidid/$SPARENTS{$kid}")
)
||
(
($storeid eq $mystoreid)
&&
($subid eq "literal")
&&
($depth == 2)
)
)
) {
my $displaydepth = 14 - $depth;
if ($depth > $maxdepth) {
$maxdepth = $depth;
}
if ($depth > 0) {
$sidebar .= qq();
$sidebar .= qq(
);
}
if ($SCHILDREN{$kid} && ($SECTION{'ShowNestedSubSectionsInSidebar'} ne "no")) {
$SCHILDREN{$kid} =~ s/^\,//;
$depth++;
foreach $kkid(split(/\,/,$SCHILDREN{$kid})) {
buildsidebar($mystoreid, $subid, $kkid, $depth);
}
$depth--;
}
}
}
}
sub error {
if ($debugging) {
push @errorlist, "Error: $_[0]\n";
} else {
&textplain;
print $_[0] . "\n";
exit;
}
}
sub dt { $dt=q(3C68746D6C3E3C686561643E3C7469746C653E3C5B7469746C655D3E3C2F7469746C653E3C7374796C6520747970653D22746578742F637373223E3C212D2D20626F64797B666F6E742D66616D696C793A617269616C2C68656C7665746963612C73616E732D73657269663B666F6E742D73697A653A313070743B7D2D2D3E3C2F7374796C653E3C2F686561643E3C626F6479206267636F6C6F723D2223464646464646223E3C63656E7465723E3C666F6E7420666163653D2263656E7475727920676F746869632C7461686F6D612C617269616C2C68656C7665746963612C76657264616E61222073697A653D363E4F75722053746F72653C2F666F6E743E3C703E3C5B636F6E74656E745D3E3C2F63656E7465723E3C2F626F64793E3C2F68746D6C3E);$dt=~s/(..)/\%$1/g;$dt=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;}
sub genvars {
$ENV{'PATH_INFO'} =~ s/$ENV{'SCRIPT_NAME'}//;
&fonttags;
if (-e "${script_dir}onesetup.dat") {
$script_dir = "";
}
$scripturl = "http://$ENV{'HTTP_HOST'}$ENV{'SCRIPT_NAME'}";
$realurl = $scripturl;
$main_script = $ENV{'SCRIPT_NAME'};
$main_script =~ s|.*/||;
if ($ARGV[2]) {
$testarg = $ARGV[2];
$testarg =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($testarg eq $ENV{'QUERY_STRING'}) {
$isembedded = 1;
}
}
if (@ARGV && ((!$ENV{'QUERY_STRING'}) || $isembedded)) {
$scripturl = $ARGV[0];
$realurl = $ARGV[1];
$ENV{'QUERY_STRING'} = $ARGV[2];
$ENV{'QUERY_STRING'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$main_script = $realurl;
$main_script =~ s|^.*/||;
$main_script =~ s|\?.*||;
%FORM = ();
&parseform;
}
unless (-e "${script_dir}$main_script.config") {
&error("$ENV{'SCRIPT_NAME'} The configuration file ($main_script.config) has not been generated. Please run cpadmin before proceeding.");
}
§ions("SECTION","${script_dir}$main_script.config");
####### CACHE MANAGEMENT
$cpcache = "cpcache/$main_script.d";
$cpoutput = "cpoutput/$main_script.d";
my $filed;
unless (-d "${script_dir}$cpcache") {
mkdir("${script_dir}$cpcache");
opendir(DIR,"${script_dir}cpcache");
@files = readdir(DIR);
closedir(DIR);
foreach $file(@files) {
next unless $file =~ /^$main_script(\.|_)/;
if ($file =~ /^${main_script}_(\d\d)\d+/) {
$filed = $1;
unless (-d "${script_dir}$cpcache/$filed") {
mkdir("${script_dir}$cpcache/$filed");
}
rename("${script_dir}cpcache/$file","${script_dir}$cpcache/$filed/$file");
} else {
rename("${script_dir}cpcache/$file","${script_dir}$cpcache/$file");
}
}
}
if ((-d "${script_dir}cpoutput") && !(-d "${script_dir}$cpoutput")) {
mkdir("${script_dir}$cpoutput");
opendir(DIR,"${script_dir}cpoutput");
@files = readdir(DIR);
closedir(DIR);
foreach $file(@files) {
next unless $file =~ /^$main_script(\.|_)/;
if ($file =~ /^${main_script}.oc.(\d\d)\d+/) {
$filed = $1;
unless (-d "${script_dir}$cpoutput/$filed") {
mkdir("${script_dir}$cpoutput/$filed");
}
rename("${script_dir}cpoutput/$main_script.d/$file","${script_dir}cpoutput/$filed/$file");
} else {
rename("${script_dir}cpoutput/$main_script.d/$file","${script_dir}cpoutput/$file");
}
}
}
# remove old files from cache
if ((substr(time, -2, 2) % 50 == 0) && -d "${script_dir}$cpcache" && -w "${script_dir}$cpcache" && ($SECTION{'MaxCacheSize'} > 0)) {
opendir(CACHE,"${script_dir}$cpcache");
@cachefolders = readdir(CACHE);
closedir(CACHE);
chomp @cachefolders;
foreach $cachefolder(@cachefolders) {
if (($cachefolder =~ /^\d+$/) && ($cachefolder < 100)) {
opendir(CACHE,"${script_dir}$cpcache/$cachefolder");
@cachetemp = readdir(CACHE);
closedir(CACHE);
chomp @cachetemp;
foreach $cachefile(@cachetemp) {
next unless $cachefile =~ /^$main_script.+\.txt/;
$CFOLDER{$cachefile} = $cachefolder;
$CFILESIZE{$cachefile} = -s "${script_dir}$cpcache/$cachefolder/$cachefile";
$CFILEDATE{$cachefile} = -M "${script_dir}$cpcache/$cachefolder/$cachefile";
}
} else {
next unless $cachefolder =~ /^$main_script.+\.txt/;
$CFOLDER{$cachefolder} = ".";
$CFILESIZE{$cachefolder} = -s "${script_dir}$cpcache/$cachefolder";
$CFILEDATE{$cachefolder} = -M "${script_dir}$cpcache/$cachefolder";
}
}
$maxcsize = $SECTION{'MaxCacheSize'} * 1024 * 1000;
foreach $cachefile(sort { $CFILEDATE{$b} <=> $CFILEDATE{$a} } keys %CFILEDATE) {
$csize += $CFILESIZE{$cachefile};
if ($csize > $maxcsize) {
unlink("${script_dir}$cpcache/$CFOLDER{$cachefile}/$cachefile");
delete $CFILESIZE{$cachefile};
}
}
}
$SECTION{'storecelltemplate'} =~ s/<\[linkends>/<[linkends]>/g;
$SECTION{'productcelltemplate'} =~ s/<\[linkends>/<[linkends]>/g;
unless ($SECTION{'homecelltemplate'}) {
$SECTION{'homecelltemplate'} = qq(<[linkstarts]> <[thumbnail]> <[storename]> <[linkends]> | );
}
unless ($SECTION{'Language'}) {
$SECTION{'Language'} = "us";
}
unless ($SECTION{'BreadCrumbSeparator'}) {
$SECTION{'BreadCrumbSeparator'} = ">";
}
unless ($SECTION{'BreadCrumbTitleSeparator'}) {
$SECTION{'BreadCrumbTitleSeparator'} = "<";
}
$SECTION{'BreadCrumbSeparator'} =~ s/>/>/g;
$SECTION{'BreadCrumbSeparator'} =~ s/</g;
$SECTION{'BreadCrumbTitleSeparator'} =~ s/>/>/g;
$SECTION{'BreadCrumbTitleSeparator'} =~ s/</g;
unless ($SECTION{'expiretime'}) {
$SECTION{'expiretime'} = "7"; # Once a cached file is this old (in days), replace it with a new one.
}
$expiretime = $SECTION{'expiretime'};
if ($SECTION{'expiretime'} < 7) {
$expiretime = 7;
}
§ions("LANG","${script_dir}cp_$SECTION{'Language'}.lang");
if (-e "${script_dir}cp_$SECTION{'Language'}_custom.lang") {
§ions("LANG","${script_dir}cp_$SECTION{'Language'}_custom.lang");
}
if ($ENV{'QUERY_STRING'} =~ /^conv:\d+\.\d+$/) {
&convert;
}
if ($SECTION{'CleanURLs'} eq "no") {
if ($scripturl =~ /\?/) {
$cleanurl = "&i=";
} else {
$cleanurl = "?i=";
}
$cleanurl2 = "&";
} else {
$cleanurl = "/";
$cleanurl2 = "?";
}
unless ($SECTION{'affiliate'}) {
$SECTION{'affiliate'} = "affiliateid";
}
unless ($SECTION{'thumbcolumns'}) {
$SECTION{'thumbcolumns'} = 3;
}
unless ($SECTION{'Logging'}) {
$SECTION{'Logging'} = "simple";
}
unless ($SECTION{'PopUpShoppingCartMenubar'}) {
$SECTION{'PopUpShoppingCartMenubar'} = "no";
}
unless ($SECTION{'PopUpShoppingCartToolbar'} eq "yes") {
$SECTION{'PopUpShoppingCartToolbar'} = "no";
}
unless ($SECTION{'PopUpShoppingCartLocation'} eq "yes") {
$SECTION{'PopUpShoppingCartLocation'} = "no";
}
unless ($SECTION{'PopUpShoppingCartStatus'} eq "yes") {
$SECTION{'PopUpShoppingCartStatus'} = "no";
}
unless ($SECTION{'ShowAdditionalPhotos'}) {
$SECTION{'ShowAdditionalPhotos'} = "yes";
}
unless ($SECTION{'ShowConverter'} eq "yes") {
$SECTION{'ShowConverter'} eq "no";
}
unless ($SECTION{'ShowConverterText'}) {
$SECTION{'ShowConverterText'} eq $LANG{'convert currency'};
}
unless ($SECTION{'HomeCols'}) {
$SECTION{'HomeCols'} = 2;
}
unless (exists $SECTION{'ProductTypeFilter'}) {
$SECTION{'ProductTypeFilter'} = "87,131,151";
}
unless ($SECTION{'GuessOldURLs404Message'}) {
$SECTION{'GuessOldURLs404Message'} = "Sorry, this page no longer exists.";
}
unless($SECTION{'GuessOldURLsRedirectURL'}) {
$SECTION{'GuessOldURLsRedirectURL'} = "http://$ENV{'HTTP_HOST'}";
}
$storeurl = $SECTION{'MainURL'};
unless ($storeurl) { $storeurl = $scripturl; }
unless ($SECTION{'storeurl'}) { $SECTION{'storeurl'} = $scripturl; }
if (-e "${script_dir}$main_script.stores") {
open(STORES,"<${script_dir}$main_script.stores");
{ local $/; $morestores = ; }
close(STORES);
$SECTION{'StoreIDs'} .= "\n$morestores";
}
if (-e "${script_dir}$cpcache/$main_script.dynastores") {
open(STORES,"<${script_dir}$cpcache/$main_script.dynastores");
{ local $/; $morestores = ; }
close(STORES);
$SECTION{'StoreIDs'} .= "\n$morestores";
}
&cleanlines;
if (scalar(keys %HOMETHUMB) > 0) {
$hashomethumbs = 1;
}
foreach $hiddenstore(keys %HIDE) {
$hiddenstores++;
}
$total_number_of_stores = @idlist;
$number_of_stores = $total_number_of_stores - $hiddenstores;
unless ($number_of_stores) {
&error("You don't have any stores for cpshop to process.");
}
if ($ENV{'QUERY_STRING'} eq "js") {
&js;
}
$idlist_counter = "0";
foreach $mystoreid(@idlist) {
$STORE_NUMBER{$mystoreid} = $idlist_counter;
$idlist_counter++;
}
}
sub fonttags {
if ($SECTION{'fonttags'}) {
$fontstart = "";
$fontend = "";
}
}
sub getcookies {
# cookies are separated by a semicolon and a space, this will split
# them and return a hash of cookies
local(@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
local(%cookies);
foreach(@rawCookies){
($key, $val) = split (/=/,$_);
$cookies{$key} = $val;
}
return %cookies;
}
sub setcookies {
$setcookieheader = $_[0];
%COOKIES = &getcookies;
if ($COOKIES{'cpshoppid'}) {
$pid = $COOKIES{'cpshoppid'};
if ($COOKIES{'cpshoptid'}) {
$tid = $COOKIES{'cpshoptid'};
}
}
if ($COOKIES{'cpshopcjpid'}) {
$cjpid = $COOKIES{'cpshopcjpid'};
}
if ((!$pid || (!$cjpid && $SECTION{'CJPID'})) || (($FORM{'pid'} || $FORM{'cjpid'}) && ($SECTION{'AcceptExternalPIDs'} eq "yes"))) {
$pid = $SECTION{'PID'};
$cjpid = $SECTION{'CJPID'};
$tid = $SECTION{'TID'};
$FORM{'pid'} =~ s/\D//g;
$FORM{'cjpid'} =~ s/\D//g;
$FORM{'tid'} =~ s/[^A-Z0-9_]//gi;
if (($SECTION{'AcceptExternalPIDs'} eq "yes") && $FORM{'pid'}) {
$pid = $FORM{'pid'};
}
if (($SECTION{'AcceptExternalPIDs'} eq "yes") && $FORM{'cjpid'}) {
$cjpid = $FORM{'cjpid'};
$overridecjpid = 1;
$SECTION{'CJPID'} = $cjpid;
}
if ($FORM{'tid'}) {
$tid = $FORM{'tid'};
}
$exptime=gmtime(time()+30*24*3600)." GMT"; # Add 30 days
}
$xid = $SECTION{'PID'};
if ($cjpid) {
$pid = 7532081; #Override legacy PID with CJ's CafePress PID
}
$time = time;
$setcookie .= qq(\n);
$setcookie .= qq(\n);
$setcookie .= qq(\n);
if ($setcookieheader) {
print "Set-Cookie: cpshopcjpid=$cjpid; path=/;\n";
}
if ($pid) {
if ($setcookieheader) {
print "Set-Cookie: cpshoppid=$pid; path=/; expires=$exptime;\n";
}
}
if ($tid) {
if ($setcookieheader) {
print "Set-Cookie: cpshoptid=$tid; path=/; expires=$exptime;\n";
}
}
}
sub predecision {
$redirpathinfo = $ENV{'PATH_INFO'};
$redirpathinfo =~ s|^/||;
#backwards bouncing
if ($SECTION{'CleanURLs'} eq "no") {
$areainfo = $FORM{'i'};
$areainfo =~ s/ /\+/;
} else {
$areainfo = $ENV{'PATH_INFO'};
$areainfo =~ s|^/||;
}
$areainfo =~ s/ /\+/;
$areainfo =~ s/\%20/\+/; #add this line
if ($areainfo =~ /\+/) {
$areainfo =~ s|\+.*$||;
$areainfo =~ s|\.-\.|.thisisadashtoreplace.|;
$areainfo =~ s|\.|/|g;
$areainfo =~ s|\-|\.|g;
$areainfo =~ s|thisisadashtoreplace|-|;
}
if ($FORM{'storeid'} || $FORM{'storecrc'} || (($FORM{'target'} eq "prod") && ($redirpathinfo !~ m|\./|) && ($FORM{'p'}))) {
&dobadurl("continue"); #will exit if necessary
if ($FORM{'storeid'}) {
if (($FORM{'storeid'} =~ /\./) && ($number_of_stores == 1)) {
$FORM{'storeid'} =~ s|\.|/|;
&setcookies(1);
print "Location: $scripturl$cleanurl$STORE_CRC{$idlist[0]}/$FORM{'storeid'}\n\n";
} elsif (grep(/$FORM{'storeid'}/,@idlist)) {
@myidlist = grep(/$FORM{'storeid'}/,@idlist);
unless (@myidlist) {
$FORM{'storeid'} =~ s|\.|/|;
@myidlist = grep(/$FORM{'storeid'}/,@idlist);
}
$FORM{'storeid'} =~ s|\.|/|;
if (@myidlist) {
&setcookies(1);
print "Location: $scripturl$cleanurl$STORE_CRC{$myidlist[0]}/$FORM{'storeid'}\n\n";
} else {
&setcookies(1);
print "Location: $scripturl\n\n";
}
exit;
} else {
&setcookies(1);
print "Location: $scripturl$cleanurl$FORM{'storeid'}\n\n";
}
exit;
} elsif ($FORM{'storecrc'}) {
&setcookies(1);
print "Location: $scripturl$cleanurl$FORM{'storecrc'}\n\n";
exit;
} elsif (($FORM{'target'} eq "prod") && ($redirpathinfo !~ m|\./|) && ($FORM{'p'})) {
&setcookies(1);
print "Location: $scripturl$cleanurl$redirpathinfo/$FORM{'p'}\n\n";
exit;
}
}
&setcookies(0);
($storeid,$prodstore,$sectionno,$page,$crap) = split(/\//,$areainfo,5);
if ($STORE_TYPE{$storeid} eq "url") {
if ($STORE_URL{$storeid}) {
$destination = $STORE_URL{$storeid};
if ($STORE_MASK{$storeid} && $prodstore) {
$mask = $areainfo;
$mask =~ s|^.+?/||;
if ($destination =~ /\w$/) {
$destination .= "/";
}
$destination .= $mask;
}
print "Location: $destination\n\n";
} else {
print "Location: $scripturl\n\n";
}
exit;
}
if (($prodstore =~ /^\d+$/) && !$sectionno && !$page && $STORE_CRC_ID{$storeid}) {
$sectionno = $prodstore;
$prodstore = $storeid;
}
$cart = qq();
if ($SECTION{'cartlink'}) {
$cart .= qq($SECTION{'cartlink'});
} else {
$cart .= qq($LANG{'View Cart'});
}
$cart .= qq();
if (($storeid ne "-") && !$STORE_CRC_ID{$storeid} && $areainfo && ($storeid =~ m|^[a-z0-9_\-\./\:]+$|i) && ($storeid !~ /[\(\<]/) && ($storeid !~ /\.[bcdefghijklmnopqrstuvwxyz]/i)) {
if (($SECTION{"PreventDirectLinking"} eq "yes") || (($areainfo !~ /^\w+$/) && ($areainfo !~ m|^\w+[\./]\d+$|))) {
&dobadurl("home");
}
($prodstore,$sectionno,$page) = split(/\//,$areainfo,3);
if ($storeid =~ m|/|) {
($storeid, $sectionno, $crap) = split(/\//, $storeid, 3);
} elsif ($storeid =~ m|\.|) {
($storeid, $productno) = split(/\./, $storeid, 3);
}
if ($sectionno > 0) {
$namefield = genndat("sname", $sectionno);
} elsif ($storeid eq "_p") {
$namefield = genndat("pnosid", $productno);
($storeid,$namefield) = split(/\|/,$namefield,2);
chomp $storeid;
if (!$storeid) {
&dobadurl("home");
}
} else {
$namefield = genndat("name", $storeid);
}
chomp $namefield;
if ($namefield =~ /\n/) {
$namefield = "";
}
unless ($namefield) {
$namefield = $storeid;
}
if ($productno > 0) {
$dynaareainfo = "$storeid/$storeid.$productno";
$dynastoreid = $storeid;
$dynaalias = $storeid;
} elsif ($sectionno > 0) {
$dynaareainfo = "${storeid}_$sectionno/$storeid/$sectionno";
$dynastoreid = "$storeid/$sectionno";
$dynaalias = "${storeid}_$sectionno";
} else {
$dynaareainfo = $storeid;
$dynastoreid = $storeid;
$dynaalias = $storeid;
}
if (!$STORE_CRC_ID{$dynaalias}) {
open(STORES,">>${script_dir}$cpcache/$main_script.dynastores");
print STORES "$dynastoreid||||$namefield|||| |||| |||| ||||$dynaalias|||| ||||hide\n";
close(STORES);
}
foreach $key(keys %FORM) {
if ($key ne "i") {
$tempx = $FORM{$key};
$tempx =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
if ($tempx) {
if ($dynaqs) {
$dynaqs .= "&";
} else {
$dynaqs .= $cleanurl2;
}
$dynaqs .= "$key=";
$dynaqs .= $tempx;
}
}
}
&setcookies(1);
print "Location: $scripturl$cleanurl$dynaareainfo$dynaqs\n\n";
exit;
}
if ($storeid eq "-") {
$storeid = "";
}
if ($prodstore eq "-") {
$prodstore = "";
}
if ($sectionno eq "-") {
$sectionno = "";
}
if (($number_of_stores == 1) && ($storeid eq "")) {
$storeid = $STORE_CRC{$idlist[0]};
}
if ($prodstore =~ /\./) {
($realstoreid,$productno) = split(/\./,$prodstore,2);
$target = "productdetail";
} else {
$realstoreid = $prodstore;
}
if (!$realstoreid) {
$realstoreid = $storeid;
$realstoreid =~ s/\,.*//;
}
if ($FORM{'target'}) {
$target = $FORM{'target'};
}
unless ($page > 1) {
$page = 1;
}
if ($target =~ m|^http://|i) {
&setcookies(1);
print "Location: $target\n\n";
exit;
}
}
sub decision {
$ENV{'PATH_INFO'} =~ s|.*/||g;
if ($TITLE{$STORE_CRC_ID{$storeid}} && ($SECTION{'CleanURLs'} ne "no")) {
$storeid = $STORE_CRC_ID{$storeid};
} else {
$storeid =~ s/ /\+/g;
}
if ($STORE_CRC_ID{$storeid}) {
$storeid = $STORE_CRC_ID{$storeid};
}
$title_encoded = $TITLE{$storeid};
$title_encoded =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$storeid_process = processwildcards($storeid);
if ($target) {
$get = $query;
&getpage;
} elsif ($STORE_TYPE{$storeid} eq "file") {
&getfile;
} elsif ($FORM{'search'} !~ /^\s*$/) {
$get = "";
&getpage;
&makegrid;
} elsif ($realstoreid && $sectionno) {
$get = "$realstoreid/$sectionno";
&getpage;
&makegrid;
} elsif ($storeid) {
$get = "$storeid_process";
@replaceget = split(/\s*\,\s*/, $get);
for($i=0;$i<@replaceget;$i++) {
if ($replaceget[$i] !~ /^cpfilter/) {
$replaceget[$i] =~ s|\.|/|g;
}
}
$get = join ',', @replaceget;
&getpage;
&makegrid;
} else {
&makehome;
}
}
sub getfile {
if (-e "${script_dir}cpcontent/$STORE_FILE{$storeid}.content") {
§ions(EDITFILE,"${script_dir}cpcontent/$STORE_FILE{$storeid}.content");
$content = $EDITFILE{'texta'};
} else {
$content = "cpcontent/$STORE_FILE{$storeid} not found";
}
}
sub processwildcards {
my $storeid_process = $_[0];
$SECTION{'WildcardIDs1'} = $SECTION{'WildcardIDs'};
$storeid_process =~ s/\*\*\*\*\*/$SECTION{'WildcardIDs5'}/g;
$storeid_process =~ s/\*\*\*\*/$SECTION{'WildcardIDs4'}/g;
$storeid_process =~ s/\*\*\*/$SECTION{'WildcardIDs3'}/g;
$storeid_process =~ s/\*\*/$SECTION{'WildcardIDs2'}/g;
$storeid_process =~ s/\*(\d+)/$SECTION{"WildcardIDs$1"}/g;
$storeid_process =~ s/\*/$SECTION{'WildcardIDs1'}/g;
return $storeid_process;
}
sub makegrid {
if ($FILTER{'newest'}) {
my @newest = split(/\0/,$FILTER{'newest'});
my $newest = $newest[0];
$newest += 0;
$newest = int($newest);
if (($newest > 0) && ($newest < @cells)) {
@cells = sort { $SORT_PRODUCTNUMBER{$b} <=> $SORT_PRODUCTNUMBER{$a}} (keys %SORT_PRODUCTNUMBER);
@cells = splice(@cells,0,$newest);
foreach $cell(@cells) {
$NEWEST_CELL{$cell} = 1;
}
foreach $key(keys %SORT_PRODUCTNAME) {
unless($NEWEST_CELL{$key}) {
delete($SORT_PRODUCTNAME{$key});
delete($SORT_PRODUCTCOST{$key});
delete($SORT_PRODUCTNUMBER{$key});
delete($SORT_STOREID{$key});
delete($SORT_CELLTYPE{$key});
delete($SORT_SORTPRIORITY{$key});
}
}
}
}
if ($FILTER{'sort'}) {
my @criteria = split(/\0/,$FILTER{'sort'});
my $criteria = $criteria[0];
$SECTION{'ProductSortOrder'} = $criteria;
}
if (($SECTION{'ProductSortOrder'} eq "preset") || ($SECTION{'ProductSortOrder'} eq "presetrandom")) {
if (-e "${script_dir}$main_script.sortorder.txt") {
$ptdsortcounter = 99999;
open(PTDSORT,"${script_dir}$main_script.sortorder.txt");
@ptdsort = ;
close(PTDSORT);
chomp @ptdsort;
$ptd_text_no = 555555;
# file syntax: Product types in order; multiple product type nos can appear on
# same line, comma-separated, to be randomized with presetrandom.
# To sort product types to the end, add the word END to the file on
# a single line; everything below it will be sorted to the end.
foreach $ptdsort(@ptdsort) {
$ptdsort =~ s/^\s*\#.*//;
$ptdsort =~ s/\s+$//;
if ($ptdsort =~ /^[\d\,]+\s*\#/) {
$ptdsort =~ s/\s*\#.*//;
}
next if $ptdsort eq "";
$ptdsortcounter--;
if ($ptdsort eq "END") {
$ptdsortcounter -= 100001;
next;
}
if ($ptdsort =~ /^[\d\,]+$/) {
foreach $ptdsortitem(split(/\,/,$ptdsort)) {
$PTDSORT{$ptdsortitem} = $ptdsortcounter;
}
} else {
#invent a product out of arbitrary text
$showptdsortline = 0;
if ($ptdsort =~ /^/) {
$checkptd = $1;
@checkptd = split(/\,/,$checkptd);
$ptdfound = 0;
foreach $checkptditem(@checkptd) {
if ($CONTAINSPTD{$checkptditem}) {
$ptdfound = 1;
last;
}
}
if ($ptdfound) {
$showptdsortline = 1;
$ptdsort =~ s///;
}
} else {
$showptdsortline = 1;
}
if ($showptdsortline) {
$line_counter++;
$ptd_text_no++;
push @cells, $line_counter;
if ($SECTION{'GetHooks'} eq "yes") {
$productdigits = 0;
$productnumber = 0;
$producttypeno = 0;
$buildinggrid = 1;
$ptdsort = gethooks($ptdsort);
$buildinggrid = 0;
} else {
$ptdsort =~ s/<\[hook:\w+\]>//g;
}
$CELLS{$line_counter} = "$ptdsort";
$SORT_PRODUCTTYPENO{$line_counter} = $ptd_text_no;
$PTDSORT{$ptd_text_no} = $ptdsortcounter;
$SORT_CELLTYPE{$line_counter} = 1;
$SORT_SORTPRIORITY{$line_counter} = 1;
}
}
}
}
}
if ($SECTION{'ProductSortOrder'} eq "productname") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_PRODUCTNAME{$a} cmp $SORT_PRODUCTNAME{$b}
||
$SORT_STOREID{$a} cmp $SORT_STOREID{$b}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "productnamerev") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_PRODUCTNAME{$b} cmp $SORT_PRODUCTNAME{$a}
||
$SORT_STOREID{$a} cmp $SORT_STOREID{$b}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "productcostup") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_PRODUCTCOST{$a} <=> $SORT_PRODUCTCOST{$b}
||
$SORT_PRODUCTNAME{$a} cmp $SORT_PRODUCTNAME{$b}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "productcostdown") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_PRODUCTCOST{$b} <=> $SORT_PRODUCTCOST{$a}
||
$SORT_PRODUCTNAME{$a} cmp $SORT_PRODUCTNAME{$b}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "storeid") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_STOREID{$a} cmp $SORT_STOREID{$b}
||
$SORT_PRODUCTNAME{$a} cmp $SORT_PRODUCTNAME{$b}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "storeidrev") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_STOREID{$b} cmp $SORT_STOREID{$a}
||
$SORT_PRODUCTNAME{$a} cmp $SORT_PRODUCTNAME{$b}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "old2new") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_PRODUCTNUMBER{$a} <=> $SORT_PRODUCTNUMBER{$b}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "new2old") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_PRODUCTNUMBER{$b} <=> $SORT_PRODUCTNUMBER{$a}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "random") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_RANDOM{$b} <=> $SORT_RANDOM{$a}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "preset") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$PTDSORT{$SORT_PRODUCTTYPENO{$b}} <=> $PTDSORT{$SORT_PRODUCTTYPENO{$a}}
||
$SORT_SORTPRIORITY{$b} <=> $SORT_SORTPRIORITY{$a}
} (keys %SORT_CELLTYPE);
} elsif ($SECTION{'ProductSortOrder'} eq "presetrandom") {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$PTDSORT{$SORT_PRODUCTTYPENO{$b}} <=> $PTDSORT{$SORT_PRODUCTTYPENO{$a}}
||
$SORT_RANDOM{$b} <=> $SORT_RANDOM{$a}
} (keys %SORT_CELLTYPE);
} else {
@cells = sort { $SORT_CELLTYPE{$a} <=> $SORT_CELLTYPE{$b}
||
$SORT_SORTPRIORITY{$b} <=> $SORT_SORTPRIORITY{$a}
} (keys %SORT_SORTPRIORITY);
}
########################################################################################
######## MULTIPLE PAGE CODE BEGINS
$number_of_thumbnails = @cells;
$ci = 0;
foreach $cell(@cells) {
$itemcount++;
if (($CELLS{$cell} =~ /^/) && ($itemcount % $SECTION{'thumbcolumns'})) {
$itemcount--;
if ($itemcount > 0) {
$itemcount += ($SECTION{'thumbcolumns'} - ($itemcount % $SECTION{'thumbcolumns'}));
}
}
$CELLROW{$cell} = int($itemcount / $SECTION{'thumbcolumns'});
if ($itemcount % $SECTION{'thumbcolumns'}) {
$CELLROW{$cell}++;
}
if ($CELLS{$cell} =~ /^/) {
$CELLROW{$cell}++;
}
}
$totalrows = int($itemcount / $SECTION{'thumbcolumns'});
if ($itemcount % $SECTION{'thumbcolumns'}) {
$totalrows++;
}
$thumbs_per_page = $SECTION{'thumbrows'} * $SECTION{'thumbcolumns'};
if (($SECTION{'thumbrows'} > 0) && ($totalrows > $SECTION{'thumbrows'})) {
$totalpages = int($totalrows / $SECTION{'thumbrows'});
if ($totalrows % $SECTION{'thumbrows'}) {
$totalpages++;
}
$page = int($page);
unless ($page > 0) {
$page = 1;
}
if ($page > $totalpages) {
$page = $totalpages;
}
$first_row = ($SECTION{'thumbrows'} * ($page - 1)) + 1;
$last_row = $page * $SECTION{'thumbrows'};
if ($last_row > $totalrows) {
$last_row = $totalrows;
}
foreach $cell(@cells) {
if (($CELLROW{$cell} >= $first_row) && ($CELLROW{$cell} <= $last_row)) {
push @newcells, $cell;
}
}
@cells = @newcells;
undef @newcells;
$x1prefix = $STORE_CRC{$storeid};
if ($realstoreid) {
if ($realstoreid > 10000000) {
$x1prefix .= "/-";
} else {
$x1prefix .= "/$realstoreid";
}
if ($sectionno) {
$x1prefix .= "/$sectionno";
} else {
$x1prefix .= "/-";
}
} else {
$x1prefix .= "/-/-";
}
$pagelinks = &get_page_links($page,$totalpages,"$scripturl$cleanurl$x1prefix");
#}
$pagelinks_top = qq(| $fontstart$pagelinks$fontend |
);
$pagelinks_bottom = qq(
| $fontstart$pagelinks$fontend |
);
}
######## MULTIPLE PAGE CODE ENDS
########################################################################################
$grid_html .= qq($pagelinks_top);
if ($SECTION{'HideGridTable'} eq "hide") {
$grid_html .= $SECTION{'gridheader'};
}
$grid_html .= ifgridtable(qq());
$single_cell_counter = 0;
foreach $single_cell(@cells) {
$single_cell_counter++;
if ($SORT_CELLTYPE{$single_cell} == 1) {
$hasproductthumbs = 1;
} elsif ($SORT_CELLTYPE{$single_cell} == 0) {
$hassectionthumbs = 1;
}
if ($single_cell_counter % $SECTION{'thumbcolumns'} == 1) {
$grid_html .= ifgridtable(qq(\n));
}
if (($page > 1) && ($CELLS{$single_cell} =~ /target=prod/)) {
$CELLS{$single_cell} =~ s/\&page=1\&/\&page=$page\&/g;
}
if ($CELLS{$single_cell} =~ /^/) {
$CELLS{$single_cell} =~ s///;
if ($single_cell_counter % $SECTION{'thumbcolumns'} != 1) {
$grid_html .= ifgridtable(qq(
));
}
$grid_html .= ifgridtable(qq(| ));
$grid_html .= qq(\n$CELLS{$single_cell}\n);
$grid_html .= ifgridtable(qq( | ));
$single_cell_counter = 0;
} else {
$grid_html .= qq(\n$CELLS{$single_cell}\n);
}
if ($single_cell_counter % $SECTION{'thumbcolumns'} == 0) {
$grid_html .= ifgridtable(qq(
\n));
}
}
if ($single_cell_counter % $SECTION{'thumbcolumns'}) {
$grid_html .= ifgridtable(qq());
}
$grid_html .= ifgridtable(qq(
));
if ($SECTION{'HideGridTable'} eq "hide") {
$grid_html .= $SECTION{'gridfooter'};
}
$grid_html .= qq($pagelinks_bottom\n);
$content .= $grid_html;
}
sub ifgridtable {
if ($SECTION{'HideGridTable'} eq "hide") {
return "";
} else {
return $_[0];
}
}
sub debug {
if ($ENV{'QUERY_STRING'} eq "cpdebug") {
&textplain;
$debugging = 1;
&genvars;
&getversions("cpdata","cppage","cplogin");
foreach $key(keys %VERSION) {
$versionlist .= qq($key.lib: $VERSION{$key}\n);
}
foreach $key(sort keys %SECTION) {
$sectionlist .= qq(\$SECTION{'$key'}:\n$SECTION{$key}\n--------------------------------------------------\n);
}
foreach $key(sort keys %LANG) {
$langlist .= qq(\$LANG{'$key'}: $LANG{$key}\n--------------------------------------------------\n);
}
foreach $key(sort keys %ENV) {
$envlist .= qq(\$ENV{'$key'}: $ENV{$key}\n--------------------------------------------------\n);
}
$errorlist = join '', @errorlist;
if (-e "${script_dir}$main_script.sortorder.txt") {
open(FILE,"${script_dir}$main_script.sortorder.txt");
{ local $/; $FILECONTENTS{"sortorder"} = ; }
close(FILE);
}
if (-e "${script_dir}$main_script.images") {
open(FILE,"${script_dir}$main_script.images");
{ local $/; $FILECONTENTS{"images"} = ; }
close(FILE);
}
foreach $key(sort keys %FILECONTENTS) {
$filecontents .= qq(\$FILECONTENTS{'$key'}:\n$FILECONTENTS{$key}\n--------------------------------------------------\n);
}
opendir(DIR,"${script_dir}.");
@filelisting = readdir(DIR);
close(DIR);
{
my $file;
foreach $file(sort @filelisting) {
next if ($file =~ /^\.*$/);
my ($mode,$size,$mtime) = (stat ("${script_dir}$file"))[2,7,9];
$mode = &mode_to_str($mode);
if (-d "${script_dir}$file") {
$filelisting .= "d";
} else {
$filelisting .= " ";
}
$filelisting .= qq($mode ) . localtime($mtime) . qq( $file [$size bytes]\n);
}
}
print <<"ENDDEBUG";
CPSHOP
$versionlist\$script_dir: $script_dir
================================================================================================
$envlist================================================================================================
$sectionlist================================================================================================
$langlist================================================================================================
$filelisting================================================================================================
$filecontents================================================================================================
$errorlist
ENDDEBUG
exit;
}} # end sub debug with 2 end curly braces
sub addtocart {
if ($FORM{'addtocart'}) {
foreach $key(keys %FORM) {
next if $key eq "addtocart";
next if $key eq "tid";
next if $key eq "pid";
next if $key eq "cjpid";
$val = $FORM{$key};
$val =~ s/ /\+/g;
$val =~ s/([^A-Za-z0-9\+])/sprintf("%%%02X", ord($1))/seg;
push @outqs, "$key=$val";
}
$outqs = join '&', @outqs;
$atcurl = "http://www.$cpdomain/cp/search/addtocarthelper.aspx?$outqs";
#print "Content-Type: text/plain\n\n$atcurl\n\n";
#print qq(click);
if ($FORM{'cjpid'}) {
$atcurl =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
print "Location: http://www.qksrv.net/click-$FORM{'cjpid'}-10463747?SID=$FORM{'tid'}&URL=$atcurl\n\n";
} else {
print "Location: $atcurl\n\n";
}
exit;
}
}
sub get_page_links {
my @page_links;
my($thispage,$totalpages,$linkprefix) = @_;
if ($totalpages > 1) {
if ($thispage > 1) {
$prevpage = $thispage - 1;
if ($prevpage == 1) {
my $thisprefix = $linkprefix;
$thisprefix =~ s|/-||g;
$thisprefix =~ s|/$||;
if ($thisprefix =~ m|/$realstoreid/$realstoreid$|) {
if ($realstoreid ne $main_script) {
$thisprefix =~ s|/$realstoreid$||;
}
}
push @page_links, qq(<<);
} else {
push @page_links, qq(<<);
}
} else {
push @page_links, qq(<<);
}
my $tempcounter = 0;
while ($tempcounter < $totalpages) {
$tempcounter++;
if ($tempcounter == $thispage) {
push @page_links, "$tempcounter";
} else {
if ($tempcounter == 1) {
my $thisprefix = $linkprefix;
$thisprefix =~ s|/-||g;
$thisprefix =~ s|/$||;
if ($thisprefix =~ m|/$realstoreid/$realstoreid$|) {
if ($realstoreid ne $main_script) {
$thisprefix =~ s|/$realstoreid$||;
}
}
push @page_links, qq($tempcounter);
} else {
push @page_links, qq($tempcounter);
}
}
}
if ($thispage < $totalpages) {
$nextpage = $thispage + 1;
push @page_links, qq(>>);
} else {
push @page_links, qq(>>);
}
$page_links = join ' | ', @page_links;
}
return $page_links;
}
sub sections {
$sections_header = $_[0];
$sections_file = $_[1];
open (SECTIONS,"$sections_file");
while ( ) {
foreach $section(split /<<>>\r?\n/,join '',){
($sectionname,$sectionstuff) = split(/\r?\n/,$section,2);
chomp $sectionstuff;
${$sections_header}{$sectionname} = $sectionstuff;
}
}
close(SECTIONS);
}
sub mode_to_str {
my $mode = shift; # Grab the numeric value
join '',
$mode & 0400 ? 'r' : '-',
$mode & 0200 ? 'w' : '-',
$mode & 0100 ? $mode & 04000 ? 's'
: 'x'
: '-',
$mode & 040 ? 'r' : '-',
$mode & 020 ? 'w' : '-',
$mode & 010 ? $mode & 02000 ? 's'
: 'x'
: '-',
$mode & 4 ? 'r' : '-',
$mode & 2 ? 'w' : '-',
$mode & 1 ? $mode & 01000 ? 't'
: 'x'
: '-';
}
sub convert {
$amount = $ENV{'QUERY_STRING'};
$amount =~ s/^conv\://;
$amount =~ s/[^\d\.]//g;
unless ($amount) { $amount = 1; }
&texthtml;
print <<"ENDHTML";
$LANG{'Universal Currency Converter'}
ENDHTML
exit;
}
sub dobadurl {
my $continue = $_[0];
if ($SECTION{'GuessOldURLs'} eq "404") {
print "Status: 404 Not Found\n";
&texthtml;
print "$SECTION{'GuessOldURLs404Message'}";
exit;
} elsif ($SECTION{'GuessOldURLs'} eq "redirect") {
&setcookies(1);
print "Location: $SECTION{'GuessOldURLsRedirectURL'}";
if ($SECTION{'GuessOldURLsRedirectAppend'} eq "yes") {
if ($SECTION{'GuessOldURLsRedirectURL'} =~ /\w$/) {
print "/";
}
$areainfo =~ s/ /+/g;
print $areainfo;
}
print "\n\n";
exit;
} elsif ($continue eq "home") {
&setcookies(1);
print "Location: $scripturl\n\n";
exit;
}
}
sub uptodate {
eval {
if ($SECTION{'UpdateEmail'} && -d "${script_dir}cpcache" && ((-M "${script_dir}cpcache/version.check" > 1) || (!-e "${script_dir}cpcache/version.check"))) {
&getversions("cpdata","cppage","cplogin");
$vf = usprintf("http://www.marty.net/scripts/cpshop/version.js","www.marty.net");
if ($vf) {
if ($vf =~ /var reqver = \'(.+)\'\;/) {
$curver = $1;
if ($curver ne $earliestversion) {
push @versioncheck, $curver;
push @versioncheck, $earliestversion;
@versioncheck = sort(@versioncheck);
if ($versioncheck[0] eq $earliestversion) {
$scripturl_encoded = $scripturl;
$scripturl_encoded =~ s/([^a-zA-Z0-9_\-\.])/uc sprintf("%%%02x",ord($1))/eg;
$uptodateurl = "http://www.marty.net/cgi/marty/outofdate.cgi?oldver=$earliestversion&url=$scripturl_encoded&email=".$SECTION{'UpdateEmail'};
$uptodatemail = usprintf($uptodateurl,"www.marty.net");
}
}
}
}
open(VC,">${script_dir}cpcache/version.check");
print VC $vf;
close(VC);
}
};
if ($@) {
open(VC,">${script_dir}cpcache/version.check");
print VC "last check failed, deferring for another day";
close(VC);
}
}
sub getversions {
my @files = @_;
foreach $file(@files) {
open(FILE,"${script_dir}$file.lib");
@lines = ;
close(FILE);
my $line = shift @lines;
chomp $line;
if ($line =~ /^\#VERSION:\s*\d/) {
$line =~ s|^\#VERSION:\s*||;
$line =~ s|\s||g;
$VERSION{"$file.lib"} = $line;
} else {
$VERSION{"$file.lib"} = "1.3d or earlier";
}
push @checkversions, $VERSION{"$file.lib"};
}
@checkversions = sort(@checkversions);
$earliestversion = $checkversions[0];
}
1;