# Blosxom Plugin: sticky # Author: Gary Gale # Version: 0.1 # Documentation: See the bottom of this file or type: perldoc sticky package sticky; use File::stat; use File::Find; use File::Basename; use CGI qw/:standard/; # --- Configurable variables ----- $sticky_prefix = "sticky-"; # What should sticky article files be # prefixed with? # -------------------------------- sub start { 1; } sub entries { return sub { my (%files, %indexes); find ( sub { my $d; my $curr_depth = $File::Find::dir =~ tr[/][]; if ($blosxom::depth and $curr_depth > $blosxom::depth) { $files{$File::Find::name} and delete $files{$File::Find::name}; return; } if ($File::Find::name =~ m!^$blosxom::datadir/(?:(.*)/)?(.+)\.$blosxom::file_extension$! and $2 ne 'index' and $2 !~ /^\./ and (-r $File::Find::name)) { if ($blosxom::show_future_entries or stat ($File::Find::name)->mtime < time) { if (is_sticky ($File::Find::name)) { $files{$File::Find::name} = time; } else { $files{$File::Find::name} = stat ($File::Find::name)->mtime; } if (param ('-all') or !-f "$blosxom::static_dir/$1/index." . $blosxom::static_flavours[0] or stat ("$blosxom::static_dir/$1/index." . $blosxom::static_flavours[0])->mtime < stat ($File::Find::name)->mtime) { $indexes{$1} = 1 and $d = join ('/', (blosxom::nice_date ($files{$File::Find::name})) [5,2,3]) and $indexes{$1} = $d and $blosxom::static_entries and $indexes{$d} = $d and $indexes{($1 ? "$1/" : '') . "$2.$blosxom::file_extension"} = 1; } } } }, $blosxom::datadir ); # end-find ... return (\%files, \%indexes); }; # end-return sub ... } sub is_sticky { my ($filepath) = @_; if (basename ($filepath) =~ m/^$sticky_prefix(.+)$/) { return 1; } return 0; } 1; __END__ =head1 NAME Blosxom Plug-in: sticky =head1 SYNOPSIS Purpose: Forces weblog entries whose file name commences with $sticky_prefix to have their modification date and time stamp overridden with the current date and time; thus making them appear at the start of the date ordered list of weblog entries. Overrides the default Blosxom entries subroutine. =head1 INSTALLATION Drop pthe sticky plugin into your Blosxom plugins folder. =head1 CONFIGURATION The file name prefix used to identify a sticky file may be changed by modifying the $sticky_prefix variable. =head1 NOTES This plugin requires the following Perl modules to be pre-installed:- o File::stat o File::Find o File::Basename o CGI :standard =head1 VERSION 0.1 =head1 VERSION HISTORY 0.1 05/03/04 Initial version of plugin. =head1 AUTHOR Gary Gale Based on the original blosxom entries code by Rael Dornfest =head1 SEE ALSO Blosxom Home/Docs/Licensing: http://www.blosxom.com/license.html Blosxom Plugin Docs: http://www.blosxom.com/documentation/users/plugins.html The latest version of this plugin is available from http://www.vicchi.org/site/downloads/sticky.plugin. =head1 BUGS There has to be a better and more elegant way of achieving this; ideally a sticky file should be able to be identified by a meta tag but without opening each file during the processing of the entries subroutine (which would impose an unacceptable performance hit) I can't see a way around this. Address bug reports and comments to the Blosxom mailing list [http://groups.yahoo.com/group/blosxom] =head1 LICENSE sticky plugin Copyright 2004, Gary Gale Blosxom and original entries subroutine code Copyright 2003, Rael Dornfest 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.