]>
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 " <span title=\"".htmlspecialchars($last_error)."\" | |
576 | class=\"feed_error\">(error)</span>"; | |
577 | ||
578 | } | |
579 | ||
580 | /* Category */ | |
581 | ||
582 | if (get_pref('ENABLE_FEED_CATS')) { | |
583 | ||
584 | $cat_id = $this->dbh->fetch_result($result, 0, "cat_id"); | |
585 | ||
586 | print "<hr/>"; | |
587 | ||
588 | print __('Place in category:') . " "; | |
589 | ||
590 | print_feed_cat_select("cat_id", $cat_id, | |
591 | 'dojoType="dijit.form.Select"'); | |
592 | } | |
593 | ||
594 | print "</div>"; | |
595 | ||
596 | print "<div class=\"dlgSec\">".__("Update")."</div>"; | |
597 | print "<div class=\"dlgSecCont\">"; | |
598 | ||
599 | /* Update Interval */ | |
600 | ||
601 | $update_interval = $this->dbh->fetch_result($result, 0, "update_interval"); | |
602 | ||
603 | print_select_hash("update_interval", $update_interval, $update_intervals, | |
604 | 'dojoType="dijit.form.Select"'); | |
605 | ||
606 | /* Purge intl */ | |
607 | ||
608 | $purge_interval = $this->dbh->fetch_result($result, 0, "purge_interval"); | |
609 | ||
610 | print "<hr/>"; | |
611 | print __('Article purging:') . " "; | |
612 | ||
613 | print_select_hash("purge_interval", $purge_interval, $purge_intervals, | |
614 | 'dojoType="dijit.form.Select" ' . | |
615 | ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); | |
616 | ||
617 | print "</div>"; | |
618 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
619 | print "<div class=\"dlgSecCont\">"; | |
620 | ||
621 | $auth_login = htmlspecialchars($this->dbh->fetch_result($result, 0, "auth_login")); | |
622 | ||
623 | print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\" | |
624 | placeHolder=\"".__("Login")."\" | |
625 | name=\"auth_login\" value=\"$auth_login\"><hr/>"; | |
626 | ||
627 | $auth_pass = $this->dbh->fetch_result($result, 0, "auth_pass"); | |
628 | ||
629 | if ($auth_pass_encrypted) { | |
630 | require_once "crypt.php"; | |
631 | $auth_pass = decrypt_string($auth_pass); | |
632 | } | |
633 | ||
634 | $auth_pass = htmlspecialchars($auth_pass); | |
635 | ||
636 | print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" | |
637 | placeHolder=\"".__("Password")."\" | |
638 | value=\"$auth_pass\">"; | |
639 | ||
640 | print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\"> | |
641 | ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')." | |
642 | </div>"; | |
643 | ||
644 | print "</div>"; | |
645 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
646 | print "<div class=\"dlgSecCont\">"; | |
647 | ||
648 | $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private")); | |
649 | ||
650 | if ($private) { | |
651 | $checked = "checked=\"1\""; | |
652 | } else { | |
653 | $checked = ""; | |
654 | } | |
655 | ||
656 | print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\" | |
657 | $checked> <label for=\"private\">".__('Hide from Popular feeds')."</label>"; | |
658 | ||
659 | $include_in_digest = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "include_in_digest")); | |
660 | ||
661 | if ($include_in_digest) { | |
662 | $checked = "checked=\"1\""; | |
663 | } else { | |
664 | $checked = ""; | |
665 | } | |
666 | ||
667 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" | |
668 | name=\"include_in_digest\" | |
669 | $checked> <label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
670 | ||
671 | ||
672 | $always_display_enclosures = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "always_display_enclosures")); | |
673 | ||
674 | if ($always_display_enclosures) { | |
675 | $checked = "checked"; | |
676 | } else { | |
677 | $checked = ""; | |
678 | } | |
679 | ||
680 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" | |
681 | name=\"always_display_enclosures\" | |
682 | $checked> <label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
683 | ||
684 | $hide_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "hide_images")); | |
685 | ||
686 | if ($hide_images) { | |
687 | $checked = "checked=\"1\""; | |
688 | } else { | |
689 | $checked = ""; | |
690 | } | |
691 | ||
692 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"hide_images\" | |
693 | name=\"hide_images\" | |
694 | $checked> <label for=\"hide_images\">". | |
695 | __('Do not embed images')."</label>"; | |
696 | ||
697 | $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images")); | |
698 | ||
699 | if ($cache_images) { | |
700 | $checked = "checked=\"1\""; | |
701 | } else { | |
702 | $checked = ""; | |
703 | } | |
704 | ||
705 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\" | |
706 | name=\"cache_images\" | |
707 | $checked> <label for=\"cache_images\">". | |
708 | __('Cache images locally')."</label>"; | |
709 | ||
710 | $mark_unread_on_update = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "mark_unread_on_update")); | |
711 | ||
712 | if ($mark_unread_on_update) { | |
713 | $checked = "checked"; | |
714 | } else { | |
715 | $checked = ""; | |
716 | } | |
717 | ||
718 | print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\" | |
719 | name=\"mark_unread_on_update\" | |
720 | $checked> <label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
721 | ||
722 | print "</div>"; | |
723 | ||
724 | /* Icon */ | |
725 | ||
726 | print "<div class=\"dlgSec\">".__("Icon")."</div>"; | |
727 | print "<div class=\"dlgSecCont\">"; | |
728 | ||
729 | print "<iframe name=\"icon_upload_iframe\" | |
730 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; | |
731 | ||
732 | print "<form style='display : block' target=\"icon_upload_iframe\" | |
733 | enctype=\"multipart/form-data\" method=\"POST\" | |
734 | action=\"backend.php\"> | |
735 | <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\"> | |
736 | <input type=\"hidden\" name=\"op\" value=\"pref-feeds\"> | |
737 | <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\"> | |
738 | <input type=\"hidden\" name=\"method\" value=\"uploadicon\"> | |
739 | <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\" | |
740 | type=\"submit\">".__('Replace')."</button> | |
741 | <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\" | |
742 | type=\"submit\">".__('Remove')."</button> | |
743 | </form>"; | |
744 | ||
745 | print "</div>"; | |
746 | ||
747 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, | |
748 | "hook_prefs_edit_feed", $feed_id); | |
749 | ||
750 | $title = htmlspecialchars($title, ENT_QUOTES); | |
751 | ||
752 | print "<div class='dlgButtons'> | |
753 | <div style=\"float : left\"> | |
754 | <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>". | |
755 | __('Unsubscribe')."</button>"; | |
756 | ||
757 | if (PUBSUBHUBBUB_ENABLED) { | |
758 | $pubsub_state = $this->dbh->fetch_result($result, 0, "pubsub_state"); | |
759 | $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\""; | |
760 | ||
761 | print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" $pubsub_btn_disabled | |
762 | onclick='return resetPubSub($feed_id, \"$title\")'>".__('Resubscribe to push updates'). | |
763 | "</button>"; | |
764 | } | |
765 | ||
766 | print "</div>"; | |
767 | ||
768 | print "<div dojoType=\"dijit.Tooltip\" connectId=\"pubsubReset_Btn\" position=\"below\">". | |
769 | __('Resets PubSubHubbub subscription status for push-enabled feeds.')."</div>"; | |
770 | ||
771 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button> | |
772 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button> | |
773 | </div>"; | |
774 | ||
775 | return; | |
776 | } | |
777 | ||
778 | function editfeeds() { | |
779 | global $purge_intervals; | |
780 | global $update_intervals; | |
781 | ||
782 | $feed_ids = $this->dbh->escape_string($_REQUEST["ids"]); | |
783 | ||
784 | print_notice("Enable the options you wish to apply using checkboxes on the right:"); | |
785 | ||
786 | print "<p>"; | |
787 | ||
788 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">"; | |
789 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; | |
790 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchEditSave\">"; | |
791 | ||
792 | print "<div class=\"dlgSec\">".__("Feed")."</div>"; | |
793 | print "<div class=\"dlgSecCont\">"; | |
794 | ||
795 | /* Category */ | |
796 | ||
797 | if (get_pref('ENABLE_FEED_CATS')) { | |
798 | ||
799 | print __('Place in category:') . " "; | |
800 | ||
801 | print_feed_cat_select("cat_id", false, | |
802 | 'disabled="1" dojoType="dijit.form.Select"'); | |
803 | ||
804 | $this->batch_edit_cbox("cat_id"); | |
805 | ||
806 | } | |
807 | ||
808 | print "</div>"; | |
809 | ||
810 | print "<div class=\"dlgSec\">".__("Update")."</div>"; | |
811 | print "<div class=\"dlgSecCont\">"; | |
812 | ||
813 | /* Update Interval */ | |
814 | ||
815 | print_select_hash("update_interval", "", $update_intervals, | |
816 | 'disabled="1" dojoType="dijit.form.Select"'); | |
817 | ||
818 | $this->batch_edit_cbox("update_interval"); | |
819 | ||
820 | /* Purge intl */ | |
821 | ||
822 | if (FORCE_ARTICLE_PURGE == 0) { | |
823 | ||
824 | print "<br/>"; | |
825 | ||
826 | print __('Article purging:') . " "; | |
827 | ||
828 | print_select_hash("purge_interval", "", $purge_intervals, | |
829 | 'disabled="1" dojoType="dijit.form.Select"'); | |
830 | ||
831 | $this->batch_edit_cbox("purge_interval"); | |
832 | } | |
833 | ||
834 | print "</div>"; | |
835 | print "<div class=\"dlgSec\">".__("Authentication")."</div>"; | |
836 | print "<div class=\"dlgSecCont\">"; | |
837 | ||
838 | print "<input dojoType=\"dijit.form.TextBox\" | |
839 | placeHolder=\"".__("Login")."\" disabled=\"1\" | |
840 | name=\"auth_login\" value=\"\">"; | |
841 | ||
842 | $this->batch_edit_cbox("auth_login"); | |
843 | ||
844 | print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" | |
845 | placeHolder=\"".__("Password")."\" disabled=\"1\" | |
846 | value=\"\">"; | |
847 | ||
848 | $this->batch_edit_cbox("auth_pass"); | |
849 | ||
850 | print "</div>"; | |
851 | print "<div class=\"dlgSec\">".__("Options")."</div>"; | |
852 | print "<div class=\"dlgSecCont\">"; | |
853 | ||
854 | print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\" | |
855 | dojoType=\"dijit.form.CheckBox\"> <label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>"; | |
856 | ||
857 | print " "; $this->batch_edit_cbox("private", "private_l"); | |
858 | ||
859 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\" | |
860 | name=\"include_in_digest\" | |
861 | dojoType=\"dijit.form.CheckBox\"> <label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; | |
862 | ||
863 | print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); | |
864 | ||
865 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\" | |
866 | name=\"always_display_enclosures\" | |
867 | dojoType=\"dijit.form.CheckBox\"> <label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; | |
868 | ||
869 | print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); | |
870 | ||
871 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"hide_images\" | |
872 | name=\"hide_images\" | |
873 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"hide_images_l\" | |
874 | for=\"hide_images\">". | |
875 | __('Do not embed images')."</label>"; | |
876 | ||
877 | print " "; $this->batch_edit_cbox("hide_images", "hide_images_l"); | |
878 | ||
879 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\" | |
880 | name=\"cache_images\" | |
881 | dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"cache_images_l\" | |
882 | for=\"cache_images\">". | |
883 | __('Cache images locally')."</label>"; | |
884 | ||
885 | print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); | |
886 | ||
887 | print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\" | |
888 | name=\"mark_unread_on_update\" | |
889 | dojoType=\"dijit.form.CheckBox\"> <label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; | |
890 | ||
891 | print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); | |
892 | ||
893 | print "</div>"; | |
894 | ||
895 | print "<div class='dlgButtons'> | |
896 | <button dojoType=\"dijit.form.Button\" | |
897 | onclick=\"return dijit.byId('feedEditDlg').execute()\">". | |
898 | __('Save')."</button> | |
899 | <button dojoType=\"dijit.form.Button\" | |
900 | onclick=\"return dijit.byId('feedEditDlg').hide()\">". | |
901 | __('Cancel')."</button> | |
902 | </div>"; | |
903 | ||
904 | return; | |
905 | } | |
906 | ||
907 | function batchEditSave() { | |
908 | return $this->editsaveops(true); | |
909 | } | |
910 | ||
911 | function editSave() { | |
912 | return $this->editsaveops(false); | |
913 | } | |
914 | ||
915 | function editsaveops($batch) { | |
916 | ||
917 | $feed_title = $this->dbh->escape_string(trim($_POST["title"])); | |
918 | $feed_link = $this->dbh->escape_string(trim($_POST["feed_url"])); | |
919 | $upd_intl = (int) $this->dbh->escape_string($_POST["update_interval"]); | |
920 | $purge_intl = (int) $this->dbh->escape_string($_POST["purge_interval"]); | |
921 | $feed_id = (int) $this->dbh->escape_string($_POST["id"]); /* editSave */ | |
922 | $feed_ids = $this->dbh->escape_string($_POST["ids"]); /* batchEditSave */ | |
923 | $cat_id = (int) $this->dbh->escape_string($_POST["cat_id"]); | |
924 | $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"])); | |
925 | $auth_pass = trim($_POST["auth_pass"]); | |
926 | $private = checkbox_to_sql_bool($this->dbh->escape_string($_POST["private"])); | |
927 | $include_in_digest = checkbox_to_sql_bool( | |
928 | $this->dbh->escape_string($_POST["include_in_digest"])); | |
929 | $cache_images = checkbox_to_sql_bool( | |
930 | $this->dbh->escape_string($_POST["cache_images"])); | |
931 | $hide_images = checkbox_to_sql_bool( | |
932 | $this->dbh->escape_string($_POST["hide_images"])); | |
933 | $always_display_enclosures = checkbox_to_sql_bool( | |
934 | $this->dbh->escape_string($_POST["always_display_enclosures"])); | |
935 | ||
936 | $mark_unread_on_update = checkbox_to_sql_bool( | |
937 | $this->dbh->escape_string($_POST["mark_unread_on_update"])); | |
938 | ||
939 | if (strlen(FEED_CRYPT_KEY) > 0) { | |
940 | require_once "crypt.php"; | |
941 | $auth_pass = substr(encrypt_string($auth_pass), 0, 250); | |
942 | $auth_pass_encrypted = 'true'; | |
943 | } else { | |
944 | $auth_pass_encrypted = 'false'; | |
945 | } | |
946 | ||
947 | $auth_pass = $this->dbh->escape_string($auth_pass); | |
948 | ||
949 | if (get_pref('ENABLE_FEED_CATS')) { | |
950 | if ($cat_id && $cat_id != 0) { | |
951 | $category_qpart = "cat_id = '$cat_id',"; | |
952 | $category_qpart_nocomma = "cat_id = '$cat_id'"; | |
953 | } else { | |
954 | $category_qpart = 'cat_id = NULL,'; | |
955 | $category_qpart_nocomma = 'cat_id = NULL'; | |
956 | } | |
957 | } else { | |
958 | $category_qpart = ""; | |
959 | $category_qpart_nocomma = ""; | |
960 | } | |
961 | ||
962 | if (!$batch) { | |
963 | ||
964 | $result = $this->dbh->query("UPDATE ttrss_feeds SET | |
965 | $category_qpart | |
966 | title = '$feed_title', feed_url = '$feed_link', | |
967 | update_interval = '$upd_intl', | |
968 | purge_interval = '$purge_intl', | |
969 | auth_login = '$auth_login', | |
970 | auth_pass = '$auth_pass', | |
971 | auth_pass_encrypted = $auth_pass_encrypted, | |
972 | private = $private, | |
973 | cache_images = $cache_images, | |
974 | hide_images = $hide_images, | |
975 | include_in_digest = $include_in_digest, | |
976 | always_display_enclosures = $always_display_enclosures, | |
977 | mark_unread_on_update = $mark_unread_on_update | |
978 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
979 | ||
980 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, | |
981 | "hook_prefs_save_feed", $feed_id); | |
982 | ||
983 | } else { | |
984 | $feed_data = array(); | |
985 | ||
986 | foreach (array_keys($_POST) as $k) { | |
987 | if ($k != "op" && $k != "method" && $k != "ids") { | |
988 | $feed_data[$k] = $_POST[$k]; | |
989 | } | |
990 | } | |
991 | ||
992 | $this->dbh->query("BEGIN"); | |
993 | ||
994 | foreach (array_keys($feed_data) as $k) { | |
995 | ||
996 | $qpart = ""; | |
997 | ||
998 | switch ($k) { | |
999 | case "title": | |
1000 | $qpart = "title = '$feed_title'"; | |
1001 | break; | |
1002 | ||
1003 | case "feed_url": | |
1004 | $qpart = "feed_url = '$feed_link'"; | |
1005 | break; | |
1006 | ||
1007 | case "update_interval": | |
1008 | $qpart = "update_interval = '$upd_intl'"; | |
1009 | break; | |
1010 | ||
1011 | case "purge_interval": | |
1012 | $qpart = "purge_interval = '$purge_intl'"; | |
1013 | break; | |
1014 | ||
1015 | case "auth_login": | |
1016 | $qpart = "auth_login = '$auth_login'"; | |
1017 | break; | |
1018 | ||
1019 | case "auth_pass": | |
1020 | $qpart = "auth_pass = '$auth_pass' AND | |
1021 | auth_pass_encrypted = $auth_pass_encrypted"; | |
1022 | break; | |
1023 | ||
1024 | case "private": | |
1025 | $qpart = "private = $private"; | |
1026 | break; | |
1027 | ||
1028 | case "include_in_digest": | |
1029 | $qpart = "include_in_digest = $include_in_digest"; | |
1030 | break; | |
1031 | ||
1032 | case "always_display_enclosures": | |
1033 | $qpart = "always_display_enclosures = $always_display_enclosures"; | |
1034 | break; | |
1035 | ||
1036 | case "mark_unread_on_update": | |
1037 | $qpart = "mark_unread_on_update = $mark_unread_on_update"; | |
1038 | break; | |
1039 | ||
1040 | case "cache_images": | |
1041 | $qpart = "cache_images = $cache_images"; | |
1042 | break; | |
1043 | ||
1044 | case "hide_images": | |
1045 | $qpart = "hide_images = $hide_images"; | |
1046 | break; | |
1047 | ||
1048 | case "cat_id": | |
1049 | $qpart = $category_qpart_nocomma; | |
1050 | break; | |
1051 | ||
1052 | } | |
1053 | ||
1054 | if ($qpart) { | |
1055 | $this->dbh->query( | |
1056 | "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids) | |
1057 | AND owner_uid = " . $_SESSION["uid"]); | |
1058 | print "<br/>"; | |
1059 | } | |
1060 | } | |
1061 | ||
1062 | $this->dbh->query("COMMIT"); | |
1063 | } | |
1064 | return; | |
1065 | } | |
1066 | ||
1067 | function resetPubSub() { | |
1068 | ||
1069 | $ids = $this->dbh->escape_string($_REQUEST["ids"]); | |
1070 | ||
1071 | $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids) | |
1072 | AND owner_uid = " . $_SESSION["uid"]); | |
1073 | ||
1074 | return; | |
1075 | } | |
1076 | ||
1077 | function remove() { | |
1078 | ||
1079 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); | |
1080 | ||
1081 | foreach ($ids as $id) { | |
1082 | Pref_Feeds::remove_feed($id, $_SESSION["uid"]); | |
1083 | } | |
1084 | ||
1085 | return; | |
1086 | } | |
1087 | ||
1088 | function clear() { | |
1089 | $id = $this->dbh->escape_string($_REQUEST["id"]); | |
1090 | $this->clear_feed_articles($id); | |
1091 | } | |
1092 | ||
1093 | function rescore() { | |
1094 | require_once "rssfuncs.php"; | |
1095 | ||
1096 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); | |
1097 | ||
1098 | foreach ($ids as $id) { | |
1099 | ||
1100 | $filters = load_filters($id, $_SESSION["uid"], 6); | |
1101 | ||
1102 | $result = $this->dbh->query("SELECT | |
1103 | title, content, link, ref_id, author,". | |
1104 | SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated | |
1105 | FROM | |
1106 | ttrss_user_entries, ttrss_entries | |
1107 | WHERE ref_id = id AND feed_id = '$id' AND | |
1108 | owner_uid = " .$_SESSION['uid']." | |
1109 | "); | |
1110 | ||
1111 | $scores = array(); | |
1112 | ||
1113 | while ($line = $this->dbh->fetch_assoc($result)) { | |
1114 | ||
1115 | $tags = get_article_tags($line["ref_id"]); | |
1116 | ||
1117 | $article_filters = get_article_filters($filters, $line['title'], | |
1118 | $line['content'], $line['link'], strtotime($line['updated']), | |
1119 | $line['author'], $tags); | |
1120 | ||
1121 | $new_score = calculate_article_score($article_filters); | |
1122 | ||
1123 | if (!$scores[$new_score]) $scores[$new_score] = array(); | |
1124 | ||
1125 | array_push($scores[$new_score], $line['ref_id']); | |
1126 | } | |
1127 | ||
1128 | foreach (array_keys($scores) as $s) { | |
1129 | if ($s > 1000) { | |
1130 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', | |
1131 | marked = true WHERE | |
1132 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1133 | } else if ($s < -500) { | |
1134 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', | |
1135 | unread = false WHERE | |
1136 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1137 | } else { | |
1138 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE | |
1139 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1140 | } | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | print __("All done."); | |
1145 | ||
1146 | } | |
1147 | ||
1148 | function rescoreAll() { | |
1149 | ||
1150 | $result = $this->dbh->query( | |
1151 | "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']); | |
1152 | ||
1153 | while ($feed_line = $this->dbh->fetch_assoc($result)) { | |
1154 | ||
1155 | $id = $feed_line["id"]; | |
1156 | ||
1157 | $filters = load_filters($id, $_SESSION["uid"], 6); | |
1158 | ||
1159 | $tmp_result = $this->dbh->query("SELECT | |
1160 | title, content, link, ref_id, author,". | |
1161 | SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated | |
1162 | FROM | |
1163 | ttrss_user_entries, ttrss_entries | |
1164 | WHERE ref_id = id AND feed_id = '$id' AND | |
1165 | owner_uid = " .$_SESSION['uid']." | |
1166 | "); | |
1167 | ||
1168 | $scores = array(); | |
1169 | ||
1170 | while ($line = $this->dbh->fetch_assoc($tmp_result)) { | |
1171 | ||
1172 | $tags = get_article_tags($line["ref_id"]); | |
1173 | ||
1174 | $article_filters = get_article_filters($filters, $line['title'], | |
1175 | $line['content'], $line['link'], strtotime($line['updated']), | |
1176 | $line['author'], $tags); | |
1177 | ||
1178 | $new_score = calculate_article_score($article_filters); | |
1179 | ||
1180 | if (!$scores[$new_score]) $scores[$new_score] = array(); | |
1181 | ||
1182 | array_push($scores[$new_score], $line['ref_id']); | |
1183 | } | |
1184 | ||
1185 | foreach (array_keys($scores) as $s) { | |
1186 | if ($s > 1000) { | |
1187 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s', | |
1188 | marked = true WHERE | |
1189 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1190 | } else { | |
1191 | $this->dbh->query("UPDATE ttrss_user_entries SET score = '$s' WHERE | |
1192 | ref_id IN (" . join(',', $scores[$s]) . ")"); | |
1193 | } | |
1194 | } | |
1195 | } | |
1196 | ||
1197 | print __("All done."); | |
1198 | ||
1199 | } | |
1200 | ||
1201 | function categorize() { | |
1202 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); | |
1203 | ||
1204 | $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]); | |
1205 | ||
1206 | if ($cat_id == 0) { | |
1207 | $cat_id_qpart = 'NULL'; | |
1208 | } else { | |
1209 | $cat_id_qpart = "'$cat_id'"; | |
1210 | } | |
1211 | ||
1212 | $this->dbh->query("BEGIN"); | |
1213 | ||
1214 | foreach ($ids as $id) { | |
1215 | ||
1216 | $this->dbh->query("UPDATE ttrss_feeds SET cat_id = $cat_id_qpart | |
1217 | WHERE id = '$id' | |
1218 | AND owner_uid = " . $_SESSION["uid"]); | |
1219 | ||
1220 | } | |
1221 | ||
1222 | $this->dbh->query("COMMIT"); | |
1223 | } | |
1224 | ||
1225 | function removeCat() { | |
1226 | $ids = explode(",", $this->dbh->escape_string($_REQUEST["ids"])); | |
1227 | foreach ($ids as $id) { | |
1228 | $this->remove_feed_category($id, $_SESSION["uid"]); | |
1229 | } | |
1230 | } | |
1231 | ||
1232 | function addCat() { | |
1233 | $feed_cat = $this->dbh->escape_string(trim($_REQUEST["cat"])); | |
1234 | ||
1235 | add_feed_category($feed_cat); | |
1236 | } | |
1237 | ||
1238 | function index() { | |
1239 | ||
1240 | print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; | |
1241 | print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">"; | |
1242 | ||
1243 | $result = $this->dbh->query("SELECT COUNT(id) AS num_errors | |
1244 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
1245 | ||
1246 | $num_errors = $this->dbh->fetch_result($result, 0, "num_errors"); | |
1247 | ||
1248 | if ($num_errors > 0) { | |
1249 | ||
1250 | $error_button = "<button dojoType=\"dijit.form.Button\" | |
1251 | onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" . | |
1252 | __("Feeds with errors") . "</button>"; | |
1253 | } | |
1254 | ||
1255 | if (DB_TYPE == "pgsql") { | |
1256 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1257 | } else { | |
1258 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1259 | } | |
1260 | ||
1261 | $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE | |
1262 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE | |
1263 | ttrss_entries.id = ref_id AND | |
1264 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND | |
1265 | ttrss_feeds.owner_uid = ".$_SESSION["uid"]); | |
1266 | ||
1267 | $num_inactive = $this->dbh->fetch_result($result, 0, "num_inactive"); | |
1268 | ||
1269 | if ($num_inactive > 0) { | |
1270 | $inactive_button = "<button dojoType=\"dijit.form.Button\" | |
1271 | onclick=\"showInactiveFeeds()\">" . | |
1272 | __("Inactive feeds") . "</button>"; | |
1273 | } | |
1274 | ||
1275 | $feed_search = $this->dbh->escape_string($_REQUEST["search"]); | |
1276 | ||
1277 | if (array_key_exists("search", $_REQUEST)) { | |
1278 | $_SESSION["prefs_feed_search"] = $feed_search; | |
1279 | } else { | |
1280 | $feed_search = $_SESSION["prefs_feed_search"]; | |
1281 | } | |
1282 | ||
1283 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; | |
1284 | ||
1285 | print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar | |
1286 | ||
1287 | print "<div style='float : right; padding-right : 4px;'> | |
1288 | <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\" | |
1289 | value=\"$feed_search\"> | |
1290 | <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">". | |
1291 | __('Search')."</button> | |
1292 | </div>"; | |
1293 | ||
1294 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1295 | "<span>" . __('Select')."</span>"; | |
1296 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1297 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" | |
1298 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1299 | print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" | |
1300 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1301 | print "</div></div>"; | |
1302 | ||
1303 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1304 | "<span>" . __('Feeds')."</span>"; | |
1305 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1306 | print "<div onclick=\"quickAddFeed()\" | |
1307 | dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>"; | |
1308 | print "<div onclick=\"editSelectedFeed()\" | |
1309 | dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>"; | |
1310 | print "<div onclick=\"resetFeedOrder()\" | |
1311 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
1312 | print "<div onclick=\"batchSubscribe()\" | |
1313 | dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>"; | |
1314 | print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">" | |
1315 | .__('Unsubscribe')."</div> "; | |
1316 | print "</div></div>"; | |
1317 | ||
1318 | if (get_pref('ENABLE_FEED_CATS')) { | |
1319 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1320 | "<span>" . __('Categories')."</span>"; | |
1321 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1322 | print "<div onclick=\"createCategory()\" | |
1323 | dojoType=\"dijit.MenuItem\">".__('Add category')."</div>"; | |
1324 | print "<div onclick=\"resetCatOrder()\" | |
1325 | dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; | |
1326 | print "<div onclick=\"removeSelectedCategories()\" | |
1327 | dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>"; | |
1328 | print "</div></div>"; | |
1329 | ||
1330 | } | |
1331 | ||
1332 | print $error_button; | |
1333 | print $inactive_button; | |
1334 | ||
1335 | if (defined('_ENABLE_FEED_DEBUGGING')) { | |
1336 | ||
1337 | print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\"> | |
1338 | <option value=\"facDefault\" selected>".__('More actions...')."</option>"; | |
1339 | ||
1340 | if (FORCE_ARTICLE_PURGE == 0) { | |
1341 | ||
1342 | "<option value=\"facPurge\">".__('Manual purge')."</option>"; | |
1343 | } | |
1344 | ||
1345 | print " | |
1346 | <option value=\"facClear\">".__('Clear feed data')."</option> | |
1347 | <option value=\"facRescore\">".__('Rescore articles')."</option>"; | |
1348 | ||
1349 | print "</select>"; | |
1350 | ||
1351 | } | |
1352 | ||
1353 | print "</div>"; # toolbar | |
1354 | ||
1355 | //print '</div>'; | |
1356 | print '<div dojoType="dijit.layout.ContentPane" region="center">'; | |
1357 | ||
1358 | print "<div id=\"feedlistLoading\"> | |
1359 | <img src='images/indicator_tiny.gif'>". | |
1360 | __("Loading, please wait...")."</div>"; | |
1361 | ||
1362 | print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" | |
1363 | url=\"backend.php?op=pref-feeds&method=getfeedtree\"> | |
1364 | </div> | |
1365 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\" | |
1366 | query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" | |
1367 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
1368 | </div> | |
1369 | <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\" | |
1370 | dndController=\"dijit.tree.dndSource\" | |
1371 | betweenThreshold=\"5\" | |
1372 | model=\"feedModel\" openOnClick=\"false\"> | |
1373 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
1374 | var id = String(item.id); | |
1375 | var bare_id = id.substr(id.indexOf(':')+1); | |
1376 | ||
1377 | if (id.match('FEED:')) { | |
1378 | editFeed(bare_id); | |
1379 | } else if (id.match('CAT:')) { | |
1380 | editCat(bare_id, item); | |
1381 | } | |
1382 | </script> | |
1383 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
1384 | Element.hide(\"feedlistLoading\"); | |
1385 | </script> | |
1386 | </div>"; | |
1387 | ||
1388 | # print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\"> | |
1389 | # ".__('<b>Hint:</b> you can drag feeds and categories around.')." | |
1390 | # </div>"; | |
1391 | ||
1392 | print '</div>'; | |
1393 | print '</div>'; | |
1394 | ||
1395 | print "</div>"; # feeds pane | |
1396 | ||
1397 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">"; | |
1398 | ||
1399 | 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.")); | |
1400 | ||
1401 | print "<iframe id=\"upload_iframe\" | |
1402 | name=\"upload_iframe\" onload=\"opmlImportComplete(this)\" | |
1403 | style=\"width: 400px; height: 100px; display: none;\"></iframe>"; | |
1404 | ||
1405 | print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\" | |
1406 | enctype=\"multipart/form-data\" method=\"POST\" | |
1407 | action=\"backend.php\"> | |
1408 | <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
1409 | <input type=\"hidden\" name=\"op\" value=\"dlg\"> | |
1410 | <input type=\"hidden\" name=\"method\" value=\"importOpml\"> | |
1411 | <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" . | |
1412 | __('Import my OPML') . "</button>"; | |
1413 | ||
1414 | print "<hr>"; | |
1415 | ||
1416 | print "<p>" . __('Filename:') . | |
1417 | " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" /> " . | |
1418 | __('Include settings') . "<input type=\"checkbox\" id=\"settings\" checked=\"1\"/>"; | |
1419 | ||
1420 | print "</p><button dojoType=\"dijit.form.Button\" | |
1421 | onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" . | |
1422 | __('Export OPML') . "</button></p></form>"; | |
1423 | ||
1424 | print "<hr>"; | |
1425 | ||
1426 | print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " "; | |
1427 | ||
1428 | print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</p>"; | |
1429 | ||
1430 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". | |
1431 | __('Display published OPML URL')."</button> "; | |
1432 | ||
1433 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, | |
1434 | "hook_prefs_tab_section", "prefFeedsOPML"); | |
1435 | ||
1436 | print "</div>"; # pane | |
1437 | ||
1438 | if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) { | |
1439 | ||
1440 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">"; | |
1441 | ||
1442 | print_notice(__('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.')); | |
1443 | ||
1444 | print "<p>"; | |
1445 | ||
1446 | print "<button onclick='window.navigator.registerContentHandler(" . | |
1447 | "\"application/vnd.mozilla.maybe.feed\", " . | |
1448 | "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" . | |
1449 | __('Click here to register this site as a feed reader.') . | |
1450 | "</button>"; | |
1451 | ||
1452 | print "</p>"; | |
1453 | ||
1454 | print "</div>"; # pane | |
1455 | } | |
1456 | ||
1457 | print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">"; | |
1458 | ||
1459 | print_notice(__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')); | |
1460 | ||
1461 | $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . | |
1462 | "/public.php?op=rss&id=-2&view-mode=all_articles");; | |
1463 | ||
1464 | print "<p>"; | |
1465 | ||
1466 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">". | |
1467 | __('Display URL')."</button> "; | |
1468 | ||
1469 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">". | |
1470 | __('Clear all generated URLs')."</button> "; | |
1471 | ||
1472 | print "</p>"; | |
1473 | ||
1474 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, | |
1475 | "hook_prefs_tab_section", "prefFeedsPublishedGenerated"); | |
1476 | ||
1477 | print "</div>"; #pane | |
1478 | ||
1479 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, | |
1480 | "hook_prefs_tab", "prefFeeds"); | |
1481 | ||
1482 | print "</div>"; #container | |
1483 | } | |
1484 | ||
1485 | private function feedlist_init_cat($cat_id) { | |
1486 | $obj = array(); | |
1487 | $cat_id = (int) $cat_id; | |
1488 | ||
1489 | if ($cat_id > 0) { | |
1490 | $cat_unread = ccache_find($cat_id, $_SESSION["uid"], true); | |
1491 | } else if ($cat_id == 0 || $cat_id == -2) { | |
1492 | $cat_unread = getCategoryUnread($cat_id); | |
1493 | } | |
1494 | ||
1495 | $obj['id'] = 'CAT:' . $cat_id; | |
1496 | $obj['items'] = array(); | |
1497 | $obj['name'] = getCategoryTitle($cat_id); | |
1498 | $obj['type'] = 'category'; | |
1499 | $obj['unread'] = (int) $cat_unread; | |
1500 | $obj['bare_id'] = $cat_id; | |
1501 | ||
1502 | return $obj; | |
1503 | } | |
1504 | ||
1505 | private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') { | |
1506 | $obj = array(); | |
1507 | $feed_id = (int) $feed_id; | |
1508 | ||
1509 | if (!$title) | |
1510 | $title = getFeedTitle($feed_id, false); | |
1511 | ||
1512 | if ($unread === false) | |
1513 | $unread = getFeedUnread($feed_id, false); | |
1514 | ||
1515 | $obj['id'] = 'FEED:' . $feed_id; | |
1516 | $obj['name'] = $title; | |
1517 | $obj['unread'] = (int) $unread; | |
1518 | $obj['type'] = 'feed'; | |
1519 | $obj['error'] = $error; | |
1520 | $obj['updated'] = $updated; | |
1521 | $obj['icon'] = getFeedIcon($feed_id); | |
1522 | $obj['bare_id'] = $feed_id; | |
1523 | $obj['auxcounter'] = 0; | |
1524 | ||
1525 | return $obj; | |
1526 | } | |
1527 | ||
1528 | function inactiveFeeds() { | |
1529 | ||
1530 | if (DB_TYPE == "pgsql") { | |
1531 | $interval_qpart = "NOW() - INTERVAL '3 months'"; | |
1532 | } else { | |
1533 | $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; | |
1534 | } | |
1535 | ||
1536 | $result = $this->dbh->query("SELECT ttrss_feeds.title, ttrss_feeds.site_url, | |
1537 | ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article | |
1538 | FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE | |
1539 | (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE | |
1540 | ttrss_entries.id = ref_id AND | |
1541 | ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart | |
1542 | AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND | |
1543 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
1544 | ttrss_entries.id = ref_id | |
1545 | GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url | |
1546 | ORDER BY last_article"); | |
1547 | ||
1548 | print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>"; | |
1549 | ||
1550 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1551 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1552 | "<span>" . __('Select')."</span>"; | |
1553 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1554 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\" | |
1555 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1556 | print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\" | |
1557 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1558 | print "</div></div>"; | |
1559 | print "</div>"; #toolbar | |
1560 | ||
1561 | print "<div class=\"inactiveFeedHolder\">"; | |
1562 | ||
1563 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">"; | |
1564 | ||
1565 | $lnum = 1; | |
1566 | ||
1567 | while ($line = $this->dbh->fetch_assoc($result)) { | |
1568 | ||
1569 | $feed_id = $line["id"]; | |
1570 | $this_row_id = "id=\"FUPDD-$feed_id\""; | |
1571 | ||
1572 | # class needed for selectTableRows() | |
1573 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1574 | ||
1575 | $edit_title = htmlspecialchars($line["title"]); | |
1576 | ||
1577 | # id needed for selectTableRows() | |
1578 | print "<td width='5%' align='center'><input | |
1579 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1580 | type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>"; | |
1581 | print "<td>"; | |
1582 | ||
1583 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1584 | "title=\"".__("Click to edit feed")."\" ". | |
1585 | "onclick=\"editFeed(".$line["id"].")\">". | |
1586 | htmlspecialchars($line["title"])."</a>"; | |
1587 | ||
1588 | print "</td><td class=\"insensitive\" align='right'>"; | |
1589 | print make_local_datetime($line['last_article'], false); | |
1590 | print "</td>"; | |
1591 | print "</tr>"; | |
1592 | ||
1593 | ++$lnum; | |
1594 | } | |
1595 | ||
1596 | print "</table>"; | |
1597 | print "</div>"; | |
1598 | ||
1599 | print "<div class='dlgButtons'>"; | |
1600 | print "<div style='float : left'>"; | |
1601 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" | |
1602 | .__('Unsubscribe from selected feeds')."</button> "; | |
1603 | print "</div>"; | |
1604 | ||
1605 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">". | |
1606 | __('Close this window')."</button>"; | |
1607 | ||
1608 | print "</div>"; | |
1609 | ||
1610 | } | |
1611 | ||
1612 | function feedsWithErrors() { | |
1613 | $result = $this->dbh->query("SELECT id,title,feed_url,last_error,site_url | |
1614 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
1615 | ||
1616 | print "<div dojoType=\"dijit.Toolbar\">"; | |
1617 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
1618 | "<span>" . __('Select')."</span>"; | |
1619 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
1620 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\" | |
1621 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
1622 | print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\" | |
1623 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
1624 | print "</div></div>"; | |
1625 | print "</div>"; #toolbar | |
1626 | ||
1627 | print "<div class=\"inactiveFeedHolder\">"; | |
1628 | ||
1629 | print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">"; | |
1630 | ||
1631 | $lnum = 1; | |
1632 | ||
1633 | while ($line = $this->dbh->fetch_assoc($result)) { | |
1634 | ||
1635 | $feed_id = $line["id"]; | |
1636 | $this_row_id = "id=\"FERDD-$feed_id\""; | |
1637 | ||
1638 | # class needed for selectTableRows() | |
1639 | print "<tr class=\"placeholder\" $this_row_id>"; | |
1640 | ||
1641 | $edit_title = htmlspecialchars($line["title"]); | |
1642 | ||
1643 | # id needed for selectTableRows() | |
1644 | print "<td width='5%' align='center'><input | |
1645 | onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" | |
1646 | type=\"checkbox\" id=\"FERDC-$feed_id\"></td>"; | |
1647 | print "<td>"; | |
1648 | ||
1649 | print "<a class=\"visibleLink\" href=\"#\" ". | |
1650 | "title=\"".__("Click to edit feed")."\" ". | |
1651 | "onclick=\"editFeed(".$line["id"].")\">". | |
1652 | htmlspecialchars($line["title"])."</a>: "; | |
1653 | ||
1654 | print "<span class=\"insensitive\">"; | |
1655 | print htmlspecialchars($line["last_error"]); | |
1656 | print "</span>"; | |
1657 | ||
1658 | print "</td>"; | |
1659 | print "</tr>"; | |
1660 | ||
1661 | ++$lnum; | |
1662 | } | |
1663 | ||
1664 | print "</table>"; | |
1665 | print "</div>"; | |
1666 | ||
1667 | print "<div class='dlgButtons'>"; | |
1668 | print "<div style='float : left'>"; | |
1669 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" | |
1670 | .__('Unsubscribe from selected feeds')."</button> "; | |
1671 | print "</div>"; | |
1672 | ||
1673 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". | |
1674 | __('Close this window')."</button>"; | |
1675 | ||
1676 | print "</div>"; | |
1677 | } | |
1678 | ||
1679 | /** | |
1680 | * Purge a feed contents, marked articles excepted. | |
1681 | * | |
1682 | * @param mixed $link The database connection. | |
1683 | * @param integer $id The id of the feed to purge. | |
1684 | * @return void | |
1685 | */ | |
1686 | private function clear_feed_articles($id) { | |
1687 | ||
1688 | if ($id != 0) { | |
1689 | $result = $this->dbh->query("DELETE FROM ttrss_user_entries | |
1690 | WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]); | |
1691 | } else { | |
1692 | $result = $this->dbh->query("DELETE FROM ttrss_user_entries | |
1693 | WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]); | |
1694 | } | |
1695 | ||
1696 | $result = $this->dbh->query("DELETE FROM ttrss_entries WHERE | |
1697 | (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0"); | |
1698 | ||
1699 | ccache_update($id, $_SESSION['uid']); | |
1700 | } // function clear_feed_articles | |
1701 | ||
1702 | private function remove_feed_category($id, $owner_uid) { | |
1703 | ||
1704 | $this->dbh->query("DELETE FROM ttrss_feed_categories | |
1705 | WHERE id = '$id' AND owner_uid = $owner_uid"); | |
1706 | ||
1707 | ccache_remove($id, $owner_uid, true); | |
1708 | } | |
1709 | ||
1710 | static function remove_feed($id, $owner_uid) { | |
1711 | ||
1712 | if ($id > 0) { | |
1713 | ||
1714 | /* save starred articles in Archived feed */ | |
1715 | ||
1716 | db_query("BEGIN"); | |
1717 | ||
1718 | /* prepare feed if necessary */ | |
1719 | ||
1720 | $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = $id | |
1721 | AND owner_uid = $owner_uid"); | |
1722 | ||
1723 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); | |
1724 | ||
1725 | $result = db_query("SELECT id FROM ttrss_archived_feeds | |
1726 | WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid"); | |
1727 | ||
1728 | if (db_num_rows($result) == 0) { | |
1729 | $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds"); | |
1730 | $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1; | |
1731 | ||
1732 | db_query("INSERT INTO ttrss_archived_feeds | |
1733 | (id, owner_uid, title, feed_url, site_url) | |
1734 | SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds | |
1735 | WHERE id = '$id'"); | |
1736 | ||
1737 | $archive_id = $new_feed_id; | |
1738 | } else { | |
1739 | $archive_id = db_fetch_result($result, 0, "id"); | |
1740 | } | |
1741 | ||
1742 | db_query("UPDATE ttrss_user_entries SET feed_id = NULL, | |
1743 | orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND | |
1744 | marked = true AND owner_uid = $owner_uid"); | |
1745 | ||
1746 | /* Remove access key for the feed */ | |
1747 | ||
1748 | db_query("DELETE FROM ttrss_access_keys WHERE | |
1749 | feed_id = '$id' AND owner_uid = $owner_uid"); | |
1750 | ||
1751 | /* remove the feed */ | |
1752 | ||
1753 | db_query("DELETE FROM ttrss_feeds | |
1754 | WHERE id = '$id' AND owner_uid = $owner_uid"); | |
1755 | ||
1756 | db_query("COMMIT"); | |
1757 | ||
1758 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
1759 | unlink(ICONS_DIR . "/$id.ico"); | |
1760 | } | |
1761 | ||
1762 | ccache_remove($id, $owner_uid); | |
1763 | ||
1764 | } else { | |
1765 | label_remove(feed_to_label_id($id), $owner_uid); | |
1766 | //ccache_remove($id, $owner_uid); don't think labels are cached | |
1767 | } | |
1768 | } | |
1769 | ||
1770 | function batchSubscribe() { | |
1771 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; | |
1772 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">"; | |
1773 | ||
1774 | print "<table width='100%'><tr><td> | |
1775 | ".__("Add one valid RSS feed per line (no feed detection is done)")." | |
1776 | </td><td align='right'>"; | |
1777 | if (get_pref('ENABLE_FEED_CATS')) { | |
1778 | print __('Place in category:') . " "; | |
1779 | print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); | |
1780 | } | |
1781 | print "</td></tr><tr><td colspan='2'>"; | |
1782 | print "<textarea | |
1783 | style='font-size : 12px; width : 100%; height: 200px;' | |
1784 | placeHolder=\"".__("Feeds to subscribe, One per line")."\" | |
1785 | dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>"; | |
1786 | ||
1787 | print "</td></tr><tr><td colspan='2'>"; | |
1788 | ||
1789 | print "<div id='feedDlg_loginContainer' style='display : none'> | |
1790 | " . | |
1791 | " <input dojoType=\"dijit.form.TextBox\" name='login'\" | |
1792 | placeHolder=\"".__("Login")."\" | |
1793 | style=\"width : 10em;\"> ". | |
1794 | " <input | |
1795 | placeHolder=\"".__("Password")."\" | |
1796 | dojoType=\"dijit.form.TextBox\" type='password' | |
1797 | style=\"width : 10em;\" name='pass'\">". | |
1798 | "</div>"; | |
1799 | ||
1800 | print "</td></tr><tr><td colspan='2'>"; | |
1801 | ||
1802 | print "<div style=\"clear : both\"> | |
1803 | <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\" | |
1804 | onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'> | |
1805 | <label for=\"feedDlg_loginCheck\">". | |
1806 | __('Feeds require authentication.')."</div>"; | |
1807 | ||
1808 | print "</form>"; | |
1809 | ||
1810 | print "</td></tr></table>"; | |
1811 | ||
1812 | print "<div class=\"dlgButtons\"> | |
1813 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button> | |
1814 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button> | |
1815 | </div>"; | |
1816 | } | |
1817 | ||
1818 | function batchAddFeeds() { | |
1819 | $cat_id = $this->dbh->escape_string($_REQUEST['cat']); | |
1820 | $feeds = explode("\n", $_REQUEST['feeds']); | |
1821 | $login = $this->dbh->escape_string($_REQUEST['login']); | |
1822 | $pass = trim($_REQUEST['pass']); | |
1823 | ||
1824 | foreach ($feeds as $feed) { | |
1825 | $feed = $this->dbh->escape_string(trim($feed)); | |
1826 | ||
1827 | if (validate_feed_url($feed)) { | |
1828 | ||
1829 | $this->dbh->query("BEGIN"); | |
1830 | ||
1831 | if ($cat_id == "0" || !$cat_id) { | |
1832 | $cat_qpart = "NULL"; | |
1833 | } else { | |
1834 | $cat_qpart = "'$cat_id'"; | |
1835 | } | |
1836 | ||
1837 | $result = $this->dbh->query( | |
1838 | "SELECT id FROM ttrss_feeds | |
1839 | WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]); | |
1840 | ||
1841 | if (strlen(FEED_CRYPT_KEY) > 0) { | |
1842 | require_once "crypt.php"; | |
1843 | $pass = substr(encrypt_string($pass), 0, 250); | |
1844 | $auth_pass_encrypted = 'true'; | |
1845 | } else { | |
1846 | $auth_pass_encrypted = 'false'; | |
1847 | } | |
1848 | ||
1849 | $pass = $this->dbh->escape_string($pass); | |
1850 | ||
1851 | if ($this->dbh->num_rows($result) == 0) { | |
1852 | $result = $this->dbh->query( | |
1853 | "INSERT INTO ttrss_feeds | |
1854 | (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted) | |
1855 | VALUES ('".$_SESSION["uid"]."', '$feed', | |
1856 | '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)"); | |
1857 | } | |
1858 | ||
1859 | $this->dbh->query("COMMIT"); | |
1860 | } | |
1861 | } | |
1862 | } | |
1863 | ||
1864 | function regenOPMLKey() { | |
1865 | $this->update_feed_access_key('OPML:Publish', | |
1866 | false, $_SESSION["uid"]); | |
1867 | ||
1868 | $new_link = Opml::opml_publish_url(); | |
1869 | ||
1870 | print json_encode(array("link" => $new_link)); | |
1871 | } | |
1872 | ||
1873 | function regenFeedKey() { | |
1874 | $feed_id = $this->dbh->escape_string($_REQUEST['id']); | |
1875 | $is_cat = $this->dbh->escape_string($_REQUEST['is_cat']) == "true"; | |
1876 | ||
1877 | $new_key = $this->update_feed_access_key($feed_id, $is_cat); | |
1878 | ||
1879 | print json_encode(array("link" => $new_key)); | |
1880 | } | |
1881 | ||
1882 | ||
1883 | private function update_feed_access_key($feed_id, $is_cat, $owner_uid = false) { | |
1884 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
1885 | ||
1886 | $sql_is_cat = bool_to_sql_bool($is_cat); | |
1887 | ||
1888 | $result = $this->dbh->query("SELECT access_key FROM ttrss_access_keys | |
1889 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat | |
1890 | AND owner_uid = " . $owner_uid); | |
1891 | ||
1892 | if ($this->dbh->num_rows($result) == 1) { | |
1893 | $key = $this->dbh->escape_string(sha1(uniqid(rand(), true))); | |
1894 | ||
1895 | $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key' | |
1896 | WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat | |
1897 | AND owner_uid = " . $owner_uid); | |
1898 | ||
1899 | return $key; | |
1900 | ||
1901 | } else { | |
1902 | return get_feed_access_key($feed_id, $is_cat, $owner_uid); | |
1903 | } | |
1904 | } | |
1905 | ||
1906 | // Silent | |
1907 | function clearKeys() { | |
1908 | $this->dbh->query("DELETE FROM ttrss_access_keys WHERE | |
1909 | owner_uid = " . $_SESSION["uid"]); | |
1910 | } | |
1911 | ||
1912 | private function calculate_children_count($cat) { | |
1913 | $c = 0; | |
1914 | ||
1915 | foreach ($cat['items'] as $child) { | |
1916 | if ($child['type'] == 'category') { | |
1917 | $c += $this->calculate_children_count($child); | |
1918 | } else { | |
1919 | $c += 1; | |
1920 | } | |
1921 | } | |
1922 | ||
1923 | return $c; | |
1924 | } | |
1925 | ||
1926 | } | |
1927 | ?> |