# Blosxom Plugin: xhtmlmime -*-cperl-*- # Author: Sam Pearson # Version: 0.1 package xhtmlmime; use strict; use CGI qw/:standard/; # --- Configuration --- # Flavours upon which you want this plugin to act. # Multiple flavours should be separated by the vertical bar # character, '|', as this will be used in a regular expression. my $flavours = ''; # Character encoding used by your website. # For English speakers, this will usually be one of: # iso-8859-1, utf-8 or windows-1251 my $charset = 'utf-8'; # --- End Configuration --- my $mime; our $meta_http_equiv; sub start { # Should this plugin run at all? $flavours or return 0; $blosxom::flavour =~ /$flavours/ or return 0; # Check for ?mime= URL parameter: if ( param('mime') ) { if ( param('mime') eq 'xhtml' ) { $mime = 'xhtml'; } else { $mime = 'html'; } return 1; } # Check user-agent HTTP headers: if ( $ENV{'HTTP_ACCEPT'} =~ m!application/xhtml\+xml! ) { if ( Accept('application/xhtml+xml') >= Accept('text/html') ) { $mime = 'xhtml'; return 1; } } # Fall back onto something safe: $mime = 'html' and return 1; } sub head { if ( $mime eq 'html' ) { $meta_http_equiv = "text/html; charset=$charset"; } else { $meta_http_equiv = "application/xhtml+xml; charset=$charset"; } return 1; } sub last { if ( $mime eq 'html' ) { $blosxom::header->{'Content-Type'} = "text/html; charset=$charset"; } else { $blosxom::header->{'Content-Type'} = "application/xhtml+xml; charset=$charset"; } } 1; __END__ =head1 NAME Blosxom Plugin: B =head1 DESCRIPTION This plugin is designed to return a B HTTP header of B to user agents that indicate they prefer it to B in their B HTTP header. The highly useful B does all the work, even down to interpreting B values. You can force the plugin to use B by specifying a URL parameter of B. Setting B to anything else will cause the plugin to use B. =head1 CONFIGURATION There are two configurable variables: Set B<$flavours> to a list of the flavours that you want the plugin to act upon. If this variable is empty, the plugin will quietly exit without doing anything. Separate each flavour using the vertical bar character, B<|>. For example: B Set B<$charset> to the encoding used on your website. The default is B, but other common English-language codes are B or B. =head1 SEE ALSO Blosxom and application/xhtml+xml: B I am aware that another similar plugin named B was once written. I was unable to locate a copy after a cursory bit of googling, so I wrote this one. I would be surprised if there were any substantial differences between the two. =head1 AUTHOR Sam Pearson =head1 LICENSE Copyright 2005, Sam Pearson This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.