From eaeffc6fa2408da8b8cbd0567efb48350fe9877f Mon Sep 17 00:00:00 2001 From: josch Date: Sun, 9 Mar 2008 19:32:24 +0000 Subject: [PATCH] added proper mime type handling git-svn-id: http://yolanda.mister-muffin.de/svn@252 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/download.pl | 1 + trunk/functions.pl | 110 ++++++++++++++++++++++++++++++--------------- 2 files changed, 75 insertions(+), 36 deletions(-) diff --git a/trunk/download.pl b/trunk/download.pl index 7b8c655..fce119b 100644 --- a/trunk/download.pl +++ b/trunk/download.pl @@ -50,6 +50,7 @@ if($query->param('id')) } #in both cases - do some slurp-eaze to the browser + #TODO: lol insecure! open(FILE, "<$root/videos/".$query->param('id')); $filesize = -s "$root/videos/".$query->param('id'); diff --git a/trunk/functions.pl b/trunk/functions.pl index 0cbf917..5a7a7ed 100644 --- a/trunk/functions.pl +++ b/trunk/functions.pl @@ -142,36 +142,6 @@ sub output_page my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); - #let the XSLT param choose other stylesheets or default to xhtml.xsl - my $param_xslt = $query->param('xslt'); - $param_xslt =~ s/[^\w]//gi; - - if( -f "$root/xsl/$param_xslt.xsl") - { - $xsltpath = "$root/xsl/$param_xslt.xsl" - } - else - { - $xsltpath = "$root/xsl/xhtml.xsl"; - } - - my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath)); - - # TODO: this usage of libxsl omits the xsl:output definition (no ident of html) but outputs in UTF8 - # TODO: later versions of XML::LibXSLT (>= 1.62) define output_as_bytes - this is what we want to use - # TODO: wait for debian packagers to update to 1.62 or later - # TODO: "foo" is not a meaningful variable name - $foo = $stylesheet->transform( - $parser->parse_string( - XMLout( - $page, - KeyAttr => {}, - RootName => 'page', - AttrIndent => '1' - ) - ) - ); - if($query->param('cortado') eq 'true') { @cookies = [$session->cookie(-name=>$session_name, -value=>$session->id), $session->cookie(-name=>'cortado', -value=>'true')]; @@ -185,13 +155,81 @@ sub output_page @cookies = [$session->cookie(-name=>$session_name, -value=>$session->id)]; } - #send everything including http headers to the user - if XSLT chosen is XSPF set download filename - return $session->header( - -type=>'application/xhtml+xml', - # TODO: fix the MIME type so that every XSLT works again - # (you earned eternal hate for this, josch) + #let the XSLT param choose other stylesheets or default to xhtml.xsl + my $param_xslt = $query->param('xslt'); + $param_xslt =~ s/[^\w]//gi; + + if($param_xslt eq "null") + { + $output = $parser->parse_string( + XMLout( + $page, + KeyAttr => {}, + RootName => 'page', + AttrIndent => '1' + ) + ); + return $session->header( + -type=>'application/xml', -charset=>'UTF-8', -cookie=>@cookies ), - $foo->toString; + $output->toString; + } + else + { + if( -f "$root/xsl/$param_xslt.xsl") + { + $xsltpath = "$root/xsl/$param_xslt.xsl" + } + else + { + $xsltpath = "$root/xsl/xhtml.xsl"; + } + + my $stylesheet = $xslt->parse_stylesheet($parser->parse_file($xsltpath)); + + # TODO: this usage of libxsl omits the xsl:output definition (no ident of html) but outputs in UTF8 + # TODO: later versions of XML::LibXSLT (>= 1.62) define output_as_bytes - this is what we want to use + # TODO: wait for debian packagers to update to 1.62 or later + $output = $stylesheet->transform( + $parser->parse_string( + XMLout( + $page, + KeyAttr => {}, + RootName => 'page', + AttrIndent => '1' + ) + ) + ); + + if($param_xslt eq "xspf") + { + return $session->header( + -type=>'application/xspf+xml', + -charset=>'UTF-8', + -attachment=>$query->param('query').".xspf", + -cookie=>@cookies + ), + $output->toString; + } + elsif($param_xslt eq "rss") + { + return $session->header( + -type=>'application/rss+xml', + -charset=>'UTF-8', + -cookie=>@cookies + ), + $output->toString; + } + else + { + return $session->header( + -type=>'application/xhtml+xml', + -charset=>'UTF-8', + -cookie=>@cookies + ), + $output->toString; + } + } }