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