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

Not parse nlsposts into XF

Discussion in 'XenForo Questions and Support' started by LPH, Jan 5, 2013.

  1. LPH

    LPH Well-Known Member

    Scenario
    XenScripts WP to XF bridge is installed. Within the WP post is a tag which brings in more WP headlines. When posted, a copy of the WP post is made into the XF forum. This creates a problem because XF cannot interpret the tag. Therefore, I don't want that part to be posted in the forum.

    The following is an example:
    Code:
    [nlposts tag="Debt Limit 2013"]
    What is Known
    The FAQ explains that using the plain tag around BB Code will stop it from parsing. This is not quite what is needed, so maybe there is a different solution.

    This is a portion of the XS script to put the WP post into the forum.

    Code:
    $body = '';
            if($post_contains == 'full')
            {
                $body = '[quote]' . XenForo_Helper_String::autoLinkBbCode(XenForo_Html_Renderer_BbCode::renderFromHtml(nl2br($content))) . "[/quote]";
            }
    Can this be function above be written to strip out the nlspost tag?

    Can a helper string be written to do this? (I've never done this before !). This thread seems like some help on creating the string.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Do a preg_replace() on it:

    http://us2.php.net/manual/en/function.preg-replace.php

    Code:
    $body = '';
            if($post_contains == 'full')
            {
                $body = '[quote]' . XenForo_Helper_String::autoLinkBbCode(XenForo_Html_Renderer_BbCode::renderFromHtml(nl2br($content))) . "[/quote]";
    
                $body = preg_replace('#\[nlposts tag="[^"]+"\]#', '', $body);
            }
    
     
  3. LPH

    LPH Well-Known Member

    Oh my. You are the champion. There were two places to put in that code and it works wonders if tag= is the only part of the code.

    Now I have to figure out what to do if there is blog_id= as well as time_frame= are used....

    I'm looking at your link right now to try to understand what you did and see if I can recreate it for the other options.
     
  4. LPH

    LPH Well-Known Member

    OK. What am I doing wrong here?

    Code:
    $body = preg_replace('/[nlposts .*/', '', $body);
    My understanding is that the .* is any pattern after the nlposts ...
     
  5. LPH

    LPH Well-Known Member

    Oh !!! I think I understand !!

    This seems to work. This means anything between the #, escape out the square brackets, the .* means anything after ... correct?

    Code:
    $body = preg_replace('#\[nlposts .*\]#', '', $body);
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yep looks good.
     
    LPH likes this.

Share This Page