]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
fix feedlist layout bug (take two) - remove unneeded CRs
[tt-rss.git] / backend.php
index 020744073278b5868106200a9ccae67ca621d061..76564fb7d9576433456077149f4889fbc0d71939 100644 (file)
@@ -1,6 +1,6 @@
 <?
        session_start();
-
+       
        if ($_GET["debug"]) {
                define('DEFAULT_ERROR_LEVEL', E_ALL);
        } else {
@@ -28,7 +28,7 @@
                exit;
        }
 
-       define('SCHEMA_VERSION', 4);
+       define('SCHEMA_VERSION', 5);
 
        require_once "sanity_check.php";
        require_once "config.php";
@@ -59,6 +59,9 @@
                } else {
                        setcookie("ttrss_vf_hreadf", 0);
                }  
+
+               setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH);
+               setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON);
        }
 
        $fetch = $_GET["fetch"];
 
        /* FIXME this needs reworking */
 
-       function getGlobalCounters($link) {
+       function getGlobalUnread($link) {
                $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
                        WHERE unread = true AND 
                        ttrss_user_entries.ref_id = ttrss_entries.id AND 
                        owner_uid = " . $_SESSION["uid"]);
                $c_id = db_fetch_result($result, 0, "c_id");
-               print "<counter type=\"global\" id='global-unread' counter='$c_id'/>";
+               return $c_id;
+       }
+
+       function getGlobalCounters($link, $global_unread = -1) {
+               if ($global_unread == -1) {     
+                       $global_unread = getGlobalUnread($link);
+               }
+               print "<counter type=\"global\" id='global-unread' counter='$global_unread'/>";
        }
 
        function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS) {
                        <script type=\"text/javascript\" src=\"pngfix.js\"></script>
                        <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
                        <![endif]-->
-                       </head><body onload=\"init()\">";
+                       </head><body>
+                       <script type=\"text/javascript\">
+                               if (document.addEventListener) {
+                                       document.addEventListener(\"DOMContentLoaded\", init, null);
+                               }
+                               window.onload = init;
+                       </script>";
 
-               print "<ul class=\"feedList\" id=\"feedList\">";
+               print "<ul class=\"feedList\" id=\"feedList\">\n";
 
                $owner_uid = $_SESSION["uid"];
 
                                "images/mark_set.png", $link);
 
                        if (get_pref($link, 'ENABLE_FEED_CATS')) {
-                               print "</li></ul>";
+                               print "</ul>\n";
                        }
 
                        if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
 
                                if (db_num_rows($result) > 0) {
                                        if (get_pref($link, 'ENABLE_FEED_CATS')) {
-                                               print "</li></ul>";
+                                               print "</ul>";
                                        }
                                }
 
                                if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
                                
                                        if ($category) {
-                                               print "</li></ul></li>";
+                                               print "</ul></li>";
                                        }
                                
                                        $category = $tmp_category;
 
                print "</ul>";
 
+               print '
+                       <script type="text/javascript">
+                               /* for IE */
+                               function statechange() {
+                                       if (document.readyState == "interactive") init();
+                               }
+                       
+                               if (document.readyState) {      
+                                       if (document.readyState == "interactive" || document.readyState == "complete") {
+                                               init();
+                                       } else {
+                                               document.onreadystatechange = statechange;
+                                       }
+                               }
+                       </script></body></html>';
        }
 
 
                }
 
                if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
-               
-                       update_all_feeds($link, $subop == "forceUpdateAllFeeds");                       
+       
+                       if (ENABLE_UPDATE_DAEMON) {
 
-                       $omode = $_GET["omode"];
+                               if ($subop == "forceUpdateAllFeeds") {                          
 
-                       if (!$omode) $omode = "tfl";
+                                       $result = db_query($link, "SELECT count(id) AS cid FROM
+                                               ttrss_scheduled_updates WHERE feed_id IS NULL AND
+                                                       owner_uid = " . $_SESSION["uid"]);
+       
+                                       $cid = db_fetch_result($result, 0, "cid");
+       
+#                                      print "<rpc-reply>";
+       
+                                       if ($cid == 0) {
+       
+                                               db_query($link, "INSERT INTO ttrss_scheduled_updates
+                                                       (owner_uid, feed_id, entered) VALUES
+                                                       (".$_SESSION["uid"].", NULL, NOW())");
+                                                       
+//                                             print "<!-- ScheduledOK -->";
+                                               
+                                       } else {
+//                                             print "<!-- RequestAlreadyInQueue -->";
+                                       }
+       
+#                                      print "</rpc-reply>";
+                               }
+                               
+                       } else {        
+                               update_all_feeds($link, $subop == "forceUpdateAllFeeds");
+                       }
+
+                       $global_unread_caller = sprintf("%d", $_GET["uctr"]);
+                       $global_unread = getGlobalUnread($link);
 
                        print "<rpc-reply>";
-                       if (strchr($omode, "l")) getLabelCounters($link);
-                       if (strchr($omode, "f")) getFeedCounters($link);
-                       if (strchr($omode, "t")) getTagCounters($link);
-                       if (get_pref($link, 'ENABLE_FEED_CATS')) {
-                               getCategoryCounters($link);
+
+                       if ($global_unread_caller != $global_unread) {
+
+                               $omode = $_GET["omode"];
+        
+                               if (!$omode) $omode = "tflc";
+        
+                               if (strchr($omode, "l")) getLabelCounters($link);
+                               if (strchr($omode, "f")) getFeedCounters($link);
+                               if (strchr($omode, "t")) getTagCounters($link);
+                               if (strchr($omode, "c")) {                      
+                                       if (get_pref($link, 'ENABLE_FEED_CATS')) {
+                                               getCategoryCounters($link);
+                                       }
+                               }
                        }
-                       getGlobalCounters($link);
+
+                       getGlobalCounters($link, $global_unread);
+
                        print "</rpc-reply>";
+
                }
        
                /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
                                <script type=\"text/javascript\" src=\"pngfix.js\"></script>
                                <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
                                <![endif]-->
-                               </head><body onload='init()'>";
+                               </head><body>
+                               <script type=\"text/javascript\">
+                               if (document.addEventListener) {
+                                       document.addEventListener(\"DOMContentLoaded\", init, null);
+                               }
+                               window.onload = init;
+                               </script>";
                }
 
                if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
 
-                       $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
-                               WHERE id = '$feed'");
+/*                     if (ENABLE_UPDATE_DAEMON) {
 
-                       $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
+                               if ($cid == 0) {
 
-                       update_rss_feed($link, $feed_url, $feed);
+                                       db_query($link, "INSERT INTO ttrss_scheduled_updates
+                                               (owner_uid, feed_id, entered) VALUES
+                                               (".$_SESSION["uid"].", '$feed', NOW())");
+                               }
 
+                       } else { 
+                               // fixme update_rss_feed...
+                       } */
+
+                       $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
+                               WHERE id = '$feed'");
+                       $feed_url = db_fetch_result($tmp_result, 0, "feed_url");                                
+                       update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON);
                }
 
                if ($subop == "MarkAllRead")  {
                                Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
                        return;
                }
-       
-               if (db_num_rows($result) > 0) {
+
+               function print_headline_subtoolbar($link, $feed_site_url, $feed_title) {
 
                        print "<table class=\"headlinesSubToolbar\" 
                                width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
                        
                                print "</td>";
 
-
                        }
 
                        if ($last_error) {
                                        print "<td align='center' class='small'>
                                                <a class=\"warning\" href=\"javascript:alert('TT-RSS encountered an error while trying to update this feed.\\n\\n$last_error')\">Could not update this feed.</a></td>";
-                               }       
+                       }       
 
                        print "<td class=\"headlineTitle\">";
                
                        print "</td>";
                        print "</tr></table>";
 
+               }
+       
+               if (db_num_rows($result) > 0) {
+
+                       print_headline_subtoolbar($link, $feed_site_url, $feed_title);
+
                        if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
                                print "<table class=\"headlinesList\" id=\"headlinesList\" 
                                        cellspacing=\"0\" width=\"100%\">";
                                print "</table>";
                        }
 
+                       print_headline_subtoolbar($link, "javascript:catchupPage()", "Mark page as read");
+
+
                } else {
                        print "<div width='100%' align='center'>No articles found.</div>";
                }
 
                print "<script type=\"text/javascript\">
                        document.onkeydown = hotkey_handler;
+                       // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
                        update_all_counters('$feed');
                </script>";
        
+               print '
+                       <script type="text/javascript">
+                               /* for IE */
+                               function statechange() {
+                                       if (document.readyState == "interactive") init();
+                               }
+                       
+                               if (document.readyState) {      
+                                       if (document.readyState == "interactive" || document.readyState == "complete") {
+                                               init();
+                                       } else {
+                                               document.onreadystatechange = statechange;
+                                       }
+                               }
+                       </script>';
+
                if ($addheader) {
                        print "</body></html>";
                }
                        $auth_login = db_escape_string($_POST["login"]);
                        $auth_pass = db_escape_string($_POST["pass"]);
                        $parent_feed = db_escape_string($_POST["pfeed"]);
-                       $private = db_escape_string($_POST["private"]);
+                       $private = db_escape_string($_POST["is_pvt"]);
 
                        if (strtoupper($upd_intl) == "DEFAULT")
                                $upd_intl = 0;
                                $tmp_user_pwd = make_password(8);
                                $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
 
-                               db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
-                                       VALUES ('$login', '$pwd_hash', 0)");
+                               db_query($link, "INSERT INTO ttrss_users 
+                                       (login,pwd_hash,access_level,last_login)
+                                       VALUES ('$login', '$pwd_hash', 0, NOW())");
 
 
                                $result = db_query($link, "SELECT id FROM ttrss_users WHERE