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