]> git.wh0rd.org - tt-rss.git/blob - plugins/flattr/init.php
Merge pull request #65 from scarabeusiv/master
[tt-rss.git] / plugins / flattr / init.php
1 <?php
2 class Flattr extends Plugin {
3 private $link;
4 private $host;
5
6 function init($host) {
7 $this->link = $host->get_link();
8 $this->host = $host;
9
10 $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
11 }
12
13 function about() {
14 return array(1.1,
15 "Share articles on Flattr (if they exist in their catalogue)",
16 "F. Eitel, N. Honing");
17 }
18
19 function hook_article_button($line) {
20
21 $rv = "";
22 $article_link = $line['link'];
23
24 if ($article_link) {
25 $encoded = urlencode($article_link);
26 $r = file_get_contents("https://api.flattr.com/rest/v2/things/lookup/?url=$encoded");
27 $response = json_decode($r, true);
28 $image = "<img src=\"plugins/flattr/flattr.png\"
29 class='tagsPic' style=\"cursor : pointer\"
30 title='".__('Flattr this article.')."'>";
31 // if Flattr has it in the catalogue, we display the button
32 if ($response and array_key_exists('link', $response)) {
33 $rv = "<a id='flattr' target='_blank' href='" . $response['link'] . "'> . $image . </a>";
34 } else {
35 // We can't submit a thing to the catalogue without giving a Flattr user id (who would be the owner)
36 // see http://developers.flattr.net/auto-submit
37 //$rv = "<a id='flattr' href='https://flattr.com/submit/auto?url=" . $encoded . "'>" . $image . "</a>";
38 $rv = '';
39 // Another useful thing would be any rel=payment link (which would have the user id as well),
40 // but tt-rss is not checking that (yet), I believe. See http://developers.flattr.net/feed
41 }
42 }
43 return $rv;
44 }
45 }
46 ?>