From e7287283e68baf7fef5a415a05d1168f9dc7ea98 Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Wed, 29 Aug 2007 00:36:24 +0000 Subject: [PATCH] Add various plugins from Mark Ivey. --- general/cooluri2 | 246 +++++++++++++++++++++++++++++++++++++++++ general/fullcategory | 123 +++++++++++++++++++++ general/permalink | 257 +++++++++++++++++++++++++++++++++++++++++++ general/uselib | 78 +++++++++++++ 4 files changed, 704 insertions(+) create mode 100644 general/cooluri2 create mode 100644 general/fullcategory create mode 100644 general/permalink create mode 100644 general/uselib diff --git a/general/cooluri2 b/general/cooluri2 new file mode 100644 index 0000000..58246cf --- /dev/null +++ b/general/cooluri2 @@ -0,0 +1,246 @@ +# Blosxom Plugin: cooluri2 +# Author(s): Mark Ivey +# Version: 0.0.1 +# Documentation: See the bottom of this file or type: perldoc cooluri2 + +package cooluri2; +use strict; +use English; + +use File::stat; +use CGI qw/:standard/; + +my $debug = 0; # log debug messages or not? + +#FIXME: Should we return 0 in static mode? +sub start {1;} + +sub filter +{ + # get info from URI + my ($year, $month, $day, $blosxom_path, $path, $flavor) = + parse_URI(path_info() || param('path')); + + # adjust blosxom's variables + $blosxom::path_info = $blosxom_path; + $blosxom::path_info_yr = ''; + $blosxom::path_info_mo = ''; + $blosxom::path_info_mo_num = ''; + $blosxom::path_info_da = ''; + $blosxom::flavour = $flavor; + + # delete stories not matching path + while (my ($file, $time) = each %blosxom::files) + { + delete $blosxom::files{$file} if ($file !~ /^$path/); + } + + # make sure path's date matches + my ($dw,$mo,$mo_num,$da,$ti,$yr) = get_date($path); + if ( ($year and $yr ne $year) or + ($month and $mo_num ne $month) or + ($day and $da ne $day) + ) + { + %blosxom::files = (); + } + + return 1; +} + +# break the URI up into pieces +sub parse_URI +{ + my @uri = split '/', shift; + shift @uri; # throw away empty item before 1st slash + + # pull off the date, then the path + my (@date_parts, @path_parts); + while (defined $uri[0] and $uri[0] =~ /^\d/) + { + push @date_parts, shift @uri; + } + + while (defined $uri[0] and $uri[0] =~ /^[a-zA-Z]/) + { + push @path_parts, shift @uri; + } + + # pull the .flavor off the story. + my $flavor = param('flav') || $blosxom::default_flavour; + my $story = pop @path_parts; # story = last part of path + if ($story =~ /(.*)\.(.*)$/) + { + $flavor = $2 if ($2); + $story = $1; # toss flavor off story + } + push @path_parts, $story unless ($story eq 'index'); #throw away "index" + + my $path = join "/", (@path_parts); + + # Strip spurious slashes FIXME: Will we ever even have spurious slashes? + $path =~ s!(^/*)|(/*$)!!g; + + my ($year, $month, $day) = @date_parts; + # FIXME: I don't think we can do this, since its hard to tell + # a month called "Dec" from a category called "Dec" + #my $month_num = $month ? + #( + # $month =~ /\d{2}/ ? $month : ($month2num{ucfirst(lc$month)} || undef) + #) : undef; + + + my $blosxom_path = $path; + $path = "$blosxom::datadir/$path"; # get full path AFTER we get blosxom_path + + # don't add flavor back on for index or if file exists user might be asking + # for either a category or something to be served by static_file + $blosxom_path .= ".$flavor" if ($story ne 'index' and not -e "$path"); + + warn "cooluri2: Internally: date[$year/$month/$day] path[$path] " . + "story[$story] flavor[$flavor]\n" if $debug > 0; + warn "cooluri2: Externally: date[//] path[$blosxom_path] flavor[$flavor]\n" + if $debug > 0; + + return ($year, $month, $day, $blosxom_path, $path, $flavor); +} + +# get the date of a file. +sub get_date +{ + my $path = shift; + my $file_time = 0; + + # check %files, %others, %metadate::dirs, finally check on the disk + if (exists $blosxom::files{"$path.$blosxom::file_extension"}) + { + $file_time = $blosxom::files{"$path.$blosxom::file_extension"}; + } + elsif (exists $blosxom::others{"$path.$blosxom::file_extension"}) + { + $file_time = $blosxom::others{"$path.$blosxom::file_extension"}; + } + elsif (exists $metadate::dirs{"$path"}) + { + $file_time = $metadate::dirs{"$path"}; + } + elsif (-e "$path") + { + $file_time = stat("$path")->mtime; + } + + return blosxom::nice_date($file_time); +} + +1; + + +__END__ + +=head1 NAME + +Blosxom Plug-in: cooluri2 + +=head1 SYNOPSIS + +Make Blosxom recognize date-based, extensionless URIs for everything. See +http://www.w3.org/Provider/Style/URI.html for motivation. + +=head1 VERSION + +0.0.1 + +=head1 AUTHOR + +Mark Ivey , http://zovirl.com + +=head1 DESCRIPTION + +Make Blosxom recognize date-based, extensionless URIs for everything (both +stories and categories). http://www.w3.org/Provider/Style/URI.html explains +the motivation. The main goal is to use URIs which never have to be broken +(ever!). The idea for this plugin came from the cooluri plugin +by Rob Hague . + +With cooluri2, URIs like this will be recognized: + + http://example.com/2003/12/03/category + http://example.com/2003/12/14/category/story + +Days and months can be left off if you prefer a shorter URI: + + http://example.com/2003/12/category + http://example.com/2003/12/category/story + + http://example.com/2003/category + http://example.com/2003/category/story + +The date part of the URI is the creation date for that document. +It is take from %blosxom::files, %blosxom::others, %metadate::dirs, or the +last-modification time of the file itself. Note that stories may have +different creation dates then the categories they are in, so you may end +up with URIs like this: + + http://example.com/2003/10/23/category + http://example.com/2003/12/14/category/story + +This means, unfortunately, that users probably won't be able to modify a URI +to find another document. + +Extensions can still be used to specify a flavor. If no extension is present +the default flavor will be used. + +=head1 SEE ALSO + +Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/ + +Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml + +=head2 If you use cooluri2, some of these other plugins might come in handy: + +=over 4 + +=item permalink + + + +makes your life easier by automatically generating Cool URI permalinks. + +=item metadate + + + +allows you to have metadates for categories and non-story files (i.e. images, +binaries, etc.). + + +=back + + +=head1 BUGS + +Address bug reports and comments to the Blosxom mailing list +[http://www.yahoogroups.com/group/blosxom]. + +=head1 LICENSE + +metadate Blosxom Plugin Copyright 2003, Mark Ivey + +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. + diff --git a/general/fullcategory b/general/fullcategory new file mode 100644 index 0000000..b76e7dd --- /dev/null +++ b/general/fullcategory @@ -0,0 +1,123 @@ +# Blosxom Plugin: fullcategory +# Author(s): Mark Ivey +# Version: 0.0.2 +# Documentation: See the bottom of this file or type: perldoc fullcategory + +package fullcategory; + +# --- Configurable variables ----- + +# -------------------------------- + +# print debug messages or not? +my $debug = 1; + +sub start +{ + return 1; +} + +sub filter +{ + my($pkg, $files_ref) = @_; + + my $path = "$blosxom::datadir/$blosxom::path_info"; + + # if there is a flavor, this is a story and we don't have to help blosxom + return if ($path =~ m!\.[^/]*?$!); + + # the / on the end of $path is what prevents partial matches + $path .= "/"; + $path =~ s!//$!/!; # remove extra trailing /'s + + warn "fullcategory: path is [$path]\n" if $debug >= 1; + + foreach my $file (keys %$files_ref) + { + my $string = "fullcategory: checking file [$file]: "; + unless ($file =~ m!^$path!) + { + delete $files_ref->{$file}; + $string .= "deleted\n"; + } + else + { + $string .= "kept\n"; + } + warn $string if $debug >= 1; + + } + + return 1; +} + + +1; + +__END__ + +=head1 NAME + +Blosxom Plug-in: fullcategory + +=head1 SYNOPSIS + +Changes blosxom behavior so full category names are required (partial names +will no longer work) + +=head1 VERSION + +0.0.2 + +=head1 AUTHOR + +Mark Ivey , http://zovirl.com + +=head1 DESCRIPTION + +fullcategory fixes blosxom so only complete category names will work. +By default, blosxom will return results for partial category name matches. +For example, if "telephone" is a category, these would all return posts about +telephones: +http://example.com/telephone +http://example.com/telepho +http://example.com/tele + +(If "television" was also a category, that last example would include +posts from both the television & telephone categories) + +=head1 SEE ALSO + +Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/ + +Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml + +parsedate() taken from Fletcher T. Penney's entriescache plugin: +http://www.blosxom.com/plugins/indexing/entries_cache.htm + +=head1 BUGS + +Address bug reports and comments to the Blosxom mailing list +[http://www.yahoogroups.com/group/blosxom]. + +=head1 LICENSE + +fullcategory Blosxom Plugin Copyright 2004, Mark Ivey + +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. diff --git a/general/permalink b/general/permalink new file mode 100644 index 0000000..20015ca --- /dev/null +++ b/general/permalink @@ -0,0 +1,257 @@ +# Blosxom Plugin: permalink +# Author(s): Mark Ivey +# Version: 0.0.2 +# Documentation: See the bottom of this file or type: perldoc permalink + +package permalink; + +# --- Configurable variables ----- +# Pick one set of formats, or modify them to make your own + +# Blosxom Date based +#$root_format = '$url/'; +#$root_flavor_format = '$url/index.$flavour'; +#$category_format = '$url$path/'; +#$category_flavor_format = '$url$path/index.$flavour'; +#$file_format = '$url/$yr/$mo_num/$da#$fn.$default_flavour'; +#$file_flavor_format = '$url/$yr/$mo_num/$da#$fn.$flavour'; + +# Blosxom Category based +#$root_format = '$url/'; +#$root_flavor_format = '$url/index.$flavour'; +#$category_format = '$url$path/'; +#$category_flavor_format = '$url$path/index.$flavour'; +#$file_format = '$url$path/$fn.$default_flavour'; +#$file_flavor_format = '$url$path/$fn.$flavour'; + +# Cool URI 2 +#$root_format = '$url/'; +#$root_flavor_format = '$url/index.$flavour'; +#$category_format = '$url/$yr/$mo_num/$da$path/'; +#$category_flavor_format = '$url/$yr/$mo_num/$da$path/index.$flavour'; +#$file_format = '$url/$yr/$mo_num/$da$path/$fn'; +#$file_flavor_format = '$url/$yr/$mo_num/$da$path/$fn.$flavour'; + +# Cool URI 2 (Year-only) +$root_format = '$url/'; +$root_flavor_format = '$url/index.$flavour'; +$category_format = '$url/$yr$path/'; +$category_flavor_format = '$url/$yr$path/index.$flavour'; +$file_format = '$url/$yr$path/$fn'; +$file_flavor_format = '$url/$yr$path/$fn.$flavour'; + +# -------------------------------- + +use File::stat; + +use vars qw($story $category); + +my $debug = 0; # log debug messages or not? + +my $interpolate = $blosxom::interpolate || sub { + package blosxom; + my $template = shift; + $template =~ + s/(\$\w+(?:::)?\w*)/"defined $1 ? $1 : ''"/gee; + return $template; +}; + +# see perldoc for description of get_link() +sub get_link +{ + # temporarily override existing blosxom variables & match variables + local ($blosxom::fn, $blosxom::flavour, $blosxom::path); + local ($1, $2); + + $blosxom::path = shift || "/"; + warn "permalink::get_link([$blosxom::path])\n" if $debug > 0; + + $blosxom::path =~ s!^([^/])!/$1!; # add a leading / if needed + $blosxom::path =~ s!/*$!!; # remove any slashes from the end + + # strip off filename & extension + my $fn = ($blosxom::path =~ s[(.*)/(.*)$][$1]) ? $2 : ""; + my $extension = ($fn =~ s!(.*)(\..*)!$1!) ? $2 : ""; + + my $fullpath = "$blosxom::datadir$blosxom::path"; + + warn "permalink::get_link() fp[$fullpath] fn[$fn] ext[$extension]\n" + if $debug > 0; + + # We look several different places trying to find a matching file. We + # check from the most specific to the least specific. + my @places = + ( + "$fullpath/$fn$extension", # exact match + "$fullpath/$fn.$blosxom::file_extension", # story + "$fullpath/$fn" # category (with flavor) + ); + push @places, "$fullpath/" if ($fn eq "index"); # category (with index) + + my ($out, $location); + while (defined ($location = shift @places)) + { + next unless (-e "$location"); + warn "permalink::get_link() found $location\n" if $debug > 0; + + if ($extension) + { + $blosxom::flavour = $extension; + $blosxom::flavour =~ s/^\.//; # remove leading . + } + + if (-d "$location") + { + # filename is part of the path for categories... + $blosxom::path .= "/$fn" if ($fn and $fn ne "index"); + + # check to see if we are working on the root or not + if ($location =~ m!^$blosxom::datadir/*$!) + { + $out=($extension) ? $root_flavor_format : $root_format; + } + else + { + $out=($extension) ? $category_flavor_format : $category_format; + } + } + else + { + $blosxom::fn = $fn; + $out = ($extension) ? $file_flavor_format : $file_format + } + last; + } + + unless (defined $location) + { + warn "permalink::get_link() can't find $fullpath/$fn$extension\n"; + return ""; + } + + # look up the date on the file + my $mtime = $blosxom::files{"$location"} || + $blosxom::others{"$location"} || + $metadate::dirs{"$location"} || + $metadate::all{"$location"} || + stat("$location")->mtime; + local ($blosxom::dw, $blosxom::mo, $blosxom::mo_num, $blosxom::da, + $blosxom::ti, $blosxom::yr) = blosxom::nice_date($mtime); + + # use interpolate() to fill in all the variables in our template + $out = &$interpolate($out); + + warn "permalink::get_link() returning [$out]\n" if $debug > 0; + return $out; +} + +sub head +{ + my($pkg, $currentdir, $head_ref) = @_; + + $story = ""; + $category = get_link("/$currentdir"); + return 1; +} + +sub start +{ + return 1; +} + +sub date +{ + my ($pkg, $currentdir, $date_ref, $mtime, $dw,$mo,$mo_num,$da,$ti,$yr) = @_; + $story = ""; + $category = get_link("/$currentdir"); + return 1; +} + +sub story +{ + my ($pkg, $path, $fn, $story_ref, $title_ref, $body_ref) = @_; + $story = get_link("$path/$fn"); + $category = get_link("$path"); + return 1; +} + +sub foot +{ + my($pkg, $currentdir, $foot_ref) = @_; + $story = ""; + $category = get_link("/$currentdir"); + return 1; +} + +1; + +__END__ + +=head1 NAME + +Blosxom Plug-in: permalink + +=head1 SYNOPSIS + +Generate permalinks + +=head1 VERSION + +0.0.2 + +=head1 AUTHOR + +Mark Ivey , http://zovirl.com + +=head1 DESCRIPTION + +This plugin generates permalinks to help make it easier to use a consistent +format throughout a site. For use in flavor files, two variables are +exported: $permalink::story and $permalink::category. These link to the +current story and category, respectively. For other plugins which may +wish to generate links, $permalink::get_link() is provided. Given a path +to a file, story, or category, it returns the correct permalink. + +$permalink::get_link() expects the path to a file, category, or story +(starting from $blosxom::datadir). If there is an extension present it +is used as flavor. + +=head1 SEE ALSO + +Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/ + +Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml + +=head1 BUGS + +get_link() can't be used for files outside the $blosxom::datadir directory. +This might be a problem if your $blosxom::datadir isn't publically available +(by being under the web-server's document root, by using the static_file plugin, +etc.) + +Address bug reports and comments to the Blosxom mailing list +[http://www.yahoogroups.com/group/blosxom]. + +=head1 LICENSE + +permalink Blosxom Plugin Copyright 2003, Mark Ivey + +(This plugin is release under the same license as Blosxom itself) + +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. + diff --git a/general/uselib b/general/uselib new file mode 100644 index 0000000..42b536a --- /dev/null +++ b/general/uselib @@ -0,0 +1,78 @@ +# Blosxom Plugin: uselib +# Author(s): Mark Ivey +# Version: 0.0.1 +# Documentation: See the bottom of this file or type: perldoc uselib + +package uselib; + +sub start { + use lib "$blosxom::plugin_dir/lib"; + 1; +} + +1; + +__END__ + +=head1 NAME + +Blosxom Plug-in: uselib + +=head1 SYNOPSIS + +Get modules from $blosxom::plugin_dir/lib + +=head1 VERSION + +0.0.1 + +=head1 AUTHOR + +Mark Ivey + +=head1 DESCRIPTION + +Tells perl to look for perl modules in $blosxom::plugin_dir/lib. This +gives users a standard place to install modules such as MIME::Types or +File::Cat. For example, Cat.pm would be installed to +$blosxom::plugin_dir/lib/File. + +Obviously, this plugin should be loaded before any plugins that need +modules. I accomplished this by renaming it to 01uselib (00 is taken by +seeerror). + +=head1 SEE ALSO + +Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/ + +Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml + +=head1 BUGS + +Address bug reports and comments to the Blosxom mailing list +[http://www.yahoogroups.com/group/blosxom]. + +=head1 LICENSE + +uselib Blosxom plugin +Copyright 2003, Mark Ivey + +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. + -- 2.30.2