package Ubersite; # $Id: Ubersite.pm,v 1.8 2000/03/24 08:05:21 bart Exp $ use strict; use HTML::Entities; use Image::Size; use lib "/home/bart/www/ubersite.com/lib"; use Common; use Category; 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 = "/cgi-bin/message_get.cgi"; $Ubersite::anonymous_id = 0; @Ubersite::stylesheets = ( "/styles/classic.css", "/styles/classic.css" ); @Ubersite::logos = ( "/images/uber_small.gif", "/images/uber_small.gif" ); sub process_part { my $ctype = shift || "text/plain"; my $cname = shift; my $body = shift; my $message_id = shift; my $part_number = shift; my $source = shift; my $body_length = length($body); my ($img_width,$img_height,$err); ($img_width,$img_height,$err) = imgsize( \$body ) if ( $ctype =~ /^image\//i ); if( !defined $img_width || !defined $img_height) { $img_width = "NULL"; $img_height = "NULL"; } $cname = &stripdosdir($cname); $ctype = &Common::dbquote( $ctype ); $cname = &Common::dbquote( $cname ); $body = &Common::dbquote( $body ); my $sql = "INSERT INTO message_parts (message_id,number,content_type,content_name,content,datasource) VALUES($message_id,$part_number,$ctype,$cname,$body,$source)"; my $sth = &Common::dosql( $sql ); $sth->finish; $sql = "INSERT INTO message_parts_aux (message_id,number,content_length,width,height) VALUES( $message_id, $part_number, $body_length, $img_width, $img_height )"; $sth = &Common::dosql( $sql ); $sth->finish; } sub generate_message_id { return time() . int(rand(10000)) . $$; } sub process_message { my $subject = shift || "No subject"; my $sender = shift || "Bob"; my $to = shift; my $message_id = shift; my $category = shift; my $sender_id = shift; my $source_id = shift; my $template = shift; my $ip = $ENV{'REMOTE_ADDR'}; chomp $subject; chomp $sender; chomp $to; my $recipient_id = &get_recipient_id($to); if( $recipient_id == 0 ) { $recipient_id = "NULL"; } $subject = &Common::dbquote( $subject ); $sender = &Common::dbquote( $sender ); $to = &Common::dbquote( $to ); $ip = &Common::dbquote( $ip ); $sender_id = int($sender_id); $source_id = int($source_id); $template = &Common::dbquote( $template); my $sql = <finish; } sub update_message { my $subject = shift; my $sender = shift; my $to = shift; my $id = shift; my $category = shift; my $user_id = shift; chomp $subject; chomp $sender; chomp $to; $subject = &Common::dbquote( $subject ); $sender = &Common::dbquote( $sender ); $to = &Common::dbquote( $to ); my $sth = &Common::dosql( "UPDATE messages SET subject=$subject, sender=$sender, recipient=$to, category=$category, sender_id=$user_id, modified=NOW() WHERE id=$id" ); $sth->finish; } sub delete_message { my $id = shift; my $sth = &Common::dosql( "DELETE FROM messages WHERE id=$id" ); $sth->finish; my $sth = &Common::dosql( "DELETE FROM message_parts WHERE message_id=$id" ); $sth->finish; my $sth = &Common::dosql( "DELETE FROM message_reviews WHERE message_id=$id" ); $sth->finish; } # This takes a username and returns a hash containing all the info for that user. # If no such user exists, undef is returned sub getuserinfo { my $user = shift; my $sql = "SELECT id, user, external_name, ve_id, eligibility, is_uberblessed, is_hiding_ads FROM users WHERE user='$user'"; my $sth = &Common::dosql( $sql ); my $userinfo = $sth->fetchrow_hashref; if( $userinfo ) { $userinfo->{name} = $userinfo->{first_name} . ' ' . $userinfo->{last_name}; } $sth->finish; return $userinfo; } # This takes a user ID and returns a hash containing all the info for that user. # If no such user exists, undef is returned sub getuserinfo_meta_id { my $id = shift; $id = int($id); my $sql = "SELECT id, user, registered, tot_messages, tot_reviews, tot_reviewed, hits, tot_avg_status FROM users WHERE id = $id"; my $sth = &Common::dosql( $sql ); my $userinfo = $sth->fetchrow_hashref; $sth->finish; return $userinfo; } # This takes a user name and returns a hash containing all the info for that user. # If no such user exists, undef is returned sub getuserinfo_meta_user { my $user = shift; $user = &Common::dbquote($user); my $sql = "SELECT id, user, registered, tot_messages, tot_reviews, tot_reviewed, hits, tot_avg_status FROM users WHERE user = $user"; my $sth = &Common::dosql( $sql ); my $userinfo = $sth->fetchrow_hashref; $sth->finish; return $userinfo; } # This takes a user ID and returns a hash containing all the info for that user. # If no such user exists, undef is returned sub getuserinfo_pref { my $user = shift; my $sql = "SELECT id, user, email, external_name, registered, password, first_name, last_name, city, state, zip, country, ve_id, is_hiding_ads, timezone_id FROM users WHERE user = '$user'"; my $sth = &Common::dosql( $sql ); my $userinfo = $sth->fetchrow_hashref; $sth->finish; return $userinfo; } # Take the given string and format it so that it looks the way you think it should sub magical_encode { my $ref = \$_[0]; my $nobr = $_[1]; my $notag = $_[2]; my $val = $$ref; $val =~ s/\&\#8211\;/\-/g; $val =~ s/\&\#8216\;/\'/g; $val =~ s/\&\#8217\;/\'/g; $val =~ s/\&\#8220\;/\"/g; $val =~ s/\&\#8221\;/\"/g; $val =~ s/\&\#8230\;/\.\.\./g; encode_entities($val); $val =~ s/\n/\n
/g unless $nobr; $val =~ s/\&\#13\;//g; $val =~ s/((http|https|ftp):\/\/[\&\;\@\=\%\#\.\+\,\/\~\?\:\-_a-zA-Z0-9]+)/$1<\/A>/g unless $notag; $val =~ s/\((www\.[\&\;\@\=\%\#\.\/\~\?\-_a-zA-Z0-9]+)\)/($1<\/A>)/gi unless $notag; $val =~ s/([a-zA-Z0-9_\.\-\=]+)\@([a-zA-Z0-9_\.\-]+\.[a-zA-Z0-9_\.\-]+)/$1.at.$2<\/I>/g unless $notag; $val =~ s/([a-zA-Z0-9_\.\-\=]+)\@([a-zA-Z0-9_\.\-]+\.[a-zA-Z0-9_\.\-]+)/$1.at.$2/g if $notag; $val =~ s/decss/DeCSS<\/A>/ig unless $notag; $val =~ s/\&\#133\;/\.\.\./g; $val =~ s/\&\#145\;/\'/g; $val =~ s/\&\#146\;/\'/g; $val =~ s/\&\#147\;/\"/g; $val =~ s/\&\#148\;/\"/g; $val =~ s/\&\#150\;/\-/g; $val =~ s/\&\#153\;/\&trade\;/g; # $val =~ s/you\'re a racist\, dr\. seuss/$&<\/A>/ig; $$ref = $val; } sub print_page_top { my %params = @_; my $uri_this = $params{URI}; my $title = $params{Title}; my $authenticated = $params{Auth}; my $user = $params{User}; my $no_submit = $params{NoSubmit}; my $no_login = $params{NoLogin}; my $my_uber = $params{MyUber}; my $next_id = $params{NextId}; my $prev_id = $params{PrevId}; my $style_idx = $params{StyleIndex}; my $my_account = $params{MyAccount}; my $rss_url = $params{RSS}; my $uri_logout = &Common::make_uri( "/cgi-bin/login.cgi", "done" => "$uri_this", "o" => 1 ); my $uri_login = &Common::make_uri( "/cgi-bin/login.cgi", "done" => "$uri_this" ); my $uri_next = &Common::make_uri( $script_view_s, "message" => $next_id ); my $uri_prev = &Common::make_uri( $script_view_s, "message" => $prev_id ); my $text_log = ($authenticated ? "Logout" : "Register / Login"); my $link_log = ($authenticated ? "$uri_logout" : "$uri_login"); my $log_button = ($no_login ? "$text_log" : "$text_log"); my $uri_email = &Common::make_uri( $script_view_a, "r" => $user ); # my $uri_posts = &Common::make_uri( $script_view_a, "uber" => $user ); my $uri_posts = "/u/$user"; my $posts_button = ($authenticated ? ( $my_uber ? "My Uber - " : "My Uber - " ) : ""); my $account_button = ($authenticated ? ( $my_account ? "My Account - " : "My Account - " ) : ""); my $welcome = ( $authenticated ? ", $user" : "" ); my $uri_submit = &Common::make_uri( $script_submit, "done" => "$uri_this" ); my $submit_button = ($no_submit ? "Submit" : "Submit"); $rss_url = "http://www.ubersite.com/ubersite.rss" unless $rss_url; $style_idx = 0 if ! ($style_idx >= 0 && $style_idx <= $#Ubersite::stylesheets ); my $doing_uberboard = 1; # my $doing_uberboard = 0; my $uberboard_msg; if($doing_uberboard) { use BoardQuotes; my @quote_ids = keys %BoardQuotes::uberboard_quotes; my $quote_idx = int(($#quote_ids+1) * rand()); my $quote_id = $quote_ids[$quote_idx]; $uberboard_msg = $BoardQuotes::uberboard_quotes{$quote_id}; &Ubersite::magical_encode($uberboard_msg); } print < $title
Ubersite
EOT # my $err_msg = "Seriously, finish up whatever you're doing. The site is going down in just a few minutes."; # my $err_msg = "Ubersite will be temporarily unavailable from 12:30am until 2am EST for some maintenance work"; my $err_msg; if( $err_msg ) { print < $err_msg EOT } if( $doing_uberboard ) { print < $uberboard_msg EOT } print <