]> git.wh0rd.org Git - tt-rss.git/commitdiff
part of #276: determine if the url contents are html
authorChristian Weiske <cweiske@cweiske.de>
Sun, 7 Nov 2010 13:43:15 +0000 (14:43 +0100)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 8 Nov 2010 20:30:10 +0000 (23:30 +0300)
functions.js
functions.php

index 626a23a896279bde44dc3a14fdfdb4b9958c69fa..af18f8383629e52ab694af6fffc5e12f7b567255 100644 (file)
@@ -1319,6 +1319,7 @@ function subscribeToFeed() {
                                }
                                break;
                        case 2:
+                       case 3:
                                alert(__("Can't subscribe to the specified URL."));
                                break;
                        case 0:
index 7f24b4d061cdb7024f33052f81e141aecc80bc86..a31e52e0bf5df4da02c16d8dda325ca9f8b02b2f 100644 (file)
         *                 0 - OK, Feed already exists
         *                 1 - OK, Feed added
         *                 2 - Invalid URL
+        *                 3 - URL content is HTML, not a feed
         */
        function subscribe_to_feed($link, $url, $cat_id = 0, 
                        $auth_login = '', $auth_pass = '') {
                        WHERE feed_url = '$url' AND owner_uid = ".$_SESSION["uid"]);
        
                if (db_num_rows($result) == 0) {
+                       if (url_is_html($url)) {
+                               return 3;
+                       }
                        
                        $result = db_query($link,
                                "INSERT INTO ttrss_feeds 
                return $feedUrls;
        }
 
+       /**
+        * Checks if the content behind the given URL is a HTML file
+        *
+        * @param string $url URL to check
+        *
+        * @return boolean True if the URL contains HTML content
+        */
+       function url_is_html($url) {
+               $content = substr(fetch_file_contents($url, false), 0, 1000);
+               if (strpos($content, '<html>') === false
+                       && strpos($content, '<html ') === false
+               ) {
+                       return false;
+               }
+
+               return true;
+       }
 ?>