Fixed Clicking on [QUOTE] header "Bob said" of an ignored user scrolls to top of page

Steffen

Well-known member
If you see a post that quotes a user you ignore then clicking the quote's header "Bob said" makes the browser scroll to the top of the page. I think that's odd but I'm not sure what should happen instead. Maybe don't turn "Bob said" into a link in such a case?
 
It turns out that this issue only exists for incomplete / imported QUOTE BB codes.

New quotes look like this:
[QUOTE="Bob, post: 12345, member: 42"]I like Alice.[/QUOTE]

Quotes imported from vBulletin 4 look like this (they lack a member id):
[QUOTE="Bob, post: 12345"]I like Alice.[/QUOTE]

So this happens "only" for imported posts but if the fix isn't too complicated maybe it's worth implementing?

Alternatively (or in addition), we could try to fix the importer such that it adds the member id (lookup via the post id).
 
The only way to do this reliably is by looking up the post ID to see if it has a user ID and using that.

My only hesitation is that it's an additional query for each quote. There's a slight optimisation if we use the entity manager find method which will save repeat queries for quotes of the same post but it could still be a significant amount of work.

It feels beneficial though, so we'll go with it.

Thanks!

Diff:
Index: src/addons/XFI/Import/Importer/vBulletin.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/addons/XFI/Import/Importer/vBulletin.php    (date 1535417219000)
+++ src/addons/XFI/Import/Importer/vBulletin.php    (date 1535417836000)
@@ -3306,10 +3306,24 @@
         $quoteEqualsPatterns = [
             '/\[QUOTE=((?P<quoted>\'|")?)(?P<username>(?(quoted)[^;\n]+|[^\][;\n]+))(;\s*(?P<postid>\d+))\1\]/siU' => function ($match)
             {
-                return sprintf('[QUOTE="%s, post: %d"]',
-                    $match['username'],
-                    $this->lookupId('post', $match['postid'])
-                );
+                $newPostId = $this->lookupId('post', $match['postid']);
+                $post = $this->em()->find('XF:Post', $newPostId);
+
+                if ($post && $post->user_id)
+                {
+                    return sprintf('[QUOTE="%s, post: %d, member: %d"]',
+                        $match['username'],
+                        $newPostId,
+                        $post->user_id
+                    );
+                }
+                else
+                {
+                    return sprintf('[QUOTE="%s, post: %d"]',
+                        $match['username'],
+                        $newPostId
+                    );
+                }
             }
         ];
 
Back
Top Bottom