iiplc/II/T.pm

206 lines
4.5 KiB
Perl
Raw Normal View History

2014-06-11 15:55:00 +04:00
package II::T;
use HTML::Template;
use Data::Dumper;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub head {
my ( $self, $title ) = @_;
my $t = HTML::Template->new( filename => 't/head.html' );
$t->param( TITLE => $title );
return $t->output;
}
2014-06-15 19:12:03 +04:00
sub echo {
2014-06-16 11:36:35 +04:00
my ( $self, $echo ) = @_;
2014-06-15 19:12:03 +04:00
2014-06-16 11:36:35 +04:00
my $e = HTML::Template->new( filename => 't/echo.html' );
2014-06-15 19:12:03 +04:00
2014-06-16 11:36:35 +04:00
$e->param( ECHO => $echo );
2014-06-15 19:12:03 +04:00
return $e->output();
}
2014-06-11 15:55:00 +04:00
sub index {
my ( $self, $echoareas ) = @_;
my $i = HTML::Template->new( filename => 't/index.html' );
my $index = '<div class="echo">';
while (<@$echoareas>) {
$i->param( ECHO => $_ );
$index .= $i->output();
}
$index .= '</div>';
return $index;
}
sub tree {
my ( $self, $data ) = @_;
my $p = HTML::Template->new( filename => 't/tree.html' );
my $time = localtime( $data->{time} );
# my $post = II::T->pre( $data->{post} );
my $link = $data->{subg};
$link =~ s/\s/%20/g;
$p->param( SUBG => "$data->{subg}" );
$p->param( LINK => $link );
$p->param( TIME => "$time" );
$p->param( FROM => $data->{from} );
# $p->param( TO => $data->{to} );
# $p->param( POST => $post );
$p->param( ECHO => $data->{echo} );
return $p->output();
}
sub out {
my ( $self, $data ) = @_;
my $p = HTML::Template->new( filename => 't/out.html' );
my $post = II::T->pre( $data->{post} );
$p->param( SUBG => $data->{subg} );
$p->param( TIME => "$time" );
$p->param( FROM => $data->{from} );
$p->param( TO => $data->{to} );
$p->param( POST => $post );
$p->param( ECHO => $data->{echo} );
$p->param( BASE64 => $data->{base64} );
$p->param( HASH => $data->{hash} );
return $p->output();
}
sub post {
my ( $self, $data ) = @_;
my $p = HTML::Template->new( filename => 't/post.html' );
my $time = localtime( $data->{time} );
my $post = II::T->pre( $data->{post} );
2014-06-16 01:40:11 +04:00
my $cut;
2014-06-17 16:27:15 +04:00
if ( $data->{subg} =~ /Re:\s+(.+)/ ) {
2014-06-16 01:40:11 +04:00
$cut = $1;
}
else {
$cut = $data->{subg};
}
2014-06-11 15:55:00 +04:00
$p->param( SUBG => $data->{subg} );
2014-06-16 11:36:35 +04:00
$p->param( CUT => $cut );
2014-06-11 15:55:00 +04:00
$p->param( TIME => "$time" );
$p->param( FROM => $data->{from} );
$p->param( TO => $data->{to} );
$p->param( POST => $post );
$p->param( ECHO => $data->{echo} );
$p->param( HASH => $data->{hash} );
return $p->output();
}
sub new_mes {
2014-06-16 11:36:35 +04:00
my ( $self, $echo ) = @_;
2014-06-11 15:55:00 +04:00
2014-06-16 11:36:35 +04:00
my $n = HTML::Template->new( filename => 't/new.html' );
$n->param( ECHO => $echo );
2014-06-11 15:55:00 +04:00
return $n->output();
}
sub send {
my ( $self, $data ) = @_;
my $p = HTML::Template->new( filename => 't/send.html' );
my $time = localtime( $data->{time} );
my $post = II::T->pre( $data->{post} );
2014-06-17 16:27:15 +04:00
$data->{subg} =~ s/Re:\s+(.+)/$1/g;
2014-06-11 15:55:00 +04:00
$p->param( SUBG => $data->{subg} );
$p->param( TIME => "$time" );
$p->param( FROM => $data->{from} );
$p->param( TO => $data->{to} );
$p->param( POST => $post );
$p->param( ECHO => $data->{echo} );
$p->param( HASH => $data->{hash} );
return $p->output();
}
2014-07-01 11:27:24 +04:00
# Preparsing before input to SQL
sub in_pre {
my ($self, $post) = @_;
$post =~ s/'/\\'/g;
$post =~ s/"/\\"/g;
$post =~ s/'/\\'/g;
$post =~ s/`/\\`/g;
$post =~ s/\$/\\\$/g;
return $post;
}
# Preparsing output
2014-06-11 15:55:00 +04:00
sub pre {
my ( $self, $post ) = @_;
$post =~ s/</&lt;/g;
$post =~ s/>/&gt;/g;
2014-06-17 11:05:10 +04:00
$post =~ s/&gt;(.+)/<font color='green'>>$1<\/font>/g;
2014-07-01 11:27:24 +04:00
$post =~ s/--/&mdash;/g;
2014-08-01 14:26:58 +04:00
$post =~ s/.?\*(.+)\*.?/&nbsp<b>$1<\/b>&nbsp/g;
2014-06-11 15:55:00 +04:00
$post =~ s/^$/<br>\n/g;
$post =~ s/(.?)\n/$1<br>\n/g;
$post
=~ s/(https?:\/\/.+\.(jpg|png|gif))/<a href="$1"><img src="$1" width="15%" height="15%" \/><\/a>/g;
2014-06-16 11:36:35 +04:00
$post
=~ s/(https?:\/\/.+\.(JPG|PNG|GIF))/<a href="$1"><img src="$1" width="15%" height="15%" \/><\/a>/g;
2014-06-11 15:55:00 +04:00
# Not are regexp parsing
my $pre = 0;
my $txt;
open my $fh, '<', \$post or die $!;
while (<$fh>) {
my $line = $_;
if ( ( $line =~ /^====/ ) and ( $pre == 0 ) ) {
2014-06-16 14:21:35 +04:00
# $txt .= $_;
$line =~ s/====/<pre class="pre">/g;
2014-06-11 15:55:00 +04:00
$pre = 1;
}
elsif ( ( $line =~ /^====/ ) and ( $pre == 1 ) ) {
2014-06-16 14:21:35 +04:00
$line =~ s/====/<\/pre>\n/g;
2014-06-11 15:55:00 +04:00
$pre = 0;
}
$txt .= $line;
}
close $fh;
return $txt;
}
sub foot {
my ($self) = @_;
my $f = HTML::Template->new( filename => 't/foot.html' );
return $f->output();
}
1;