# Blosxom Plugin: update -*- perl -*- # Author: Anthony Towns # Version: 0.1 # Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom # update plugin Home/Docs/Licensing: # http://azure.humbug.org.au/~aj/blosxom/plugins/update/update-0.1.gz package update; use File::stat; # --- Configuration Variables --- # what extension will updates have? $extension ||= "upd"; # foo.txt -> foo-1.upd # should updates be repeated in the main blog? $repeat_updates ||= 0 unless defined $debug_level; $debug_level = 0 unless defined $debug_level; # ---------------------------------------------------------------------- use FileHandle; use CGI; my $package = 'update'; sub debug { my ($level, @msg) = @_; if ($debug_level >= $level) { print STDERR "$package debug $level: @msg\n"; } } sub load_template { my ($bit) = @_; return $blosxom::template->('', "$package.$bit", $blosxom::flavour); } sub report { my ($bit, $path, $fn, $updn, $updfn) = @_; open(UPD, $updfn) or return ""; my $title = ; while() { last if ($_ =~ m/^$/); } my $body = ""; while() { $body .= $_; } close(UPD); my ($dw,$mo,$mo_num,$da,$ti,$yr) = blosxom::nice_date(stat($updfn)->mtime); my $f = load_template($bit); $f =~ s/((\$[\w:]+)|(\$\{[\w:]+\}))/$1 . "||''"/gee; return $f; } sub start { debug(1, "start() called, enabled"); while () { last if /^(__END__)?$/; my ($flavour, $comp, $txt) = split ' ',$_,3; $txt =~ s:\\n:\n:g; $blosxom::template{$flavour}{"$package.$comp"} = $txt; } return 1; } sub filter { my ($pkg, $files_ref) = @_; my $bext = $blosxom::file_extension; return 1 unless ($bext eq $extension); return 1 if $repeat_updates; my $bdd = $blosxom::datadir . "/$path"; foreach my $fn ( keys %$files_ref ) { debug(1, "looking at $fn"); if ($fn =~ m/(.*)-\d+\.\Q$bext\E$/) { my $realfn = "$1.$bext"; debug(1, "matched, comparing to $realfn"); delete $files_ref->{$fn} if -e "$realfn"; } } 1; } sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; debug(1, "story() called"); my $bdd = $blosxom::datadir . "/$path"; my $updfn; for (my $updn = 1; -e ($updfn = "$bdd/$filename-$updn.$extension"); $updn++) { debug(1, "found update $updatename"); $$body_ref .= report('update', $path, $filename, $updn, $updfn); } return 1; } 1; __DATA__ error update

UPDATE $yr/$mo_num/${da}: $title
$body

\n rss update

UPDATE $yr/$mo_num/${da}: $title
$body

\n __END__ =head1 NAME Blosxom Plug-in: update =head1 SYNOPSIS Purpose: Allows for updates to posts without editing the original file (and risking changing the date stamp, or tempting you to change history) =head1 VERSION 0.1 1st release =head1 AUTHOR Anthony Towns , http://azure.humbug.org.au/~aj/ =head1 BUGS None known; address bug reports and comments to me (even better, blog about them, and send me a link). =head1 Customization =head2 Configuration variables C<$extension> is the extension files containing updates will have. You can either set this to something different to regular blog articles (eg, "upd") to keep them seperate, or you can set it to the same as your regular blog articles (eg, "txt"). C<$repeat_updates> controls whether updates should appear as real articles as well. This has no effect if you have a different extension for updates and regular articles. C<$debug_level> can be set to a value between 0 and 5; 0 will output no debug information, while 5 will be very verbose. The default is 1, and should be changed after you've verified the plugin is working correctly. =head2 Classes for CSS control There's a class used, available for CSS customization. * C -- the anchor used for the update title. * C -- the body of the update. =head2 Flavour-style files If you want a format change that can't be made by CSS, you can override the HTML generated by creating files similar to Blosxom's flavour files. They should be named update.I.I; for available Is and their default meanings, see the C<__DATA__> section in the plugin. (update.update.html is what you most likely want to mess with) =head1 CREDITS The structure of this plugin and some of the helper functions is based on the seemore plugin by Todd Larason. =head1 LICENSE this Blosxom Plug-in Copyright 2003, Anthony Towns Portions Copyright 2003, Todd Larason (jtl@molehill.org) (This license is the same as Blosxom's) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.