# Album Plugin: captions/paypal/simple # For info: 'album -plugin_info captions/paypal/simple' # For usage: 'album -plugin_usage captions/paypal/simple' use strict; sub start_plugin { my ($opt,$plugin,$path) = @_; # Setup my hooks album::hook($opt,'modify_caption',\&modify_caption); album::add_option(1,'paypal_email',$album::OPTION_STR, usage=>"Your paypal email address"); album::add_option(1,'paypal_price',$album::OPTION_STR, usage=>"Price of images"); return { author => 'David Ljung Madison', href => 'http://MarginalHacks.com/', version => '1.0', description => "Paypal linker. Adds simple paypal links to each image. You need to set the email with the -paypal_email option. You can also set a default price with the -paypal_price option, or else specify a price in the beginning of each caption, such as: sunset.jpg Beautiful Sunset $21.50 Here is the caption ", }; } sub modify_caption { my ($opt, $data, $hookname, $dir, $pic, $cap) = @_; # Make sure we have the options album::fatal($opt,"Need to specify paypal email address with -paypal_email") unless $opt->{paypal_email}; # Figure out the price my $price = $opt->{paypal_price}; $price = $1 if $cap =~ s/^\s*\$(\d+(\.\d+)?)(\s+|$)//; return $cap unless $price; # Item number (don't know how paypal uses this.. my $num = ($pic =~ /(\d+)/) ? $1 : 1; # Do we need to ensure regen of the HTML? album::new_html($opt,$data,$pic) if album::option_changed($opt,'paypal_price'); # The new caption with the paypal button $cap . < PAYPAL } # Plugins always end with: 1;