Ejemplo n.º 1
0
    /**
     * Shortcode for <figure>.
     *
     * Usage example: [FIGURE src="img/home/me.jpg" caption="Me" alt="Bild på mig" nolink="nolink"]
     *
     * @param string $options for the shortcode.
     *
     * @return array with all the options.
     */
    public static function shortCodeFigure($options)
    {
        extract(array_merge(array('id' => null, 'class' => null, 'src' => null, 'title' => null, 'alt' => null, 'caption' => null, 'href' => null, 'nolink' => false), CTextFilter::ShortCodeInit($options)), EXTR_SKIP);
        $id = $id ? " id='{$id}'" : null;
        $class = $class ? " class='figure {$class}'" : " class='figure'";
        $title = $title ? " title='{$title}'" : null;
        if (!$alt && $caption) {
            $alt = $caption;
        }
        if (!$href) {
            $pos = strpos($src, '?');
            $href = $pos ? substr($src, 0, $pos) : $src;
        }
        $a_start = null;
        $a_end = null;
        if (!$nolink) {
            $a_start = "<a href='{$href}'>";
            $a_end = "</a>";
        }
        $html = <<<EOD
<figure{$id}{$class}>
{$a_start}<img src='{$src}' alt='{$alt}'{$title}/>{$a_end}
<figcaption markdown=1>{$caption}</figcaption>
</figure>
EOD;
        return $html;
    }