// 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 = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
- $link = pg_connect(DB_CONN);
-
- error_reporting (E_ERROR | E_WARNING | E_PARSE);
-
- if (!$link) {
- print "Could not connect to database. Please check local configuration.";
- return;
+ if (DB_TYPE == "pgsql") {
+ pg_query("set client_encoding = 'utf-8'");
}
- pg_query("set client_encoding = 'utf-8'");
-
$op = $_GET["op"];
$fetch = $_GET["fetch"];
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
</head><body>";
- $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
$total_unread = 0;
- while ($line = pg_fetch_assoc($result)) {
+ while ($line = db_fetch_assoc($result)) {
$feed = $line["title"];
$feed_id = $line["id"];
if (file_exists($icon_file) && filesize($icon_file) > 0) {
$feed_icon = "<img src=\"" . ICONS_URL . "/$feed_id.ico\">";
} else {
- $feed_icon = "<img src=\"images/blank_icon.png\">";
+ $feed_icon = "<img src=\"images/blank_icon.gif\">";
}
} else {
$feed_icon = "<img width=\"16\" height=\"16\"
}
print "<span id=\"FEEDN-$feed_id\">$feed</span>";
- if ($unread > 0) {
- print "<span id=\"FEEDCTR-$feed_id\">
- (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
+ if ($unread != 0) {
+ $fctr_class = "";
+ } else {
+ $fctr_class = "class=\"invisible\"";
}
+
+ print "<span $fctr_class id=\"FEEDCTR-$feed_id\">
+ (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
print "</li>";
print "</table>";
print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
- print "<div class=\"invisible\" id=\"ACTFEEDID\">$actid</div>";
+// print "<div class=\"invisible\" id=\"ACTFEEDID\">$actid</div>";
}
if ($subop == "mark") {
$mark = $_GET["mark"];
- $id = pg_escape_string($_GET["id"]);
+ $id = db_escape_string($_GET["id"]);
if ($mark == "1") {
$mark = "true";
$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);
}
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'");
}
$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);
$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'");
if ($result) {
- $line = pg_fetch_assoc($result);
+ $line = db_fetch_assoc($result);
if ($line["icon_url"]) {
$feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
$feed_icon = " ";
}
+ if ($line["comments"] && $line["link"] != $line["comments"]) {
+ $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
+ } else {
+ $entry_comments = "";
+ }
+
print "<div class=\"postReply\">";
print "<div class=\"postHeader\"><table>";
print "<tr><td><b>Title:</b></td>
<td width='100%'>" . $line["title"] . "</td></tr>";
+
print "<tr><td><b>Link:</b></td>
- <td width='100%'>" . $line["link"] . "</td></tr>";
+ <td width='100%'>
+ <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
+ $entry_comments</td></tr>";
print "</table></div>";
print "</div>";
-/* print "<table class=\"postTable\" width=\"100%\" cellspacing=\"0\"
- cellpadding=\"0\">";
-
- print "<tr class=\"titleTop\"><td align=\"right\"><b>Title:</b></td>
- <td width=\"100%\">".$line["title"]."</td>
- <td> </td></tr>";
-
- if ($line["comments"] && $line["comments"] != $line["link"]) {
- $comments_prompt = "(<a href=\"".$line["comments"]."\">Comments</a>)";
- }
-
- print "<tr class=\"titleBottom\"><td align=\"right\"><b>Link:</b></td>
- <td><a href=\"".$line["link"]."\">".$line["link"]."</a> $comments_prompt</td>
- <td> </td></tr>";
- print "<tr><td valign=\"top\" class=\"post\"
- colspan=\"2\" width=\"100%\">" . $line["content"] . "</td>
- <td valign=\"top\">$feed_icon</td>
- </tr>";
- print "</table>"; */
-
}
if ($addheader) {
$addheader = $_GET["addheader"];
$limit = $_GET["limit"];
+ if (!$feed) {
+ print "Error: no feed to display.";
+ return;
+ }
+
if (!$skip) $skip = 0;
if ($subop == "undefined") $subop = "";
</head><body>";
}
- // 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
+ $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);
-
- if ($subop == "ForceUpdate" ||
- $line["last_updated"] == "" ||
- $line["update_timeout"] > MIN_UPDATE_TIME) {
+ $line = db_fetch_assoc($result);
- 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'");
}
}
$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 < $unread_entries)
- $limit = $unread_entries;
-
- if ($limit != "All") {
+ if ($limit && $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,
+ SUBSTRING(last_read,1,19) as last_read_noms,
+ SUBSTRING(updated,1,19) as updated_noms
FROM
ttrss_entries
WHERE
$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 = "<img src=\"images/updated.png\" alt=\"Updated\">";
- ++$num_unread;
+ $id = $line["id"];
+ $feed_id = $line["feed_id"];
+
+// printf("L %d (%s) > U %d (%s) = %d<br>",
+// strtotime($line["last_read_noms"]), $line["last_read_noms"],
+// strtotime($line["updated"]), $line["updated"],
+// strtotime($line["last_read"]) >= strtotime($line["updated"]));
+
+ if ($line["last_read"] != "" && $line["updated"] != "" &&
+ strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
+
+ $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
+ alt=\"Updated\">";
+
} else {
- $update_pic = " ";
+
+ $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
+ alt=\"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 = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
} else {
$content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
$line["title"] . "</a>";
- print "<tr class='$class' id='RROW-$id'";
+ print "<tr class='$class' id='RROW-$id'>";
// onclick=\"javascript:view($id,$feed_id)\">
- print "<td id='FUPDPIC-$id' valign='center'
- class='headlineUpdateMark'>$update_pic</td>";
-
- print "<td valign='center'
- class='headlineUpdateMark'>$marked_pic</td>";
+ print "<td valign='center' align='center'>$update_pic</td>";
+ print "<td valign='center' align='center'>$marked_pic</td>";
- print "<td class='headlineUpdated'>
+ print "<td width='25%'>
<a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
- print "<td class='headlineTitle'>$content_link</td>";
+ print "<td width='70%'>$content_link</td>";
print "</tr>";
print "</table>";
- $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()
var p_document = parent.frames['feeds-frame'].document;
var feedr = p_document.getElementById(\"FEEDR-\" + $feed);
- var feedt = p_document.getElementById(\"FEEDT-\" + $feed);
var feedu = p_document.getElementById(\"FEEDU-\" + $feed);
- feedt.innerHTML = \"$total\";
- feedu.innerHTML = \"$unread\";
+ if (feedu) {
+ feedu.innerHTML = \"$unread\";
+ }
+
+ var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed);
if ($unread > 0 && !feedr.className.match(\"Unread\")) {
feedr.className = feedr.className + \"Unread\";
+ feedctr.className = '';
} else if ($unread <= 0) {
feedr.className = feedr.className.replace(\"Unread\", \"\");
+ feedctr.className = 'invisible';
}
- //p_notify('');
+// p_notify(\"\");
+
</script>";
if ($addheader) {
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.";
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'");
}
$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'");
}
$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");
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);
<a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
</table>";
- $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");
$lnum = 0;
- while ($line = pg_fetch_assoc($result)) {
+ while ($line = db_fetch_assoc($result)) {
$class = ($lnum % 2) ? "even" : "odd";
<input type=\"submit\" class=\"button\"
onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
<input type=\"submit\" class=\"button\"
- onclickf=\"javascript:feedEditSave()\" value=\"Save\">";
+ onclick=\"javascript:feedEditSave()\" value=\"Save\">";
} else {
print "
print "
All feeds:
<input type=\"submit\"
- class=\"button\" onclick=\"opml.php?op=Export\" value=\"Export OPML\">";
+ class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
}
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')
$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'");
}
}
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"]);
}
<a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
</table>";
- $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 "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
$lnum = 0;
- while ($line = pg_fetch_assoc($result)) {
+ while ($line = db_fetch_assoc($result)) {
$class = ($lnum % 2) ? "even" : "odd";
print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
- $line["regexp"] = htmlspecialchars($line["regexp"]);
+ $line["regexp"] = htmlspecialchars($line["reg_exp"]);
$line["description"] = htmlspecialchars($line["description"]);
if (!$edit_filter_id || $subop != "edit") {
type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
- $line["regexp"] . "</td>";
+ $line["reg_exp"] . "</td>";
print "<td><a href=\"javascript:editFilter($filter_id);\">" .
$line["description"] . "</td>";
print "<td><input disabled=\"true\" type=\"checkbox\"
id=\"FICHK-".$line["id"]."\"></td>";
- print "<td>".$line["regexp"]."</td>";
+ print "<td>".$line["reg_exp"]."</td>";
print "<td>".$line["description"]."</td>";
print "<td>".$line["filter_type_descr"]."</td>";
print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
- print "<td><input id=\"iedit_regexp\" value=\"".$line["regexp"].
+ print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
"\"></td>";
print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
print "</div>";
}
- pg_close($link);
+ db_close($link);
?>