]> git.wh0rd.org - tt-rss.git/blob - plugins/flattr/flattr.php
add -list-plugins option; about sections to plugins
[tt-rss.git] / plugins / flattr / flattr.php
1 <?php
2 class Flattr extends Plugin {
3 private $link;
4 private $host;
5
6 function __construct($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.0,
15 "Share on Flattr plugin",
16 "Nic Honing");
17 }
18
19 function hook_article_button($line) {
20
21 $article_id = $line["id"];
22
23 $result = db_query($this->link, "SELECT link
24 FROM ttrss_entries, ttrss_user_entries
25 WHERE id = '$article_id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']);
26
27 if (db_num_rows($result) != 0) {
28 $article_link = db_fetch_result($result, 0, 'link');
29 }
30
31 $response = null;
32 if ($article_link) {
33 $encoded = urlencode($article_link);
34 $r = file_get_contents("https://api.flattr.com/rest/v2/things/lookup/?url=$encoded");
35 $response = json_decode($r, true);
36 }
37
38 $rv = null;
39 if ($response and array_key_exists('link', $response)) {
40 $rv = "<a id='flattr' href='" . $response['link'] . "'>
41 <img src=\"".theme_image($this->link, 'plugins/flattr/flattr.png')."\"
42 class='tagsPic' style=\"cursor : pointer\"
43 title='".__('Flattr article')."'>
44 </a>";
45 } else {
46 $rv = "";
47 }
48
49 return $rv;
50 }
51 }
52 ?>