]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
force scripts refresh on every reload
[tt-rss.git] / backend.php
index 8acf268685a75d53215b45f9ec7896aaed4dbd96..bc3b388dfe1a56a74f582f32cac3bba6ec8d4648 100644 (file)
@@ -1,5 +1,6 @@
 <?
        require_once "sessions.php";
+       require_once "backend-rpc.php";
        
        header("Cache-Control: no-cache, must-revalidate");
        header("Pragma: no-cache");
@@ -82,6 +83,7 @@
                10080 => "Weekly");
 
        $script_started = getmicrotime();
+       $script_dt_add = time();
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
                                        type=\"text/css\" href=\"tt-rss_compact.css\"/>";
                }
 
-               print "<script type=\"text/javascript\" src=\"functions.js\"></script>
-                       <script type=\"text/javascript\" src=\"feedlist.js\"></script>
+               print "<script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
+                       <script type=\"text/javascript\" src=\"feedlist.js?$script_dt_add\"></script>
                        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
                        <!--[if gte IE 5.5000]>
                        <script type=\"text/javascript\" src=\"pngfix.js\"></script>
 
 
        if ($op == "rpc") {
-
-               $subop = $_GET["subop"];
-
-               if ($subop == "setpref") {
-                       if (WEB_DEMO_MODE) {
-                               return;
-                       }
-
-                       print "<rpc-reply>";
-
-                       $key = db_escape_string($_GET["key"]);
-                       $value = db_escape_string($_GET["value"]);
-
-                       set_pref($link, $key, $value);
-
-                       print "<param-set key=\"$key\" value=\"$value\"/>";
-
-                       print "</rpc-reply>";
-
-               }
-
-               if ($subop == "getLabelCounters") {
-                       $aid = $_GET["aid"];            
-                       print "<rpc-reply>";
-                       getLabelCounters($link);
-                       if ($aid) {
-                               getFeedCounter($link, $aid);
-                       }
-                       print "</rpc-reply>";
-               }
-
-               if ($subop == "getFeedCounters") {
-                       print "<rpc-reply>";
-                       getFeedCounters($link);
-                       print "</rpc-reply>";
-               }
-
-               if ($subop == "getAllCounters") {
-                       print "<rpc-reply>";
-                       getAllCounters($link);
-                       print "</rpc-reply>";
-               }
-
-               if ($subop == "mark") {
-                       $mark = $_GET["mark"];
-                       $id = db_escape_string($_GET["id"]);
-
-                       if ($mark == "1") {
-                               $mark = "true";
-                       } else {
-                               $mark = "false";
-                       }
-
-                       // FIXME this needs collision testing
-
-                       $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
-                               WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-               }
-
-               if ($subop == "updateFeed") {
-                       $feed_id = db_escape_string($_GET["feed"]);
-
-                       $result = db_query($link, 
-                               "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
-                                       AND owner_uid = " . $_SESSION["uid"]);
-
-                       if (db_num_rows($result) > 0) {                 
-                               $feed_url = db_fetch_result($result, 0, "feed_url");
-                               update_rss_feed($link, $feed_url, $feed_id);
-                       }
-
-                       print "<rpc-reply>";
-                       getFeedCounter($link, $feed_id);
-                       print "</rpc-reply>";
-                       
-                       return;
-               }
-
-               if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
-       
-                       if (ENABLE_UPDATE_DAEMON) {
-
-                               if ($subop == "forceUpdateAllFeeds") {                          
-
-                                       $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 ($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, $global_unread);
-
-                       print "</rpc-reply>";
-
-               }
-       
-               /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
-               if ($subop == "catchupSelected") {
-
-                       $ids = split(",", db_escape_string($_GET["ids"]));
-
-                       $cmode = sprintf("%d", $_GET["cmode"]);
-
-                       foreach ($ids as $id) {
-
-                               if ($cmode == 0) {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       unread = false,last_read = NOW()
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               } else if ($cmode == 1) {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       unread = true
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               } else {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       unread = NOT unread,last_read = NOW()
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               }
-                       }
-                       print "<rpc-reply>";
-                       getAllCounters($link);
-                       print "</rpc-reply>";
-               }
-
-               if ($subop == "markSelected") {
-
-                       $ids = split(",", db_escape_string($_GET["ids"]));
-
-                       $cmode = sprintf("%d", $_GET["cmode"]);
-
-                       foreach ($ids as $id) {
-
-                               if ($cmode == 0) {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       marked = false
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               } else if ($cmode == 1) {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       marked = true
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               } else {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       marked = NOT marked
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               }
-                       }
-                       print "<rpc-reply>";
-                       getAllCounters($link);
-                       print "</rpc-reply>";
-               }
-
-               if ($subop == "sanityCheck") {
-                       if (sanity_check($link)) {
-                               print "<error error-code=\"0\"/>";
-                       }
-               }
-
-               if ($subop == "globalPurge") {
-
-                       print "<rpc-reply>";
-                       global_purge_old_posts($link, true);
-                       print "</rpc-reply>";
-
-               }
-
+               handle_rpc_request($link);
        }
        
        if ($op == "feeds") {
                                        type=\"text/css\" href=\"tt-rss_compact.css\"/>";
                }
 
-               print "<script type=\"text/javascript\" src=\"functions.js\"></script>
+               print "<script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
                        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
                        </head><body $rtl_tag>";
 
                }
 
                print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">  
-                       <script type=\"text/javascript\" src=\"functions.js\"></script>
-                       <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
+                       <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
+                       <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
                        <!--[if gte IE 5.5000]>
                        <script type=\"text/javascript\" src=\"pngfix.js\"></script>
                        <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
                        if (!get_pref($link, 'ENABLE_FEED_CATS')) {
                                print "<tr class=\"title\">
                                        <td width='5%' align='center'>&nbsp;</td>
-                                       <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
-                                       <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
-                                       <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
-                                       <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
+                                       <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
+                                       <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
+                                       <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
                        }
                        
                        $lnum = 0;
                                $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
                                $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
                                $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
-       
-//                             if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
-//                             if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
-//                             if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
-//                             if ($line["purge_interval"] < 0)        $line["purge_interval"] = "Disabled";
 
                                if (!$edit_cat) $edit_cat = "Uncategorized";
 
+                               $last_updated = $line["last_updated"];
+
+                               if (get_pref($link, 'HEADLINES_SMART_DATE')) {
+                                       $last_updated = smart_date_time(strtotime($last_updated));
+                               } else {
+                                       $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
+                                       $last_updated = date($short_date, strtotime($last_updated));
+                               }
+
                                if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
                                        $lnum = 0;
                                
 
                                        print "<tr class=\"title\">
                                                <td width='5%' align='center'>&nbsp;</td>
-                                               <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
-                                               <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
-                                               <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
-                                               <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
+                                               <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
+                                               <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
+                                               <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
 
                                        $cur_cat_id = $cat_id;
                                }
                                                $edit_cat . "</a></td>";                
                                } */
 
-                               print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
+/*                             print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
                                        $update_intervals[$line["update_interval"]] . "</a></td>";
 
                                print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
-                                       $purge_intervals[$line["purge_interval"]] . "</a></td>";
-       
+                                       $purge_intervals[$line["purge_interval"]] . "</a></td>"; */
+
+                               print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" . 
+                                       "$last_updated</a></td>";
+
                                print "</tr>";
        
                                ++$lnum;
                                        onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
 
                                }
-
-                               if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
-                                       print "
-                                       <input type=\"submit\" class=\"button\" 
-                                               onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
-                                       <input type=\"submit\" class=\"button\" 
-                                               onclick=\"javascript:readSelectedFeeds(false)\" 
-                                               value=\"Mark as unread\">&nbsp;";
-                               }
                                
                                print "
                                        &nbsp;All feeds: <input type=\"submit\" 
                if ($subop == "editSave") {
 
                        $regexp = db_escape_string($_GET["r"]);
-                       $descr = db_escape_string($_GET["d"]);
                        $match = db_escape_string($_GET["m"]);
                        $filter_id = db_escape_string($_GET["id"]);
                        $feed_id = db_escape_string($_GET["fid"]);
                        
                        $result = db_query($link, "UPDATE ttrss_filters SET 
                                reg_exp = '$regexp', 
-                               description = '$descr',
                                feed_id = $feed_id,
                                action_id = '$action_id',
                                filter_type = (SELECT id FROM ttrss_filter_types WHERE
 
                $result = db_query($link, "SELECT 
                                ttrss_filters.id AS id,reg_exp,
-                               ttrss_filters.description AS description,
                                ttrss_filter_types.name AS filter_type_name,
                                ttrss_filter_types.description AS filter_type_descr,
                                feed_id,
                                                <td width=\"20%\">Filter expression</td>
                                                <td width=\"20%\">Feed</td>
                                                <td width=\"15%\">Match</td>
-                                               <td width=\"15%\">Action</td>
-                                               <td width=\"30%\">Description</td></tr>";
-               
+                                               <td width=\"15%\">Action</td>";
+
                        $lnum = 0;
                        
                        while ($line = db_fetch_assoc($result)) {
                                print "<tr class=\"$class\" $this_row_id>";
        
                                $line["regexp"] = htmlspecialchars($line["reg_exp"]);
-                               $line["description"] = htmlspecialchars($line["description"]);
        
                                if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
        
                                if (!$edit_filter_id || $subop != "edit") {
        
-                                       if (!$line["description"]) $line["description"] = "[No description]";
-       
                                        print "<td align='center'><input onclick='toggleSelectRow(this);' 
                                        type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
        
                
                                        print "<td><a href=\"javascript:editFilter($filter_id);\">" . 
                                                $line["action_description"] . "</td>";                  
-
-                                       print "<td><a href=\"javascript:editFilter($filter_id);\">" . 
-                                               $line["description"] . "</td>";                 
        
                                } else if ($filter_id != $edit_filter_id) {
        
                                        print "<td>".$line["feed_title"]."</td>";
                                        print "<td>".$line["filter_type_descr"]."</td>";
                                        print "<td>".$line["action_description"]."</td>";               
-                                       print "<td>".$line["description"]."</td>";              
 
                                } else {
        
        
                                        print "</select></td>";
 
-
-                                       print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
-                                               "\"></td>";
-       
                                        print "</td>";
                                }
                                
                        print "<html><head>
                                <title>Tiny Tiny RSS : Help</title>
                                <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
-                               <script type=\"text/javascript\" src=\"functions.js\"></script>
+                               <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
                                <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
                                </head><body>";
                }
                        return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
                }
 
+               if (DATABASE_BACKED_SESSIONS && SINGLE_USER_MODE) {
+                       return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
+               }
+
                return false;
        }