]> git.wh0rd.org - tt-rss.git/commitdiff
basic functionality pass 10
authorAndrew Dolgov <fox@madoka.spb.ru>
Mon, 22 Aug 2005 04:56:40 +0000 (05:56 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Mon, 22 Aug 2005 04:56:40 +0000 (05:56 +0100)
backend.php
functions.php
prefs.js
prefs.php
tt-rss.css
tt-rss.js
tt-rss.php

index 3b9ff5421d5a9160a11ef9f200e2ffcf527e66c6..6ea1355b9cf6824adbe6d4635f1a8f2e214af935 100644 (file)
        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>";
 
 
        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>";
                
                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>";
 
index d49c951fc5141aeafb6f061df78b8c321a895f87..3da349f1d58a2161ff31a9016818bde26b947c55 100644 (file)
@@ -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);
 
                $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;
index b068e01be0ee09556041a07469226286607dc92f..7fb4562f7d5a39c3b4a0407dd31b015e6a78026e 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -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.");
+
        }
 
 }
index 6ec78a5b2167792d50eb22f4c66077748a2968c7..7f2a8cb3695dc18b5b7962b08c17a709b6cf0e48 100644 (file)
--- a/prefs.php
+++ b/prefs.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="prefs.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 </head>
        </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">&nbsp;</div>
 
+               <p><a class="button" href="javascript:removeSelectedFeeds()">Remove Selected</a>&nbsp;
+
                <hr>
 
        </td>
index 4bde18858146f0531a6362ce6e5d0b9f56d40bb1..38187380ef66a6615d1663755982315eb7dd9c3e 100644 (file)
@@ -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;
+}
+
+
index 5426e4f3d58c67ad64e84cbce7ff24e5ca288352..3f6aab00bee5a4cc37471fbe453749182ea882dd 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -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='&nbsp;';          
@@ -164,8 +146,9 @@ function search(feed, sender) {
 
 function init() {
 
-       update_feed_list();
+       update_feed_list(false, false);
 
        setTimeout("timeout()", 1800*1000);
 
+
 }
index 34d99ff45a7dbfdd0ce2cba0777e42a9bf666e21..f267a3b4430cf1b4d300d4bbabc0600c7513cdb8 100644 (file)
@@ -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>
        </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">&nbsp;</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 &copy; 2005 Andrew Dolgov
        </td>
 </td>