flattr.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class Flattr extends Plugin {
  3. private $link;
  4. private $host;
  5. function init($host) {
  6. $this->link = $host->get_link();
  7. $this->host = $host;
  8. $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
  9. }
  10. function about() {
  11. return array(1.0,
  12. "Share articles on Flattr",
  13. "Nic Honing");
  14. }
  15. function hook_article_button($line) {
  16. $article_id = $line["id"];
  17. $result = db_query($this->link, "SELECT link
  18. FROM ttrss_entries, ttrss_user_entries
  19. WHERE id = '$article_id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']);
  20. if (db_num_rows($result) != 0) {
  21. $article_link = db_fetch_result($result, 0, 'link');
  22. }
  23. $response = null;
  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. }
  29. $rv = null;
  30. if ($response and array_key_exists('link', $response)) {
  31. $rv = "<a id='flattr' href='" . $response['link'] . "'>
  32. <img src=\"".theme_image($this->link, 'plugins/flattr/flattr.png')."\"
  33. class='tagsPic' style=\"cursor : pointer\"
  34. title='".__('Flattr article')."'>
  35. </a>";
  36. } else {
  37. $rv = "";
  38. }
  39. return $rv;
  40. }
  41. }
  42. ?>