BBCode::doQuote PHP Method

doQuote() public method

Perform formatting against a string for the quote tag.
public doQuote ( 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 doQuote($bbcode, $action, $name, $default, $params, $content)
    {
        if ($action == Nbbc::BBCODE_CHECK) {
            return true;
        }
        if (is_string($default)) {
            $defaultParts = explode(';', $default);
            // support vbulletin style quoting.
            $Url = array_pop($defaultParts);
            if (count($defaultParts) == 0) {
                $params['name'] = $Url;
            } else {
                $params['name'] = implode(';', $defaultParts);
                $params['url'] = $Url;
            }
        }
        $title = '';
        if (isset($params['name'])) {
            $username = trim($params['name']);
            $username = html_entity_decode($username, ENT_QUOTES, 'UTF-8');
            $User = Gdn::userModel()->getByUsername($username);
            if ($User) {
                $userAnchor = userAnchor($User);
            } else {
                $userAnchor = anchor(htmlspecialchars($username, null, 'UTF-8'), '/profile/' . rawurlencode($username));
            }
            $title = concatSep(' ', $title, $userAnchor, t('Quote wrote', 'wrote'));
        }
        if (isset($params['date'])) {
            $title = concatSep(' ', $title, t('Quote on', 'on'), htmlspecialchars(trim($params['date'])));
        }
        if ($title) {
            $title = $title . ':';
        }
        if (isset($params['url'])) {
            $url = trim($params['url']);
            if (preg_match('/(c|d)-(\\d+)/', strtolower($url), $matches)) {
                if ($matches[1] === 'd') {
                    $url = "/discussion/{$matches[2]}";
                } else {
                    $url = "/discussion/comment/{$matches[2]}#Comment_{$matches[2]}";
                }
            } elseif (is_numeric($url)) {
                $url = "/discussion/comment/{$url}#Comment_{$url}";
            } elseif (!$bbcode->isValidURL($url)) {
                $url = '';
            }
            if ($url) {
                $title = concatSep(' ', $title, anchor('<span class="ArrowLink">ยป</span>', $url, ['class' => 'QuoteLink']));
            }
        }
        if ($title) {
            $title = "<div class=\"QuoteAuthor\">{$title}</div>";
        }
        return "\n<blockquote class=\"Quote UserQuote\">\n{$title}\n<div class=\"QuoteText\">{$content}</div>\n</blockquote>\n";
    }