From 0e82653017f4620529c0ab72178280f9f2267ce5 Mon Sep 17 00:00:00 2001 From: Barijaona Ramaholimihaso Date: Fri, 24 Aug 2007 23:29:41 +0000 Subject: [PATCH] Initial addition of Barijaona Ramaholimihaso's plugins --- barijaona/fix_static_url | 75 +++++++++++++++++ barijaona/pagetype | 79 ++++++++++++++++++ barijaona/prefs | 141 +++++++++++++++++++++++++++++++ barijaona/prevnextstory | 168 +++++++++++++++++++++++++++++++++++++ barijaona/static_file | 175 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 638 insertions(+) create mode 100644 barijaona/fix_static_url create mode 100644 barijaona/pagetype create mode 100644 barijaona/prefs create mode 100644 barijaona/prevnextstory create mode 100644 barijaona/static_file diff --git a/barijaona/fix_static_url b/barijaona/fix_static_url new file mode 100644 index 0000000..b25599d --- /dev/null +++ b/barijaona/fix_static_url @@ -0,0 +1,75 @@ +# Blosxom plugin: fix-static-url +# Author(s): Barijaona Ramaholimihaso +# Version: 2004-08-22blosxom2 +# Documentation: see bottom of file or perldoc title + +package fix_static_url; +# ------------------ Configuration variables --------------- + +use vars qw($static_url); + +# Define here the url of your blog i.e. http://homepage.mac.com/barijaona +# alternatively, use the prefs plugin to define $fix_static_url::static_url +$static_url = "" ; + +# --------------------------------------------------------- + + +sub start { + if ( $blosxom::static_or_dynamic eq 'static') { + $saveurl = $blosxom::url; + $blosxom::url = '*DEFANG_STATIC_URL*'; + return 1; + } + else {return 0 }; +} + +sub head { + $blosxom::url= $static_url; +} + +sub last { + # for plugins who use $url before the head sub + $blosxom::output =~ s>\*DEFANG_STATIC_URL\*>$static_url>g; + 1; +} + +1; +__END__ +=head1 NAME + +Blosxom Plug-in: fix_static_url + +=head1 SYNOPSIS + +This plugin corrects the $blosxom::url variable for static rendering. + +When you use blosxom for rendering static pages, the $url variable refers to your local machine, which is rarely acurate, especially if you intend to upload the static files to a different server... You have to explicitly assign the $url variable in the source of blosxom, or you can use this plugin as an alternative. + +You can assign the $static_url variable in the config section, or use the prefs plugin (the alternative to the config plugin for static rendering) to define +$fix_static_url::static_url. + +=head1 VERSION + +2004-08-22blosxom2 + +=head2 CHANGES + +2004-08-22blosxom2 : First published version + +=head1 AUTHOR + +Barijaona Ramaholimihaso + +=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 COPYRIGHT + +This program is free software; you can redistribute +it and/or modify it under the same terms as Perl itself. + +=cut diff --git a/barijaona/pagetype b/barijaona/pagetype new file mode 100644 index 0000000..4622249 --- /dev/null +++ b/barijaona/pagetype @@ -0,0 +1,79 @@ +# Blosxom plugin: pagetype +# Author(s): Barijaona Ramaholimihaso +# Version: 2006-01-01blosxom2 +# Documentation: see bottom of file or perldoc title + +package pagetype; + +# ------------------ Config variables --------------------- + +use vars qw($pagetype $static); +$pagetype = "" ; + +# --------------------------------------------------------- +sub start { +$static = ($blosxom::static_or_dynamic eq 'static'); +1; } + +sub skip { + + if ($blosxom::path_info_yr ne '' ) + {$pagetype = 'chrono' ; } + elsif ($static && ( $blosxom::path_info =~ m!^(\d{4})!)) + {$pagetype = 'chrono' ; } + elsif (($blosxom::path_info =~ /$blosxom::flavour$/) or (($blosxom::path_info =~ /$blosxom::file_extension$/) && $static)) + {$pagetype = 'story' ; } + elsif ($blosxom::path_info eq "") + {$pagetype = 'main' ; } + else + { $pagetype = 'category';}; + + # let blosxom continue + return undef; +} + + +1; + +__END__ +=head1 NAME + +Blosxom Plug-in: pagetype + +=head1 SYNOPSIS + +The variable $pagetype::pagetype is to be used with interpolate_fancy. + +You can test it in your templates to know what kind of page Blosxom is currently rendering : + +main : the root of the blog +category : a category archive page +chrono : a chronological archive page (per year, per month, per day...) +story : an individual story page + +=head1 VERSION + +2004-08-22blosxom2 + +=head2 CHANGES + +2006-01-01blosxom2 : take into account the corrections of $path_info in recent versions of blosxom.cgi + +2004-08-22blosxom2 : First published version + +=head1 AUTHOR + +Barijaona Ramaholimihaso + +=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 COPYRIGHT + +This program is free software; you can redistribute +it and/or modify it under the same terms as Perl itself. + +=cut diff --git a/barijaona/prefs b/barijaona/prefs new file mode 100644 index 0000000..0bbb313 --- /dev/null +++ b/barijaona/prefs @@ -0,0 +1,141 @@ +# Blosxom Plugin: prefs +# Author(s): Barijaona Ramaholimihaso +# based on config plugin authored by Rael Dornfest +# Version: 2005-11-20 +# Documentation: See the bottom of this file or type: perldoc prefs + +# WARNING: DO NOT PUT PREFERENCE FILES IN WORLD-READABLE PLACES SUCH AS WITHIN +# YOUR DOCUMENT ROOT. IF YOUR $DATADIR IS LOCATED WITHIN YOUR DOCUMENT ROOT, +# I HEARTILY ADVISE THAT YOU MOVE IT. WHILE MOST OF THE CONFIGURATION +# DIRECTIVES ARE INNOCUOUS ENOUGH, IT'S A SLIPPERY SLOPE AND YOU MIGHT WELL +# FIND YOU'VE EXPOSED YOUR STATIC PASSWORD OR INTERNAL DIRECTORY STRUCTURE +# TO ANYONE WITH A WEB BROWSER! + +package prefs; + +# --- Configurable variables ----- +# where are located the preference files + +# I prefer to have mines in my flavour directory +# $basepath = "/Users/barijaon/blosxom/flavours"; + +$basepath = $blosxom::datadir unless defined $basepath ; +# -------------------------------- + +sub start { + 1; +} + +sub head { + +$path='/'; +$path_find = $blosxom::path_info ; +do { + $file = "$basepath$path"."pageprefs"; + if (-r $file) { unless ($return = do $file) { + warn "Couldn't parse $file: $@" if $@; + }} + + + $file .= ".$blosxom::flavour"; + if (-r $file) { unless ($return = do $file) { + warn "Couldn't parse $file: $@" if $@; + }} + } + while ($path_find =~ s#/?([^/]*)##) and $1 and ($path .= $1."/" ); +1; +} + +sub story { + +my ($pkg, $path_find, $filename, $story_ref, $title_ref, $body_ref)= @_; +$path='/'; +do { + $file = "$basepath$path"."storyprefs"; + if (-r $file) { unless ($return = do $file) { + warn "Couldn't parse $file: $@" if $@; + }} + + + $file .= ".$blosxom::flavour"; + if (-r $file) { unless ($return = do $file) { + warn "Couldn't parse $file: $@" if $@; + }} + } + while ($path_find =~ s#/?([^/]*)##) and $1 and ($path .= $1."/" ); +1; +} + +1; + +__END__ + +=head1 NAME + +Blosxom Plug-in: prefs + +=head1 SYNOPSIS + +Override Blosxom's inline configuration settings on a per-directory, per-flavour, and per-directory-per-flavour basis. + +For each generated page, looks for B and B files which should contain valid Perl instructions. + +For each story, looks for B and B files which should contain valid Perl instructions. + +Prefs has a purpose very similar to Rael Dornfest's B plugin, but was written because in static rendering, B uses the same config file for all pages. + +When Blosxom process a page or a story, all prefs files (pageprefs, pageprefs.flavour, storyprefs, storyprefs.flavour) in the directory tree for this page or story are executed. Prefs files for a specific flavour override prefs files applying to all flavours, and prefs files in subdirectories override prefs files in their parents. + +pageprefs are executed once per page (when the head of the page is generated), and storyprefs are executed once per story (allowing a per story tuning inside a page). + +It is recommanded that you prefix the name of the plugin with a number (for instance, naming it 10prefs) so that it loads before other Blosxom plugins (but after the B plugin if you use it). + +=head1 VERSION + +2005-11-20 + +Version number is the date on which this version of the plug-in was created. + +=head1 AUTHOR + +Barijaona Ramaholimihaso + +Prefs is based on the config plugin written by Rael Dornfest , http://www.raelity.org/ + + +=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 or to the Blosxom mailing list +[http://www.yahoogroups.com/group/blosxom]. + +=head1 LICENSE + +Prefs plugin +Copyright 2003-2005, Barijaona Ramaholimihaso + +Blosxom and config Plug-in +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. diff --git a/barijaona/prevnextstory b/barijaona/prevnextstory new file mode 100644 index 0000000..af88516 --- /dev/null +++ b/barijaona/prevnextstory @@ -0,0 +1,168 @@ +# Blosxom Plugin: prevnexstory +# Author(s): Barijaona Ramaholimihaso +# Based on chrono_nav plugin by Victor Ganata +# and tree plug-in by Ryan Schram +# Ideas From: Tatsuhiko Miyagawa +# Version: 2006-01-01blosxom2 +# Documentation: See the bottom of this file or type: perldoc tree + +package prevnextstory; + + +use strict; +use vars qw($prevlink $nextlink $prevtitle $nexttitle $prevdate $nextdate @file_info @dir_info $files_ref @monthname @monthabbr); +# --- Configuration Variables --- + +@monthname = qw/January February March + April May June + July August September + October November December/ if ($#monthname != 11); +@monthabbr = qw/Jan Feb Mar + Apr May Jun + Jul Aug Sep + Oct Nov Dec/ if ($#monthabbr != 11); + +# ------------------------------------------------------------------- + +$prevlink; +$nextlink; +$prevtitle; +$nexttitle; +$prevdate; +$nextdate; +@file_info; +@dir_info; + +sub start { + return 1; +} + +sub skip { + %$files_ref = %blosxom::files; + # Take %files and find all the places blosxom will generate a story page. + @file_info = sort { $files_ref->{$b} <=> $files_ref->{$a} } keys %$files_ref; +0; +} + + + +sub head { + if (($blosxom::path_info =~ /$blosxom::flavour$/) or (($blosxom::path_info =~ /$blosxom::file_extension$/) && ($blosxom::static_or_dynamic eq "static"))) { + # It's an individual story file. + my %path2idx = map { $file_info[$_] => $_ } 0..$#file_info; + + my $key = "$blosxom::datadir/$blosxom::path_info"; + $key =~ s#$blosxom::flavour#$blosxom::file_extension#; + my $index = $path2idx{"$key"}; + if ($index < $#file_info ){ ($prevlink , $prevtitle, $prevdate) = make_link($index + 1) ;} + else {undef $prevlink}; + if ($index > 0 ){ ($nextlink , $nexttitle, $nextdate) = make_link($index - 1) ;} + else {undef $nextlink;}; + + } + elsif (($blosxom::path_info eq "") && ($blosxom::path_info_yr eq "")) { + # it's the blog main page + if ($blosxom::num_entries <= $#file_info ){($prevlink, $prevtitle, $prevdate) = make_link($blosxom::num_entries) ;} + else { undef $prevlink ;}; + + + } + else + {undef $prevlink; + undef $nextlink;}; +1; +} + +sub make_link { + my ($array_index) = @_; + my $file = $file_info[$array_index]; + my($path, $fn) = $file =~ m!^$blosxom::datadir/(?:(.*)/)?(.*)\.$blosxom::file_extension!; + my $title=''; + + my $fh = FileHandle->new(); + if (-f $file && $fh->open("< $file")) { + chomp($title = <$fh>); + $fh->close; + } + $path = $path . ( $path ne "" ? "/" : "") ; + my @date = localtime($files_ref->{$file_info[$array_index]}); + my $mday = $date[3]; + my $month = $date[4]; + my $year = $date[5] + 1900; + + #here we format the date as a text + my $datetext = $mday." ".$monthname[$month]." ".$year ; + return (qq($blosxom::url/$path$fn.$blosxom::flavour), $title, $datetext); +} + + + + +1; + + +__END__ + +=head1 NAME + +Blosxom Plug-in: chrono_nav + +=head1 SYNOPSIS + +Populates the prevnexstory namespace with links for pointing to preceding +and following stories (arranged chronologically). I suggest you use it with interpolate_fancy for testing whether $prevnextstory::prevlink and $prevnextstory::nextlink are defined to avoid spurious links to appear when there is no older or fresher story. + +=head1 INSTALLATION + +Drop this plugin into your plugin directory. Place substitution +variables $prevnextstory::prevlink and $prevnextstory::nextlink in your flavour file as an href value for an anchor element. You can also use $prevnextstory::prevtitle and $prevnextstory::nextlink to get the titles of those stories, and $prevnextstory::prevdate and $prevnextstory::nextdate to get their publication dates. If you need the dates, you will have to adapt the @monthname and @monthabbr lists to your needs, and in some cases modify the formatting performed by the make_list subroutine (default date format is DD/MM/YYYY, with month names in French). + +=head1 VERSION + +2005-02-12blosxom2 + +Version number is the date on which this version of the plug-in was created. + +=head2 CHANGES + +2006-01-01blosxom2 : take into account the corrections of $path_info in recent versions of blosxom.cgi + +2004-08-22blosxom2 : First published version + +=head1 AUTHOR(S) + +Barijaona Ramaholimihaso +Based on chrono_nav plugin by Victor Ganata (, http://blog.fatoprofugus.net ) +which was itself based on tree plugin by Ryan Schram (http://www.rschram.org) +with inspiration and some code techniques used in prevnextentry from Tatsuhiko Miyagawa (http://www.bulknews.net) + +=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 + +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/barijaona/static_file b/barijaona/static_file new file mode 100644 index 0000000..b70ca66 --- /dev/null +++ b/barijaona/static_file @@ -0,0 +1,175 @@ +# Blosxom Plugin: static_file +# Author(s): Barijaona Ramaholimihaso +# original idea by Raffi Krikorian (binary plugin) +# Version: 2004-09-19 +# Documentation: See the bottom of this file or type: perldoc static_file + +package static_file; +use lib qq{$blosxom::plugin_dir/lib}; +use CGI qw/:standard :netscape/; +use File::Copy; +use File::Cat; +use File::Find; +use File::Path; +use FileHandle; +use MIME::Types; + + +# --- Configuration Variables --- + +# You may want to hide from the public some kind of files, +# for instance the files Blosxom renders, generally .txt files. +# Files whose filename extension is in the following list +# will be ignored in dynamic rendering +@exclude_extensions_dynamic = (); + +# Files whose filename extension is in the following list +# will be ignored in static rendering +@exclude_extensions_static = ("$blosxom::file_extension", txt_); + +# This is the MIME type that will be used if nothing else +# can be found. If your server contains mostly text or HTML +# documents, "text/plain" is a good value. If most of your +# content is binary, such as applications or images, you may +# want to use "application/octet-stream" instead to keep browsers +# from trying to display binary files as though they are text. +$default_type="text/plain"; + +# -------------------------------- + +sub start { + 1; +} + +sub skip { + if( $blosxom::static_or_dynamic eq "dynamic" ) { + # if Blosxom is being dynamically generated -- then we have to + # see if the URL requested specifies a file that is on the + # filesystem, then it will return that file with the right + # Content-Type header + if( ( $blosxom::path_info =~ m!^(.*?/?)([^/]*?\.?)([^\.]*?)$! ) && + ( -e "$blosxom::datadir/$1$2$3" ) && (! -d "$blosxom::datadir/$1$2$3" ) ) + { + # access path and name, name and extension of the file + $fileaccess = "$blosxom::datadir/$1$2$3" ; + # adequate file extension ? + if ( grep(/$3/, @exclude_extensions_dynamic) ) {return 0 ;} + my MIME::Types $types = MIME::Types->new; + my MIME::Type $mimetype = $types->mimeTypeOf($blosxom::flavour); + $blosxom::header = + header( { -type=> + ( $mimetype ) ? + $mimetype->mediaType . "/" . $mimetype->subType : + $default_type } ); + my @data = stat( $fileaccess ); + # forge some HTTP header stuff + print("Accept-Ranges: bytes\nContent-Length: $data[7]\n$blosxom::header"); + cat( $fileaccess, \*STDOUT); + # empty what blosxom main script may use + $blosxom::header= ""; + $blosxom::output=''; + # tell blosxom main script to end processing for this file + return 1; + } + return 0 ; + } + return 0; +} + +sub end { + # if we are statically rendering the blog, then we have to copy + # over the entire data tree to the static tree so that it can be + # served out of there + if( $blosxom::static_or_dynamic eq "static" ) { + find( + sub { + if( $File::Find::name =~ + m!^$blosxom::datadir(.*?/?)([^/]*?\.?)([^\.]*?)$! ) { + # do we have to create a directory ? + if ( ( ! -e "$blosxom::static_dir$1$2$3") + && (-d $File::Find::name) ) { + mkpath ("$blosxom::static_dir$1$2$3");} + # is it a file to be updated ? + elsif ( ! grep(/$3/, @exclude_extensions_static) ) { + my @static = stat( "$blosxom::static_dir$1$2$3" ); + my @data = stat( $File::Find::name ); + ( ( ! -e "$blosxom::static_dir$1$2$3" ) || + ( ( ( $static[9] < $data[9] ) || + ( $static[7] != $data[7] ) ) ) ) && + copy( $File::Find::name, + "$blosxom::static_dir$1$2$3" ); + } + } + }, $blosxom::datadir ); + + } + + 1; + +} + + + +1; + +__END__ + +=head1 NAME + +Blosxom Plug-in: static_file + +=head1 SYNOPSIS + +Cause Blosxom to see if the URL requested actually exists on the filesystem. If it does, then return the file, and then exit the script allowing for binary file serves. If the file does not exist, then the Bloxsom script will continue noting whether it needs to do a flavour translation on the data file, etc. + +This allows you to integrate existing webpages to a Blosxom site. + +Another convinience of this is that when you wish to include an image or anything besides just the blog entry, you can place the file in the same directory as your text file, and reference it with a <$url /><$path /> (supposing you are using interpolate_fancy and its ability to interpolate variables in stories). + +=head1 VERSION + +2004-09-19 + +Version number is the date on which this version of the plug-in was created. + +=head1 AUTHOR + +Barijaona Ramaholimihaso + +Original idea by Raffi Krikorian , http://www.bitwaste.com/, author of the binary plugin. + +=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 NOTES + +If you are using this plugin in Blosxom's dynamic mode, you might consider creating a custom B flavour, because Blosxom's default B flavour could be confusing for the user. + +It is recommanded, for performance optimization, to put a number in front of the name of this plugin, for instance to name it B<00static_file>, so that it loads among the first. + +=head1 LICENSE + +static_file Blosxom plugin +Copyright 2003, Barijaona Ramaholimihaso +Copyright 2003, Raffi Krikorian + +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