From 2a5664ad1abf679b9e50a6c409902ce2ef638cc5 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Thu, 25 Aug 2005 21:02:39 +0000 Subject: Bug 208761: Move GetFormat() from globals.pl into Bugzilla::Template - Patch by Frédéric Buclin r=wicked a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- globals.pl | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) (limited to 'globals.pl') diff --git a/globals.pl b/globals.pl index 17174540a..6e9dcbeba 100644 --- a/globals.pl +++ b/globals.pl @@ -1082,54 +1082,6 @@ sub OpenStates { return ('NEW', 'REOPENED', 'ASSIGNED', 'UNCONFIRMED'); } - -############################################################################### - -# Constructs a format object from URL parameters. You most commonly call it -# like this: -# my $format = GetFormat("foo/bar", scalar($cgi->param('format')), -# scalar($cgi->param('ctype'))); - -sub GetFormat { - my ($template, $format, $ctype) = @_; - - $ctype ||= "html"; - $format ||= ""; - - # Security - allow letters and a hyphen only - $ctype =~ s/[^a-zA-Z\-]//g; - $format =~ s/[^a-zA-Z\-]//g; - trick_taint($ctype); - trick_taint($format); - - $template .= ($format ? "-$format" : ""); - $template .= ".$ctype.tmpl"; - - # Now check that the template actually exists. We only want to check - # if the template exists; any other errors (eg parse errors) will - # end up being detected later. - eval { - Bugzilla->template->context->template($template); - }; - # This parsing may seem fragile, but its OK: - # http://lists.template-toolkit.org/pipermail/templates/2003-March/004370.html - # Even if it is wrong, any sort of error is going to cause a failure - # eventually, so the only issue would be an incorrect error message - if ($@ && $@->info =~ /: not found$/) { - ThrowUserError("format_not_found", { 'format' => $format, - 'ctype' => $ctype, - }); - } - - # Else, just return the info - return - { - 'template' => $template , - 'extension' => $ctype , - 'ctype' => Bugzilla::Constants::contenttypes->{$ctype} , - }; -} - ############# Live code below here (that is, not subroutine defs) ############# use Bugzilla; -- cgit v1.2.3-24-g4f1b