]> git.wh0rd.org Git - tt-rss.git/commitdiff
don't allow duplicate feeds for user
authorAndrew Dolgov <fox@bah.spb.su>
Sat, 19 Nov 2005 17:57:14 +0000 (18:57 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Sat, 19 Nov 2005 17:57:14 +0000 (18:57 +0100)
backend.php

index afa04fe161f729b220924d4148efeeebe39271d9..3eca4eda7e99d4aff123f14876bafb138b781bc7 100644 (file)
                        if (!WEB_DEMO_MODE) {
 
                                $feed_link = db_escape_string($_GET["link"]);
-                                       
-                               $result = db_query($link,
-                                       "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
 
                                $result = db_query($link,
-                                       "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' AND owner_uid = " . $_SESSION["uid"]);
+                                       "SELECT id FROM ttrss_feeds 
+                                       WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
+
+                               if (db_num_rows($result) == 0) {
+                                       
+                                       $result = db_query($link,
+                                               "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) 
+                                               VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
 
-                               $feed_id = db_fetch_result($result, 0, "id");
+                                       $result = db_query($link,
+                                       "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link' 
+                                               AND owner_uid = " . $_SESSION["uid"]);
+
+                                       $feed_id = db_fetch_result($result, 0, "id");
+
+                                       if ($feed_id) {
+                                               update_rss_feed($link, $feed_link, $feed_id);
+                                       }
+                               } else {
 
-                               if ($feed_id) {
-                                       update_rss_feed($link, $feed_link, $feed_id);
+                                       print "<div class=\"warning\">
+                                               Feed <b>$feed_link</b> already exists in the database.
+                                       </div>";
                                }
                        }
                }