# Album Plugin:	social/flattr
# For info:	'album -plugin_info social/flattr'
# For usage:	'album -plugin_usage social/flattr'

use strict;

my $DESCRIPTION = << 'DESCRIPTION';
Plugin: social/flattr

Adds flattr tags to the <head> section of album pages
and a flattr-Button below your picture.
For details on flattr see:  http://flattr.com

You need to specify your flattr-URL.
The flattr-URL can be found embedded in the HTML-code that
flattr gives you, probably on a line that looks like this:

	<a class="FlattrButton" style="display:none;" rev="flattr;button:compact;" href="http://this.is.my-flattr.url"></a>

It's the href-part inside the <a> tag. Probably it is the url of your site!

Flattr may update/change their code, in which case this plugin
will no longer work without being updated!  If you find that the
code this plugin generates is out-of-date, make sure you have the
most current version of album and it's plugins from:

  http://MarginalHacks.com/

And if so, please contact us and let us know!

  Volker Sauer
  http://www.volker-sauer.de/

DESCRIPTION

sub start_plugin {
	my ($opt) = @_;

	# Setup the options
	album::add_option(1, 'url', album::OPTION_STR,
		usage=>"The flattr-url \n\n".$DESCRIPTION);

	# Setup the hooks
	album::hook($opt, 'do_album', \&setup_head);
	album::hook($opt, 'modify_caption', \&insert_button);

	return {
		author => 'Volker Sauer',
		href => 'http://www.volker-sauer.de/',
		version => '1.0',
		description => $DESCRIPTION,
	};
}

sub setup_head {
	my ($opt,$data, undef,  $dir, $album) = @_;
	my $url = album::option($opt, 'url');

	album::usage($opt,"Plugin flattr needs you to specify:\n  -flattr:url")
		unless $url;

	# Add it to the head
	$data->{head} .= <<FLATTR;
	<!-- code for flattr -->
	<script type="text/javascript">
	/* <![CDATA[ */
	    (function() {
	        var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
	        s.type = 'text/javascript';
	        s.async = true;
	        s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
	        t.parentNode.insertBefore(s, t);
	    })();
	/* ]]> */
	</script>
	<!-- end code for flattr -->
FLATTR
	return 0;
}

sub insert_button {
	my ($opt,$data, undef,  $cap, $dir, $pic) = @_;
	my $url = album::option($opt, 'url');
	return "$cap<br /><a class='FlattrButton' style='display:none;' rev='flattr;button:compact;' href='$url'></a>" ;
}

# Plugins always end with:
1;
