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