]> git.wh0rd.org - tt-rss.git/commitdiff
update schema, more mysql work
authorAndrew Dolgov <fox@bah.spb.su>
Wed, 7 Sep 2005 13:31:21 +0000 (14:31 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Wed, 7 Sep 2005 13:31:21 +0000 (14:31 +0100)
backend.php
db.php
functions.js
functions.php
opml.php
tt-rss.js
ttrss_schema_mysql.sql

index 82e07e6d75fc694a71ce5ed14efa97e5475b2f39..b4181069fd38bf9408415e99243c0bb6e50ece72 100644 (file)
                                </head><body>";
                }
 
-               // FIXME: check for null value here
-
-               $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'");
+               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) {
 
                        $limit_query_part = "LIMIT " . $limit;
                } 
 
+               if (DB_TYPE == "pgsql") {
+                       $extract_epoch_qpart = "
+                       ,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,
-                               EXTRACT(EPOCH FROM last_read) AS last_read_ts,
-                               EXTRACT(EPOCH FROM updated) AS updated_ts
+                               id,title,updated,unread,feed_id,marked,link
+                               $extract_epoch_qpart
                        FROM
                                ttrss_entries 
                        WHERE
                                        alt=\"Updated\">";
                        }
 
-                       if ($line["unread"] == "t") {
+                       if ($line["unread"] == "t" || $line["unread"] == "1") {
                                $class .= "Unread";
                                ++$num_unread;
                        }
 
-                       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 {
                                <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 (!WEB_DEMO_MODE) {
 
-                               $regexp = db_escape_string($_GET["reg_exp"]);
+                               $regexp = db_escape_string($_GET["regexp"]);
                                $match = db_escape_string($_GET["match"]);
                                        
                                $result = db_query($link,
diff --git a/db.php b/db.php
index cfb289e0cd6e9ef02c5f49bd245268700708653f..d739aa9b2ac5271efa5c8293cbc99ed7fdaa4849 100644 (file)
--- a/db.php
+++ b/db.php
@@ -20,7 +20,7 @@ function db_escape_string($s) {
        if (DB_TYPE == "pgsql") {       
                return pg_escape_string($s);
        } else {
-               return mysql_escape_string($s);
+               return mysql_real_escape_string($s);
        }
 }
 
@@ -32,6 +32,14 @@ function db_query($link, $query) {
        }
 }
 
+function db_query_2($query) {
+       if (DB_TYPE == "pgsql") {
+               return pg_query($query);
+       } else if (DB_TYPE == "mysql") {
+               return mysql_query($link);
+       }
+}
+
 function db_fetch_assoc($result) {
        if (DB_TYPE == "pgsql") {
                return pg_fetch_assoc($result);
@@ -43,9 +51,9 @@ function db_fetch_assoc($result) {
 
 function db_num_rows($result) {
        if (DB_TYPE == "pgsql") {
-               return pg_num_rows($link, $query);
+               return pg_num_rows($result);
        } else if (DB_TYPE == "mysql") {
-               return mysql_num_rows($link, $query);
+               return mysql_num_rows($result);
        }
 }
 
index ebb1bb8f3ff83693ce5d014869346f19971795e7..540d7b89cd0854816335fff69a59ee67a44a2b01 100644 (file)
@@ -263,4 +263,6 @@ function gotoMain() {
        document.location.href = "tt-rss.php";
 }
 
-
+function gotoExportOpml() {
+       document.location.href = "opml.php?op=Export";
+}
index bea443c2765d283ca445c7f253a549dfc84da8a1..742e026f5c54f01c63ef26c02451bc82299deb91 100644 (file)
 
                                $entry_guid = db_escape_string($entry_guid);
 
+                               if (DB_TYPE == "pgsql") {
+                                       $extract_ts_qpart = ",EXTRACT(EPOCH FROM updated) as updated_timestamp";
+                               }
+
                                $result = db_query($link, "
                                        SELECT 
-                                               id,last_read,no_orig_date,title,feed_id,content_hash,
-                                               EXTRACT(EPOCH FROM updated) as updated_timestamp
+                                               id,last_read,no_orig_date,title,feed_id,content_hash
+                                               $extract_ts_qpart
                                        FROM
                                                ttrss_entries 
                                        WHERE
index f3dd34ef47ebb6a4d2ba164615ff727471147173..d932d8bd9e3c26956f0661324f2bb62df8bd51da 100644 (file)
--- a/opml.php
+++ b/opml.php
@@ -8,20 +8,22 @@
        }
 
        require_once "config.php";
-       require_once "functions.php";
+       require_once "db.php";
 
-       $link = pg_connect(DB_CONN);
+       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
-       pg_query($link, "set client_encoding = 'utf-8'");
+       if (DB_TYPE == "pgsql") {
+               pg_query($link, "set client_encoding = 'utf-8'");
+       }
 
        if ($op == "Export") {
                print "<opml version=\"1.0\">";
                print "<head><dateCreated>" . date("r", time()) . "</dateCreated></head>"; 
                print "<body>";
 
-               $result = pg_query("SELECT * FROM ttrss_feeds ORDER BY title");
+               $result = db_query($link, "SELECT * FROM ttrss_feeds ORDER BY title");
 
-               while ($line = pg_fetch_assoc($result)) {
+               while ($line = db_fetch_assoc($result)) {
                        $title = $line["title"];
                        $url = $line["feed_url"];
 
        }
 
        function startElement($parser, $name, $attrs) {
+
                if ($name == "OUTLINE") {
-                       $title = pg_escape_string($attrs['TEXT']);
-                       $url = pg_escape_string($attrs['XMLURL']);
+                       $title = db_escape_string($attrs['TEXT']);
+                       $url = db_escape_string($attrs['XMLURL']);
 
                        if (!$title || !$url) return;
 
                        print "Feed <b>$title</b> ($url)... ";
 
-                       $result = pg_query("SELECT id FROM ttrss_feeds WHERE
+                       $result = db_query_2("SELECT id FROM ttrss_feeds WHERE
                                title = '$title' OR feed_url = '$url'");
 
-                       if (pg_num_rows($result) > 0) {
+                       if (db_num_rows($result) > 0) {
                                
                                print " Already imported.<br>";
 
                        } else {
 
-                               $result = pg_query("INSERT INTO ttrss_feeds (title, feed_url) VALUES
+                               $result = db_query_2("INSERT INTO ttrss_feeds (title, feed_url) VALUES
                                        ('$title', '$url')");
 
                                print "<b>Done.</b><br>";
 
        }
 
-       pg_close($link);
+       db_close($link);
 
 ?>
index 2015797c5c188ee6346e807ea976bb0a7765325f..1d1c793a966b2cd5db4b559793f527f80840a680 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -58,16 +58,18 @@ function feedlist_callback() {
 }
 */
 
+function checkActiveFeedId() {
 
-function refetch_callback() {
+       var actfeedid = frames["feeds-frame"].document.getElementById("ACTFEEDID");
 
-       if (xmlhttp_rpc.readyState == 4) {
+       if (actfeedid) {
+               active_feed_id = actfeedid.innerHTML;
+       }
+}
 
-               var actfeedid = frames["feeds-frame"].document.getElementById("ACTFEEDID");
+function refetch_callback() {
 
-               if (actfeedid) {
-                       active_feed_id = actfeedid.innerHTML;
-               }
+       if (xmlhttp_rpc.readyState == 4) {
 
                document.title = "Tiny Tiny RSS";
                notify("All feeds updated.");
@@ -253,6 +255,7 @@ function resetSearch() {
 }
 
 function search() {
+       checkActiveFeedId();
        if (active_feed_id) {
                viewfeed(active_feed_id, 0, "");
        } else {
@@ -315,9 +318,9 @@ function init() {
 
        updateFeedList(false, false);
        document.onkeydown = hotkey_handler;
-       setTimeout("timeout()", 1800*1000);
 
-       scheduleFeedUpdate(true);
+//     setTimeout("timeout()", 1800*1000);
+//     scheduleFeedUpdate(true);
 
        var content = document.getElementById("content");
 
index 91fde947f1808cdef45259fd8a2414f37306c936..348cb24211c49608fadbf70df362f79df9b89d41 100644 (file)
@@ -5,7 +5,7 @@ create table ttrss_feeds (id integer not null auto_increment primary key,
        title varchar(200) not null unique, 
        feed_url varchar(250) unique not null, 
        icon_url varchar(250) not null default '',
-       last_updated timestamp default null) TYPE=InnoDB;
+       last_updated datetime default '') TYPE=InnoDB;
 
 insert into ttrss_feeds (title,feed_url) values ('Footnotes', 'http://gnomedesktop.org/node/feed');
 insert into ttrss_feeds (title,feed_url) values ('Freedesktop.org', 'http://planet.freedesktop.org/rss20.xml');
@@ -28,19 +28,19 @@ insert into ttrss_feeds (title,feed_url) values ('Technocrat.net',
        'http://syndication.technocrat.net/rss');
 
 create table ttrss_entries (id integer not null primary key auto_increment, 
-       feed_id integer not null, 
-       updated timestamp not null, 
+       feed_id integer not null references ttrss_feeds(id)
+       updated datetime not null, 
        title varchar(250) not null, 
        guid varchar(250) not null unique, 
        link varchar(250) not null, 
        content text not null,
        content_hash varchar(250) not null,
-       last_read timestamp,
-       marked bool not null default 'false',
-       date_entered timestamp not null,
-       no_orig_date bool not null default 'false',
+       last_read datetime,
+       marked bool not null default 0,
+       date_entered datetime not null,
+       no_orig_date bool not null default 0,
        comments varchar(250) not null default '',
-       unread bool not null default 'true') TYPE=InnoDB;
+       unread bool not null default 1) TYPE=InnoDB;
 
 drop table if exists ttrss_filters;
 drop table if exists ttrss_filter_types;
@@ -56,7 +56,7 @@ insert into ttrss_filter_types (id,name,description) values (3, 'both',
        'Title or Content');
 
 create table ttrss_filters (id integer primary key auto_increment, 
-       filter_type integer not null, 
+       filter_type integer not null references ttrss_filter_types(id)
        reg_exp varchar(250) not null,
        description varchar(250) not null default '') TYPE=InnoDB;