#!/usr/bin/perl $appname = $0; $appname =~ s/.*\///g; $blogname = $ENV{PWD}; $blogname =~ s/.*\///g; $blogname = "larrys_${$blogname}_blog"; require "cgi-lib.pl"; require "ctime.pl"; require "larry_html_subs.pl"; $cap_string = captcha_string (); &ReadParse(*values); %values2=@ARGV; # weak password for now if ( $values{master} eq "1234blog" ){ $values2{master} = "1234blog" } foreach $i ( keys ( %values2 )) { $values{$i} = $values2{$i} } chomp( $values{vistors_name} ) ; $values{vistors_name} =~ s/\W+/ /g; $values{vistors_name} =~ s/\s+/ /g; set_up(); init_cookies(); zen_init (); meme_init (); babel_init(); rebus_init(); shake_init(); update_counters (); display_blog(); exit 0 ; sub set_up { @actual_time = localtime(time); $current_time = localtime(time); $this_year = $actual_time[5] + 1900 ; $this_month = $actual_time[4]; $this_day = $actual_time[3]; $this_hour = $actual_time[2]; $this_minute = $actual_time[1]; if ( $values{hday} eq "" ) { $values{hday} = $this_day } ; if ( $values{hmonth} eq "" ) { $values{hmonth}= $this_month } ; if ( $values{hyear} eq "" ) { $values{hyear} = $this_year } ; # define previous mounth $pvm_y = $values{hyear} ; $pvm_m = $values{hmonth} - 1; if ( $pvm_m < 0 ) { $pvm_m = 11 ; --$pvm_y } #if ( $values{submit} =~ /View.Month.Before/ ) { # $values{hmonth} = $pvm_m; # $values{hyear} = $pvm_y; # } @month = ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ); } sub web_clean { my $webstring = $_[0]; $webstring =~ s/\/>/g; $webstring } sub zen_init { if ( -d "blog_files/zen_images") { if ( ! -d "blog_files/$this_year" ) { mkdir "blog_files/$this_year", 0777 } if ( ! -d "blog_files/$this_year/$this_month" ) { mkdir "blog_files/$this_year/$this_month", 0777 } if ( ! -d "blog_files/$this_year/$this_month/$this_day" ) { mkdir "blog_files/$this_year/$this_month/$this_day", 0777 } if ( ! -e "blog_files/$this_year/$this_month/$this_day/zen_image.txt" ) { opendir ZD, "blog_files/zen_images"; @zen_img_list = grep !/^\./, grep !/\.txt$/, readdir ZD; close ZD; $zen_image = $zen_img_list[rand($#zen_img_list)]; chomp $zen_image; open ZD, ">blog_files/$this_year/$this_month/$this_day/zen_image.txt"; print ZD "$zen_image\n"; close ZD; } else { open ZN, "blog_files/$this_year/$this_month/$this_day/zen_image.txt"; $zen_image = readline *ZN; chomp ( $zen_image ) ; close ZN; } if ( $values{zen_submit} ne "" && $values{visitor_name} !~ /^\s*$/ && $values{zen_text} !~ /^\s*$/ && $values{vword} =~ /^\s*$captcha{$values{last_imgnum}}\s*$/i ) { $vn = $values{visitor_name}; chomp($vn); $vn =~ s/\s+/_/g; chomp( $vn ); # one comment per day opendir ZD , "blog_files/$this_year/$this_month/$this_day"; @zendir = grep /\.$vn.txt/, grep !/^zen_image.txt$/, grep !/visitors.txt$/, readdir ZD; close ZD; foreach $t (@zendir){ $tt = $t; chomp($tt); unlink ( "blog_files/$this_year/$this_month/$this_day/$tt" ) } # adding 10 just keeps the list sorted. $th = $this_hour + 10 ; $tm = $this_minute + 10 ; open ZD, ">blog_files/$this_year/$this_month/$this_day/$th.$tm.$vn.txt" ; $vname = web_clean($values{visitor_name}); print ZD "$vname says:\n"; $zentext = web_clean ($values{zen_text}); print ZD "$zentext"; close ZD; $visitor_cookie = $values{visitor_name}; $cookiestring = "Set-Cookie: $blogname=$visitor_cookie; path=/; expires $exptime GMT"; } if ( $values{zen_suggest} ne "" && $values{visitor_name} !~ /^\s*$/ && $values{zen_url} !~ /^\s*$/ && $values{vword} =~ /^\s*$captcha{$values{last_imgnum}}\s*$/i ) { open ZD, ">>blog_files/image_suggestions.txt" ; $vname = web_clean ( $values{visitor_name}); print ZD "$vname suggests:\n"; $zenurl = web_clean ($values{zen_url}); print ZD " $zenurl\n"; $zensite = web_clean($values{zen_site}); print ZD " $zensite\n"; close ZD; $visitor_cookie = $values{visitor_name}; $visitor_cookie =~ s/\W+/ /g ; $cookiestring = "Set-Cookie: $blogname=$visitor_cookie; path=/; expires $exptime GMT"; } $zen_coms = ""; opendir ZD, "blog_files/$this_year/$this_month/$this_day"; @zen_comments = grep !/^\./, grep !/^zen_image.txt$/, grep !/visitors.txt$/, readdir ZD; close ZD; foreach $c ( sort ( @zen_comments ) ) { open ZD , "blog_files/$this_year/$this_month/$this_day/$c"; while () { $zen_coms .= "$_
"; } $zen_coms .= "\n
"; close ZD; } if ( $#zen_comments == -1 ) { $zen_coms .= "What is the sound of no one commenting?
\n(no Zen Image comments yet)
\n"} $zen_submitter = ""; $zen_url = ""; if ( -e "blog_files/zen_images/$zen_image.txt" ) { open ZN, "blog_files/zen_images/$zen_image.txt"; while () { chomp; if ( $_ =~ /ZEN_SUBMITTER: (.*)$/ ) { $zen_submitter = $1} elsif ( $_ =~ /ZEN_URL (.*)$/ ) { $zen_url = $1} } close ZN; } if ( $zen_submitter ne "" ) { $zen_submitter = "Submitted by $zen_submitter
\n" } if ( $zen_url eq "" ) { $zen_src = "" } else { $zen_src = "" } $zen_string = "
Zen Image Of The Day
$zen_submitter$zen_src
$zen_coms
Nickname
$cap_string Zen Comment for Zen Image Of The Day



Nickname
Verification Word
Image Suggestion for Zen Image Of The Day
Image URL
Website URL (optional)

"; } else { $zen_string = "" } $zen_list_last = $zen_list[-1]; $zen_list_len = $#zen_list; } sub meme_count { $phrase = $_[0]; $phrase =~ s/\W+/ /g ; $phrase =~ s/^ +//g ; $phrase =~ s/ +$//g ; $phrase =~ s/ /\+/g ; my $result = ""; $bget = `perl bget-1.2 "http://search.yahoo.com/search?fr=FP-pull-web-t&p=%22$phrase%22\n"`; my @tt = split /\n/ , $bget; foreach $i ( @tt ) { if ( $i =~ /yschinfo/ ) { /()()()/; $i =~ /

Results.*of about ([\d,]+)<\/strong> for/; $result = $1; $result =~ s/,//g; $result =~ s/[^\d]//g; } } if ( $result eq "" ) { $result = "0" } $result } sub rebus_init { $rebus_string = "New to BNL -- CNN Headline Puzzle (guess the headline)\n" ; open REBUS, "CNN_small_rebus.txt"; while () { $rebus_string .= $_ } ; close REBUS; $rebus_string .= "
\nSee the Full Size Puzzle with Clues & Solution "; $rebus_string .= "CNN Headline Puzzle
\n"; $rebus_string .= "Make your own Picture Puzzle (Rebus) with the "; $rebus_string .= "BNL REBUSizer
\n"; $rebus_string .= "Or checkout the last Visitor Rebus
\n"; } sub babel_init { $babel_string = "" ; open BABEL, "babelizer.txt"; while () { $babel_string .= $_ } ; close BABEL; } sub shake_init { $shake_string = "

Shakespeare-O-Meter

Last Use:
"; open SHAKE, "last_Shakespeare.txt"; while () { $shake_string .= $_ } ; close SHAKE; $shake_string .= "
Try Shakespear-O-Meter for Yourself
Note: based on fequency of word use only
Green:High Red:Purple:Blue:Low

" } sub meme_init { if ( -d "blog_files/meme_watch") { $have_updated_one = "false"; if ( $values{meme_submit} ne "" && $values{meme_phrase} !~ /^\s*$/ && $values{visitor_name} !~ /^\s*$/ && $values{vword} =~ /^\s*$captcha{$values{last_imgnum}}\s*$/i) { my $vn = $values{visitor_name}; $vn =~ s/\W/_/g; $vn = "meme.$values{meme_num}.$vn.$this_year.$this_month.$this_day.txt"; opendir MD, "blog_files/meme_watch"; @to_remove = grep /meme.$values{meme_num}.$vn/, readdir MD; foreach $tmeme ( @to_remove ) { $t = $tmeme; chomp ($t) ; unlink("blog_files/meme_watch/$t") } my $meme_citations = meme_count( web_clean($values{meme_phrase})) ; if ( -d "blog_files/meme_watch" ) { mkdir "blog_files/meme_watch" ,0777 } open MW, ">blog_files/meme_watch/$vn"; $memephrase = web_clean($values{meme_phrase}); print MW "MEME phrase($values{meme_num}): $memephrase\n"; $vname = web_clean($values{visitor_name}); print MW "Submitted by: $vname\n"; $memetext = web_clean($values{meme_text}); $memetext =~ s/\s+\n$//g; if ( $values{meme_text} !~ /^\s*$/ ) { print MW "--- Meme Definition ---\n$memetext\n" } print MW "Web Citations: $meme_citations for $this_year/$this_month/$this_day\n"; close MW; $have_updated_one = "true"; } $meme_text = ""; opendir ZD, "blog_files/meme_watch"; @memes = grep !/^\./, grep /meme.*.txt/, readdir ZD; close ZD; $needs_update = "false"; foreach $m (sort(@memes)){ open ZD , "blog_files/meme_watch/$m"; /()()()/; $m =~ /(\d+)\.(\d+)\.(\d+)\.txt$/; $meme_year = $1; $meme_month = $2 ; $meme_day = $3; $meme_text .= "\n
  • \n" ; $meme_update .= ""; $last_citation = ""; $first_citation = ""; while () { chomp; /()()()/; if ( $_ =~ /MEME phrase\(\d\): (.*)<\/b>/ ) { $meme_phrase = $1; $meme_text .= "$_
    \n" } elsif ( $_ =~ /Web Citations: (\d+)<\/b> for (\d+)\/(\d+)\/(\d+)/ ) { $last_number_of_citations = $1 ; if ( $first_citation eq "" ) { $first_citation = $_; $meme_text .= "$_ (date of submission)
    \n" } else { $last_citation = $_ } } else { $meme_text .= "$_
    \n" } } if ( $last_citation ne "" ) { $meme_text .= "$last_citation (date of last change)

    \n" } else { $meme_text .= "No change for Citation numbers since Submission

    \n"; } $meme_text .= "\n
  • "; close ZD; # Do one meme file update per visit. # Only update meme max of once a day if ( $have_updated_one eq "false" && ( $meme_year != $this_year || $meme_month != $this_month || $meme_day != $this_day )) { $have_updated_one = "true"; $current_citations = meme_count ( $meme_phrase ) ; if ( $current_citations != $last_number_of_citations ) { open ZD, ">>blog_files/meme_watch/$m"; print ZD "Web Citations: $current_citations for $this_year/$this_month/$this_day\n"; print ZD $meme_update; close ZD; } # rename file whether updated or not to reflect last update attempt $m =~ /(.*)\.\d+\.\d+\.\d+\.txt/; $filename = $1; rename "blog_files/meme_watch/$m", "blog_files/meme_watch/$filename.$this_year.$this_month.$this_day.txt" ; } } if ( $#memes == -1 ) { $meme_text .= "No MEME Watch Submisions
    \n"} $vname = web_clean ( $values{visitor_name} ); $meme_string = "
    MEME Watch
      $meme_text
    Nickname
    MEME (track upto 9)
    Definition/Explanation of MEME

    $cap_string

    -- Meme --
    Pronunciation: 'mEm
    Function: noun
    Etymology: alteration of mimeme, from mim- (as in mimesis) + -eme
    : an idea, behavior, style, or usage that spreads from person to person within a culture

    Enter a short phrase or meme into Meme Watch and see how its usage increases with time on the web
    "; } } sub init_cookies { open ZN, ">cookie_debug.txt"; @cookie_pairs=split(/; /, $ENV{'HTTP_COOKIE'}); foreach $pair (@cookie_pairs) { ($name, $value) = split(/=/, $pair); $cookie{$name} = $value; print ZN "\"$name\" -> \"$value\"\n"; } close ZN; open ZN, ">env_debug.txt"; foreach $e (keys(%ENV)) {print ZN "\"$e\" -> \"$ENV{$e}\"\n" } close ZN; $new_visitor = "false"; if ( $values{visitor_name} ne "" ) { $visitor_cookie = $values{visitor_name} ; $cookie{$blogname} = $visitor_cookie } elsif ( $cookie{$blogname} eq "" ) { open COOKIE_LIST, "BlogVisitors.txt"; print COOKIE_LIST "$visitor_cookie\n"; close COOKIE_LIST; } else { $visitor_cookie = $cookie{$blogname}; $values{visitor_name} = $cookie{$blogname} } # set to expire in 1 year $exptime = localtime(time + 365*24*60*60); $cookiestring = "Set-Cookie: $blogname=$visitor_cookie; path=/; expires $exptime GMT"; if ( $visitor_cookie !~ /^\d+$/ && $visitor_cookie !~ /^\s*$/ ) { $values{visitor_name} = $visitor_cookie } else { $values{visitor_name} = "" } } sub display_blog { print "Content-type: text/html $cookiestring "; $string1 = "

  • Total visits to BNL \"Free
    Free Counter
  • "; # don't count if a hit on submits if ( $values{zen_suggest} ne "" || $values{zen_submit} ne "" || $values{meme_submit} ) { $string1 = "" } # if DumbSwede then don't update counter, but give stats instead if ( $values{visitor_name} =~ /DumbSwede/ ) { $string1="DEBUG INFO FOR DUMBSWEDE:
    \n". "Zen_Image $zen_image
    \n". "Cookiestring $cookiestring
    \n". "blogname $blogname
    \n". "Visits today: $vtd
    ". "Total visits: $tv
    \n" } open TEMP, "blog_index.html"; while () { $t = $_; $t =~ s//$string1/g; $t =~ s//$zen_string/g; $t =~ s//$meme_string/g; $t =~ s//$babel_string/g; $t =~ s//$rebus_string/g; $t =~ s//$shake_string/g; if ( $values{visitor_name} =~ /DumbSwede/ ) { $t =~ s/<\/body>/
    $bget
    <\/body>/g; } print $t } } sub update_counters { if ( ! -d "blog_files/$this_year" ) { mkdir "blog_files/$this_year", 0777 } if ( ! -d "blog_files/$this_year/$this_month" ) { mkdir "blog_files/$this_year/$this_month", 0777 } if ( ! -d "blog_files/$this_year/$this_month/$this_day" ) { mkdir "blog_files/$this_year/$this_month/$this_day", 0777 } open ZN, "blog_files/total_visitors.txt"; $tv = readline *ZN; close ZN; chomp ($tv); if ( $values{visitor_name} !~ /DumbSwede/ ) { ++$tv; open ZN, ">blog_files/total_visitors.txt"; print ZN "$tv\n"; close ZN; } open ZN, "blog_files/$this_year/$this_month/$this_day/visitors.txt"; $vtd = readline *ZN; close ZN; chomp ($vtd); if ( $values{visitor_name} !~ /DumbSwede/ ) { ++$vtd; open ZN, ">blog_files/$this_year/$this_month/$this_day/visitors.txt"; print ZN "$vtd\n"; close ZN; } if ( $new_visitor eq "true" ) { open ZN, "blog_files/total_new_visitors.txt"; $tnv = readline *ZN; close ZN; chomp ($tnv); ++$tnv; open ZN, ">blog_files/total_new_visitors.txt"; print ZN "$tnv\n"; close ZN; open ZN, "blog_files/$this_year/$this_month/$this_day/new_visitors.txt"; $nvtd = readline *ZN; close ZN; chomp ($nvtd); ++$nvtd; open ZN, ">blog_files/$this_year/$this_month/$this_day/new_visitors.txt"; print ZN "$nvtd\n"; close ZN; } elsif ( $values{visitor_name} !~ /DumbSwede/ ) { open ZN, "blog_files/total_return_visitors.txt"; $trv = readline *ZN; close ZN; chomp ($trv); ++$trv; open ZN, ">blog_files/total_return_visitors.txt"; print ZN "$trv\n"; close ZN; open ZN, "blog_files/$this_year/$this_month/$this_day/return_visitors.txt"; $rvtd = readline *ZN; close ZN; chomp ($rvtd); ++$rvtd; open ZN, ">blog_files/$this_year/$this_month/$this_day/return_visitors.txt"; print ZN "$rvtd\n"; close ZN; } } exit 0;