]> git.wh0rd.org - tt-rss.git/blobdiff - classes/rssutils.php
strip utf8mb4 characters in enclosures on mysql
[tt-rss.git] / classes / rssutils.php
old mode 100644 (file)
new mode 100755 (executable)
index c9e6bc0..52ac680
@@ -16,6 +16,11 @@ class RSSUtils {
                return sha1(implode(",", $pluginhost->get_plugin_names()) . $tmp);
        }
 
+       // 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);
+    }
+
        static function update_feedbrowser_cache() {
 
                $pdo = Db::pdo();
@@ -304,7 +309,7 @@ class RSSUtils {
         */
        static function update_rss_feed($feed, $no_cache = false) {
 
-               $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
+               $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || clean($_REQUEST['xdebug']);
 
                _debug_suppress(!$debug_enabled);
                _debug("start", $debug_enabled);
@@ -492,8 +497,6 @@ class RSSUtils {
                $rss = new FeedParser($feed_data);
                $rss->init();
 
-               $feed = $feed;
-
                if (!$rss->error()) {
 
                        // We use local pluginhost here because we need to load different per-user feed plugins
@@ -593,7 +596,7 @@ class RSSUtils {
                        foreach ($items as $item) {
                                $pdo->beginTransaction();
 
-                               if ($_REQUEST['xdebug'] == 3) {
+                               if (clean($_REQUEST['xdebug']) == 3) {
                                        print_r($item);
                                }
 
@@ -642,7 +645,7 @@ class RSSUtils {
                                $entry_content = $item->get_content();
                                if (!$entry_content) $entry_content = $item->get_description();
 
-                               if ($_REQUEST["xdebug"] == 2) {
+                               if (clean($_REQUEST["xdebug"]) == 2) {
                                        print "content: ";
                                        print htmlspecialchars($entry_content);
                                        print "\n";
@@ -751,7 +754,7 @@ class RSSUtils {
                                        $entry_plugin_data .= mb_strtolower(get_class($plugin)) . ",";
                                }
 
-                               if ($_REQUEST["xdebug"] == 2) {
+                               if (clean($_REQUEST["xdebug"]) == 2) {
                                        print "processed content: ";
                                        print htmlspecialchars($article["content"]);
                                        print "\n";
@@ -762,10 +765,9 @@ class RSSUtils {
                                // 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") {
                                        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])) {
-                                                       $article[$k] = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $v);
+                                                       $article[$k] = RSSUtils::strip_utf8mb4($v);
                                                }
                                        }
                                }
@@ -932,7 +934,7 @@ class RSSUtils {
                                                        $last_read_qpart = null;
                                                } else {
                                                        $unread = 0;
-                                                       $last_read_qpart = 'NOW()';
+                                                       $last_read_qpart = date("Y-m-d H:i"); // we can't use NOW() here because it gets quoted
                                                }
 
                                                if (RSSUtils::find_article_filter($article_filters, 'mark') || $score > 1000) {
@@ -947,18 +949,18 @@ class RSSUtils {
                                                        $published = 0;
                                                }
 
-                                               $last_marked = ($marked == 'true') ? 'NOW()' : null;
-                                               $last_published = ($published == 'true') ? 'NOW()' : null;
+                                               $last_marked = ($marked == 1) ? 'NOW()' : 'NULL';
+                                               $last_published = ($published == 1) ? 'NOW()' : 'NULL';
 
                                                $sth = $pdo->prepare(
                                                        "INSERT INTO ttrss_user_entries
                                                                (ref_id, owner_uid, feed_id, unread, last_read, marked,
                                                                published, score, tag_cache, label_cache, uuid,
                                                                last_marked, last_published)
-                                                       VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', '', '', ?, ?)");
+                                                       VALUES (?, ?, ?, ?, ?, ?, ?, ?, '', '', '', ".$last_marked.", ".$last_published.")");
 
                                                $sth->execute([$ref_id, $owner_uid, $feed, $unread, $last_read_qpart, $marked,
-                                                       $published, $score, $last_marked, $last_published]);
+                                                       $published, $score]);
 
                                                $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
                                                                ref_id = ? AND owner_uid = ? AND
@@ -1045,7 +1047,17 @@ class RSSUtils {
                                                $e_item = array(
                                                        rewrite_relative_url($site_url, $e->link),
                                                        $e->type, $e->length, $e->title, $e->width, $e->height);
-                                               array_push($enclosures, $e_item);
+
+                                               // 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]);
+                                }
+                            }
+                                               }
+
+                        array_push($enclosures, $e_item);
                                        }
                                }