HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Fixing the regex for author to work as converted from SMF

This discussion is related to the Quotes addon.

Hi,

I've installed Vanilla 2.1 and converted from SMF 2.x

Installing the Quotes 1.6.1, I could not get it to show the author of a quote. The format of the quote from SMF is as an example:

[quote author=Ilson Estrela link=topic=91728.msg1495076#msg1495076 date=1400972146]

The original regex for items with author in RenderQuotes is:

$Sender->EventArguments['Object']->Body = preg_replace_callback("#(\[quote(\s+author)?=[\"']?(.*?)(\s+link.*?)?(;[\d]+)?[\"']?\])#usi", array($this, 'QuoteAuthorCallback'), $Sender->EventArguments['Object']->Body);

This was not working properly for me, it always would display "author says" rather than the actual author's ID name. I changed the regex as follows:

$Sender->EventArguments['Object']->Body = preg_replace_callback("#(\[quote author=[\"']?(.*?)(\s+link.*?)?(;[\d]+)?[\"']?\])#usi", array($this, 'QuoteAuthorCallback'), $Sender->EventArguments['Object']->Body);

This seems to be working for me, it now properly shows the author ID name and has the appropriate link to the author's profile.

I was wondering if this particular regex is meant to cover ones with author, why is the regex formatted "(\s+author)?"

Thanks
Ricardo

hgtonight

Comments

  • hgtonighthgtonight ∞ · New Moderator

    Glad you got it figured out!

    Regex are tricky, check out https://www.debuggex.com/ for a visual representation of what is happening.

    The difference is your regex requires an author attribution where the original does not.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • x00x00 MVP
    edited June 2014

    BBCode is not a standard, therefore it is anyone's guess how it is formatted.

    Actually how SMF does is it questionable becuase the author name Ilson Estrela is not encapsulated in something like quotes, and why assume that that the attribute link comes immediately after author, and not before or with some other attributes.

    grep is your friend.

    UnderDogperegrine
  • R_JR_J Ex-Fanboy Munich Admin

    Please excuse me being offtopic but apropos regex - try Regex Golf! B)


    hgtonightperegrine
  • hgtonighthgtonight ∞ · New Moderator

    @R_J said:
    Please excuse me being offtopic but apropos regex - try Regex Golf! B)

    That definitely wasted about 2 hours of prime working time. :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    peregrineR_J
  • edited June 2014

    @hgtonight said:
    Glad you got it figured out!

    Regex are tricky, check out https://www.debuggex.com/ for a visual representation of what is happening.

    The difference is your regex requires an author attribution where the original does not.

    Thanks for the debuggex link, it's certainly useful.

    So, I'm wondering, does the quotes plugin also qet utilized for personal messages in the inbox?

    The reason I ask is because at least according to debuggex, I have a matching quote expression, however in the inbox it will always display the bbcode text rather than rendering the blockquotes.

    So for example I have a bbcode like this:

    quote author=Dennis07 link=action=profile;u=828 date=1397484548

    (I removed the start/end brackets [] because it was messing up the display)

    which appears as text when reading the inbox messages.

  • Here's an example of what's shown on the inbox message

Sign In or Register to comment.