and the html:#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI::Cookie; use CGI qw(:standard); use DBI; use DBD::mysql; use HTML::Template; $tmpl = HTML::Template->new(filename => 'index.html'); @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Se +p', 'Oct', 'Nov', 'Dec'); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localt +ime; $xronos = "$mday $months[$mon], $hour:$min"; $ip = $ENV{'REMOTE_ADDR'}; @numbers = split (/\./,$ip); $address = pack ("C4", @numbers); $host = gethostbyaddr ($address, 2) || $ip; $host = "Νίκος" if ( ($host eq "localhost") or ($host eq "dslcustomer- +221-228.vivodi.gr" or $host eq "dell") ); print header( -charset=>'iso-8859-7' ); $db = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net') ? DBI->connect('DBI:mysql:nikos_db', 'root', '') : DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', '***** +***') or print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0 +; #********************************************************************* +********** @files = <../data/text/*.txt>; @display_files = map( /([^\/]+)\.txt/, @files ); $keimeno = param('select') or "Αρχική Σελίδα"; $st = $db->prepare( "SELECT host FROM logs" ); $st->execute(); while( $row = $st->fetchrow_hashref ) { if( $host eq $row->{host} ) { $hostmatch = 1; } } if( param('select') and param('select') !~ /\.\./ ) { open(FILE, "<../data/text/$keimeno.txt") or die $!; @data = <FILE>; close(FILE); $data = join('', @data); $db->do( "UPDATE logs SET keimeno='$keimeno' WHERE host='$host'" ) + or die $db->errstr; } elsif( $hostmatch == 1 ) { $db->do( "UPDATE logs SET visits = visits + 1 WHERE host='$host'" +) or die $db->errstr; $st = $db->prepare( "SELECT * FROM logs WHERE host='$host'" ); $st->execute(); $row = $st->fetchrow_hashref; $data = "Καλώς ήλθες " .$host. "! Χαίρομαι που βρίσκες την σελίδα +ενδιαφέρουσα!\n" . "Τελευταία φορά ήρθες εδώ ως " .$row->{host}. " στις " .$r +ow->{xronos}. " !!\n" . "Σύνολικές ήρθες εδώ " .$row->{visits}. " φορές!!!\n" . "Τελευταία είδες το κείμενο { " .$row->{keimeno}. " }\n" . "Ποιό κείμενο θα μελετήσεςι αυτήν τη φορά !?"; } elsif( $hostmatch != 1 ) { if ( $host ne "Νίκος" ) { $data = "Γεια σου " .$host. "!\n" . "Έρχεσαι για 1η φορά εδώ !!\n" . "Ελπίζω να βρεις τα κείμενα ενδιαφεροντα !!!"; $db->do( "INSERT INTO logs VALUES (null, '$host', '$xronos', '$ +text', 1)" ) or die $db->errstr; } else { $data = "Γεια σου Νικόλα, τι χαμπάρια !?! :-)"; } } $data =~ s/\n/\\n/g; $data =~ s/"/\\"/g; $data =~ tr/\cM//d; $tmpl->param( data => $data ); # To fill TMPL_LOOPs you have to pass a reference to an array with # references to hashes inside. And the inner hashes contain the data # for the TMPL_VARs inside the TMPL_LOOP. Well, it's a bit tricky. @display_files = map ( /([^\/]+)\.txt/, glob '../data/text/*.txt' ); @array_of_hashes = map { option => $_ }, @display_files; $tmpl->param( options => \@array_of_hashes ); open(FILE, "<../data/text/tips") or die $!; @tips = <FILE>; close(FILE); @tips = grep { !/^\s*\z/s } @tips; $tip = $tips[int(rand(@tips))]; $db->do( "UPDATE counter SET counter = counter + 1" ) if ($host ne "Νί +κος"); $st = $db->prepare( "SELECT counter FROM counter" ); $st->execute(); $row = $st->fetchrow_hashref; $tip = $tips[ int rand @tips ]; $tmpl->param( tip => $tip ); $tmpl->param(host => $host); $tmpl->param(xronos => $xronos); $tmpl->param(counter => $counter); # Appropriate headers go here print $tmpl->output;
<html> <head> <title>Ψυχωφελή Π_ +7;ευματικά Κεί +μενα!</title> <link rel="stylesheet" type="text/css" href="../style.css" /> <script language="JavaScript" tape="text/javascript"> var textToShow = "<TMPL_VAR name=data>"; <!-- ***************************************************************** +***** --> <script type='text/javascript'> var textToShow = "$data"; var tm; var pos = 0; var counter = 0; function init() { tm = setInterval("type()", 45) } function type() { if (textToShow.length != pos) { d = document.getElementById("DivText"); c = textToShow.charAt(pos++); if (c.charCodeAt(0) != 10) d.appendChild(document.createTextNode(c)); else d.appendChild(document.createElement("br")); counter++; if (counter >= 1800 && (c.charCodeAt(0) == 10 || c == ".")) { d.appendChild(document.createElement("br")); d.appendChild(document.createTextNode("Press any key...")); counter = 0; clearInterval(tm); document.body.onkeypress = function () { document.getElementB +yId("DivText").innerHTML = ''; tm = setInterval("ty +pe()", 50); document.body.onkeyp +ress = null; }; } } else clearInterval(tm); } </script> <body onload=init()> <center> <div id="DivText" align="Left" style=" background-image: url(../data/images/kenzo.jpg); border: Ridge Orange 5px; width: 850px; height: 500px; color: LightSkyBlue; font-family: Times; font-size: 18px;"> </div <!-- ***************************************************************** +***** --> </script> </head> <body onload="init()"> <form method="post" action="index.pl" enctype="application/x-www-f +orm-urlencoded"> <p align="center"> <font color="Lime" size="5">Λόγος 	 +36;υχωφελής και +; Θαυμάσιος => </font> <select name="select"> <TMPL_LOOP name=options> <option value="<TMPL_VAR name=@array_of_hashes>"><TMPL_VAR + name=@array_of_hashes></option> </TMPL_LOOP> </select> <input type="submit" name="ok" value="ok" /> </p> </form> <br /> <center> <div id="DivText" align="Left" style="background-image: url(../dat +a/images/kenzo.jpg); border: Ridge Orange 5px; width: 850px; height: 500px; color: +LightSkyBlue; font-family: Times; font-size: 18px;"></div> <br /><br /><br /> <form method="post" action="show.pl" enctype="application/x-www-fo +rm-urlencoded"> <table class="user"> <tr><td>Πώς σε λέν^ +9; αδελφέ?</td> <td><input type="text" +name="onoma" /></td></tr> <tr><td>Ποιά είναι +; η γνώμη σου γ_ +3;α την ευχούλα +; *Κύριε Ιησού ] +5;ριστέ Ελέησο +ν Με* ?</td> <td><textarea name="euxoula" rows="4" col +s="25"></textarea></td></tr> <tr><td>Μοιράσου μ +;αζί μας μία κα +;τά τη γνώμη σο +;υ θαυμαστή πρ +οσωπική πνευ&# +956;ατική εμπει` +1;ία από κάποιο +;ν γέροντα προ +ς ώφελος των υ +πολοίπων αδε&# +955;φών (αν φυσικ&# +940; έχεις :-)</td> <td><textarea name="sxol +io" rows="6" cols="25"></textarea></td></tr> <tr><td>Ποιό είναι +; το e-mail σου?</td> <td><input type="text" + name="email" /></td></tr> <tr><td><input type="submit" name="Εμφά	 +57;ιση όλων των 	 +45;πόψεων" value="Εμφ	 +40;νιση όλων τω_ +7; απόψεων" /></td> <td><input typ +e="submit" name="Αποστολή" va +lue="Αποστολή" /></td></tr> </table> <div></div> </form> <br /><br /> <!-- table: tip --> <table class="quote"> <tr><td><TMPL_VAR name=tip></td></tr> </table> <br /> <!-- table: host, date and counter --> <table class="info"> <tr><td><TMPL_VAR name=host></td></tr> <tr><td><TMPL_VAR name=xronos></td></tr> <tr><td><TMPL_VAR name=counter></td></tr> </table> <br /> <a href="games.pl"><img src="../data/images/games.gif" /></a> <p class="first"><a href="show.pl?onoma=showlog"><b>Last Update: 2 +1/4/2005</b></a></p> </body> </html>
20050426 Edit by ysth: change title from "html::tempalte help"
In reply to HTML::Template help by Nik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |