]> git.wh0rd.org - tt-rss.git/blobdiff - classes/rpc.php
fix multiple issues with archived feeds
[tt-rss.git] / classes / rpc.php
old mode 100644 (file)
new mode 100755 (executable)
index 750aa2c..235db59
@@ -95,7 +95,7 @@ class RPC extends Handler_Protected {
                                                        WHERE orig_feed_id = '$id') = 0 AND
                id = '$id' AND owner_uid = ".$_SESSION["uid"]);
 
-                       $rc = $this->dbh->affected_rows($result);
+                       $this->dbh->affected_rows($result);
                }
        }
 
@@ -123,7 +123,7 @@ class RPC extends Handler_Protected {
                $key = $_REQUEST['key'];
                $value = str_replace("\n", "<br/>", $_REQUEST['value']);
 
-               set_pref($key, $value, $_SESSION['uid'], $key != 'USER_STYLESHEET');
+               set_pref($key, $value, false, $key != 'USER_STYLESHEET');
 
                print json_encode(array("param" =>$key, "value" => $value));
        }
@@ -138,7 +138,7 @@ class RPC extends Handler_Protected {
                        $mark = "false";
                }
 
-               $result = $this->dbh->query("UPDATE ttrss_user_entries SET marked = $mark,
+               $this->dbh->query("UPDATE ttrss_user_entries SET marked = $mark,
                                        last_marked = NOW()
                                        WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
@@ -148,8 +148,8 @@ class RPC extends Handler_Protected {
        function delete() {
                $ids = $this->dbh->escape_string($_REQUEST["ids"]);
 
-               $result = $this->dbh->query("DELETE FROM ttrss_user_entries
-               WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
+               $this->dbh->query("DELETE FROM ttrss_user_entries
+                       WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
 
                purge_orphans();
 
@@ -165,7 +165,7 @@ class RPC extends Handler_Protected {
 
                        $result = $this->dbh->query("SELECT feed_url,site_url,title FROM ttrss_archived_feeds
                                WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = $id
-                               AND owner_uid = ".$_SESSION["uid"].")");
+                               AND owner_uid = ".$_SESSION["uid"].") AND owner_uid = " . $_SESSION["uid"]);
 
                        if ($this->dbh->num_rows($result) != 0) {
                                $feed_url = $this->dbh->escape_string(db_fetch_result($result, 0, "feed_url"));
@@ -237,17 +237,22 @@ class RPC extends Handler_Protected {
 
                        if ($feed_id) {
                                $result = $this->dbh->query("SELECT id FROM ttrss_archived_feeds
-                                       WHERE id = '$feed_id'");
+                                       WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
 
                                if ($this->dbh->num_rows($result) == 0) {
+                                       $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds");
+                                       $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1;
+
                                        $this->dbh->query("INSERT INTO ttrss_archived_feeds
                                                (id, owner_uid, title, feed_url, site_url)
-                                       SELECT id, owner_uid, title, feed_url, site_url from ttrss_feeds
+                                       SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds
                                        WHERE id = '$feed_id'");
+                               } else {
+                                       $new_feed_id = $this->dbh->fetch_result($result, 0, "id");
                                }
 
                                $this->dbh->query("UPDATE ttrss_user_entries
-                                       SET orig_feed_id = feed_id, feed_id = NULL
+                                       SET orig_feed_id = $new_feed_id, feed_id = NULL
                                        WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
                        }
                }
@@ -258,7 +263,6 @@ class RPC extends Handler_Protected {
        function publ() {
                $pub = $_REQUEST["pub"];
                $id = $this->dbh->escape_string($_REQUEST["id"]);
-               $note = trim(strip_tags($this->dbh->escape_string($_REQUEST["note"])));
 
                if ($pub == "1") {
                        $pub = "true";
@@ -266,7 +270,7 @@ class RPC extends Handler_Protected {
                        $pub = "false";
                }
 
-               $result = $this->dbh->query("UPDATE ttrss_user_entries SET
+               $this->dbh->query("UPDATE ttrss_user_entries SET
                        published = $pub, last_published = NOW()
                        WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
@@ -291,7 +295,7 @@ class RPC extends Handler_Protected {
 
                $reply = array();
 
-               if ($seq) $reply['seq'] = $seq;
+               if (!empty($_REQUEST['seq'])) $reply['seq'] = (int) $_REQUEST['seq'];
 
                if ($last_article_id != getLastArticleId()) {
                        $reply['counters'] = getAllCounters();
@@ -334,6 +338,7 @@ class RPC extends Handler_Protected {
                $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
                $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true";
                $_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true";
+               $_SESSION["clientTzOffset"] = $_REQUEST["clientTzOffset"];
 
                $reply = array();
 
@@ -379,6 +384,8 @@ class RPC extends Handler_Protected {
        }
 
        function updateFeedBrowser() {
+               if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
+
                $search = $this->dbh->escape_string($_REQUEST["search"]);
                $limit = $this->dbh->escape_string($_REQUEST["limit"]);
                $mode = (int) $this->dbh->escape_string($_REQUEST["mode"]);
@@ -463,27 +470,20 @@ class RPC extends Handler_Protected {
                        $id = 0;
                }
 
-               print_feed_cat_select("cat_id", $id);
-       }
-
-       // Silent
-       function clearArticleKeys() {
-               $this->dbh->query("UPDATE ttrss_user_entries SET uuid = '' WHERE
-                       owner_uid = " . $_SESSION["uid"]);
-
-               return;
+               print_feed_cat_select("cat_id", $id, '');
        }
 
        function setpanelmode() {
                $wide = (int) $_REQUEST["wide"];
 
                setcookie("ttrss_widescreen", $wide,
-                       time() + SESSION_COOKIE_LIFETIME);
+                       time() + COOKIE_LIFETIME_LONG);
 
                print json_encode(array("wide" => $wide));
        }
 
-       function updaterandomfeed() {
+       static function updaterandomfeed_real($dbh) {
+
                // Test if the feed need a update (update interval exceded).
                if (DB_TYPE == "pgsql") {
                        $update_limit_qpart = "AND ((
@@ -514,16 +514,24 @@ class RPC extends Handler_Protected {
 
                $random_qpart = sql_random_function();
 
+               // we could be invoked from public.php with no active session
+               if ($_SESSION["uid"]) {
+                       $owner_check_qpart = "AND ttrss_feeds.owner_uid = '".$_SESSION["uid"]."'";
+               } else {
+                       $owner_check_qpart = "";
+               }
+
                // We search for feed needing update.
-               $result = $this->dbh->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id
+               $result = $dbh->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id
                        FROM
                                ttrss_feeds, ttrss_users, ttrss_user_prefs
                        WHERE
                                ttrss_feeds.owner_uid = ttrss_users.id
                                AND ttrss_users.id = ttrss_user_prefs.owner_uid
                                AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
-                               AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
-                               $update_limit_qpart $updstart_thresh_qpart
+                               $owner_check_qpart
+                               $update_limit_qpart
+                               $updstart_thresh_qpart
                        ORDER BY $random_qpart LIMIT 30");
 
                $feed_id = -1;
@@ -534,7 +542,7 @@ class RPC extends Handler_Protected {
 
                $tstart = time();
 
-               while ($line = $this->dbh->fetch_assoc($result)) {
+               while ($line = $dbh->fetch_assoc($result)) {
                        $feed_id = $line["id"];
 
                        if (time() - $tstart < ini_get("max_execution_time") * 0.7) {
@@ -547,7 +555,7 @@ class RPC extends Handler_Protected {
 
                // Purge orphans and cleanup tags
                purge_orphans();
-               cleanup_tags(14, 50000);
+               //cleanup_tags(14, 50000);
 
                if ($num_updated > 0) {
                        print json_encode(array("message" => "UPDATE_COUNTERS",
@@ -558,6 +566,10 @@ class RPC extends Handler_Protected {
 
        }
 
+       function updaterandomfeed() {
+               RPC::updaterandomfeed_real($this->dbh);
+       }
+
        private function markArticlesById($ids, $cmode) {
 
                $tmp_ids = array();
@@ -614,7 +626,7 @@ class RPC extends Handler_Protected {
 
                        $p = new Publisher(PUBSUBHUBBUB_HUB);
 
-                       $pubsub_result = $p->publish_update($rss_link);
+                       /* $pubsub_result = */ $p->publish_update($rss_link);
                }
        }