#!/usr/bin/perl # -*- perl -*- # Blosxom Plugin: valog # Author: Brian St. Pierre # Download: http://bstpierre.org/Projects/valog # Version: 1.0 # License: MIT style # Purpose: Treats stock-related posts specially. # See bottom for documentaiton. package valog; #use FileHandle; #use File::Find; #use File::stat; use File::Basename; # --- Configurable variables ----- # Create your valog data dir and point to its full path location. # This is relative to your blosxom root. # # If you do not want these posts to appear under your regular blosxom # blog, use the hide plugin: # http://fletcher.freeshell.org/computers/web/blosxom/hide/hide.html # my $valog_dir = "/stocks"; # Where should quote links be directed? %s will be replaced with the # ticker. my $quote_url = "http://finance.yahoo.com/q?s=%s"; my $quote_title = "Stock quote for %s"; # -------------------------------- my $package = 'valog'; $quote_link; ##use vars qw! !; sub start { 1; } sub buildLink { my ($ticker) = @_; my ($url, $title, $new_tag); $url = sprintf($quote_url, $ticker); $title = sprintf($quote_title, $ticker); $new_tag = sprintf("%s", $url, $title, $ticker); return $new_tag; } sub rewriteQuote { my ($ticker) = @_; $ticker =~ s%stock:(.+)%$1%es; return buildLink($ticker); } # 1) Fill in the $valog::quote_link variable. # # 2) Modify the body of stories by rewriting tags to real # URLs. # sub story { my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; if(index($path, $valog_dir) == 0) { # Fill in $valog::quote_link. my ($dirName, $dirPath, $suffix) = fileparse($path); # Must make sure that this is in a TICKER directory. if ($dirName =~ /[A-Z]+/) { $quote_link = buildLink($dirName); # Rewrite the title. $$title_ref =~ s/$dirName/$quote_link/; } else { $quote_link = ""; } # Rewrite any tag in the post body $$body_ref =~ s/<(stock:[^>]+)>/rewriteQuote($1)/ges; } 1; } 1; =head1 NAME Blosxom Plug-in: valog =head1 SYNOPSIS This plugin (valog == "value" + "log") treats a tree of your blosxom weblog as stock commentary. =head1 VERSION 1.0 =head1 AUTHOR Brian St. Pierre , http://bstpierre.org/ =head1 BUGS None known; address bug reports and comments to me. =head1 INSTALLATION This plugin (valog == "value" + "log") treats a tree of your blosxom weblog as stock commentary. The tree must be set up as follows: blosxom-data-root ... valog-root ## Must appear under blosxom root. TICKER1 posts about TICKER1 TICKER2 posts about TICKER2 Note that all ticker symbols must be in all-caps. To include non-stock directories in this hierarchy, simply use lowercase and they will be ignored. For posts under a TICKER directory, the $valog::quote_link variable is populated with a link to a stock quote. =head1 stock: tags Valog also supports a shortcut URL notation. The following link: will be transformed into: QQQQ (Assuming your quote provider is set to Yahoo -- the default.) This shortcut functionality is heavily borrowed from Nelson Minar's ASIN plugin: http://www.nelson.monkey.org/~nelson/weblog/ This plugin does not support flavors. =head1 Title Rewriting If the title of a post contains the ticker in all caps, it is made into a link to a quote. =head1 Customization =head2 Configuration variables C<$valog_dir> is the directory tree in which to look for TICKER subdirectories. C<$quote_url> is a template used to build URLs for stock quotes. =head1 TODO * fetch (cached) quotes automatically and populate a $valog:: variable with information. * read data files (.valog) in each stock's dir -- maybe for info like recommended list/buy/sell/etc? =head1 LICENSE (This is an "MIT-style" license.) Copyright (c) 2004, Brian St. Pierre Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies. IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.