2 package IkiWiki::Plugin::flattr;
9 hook(type => "getsetup", id => "flattr", call => \&getsetup);
10 hook(type => "preprocess", id => "flattr", call => \&preprocess);
11 hook(type => "format", id => "flattr", call => \&format);
23 description => "userid or user name to use by default for Flattr buttons",
35 $flattr_pages{$params{destpage}}=1;
39 $url=urlto($params{page}, "", 1);
43 foreach my $field (qw{language uid button hidden category tags}) {
44 if (exists $params{$field}) {
45 push @fields, "$field:$params{$field}";
49 return '<a class="FlattrButton" href="'.$url.'"'.
50 (exists $params{title} ? ' title="'.$params{title}.'"' : '').
51 ' rev="flattr;'.join(';', @fields).';"'.
53 (exists $params{description} ? $params{description} : '').
60 # Add flattr's javascript to pages with flattr buttons.
61 if ($flattr_pages{$params{page}}) {
62 if (! ($params{content}=~s!^(<body[^>]*>)!$1.flattrjs()!em)) {
63 # no <body> tag, probably in preview mode
64 $params{content}=flattrjs().$params{content};
67 return $params{content};
72 return $js_cached if defined $js_cached;
74 my $js_url='https://api.flattr.com/js/0.5.0/load.js?mode=auto';
75 if (defined $config{flattr_userid}) {
76 my $userid=$config{flattr_userid};
77 $userid=~s/[^-A-Za-z0-9_]//g; # sanitize for inclusion in javascript
78 $js_url.="&uid=$userid";
81 # This is Flattr's standard javascript snippet to include their
82 # external javascript file, asynchronously.
83 return $js_cached=<<"EOF";
84 <script type="text/javascript">
85 <!--//--><![CDATA[//><!--
87 var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
88 s.type = 'text/javascript';
91 t.parentNode.insertBefore(s, t);