]> git.wh0rd.org Git - tt-rss.git/commitdiff
add aggregated feed generator
authorAndrew Dolgov <fox@bah.spb.su>
Mon, 31 Jul 2006 11:35:50 +0000 (12:35 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Mon, 31 Jul 2006 11:35:50 +0000 (12:35 +0100)
NEWS
backend.php
functions.php
images/feed-icon-12x12.png [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index f051034b1e13624390d995ba2310bf0c60308547..fb7fed77cbbfa6f157b3625e0a6e98f212e53403 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ v1.2.2  (Aug xx, 2006)
 
        * Bugfixes
        * Support for HTTP Digest authentication (via included Snoopy class)
+       * Support for generation of aggregated feeds
 
 v1.2.1 (Jul 17, 2006)
 
index ff19595f5900da9f74878b41be509a504b3be787..107074fb4d5ab878ba4b52f612cdfe6b22b46061 100644 (file)
                print_error_xml(9, $err_msg); die;
        }
 
-       if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
+       if ((!$op || $op == "rpc" || $op == "rss" || 
+                       $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
                header("Content-Type: application/xml");
        }
 
-       if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
+       if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss") {
 
                if ($op == "rpc") {
                        print_error_xml(6); die;
                }
 
                function print_headline_subtoolbar($link, $feed_site_url, $feed_title, 
-                                               $bottom = false, $rtl_content = false) {
+                       $bottom = false, $rtl_content = false, $feed_id = 0,
+                       $is_cat = false) {
 
                        if (!$bottom) {
                                $class = "headlinesSubToolbar";
                        } else {
                                print $feed_title;
                        }
+
+                       print "&nbsp;
+                               <a target=\"_new\" 
+                                       href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat\"
+                                       <img class=\"noborder\" 
+                                               alt=\"Generated feed\" src=\"images/feed-icon-12x12.png\">
+                               </a>";
                                
                        print "</td>";
                        print "</tr></table>";
                if (db_num_rows($result) > 0) {
 
                        print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, 
-                               $rtl_content);
+                               $rtl_content, $feed, $cat_view);
 
                        if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
                                print "<table class=\"headlinesList\" id=\"headlinesList\" 
 
        }
 
+       if ($op == "rss") {
+               $feed = db_escape_string($_GET["id"]);
+               $user = db_escape_string($_GET["user"]);
+               $pass = db_escape_string($_GET["pass"]);
+               $is_cat = $_GET["is_cat"] != false;
+
+               if (!$_SESSION["uid"] && $user && $pass) {
+                       authenticate_user($link, $user, $pass);
+               }
+
+               if ($_SESSION["uid"] ||
+                       http_authenticate_user($link)) {
+
+                               generate_syndicated_feed($link, $feed, $is_cat);
+               }
+       }
+
        function check_configuration_variables() {
                if (!defined('SESSION_EXPIRE_TIME')) {
                        return "config: SESSION_EXPIRE_TIME is undefined";
index 686cecfeb1422b2a7e8ef285e45ef8e5432a7c8c..e77f2d5a0450c05d9a8edf924151708c20b8099e 100644 (file)
                }
        }
 
+       function http_authenticate_user($link) {
+
+               if (!$_SERVER["PHP_AUTH_USER"]) {
+
+                       header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"');
+                       header('HTTP/1.0 401 Unauthorized');
+                       exit;
+                                       
+               } else {
+                       $auth_result = authenticate_user($link, 
+                               $_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]);
+
+                       if (!$auth_result) {
+                               header('WWW-Authenticate: Basic realm="Tiny Tiny RSS RSSGen"');
+                               header('HTTP/1.0 401 Unauthorized');
+                               exit;
+                       }
+               }
+
+               return true;
+       }
+
        function authenticate_user($link, $login, $password) {
 
                if (!SINGLE_USER_MODE) {
 
        function getCategoryUnread($link, $cat) {
 
-               $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE cat_id = '$cat' 
+               if ($cat != 0) {
+                       $cat_query = "cat_id = '$cat'";
+               } else {
+                       $cat_query = "cat_id IS NULL";
+               }
+
+               $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE $cat_query 
                                AND owner_uid = " . $_SESSION["uid"]);
 
                $cat_feeds = array();
                        array_push($cat_feeds, "feed_id = " . $line["id"]);
                }
 
+               if (count($cat_feeds) == 0) return 0;
+
                $match_part = implode(" OR ", $cat_feeds);
 
                $result = db_query($link, "SELECT COUNT(int_id) AS unread 
                        
        }
 
+       function generate_syndicated_feed($link, $feed, $is_cat) {
+
+               $qfh_ret = queryFeedHeadlines($link, $feed, 
+                               30, false, $is_cat, false, false, false);
+
+               $result = $qfh_ret[0];
+               $feed_title = $qfh_ret[1];
+               $feed_site_url = $qfh_ret[2];
+               $last_error = $qfh_ret[3];
+
+               print "<rss version=\"2.0\">
+                       <channel>
+                       <title>$feed_title</title>
+                       <link>$feed_site_url</link>
+                       <generator>Tiny Tiny RSS v".VERSION."</generator>";
+
+               while ($line = db_fetch_assoc($result)) {
+                       print "<item>";
+                       print "<link>" . htmlspecialchars($line["link"]) . "</link>";
+
+                       $rfc822_date = date('r', strtotime($line["updated"]));
+
+                       print "<pubDate>$rfc822_date</pubDate>";
+
+                       print "<title>" . 
+                               htmlspecialchars($line["title"]) . "</title>";
+
+                       print "<description>" . 
+                               htmlspecialchars($line["content_preview"]) . "</description>";
+
+                       print "</item>";
+               }
+
+               print "</channel></rss>";
+
+       }
+
 ?>
diff --git a/images/feed-icon-12x12.png b/images/feed-icon-12x12.png
new file mode 100644 (file)
index 0000000..291000e
Binary files /dev/null and b/images/feed-icon-12x12.png differ