use strict;
use lib 'lib';
use Benchmark;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use HTML::Template;
use Config::IniFiles;
use File::Slurp;
use Perl::Tidy;
use HTML::Clean;
use POSIX qw(strftime);
use Text::Highlight 'preload';
my $t0 = new Benchmark;
my $q = new CGI;
my $cfg = new Config::IniFiles( -file => 'konfiguracija.txt' );
my $print = 'templeitas';
if ( lc( $q->param('t') ) eq 'print' ) { $print = 'print'; }
my $tmpl = HTML::Template->new( filename => $cfg->val( 'pradiniai', $print ) );
my $puslapis = lc( $q->param('p') ) || 'apie';
$puslapis =~ s/.*?(\w+).*/$1/s;
$puslapis = 'apie' unless ( $cfg->val( 'path', $puslapis ) );
my $obfuscation = lc( $q->param('o') ) || 0;
$obfuscation =~ s/.*?(\w+).*/$1/s;
my $path = $cfg->val( 'path', $puslapis );
my $dntime = 'n';
my $google = '9087993998';
print "Content-type: text/html;Charset=utf-8\n\n";
my $turinys = read_file("duomenys/$path/$puslapis.html");
if ( $path eq 'kodas' ) {
if ( !$obfuscation ) {
perltidy( source => \$turinys, destination => \$turinys );
}
my $th = new Text::Highlight( wrapper => "<pre>%s</pre>" );
$turinys = $th->highlight( 'Perl', $turinys );
}
my $laikas = strftime "%H", localtime;
if ( ( $laikas > 7 ) && ( $laikas < 21 ) ) {
$dntime = 'd';
$google = '1133789599';
}
$tmpl->param( 'google', $google );
$tmpl->param( 'tekstas', $turinys );
$tmpl->param( 'pavadinimas', $cfg->val( 'html', $puslapis ) );
$tmpl->param( 'print', $puslapis );
$tmpl->param( 'laikas', strftime '%Y.%m.%d', localtime );
$tmpl->param( 'dntime', $dntime );
if ( $path ne 'kodas' ) {
my $h = new HTML::Clean( \$tmpl->output );
$h->strip();
my $results = $h->data();
print $$results;
}
else { print $tmpl->output; }
my $t1 = new Benchmark;
my $td = timediff( $t1, $t0 );
print '<!-- ', timestr($td), ' -->';
|