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