#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/ ############### if ($ENV{'QUERY_STRING'} =~ /outputerror/) { use CGI::Carp qw( fatalsToBrowser ); } sub noconnection { if ($_[1] !~ /marty/i) { if ($SECTION{'SorryPage'}) { if ($loadingscreen) { print "\n"; } else { print "Location: $SECTION{'SorryPage'}\n\n"; } } elsif ($getting_template) { if ($loadingscreen) { &loadingscreen("off"); } &badtemplate; } else { if ($loadingscreen) { &loadingscreen("off"); } &texthtml; if ($_[2]) { print $_[2] . "\n"; } else { print "$LANG{'Maintenance Message'}\n"; } if ($_[0]) { print "($_[0])\n"; } } exit; } } sub parsemainline { $flag = 0; my $mainline = $_[0]; if (scalar(keys %FN) == 0) { foreach $key(split(/\t/,$mainline)) { if ($key =~ /~$/) { $key =~ s/~//g; $DECODE{$key} = 1; } push @keys, $key; } foreach $key(@keys) { $FN{$key} = $flag; $flag++; } } } sub prepnoise { @noise = qw(about after all also an and another any are as at be because been before being between both but by came can come could did do each for from get got has had he have her here him himself his how if in into is it like make many me might more most much must my never now of on only or other our out over said same see should since some still such take than that the their them then there these they this those through to too under up very was way we well were what where which while who with would you your a b c d e f g h i j k l m n o p q r s t u v w x y z); foreach $noiseword(@noise) { $NOISE{$noiseword} = 1; } } sub wordfilter { my $string = $_[0]; my $string = lc($string); $string =~ s/<.*?>//g; $string =~ s/[^A-Za-z0-9_]/ /g; $string =~ s/\b\d{1,3}\b/ /g; $string =~ s/^\s+//; $string =~ s/\s+$//; $string =~ s/\s+/ /g; my $word; my %WORDS; my @words = split(/ /,$string); foreach $word(@words) { next if $NOISE{$word}; $WORDS{$word} = 1; } return sort keys %WORDS; } sub loadtree { my ($parentname,@fdata) = @_; foreach $line(@fdata) { @ffields = split(/\t/,$line); if ($ffields[$FN{'type'}] eq "s") { $this = $ffields[$FN{'store_id'}] . '/' . $ffields[$FN{'parent_section_no'}]; $that = $ffields[$FN{'store_id'}] . '/' . $ffields[$FN{'section_no'}]; ${$parentname}{$that} = $this; } } } sub progressmeter { if (1 == 2) { my $message = shift; $bouncerequest = shift; if ($ENV{'HTTP_HOST'}) { if ($bouncerequest) { print qq(\n); exit; } if (!$printingprogress) { $printingprogress = 1; $| = 1; &texthtml; print ""; print "Thanks for visiting. Please hold on a moment while we update our records."; } if ($FORM{'verbose'}) { print "$message
\n"; } else { print ". "; } } } } sub checksection { my $scope = shift; my $pvarname = shift; my $sidsno = shift; my $loopsectionall = shift; $checksectioncounter++; if ($checksectioncounter > 5000000) { exit; } if ($ALLIDS{$sidsno} && ($scope eq "global")) { pp(99,qq(----checksection: returned 1 for $sidsno [if clause part 1])); return 1; } elsif ($ALLIDS{${$pvarname}{$sidsno}} && ($scope eq "global") && ($ffields[$FN{'visible'}] ne "False") && ($ffields[$FN{'visible'}] ne "0")) { pp(99,qq(----checksection: returned 1 for $sidsno [if clause part 2])); pp(99,qq(------ ffields[FN{'visible'}]: $ffields[$FN{'visible'}])); pp(99,qq(------ scope: $scope)); pp(99,qq(------ pvarname: $pvarname)); pp(99,qq(------ sidsno: $sidsno)); pp(99,qq(------ loopsectionall: $loopsectionall)); return 1; } elsif (($ALLGETS{$sidsno} || $ALLGETS{${$pvarname}{$scope}}) && ($ffields[$FN{'visible'}] ne "False") && ($ffields[$FN{'visible'}] ne "0")) { pp(99,qq(----checksection: returned 1 for $sidsno [if clause part 3])); return 1; } elsif (${$pvarname}{$sidsno} && (${$pvarname}{$sidsno} ne $sidsno) && !$CHECKMAP{$sidsno}) { pp(99,qq(----checksection: continuing loop for $sidsno with ${$pvarname}{$sidsno})); $CHECKMAP{$sidsno} = 1; return checksection($scope,$pvarname,${$pvarname}{$sidsno},$loopsectionall); } else { pp(99,qq(----checksection: failed loop for $sidsno)); return 0; } } sub loadsectiondatafile { if ((!-e "${script_dir}$cpcache/$main_script.loading.txt") || (-M "${script_dir}$cpcache/$main_script.loading.txt" > 0.5)) { &loadingscreen("on"); $loadthisstore = $_[0]; #&textplain; #print "$loadthisstore\n"; if ($loadthisstore) { @loadthese = qq($loadthisstore); } else { @loadthese = keys %IDLIST; } if (!$LOADEDSECTIONDATAFILE{$loadthisstore}) { $| = 1; if (-e "${script_dir}$cpcache/$main_script.safe") { unlink("${script_dir}$cpcache/$main_script.safe"); } # using the list of all store IDs, load the list of storeID/sectionNo combos into %SLIST foreach $sid(@loadthese) { pp(99,qq("processing $sid")); $sectiondata = gencdat("","&sonly=sonly",qq($sid)); @fdata = split(/[\r\n]+/,$sectiondata); chomp @fdata; $NUMBEROFSECTIONS{$sid} = scalar(@fdata); $mainline = shift @fdata; &parsemainline($mainline); %LPARENTS = (); loadtree("LPARENTS",@fdata); foreach $key(keys %LPARENTS) { pp(99,qq("\$LPARENTS{$key} = $LPARENTS{$key}")); } @slist = (); if ($ALLIDS{"$sid/0"} || $ALLIDS{"$sid/all"}) { push @slist, "0"; } pp(99,qq(checkpoint 1)); foreach $slistitem(@slist) { pp(99,qq(item: $slistitem)); } foreach $key(keys %SUBALLIDS) { if ($key =~ m|^$sid/|) { ($subkey,$subno) = split(/\//,$key,2); pp(99,qq(split $key into $subkey and $subno, adding $subno to \@slist)); push @slist, $subno; } } pp(99,qq(checkpoint 2)); foreach $slistitem(@slist) { pp(99,qq(item: $slistitem)); } foreach $line(@fdata) { @ffields = split(/\t/,$line); $sidsno = $ffields[$FN{'store_id'}].'/'.$ffields[$FN{'section_no'}]; pp(99,qq("Iterating through \@fdata: $line")); %CHECKMAP = (); if (&checksection("global","LPARENTS",$sidsno) == 1) { push @slist, $ffields[$FN{'section_no'}]; push @allsections, $line; pp(99,qq(first time through, adding to \@allsections - $line)); } } $SLIST{$sid} = join ",", @slist; pp(99,qq(Done with $sid, and added $SLIST{$sid})); pp(99,qq(checkpoint 1)); foreach $slistitem(@slist) { pp(99,qq(item: $slistitem)); } @slist = (); } if ($loadthisstore) { if (-e "${script_dir}$cpcache/$sectiondatafilename") { open(FILE, "${script_dir}$cpcache/$sectiondatafilename"); @lines = ; close(FILE); chomp @lines; shift @lines; foreach $line(@lines) { @ffields = split(/\t/,$line); if($ffields[$FN{'store_id'}] ne $loadthisstore) { push @allsections, $line; pp(99,qq(second time through, adding to \@allsections - $line)); } } } } open(FILE, ">${script_dir}$cpcache/$sectiondatafilename"); print FILE "$mainline\n"; print FILE join "\n", @allsections; close(FILE); @allsections = (); open(FILE, ">>${script_dir}$cpcache/$main_script.safe"); print FILE localtime(time); close(FILE); $LOADEDSECTIONDATAFILE{$loadthisstore} = 1; #if ($loadthisstore) { # pp(99,qq(end)); #} } } } sub loadsectiondata { if (!$loadedsectiondata) { # generate list of noise words &prepnoise; $sectiondatacrc = &crc32_calc("sections"); $sectiondatafolder = substr($sectiondatacrc,-2,2); $sectiondatafilename = "$sectiondatafolder/${main_script}_$sectiondatacrc.data"; unless (-d "${script_dir}$cpcache/$sectiondatafolder") { mkdir("${script_dir}$cpcache/$sectiondatafolder"); } my $id; # create list of all store IDs/section no combinations in this install my $ids = processwildcards(join ',', @idlist); # create lists of storeid/sectionno combinations # %SUBALLIDS (a list of storeid/sectionno combos with the .all flag) # %ALLIDS (a list of all storeid/sectionno combos # %IDLIST{$sid}{$sno} (a hash of storeid hashes of sectionnos) pp(99,qq(about to split $ids by commas)); foreach $id(split(/\,/, $ids)) { chomp $id; next if $id eq ""; next if $id =~ /^cpfilter_/i; pp(99,qq(processing split item $id)); my ($sid,$sno,$sall) = split(/[\.\/]/,$id,3); if (!$sno) { $sno = "0"; } if ($sno eq "all") { $sno = "0"; } if ($sall) { $SUBALLIDS{"$sid/$sno"} = 1; } $ALLIDS{"$sid/$sno"} = 1; $IDLIST{$sid}{$sno} = 1; } #&textplain; # if the cache directory exists, the cache file exists, and it's not too old to use #print "sectiondatafilename: $sectiondatafilename\n"; #foreach $key(keys %SLIST) { # print "SLIST{$key}: $SLIST{$key}\n"; #} #exit; if (!-e "${script_dir}$cpcache/$sectiondatafilename" || (-M "${script_dir}$cpcache/$sectiondatafilename" > $expiretime) || $nocache) { #print "entered first loop\n"; #&textplain; #print "Running loadsectiondatafile('')\n"; $| = 1; &loadingscreen("on"); pp(99,qq(running loadsectiondatafile)); &loadsectiondatafile(''); } #print "realstoreid is $realstoreid\n"; #print "$STORE_CRC_ID{$realstoreid}\n"; pp(99,qq(realstoreid is $realstoreid)); foreach $myget(@gets) { $mygetid = $myget; $mygetid =~ s/\W.*//; if ($mygetid && (!-e "${script_dir}$cpcache/${main_script}_iscached_$mygetid.data") || (-M ("${script_dir}$cpcache/${main_script}_iscached_$mygetid.data") > $expiretime)) { #print "entered second loop\n"; pp(99,qq(running loadsectiondatafile for $mygetid)); #&textplain; #print "Running loadsectiondatafile($mygetid)\n"; &loadingscreen("on"); &loadsectiondatafile($mygetid); } } #exit; # and now we actually read in the sectiondata file open(FILE, "${script_dir}$cpcache/$sectiondatafilename"); @fdata = ; close(FILE); chomp @fdata; $mainline = shift @fdata; &parsemainline($mainline); if (exists $FILTER{'literal'}) { foreach $myget(@gets) { $LITERALIDS{$myget} = 1; } } # the purpose of this section is to assemble: # - a list of stores (%STOREIDLIST) # - %RESULTS if a search has been performed (key = storeID.productno) # - %ALLGETS if a .all has been invoked if ($FORM{'search'} !~ /^\s*$/) { $terms = $FORM{'search'}; # Make a URL-Encoded version of the search terms $urlterms = $terms; $urlterms =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; $urlterms =~ s/ /\+/g; # Get rid of dangerous characters $terms = " $terms "; $terms =~ s/[^a-zA-Z0-9\*\? ]/ /g; $terms =~ s/\*\*+/\*/g; $terms =~ s/\?\?+/\?/g; $terms =~ s/\b[\?\*]+\b/ /g; # Save a copy of their search for later; $realterms = $terms; $realterms =~ s/^\s+//; $realterms =~ s/\s+$//; $realterms =~ s/\s+/ /; # Replace wildcards with .wildcards $terms =~ s/\*/\.\*/g; $terms =~ s/\?/\.\?/g; # Remove single quotes (transparently) $terms =~ s/\'//g; @terms = split(/\s+/,$terms); $allindexdatafile = "${main_script}_" . &crc32_calc("index") . ".index"; open(FILE, "${script_dir}$cpcache/$allindexdatafile.data"); while ($fileline = ) { foreach $term(@terms) { if ($fileline =~ /^$term \|/i) { ($term,$linedata) = split(/\s*\|\s*/, $fileline, 2); $resultset .= " $linedata"; } } } $resultset =~ s/^\s+//; $resultset =~ s/\s+$//; @resultset = split(/\s+/, $resultset); foreach $result(@resultset) { ($resultstore,$resultno) = split(/[\/\.]/, $result, 2); $STOREIDLIST{$resultstore} = 1; $RESULTS{$result}++; } } elsif ($productno) { $STOREIDLIST{$realstoreid} = 1; } else { $getcount = @gets; pp(99,qq(there are $getcount \@gets)); foreach $myget(@gets) { next if $myget eq ""; next if $myget =~ /^cpfilter_/i; my ($sid,$sno,$sall) = split(/[\.\/]/,$myget,3); if (!$sno) { $sno = "0"; } if ($sno eq "all") { $sno = "0"; } $ALLGETS{"$sid/$sno"} = 1; $GETLIST{$sid}{$sno} = 1; } foreach $myget(@gets) { pp(99,qq(-processing $myget)); ($loopstoreid,$loopsectionno,$loopsectionall) = split(/\//,$myget,3); if (!$loopsectionno) { $loopsectionno = "0"; } if (($loopsectionno eq "all") || $loopsectionall) { %TPARENTS = (); loadtree("TPARENTS",@fdata); @slist = (); if ($loopsectionall) { pp(99,qq(--into "all" block because loopsectionall is $loopsectionall)); push @slist, $loopsectionno; } else { pp(99,qq(--into "all" block because loopsectionno is $loopsectionno)); push @slist, "0"; } pp(99,qq(--entering \@fdata loop)); foreach $line(@fdata) { @ffields = split(/\t/,$line); $sidsno = $ffields[$FN{'store_id'}].'/'.$ffields[$FN{'section_no'}]; pp(99,qq(---processing $sidno: $line)); %CHECKMAP = (); if (&checksection("$loopstoreid/$loopsectionno","TPARENTS",$sidsno,$loopsectionall) == 1) { pp(99,qq(---adding $ffields[$FN{'section_no'}] to \@slist)); push @slist, $ffields[$FN{'section_no'}]; } } foreach $sitem(@slist) { pp(99,qq(---adding $sitem to \$STOREIDLIST{$loopstoreid})); $STOREIDLIST{$loopstoreid}{$sitem} = 1; } } pp(99,qq(---adding $loopsectionno as sub key to \$STOREIDLIST{$loopstoreid})); $STOREIDLIST{$loopstoreid}{$loopsectionno} .= 1; } } pp(99,qq(here now)); # here we read through the sectiondata file, and save # %SPARENTS, %SNAMES, %SSORTORDER, %SVISIBLE and @thumbsections pp(99,qq(looping through sectiondatafile)); foreach $sectiondataline(@fdata) { pp(99,qq( now on $sectiondataline)); @ffields = split(/\t/,$sectiondataline); $thisstoresection = $ffields[$FN{'store_id'}] . "/" . $ffields[$FN{'section_no'}]; $SPARENTS{$thisstoresection} = $ffields[$FN{'parent_section_no'}]; $SNAMES{$thisstoresection} = $ffields[$FN{'caption'}]; $SNAMES{$thisstoresection} =~ s/<.*?>//g; if ($SNAMES{$thisstoresection} =~ /^\s*$/) { $SNAMES{$thisstoresection} = "Unnamed Section"; } $SSORTORDER{$thisstoresection} = $ffields[$FN{'sort_priority'}]; $SVISIBLE{$thisstoresection} = $ffields[$FN{'visible'}]; if (!$productno) { $teststoreid = $ffields[$FN{'store_id'}]; $testparentsectionno = $ffields[$FN{'parent_section_no'}]; $testsectionno = $ffields[$FN{'section_no'}]; pp(99,qq( \$teststoreid = $teststoreid)); pp(99,qq( \$testparentsectionno = $testparentsectionno)); pp(99,qq( \$testsectionno = $testsectionno)); if ($STOREIDLIST{$teststoreid} || $LITERALIDS{"$teststoreid/$testsectionno"} || $RESULTS{"$teststoreid/$testsectionno"}) { pp(99,qq( In the first block)); #if($STOREIDLIST{$teststoreid}{$testparentsectionno}) { pp(99,qq( Test 1 passed)); #} else { pp(99,qq( Test 1 failed)); #} #if(($ffields[$FN{'visible'}] == 1) || (lc($ffields[$FN{'visible'}]) eq "true")) { pp(99,qq( Test 2 passed)); #} else { pp(99,qq( Test 2 failed)); #} #if(!exists $LITERALIDS{"$teststoreid/$testparentsectionno"}) { pp(99,qq( Test 3 passed)); #} else { pp(99,qq( Test 3 failed)); #} if((($STOREIDLIST{$teststoreid}{$testparentsectionno} && (($ffields[$FN{'visible'}] == 1) || (lc($ffields[$FN{'visible'}]) eq "true")) && (!exists $LITERALIDS{"$teststoreid/$testparentsectionno"})) || $LITERALIDS{"$teststoreid/$testsectionno"} || $RESULTS{"$teststoreid/$testsectionno"}) && ((!exists $FILTER{'type'}) || exists($FILTER{'inherit'})) && !$KILLSECTIONS{$testsectionno} ) { pp(99,qq( In the second block, part 1)); push @thumbsections, $sectiondataline; pp(99,qq(adding to \@thumbsections $sectiondataline)); } elsif ((($realstoreid eq $teststoreid) && ($sectionno == $testsectionno)) || (($storeid eq "$teststoreid/$testsectionno") && !$prodstore)) { pp(99,qq( In the second block, part 2)); for($i=0;$i<@ffields;$i++) { $SECTIONINFO{$keys[$i]} = $ffields[$i]; if ($DECODE{$keys[$i]}) { $SECTIONINFO{$keys[$i]} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $SECTIONINFO{$keys[$i]} =~ tr/\+/ /; } } } } } } pp(99,qq(blah)); # unless we've got a cpfilter_literal or a product page, # we need to go through the list of stores to see what we want to display # So we iterate through the store list, and read in each store's products. # If the product is in one of the sections in our section list, # we add it to the @thumbproducts list. if (!exists $FILTER{"literal"} || $productno) { pp(99,qq(processing \%STOREIDLIST)); if (!-d "${script_dir}cpcache") { mkdir("${script_dir}cpcache", 0777); } if (!-d "${script_dir}$cpcache") { mkdir("${script_dir}$cpcache", 0777); } foreach $storeidget(sort keys %STOREIDLIST) { pp(99,qq(-now at $storeidget)); $productdatacrc = &crc32_calc("$storeidget"); $productdatafolder = substr($productdatacrc,-2,2); $productdatafilename = "$productdatafolder/${main_script}_$productdatacrc.data"; unless (-d "${script_dir}$cpcache/$productdatafolder") { mkdir("${script_dir}$cpcache/$productdatafolder"); } pp(99,qq(-filename: $productdatafilename)); if ((!-e "${script_dir}$cpcache/$main_script.loading.txt") || (-M "${script_dir}$cpcache/$main_script.loading.txt" > 0.5)) { if (!(-d "${script_dir}$cpcache" && -e "${script_dir}$cpcache/$productdatafilename" && (-M "${script_dir}$cpcache/$productdatafilename" < $expiretime) && !$nocache && (-e "${script_dir}$cpcache/$main_script.safe"))) { pp(99,qq(going to get data for $storeidget...)); if (-e "${script_dir}$cpcache/$main_script.safe") { unlink("${script_dir}$cpcache/$main_script.safe"); open(LOADING,">${script_dir}$cpcache/$main_script.loading.txt"); print LOADING "."; close(LOADING); } &loadsectiondatafile($storeidget); # read in data for this store ID pp(99,qq(going to get data for ) . $SLIST{$storeidget}); ############# # OLD: #&textplain; #$sectiondata = gencdat($SLIST{$storeidget},"",$storeidget); #print "SLIST{$storeidget}: $SLIST{$storeidget}\n"; #print $sectiondata; #exit; ############# ############# # NEW: #unless($maxcpresults) { # $maxcpresults = gencdat("","&maxresults=yes",""); # unless ($maxcpresults > 0) { # $maxcpresults = "20000"; # } #} $maxcpresults = "5000"; #&textplain; #print "SLIST{$storeidget}: $SLIST{$storeidget}\n"; $maxsectioncall = int($maxcpresults / 100); pp(99,qq(SLIST{$storeidget}: $SLIST{$storeidget})); @sectiondatabits = split(/\,/,$SLIST{$storeidget}); foreach $sectiondatabit(@sectiondatabits) { $SDB{$sectiondatabit} = 1; } @sectiondatabits = keys %SDB; undef %SDB; @sectiondatabits = sort(@sectiondatabits); $sectiondata = ""; $getheader = 1; while (@sectiondatabits) { my @mysectiondatabits = splice(@sectiondatabits,0,$maxsectioncall); if ($getheader == 1) { # read in data for this store ID pp(99,qq(going to get data for $storeidget sections: ) . join(",", @mysectiondatabits)); $sectiondata = gencdat(join(",", @mysectiondatabits),"&nosections=true",$storeidget); } else { $sectiondata = gencdat(join(",", @mysectiondatabits),"&noheader=true&nosections=true",$storeidget); pp(99,qq(going to get data for $storeidget sections with no header or section info: ) . join(",", @mysectiondatabits)); } if ($getheader == 1) { @fdata = split(/[\r\n]+/,$sectiondata); chomp @fdata; $mainline = shift @fdata; &parsemainline($mainline); if (length($fdata[0]) > 10) { @ffields = split(/\t/,$fdata[0]); $fileset = $ffields[$FN{'store_id'}]; $filesetcrc = &crc32_calc($fileset); $filesetfolder = substr($filesetcrc,-2,2); $filesetname = "$filesetfolder/${main_script}_$filesetcrc"; unless(-d "${script_dir}$cpcache/$filesetfolder") { mkdir("${script_dir}$cpcache/$filesetfolder"); } $getheader = 0; if (!(-e "${script_dir}$cpcache/$filesetname.data") || (-M "${script_dir}$cpcache/$filesetname.data" > 0.0009)) { open(FILE, ">${script_dir}$cpcache/$filesetname.data"); #print FILE "\n\nprinting first line " . ++$printing . " ----------------------------------------------------------------------\n\n"; print FILE $sectiondata; #print FILE "\n\nstop printing first line $printing ---------------------------------------------------------------------\n\n"; close(FILE); open(FLAG,">${script_dir}$cpcache/${main_script}_iscached_$fileset.data"); print FLAG localtime(time); close(FLAG); } } } else { #subsequent call, take it on faith open(FILE, ">>${script_dir}$cpcache/$filesetname.data"); #print FILE "\n\nprinting additional line " . ++$printing . " ----------------------------------------------------------------------\n\n"; print FILE $sectiondata; #print FILE "\n\nstop printing additional line $printing ---------------------------------------------------------------------\n\n"; close(FILE); } } #exit; # END NEW ############ open(FILE, ">>${script_dir}$cpcache/$main_script.safe"); print FILE localtime(time); close(FILE); unlink("${script_dir}$cpcache/$main_script.loading.txt"); } } pp(99,qq(-processing \@productdatalines)); $pdlcounter = 0; open(FILE, "${script_dir}$cpcache/$productdatafilename"); $skip = ; while ($productdataline = ) { $pdlcounter++; chomp $productdataline; pp(99,qq(--now on $productdataline)); @ffields = split(/\t/,$productdataline); if (( ($STOREIDLIST{$ffields[$FN{'store_id'}]}{$ffields[$FN{'parent_section_no'}]} && !$target) || ($target && $ffields[$FN{'product_no'}] == $productno) || ($RESULTS{$ffields[$FN{'store_id'}].".".$ffields[$FN{'product_no'}]}) ) && ($ffields[$FN{'type'}] eq "p")) { # run filters on products if (!$productno) { my $testname = $ffields[$FN{'caption'}]; if ($FILTER{'name'}) { my @names = split(/\0/,$FILTER{'name'}); my $name; my $match = 0; my $badmatch = 0; foreach $name(@names) { if ($name =~ /^\-/) { $name =~ s/^\-//; if ($testname =~ /$name/i) { $badmatch = 1; } } else { $positivematch = 1; if ($name =~ /^\~(.+)\~$/) { $name =~ s/\~//g; if ( $testname =~ /\b$name\b/i) { $match = 1; } } else { if ($testname =~ /$name/i) { $match = 1; } } } } unless (($match && !$badmatch && $positivematch) || (!$badmatch && !$positivematch)) { next; } } my $testprice = $ffields[$FN{'sell_price'}]; if ($FILTER{'cost'}) { my @prices = split(/\0/,$FILTER{'cost'}); $badcost = 0; foreach $price(@prices) { if ($price =~ /^\~/) { $price =~ s/^\~//; $badcost = 1 if $testprice > $price; } elsif ($price =~ /\~$/) { $price =~ s/\~$//; $badcost = 1 if $testprice < $price; } else { $badcost = 1 if $testprice != $price; } } next if $badcost; } if (exists $FILTER{'type'} || $SECTION{'ProductTypeFilter'}) { my @types = split(/\0/,$FILTER{'type'}); if ($SECTION{'ProductTypeFilter'} && (!exists $FILTER{'type'} || ($FILTER{'type'} =~ /\-/))) { $SECTION{'ProductTypeFilter'} =~ s/[^0-9\,]//g; $SECTION{'ProductTypeFilter'} =~ s/^\,+//; $SECTION{'ProductTypeFilter'} =~ s/\,+$//; $SECTION{'ProductTypeFilter'} =~ s/(\d+)/-$1/g; push @types, split(/\,/, $SECTION{'ProductTypeFilter'}); } my $goodtype = 0; my $badtype = 0; my $badlookup = 0; foreach $type(@types) { if ($type =~ /^-/) { $badlookup = 1; $type =~ s/\D//g; if ($type eq $ffields[$FN{'product_type_no'}]) { $badtype = 1; } } else { if ($type eq $ffields[$FN{'product_type_no'}]) { $goodtype = 1; } } } next unless ($goodtype || ($badlookup && !$badtype)); } } push @thumbproducts, $productdataline; if ($productno) { $foundproductno = 1; last; } } } close(FILE); last if $foundproductno; } } push @allthumbs, @thumbsections; push @allthumbs, @thumbproducts; chomp @allthumbs; # then, with all the product and section lines added to @allthumbs, # we add each product's information to %THUMBDATA foreach $line(@allthumbs) { $line =~ s/\s+$//; @ffields = split(/\t/,$line); for($i = 0; $i < @ffields; $i++) { my $prodid; if ($ffields[$FN{'type'}] eq "s") { $prodid = $ffields[$FN{'store_id'}]."/".$ffields[$FN{'section_no'}]; } else { $prodid = $ffields[$FN{'store_id'}].".".$ffields[$FN{'product_no'}]; } my $key = $keys[$i]; my $field = $ffields[$i]; if ($DECODE{$key}) { $field =~ s/\+/ /g; $field =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; } if ($key eq "caption") { $field =~ s/<.*?>/ /g; } $THUMBDATA{$prodid}{$key} = $field; } } $loadedsectiondata = 1; } &loadingscreen("off"); } sub getit { &loadsectiondata; my $get = shift; my $url = shift; my $nocache = shift; if ($get eq "sectionpage") { #do nothing } else { $cached = 0; if ($url) { $url =~ s|^http://||; ($domain,$get) = split(/\//,$url,2); $h = $domain; $f = "/$get"; $p = "80"; } else { $h = "www.$cpdomain"; $f = "/cp/$get"; $p = "80"; } $crcno = &crc32_calc($get); $crcfolder = substr($crcno,-2,2); $crc = "$crcfolder/${main_script}_$crcno"; unless (-d "${script_dir}$cpcache/$crcfolder") { mkdir("${script_dir}$cpcache/$crcfolder"); } if (-d "${script_dir}$cpcache" && -e "${script_dir}$cpcache/$crc.txt" && (-M "${script_dir}$cpcache/$crc.txt" < $expiretime) && !$nocache && ($FORM{'nocache'} eq "")) { open(CACHE,"<${script_dir}$cpcache/$crc.txt"); { local $/; $cpdata = ; } close(CACHE); if (length($cpdata) > 100) { $cached = 1; } } if (($cpdata =~ /(product|store) not found/i) || ($target && ($cpdata !~ /qty/)) || (!$target && ($cpdata !~ /store_id\t/)) || ($cpdata =~ /down for maintenance/i) ) { $cached = 0; $cpdata = ""; } unless ($cached) { if (-e "${script_dir}forcelwp.txt") { BEGIN { eval "use LWP::Simple"; } $cpdata = get("http://$h$f") || &noconnection($!,$h); } else { BEGIN { eval "use LWP::Simple"; if ($@ || $nolwp) { $ERROR{'LWP'} = $@; $nolwp = 1; use IO::Socket; } } if ($nolwp) { my $socket = new IO::Socket::INET (PeerAddr => $h, PeerPort => $p, Proto => 'tcp') or &noconnection($!,$h); $socket->autoflush (1); print $socket "GET $f HTTP/1.1\015\012", "Host: $h\015\012", "Connection: close\015\012", "User-Agent: cpshop\015\012\015\012"; while (<$socket>) { push @text, $_; if ((/ITEMS \#\#\# \-\->/) || (//)) { $socket->close; $socketclosed = 1; } } unless ($socketclosed) { $socket->close; } $htmlfile = join '', @text; ($headers,$cpdata) = split(/\r?\n\r?\n/,$htmlfile,2); } else { $cpdata = get("http://$h$f") || &noconnection($!,$h); } } } if (!$cpdata && !$nolwp) { # Try socket anyway. use Socket; socket(S,AF_INET,SOCK_STREAM,0)||&noconnection($!,$h); select((select(S),$|++)[0]); connect(S, sockaddr_in($p,inet_aton($h)))||&noconnection($!,$h); print S "GET $f HTTP/1.0\nUser-Agent: cpshop\n\n"; # print; my @text = ; $htmlfile = join '', @text; ($headers,$cpdata) = split(/\r?\n\r?\n/,$htmlfile,2); } if (-d "${script_dir}$cpcache" && -w "${script_dir}$cpcache" && !$cached) { open(CACHE,">${script_dir}$cpcache/$crc.txt"); print CACHE "\n"; if ($target && !$domain) { if ($cpdata =~ m|(
.*?)|s) { $cpmatch = $1; print CACHE $cpmatch; } else { print CACHE $cpdata; } } else { if ($cpdata =~ m|(<\!\-\- \#\#\# Items.*ITEMS \#\#\# \-\->)|s) { $cpmatch = $1; print CACHE $cpmatch; } else { print CACHE $cpdata; } } close(CACHE); #unless ($ENV{'OS'} =~ /windows/i) { # `chmod 666 ${script_dir}$cpcache/$crc.txt`; #} } $cpdata =~ s|’|\'|g; $cpdata =~ s|®||g; $cpdata =~ s|ñ||g; $cpdata =~ s|”|\"|g; $cpdata =~ s||\"|g; $cpdata =~ s|Æ|\'|g; @text = (); return $cpdata; } } sub assemble_gets { pp(99,qq(assembling gets)); @subgets = split(/\s*\,\s*/,$get); foreach $subget(@subgets) { push @gets, $subget; pp(99,qq(adding $subget to \@gets)); } } sub getpage { if ($target) { $temp_storeid = $storeid; $temp_storeid = &get_filters($temp_storeid); if ($SECTION{'ShowZoomLink'} eq "no") { $get =~ s/\&zoom\=yes//gi; } push @gets, $get; } else { $get = &get_filters($get); &assemble_gets; } if (int($FILTER{'columns'}) > 0) { $SECTION{'thumbcolumns'} = int($FILTER{'columns'}); } if (int($FILTER{'rowsperpage'}) > 0) { $SECTION{'thumbrows'} = int($FILTER{'rowsperpage'}); } elsif ($FORM{'search'} !~ /^\s*$/) { if ($SECTION{'searchrows'}) { $SECTION{'thumbrows'} = $SECTION{'searchrows'}; } else { $SECTION{'thumbrows'} = 5; } } if ($target) { &getit("browse/store/$realstoreid.$productno"); } else { &getit('sectionpage'); } if ($target) { $cpdata =~ m|()|s; my $productjs = $1; $productjs =~ s|href=\"/|href=\"http://www.cafepress.com/|g; $productjs =~ s|src=\"/|src=\"http://www.cafepress.com/|g; $cpdata =~ m|(.*?)|s; my $table = $1; unless ($table =~ /addtocart/) { &dobadurl("home"); } $table =~ s/
/
/; $table =~ s/ href="#"/ poundlink/g; $table =~ s/.*?||si; if (($SECTION{'DisplayDescriptionAboveOrderForm'} eq "yes") && ($SECTION{'OrderFormOnRight'} ne "yes")) { $table =~ s|(.*?)||i; $thisproddescription = $1; $table =~ s|
$thisproddescription
.*?
||i; } $table =~ s|Value="Add to Cart"|Value="$LANG{'Add to Cart'}"|gi; if ($SECTION{'DummyStoreID'} ne "") { $table =~ s|||ig; } $table =~ s|||gi; if ($SECTION{'PopUpShoppingCart'} eq "yes") { $table =~ s|/cp/addtocart.aspx"|/cp/addtocart.aspx" target="cartWin"|i; $table =~ s|)|$1|; } elsif ($SECTION{'PopUpShoppingCart'} eq "newwindow") { $table =~ s|/cp/addtocart.aspx"|/cp/addtocart.aspx" target="_blank"|i; $table =~ s|(addtocart.aspx\".*?>)|$1|; } elsif ($SECTION{'PopUpShoppingCart'} eq "frametop") { $table =~ s|/cp/addtocart.aspx"|/cp/addtocart.aspx" target="_top"|i; $table =~ s|(addtocart.aspx\".*?>)|$1|; } else { $table =~ s|(addtocart.aspx\".*?>)|$1|; } $table =~ s|||; $table =~ s|color:\#000000\;text\-decoration:underline\;|color:\#000000\;|; $table =~ s|.*?||; if ($SECTION{'ShowZoomLink'} eq "no") { $table =~ s|]+moredetails\.aspx.+?||g; } else { $table =~ s|>View Larger|>$LANG{'View Larger Image'}|; } if ($SECTION{'ShowEmailFriendLink'} eq "no") { $table =~ s|]+efriend.+?||i; } else { $table =~ s|>Tell [^<]+ product!<|>$LANG{'Tell a friend'}<|; $table =~ s|»|

»|; } $table =~ s|\)

(.*?)

$fontstart$1$fontend

(.*?)<|; $producttype = $2; $table =~ s|||; if ($SECTION{'ShowFrontAndBack'} eq "yes") { if ($table =~ m|Back[_-\w]*\.jpg\" height="240"|) { $table =~ s|]*>]*>click to view.*?name="img1" src="(.*?)".*?
||; } else { $table =~ s|]*>]*>click to view.*?name="img2" src="(.*?)".*?
||; } } else { $table =~ s|click to view|click to view|; } $table =~ s|class="head"|class="cpshopbig"|g; $table =~ s|class=\"smallprint(\" style=\")?|class=\"cpshopsmaller\"|g; $table =~ s|>Qty:<|>$fontstart$LANG{'Quantity'}:$fontend<|; $table =~ s|>Size:|>$fontstart$LANG{'Size'}:$fontend|; $table =~ s|>Color:<|>$fontstart$LANG{'Color'}:$fontend<|; $table =~ s|

Original Price \$(.*?)
Sale Price \$(.*?)

|

$LANG{'Original Price'} \$$1
$LANG{'Sale Price'} \$$2

|; $table =~ s|>View size chart<|>$LANG{'View size chart'}<|i; $table =~ s|>Kids Small|>$LANG{'Kids Small'}|; $table =~ s|>Kids Medium|>$LANG{'Kids Medium'}|; $table =~ s|>Kids Large|>$LANG{'Kids Large'}|; $table =~ s|>Small|>$LANG{'Small'}|; $table =~ s|>Medium|>$LANG{'Medium'}|; $table =~ s|>Large|>$LANG{'Large'}|; $table =~ s|>X-Large|>$LANG{'X-Large'}|; $table =~ s|>2X-Large \(|>$LANG{'2X-Large'} \(|; $table =~ s|>3X-Large \(|>$LANG{'3X-Large'} \(|; $table =~ s|>4X-Large \(|>$LANG{'4X-Large'} \(|; $table =~ s|([^A-Za-z\/])img/|${1}http://www.cafepress.com/cp/img/|g; $table =~ s|(Product Number): (\d+)|$LANG{'Product Number'}: $2|; $table =~ s|Provided by Store Owner -->

(.*?)

$fontstart$1$fontend

||i; $table =~ s|||i; $table =~ s|||i; $table =~ s|||i; $table =~ s|||i; $table =~ s|||; if ($SECTION{'ShowProductInformation'} eq "no") { $table =~ s|Detailed product information below\.||; $table =~ s|.*?||i; } else { $table =~ s|href="#|href="$scripturl$cleanurl$STORE_CRC{$storeid}$cleanurl2$ENV{'QUERY_STRING'}#|g; $table =~ s///g; $table =~ s|

(.*?)

|

$fontstart$1$fontend

|; } if ($SECTION{'ShowAdditionalPhotos'} eq "no") { $table =~ s|.*?||; } elsif ($SECTION{'ShowAdditionalPhotos'} eq "split") { $table =~ s|(_2.jpg.*?).*?|$1|; } $table =~ s|

Additional Photos:|

$fontstart$LANG{'Additional Photos'}:$fontend|; $table =~ s|>click to view
front / back:<|>$LANG{'click to view'}
$LANG{'front back'}:<|i; $table =~ s/(storeid\=\Q$storeid\E)\&(storeid\=\Q$storeid\E)/storeid=$storeid/g; $table =~ s/(storecrc\=$STORE_CRC{$storeid})\&(storecrc\=$STORE_CRC{$storeid})/storecrc=$STORE_CRC{$storeid}/g; if ($SECTION{'ShowConverter'} eq "yes") { $table =~ s|(.*?)(\d+\.\d+)(.*?)|

|; #$table =~ s|Price -->

(.*?)(\d+\.\d+)()?()?|Price -->$1$2$3$4
$SECTION{'ShowConverterText'}|; } $table =~ s|(.*?)|$1|; # Inventory Status $table =~ s|In Stock: Will ship in 2-3 business days\.|$LANG{'In Stock: Will ship in 2-3 business days.'}|; #$table =~ s|>Front Image:<|>$LANG{'Front Image'}:<|; #$table =~ s|>Back Image:<|>$LANG{'Back Image'}:<|; $table =~ s|Image (\d+):\s*|$LANG{'Image'} $1: |g; $table =~ s|
()
|$1|; $table =~ s|'media_player.aspx\?|'http://www.cafepress.com/cp/media_player.aspx\?pid=[<[pid]>]&cjpid=[<[cjpid]>]&xid=[<[xid]>]&tid=[<[tid]>]\&|g; #$table = qq(\s*$|$LINE{'costconvert'}|i; #} $line = $cell; $line =~ s|"/cp/img/|"http://www.cafepress.com/cp/img/|g; $line =~ s|"/content/|"http://www.cafepress.com/content/|g; $line_counter++; $CELLS{$line_counter} = $line; $SORT_PRODUCTNAME{$line_counter} = $TYPE{$productnumber}; $SORT_PRODUCTCOST{$line_counter} = $PRICE{$productnumber}; $SORT_PRODUCTNUMBER{$line_counter} = $productdigits; $SORT_PRODUCTTYPENO{$line_counter} = $LINE{'producttypeno'}; $SORT_STOREID{$line_counter} = $storeprefix; $SORT_CELLTYPE{$line_counter} = 1; $SORT_SORTPRIORITY{$line_counter} = $THUMBDATA{$thumb}{'sort_priority'}; $SORT_RANDOM{$line_counter} = substr(substr($productnumber, -4, 4) * substr(time, 0, -4) * 7, -4, 4); $CONTAINSPTD{$LINE{'producttypeno'}} = 1; push @cells, $line_counter; } elsif ($THUMBDATA{$thumb}{'type'} eq "s") { if ($FILTER{'name'} && !exists($FILTER{'inherit'})) { next; } if ($FILTER{'cost'} && !exists($FILTER{'inherit'})) { next; } if ($FILTER{'type'} && !exists($FILTER{'inherit'})) { next; } next if $KILLSECTIONS{$THUMBDATA{$thumb}{'section_no'}}; $storeprefix = $THUMBDATA{$thumb}{'store_id'}; $sectionnumber = $THUMBDATA{$thumb}{'section_no'}; $storetitle = $THUMBDATA{$thumb}{'caption'}; if ($THUMBDATA{$thumb}{'img_type'} =~ /^\w+$/) { $extension = $THUMBDATA{$thumb}{'img_type'}; } else { $extension = "jpg"; } if ($THUMBDATA{$thumb}{'img'}) { $storethumb = "http://logo.cafepress.com/" . substr($THUMBDATA{$thumb}{'img'},length($THUMBDATA{$thumb}{'img'}) - 1,1) . "/" . $THUMBDATA{$thumb}{'img'} . "." . $extension; } else { $storethumb = ""; } $teaser = $THUMBDATA{$thumb}{'teaser'}; $storetitle_encoded = $storetitle; $storetitle_encoded =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; $LINE{'linksrc'} = qq($scripturl$cleanurl) . urlcommify(qq($STORE_CRC{$storeid}/$storeprefix/$sectionnumber) . urlify($storetitle,"/-")); $LINE{'linkstarts'} = qq(); if ($storethumb) { $LINE{'thumbnail'} = qq($storetitle); $LINE{'thumbsrc'} = $storethumb; } else { $LINE{'thumbnail'} = qq(); $LINE{'thumbsrc'} = "http://content.cafepress.com/global/img/spacer.gif"; } $LINE{'storename'} = $storetitle; $LINE{'linkends'} = qq(); $LINE{'storeid'} = $storeid; $LINE{'teaser'} = $teaser; $LINE{'parentsectionno'} = $THUMBDATA{$thumb}{'parent_section_no'}; $LINE{'alias'} = $STORE_CRC{$storeid}; $LINE{'sectionstoreid'} = $THUMBDATA{$thumb}{'store_id'}; my $cell = $SECTION{'storecelltemplate'}; if ($SECTION{'GetHooks'} eq "yes") { $buildinggrid = 1; $cell = gethooks($cell); $buildinggrid = 0; } else { $cell =~ s/<\[hook:\w+\]>//g; } $cell =~ s/<\[(.*?)\]>/$LINE{$1}/g; my $dimensions = qq(height="$SECTION{'thumbheight'}" width="$SECTION{'thumbwidth'}"); $cell =~ s/height="150" width="150"/$dimensions/; $line = $cell; $line_counter++; $CELLS{$line_counter} = $line; $SORT_PRODUCTNAME{$line_counter} = $storetitle; $SORT_PRODUCTCOST{$line_counter} = 999999999999; $SORT_PRODUCTNUMBER{$line_counter} = 0; $SORT_PRODUCTTYPENO{$line_counter} = 0; $SORT_STOREID{$line_counter} = "$storeprefix.$sectionnumber"; $SORT_CELLTYPE{$line_counter} = 0; $SORT_SORTPRIORITY{$line_counter} = 10000 - $THUMBDATA{$thumb}{'sort_priority'}; $SORT_RANDOM{$line_counter} = 0; push @cells, $line_counter; } if (!$foundaproduct) { if ((-e "${script_dir}$cpcache/$crc.txt") && (-M "${script_dir}$cpcache/$crc.txt" > 0.04)) { unlink("${script_dir}$cpcache/$crc.txt"); } } } } } sub get_filters { my $get = $_[0]; while ($get =~ /(\,)?cpfilter_(name|cost|newest|sort|keywords|description|template|prodtemplate|columns|rowsperpage|inherit|type|literal|killsection)/) { # cpfilter_name:mug (with "mug" in the name) # cpfilter_name:-mug (without "mug" in the name) # cpfilter_cost:17.99 (with a price of 17.99) # cpfilter_cost:~17.99 (priced 17.99 and under) # cpfilter_cost:17.99~ (priced 17.99 and up) # cpfilter_newest:10 (newest 10 items) # cpfilter_sort:productname,productcostup,productcostdown,storeid,storeidrev,old2new,new2old $get =~ s/(\,)?cpfilter_([^\#\&\,]*)//; my $code = $2; my($code,$code_content) = split(/\:/,$code,2); $code_content =~ s/\++/ /g; $code_content =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($FILTER{$code}) { $FILTER{$code} .= "\0"; } $FILTER{$code} .= $code_content; if ($code eq "killsection") { $KILLSECTIONS{$code_content} = $code_content; } } if (($storeid =~ /cpfilter_inherit/) && !$processed_inheritance && $prodstore) { $processed_inheritance = 1; $inherited_get = &get_filters($storeid); } else { foreach my $piece(split(/\s*\,\s*/,$storeid)) { if ($piece =~ /cpfilter_template:/) { $piece =~ s/^cpfilter_template://; $inherited_template = $piece; } if ($piece =~ /cpfilter_prodtemplate:/) { $piece =~ s/^cpfilter_prodtemplate://; $inherited_prodtemplate = $piece; } } } return $get; } sub getmorecolordata { unless ($gotnocolors) { $gotnocolors = 1; if (-e "${script_dir}$main_script.nocolors") { my $nc; open(NC,"<${script_dir}$main_script.nocolors"); { local $/; $nc = ; } close(NC); $nc =~ s/[^0-9 ]/ /g; $nc =~ s/\s+/ /g; $nc =~ s/ $//; $nc =~ s/^ //; foreach $line(split(/ /,$nc)) { $NOCOLORS{$line} = 1; } } } } sub crc32_calc #-- Calculate 32-bit CRC checksum ----------------------------------------------------------------- { # 32 BIT ANSI X3.66 CRC checksum # Based on C source: http://www.snippets.org/snippets/portable/CRC_32+C.php3, Copyright (C) 1986 Gary S. Brown # Converted to Perl by: Cusimano.Com Corporation, http://www.cusimano.com local($s) = @_; local($n, $crc, $i) = (length($s), 0xFFFFFFFF, 0); &crc32_init if (!defined(@crc32_table)); for ($i = 0; $i < $n; $i++) { $crc = $crc32_table[($crc ^ ord(substr($s, $i, 1))) & 0xff] ^ ($crc >> 8) } $crc = ~$crc; if ($crc == 0) { return 999; } else { return $crc; } } sub crc32_init #-- Initialize 32-bit CRC checksum polynomial table ----------------------------------------------- { # CRC polynomial 0xedb88320 # Polynomial: X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 @crc32_table = ( 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d ); } sub gencdat { local $s = shift; local $o = shift; $sids = join ",",@_; #if (length($s) > 13000) { # $s = ""; #} $rdm = int(rand(38))+1; $S = qq(\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x63\x61\x66\x65\x70\x72\x65\x73\x73\x2e\x63\x6f\x6d\x2f\x63\x70\x2f\x73\x74\x6f\x72\x65\x74\x73\x76\x2e\x61\x73\x70\x78\x3f\x69\x70\x3d); local $d2 = qq($S&id=$sids).&genxdat.qq($o§ions=$s&pw=).(237*$rdm).'.'.ksprintf($rdm,jsprintf(2)); local $d = usprintf($d2); #&textplain; #print "$d2\n"; $cdatdebug = 1; if ($cdatdebug) { $cdatdebugger++; open(DEBUG,">${script_dir}$cpcache/$main_script.cdat.txt"); print DEBUG localtime(time); #print DEBUG "$d2\n\n"; #print DEBUG "$d"; close(DEBUG); } return $d; } sub genndat { local $t = shift; local $n = shift; local $S = qq(\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x63\x61\x66\x65\x70\x72\x65\x73\x73\x2e\x63\x6f\x6d\x2f\x63\x70\x2f\x73\x74\x6f\x72\x65\x74\x73\x76\x2e\x61\x73\x70\x78\x3f\x69\x70\x3d); local $d = usprintf(qq($S&$t=$n)); return $d; } sub genxdat { if (-e "${script_dir}cpdata.lib") { return "&freepass=yes"; } } sub pad { if (length($_[0]) < 2) { return "0$_[0]"; } else { return $_[0]; } } sub let { @ab=(A..Z);return $ab[int(rand(@ab))]; } sub usprintf { my $e; my $g = $_[0]; my $h = $_[1]; $f = $g; $f =~ s|.*?//||; $f =~ s|^[^/]+||; pp(99,qq($f)); unless ($h) { $h = "www.$cpdomain"; } if (-e "${script_dir}forcelwp.txt") { BEGIN { eval "use LWP::Simple"; } $e = get($g); } else { BEGIN { eval "use LWP::Simple"; if ($@ || $nolwp) { $ERROR{'LWP'} = $@; $nolwp = 1; } } if (!$nolwp) { $e = get($g); } if (!$e) { use IO::Socket; my $socket = new IO::Socket::INET (PeerAddr => $h, PeerPort => 80, Proto => 'tcp') or &noconnection($!,$h); $socket->autoflush (1); my @text; print $socket "GET $f HTTP/1.1\015\012", "Host: www.$cpdomain\015\012", "Connection: close\015\012", "User-Agent: cpshop\015\012\015\012"; while (<$socket>) { push @text, $_; } $socket->close; $htmlfile = join '', @text; ($headers,$e) = split(/\r?\n\r?\n/,$htmlfile,2); $e =~ s/^0[0-9ABCDEF]{7}\r?\n//; $e =~ s/\r?\n0[0-9ABCDEF]{7}\r?\n//g; } } if (($e =~ />CafePress.com : Error\s*|)) { &noconnection("CafePress is undergoing maintenance."); } return $e; } sub jsprintf { if ($ip) { return $ip . "_" . getdt(1); } elsif (-e "${script_dir}cpcache/local.ip") { open(IP,"${script_dir}cpcache/local.ip"); { local $/; $ip = ; } close(IP); $ip =~ s/_.*//; $ip =~ s/[^\d\.]//g; return $ip . "_" . getdt(1); } else { $ip = usprintf("${S}1"); open(IP,">${script_dir}cpcache/local.ip"); print IP $ip; close(IP); $ip =~ s/_.*//; $ip =~ s/[^\d\.]//g; return $ip . "_" . getdt(1); } } sub ksprintf { local($rdm,$str) = @_;$i=0; local $c; local @n; local @s = split(//,$str); foreach $c(@s) { $i++;push @n, int((ord($c)*$rdm)+$i) . let(1); } return join '', @n; } sub getdt { $date = localtime; ($second, $minute, $hour, $day, $month, $year, $weekday, $dayofyear, $isdst) = localtime(time); $year += 1900; $month = pad($month + 1); $day = pad($day); $hour = pad($hour); $minute = pad($minute); $second = pad($second); return "$year-$month-$day $hour:$minute:$second"; } sub urlcommify { my $bit = $_[0]; if ($SECTION{'UseSEOLinks'} eq "yes") { #$bit =~ s|/|,|g; #$bit =~ s|,-,-,|,|; $bit =~ s|\.|\-|; $bit =~ s|/|\.|g; $bit =~ s|\.\-\.-\+|\+|; $bit =~ s|\.-\+|\+|; #$bit =~ s|\.|/|; #$bit =~ s|,-,|_|; $bit .= $SECTION{'SEOLinksYesExtension'}; } return $bit; } sub urlify { if ($SECTION{'UseSEOLinks'} eq "custom") { return $SECTION{'SEOLinksCustomText'}; } elsif ($SECTION{'UseSEOLinks'} eq "yes") { $toencode = $_[0]; $toencode =~ tr/A-Z/a-z/; $toencode =~ s/ \& / and /g; $toencode =~ s/^\s+//; $toencode =~ s/\s+$//; $toencode =~ s/\s/\-/g; $toencode =~ s/[^a-z0-9\-_\.]//g; return $_[1] . "+" . $toencode; } else { return ""; } } sub commonscripts { unless ($SECTION{'HideCommonCSS'} eq "yes") { $commonscripts = <<"ENDHTML"; ENDHTML } unless ($SECTION{'HideCommonJS'} eq "yes") { $commonscripts .= <<"ENDHTML"; ENDHTML } $commonscripts .= <<"ENDHTML"; $SECTION{'StyleOverride'} ENDHTML } sub loadingscreen { $lstype = $_[0]; if ($SECTION{'DisplayNowLoading'} eq "yes") { if ($lstype eq "on") { unless ($loadingscreen) { &texthtml; print qq(
$SECTION{'NowLoadingHTML'}
); $loadingscreen = 1; } } elsif ($lstype eq "off") { if ($loadingscreen) { print qq(\n); } } } } sub texthtml { if (!$headersprinted) { unless (@ARGV && ($ARGV[0] !~ /^conv\:/)) { print "Content-Type: text/html\n\n"; $headersprinted = 1; push @ARGV, "noheader"; } } } sub textplain { if (!$headersprinted) { print "Content-Type: text/plain\n\n"; $headersprinted = 1; } } sub pp { $gopp = 0; if ($gopp == $_[0]) { if (!$pp) { $pp = 1; &textplain; } if ($_[1] eq "end") { exit; } else { print "$_[1]\n"; } } } 1;
$table); $table =~ s|([\"\'])/content/|${1}http://content.cafepress.com/|g; #fixcomment" $table =~ s/ poundlink/ href="javascript:void(returnFalse())"/g; $table =~ s/style="padding:5px;background-color:#006699;"/id="orderingbox"/; $table =~ s|.*?||gi; if ($SECTION{'ShowCarousel'} eq "no") { $table =~ s|
|