]> git.wh0rd.org - tt-rss.git/blobdiff - classes/rssutils.php
Call the subscription hook from the plugins even if fetch_file_contents returned...
[tt-rss.git] / classes / rssutils.php
index 52ac68062e16c6c1c145da8a8521e252eac9553f..dd6d1dd31379818f6364161f0be61df66cb862da 100755 (executable)
@@ -18,8 +18,8 @@ class RSSUtils {
 
        // Strips utf8mb4 characters (i.e. emoji) for mysql
        static function strip_utf8mb4($str) {
-        return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str);
-    }
+               return preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $str);
+       }
 
        static function update_feedbrowser_cache() {
 
@@ -422,15 +422,15 @@ class RSSUtils {
                                _debug("not using CURL due to open_basedir restrictions");
                        }
 
-            if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) {
-                _debug("maximum allowed interval for conditional requests exceeded, forcing refetch");
+                       if (time() - strtotime($last_unconditional) > MAX_CONDITIONAL_INTERVAL) {
+                               _debug("maximum allowed interval for conditional requests exceeded, forcing refetch");
 
-                $force_refetch = true;
-            } else {
-                _debug("stored last modified for conditional request: $stored_last_modified", $debug_enabled);
-            }
+                               $force_refetch = true;
+                       } else {
+                               _debug("stored last modified for conditional request: $stored_last_modified", $debug_enabled);
+                       }
 
-            _debug("fetching [$fetch_url] (force_refetch: $force_refetch)...", $debug_enabled);
+                       _debug("fetching [$fetch_url] (force_refetch: $force_refetch)...", $debug_enabled);
 
                        $feed_data = fetch_file_contents([
                                "url" => $fetch_url,
@@ -572,8 +572,8 @@ class RSSUtils {
                        $filters = load_filters($feed, $owner_uid);
 
                        if ($debug_enabled) {
-                           print_r($filters);
-            }
+                               print_r($filters);
+                       }
 
                        _debug("" . count($filters) . " filters loaded.", $debug_enabled);
 
@@ -675,9 +675,13 @@ class RSSUtils {
 
                                $entry_tags = array_unique($additional_tags);
 
-                               for ($i = 0; $i < count($entry_tags); $i++)
+                               for ($i = 0; $i < count($entry_tags); $i++) {
                                        $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
 
+                                       // we don't support numeric tags, let's prefix them
+                                       if (is_numeric($entry_tags[$i])) $entry_tags[$i] = 't:' . $entry_tags[$i];
+                               }
+
                                _debug("tags found: " . join(",", $entry_tags), $debug_enabled);
 
                                _debug("done collecting data.", $debug_enabled);
@@ -974,18 +978,10 @@ class RSSUtils {
 
                                        _debug("resulting RID: $entry_ref_id, IID: $entry_int_id", $debug_enabled);
 
-                                       if (DB_TYPE == "pgsql") {
-                                               $tsvector_combined = mb_substr($entry_title . ' ' .
-                                                       preg_replace('/[<\?\:]/', ' ', strip_tags($entry_content)),
-                                                       0, 1000000);
-
-                                               $tsvector_qpart = "tsvector_combined = to_tsvector(".$pdo->quote($feed_language).", ".$pdo->quote($tsvector_combined)."),";
-
-                                       } else {
+                                       if (DB_TYPE == "pgsql")
+                                               $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),";
+                                       else
                                                $tsvector_qpart = "";
-                                       }
-
-                                       //_debug($tsvector_qpart);
 
                                        $sth = $pdo->prepare("UPDATE ttrss_entries
                                                SET title = :title,
@@ -993,13 +989,14 @@ class RSSUtils {
                                                        content = :content,
                                                        content_hash = :content_hash,
                                                        updated = :updated,
+                                                       date_updated = NOW(),
                                                        num_comments = :num_comments,
                                                        plugin_data = :plugin_data,
                                                        author = :author,
                                                        lang = :lang                                                                                                            
                                                WHERE id = :id");
 
-                                       $sth->execute([":title" => $entry_title,
+                                       $params = [":title" => $entry_title,
                                                ":content" => "$entry_content",
                                                ":content_hash" => $entry_current_hash,
                                                ":updated" => $entry_timestamp_fmt,
@@ -1007,7 +1004,14 @@ class RSSUtils {
                                                ":plugin_data" => $entry_plugin_data,
                                                ":author" => "$entry_author",
                                                ":lang" => $entry_language,
-                                               ":id" => $ref_id]);
+                                               ":id" => $ref_id];
+
+                                       if (DB_TYPE == "pgsql") {
+                                               $params[":ts_lang"] = $feed_language;
+                                               $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 1000000);
+                                       }
+
+                                       $sth->execute($params);
 
                                        // update aux data
                                        $sth = $pdo->prepare("UPDATE ttrss_user_entries
@@ -1050,14 +1054,14 @@ class RSSUtils {
 
                                                // Yet another episode of "mysql utf8_general_ci is gimped"
                                                if (DB_TYPE == "mysql") {
-                            for ($i = 0; $i < count($e_item); $i++) {
-                                if (is_string($e_item[$i])) {
-                                    $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]);
-                                }
-                            }
+                                                       for ($i = 0; $i < count($e_item); $i++) {
+                                                               if (is_string($e_item[$i])) {
+                                                                       $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]);
+                                                               }
+                                                       }
                                                }
 
-                        array_push($enclosures, $e_item);
+                                               array_push($enclosures, $e_item);
                                        }
                                }