XF 2.0 Is there a way to parse a string as a URL using the XenForo router?

Jaxel

Well-known member
I have a string. This string could contain a URL.

Is there an easy way to run this through the route matcher; determine if it's a local URL, and if it is, extract the parameterbag?
 
You'd have to determine if it's a local URL first (check against boardUrl maybe?) and strip it to just the path, but then you can do:
PHP:
$routeMatch = \XF::router()->routeToController($path);
$params = $routeMatch->getParameterBag();
 
Hmm... this code is not returning the proper parameters:

Code:
        $url = $this->filter('url', 'str');
        $url = substr($url, 0, 4) == 'http' ? $url : 'https://'.$url;
        
        $formatter = \XF::app()->stringFormatter();
        $linkInfo = $formatter->getLinkClassTarget($url);
        
        if ($linkInfo['local'])
        {
            $linkParse = parse_url($url);
            
            $routeMatch = $this->router()->routeToController($linkParse['path']);
            $params = $routeMatch->getParameterBag();
            
            \XF::dump($params);
        }
 
I believe you will need to strip the leading / from the path, otherwise it doesn't get matched correctly.
 
Top Bottom