c917ed46a675d1383b2831dc64777bc3b5d3ac2b
3 # This plugin allows your page templates to include Flattr buttons, so
4 # Flattr buttons are automatically added on every page that uses the template.
5 # If you don't specify a thing ID with the flattrthing directive, it adds
6 # auto-submit buttons so things are created when the button is clicked the first
9 # The plugin is customizable through the following configuration options:
10 # - flattrthing_pagespec: allows you to specify a pagespec on which pages the
11 # plugin is active. If empty, no Flattr buttons are generated at all.
12 # - flattrthing_defaultuser: sets the default user that owns the Flattr things
13 # which are created by the auto-submit buttons.
15 # Also, the plugin adds the flattrthing directive, which allows you to customize
16 # the behaviour for one page. It knows the following parameters:
17 # - id: the Flattr thing ID (like in http://flattr.com/thing/12341234). If you
18 # specify this option, a button with a thing URL is generated instead of an
19 # auto-submit button. This allows you to link to things which already exist
20 # by the time you create your page.
21 # - user: a Flattr username that owns the thing created by the generated
22 # auto-submit button. This parameter has no effect when an ID is specified,
23 # since in this case, the owner is already known to Flattr.
25 # This plugin sets the following template variables which your templates should
26 # process and generate the according buttons with the right URLs:
27 # - FLATTR_ENABLE: contains a truthful value if the page matches the pagespec
28 # configured with flattrthing_pagespec. You can use it with TMPL_IF to
29 # generate code specific to pages which have a Flattr button.
30 # - FLATTR_THING_ID: if a thing ID was specified with the flattrthing directive,
31 # this variable contains the ID that was given in the directive.
32 # - FLATTR_THING_ID_SET: contains a thurthful value if FLATTR_THING_ID is set.
33 # - FLATTR_USER: contains the username that was specified with the flattrthing
34 # directive, or if that was not the case, the username that was configured
35 # with flattrthing_defaultuser in your setup file.
36 # - FLATTR_THING_URL: contains the full URL to the page.
38 package IkiWiki
::Plugin
::flattrthing
;
45 hook
(type
=> "getsetup", id
=> "flattrthing", call
=> \
&getsetup
);
46 hook
(type
=> "scan", id
=> "flattrthing", call
=> \
&scan
);
47 hook
(type
=> "preprocess", id
=> "flattrthing", call
=> \
&preprocess
);
48 hook
(type
=> "pagetemplate", id
=> "flattrthing", call
=> \
&pagetemplate
);
58 flattrthing_pagespec
=> {
60 example
=> "!*/Discussion",
61 description
=> "Pages on which flattr button should be inserted. If empty, flattr buttons are not shown on any page.",
62 link => "ikiwiki/PageSpec",
66 flattrthing_defaultuser
=> {
68 example
=> "!*/Discussion",
69 description
=> "Default flattr user that owns a thing if the username is not changed with the flattrthing directive",
77 my $page = $params{page
};
78 my $destpage = $params{destpage
};
79 my $baseurl = $config{url
};
80 $baseurl .= "/" unless substr($baseurl, -1) eq "/";
82 $baseurl .= $destpage;
86 $pagestate{$page}{flattrthing
}{url
} = $baseurl;
88 if(exists $config{flattrthing_defaultuser
} &&
89 length $config{flattrthing_defaultuser
}) {
90 $pagestate{$page}{flattrthing
}{user
} = $config{flattrthing_defaultuser
};
92 return error
("Please set flattrthing_defaultuser in configuration!");
100 return error
("flattrthing: please specify id or user") unless ($params{id
}
103 my $page = $params{page
};
104 $pagestate{$page}{flattrthing
}{id
} = int($params{id
}) if $params{id
};
105 $pagestate{$page}{flattrthing
}{user
} = int($params{user
}) if $params{user
};
112 my $page = $params{page
};
113 my $template = $params{template
};
115 if(exists $config{flattrthing_pagespec
} &&
116 length $config{flattrthing_pagespec
} &&
117 exists $pagestate{$page}{flattrthing
}{user
} &&
118 length $pagestate{$page}{flattrthing
}{user
} &&
119 pagespec_match
($params{page
}, $config{flattrthing_pagespec
})) {
120 $template->param(FLATTR_ENABLED
=> 1);
122 FLATTR_THING_URL
=> $pagestate{$page}{flattrthing
}{url
},
123 FLATTR_USER
=> $pagestate{$page}{flattrthing
}{user
},
126 if(exists $pagestate{$page}{flattrthing
}{id
}) {
128 FLATTR_THING_ID_SET
=> 1,
129 FLATTR_THING_ID
=> $pagestate{$page}{flattrthing
}{id
},
This page took 0.053412 seconds and 3 git commands to generate.