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

URL Tag Parser/Formatter?

Discussion in 'XenForo Development Discussions' started by Mr. Goodie2Shoes, Aug 17, 2012.

  1. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Hello, I am just checking out some stuff and found that if I manipulate [url]http://something.com[/url] I can change the output, like changing it to a short URL, but this doesn't work on: [url=http://something.com]Hello![/url]
    :(
    Am I missing something?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    I assume you're extending XenForo_BbCode_Formatter_Base::renderTagUrl?

    In the latter format that isn't working, the URL is defined as $tag['option'] relevant code highlighted in red:

    Code:
    public function renderTagUrl(array $tag, array $rendererStates)
    {
    
    if (!empty($tag['option']))​
    {​
    $url = $tag['option'];
    $text = $this->renderSubTree($tag['children'], $rendererStates);​
    echo $url;​
    }​
    else​
    {​
    $url = $this->stringifyTree($tag['children']);​
    $text = urldecode($url);​
    if (!utf8_check($text))​
    {​
    $text = $url;​
    }​
    $text = XenForo_Helper_String::censorString($text);​
    if (!empty($rendererStates['shortenUrl']))​
    {​
    $length = utf8_strlen($text);​
    if ($length > 100)​
    {​
    $text = utf8_substr_replace($text, '...', 35, $length - 35 - 45);​
    }​
    }​
    $text = htmlspecialchars($text);​
    }​
    I'm guessing you've only applied your changes to the else statement where the URL is defined as $tag['children'].
     
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    I actually extended the XenForo_BbCode_Formatter_BbCode_AutoLink class
     
  4. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    and also, it needs to be rendered when the user posts the link... not when someone views it...
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    Ah I see...

    Hmm...
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    Is extending AutoLink going to work?

    As far as I can tell, autolinking only occurs when a user posts a link. It won't occur when people wrap a link in URL tags. Also would autolink ever be able to generate links in this format [url=http://www.google.co.uk]www.google.co.uk[/url]?

    I see XenForo_Helper_String::prepareAutoLinkedUrl($url) looks like there should be a way for it to render a URL as an option with link text as the tag child but I can't seem to get it to work like that.

    But yeah, it seems like the Autolink class would only apply to a small fraction of URLs posted on the board.
     
  7. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    yes, it works, except for the already wrapped URLs...

    Yes it can! :D

    yep, the same thing happens...
     

Share This Page