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