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