XF 2.2 Add more Protocols to [URL]-Tag

Sp4x

Member
Hi Guys.

I want to add more protocols to the URL-BB Code Tag. I look in src/XF/BbCode/Renderer/Html.php an found protected $allowedUrlProtocolRegex = '#^(https?|ftp)://#i';

so i try to add other protocols like steam:// or meta://

protected $allowedUrlProtocolRegex = '#^(https?|ftp|steam|meta)://#i';

but if i add a steam:// link the Renderer will change it to https://steam/

I think i must change something in this function (also in the Html.php) but I'm not a coder and don't know what to change.

Code:
    /**
     * Returns a version of the passed in URL that is valid for use in a message or false
     * if the URL is definitively unusable. Note that this is distinct from the URL being valid
     * from an RFC perspective, as users may submit URLs that don't always have all components
     * URL encoded as needed. We generally defer to the browsers to handle this for us rather
     * than rejecting the URL.
     *
     * @param string $url
     *
     * @return false|string
     */
    protected function getValidUrl($url)
    {
        $url = trim($url);

        if (preg_match('/^(\?|\/|#|:)/', $url))
        {
            return false;
        }

        if (strpos($url, "\n") !== false)
        {
            return false;
        }

        if (preg_match('#^(data|https?://data|javascript|about):#i', $url))
        {
            return false;
        }

        if (preg_match('/proxy\.php\?\w+=(http[^&]+)&/i', $url, $match))
        {
            // proxy link of some sort, adjust to the original one
            $proxiedUrl = urldecode($match[1]);
            if (preg_match('/./su', $proxiedUrl))
            {
                $url = $proxiedUrl;
            }
        }

        if (preg_match($this->allowedUrlProtocolRegex, $url))
        {
            return $url;
        }
        else
        {
            return 'http://' . $url;
        }
    }

So i hope someon can help me. With a hint or a modification. I'm also willing to pay.

Greets Sp4x
 
Back
Top Bottom