]> git.wh0rd.org - tt-rss.git/blobdiff - classes/rssutils.php
fix previous to not crash if document first child is not a DOMElement or whatever
[tt-rss.git] / classes / rssutils.php
index d125a5032f4c4a5713de200a8da1903ccad29167..af5fd057ce33278a0d1988a88a5dd0f9a116f93e 100755 (executable)
@@ -637,8 +637,11 @@ class RSSUtils {
 
                                $entry_link = rewrite_relative_url($site_url, $item->get_link());
 
+                               $entry_language = mb_substr(trim($item->get_language()), 0, 2);
+
                                _debug("title $entry_title", $debug_enabled);
                                _debug("link $entry_link", $debug_enabled);
+                               _debug("language $entry_language", $debug_enabled);
 
                                if (!$entry_title) $entry_title = date("Y-m-d H:i:s", $entry_timestamp);;
 
@@ -694,7 +697,6 @@ class RSSUtils {
                                        $base_entry_id = $row["id"];
                                        $entry_stored_hash = $row["content_hash"];
                                        $article_labels = Article::get_article_labels($base_entry_id, $owner_uid);
-                                       $entry_language = $row["lang"];
 
                                        $existing_tags = Article::get_article_tags($base_entry_id, $owner_uid);
                                        $entry_tags = array_unique(array_merge($entry_tags, $existing_tags));
@@ -702,7 +704,6 @@ class RSSUtils {
                                        $base_entry_id = false;
                                        $entry_stored_hash = "";
                                        $article_labels = array();
-                                       $entry_language = "";
                                }
 
                                $article = array("owner_uid" => $owner_uid, // read only
@@ -767,7 +768,7 @@ class RSSUtils {
                                _debug("plugin data: $entry_plugin_data", $debug_enabled);
 
                                // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077
-                               if (DB_TYPE == "mysql") {
+                               if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") {
                                        foreach ($article as $k => $v) {
                                                // i guess we'll have to take the risk of 4byte unicode labels & tags here
                                                if (is_string($article[$k])) {
@@ -978,18 +979,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,
@@ -997,13 +990,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,
@@ -1011,7 +1005,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, 900000);
+                                       }
+
+                                       $sth->execute($params);
 
                                        // update aux data
                                        $sth = $pdo->prepare("UPDATE ttrss_user_entries
@@ -1053,7 +1054,7 @@ class RSSUtils {
                                                        $e->type, $e->length, $e->title, $e->width, $e->height);
 
                                                // Yet another episode of "mysql utf8_general_ci is gimped"
-                                               if (DB_TYPE == "mysql") {
+                                               if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") {
                                                        for ($i = 0; $i < count($e_item); $i++) {
                                                                if (is_string($e_item[$i])) {
                                                                        $e_item[$i] = RSSUtils::strip_utf8mb4($e_item[$i]);