]>
Commit | Line | Data |
---|---|---|
1 | <? | |
2 | require_once "sessions.php"; | |
3 | ||
4 | header("Cache-Control: no-cache, must-revalidate"); | |
5 | header("Pragma: no-cache"); | |
6 | header("Expires: -1"); | |
7 | ||
8 | /* if ($_GET["debug"]) { | |
9 | define('DEFAULT_ERROR_LEVEL', E_ALL); | |
10 | } else { | |
11 | define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE); | |
12 | } | |
13 | ||
14 | error_reporting(DEFAULT_ERROR_LEVEL); */ | |
15 | ||
16 | $op = $_REQUEST["op"]; | |
17 | ||
18 | if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) { | |
19 | header("Content-Type: application/xml"); | |
20 | } | |
21 | ||
22 | if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") { | |
23 | ||
24 | if ($op == "rpc") { | |
25 | print "<error error-code=\"6\"/>"; | |
26 | } else { | |
27 | print " | |
28 | <html><body> | |
29 | <p>Error: Not logged in.</p> | |
30 | <script type=\"text/javascript\"> | |
31 | if (parent.window != 'undefined') { | |
32 | parent.window.location = \"login.php\"; | |
33 | } else { | |
34 | window.location = \"login.php\"; | |
35 | } | |
36 | </script> | |
37 | </body></html> | |
38 | "; | |
39 | } | |
40 | exit; | |
41 | } | |
42 | ||
43 | if (!$op) { | |
44 | print "<error error-code=\"7\"/>"; | |
45 | exit; | |
46 | } | |
47 | ||
48 | define('SCHEMA_VERSION', 7); | |
49 | ||
50 | require_once "sanity_check.php"; | |
51 | require_once "config.php"; | |
52 | require_once "db.php"; | |
53 | require_once "db-prefs.php"; | |
54 | require_once "functions.php"; | |
55 | require_once "magpierss/rss_fetch.inc"; | |
56 | ||
57 | $purge_intervals = array( | |
58 | 0 => "Default", | |
59 | -1 => "Never purge", | |
60 | 5 => "1 week", | |
61 | 14 => "2 weeks", | |
62 | 31 => "1 month", | |
63 | 60 => "2 months", | |
64 | 90 => "3 months"); | |
65 | ||
66 | $update_intervals = array( | |
67 | 0 => "Default", | |
68 | -1 => "Disable updates", | |
69 | 30 => "30 minutes", | |
70 | 60 => "1 hour", | |
71 | 240 => "4 hours", | |
72 | 720 => "12 hours", | |
73 | 1440 => "Daily", | |
74 | 10080 => "Weekly"); | |
75 | ||
76 | $script_started = getmicrotime(); | |
77 | ||
78 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
79 | ||
80 | if (!$link) { | |
81 | if (DB_TYPE == "mysql") { | |
82 | print mysql_error(); | |
83 | } | |
84 | // PG seems to display its own errors just fine by default. | |
85 | return; | |
86 | } | |
87 | ||
88 | if (DB_TYPE == "pgsql") { | |
89 | pg_query("set client_encoding = 'utf-8'"); | |
90 | } | |
91 | ||
92 | if ($_SESSION["uid"]) { | |
93 | if (get_pref($link, "HIDE_READ_FEEDS") == "true") { | |
94 | setcookie("ttrss_vf_hreadf", 1); | |
95 | } else { | |
96 | setcookie("ttrss_vf_hreadf", 0); | |
97 | } | |
98 | ||
99 | setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH); | |
100 | setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON); | |
101 | } | |
102 | ||
103 | $fetch = $_GET["fetch"]; | |
104 | ||
105 | // setcookie("ttrss_icons_url", ICONS_URL); | |
106 | ||
107 | if (!sanity_check($link)) { return; } | |
108 | ||
109 | function getAllCounters($link) { | |
110 | getLabelCounters($link); | |
111 | getFeedCounters($link); | |
112 | getTagCounters($link); | |
113 | getGlobalCounters($link); | |
114 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
115 | getCategoryCounters($link); | |
116 | } | |
117 | } | |
118 | ||
119 | function getCategoryCounters($link) { | |
120 | $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id) | |
121 | FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id | |
122 | AND unread = true)) AS unread FROM ttrss_feeds | |
123 | WHERE | |
124 | owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id"); | |
125 | ||
126 | while ($line = db_fetch_assoc($result)) { | |
127 | $line["cat_id"] = sprintf("%d", $line["cat_id"]); | |
128 | print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"". | |
129 | $line["unread"]."\"/>"; | |
130 | } | |
131 | } | |
132 | ||
133 | function getFeedUnread($link, $feed) { | |
134 | $n_feed = sprintf("%d", $feed); | |
135 | ||
136 | if ($n_feed == -1) { | |
137 | $match_part = "marked = true"; | |
138 | } else if ($feed > 0) { | |
139 | $match_part = "feed_id = '$n_feed'"; | |
140 | } else if ($feed < -10) { | |
141 | $label_id = -$feed - 11; | |
142 | ||
143 | $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE | |
144 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
145 | ||
146 | $match_part = db_fetch_result($result, 0, "sql_exp"); | |
147 | } | |
148 | ||
149 | if ($match_part) { | |
150 | ||
151 | $result = db_query($link, "SELECT count(int_id) AS unread | |
152 | FROM ttrss_user_entries | |
153 | WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]); | |
154 | ||
155 | } else { | |
156 | ||
157 | $result = db_query($link, "SELECT COUNT(post_int_id) AS unread | |
158 | FROM ttrss_tags,ttrss_user_entries | |
159 | WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND | |
160 | ttrss_tags.owner_uid = " . $_SESSION["uid"]); | |
161 | } | |
162 | ||
163 | $unread = db_fetch_result($result, 0, "unread"); | |
164 | return $unread; | |
165 | } | |
166 | ||
167 | /* FIXME this needs reworking */ | |
168 | ||
169 | function getGlobalUnread($link) { | |
170 | $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries | |
171 | WHERE unread = true AND | |
172 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
173 | owner_uid = " . $_SESSION["uid"]); | |
174 | $c_id = db_fetch_result($result, 0, "c_id"); | |
175 | return $c_id; | |
176 | } | |
177 | ||
178 | function getGlobalCounters($link, $global_unread = -1) { | |
179 | if ($global_unread == -1) { | |
180 | $global_unread = getGlobalUnread($link); | |
181 | } | |
182 | print "<counter type=\"global\" id='global-unread' counter='$global_unread'/>"; | |
183 | } | |
184 | ||
185 | function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
186 | ||
187 | if ($smart_mode) { | |
188 | if (!$_SESSION["tctr_last_value"]) { | |
189 | $_SESSION["tctr_last_value"] = array(); | |
190 | } | |
191 | } | |
192 | ||
193 | $old_counters = $_SESSION["tctr_last_value"]; | |
194 | ||
195 | $tctrs_modified = false; | |
196 | ||
197 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
198 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
199 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
200 | ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND | |
201 | post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name | |
202 | UNION | |
203 | select tag_name,0 as count FROM ttrss_tags | |
204 | WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */ | |
205 | ||
206 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) | |
207 | FROM ttrss_user_entries WHERE int_id = post_int_id | |
208 | AND unread = true)) AS count FROM ttrss_tags | |
209 | WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name"); | |
210 | ||
211 | $tags = array(); | |
212 | ||
213 | while ($line = db_fetch_assoc($result)) { | |
214 | $tags[$line["tag_name"]] += $line["count"]; | |
215 | } | |
216 | ||
217 | foreach (array_keys($tags) as $tag) { | |
218 | $unread = $tags[$tag]; | |
219 | ||
220 | $tag = htmlspecialchars($tag); | |
221 | ||
222 | if (!$smart_mode || $old_counters[$tag] != $unread) { | |
223 | $old_counters[$tag] = $unread; | |
224 | $tctrs_modified = true; | |
225 | print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>"; | |
226 | } | |
227 | ||
228 | } | |
229 | ||
230 | if ($smart_mode && $tctrs_modified) { | |
231 | $_SESSION["tctr_last_value"] = $old_counters; | |
232 | } | |
233 | ||
234 | } | |
235 | ||
236 | function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
237 | ||
238 | if ($smart_mode) { | |
239 | if (!$_SESSION["lctr_last_value"]) { | |
240 | $_SESSION["lctr_last_value"] = array(); | |
241 | } | |
242 | } | |
243 | ||
244 | $old_counters = $_SESSION["lctr_last_value"]; | |
245 | $lctrs_modified = false; | |
246 | ||
247 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries | |
248 | WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND | |
249 | unread = true AND owner_uid = ".$_SESSION["uid"]); | |
250 | ||
251 | $count = db_fetch_result($result, 0, "count"); | |
252 | ||
253 | print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>"; | |
254 | ||
255 | $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM | |
256 | ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description"); | |
257 | ||
258 | while ($line = db_fetch_assoc($result)) { | |
259 | ||
260 | $id = -$line["id"] - 11; | |
261 | ||
262 | error_reporting (0); | |
263 | ||
264 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries | |
265 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND | |
266 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
267 | owner_uid = ".$_SESSION["uid"]); | |
268 | ||
269 | $count = db_fetch_result($tmp_result, 0, "count"); | |
270 | ||
271 | if (!$smart_mode || $old_counters[$id] != $count) { | |
272 | $old_counters[$id] = $count; | |
273 | $lctrs_modified = true; | |
274 | print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>"; | |
275 | } | |
276 | ||
277 | error_reporting (DEFAULT_ERROR_LEVEL); | |
278 | } | |
279 | ||
280 | if ($smart_mode && $lctrs_modified) { | |
281 | $_SESSION["lctr_last_value"] = $old_counters; | |
282 | } | |
283 | } | |
284 | ||
285 | /* function getFeedCounter($link, $id) { | |
286 | ||
287 | $result = db_query($link, "SELECT | |
288 | count(id) as count,last_error | |
289 | FROM ttrss_entries,ttrss_user_entries,ttrss_feeds | |
290 | WHERE feed_id = '$id' AND unread = true | |
291 | AND ttrss_user_entries.feed_id = ttrss_feeds.id | |
292 | AND ttrss_user_entries.ref_id = ttrss_entries.id"); | |
293 | ||
294 | $count = db_fetch_result($result, 0, "count"); | |
295 | $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error")); | |
296 | ||
297 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>"; | |
298 | } */ | |
299 | ||
300 | function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS) { | |
301 | ||
302 | if ($smart_mode) { | |
303 | if (!$_SESSION["fctr_last_value"]) { | |
304 | $_SESSION["fctr_last_value"] = array(); | |
305 | } | |
306 | } | |
307 | ||
308 | $old_counters = $_SESSION["fctr_last_value"]; | |
309 | ||
310 | $result = db_query($link, "SELECT id,last_error,parent_feed, | |
311 | (SELECT count(id) | |
312 | FROM ttrss_entries,ttrss_user_entries | |
313 | WHERE feed_id = ttrss_feeds.id AND | |
314 | ttrss_user_entries.ref_id = ttrss_entries.id | |
315 | AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count | |
316 | FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . " | |
317 | AND parent_feed IS NULL"); | |
318 | ||
319 | $fctrs_modified = false; | |
320 | ||
321 | while ($line = db_fetch_assoc($result)) { | |
322 | ||
323 | $id = $line["id"]; | |
324 | $count = $line["count"]; | |
325 | $last_error = htmlspecialchars($line["last_error"]); | |
326 | ||
327 | $has_img = is_file(ICONS_DIR . "/$id.ico"); | |
328 | ||
329 | $tmp_result = db_query($link, | |
330 | "SELECT id,COUNT(unread) AS unread | |
331 | FROM ttrss_feeds LEFT JOIN ttrss_user_entries | |
332 | ON (ttrss_feeds.id = ttrss_user_entries.feed_id) | |
333 | WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id"); | |
334 | ||
335 | if (db_num_rows($tmp_result) > 0) { | |
336 | while ($l = db_fetch_assoc($tmp_result)) { | |
337 | $count += $l["unread"]; | |
338 | } | |
339 | } | |
340 | ||
341 | if (!$smart_mode || $old_counters[$id] != $count) { | |
342 | $old_counters[$id] = $count; | |
343 | $fctrs_modified = true; | |
344 | ||
345 | if ($last_error) { | |
346 | $error_part = "error=\"$last_error\""; | |
347 | } else { | |
348 | $error_part = ""; | |
349 | } | |
350 | ||
351 | if ($has_img) { | |
352 | $has_img_part = "hi=\"$has_img\""; | |
353 | } else { | |
354 | $has_img_part = ""; | |
355 | } | |
356 | ||
357 | print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part/>"; | |
358 | } | |
359 | } | |
360 | ||
361 | if ($smart_mode && $fctrs_modified) { | |
362 | $_SESSION["fctr_last_value"] = $old_counters; | |
363 | } | |
364 | } | |
365 | ||
366 | function outputFeedList($link, $tags = false) { | |
367 | ||
368 | print "<html><head> | |
369 | <title>Tiny Tiny RSS : Feedlist</title> | |
370 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; | |
371 | ||
372 | $user_theme = $_SESSION["theme"]; | |
373 | if ($user_theme) { | |
374 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
375 | href=\"themes/$user_theme/theme.css\">"; | |
376 | } | |
377 | ||
378 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { | |
379 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
380 | href=\"tt-rss_compact.css\"/>"; | |
381 | } else { | |
382 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
383 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
384 | } | |
385 | ||
386 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
387 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> | |
388 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
389 | <!--[if gte IE 5.5000]> | |
390 | <script type=\"text/javascript\" src=\"pngfix.js\"></script> | |
391 | <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\"> | |
392 | <![endif]--> | |
393 | </head><body> | |
394 | <script type=\"text/javascript\"> | |
395 | if (document.addEventListener) { | |
396 | document.addEventListener(\"DOMContentLoaded\", init, null); | |
397 | } | |
398 | window.onload = init; | |
399 | </script>"; | |
400 | ||
401 | print "<ul class=\"feedList\" id=\"feedList\">\n"; | |
402 | ||
403 | $owner_uid = $_SESSION["uid"]; | |
404 | ||
405 | if (!$tags) { | |
406 | ||
407 | /* virtual feeds */ | |
408 | ||
409 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
410 | print "<li class=\"feedCat\">Special</li>"; | |
411 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; | |
412 | } | |
413 | ||
414 | $result = db_query($link, "SELECT count(id) as num_starred | |
415 | FROM ttrss_entries,ttrss_user_entries | |
416 | WHERE marked = true AND | |
417 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
418 | unread = true AND owner_uid = '$owner_uid'"); | |
419 | $num_starred = db_fetch_result($result, 0, "num_starred"); | |
420 | ||
421 | $class = "virt"; | |
422 | ||
423 | if ($num_starred > 0) $class .= "Unread"; | |
424 | ||
425 | printFeedEntry(-1, $class, "Starred articles", $num_starred, | |
426 | "images/mark_set.png", $link); | |
427 | ||
428 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
429 | print "</ul>\n"; | |
430 | } | |
431 | ||
432 | if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) { | |
433 | ||
434 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
435 | ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description"); | |
436 | ||
437 | if (db_num_rows($result) > 0) { | |
438 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
439 | print "<li class=\"feedCat\">Labels</li>"; | |
440 | print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">"; | |
441 | } else { | |
442 | print "<li><hr></li>"; | |
443 | } | |
444 | } | |
445 | ||
446 | while ($line = db_fetch_assoc($result)) { | |
447 | ||
448 | error_reporting (0); | |
449 | ||
450 | $tmp_result = db_query($link, "SELECT count(id) as count | |
451 | FROM ttrss_entries,ttrss_user_entries | |
452 | WHERE (" . $line["sql_exp"] . ") AND unread = true AND | |
453 | ttrss_user_entries.ref_id = ttrss_entries.id | |
454 | AND owner_uid = '$owner_uid'"); | |
455 | ||
456 | $count = db_fetch_result($tmp_result, 0, "count"); | |
457 | ||
458 | $class = "label"; | |
459 | ||
460 | if ($count > 0) { | |
461 | $class .= "Unread"; | |
462 | } | |
463 | ||
464 | error_reporting (DEFAULT_ERROR_LEVEL); | |
465 | ||
466 | printFeedEntry(-$line["id"]-11, | |
467 | $class, $line["description"], $count, "images/label.png", $link); | |
468 | ||
469 | } | |
470 | ||
471 | if (db_num_rows($result) > 0) { | |
472 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
473 | print "</ul>"; | |
474 | } | |
475 | } | |
476 | ||
477 | } | |
478 | ||
479 | // if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
480 | print "<li><hr></li>"; | |
481 | // } | |
482 | ||
483 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
484 | $order_by_qpart = "category,title"; | |
485 | } else { | |
486 | $order_by_qpart = "title"; | |
487 | } | |
488 | ||
489 | $result = db_query($link, "SELECT ttrss_feeds.*, | |
490 | (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries | |
491 | WHERE feed_id = ttrss_feeds.id AND | |
492 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
493 | owner_uid = '$owner_uid') AS total, | |
494 | (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries | |
495 | WHERE feed_id = ttrss_feeds.id AND unread = true | |
496 | AND ttrss_user_entries.ref_id = ttrss_entries.id | |
497 | AND owner_uid = '$owner_uid') as unread, | |
498 | cat_id,last_error, | |
499 | ttrss_feed_categories.title AS category, | |
500 | ttrss_feed_categories.collapsed | |
501 | FROM ttrss_feeds LEFT JOIN ttrss_feed_categories | |
502 | ON (ttrss_feed_categories.id = cat_id) | |
503 | WHERE | |
504 | ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL | |
505 | ORDER BY $order_by_qpart"); | |
506 | ||
507 | $actid = $_GET["actid"]; | |
508 | ||
509 | /* real feeds */ | |
510 | ||
511 | $lnum = 0; | |
512 | ||
513 | $total_unread = 0; | |
514 | ||
515 | $category = ""; | |
516 | ||
517 | while ($line = db_fetch_assoc($result)) { | |
518 | ||
519 | $feed = db_unescape_string($line["title"]); | |
520 | $feed_id = $line["id"]; | |
521 | ||
522 | $subop = $_GET["subop"]; | |
523 | ||
524 | $total = $line["total"]; | |
525 | $unread = $line["unread"]; | |
526 | ||
527 | $rtl_content = sql_bool_to_bool($line["rtl_content"]); | |
528 | ||
529 | if ($rtl_content) { | |
530 | $rtl_tag = "dir=\"RTL\""; | |
531 | } else { | |
532 | $rtl_tag = ""; | |
533 | } | |
534 | ||
535 | $tmp_result = db_query($link, | |
536 | "SELECT id,COUNT(unread) AS unread | |
537 | FROM ttrss_feeds LEFT JOIN ttrss_user_entries | |
538 | ON (ttrss_feeds.id = ttrss_user_entries.feed_id) | |
539 | WHERE parent_feed = '$feed_id' AND unread = true | |
540 | GROUP BY ttrss_feeds.id"); | |
541 | ||
542 | if (db_num_rows($tmp_result) > 0) { | |
543 | while ($l = db_fetch_assoc($tmp_result)) { | |
544 | $unread += $l["unread"]; | |
545 | } | |
546 | } | |
547 | ||
548 | $cat_id = $line["cat_id"]; | |
549 | ||
550 | $tmp_category = $line["category"]; | |
551 | ||
552 | if (!$tmp_category) { | |
553 | $tmp_category = "Uncategorized"; | |
554 | } | |
555 | ||
556 | // $class = ($lnum % 2) ? "even" : "odd"; | |
557 | ||
558 | if ($line["last_error"]) { | |
559 | $class = "error"; | |
560 | } else { | |
561 | $class = "feed"; | |
562 | } | |
563 | ||
564 | if ($unread > 0) $class .= "Unread"; | |
565 | ||
566 | if ($actid == $feed_id) { | |
567 | $class .= "Selected"; | |
568 | } | |
569 | ||
570 | $total_unread += $unread; | |
571 | ||
572 | if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) { | |
573 | ||
574 | if ($category) { | |
575 | print "</ul></li>"; | |
576 | } | |
577 | ||
578 | $category = $tmp_category; | |
579 | ||
580 | $collapsed = $line["collapsed"]; | |
581 | ||
582 | // workaround for NULL category | |
583 | if ($category == "Uncategorized") { | |
584 | if ($_COOKIE["ttrss_vf_uclps"] == 1) { | |
585 | $collapsed = "t"; | |
586 | } | |
587 | } | |
588 | ||
589 | if ($collapsed == "t" || $collapsed == "1") { | |
590 | $holder_class = "invisible"; | |
591 | $ellipsis = "..."; | |
592 | } else { | |
593 | $holder_class = ""; | |
594 | $ellipsis = ""; | |
595 | } | |
596 | ||
597 | if ($cat_id) { | |
598 | $cat_id_qpart = "cat_id = '$cat_id'"; | |
599 | } else { | |
600 | $cat_id_qpart = "cat_id IS NULL"; | |
601 | } | |
602 | ||
603 | $tmp_result = db_query($link, "SELECT count(int_id) AS unread | |
604 | FROM ttrss_user_entries,ttrss_feeds WHERE | |
605 | unread = true AND | |
606 | feed_id = ttrss_feeds.id AND $cat_id_qpart AND | |
607 | ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); | |
608 | ||
609 | $cat_unread = db_fetch_result($tmp_result, 0, "unread"); | |
610 | ||
611 | $cat_id = sprintf("%d", $cat_id); | |
612 | ||
613 | print "<li class=\"feedCat\" id=\"FCAT-$cat_id\"> | |
614 | <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a> | |
615 | <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\"> | |
616 | <span id=\"FCATCTR-$cat_id\" | |
617 | class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a></li>"; | |
618 | ||
619 | // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function | |
620 | // -> keyboard navigation, etc. | |
621 | print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">"; | |
622 | } | |
623 | ||
624 | printFeedEntry($feed_id, $class, $feed, $unread, | |
625 | "icons/$feed_id.ico", $link, $rtl_content); | |
626 | ||
627 | ++$lnum; | |
628 | } | |
629 | ||
630 | } else { | |
631 | ||
632 | // tags | |
633 | ||
634 | /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
635 | FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE | |
636 | post_int_id = ttrss_user_entries.int_id AND | |
637 | unread = true AND ref_id = ttrss_entries.id | |
638 | AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name | |
639 | UNION | |
640 | select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid' | |
641 | ORDER BY tag_name"); */ | |
642 | ||
643 | $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) | |
644 | FROM ttrss_user_entries WHERE int_id = post_int_id | |
645 | AND unread = true)) AS count FROM ttrss_tags | |
646 | WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name"); | |
647 | ||
648 | $tags = array(); | |
649 | ||
650 | while ($line = db_fetch_assoc($result)) { | |
651 | $tags[$line["tag_name"]] += $line["count"]; | |
652 | } | |
653 | ||
654 | foreach (array_keys($tags) as $tag) { | |
655 | ||
656 | $unread = $tags[$tag]; | |
657 | ||
658 | $class = "tag"; | |
659 | ||
660 | if ($unread > 0) { | |
661 | $class .= "Unread"; | |
662 | } | |
663 | ||
664 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); | |
665 | ||
666 | } | |
667 | ||
668 | } | |
669 | ||
670 | if (db_num_rows($result) == 0) { | |
671 | if ($tags) { | |
672 | $what = "tags"; | |
673 | } else { | |
674 | $what = "feeds"; | |
675 | } | |
676 | print "<li>No $what to display.</li>"; | |
677 | } | |
678 | ||
679 | print "</ul>"; | |
680 | ||
681 | print ' | |
682 | <script type="text/javascript"> | |
683 | /* for IE */ | |
684 | function statechange() { | |
685 | if (document.readyState == "interactive") init(); | |
686 | } | |
687 | ||
688 | if (document.readyState) { | |
689 | if (document.readyState == "interactive" || document.readyState == "complete") { | |
690 | init(); | |
691 | } else { | |
692 | document.onreadystatechange = statechange; | |
693 | } | |
694 | } | |
695 | </script></body></html>'; | |
696 | } | |
697 | ||
698 | ||
699 | if ($op == "rpc") { | |
700 | ||
701 | $subop = $_GET["subop"]; | |
702 | ||
703 | if ($subop == "setpref") { | |
704 | if (WEB_DEMO_MODE) { | |
705 | return; | |
706 | } | |
707 | ||
708 | print "<rpc-reply>"; | |
709 | ||
710 | $key = db_escape_string($_GET["key"]); | |
711 | $value = db_escape_string($_GET["value"]); | |
712 | ||
713 | set_pref($link, $key, $value); | |
714 | ||
715 | print "<param-set key=\"$key\" value=\"$value\"/>"; | |
716 | ||
717 | print "</rpc-reply>"; | |
718 | ||
719 | } | |
720 | ||
721 | if ($subop == "getLabelCounters") { | |
722 | $aid = $_GET["aid"]; | |
723 | print "<rpc-reply>"; | |
724 | getLabelCounters($link); | |
725 | if ($aid) { | |
726 | getFeedCounter($link, $aid); | |
727 | } | |
728 | print "</rpc-reply>"; | |
729 | } | |
730 | ||
731 | if ($subop == "getFeedCounters") { | |
732 | print "<rpc-reply>"; | |
733 | getFeedCounters($link); | |
734 | print "</rpc-reply>"; | |
735 | } | |
736 | ||
737 | if ($subop == "getAllCounters") { | |
738 | print "<rpc-reply>"; | |
739 | getAllCounters($link); | |
740 | print "</rpc-reply>"; | |
741 | } | |
742 | ||
743 | if ($subop == "mark") { | |
744 | $mark = $_GET["mark"]; | |
745 | $id = db_escape_string($_GET["id"]); | |
746 | ||
747 | if ($mark == "1") { | |
748 | $mark = "true"; | |
749 | } else { | |
750 | $mark = "false"; | |
751 | } | |
752 | ||
753 | // FIXME this needs collision testing | |
754 | ||
755 | $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark | |
756 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
757 | } | |
758 | ||
759 | if ($subop == "updateFeed") { | |
760 | $feed_id = db_escape_string($_GET["feed"]); | |
761 | ||
762 | $result = db_query($link, | |
763 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id' | |
764 | AND owner_uid = " . $_SESSION["uid"]); | |
765 | ||
766 | if (db_num_rows($result) > 0) { | |
767 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
768 | update_rss_feed($link, $feed_url, $feed_id); | |
769 | } | |
770 | ||
771 | print "<rpc-reply>"; | |
772 | getFeedCounter($link, $feed_id); | |
773 | print "</rpc-reply>"; | |
774 | ||
775 | return; | |
776 | } | |
777 | ||
778 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { | |
779 | ||
780 | if (ENABLE_UPDATE_DAEMON) { | |
781 | ||
782 | if ($subop == "forceUpdateAllFeeds") { | |
783 | ||
784 | $result = db_query($link, "SELECT count(id) AS cid FROM | |
785 | ttrss_scheduled_updates WHERE feed_id IS NULL AND | |
786 | owner_uid = " . $_SESSION["uid"]); | |
787 | ||
788 | $cid = db_fetch_result($result, 0, "cid"); | |
789 | ||
790 | # print "<rpc-reply>"; | |
791 | ||
792 | if ($cid == 0) { | |
793 | ||
794 | db_query($link, "INSERT INTO ttrss_scheduled_updates | |
795 | (owner_uid, feed_id, entered) VALUES | |
796 | (".$_SESSION["uid"].", NULL, NOW())"); | |
797 | ||
798 | // print "<!-- ScheduledOK -->"; | |
799 | ||
800 | } else { | |
801 | // print "<!-- RequestAlreadyInQueue -->"; | |
802 | } | |
803 | ||
804 | # print "</rpc-reply>"; | |
805 | } | |
806 | ||
807 | } else { | |
808 | update_all_feeds($link, $subop == "forceUpdateAllFeeds"); | |
809 | } | |
810 | ||
811 | $global_unread_caller = sprintf("%d", $_GET["uctr"]); | |
812 | $global_unread = getGlobalUnread($link); | |
813 | ||
814 | print "<rpc-reply>"; | |
815 | ||
816 | if ($global_unread_caller != $global_unread) { | |
817 | ||
818 | $omode = $_GET["omode"]; | |
819 | ||
820 | if (!$omode) $omode = "tflc"; | |
821 | ||
822 | if (strchr($omode, "l")) getLabelCounters($link); | |
823 | if (strchr($omode, "f")) getFeedCounters($link); | |
824 | if (strchr($omode, "t")) getTagCounters($link); | |
825 | if (strchr($omode, "c")) { | |
826 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
827 | getCategoryCounters($link); | |
828 | } | |
829 | } | |
830 | } | |
831 | ||
832 | getGlobalCounters($link, $global_unread); | |
833 | ||
834 | print "</rpc-reply>"; | |
835 | ||
836 | } | |
837 | ||
838 | /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ | |
839 | if ($subop == "catchupSelected") { | |
840 | ||
841 | $ids = split(",", db_escape_string($_GET["ids"])); | |
842 | ||
843 | $cmode = sprintf("%d", $_GET["cmode"]); | |
844 | ||
845 | foreach ($ids as $id) { | |
846 | ||
847 | if ($cmode == 0) { | |
848 | db_query($link, "UPDATE ttrss_user_entries SET | |
849 | unread = false,last_read = NOW() | |
850 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
851 | } else if ($cmode == 1) { | |
852 | db_query($link, "UPDATE ttrss_user_entries SET | |
853 | unread = true | |
854 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
855 | } else { | |
856 | db_query($link, "UPDATE ttrss_user_entries SET | |
857 | unread = NOT unread,last_read = NOW() | |
858 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
859 | } | |
860 | } | |
861 | print "<rpc-reply>"; | |
862 | getAllCounters($link); | |
863 | print "</rpc-reply>"; | |
864 | } | |
865 | ||
866 | if ($subop == "markSelected") { | |
867 | ||
868 | $ids = split(",", db_escape_string($_GET["ids"])); | |
869 | ||
870 | $cmode = sprintf("%d", $_GET["cmode"]); | |
871 | ||
872 | foreach ($ids as $id) { | |
873 | ||
874 | if ($cmode == 0) { | |
875 | db_query($link, "UPDATE ttrss_user_entries SET | |
876 | marked = false | |
877 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
878 | } else if ($cmode == 1) { | |
879 | db_query($link, "UPDATE ttrss_user_entries SET | |
880 | marked = true | |
881 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
882 | } else { | |
883 | db_query($link, "UPDATE ttrss_user_entries SET | |
884 | marked = NOT marked | |
885 | WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
886 | } | |
887 | } | |
888 | print "<rpc-reply>"; | |
889 | getAllCounters($link); | |
890 | print "</rpc-reply>"; | |
891 | } | |
892 | ||
893 | if ($subop == "sanityCheck") { | |
894 | if (sanity_check($link)) { | |
895 | print "<error error-code=\"0\"/>"; | |
896 | } | |
897 | } | |
898 | ||
899 | if ($subop == "globalPurge") { | |
900 | ||
901 | print "<rpc-reply>"; | |
902 | global_purge_old_posts($link, true); | |
903 | print "</rpc-reply>"; | |
904 | ||
905 | } | |
906 | ||
907 | } | |
908 | ||
909 | if ($op == "feeds") { | |
910 | ||
911 | $tags = $_GET["tags"]; | |
912 | ||
913 | $subop = $_GET["subop"]; | |
914 | ||
915 | if ($subop == "catchupAll") { | |
916 | db_query($link, "UPDATE ttrss_user_entries SET | |
917 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); | |
918 | } | |
919 | ||
920 | if ($subop == "collapse") { | |
921 | $cat_id = db_escape_string($_GET["cid"]); | |
922 | ||
923 | db_query($link, "UPDATE ttrss_feed_categories SET | |
924 | collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " . | |
925 | $_SESSION["uid"]); | |
926 | return; | |
927 | } | |
928 | ||
929 | outputFeedList($link, $tags); | |
930 | ||
931 | } | |
932 | ||
933 | if ($op == "view") { | |
934 | ||
935 | $id = db_escape_string($_GET["id"]); | |
936 | $feed_id = db_escape_string($_GET["feed"]); | |
937 | ||
938 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds | |
939 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
940 | ||
941 | if (db_num_rows($result) == 1) { | |
942 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
943 | } else { | |
944 | $rtl_content = false; | |
945 | } | |
946 | ||
947 | if ($rtl_content) { | |
948 | $rtl_tag = "dir=\"RTL\""; | |
949 | } else { | |
950 | $rtl_tag = ""; | |
951 | } | |
952 | ||
953 | $result = db_query($link, "UPDATE ttrss_user_entries | |
954 | SET unread = false,last_read = NOW() | |
955 | WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
956 | ||
957 | $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id, | |
958 | SUBSTRING(updated,1,16) as updated, | |
959 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url, | |
960 | num_comments, | |
961 | author | |
962 | FROM ttrss_entries,ttrss_user_entries | |
963 | WHERE id = '$id' AND ref_id = id"); | |
964 | ||
965 | print "<html><head> | |
966 | <title>Tiny Tiny RSS : Article $id</title> | |
967 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; | |
968 | ||
969 | $user_theme = $_SESSION["theme"]; | |
970 | if ($user_theme) { | |
971 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
972 | href=\"themes/$user_theme/theme.css\">"; | |
973 | } | |
974 | ||
975 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { | |
976 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
977 | href=\"tt-rss_compact.css\"/>"; | |
978 | } else { | |
979 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
980 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
981 | } | |
982 | ||
983 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
984 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
985 | </head><body $rtl_tag>"; | |
986 | ||
987 | if ($result) { | |
988 | ||
989 | $line = db_fetch_assoc($result); | |
990 | ||
991 | if ($line["icon_url"]) { | |
992 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
993 | } else { | |
994 | $feed_icon = " "; | |
995 | } | |
996 | ||
997 | /* if ($line["comments"] && $line["link"] != $line["comments"]) { | |
998 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
999 | } else { | |
1000 | $entry_comments = ""; | |
1001 | } */ | |
1002 | ||
1003 | $num_comments = $line["num_comments"]; | |
1004 | $entry_comments = ""; | |
1005 | ||
1006 | if ($num_comments > 0) { | |
1007 | if ($line["comments"]) { | |
1008 | $comments_url = $line["comments"]; | |
1009 | } else { | |
1010 | $comments_url = $line["link"]; | |
1011 | } | |
1012 | $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>"; | |
1013 | } else { | |
1014 | if ($line["comments"] && $line["link"] != $line["comments"]) { | |
1015 | $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>"; | |
1016 | } | |
1017 | } | |
1018 | ||
1019 | print "<div class=\"postReply\">"; | |
1020 | ||
1021 | print "<div class=\"postHeader\"><table width=\"100%\">"; | |
1022 | ||
1023 | $entry_author = $line["author"]; | |
1024 | ||
1025 | if ($entry_author) { | |
1026 | $entry_author = " - by $entry_author"; | |
1027 | } | |
1028 | ||
1029 | print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] . | |
1030 | "</a>$entry_author</td>"; | |
1031 | ||
1032 | $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
1033 | strtotime($line["updated"])); | |
1034 | ||
1035 | print "<td class=\"postDate\">$parsed_updated</td>"; | |
1036 | ||
1037 | print "</tr>"; | |
1038 | ||
1039 | $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM | |
1040 | ttrss_tags WHERE post_int_id = " . $line["int_id"] . " | |
1041 | ORDER BY tag_name"); | |
1042 | ||
1043 | $tags_str = ""; | |
1044 | $f_tags_str = ""; | |
1045 | ||
1046 | $num_tags = 0; | |
1047 | ||
1048 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1049 | $num_tags++; | |
1050 | $tag = $tmp_line["tag_name"]; | |
1051 | $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, "; | |
1052 | ||
1053 | if ($num_tags == 5) { | |
1054 | $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>"; | |
1055 | } else if ($num_tags < 5) { | |
1056 | $tags_str .= $tag_str; | |
1057 | } | |
1058 | $f_tags_str .= $tag_str; | |
1059 | } | |
1060 | ||
1061 | $tags_str = preg_replace("/, $/", "", $tags_str); | |
1062 | $f_tags_str = preg_replace("/, $/", "", $f_tags_str); | |
1063 | ||
1064 | // $truncated_link = truncate_string($line["link"], 60); | |
1065 | ||
1066 | if ($tags_str || $entry_comments) { | |
1067 | print "<tr><td width='50%'> | |
1068 | $entry_comments</td> | |
1069 | <td align=\"right\">$tags_str</td></tr>"; | |
1070 | } | |
1071 | ||
1072 | print "</table></div>"; | |
1073 | ||
1074 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
1075 | print "<div class=\"postContent\">"; | |
1076 | ||
1077 | if (db_num_rows($tmp_result) > 5) { | |
1078 | print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>"; | |
1079 | } | |
1080 | ||
1081 | if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) { | |
1082 | $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]); | |
1083 | } | |
1084 | ||
1085 | print $line["content"] . "</div>"; | |
1086 | ||
1087 | print "</div>"; | |
1088 | ||
1089 | print "<script type=\"text/javascript\"> | |
1090 | update_all_counters('$feed_id'); | |
1091 | </script>"; | |
1092 | } | |
1093 | ||
1094 | print "</body></html>"; | |
1095 | } | |
1096 | ||
1097 | if ($op == "viewfeed") { | |
1098 | ||
1099 | $feed = $_GET["feed"]; | |
1100 | $skip = $_GET["skip"]; | |
1101 | $subop = $_GET["subop"]; | |
1102 | $view_mode = $_GET["view"]; | |
1103 | $limit = $_GET["limit"]; | |
1104 | $cat_view = $_GET["cat"]; | |
1105 | ||
1106 | if (!$skip) $skip = 0; | |
1107 | ||
1108 | if ($subop == "undefined") $subop = ""; | |
1109 | ||
1110 | print "<html><head> | |
1111 | <title>Tiny Tiny RSS : Feed $feed</title> | |
1112 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; | |
1113 | ||
1114 | $user_theme = $_SESSION["theme"]; | |
1115 | if ($user_theme) { | |
1116 | print "<link rel=\"stylesheet\" type=\"text/css\" | |
1117 | href=\"themes/$user_theme/theme.css\">"; | |
1118 | } | |
1119 | ||
1120 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { | |
1121 | print "<link rel=\"stylesheet\" | |
1122 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
1123 | ||
1124 | } else { | |
1125 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
1126 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
1127 | } | |
1128 | ||
1129 | $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds | |
1130 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
1131 | ||
1132 | if (db_num_rows($result) == 1) { | |
1133 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
1134 | } else { | |
1135 | $rtl_content = false; | |
1136 | } | |
1137 | ||
1138 | if ($rtl_content) { | |
1139 | $rtl_tag = "dir=\"RTL\""; | |
1140 | } else { | |
1141 | $rtl_tag = ""; | |
1142 | } | |
1143 | ||
1144 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1145 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
1146 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
1147 | <!--[if gte IE 5.5000]> | |
1148 | <script type=\"text/javascript\" src=\"pngfix.js\"></script> | |
1149 | <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\"> | |
1150 | <![endif]--> | |
1151 | </head><body $rtl_tag> | |
1152 | <script type=\"text/javascript\"> | |
1153 | if (document.addEventListener) { | |
1154 | document.addEventListener(\"DOMContentLoaded\", init, null); | |
1155 | } | |
1156 | window.onload = init; | |
1157 | </script>"; | |
1158 | ||
1159 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { | |
1160 | ||
1161 | /* if (ENABLE_UPDATE_DAEMON) { | |
1162 | ||
1163 | if ($cid == 0) { | |
1164 | ||
1165 | db_query($link, "INSERT INTO ttrss_scheduled_updates | |
1166 | (owner_uid, feed_id, entered) VALUES | |
1167 | (".$_SESSION["uid"].", '$feed', NOW())"); | |
1168 | } | |
1169 | ||
1170 | } else { | |
1171 | // fixme update_rss_feed... | |
1172 | } */ | |
1173 | ||
1174 | if ($cat_view) { | |
1175 | ||
1176 | if ($feed > 0) { | |
1177 | $cat_qpart = "cat_id = '$feed'"; | |
1178 | } else { | |
1179 | $cat_qpart = "cat_id IS NULL"; | |
1180 | } | |
1181 | ||
1182 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
1183 | WHERE $cat_qpart AND owner_uid = " . $_SESSION["uid"]); | |
1184 | ||
1185 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1186 | $feed_url = $tmp_line["feed_url"]; | |
1187 | update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON); | |
1188 | } | |
1189 | ||
1190 | } else { | |
1191 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
1192 | WHERE id = '$feed'"); | |
1193 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
1194 | update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON); | |
1195 | } | |
1196 | } | |
1197 | ||
1198 | if ($subop == "MarkAllRead") { | |
1199 | ||
1200 | if (preg_match("/^[0-9][0-9]*$/", $feed) != false && $feed >= 0) { | |
1201 | ||
1202 | if ($cat_view) { | |
1203 | ||
1204 | if ($feed > 0) { | |
1205 | $cat_qpart = "cat_id = '$feed'"; | |
1206 | } else { | |
1207 | $cat_qpart = "cat_id IS NULL"; | |
1208 | } | |
1209 | ||
1210 | $tmp_result = db_query($link, "SELECT id | |
1211 | FROM ttrss_feeds WHERE $cat_qpart AND owner_uid = " . | |
1212 | $_SESSION["uid"]); | |
1213 | ||
1214 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1215 | ||
1216 | $tmp_feed = $tmp_line["id"]; | |
1217 | ||
1218 | db_query($link, "UPDATE ttrss_user_entries | |
1219 | SET unread = false,last_read = NOW() | |
1220 | WHERE feed_id = '$tmp_feed' AND owner_uid = " . $_SESSION["uid"]); | |
1221 | } | |
1222 | ||
1223 | } else if ($feed > 0) { | |
1224 | ||
1225 | $tmp_result = db_query($link, "SELECT id | |
1226 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
1227 | ORDER BY cat_id,title"); | |
1228 | ||
1229 | $parent_ids = array(); | |
1230 | ||
1231 | if (db_num_rows($tmp_result) > 0) { | |
1232 | while ($p = db_fetch_assoc($tmp_result)) { | |
1233 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
1234 | } | |
1235 | ||
1236 | $children_qpart = implode(" OR ", $parent_ids); | |
1237 | ||
1238 | db_query($link, "UPDATE ttrss_user_entries | |
1239 | SET unread = false,last_read = NOW() | |
1240 | WHERE (feed_id = '$feed' OR $children_qpart) | |
1241 | AND owner_uid = " . $_SESSION["uid"]); | |
1242 | ||
1243 | } else { | |
1244 | db_query($link, "UPDATE ttrss_user_entries | |
1245 | SET unread = false,last_read = NOW() | |
1246 | WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
1247 | } | |
1248 | ||
1249 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
1250 | ||
1251 | if ($feed == -1) { | |
1252 | db_query($link, "UPDATE ttrss_user_entries | |
1253 | SET unread = false,last_read = NOW() | |
1254 | WHERE marked = true AND owner_uid = ".$_SESSION["uid"]); | |
1255 | } | |
1256 | ||
1257 | } else if ($feed < -10) { // label | |
1258 | ||
1259 | // TODO make this more efficient | |
1260 | ||
1261 | $label_id = -$feed - 11; | |
1262 | ||
1263 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
1264 | WHERE id = '$label_id'"); | |
1265 | ||
1266 | if ($tmp_result) { | |
1267 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
1268 | ||
1269 | db_query($link, "BEGIN"); | |
1270 | ||
1271 | $tmp2_result = db_query($link, | |
1272 | "SELECT | |
1273 | int_id | |
1274 | FROM | |
1275 | ttrss_user_entries,ttrss_entries | |
1276 | WHERE | |
1277 | ref_id = id AND | |
1278 | $sql_exp AND | |
1279 | owner_uid = " . $_SESSION["uid"]); | |
1280 | ||
1281 | while ($tmp_line = db_fetch_assoc($tmp2_result)) { | |
1282 | db_query($link, "UPDATE | |
1283 | ttrss_user_entries | |
1284 | SET | |
1285 | unread = false, last_read = NOW() | |
1286 | WHERE | |
1287 | int_id = " . $tmp_line["int_id"]); | |
1288 | } | |
1289 | ||
1290 | db_query($link, "COMMIT"); | |
1291 | ||
1292 | /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries | |
1293 | SET unread = false,last_read = NOW() | |
1294 | WHERE $sql_exp | |
1295 | AND ref_id = id | |
1296 | AND owner_uid = ".$_SESSION["uid"]); */ | |
1297 | } | |
1298 | } | |
1299 | } else { // tag | |
1300 | db_query($link, "BEGIN"); | |
1301 | ||
1302 | $tag_name = db_escape_string($feed); | |
1303 | ||
1304 | $result = db_query($link, "SELECT post_int_id FROM ttrss_tags | |
1305 | WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]); | |
1306 | ||
1307 | while ($line = db_fetch_assoc($result)) { | |
1308 | db_query($link, "UPDATE ttrss_user_entries SET | |
1309 | unread = false, last_read = NOW() | |
1310 | WHERE int_id = " . $line["post_int_id"]); | |
1311 | } | |
1312 | db_query($link, "COMMIT"); | |
1313 | } | |
1314 | ||
1315 | } | |
1316 | ||
1317 | $search = db_escape_string($_GET["search"]); | |
1318 | $search_mode = db_escape_string($_GET["smode"]); | |
1319 | ||
1320 | if ($search) { | |
1321 | $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%') | |
1322 | OR ttrss_entries.content LIKE '%$search%') AND"; | |
1323 | } else { | |
1324 | $search_query_part = ""; | |
1325 | } | |
1326 | ||
1327 | $view_query_part = ""; | |
1328 | ||
1329 | if ($view_mode == "Adaptive") { | |
1330 | if ($search) { | |
1331 | $view_query_part = " "; | |
1332 | } else if ($feed != -1) { | |
1333 | $unread = getFeedUnread($link, $feed); | |
1334 | if ($unread > 0) { | |
1335 | $view_query_part = " unread = true AND "; | |
1336 | } | |
1337 | } | |
1338 | } | |
1339 | ||
1340 | if ($view_mode == "Starred") { | |
1341 | $view_query_part = " marked = true AND "; | |
1342 | } | |
1343 | ||
1344 | if ($view_mode == "Unread") { | |
1345 | $view_query_part = " unread = true AND "; | |
1346 | } | |
1347 | ||
1348 | if ($limit && $limit != "All") { | |
1349 | $limit_query_part = "LIMIT " . $limit; | |
1350 | } | |
1351 | ||
1352 | $vfeed_query_part = ""; | |
1353 | ||
1354 | // override query strategy and enable feed display when searching globally | |
1355 | if ($search && $search_mode == "All feeds") { | |
1356 | $query_strategy_part = "ttrss_entries.id > 0"; | |
1357 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1358 | } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) { | |
1359 | $query_strategy_part = "ttrss_entries.id > 0"; | |
1360 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
1361 | id = feed_id) as feed_title,"; | |
1362 | } else if ($feed >= 0 && $search && $search_mode == "This category") { | |
1363 | ||
1364 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1365 | ||
1366 | $tmp_result = db_query($link, "SELECT id | |
1367 | FROM ttrss_feeds WHERE cat_id = | |
1368 | (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'"); | |
1369 | ||
1370 | $cat_siblings = array(); | |
1371 | ||
1372 | if (db_num_rows($tmp_result) > 0) { | |
1373 | while ($p = db_fetch_assoc($tmp_result)) { | |
1374 | array_push($cat_siblings, "feed_id = " . $p["id"]); | |
1375 | } | |
1376 | ||
1377 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
1378 | $feed, implode(" OR ", $cat_siblings)); | |
1379 | ||
1380 | } else { | |
1381 | $query_strategy_part = "ttrss_entries.id > 0"; | |
1382 | } | |
1383 | ||
1384 | } else if ($feed >= 0) { | |
1385 | ||
1386 | if ($cat_view) { | |
1387 | ||
1388 | if ($feed > 0) { | |
1389 | $query_strategy_part = "cat_id = '$feed'"; | |
1390 | } else { | |
1391 | $query_strategy_part = "cat_id IS NULL"; | |
1392 | } | |
1393 | ||
1394 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1395 | ||
1396 | } else { | |
1397 | $tmp_result = db_query($link, "SELECT id | |
1398 | FROM ttrss_feeds WHERE parent_feed = '$feed' | |
1399 | ORDER BY cat_id,title"); | |
1400 | ||
1401 | $parent_ids = array(); | |
1402 | ||
1403 | if (db_num_rows($tmp_result) > 0) { | |
1404 | while ($p = db_fetch_assoc($tmp_result)) { | |
1405 | array_push($parent_ids, "feed_id = " . $p["id"]); | |
1406 | } | |
1407 | ||
1408 | $query_strategy_part = sprintf("(feed_id = %d OR %s)", | |
1409 | $feed, implode(" OR ", $parent_ids)); | |
1410 | ||
1411 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1412 | } else { | |
1413 | $query_strategy_part = "feed_id = '$feed'"; | |
1414 | } | |
1415 | } | |
1416 | } else if ($feed == -1) { // starred virtual feed | |
1417 | $query_strategy_part = "marked = true"; | |
1418 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1419 | } else if ($feed <= -10) { // labels | |
1420 | $label_id = -$feed - 11; | |
1421 | ||
1422 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
1423 | WHERE id = '$label_id'"); | |
1424 | ||
1425 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
1426 | ||
1427 | $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; | |
1428 | } else { | |
1429 | $query_strategy_part = "id > 0"; // dumb | |
1430 | } | |
1431 | ||
1432 | $order_by = "updated DESC"; | |
1433 | ||
1434 | // if ($feed < -10) { | |
1435 | // $order_by = "feed_id,updated DESC"; | |
1436 | // } | |
1437 | ||
1438 | $feed_title = ""; | |
1439 | ||
1440 | if ($search && $search_mode == "All feeds") { | |
1441 | $feed_title = "Global search results ($search)"; | |
1442 | } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { | |
1443 | $feed_title = "Feed search results ($search, $feed)"; | |
1444 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) { | |
1445 | $feed_title = $feed; | |
1446 | } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) { | |
1447 | ||
1448 | if ($cat_view) { | |
1449 | ||
1450 | if ($feed != 0) { | |
1451 | $result = db_query($link, "SELECT title FROM ttrss_feed_categories | |
1452 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
1453 | $feed_title = db_fetch_result($result, 0, "title"); | |
1454 | } else { | |
1455 | $feed_title = "Uncategorized"; | |
1456 | } | |
1457 | } else { | |
1458 | ||
1459 | $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds | |
1460 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]); | |
1461 | ||
1462 | $feed_title = db_fetch_result($result, 0, "title"); | |
1463 | $feed_site_url = db_fetch_result($result, 0, "site_url"); | |
1464 | $last_error = db_fetch_result($result, 0, "last_error"); | |
1465 | ||
1466 | } | |
1467 | ||
1468 | } else if ($feed == -1) { | |
1469 | $feed_title = "Starred articles"; | |
1470 | } else if ($feed < -10) { | |
1471 | $label_id = -$feed - 11; | |
1472 | $result = db_query($link, "SELECT description FROM ttrss_labels | |
1473 | WHERE id = '$label_id'"); | |
1474 | $feed_title = db_fetch_result($result, 0, "description"); | |
1475 | } else { | |
1476 | $feed_title = "?"; | |
1477 | } | |
1478 | ||
1479 | if ($feed < -10) error_reporting (0); | |
1480 | ||
1481 | print "<div id=\"headlinesContainer\">"; | |
1482 | ||
1483 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) { | |
1484 | ||
1485 | if ($feed >= 0) { | |
1486 | $feed_kind = "Feeds"; | |
1487 | } else { | |
1488 | $feed_kind = "Labels"; | |
1489 | } | |
1490 | ||
1491 | // if (!$vfeed_query_part) { | |
1492 | $content_query_part = "content as content_preview,"; | |
1493 | // } else { | |
1494 | // $content_query_part = ""; | |
1495 | // } | |
1496 | ||
1497 | $query = "SELECT | |
1498 | ttrss_entries.id,ttrss_entries.title, | |
1499 | SUBSTRING(updated,1,16) as updated, | |
1500 | unread,feed_id,marked,link,last_read, | |
1501 | SUBSTRING(last_read,1,19) as last_read_noms, | |
1502 | $vfeed_query_part | |
1503 | $content_query_part | |
1504 | SUBSTRING(updated,1,19) as updated_noms | |
1505 | FROM | |
1506 | ttrss_entries,ttrss_user_entries,ttrss_feeds | |
1507 | WHERE | |
1508 | ttrss_user_entries.feed_id = ttrss_feeds.id AND | |
1509 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
1510 | ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND | |
1511 | $search_query_part | |
1512 | $view_query_part | |
1513 | $query_strategy_part ORDER BY $order_by | |
1514 | $limit_query_part"; | |
1515 | ||
1516 | $result = db_query($link, $query); | |
1517 | ||
1518 | if ($_GET["debug"]) print $query; | |
1519 | ||
1520 | } else { | |
1521 | // browsing by tag | |
1522 | ||
1523 | $feed_kind = "Tags"; | |
1524 | ||
1525 | $result = db_query($link, "SELECT | |
1526 | ttrss_entries.id as id,title, | |
1527 | SUBSTRING(updated,1,16) as updated, | |
1528 | unread,feed_id, | |
1529 | marked,link,last_read, | |
1530 | SUBSTRING(last_read,1,19) as last_read_noms, | |
1531 | $vfeed_query_part | |
1532 | $content_query_part | |
1533 | SUBSTRING(updated,1,19) as updated_noms | |
1534 | FROM | |
1535 | ttrss_entries,ttrss_user_entries,ttrss_tags | |
1536 | WHERE | |
1537 | ref_id = ttrss_entries.id AND | |
1538 | ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND | |
1539 | post_int_id = int_id AND tag_name = '$feed' AND | |
1540 | $view_query_part | |
1541 | $search_query_part | |
1542 | $query_strategy_part ORDER BY $order_by | |
1543 | $limit_query_part"); | |
1544 | } | |
1545 | ||
1546 | if (!$result) { | |
1547 | print "<div align='center'> | |
1548 | Could not display feed (query failed). Please check label match syntax or local configuration.</div>"; | |
1549 | return; | |
1550 | } | |
1551 | ||
1552 | function print_headline_subtoolbar($link, $feed_site_url, $feed_title, | |
1553 | $bottom = false, $rtl_content = false) { | |
1554 | ||
1555 | if (!$bottom) { | |
1556 | $class = "headlinesSubToolbar"; | |
1557 | $tid = "headlineActionsTop"; | |
1558 | } else { | |
1559 | $class = "invisible"; | |
1560 | $tid = "headlineActionsBottom"; | |
1561 | } | |
1562 | ||
1563 | print "<table class=\"$class\" id=\"$tid\" | |
1564 | width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>"; | |
1565 | ||
1566 | if ($rtl_content) { | |
1567 | $rtl_cpart = "RTL"; | |
1568 | } else { | |
1569 | $rtl_cpart = ""; | |
1570 | } | |
1571 | ||
1572 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1573 | ||
1574 | print "<td class=\"headlineActions$rtl_cpart\"> | |
1575 | Select: | |
1576 | <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>, | |
1577 | <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>, | |
1578 | <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a> | |
1579 | | |
1580 | Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>, | |
1581 | <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>"; | |
1582 | print "</td>"; | |
1583 | ||
1584 | } else { | |
1585 | ||
1586 | print "<td class=\"headlineActions$rtl_cpart\"> | |
1587 | Select: | |
1588 | <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>, | |
1589 | <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>, | |
1590 | <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a> | |
1591 | | |
1592 | Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>, | |
1593 | <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>"; | |
1594 | ||
1595 | print "</td>"; | |
1596 | ||
1597 | } | |
1598 | ||
1599 | print "<td class=\"headlineTitle$rtl_cpart\">"; | |
1600 | ||
1601 | if ($feed_site_url) { | |
1602 | if (!$bottom) { | |
1603 | $target = "target=\"_blank\""; | |
1604 | } | |
1605 | print "<a $target href=\"$feed_site_url\">$feed_title</a>"; | |
1606 | } else { | |
1607 | print $feed_title; | |
1608 | } | |
1609 | ||
1610 | print "</td>"; | |
1611 | print "</tr></table>"; | |
1612 | ||
1613 | } | |
1614 | ||
1615 | if (db_num_rows($result) > 0) { | |
1616 | ||
1617 | print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, | |
1618 | $rtl_content); | |
1619 | ||
1620 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1621 | print "<table class=\"headlinesList\" id=\"headlinesList\" | |
1622 | cellspacing=\"0\" width=\"100%\">"; | |
1623 | } | |
1624 | ||
1625 | $lnum = 0; | |
1626 | ||
1627 | error_reporting (DEFAULT_ERROR_LEVEL); | |
1628 | ||
1629 | $num_unread = 0; | |
1630 | ||
1631 | while ($line = db_fetch_assoc($result)) { | |
1632 | ||
1633 | $class = ($lnum % 2) ? "even" : "odd"; | |
1634 | ||
1635 | $id = $line["id"]; | |
1636 | $feed_id = $line["feed_id"]; | |
1637 | ||
1638 | if ($line["last_read"] == "" && | |
1639 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
1640 | ||
1641 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
1642 | alt=\"Updated\">"; | |
1643 | } else { | |
1644 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
1645 | alt=\"Updated\">"; | |
1646 | } | |
1647 | ||
1648 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
1649 | $class .= "Unread"; | |
1650 | ++$num_unread; | |
1651 | $is_unread = true; | |
1652 | } else { | |
1653 | $is_unread = false; | |
1654 | } | |
1655 | ||
1656 | if ($line["marked"] == "t" || $line["marked"] == "1") { | |
1657 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" | |
1658 | alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>"; | |
1659 | } else { | |
1660 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
1661 | alt=\"Set mark\" onclick='javascript:toggleMark($id)'>"; | |
1662 | } | |
1663 | ||
1664 | $content_link = "<a href=\"javascript:view($id,$feed_id);\">" . | |
1665 | $line["title"] . "</a>"; | |
1666 | ||
1667 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
1668 | $updated_fmt = smart_date_time(strtotime($line["updated"])); | |
1669 | } else { | |
1670 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
1671 | $updated_fmt = date($short_date, strtotime($line["updated"])); | |
1672 | } | |
1673 | ||
1674 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) { | |
1675 | $content_preview = truncate_string(strip_tags($line["content_preview"]), | |
1676 | 100); | |
1677 | } | |
1678 | ||
1679 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1680 | ||
1681 | print "<tr class='$class' id='RROW-$id'>"; | |
1682 | ||
1683 | print "<td class='hlUpdatePic'>$update_pic</td>"; | |
1684 | ||
1685 | print "<td class='hlSelectRow'> | |
1686 | <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\" | |
1687 | class=\"feedCheckBox\" id=\"RCHK-$id\"> | |
1688 | </td>"; | |
1689 | ||
1690 | print "<td class='hlMarkedPic'>$marked_pic</td>"; | |
1691 | ||
1692 | if ($line["feed_title"]) { | |
1693 | print "<td class='hlContent'>$content_link</td>"; | |
1694 | print "<td class='hlFeed'> | |
1695 | <a href='javascript:viewfeed($feed_id)'>". | |
1696 | $line["feed_title"]."</a> </td>"; | |
1697 | } else { | |
1698 | print "<td class='hlContent' valign='middle'>"; | |
1699 | ||
1700 | print "<a href=\"javascript:view($id,$feed_id);\">" . | |
1701 | $line["title"]; | |
1702 | ||
1703 | if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) { | |
1704 | if ($content_preview) { | |
1705 | print "<span class=\"contentPreview\"> - $content_preview</span>"; | |
1706 | } | |
1707 | } | |
1708 | ||
1709 | print "</a>"; | |
1710 | print "</td>"; | |
1711 | } | |
1712 | ||
1713 | print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>"; | |
1714 | ||
1715 | print "</tr>"; | |
1716 | ||
1717 | } else { | |
1718 | ||
1719 | if ($is_unread) { | |
1720 | $add_class = "Unread"; | |
1721 | } else { | |
1722 | $add_class = ""; | |
1723 | } | |
1724 | ||
1725 | print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">"; | |
1726 | ||
1727 | print "<div class=\"cdmHeader\">"; | |
1728 | ||
1729 | print "<div style=\"float : right\">$updated_fmt</div>"; | |
1730 | ||
1731 | print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>"; | |
1732 | ||
1733 | if ($line["feed_title"]) { | |
1734 | print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)"; | |
1735 | } | |
1736 | ||
1737 | print "</div>"; | |
1738 | ||
1739 | print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>"; | |
1740 | ||
1741 | print "<div style=\"float : right\">$marked_pic</div> | |
1742 | <div class=\"cdmFooter\"> | |
1743 | <input type=\"checkbox\" onclick=\"toggleSelectRowById(this, | |
1744 | 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>"; | |
1745 | ||
1746 | print "</div>"; | |
1747 | ||
1748 | } | |
1749 | ||
1750 | ++$lnum; | |
1751 | } | |
1752 | ||
1753 | if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { | |
1754 | print "</table>"; | |
1755 | } | |
1756 | ||
1757 | print_headline_subtoolbar($link, | |
1758 | "javascript:catchupPage()", "Mark page as read", true); | |
1759 | ||
1760 | ||
1761 | } else { | |
1762 | print "<div width='100%' align='center'>No articles found.</div>"; | |
1763 | } | |
1764 | ||
1765 | print "</div>"; | |
1766 | ||
1767 | print "<script type=\"text/javascript\"> | |
1768 | document.onkeydown = hotkey_handler; | |
1769 | // if (parent.daemon_enabled) parent.updateTitle('$feed_title'); | |
1770 | update_all_counters('$feed'); | |
1771 | </script>"; | |
1772 | ||
1773 | print ' | |
1774 | <script type="text/javascript"> | |
1775 | /* for IE */ | |
1776 | function statechange() { | |
1777 | if (document.readyState == "interactive") init(); | |
1778 | } | |
1779 | ||
1780 | if (document.readyState) { | |
1781 | if (document.readyState == "interactive" || document.readyState == "complete") { | |
1782 | init(); | |
1783 | } else { | |
1784 | document.onreadystatechange = statechange; | |
1785 | } | |
1786 | } | |
1787 | </script>'; | |
1788 | ||
1789 | print "</body></html>"; | |
1790 | } | |
1791 | ||
1792 | if ($op == "pref-rpc") { | |
1793 | ||
1794 | $subop = $_GET["subop"]; | |
1795 | ||
1796 | if ($subop == "unread") { | |
1797 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1798 | foreach ($ids as $id) { | |
1799 | db_query($link, "UPDATE ttrss_user_entries SET unread = true | |
1800 | WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
1801 | } | |
1802 | ||
1803 | print "Marked selected feeds as unread."; | |
1804 | } | |
1805 | ||
1806 | if ($subop == "read") { | |
1807 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1808 | foreach ($ids as $id) { | |
1809 | db_query($link, "UPDATE ttrss_user_entries | |
1810 | SET unread = false,last_read = NOW() WHERE | |
1811 | feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]); | |
1812 | } | |
1813 | ||
1814 | print "Marked selected feeds as read."; | |
1815 | ||
1816 | } | |
1817 | ||
1818 | } | |
1819 | ||
1820 | if ($op == "pref-feeds") { | |
1821 | ||
1822 | $subop = $_REQUEST["subop"]; | |
1823 | $quiet = $_REQUEST["quiet"]; | |
1824 | ||
1825 | if ($subop == "massSubscribe") { | |
1826 | $ids = split(",", db_escape_string($_GET["ids"])); | |
1827 | ||
1828 | $subscribed = array(); | |
1829 | ||
1830 | foreach ($ids as $id) { | |
1831 | $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds | |
1832 | WHERE id = '$id'"); | |
1833 | ||
1834 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
1835 | $title = db_fetch_result($result, 0, "title"); | |
1836 | ||
1837 | $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE | |
1838 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); | |
1839 | ||
1840 | if (db_num_rows($result) == 0) { | |
1841 | $result = db_query($link, | |
1842 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
1843 | VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); | |
1844 | ||
1845 | array_push($subscribed, $title); | |
1846 | } | |
1847 | } | |
1848 | ||
1849 | if (count($subscribed) > 0) { | |
1850 | print "<div class=\"notice\">"; | |
1851 | print "<b>Subscribed to feeds:</b>"; | |
1852 | print "<ul class=\"nomarks\">"; | |
1853 | foreach ($subscribed as $title) { | |
1854 | print "<li>$title</li>"; | |
1855 | } | |
1856 | print "</ul>"; | |
1857 | print "</div>"; | |
1858 | } | |
1859 | } | |
1860 | ||
1861 | if ($subop == "browse") { | |
1862 | ||
1863 | if (!ENABLE_FEED_BROWSER) { | |
1864 | print "Feed browser is administratively disabled."; | |
1865 | return; | |
1866 | } | |
1867 | ||
1868 | print "<div class=\"infoBoxContents\">"; | |
1869 | ||
1870 | print "<h1>Feed browser</h1>"; | |
1871 | ||
1872 | print "<p>Showing top 50 registered feeds, sorted by popularity:</p>"; | |
1873 | ||
1874 | $result = db_query($link, "SELECT feed_url,count(id) AS subscribers | |
1875 | FROM ttrss_feeds | |
1876 | WHERE auth_login = '' AND auth_pass = '' AND private = false | |
1877 | GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50"); | |
1878 | ||
1879 | print "<ul class='browseFeedList' id='browseFeedList'>"; | |
1880 | ||
1881 | $feedctr = 0; | |
1882 | ||
1883 | while ($line = db_fetch_assoc($result)) { | |
1884 | $feed_url = $line["feed_url"]; | |
1885 | $subscribers = $line["subscribers"]; | |
1886 | ||
1887 | $sub_result = db_query($link, "SELECT id | |
1888 | FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" . | |
1889 | $_SESSION["uid"]); | |
1890 | ||
1891 | if (db_num_rows($sub_result) > 0) { | |
1892 | continue; // already subscribed | |
1893 | } | |
1894 | ||
1895 | $det_result = db_query($link, "SELECT site_url,title,id | |
1896 | FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); | |
1897 | ||
1898 | $details = db_fetch_assoc($det_result); | |
1899 | ||
1900 | $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; | |
1901 | ||
1902 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1903 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . | |
1904 | "/".$details["id"].".ico\">"; | |
1905 | } else { | |
1906 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
1907 | } | |
1908 | ||
1909 | $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' | |
1910 | type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">"; | |
1911 | ||
1912 | $class = ($feedctr % 2) ? "even" : "odd"; | |
1913 | ||
1914 | print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box". | |
1915 | "$feed_icon " . db_unescape_string($details["title"]) . | |
1916 | " <span class='subscribers'>($subscribers)</span></li>"; | |
1917 | ||
1918 | ++$feedctr; | |
1919 | } | |
1920 | ||
1921 | if ($feedctr == 0) { | |
1922 | print "<li>No feeds found to subscribe.</li>"; | |
1923 | } | |
1924 | ||
1925 | print "</ul>"; | |
1926 | ||
1927 | print "<div align='center'> | |
1928 | <input type=\"submit\" class=\"button\" | |
1929 | onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\"> | |
1930 | <input type='submit' class='button' | |
1931 | onclick=\"closeInfoBox()\" value=\"Cancel\"></div>"; | |
1932 | ||
1933 | print "</div>"; | |
1934 | return; | |
1935 | } | |
1936 | ||
1937 | if ($subop == "editfeed") { | |
1938 | $feed_id = db_escape_string($_GET["id"]); | |
1939 | ||
1940 | $result = db_query($link, | |
1941 | "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND | |
1942 | owner_uid = " . $_SESSION["uid"]); | |
1943 | ||
1944 | $title = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1945 | 0, "title"))); | |
1946 | ||
1947 | print "<div class=\"infoBoxContents\">"; | |
1948 | ||
1949 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
1950 | ||
1951 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
1952 | $feed_icon = "<img width=\"16\" height=\"16\" | |
1953 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
1954 | } else { | |
1955 | $feed_icon = ""; | |
1956 | } | |
1957 | ||
1958 | print "<h1>$feed_icon $title</h1>"; | |
1959 | ||
1960 | print "<table width='100%'>"; | |
1961 | ||
1962 | $row_class = "odd"; | |
1963 | ||
1964 | print "<tr class='$row_class'><td>Title:</td>"; | |
1965 | print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>"; | |
1966 | ||
1967 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
1968 | $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result, | |
1969 | 0, "feed_url"))); | |
1970 | $row_class = toggleEvenOdd($row_class); | |
1971 | ||
1972 | print "<tr class='$row_class'><td>Feed URL:</td>"; | |
1973 | print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>"; | |
1974 | ||
1975 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
1976 | ||
1977 | $cat_id = db_fetch_result($result, 0, "cat_id"); | |
1978 | ||
1979 | $row_class = toggleEvenOdd($row_class); | |
1980 | ||
1981 | print "<tr class='$row_class'><td>Category:</td>"; | |
1982 | print "<td>"; | |
1983 | print "<select id=\"iedit_fcat\">"; | |
1984 | print "<option id=\"0\">Uncategorized</option>"; | |
1985 | ||
1986 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories | |
1987 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
1988 | ||
1989 | if (db_num_rows($tmp_result) > 0) { | |
1990 | print "<option disabled>--------</option>"; | |
1991 | } | |
1992 | ||
1993 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
1994 | if ($tmp_line["id"] == $cat_id) { | |
1995 | $is_selected = "selected"; | |
1996 | } else { | |
1997 | $is_selected = ""; | |
1998 | } | |
1999 | printf("<option $is_selected id='%d'>%s</option>", | |
2000 | $tmp_line["id"], $tmp_line["title"]); | |
2001 | } | |
2002 | ||
2003 | print "</select></td>"; | |
2004 | print "</td></tr>"; | |
2005 | ||
2006 | } | |
2007 | ||
2008 | $update_interval = db_fetch_result($result, 0, "update_interval"); | |
2009 | $row_class = toggleEvenOdd($row_class); | |
2010 | ||
2011 | print "<tr class='$row_class'><td>Update Interval:</td>"; | |
2012 | // print "<td><input id=\"iedit_updintl\" | |
2013 | // value=\"$update_interval\"></td></tr>"; | |
2014 | ||
2015 | print "<td>"; | |
2016 | ||
2017 | print "<select id=\"iedit_updintl\">"; | |
2018 | ||
2019 | foreach (array_keys($update_intervals) as $i) { | |
2020 | ||
2021 | if ($i == $update_interval) { | |
2022 | $selected = "selected"; | |
2023 | } else { | |
2024 | $selected = ""; | |
2025 | } | |
2026 | print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>"; | |
2027 | } | |
2028 | ||
2029 | print "</select>"; | |
2030 | ||
2031 | print "</td>"; | |
2032 | ||
2033 | $row_class = toggleEvenOdd($row_class); | |
2034 | print "<tr class='$row_class'><td>Link to:</td>"; | |
2035 | ||
2036 | $tmp_result = db_query($link, "SELECT COUNT(id) AS count | |
2037 | FROM ttrss_feeds WHERE parent_feed = '$feed_id'"); | |
2038 | ||
2039 | $linked_count = db_fetch_result($tmp_result, 0, "count"); | |
2040 | ||
2041 | $parent_feed = db_fetch_result($result, 0, "parent_feed"); | |
2042 | ||
2043 | if ($linked_count > 0) { | |
2044 | $disabled = "disabled"; | |
2045 | } | |
2046 | ||
2047 | print "<select $disabled id=\"iedit_parent_feed\">"; | |
2048 | ||
2049 | print "<option id=\"0\">Not linked</option>"; | |
2050 | ||
2051 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2052 | if ($cat_id) { | |
2053 | $cat_qpart = "AND cat_id = '$cat_id'"; | |
2054 | } else { | |
2055 | $cat_qpart = "AND cat_id IS NULL"; | |
2056 | } | |
2057 | } | |
2058 | ||
2059 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2060 | WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." | |
2061 | $cat_qpart ORDER BY title"); | |
2062 | ||
2063 | if (db_num_rows($tmp_result) > 0) { | |
2064 | print "<option disabled>--------</option>"; | |
2065 | } | |
2066 | ||
2067 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2068 | if ($tmp_line["id"] == $parent_feed) { | |
2069 | $is_selected = "selected"; | |
2070 | } else { | |
2071 | $is_selected = ""; | |
2072 | } | |
2073 | printf("<option $is_selected id='%d'>%s</option>", | |
2074 | $tmp_line["id"], $tmp_line["title"]); | |
2075 | } | |
2076 | ||
2077 | print "</select></td>"; | |
2078 | print "</td></tr>"; | |
2079 | ||
2080 | $purge_interval = db_fetch_result($result, 0, "purge_interval"); | |
2081 | $row_class = toggleEvenOdd($row_class); | |
2082 | ||
2083 | print "<tr class='$row_class'><td>Purge Days:</td>"; | |
2084 | // print "<td><input id=\"iedit_purgintl\" | |
2085 | // value=\"$purge_interval\"></td></tr>"; | |
2086 | ||
2087 | print "<td>"; | |
2088 | ||
2089 | print "<select id=\"iedit_purgintl\">"; | |
2090 | ||
2091 | foreach (array_keys($purge_intervals) as $i) { | |
2092 | ||
2093 | if ($i == $purge_interval) { | |
2094 | $selected = "selected"; | |
2095 | } else { | |
2096 | $selected = ""; | |
2097 | } | |
2098 | print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>"; | |
2099 | } | |
2100 | ||
2101 | print "</select>"; | |
2102 | ||
2103 | print "</td>"; | |
2104 | ||
2105 | // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>"; | |
2106 | ||
2107 | $row_class = toggleEvenOdd($row_class); | |
2108 | $auth_login = db_fetch_result($result, 0, "auth_login"); | |
2109 | ||
2110 | print "<tr class='$row_class'><td>Login:</td>"; | |
2111 | print "<td><input id=\"iedit_login\" | |
2112 | value=\"$auth_login\"></td></tr>"; | |
2113 | ||
2114 | $row_class = toggleEvenOdd($row_class); | |
2115 | $auth_pass = db_fetch_result($result, 0, "auth_pass"); | |
2116 | ||
2117 | print "<tr class='$row_class'><td>Password:</td>"; | |
2118 | print "<td><input type=\"password\" id=\"iedit_pass\" | |
2119 | value=\"$auth_pass\"></td></tr>"; | |
2120 | ||
2121 | $row_class = toggleEvenOdd($row_class); | |
2122 | $private = sql_bool_to_bool(db_fetch_result($result, 0, "private")); | |
2123 | ||
2124 | if ($private) { | |
2125 | $checked = "checked"; | |
2126 | } else { | |
2127 | $checked = ""; | |
2128 | } | |
2129 | ||
2130 | print "<tr class='$row_class'><td valign='top'>Options:</td>"; | |
2131 | print "<td><input type=\"checkbox\" id=\"iedit_private\" | |
2132 | $checked><label for=\"iedit_private\">Hide from feed browser</label>"; | |
2133 | ||
2134 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); | |
2135 | ||
2136 | if ($rtl_content) { | |
2137 | $checked = "checked"; | |
2138 | } else { | |
2139 | $checked = ""; | |
2140 | } | |
2141 | ||
2142 | print "<br><input type=\"checkbox\" id=\"iedit_rtl\" | |
2143 | $checked><label for=\"iedit_rtl\">Right-to-left content</label>"; | |
2144 | ||
2145 | print "</td></tr>"; | |
2146 | ||
2147 | print "</table>"; | |
2148 | print "</div>"; | |
2149 | ||
2150 | print "<div align='center'> | |
2151 | <input type=\"submit\" class=\"button\" | |
2152 | onclick=\"feedEditSave()\" value=\"Save\"> | |
2153 | <input type='submit' class='button' | |
2154 | onclick=\"feedEditCancel()\" value=\"Cancel\"></div>"; | |
2155 | return; | |
2156 | } | |
2157 | ||
2158 | if ($subop == "editSave") { | |
2159 | $feed_title = db_escape_string($_POST["t"]); | |
2160 | $feed_link = db_escape_string($_POST["l"]); | |
2161 | $upd_intl = db_escape_string($_POST["ui"]); | |
2162 | $purge_intl = db_escape_string($_POST["pi"]); | |
2163 | $feed_id = db_escape_string($_POST["id"]); | |
2164 | $cat_id = db_escape_string($_POST["catid"]); | |
2165 | $auth_login = db_escape_string($_POST["login"]); | |
2166 | $auth_pass = db_escape_string($_POST["pass"]); | |
2167 | $parent_feed = db_escape_string($_POST["pfeed"]); | |
2168 | $private = db_escape_string($_POST["is_pvt"]); | |
2169 | $rtl_content = db_escape_string($_POST["is_rtl"]); | |
2170 | ||
2171 | if (strtoupper($upd_intl) == "DEFAULT") | |
2172 | $upd_intl = 0; | |
2173 | ||
2174 | if (strtoupper($upd_intl) == "DISABLED") | |
2175 | $upd_intl = -1; | |
2176 | ||
2177 | if (strtoupper($purge_intl) == "DEFAULT") | |
2178 | $purge_intl = 0; | |
2179 | ||
2180 | if (strtoupper($purge_intl) == "DISABLED") | |
2181 | $purge_intl = -1; | |
2182 | ||
2183 | if ($cat_id != 0) { | |
2184 | $category_qpart = "cat_id = '$cat_id'"; | |
2185 | } else { | |
2186 | $category_qpart = 'cat_id = NULL'; | |
2187 | } | |
2188 | ||
2189 | if ($parent_feed != 0) { | |
2190 | $parent_qpart = "parent_feed = '$parent_feed'"; | |
2191 | } else { | |
2192 | $parent_qpart = 'parent_feed = NULL'; | |
2193 | } | |
2194 | ||
2195 | $result = db_query($link, "UPDATE ttrss_feeds SET | |
2196 | $category_qpart, | |
2197 | $parent_qpart, | |
2198 | title = '$feed_title', feed_url = '$feed_link', | |
2199 | update_interval = '$upd_intl', | |
2200 | purge_interval = '$purge_intl', | |
2201 | auth_login = '$auth_login', | |
2202 | auth_pass = '$auth_pass', | |
2203 | private = $private, | |
2204 | rtl_content = $rtl_content | |
2205 | WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); | |
2206 | } | |
2207 | ||
2208 | if ($subop == "saveCat") { | |
2209 | $cat_title = db_escape_string($_GET["title"]); | |
2210 | $cat_id = db_escape_string($_GET["id"]); | |
2211 | ||
2212 | $result = db_query($link, "UPDATE ttrss_feed_categories SET | |
2213 | title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); | |
2214 | ||
2215 | } | |
2216 | ||
2217 | if ($subop == "remove") { | |
2218 | ||
2219 | if (!WEB_DEMO_MODE) { | |
2220 | ||
2221 | $ids = split(",", db_escape_string($_GET["ids"])); | |
2222 | ||
2223 | foreach ($ids as $id) { | |
2224 | db_query($link, "DELETE FROM ttrss_feeds | |
2225 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
2226 | ||
2227 | $icons_dir = ICONS_DIR; | |
2228 | ||
2229 | if (file_exists($icons_dir . "/$id.ico")) { | |
2230 | unlink($icons_dir . "/$id.ico"); | |
2231 | } | |
2232 | } | |
2233 | } | |
2234 | } | |
2235 | ||
2236 | if ($subop == "add") { | |
2237 | ||
2238 | if (!WEB_DEMO_MODE) { | |
2239 | ||
2240 | $feed_link = db_escape_string(trim($_GET["link"])); | |
2241 | $cat_id = db_escape_string($_GET["cid"]); | |
2242 | ||
2243 | if ($cat_id == "0" || !$cat_id) { | |
2244 | $cat_qpart = "NULL"; | |
2245 | } else { | |
2246 | $cat_qpart = "'$cat_id'"; | |
2247 | } | |
2248 | ||
2249 | $result = db_query($link, | |
2250 | "SELECT id FROM ttrss_feeds | |
2251 | WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]); | |
2252 | ||
2253 | if (db_num_rows($result) == 0) { | |
2254 | ||
2255 | $result = db_query($link, | |
2256 | "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) | |
2257 | VALUES ('".$_SESSION["uid"]."', '$feed_link', | |
2258 | '[Unknown]', $cat_qpart)"); | |
2259 | ||
2260 | $result = db_query($link, | |
2261 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' | |
2262 | AND owner_uid = " . $_SESSION["uid"]); | |
2263 | ||
2264 | $feed_id = db_fetch_result($result, 0, "id"); | |
2265 | ||
2266 | if ($feed_id) { | |
2267 | update_rss_feed($link, $feed_link, $feed_id, true); | |
2268 | } | |
2269 | } else { | |
2270 | ||
2271 | print "<div class=\"warning\"> | |
2272 | Feed <b>$feed_link</b> already exists in the database. | |
2273 | </div>"; | |
2274 | } | |
2275 | } | |
2276 | } | |
2277 | ||
2278 | if ($subop == "addCat") { | |
2279 | ||
2280 | if (!WEB_DEMO_MODE) { | |
2281 | ||
2282 | $feed_cat = db_escape_string(trim($_GET["cat"])); | |
2283 | ||
2284 | $result = db_query($link, | |
2285 | "SELECT id FROM ttrss_feed_categories | |
2286 | WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]); | |
2287 | ||
2288 | if (db_num_rows($result) == 0) { | |
2289 | ||
2290 | $result = db_query($link, | |
2291 | "INSERT INTO ttrss_feed_categories (owner_uid,title) | |
2292 | VALUES ('".$_SESSION["uid"]."', '$feed_cat')"); | |
2293 | ||
2294 | } else { | |
2295 | ||
2296 | print "<div class=\"warning\"> | |
2297 | Category <b>$feed_cat</b> already exists in the database. | |
2298 | </div>"; | |
2299 | } | |
2300 | ||
2301 | ||
2302 | } | |
2303 | } | |
2304 | ||
2305 | if ($subop == "removeCats") { | |
2306 | ||
2307 | if (!WEB_DEMO_MODE) { | |
2308 | ||
2309 | $ids = split(",", db_escape_string($_GET["ids"])); | |
2310 | ||
2311 | foreach ($ids as $id) { | |
2312 | ||
2313 | db_query($link, "BEGIN"); | |
2314 | ||
2315 | $result = db_query($link, | |
2316 | "SELECT count(id) as num_feeds FROM ttrss_feeds | |
2317 | WHERE cat_id = '$id'"); | |
2318 | ||
2319 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
2320 | ||
2321 | if ($num_feeds == 0) { | |
2322 | db_query($link, "DELETE FROM ttrss_feed_categories | |
2323 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
2324 | } else { | |
2325 | ||
2326 | print "<div class=\"warning\"> | |
2327 | Unable to delete non empty feed categories.</div>"; | |
2328 | ||
2329 | } | |
2330 | ||
2331 | db_query($link, "COMMIT"); | |
2332 | } | |
2333 | } | |
2334 | } | |
2335 | ||
2336 | if ($subop == "categorize") { | |
2337 | ||
2338 | if (!WEB_DEMO_MODE) { | |
2339 | ||
2340 | $ids = split(",", db_escape_string($_GET["ids"])); | |
2341 | ||
2342 | $cat_id = db_escape_string($_GET["cat_id"]); | |
2343 | ||
2344 | if ($cat_id == 0) { | |
2345 | $cat_id_qpart = 'NULL'; | |
2346 | } else { | |
2347 | $cat_id_qpart = "'$cat_id'"; | |
2348 | } | |
2349 | ||
2350 | db_query($link, "BEGIN"); | |
2351 | ||
2352 | foreach ($ids as $id) { | |
2353 | ||
2354 | db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart | |
2355 | WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); | |
2356 | } | |
2357 | ||
2358 | db_query($link, "COMMIT"); | |
2359 | } | |
2360 | ||
2361 | } | |
2362 | ||
2363 | if ($quiet) return; | |
2364 | ||
2365 | // print "<h3>Edit Feeds</h3>"; | |
2366 | ||
2367 | $result = db_query($link, "SELECT id,title,feed_url,last_error | |
2368 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); | |
2369 | ||
2370 | if (db_num_rows($result) > 0) { | |
2371 | ||
2372 | print "<div class=\"warning\">"; | |
2373 | ||
2374 | // print"<img class=\"closeButton\" | |
2375 | // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">"; | |
2376 | ||
2377 | print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\"> | |
2378 | <b>Feeds with update errors</b> (click to expand)</a>"; | |
2379 | ||
2380 | print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">"; | |
2381 | ||
2382 | while ($line = db_fetch_assoc($result)) { | |
2383 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
2384 | $line["last_error"]; | |
2385 | } | |
2386 | ||
2387 | print "</ul>"; | |
2388 | print "</div>"; | |
2389 | ||
2390 | } | |
2391 | ||
2392 | $feed_search = db_escape_string($_GET["search"]); | |
2393 | ||
2394 | if (array_key_exists("search", $_GET)) { | |
2395 | $_SESSION["prefs_feed_search"] = $feed_search; | |
2396 | } else { | |
2397 | $feed_search = $_SESSION["prefs_feed_search"]; | |
2398 | } | |
2399 | ||
2400 | print "<table width='100%' class=\"prefGenericAddBox\" | |
2401 | cellspacing='0' cellpadding='0'><tr> | |
2402 | <td> | |
2403 | <input id=\"fadd_link\" | |
2404 | onchange=\"javascript:addFeed()\" | |
2405 | size=\"40\"> | |
2406 | <input type=\"submit\" class=\"button\" | |
2407 | onclick=\"javascript:addFeed()\" value=\"Add feed\">"; | |
2408 | ||
2409 | if (ENABLE_FEED_BROWSER) { | |
2410 | print " (<a href='javascript:browseFeeds()'>Top 50</a>)"; | |
2411 | } | |
2412 | ||
2413 | print "</td><td align='right'> | |
2414 | <input id=\"feed_search\" size=\"20\" | |
2415 | onchange=\"javascript:updateFeedList()\" | |
2416 | value=\"$feed_search\"> | |
2417 | <input type=\"submit\" class=\"button\" | |
2418 | onclick=\"javascript:updateFeedList()\" value=\"Search\"> | |
2419 | </td> | |
2420 | </tr></table>"; | |
2421 | ||
2422 | $feeds_sort = db_escape_string($_GET["sort"]); | |
2423 | ||
2424 | if (!$feeds_sort || $feeds_sort == "undefined") { | |
2425 | $feeds_sort = $_SESSION["pref_sort_feeds"]; | |
2426 | if (!$feeds_sort) $feeds_sort = "title"; | |
2427 | } | |
2428 | ||
2429 | $_SESSION["pref_sort_feeds"] = $feeds_sort; | |
2430 | ||
2431 | if ($feed_search) { | |
2432 | $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR | |
2433 | UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND"; | |
2434 | } else { | |
2435 | $search_qpart = ""; | |
2436 | } | |
2437 | ||
2438 | $result = db_query($link, "SELECT | |
2439 | F1.id, | |
2440 | F1.title, | |
2441 | F1.feed_url, | |
2442 | substring(F1.last_updated,1,16) AS last_updated, | |
2443 | F1.parent_feed, | |
2444 | F1.update_interval, | |
2445 | F1.purge_interval, | |
2446 | F1.cat_id, | |
2447 | F2.title AS parent_title, | |
2448 | C1.title AS category | |
2449 | FROM | |
2450 | ttrss_feeds AS F1 | |
2451 | LEFT JOIN ttrss_feeds AS F2 | |
2452 | ON (F1.parent_feed = F2.id) | |
2453 | LEFT JOIN ttrss_feed_categories AS C1 | |
2454 | ON (F1.cat_id = C1.id) | |
2455 | WHERE | |
2456 | $search_qpart F1.owner_uid = '".$_SESSION["uid"]."' | |
2457 | ORDER by category,$feeds_sort,title"); | |
2458 | ||
2459 | if (db_num_rows($result) != 0) { | |
2460 | ||
2461 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
2462 | ||
2463 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
2464 | class=\"prefFeedList\" id=\"prefFeedList\">"; | |
2465 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2466 | Select: | |
2467 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', | |
2468 | 'FEEDR-', 'FRCHK-', true)\">All</a>, | |
2469 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList', | |
2470 | 'FEEDR-', 'FRCHK-', false)\">None</a> | |
2471 | </td</tr>"; | |
2472 | ||
2473 | if (!get_pref($link, 'ENABLE_FEED_CATS')) { | |
2474 | print "<tr class=\"title\"> | |
2475 | <td width='5%' align='center'> </td> | |
2476 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> | |
2477 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> | |
2478 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> | |
2479 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>"; | |
2480 | } | |
2481 | ||
2482 | $lnum = 0; | |
2483 | ||
2484 | $cur_cat_id = -1; | |
2485 | ||
2486 | while ($line = db_fetch_assoc($result)) { | |
2487 | ||
2488 | $feed_id = $line["id"]; | |
2489 | $cat_id = $line["cat_id"]; | |
2490 | ||
2491 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2492 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
2493 | $edit_cat = htmlspecialchars(db_unescape_string($line["category"])); | |
2494 | ||
2495 | // if ($line["update_interval"] == "0") $line["update_interval"] = "Default"; | |
2496 | // if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled"; | |
2497 | // if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default"; | |
2498 | // if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled"; | |
2499 | ||
2500 | if (!$edit_cat) $edit_cat = "Uncategorized"; | |
2501 | ||
2502 | if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) { | |
2503 | $lnum = 0; | |
2504 | ||
2505 | print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>"; | |
2506 | ||
2507 | print "<tr class=\"title\"> | |
2508 | <td width='5%' align='center'> </td> | |
2509 | <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td> | |
2510 | <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td> | |
2511 | <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td> | |
2512 | <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>"; | |
2513 | ||
2514 | $cur_cat_id = $cat_id; | |
2515 | } | |
2516 | ||
2517 | $class = ($lnum % 2) ? "even" : "odd"; | |
2518 | $this_row_id = "id=\"FEEDR-$feed_id\""; | |
2519 | ||
2520 | print "<tr class=\"$class\" $this_row_id>"; | |
2521 | ||
2522 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
2523 | ||
2524 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
2525 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
2526 | } else { | |
2527 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
2528 | } | |
2529 | // print "<td class='feedIcon'>$feed_icon</td>"; | |
2530 | ||
2531 | print "<td class='feedSelect'><input onclick='toggleSelectRow(this);' | |
2532 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; | |
2533 | ||
2534 | $edit_title = truncate_string($edit_title, 40); | |
2535 | $edit_link = truncate_string($edit_link, 60); | |
2536 | ||
2537 | $parent_title = $line["parent_title"]; | |
2538 | if ($parent_title) { | |
2539 | $parent_title = "<span class='groupPrompt'>(linked to | |
2540 | $parent_title)</span>"; | |
2541 | } | |
2542 | ||
2543 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2544 | "$feed_icon $edit_title $parent_title" . "</a></td>"; | |
2545 | ||
2546 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2547 | $edit_link . "</a></td>"; | |
2548 | ||
2549 | /* if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2550 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2551 | $edit_cat . "</a></td>"; | |
2552 | } */ | |
2553 | ||
2554 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2555 | $update_intervals[$line["update_interval"]] . "</a></td>"; | |
2556 | ||
2557 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
2558 | $purge_intervals[$line["purge_interval"]] . "</a></td>"; | |
2559 | ||
2560 | print "</tr>"; | |
2561 | ||
2562 | ++$lnum; | |
2563 | } | |
2564 | ||
2565 | print "</table>"; | |
2566 | ||
2567 | print "<p>"; | |
2568 | ||
2569 | if ($subop == "edit") { | |
2570 | print "Edit feed: | |
2571 | <input type=\"submit\" class=\"button\" | |
2572 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
2573 | <input type=\"submit\" class=\"button\" | |
2574 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; | |
2575 | } else { | |
2576 | ||
2577 | print " | |
2578 | Selection: | |
2579 | <input type=\"submit\" class=\"button\" | |
2580 | onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> | |
2581 | <input type=\"submit\" class=\"button\" | |
2582 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
2583 | <input type=\"submit\" class=\"button\" | |
2584 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
2585 | ||
2586 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2587 | ||
2588 | print " "; | |
2589 | ||
2590 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2591 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2592 | ORDER BY title"); | |
2593 | ||
2594 | print "<select id=\"sfeed_set_fcat\">"; | |
2595 | print "<option id=\"0\">Uncategorized</option>"; | |
2596 | ||
2597 | if (db_num_rows($result) != 0) { | |
2598 | ||
2599 | print "<option disabled>--------</option>"; | |
2600 | ||
2601 | while ($line = db_fetch_assoc($result)) { | |
2602 | printf("<option id='%d'>%s</option>", | |
2603 | $line["id"], $line["title"]); | |
2604 | } | |
2605 | } | |
2606 | ||
2607 | print "</select>"; | |
2608 | ||
2609 | print " <input type=\"submit\" class=\"button\" | |
2610 | onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">"; | |
2611 | ||
2612 | } | |
2613 | ||
2614 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { | |
2615 | print " | |
2616 | <input type=\"submit\" class=\"button\" | |
2617 | onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\"> | |
2618 | <input type=\"submit\" class=\"button\" | |
2619 | onclick=\"javascript:readSelectedFeeds(false)\" | |
2620 | value=\"Mark as unread\"> "; | |
2621 | } | |
2622 | ||
2623 | print " | |
2624 | All feeds: <input type=\"submit\" | |
2625 | class=\"button\" onclick=\"gotoExportOpml()\" | |
2626 | value=\"Export OPML\">"; | |
2627 | } | |
2628 | } else { | |
2629 | ||
2630 | print "<p>No feeds defined.</p>"; | |
2631 | ||
2632 | } | |
2633 | ||
2634 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
2635 | ||
2636 | print "<h3>Edit Categories</h3>"; | |
2637 | ||
2638 | // print "<h3>Categories</h3>"; | |
2639 | ||
2640 | print "<div class=\"prefGenericAddBox\"> | |
2641 | <input id=\"fadd_cat\" | |
2642 | onchange=\"javascript:addFeedCat()\" | |
2643 | size=\"40\"> | |
2644 | <input | |
2645 | type=\"submit\" class=\"button\" | |
2646 | onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>"; | |
2647 | ||
2648 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
2649 | WHERE owner_uid = ".$_SESSION["uid"]." | |
2650 | ORDER BY title"); | |
2651 | ||
2652 | if (db_num_rows($result) != 0) { | |
2653 | ||
2654 | print "<p><table width=\"100%\" class=\"prefFeedCatList\" | |
2655 | cellspacing=\"0\" id=\"prefFeedCatList\">"; | |
2656 | ||
2657 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2658 | Select: | |
2659 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', | |
2660 | 'FCATR-', 'FCCHK-', true)\">All</a>, | |
2661 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList', | |
2662 | 'FCATR-', 'FCCHK-', false)\">None</a> | |
2663 | </td</tr>"; | |
2664 | ||
2665 | print "<tr class=\"title\"> | |
2666 | <td width=\"5%\"></td><td width=\"80%\">Title</td> | |
2667 | </tr>"; | |
2668 | ||
2669 | $lnum = 0; | |
2670 | ||
2671 | while ($line = db_fetch_assoc($result)) { | |
2672 | ||
2673 | $class = ($lnum % 2) ? "even" : "odd"; | |
2674 | ||
2675 | $cat_id = $line["id"]; | |
2676 | ||
2677 | $edit_cat_id = $_GET["id"]; | |
2678 | ||
2679 | if ($subop == "editCat" && $cat_id != $edit_cat_id) { | |
2680 | $class .= "Grayed"; | |
2681 | $this_row_id = ""; | |
2682 | } else { | |
2683 | $this_row_id = "id=\"FCATR-$cat_id\""; | |
2684 | } | |
2685 | ||
2686 | print "<tr class=\"$class\" $this_row_id>"; | |
2687 | ||
2688 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); | |
2689 | ||
2690 | if (!$edit_cat_id || $subop != "editCat") { | |
2691 | ||
2692 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
2693 | type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>"; | |
2694 | ||
2695 | print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . | |
2696 | $edit_title . "</a></td>"; | |
2697 | ||
2698 | } else if ($cat_id != $edit_cat_id) { | |
2699 | ||
2700 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2701 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
2702 | ||
2703 | print "<td>$edit_title</td>"; | |
2704 | ||
2705 | } else { | |
2706 | ||
2707 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2708 | ||
2709 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; | |
2710 | ||
2711 | } | |
2712 | ||
2713 | print "</tr>"; | |
2714 | ||
2715 | ++$lnum; | |
2716 | } | |
2717 | ||
2718 | print "</table>"; | |
2719 | ||
2720 | print "<p>"; | |
2721 | ||
2722 | if ($subop == "editCat") { | |
2723 | print "Edit category: | |
2724 | <input type=\"submit\" class=\"button\" | |
2725 | onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\"> | |
2726 | <input type=\"submit\" class=\"button\" | |
2727 | onclick=\"javascript:feedCatEditSave()\" value=\"Save\">"; | |
2728 | } else { | |
2729 | ||
2730 | print " | |
2731 | Selection: | |
2732 | <input type=\"submit\" class=\"button\" | |
2733 | onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\"> | |
2734 | <input type=\"submit\" class=\"button\" | |
2735 | onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">"; | |
2736 | ||
2737 | } | |
2738 | ||
2739 | } else { | |
2740 | print "<p>No feed categories defined.</p>"; | |
2741 | } | |
2742 | } | |
2743 | ||
2744 | print "<h3>Import OPML</h3> | |
2745 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> | |
2746 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
2747 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
2748 | type=\"submit\" value=\"Import\"> | |
2749 | </form>"; | |
2750 | ||
2751 | } | |
2752 | ||
2753 | if ($op == "pref-filters") { | |
2754 | ||
2755 | $subop = $_GET["subop"]; | |
2756 | $quiet = $_GET["quiet"]; | |
2757 | ||
2758 | if ($subop == "editSave") { | |
2759 | ||
2760 | $regexp = db_escape_string($_GET["r"]); | |
2761 | $descr = db_escape_string($_GET["d"]); | |
2762 | $match = db_escape_string($_GET["m"]); | |
2763 | $filter_id = db_escape_string($_GET["id"]); | |
2764 | $feed_id = db_escape_string($_GET["fid"]); | |
2765 | $action_id = db_escape_string($_GET["aid"]); | |
2766 | ||
2767 | if (!$feed_id) { | |
2768 | $feed_id = 'NULL'; | |
2769 | } else { | |
2770 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2771 | } | |
2772 | ||
2773 | $result = db_query($link, "UPDATE ttrss_filters SET | |
2774 | reg_exp = '$regexp', | |
2775 | description = '$descr', | |
2776 | feed_id = $feed_id, | |
2777 | action_id = '$action_id', | |
2778 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
2779 | description = '$match') | |
2780 | WHERE id = '$filter_id'"); | |
2781 | } | |
2782 | ||
2783 | if ($subop == "remove") { | |
2784 | ||
2785 | if (!WEB_DEMO_MODE) { | |
2786 | ||
2787 | $ids = split(",", db_escape_string($_GET["ids"])); | |
2788 | ||
2789 | foreach ($ids as $id) { | |
2790 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); | |
2791 | ||
2792 | } | |
2793 | } | |
2794 | } | |
2795 | ||
2796 | if ($subop == "add") { | |
2797 | ||
2798 | if (!WEB_DEMO_MODE) { | |
2799 | ||
2800 | $regexp = db_escape_string(trim($_GET["regexp"])); | |
2801 | $match = db_escape_string(trim($_GET["match"])); | |
2802 | $feed_id = db_escape_string($_GET["fid"]); | |
2803 | $action_id = db_escape_string($_GET["aid"]); | |
2804 | ||
2805 | if (!$feed_id) { | |
2806 | $feed_id = 'NULL'; | |
2807 | } else { | |
2808 | $feed_id = sprintf("'%s'", db_escape_string($feed_id)); | |
2809 | } | |
2810 | ||
2811 | $result = db_query($link, | |
2812 | "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id, | |
2813 | action_id) | |
2814 | VALUES | |
2815 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE | |
2816 | description = '$match'),'".$_SESSION["uid"]."', | |
2817 | $feed_id, '$action_id')"); | |
2818 | } | |
2819 | } | |
2820 | ||
2821 | if ($quiet) return; | |
2822 | ||
2823 | $result = db_query($link, "SELECT description | |
2824 | FROM ttrss_filter_types ORDER BY description"); | |
2825 | ||
2826 | $filter_types = array(); | |
2827 | ||
2828 | while ($line = db_fetch_assoc($result)) { | |
2829 | array_push($filter_types, $line["description"]); | |
2830 | } | |
2831 | ||
2832 | print "<div class=\"prefGenericAddBox\"> | |
2833 | <input id=\"fadd_regexp\" size=\"40\"> "; | |
2834 | ||
2835 | print_select("fadd_match", "Title", $filter_types); | |
2836 | ||
2837 | print " <select id=\"fadd_feed\">"; | |
2838 | ||
2839 | print "<option selected id=\"0\">All feeds</option>"; | |
2840 | ||
2841 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2842 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2843 | ||
2844 | if (db_num_rows($result) > 0) { | |
2845 | print "<option disabled>--------</option>"; | |
2846 | } | |
2847 | ||
2848 | while ($line = db_fetch_assoc($result)) { | |
2849 | printf("<option id='%d'>%s</option>", $line["id"], $line["title"]); | |
2850 | } | |
2851 | ||
2852 | print "</select> "; | |
2853 | ||
2854 | print " Action: "; | |
2855 | ||
2856 | print "<select id=\"fadd_action\">"; | |
2857 | ||
2858 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
2859 | ORDER BY name"); | |
2860 | ||
2861 | while ($line = db_fetch_assoc($result)) { | |
2862 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
2863 | } | |
2864 | ||
2865 | print "</select> "; | |
2866 | ||
2867 | /* print "<input type=\"submit\" | |
2868 | class=\"button\" onclick=\"javascript:testFilter()\" | |
2869 | value=\"Test filter\"> "; */ | |
2870 | ||
2871 | print "<input type=\"submit\" | |
2872 | class=\"button\" onclick=\"javascript:addFilter()\" | |
2873 | value=\"Add filter\">"; | |
2874 | ||
2875 | print "</div>"; | |
2876 | ||
2877 | $result = db_query($link, "SELECT | |
2878 | ttrss_filters.id AS id,reg_exp, | |
2879 | ttrss_filters.description AS description, | |
2880 | ttrss_filter_types.name AS filter_type_name, | |
2881 | ttrss_filter_types.description AS filter_type_descr, | |
2882 | feed_id, | |
2883 | ttrss_filter_actions.description AS action_description, | |
2884 | ttrss_feeds.title AS feed_title | |
2885 | FROM | |
2886 | ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN | |
2887 | ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) | |
2888 | WHERE | |
2889 | filter_type = ttrss_filter_types.id AND | |
2890 | ttrss_filter_actions.id = action_id AND | |
2891 | ttrss_filters.owner_uid = ".$_SESSION["uid"]." | |
2892 | ORDER by reg_exp"); | |
2893 | ||
2894 | if (db_num_rows($result) != 0) { | |
2895 | ||
2896 | print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\" | |
2897 | id=\"prefFilterList\">"; | |
2898 | ||
2899 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
2900 | Select: | |
2901 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', | |
2902 | 'FILRR-', 'FICHK-', true)\">All</a>, | |
2903 | <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList', | |
2904 | 'FILRR-', 'FICHK-', false)\">None</a> | |
2905 | </td</tr>"; | |
2906 | ||
2907 | print "<tr class=\"title\"> | |
2908 | <td align='center' width=\"5%\"> </td> | |
2909 | <td width=\"20%\">Filter expression</td> | |
2910 | <td width=\"20%\">Feed</td> | |
2911 | <td width=\"15%\">Match</td> | |
2912 | <td width=\"15%\">Action</td> | |
2913 | <td width=\"30%\">Description</td></tr>"; | |
2914 | ||
2915 | $lnum = 0; | |
2916 | ||
2917 | while ($line = db_fetch_assoc($result)) { | |
2918 | ||
2919 | $class = ($lnum % 2) ? "even" : "odd"; | |
2920 | ||
2921 | $filter_id = $line["id"]; | |
2922 | $edit_filter_id = $_GET["id"]; | |
2923 | ||
2924 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
2925 | $class .= "Grayed"; | |
2926 | $this_row_id = ""; | |
2927 | } else { | |
2928 | $this_row_id = "id=\"FILRR-$filter_id\""; | |
2929 | } | |
2930 | ||
2931 | print "<tr class=\"$class\" $this_row_id>"; | |
2932 | ||
2933 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); | |
2934 | $line["description"] = htmlspecialchars($line["description"]); | |
2935 | ||
2936 | if (!$line["feed_title"]) $line["feed_title"] = "All feeds"; | |
2937 | ||
2938 | if (!$edit_filter_id || $subop != "edit") { | |
2939 | ||
2940 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2941 | ||
2942 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
2943 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
2944 | ||
2945 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2946 | $line["reg_exp"] . "</td>"; | |
2947 | ||
2948 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2949 | $line["feed_title"] . "</td>"; | |
2950 | ||
2951 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2952 | $line["filter_type_descr"] . "</td>"; | |
2953 | ||
2954 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2955 | $line["action_description"] . "</td>"; | |
2956 | ||
2957 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
2958 | $line["description"] . "</td>"; | |
2959 | ||
2960 | } else if ($filter_id != $edit_filter_id) { | |
2961 | ||
2962 | if (!$line["description"]) $line["description"] = "[No description]"; | |
2963 | ||
2964 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
2965 | id=\"FICHK-".$line["id"]."\"></td>"; | |
2966 | ||
2967 | print "<td>".$line["reg_exp"]."</td>"; | |
2968 | print "<td>".$line["feed_title"]."</td>"; | |
2969 | print "<td>".$line["filter_type_descr"]."</td>"; | |
2970 | print "<td>".$line["action_description"]."</td>"; | |
2971 | print "<td>".$line["description"]."</td>"; | |
2972 | ||
2973 | } else { | |
2974 | ||
2975 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
2976 | ||
2977 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. | |
2978 | "\"></td>"; | |
2979 | ||
2980 | print "<td>"; | |
2981 | print "<select id=\"iedit_feed\">"; | |
2982 | print "<option id=\"0\">All feeds</option>"; | |
2983 | ||
2984 | $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
2985 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
2986 | ||
2987 | if (db_num_rows($tmp_result) > 0) { | |
2988 | print "<option disabled>--------</option>"; | |
2989 | } | |
2990 | ||
2991 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
2992 | if ($tmp_line["id"] == $line["feed_id"]) { | |
2993 | $is_selected = "selected"; | |
2994 | } else { | |
2995 | $is_selected = ""; | |
2996 | } | |
2997 | printf("<option $is_selected id='%d'>%s</option>", | |
2998 | $tmp_line["id"], $tmp_line["title"]); | |
2999 | } | |
3000 | ||
3001 | print "</select></td>"; | |
3002 | ||
3003 | print "<td>"; | |
3004 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
3005 | print "</td>"; | |
3006 | ||
3007 | print "<td>"; | |
3008 | print "<select id=\"iedit_filter_action\">"; | |
3009 | ||
3010 | $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
3011 | ORDER BY description"); | |
3012 | ||
3013 | while ($tmp_line = db_fetch_assoc($tmp_result)) { | |
3014 | if ($tmp_line["description"] == $line["action_description"]) { | |
3015 | $is_selected = "selected"; | |
3016 | } else { | |
3017 | $is_selected = ""; | |
3018 | } | |
3019 | printf("<option $is_selected id='%d'>%s</option>", | |
3020 | $tmp_line["id"], $tmp_line["description"]); | |
3021 | } | |
3022 | ||
3023 | print "</select></td>"; | |
3024 | ||
3025 | ||
3026 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
3027 | "\"></td>"; | |
3028 | ||
3029 | print "</td>"; | |
3030 | } | |
3031 | ||
3032 | print "</tr>"; | |
3033 | ||
3034 | ++$lnum; | |
3035 | } | |
3036 | ||
3037 | if ($lnum == 0) { | |
3038 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
3039 | } | |
3040 | ||
3041 | print "</table>"; | |
3042 | ||
3043 | print "<p>"; | |
3044 | ||
3045 | if ($subop == "edit") { | |
3046 | print "Edit filter: | |
3047 | <input type=\"submit\" class=\"button\" | |
3048 | onclick=\"javascript:filterEditSave()\" value=\"Save\"> | |
3049 | <input type=\"submit\" class=\"button\" | |
3050 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">"; | |
3051 | ||
3052 | } else { | |
3053 | ||
3054 | print " | |
3055 | Selection: | |
3056 | <input type=\"submit\" class=\"button\" | |
3057 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
3058 | <input type=\"submit\" class=\"button\" | |
3059 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
3060 | } | |
3061 | ||
3062 | } else { | |
3063 | ||
3064 | print "<p>No filters defined.</p>"; | |
3065 | ||
3066 | } | |
3067 | } | |
3068 | ||
3069 | // We need to accept raw SQL data in label queries, so not everything is escaped | |
3070 | // here, this is by design. If you don't like the whole idea, disable labels | |
3071 | // altogether with GLOBAL_ENABLE_LABELS = false | |
3072 | ||
3073 | if ($op == "pref-labels") { | |
3074 | ||
3075 | if (!GLOBAL_ENABLE_LABELS) { | |
3076 | return; | |
3077 | } | |
3078 | ||
3079 | $subop = $_GET["subop"]; | |
3080 | ||
3081 | if ($subop == "test") { | |
3082 | ||
3083 | $expr = $_GET["expr"]; | |
3084 | $descr = $_GET["descr"]; | |
3085 | ||
3086 | print "<div class='infoBoxContents'>"; | |
3087 | ||
3088 | print "<h1>Label «$descr»</h1>"; | |
3089 | ||
3090 | // print "<p><b>Expression</b>: $expr</p>"; | |
3091 | ||
3092 | $result = db_query($link, | |
3093 | "SELECT count(id) AS num_matches | |
3094 | FROM ttrss_entries,ttrss_user_entries | |
3095 | WHERE ($expr) AND | |
3096 | ttrss_user_entries.ref_id = ttrss_entries.id AND | |
3097 | owner_uid = " . $_SESSION["uid"]); | |
3098 | ||
3099 | $num_matches = db_fetch_result($result, 0, "num_matches");; | |
3100 | ||
3101 | if ($num_matches > 0) { | |
3102 | ||
3103 | print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>"; | |
3104 | ||
3105 | $result = db_query($link, | |
3106 | "SELECT title, | |
3107 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title | |
3108 | FROM ttrss_entries,ttrss_user_entries | |
3109 | WHERE ($expr) AND | |
3110 | ttrss_user_entries.ref_id = ttrss_entries.id | |
3111 | AND owner_uid = " . $_SESSION["uid"] . " | |
3112 | ORDER BY date_entered DESC LIMIT 5"); | |
3113 | ||
3114 | print "<ul class=\"nomarks\">"; | |
3115 | while ($line = db_fetch_assoc($result)) { | |
3116 | print "<li>".$line["title"]. | |
3117 | " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>"; | |
3118 | } | |
3119 | print "</ul>"; | |
3120 | ||
3121 | } else { | |
3122 | print "<p>Query didn't return any matches.</p>"; | |
3123 | } | |
3124 | ||
3125 | print "</div>"; | |
3126 | ||
3127 | print "<div align='center'> | |
3128 | <input type='submit' class='button' | |
3129 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
3130 | return; | |
3131 | } | |
3132 | ||
3133 | if ($subop == "editSave") { | |
3134 | ||
3135 | $sql_exp = $_GET["s"]; | |
3136 | $descr = $_GET["d"]; | |
3137 | $label_id = db_escape_string($_GET["id"]); | |
3138 | ||
3139 | // print "$sql_exp : $descr : $label_id"; | |
3140 | ||
3141 | $result = db_query($link, "UPDATE ttrss_labels SET | |
3142 | sql_exp = '$sql_exp', | |
3143 | description = '$descr' | |
3144 | WHERE id = '$label_id'"); | |
3145 | } | |
3146 | ||
3147 | if ($subop == "remove") { | |
3148 | ||
3149 | if (!WEB_DEMO_MODE) { | |
3150 | ||
3151 | $ids = split(",", db_escape_string($_GET["ids"])); | |
3152 | ||
3153 | foreach ($ids as $id) { | |
3154 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
3155 | ||
3156 | } | |
3157 | } | |
3158 | } | |
3159 | ||
3160 | if ($subop == "add") { | |
3161 | ||
3162 | if (!WEB_DEMO_MODE) { | |
3163 | ||
3164 | // no escaping is done here on purpose | |
3165 | $exp = trim($_GET["exp"]); | |
3166 | ||
3167 | $result = db_query($link, | |
3168 | "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) | |
3169 | VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')"); | |
3170 | } | |
3171 | } | |
3172 | ||
3173 | print "<div class=\"prefGenericAddBox\"> | |
3174 | <input size=\"40\" id=\"ladd_expr\"> "; | |
3175 | ||
3176 | print"<input type=\"submit\" class=\"button\" | |
3177 | onclick=\"javascript:addLabel()\" value=\"Add label\"></div>"; | |
3178 | ||
3179 | $result = db_query($link, "SELECT | |
3180 | id,sql_exp,description | |
3181 | FROM | |
3182 | ttrss_labels | |
3183 | WHERE | |
3184 | owner_uid = ".$_SESSION["uid"]." | |
3185 | ORDER by description"); | |
3186 | ||
3187 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
3188 | ||
3189 | if (db_num_rows($result) != 0) { | |
3190 | ||
3191 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
3192 | class=\"prefLabelList\" id=\"prefLabelList\">"; | |
3193 | ||
3194 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
3195 | Select: | |
3196 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', | |
3197 | 'LILRR-', 'LICHK-', true)\">All</a>, | |
3198 | <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList', | |
3199 | 'LILRR-', 'LICHK-', false)\">None</a> | |
3200 | </td</tr>"; | |
3201 | ||
3202 | print "<tr class=\"title\"> | |
3203 | <td align='center' width=\"5%\"> </td> | |
3204 | <td width=\"40%\">SQL expression | |
3205 | <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a> | |
3206 | </td> | |
3207 | <td width=\"40%\">Caption</td></tr>"; | |
3208 | ||
3209 | $lnum = 0; | |
3210 | ||
3211 | while ($line = db_fetch_assoc($result)) { | |
3212 | ||
3213 | $class = ($lnum % 2) ? "even" : "odd"; | |
3214 | ||
3215 | $label_id = $line["id"]; | |
3216 | $edit_label_id = $_GET["id"]; | |
3217 | ||
3218 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
3219 | $class .= "Grayed"; | |
3220 | $this_row_id = ""; | |
3221 | } else { | |
3222 | $this_row_id = "id=\"LILRR-$label_id\""; | |
3223 | } | |
3224 | ||
3225 | print "<tr class=\"$class\" $this_row_id>"; | |
3226 | ||
3227 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
3228 | $line["description"] = htmlspecialchars($line["description"]); | |
3229 | ||
3230 | if (!$edit_label_id || $subop != "edit") { | |
3231 | ||
3232 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
3233 | ||
3234 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
3235 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
3236 | ||
3237 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
3238 | $line["sql_exp"] . "</td>"; | |
3239 | ||
3240 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
3241 | $line["description"] . "</td>"; | |
3242 | ||
3243 | } else if ($label_id != $edit_label_id) { | |
3244 | ||
3245 | if (!$line["description"]) $line["description"] = "[No description]"; | |
3246 | ||
3247 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
3248 | id=\"LICHK-".$line["id"]."\"></td>"; | |
3249 | ||
3250 | print "<td>".$line["sql_exp"]."</td>"; | |
3251 | print "<td>".$line["description"]."</td>"; | |
3252 | ||
3253 | } else { | |
3254 | ||
3255 | print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
3256 | ||
3257 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
3258 | "\"></td>"; | |
3259 | ||
3260 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
3261 | "\"></td>"; | |
3262 | ||
3263 | } | |
3264 | ||
3265 | ||
3266 | print "</tr>"; | |
3267 | ||
3268 | ++$lnum; | |
3269 | } | |
3270 | ||
3271 | if ($lnum == 0) { | |
3272 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
3273 | } | |
3274 | ||
3275 | print "</table>"; | |
3276 | ||
3277 | print "<p>"; | |
3278 | ||
3279 | if ($subop == "edit") { | |
3280 | print "Edit label: | |
3281 | <input type=\"submit\" class=\"button\" | |
3282 | onclick=\"javascript:labelTest()\" value=\"Test\"> | |
3283 | <input type=\"submit\" class=\"button\" | |
3284 | onclick=\"javascript:labelEditSave()\" value=\"Save\"> | |
3285 | <input type=\"submit\" class=\"button\" | |
3286 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">"; | |
3287 | ||
3288 | } else { | |
3289 | ||
3290 | print " | |
3291 | Selection: | |
3292 | <input type=\"submit\" class=\"button\" | |
3293 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
3294 | <input type=\"submit\" class=\"button\" | |
3295 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
3296 | } | |
3297 | } else { | |
3298 | print "<p>No labels defined.</p>"; | |
3299 | } | |
3300 | } | |
3301 | ||
3302 | if ($op == "error") { | |
3303 | print "<div width=\"100%\" align='center'>"; | |
3304 | $msg = $_GET["msg"]; | |
3305 | print $msg; | |
3306 | print "</div>"; | |
3307 | } | |
3308 | ||
3309 | if ($op == "help") { | |
3310 | if (!$_GET["noheaders"]) { | |
3311 | print "<html><head> | |
3312 | <title>Tiny Tiny RSS : Help</title> | |
3313 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
3314 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
3315 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
3316 | </head><body>"; | |
3317 | } | |
3318 | ||
3319 | $tid = sprintf("%d", $_GET["tid"]); | |
3320 | ||
3321 | print "<div class='infoBoxContents'>"; | |
3322 | ||
3323 | if (file_exists("help/$tid.php")) { | |
3324 | include("help/$tid.php"); | |
3325 | } else { | |
3326 | print "<p>Help topic not found.</p>"; | |
3327 | } | |
3328 | ||
3329 | print "</div>"; | |
3330 | ||
3331 | print "<div align='center'> | |
3332 | <input type='submit' class='button' | |
3333 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
3334 | ||
3335 | if (!$_GET["noheaders"]) { | |
3336 | print "</body></html>"; | |
3337 | } | |
3338 | ||
3339 | } | |
3340 | ||
3341 | if ($op == "dlg") { | |
3342 | $id = $_GET["id"]; | |
3343 | $param = $_GET["param"]; | |
3344 | ||
3345 | if ($id == "quickAddFeed") { | |
3346 | print " | |
3347 | Feed URL: <input | |
3348 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
3349 | id=\"qafInput\">"; | |
3350 | ||
3351 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3352 | $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories | |
3353 | WHERE owner_uid = ".$_SESSION["uid"]." | |
3354 | ORDER BY title"); | |
3355 | ||
3356 | print " <select id=\"qafCat\">"; | |
3357 | print "<option id=\"0\">Uncategorized</option>"; | |
3358 | ||
3359 | if (db_num_rows($result) != 0) { | |
3360 | ||
3361 | print "<option disabled>--------</option>"; | |
3362 | ||
3363 | while ($line = db_fetch_assoc($result)) { | |
3364 | printf("<option id='%d'>%s</option>", | |
3365 | $line["id"], $line["title"]); | |
3366 | } | |
3367 | } | |
3368 | ||
3369 | print "</select>"; | |
3370 | } | |
3371 | ||
3372 | print " <input class=\"button\" | |
3373 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> | |
3374 | <input class=\"button\" | |
3375 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3376 | value=\"Cancel\">"; | |
3377 | } | |
3378 | ||
3379 | if ($id == "quickDelFeed") { | |
3380 | ||
3381 | $param = db_escape_string($param); | |
3382 | ||
3383 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
3384 | ||
3385 | if ($result) { | |
3386 | ||
3387 | $f_title = db_fetch_result($result, 0, "title"); | |
3388 | ||
3389 | print "Remove current feed (<b>$f_title</b>)? | |
3390 | <input class=\"button\" | |
3391 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
3392 | <input class=\"button\" | |
3393 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3394 | value=\"Cancel\">"; | |
3395 | } else { | |
3396 | print "Error: Feed $param not found. | |
3397 | <input class=\"button\" | |
3398 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3399 | value=\"Cancel\">"; | |
3400 | } | |
3401 | } | |
3402 | ||
3403 | if ($id == "search") { | |
3404 | ||
3405 | $active_feed_id = db_escape_string($_GET["param"]); | |
3406 | ||
3407 | print "<input id=\"searchbox\" class=\"extSearch\" | |
3408 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
3409 | onchange=\"javascript:search()\"> | |
3410 | <select id=\"searchmodebox\"> | |
3411 | <option selected>All feeds</option>"; | |
3412 | ||
3413 | if ($active_feed_id) { | |
3414 | print "<option>This feed</option>"; | |
3415 | } else { | |
3416 | print "<option disabled>This feed</option>"; | |
3417 | } | |
3418 | ||
3419 | if (get_pref($link, 'ENABLE_FEED_CATS')) { | |
3420 | print "<option>This category</option>"; | |
3421 | } | |
3422 | ||
3423 | print "</select> | |
3424 | <input type=\"submit\" | |
3425 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
3426 | <input class=\"button\" | |
3427 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3428 | value=\"Close\">"; | |
3429 | ||
3430 | } | |
3431 | ||
3432 | if ($id == "quickAddFilter") { | |
3433 | ||
3434 | $result = db_query($link, "SELECT description | |
3435 | FROM ttrss_filter_types ORDER BY description"); | |
3436 | ||
3437 | $filter_types = array(); | |
3438 | ||
3439 | while ($line = db_fetch_assoc($result)) { | |
3440 | array_push($filter_types, $line["description"]); | |
3441 | } | |
3442 | ||
3443 | print "<table>"; | |
3444 | ||
3445 | print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> "; | |
3446 | ||
3447 | print_select("fadd_match", "Title", $filter_types); | |
3448 | ||
3449 | print "</td></tr>"; | |
3450 | print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">"; | |
3451 | ||
3452 | print "<option selected id=\"0\">All feeds</option>"; | |
3453 | ||
3454 | $result = db_query($link, "SELECT id,title FROM ttrss_feeds | |
3455 | WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); | |
3456 | ||
3457 | if (db_num_rows($result) > 0) { | |
3458 | print "<option disabled>--------</option>"; | |
3459 | } | |
3460 | ||
3461 | while ($line = db_fetch_assoc($result)) { | |
3462 | if ($param == $line["id"]) { | |
3463 | $selected = "selected"; | |
3464 | } else { | |
3465 | $selected = ""; | |
3466 | } | |
3467 | printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]); | |
3468 | } | |
3469 | ||
3470 | print "</select></td></tr>"; | |
3471 | ||
3472 | print "<tr><td>Action:</td>"; | |
3473 | ||
3474 | print "<td><select id=\"fadd_action\">"; | |
3475 | ||
3476 | $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions | |
3477 | ORDER BY name"); | |
3478 | ||
3479 | while ($line = db_fetch_assoc($result)) { | |
3480 | printf("<option id='%d'>%s</option>", $line["id"], $line["description"]); | |
3481 | } | |
3482 | ||
3483 | print "</select>"; | |
3484 | ||
3485 | print "</td></tr><tr><td colspan=\"2\" align=\"right\">"; | |
3486 | ||
3487 | print "<input type=\"submit\" | |
3488 | class=\"button\" onclick=\"javascript:qaddFilter()\" | |
3489 | value=\"Add filter\"> "; | |
3490 | ||
3491 | print "<input class=\"button\" | |
3492 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
3493 | value=\"Close\">"; | |
3494 | ||
3495 | print "</td></tr></table>"; | |
3496 | } | |
3497 | } | |
3498 | ||
3499 | // update feeds of all users, may be used anonymously | |
3500 | if ($op == "globalUpdateFeeds") { | |
3501 | ||
3502 | $result = db_query($link, "SELECT id FROM ttrss_users"); | |
3503 | ||
3504 | while ($line = db_fetch_assoc($result)) { | |
3505 | $user_id = $line["id"]; | |
3506 | // print "<!-- updating feeds of uid $user_id -->"; | |
3507 | update_all_feeds($link, false, $user_id); | |
3508 | } | |
3509 | ||
3510 | print "<rpc-reply> | |
3511 | <message msg=\"All feeds updated\"/> | |
3512 | </rpc-reply>"; | |
3513 | ||
3514 | } | |
3515 | ||
3516 | if ($op == "pref-prefs") { | |
3517 | ||
3518 | $subop = $_REQUEST["subop"]; | |
3519 | ||
3520 | if ($subop == "Save configuration") { | |
3521 | ||
3522 | if (WEB_DEMO_MODE) { | |
3523 | header("Location: prefs.php"); | |
3524 | return; | |
3525 | } | |
3526 | ||
3527 | $_SESSION["prefs_op_result"] = "save-config"; | |
3528 | ||
3529 | $_SESSION["prefs_cache"] = false; | |
3530 | ||
3531 | foreach (array_keys($_POST) as $pref_name) { | |
3532 | ||
3533 | $pref_name = db_escape_string($pref_name); | |
3534 | $value = db_escape_string($_POST[$pref_name]); | |
3535 | ||
3536 | $result = db_query($link, "SELECT type_name | |
3537 | FROM ttrss_prefs,ttrss_prefs_types | |
3538 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
3539 | ||
3540 | if (db_num_rows($result) > 0) { | |
3541 | ||
3542 | $type_name = db_fetch_result($result, 0, "type_name"); | |
3543 | ||
3544 | // print "$pref_name : $type_name : $value<br>"; | |
3545 | ||
3546 | if ($type_name == "bool") { | |
3547 | if ($value == "1") { | |
3548 | $value = "true"; | |
3549 | } else { | |
3550 | $value = "false"; | |
3551 | } | |
3552 | } else if ($type_name == "integer") { | |
3553 | $value = sprintf("%d", $value); | |
3554 | } | |
3555 | ||
3556 | // print "$pref_name : $type_name : $value<br>"; | |
3557 | ||
3558 | db_query($link, "UPDATE ttrss_user_prefs SET value = '$value' | |
3559 | WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]); | |
3560 | ||
3561 | } | |
3562 | ||
3563 | header("Location: prefs.php"); | |
3564 | ||
3565 | } | |
3566 | ||
3567 | } else if ($subop == "getHelp") { | |
3568 | ||
3569 | $pref_name = db_escape_string($_GET["pn"]); | |
3570 | ||
3571 | $result = db_query($link, "SELECT help_text FROM ttrss_prefs | |
3572 | WHERE pref_name = '$pref_name'"); | |
3573 | ||
3574 | if (db_num_rows($result) > 0) { | |
3575 | $help_text = db_fetch_result($result, 0, "help_text"); | |
3576 | print $help_text; | |
3577 | } else { | |
3578 | print "Unknown option: $pref_name"; | |
3579 | } | |
3580 | ||
3581 | } else if ($subop == "Change e-mail") { | |
3582 | ||
3583 | if (WEB_DEMO_MODE) { | |
3584 | header("Location: prefs.php"); | |
3585 | return; | |
3586 | } | |
3587 | ||
3588 | $email = db_escape_string($_GET["email"]); | |
3589 | $active_uid = $_SESSION["uid"]; | |
3590 | ||
3591 | if ($email) { | |
3592 | db_query($link, "UPDATE ttrss_users SET email = '$email' | |
3593 | WHERE id = '$active_uid'"); | |
3594 | } | |
3595 | ||
3596 | header("Location: prefs.php"); | |
3597 | ||
3598 | } else if ($subop == "Change password") { | |
3599 | ||
3600 | if (WEB_DEMO_MODE) { | |
3601 | header("Location: prefs.php"); | |
3602 | return; | |
3603 | } | |
3604 | ||
3605 | $old_pw = $_POST["OLD_PASSWORD"]; | |
3606 | $new_pw = $_POST["OLD_PASSWORD"]; | |
3607 | ||
3608 | $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]); | |
3609 | $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]); | |
3610 | ||
3611 | $active_uid = $_SESSION["uid"]; | |
3612 | ||
3613 | if ($old_pw && $new_pw) { | |
3614 | ||
3615 | $login = db_escape_string($_SERVER['PHP_AUTH_USER']); | |
3616 | ||
3617 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3618 | id = '$active_uid' AND (pwd_hash = '$old_pw' OR | |
3619 | pwd_hash = '$old_pw_hash')"); | |
3620 | ||
3621 | if (db_num_rows($result) == 1) { | |
3622 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' | |
3623 | WHERE id = '$active_uid'"); | |
3624 | ||
3625 | $_SESSION["pwd_change_result"] = "ok"; | |
3626 | } else { | |
3627 | $_SESSION["pwd_change_result"] = "failed"; | |
3628 | } | |
3629 | } | |
3630 | ||
3631 | header("Location: prefs.php"); | |
3632 | ||
3633 | } else if ($subop == "Reset to defaults") { | |
3634 | ||
3635 | if (WEB_DEMO_MODE) { | |
3636 | header("Location: prefs.php"); | |
3637 | return; | |
3638 | } | |
3639 | ||
3640 | $_SESSION["prefs_op_result"] = "reset-to-defaults"; | |
3641 | ||
3642 | if (DB_TYPE == "pgsql") { | |
3643 | db_query($link,"UPDATE ttrss_user_prefs | |
3644 | SET value = ttrss_prefs.def_value | |
3645 | WHERE owner_uid = '".$_SESSION["uid"]."' AND | |
3646 | ttrss_prefs.pref_name = ttrss_user_prefs.pref_name"); | |
3647 | } else { | |
3648 | db_query($link, "DELETE FROM ttrss_user_prefs | |
3649 | WHERE owner_uid = ".$_SESSION["uid"]); | |
3650 | initialize_user_prefs($link, $_SESSION["uid"]); | |
3651 | } | |
3652 | ||
3653 | header("Location: prefs.php"); | |
3654 | ||
3655 | } else if ($subop == "Change theme") { | |
3656 | ||
3657 | $theme = db_escape_string($_POST["theme"]); | |
3658 | ||
3659 | if ($theme == "Default") { | |
3660 | $theme_qpart = 'NULL'; | |
3661 | } else { | |
3662 | $theme_qpart = "'$theme'"; | |
3663 | } | |
3664 | ||
3665 | $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes | |
3666 | WHERE theme_name = '$theme'"); | |
3667 | ||
3668 | if (db_num_rows($result) == 1) { | |
3669 | $theme_id = db_fetch_result($result, 0, "id"); | |
3670 | $theme_path = db_fetch_result($result, 0, "theme_path"); | |
3671 | } else { | |
3672 | $theme_id = "NULL"; | |
3673 | $theme_path = ""; | |
3674 | } | |
3675 | ||
3676 | db_query($link, "UPDATE ttrss_users SET | |
3677 | theme_id = $theme_id WHERE id = " . $_SESSION["uid"]); | |
3678 | ||
3679 | $_SESSION["theme"] = $theme_path; | |
3680 | ||
3681 | header("Location: prefs.php"); | |
3682 | ||
3683 | } else { | |
3684 | ||
3685 | if (!SINGLE_USER_MODE) { | |
3686 | ||
3687 | $result = db_query($link, "SELECT id,email FROM ttrss_users | |
3688 | WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR | |
3689 | pwd_hash = 'SHA1:".sha1("password")."')"); | |
3690 | ||
3691 | if (db_num_rows($result) != 0) { | |
3692 | print "<div class=\"warning\"> | |
3693 | Your password is at default value, please change it. | |
3694 | </div>"; | |
3695 | } | |
3696 | ||
3697 | if ($_SESSION["pwd_change_result"] == "failed") { | |
3698 | print "<div class=\"warning\"> | |
3699 | There was an error while changing your password. | |
3700 | </div>"; | |
3701 | } | |
3702 | ||
3703 | if ($_SESSION["pwd_change_result"] == "ok") { | |
3704 | print "<div class=\"notice\"> | |
3705 | Password changed successfully. | |
3706 | </div>"; | |
3707 | } | |
3708 | ||
3709 | $_SESSION["pwd_change_result"] = ""; | |
3710 | ||
3711 | if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { | |
3712 | print "<div class=\"notice\"> | |
3713 | Your configuration was reset to defaults. | |
3714 | </div>"; | |
3715 | } | |
3716 | ||
3717 | if ($_SESSION["prefs_op_result"] == "save-config") { | |
3718 | print "<div class=\"notice\"> | |
3719 | Your configuration was saved successfully. | |
3720 | </div>"; | |
3721 | } | |
3722 | ||
3723 | $_SESSION["prefs_op_result"] = ""; | |
3724 | ||
3725 | print "<form action=\"backend.php\" method=\"GET\">"; | |
3726 | ||
3727 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3728 | print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>"; | |
3729 | ||
3730 | $result = db_query($link, "SELECT email FROM ttrss_users | |
3731 | WHERE id = ".$_SESSION["uid"]); | |
3732 | ||
3733 | $email = db_fetch_result($result, 0, "email"); | |
3734 | ||
3735 | print "<tr><td width=\"40%\">E-mail</td>"; | |
3736 | print "<td><input class=\"editbox\" name=\"email\" | |
3737 | value=\"$email\"></td></tr>"; | |
3738 | ||
3739 | print "</table>"; | |
3740 | ||
3741 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3742 | ||
3743 | print "<p><input class=\"button\" type=\"submit\" | |
3744 | value=\"Change e-mail\" name=\"subop\">"; | |
3745 | ||
3746 | print "</form>"; | |
3747 | ||
3748 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3749 | ||
3750 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3751 | print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>"; | |
3752 | ||
3753 | print "<tr><td width=\"40%\">Old password</td>"; | |
3754 | print "<td><input class=\"editbox\" type=\"password\" | |
3755 | name=\"OLD_PASSWORD\"></td></tr>"; | |
3756 | ||
3757 | print "<tr><td width=\"40%\">New password</td>"; | |
3758 | ||
3759 | print "<td><input class=\"editbox\" type=\"password\" | |
3760 | name=\"NEW_PASSWORD\"></td></tr>"; | |
3761 | ||
3762 | print "</table>"; | |
3763 | ||
3764 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3765 | ||
3766 | print "<p><input class=\"button\" type=\"submit\" | |
3767 | value=\"Change password\" name=\"subop\">"; | |
3768 | ||
3769 | print "</form>"; | |
3770 | ||
3771 | } | |
3772 | ||
3773 | $result = db_query($link, "SELECT | |
3774 | theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]); | |
3775 | ||
3776 | $user_theme_id = db_fetch_result($result, 0, "theme_id"); | |
3777 | ||
3778 | $result = db_query($link, "SELECT | |
3779 | id,theme_name FROM ttrss_themes ORDER BY theme_name"); | |
3780 | ||
3781 | if (db_num_rows($result) > 0) { | |
3782 | ||
3783 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3784 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
3785 | print "<tr><td colspan='3'><h3>Themes</h3></tr></td>"; | |
3786 | print "<tr><td width=\"40%\">Select theme</td>"; | |
3787 | print "<td><select name=\"theme\">"; | |
3788 | print "<option>Default</option>"; | |
3789 | print "<option disabled>--------</option>"; | |
3790 | ||
3791 | while ($line = db_fetch_assoc($result)) { | |
3792 | if ($line["id"] == $user_theme_id) { | |
3793 | $selected = "selected"; | |
3794 | } else { | |
3795 | $selected = ""; | |
3796 | } | |
3797 | print "<option $selected>" . $line["theme_name"] . "</option>"; | |
3798 | } | |
3799 | print "</select></td></tr>"; | |
3800 | print "</table>"; | |
3801 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3802 | print "<p><input class=\"button\" type=\"submit\" | |
3803 | value=\"Change theme\" name=\"subop\">"; | |
3804 | print "</form>"; | |
3805 | } | |
3806 | ||
3807 | $result = db_query($link, "SELECT | |
3808 | ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, | |
3809 | section_name,def_value | |
3810 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs | |
3811 | WHERE type_id = ttrss_prefs_types.id AND | |
3812 | section_id = ttrss_prefs_sections.id AND | |
3813 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND | |
3814 | owner_uid = ".$_SESSION["uid"]." | |
3815 | ORDER BY section_id,short_desc"); | |
3816 | ||
3817 | print "<form action=\"backend.php\" method=\"POST\">"; | |
3818 | ||
3819 | $lnum = 0; | |
3820 | ||
3821 | $active_section = ""; | |
3822 | ||
3823 | while ($line = db_fetch_assoc($result)) { | |
3824 | ||
3825 | if ($active_section != $line["section_name"]) { | |
3826 | ||
3827 | if ($active_section != "") { | |
3828 | print "</table>"; | |
3829 | } | |
3830 | ||
3831 | print "<p><table width=\"100%\" class=\"prefPrefsList\">"; | |
3832 | ||
3833 | $active_section = $line["section_name"]; | |
3834 | ||
3835 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; | |
3836 | // print "<tr class=\"title\"> | |
3837 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
3838 | ||
3839 | $lnum = 0; | |
3840 | } | |
3841 | ||
3842 | // $class = ($lnum % 2) ? "even" : "odd"; | |
3843 | ||
3844 | print "<tr>"; | |
3845 | ||
3846 | $type_name = $line["type_name"]; | |
3847 | $pref_name = $line["pref_name"]; | |
3848 | $value = $line["value"]; | |
3849 | $def_value = $line["def_value"]; | |
3850 | $help_text = $line["help_text"]; | |
3851 | ||
3852 | print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"]; | |
3853 | ||
3854 | if ($help_text) print "<div class=\"prefHelp\">$help_text</div>"; | |
3855 | ||
3856 | print "</td>"; | |
3857 | ||
3858 | print "<td>"; | |
3859 | ||
3860 | if ($type_name == "bool") { | |
3861 | // print_select($pref_name, $value, array("true", "false")); | |
3862 | ||
3863 | if ($value == "true") { | |
3864 | $value = "Yes"; | |
3865 | } else { | |
3866 | $value = "No"; | |
3867 | } | |
3868 | ||
3869 | print_radio($pref_name, $value, array("Yes", "No")); | |
3870 | ||
3871 | } else { | |
3872 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
3873 | } | |
3874 | ||
3875 | print "</td>"; | |
3876 | ||
3877 | print "</tr>"; | |
3878 | ||
3879 | $lnum++; | |
3880 | } | |
3881 | ||
3882 | print "</table>"; | |
3883 | ||
3884 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
3885 | ||
3886 | print "<p><input class=\"button\" type=\"submit\" | |
3887 | name=\"subop\" value=\"Save configuration\">"; | |
3888 | ||
3889 | print " <input class=\"button\" type=\"submit\" | |
3890 | name=\"subop\" onclick=\"return validatePrefsReset()\" | |
3891 | value=\"Reset to defaults\"></p>"; | |
3892 | ||
3893 | print "</form>"; | |
3894 | ||
3895 | } | |
3896 | ||
3897 | } | |
3898 | ||
3899 | if ($op == "pref-users") { | |
3900 | ||
3901 | $subop = $_GET["subop"]; | |
3902 | ||
3903 | if ($subop == "editSave") { | |
3904 | ||
3905 | if (!WEB_DEMO_MODE) { | |
3906 | ||
3907 | $login = db_escape_string($_GET["l"]); | |
3908 | $uid = db_escape_string($_GET["id"]); | |
3909 | $access_level = sprintf("%d", $_GET["al"]); | |
3910 | $email = db_escape_string($_GET["e"]); | |
3911 | ||
3912 | db_query($link, "UPDATE ttrss_users SET login = '$login', | |
3913 | access_level = '$access_level', email = '$email' WHERE id = '$uid'"); | |
3914 | ||
3915 | } | |
3916 | } else if ($subop == "remove") { | |
3917 | ||
3918 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3919 | ||
3920 | $ids = split(",", db_escape_string($_GET["ids"])); | |
3921 | ||
3922 | foreach ($ids as $id) { | |
3923 | db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]); | |
3924 | ||
3925 | } | |
3926 | } | |
3927 | } else if ($subop == "add") { | |
3928 | ||
3929 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3930 | ||
3931 | $login = db_escape_string(trim($_GET["login"])); | |
3932 | $tmp_user_pwd = make_password(8); | |
3933 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3934 | ||
3935 | db_query($link, "INSERT INTO ttrss_users | |
3936 | (login,pwd_hash,access_level,last_login) | |
3937 | VALUES ('$login', '$pwd_hash', 0, NOW())"); | |
3938 | ||
3939 | ||
3940 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
3941 | login = '$login' AND pwd_hash = '$pwd_hash'"); | |
3942 | ||
3943 | if (db_num_rows($result) == 1) { | |
3944 | ||
3945 | $new_uid = db_fetch_result($result, 0, "id"); | |
3946 | ||
3947 | print "<div class=\"notice\">Added user <b>".$_GET["login"]. | |
3948 | "</b> with password <b>$tmp_user_pwd</b>.</div>"; | |
3949 | ||
3950 | initialize_user($link, $new_uid); | |
3951 | ||
3952 | } else { | |
3953 | ||
3954 | print "<div class=\"warning\">Error while adding user <b>". | |
3955 | $_GET["login"].".</b></div>"; | |
3956 | ||
3957 | } | |
3958 | } | |
3959 | } else if ($subop == "resetPass") { | |
3960 | ||
3961 | if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) { | |
3962 | ||
3963 | $uid = db_escape_string($_GET["id"]); | |
3964 | ||
3965 | $result = db_query($link, "SELECT login,email | |
3966 | FROM ttrss_users WHERE id = '$uid'"); | |
3967 | ||
3968 | $login = db_fetch_result($result, 0, "login"); | |
3969 | $email = db_fetch_result($result, 0, "email"); | |
3970 | $tmp_user_pwd = make_password(8); | |
3971 | $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd); | |
3972 | ||
3973 | db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' | |
3974 | WHERE id = '$uid'"); | |
3975 | ||
3976 | print "<div class=\"notice\">Changed password of | |
3977 | user <b>$login</b> to <b>$tmp_user_pwd</b>."; | |
3978 | ||
3979 | if (MAIL_RESET_PASS && $email) { | |
3980 | print " Notifying <b>$email</b>."; | |
3981 | ||
3982 | mail("$login <$email>", "Password reset notification", | |
3983 | "Hi, $login.\n". | |
3984 | "\n". | |
3985 | "Your password for this TT-RSS installation was reset by". | |
3986 | " an administrator.\n". | |
3987 | "\n". | |
3988 | "Your new password is $tmp_user_pwd, please remember". | |
3989 | " it for later reference.\n". | |
3990 | "\n". | |
3991 | "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM); | |
3992 | } | |
3993 | ||
3994 | print "</div>"; | |
3995 | ||
3996 | } | |
3997 | } | |
3998 | ||
3999 | print "<div class=\"prefGenericAddBox\"> | |
4000 | <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> "; | |
4001 | ||
4002 | print"<input type=\"submit\" class=\"button\" | |
4003 | onclick=\"javascript:addUser()\" value=\"Add user\"></div>"; | |
4004 | ||
4005 | $result = db_query($link, "SELECT | |
4006 | id,login,access_level,email, | |
4007 | SUBSTRING(last_login,1,16) as last_login | |
4008 | FROM | |
4009 | ttrss_users | |
4010 | ORDER by login"); | |
4011 | ||
4012 | print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>"; | |
4013 | ||
4014 | print "<p><table width=\"100%\" cellspacing=\"0\" | |
4015 | class=\"prefUserList\" id=\"prefUserList\">"; | |
4016 | ||
4017 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
4018 | Select: | |
4019 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', | |
4020 | 'UMRR-', 'UMCHK-', true)\">All</a>, | |
4021 | <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList', | |
4022 | 'UMRR-', 'UMCHK-', false)\">None</a> | |
4023 | </td</tr>"; | |
4024 | ||
4025 | print "<tr class=\"title\"> | |
4026 | <td align='center' width=\"5%\"> </td> | |
4027 | <td width='20%'>Username</td> | |
4028 | <td width='20%'>E-mail</td> | |
4029 | <td width='20%'>Access Level</td> | |
4030 | <td width='20%'>Last login</td></tr>"; | |
4031 | ||
4032 | $lnum = 0; | |
4033 | ||
4034 | while ($line = db_fetch_assoc($result)) { | |
4035 | ||
4036 | $class = ($lnum % 2) ? "even" : "odd"; | |
4037 | ||
4038 | $uid = $line["id"]; | |
4039 | $edit_uid = $_GET["id"]; | |
4040 | ||
4041 | if ($subop == "edit" && $uid != $edit_uid) { | |
4042 | $class .= "Grayed"; | |
4043 | $this_row_id = ""; | |
4044 | } else { | |
4045 | $this_row_id = "id=\"UMRR-$uid\""; | |
4046 | } | |
4047 | ||
4048 | print "<tr class=\"$class\" $this_row_id>"; | |
4049 | ||
4050 | $line["login"] = htmlspecialchars($line["login"]); | |
4051 | ||
4052 | $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'), | |
4053 | strtotime($line["last_login"])); | |
4054 | ||
4055 | $access_level_names = array(0 => "User", 10 => "Administrator"); | |
4056 | ||
4057 | /* if ($uid == $_SESSION["uid"]) { | |
4058 | ||
4059 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" | |
4060 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
4061 | ||
4062 | print "<td>".$line["login"]."</td>"; | |
4063 | print "<td>".$line["email"]."</td>"; | |
4064 | print "<td>".$line["access_level"]."</td>"; | |
4065 | ||
4066 | } else */ if (!$edit_uid || $subop != "edit") { | |
4067 | ||
4068 | print "<td align='center'><input onclick='toggleSelectRow(this);' | |
4069 | type=\"checkbox\" id=\"UMCHK-$uid\"></td>"; | |
4070 | ||
4071 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
4072 | $line["login"] . "</td>"; | |
4073 | ||
4074 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
4075 | $line["email"] . "</td>"; | |
4076 | ||
4077 | print "<td><a href=\"javascript:editUser($uid);\">" . | |
4078 | $access_level_names[$line["access_level"]] . "</td>"; | |
4079 | ||
4080 | } else if ($uid != $edit_uid) { | |
4081 | ||
4082 | print "<td align='center'><input disabled=\"true\" type=\"checkbox\" | |
4083 | id=\"UMCHK-".$line["id"]."\"></td>"; | |
4084 | ||
4085 | print "<td>".$line["login"]."</td>"; | |
4086 | print "<td>".$line["email"]."</td>"; | |
4087 | print "<td>".$access_level_names[$line["access_level"]]."</td>"; | |
4088 | ||
4089 | } else { | |
4090 | ||
4091 | print "<td align='center'> | |
4092 | <input disabled=\"true\" type=\"checkbox\" checked></td>"; | |
4093 | ||
4094 | print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"]. | |
4095 | "\"></td>"; | |
4096 | ||
4097 | print "<td><input id=\"iedit_email\" value=\"".$line["email"]. | |
4098 | "\"></td>"; | |
4099 | ||
4100 | // print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"]. | |
4101 | // "\"></td>"; | |
4102 | ||
4103 | print "<td>"; | |
4104 | print "<select id=\"iedit_ulevel\">"; | |
4105 | foreach (array_keys($access_level_names) as $al) { | |
4106 | if ($al == $line["access_level"]) { | |
4107 | $selected = "selected"; | |
4108 | } else { | |
4109 | $selected = ""; | |
4110 | } | |
4111 | print "<option $selected id=\"$al\">" . | |
4112 | $access_level_names[$al] . "</option>"; | |
4113 | } | |
4114 | print "</select>"; | |
4115 | print "</td>"; | |
4116 | ||
4117 | } | |
4118 | ||
4119 | print "<td>".$line["last_login"]."</td>"; | |
4120 | ||
4121 | print "</tr>"; | |
4122 | ||
4123 | ++$lnum; | |
4124 | } | |
4125 | ||
4126 | print "</table>"; | |
4127 | ||
4128 | print "<p>"; | |
4129 | ||
4130 | if ($subop == "edit") { | |
4131 | print "Edit user: | |
4132 | <input type=\"submit\" class=\"button\" | |
4133 | onclick=\"javascript:userEditSave()\" value=\"Save\"> | |
4134 | <input type=\"submit\" class=\"button\" | |
4135 | onclick=\"javascript:userEditCancel()\" value=\"Cancel\">"; | |
4136 | ||
4137 | } else { | |
4138 | ||
4139 | print " | |
4140 | Selection: | |
4141 | <input type=\"submit\" class=\"button\" | |
4142 | onclick=\"javascript:selectedUserDetails()\" value=\"User details\"> | |
4143 | <input type=\"submit\" class=\"button\" | |
4144 | onclick=\"javascript:editSelectedUser()\" value=\"Edit\"> | |
4145 | <input type=\"submit\" class=\"button\" | |
4146 | onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\"> | |
4147 | <input type=\"submit\" class=\"button\" | |
4148 | onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">"; | |
4149 | ||
4150 | } | |
4151 | } | |
4152 | ||
4153 | if ($op == "user-details") { | |
4154 | ||
4155 | if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) { | |
4156 | return; | |
4157 | } | |
4158 | ||
4159 | /* print "<html><head> | |
4160 | <title>Tiny Tiny RSS : User Details</title> | |
4161 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
4162 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
4163 | </head><body>"; */ | |
4164 | ||
4165 | $uid = sprintf("%d", $_GET["id"]); | |
4166 | ||
4167 | print "<div class='infoBoxContents'>"; | |
4168 | ||
4169 | $result = db_query($link, "SELECT login, | |
4170 | SUBSTRING(last_login,1,16) AS last_login, | |
4171 | access_level, | |
4172 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
4173 | WHERE owner_uid = id) AS stored_articles | |
4174 | FROM ttrss_users | |
4175 | WHERE id = '$uid'"); | |
4176 | ||
4177 | if (db_num_rows($result) == 0) { | |
4178 | print "<h1>User not found</h1>"; | |
4179 | return; | |
4180 | } | |
4181 | ||
4182 | print "<h1>User Details</h1>"; | |
4183 | ||
4184 | print "<table width='100%'>"; | |
4185 | ||
4186 | $login = db_fetch_result($result, 0, "login"); | |
4187 | $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
4188 | strtotime(db_fetch_result($result, 0, "last_login"))); | |
4189 | $access_level = db_fetch_result($result, 0, "access_level"); | |
4190 | $stored_articles = db_fetch_result($result, 0, "stored_articles"); | |
4191 | ||
4192 | print "<tr><td>Username</td><td>$login</td></tr>"; | |
4193 | print "<tr><td>Access level</td><td>$access_level</td></tr>"; | |
4194 | print "<tr><td>Last logged in</td><td>$last_login</td></tr>"; | |
4195 | print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>"; | |
4196 | ||
4197 | $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds | |
4198 | WHERE owner_uid = '$uid'"); | |
4199 | ||
4200 | $num_feeds = db_fetch_result($result, 0, "num_feeds"); | |
4201 | ||
4202 | print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>"; | |
4203 | ||
4204 | /* $result = db_query($link, "SELECT | |
4205 | SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size | |
4206 | FROM ttrss_user_entries,ttrss_entries | |
4207 | WHERE owner_uid = '$uid' AND ref_id = id"); | |
4208 | ||
4209 | $db_size = round(db_fetch_result($result, 0, "db_size") / 1024); | |
4210 | ||
4211 | print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */ | |
4212 | ||
4213 | print "</table>"; | |
4214 | ||
4215 | print "<h1>Subscribed feeds</h1>"; | |
4216 | ||
4217 | $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds | |
4218 | WHERE owner_uid = '$uid' ORDER BY title"); | |
4219 | ||
4220 | print "<ul class=\"userFeedList\">"; | |
4221 | ||
4222 | while ($line = db_fetch_assoc($result)) { | |
4223 | ||
4224 | $icon_file = ICONS_URL."/".$line["id"].".ico"; | |
4225 | ||
4226 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
4227 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">"; | |
4228 | } else { | |
4229 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
4230 | } | |
4231 | ||
4232 | print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>"; | |
4233 | } | |
4234 | ||
4235 | if (db_num_rows($result) < $num_feeds) { | |
4236 | // FIXME - add link to show ALL subscribed feeds here somewhere | |
4237 | print "<li><img | |
4238 | class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>"; | |
4239 | } | |
4240 | ||
4241 | print "</ul>"; | |
4242 | ||
4243 | print "</div>"; | |
4244 | ||
4245 | print "<div align='center'> | |
4246 | <input type='submit' class='button' | |
4247 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
4248 | ||
4249 | // print "</body></html>"; | |
4250 | ||
4251 | } | |
4252 | ||
4253 | if ($op == "feed-details") { | |
4254 | ||
4255 | // $feed_id = $_GET["id"]; | |
4256 | ||
4257 | $feed_ids = split(",", db_escape_string($_GET["id"])); | |
4258 | ||
4259 | print "<div class=\"infoBoxContents\">"; | |
4260 | ||
4261 | foreach ($feed_ids as $feed_id) { | |
4262 | ||
4263 | $result = db_query($link, | |
4264 | "SELECT | |
4265 | title,feed_url, | |
4266 | SUBSTRING(last_updated,1,16) as last_updated, | |
4267 | icon_url,site_url, | |
4268 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
4269 | WHERE feed_id = id) AS total, | |
4270 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
4271 | WHERE feed_id = id AND unread = true) AS unread, | |
4272 | (SELECT COUNT(int_id) FROM ttrss_user_entries | |
4273 | WHERE feed_id = id AND marked = true) AS marked | |
4274 | FROM ttrss_feeds | |
4275 | WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]); | |
4276 | ||
4277 | if (db_num_rows($result) == 0) return; | |
4278 | ||
4279 | $title = db_unescape_string(db_fetch_result($result, 0, "title")); | |
4280 | $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'), | |
4281 | strtotime(db_fetch_result($result, 0, "last_updated"))); | |
4282 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
4283 | $icon_url = db_fetch_result($result, 0, "icon_url"); | |
4284 | $total = db_fetch_result($result, 0, "total"); | |
4285 | $unread = db_fetch_result($result, 0, "unread"); | |
4286 | $marked = db_fetch_result($result, 0, "marked"); | |
4287 | $site_url = db_fetch_result($result, 0, "site_url"); | |
4288 | ||
4289 | $result = db_query($link, "SELECT COUNT(id) AS subscribed | |
4290 | FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false"); | |
4291 | ||
4292 | $subscribed = db_fetch_result($result, 0, "subscribed"); | |
4293 | ||
4294 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
4295 | ||
4296 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
4297 | $feed_icon = "<img width=\"16\" height=\"16\" | |
4298 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
4299 | } else { | |
4300 | $feed_icon = ""; | |
4301 | } | |
4302 | ||
4303 | print "<h1>$feed_icon $title</h1>"; | |
4304 | ||
4305 | print "<table width='100%'>"; | |
4306 | ||
4307 | if ($site_url) { | |
4308 | print "<tr><td width='30%'>Link</td> | |
4309 | <td><a href=\"$site_url\">$site_url</a> | |
4310 | <a href=\"$feed_url\">(feed)</a></td> | |
4311 | </td></tr>"; | |
4312 | } else { | |
4313 | print "<tr><td width='30%'>Feed URL</td> | |
4314 | <td><a href=\"$feed_url\">$feed_url</a></td></tr>"; | |
4315 | } | |
4316 | print "<tr><td>Last updated</td><td>$last_updated</td></tr>"; | |
4317 | print "<tr><td>Total articles</td><td>$total</td></tr>"; | |
4318 | print "<tr><td>Unread articles</td><td>$unread</td></tr>"; | |
4319 | print "<tr><td>Starred articles</td><td>$marked</td></tr>"; | |
4320 | print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>"; | |
4321 | ||
4322 | print "</table>"; | |
4323 | ||
4324 | /* $result = db_query($link, "SELECT title, | |
4325 | SUBSTRING(updated,1,16) AS updated,unread | |
4326 | FROM ttrss_entries,ttrss_user_entries | |
4327 | WHERE ref_id = id AND feed_id = '$feed_id' | |
4328 | ORDER BY date_entered DESC LIMIT 5"); | |
4329 | ||
4330 | if (db_num_rows($result) > 0) { | |
4331 | ||
4332 | print "<h1>Latest headlines</h1>"; | |
4333 | ||
4334 | print "<ul class=\"nomarks\">"; | |
4335 | ||
4336 | while ($line = db_fetch_assoc($result)) { | |
4337 | if ($line["unread"] == "t" || $line["unread"] == "1") { | |
4338 | $line["title"] = "<b>" . $line["title"] . "</b>"; | |
4339 | } | |
4340 | print "<li>" . $line["title"]. | |
4341 | " <span class=\"insensitive\">(" . | |
4342 | date(get_pref($link, 'SHORT_DATE_FORMAT'), | |
4343 | strtotime($line["updated"])). | |
4344 | ")</span></li>"; | |
4345 | } | |
4346 | ||
4347 | print "</ul>"; | |
4348 | ||
4349 | } */ | |
4350 | } | |
4351 | ||
4352 | print "</div>"; | |
4353 | ||
4354 | print "<div align='center'> | |
4355 | <input type='submit' class='button' | |
4356 | onclick=\"closeInfoBox()\" value=\"Close this window\"></div>"; | |
4357 | } | |
4358 | ||
4359 | if ($op == "pref-feed-browser") { | |
4360 | ||
4361 | if (!ENABLE_FEED_BROWSER) { | |
4362 | print "Feed browser is administratively disabled."; | |
4363 | return; | |
4364 | } | |
4365 | ||
4366 | $subop = $_REQUEST["subop"]; | |
4367 | ||
4368 | if ($subop == "details") { | |
4369 | $id = db_escape_string($_GET["id"]); | |
4370 | ||
4371 | print "<div class=\"browserFeedInfo\">"; | |
4372 | print "<b>Feed information:</b>"; | |
4373 | print "<div class=\"detailsPart\">"; | |
4374 | ||
4375 | $result = db_query($link, "SELECT | |
4376 | feed_url,site_url, | |
4377 | SUBSTRING(last_updated,1,19) AS last_updated | |
4378 | FROM ttrss_feeds WHERE id = '$id'"); | |
4379 | ||
4380 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
4381 | $site_url = db_fetch_result($result, 0, "site_url"); | |
4382 | $last_updated = db_fetch_result($result, 0, "last_updated"); | |
4383 | ||
4384 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
4385 | $last_updated = smart_date_time(strtotime($last_updated)); | |
4386 | } else { | |
4387 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
4388 | $last_updated = date($short_date, strtotime($last_updated)); | |
4389 | } | |
4390 | ||
4391 | print "Site: <a href='$site_url'>$site_url</a> ". | |
4392 | "(<a href='$feed_url'>feed</a>), ". | |
4393 | "Last updated: $last_updated"; | |
4394 | ||
4395 | print "</div>"; | |
4396 | ||
4397 | $result = db_query($link, "SELECT | |
4398 | ttrss_entries.title, | |
4399 | content, | |
4400 | substring(date_entered,1,19) as date_entered, | |
4401 | substring(updated,1,19) as updated | |
4402 | FROM ttrss_entries,ttrss_user_entries | |
4403 | WHERE ttrss_entries.id = ref_id AND feed_id = '$id' | |
4404 | ORDER BY updated DESC LIMIT 5"); | |
4405 | ||
4406 | if (db_num_rows($result) > 0) { | |
4407 | ||
4408 | print "<b>Last headlines:</b><br>"; | |
4409 | ||
4410 | print "<div class=\"detailsPart\">"; | |
4411 | print "<ul class=\"compact\">"; | |
4412 | while ($line = db_fetch_assoc($result)) { | |
4413 | ||
4414 | if (get_pref($link, 'HEADLINES_SMART_DATE')) { | |
4415 | $entry_dt = smart_date_time(strtotime($line["updated"])); | |
4416 | } else { | |
4417 | $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); | |
4418 | $entry_dt = date($short_date, strtotime($line["updated"])); | |
4419 | } | |
4420 | ||
4421 | print "<li>" . $line["title"] . | |
4422 | " <span class=\"insensitive\">($entry_dt)</span></li>"; | |
4423 | } | |
4424 | print "</ul></div>"; | |
4425 | } | |
4426 | ||
4427 | print "</div>"; | |
4428 | ||
4429 | return; | |
4430 | } | |
4431 | ||
4432 | $result = db_query($link, "SELECT feed_url,count(id) AS subscribers | |
4433 | FROM ttrss_feeds | |
4434 | WHERE auth_login = '' AND auth_pass = '' AND private = false | |
4435 | GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100"); | |
4436 | ||
4437 | print "<ul class='nomarks' id='browseBigFeedList'>"; | |
4438 | ||
4439 | $feedctr = 0; | |
4440 | ||
4441 | while ($line = db_fetch_assoc($result)) { | |
4442 | $feed_url = $line["feed_url"]; | |
4443 | $subscribers = $line["subscribers"]; | |
4444 | ||
4445 | $sub_result = db_query($link, "SELECT id | |
4446 | FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" . | |
4447 | $_SESSION["uid"]); | |
4448 | ||
4449 | if (db_num_rows($sub_result) > 0) { | |
4450 | continue; // already subscribed | |
4451 | } | |
4452 | ||
4453 | $det_result = db_query($link, "SELECT site_url,title,id | |
4454 | FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1"); | |
4455 | ||
4456 | $details = db_fetch_assoc($det_result); | |
4457 | ||
4458 | $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico"; | |
4459 | ||
4460 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
4461 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . | |
4462 | "/".$details["id"].".ico\">"; | |
4463 | } else { | |
4464 | $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">"; | |
4465 | } | |
4466 | ||
4467 | $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' | |
4468 | type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">"; | |
4469 | ||
4470 | $class = ($feedctr % 2) ? "even" : "odd"; | |
4471 | ||
4472 | print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box". | |
4473 | "$feed_icon "; | |
4474 | ||
4475 | print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" . | |
4476 | $details["title"] ."</a> " . | |
4477 | "<span class='subscribers'>($subscribers)</span>"; | |
4478 | ||
4479 | print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">"; | |
4480 | print "</div>"; | |
4481 | ||
4482 | print "</li>"; | |
4483 | ||
4484 | ++$feedctr; | |
4485 | } | |
4486 | ||
4487 | if ($feedctr == 0) { | |
4488 | print "<li>No feeds found to subscribe.</li>"; | |
4489 | } | |
4490 | ||
4491 | print "</ul>"; | |
4492 | ||
4493 | print "<p>Selection: | |
4494 | <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\" | |
4495 | value=\"Subscribe\"></p>"; | |
4496 | ||
4497 | print "</div>"; | |
4498 | ||
4499 | } | |
4500 | ||
4501 | db_close($link); | |
4502 | ?> | |
4503 | ||
4504 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
4505 |