X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/7972a1398462162fbeb2283a32e5e1e0247a8d04..863abbbee47daf6df718856079cb50833e3552c2:/modules/Output.pm diff --git a/modules/Output.pm b/modules/Output.pm index e30dd83..ba41e38 100644 --- a/modules/Output.pm +++ b/modules/Output.pm @@ -6,7 +6,7 @@ package Output; # HTML generating routines # # Author: Patrick Canterino <patshaping@gmx.net> -# Last modified: 2003-10-13 +# Last modified: 2004-02-23 # use strict; @@ -14,65 +14,32 @@ use strict; use vars qw(@EXPORT); use CGI qw(header); -use HTML::Entities; use Tool; +use HTML::Entities; +use Template; + ### Export ### use base qw(Exporter); -@EXPORT = qw(htmlhead - htmlfoot +@EXPORT = qw(error_template error abort - error_in_use - equal_url - dir_link); - -# htmlhead() -# -# Generate the head of a HTML document -# (a text/html HTTP header will also be created) -# -# Params: Title and heading -# -# Return: Head for the HTML document - -sub htmlhead($) -{ - my $title = shift; - - my $html = header(-type => "text/html"); + error_in_use); - $html .= <<END; -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" -"http://www.w3.org/TR/html4/loose.dtd"> +my $tpl_error; -<html> -<head> -<title>$title</title> -<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> -</head> -<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> - -<h1>$title</h1> - -END - - return $html; -} - -# htmlfoot() +# error_template() # -# Generate the foot of a HTML document +# Set the path to the template file used for error messages +# (I'm lazy...) # -# Params: -nothing- -# -# Return: Foot for the HTML document +# Params: Template file -sub htmlfoot +sub error_template($) { - return "\n</body>\n</html>"; + $tpl_error = shift; } # error() @@ -81,25 +48,33 @@ sub htmlfoot # # Params: 1. Error message # 2. Virtual path to which a link should be displayed (optional) +# 3. Hash reference: Template variables (optional) # # Return: Formatted message (Scalar Reference) -sub error($;$) +sub error($;$$) { - my ($message,$path) = @_; + my ($message,$path,$vars) = @_; - my $output = htmlhead("Error"); - $output .= "<p>$message</p>"; + my $tpl = new Template; + $tpl->read_file($tpl_error); - if($path) - { - $path = encode_entities($path); + $tpl->fillin("ERROR",$message); + $tpl->fillin("DIR",$path); + $tpl->fillin("SCRIPT",encode_entities($ENV{'SCRIPT_NAME'})); - $output .= "\n\n"; - $output .= "<p><a href=\"$ENV{'SCRIPT_NAME'}?command=show&file=$path\">Back to $path</a></p>"; + $tpl->parse_if_block("dir",defined $path); + + if(ref($vars) eq "HASH") + { + while(my ($key,$value) = each(%$vars)) + { + $tpl->fillin($key,$value); + } } - $output .= htmlfoot; + my $output = header(-type => "text/html"); + $output .= $tpl->get_template; return \$output; } @@ -109,18 +84,20 @@ sub error($;$) # Print an error message and exit script # ^^^^^ # -# Params: Error message +# Params: 1. Error message +# 2. Hash reference: Template variables (optional) -sub abort($) +sub abort($;$) { - my $output = error(shift); + my $output = error(shift,undef,shift); print $$output; exit; } # error_in_use() # -# Create a message, that a file is currently in use +# Create a message, which shows, that a +# file is currently in use # # Params: File, which is in use # @@ -130,46 +107,7 @@ sub error_in_use($) { my $file = shift; - return error("The file '".encode_entities($file)."' is currently editet by someone else.",upper_path($file)); -} - -# equal_url() -# -# Create an "equals"-link and print it out -# -# Params: 1. HTTP root -# 2. Relative path -# -# Return: Formatted link (String) - -sub equal_url($$) -{ - my ($root,$path) = @_; - my $url; - - $root =~ s!/$!!; - $path =~ s!^/!!; - $url = $root."/".$path; - $url = encode_entities($url); - - return "<p>(equals <a href=\"$url\" target=\"_blank\">$url</a>)</p>\n\n"; -} - -# dir_link() -# -# Create the link to the directory of a file and -# print it out -# -# Params: File -# -# Return: Formatted link (String) - -sub dir_link($) -{ - my $dir = upper_path(shift); - $dir = encode_entities($dir); - - return "<p><a href=\"$ENV{'SCRIPT_NAME'}?command=show&file=$dir\">Back to $dir</a></p>\n\n"; + return error("The file '".encode_entities($file)."' is currently edited by someone else.",upper_path($file)); } # it's true, baby ;-)