package Replace; use base Bbs; use strict; sub line_break {${$_[1]} =~ s/\x0D\x0A/
/g; ${$_[1]} =~ s/\x0D/
/g; ${$_[1]} =~ s/\x0A/
/g; ${$_[1]} =~ s/\x20
\x20
//g; ${$_[1]} =~ s/\x81\x40
\x81\x40
//g; ${$_[1]} =~ s/\x20
/
/g; ${$_[1]} =~ s/\x81\x40
/
/g; ${$_[1]} =~ s/

\x20?

//g; ${$_[1]} =~ s/

(?:\x81\x40)?

//g; ${$_[1]} =~ s/[\x00-\x1F]/ /g; my $c = 0; my $br = $_[0]->conf('line_break'); $c = ${$_[1]} =~ s/
/$br/g; $_[0]->flag('replace_line_break'=>1); $_[0]->counter('replace_line_break'=>$c), $_[0]->flag('line_break'=>1) if $c; $_[0];} sub char_entity_set { my $c = 0; # $c += ${$_[1]} =~ s/&/&/g; $c += ${$_[1]} =~ s/\"/"/g; $c += ${$_[1]} =~ s//>/g; $_[0]->flag('replace_char_entity_set'=>1); $_[0]->counter('replace_char_entity_set'=>$c), $_[0]->flag('char_entity_set'=>1) if $c; $_[0]; } sub unicode {my $c=0; $c=${$_[1]} =~ s/&\#[x0-9a-fA-F;]+/H/g; $_[0]->flag('replace_unicode'=>1); $_[0]->counter('replace_unicode'=>$c), $_[0]->flag('unicode'=>1) if $c; $_[0];} sub cap {my $name=$_[0]->from('name'); my $mail=$_[0]->from('mail'); my $cap=$_[0]->get_cap(\$mail); $mail =~ s/\#.*//g; if ( $cap && length $name == 0) { $name = "$capš"; } elsif ( $cap ) { $name .= "—$capš"; } $_[0]->from('name' => $name, 'mail' => $mail); $_[0]->flag('replace_cap'=>1); $_[0]->counter('replace_cap'=>1), $_[0]->flag('cap'=>1) if $cap; $_[0];} sub trip {my $name=$_[1] || $_[0]->from('name'); my $trip=$_[0]->get_trip(\$name); $name =~ s|(.*?)(?:\#.*)|$1Ÿ$trip|; $_[0]->from('name' => $name); $_[0]->flag('replace_trip'=>1); $_[0]->counter('replace_trip'=>1), $_[0]->flag('trip'=>1) if $trip; $_[0];} sub fusianasan {my $name=$_[0]->from('name'); my $host=$_[0]->get_host(); my $c = 0; $c = $name =~ s|(.*?)fusianasan(.*?)|$1$host$2|; $_[0]->from('name' => $name); $_[0]->flag('replace_fusianasan'=>1); $_[0]->counter('replace_fusianasan'=>$c), $_[0]->flag('fusianasan'=>1) if $c; $_[0];} sub res_anchor {my $uri=$_[0]->path('script').'read.cgi/'.$_[0]->from('bbs').'/'.$_[0]->from('key').'/'; my $c=0; $c = ${$_[1]} =~ s/(?:>>|>>)(\d*-\d*|\d+)/>>$1<\/a>/g; $_[0]->flag('replace_resanchor'=>1); $_[0]->counter('replace_resanchor'=>$c), $_[0]->flag('resanchor'=>1) if $c; $_[0];} sub uri_anchor {my $c=0; $c = ${$_[1]} =~ s{(https?|ftp|gopher|telnet|whois|news)\:([\w|\:\!\#\$\%\=\&\-\^\`\\\|\@\~\[\{\]\}\;\+\*\,\.\?\/]+)}{$1\:$2<\/a>}ig; $_[0]->flag('replace_urianchor'=>1); $_[0]->counter('replace_urianchor'=>$c), $_[0]->flag('urianchor'=>1) if $c; $_[0];} sub ng_word {my $f=$_[0]->path('bbs').$_[0]->file('henkan'); my($k,$m,$t,$c,$tmp,$count); my $d=$_[0]->conf('delimiter'); open FH, "<$f"; while(){chomp; ($k,$m,$t,$c) = split $d; $tmp = $_[0]->from($k); if ($m eq 's') {$count += $tmp =~ s/$t/$c/g;} elsif ($m eq 'tr') {eval{$count += $tmp =~ tr/$t/$c/;};} $_[0]->from( $k => $tmp );} close FH; $_[0]->flag('replace_ng_word'=>1); $_[0]->counter('replace_ng_word'=>$count), $_[0]->flag('ng_word'=>1) if $count; $_[0];} 1; __END__