# -*-Perl-*- ####################################################################### ### $Id: mt-isbn-0.01.txt,v 1.4 2003/12/03 09:53:08 mate Exp $ ### ### MTISBN (mt-isbn.pl) ### A Plugin for Movable Type ### ### by Yutaka/@smate.NET ### http://www.asmate.net/software/perl/mt-isbn/ ### package MT::Plugin::ISBN; use strict; use MT::Template::Context; use vars qw($VERSION); my $VERSION = '0.01'; # # In the Templates, "Main Index", "Category Archive", # "Individual Entry Archive", "Date-Based Archive" and so on: # # <$MTEntryBody isbn="1"$> # # And you can write "ISBN:4-8443-1812-8" or "ISBN:4844318128" # in an Entry. # # # SET LINK HTML # my $ISBN_HTML =<<'__EOF__';
[ ISBN:$isbn: bk1 - jbook - amazon ]
__EOF__ # ####################################################################### MT::Template::Context->add_global_filter(isbn => sub { my ($str, $onoff, $ctx) = @_; $str =~ s/ISBN:\s*([-\w]+)/to_html($1)/ge if $onoff && $str =~ /ISBN:\s*[-\w]+/; return $str; }); sub to_html { my $isbn = shift; my $html = $ISBN_HTML; $html =~ s/\$isbn/$isbn/g if $html =~ /\$isbn/; $isbn =~ tr/-//d if $isbn =~ /\-/; $html =~ s/\$no/$isbn/g if $html =~ /\$no/; return $html; } 1; __END__ ### Local Variables: ### mode: perl ### End: