diff options
author | Andrew Dolgov <[email protected]> | 2005-08-22 05:56:40 +0100 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2005-08-22 05:56:40 +0100 |
commit | 331900c642bbea3f8b7e242975fae4cfec459433 (patch) | |
tree | 0274646a70639a2cff5fdec9cfa5ac8c1fb6acbd | |
parent | 857a92708b77c3d570f4ec97936de6c19900abd6 (diff) |
basic functionality pass 10
-rw-r--r-- | backend.php | 56 | ||||
-rw-r--r-- | functions.php | 16 | ||||
-rw-r--r-- | prefs.js | 86 | ||||
-rw-r--r-- | prefs.php | 19 | ||||
-rw-r--r-- | tt-rss.css | 44 | ||||
-rw-r--r-- | tt-rss.js | 37 | ||||
-rw-r--r-- | tt-rss.php | 15 |
7 files changed, 166 insertions, 107 deletions
diff --git a/backend.php b/backend.php index 3b9ff5421..6ea1355b9 100644 --- a/backend.php +++ b/backend.php @@ -11,10 +11,11 @@ pg_query("set client_encoding = 'utf-8'"); $op = $_GET["op"]; + $fetch = $_GET["fetch"]; if ($op == "feeds") { - update_all_feeds($link); + if ($fetch) update_all_feeds($link); $result = pg_query("SELECT *, (SELECT count(id) FROM ttrss_entries @@ -53,7 +54,7 @@ } print "<tr><td class=\"footer\" colspan=\"3\"> - <a href=\"javascript:update_feed_list()\">Update all feeds</a></td></tr>"; + <a href=\"javascript:update_feed_list(false,true)\">Update all feeds</a></td></tr>"; print "</table>"; @@ -201,9 +202,43 @@ if ($op == "pref-feeds") { + $subop = $_GET["subop"]; + + if ($subop == "edit") { + print "<p>[Edit feed placeholder]</p>"; + } + + if ($subop == "remove") { + $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"); + + } + } + + if ($subop == "add") { + $feed_link = pg_escape_string($_GET["link"]); + + $result = pg_query( + "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); + + $result = pg_query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); + + $feed_id = pg_fetch_result($result, 0, "id"); + + if ($feed_id) { + update_rss_feed($link, $feed_link, $feed_id); + } + + } + $result = pg_query("SELECT * FROM ttrss_feeds ORDER by title"); - print "<p><table width=\"100%\" class=\"prefFeedList\">"; + print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; print "<tr class=\"title\"> <td>Select</td><td>Title</td><td>Link</td><td>Last Updated</td></tr>"; @@ -212,13 +247,18 @@ while ($line = pg_fetch_assoc($result)) { $class = ($lnum % 2) ? "even" : "odd"; - - print "<tr class=\"$class\">"; + + $feed_id = $line["id"]; + + print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; print "<td><input onclick='toggleSelectRow(this);' - type=\"checkbox\" id=\"FROW-".$line["id"]."\"></td>"; - print "<td>" . $line["title"] . "</td>"; - print "<td>" . $line["feed_url"] . "</td>"; + type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; + print "<td><a href=\"javascript:editFeed($feed_id);\">" . + $line["title"] . "</td>"; + print "<td><a href=\"javascript:editFeed($feed_id);\">" . + $line["feed_url"] . "</td>"; + print "<td>" . $line["last_updated"] . "</td>"; print "</tr>"; diff --git a/functions.php b/functions.php index d49c951fc..3da349f1d 100644 --- a/functions.php +++ b/functions.php @@ -4,7 +4,7 @@ function update_all_feeds($link) { $result = pg_query($link, "SELECT feed_url,id FROM ttrss_feeds WHERE - last_updated is null OR + last_updated is null OR title = '' OR EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) > " . MIN_UPDATE_TIME); @@ -19,6 +19,16 @@ $rss = fetch_rss($feed_url); if ($rss) { + + $result = pg_query("SELECT title FROM ttrss_feeds WHERE id = '$feed'"); + + $registered_title = pg_fetch_result($result, 0, "title"); + + if (!$registered_title) { + + $feed_title = $rss->channel["title"]; + pg_query("UPDATE ttrss_feeds SET title = '$feed_title' WHERE id = '$feed'"); + } foreach ($rss->items as $item) { @@ -30,7 +40,9 @@ $entry_timestamp = $item["pubdate"]; if (!$entry_timestamp) $entry_timestamp = $item["modified"]; if (!$entry_timestamp) $entry_timestamp = $item["updated"]; - + + if (!$entry_timestamp) continue; + $entry_timestamp = strtotime($entry_timestamp); if (!$entry_timestamp) continue; @@ -24,33 +24,6 @@ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } -function param_escape(arg) { - if (typeof encodeURIComponent != 'undefined') - return encodeURIComponent(arg); - else - return escape(arg); -} - -function param_unescape(arg) { - if (typeof decodeURIComponent != 'undefined') - return decodeURIComponent(arg); - else - return unescape(arg); -} - -function notify(msg) { - - var n = document.getElementById("notify"); - - n.innerHTML = msg; - - if (msg.length == 0) { - n.style.display = "none"; - } else { - n.style.display = "block"; - } - -} function feedlist_callback() { var container = document.getElementById('feeds'); @@ -85,13 +58,62 @@ function toggleSelectRow(sender) { function addFeed() { - var link = document.getElementById("fadd_link").value; - var title = document.getElementById("fadd_title").value; + var link = document.getElementById("fadd_link"); + + if (link.length == 0) { + notify("Missing feed URL."); + } else { + notify("Adding feed..."); + + xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" + + param_escape(link.value), true); + xmlhttp.onreadystatechange=feedlist_callback; + xmlhttp.send(null); + + link.value = ""; + + } + +} + +function editFeed(feed) { + + notify("Editing feed..."); + + xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" + + param_escape(feed), true); + xmlhttp.onreadystatechange=feedlist_callback; + xmlhttp.send(null); + +} + + +function removeSelectedFeeds() { + + var content = document.getElementById("prefFeedList"); + + var sel_rows = new Array(); + + for (i = 0; i < content.rows.length; i++) { + if (content.rows[i].className.match("Selected")) { + var row_id = content.rows[i].id.replace("FEEDR-", ""); + sel_rows.push(row_id); + } + } + + if (sel_rows.length > 0) { + + notify("Removing selected feeds..."); + + xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+ + param_escape(sel_rows.toString()), true); + xmlhttp.onreadystatechange=feedlist_callback; + xmlhttp.send(null); - if (link.length == 0 || title.length == 0) { - notify("Error: all fields must be filled in."); } else { - notify("addFeed : " + link + ", " + title); + + notify("Please select some feeds first."); + } } @@ -2,6 +2,7 @@ <head> <title>Tiny Tiny RSS</title> <link rel="stylesheet" href="tt-rss.css" type="text/css"> + <script type="text/javascript" src="functions.js"></script> <script type="text/javascript" src="prefs.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> @@ -23,27 +24,19 @@ </td> </tr> </tr> - <td class="content" id="content" valign="top" colspan="2"> + <td class="prefContent" valign="top" colspan="2"> <h2>Feed Configuration</h2> - <!-- <input type="submit" value="Add feed"> --> - - <!-- <table class="prefAddFeed"> - <tr><td>Title:</td><td><input id="fadd_title"></td></tr> - <tr><td>Link:</td><td><input id="fadd_link"></td></tr> - <tr><td colspan="2" align="right"> - <a class="button" href="javascript:addFeed()">Add feed</a></td></tr> - </table> --> - <table class="prefAddFeed"> - <tr><td>Title:</td><td><input id="fadd_title"></td> - <td>Link:</td><td><input id="fadd_link"></td></tr> - <tr><td colspan="4" align="right"> + <td><input id="fadd_link"></td> + <td colspan="4" align="right"> <a class="button" href="javascript:addFeed()">Add feed</a></td></tr> </table> <div id="feeds"> </div> + <p><a class="button" href="javascript:removeSelectedFeeds()">Remove Selected</a> + <hr> </td> diff --git a/tt-rss.css b/tt-rss.css index 4bde18858..38187380e 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -32,22 +32,6 @@ a:hover { color : #5050aa; } -a.button { - border : 1px solid #d0d0d0; - background-image : url("button.png"); - background-position : top; - background-repeat : repeat-x; - background-color : white; - color : black; - padding : 2px 10px 2px 10px; - font-size : small; -} - -a.button:hover { - background : white; - text-decoration : none; -} - table.feedOverview { margin : 5px; border : 1px solid #c0c0c0; @@ -112,7 +96,7 @@ table.main td.toolbar { font-weight : bold; border : 1px solid #c0c0c0; font-size : small; - display : block; + display : none; background : white; -moz-border-radius : 5px; padding : 3px 10px 3px 10px; @@ -149,12 +133,18 @@ table.main td.headlines { overflow : scroll; } +table.main td.prefContent { + padding : 10px; + border-width : 1px 0px 0px 0px; + border-color : #c0c0c0; + border-style : solid; +} + table.main td.content { padding : 10px; border-width : 1px 0px 0px 0px; border-color : #c0c0c0; border-style : solid; - overflow : scroll; } td.content a { @@ -240,3 +230,21 @@ table.prefFeedList tr.title td { background-color : #c0c0c0; } +a.button { + border : 1px solid #d0d0d0; + background-image : url("button.png"); + background-position : top; + background-repeat : repeat-x; + background-color : white; + color : black; + padding : 2px 10px 2px 10px; + font-size : small; +} + +a.button:hover { + background : white; + text-decoration : none; + color : black; +} + + @@ -24,28 +24,6 @@ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } -function param_escape(arg) { - if (typeof encodeURIComponent != 'undefined') - return encodeURIComponent(arg); - else - return escape(arg); -} - -function param_unescape(arg) { - if (typeof decodeURIComponent != 'undefined') - return decodeURIComponent(arg); - else - return unescape(arg); -} - -function notify(msg) { - - var n = document.getElementById("notify"); - - n.innerHTML = msg; - -} - function feedlist_callback() { var container = document.getElementById('feeds'); if (xmlhttp.readyState == 4) { @@ -90,13 +68,17 @@ function view_callback() { } -function update_feed_list(called_from_timer) { +function update_feed_list(called_from_timer, fetch) { if (called_from_timer != true) { - document.getElementById("feeds").innerHTML = "Updating feeds, please wait..."; + document.getElementById("feeds").innerHTML = "Loading feeds, please wait..."; } - xmlhttp.open("GET", "backend.php?op=feeds", true); + var query_str = "backend.php?op=feeds"; + + if (fetch) query_str = query_str + "&fetch=yes"; + + xmlhttp.open("GET", query_str, true); xmlhttp.onreadystatechange=feedlist_callback; xmlhttp.send(null); @@ -105,7 +87,7 @@ function update_feed_list(called_from_timer) { function viewfeed(feed, skip, ext) { - notify("view-feed: " + feed); +// notify("view-feed: " + feed); document.getElementById('headlines').innerHTML='Loading headlines, please wait...'; document.getElementById('content').innerHTML=' '; @@ -164,8 +146,9 @@ function search(feed, sender) { function init() { - update_feed_list(); + update_feed_list(false, false); setTimeout("timeout()", 1800*1000); + } diff --git a/tt-rss.php b/tt-rss.php index 34d99ff45..f267a3b44 100644 --- a/tt-rss.php +++ b/tt-rss.php @@ -2,6 +2,7 @@ <head> <title>Tiny Tiny RSS</title> <link rel="stylesheet" href="tt-rss.css" type="text/css"> + <script type="text/javascript" src="functions.js"></script> <script type="text/javascript" src="tt-rss.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> @@ -15,12 +16,12 @@ </td> </tr> <tr> - <!-- <td class="toolbar" valign="middle" > - Search: <input name="q" onclick=\"javascript:search(this);\"> - </td> --> - <td class="toolbar" valign="middle" colspan="2"> - <a href="prefs.php" class="button">Preferences</a> - <!-- <a class="button" href="javascript:refresh()">Refresh</a> --> + <td class="toolbar" colspan="2"> + <table width="100%" cellspacing="0" cellpadding="0"> + <td valign="middle"> <div id="notify"> </div></td> + <td class="toolbar" valign="middle" align="right"> + <a href="prefs.php" class="button">Preferences</a></td> + </tr></table> </td> </tr> <tr> @@ -36,7 +37,7 @@ </td> </tr> <tr> - <td colspan="2" id="notify" class="notify"> + <td colspan="2" class="notify"> <a href="">Tiny-Tiny RSS</a> v0.1 © 2005 Andrew Dolgov </td> </td> |