BBCode::doAttachment PHP Method

doAttachment() public method

Perform formatting against a string for the attach tag.
public doAttachment ( Nbbc\BBCode $bbcode, integer $action, string $name, string $default, array $params, string $content ) : 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 string Formatted value.
    public function doAttachment($bbcode, $action, $name, $default, $params, $content)
    {
        $medias = $this->media();
        $mediaID = $content;
        if (isset($medias[$mediaID])) {
            $media = $medias[$mediaID];
            $src = htmlspecialchars(Gdn_Upload::url(val('Path', $media)));
            $name = htmlspecialchars(val('Name', $media));
            if (val('ImageWidth', $media)) {
                return "<div class=\"Attachment Image\"><img src=\"{$src}\" alt=\"{$name}\" /></div>";
            } else {
                return anchor($name, $src, 'Attachment File');
            }
        }
        return anchor(t('Attachment not found.'), '#', 'Attachment NotFound');
    }