#!/usr/bin/perl # $Id: message_get.cgi,v 1.38 2000/12/14 00:18:42 bart Exp $ use strict; use DBI; use CGI; use HTML::Entities; use Image::Size; my $script_submit = "/cgi-bin/message_submit.cgi"; my $script_review = "/cgi-bin/message_review.cgi"; my $script_attach = "/cgi-bin/message_get_attach.cgi"; my $script_view_s = "/cgi-bin/message_get.cgi"; my $script_view_a = $ENV{SCRIPT_NAME}; my $script_search = "/cgi-bin/search.cgi"; my $fv_short_id = "id"; my $fv_message_id = "message"; my $fv_view_reviews = "view_rate"; my $fv_done = "done"; my $fv_search_mode = "sm"; my $fv_search_mode_prev = "smh"; my $fv_special_sort = "sp"; my $fv_sort_by = "sb"; my $fv_category = "category"; my $fv_cutoff_reviews = "cr"; my $fv_cutoff_rank = "cs"; my $fv_cutoff_year = "ccy"; my $fv_cutoff_month = "ccm"; my $fv_cutoff_day = "ccd"; my $fv_direction_date = "oa"; my $fv_return_limit = "li"; my $fv_start_index = "si"; my $fv_user_id = "user_id"; my $fv_user_name = "uber"; my $fv_search_string = "q"; my $fv_search_desc = "sd"; my $fv_message_part = "part"; my $fv_recipient = "r"; my $fv_source = "sr"; my $fv_topten = "tt"; my $source_upload = 1; my $source_mail = 2; my $file_cache_dir = "/home/bart/www/ubersite.com/cgi-bin/file_cache"; my $sys_is_hiding_ad = 1; use lib "/home/bart/www/ubersite.com/lib"; use Common; use Ubersite; use Category; use CookieAuth; &do_everything; sub do_everything { my $string_uri_this = "http://$ENV{HTTP_HOST}/cgi-bin/message_get.cgi"; $string_uri_this .= "?$ENV{QUERY_STRING}" if( $ENV{QUERY_STRING} ); my $uri_this = &Common::make_uri( $string_uri_this ); my $cgi = new CGI; my( $user, $authenticated ) = &CookieAuth::determine_user($cgi); # Only send a cookie if the token is just being created if( $authenticated && $authenticated != 1 ) { #print $cgi->header( -cookie => $authenticated, -last_modified => CGI::expires("now"), -cache_control => "no-cache" ); print $cgi->header( -cookie => $authenticated, -cache_control => "no-cache" ); } else { #print $cgi->header( -last_modified => CGI::expires("now"), -cache_control => "no-cache" ); print $cgi->header( -cache_control => "no-cache" ); } my $my_uber = ($cgi->param($fv_user_name) eq $user ? 1 : 0); my $my_account = ($cgi->param($fv_recipient) ? 1 : 0); my %top_params = ( URI => $uri_this, Title => "Ubersite - Because The Future Is Uber", Auth => $authenticated, User => $user, MyUber => $my_uber, MyAccount => $my_account ); # Do a quick security sanity check here my $recipient = $cgi->param($fv_recipient); if( $recipient && lc($recipient) ne lc($user) ) { &Ubersite::print_page_top( %top_params ); print <your email.

We apologize for any inconvenience.

Management EOT } else { my $message_id = &Common::cgi_param( $cgi, $fv_message_id ); $message_id =~ s/\D//g; my $short_id = &Common::cgi_param( $cgi, $fv_short_id ); $short_id =~ s/\D//g; if( $message_id eq "" && $short_id eq "" ) { &list_all_messages( $cgi, $uri_this, \%top_params ); } else { &list_single_message( $message_id, $short_id, $cgi, $authenticated, $user, $uri_this, \%top_params ); } } my $fortune = `/usr/games/fortune homer`; &Ubersite::magical_encode($fortune); print <

$fortune

@{[&get_analytic()]} EOT } sub print_ad { &print_yahoo_ad(); } sub print_google_ad { print < EOT } sub print_yahoo_ad { print < EOT } sub list_single_message { my $message_id = shift; my $short_id = shift; my $cgi = shift; my $authenticated = shift; my $user = shift; my $uri_this = shift; my $top_params_ref = shift; my $recipient_ids = $Ubersite::anonymous_id; my $this_userinfo; if( $authenticated ) { $this_userinfo = &Ubersite::getuserinfo($user); $recipient_ids .= ',' . $this_userinfo->{id}; } my $sql = <fetchrow_hashref; if( ! $hashref ) { &Ubersite::print_page_top( %{$top_params_ref} ); print "

As far as you are concerned, there is no message $message_id $short_id
\n"; return; } if( $hashref->{sender_id} == 614 || $hashref->{sender_id} == 2880 ) { &Ubersite::print_page_top( %{$top_params_ref} ); print "

This message is pending approval
\n"; return; } $message_id = $hashref->{id} if !$message_id; $top_params_ref->{Title} = &Ubersite::magical_encode( "Ubersite - " . $hashref->{subject}, 1, 1 ); &Ubersite::print_page_top( %{$top_params_ref}, NextId => ($hashref->{link_next_id} || ""), PrevId => ($hashref->{link_prev_id} || "")); &print_left_bar( $cgi, $uri_this ); print < EOT print < Click here to return to the list of messages. EOT &print_single_message( $message_id, $hashref, $cgi, $this_userinfo ); print < EOT } # This creates the display for a message by printing out the main # message info and then calling print_single_part for each part of the message sub print_single_message { my $message_id = shift; my $hashref = shift; my $cgi = shift; my $this_userinfo = shift; my $subject = $hashref->{subject}; &Ubersite::magical_encode( $subject ); my $category = new Category( $hashref->{category} ); my $category_bar = $category->get_category_bar; my $hits = $hashref->{hits}; my $hits_string = ($hits ? "($hits hits)" : ""); print <$subject $hits_string Category: $category_bar

@{[ &get_single_message_info($hashref,$cgi,$this_userinfo) ]}

EOT my $sql = <{template_code} eq "UBERMADNESS" ) { print < This post is officially part of UberMadness!.

Click here for more information on the rules and restrictions.

Entry 1

EOT while( my $hashref = $sth->fetchrow_hashref ) { # Part number 2 is the first part of the second entry if( $hashref->{number} == 2 ) { print <

- VS -


Entry 2

EOT } &print_single_part( $hashref ); print "

\n"; } my $dbh = &Common::dbconnect(); my $vote_ref; # See if the user has already voted on this matchup if( $this_userinfo && $this_userinfo->{id} ) { my $sql = <prepare($sql); $sth->execute( $message_id, $this_userinfo->{id} ); $vote_ref = $sth->fetchrow_hashref; $sth->finish; } my $voting_expired = 0; my $duel_id; { my $sql = < d.vote_expires AS vote_expired, d.duel_id FROM duels d WHERE d.message_id = ? SQL my $sth = $dbh->prepare($sql); $sth->execute($message_id); my $hashref = $sth->fetchrow_hashref; $sth->finish; $duel_id = $hashref->{duel_id}; if( $hashref->{vote_expired}) { $voting_expired = 1; } } # $voting_expired = 1 if ($this_userinfo && $this_userinfo->{id} == 1); # If the user hasn't voted yet, show the links to vote if( !$vote_ref && !$voting_expired ) { my $uri_review = &Common::make_uri( $script_review, $fv_message_id => $message_id ); print < Vote for Entry 1   |   Vote for Entry 2 EOT } # If the user has voted, show their vote and the reviews else { print < EOT if( $vote_ref ) { my $vote = $vote_ref->{vote}; $vote = ($vote == 1 ? "1" : "2"); print <You voted for Entry $vote
EOT } my $sql = <fetchrow_hashref ) { if( $last_vote ne $hashref->{vote} ) { if( $last_vote ) { print "
  $count_y eligible votes ($count_a total) *
\n"; } $last_vote = $hashref->{vote}; print "
Entry $last_vote:
\n"; $count_y = 0; $count_a = 0; } my $eligible = $hashref->{eligible}; $count_y++ if $eligible; $count_a++; my $color = ($eligible ? "#000000" : "#CCCCCC"); print "  ", $hashref->{user}, "
\n"; } if( $last_vote ) { print "
  $count_y eligible votes ($count_a total) *
\n"; } $sth->finish; print <
* Eligible votes are those made by users who had either (A) posted 3+ messages OR (B) written 100+ [lowered from 750+] reviews as of the beginning of the UberMadness! competition. EOT print "
\n"; print "\n"; &print_message_reviews( $message_id ); } } # NOT an UberMadness post else { if( $hashref->{template_code} eq "UBERMADNESS_ENTRY" ) { my $sql_matchup = <prepare($sql_matchup); $sth_matchup->execute($message_id); if( my $hashref = $sth_matchup->fetchrow_hashref ) { print < This post was an official UberMadness! entry. Click here to view the original matchup.

EOT } $sth_matchup->finish; } # Display any annotations associated with the message if( $hashref->{has_annotations} ) { my $sql_select_annotation = <prepare($sql_select_annotation); $sth_select_annotation->execute($message_id); while( my $hashref = $sth_select_annotation->fetchrow_hashref ) { my $annotation = $hashref->{annotation}; my $css_class = $hashref->{style} || "special-box"; print < $annotation
EOT } $sth_select_annotation->finish; } while( my $hashref = $sth->fetchrow_hashref ) { &print_single_part( $hashref ); print "

\n"; if( $this_userinfo->{is_uberblessed} ) { use Worthless; my $content_type = $hashref->{content_type}; if( $content_type =~ /^image/ ) { my $inline = $hashref->{inline}; my $part = $hashref->{number}; my $msg = $inline ? "Click here to turn this image into a link" : "Click here to display this image inline"; my $t_inline = $inline ? 0 : 1; print <
EOT } } } print "
\n"; if( $sys_is_hiding_ad || ($this_userinfo && $this_userinfo->{is_hiding_ads}) ) { } else { &print_ad(); print "
\n"; } print "\n"; &print_message_reviews( $message_id ); } } # This function is where we fork the processing path based on content type sub print_single_part { my $hashref = shift; if( $hashref->{is_hidden} ) { print <[attachment not displayed] EOT return; } my %partinfo = %$hashref; my $type = $partinfo{content_type}; my $inline = $partinfo{inline}; # For plain text, we format it nicely so that it looks the way you think # it should. Also, links are added to any URLs and email addresses. if( $type =~ /^text\/plain/i ) { my $body = $partinfo{content}; my $pre = ($partinfo{datasource} == $source_upload || $partinfo{datasource} == $source_mail); &Ubersite::magical_encode( $body, $pre ); print "
" if $pre;
	print $body;
	print "
" if $pre; } # HTML text just gets printed out elsif( $type =~ /^text\/uberhtml/i ) { print $partinfo{content}; } else { my $uri_attach = "http://stuff.ubersite.com/$partinfo{message_id}/$partinfo{number}/$partinfo{content_name}"; # Images are printed out as image tags if( $inline && ( $type =~ /^image\/gif$/i || $type =~ /^image\/jpeg$/i || $type =~ /^image\/png$/i || $type =~ /^image\/x-png$/i || $type =~ /^image\/pjpeg$/i) ) { my $img_size = &get_size_as_string( $partinfo{content_length} ); my $alt_tag = "$partinfo{content_name} ($img_size)"; my $img_x = $partinfo{width}; my $img_y = $partinfo{height}; print < EOT } # Other types are printed out as links else { my $len = $partinfo{content_length}; my $file_size = &get_size_as_string( $len ); my $ctype = $partinfo{content_type} || "unknown"; my $cname = $partinfo{content_name} || "attachment"; encode_entities($cname); print <$cname ($file_size) [$ctype] EOT } } } sub get_size_as_string { my $len = shift; my $z = 0; my @zabbrs = ("bytes","kB","MB","GB","TB"); while( $len >= 1024 ) { $len = int($len/1024); $z++; } return "$len $zabbrs[$z]"; } # Prints all the user reviews for the given message sub print_message_reviews { my $message_id = shift; print <User Reviews EOT my $sql = <fetchrow_hashref; if( !$hashref ) { print "
\nNo reviews
\n"; } else { do { my %review = %$hashref; my $comment = $review{comment} || "No Comment"; if( $review{formatting} ) { $comment = encode_entities($comment); } else { if( $review{user_id} ) { &Ubersite::magical_encode( $comment ); } else { &Ubersite::magical_encode( $comment, 0, 1 ); } } my $username = $review{user}; my $user_info = undef; if( $username eq "" ) { $username = encode_entities($review{anon_name}); if( $review{anon_email} ) { $username .= " <" . &Ubersite::magical_encode($review{anon_email}) . ">"; } if( $username eq "" ) { $username = "Random Joe"; } $username = "$username"; } else { my $uri_user = &Common::make_uri( $script_view_a, ($fv_user_id => $review{user_id}) ); $user_info = "(user info)"; $username = "$username"; } print <
Submitted by $username $user_info at $review{xwhen} (#)
Ranking: $review{rank}

@{[$review{formatting} ? "
": ""]}
$comment
@{[$review{formatting} ? "
" : "
"]} EOT } while( $hashref = $sth->fetchrow_hashref ); } $sth->finish; } # Print a big list of all the messages that match the search criteria sub list_all_messages { my $cgi = shift; my $uri_this = shift; my $top_params_ref = shift; # This while hold the user info for the user we are viewing my $user_info; # See if the user id parameter is set if( $cgi->param($fv_user_id)) { # Set the user info based on user id $user_info = &Ubersite::getuserinfo_meta_id($cgi->param($fv_user_id)); } # See if the user name parameter is set elsif( $cgi->param($fv_user_name)) { # Set the user info based on user name $user_info = &Ubersite::getuserinfo_meta_user($cgi->param($fv_user_name)); # Set the user id parameter to get picked up by other conditions that look for it later if( $user_info ) { $cgi->param( -name => $fv_user_id, -value => $user_info->{id} ); } } # Set the title differently if we are looking at a user profile page if( $user_info ) { $top_params_ref->{Title} = encode_entities( "Ubersite - " . $user_info->{user}); $top_params_ref->{RSS} = "http://www.ubersite.com/u/" . $user_info->{user} . "/rss"; } &Ubersite::print_page_top( %{$top_params_ref}); &print_left_bar( $cgi, $uri_this ); print < EOT &print_my_uber_bar($cgi); my $search_mode = $cgi->param($fv_search_mode) || $cgi->param($fv_search_mode_prev); my $category_id = $cgi->param($fv_category); print < EOT # Based on the search mode, print either the simple or advanced form if( !$search_mode || $search_mode eq "Simple" ) { &print_simple_search_form($cgi); } else { &print_advanced_search_form($cgi); } print "
\n"; # print "Bored At Work?
\n"; # print "Fourth Annual Ubersite Oscar Contest (Results Are In! Fourteen Perfect Scores!)
\n"; # print "Bored At Work?   (Ubersite Prizeless NFL 2004 Playoff Contest Results Are In! ...the winner is - spedmonkey)
\n"; print "Ubersite Prizeless NFL 2007 Playoff Contest -or- Bored At Work?
\n"; # print "Ubersite Oscars 2006 Contest -or- Bored At Work?
\n"; print "
\n"; if( $user_info ) { # &print_user_reviews($user_info,$cgi); } my $cache_key = $ENV{QUERY_STRING}; $cache_key =~ s/\W/_/g; $cache_key = "default" if $cache_key eq ""; my $cache_file = $file_cache_dir . "/messages_$cache_key"; # START CACHE CREATION if( ! -e $cache_file ) { local *STDOUT; open( STDOUT, ">$cache_file" ); # In a search by category, print category bar at top if( $category_id ) { my $category = new Category( $category_id ); my $category_bar = $category->get_category_bar; print "Category: $category_bar

\n"; my $sub_categories = $category->get_sub_categories; # Print links for subcategories if( @$sub_categories ) { print "Subcategories:
    \n"; local $_; foreach (@$sub_categories) { print $_->get_category_link, "
    \n"; } print "
\n"; } } my( $order, @clauses ) = &extract_search_criteria( $cgi ); my @orig_clauses = @clauses; if( defined $cgi->param($fv_topten)) { my $sql = &generate_list_sql_for_topten( $cgi->param($fv_topten)); my $sth = &Common::dosql( $sql ); my $tt_desc = &get_topten_description($cgi->param($fv_topten)); print "

", $tt_desc->{description}, "

\n"; &list_messages_from_sth($sth,$cgi,$uri_this,0,100,0); $sth->finish; @clauses = ("0=1"); @orig_clauses = ("0=1"); } else { if( !defined $cgi->param($fv_source)) { push @clauses, "source = 0"; } # FIX for join table full &Common::dosql( "SET SQL_BIG_TABLES = 1" ); if( !defined $cgi->param($fv_source) || $cgi->param($fv_source) == 0 ) { my $def_return_limit = 40; my $max_return_limit = 500; my $start_index = int($cgi->param($fv_start_index)); my $return_limit = (int($cgi->param($fv_return_limit)) || $def_return_limit); $return_limit = $max_return_limit if $return_limit > $max_return_limit; my $sql_limit = "$start_index, " . ($return_limit + 40); my $sql = &generate_list_sql( $order, $sql_limit, \@clauses ); my $sth = &Common::dosql( $sql ); my $is_showing_home = ($ENV{QUERY_STRING} eq ""); if( $user_info ) { print "

Labels

\n"; my $sql_select_tags = <prepare($sql_select_tags); $sth_select_tags->execute($user_info->{id}); $sth_select_tags->bind_col( 1, \$tag_name ); $sth_select_tags->bind_col( 2, \$tag_count ); my $is_empty = 1; while( $sth_select_tags->fetch ) { $is_empty = 0; print <$tag_name ($tag_count) EOT } $sth_select_tags->finish; if( $is_empty ) { print <
more labels... EOT } } print "

Original Submissions

\n"; &list_messages_from_sth($sth,$cgi,$uri_this,$start_index,$return_limit,0, $is_showing_home ); $sth->finish; } if( $cgi->param($fv_source) == 1 ) { my $def_return_limit = 30; my $max_return_limit = 500; my $start_index = int($cgi->param($fv_start_index)); my $return_limit = (int($cgi->param($fv_return_limit)) || $def_return_limit); $return_limit = $max_return_limit if $return_limit > $max_return_limit; my $sql_limit = "$start_index, " . ($return_limit + 1); @clauses = @orig_clauses; push @clauses, "source = 1"; my $sql = &generate_list_sql( $order, $sql_limit, \@clauses ); my $sth = &Common::dosql( $sql ); print "

Automated Submissions

\n"; &list_messages_from_sth($sth,$cgi,$uri_this,$start_index,$return_limit,1); $sth->finish; } if( $user_info ) { print "



\n"; print "

Everything you ever wanted to know about ", encode_entities($user_info->{user}), "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
User id:", $user_info->{id}, "
Registered on or around: ", $user_info->{registered}, "
# Messages posted:", $user_info->{tot_messages}, "
# Reviews written:", $user_info->{tot_reviews}, "
# Times these posts have been reviewed :", $user_info->{tot_reviewed}, "
# Hits:", $user_info->{hits}, "
Average rating of all messages:", $user_info->{tot_avg_status}, "
\n"; print "
{user}, "/rss\" CLASS=\"rss\">RSS
\n"; } } close(STDOUT); } #END CACHE CREATION local $/ = undef; local *FILE; open( FILE, $cache_file ); my $content = ; close(FILE); print $content; my $is_hiding_ad = 0; if( $top_params_ref->{Auth} ) { my $this_userinfo = &Ubersite::getuserinfo($top_params_ref->{User}); if( $this_userinfo && $this_userinfo->{is_hiding_ads} ) { $is_hiding_ad = 1; } } if( $sys_is_hiding_ad || $is_hiding_ad ) { } else { print < EOT &print_ad(); } print < EOT } sub print_user_reviews { my $user_info = shift; my $cgi = shift; my $sql = <prepare($sql); $sth->execute($user_info->{id}); print <@{[$user_info->{user}]}'s Recent Reviews EOT while( my $hashref = $sth->fetchrow_hashref ) { my $uri_message = "/m/" . $hashref->{short_id}; my $subject = $hashref->{subject}; my $review_id = $hashref->{review_id}; encode_entities($subject); my $uri_user = &Common::make_uri( "/cgi-bin/message_get.cgi", ("user_id" => $hashref->{user_id}) ); my $user_info = "(user info)"; my $username = "" . $hashref->{user} . ""; my $comment = $hashref->{comment} || "No Comment"; &Ubersite::magical_encode($comment); print <$subject   @{[&get_list_message_info($hashref,$cgi,0)]} Review submitted by $username $user_info at @{[$hashref->{xwhen}]}
Ranking: @{[$hashref->{rank}]}

$comment

EOT } $sth->finish; print <param($_); }; return %params; } sub get_search_params_as_hash2 { my $cgi = shift; return ( $fv_search_mode => $cgi->param($fv_search_mode), $fv_search_mode_prev => $cgi->param($fv_search_mode_prev), $fv_special_sort => $cgi->param($fv_special_sort), $fv_sort_by => $cgi->param($fv_sort_by), $fv_category => $cgi->param($fv_category), $fv_cutoff_reviews => $cgi->param($fv_cutoff_reviews), $fv_cutoff_rank => $cgi->param($fv_cutoff_rank), $fv_cutoff_year => $cgi->param($fv_cutoff_year), $fv_cutoff_month => $cgi->param($fv_cutoff_month), $fv_cutoff_day => $cgi->param($fv_cutoff_day), $fv_direction_date => $cgi->param($fv_direction_date), $fv_return_limit => $cgi->param($fv_return_limit), $fv_user_id => $cgi->param($fv_user_id), $fv_search_string => $cgi->param($fv_search_string), $fv_search_desc => $cgi->param($fv_search_desc), $fv_recipient => $cgi->param($fv_recipient) ); } # This function takes the CGI object and determines: # 1) The db parameter to sort by # 2) Various conditions limiting the returned items sub extract_search_criteria { my $cgi = shift; my $cut_reviews = int($cgi->param($fv_cutoff_reviews)); my $cut_avg_status = $cgi->param($fv_cutoff_rank); my $cut_created = "'" . &format_mysql_date( $cgi->param($fv_cutoff_year), $cgi->param($fv_cutoff_month), $cgi->param($fv_cutoff_day) ) . "'"; my $sort_by = $cgi->param($fv_sort_by) || "created DESC"; if( $sort_by ne "created DESC" && $sort_by ne "created" && $sort_by ne "tot_avg_status DESC" && $sort_by ne "tot_reviews DESC" && $sort_by ne "hits DESC" && $sort_by ne "last_reviewed DESC" ) { $sort_by = "created DESC"; } my $special = $cgi->param($fv_special_sort); if( ! $special ) { } elsif( $special eq "best_ever" ) { $cut_reviews = 40; $sort_by = "tot_avg_status DESC, tot_reviews DESC"; } elsif( $special eq "best_week" ) { $cut_reviews = 25; $sort_by = "tot_avg_status DESC, tot_reviews DESC"; $cut_created = "FROM_UNIXTIME(UNIX_TIMESTAMP()-7*24*60*60)"; } elsif( $special eq "best_today" ) { $cut_reviews = 10; $sort_by = "tot_avg_status DESC, tot_reviews DESC"; $cut_created = "FROM_UNIXTIME(UNIX_TIMESTAMP()-24*60*60)"; } elsif( $special eq "worst_ever" ) { $cut_reviews = 40; $sort_by = "tot_avg_status, tot_reviews DESC"; } my @clauses = ("m.id != 0"); if( $cut_reviews ) { push @clauses, "tot_reviews >= $cut_reviews"; } if( $cut_avg_status ) { push @clauses, "tot_avg_status >= $cut_avg_status"; } if( $cut_created ) { my $del = $cgi->param($fv_direction_date) ? "<=" : ">="; push @clauses, "m.created $del $cut_created"; } my $category = $cgi->param($fv_category); push @clauses, "m.category = $category" if $category; my $user_id = $cgi->param($fv_user_id); if( $user_id ne "" ) { $user_id = int($user_id); if( $user_id ) { push @clauses, "m.sender_id = $user_id"; } else { push @clauses, "m.sender_id IS NULL"; } } else { push @clauses, "m.is_vanquished = 0"; } my $source_id = $cgi->param($fv_source); push @clauses, "m.source = $source_id" if defined $source_id; my $recipient_id = $Ubersite::anonymous_id; my $recipient = $cgi->param($fv_recipient); if( $recipient ) { my $user_info = &Ubersite::getuserinfo($recipient); $recipient_id = $user_info->{id}; } if( $recipient_id ) { push @clauses, "m.recipient_id = $recipient_id"; } else { push @clauses, "(m.recipient_id = $recipient_id OR m.recipient_id IS NULL)"; } return ($sort_by, @clauses); } sub get_ids_containing { my $s = shift; $s = &Common::dbquote($_); $s =~ s/^\'/\'%/; $s =~ s/\'$/%\'/; my $sql = "SELECT message_id FROM message_parts WHERE content_type like '%text%' AND content like $s"; my $sth = &Common::dosql($sql); my @ids; while( my $hashref = $sth->fetchrow_hashref ) { push @ids, $hashref->{message_id}; } return @ids; } sub print_left_bar { my $cgi = shift; my $uri_this = shift; print < EOT &print_madness_box(); &print_search_box($cgi); &print_topten(3,$uri_this); &print_topten(10,$uri_this); &print_topten(9,$uri_this); &print_topten(5,$uri_this); &print_topten(8,$uri_this); print < EOT } sub get_topten_description { my $type = shift; # Get the description for the list my $sql = "SELECT * FROM topten_desc WHERE id=$type"; my $sth = &Common::dosql($sql); my $hashref; # Set the title for the list if( !($hashref = $sth->fetchrow_hashref) ) { $hashref->{description} = "Who Knows?"; } $sth->finish; return $hashref; } # This will print a top ten list but will first look in the file cache sub print_topten { my $type = shift; if( $type == 7 ) { &print_topten_raw($type); return; } my $cache_file = "$file_cache_dir/topten_$type"; if( ! -e $cache_file ) { local *STDOUT; open( STDOUT, ">$cache_file" ); if($type == 8) { &print_user_topten_raw($type); } else { &print_topten_raw($type,1); } close(STDOUT); } local $/ = undef; local *FILE; open( FILE, $cache_file ); my $content = ; close(FILE); print $content; } # This will print a top ten list in a small table. # The identify of the list should be passed as an argument. sub print_topten_raw { my $type = shift; my $more = shift; my $topten_desc_ref = &get_topten_description($type); # Get all the items in the list my $sql = <"; # The max number of things to list my $limit = 10; my $is_empty = 1; # Go over the returned items and generate a link for each while( my $hashref = $sth->fetchrow_hashref ) { $is_empty = 0; my $uri_message = &create_message_link($hashref); my $subject = $hashref->{subject}; my $full_subject = $subject; # This is the maximum number of viewable characters in a topten item my $arbitrary_limit = 29; # If the string is too big, truncate it and add ellipsis if( length $subject > $arbitrary_limit ) { $subject = substr($subject,0,$arbitrary_limit-3) . "..."; } # Hack around subjects that are all caps $arbitrary_limit = int( .78 * $arbitrary_limit ) if uc($subject) eq $subject; # If the string is too big, truncate it and add ellipsis if( length $subject > $arbitrary_limit ) { $subject = substr($subject,0,$arbitrary_limit-3) . "..."; } # If the subject contains 18 characters in a row, insert a dash somewhere if( $subject =~ /\S{18}/ ) { $subject = substr($subject,0,14) . "- " . substr($subject,14); } # Generate a link for this message # encode_entities($subject); # encode_entities($full_subject); &Ubersite::magical_encode($subject,1,1); &Ubersite::magical_encode($full_subject,1,1); my $datadesc = ""; { # Add the descriptive info after the item my $format = $topten_desc_ref->{format}; if( $format ) { $datadesc = sprintf( $format, $hashref->{rank} ); encode_entities($datadesc); } } $content .= < $subject $datadesc EOT chomp $content; # Exit the loop if we've reached the limit last if !--$limit; } $sth->finish; $content .= "\n"; if( $more ) { my $uri_more = &Common::make_uri( $script_view_a, $fv_topten => $type ); $content .= "more..."; } if( ! $is_empty ) { &print_misc_box( $topten_desc_ref->{description}, $content ); } } # This will print a top ten list in a small table. # The identify of the list should be passed as an argument. sub print_user_topten_raw { my $type = shift; my $topten_desc_ref = &get_topten_description($type); # Get all the items in the list my $sql = <"; # The max number of things to list my $limit = 30; # Go over the returned items and generate a link for each while( my $hashref = $sth->fetchrow_hashref ) { my $user_id = $hashref->{user_id}; my $user = $hashref->{user}; my $uri_user = "/u/$user"; #&Common::make_uri( $script_view_s, $fv_user_id => $user_id ); my $fullname = $hashref->{first_name}; if( $fullname ne "" && $hashref->{last_name} ne "" ) { $fullname .= " "; } $fullname .= $hashref->{last_name}; $fullname = $user if $fullname eq ""; my $full_fullname = $fullname; # This is the maximum number of viewable characters in a topten item my $arbitrary_limit = 29; # Hack around items that are all caps $arbitrary_limit = int( .78 * $arbitrary_limit ) if uc($fullname) eq $fullname; # If the string is too big, truncate it and add ellipsis if( length $fullname > $arbitrary_limit ) { $fullname = substr($fullname,0,$arbitrary_limit-3) . "..."; } # If the name contains 18 characters in a row, insert a dash somewhere if( $fullname =~ /\S{18}/ ) { $fullname = substr($fullname,0,12) . "- " . substr($fullname,12); } # Generate a link for this message # encode_entities($fullname); # encode_entities($full_fullname); &Ubersite::magical_encode($fullname,1,1); &Ubersite::magical_encode($full_fullname,1,1); my $datadesc = ""; { # Add the descriptive info after the item my $format = $topten_desc_ref->{format}; if( $format ) { $datadesc = sprintf( $format, $hashref->{rank} ); encode_entities($datadesc); } } $content .= < $fullname $datadesc EOT chomp $content; # Exit the loop if we've reached the limit last if !--$limit; } $sth->finish; $content .= ""; &print_misc_box( $topten_desc_ref->{description}, $content ); } sub print_misc_box { my $title = shift; my $content = shift; # print < #
#$title #$content #
# #EOT print < $title $content EOT #print < #$title #$content # #EOT } sub print_form_box { my $title = shift; my $subtitle = shift; my $script = shift; my $boxname = shift; my $boxvalue = shift; my %params = @_; my $form_content = < ${subtitle}:
EOT while( my($k,$v) = each(%params) ) { $form_content .= < EOT } $form_content .= <
This user only
EOT &print_misc_box( $title, $form_content ); } sub print_madness_box4 { my $html = <UberMadness! Voting EOT &print_misc_box( "UberMadness!", $html ); } sub print_madness_box { my $uri_category = &Common::make_uri( $script_view_a, $fv_category => "23" ); my $html = <Latest news & entries...
The scoreboard... EOT &print_misc_box( "UberMadness!", $html ); } sub print_madness_box1 { my $uri_category = &Common::make_uri( $script_view_a, $fv_category => "23" ); my $html = <Latest news & entries...
The scoreboard...

The Winning Entry
by Snark! EOT &print_misc_box( "UberMadness!", $html ); } sub print_madness_box2 { my $uri_category = &Common::make_uri( $script_view_a, $fv_category => "23" ); my $html = <Latest news & entries...
The scoreboard...

The Winning Entry by Jack_McCallum! EOT &print_misc_box( "UberMadness!", $html ); } sub print_madness_box3 { my $uri_category = &Common::make_uri( $script_view_a, $fv_category => "23" ); my $html = <Winner: Razor
Winning Entry

Runner up: gascs
Running Up Entry

Latest news & entries...
The scoreboard... EOT &print_misc_box( "UberMadness!", $html ); } sub print_search_box_google { my $form_content = <
Search for:

EOT &print_misc_box( "Search Ubersite", $form_content ); } sub print_search_box { my $cgi = shift; my $default = encode_entities( $cgi->param($fv_search_string)); my $user_id = $cgi->param($fv_user_id); $user_id =~ s/\D//g; my $form_content = < Search for:

EOT if( $user_id ) { $form_content .= < EOT } $form_content .= < EOT &print_misc_box( "Search Ubersite", $form_content ); } sub print_affiliate_links { my $message_id = shift; my $sql = <fetchrow_hashref ) { my $aff_name = $hashref->{name}; my $aff_format = $hashref->{format}; my $aff_data = $hashref->{aff_data}; my $media = $hashref->{media_desc}; my $aff_image = $hashref->{image}; $aff_format =~ s/\$ID/$aff_data/g; print <Buy this $media at $aff_name


EOT } $sth->finish; } sub print_my_uber_bar { my $cgi = shift; my $recipient = $cgi->param($fv_recipient); return undef unless $recipient; my $uri_email = &Common::make_uri( $script_view_a, $fv_recipient => $recipient ); print <Account Services - Email - Calendar - Profile - Change Your Password

EOT } sub get_list_message_info { return &get_message_info(@_,1); } sub get_single_message_info { return &get_message_info(@_,0); } # This function exists as a feeble attempt to have one function for two purposes sub get_message_info { my $hashref = shift; my $cgi = shift; my $this_userinfo = shift; my $list = shift; my $message_id = $hashref->{id}; my $from = $hashref->{sender}; my $subject = $hashref->{subject}; &Ubersite::magical_encode( $from ); &Ubersite::magical_encode( $subject ); my $uri_review = &Common::make_uri( $script_review, $fv_message_id => $message_id ); my $auth_icon = ( $hashref->{sender_id} ? "\"[Authenticated]\"   " : "" ); my $x1 = ($list ? "(" : "" ); my $x2 = ($list ? ")" : "" ); my $x3 = ($list ? "" : <Rate this item) EOT if( $message_id == 1057030797535621011 ) { $x3 = ""; } if( !$list && $hashref->{tot_reviews} ) { $x3 .= <V) EOT } if( !$list && $this_userinfo && $this_userinfo->{id} ) { my $dbh = &Common::dbconnect(); my $sql_select_tags = <prepare($sql_select_tags); my $tags; $sth_select_tags->execute( $this_userinfo->{id}, 1, $message_id ); $sth_select_tags->bind_col( 1, \$tags ); $sth_select_tags->fetch; $sth_select_tags->finish; my $user_tags; my $tag_text = "Label this item"; if( $tags ) { my $tmp_tags = join( " ", map { my $tmp = $_; $tmp = lc($tmp); $tmp =~ s/[^a-zA-Z0-9\.\-\_]//g; encode_entities($_); "{user} . "/l/$tmp\">$_"; } split( / /, $tags ) ); $user_tags = "Your Labels: $tmp_tags"; $tag_text = "Edit"; } encode_entities($tags); $x3 .= < $user_tags ($tag_text) EOT } my $x4 = ($list ? "" : ""); my $x5 = ($list ? "" : ""); my $user_info = ""; if( $hashref->{sender_id} ) { my $uri_user = &Common::make_uri( $script_view_a, ($fv_user_id => $hashref->{sender_id}) ); $user_info = "(View user info)"; } my $tot_avg_status = $hashref->{tot_avg_status}; $tot_avg_status = int($tot_avg_status * 100) * .01; my $last_reviewer = ""; if( defined $hashref->{last_reviewer} ) { $last_reviewer = ", last by " . $hashref->{last_reviewer}; if( defined $hashref->{reviewed_ago} ) { my $last_reviewed = $hashref->{reviewed_ago}; if( $last_reviewed < 90*60 ) { my $minutes = int($last_reviewed/60); $last_reviewed = " $minutes minute" . ($minutes != 1 ? "s" : "") . " ago"; } elsif( $last_reviewed < 24*60*60 ) { my $hours = int($last_reviewed/(60*60)); $last_reviewed = " $hours hour" . ($hours != 1 ? "s" : "") . " ago"; } elsif( $last_reviewed < 24*60*60*730 ) { my $days = int($last_reviewed/(24*60*60)); $last_reviewed = " $days day" . ($days != 1 ? "s" : "") . " ago"; } else { my $years = int($last_reviewed/(24*60*60*365)); $last_reviewed = " $years year" . ($years != 1 ? "s" : "") . " ago"; } $last_reviewer .= $last_reviewed; } } my $reviews = $hashref->{tot_reviews}; my $rating = ""; if( $reviews ) { $reviews = "$reviews review" . ($reviews != 1 ? "s" : ""); $rating = "Rating: $tot_avg_status on $reviews${last_reviewer}"; } else { $rating = "no reviews" } return < ${x4}Submitted by $from $auth_icon $user_info at @{[$hashref->{created}]}
${x5} EOT } sub print_system_image { my $image_id = shift; my $message_id = 0; my $sql = "SELECT message_id,number,content_type,content_name,content FROM message_parts WHERE message_id=$message_id AND number=$image_id AND content_type like 'image%'"; my $sth = &Common::dosql( $sql ); if( my $hashref = $sth->fetchrow_hashref ) { &print_single_part( $hashref ); } } sub print_simple_search_form { my $cgi = shift; my $sp = $cgi->param($fv_special_sort); print <