--- absolute.orig 2003-12-26 20:05:17.000000000 -0800 +++ absolute 2003-12-26 20:06:06.000000000 -0800 @@ -1,11 +1,12 @@ # Blosxom Plugin: absolute # Author(s): Rael Dornfest -# Version: 2.0b3-4 +# Version: 2.0b3-4permalink2 # Documentation: See the bottom of this file or type: perldoc readme package absolute; # --- Configurable variables ----- +# Permalink patch: these variables aren't used with the permalink patch. # What's the URL of your images directory? my $image_url = ""; @@ -16,6 +17,11 @@ # e.g. http://www.example/blosxom # -------------------------------- +use Cwd; +use File::Basename; + +my $debug = 0; # log debug messages or not? + $image_url =~ s!/$!!; $datadir_url =~ s!/$!!; @@ -23,18 +29,56 @@ 1; } +#FIXME doesn't handle elements from the html + sub story { my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; - $$body_ref =~ s!(!$1$blosxom::url$3$2$4>!sig; +# $$body_ref =~ s!(!$1$blosxom::url$3$2$4>!sig; + $$body_ref =~ s!(!$1.adjust_address($3, $path)."$2$4>"!sige; - $image_url and $$body_ref =~ s!(!$1$image_url$3$2$4>!sig; - - $datadir_url and $$body_ref =~ s!(!$1$datadir_url$path/$3$2$4>!sig; +# permalink can't handle files outside $blosxom::datadir. +# $image_url and $$body_ref =~ s!(!$1$image_url$3$2$4>!sig; + +# $datadir_url and $$body_ref =~ s!(!$1$datadir_url$path/$3$2$4>!sig; + $$body_ref =~ s!(!$1.adjust_address($3, $path)."$2$4>"!sige; return 1; } + +# resolve relative addresses +sub adjust_address +{ + my ($file, $path) = @_; + my $orig_file = $file; # keep this in case we don't find an address + + warn "absolute::adjust_address([$file], [$path])\n" if $debug > 0; + my $fullpath = $file =~ m!^/! ? "$blosxom::datadir/$file" : + "$blosxom::datadir$path/$file"; # only add $path if $file doesn't start with / + + if (-d $fullpath) + { + $file = Cwd::abs_path("$fullpath"); # get the "canonical" path + } + elsif (-d dirname($fullpath)) + { + # Perl 5.6's Cwd isn't very smart and chokes on files + # so we make sure to only give it directories + my $basename = basename($fullpath); + $file = Cwd::abs_path(dirname($fullpath)); + $file .= "/$basename"; + } + else + { + return $orig_file; # give up if we can't find the file. + } + $file =~ s/$blosxom::datadir//; + $file = permalink::get_link($file); + + return ($file) ? $file : $orig_file; +} + 1; __END__ @@ -62,9 +106,13 @@ The plug-in also should preserve any attributes included in the or tags. +Permalink patch: relative URLs are resolved in both and tags. +Resolution is done using permalink. The old $image_url and $datadir_url +variables are not used. + =head1 VERSION -2.0b3-4 +2.0b3-4permalink Version number coincides with the version of Blosxom with which the current version was first bundled. @@ -73,6 +121,8 @@ Rael Dornfest , http://www.raelity.org/ +Permalink patch by Mark Ivey , http://zovirl.com + =head1 SEE ALSO Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/