init.php 2.7 KB

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