]>
Commit | Line | Data |
---|---|---|
afcfe6ca | 1 | <?php |
369dbc19 | 2 | class Pref_Feeds extends Handler_Protected { |
df659891 AD |
3 | public static $feed_languages = array("English", "Danish", "Dutch", "Finnish", "French", "German", "Hungarian", "Italian", "Norwegian", |
4 | "Portuguese", "Russian", "Spanish", "Swedish", "Turkish", "Simple"); | |
8484ce22 AD |
5 | |
6 | function csrf_ignore($method) { | |
f6cd767b | 7 | $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed", |
201bb1ca AD |
8 | "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds", |
9 | "batchsubscribe"); | |
8484ce22 AD |
10 | |
11 | return array_search($method, $csrf_ignored) !== false; | |
12 | } | |
13 | ||
afcfe6ca AD |
14 | function batch_edit_cbox($elem, $label = false) { |
15 | print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" | |
16 | onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">"; | |
17 | } | |
18 | ||
19 | function renamecat() { | |
d9c85e0f AD |
20 | $title = $this->dbh->escape_string($_REQUEST['title']); |
21 | $id = $this->dbh->escape_string($_REQUEST['id']); | |
afcfe6ca AD |
22 | |
23 | if ($title) { | |
d9c85e0f | 24 | $this->dbh->query("UPDATE ttrss_feed_categories SET |
afcfe6ca AD |
25 | title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); |
26 | } | |
27 | return; | |
28 | } | |
29 | ||
2a060a94 | 30 | private function get_category_items($cat_id) { |
6e0ee833 AD |
31 | |
32 | if ($_REQUEST['mode'] != 2) | |
33 | $search = $_SESSION["prefs_feed_search"]; | |
34 | else | |
35 | $search = ""; | |
17c755f0 | 36 | |
9def5540 | 37 | if ($search) $search_qpart = " AND (LOWER(title) LIKE LOWER('%$search%') OR LOWER(feed_url) LIKE LOWER('%$search%'))"; |
17c755f0 | 38 | |
66ca7c30 AD |
39 | // first one is set by API |
40 | $show_empty_cats = $_REQUEST['force_show_empty'] || | |
e5e6cde0 | 41 | ($_REQUEST['mode'] != 2 && !$search); |
2a060a94 AD |
42 | |
43 | $items = array(); | |
44 | ||
d9c85e0f | 45 | $result = $this->dbh->query("SELECT id, title FROM ttrss_feed_categories |
2a060a94 AD |
46 | WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title"); |
47 | ||
d9c85e0f | 48 | while ($line = $this->dbh->fetch_assoc($result)) { |
2a060a94 AD |
49 | |
50 | $cat = array(); | |
51 | $cat['id'] = 'CAT:' . $line['id']; | |
2ecd2df5 | 52 | $cat['bare_id'] = (int)$line['id']; |
2a060a94 AD |
53 | $cat['name'] = $line['title']; |
54 | $cat['items'] = array(); | |
55 | $cat['checkbox'] = false; | |
56 | $cat['type'] = 'category'; | |
2ecd2df5 | 57 | $cat['unread'] = 0; |
2c5f231e | 58 | $cat['child_unread'] = 0; |
c594eca0 | 59 | $cat['auxcounter'] = 0; |
d922b09c | 60 | $cat['parent_id'] = $cat_id; |
2a060a94 AD |
61 | |
62 | $cat['items'] = $this->get_category_items($line['id']); | |
63 | ||
496195db | 64 | $num_children = $this->calculate_children_count($cat); |
967f0619 | 65 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
2a060a94 | 66 | |
496195db | 67 | if ($num_children > 0 || $show_empty_cats) |
2a060a94 AD |
68 | array_push($items, $cat); |
69 | ||
70 | } | |
71 | ||
d9c85e0f | 72 | $feed_result = $this->dbh->query("SELECT id, title, last_error, |
2a060a94 AD |
73 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
74 | FROM ttrss_feeds | |
75 | WHERE cat_id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]. | |
76 | "$search_qpart ORDER BY order_id, title"); | |
77 | ||
d9c85e0f | 78 | while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { |
2a060a94 AD |
79 | $feed = array(); |
80 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 81 | $feed['bare_id'] = (int)$feed_line['id']; |
c594eca0 | 82 | $feed['auxcounter'] = 0; |
2a060a94 AD |
83 | $feed['name'] = $feed_line['title']; |
84 | $feed['checkbox'] = false; | |
2ecd2df5 | 85 | $feed['unread'] = 0; |
2a060a94 | 86 | $feed['error'] = $feed_line['last_error']; |
86a8351c | 87 | $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
6322ac79 | 88 | $feed['param'] = make_local_datetime( |
2a060a94 AD |
89 | $feed_line['last_updated'], true); |
90 | ||
91 | array_push($items, $feed); | |
92 | } | |
93 | ||
94 | return $items; | |
95 | } | |
96 | ||
afcfe6ca | 97 | function getfeedtree() { |
0bb5833b AD |
98 | print json_encode($this->makefeedtree()); |
99 | } | |
100 | ||
101 | function makefeedtree() { | |
afcfe6ca | 102 | |
6e0ee833 AD |
103 | if ($_REQUEST['mode'] != 2) |
104 | $search = $_SESSION["prefs_feed_search"]; | |
105 | else | |
106 | $search = ""; | |
afcfe6ca AD |
107 | |
108 | if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')"; | |
109 | ||
110 | $root = array(); | |
111 | $root['id'] = 'root'; | |
112 | $root['name'] = __('Feeds'); | |
113 | $root['items'] = array(); | |
114 | $root['type'] = 'category'; | |
115 | ||
a42c55f0 | 116 | $enable_cats = get_pref('ENABLE_FEED_CATS'); |
2ecd2df5 AD |
117 | |
118 | if ($_REQUEST['mode'] == 2) { | |
119 | ||
120 | if ($enable_cats) { | |
88918ca6 | 121 | $cat = $this->feedlist_init_cat(-1); |
2ecd2df5 AD |
122 | } else { |
123 | $cat['items'] = array(); | |
124 | } | |
125 | ||
5417fbd7 | 126 | foreach (array(-4, -3, -1, -2, 0, -6) as $i) { |
2ecd2df5 AD |
127 | array_push($cat['items'], $this->feedlist_init_feed($i)); |
128 | } | |
129 | ||
a413f53e AD |
130 | /* Plugin feeds for -1 */ |
131 | ||
1ffe3391 | 132 | $feeds = PluginHost::getInstance()->get_feeds(-1); |
a413f53e AD |
133 | |
134 | if ($feeds) { | |
135 | foreach ($feeds as $feed) { | |
136 | $feed_id = PluginHost::pfeed_to_feed_id($feed['id']); | |
137 | ||
138 | $item = array(); | |
139 | $item['id'] = 'FEED:' . $feed_id; | |
140 | $item['bare_id'] = (int)$feed_id; | |
c594eca0 | 141 | $item['auxcounter'] = 0; |
a413f53e AD |
142 | $item['name'] = $feed['title']; |
143 | $item['checkbox'] = false; | |
144 | $item['error'] = ''; | |
145 | $item['icon'] = $feed['icon']; | |
146 | ||
147 | $item['param'] = ''; | |
148 | $item['unread'] = 0; //$feed['sender']->get_unread($feed['id']); | |
149 | $item['type'] = 'feed'; | |
150 | ||
151 | array_push($cat['items'], $item); | |
152 | } | |
153 | } | |
154 | ||
2ecd2df5 AD |
155 | if ($enable_cats) { |
156 | array_push($root['items'], $cat); | |
157 | } else { | |
158 | $root['items'] = array_merge($root['items'], $cat['items']); | |
159 | } | |
afcfe6ca | 160 | |
d9c85e0f | 161 | $result = $this->dbh->query("SELECT * FROM |
2ecd2df5 AD |
162 | ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption"); |
163 | ||
d9c85e0f | 164 | if ($this->dbh->num_rows($result) > 0) { |
2ecd2df5 | 165 | |
a42c55f0 | 166 | if (get_pref('ENABLE_FEED_CATS')) { |
88918ca6 | 167 | $cat = $this->feedlist_init_cat(-2); |
2ecd2df5 AD |
168 | } else { |
169 | $cat['items'] = array(); | |
170 | } | |
171 | ||
d9c85e0f | 172 | while ($line = $this->dbh->fetch_assoc($result)) { |
2ecd2df5 | 173 | |
7c9b5a3f | 174 | $label_id = Labels::label_to_feed_id($line['id']); |
2ecd2df5 | 175 | |
88918ca6 | 176 | $feed = $this->feedlist_init_feed($label_id, false, 0); |
2ecd2df5 AD |
177 | |
178 | $feed['fg_color'] = $line['fg_color']; | |
179 | $feed['bg_color'] = $line['bg_color']; | |
180 | ||
181 | array_push($cat['items'], $feed); | |
182 | } | |
183 | ||
184 | if ($enable_cats) { | |
185 | array_push($root['items'], $cat); | |
186 | } else { | |
187 | $root['items'] = array_merge($root['items'], $cat['items']); | |
188 | } | |
189 | } | |
190 | } | |
191 | ||
192 | if ($enable_cats) { | |
66ca7c30 | 193 | $show_empty_cats = $_REQUEST['force_show_empty'] || |
e5e6cde0 | 194 | ($_REQUEST['mode'] != 2 && !$search); |
2ecd2df5 | 195 | |
d9c85e0f | 196 | $result = $this->dbh->query("SELECT id, title FROM ttrss_feed_categories |
2a060a94 | 197 | WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title"); |
afcfe6ca | 198 | |
d9c85e0f | 199 | while ($line = $this->dbh->fetch_assoc($result)) { |
afcfe6ca AD |
200 | $cat = array(); |
201 | $cat['id'] = 'CAT:' . $line['id']; | |
2ecd2df5 | 202 | $cat['bare_id'] = (int)$line['id']; |
c594eca0 | 203 | $cat['auxcounter'] = 0; |
afcfe6ca AD |
204 | $cat['name'] = $line['title']; |
205 | $cat['items'] = array(); | |
206 | $cat['checkbox'] = false; | |
207 | $cat['type'] = 'category'; | |
2ecd2df5 | 208 | $cat['unread'] = 0; |
2c5f231e | 209 | $cat['child_unread'] = 0; |
afcfe6ca | 210 | |
2a060a94 | 211 | $cat['items'] = $this->get_category_items($line['id']); |
afcfe6ca | 212 | |
496195db | 213 | $num_children = $this->calculate_children_count($cat); |
967f0619 | 214 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
afcfe6ca | 215 | |
496195db | 216 | if ($num_children > 0 || $show_empty_cats) |
afcfe6ca AD |
217 | array_push($root['items'], $cat); |
218 | ||
219 | $root['param'] += count($cat['items']); | |
220 | } | |
221 | ||
222 | /* Uncategorized is a special case */ | |
223 | ||
224 | $cat = array(); | |
225 | $cat['id'] = 'CAT:0'; | |
226 | $cat['bare_id'] = 0; | |
c594eca0 | 227 | $cat['auxcounter'] = 0; |
afcfe6ca AD |
228 | $cat['name'] = __("Uncategorized"); |
229 | $cat['items'] = array(); | |
230 | $cat['type'] = 'category'; | |
231 | $cat['checkbox'] = false; | |
2ecd2df5 | 232 | $cat['unread'] = 0; |
2c5f231e | 233 | $cat['child_unread'] = 0; |
afcfe6ca | 234 | |
d9c85e0f | 235 | $feed_result = $this->dbh->query("SELECT id, title,last_error, |
afcfe6ca AD |
236 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
237 | FROM ttrss_feeds | |
238 | WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"]. | |
239 | "$search_qpart ORDER BY order_id, title"); | |
240 | ||
d9c85e0f | 241 | while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { |
afcfe6ca AD |
242 | $feed = array(); |
243 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 244 | $feed['bare_id'] = (int)$feed_line['id']; |
c594eca0 | 245 | $feed['auxcounter'] = 0; |
afcfe6ca AD |
246 | $feed['name'] = $feed_line['title']; |
247 | $feed['checkbox'] = false; | |
248 | $feed['error'] = $feed_line['last_error']; | |
86a8351c | 249 | $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
6322ac79 | 250 | $feed['param'] = make_local_datetime( |
afcfe6ca | 251 | $feed_line['last_updated'], true); |
2ecd2df5 AD |
252 | $feed['unread'] = 0; |
253 | $feed['type'] = 'feed'; | |
afcfe6ca AD |
254 | |
255 | array_push($cat['items'], $feed); | |
256 | } | |
257 | ||
1a293f10 | 258 | $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca | 259 | |
5b7bd238 | 260 | if (count($cat['items']) > 0 || $show_empty_cats) |
afcfe6ca AD |
261 | array_push($root['items'], $cat); |
262 | ||
496195db | 263 | $num_children = $this->calculate_children_count($root); |
967f0619 | 264 | $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); |
afcfe6ca AD |
265 | |
266 | } else { | |
d9c85e0f | 267 | $feed_result = $this->dbh->query("SELECT id, title, last_error, |
afcfe6ca AD |
268 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
269 | FROM ttrss_feeds | |
270 | WHERE owner_uid = ".$_SESSION["uid"]. | |
271 | "$search_qpart ORDER BY order_id, title"); | |
272 | ||
d9c85e0f | 273 | while ($feed_line = $this->dbh->fetch_assoc($feed_result)) { |
afcfe6ca AD |
274 | $feed = array(); |
275 | $feed['id'] = 'FEED:' . $feed_line['id']; | |
2ecd2df5 | 276 | $feed['bare_id'] = (int)$feed_line['id']; |
c594eca0 | 277 | $feed['auxcounter'] = 0; |
afcfe6ca AD |
278 | $feed['name'] = $feed_line['title']; |
279 | $feed['checkbox'] = false; | |
280 | $feed['error'] = $feed_line['last_error']; | |
86a8351c | 281 | $feed['icon'] = Feeds::getFeedIcon($feed_line['id']); |
6322ac79 | 282 | $feed['param'] = make_local_datetime( |
afcfe6ca | 283 | $feed_line['last_updated'], true); |
2ecd2df5 AD |
284 | $feed['unread'] = 0; |
285 | $feed['type'] = 'feed'; | |
afcfe6ca AD |
286 | |
287 | array_push($root['items'], $feed); | |
288 | } | |
289 | ||
1a293f10 | 290 | $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); |
afcfe6ca AD |
291 | } |
292 | ||
293 | $fl = array(); | |
294 | $fl['identifier'] = 'id'; | |
295 | $fl['label'] = 'name'; | |
2ecd2df5 AD |
296 | |
297 | if ($_REQUEST['mode'] != 2) { | |
298 | $fl['items'] = array($root); | |
299 | } else { | |
1bd552ee | 300 | $fl['items'] = $root['items']; |
2ecd2df5 | 301 | } |
afcfe6ca | 302 | |
0bb5833b | 303 | return $fl; |
afcfe6ca AD |
304 | } |
305 | ||
306 | function catsortreset() { | |
d9c85e0f | 307 | $this->dbh->query("UPDATE ttrss_feed_categories |
afcfe6ca AD |
308 | SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); |
309 | return; | |
310 | } | |
311 | ||
312 | function feedsortreset() { | |
d9c85e0f | 313 | $this->dbh->query("UPDATE ttrss_feeds |
afcfe6ca AD |
314 | SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); |
315 | return; | |
316 | } | |
317 | ||
95ee44b3 AD |
318 | private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) { |
319 | $debug = isset($_REQUEST["debug"]); | |
320 | ||
321 | $prefix = ""; | |
322 | for ($i = 0; $i < $nest_level; $i++) | |
323 | $prefix .= " "; | |
324 | ||
325 | if ($debug) _debug("$prefix C: $item_id P: $parent_id"); | |
326 | ||
a5556c24 | 327 | $bare_item_id = $this->dbh->escape_string(substr($item_id, strpos($item_id, ':')+1)); |
2a060a94 AD |
328 | |
329 | if ($item_id != 'root') { | |
330 | if ($parent_id && $parent_id != 'root') { | |
331 | $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1); | |
d9c85e0f | 332 | $parent_qpart = $this->dbh->escape_string($parent_bare_id); |
2a060a94 AD |
333 | } else { |
334 | $parent_qpart = 'NULL'; | |
335 | } | |
336 | ||
d9c85e0f | 337 | $this->dbh->query("UPDATE ttrss_feed_categories |
95ee44b3 | 338 | SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND |
2a060a94 AD |
339 | owner_uid = " . $_SESSION["uid"]); |
340 | } | |
341 | ||
342 | $order_id = 0; | |
343 | ||
344 | $cat = $data_map[$item_id]; | |
345 | ||
346 | if ($cat && is_array($cat)) { | |
347 | foreach ($cat as $item) { | |
348 | $id = $item['_reference']; | |
a5556c24 | 349 | $bare_id = $this->dbh->escape_string(substr($id, strpos($id, ':')+1)); |
2a060a94 | 350 | |
95ee44b3 | 351 | if ($debug) _debug("$prefix [$order_id] $id/$bare_id"); |
2a060a94 AD |
352 | |
353 | if ($item['_reference']) { | |
354 | ||
355 | if (strpos($id, "FEED") === 0) { | |
356 | ||
95ee44b3 | 357 | $cat_id = ($item_id != "root") ? |
d9c85e0f | 358 | $this->dbh->escape_string($bare_item_id) : "NULL"; |
95ee44b3 | 359 | |
49b2401e AD |
360 | $cat_qpart = ($cat_id != 0) ? "cat_id = '$cat_id'" : |
361 | "cat_id = NULL"; | |
362 | ||
d9c85e0f | 363 | $this->dbh->query("UPDATE ttrss_feeds |
49b2401e | 364 | SET order_id = $order_id, $cat_qpart |
95ee44b3 | 365 | WHERE id = '$bare_id' AND |
2a060a94 AD |
366 | owner_uid = " . $_SESSION["uid"]); |
367 | ||
368 | } else if (strpos($id, "CAT:") === 0) { | |
95ee44b3 AD |
369 | $this->process_category_order($data_map, $item['_reference'], $item_id, |
370 | $nest_level+1); | |
2a060a94 AD |
371 | |
372 | if ($item_id != 'root') { | |
d9c85e0f | 373 | $parent_qpart = $this->dbh->escape_string($bare_id); |
2a060a94 AD |
374 | } else { |
375 | $parent_qpart = 'NULL'; | |
376 | } | |
377 | ||
d9c85e0f | 378 | $this->dbh->query("UPDATE ttrss_feed_categories |
2a060a94 AD |
379 | SET order_id = '$order_id' WHERE id = '$bare_id' AND |
380 | owner_uid = " . $_SESSION["uid"]); | |
381 | } | |
382 | } | |
383 | ||
384 | ++$order_id; | |
385 | } | |
386 | } | |
387 | } | |
388 | ||
afcfe6ca AD |
389 | function savefeedorder() { |
390 | $data = json_decode($_POST['payload'], true); | |
391 | ||
2a060a94 AD |
392 | #file_put_contents("/tmp/saveorder.json", $_POST['payload']); |
393 | #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true); | |
a26f57e6 | 394 | |
95ee44b3 AD |
395 | if (!is_array($data['items'])) |
396 | $data['items'] = json_decode($data['items'], true); | |
397 | ||
398 | # print_r($data['items']); | |
2a060a94 | 399 | |
afcfe6ca | 400 | if (is_array($data) && is_array($data['items'])) { |
4a80c57c | 401 | # $cat_order_id = 0; |
afcfe6ca AD |
402 | |
403 | $data_map = array(); | |
2a060a94 | 404 | $root_item = false; |
afcfe6ca AD |
405 | |
406 | foreach ($data['items'] as $item) { | |
407 | ||
2a060a94 | 408 | # if ($item['id'] != 'root') { |
afcfe6ca AD |
409 | if (is_array($item['items'])) { |
410 | if (isset($item['items']['_reference'])) { | |
411 | $data_map[$item['id']] = array($item['items']); | |
412 | } else { | |
1bd552ee | 413 | $data_map[$item['id']] = $item['items']; |
afcfe6ca AD |
414 | } |
415 | } | |
2a060a94 AD |
416 | if ($item['id'] == 'root') { |
417 | $root_item = $item['id']; | |
afcfe6ca AD |
418 | } |
419 | } | |
420 | ||
d04f8c82 | 421 | $this->process_category_order($data_map, $root_item); |
2a060a94 AD |
422 | |
423 | /* foreach ($data['items'][0]['items'] as $item) { | |
afcfe6ca AD |
424 | $id = $item['_reference']; |
425 | $bare_id = substr($id, strpos($id, ':')+1); | |
426 | ||
427 | ++$cat_order_id; | |
428 | ||
429 | if ($bare_id > 0) { | |
d9c85e0f | 430 | $this->dbh->query("UPDATE ttrss_feed_categories |
afcfe6ca AD |
431 | SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND |
432 | owner_uid = " . $_SESSION["uid"]); | |
433 | } | |
434 | ||
435 | $feed_order_id = 0; | |
436 | ||
437 | if (is_array($data_map[$id])) { | |
438 | foreach ($data_map[$id] as $feed) { | |
439 | $id = $feed['_reference']; | |
440 | $feed_id = substr($id, strpos($id, ':')+1); | |
441 | ||
442 | if ($bare_id != 0) | |
443 | $cat_query = "cat_id = '$bare_id'"; | |
444 | else | |
445 | $cat_query = "cat_id = NULL"; | |
446 | ||
d9c85e0f | 447 | $this->dbh->query("UPDATE ttrss_feeds |
afcfe6ca AD |
448 | SET order_id = '$feed_order_id', |
449 | $cat_query | |
450 | WHERE id = '$feed_id' AND | |
451 | owner_uid = " . $_SESSION["uid"]); | |
452 | ||
453 | ++$feed_order_id; | |
454 | } | |
455 | } | |
2a060a94 | 456 | } */ |
afcfe6ca AD |
457 | } |
458 | ||
459 | return; | |
460 | } | |
461 | ||
462 | function removeicon() { | |
d9c85e0f | 463 | $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]); |
afcfe6ca | 464 | |
d9c85e0f | 465 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds |
afcfe6ca AD |
466 | WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); |
467 | ||
d9c85e0f | 468 | if ($this->dbh->num_rows($result) != 0) { |
3306daec | 469 | @unlink(ICONS_DIR . "/$feed_id.ico"); |
bc7a144d | 470 | |
d9c85e0f | 471 | $this->dbh->query("UPDATE ttrss_feeds SET favicon_avg_color = NULL |
bc7a144d | 472 | where id = '$feed_id'"); |
afcfe6ca AD |
473 | } |
474 | ||
475 | return; | |
476 | } | |
477 | ||
478 | function uploadicon() { | |
350e3944 AD |
479 | header("Content-type: text/html"); |
480 | ||
3306daec AD |
481 | $tmp_file = false; |
482 | ||
483 | if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { | |
484 | $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon'); | |
485 | ||
486 | $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], | |
487 | $tmp_file); | |
488 | ||
489 | if (!$result) { | |
490 | return; | |
491 | } | |
492 | } else { | |
493 | return; | |
494 | } | |
495 | ||
496 | $icon_file = $tmp_file; | |
d9c85e0f | 497 | $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]); |
afcfe6ca AD |
498 | |
499 | if (is_file($icon_file) && $feed_id) { | |
4a1d122c | 500 | if (filesize($icon_file) < 65535) { |
afcfe6ca | 501 | |
d9c85e0f | 502 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds |
afcfe6ca AD |
503 | WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); |
504 | ||
d9c85e0f | 505 | if ($this->dbh->num_rows($result) != 0) { |
3306daec | 506 | @unlink(ICONS_DIR . "/$feed_id.ico"); |
bc7a144d | 507 | if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { |
d9c85e0f | 508 | $this->dbh->query("UPDATE ttrss_feeds SET |
258068b3 | 509 | favicon_avg_color = '' |
bc7a144d AD |
510 | WHERE id = '$feed_id'"); |
511 | ||
512 | $rc = 0; | |
513 | } | |
afcfe6ca AD |
514 | } else { |
515 | $rc = 2; | |
516 | } | |
517 | } else { | |
518 | $rc = 1; | |
519 | } | |
520 | } else { | |
521 | $rc = 2; | |
522 | } | |
523 | ||
3306daec AD |
524 | @unlink($icon_file); |
525 | ||
afcfe6ca AD |
526 | print "<script type=\"text/javascript\">"; |
527 | print "parent.uploadIconHandler($rc);"; | |
528 | print "</script>"; | |
529 | return; | |
530 | } | |
531 | ||
532 | function editfeed() { | |
533 | global $purge_intervals; | |
534 | global $update_intervals; | |
afcfe6ca | 535 | |
d9877997 AD |
536 | print '<div dojoType="dijit.layout.TabContainer" style="height : 450px"> |
537 | <div dojoType="dijit.layout.ContentPane" title="'.__('General').'">'; | |
538 | ||
d9c85e0f | 539 | $feed_id = $this->dbh->escape_string($_REQUEST["id"]); |
afcfe6ca | 540 | |
d9c85e0f | 541 | $result = $this->dbh->query( |
afcfe6ca AD |
542 | "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND |
543 | owner_uid = " . $_SESSION["uid"]); | |
544 | ||
d9c85e0f | 545 | $auth_pass_encrypted = sql_bool_to_bool($this->dbh->fetch_result($result, 0, |
044cff2d AD |
546 | "auth_pass_encrypted")); |
547 | ||
d9c85e0f | 548 | $title = htmlspecialchars($this->dbh->fetch_result($result, |
afcfe6ca AD |
549 | 0, "title")); |
550 | ||
328118d1 AD |
551 | print_hidden("id", "$feed_id"); |
552 | print_hidden("op", "pref-feeds"); | |
553 | print_hidden("method", "editSave"); | |
afcfe6ca AD |
554 | |
555 | print "<div class=\"dlgSec\">".__("Feed")."</div>"; | |
556 | print "<div class=\"dlgSecCont\">"; | |
557 | ||
558 | /* Title */ | |
559 | ||
560 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" | |
561 | placeHolder=\"".__("Feed Title")."\" | |
562 | style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">"; | |
563 | ||
564 | /* Feed URL */ | |
565 | ||
d9c85e0f AD |
566 | $feed_url = $this->dbh->fetch_result($result, 0, "feed_url"); |
567 | $feed_url = htmlspecialchars($this->dbh->fetch_result($result, | |
afcfe6ca AD |
568 | 0, "feed_url")); |
569 | ||
570 | print "<hr/>"; | |
571 | ||
572 | print __('URL:') . " "; | |
573 | print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" | |
574 | placeHolder=\"".__("Feed URL")."\" | |
575 | regExp='^(http|https)://.*' style=\"width : 20em\" | |
576 | name=\"feed_url\" value=\"$feed_url\">"; | |
577 | ||
d9c85e0f | 578 | $last_error = $this->dbh->fetch_result($result, 0, "last_error"); |
afcfe6ca AD |
579 | |
580 | if ($last_error) { | |
1a545dcb AD |
581 | print " <img src=\"images/error.png\" alt=\"(error)\" |
582 | style=\"vertical-align : middle\" | |
583 | title=\"".htmlspecialchars($last_error)."\">"; | |
afcfe6ca AD |
584 | |
585 | } | |
586 | ||
587 | /* Category */ | |
588 | ||
a42c55f0 | 589 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca | 590 | |
d9c85e0f | 591 | $cat_id = $this->dbh->fetch_result($result, 0, "cat_id"); |
afcfe6ca AD |
592 | |
593 | print "<hr/>"; | |
594 | ||
595 | print __('Place in category:') . " "; | |
596 | ||
a42c55f0 | 597 | print_feed_cat_select("cat_id", $cat_id, |
afcfe6ca AD |
598 | 'dojoType="dijit.form.Select"'); |
599 | } | |
600 | ||
df659891 AD |
601 | /* FTS Stemming Language */ |
602 | ||
603 | if (DB_TYPE == "pgsql") { | |
604 | $feed_language = $this->dbh->fetch_result($result, 0, "feed_language"); | |
605 | ||
606 | print "<hr/>"; | |
607 | ||
608 | print __('Language:') . " "; | |
609 | print_select("feed_language", $feed_language, $this::$feed_languages, | |
610 | 'dojoType="dijit.form.Select"'); | |
611 | } | |
612 | ||
afcfe6ca AD |
613 | print "</div>"; |
614 | ||
615 | print "<div class=\"dlgSec\">".__("Update")."</div>"; | |
616 | print "<div class=\"dlgSecCont\">"; | |
617 | ||
618 | /* Update Interval */ | |
619 | ||
d9c85e0f | 620 | $update_interval = $this->dbh->fetch_result($result, 0, "update_interval"); |
afcfe6ca AD |
621 | |
622 | print_select_hash("update_interval", $update_interval, $update_intervals, | |
623 | 'dojoType="dijit.form.Select"'); | |
624 | ||
19b3992b | 625 | /* Purge intl */ |
afcfe6ca | 626 | |
d9c85e0f | 627 | $purge_interval = $this->dbh->fetch_result($result, 0, "purge_interval"); |
afcfe6ca | 628 | |
afcfe6ca AD |
629 | print "<hr/>"; |
630 | print __('Article purging:') . " "; | |
631 | ||
632 | print_select_hash("purge_interval", $purge_interval, $purge_intervals, | |
633 | 'dojoType="dijit.form.Select" ' . | |
634 | ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); | |
635 | ||
636 | print "</div>"; | |
637 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
638 | print "<div class=\"dlgSecCont\">"; | |
639 | ||
d9c85e0f | 640 | $auth_login = htmlspecialchars($this->dbh->fetch_result($result, 0, "auth_login")); |
afcfe6ca AD |
641 | |
642 | print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\" | |
643 | placeHolder=\"".__("Login")."\" | |
ec21abb8 | 644 | autocomplete=\"new-password\" |
afcfe6ca AD |
645 | name=\"auth_login\" value=\"$auth_login\"><hr/>"; |
646 | ||
d9c85e0f | 647 | $auth_pass = $this->dbh->fetch_result($result, 0, "auth_pass"); |
044cff2d | 648 | |
17a8e61d | 649 | if ($auth_pass_encrypted && function_exists("mcrypt_decrypt")) { |
044cff2d AD |
650 | require_once "crypt.php"; |
651 | $auth_pass = decrypt_string($auth_pass); | |
652 | } | |
653 | ||
654 | $auth_pass = htmlspecialchars($auth_pass); | |
afcfe6ca AD |
655 | |
656 | print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" | |
ec21abb8 | 657 | autocomplete=\"new-password\" |
afcfe6ca AD |
658 | placeHolder=\"".__("Password")."\" |
659 | value=\"$auth_pass\">"; | |
660 | ||
661 | print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\"> | |
662 | ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')." | |
663 | </div>"; | |
664 | ||
665 | print "</div>"; | |
d9877997 AD |
666 | |
667 | print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">'; | |
668 | ||
669 | //print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
670 | print "<div class=\"dlgSecSimple\">"; | |
afcfe6ca | 671 | |
d9c85e0f | 672 | $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private")); |
afcfe6ca AD |
673 | |
674 | if ($private) { | |
675 | $checked = "checked=\"1\""; | |
676 | } else { | |
677 | $checked = ""; | |
678 | } | |
679 | ||
680 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\" | |
681 | $checked> <label for=\"private\">".__('Hide from Popular feeds')."</label>"; | |
682 | ||
d9c85e0f | 683 | $include_in_digest = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "include_in_digest")); |
afcfe6ca AD |
684 | |
685 | if ($include_in_digest) { | |
686 | $checked = "checked=\"1\""; | |
687 | } else { | |
688 | $checked = ""; | |
689 | } | |
690 | ||
691 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" | |
692 | name=\"include_in_digest\" | |
693 | $checked> <label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
694 | ||
695 | ||
d9c85e0f | 696 | $always_display_enclosures = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "always_display_enclosures")); |
afcfe6ca AD |
697 | |
698 | if ($always_display_enclosures) { | |
699 | $checked = "checked"; | |
700 | } else { | |
701 | $checked = ""; | |
702 | } | |
703 | ||
704 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" | |
705 | name=\"always_display_enclosures\" | |
706 | $checked> <label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
707 | ||
d9c85e0f | 708 | $hide_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "hide_images")); |
bfd61d3f AD |
709 | |
710 | if ($hide_images) { | |
711 | $checked = "checked=\"1\""; | |
712 | } else { | |
713 | $checked = ""; | |
714 | } | |
715 | ||
716 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\" | |
717 | name=\"hide_images\" | |
718 | $checked> <label for=\"hide_images\">". | |
719 | __('Do not embed images')."</label>"; | |
afcfe6ca | 720 | |
d9c85e0f | 721 | $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images")); |
afcfe6ca AD |
722 | |
723 | if ($cache_images) { | |
724 | $checked = "checked=\"1\""; | |
725 | } else { | |
726 | $checked = ""; | |
727 | } | |
728 | ||
3c696512 AD |
729 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\" |
730 | name=\"cache_images\" | |
afcfe6ca | 731 | $checked> <label for=\"cache_images\">". |
9c3c0ace | 732 | __('Cache media')."</label>"; |
afcfe6ca | 733 | |
d9c85e0f | 734 | $mark_unread_on_update = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "mark_unread_on_update")); |
afcfe6ca AD |
735 | |
736 | if ($mark_unread_on_update) { | |
737 | $checked = "checked"; | |
738 | } else { | |
739 | $checked = ""; | |
740 | } | |
741 | ||
742 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\" | |
743 | name=\"mark_unread_on_update\" | |
744 | $checked> <label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
745 | ||
afcfe6ca AD |
746 | print "</div>"; |
747 | ||
d9877997 AD |
748 | print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">'; |
749 | ||
afcfe6ca AD |
750 | /* Icon */ |
751 | ||
d9877997 | 752 | print "<div class=\"dlgSecSimple\">"; |
afcfe6ca AD |
753 | |
754 | print "<iframe name=\"icon_upload_iframe\" | |
755 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; | |
756 | ||
757 | print "<form style='display : block' target=\"icon_upload_iframe\" | |
758 | enctype=\"multipart/form-data\" method=\"POST\" | |
759 | action=\"backend.php\"> | |
760 | <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\"> | |
761 | <input type=\"hidden\" name=\"op\" value=\"pref-feeds\"> | |
762 | <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\"> | |
d9877997 AD |
763 | <input type=\"hidden\" name=\"method\" value=\"uploadicon\"><p> |
764 | <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\" | |
afcfe6ca | 765 | type=\"submit\">".__('Replace')."</button> |
d9877997 | 766 | <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\" |
afcfe6ca AD |
767 | type=\"submit\">".__('Remove')."</button> |
768 | </form>"; | |
769 | ||
770 | print "</div>"; | |
771 | ||
d9877997 AD |
772 | print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">'; |
773 | ||
057177eb AD |
774 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, |
775 | "hook_prefs_edit_feed", $feed_id); | |
776 | ||
d9877997 AD |
777 | |
778 | print "</div></div>"; | |
779 | ||
afcfe6ca AD |
780 | $title = htmlspecialchars($title, ENT_QUOTES); |
781 | ||
782 | print "<div class='dlgButtons'> | |
783 | <div style=\"float : left\"> | |
73dfda1d | 784 | <button class=\"danger\" dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>". |
afcfe6ca AD |
785 | __('Unsubscribe')."</button>"; |
786 | ||
787 | if (PUBSUBHUBBUB_ENABLED) { | |
d9c85e0f | 788 | $pubsub_state = $this->dbh->fetch_result($result, 0, "pubsub_state"); |
afcfe6ca AD |
789 | $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\""; |
790 | ||
791 | print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" $pubsub_btn_disabled | |
792 | onclick='return resetPubSub($feed_id, \"$title\")'>".__('Resubscribe to push updates'). | |
793 | "</button>"; | |
794 | } | |
795 | ||
796 | print "</div>"; | |
797 | ||
798 | print "<div dojoType=\"dijit.Tooltip\" connectId=\"pubsubReset_Btn\" position=\"below\">". | |
799 | __('Resets PubSubHubbub subscription status for push-enabled feeds.')."</div>"; | |
800 | ||
801 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button> | |
802 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button> | |
803 | </div>"; | |
804 | ||
d9877997 | 805 | |
afcfe6ca AD |
806 | return; |
807 | } | |
808 | ||
809 | function editfeeds() { | |
810 | global $purge_intervals; | |
811 | global $update_intervals; | |
46da73c2 | 812 | |
d9c85e0f | 813 | $feed_ids = $this->dbh->escape_string($_REQUEST["ids"]); |
afcfe6ca | 814 | |
fcef9eea AD |
815 | print_notice("Enable the options you wish to apply using checkboxes on the right:"); |
816 | ||
817 | print "<p>"; | |
ca6a0741 | 818 | |
328118d1 AD |
819 | print_hidden("ids", "$feed_ids"); |
820 | print_hidden("op", "pref-feeds"); | |
821 | print_hidden("method", "batchEditSave"); | |
afcfe6ca AD |
822 | |
823 | print "<div class=\"dlgSec\">".__("Feed")."</div>"; | |
824 | print "<div class=\"dlgSecCont\">"; | |
825 | ||
afcfe6ca AD |
826 | /* Category */ |
827 | ||
a42c55f0 | 828 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca | 829 | |
afcfe6ca AD |
830 | print __('Place in category:') . " "; |
831 | ||
d29357fa | 832 | print_feed_cat_select("cat_id", false, |
afcfe6ca AD |
833 | 'disabled="1" dojoType="dijit.form.Select"'); |
834 | ||
835 | $this->batch_edit_cbox("cat_id"); | |
836 | ||
837 | } | |
838 | ||
df659891 AD |
839 | /* FTS Stemming Language */ |
840 | ||
841 | if (DB_TYPE == "pgsql") { | |
842 | print "<hr/>"; | |
843 | ||
844 | print __('Language:') . " "; | |
845 | print_select("feed_language", "", $this::$feed_languages, | |
846 | 'disabled="1" dojoType="dijit.form.Select"'); | |
847 | ||
848 | $this->batch_edit_cbox("feed_language"); | |
849 | } | |
850 | ||
afcfe6ca AD |
851 | print "</div>"; |
852 | ||
853 | print "<div class=\"dlgSec\">".__("Update")."</div>"; | |
854 | print "<div class=\"dlgSecCont\">"; | |
855 | ||
856 | /* Update Interval */ | |
857 | ||
d29357fa | 858 | print_select_hash("update_interval", "", $update_intervals, |
afcfe6ca AD |
859 | 'disabled="1" dojoType="dijit.form.Select"'); |
860 | ||
861 | $this->batch_edit_cbox("update_interval"); | |
862 | ||
afcfe6ca AD |
863 | /* Purge intl */ |
864 | ||
865 | if (FORCE_ARTICLE_PURGE == 0) { | |
866 | ||
867 | print "<br/>"; | |
868 | ||
869 | print __('Article purging:') . " "; | |
870 | ||
d29357fa | 871 | print_select_hash("purge_interval", "", $purge_intervals, |
afcfe6ca AD |
872 | 'disabled="1" dojoType="dijit.form.Select"'); |
873 | ||
874 | $this->batch_edit_cbox("purge_interval"); | |
875 | } | |
876 | ||
877 | print "</div>"; | |
878 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
879 | print "<div class=\"dlgSecCont\">"; | |
880 | ||
881 | print "<input dojoType=\"dijit.form.TextBox\" | |
882 | placeHolder=\"".__("Login")."\" disabled=\"1\" | |
ec21abb8 | 883 | autocomplete=\"new-password\" |
d29357fa | 884 | name=\"auth_login\" value=\"\">"; |
afcfe6ca AD |
885 | |
886 | $this->batch_edit_cbox("auth_login"); | |
887 | ||
44727c79 | 888 | print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" |
ec21abb8 | 889 | autocomplete=\"new-password\" |
afcfe6ca | 890 | placeHolder=\"".__("Password")."\" disabled=\"1\" |
d29357fa | 891 | value=\"\">"; |
afcfe6ca AD |
892 | |
893 | $this->batch_edit_cbox("auth_pass"); | |
894 | ||
895 | print "</div>"; | |
896 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
897 | print "<div class=\"dlgSecCont\">"; | |
898 | ||
899 | print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\" | |
900 | dojoType=\"dijit.form.CheckBox\"> <label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>"; | |
901 | ||
902 | print " "; $this->batch_edit_cbox("private", "private_l"); | |
903 | ||
afcfe6ca AD |
904 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\" |
905 | name=\"include_in_digest\" | |
906 | dojoType=\"dijit.form.CheckBox\"> <label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
907 | ||
908 | print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); | |
909 | ||
910 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\" | |
911 | name=\"always_display_enclosures\" | |
912 | dojoType=\"dijit.form.CheckBox\"> <label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
913 | ||
914 | print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); | |
915 | ||
bfd61d3f AD |
916 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\" |
917 | name=\"hide_images\" | |
918 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"hide_images_l\" | |
919 | for=\"hide_images\">". | |
920 | __('Do not embed images')."</label>"; | |
921 | ||
922 | print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); | |
923 | ||
3c696512 AD |
924 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\" |
925 | name=\"cache_images\" | |
926 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"cache_images_l\" | |
927 | for=\"cache_images\">". | |
9c3c0ace | 928 | __('Cache media')."</label>"; |
afcfe6ca | 929 | |
3c696512 | 930 | print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); |
afcfe6ca AD |
931 | |
932 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\" | |
933 | name=\"mark_unread_on_update\" | |
934 | dojoType=\"dijit.form.CheckBox\"> <label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
935 | ||
936 | print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); | |
937 | ||
afcfe6ca AD |
938 | print "</div>"; |
939 | ||
940 | print "<div class='dlgButtons'> | |
941 | <button dojoType=\"dijit.form.Button\" | |
942 | onclick=\"return dijit.byId('feedEditDlg').execute()\">". | |
943 | __('Save')."</button> | |
944 | <button dojoType=\"dijit.form.Button\" | |
945 | onclick=\"return dijit.byId('feedEditDlg').hide()\">". | |
946 | __('Cancel')."</button> | |
947 | </div>"; | |
948 | ||
949 | return; | |
950 | } | |
951 | ||
952 | function batchEditSave() { | |
3a76e2a2 | 953 | return $this->editsaveops(true); |
afcfe6ca | 954 | } |
46da73c2 | 955 | |
afcfe6ca | 956 | function editSave() { |
3a76e2a2 | 957 | return $this->editsaveops(false); |
afcfe6ca | 958 | } |
46da73c2 AD |
959 | |
960 | function editsaveops($batch) { | |
961 | ||
d9c85e0f AD |
962 | $feed_title = $this->dbh->escape_string(trim($_POST["title"])); |
963 | $feed_link = $this->dbh->escape_string(trim($_POST["feed_url"])); | |
964 | $upd_intl = (int) $this->dbh->escape_string($_POST["update_interval"]); | |
965 | $purge_intl = (int) $this->dbh->escape_string($_POST["purge_interval"]); | |
966 | $feed_id = (int) $this->dbh->escape_string($_POST["id"]); /* editSave */ | |
967 | $feed_ids = $this->dbh->escape_string($_POST["ids"]); /* batchEditSave */ | |
968 | $cat_id = (int) $this->dbh->escape_string($_POST["cat_id"]); | |
969 | $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"])); | |
41694a95 | 970 | $auth_pass = trim($_POST["auth_pass"]); |
d9c85e0f | 971 | $private = checkbox_to_sql_bool($this->dbh->escape_string($_POST["private"])); |
afcfe6ca | 972 | $include_in_digest = checkbox_to_sql_bool( |
d9c85e0f | 973 | $this->dbh->escape_string($_POST["include_in_digest"])); |
afcfe6ca | 974 | $cache_images = checkbox_to_sql_bool( |
d9c85e0f | 975 | $this->dbh->escape_string($_POST["cache_images"])); |
bfd61d3f | 976 | $hide_images = checkbox_to_sql_bool( |
d9c85e0f | 977 | $this->dbh->escape_string($_POST["hide_images"])); |
afcfe6ca | 978 | $always_display_enclosures = checkbox_to_sql_bool( |
d9c85e0f | 979 | $this->dbh->escape_string($_POST["always_display_enclosures"])); |
afcfe6ca AD |
980 | |
981 | $mark_unread_on_update = checkbox_to_sql_bool( | |
d9c85e0f | 982 | $this->dbh->escape_string($_POST["mark_unread_on_update"])); |
afcfe6ca | 983 | |
df659891 AD |
984 | $feed_language = $this->dbh->escape_string(trim($_POST["feed_language"])); |
985 | ||
17a8e61d | 986 | $auth_pass_encrypted = 'false'; |
d9c85e0f | 987 | $auth_pass = $this->dbh->escape_string($auth_pass); |
41694a95 | 988 | |
a42c55f0 | 989 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca AD |
990 | if ($cat_id && $cat_id != 0) { |
991 | $category_qpart = "cat_id = '$cat_id',"; | |
992 | $category_qpart_nocomma = "cat_id = '$cat_id'"; | |
993 | } else { | |
994 | $category_qpart = 'cat_id = NULL,'; | |
995 | $category_qpart_nocomma = 'cat_id = NULL'; | |
996 | } | |
997 | } else { | |
998 | $category_qpart = ""; | |
999 | $category_qpart_nocomma = ""; | |
1000 | } | |
1001 | ||
3a76e2a2 | 1002 | if (!$batch) { |
afcfe6ca | 1003 | |
91837f0a AD |
1004 | $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = " . $feed_id); |
1005 | $orig_feed_url = db_fetch_result($result, 0, "feed_url"); | |
1006 | ||
1007 | $reset_basic_info = $orig_feed_url != $feed_link; | |
1008 | ||
4a80c57c | 1009 | $this->dbh->query("UPDATE ttrss_feeds SET |
afcfe6ca AD |
1010 | $category_qpart |
1011 | title = '$feed_title', feed_url = '$feed_link', | |
1012 | update_interval = '$upd_intl', | |
1013 | purge_interval = '$purge_intl', | |
1014 | auth_login = '$auth_login', | |
1015 | auth_pass = '$auth_pass', | |
044cff2d | 1016 | auth_pass_encrypted = $auth_pass_encrypted, |
afcfe6ca | 1017 | private = $private, |
87764a50 | 1018 | cache_images = $cache_images, |
bfd61d3f | 1019 | hide_images = $hide_images, |
afcfe6ca AD |
1020 | include_in_digest = $include_in_digest, |
1021 | always_display_enclosures = $always_display_enclosures, | |
df659891 AD |
1022 | mark_unread_on_update = $mark_unread_on_update, |
1023 | feed_language = '$feed_language' | |
19b3992b | 1024 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); |
afcfe6ca | 1025 | |
91837f0a | 1026 | if ($reset_basic_info) { |
e6c886bf | 1027 | RSSUtils::set_basic_feed_info($feed_id); |
91837f0a AD |
1028 | } |
1029 | ||
8cefe38a AD |
1030 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, |
1031 | "hook_prefs_save_feed", $feed_id); | |
1032 | ||
3a76e2a2 | 1033 | } else { |
afcfe6ca AD |
1034 | $feed_data = array(); |
1035 | ||
1036 | foreach (array_keys($_POST) as $k) { | |
1037 | if ($k != "op" && $k != "method" && $k != "ids") { | |
1038 | $feed_data[$k] = $_POST[$k]; | |
1039 | } | |
1040 | } | |
1041 | ||
d9c85e0f | 1042 | $this->dbh->query("BEGIN"); |
afcfe6ca AD |
1043 | |
1044 | foreach (array_keys($feed_data) as $k) { | |
1045 | ||
1046 | $qpart = ""; | |
1047 | ||
1048 | switch ($k) { | |
1049 | case "title": | |
1050 | $qpart = "title = '$feed_title'"; | |
1051 | break; | |
1052 | ||
1053 | case "feed_url": | |
1054 | $qpart = "feed_url = '$feed_link'"; | |
1055 | break; | |
1056 | ||
1057 | case "update_interval": | |
1058 | $qpart = "update_interval = '$upd_intl'"; | |
1059 | break; | |
1060 | ||
1061 | case "purge_interval": | |
1062 | $qpart = "purge_interval = '$purge_intl'"; | |
1063 | break; | |
1064 | ||
1065 | case "auth_login": | |
1066 | $qpart = "auth_login = '$auth_login'"; | |
1067 | break; | |
1068 | ||
1069 | case "auth_pass": | |
044cff2d AD |
1070 | $qpart = "auth_pass = '$auth_pass' AND |
1071 | auth_pass_encrypted = $auth_pass_encrypted"; | |
afcfe6ca AD |
1072 | break; |
1073 | ||
1074 | case "private": | |
a498d18b | 1075 | $qpart = "private = $private"; |
afcfe6ca AD |
1076 | break; |
1077 | ||
1078 | case "include_in_digest": | |
a498d18b | 1079 | $qpart = "include_in_digest = $include_in_digest"; |
afcfe6ca AD |
1080 | break; |
1081 | ||
1082 | case "always_display_enclosures": | |
a498d18b | 1083 | $qpart = "always_display_enclosures = $always_display_enclosures"; |
afcfe6ca AD |
1084 | break; |
1085 | ||
1086 | case "mark_unread_on_update": | |
a498d18b | 1087 | $qpart = "mark_unread_on_update = $mark_unread_on_update"; |
afcfe6ca AD |
1088 | break; |
1089 | ||
afcfe6ca | 1090 | case "cache_images": |
a498d18b | 1091 | $qpart = "cache_images = $cache_images"; |
afcfe6ca AD |
1092 | break; |
1093 | ||
bfd61d3f AD |
1094 | case "hide_images": |
1095 | $qpart = "hide_images = $hide_images"; | |
1096 | break; | |
1097 | ||
afcfe6ca AD |
1098 | case "cat_id": |
1099 | $qpart = $category_qpart_nocomma; | |
1100 | break; | |
1101 | ||
df659891 AD |
1102 | case "feed_language": |
1103 | $qpart = "feed_language = '$feed_language'"; | |
1104 | break; | |
1105 | ||
afcfe6ca AD |
1106 | } |
1107 | ||
1108 | if ($qpart) { | |
d9c85e0f | 1109 | $this->dbh->query( |
afcfe6ca AD |
1110 | "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids) |
1111 | AND owner_uid = " . $_SESSION["uid"]); | |
1112 | print "<br/>"; | |
1113 | } | |
1114 | } | |
1115 | ||
d9c85e0f | 1116 | $this->dbh->query("COMMIT"); |
afcfe6ca AD |
1117 | } |
1118 | return; | |
1119 | } | |
1120 | ||
1121 | function resetPubSub() { | |
1122 | ||
d9c85e0f | 1123 | $ids = $this->dbh->escape_string($_REQUEST["ids"]); |
afcfe6ca | 1124 | |
d9c85e0f | 1125 | $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids) |
afcfe6ca AD |
1126 | AND owner_uid = " . $_SESSION["uid"]); |
1127 | ||
1128 | return; | |
1129 | } | |
1130 | ||
1131 | function remove() { | |
1132 | ||
d9c85e0f | 1133 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
afcfe6ca AD |
1134 | |
1135 | foreach ($ids as $id) { | |
a42c55f0 | 1136 | Pref_Feeds::remove_feed($id, $_SESSION["uid"]); |
afcfe6ca AD |
1137 | } |
1138 | ||
1139 | return; | |
1140 | } | |
1141 | ||
1142 | function clear() { | |
d9c85e0f | 1143 | $id = $this->dbh->escape_string($_REQUEST["id"]); |
a42c55f0 | 1144 | $this->clear_feed_articles($id); |
afcfe6ca AD |
1145 | } |
1146 | ||
1147 | function rescore() { | |
d9c85e0f | 1148 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
afcfe6ca AD |
1149 | |
1150 | foreach ($ids as $id) { | |
1151 | ||
a42c55f0 | 1152 | $filters = load_filters($id, $_SESSION["uid"], 6); |
afcfe6ca | 1153 | |
d9c85e0f | 1154 | $result = $this->dbh->query("SELECT |
afcfe6ca AD |
1155 | title, content, link, ref_id, author,". |
1156 | SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated | |
1157 | FROM | |
1158 | ttrss_user_entries, ttrss_entries | |
1159 | WHERE ref_id = id AND feed_id = '$id' AND | |
1160 | owner_uid = " .$_SESSION['uid']." | |
1161 | "); | |
1162 | ||
1163 | $scores = array(); | |
1164 | ||
d9c85e0f | 1165 | while ($line = $this->dbh->fetch_assoc($result)) { |
afcfe6ca | 1166 | |
2ed0d6c4 | 1167 | $tags = Article::get_article_tags($line["ref_id"]); |
afcfe6ca | 1168 | |
e6c886bf | 1169 | $article_filters = RSSUtils::get_article_filters($filters, $line['title'], |
afcfe6ca AD |
1170 | $line['content'], $line['link'], strtotime($line['updated']), |
1171 | $line['author'], $tags); | |
1172 | ||
e6c886bf | 1173 | $new_score = RSSUtils::calculate_article_score($article_filters); |
afcfe6ca AD |
1174 | |
1175 | if (!$scores[$new_score]) $scores[$new_score] = array(); | |
1176 | ||
1177 | array_push($scores[$new_score], $line['ref_id']); | |
1178 | } | |
1179 | ||
1180 | foreach (array_keys($scores) as $s) { | |
1181 | if ($s > 1000) { | |
d9c85e0f | 1182 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', |
afcfe6ca AD |
1183 | marked = true WHERE |
1184 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1185 | } else if ($s < -500) { | |
d9c85e0f | 1186 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', |
afcfe6ca AD |
1187 | unread = false WHERE |
1188 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1189 | } else { | |
d9c85e0f | 1190 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE |
afcfe6ca AD |
1191 | ref_id IN (" . join(',', $scores[$s]) . ")"); |
1192 | } | |
1193 | } | |
1194 | } | |
1195 | ||
1196 | print __("All done."); | |
1197 | ||
1198 | } | |
1199 | ||
1200 | function rescoreAll() { | |
1201 | ||
d9c85e0f | 1202 | $result = $this->dbh->query( |
afcfe6ca AD |
1203 | "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']); |
1204 | ||
d9c85e0f | 1205 | while ($feed_line = $this->dbh->fetch_assoc($result)) { |
afcfe6ca AD |
1206 | |
1207 | $id = $feed_line["id"]; | |
1208 | ||
a42c55f0 | 1209 | $filters = load_filters($id, $_SESSION["uid"], 6); |
afcfe6ca | 1210 | |
d9c85e0f | 1211 | $tmp_result = $this->dbh->query("SELECT |
afcfe6ca AD |
1212 | title, content, link, ref_id, author,". |
1213 | SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated | |
1214 | FROM | |
1215 | ttrss_user_entries, ttrss_entries | |
1216 | WHERE ref_id = id AND feed_id = '$id' AND | |
1217 | owner_uid = " .$_SESSION['uid']." | |
1218 | "); | |
1219 | ||
1220 | $scores = array(); | |
1221 | ||
d9c85e0f | 1222 | while ($line = $this->dbh->fetch_assoc($tmp_result)) { |
afcfe6ca | 1223 | |
2ed0d6c4 | 1224 | $tags = Article::get_article_tags($line["ref_id"]); |
afcfe6ca | 1225 | |
e6c886bf | 1226 | $article_filters = RSSUtils::get_article_filters($filters, $line['title'], |
afcfe6ca AD |
1227 | $line['content'], $line['link'], strtotime($line['updated']), |
1228 | $line['author'], $tags); | |
1229 | ||
e6c886bf | 1230 | $new_score = RSSUtils::calculate_article_score($article_filters); |
afcfe6ca AD |
1231 | |
1232 | if (!$scores[$new_score]) $scores[$new_score] = array(); | |
1233 | ||
1234 | array_push($scores[$new_score], $line['ref_id']); | |
1235 | } | |
1236 | ||
1237 | foreach (array_keys($scores) as $s) { | |
1238 | if ($s > 1000) { | |
d9c85e0f | 1239 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', |
afcfe6ca AD |
1240 | marked = true WHERE |
1241 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1242 | } else { | |
d9c85e0f | 1243 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE |
afcfe6ca AD |
1244 | ref_id IN (" . join(',', $scores[$s]) . ")"); |
1245 | } | |
1246 | } | |
1247 | } | |
1248 | ||
1249 | print __("All done."); | |
1250 | ||
1251 | } | |
1252 | ||
afcfe6ca | 1253 | function categorize() { |
d9c85e0f | 1254 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
afcfe6ca | 1255 | |
d9c85e0f | 1256 | $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]); |
afcfe6ca AD |
1257 | |
1258 | if ($cat_id == 0) { | |
1259 | $cat_id_qpart = 'NULL'; | |
1260 | } else { | |
1261 | $cat_id_qpart = "'$cat_id'"; | |
1262 | } | |
1263 | ||
d9c85e0f | 1264 | $this->dbh->query("BEGIN"); |
afcfe6ca AD |
1265 | |
1266 | foreach ($ids as $id) { | |
1267 | ||
d9c85e0f | 1268 | $this->dbh->query("UPDATE ttrss_feeds SET cat_id = $cat_id_qpart |
afcfe6ca AD |
1269 | WHERE id = '$id' |
1270 | AND owner_uid = " . $_SESSION["uid"]); | |
1271 | ||
1272 | } | |
1273 | ||
d9c85e0f | 1274 | $this->dbh->query("COMMIT"); |
afcfe6ca AD |
1275 | } |
1276 | ||
28537341 | 1277 | function removeCat() { |
d9c85e0f | 1278 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); |
28537341 | 1279 | foreach ($ids as $id) { |
a42c55f0 | 1280 | $this->remove_feed_category($id, $_SESSION["uid"]); |
28537341 AD |
1281 | } |
1282 | } | |
1283 | ||
1284 | function addCat() { | |
d9c85e0f | 1285 | $feed_cat = $this->dbh->escape_string(trim($_REQUEST["cat"])); |
28537341 | 1286 | |
a42c55f0 | 1287 | add_feed_category($feed_cat); |
28537341 AD |
1288 | } |
1289 | ||
afcfe6ca AD |
1290 | function index() { |
1291 | ||
1292 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; | |
1293 | print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">"; | |
1294 | ||
d9c85e0f | 1295 | $result = $this->dbh->query("SELECT COUNT(id) AS num_errors |
afcfe6ca AD |
1296 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
1297 | ||
d9c85e0f | 1298 | $num_errors = $this->dbh->fetch_result($result, 0, "num_errors"); |
afcfe6ca AD |
1299 | |
1300 | if ($num_errors > 0) { | |
1301 | ||
1302 | $error_button = "<button dojoType=\"dijit.form.Button\" | |
1303 | onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" . | |
1304 | __("Feeds with errors") . "</button>"; | |
1305 | } | |
1306 | ||
f9c1f8b0 AD |
1307 | $inactive_button = "<button dojoType=\"dijit.form.Button\" |
1308 | id=\"pref_feeds_inactive_btn\" | |
1309 | style=\"display : none\" | |
1310 | onclick=\"showInactiveFeeds()\">" . | |
1311 | __("Inactive feeds") . "</button>"; | |
afcfe6ca | 1312 | |
d9c85e0f | 1313 | $feed_search = $this->dbh->escape_string($_REQUEST["search"]); |
afcfe6ca AD |
1314 | |
1315 | if (array_key_exists("search", $_REQUEST)) { | |
1316 | $_SESSION["prefs_feed_search"] = $feed_search; | |
1317 | } else { | |
1318 | $feed_search = $_SESSION["prefs_feed_search"]; | |
1319 | } | |
1320 | ||
1321 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
1322 | ||
1323 | print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar | |
1324 | ||
1325 | print "<div style='float : right; padding-right : 4px;'> | |
1326 | <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\" | |
1327 | value=\"$feed_search\"> | |
1328 | <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">". | |
1329 | __('Search')."</button> | |
1330 | </div>"; | |
1331 | ||
1332 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1333 | "<span>" . __('Select')."</span>"; | |
1334 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1335 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" | |
1336 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1337 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" | |
1338 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1339 | print "</div></div>"; | |
1340 | ||
1341 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1342 | "<span>" . __('Feeds')."</span>"; | |
1343 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1344 | print "<div onclick=\"quickAddFeed()\" | |
1345 | dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>"; | |
1346 | print "<div onclick=\"editSelectedFeed()\" | |
1347 | dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>"; | |
1348 | print "<div onclick=\"resetFeedOrder()\" | |
1349 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
33f0fdd0 AD |
1350 | print "<div onclick=\"batchSubscribe()\" |
1351 | dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>"; | |
0671359f AD |
1352 | print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">" |
1353 | .__('Unsubscribe')."</div> "; | |
afcfe6ca AD |
1354 | print "</div></div>"; |
1355 | ||
a42c55f0 | 1356 | if (get_pref('ENABLE_FEED_CATS')) { |
afcfe6ca AD |
1357 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
1358 | "<span>" . __('Categories')."</span>"; | |
1359 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
5ef071e0 AD |
1360 | print "<div onclick=\"createCategory()\" |
1361 | dojoType=\"dijit.MenuItem\">".__('Add category')."</div>"; | |
afcfe6ca AD |
1362 | print "<div onclick=\"resetCatOrder()\" |
1363 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
fd26d5bf AD |
1364 | print "<div onclick=\"removeSelectedCategories()\" |
1365 | dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>"; | |
afcfe6ca AD |
1366 | print "</div></div>"; |
1367 | ||
1368 | } | |
1369 | ||
1370 | print $error_button; | |
1371 | print $inactive_button; | |
1372 | ||
afcfe6ca AD |
1373 | if (defined('_ENABLE_FEED_DEBUGGING')) { |
1374 | ||
1375 | print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\"> | |
1376 | <option value=\"facDefault\" selected>".__('More actions...')."</option>"; | |
1377 | ||
1378 | if (FORCE_ARTICLE_PURGE == 0) { | |
1379 | ||
1380 | "<option value=\"facPurge\">".__('Manual purge')."</option>"; | |
1381 | } | |
1382 | ||
1383 | print " | |
1384 | <option value=\"facClear\">".__('Clear feed data')."</option> | |
1385 | <option value=\"facRescore\">".__('Rescore articles')."</option>"; | |
1386 | ||
1387 | print "</select>"; | |
1388 | ||
1389 | } | |
1390 | ||
1391 | print "</div>"; # toolbar | |
1392 | ||
1393 | //print '</div>'; | |
1394 | print '<div dojoType="dijit.layout.ContentPane" region="center">'; | |
1395 | ||
1396 | print "<div id=\"feedlistLoading\"> | |
1397 | <img src='images/indicator_tiny.gif'>". | |
1398 | __("Loading, please wait...")."</div>"; | |
1399 | ||
1400 | print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" | |
1401 | url=\"backend.php?op=pref-feeds&method=getfeedtree\"> | |
1402 | </div> | |
1403 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\" | |
1404 | query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" | |
1405 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
1406 | </div> | |
1407 | <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\" | |
1408 | dndController=\"dijit.tree.dndSource\" | |
1409 | betweenThreshold=\"5\" | |
84012df5 | 1410 | autoExpand='true' |
afcfe6ca AD |
1411 | model=\"feedModel\" openOnClick=\"false\"> |
1412 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
1413 | var id = String(item.id); | |
1414 | var bare_id = id.substr(id.indexOf(':')+1); | |
1415 | ||
1416 | if (id.match('FEED:')) { | |
1417 | editFeed(bare_id); | |
1418 | } else if (id.match('CAT:')) { | |
1419 | editCat(bare_id, item); | |
1420 | } | |
1421 | </script> | |
1422 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
1423 | Element.hide(\"feedlistLoading\"); | |
f9c1f8b0 AD |
1424 | |
1425 | checkInactiveFeeds(); | |
afcfe6ca AD |
1426 | </script> |
1427 | </div>"; | |
1428 | ||
ba5296a1 AD |
1429 | # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\"> |
1430 | # ".__('<b>Hint:</b> you can drag feeds and categories around.')." | |
1431 | # </div>"; | |
afcfe6ca AD |
1432 | |
1433 | print '</div>'; | |
1434 | print '</div>'; | |
1435 | ||
1436 | print "</div>"; # feeds pane | |
1437 | ||
6c2637d9 | 1438 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">"; |
afcfe6ca | 1439 | |
73dfda1d AD |
1440 | print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . |
1441 | __("Only main settings profile can be migrated using OPML.") . "</p>"; | |
afcfe6ca | 1442 | |
55f34b81 | 1443 | print "<iframe id=\"upload_iframe\" |
afcfe6ca AD |
1444 | name=\"upload_iframe\" onload=\"opmlImportComplete(this)\" |
1445 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; | |
1446 | ||
1447 | print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\" | |
1448 | enctype=\"multipart/form-data\" method=\"POST\" | |
55f34b81 | 1449 | action=\"backend.php\"> |
afcfe6ca AD |
1450 | <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> |
1451 | <input type=\"hidden\" name=\"op\" value=\"dlg\"> | |
c4c74732 | 1452 | <input type=\"hidden\" name=\"method\" value=\"importOpml\"> |
afcfe6ca | 1453 | <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" . |
a1159c01 | 1454 | __('Import my OPML') . "</button>"; |
afcfe6ca | 1455 | |
a1159c01 | 1456 | print "<hr>"; |
afcfe6ca | 1457 | |
77e81006 AD |
1458 | $opml_export_filename = "TinyTinyRSS_".date("Y-m-d").".opml"; |
1459 | ||
afcfe6ca | 1460 | print "<p>" . __('Filename:') . |
77e81006 | 1461 | " <input type=\"text\" id=\"filename\" value=\"$opml_export_filename\" /> " . |
a1159c01 | 1462 | __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>"; |
afcfe6ca | 1463 | |
a1159c01 | 1464 | print "</p><button dojoType=\"dijit.form.Button\" |
afcfe6ca | 1465 | onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" . |
a1159c01 | 1466 | __('Export OPML') . "</button></p></form>"; |
afcfe6ca | 1467 | |
a1159c01 | 1468 | print "<hr>"; |
afcfe6ca | 1469 | |
73dfda1d | 1470 | print "<p>" . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . "</p>"; |
afcfe6ca | 1471 | |
73dfda1d | 1472 | print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds."); |
afcfe6ca | 1473 | |
fb54e3b1 | 1474 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". |
a1159c01 | 1475 | __('Display published OPML URL')."</button> "; |
afcfe6ca | 1476 | |
1ffe3391 | 1477 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
1478 | "hook_prefs_tab_section", "prefFeedsOPML"); |
1479 | ||
afcfe6ca AD |
1480 | print "</div>"; # pane |
1481 | ||
1482 | if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) { | |
1483 | ||
1484 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">"; | |
1485 | ||
11334fdf | 1486 | print_notice(__('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.')); |
afcfe6ca AD |
1487 | |
1488 | print "<p>"; | |
1489 | ||
1490 | print "<button onclick='window.navigator.registerContentHandler(" . | |
1491 | "\"application/vnd.mozilla.maybe.feed\", " . | |
1492 | "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" . | |
1493 | __('Click here to register this site as a feed reader.') . | |
1494 | "</button>"; | |
1495 | ||
1496 | print "</p>"; | |
1497 | ||
1498 | print "</div>"; # pane | |
1499 | } | |
1500 | ||
e95e7819 | 1501 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">"; |
afcfe6ca | 1502 | |
73dfda1d | 1503 | print "<p>" . __('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.') . "</p>"; |
afcfe6ca AD |
1504 | |
1505 | $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . | |
1506 | "/public.php?op=rss&id=-2&view-mode=all_articles");; | |
1507 | ||
11334fdf AD |
1508 | print "<p>"; |
1509 | ||
fb54e3b1 | 1510 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">". |
afcfe6ca AD |
1511 | __('Display URL')."</button> "; |
1512 | ||
73dfda1d | 1513 | print "<button class=\"warning\" dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">". |
afcfe6ca AD |
1514 | __('Clear all generated URLs')."</button> "; |
1515 | ||
11334fdf | 1516 | print "</p>"; |
afcfe6ca | 1517 | |
1ffe3391 | 1518 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
699daf58 AD |
1519 | "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); |
1520 | ||
afcfe6ca AD |
1521 | print "</div>"; #pane |
1522 | ||
1ffe3391 | 1523 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
6065f3ad AD |
1524 | "hook_prefs_tab", "prefFeeds"); |
1525 | ||
afcfe6ca | 1526 | print "</div>"; #container |
afcfe6ca | 1527 | } |
2ecd2df5 | 1528 | |
88918ca6 | 1529 | private function feedlist_init_cat($cat_id) { |
2ecd2df5 AD |
1530 | $obj = array(); |
1531 | $cat_id = (int) $cat_id; | |
1532 | ||
1533 | if ($cat_id > 0) { | |
2ed0d6c4 | 1534 | $cat_unread = CCache::find($cat_id, $_SESSION["uid"], true); |
2ecd2df5 | 1535 | } else if ($cat_id == 0 || $cat_id == -2) { |
86a8351c | 1536 | $cat_unread = Feeds::getCategoryUnread($cat_id); |
2ecd2df5 AD |
1537 | } |
1538 | ||
1539 | $obj['id'] = 'CAT:' . $cat_id; | |
1540 | $obj['items'] = array(); | |
a230bf88 | 1541 | $obj['name'] = Feeds::getCategoryTitle($cat_id); |
2ecd2df5 AD |
1542 | $obj['type'] = 'category'; |
1543 | $obj['unread'] = (int) $cat_unread; | |
2ecd2df5 AD |
1544 | $obj['bare_id'] = $cat_id; |
1545 | ||
1546 | return $obj; | |
1547 | } | |
1548 | ||
1549 | private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { | |
1550 | $obj = array(); | |
1551 | $feed_id = (int) $feed_id; | |
1552 | ||
1553 | if (!$title) | |
86a8351c | 1554 | $title = Feeds::getFeedTitle($feed_id, false); |
2ecd2df5 AD |
1555 | |
1556 | if ($unread === false) | |
a42c55f0 | 1557 | $unread = getFeedUnread($feed_id, false); |
2ecd2df5 AD |
1558 | |
1559 | $obj['id'] = 'FEED:' . $feed_id; | |
1560 | $obj['name'] = $title; | |
1561 | $obj['unread'] = (int) $unread; | |
1562 | $obj['type'] = 'feed'; | |
1563 | $obj['error'] = $error; | |
1564 | $obj['updated'] = $updated; | |
86a8351c | 1565 | $obj['icon'] = Feeds::getFeedIcon($feed_id); |
2ecd2df5 | 1566 | $obj['bare_id'] = $feed_id; |
c594eca0 | 1567 | $obj['auxcounter'] = 0; |
2ecd2df5 AD |
1568 | |
1569 | return $obj; | |
1570 | } | |
1571 | ||
bc6fa236 AD |
1572 | function inactiveFeeds() { |
1573 | ||
1574 | if (DB_TYPE == "pgsql") { | |
1575 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1576 | } else { | |
1577 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1578 | } | |
1579 | ||
d9c85e0f | 1580 | $result = $this->dbh->query("SELECT ttrss_feeds.title, ttrss_feeds.site_url, |
bc6fa236 AD |
1581 | ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article |
1582 | FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE | |
1583 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE | |
1584 | ttrss_entries.id = ref_id AND | |
1585 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart | |
1586 | AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND | |
1587 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
1588 | ttrss_entries.id = ref_id | |
1589 | GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url | |
1590 | ORDER BY last_article"); | |
1591 | ||
11334fdf | 1592 | print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>"; |
bc6fa236 AD |
1593 | |
1594 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1595 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1596 | "<span>" . __('Select')."</span>"; | |
1597 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1598 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\" | |
1599 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1600 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\" | |
1601 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1602 | print "</div></div>"; | |
1603 | print "</div>"; #toolbar | |
1604 | ||
1605 | print "<div class=\"inactiveFeedHolder\">"; | |
1606 | ||
1607 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">"; | |
1608 | ||
1609 | $lnum = 1; | |
1610 | ||
d9c85e0f | 1611 | while ($line = $this->dbh->fetch_assoc($result)) { |
bc6fa236 | 1612 | |
bc6fa236 AD |
1613 | $feed_id = $line["id"]; |
1614 | $this_row_id = "id=\"FUPDD-$feed_id\""; | |
1615 | ||
1616 | # class needed for selectTableRows() | |
1617 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1618 | ||
bc6fa236 AD |
1619 | # id needed for selectTableRows() |
1620 | print "<td width='5%' align='center'><input | |
1621 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1622 | type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>"; | |
1623 | print "<td>"; | |
1624 | ||
1625 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1626 | "title=\"".__("Click to edit feed")."\" ". | |
1627 | "onclick=\"editFeed(".$line["id"].")\">". | |
1628 | htmlspecialchars($line["title"])."</a>"; | |
1629 | ||
1630 | print "</td><td class=\"insensitive\" align='right'>"; | |
a42c55f0 | 1631 | print make_local_datetime($line['last_article'], false); |
bc6fa236 AD |
1632 | print "</td>"; |
1633 | print "</tr>"; | |
1634 | ||
1635 | ++$lnum; | |
1636 | } | |
1637 | ||
1638 | print "</table>"; | |
1639 | print "</div>"; | |
1640 | ||
1641 | print "<div class='dlgButtons'>"; | |
1642 | print "<div style='float : left'>"; | |
73dfda1d | 1643 | print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" |
bc6fa236 AD |
1644 | .__('Unsubscribe from selected feeds')."</button> "; |
1645 | print "</div>"; | |
1646 | ||
1647 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">". | |
1648 | __('Close this window')."</button>"; | |
1649 | ||
1650 | print "</div>"; | |
1651 | ||
1652 | } | |
1653 | ||
1654 | function feedsWithErrors() { | |
d9c85e0f | 1655 | $result = $this->dbh->query("SELECT id,title,feed_url,last_error,site_url |
bc6fa236 AD |
1656 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
1657 | ||
1658 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1659 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1660 | "<span>" . __('Select')."</span>"; | |
1661 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1662 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\" | |
1663 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1664 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\" | |
1665 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1666 | print "</div></div>"; | |
1667 | print "</div>"; #toolbar | |
1668 | ||
1669 | print "<div class=\"inactiveFeedHolder\">"; | |
1670 | ||
1671 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">"; | |
1672 | ||
1673 | $lnum = 1; | |
1674 | ||
d9c85e0f | 1675 | while ($line = $this->dbh->fetch_assoc($result)) { |
bc6fa236 | 1676 | |
bc6fa236 AD |
1677 | $feed_id = $line["id"]; |
1678 | $this_row_id = "id=\"FERDD-$feed_id\""; | |
1679 | ||
1680 | # class needed for selectTableRows() | |
1681 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1682 | ||
bc6fa236 AD |
1683 | # id needed for selectTableRows() |
1684 | print "<td width='5%' align='center'><input | |
1685 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1686 | type=\"checkbox\" id=\"FERDC-$feed_id\"></td>"; | |
1687 | print "<td>"; | |
1688 | ||
1689 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1690 | "title=\"".__("Click to edit feed")."\" ". | |
1691 | "onclick=\"editFeed(".$line["id"].")\">". | |
1692 | htmlspecialchars($line["title"])."</a>: "; | |
1693 | ||
1694 | print "<span class=\"insensitive\">"; | |
1695 | print htmlspecialchars($line["last_error"]); | |
1696 | print "</span>"; | |
1697 | ||
1698 | print "</td>"; | |
1699 | print "</tr>"; | |
1700 | ||
1701 | ++$lnum; | |
1702 | } | |
1703 | ||
1704 | print "</table>"; | |
1705 | print "</div>"; | |
1706 | ||
1707 | print "<div class='dlgButtons'>"; | |
1708 | print "<div style='float : left'>"; | |
73dfda1d | 1709 | print "<button class=\"danger\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" |
bc6fa236 AD |
1710 | .__('Unsubscribe from selected feeds')."</button> "; |
1711 | print "</div>"; | |
1712 | ||
1713 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". | |
1714 | __('Close this window')."</button>"; | |
1715 | ||
1716 | print "</div>"; | |
1717 | } | |
1718 | ||
87d7e850 AD |
1719 | /** |
1720 | * Purge a feed contents, marked articles excepted. | |
1721 | * | |
1722 | * @param mixed $link The database connection. | |
1723 | * @param integer $id The id of the feed to purge. | |
1724 | * @return void | |
1725 | */ | |
6322ac79 | 1726 | private function clear_feed_articles($id) { |
87d7e850 AD |
1727 | |
1728 | if ($id != 0) { | |
d9c85e0f | 1729 | $result = $this->dbh->query("DELETE FROM ttrss_user_entries |
87d7e850 AD |
1730 | WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]); |
1731 | } else { | |
d9c85e0f | 1732 | $result = $this->dbh->query("DELETE FROM ttrss_user_entries |
87d7e850 AD |
1733 | WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]); |
1734 | } | |
1735 | ||
d9c85e0f | 1736 | $result = $this->dbh->query("DELETE FROM ttrss_entries WHERE |
87d7e850 AD |
1737 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); |
1738 | ||
2ed0d6c4 | 1739 | CCache::update($id, $_SESSION['uid']); |
87d7e850 AD |
1740 | } // function clear_feed_articles |
1741 | ||
a42c55f0 | 1742 | private function remove_feed_category($id, $owner_uid) { |
a6a9b812 | 1743 | |
d9c85e0f | 1744 | $this->dbh->query("DELETE FROM ttrss_feed_categories |
a6a9b812 AD |
1745 | WHERE id = '$id' AND owner_uid = $owner_uid"); |
1746 | ||
2ed0d6c4 | 1747 | CCache::remove($id, $owner_uid, true); |
a6a9b812 AD |
1748 | } |
1749 | ||
a42c55f0 | 1750 | static function remove_feed($id, $owner_uid) { |
a6a9b812 AD |
1751 | |
1752 | if ($id > 0) { | |
1753 | ||
1754 | /* save starred articles in Archived feed */ | |
1755 | ||
a42c55f0 | 1756 | db_query("BEGIN"); |
a6a9b812 AD |
1757 | |
1758 | /* prepare feed if necessary */ | |
1759 | ||
a42c55f0 | 1760 | $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = $id |
aa5ac2cd AD |
1761 | AND owner_uid = $owner_uid"); |
1762 | ||
a42c55f0 | 1763 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); |
aa5ac2cd | 1764 | |
a42c55f0 | 1765 | $result = db_query("SELECT id FROM ttrss_archived_feeds |
aa5ac2cd | 1766 | WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid"); |
a6a9b812 AD |
1767 | |
1768 | if (db_num_rows($result) == 0) { | |
a42c55f0 | 1769 | $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); |
b1df14d0 AD |
1770 | $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1; |
1771 | ||
a42c55f0 | 1772 | db_query("INSERT INTO ttrss_archived_feeds |
a6a9b812 | 1773 | (id, owner_uid, title, feed_url, site_url) |
b1df14d0 | 1774 | SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds |
aa5ac2cd AD |
1775 | WHERE id = '$id'"); |
1776 | ||
b1df14d0 | 1777 | $archive_id = $new_feed_id; |
aa5ac2cd AD |
1778 | } else { |
1779 | $archive_id = db_fetch_result($result, 0, "id"); | |
a6a9b812 AD |
1780 | } |
1781 | ||
a42c55f0 | 1782 | db_query("UPDATE ttrss_user_entries SET feed_id = NULL, |
aa5ac2cd | 1783 | orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND |
a6a9b812 AD |
1784 | marked = true AND owner_uid = $owner_uid"); |
1785 | ||
1786 | /* Remove access key for the feed */ | |
1787 | ||
a42c55f0 | 1788 | db_query("DELETE FROM ttrss_access_keys WHERE |
a6a9b812 AD |
1789 | feed_id = '$id' AND owner_uid = $owner_uid"); |
1790 | ||
1791 | /* remove the feed */ | |
1792 | ||
a42c55f0 | 1793 | db_query("DELETE FROM ttrss_feeds |
a6a9b812 AD |
1794 | WHERE id = '$id' AND owner_uid = $owner_uid"); |
1795 | ||
a42c55f0 | 1796 | db_query("COMMIT"); |
a6a9b812 AD |
1797 | |
1798 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
1799 | unlink(ICONS_DIR . "/$id.ico"); | |
1800 | } | |
1801 | ||
2ed0d6c4 | 1802 | CCache::remove($id, $owner_uid); |
a6a9b812 AD |
1803 | |
1804 | } else { | |
7c9b5a3f | 1805 | Labels::remove(Labels::feed_to_label_id($id), $owner_uid); |
2ed0d6c4 | 1806 | //CCache::remove($id, $owner_uid); don't think labels are cached |
a6a9b812 AD |
1807 | } |
1808 | } | |
87d7e850 | 1809 | |
201bb1ca | 1810 | function batchSubscribe() { |
328118d1 AD |
1811 | print_hidden("op", "pref-feeds"); |
1812 | print_hidden("method", "batchaddfeeds"); | |
201bb1ca AD |
1813 | |
1814 | print "<table width='100%'><tr><td> | |
1815 | ".__("Add one valid RSS feed per line (no feed detection is done)")." | |
1816 | </td><td align='right'>"; | |
a42c55f0 | 1817 | if (get_pref('ENABLE_FEED_CATS')) { |
201bb1ca | 1818 | print __('Place in category:') . " "; |
a42c55f0 | 1819 | print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); |
201bb1ca AD |
1820 | } |
1821 | print "</td></tr><tr><td colspan='2'>"; | |
1822 | print "<textarea | |
fb8a032a | 1823 | style='font-size : 12px; width : 98%; height: 200px;' |
201bb1ca AD |
1824 | placeHolder=\"".__("Feeds to subscribe, One per line")."\" |
1825 | dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>"; | |
1826 | ||
1827 | print "</td></tr><tr><td colspan='2'>"; | |
1828 | ||
1829 | print "<div id='feedDlg_loginContainer' style='display : none'> | |
1830 | " . | |
1831 | " <input dojoType=\"dijit.form.TextBox\" name='login'\" | |
1832 | placeHolder=\"".__("Login")."\" | |
1833 | style=\"width : 10em;\"> ". | |
1834 | " <input | |
1835 | placeHolder=\"".__("Password")."\" | |
1836 | dojoType=\"dijit.form.TextBox\" type='password' | |
ec21abb8 | 1837 | autocomplete=\"new-password\" |
201bb1ca AD |
1838 | style=\"width : 10em;\" name='pass'\">". |
1839 | "</div>"; | |
1840 | ||
1841 | print "</td></tr><tr><td colspan='2'>"; | |
1842 | ||
1843 | print "<div style=\"clear : both\"> | |
1844 | <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\" | |
1845 | onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'> | |
1846 | <label for=\"feedDlg_loginCheck\">". | |
1847 | __('Feeds require authentication.')."</div>"; | |
1848 | ||
1849 | print "</form>"; | |
1850 | ||
1851 | print "</td></tr></table>"; | |
1852 | ||
1853 | print "<div class=\"dlgButtons\"> | |
1854 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button> | |
1855 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button> | |
1856 | </div>"; | |
1857 | } | |
1858 | ||
96e3ae8c | 1859 | function batchAddFeeds() { |
d9c85e0f | 1860 | $cat_id = $this->dbh->escape_string($_REQUEST['cat']); |
2714d5ca | 1861 | $feeds = explode("\n", $_REQUEST['feeds']); |
d9c85e0f | 1862 | $login = $this->dbh->escape_string($_REQUEST['login']); |
41694a95 | 1863 | $pass = trim($_REQUEST['pass']); |
96e3ae8c AD |
1864 | |
1865 | foreach ($feeds as $feed) { | |
d9c85e0f | 1866 | $feed = $this->dbh->escape_string(trim($feed)); |
96e3ae8c AD |
1867 | |
1868 | if (validate_feed_url($feed)) { | |
1869 | ||
d9c85e0f | 1870 | $this->dbh->query("BEGIN"); |
96e3ae8c AD |
1871 | |
1872 | if ($cat_id == "0" || !$cat_id) { | |
1873 | $cat_qpart = "NULL"; | |
1874 | } else { | |
1875 | $cat_qpart = "'$cat_id'"; | |
1876 | } | |
1877 | ||
d9c85e0f | 1878 | $result = $this->dbh->query( |
96e3ae8c AD |
1879 | "SELECT id FROM ttrss_feeds |
1880 | WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
1881 | ||
17a8e61d | 1882 | $auth_pass_encrypted = 'false'; |
d9c85e0f | 1883 | $pass = $this->dbh->escape_string($pass); |
41694a95 | 1884 | |
d9c85e0f AD |
1885 | if ($this->dbh->num_rows($result) == 0) { |
1886 | $result = $this->dbh->query( | |
96e3ae8c | 1887 | "INSERT INTO ttrss_feeds |
044cff2d | 1888 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) |
96e3ae8c | 1889 | VALUES ('".$_SESSION["uid"]."', '$feed', |
044cff2d | 1890 | '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)"); |
96e3ae8c AD |
1891 | } |
1892 | ||
d9c85e0f | 1893 | $this->dbh->query("COMMIT"); |
96e3ae8c AD |
1894 | } |
1895 | } | |
1896 | } | |
201bb1ca | 1897 | |
195187c4 | 1898 | function regenOPMLKey() { |
a42c55f0 | 1899 | $this->update_feed_access_key('OPML:Publish', |
195187c4 AD |
1900 | false, $_SESSION["uid"]); |
1901 | ||
6322ac79 | 1902 | $new_link = Opml::opml_publish_url(); |
195187c4 AD |
1903 | |
1904 | print json_encode(array("link" => $new_link)); | |
1905 | } | |
1906 | ||
1907 | function regenFeedKey() { | |
d9c85e0f AD |
1908 | $feed_id = $this->dbh->escape_string($_REQUEST['id']); |
1909 | $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true"; | |
195187c4 | 1910 | |
a42c55f0 | 1911 | $new_key = $this->update_feed_access_key($feed_id, $is_cat); |
195187c4 AD |
1912 | |
1913 | print json_encode(array("link" => $new_key)); | |
1914 | } | |
1915 | ||
1916 | ||
a42c55f0 | 1917 | private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
195187c4 AD |
1918 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
1919 | ||
1920 | $sql_is_cat = bool_to_sql_bool($is_cat); | |
1921 | ||
d9c85e0f | 1922 | $result = $this->dbh->query("SELECT access_key FROM ttrss_access_keys |
195187c4 AD |
1923 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat |
1924 | AND owner_uid = " . $owner_uid); | |
1925 | ||
d9c85e0f | 1926 | if ($this->dbh->num_rows($result) == 1) { |
3ceb893f | 1927 | $key = $this->dbh->escape_string(uniqid_short()); |
195187c4 | 1928 | |
d9c85e0f | 1929 | $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key' |
195187c4 AD |
1930 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat |
1931 | AND owner_uid = " . $owner_uid); | |
1932 | ||
1933 | return $key; | |
1934 | ||
1935 | } else { | |
a42c55f0 | 1936 | return get_feed_access_key($feed_id, $is_cat, $owner_uid); |
195187c4 AD |
1937 | } |
1938 | } | |
1939 | ||
1940 | // Silent | |
1941 | function clearKeys() { | |
d9c85e0f | 1942 | $this->dbh->query("DELETE FROM ttrss_access_keys WHERE |
195187c4 AD |
1943 | owner_uid = " . $_SESSION["uid"]); |
1944 | } | |
1945 | ||
496195db AD |
1946 | private function calculate_children_count($cat) { |
1947 | $c = 0; | |
1948 | ||
1949 | foreach ($cat['items'] as $child) { | |
1950 | if ($child['type'] == 'category') { | |
1951 | $c += $this->calculate_children_count($child); | |
1952 | } else { | |
1953 | $c += 1; | |
1954 | } | |
1955 | } | |
1956 | ||
1957 | return $c; | |
1958 | } | |
195187c4 | 1959 | |
f9c1f8b0 AD |
1960 | function getinactivefeeds() { |
1961 | if (DB_TYPE == "pgsql") { | |
1962 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1963 | } else { | |
1964 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1965 | } | |
1966 | ||
1967 | $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE | |
1968 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE | |
1969 | ttrss_entries.id = ref_id AND | |
1970 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND | |
1971 | ttrss_feeds.owner_uid = ".$_SESSION["uid"]); | |
1972 | ||
1973 | print (int) $this->dbh->fetch_result($result, 0, "num_inactive"); | |
1974 | } | |
ea79a0e0 | 1975 | } |