]> git.wh0rd.org - tt-rss.git/blobdiff - include/rssfuncs.php
fix broken article processing if ALLOW_DUPLICATE_POSTS is enabled
[tt-rss.git] / include / rssfuncs.php
old mode 100644 (file)
new mode 100755 (executable)
index 7ea0bf0..cd82481
@@ -9,7 +9,11 @@
 
                foreach ($article as $k => $v) {
                        if ($k != "feed" && isset($v)) {
-                               $tmp .= sha1("$k:" . (is_array($v) ? implode(",", $v) : $v));
+                               $x = strip_tags(is_array($v) ? implode(",", $v) : $v);
+
+                               //_debug("$k:" . sha1($x) . ":" . htmlspecialchars($x), true);
+
+                               $tmp .= sha1("$k:" . sha1($x));
                        }
                }
 
                $query_limit = "";
                if($limit) $query_limit = sprintf("LIMIT %d", $limit);
 
+               // Update the least recently updated feeds first
+               $query_order = "ORDER BY last_updated";
+               if (DB_TYPE == "pgsql") $query_order .= " NULLS FIRST";
+
                $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated
                        FROM
                                ttrss_feeds, ttrss_users, ttrss_user_prefs
                                AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
                                $login_thresh_qpart $update_limit_qpart
                                $updstart_thresh_qpart
-                               ORDER BY last_updated $query_limit";
+                               $query_order $query_limit";
 
                // We search for feed needing update.
                $result = db_query($query);
 
                $feed = db_escape_string($feed);
 
-               $result = db_query("SELECT feed_url,auth_pass,auth_pass_encrypted
+               $result = db_query("SELECT feed_url,auth_pass,auth_login,auth_pass_encrypted
                                        FROM ttrss_feeds WHERE id = '$feed'");
 
                $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result,
                                        $entry_stored_hash = db_fetch_result($result, 0, "content_hash");
                                        $article_labels = get_article_labels($base_entry_id, $owner_uid);
                                        $entry_language = db_fetch_result($result, 0, "lang");
+
+                                       $existing_tags = get_article_tags($base_entry_id, $owner_uid);
+                                       $entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
+
                                } else {
                                        $base_entry_id = false;
                                        $entry_stored_hash = "";
                                                WHERE id = '$base_entry_id'");
 
                     // if we allow duplicate posts, we have to continue to
-                    // create the user entries for this feed
-                    if (!get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
-                        continue;
-                    }
+                    // create the user entries for this feed (if needed)
+                    if (get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
+
+                                               $query = "SELECT int_id FROM ttrss_user_entries WHERE
+                                                       ref_id = '$base_entry_id' AND owner_uid = '$owner_uid'
+                                                       AND (feed_id = '$feed' OR feed_id IS NULL) LIMIT 1";
+
+                                               $result = db_query($query);
+
+                                               if (db_num_rows($result) == 0) {
+                                                       _debug("allow duplicate posts is enabled and user record is not found, continuing.");
+                                               } else {
+                                                       continue;
+                                               }
+
+                                       } else {
+                                               continue;
+                                       }
                                }
 
                                _debug("hash differs, applying plugin filters:", $debug_enabled);
                                                        id = '$ref_id'");
                                        } */
 
-                                       // check for user post link to main table
-
-                                       // do we allow duplicate posts with same GUID in different feeds?
-                                       if (get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
-                                               $dupcheck_qpart = "AND (feed_id = '$feed' OR feed_id IS NULL)";
-                                       } else {
-                                               $dupcheck_qpart = "";
-                                       }
-
                                        if (find_article_filter($article_filters, "filter")) {
                                                //db_query("COMMIT"); // close transaction in progress
                                                continue;
 
                                        _debug("initial score: $score [including plugin modifier: $entry_score_modifier]", $debug_enabled);
 
+                                       // check for user post link to main table
+
+                                       // do we allow duplicate posts with same GUID in different feeds?
+                                       if (get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
+                                               $dupcheck_qpart = "AND (feed_id = '$feed' OR feed_id IS NULL)";
+                                       } else {
+                                               $dupcheck_qpart = "";
+                                       }
+
                                        $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE
                                                        ref_id = '$ref_id' AND owner_uid = '$owner_uid'
                                                        $dupcheck_qpart";
                                        _debug("RID: $entry_ref_id, IID: $entry_int_id", $debug_enabled);
 
                                        if (DB_TYPE == "pgsql") {
-                                               $tsvector_combined = db_escape_string(mb_substr($entry_title . ' ' . strip_tags($entry_content),
+                                          $tsvector_combined = db_escape_string(mb_substr($entry_title . ' ' . strip_tags(str_replace('<', ' <', $entry_content)),
                                                        0, 1000000));
 
                                                $tsvector_qpart = "tsvector_combined = to_tsvector('$feed_language', '$tsvector_combined'),";
                                                        SET score = '$score' WHERE ref_id = '$ref_id'");
 
                                        if ($mark_unread_on_update) {
+                                               _debug("article updated, marking unread as requested.", $debug_enabled);
+
                                                db_query("UPDATE ttrss_user_entries
                                                        SET last_read = null, unread = true WHERE ref_id = '$ref_id'");
                                        }
                                        array_push($matches, $action);
 
                                        // if Stop action encountered, perform no further processing
-                                       if ($action["type"] == "stop") return $matches;
+                                       if (isset($action["type"]) && $action["type"] == "stop") return $matches;
                                }
                        }
                }
 
                purge_orphans( true);
                cleanup_counters_cache($debug);
-               $rc = cleanup_tags( 14, 50000);
 
-               _debug("Cleaned $rc cached tags.");
+               //$rc = cleanup_tags( 14, 50000);
+               //_debug("Cleaned $rc cached tags.");
 
                PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", "");