]>
Commit | Line | Data |
---|---|---|
ef8be8ea | 1 | <?php |
d20f3544 | 2 | |
ef8be8ea AD |
3 | function module_pref_feeds($link) { |
4 | ||
d20f3544 AD |
5 | global $update_intervals; |
6 | global $purge_intervals; | |
7 | ||
ef8be8ea AD |
8 | $subop = $_REQUEST["subop"]; |
9 | $quiet = $_REQUEST["quiet"]; | |
10 | ||
11 | if ($subop == "massSubscribe") { | |
12 | $ids = split(",", db_escape_string($_GET["ids"])); | |
13 | ||
14 | $subscribed = array(); | |
15 | ||
16 | foreach ($ids as $id) { | |
17 | $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds | |
18 | WHERE id = '$id'"); | |
19 | ||
20 | $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); | |
21 | $title = db_escape_string(db_fetch_result($result, 0, "title")); | |
22 | ||
23 | $title_orig = db_fetch_result($result, 0, "title"); | |
24 | ||
25 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
26 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
27 | ||
28 | if (db_num_rows($result) == 0) { | |
29 | $result = db_query($link, | |
30 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
31 | VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); | |
32 | ||
33 | array_push($subscribed, $title_orig); | |
34 | } | |
35 | } | |
36 | ||
37 | if (count($subscribed) > 0) { | |
38 | print "<div class=\"notice\">"; | |
39 | print "<b>Subscribed to feeds:</b>"; | |
40 | print "<ul class=\"nomarks\">"; | |
41 | foreach ($subscribed as $title) { | |
42 | print "<li>$title</li>"; | |
43 | } | |
44 | print "</ul>"; | |
45 | print "</div>"; | |
46 | } | |
47 | } | |
48 | ||
49 | if ($subop == "browse") { | |
50 | ||
51 | if (!ENABLE_FEED_BROWSER) { | |
52 | print "Feed browser is administratively disabled."; | |
53 | return; | |
54 | } | |
55 | ||
56 | print "<div id=\"infoBoxTitle\">Other feeds: Top 25</div>"; | |
57 | ||
58 | print "<div class=\"infoBoxContents\">"; | |
59 | ||
60 | print "<p>Showing top 25 registered feeds, sorted by popularity:</p>"; | |
61 | ||
62 | # $result = db_query($link, "SELECT feed_url,count(id) AS subscribers | |
63 | # FROM ttrss_feeds | |
64 | # WHERE auth_login = '' AND auth_pass = '' AND private = false | |
65 | # GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25"); | |
66 | ||
67 | $owner_uid = $_SESSION["uid"]; | |
68 | ||
69 | $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers | |
70 | FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf | |
71 | WHERE tf.feed_url = ttrss_feeds.feed_url | |
72 | AND owner_uid = '$owner_uid') GROUP BY feed_url | |
73 | ORDER BY subscribers DESC LIMIT 25"); | |
74 | ||
75 | print "<ul class='browseFeedList' id='browseFeedList'>"; | |
76 | ||
77 | $feedctr = 0; | |
78 | ||
79 | while ($line = db_fetch_assoc($result)) { | |
80 | $feed_url = $line["feed_url"]; | |
81 | $subscribers = $line["subscribers"]; | |
82 | ||
83 | $det_result = db_query($link, "SELECT site_url,title,id | |
84 | FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); | |
85 | ||
86 | $details = db_fetch_assoc($det_result); | |
87 | ||
88 | $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; | |
89 | ||
90 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
91 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . | |
92 | "/".$details["id"].".ico\">"; | |
93 | } else { | |
94 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
95 | } | |
96 | ||
97 | $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' | |
98 | type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">"; | |
99 | ||
100 | $class = ($feedctr % 2) ? "even" : "odd"; | |
101 | ||
102 | print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box". | |
103 | "$feed_icon " . db_unescape_string($details["title"]) . | |
104 | " <span class='subscribers'>($subscribers)</span></li>"; | |
105 | ||
106 | ++$feedctr; | |
107 | } | |
108 | ||
109 | if ($feedctr == 0) { | |
110 | print "<li>No feeds found to subscribe.</li>"; | |
111 | } | |
112 | ||
113 | print "</ul>"; | |
114 | ||
115 | print "<div align='center'> | |
116 | <input type=\"submit\" class=\"button\" | |
117 | onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\"> | |
118 | <input type='submit' class='button' | |
119 | onclick=\"closeInfoBox()\" value=\"Cancel\"></div>"; | |
120 | ||
121 | print "</div>"; | |
122 | return; | |
123 | } | |
124 | ||
125 | if ($subop == "editfeed") { | |
126 | $feed_id = db_escape_string($_REQUEST["id"]); | |
127 | ||
128 | $result = db_query($link, | |
129 | "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND | |
130 | owner_uid = " . $_SESSION["uid"]); | |
131 | ||
132 | $title = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
133 | 0, "title"))); | |
134 | ||
135 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
136 | ||
137 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
138 | $feed_icon = "<img width=\"16\" height=\"16\" | |
139 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
140 | } else { | |
141 | $feed_icon = ""; | |
142 | } | |
143 | ||
144 | print "<div id=\"infoBoxTitle\">Feed editor</div>"; | |
145 | ||
146 | print "<div class=\"infoBoxContents\">"; | |
147 | ||
148 | print "<form id=\"edit_feed_form\">"; | |
149 | ||
150 | print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">"; | |
151 | print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">"; | |
152 | print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">"; | |
153 | ||
154 | print "<table width='100%'>"; | |
155 | ||
156 | print "<tr><td>Title:</td>"; | |
157 | print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\" | |
158 | name=\"title\" value=\"$title\"></td></tr>"; | |
159 | ||
160 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
161 | $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
162 | 0, "feed_url"))); | |
163 | ||
164 | print "<tr><td>Feed URL:</td>"; | |
165 | print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\" | |
166 | name=\"feed_url\" value=\"$feed_url\"></td></tr>"; | |
167 | ||
168 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
169 | ||
170 | $cat_id = db_fetch_result($result, 0, "cat_id"); | |
171 | ||
172 | print "<tr><td>Category:</td>"; | |
173 | print "<td>"; | |
174 | ||
175 | $parent_feed = db_fetch_result($result, 0, "parent_feed"); | |
176 | ||
177 | if (sprintf("%d", $parent_feed) > 0) { | |
178 | $disabled = "disabled"; | |
179 | } else { | |
180 | $disabled = ""; | |
181 | } | |
182 | ||
183 | print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\" $disabled"); | |
184 | ||
185 | print "</td>"; | |
186 | print "</td></tr>"; | |
187 | ||
188 | } | |
189 | ||
190 | $update_interval = db_fetch_result($result, 0, "update_interval"); | |
191 | ||
192 | print "<tr><td>Update Interval:</td>"; | |
193 | ||
194 | print "<td>"; | |
195 | ||
196 | print_select_hash("update_interval", $update_interval, $update_intervals, | |
197 | "class=\"iedit\""); | |
198 | ||
199 | print "</td>"; | |
200 | ||
201 | print "<tr><td>Link to:</td><td>"; | |
202 | ||
203 | $tmp_result = db_query($link, "SELECT COUNT(id) AS count | |
204 | FROM ttrss_feeds WHERE parent_feed = '$feed_id'"); | |
205 | ||
206 | $linked_count = db_fetch_result($tmp_result, 0, "count"); | |
207 | ||
208 | $parent_feed = db_fetch_result($result, 0, "parent_feed"); | |
209 | ||
210 | if ($linked_count > 0) { | |
211 | $disabled = "disabled"; | |
212 | } else { | |
213 | $disabled = ""; | |
214 | } | |
215 | ||
216 | print "<select class=\"iedit\" $disabled name=\"parent_feed\">"; | |
217 | ||
218 | print "<option value=\"0\">Not linked</option>"; | |
219 | ||
220 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
221 | if ($cat_id) { | |
222 | $cat_qpart = "AND cat_id = '$cat_id'"; | |
223 | } else { | |
224 | $cat_qpart = "AND cat_id IS NULL"; | |
225 | } | |
226 | } | |
227 | ||
228 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
229 | WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND | |
230 | (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0 | |
231 | $cat_qpart ORDER BY title"); | |
232 | ||
233 | if (db_num_rows($tmp_result) > 0) { | |
234 | print "<option disabled>--------</option>"; | |
235 | } | |
236 | ||
237 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
238 | if ($tmp_line["id"] == $parent_feed) { | |
239 | $is_selected = "selected"; | |
240 | } else { | |
241 | $is_selected = ""; | |
242 | } | |
243 | printf("<option $is_selected value='%d'>%s</option>", | |
244 | $tmp_line["id"], $tmp_line["title"]); | |
245 | } | |
246 | ||
247 | print "</select>"; | |
248 | print "</td></tr>"; | |
249 | ||
250 | $purge_interval = db_fetch_result($result, 0, "purge_interval"); | |
251 | ||
252 | print "<tr><td>Article purging:</td>"; | |
253 | ||
254 | print "<td>"; | |
255 | ||
256 | print_select_hash("purge_interval", $purge_interval, $purge_intervals, | |
257 | "class=\"iedit\""); | |
258 | ||
259 | print "</td>"; | |
260 | ||
261 | $auth_login = escape_for_form(db_fetch_result($result, 0, "auth_login")); | |
262 | ||
263 | print "<tr><td>Login:</td>"; | |
264 | print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\" | |
265 | name=\"auth_login\" value=\"$auth_login\"></td></tr>"; | |
266 | ||
267 | $auth_pass = escape_for_form(db_fetch_result($result, 0, "auth_pass")); | |
268 | ||
269 | print "<tr><td>Password:</td>"; | |
270 | print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\" | |
271 | onkeypress=\"return filterCR(event, feedEditSave)\" | |
272 | value=\"$auth_pass\"></td></tr>"; | |
273 | ||
274 | $private = sql_bool_to_bool(db_fetch_result($result, 0, "private")); | |
275 | ||
276 | if ($private) { | |
277 | $checked = "checked"; | |
278 | } else { | |
279 | $checked = ""; | |
280 | } | |
281 | ||
282 | print "<tr><td valign='top'>Options:</td>"; | |
283 | print "<td><input type=\"checkbox\" name=\"private\" id=\"private\" | |
284 | $checked><label for=\"private\">Hide from \"Other Feeds\"</label>"; | |
285 | ||
286 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
287 | ||
288 | if ($rtl_content) { | |
289 | $checked = "checked"; | |
290 | } else { | |
291 | $checked = ""; | |
292 | } | |
293 | ||
294 | print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\" | |
295 | $checked><label for=\"rtl_content\">Right-to-left content</label>"; | |
296 | ||
297 | $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden")); | |
298 | ||
299 | if ($hidden) { | |
300 | $checked = "checked"; | |
301 | } else { | |
302 | $checked = ""; | |
303 | } | |
304 | ||
305 | print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\" | |
306 | $checked><label for=\"hidden\">Hide from my feed list</label>"; | |
307 | ||
308 | $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest")); | |
309 | ||
310 | if ($include_in_digest) { | |
311 | $checked = "checked"; | |
312 | } else { | |
313 | $checked = ""; | |
314 | } | |
315 | ||
316 | print "<br><input type=\"checkbox\" id=\"include_in_digest\" | |
317 | name=\"include_in_digest\" | |
318 | $checked><label for=\"include_in_digest\">Include in e-mail digest</label>"; | |
319 | ||
320 | print "</td></tr>"; | |
321 | ||
322 | print "</table>"; | |
323 | ||
324 | print "</form>"; | |
325 | ||
326 | print "<div align='right'> | |
327 | <input type=\"submit\" class=\"button\" | |
328 | onclick=\"return feedEditSave()\" value=\"Save\"> | |
329 | <input type='submit' class='button' | |
330 | onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>"; | |
331 | ||
332 | print "</div>"; | |
333 | ||
334 | return; | |
335 | } | |
336 | ||
337 | if ($subop == "editSave") { | |
338 | ||
339 | $feed_title = db_escape_string(trim($_POST["title"])); | |
340 | $feed_link = db_escape_string(trim($_POST["feed_url"])); | |
341 | $upd_intl = db_escape_string($_POST["update_interval"]); | |
342 | $purge_intl = db_escape_string($_POST["purge_interval"]); | |
343 | $feed_id = db_escape_string($_POST["id"]); | |
344 | $cat_id = db_escape_string($_POST["cat_id"]); | |
345 | $auth_login = db_escape_string(trim($_POST["auth_login"])); | |
346 | $auth_pass = db_escape_string(trim($_POST["auth_pass"])); | |
347 | $parent_feed = db_escape_string($_POST["parent_feed"]); | |
348 | $private = checkbox_to_sql_bool(db_escape_string($_POST["private"])); | |
349 | $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"])); | |
350 | $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"])); | |
351 | $include_in_digest = checkbox_to_sql_bool( | |
352 | db_escape_string($_POST["include_in_digest"])); | |
353 | ||
354 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
355 | if ($cat_id && $cat_id != 0) { | |
356 | $category_qpart = "cat_id = '$cat_id',"; | |
357 | $category_qpart_nocomma = "cat_id = '$cat_id'"; | |
358 | } else { | |
359 | $category_qpart = 'cat_id = NULL,'; | |
360 | $category_qpart_nocomma = 'cat_id = NULL'; | |
361 | } | |
362 | } else { | |
363 | $category_qpart = ""; | |
364 | $category_qpart_nocomma = ""; | |
365 | } | |
366 | ||
367 | if ($parent_feed && $parent_feed != 0) { | |
368 | $parent_qpart = "parent_feed = '$parent_feed'"; | |
369 | } else { | |
370 | $parent_qpart = 'parent_feed = NULL'; | |
371 | } | |
372 | ||
373 | $result = db_query($link, "UPDATE ttrss_feeds SET | |
374 | $category_qpart $parent_qpart, | |
375 | title = '$feed_title', feed_url = '$feed_link', | |
376 | update_interval = '$upd_intl', | |
377 | purge_interval = '$purge_intl', | |
378 | auth_login = '$auth_login', | |
379 | auth_pass = '$auth_pass', | |
380 | private = $private, | |
381 | rtl_content = $rtl_content, | |
382 | hidden = $hidden, | |
383 | include_in_digest = $include_in_digest | |
384 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
385 | ||
386 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
387 | # update linked feed categories | |
388 | $result = db_query($link, "UPDATE ttrss_feeds SET | |
389 | $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND | |
390 | owner_uid = " . $_SESSION["uid"]); | |
391 | } | |
392 | } | |
393 | ||
ef8be8ea AD |
394 | if ($subop == "remove") { |
395 | ||
396 | if (!WEB_DEMO_MODE) { | |
397 | ||
398 | $ids = split(",", db_escape_string($_GET["ids"])); | |
399 | ||
400 | foreach ($ids as $id) { | |
401 | ||
402 | if ($id > 0) { | |
403 | ||
404 | db_query($link, "DELETE FROM ttrss_feeds | |
405 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
406 | ||
407 | $icons_dir = ICONS_DIR; | |
408 | ||
409 | if (file_exists($icons_dir . "/$id.ico")) { | |
410 | unlink($icons_dir . "/$id.ico"); | |
411 | } | |
412 | } else if ($id < -10) { | |
413 | ||
414 | $label_id = -$id - 11; | |
415 | ||
416 | db_query($link, "DELETE FROM ttrss_labels | |
417 | WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
418 | } | |
419 | } | |
420 | } | |
421 | } | |
422 | ||
423 | if ($subop == "add") { | |
424 | ||
425 | if (!WEB_DEMO_MODE) { | |
426 | ||
427 | $feed_url = db_escape_string(trim($_GET["feed_url"])); | |
428 | $cat_id = db_escape_string($_GET["cat_id"]); | |
aa2122d4 AD |
429 | $p_from = db_escape_string($_GET["from"]); |
430 | ||
431 | if ($p_from) { | |
432 | print "<html> | |
433 | <head> | |
434 | <title>Tiny Tiny RSS - Subscribe to feed...</title> | |
435 | <link rel=\"stylesheet\" type=\"text/css\" href=\"quicksub.css\"> | |
436 | </head> | |
437 | <body> | |
438 | <img class=\"logo\" src=\"images/ttrss_logo.png\" | |
439 | alt=\"Tiny Tiny RSS\"/> | |
440 | <h1>Subscribe to feed...</h1>"; | |
441 | } | |
ef8be8ea AD |
442 | |
443 | if (subscribe_to_feed($link, $feed_url, $cat_id)) { | |
444 | print "Added feed."; | |
445 | } else { | |
446 | print "<div class=\"warning\"> | |
447 | Feed <b>$feed_url</b> already exists in the database. | |
448 | </div>"; | |
449 | } | |
aa2122d4 AD |
450 | |
451 | if ($p_from) { | |
452 | $tt_uri = 'http://' . $_SERVER['SERVER_NAME'] . | |
453 | preg_replace('/backend\.php.*$/', | |
454 | 'tt-rss.php', $_SERVER["REQUEST_URI"]); | |
455 | ||
456 | print "<p><a href='$tt_uri'>Return to Tiny Tiny RSS</a> or | |
457 | <a href='javascript:window.close()'>close this window</a>.</p>"; | |
458 | ||
459 | print "</body></html>"; | |
460 | return; | |
461 | } | |
ef8be8ea AD |
462 | } |
463 | } | |
464 | ||
ef8be8ea AD |
465 | if ($subop == "categorize") { |
466 | ||
467 | if (!WEB_DEMO_MODE) { | |
468 | ||
469 | $ids = split(",", db_escape_string($_GET["ids"])); | |
470 | ||
471 | $cat_id = db_escape_string($_GET["cat_id"]); | |
472 | ||
473 | if ($cat_id == 0) { | |
474 | $cat_id_qpart = 'NULL'; | |
475 | } else { | |
476 | $cat_id_qpart = "'$cat_id'"; | |
477 | } | |
478 | ||
479 | db_query($link, "BEGIN"); | |
480 | ||
481 | foreach ($ids as $id) { | |
482 | ||
483 | db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart | |
484 | WHERE id = '$id' AND parent_feed IS NULL | |
485 | AND owner_uid = " . $_SESSION["uid"]); | |
486 | ||
487 | # update linked feed categories | |
488 | db_query($link, "UPDATE ttrss_feeds SET | |
489 | cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND | |
490 | owner_uid = " . $_SESSION["uid"]); | |
491 | ||
492 | } | |
493 | ||
494 | db_query($link, "COMMIT"); | |
495 | } | |
496 | ||
497 | } | |
498 | ||
9c483746 AD |
499 | if ($subop == "editCats") { |
500 | ||
501 | print "<div id=\"infoBoxTitle\">Category editor</div>"; | |
502 | ||
503 | print "<div class=\"infoBoxContents\">"; | |
504 | ||
505 | $action = $_REQUEST["action"]; | |
506 | ||
507 | if ($action == "save") { | |
508 | ||
509 | $cat_title = db_escape_string(trim($_GET["title"])); | |
510 | $cat_id = db_escape_string($_GET["id"]); | |
511 | ||
512 | $result = db_query($link, "UPDATE ttrss_feed_categories SET | |
513 | title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); | |
514 | ||
515 | } | |
516 | ||
517 | if ($action == "add") { | |
518 | ||
519 | if (!WEB_DEMO_MODE) { | |
520 | ||
521 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
522 | ||
523 | $result = db_query($link, | |
524 | "SELECT id FROM ttrss_feed_categories | |
525 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
526 | ||
527 | if (db_num_rows($result) == 0) { | |
528 | ||
529 | $result = db_query($link, | |
530 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
531 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
532 | ||
533 | } else { | |
534 | ||
535 | print "<div class=\"warning\"> | |
536 | Category <b>$feed_cat</b> already exists in the database. | |
537 | </div>"; | |
538 | } | |
539 | ||
540 | } | |
541 | } | |
542 | ||
543 | if ($action == "remove") { | |
544 | ||
545 | if (!WEB_DEMO_MODE) { | |
546 | ||
547 | $ids = split(",", db_escape_string($_GET["ids"])); | |
548 | ||
549 | foreach ($ids as $id) { | |
550 | ||
551 | db_query($link, "BEGIN"); | |
552 | ||
553 | $result = db_query($link, | |
554 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
555 | WHERE cat_id = '$id'"); | |
556 | ||
557 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
558 | ||
559 | if ($num_feeds == 0) { | |
560 | db_query($link, "DELETE FROM ttrss_feed_categories | |
561 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
562 | } else { | |
563 | ||
564 | print "<div class=\"warning\"> | |
565 | Unable to delete non empty feed categories.</div>"; | |
566 | ||
567 | } | |
568 | ||
569 | db_query($link, "COMMIT"); | |
570 | } | |
571 | } | |
572 | } | |
573 | ||
574 | print "<div class=\"prefGenericAddBox\"> | |
575 | <input id=\"fadd_cat\" | |
1043a8c3 | 576 | onkeypress=\"return filterCR(event, addFeedCat)\" |
9c483746 AD |
577 | onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\" |
578 | size=\"40\"> | |
579 | <input | |
580 | type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\" | |
581 | onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>"; | |
582 | ||
583 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
584 | WHERE owner_uid = ".$_SESSION["uid"]." | |
585 | ORDER BY title"); | |
586 | ||
587 | print "<p>"; | |
588 | ||
589 | if (db_num_rows($result) != 0) { | |
590 | ||
591 | print "<table width=\"100%\" class=\"prefFeedCatList\" | |
592 | cellspacing=\"0\">"; | |
593 | ||
594 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
595 | Select: | |
596 | <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>, | |
597 | <a href=\"javascript:selectPrefRows('fcat', false)\">None</a> | |
598 | </td></tr>"; | |
599 | ||
600 | print "</table>"; | |
601 | ||
602 | print "<div class=\"prefFeedCatHolder\">"; | |
603 | ||
604 | print "<form id=\"feed_cat_edit_form\">"; | |
605 | ||
606 | print "<table width=\"100%\" class=\"prefFeedCatList\" | |
607 | cellspacing=\"0\" id=\"prefFeedCatList\">"; | |
608 | ||
609 | /* print "<tr class=\"title\"> | |
610 | <td width=\"5%\"> </td><td width=\"80%\">Title</td> | |
611 | </tr>"; */ | |
612 | ||
613 | $lnum = 0; | |
614 | ||
615 | while ($line = db_fetch_assoc($result)) { | |
616 | ||
617 | $class = ($lnum % 2) ? "even" : "odd"; | |
618 | ||
619 | $cat_id = $line["id"]; | |
620 | ||
621 | $edit_cat_id = $_GET["id"]; | |
81780e8f AD |
622 | |
623 | if ($action == "edit" && $cat_id == $edit_cat_id) { | |
624 | $class .= "Selected"; | |
625 | $this_row_id = ""; | |
626 | } else if ($action == "edit" && $cat_id != $edit_cat_id) { | |
627 | $class .= "Grayed"; | |
628 | $this_row_id = ""; | |
9c483746 AD |
629 | } else { |
630 | $this_row_id = "id=\"FCATR-$cat_id\""; | |
631 | } | |
632 | ||
633 | print "<tr class=\"$class\" $this_row_id>"; | |
634 | ||
635 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
636 | ||
637 | if (!$edit_cat_id || $action != "edit") { | |
638 | ||
639 | print "<td width='5%' align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");' | |
640 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; | |
641 | ||
642 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
643 | $edit_title . "</a></td>"; | |
644 | ||
645 | } else if ($cat_id != $edit_cat_id) { | |
646 | ||
647 | print "<td width='5%' align='center'><input disabled=\"true\" type=\"checkbox\" | |
648 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
649 | ||
650 | print "<td>$edit_title</td>"; | |
651 | ||
652 | } else { | |
653 | ||
654 | print "<td width='5%' align='center'><input disabled=\"true\" type=\"checkbox\" checked>"; | |
655 | ||
656 | print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">"; | |
657 | print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">"; | |
658 | print "<input type=\"hidden\" name=\"subop\" value=\"editCats\">"; | |
659 | print "<input type=\"hidden\" name=\"action\" value=\"save\">"; | |
660 | ||
661 | print "</td>"; | |
662 | ||
1043a8c3 | 663 | print "<td><input onkeypress=\"return filterCR(event, feedCatEditSave)\" |
9c483746 AD |
664 | name=\"title\" size=\"40\" value=\"$edit_title\"></td>"; |
665 | ||
666 | } | |
667 | ||
668 | print "</tr>"; | |
669 | ||
670 | ++$lnum; | |
671 | } | |
672 | ||
673 | print "</table>"; | |
674 | ||
675 | print "</form>"; | |
676 | ||
677 | print "</div>"; | |
678 | ||
6f5b1e04 AD |
679 | } else { |
680 | print "<p>No feed categories defined.</p>"; | |
681 | } | |
9c483746 | 682 | |
6f5b1e04 AD |
683 | print "<div style='float : right'> |
684 | <input type='submit' class='button' | |
cbb9982e | 685 | onclick=\"selectTab('feedConfig')\" value=\"Close this window\"></div>"; |
9c483746 | 686 | |
6f5b1e04 | 687 | print "<div id=\"catOpToolbar\">"; |
9c483746 | 688 | |
6f5b1e04 AD |
689 | if ($action == "edit") { |
690 | print "<input type=\"submit\" class=\"button\" | |
691 | onclick=\"return feedCatEditSave()\" value=\"Save\"> | |
692 | <input type=\"submit\" class=\"button\" | |
693 | onclick=\"return feedCatEditCancel()\" value=\"Cancel\">"; | |
9c483746 | 694 | } else { |
6f5b1e04 AD |
695 | |
696 | print " | |
697 | <input type=\"submit\" class=\"button\" disabled=\"true\" | |
698 | onclick=\"return editSelectedFeedCat()\" value=\"Edit\"> | |
699 | <input type=\"submit\" class=\"button\" disabled=\"true\" | |
700 | onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">"; | |
9c483746 AD |
701 | } |
702 | ||
703 | print "</div>"; | |
704 | ||
6f5b1e04 AD |
705 | print "</div>"; |
706 | ||
9c483746 AD |
707 | return; |
708 | ||
709 | } | |
710 | ||
ef8be8ea AD |
711 | if ($quiet) return; |
712 | ||
a3656a41 | 713 | $result = db_query($link, "SELECT COUNT(id) AS num_errors |
ef8be8ea AD |
714 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
715 | ||
a3656a41 | 716 | $num_errors = db_fetch_result($result, 0, "num_errors"); |
ef8be8ea | 717 | |
a3656a41 | 718 | if ($num_errors > 0) { |
ef8be8ea | 719 | |
a3656a41 AD |
720 | print "<a href=\"javascript:showFeedsWithErrors()\" |
721 | class=\"feedUpdErrLink\">Some feeds have update errors (click | |
722 | for details)</a>"; | |
ef8be8ea AD |
723 | } |
724 | ||
725 | $feed_search = db_escape_string($_GET["search"]); | |
726 | ||
727 | if (array_key_exists("search", $_GET)) { | |
728 | $_SESSION["prefs_feed_search"] = $feed_search; | |
729 | } else { | |
730 | $feed_search = $_SESSION["prefs_feed_search"]; | |
731 | } | |
732 | ||
733 | print "<div class=\"feedEditSearch\"> | |
734 | <input id=\"feed_search\" size=\"20\" | |
735 | onchange=\"javascript:updateFeedList()\" value=\"$feed_search\"> | |
736 | <input type=\"submit\" class=\"button\" | |
737 | onclick=\"javascript:updateFeedList()\" value=\"Search\"> | |
738 | </div>"; | |
739 | ||
740 | print "<div class=\"prefGenericAddBox\"> | |
741 | <input id=\"fadd_link\" | |
742 | onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\" | |
743 | size=\"40\"> | |
744 | <input type=\"submit\" class=\"button\" | |
745 | disabled=\"true\" id=\"fadd_submit_btn\" | |
746 | onclick=\"addFeed()\" value=\"Subscribe\">"; | |
747 | ||
748 | if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) { | |
749 | print " <input type=\"submit\" class=\"button\" | |
750 | onclick=\"javascript:browseFeeds()\" value=\"Top 25\">"; | |
751 | } | |
752 | ||
753 | print "</div>"; | |
754 | ||
755 | $feeds_sort = db_escape_string($_GET["sort"]); | |
756 | ||
757 | if (!$feeds_sort || $feeds_sort == "undefined") { | |
758 | $feeds_sort = $_SESSION["pref_sort_feeds"]; | |
759 | if (!$feeds_sort) $feeds_sort = "title"; | |
760 | } | |
761 | ||
762 | $_SESSION["pref_sort_feeds"] = $feeds_sort; | |
763 | ||
764 | if ($feed_search) { | |
765 | $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR | |
766 | UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND"; | |
767 | } else { | |
768 | $search_qpart = ""; | |
769 | } | |
770 | ||
771 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
772 | $order_by_qpart = "category,$feeds_sort,title"; | |
773 | } else { | |
774 | $order_by_qpart = "$feeds_sort,title"; | |
775 | } | |
776 | ||
777 | $result = db_query($link, "SELECT | |
778 | F1.id, | |
779 | F1.title, | |
780 | F1.feed_url, | |
781 | substring(F1.last_updated,1,16) AS last_updated, | |
782 | F1.parent_feed, | |
783 | F1.update_interval, | |
784 | F1.purge_interval, | |
785 | F1.cat_id, | |
786 | F2.title AS parent_title, | |
787 | C1.title AS category, | |
788 | F1.hidden, | |
789 | F1.include_in_digest, | |
790 | (SELECT SUBSTRING(MAX(updated),1,16) FROM ttrss_user_entries, | |
791 | ttrss_entries WHERE ref_id = ttrss_entries.id | |
792 | AND feed_id = F1.id) AS last_article | |
793 | FROM | |
794 | ttrss_feeds AS F1 | |
795 | LEFT JOIN ttrss_feeds AS F2 | |
796 | ON (F1.parent_feed = F2.id) | |
797 | LEFT JOIN ttrss_feed_categories AS C1 | |
798 | ON (F1.cat_id = C1.id) | |
799 | WHERE | |
800 | $search_qpart F1.owner_uid = '".$_SESSION["uid"]."' | |
801 | ORDER by $order_by_qpart"); | |
802 | ||
803 | if (db_num_rows($result) != 0) { | |
804 | ||
805 | // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
806 | ||
807 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
808 | class=\"prefFeedList\" id=\"prefFeedList\">"; | |
809 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
810 | Select: | |
811 | <a href=\"javascript:selectPrefRows('feed', true)\">All</a>, | |
812 | <a href=\"javascript:selectPrefRows('feed', false)\">None</a> | |
813 | </td</tr>"; | |
814 | ||
815 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
816 | print "<tr class=\"title\"> | |
817 | <td width='5%' align='center'> </td>"; | |
818 | ||
819 | if (get_pref($link, 'ENABLE_FEED_ICONS')) { | |
820 | print "<td width='3%'> </td>"; | |
821 | } | |
822 | ||
823 | print " | |
824 | <td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> | |
825 | <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> | |
826 | <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last Article</a></td> | |
827 | <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>"; | |
828 | } | |
829 | ||
830 | $lnum = 0; | |
831 | ||
832 | $cur_cat_id = -1; | |
833 | ||
834 | while ($line = db_fetch_assoc($result)) { | |
835 | ||
836 | $feed_id = $line["id"]; | |
837 | $cat_id = $line["cat_id"]; | |
838 | ||
839 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
840 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
841 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); | |
842 | ||
843 | $hidden = sql_bool_to_bool($line["hidden"]); | |
844 | ||
845 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
846 | ||
847 | $last_updated = $line["last_updated"]; | |
848 | ||
849 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
850 | $last_updated = smart_date_time(strtotime($last_updated)); | |
851 | } else { | |
852 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
853 | $last_updated = date($short_date, strtotime($last_updated)); | |
854 | } | |
855 | ||
856 | $last_article = $line["last_article"]; | |
857 | ||
858 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
859 | $last_article = smart_date_time(strtotime($last_article)); | |
860 | } else { | |
861 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
862 | $last_article = date($short_date, strtotime($last_article)); | |
863 | } | |
864 | ||
865 | if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) { | |
866 | $lnum = 0; | |
867 | ||
868 | print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>"; | |
869 | ||
870 | print "<tr class=\"title\"> | |
871 | <td width='5%'> </td>"; | |
872 | ||
873 | if (get_pref($link, 'ENABLE_FEED_ICONS')) { | |
874 | print "<td width='3%'> </td>"; | |
875 | } | |
876 | ||
877 | print "<td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> | |
878 | <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> | |
879 | <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last Article</a></td> | |
880 | <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>"; | |
881 | ||
882 | $cur_cat_id = $cat_id; | |
883 | } | |
884 | ||
885 | $class = ($lnum % 2) ? "even" : "odd"; | |
886 | $this_row_id = "id=\"FEEDR-$feed_id\""; | |
887 | ||
888 | print "<tr class=\"$class\" $this_row_id>"; | |
889 | ||
890 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
891 | ||
892 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
893 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
894 | } else { | |
895 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
896 | } | |
897 | ||
898 | print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");' | |
899 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; | |
900 | ||
901 | if (get_pref($link, 'ENABLE_FEED_ICONS')) { | |
902 | print "<td class='feedIcon'>$feed_icon</td>"; | |
903 | } | |
904 | ||
905 | $edit_title = truncate_string($edit_title, 40); | |
906 | $edit_link = truncate_string($edit_link, 60); | |
907 | ||
908 | if ($hidden) { | |
909 | $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>"; | |
910 | $edit_link = "<span class=\"insensitive\">$edit_link</span>"; | |
911 | $last_updated = "<span class=\"insensitive\">$last_updated</span>"; | |
912 | $last_article = "<span class=\"insensitive\">$last_article</span>"; | |
913 | } | |
914 | ||
915 | $parent_title = $line["parent_title"]; | |
916 | if ($parent_title) { | |
917 | $parent_title = "<span class='groupPrompt'>(linked to | |
918 | $parent_title)</span>"; | |
919 | } | |
920 | ||
921 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
922 | "$edit_title $parent_title" . "</a></td>"; | |
923 | ||
924 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
925 | $edit_link . "</a></td>"; | |
926 | ||
927 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
928 | "$last_article</a></td>"; | |
929 | ||
930 | print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" . | |
931 | "$last_updated</a></td>"; | |
932 | ||
933 | print "</tr>"; | |
934 | ||
935 | ++$lnum; | |
936 | } | |
937 | ||
938 | print "</table>"; | |
939 | ||
940 | print "<p><span id=\"feedOpToolbar\">"; | |
941 | ||
942 | if ($subop == "edit") { | |
943 | print "Edit feed: | |
944 | <input type=\"submit\" class=\"button\" | |
945 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
946 | <input type=\"submit\" class=\"button\" | |
947 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; | |
948 | } else { | |
949 | ||
950 | print " | |
951 | Selection: | |
952 | <input type=\"submit\" class=\"button\" disabled=\"true\" | |
953 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
954 | <input type=\"submit\" class=\"button\" disabled=\"true\" | |
955 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">"; | |
956 | ||
957 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
958 | ||
959 | print " | "; | |
960 | ||
961 | print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled"); | |
962 | ||
963 | print " <input type=\"submit\" class=\"button\" disabled=\"true\" | |
964 | onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">"; | |
965 | ||
966 | } | |
967 | ||
9c483746 AD |
968 | print "</span>"; |
969 | ||
970 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
971 | ||
972 | print " <input type=\"submit\" class=\"button\" | |
973 | onclick=\"javascript:editFeedCats()\" value=\"Edit categories\">"; | |
974 | ||
94a4ba88 | 975 | # print " | "; |
9c483746 AD |
976 | |
977 | } | |
978 | ||
ef8be8ea AD |
979 | } |
980 | } else { | |
981 | ||
6f5b1e04 | 982 | // print "<p>No feeds defined.</p>"; |
ef8be8ea AD |
983 | |
984 | } | |
985 | ||
94a4ba88 AD |
986 | print "<h3>OPML</h3> |
987 | ||
988 | <div style='float : left'> | |
ef8be8ea AD |
989 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> |
990 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
991 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
992 | type=\"submit\" value=\"Import\"> | |
94a4ba88 AD |
993 | </form></div>"; |
994 | ||
995 | print " | "; | |
996 | ||
997 | print "<input type=\"submit\" | |
998 | class=\"button\" onclick=\"gotoExportOpml()\" | |
999 | value=\"Export\">"; | |
1000 | ||
ef8be8ea AD |
1001 | } |
1002 | ?> |