#!/usr/bin/perl #--------------------------------------------------------------------- # FCGI to help manage the Daily Thought content #--------------------------------------------------------------------- use CNET::lib; use lib '/home/lib'; use strict; use CGI::Fast; use webshots::WebshotsUtility; use webshots::WebshotsDB; use webshots::SuperMail; use webshots::MDocs; use webshots::SuperLogEvent; my $TEMPLATE = WebshotsUtility::ReadFile('/home/dailyphoto/htdocs/content/dailythought/dt_archive_template.html'); my $QUOTE_TEMPLATE =<
_THOUGHT_
- _AUTHOR_
_FORM_
EOM my $DB = new WebshotsDB; $DB->Connect(-DB=>'dailygoodies'); my @ROWS; $DB->SQL(-SQL=>"select * from thoughts", -ROWS=>\@ROWS); $DB->DESTROY; my @DT_ROWS; my $i = 1; foreach my $row (@ROWS) { my $author = $row->{AUTHOR} || ''; my $thought = $row->{THOUGHT} || ''; my $date = $row->{DATE} || ''; my $send_link = SuperMail::GetFormHTML ( -MYSUBJECT => "Daily Thought", -MYTEXT => "Thought you might like this...\n\n$thought\n\n-$author\n", -MYGREETING => "Hi.", -MYSALUTATION => "Cheers", -MYLINKSIZE => "1", -MYLINKTEXT => "Email This Thought To A Friend", -MYCUSTOM => "Send The Daily Thought", -MYINSTANCE => 'search_' . $i, -MYREF => "dailythought_ar" ); my $data_line = $date . '|' . $thought . '|' . $author . '|' . $send_link; push (@DT_ROWS, $data_line); $i++; } #--------------------------------------------------------------------- #--------------------------------------------------------------------- LOOP: while (my $CGI = new CGI::Fast) { print "Content-type: text/html\n\n"; my $template = $TEMPLATE; my $search_term = $CGI->param('search_for'); my $return_html =< EOM if ($search_term eq '') { $return_html .= 'Search term blank


'; } else { $return_html .= 'Daily Thoughts matching "' . $search_term . '"'; my $line; my @match_list = grep(/$search_term/i,@DT_ROWS); my $count = @match_list; if ($count == 0) { $return_html .= '

  Sorry, there are no matches for that search. Be sure to check your spelling!

'; } foreach $line (@match_list) { my $quote_template = $QUOTE_TEMPLATE; my ($pub_date,$quote,$author,$send_link) = split (/\|/, $line); $quote_template =~ s/_THOUGHT_/$quote/; $quote_template =~ s/_AUTHOR_/$author/; $quote_template =~ s/_FORM_/$send_link/; $return_html .= $quote_template; } } $return_html .= <   Look for more quotes...  
  (you can search on authors or key words) EOM $template =~ s/.*/$return_html/s; $template =~ s/.*//s; my $back_link = 'Back To Archives'; $template =~ s/Click A Date/$back_link/s; MDocs::InsertSitewideHeaderFooter(\$template,'/home/dailyphoto/htdocs/mdocs/',{-PAGE_COUNT_TAG=>'/Page/Daily/ThoughtSearch/'}); SuperLogEvent::Log("thought_search", 1, { SEARCH => $search_term } ); print $template; } #--------------------------------------------------------------------- #--------------------------------------------------------------------- sub ReadFileToArray { my $file = $_[0]; open(FILE, "<$file"); my @lines = ; close(FILE); return @lines; } #--------------------------------------------------------------------- # END #---------------------------------------------------------------------