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