1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.2 How To Re-Embed A BB Code?

Discussion in 'Troubleshooting and Problems' started by DRE, Aug 13, 2013.

  1. DRE

    DRE Well-Known Member

    I once used @Kier Post Replace addon to change my video bb codes for YouTube vid. It worked but in most cases it did not embed the video. Instead, the only thing that showed was the link to the video but not in a embedded url format. It was just plain ole text.

    I have encountered the same issue after experiencing this with Protected Content BB Codes in @cclaerhout addon. My question to him was, how come after I uninstalled the bb code, then re-installed it, it only shows the text of the bb code and did not actually embed?

    This is basically the same issue that happened with Post Replace. So my question is, how can we get posts that were changed or bb codes that were uninstalled then reinstalled, to re-embed the previous posts that had the embed code? What kind of rebuild needs to be done to the message part of xf_post table in order to recognize and embed old bb codes or media links so that it can embed them?
     
    Last edited: Aug 13, 2013
  2. Chris D

    Chris D XenForo Developer Staff Member

    If it's just now a plain text URL you're probably out of luck.

    It's the action of saving the post that detects media bb code and converts it into [ media=someservice] someId[/media].

    The only way now is to perform a find and replace using regular expressions on all posts, detecting a YouTube link or whatever, extracting its id and wrapping it in the media tag. It's a complex one.
     
  3. EQnoble

    EQnoble Well-Known Member

    Bbcodes are transformed only when creating a post or editing and saving. When you replace in posts you are basically changing it directly in the database so it doesn't run through the parser. If you edit (and change nothing) and save the post it gets parsed.


    What you need to do is 3 steps.


    Find what you have now (example links etc)

    Figure out what it would be as a parsed bbcode

    Write a regular expression to convert all the needed data from the link to the bbcode.
     
  4. DRE

    DRE Well-Known Member

    I tried running this SELECT * FROM xf_post WHERE message = "vip"

    Didn't see jack but I know it's there.

    Tried SELECT * FROM xf_post WHERE message = "anchorman"

    Didn't see jack but I know it's there.

    Tried SELECT * FROM xf_post WHERE message = "tapatalk"

    Didn't see jack but I know it's there.

    My database is screwed up beyond belief ain't it?

    All I wanted to do was 1. Make those old youtube links (which are now text) embed and
    2. Make a bb code (example) [vip] custom bb code [/vip] actually embed instead of just showing the text of [vip] etc.

    So are you saying that all that can be done with Kier's Post Replace addon but it won't work by doing queries in the database because it doesn't convert them unless you edit and save? That doesn't make any sense or else no one would use that addon unless it was only for changing words.
     
  5. EQnoble

    EQnoble Well-Known Member

    Yes you can replace anything in posts with any part of that post + or - other data

    Give an example of what you see in the editor in a post with a good example of the text you need parsed as a bbcode.
     
  6. DRE

    DRE Well-Known Member

    This is an example of a link that should be an embedded BB Code:

    Code:
    http://www.youtube.com/watch?v=88MOSP6Doak
    
    The Post Replace addon created that because before it was an embedded vb4 vid.

    This is an example of a BB Code that used to be a protected content BB Code:
    Code:
    [vip] stuff inside here [/vip]
    If I use that code now it works, but there are old posts that have that code and it's not embedded. Do I need to use the Post Replace addon to get them to work again?
     
  7. EQnoble

    EQnoble Well-Known Member

    Well there is no one way to convert it in the post replacement addon, it all depends on the expression or expressions you use.



    To replace your youtube links - In the replace as posts addon


    quick search: youtube.com

    regex: #http\:\/\/(www\.)?youtube.com\/watch\?([a-z]+\=[^\=\&\]]+\&)*v\=([^\]\&]+)(\&[a-z]+\=[^\=\&\]]+)*\][^\[]+#siu

    replace: [media=youtube]\3[/media]

    edit - ignore this for now - i need to test it better when i am awake


    That is different. It is using a custom addon for the bbcode so I can't tell you that at this point nor can I give you regex off the top of my head like the youtube conversion that would fix that problem because of that.
     
    Last edited: Aug 13, 2013
  8. DRE

    DRE Well-Known Member

    In AdminCP/Options/Messages I have the 3rd option selected under Auto-Embed Media Links
    (Auto-embed media, and add a link to the content within this BB code)
    Would using that post replace code screw up my existing links that are underneath the vid?
     
  9. Brogan

    Brogan XenForo Moderator Staff Member

    No.
    You keep claiming this but again it is a case of user error.

    It would help if you used the correct queries:
    Code:
    SELECT * FROM xf_post WHERE message LIKE "%vip%"
     
  10. EQnoble

    EQnoble Well-Known Member

    Yes that would have caught everything (including links generated by the auto embed) and being half asleep I also made an error in it...


    This should catch all youtube links that aren't part of the links in the autoembed and convert them to bbcodes.

    quick search: youtube.com

    regex: #(?<!view\:\s|\')http\:\/\/(www\.)?youtube.com\/watch\?([a-z]+\=[^\=\&\'\[\]\s]+\&)*v\=([^\]\&\[\'\s]+)(\&[a-z]+\=[^\=\&\]\[\s]+)*#siu

    replace: [media=youtube]\3[/media]
     
    Mouth likes this.
  11. Mouth

    Mouth Well-Known Member

    Terrific, thanks!
     

Share This Page