#!/usr/bin/perl ############################################################################## # Cliff's Thumbnail Gallery Post Script Version 1.04 # # Copyright 1998 Shaven Ferret Productions # # Created: 5/25/99 Last Modified: 09/28/99 # # Available at http://www.shavenferret.com/scripts # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998 Shaven Ferret Productions All Rights Reserved. # # # # This script can be used\modified free of charge as long as you don't # # change this header, or the parts of this script that generate the return # # link\form. If you really need to remove these, go to # # http://www.shavenferret.com/scripts/register.shtml . By using this script # # you agree to indemnify me from any liability that might arise from its use.# # # # Redistributing\selling the code for this program without prior written # # consent is expressly forbidden. # ############################################################################## require "tgpsetup.cgi"; require "tgp-lib.cgi"; &start; if ($FORM{'action'} eq "rate") { &ratepost; } elsif ($FORM{'action'} eq "post") { &post; } elsif ($FORM{'action'} eq "preview") { &preview; } elsif ($FORM{'action'} eq "preview2") { &preview2; } elsif ($FORM{'action'} eq "search") { &search; } elsif ($FORM{'action'} eq "random") { &random; } else { &submit; } sub ratepost { open(FILE,"$datadir/r$FORM{'postnum'}.txt"); my $junk = ; close(FILE); ($total,$votes,$last) = split(/\|/,$junk); if ($last eq $ENV{'REMOTE_ADDR'}) { &error("You just rated this post."); } if ($FORM{'rating'} > 10 || $FORM{'rating'} < 1) { &error("You're trying to cheat, aren't you?"); } $total += $FORM{'rating'}; $votes++; open(FILE,">$datadir/r$FORM{'postnum'}.txt"); print FILE "$total|$votes|$ENV{'REMOTE_ADDR'}"; close(FILE); print "$title\n"; &body("FILE"); unless ($norate) { print "\n"; } else { print "
\n"; } print "\n"; print "
Your rating of $FORM{'rating'} has been recorded.\n"; print "$cfont
\n"; print "
$font
Back to
\n"; print "$tgptitle$cfont\n"; print "
$font\n"; print "Get Rid of this frame!$cfont
\n"; print "
\n"; if ($eachrate) { &update; } exit; } sub submit { &top("Add your gallery.","STDOUT"); print "$posthead

Step 1:

\n"; if ($link) { print "We require a return link. Please copy and paste the\n"; print "following HTML into your web page:


In case you're wondering, that\n"; print "HTML will look like this:

$link

\n"; unless ($samepage) { print "\n"; &textrow("Enter the URL of the page with my link here:","link_url","21","http://",-1); $html .= "
\n"; } else { $html .= "This link must be added to the gallery page."; } if ($link =~ /$counturl\?/) { $html .= "Please note that I do list sites by the ammount a return traffic I receive from them, so you will receive more hits if you give me a good link.\n"; } $html .= "

Step 2:

\n"; } else { $html .= "\n"; } $html .= "Please fill out the following information about the gallery you\n"; $html .= "wish to post.

\n"; $html .= "

\n"; if ($rules) { $html .= "
Rules: $rules
\n"; } $html .= "\n"; if ($samepage) { &textrow("URL of Gallery and my link\n:","post_url","21","http://",-1); } else { &textrow("URL of Gallery\n:","post_url","21","http://",-1); } if ($#post_types > 0) { @post_types = sort(@post_types); $html .= "\n"; } &textrow("Describe the gallery:","post_desc","21","",-1); $html .= "\n"; &textrow("Your E-mail address:","email","21","",-1); $html .= "
$font"."Type of gallery:$cfont
$font"."How many images are in this gallery?$cfont$font$cfont

Step "; if ($link) { $html .= "3:

\n"; } else { $html .= "2:\n"; } unless ($showhints) { $html =~ s///ig; $html =~ s/<\/a>//ig; } print "$html"; print "\n"; print "Please make sure all of the information is correct and click\n"; print "
\n"; print "
Thumbnail Gallery Post script by
Cliff(tm), Shaven "; print "Ferret Productions, and can be found at http://www."; print "shavenferret.com/scripts.
\n"; if ($showhints) { print "

Stuff you should know before posting

\n"; if ($link) { print "

About your return link

\n"; } print "

About your gallery

\n"; if ($post_types > 0) { print "

About your category

\n"; } print "

About your gallery's description

\n"; print "

About your e-mail address

\n"; } print "$postfoot$cfont\n"; exit; } sub preview { if ($samepage) { $FORM{'link_url'} = $FORM{'post_url'}; } &checkme; @stuff = ("post_type","post_url","post_desc","email","link_url","numimages"); open(FILE,">$datadir/tempost.txt"); foreach $thingie(@stuff) { print FILE "$FORM{$thingie}|"; } close(FILE); print "Preview your post\n"; print "\n"; print "\n"; print "\n"; print "\n"; &body("STDOUT"); print "Please click these links to make sure that you gave the right URLs:<ul>\n"; print "<li><a href=\"$FORM{'post_url'}\" target=\"post\">Post URL</a></li>\n"; if ($FORM{'link_url'}) { print "<li><a href=\"$FORM{'link_url'}\" target=\"link\">Link URL</a></li>\n"; } print "</ul><form method=\"POST\" action=\"$scripturl\">\n"; print "<input type=\"hidden\" name=\"action\" value=\"post\">\n"; foreach $thingie(@stuff) { print "<input type=\"hidden\" name=\"$thingie\" value=\"$FORM{$thingie}\">\n"; } print "Once you're sure you gave the correct URLs, click <input type=\"submit\" value=\" this button \">.\n"; print "</form>\n"; exit; } sub preview2 { open(FILE,"$datadir/tempost.txt"); $temp = ; close(FILE); ($FORM{'post_type'},$FORM{'post_url'},$FORM{'post_desc'},$FORM{'email'},$FORM{'link_url'},$FORM{'numimages'},$junk) = split(/\|/,$temp); &top("Preview your post","STDOUT"); print "Please make sure that you gave the correct URLs. Each link opens in the bottom window.
\n"; @stuff = ("post_type","post_url","post_desc","email","link_url","numimages"); print "\n"; foreach $thingie(@stuff) { print "\n"; } print "Once you're sure you gave the correct URLs, click .\n"; print "
\n"; } sub post { &checkme; open(FILE,"$datadir/auto.txt"); @autos = ; close(FILE); foreach $auto(@autos) { chomp($auto); if ($FORM{'post_url'} =~ /$auto/) { $approval = 0; } } &gettime; if ($lwp && $checkapprove && $link) { $searchlink =~ s/\s+/ /g; $searchlink =~ tr/A-Z/a-z/; $searchlink = quotemeta($searchlink); if (length($tgptitle) > 36) { $temp = substr($tgptitle,0,36); } else { $temp = $tgptitle; } $searchlink2 = quotemeta("[$temp]"); $searchlink2 =~ s/\s+/ /g; $searchlink2 =~ tr/A-Z/a-z/; $page = get($FORM{'link_url'}); $page =~ s/\s+/ /g; $page =~ tr/A-Z/a-z/; unless ($page =~ /$searchlink/ || $page =~ /$searchlink2/) { &error("Please add my link to your links page."); } } if ($approval) { unless ($FORM{'test'}) { open(FILE,">>$datadir/approve.txt"); print FILE "$FORM{'post_type'}|$FORM{'post_url'}|$FORM{'post_desc'}|$FORM{'email'}|$FORM{'link_url'}|$date|$time|$FORM{'numimages'}|$ENV{'REMOTE_ADDR'}|\n"; close(FILE); } if ($notify1 && $youremail && $FORM{'test'} != -1) { open (MAIL,"|$mailprogram -t"); print MAIL "To: $youremail\n"; print MAIL "From: $FORM{'email'}\n"; print MAIL "Subject: Thumbnail Gallery Post Needs Your Approval\n"; print MAIL "Hello. On $date at $time $FORM{'email'}\n"; print MAIL "stopped by your TGP site and posted a gallery.\n"; print MAIL "Please stop by your page at $adminurl\n"; print MAIL "and approve it sometime.\n"; close (MAIL); } &top("Thank you!","STDOUT"); print "Thank you for your post! I will check it out and let you know as soon as possible.\n"; if ($moreposts) { &moreposts; } print "\n"; exit; } else { unless ($FORM{'test'}) { open(FILE,"$datadir/posts.txt"); @lines = ; close(FILE); if (@lines) { &getpost(0); } else { $index_num = -1; } $index_num++; splice(@lines,0,0,"$FORM{'post_type'}|$FORM{'post_url'}|$FORM{'post_desc'}|$FORM{'email'}|$FORM{'link_url'}|$date|$time|$FORM{'numimages'}|$ENV{'REMOTE_ADDR'}|$index_num\n"); open(FILE,">$datadir/c$index_num.txt"); print FILE "0"; close(FILE); open(FILE,">$datadir/r$index_num.txt"); print FILE "5|1|"; close(FILE); } &top("Gallery posted","STDOUT"); print "The gallery has been posted and can be found at $posturl/$index_num$ex.\n"; if ($moreposts) { &moreposts; } unless ($FORM{'test'}) { &checkpersite($FORM{'post_url'}); open(FILE,">$datadir/posts.txt"); foreach $line(@lines) { print FILE "$line"; } close(FILE); unless ($norate) { $FORM{'rr'} = -1; } if ($link =~ /$counturl\?/) { $FORM{'rt'} = -1; } unless ($lnumimages) { $FORM{'rn'} = -1; } &update; } print "$cfont\n"; exit; } } sub checkme { if ($#post_types > 0) { unless ($FORM{'post_type'}) { &error("Please select a category for your post."); } unless (@temp = grep(/$FORM{'post_type'}/,@post_types)) { &error("I don't have a $FORM{'post_type'} category."); } } unless ($FORM{'post_desc'}) { &missing("a description of the gallery"); } unless ($FORM{'post_url'} =~ /^http\:\/\/.+\.\w\w+.*/) { &error("The site URL appears to be invalid."); } unless ($FORM{'email'} =~ /.+\@.+\.\w\w+/) { &error("The e-mail address $FORM{'email'} appears to be invalid."); } if ($link && $FORM{'link_url'} !~ /^http\:\/\/.+\.\w\w+.*/) { &error("The return link URL appears to be invalid."); } open(FILE,"$datadir/lock.txt"); my @locks = ; close(FILE); my $temp = "$FORM{'post_type'}|$FORM{'post_url'}|$FORM{'post_desc'}|$FORM{'email'}|$FORM{'link_url'}|$ENV{'REMOTE_ADDR'}"; $temp =~ tr/A-Z/a-z/; foreach $lock(@locks) { chomp($lock); $templock = quotemeta($lock); $templock =~ tr/A-Z/a-z/; if ($temp =~ /$templock/) { &error("I have locked out the text $lock."); } } if ($samedomain && $link) { my @temp = split(/\//, $FORM{'post_url'}); if ($FORM{'link_url'} !~ /$temp[2]/) { &error("Your gallery URL and return link URL must be on the same domain."); } } @ix = ("approve","posts"); foreach $filename(@ix) { open(FILE,"$datadir/$filename.txt"); my @lines = ; close(FILE); for ($i = 0; $i <= $#lines; $i++) { ($post_type,$post_url,$post_desc,$email,$link_url,$odate,$otime,$numimages,$posters_ip,$index_num) = split(/\|/,$lines[$i]); if ($post_url eq $FORM{'post_url'}) { &error("That gallery has already been posted."); } } } } sub moreposts { print "

\n"; print "
$fontThe owner of this pic-post\n"; print "page is using Cliff's ever-so-wonderful "Get More Posts"\n"; print "system. What does this mean to you? Well, simply that you can easily\n"; print "post the gallery that you just posted here to other pic-post sites without\n"; print "having to fill out all the information again. If you'd like to do this now,\n"; print "please click
\n"; @checkthese = ("post_type","post_url","post_desc","email","link_url","numimages"); foreach $check(@checkthese) { print "\n"; } print "\n"; print "
\n"; } sub search { unless ($FORM{'text'}) { &error("Please enter some terms you want to search for."); } $FORM{'text'} =~ tr/A-Z/a-z/; $FORM{'text'} =~ s/ not / -/ig; $FORM{'text'} =~ s/ and / \+/ig; $FORM{'text'} =~ s/ or / /ig; $FORM{'text'} =~ s/\s+/ /g; @temp = split(/\"/, $FORM{'text'}); if ($keepsearch) { open(FILE,"$datadir/search.txt"); my @searches = ; close(FILE); for($i = 0; $i <= $#searches; $i++) { @stuff = split(/\|/, $searches[$i]); if ($stuff[0] eq $FORM{'text'}) { chomp($stuff[1]); $stuff[1]++; $searches[$i] = "$stuff[0]|$stuff[1]\n"; $found = -1; } } unless ($found) { splice(@searches,0,0,"$FORM{'text'}|1\n"); } open(FILE,">$datadir/search.txt"); foreach $search(@searches) { print FILE "$search"; } close(FILE); } for ($i = 0; $i <= $#temp; $i++) { $sign = ""; if ($temp[$i]) { if (substr($temp[$i],-1,1) eq "+" || substr($temp[$i],-1,1) eq "-") { $sign = substr($temp[$i],-1,1); chop($temp[$i]); } @terms = split(/ /, $temp[$i]); foreach $term(@terms) { $term =~ s/\s//ig; if (substr($term,0,1) eq "+") { $term = substr($term,1,length($term)-1); push(@must,$term); } elsif (substr($term,0,1) eq "-") { $term = substr($term,1,length($term)-1); push(@cant,$term); } else { push(@should,$term); } } } $i++; if ($temp[$i]) { if ($sign eq "+") { push(@must,$temp[$i]); } elsif ($sign eq "-") { push(@cant,$temp[$i]); } else { push(@should,$temp[$i]); } } } open(FILE,"$datadir/posts.txt"); @lines = ; close(FILE); if (@should) { for ($i = 0; $i <= $#lines; $i++) { $lines[$i] =~ tr/A-Z/a-z/; foreach $term(@should) { if ($lines[$i] =~ /$term/) { push(@found,"$i"); last } } } } else { for ($i = 0; $i <= $#lines; $i++) { $lines[$i] =~ tr/A-Z/a-z/; $found[$i] = "$i"; } } if (@must) { for ($i = $#found; $i >= 0; $i--) { foreach $term(@must) { unless ($lines[$found[$i]] =~ /$term/) { splice(@found,$i,1); last } } } } if (@cant) { for ($i = $#found; $i >= 0; $i--) { foreach $term(@cant) { if ($lines[$found[$i]] =~ /$term/) { splice(@found,$i,1); last } } } } unless (@found) { &top("No results","STDOUT"); print "I'm sorry, but your search turned up no results. Please\n"; print "click back and try again.$cfont\n"; exit; } if ($#post_types > 0) { for ($i = 0; $i <= $#post_types; $i++) { $temp = $post_types[$i]; $temp =~ tr/A-Z/a-z/; $TYPE{$temp} = $i; } } &top("$tgptitle - Results - $FORM{'text'}","STDOUT","","",-1); print "
$head
"; &banners("STDOUT"); print "

$tgptitle - Results - $FORM{'text'}

\n"; &jump("STDOUT"); &sig("STDOUT"); print "
\n"; unless ($#post_types <= 0) { print "
$font\n"; print "category$cfont
\n"; } else { print "\n"; print "\n"; for ($postnum = 0; $postnum <= $#found; $postnum++) { &getpost($found[$postnum]); $temp = $post_type; $temp =~ tr/A-Z/a-z/; unless ($#post_types <= 0) { print "\n"; unless ($norate) { open(FILE,"$datadir/r$index_num.txt"); my $stuff = ; close(FILE); ($total,$votes,$junk) = split(/\|/,$stuff); if ($votes) { $rating = sprintf("%.2f", $total / $votes); } else { $rating = "5"; } print "\n"; } else { print "\n"; } print "\n"; } print "
\n"; } print "$font
Description
$cfont
$font
\n"; unless ($norate) { print "Rating"; } else { print "Posted on.."; } print "
$cfont
$font
Images
$cfont
$font
$post_type
$cfont
\n"; } else { print "
\n"; } print "$font
$post_desc
$cfont
$font
$rating
$cfont
$font
$odate
$cfont
$font
$numimages
$cfont
\n"; &searchwindow("STDOUT"); &sig("STDOUT"); &banners("STDOUT"); print "
$foot$cfont"; exit; } sub random { open(FILE,"$datadir/posts.txt"); @lines = ; close(FILE); srand; $i = int(rand($#lines)); &getpost($i); print "Location: $posturl/$index_num$ex\n\n"; }