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