X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/7febe1a1710566c5d66cdbd125fd81fb0f89512f..03d83644ce2d958fe3e0466fa272c67f0566f4ab:/modules/Output.pm diff --git a/modules/Output.pm b/modules/Output.pm index 6e48bf3..449731f 100644 --- a/modules/Output.pm +++ b/modules/Output.pm @@ -6,7 +6,7 @@ package Output; # HTML generating routines # # Author: Patrick Canterino -# Last modified: 2003-12-13 +# Last modified: 2004-02-06 # 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/heading -# -# Return: Head for the HTML document - -sub htmlhead($) -{ - my $title = shift; + error_in_use); - my $html = header(-type => "text/html"); +my $tpl_error; - $html .= < - - - -$title - - - - -

$title

- -END - - return $html; -} - -# htmlfoot() -# -# Generate the foot of a HTML document +# error_template() # -# Params: -nothing- +# Set the path to the template file using for error messages +# (I'm lazy...) # -# Return: Foot for the HTML document +# Params: Template file -sub htmlfoot +sub error_template($) { - return "\n\n"; + $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 .= "

$message

"; + 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'})); + + $tpl->parse_if_block("dir",defined $path); - $output .= "\n\n"; - $output .= "

Back to $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; } @@ -134,44 +109,6 @@ sub error_in_use($) return error("The file '".encode_entities($file)."' is currently edited by someone else.",upper_path($file)); } -# equal_url() -# -# Create an "equals"-link -# -# 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 "

(equals $url)

\n\n"; -} - -# dir_link() -# -# Create the link to the directory of a file -# -# Params: File -# -# Return: Formatted link (String) - -sub dir_link($) -{ - my $dir = upper_path(shift); - $dir = encode_entities($dir); - - return "

Back to $dir

\n\n"; -} - # it's true, baby ;-) 1;