#Shoutbox.pl #v1.0b1 #16/10/03 #ronnie@badpoo.co.uk #http://www.badpoo.co.uk/ronnie/pages/yabbmods.shtml #file locations $shout_template_file = "$vardir/shoutbox.html"; $shout_messages_file = "$vardir/shoutbox.txt"; $shout_settings_file = "$vardir/shoutbox.pl"; require $shout_settings_file; #display the shoutbox HTML - the iframe and the form to add shouts sub ShoutBox { if ($username eq 'Guest') { $random = int(rand(99)); $displayname = $txt{'28'} . $random; } else { $displayname = $settings[1]; } $colspan = ($settings[7] eq 'Administrator') ? 3 : 2; $width = ($settings[7] eq 'Administrator') ? '33%' : '50%'; my $scrolling; if ($shout_scrolling == 2) { $scrolling = 'auto'; } elsif ($shout_scrolling == 1) { $scrolling = 'yes'; } else { $scrolling = 'no'; } $iframe_url = qq~$cgi;action=shoutboxdisplay~; $yymain .= qq~ ~; #check whether they're a guest before showing the form to add shouts unless ($shout_guest_posting == 0 && $username eq 'Guest') { $yymain .= qq~ ~; if ($shout_change_names) { $yymain .= qq~ ~; } else { $yymain .= qq~~; } $yymain .= qq~ ~; if ($settings[7] eq 'Administrator' || $settings[7] eq 'Global Moderator') { $yymain .= qq~~; } $yymain .= qq~ ~; } $yymain .= qq~
~; #whether to position the frame at the bottom of the list or top if ($shout_add_to_top) { $yymain .= qq~ ~; } else { $yymain .= qq~ ~; } $yymain .= qq~
$txt{'287'} $txt{'293'} $txt{'291'} $txt{'451'} $txt{'292'} $txt{'288'} $txt{'295'} $txt{'530'}
~; } #add a message to the shoutbox sub ShoutboxAdd { my $message = $FORM{'message'}; my $name = $FORM{'name'}; my $submit_type = $FORM{'submit'}; #just redirect to the display page when we don't want to print the standard message, or if they clicked refresh if ($message eq $shout_txt{'1'} || $submit_type eq $shout_txt{'3'}) { $yySetLocation = qq~$cgi;action=shoutboxdisplay~; &redirectexit; } #clear the shoutbox file if that's what we've been told to do if ($submit_type eq $shout_txt{'4'}) { &ShoutboxClear; } #call them "Anon" if they haven't entered a name if (!$name) { $name = $shout_txt{'6'}; } #append "(Guest)" to their name if they've entered a different name than their randomly-generated "Guest52" etc. if ($username eq 'Guest' && $name !~ $txt{'28'}) { $name = $name . qq~($txt{'28'})~; } #cut up overly-long strings of characters (15+) with a space to avoid distorting the table too much $message =~ s~(\w{15})~$1 ~ig; #replace < and > to avoid nastiness $message =~ s//>/g; #cut off the message if it's too long if (length($message) > $shout_max_shout_length) { $message = substr($message, 0, $shout_max_shout_length); } #construct the line to store on file $shout_new_line = qq~$name|$message\n~; #read in the shout file so we know what we have fopen(DATA, "$shout_messages_file"); @lines = ; fclose(DATA); #if there are no lines stored, just add it now if (scalar(@lines) == 0) { fopen(DATA, ">$shout_messages_file"); print DATA $shout_new_line; fclose(DATA); } else { #add this line to the shout file and make sure we're only storing as many as we've been told to if ($shout_add_to_top) { unshift(@lines, $shout_new_line); while (scalar(@lines) > $shout_max_shouts) { pop(@lines); } } else { push(@lines, $shout_new_line); while (scalar(@lines) > $shout_max_shouts) { shift(@lines); } } #add to file fopen(DATA, ">$shout_messages_file"); print DATA @lines; fclose(DATA); } $yySetLocation = qq~$cgi;action=shoutboxdisplay~; &redirectexit; } #create html output to display the shouts in the iframe sub ShoutboxDisplay { &LoadCensorList; #read the template file fopen(FILE, "$shout_template_file"); @lines = ; fclose(FILE); print qq~Content-type:text/html\n\n~; foreach $line (@lines) { #print out the template, replacing with the shouts if ($line eq qq~\n~) { #read the messages file fopen(FILE, "$shout_messages_file"); @shouts = ; fclose(FILE); chomp @shouts; #print each shout in the file $count2 = 0; foreach $shout_line (@shouts) { ($poster, $shout) = split(/\|/, $shout_line); #if name-changing is off, we know that $poster is a username so we can get their real name from it if (!$shout_change_names && $poster ne 'Guest') { if (fopen(MEMFILE, "$memberdir/$poster.dat")) { @memsets = ; fclose(MEMFILE); chomp $memsets[1]; $poster = qq~$memsets[1]~; } } #censor the shout foreach (@censored) { ($tmpa,$tmpb) = @{$_}; $shout =~ s~\Q$tmpa\E~$tmpb~gi; $poster =~ s~\Q$tmpa\E~$tmpb~gi; } #UBBC the shout? if ($enable_ubbc) { require "$sourcedir/YaBBC.pl"; $message = $shout; &DoUBBC; $shout = $message; } else { $shout =~ s~\n~
\n~g; } #give this row the right alternating bgcolor if ($count2 % 2 == 0) { $bgcolor = 'message1';} else { $bgcolor = 'message2';} if ($shout_self_highlight) { if ($poster =~ qq~>$settings[1]<~) { $bgcolor = 'ownmessage'; } } $count2++; print qq~$poster: $shout\n~; } } else { print $line; } } exit; } #return $shout_messages_file to its default state sub ShoutboxClear { unlink($shout_messages_file); #whether to position the frame at the bottom of the list or top $yySetLocation = qq~$cgi;action=shoutboxdisplay~; &redirectexit; } #configure the shoutbox options sub ShoutboxConfig { &is_admin; #fill in fields $checked_guest_posting = $shout_guest_posting ? ' checked' : ''; $checked_self_highlight = $shout_self_highlight ? ' checked' : ''; $checked_change_names = $shout_change_names ? ' checked' : ''; $checked_add_to_top = $shout_add_to_top ? ' checked' : ''; if ($shout_scrolling == 0) { $select_scrolling_0 = ' selected'; } elsif ($shout_scrolling == 1) { $select_scrolling_1 = ' selected'; } else { $select_scrolling_2 = ' selected'; } $yymain .= qq~
$shout_txt{'7'}

$shout_txt{'20'}.

$shout_txt{'8'}
$shout_txt{'9'}
$shout_txt{'10'}
$shout_txt{'11'}
$shout_txt{'12'}
$shout_txt{'14'}
$shout_txt{'15'}
$shout_txt{'16'}
$shout_txt{'17'}
$shout_txt{'18'}
$shout_txt{'19'}

~; $yytitle = $shout_txt{'7'}; &template; exit; } #save the shoutbox options to file sub ShoutboxConfig2 { &is_admin; #error checking for bad characters if ($FORM{'max_shouts'} =~ /\D/) { &fatal_error($shout_txt{'21'}); } if ($FORM{'max_shout_length'} =~ /\D/) { &fatal_error($shout_txt{'21'}); } if ($FORM{'rowspan'} =~ /\D/) { &fatal_error($shout_txt{'21'}); } if ($FORM{'box_width'} =~ /\D/) { &fatal_error($shout_txt{'21'}); } if ($FORM{'box_height'} =~ /\D/) { &fatal_error($shout_txt{'21'}); } #default values if submitted bad values $shout_guest_posting = $FORM{'guest_posting'} ? 1 : 0; $shout_self_highlight = $FORM{'self_highlight'} ? 1 : 0; $shout_change_names = $FORM{'change_names'} ? 1 : 0; $shout_add_to_top = $FORM{'add_to_top'} ? 1 : 0; $shout_scrolling = $FORM{'scrolling'}; $shout_max_shouts = $FORM{'max_shouts'} || 15; $shout_max_shout_length = $FORM{'max_shout_length'} || 150; $shout_refresh = $FORM{'refresh'} || -1; $shout_box_width = $FORM{'box_width'} || 190; $shout_box_height = $FORM{'box_height'} || 190; $shout_rowspan = $FORM{'rowspan'} || 6; #print to file fopen(SETFILE, ">$shout_settings_file"); print SETFILE qq~\$shout_guest_posting = $shout_guest_posting; \$shout_self_highlight = $shout_self_highlight; \$shout_change_names = $shout_change_names; \$shout_add_to_top = $shout_add_to_top; \$shout_scrolling = $shout_scrolling; \$shout_max_shouts = $shout_max_shouts; \$shout_max_shout_length = $shout_max_shout_length; \$shout_refresh = $shout_refresh; \$shout_box_width = $shout_box_width; \$shout_box_height = $shout_box_height; \$shout_rowspan = $shout_rowspan; 1;~; fclose(SETFILE); $yySetLocation = qq~$cgi;action=shoutboxconfig~; &redirectexit; } #the page for editing the template sub ShoutboxTemplate { &is_admin; #if this is first time run and no template file yet exists, create it with default values if (fopen(FILE, "$shout_template_file")) { @tem_lines = ; fclose(FILE); $template = join("", @tem_lines); } else { $template = ShoutboxDefaultHTML; } $yymain .= qq~
$shout_txt{'20'}

$shout_txt{'23'}


 
~; $yytitle = $shout_txt{'20'}; &template; exit; } #save the template to file sub ShoutboxTemplate2 { &is_admin; if ($FORM{'submit'} eq $shout_txt{'22'} || $FORM{'template'} eq '') { $template = &ShoutboxDefaultHTML; } else { $template = $FORM{'template'}; $template =~ s~\r~~g; } fopen(FILE, ">$shout_template_file"); print FILE $template; fclose(FILE); $yySetLocation = qq~$cgi;action=shoutboxtemplate~; &redirectexit; } #generate the default HTML for the shoutbox iframe if the user hasn't created any yet or is wiping the file sub ShoutboxDefaultHTML { #whether to position the frame at the bottom of the list or top # $refresh_url = ($shout_add_to_top) ? qq~$cgi;action=shoutboxdisplay~ : qq~$cgi;action=shoutboxdisplay#bottom~; $refresh_url = qq~$cgi;action=shoutboxdisplay~; #add the positioning html if new shouts are being added to the bottom # $bottom_anchor = ($shout_add_to_top) ? '' : qq~\n\n~; return qq~
$bottom_anchor ~; } 1;