BBCode::doURL PHP Method

doURL() public method

Perform formatting against a string for the url tag.
public doURL ( Nbbc\BBCode $bbcode, integer $action, string $name, string $default, array $params, string $content ) : boolean | string
$bbcode Nbbc\BBCode Instance of Nbbc doing the parsing.
$action integer Value of one of NBBC's defined constants. Typically, this will be BBCODE_CHECK.
$name string Name of the tag.
$default string Value of the _default parameter, from the $params array.
$params array A standard set parameters related to the tag.
$content string Value between the open and close tags, if any.
return boolean | string Formatted value.
    function doURL($bbcode, $action, $name, $default, $params, $content)
    {
        if ($action == Nbbc::BBCODE_CHECK) {
            return true;
        }
        $url = is_string($default) ? $default : $bbcode->unHtmlEncode(strip_tags($content));
        if ($bbcode->isValidURL($url)) {
            if ($bbcode->getDebug()) {
                print "ISVALIDURL<br />";
            }
            if ($bbcode->getUrlTargetable() !== false && isset($params['target'])) {
                $target = " target=\"" . htmlspecialchars($params['target']) . "\"";
            } else {
                $target = "";
            }
            if ($bbcode->getURLTarget() !== false) {
                if (!($bbcode->getUrlTargetable() == 'override' && isset($params['target']))) {
                    $target = " target=\"" . htmlspecialchars($bbcode->getUrlTarget()) . "\"";
                }
            }
            $encodedUrl = htmlspecialchars($url);
            return "<a href=\"{$encodedUrl}\" rel=\"nofollow\" class=\"bbcode_url\"{$target}\">{$content}</a>";
        } else {
            return htmlspecialchars($params['_tag']) . $content . htmlspecialchars($params['_endtag']);
        }
    }