digest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. class Digest extends Plugin implements IHandler {
  3. private $link;
  4. private $host;
  5. function about() {
  6. return array(1.0,
  7. "Digest mode for tt-rss (tablet friendly UI)",
  8. "fox",
  9. true);
  10. }
  11. function init($host) {
  12. $this->link = $host->get_link();
  13. $this->host = $host;
  14. $host->add_handler("digest", "*", $this);
  15. }
  16. function index() {
  17. header("Content-type: text/html; charset=utf-8");
  18. login_sequence($this->link);
  19. global $link;
  20. $link = $this->link;
  21. require_once dirname(__FILE__) . "/digest_body.php";
  22. }
  23. /* function get_js() {
  24. return file_get_contents(dirname(__FILE__) . "/digest.js");
  25. } */
  26. function csrf_ignore($method) {
  27. return in_array($method, array("index"));
  28. }
  29. function before($method) {
  30. return true;
  31. }
  32. function after() {
  33. }
  34. function digestgetcontents() {
  35. $article_id = db_escape_string($_REQUEST['article_id']);
  36. $result = db_query($this->link, "SELECT content,title,link,marked,published
  37. FROM ttrss_entries, ttrss_user_entries
  38. WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
  39. $content = sanitize($this->link, db_fetch_result($result, 0, "content"));
  40. $title = strip_tags(db_fetch_result($result, 0, "title"));
  41. $article_url = htmlspecialchars(db_fetch_result($result, 0, "link"));
  42. $marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked"));
  43. $published = sql_bool_to_bool(db_fetch_result($result, 0, "published"));
  44. print json_encode(array("article" =>
  45. array("id" => $article_id, "url" => $article_url,
  46. "tags" => get_article_tags($this->link, $article_id),
  47. "marked" => $marked, "published" => $published,
  48. "title" => $title, "content" => $content)));
  49. }
  50. function digestupdate() {
  51. $feed_id = db_escape_string($_REQUEST['feed_id']);
  52. $offset = db_escape_string($_REQUEST['offset']);
  53. $seq = db_escape_string($_REQUEST['seq']);
  54. if (!$feed_id) $feed_id = -4;
  55. if (!$offset) $offset = 0;
  56. $reply = array();
  57. $reply['seq'] = $seq;
  58. $headlines = api_get_headlines($this->link, $feed_id, 30, $offset,
  59. '', ($feed_id == -4), true, false, "unread", "updated DESC", 0, 0);
  60. $reply['headlines'] = array();
  61. $reply['headlines']['title'] = getFeedTitle($this->link, $feed_id);
  62. $reply['headlines']['content'] = $headlines;
  63. print json_encode($reply);
  64. }
  65. function digestinit() {
  66. $tmp_feeds = api_get_feeds($this->link, -4, true, false, 0);
  67. $feeds = array();
  68. foreach ($tmp_feeds as $f) {
  69. if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
  70. }
  71. print json_encode(array("feeds" => $feeds));
  72. }
  73. }
  74. ?>