X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=backend.php;h=556c9469791f890a691205d10d0212ecad881435;hb=deaaa02c504a685ea383b203e1432fadd01d1a27;hp=a93ca57b748824bd495aac428a5d759749bf8eb9;hpb=ad3cb7108ecae37b0eefad942ef04b0cee473860;p=tt-rss.git diff --git a/backend.php b/backend.php index a93ca57b..556c9469 100644 --- a/backend.php +++ b/backend.php @@ -2,12 +2,13 @@ // header("Content-Type: application/xml"); require_once "config.php"; + require_once "db.php"; require_once "functions.php"; require_once "magpierss/rss_fetch.inc"; error_reporting(0); - $link = pg_connect(DB_CONN); + $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); error_reporting (E_ERROR | E_WARNING | E_PARSE); @@ -16,7 +17,9 @@ return; } - pg_query("set client_encoding = 'utf-8'"); + if (DB_TYPE == "pgsql") { + pg_query("set client_encoding = 'utf-8'"); + } $op = $_GET["op"]; $fetch = $_GET["fetch"]; @@ -31,7 +34,7 @@ "; - $result = pg_query($link, "SELECT *, + $result = db_query($link, "SELECT *, (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id) AS total, (SELECT count(id) FROM ttrss_entries @@ -48,7 +51,7 @@ $total_unread = 0; - while ($line = pg_fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { $feed = $line["title"]; $feed_id = $line["id"]; @@ -134,7 +137,7 @@ if ($subop == "mark") { $mark = $_GET["mark"]; - $id = pg_escape_string($_GET["id"]); + $id = db_escape_string($_GET["id"]); if ($mark == "1") { $mark = "true"; @@ -142,18 +145,18 @@ $mark = "false"; } - $result = pg_query("UPDATE ttrss_entries SET marked = $mark + $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark WHERE id = '$id'"); } if ($subop == "updateFeed") { - $feed_id = pg_escape_string($_GET["feed"]); + $feed_id = db_escape_string($_GET["feed"]); - $result = pg_query($link, + $result = db_query($link, "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'"); - if (pg_num_rows($result) > 0) { - $feed_url = pg_fetch_result($result, 0, "feed_url"); + if (db_num_rows($result) > 0) { + $feed_url = db_fetch_result($result, 0, "feed_url"); // update_rss_feed($link, $feed_url, $feed_id); } @@ -176,7 +179,7 @@ foreach ($ids as $id) { - pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW() + db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW() WHERE id = '$id'"); } @@ -191,7 +194,7 @@ $subop = $_GET["subop"]; if ($subop == "catchupAll") { - pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false"); + db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false"); } outputFeedList($link); @@ -202,11 +205,11 @@ $id = $_GET["id"]; - $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); + $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); $addheader = $_GET["addheader"]; - $result = pg_query("SELECT title,link,content,feed_id,comments, + $result = db_query($link, "SELECT title,link,content,feed_id,comments, (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url FROM ttrss_entries WHERE id = '$id'"); @@ -222,7 +225,7 @@ if ($result) { - $line = pg_fetch_assoc($result); + $line = db_fetch_assoc($result); if ($line["icon_url"]) { $feed_icon = ""; @@ -230,14 +233,23 @@ $feed_icon = " "; } + if ($line["comments"] && $line["link"] != $line["comments"]) { + $entry_comments = "(Comments)"; + } else { + $entry_comments = ""; + } + print "
"; print "
"; print ""; + print " - "; + "; print "
Title: " . $line["title"] . "
Link:" . $line["link"] . "
+ ".$line["link"]." + $entry_comments
"; @@ -246,26 +258,6 @@ print "
"; -/* print ""; - - print " - - "; - - if ($line["comments"] && $line["comments"] != $line["link"]) { - $comments_prompt = "(Comments)"; - } - - print " - - "; - print " - - "; - print "
Title:".$line["title"]." 
Link:".$line["link"]." $comments_prompt 
" . $line["content"] . "$feed_icon
"; */ - } if ($addheader) { @@ -296,29 +288,27 @@ "; } - // FIXME: check for null value here - - $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s, - EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout - FROM ttrss_feeds WHERE id = '$feed'"); + if (DB_TYPE == "pgsql") { + $result = db_query($link, + "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s, + EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout + FROM ttrss_feeds WHERE id = '$feed'"); + } else { + $result = db_query($link, + "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s + FROM ttrss_feeds WHERE id = '$feed'"); + } if ($result) { - $line = pg_fetch_assoc($result); + $line = db_fetch_assoc($result); - if ($subop == "ForceUpdate" || - $line["last_updated"] == "" || - $line["update_timeout"] > MIN_UPDATE_TIME) { - - update_rss_feed($link, $line["feed_url"], $feed); + update_rss_feed($link, $line["feed_url"], $feed); - } else { - - if ($subop == "MarkAllRead") { + if ($subop == "MarkAllRead") { - pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() - WHERE feed_id = '$feed'"); - } + db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() + WHERE feed_id = '$feed'"); } } @@ -345,29 +335,27 @@ $view_query_part = " unread = true AND "; } - $result = pg_query("SELECT count(id) AS total_entries + $result = db_query($link, "SELECT count(id) AS total_entries FROM ttrss_entries WHERE $search_query_part feed_id = '$feed'"); - $total_entries = pg_fetch_result($result, 0, "total_entries"); + $total_entries = db_fetch_result($result, 0, "total_entries"); -/* $result = pg_query("SELECT count(id) AS unread_entries +/* $result = db_query("SELECT count(id) AS unread_entries FROM ttrss_entries WHERE $search_query_part unread = true AND feed_id = '$feed'"); - $unread_entries = pg_fetch_result($result, 0, "unread_entries"); */ + $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ if ($limit != "All") { $limit_query_part = "LIMIT " . $limit; } - $result = pg_query("SELECT - id,title,updated,unread,feed_id,marked,link, - EXTRACT(EPOCH FROM last_read) AS last_read_ts, - EXTRACT(EPOCH FROM updated) AS updated_ts + $result = db_query($link, "SELECT + id,title,updated,unread,feed_id,marked,link,last_read FROM ttrss_entries WHERE @@ -380,26 +368,33 @@ $num_unread = 0; - while ($line = pg_fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; - if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") { - $update_pic = "\"Updated\""; + $id = $line["id"]; + $feed_id = $line["feed_id"]; + +// printf("%d %s - %d %s
", strtotime($line["last_read"]), $line["last_read"], +// strtotime($line["updated"]), $line["updated"]); + + if (strtotime($line["last_read"]) < strtotime($line["updated"]) && + ($line["unread"] == "f" || $line["unread"] == "0")) { + + $update_pic = "\"Updated\""; ++$num_unread; } else { - $update_pic = "\"Updated\""; + $update_pic = "\"Updated\""; } - if ($line["unread"] == "t") { + if ($line["unread"] == "t" || $line["unread"] == "1") { $class .= "Unread"; ++$num_unread; } - $id = $line["id"]; - $feed_id = $line["feed_id"]; - - if ($line["marked"] == "t") { + if ($line["marked"] == "t" || $line["marked"] == "1") { $marked_pic = "\"Reset"; } else { @@ -413,7 +408,7 @@ print " - print "$update_pic"; print ""; - $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries + $result = db_query($link, "SELECT id, (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id) AS total, (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id AND unread = true) as unread FROM ttrss_feeds WHERE id = '$feed'"); - $total = pg_fetch_result($result, 0, "total"); - $unread = pg_fetch_result($result, 0, "unread"); + $total = db_fetch_result($result, 0, "total"); + $unread = db_fetch_result($result, 0, "unread"); // update unread/total counters and status for active feed in the feedlist // kludge, because iframe doesn't seem to support onload() @@ -473,7 +468,7 @@ feedctr.className = 'invisible'; } - p_notify(\"\"); +// p_notify(\"\"); "; @@ -490,7 +485,7 @@ if ($subop == "unread") { $ids = split(",", $_GET["ids"]); foreach ($ids as $id) { - pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); + db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); } print "Marked selected feeds as read."; @@ -499,7 +494,7 @@ if ($subop == "read") { $ids = split(",", $_GET["ids"]); foreach ($ids as $id) { - pg_query("UPDATE ttrss_entries + db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); } @@ -514,11 +509,11 @@ $subop = $_GET["subop"]; if ($subop == "editSave") { - $feed_title = pg_escape_string($_GET["t"]); - $feed_link = pg_escape_string($_GET["l"]); + $feed_title = db_escape_string($_GET["t"]); + $feed_link = db_escape_string($_GET["l"]); $feed_id = $_GET["id"]; - $result = pg_query("UPDATE ttrss_feeds SET + $result = db_query($link, "UPDATE ttrss_feeds SET title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'"); } @@ -530,10 +525,10 @@ $ids = split(",", $_GET["ids"]); foreach ($ids as $id) { - pg_query("BEGIN"); - pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'"); - pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'"); - pg_query("COMMIT"); + db_query($link, "BEGIN"); + db_query($link, "DELETE FROM ttrss_entries WHERE feed_id = '$id'"); + db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'"); + db_query($link, "COMMIT"); if (file_exists(ICONS_DIR . "/$id.ico")) { unlink(ICONS_DIR . "/$id.ico"); @@ -546,15 +541,15 @@ if (!WEB_DEMO_MODE) { - $feed_link = pg_escape_string($_GET["link"]); + $feed_link = db_escape_string($_GET["link"]); - $result = pg_query( + $result = db_query($link, "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); - $result = pg_query( + $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); - $feed_id = pg_fetch_result($result, 0, "id"); + $feed_id = db_fetch_result($result, 0, "id"); if ($feed_id) { update_rss_feed($link, $feed_link, $feed_id); @@ -568,7 +563,7 @@ Add feed "; - $result = pg_query("SELECT + $result = db_query($link, "SELECT id,title,feed_url,substring(last_updated,1,16) as last_updated FROM ttrss_feeds ORDER by title"); @@ -580,7 +575,7 @@ $lnum = 0; - while ($line = pg_fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; @@ -654,7 +649,7 @@ "; + onclick=\"javascript:feedEditSave()\" value=\"Save\">"; } else { print " @@ -674,7 +669,7 @@ print " All feeds: "; + class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; } @@ -686,13 +681,13 @@ if ($subop == "editSave") { - $regexp = pg_escape_string($_GET["r"]); - $descr = pg_escape_string($_GET["d"]); - $match = pg_escape_string($_GET["m"]); - $filter_id = pg_escape_string($_GET["id"]); + $regexp = db_escape_string($_GET["r"]); + $descr = db_escape_string($_GET["d"]); + $match = db_escape_string($_GET["m"]); + $filter_id = db_escape_string($_GET["id"]); - $result = pg_query("UPDATE ttrss_filters SET - regexp = '$regexp', + $result = db_query($link, "UPDATE ttrss_filters SET + reg_exp = '$regexp', description = '$descr', filter_type = (SELECT id FROM ttrss_filter_types WHERE description = '$match') @@ -706,7 +701,7 @@ $ids = split(",", $_GET["ids"]); foreach ($ids as $id) { - pg_query("DELETE FROM ttrss_filters WHERE id = '$id'"); + db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); } } @@ -716,22 +711,22 @@ if (!WEB_DEMO_MODE) { - $regexp = pg_escape_string($_GET["regexp"]); - $match = pg_escape_string($_GET["match"]); + $regexp = db_escape_string($_GET["regexp"]); + $match = db_escape_string($_GET["match"]); - $result = pg_query( - "INSERT INTO ttrss_filters (regexp,filter_type) VALUES + $result = db_query($link, + "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES ('$regexp', (SELECT id FROM ttrss_filter_types WHERE description = '$match'))"); } } - $result = pg_query("SELECT description + $result = db_query($link, "SELECT description FROM ttrss_filter_types ORDER BY description"); $filter_types = array(); - while ($line = pg_fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { array_push($filter_types, $line["description"]); } @@ -744,14 +739,14 @@ Add filter "; - $result = pg_query("SELECT - id,regexp,description, + $result = db_query($link, "SELECT + id,reg_exp,description, (SELECT name FROM ttrss_filter_types WHERE id = filter_type) as filter_type_name, (SELECT description FROM ttrss_filter_types WHERE id = filter_type) as filter_type_descr FROM - ttrss_filters ORDER by regexp"); + ttrss_filters ORDER by reg_exp"); print "

"; @@ -761,7 +756,7 @@ $lnum = 0; - while ($line = pg_fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; @@ -774,7 +769,7 @@ print ""; - $line["regexp"] = htmlspecialchars($line["regexp"]); + $line["regexp"] = htmlspecialchars($line["reg_exp"]); $line["description"] = htmlspecialchars($line["description"]); if (!$edit_filter_id || $subop != "edit") { @@ -785,7 +780,7 @@ type=\"checkbox\" id=\"FICHK-".$line["id"]."\">"; print ""; + $line["reg_exp"] . ""; print ""; @@ -799,7 +794,7 @@ print ""; - print ""; + print ""; print ""; print ""; @@ -807,7 +802,7 @@ print ""; - print ""; print "
" . - $line["regexp"] . "" . $line["description"] . "".$line["regexp"]."".$line["reg_exp"]."".$line["description"]."".$line["filter_type_descr"].""; } - pg_close($link); + db_close($link); ?>