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