]>
Commit | Line | Data |
---|---|---|
3f363052 AD |
1 | <?php\r |
2 | class Feeds extends Handler {\r | |
3 | \r | |
4 | function catchupAll() {\r | |
5 | db_query($this->link, "UPDATE ttrss_user_entries SET\r | |
6 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);\r | |
7 | ccache_zero_all($this->link, $_SESSION["uid"]);\r | |
8 | } \r | |
9 | \r | |
10 | function collapse() {\r | |
11 | $cat_id = db_escape_string($_REQUEST["cid"]);\r | |
12 | $mode = (int) db_escape_string($_REQUEST['mode']);\r | |
13 | toggle_collapse_cat($this->link, $cat_id, $mode);\r | |
14 | }\r | |
15 | \r | |
16 | function index() {\r | |
17 | $root = (bool)$_REQUEST["root"];\r | |
18 | \r | |
19 | if (!$root) {\r | |
20 | print json_encode(outputFeedList($this->link));\r | |
21 | } else {\r | |
22 | \r | |
23 | $feeds = outputFeedList($this->link, false);\r | |
24 | \r | |
25 | $root = array();\r | |
26 | $root['id'] = 'root';\r | |
27 | $root['name'] = __('Feeds');\r | |
28 | $root['items'] = $feeds['items'];\r | |
29 | \r | |
30 | $fl = array();\r | |
31 | $fl['identifier'] = 'id';\r | |
32 | $fl['label'] = 'name';\r | |
33 | $fl['items'] = array($root);\r | |
34 | \r | |
35 | print json_encode($fl);\r | |
36 | }\r | |
37 | } \r | |
38 | \r | |
39 | function view() {\r | |
40 | $timing_info = getmicrotime();\r | |
41 | \r | |
42 | $reply = array();\r | |
43 | \r | |
44 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);\r | |
45 | \r | |
46 | $omode = db_escape_string($_REQUEST["omode"]);\r | |
47 | \r | |
48 | $feed = db_escape_string($_REQUEST["feed"]);\r | |
49 | $method = db_escape_string($_REQUEST["m"]);\r | |
50 | $view_mode = db_escape_string($_REQUEST["view_mode"]);\r | |
51 | $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");\r | |
52 | @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";\r | |
53 | @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);\r | |
54 | @$offset = db_escape_string($_REQUEST["skip"]);\r | |
55 | @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);\r | |
56 | $order_by = db_escape_string($_REQUEST["order_by"]);\r | |
57 | \r | |
58 | if (is_numeric($feed)) $feed = (int) $feed;\r | |
59 | \r | |
60 | /* Feed -5 is a special case: it is used to display auxiliary information\r | |
61 | * when there's nothing to load - e.g. no stuff in fresh feed */\r | |
62 | \r | |
63 | if ($feed == -5) {\r | |
64 | print json_encode(generate_dashboard_feed($this->link));\r | |
65 | return;\r | |
66 | }\r | |
67 | \r | |
68 | $result = false;\r | |
69 | \r | |
70 | if ($feed < -10) {\r | |
71 | $label_feed = -11-$feed;\r | |
72 | $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE\r | |
73 | id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);\r | |
74 | } else if (!$cat_view && is_numeric($feed) && $feed > 0) {\r | |
75 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE\r | |
76 | id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r | |
77 | } else if ($cat_view && is_numeric($feed) && $feed > 0) {\r | |
78 | $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE\r | |
79 | id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r | |
80 | }\r | |
81 | \r | |
82 | if ($result && db_num_rows($result) == 0) {\r | |
83 | print json_encode(generate_error_feed($this->link, __("Feed not found.")));\r | |
84 | return;\r | |
85 | }\r | |
86 | \r | |
87 | /* Updating a label ccache means recalculating all of the caches\r | |
88 | * so for performance reasons we don't do that here */\r | |
89 | \r | |
90 | if ($feed >= 0) {\r | |
91 | ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);\r | |
92 | }\r | |
93 | \r | |
94 | set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);\r | |
95 | set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);\r | |
96 | set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);\r | |
97 | \r | |
98 | if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {\r | |
99 | db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()\r | |
100 | WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);\r | |
101 | }\r | |
102 | \r | |
103 | $reply['headlines'] = array();\r | |
104 | \r | |
105 | if (!$next_unread_feed)\r | |
106 | $reply['headlines']['id'] = $feed;\r | |
107 | else\r | |
108 | $reply['headlines']['id'] = $next_unread_feed;\r | |
109 | \r | |
110 | $reply['headlines']['is_cat'] = (bool) $cat_view;\r | |
111 | \r | |
112 | $override_order = false;\r | |
113 | \r | |
114 | if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {\r | |
115 | $date_sort_field = "updated";\r | |
116 | } else {\r | |
117 | $date_sort_field = "date_entered";\r | |
118 | }\r | |
119 | \r | |
120 | switch ($order_by) {\r | |
121 | case "date":\r | |
122 | if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r | |
123 | $override_order = "$date_sort_field";\r | |
124 | } else {\r | |
125 | $override_order = "$date_sort_field DESC";\r | |
126 | }\r | |
127 | break;\r | |
128 | \r | |
129 | case "title":\r | |
130 | if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r | |
131 | $override_order = "title DESC, $date_sort_field";\r | |
132 | } else {\r | |
133 | $override_order = "title, $date_sort_field DESC";\r | |
134 | }\r | |
135 | break;\r | |
136 | \r | |
137 | case "score":\r | |
138 | if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r | |
139 | $override_order = "score, $date_sort_field";\r | |
140 | } else {\r | |
141 | $override_order = "score DESC, $date_sort_field DESC";\r | |
142 | }\r | |
143 | break;\r | |
144 | }\r | |
145 | \r | |
146 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);\r | |
147 | \r | |
148 | $ret = format_headlines_list($this->link, $feed, $method,\r | |
149 | $view_mode, $limit, $cat_view, $next_unread_feed, $offset,\r | |
150 | $vgroup_last_feed, $override_order);\r | |
151 | \r | |
152 | $topmost_article_ids = $ret[0];\r | |
153 | $headlines_count = $ret[1];\r | |
154 | $returned_feed = $ret[2];\r | |
155 | $disable_cache = $ret[3];\r | |
156 | $vgroup_last_feed = $ret[4];\r | |
157 | \r | |
158 | $reply['headlines']['content'] =& $ret[5]['content'];\r | |
159 | $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];\r | |
160 | \r | |
161 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);\r | |
162 | \r | |
163 | $reply['headlines-info'] = array("count" => (int) $headlines_count,\r | |
164 | "vgroup_last_feed" => $vgroup_last_feed,\r | |
165 | "disable_cache" => (bool) $disable_cache);\r | |
166 | \r | |
167 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);\r | |
168 | \r | |
169 | if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {\r | |
170 | $articles = array();\r | |
171 | \r | |
172 | foreach ($topmost_article_ids as $id) {\r | |
173 | array_push($articles, format_article($this->link, $id, false));\r | |
174 | }\r | |
175 | \r | |
176 | $reply['articles'] = $articles;\r | |
177 | }\r | |
178 | \r | |
179 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);\r | |
180 | \r | |
181 | $reply['runtime-info'] = make_runtime_info($this->link);\r | |
182 | \r | |
183 | print json_encode($reply);\r | |
184 | \r | |
185 | }\r | |
186 | }\r | |
187 | ?> |