Wikka Mod 019

Type: Feature addition

Credit:

Adrian Look
InlineImages @ WakkaWiki

Inline Images

To include an image just type in an URL to a jpeg or gif. No special formatting is necessary. No brackets or anything like that.

So if I wanted the Google logo to show up on this page, I just have to put http://www.google.com/images/logo.gif....
http://www.google.com/images/logo.gif



Implementation

A simple alternative to ImgAction would be to modify URL matching in formatters/wakka.php. This converts gif, jpg, and png URLs into <img> tags rather than <a> tags. Of course, if you want to force a link, instead of an inline image, just use [[ | ]] as usual.

Add one line to formatters/wakka.php so that instead of:

<?php
        // urls
        else if (preg_match("/^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$/", $thing, $matches)) {
            $url = $matches[1];
            return "<a href=\"$url\">$url</a>".$matches[2];
        }
?>


it now reads:

<?php
        // urls
        else if (preg_match("/^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$/", $thing, $matches)) {
            $url = $matches[1];
            if (preg_match("/^(.*)\.(gif|jpg|png)/si", $url)) return "<img src=\"$url\" />".$matches[2];
            return "<a href=\"$url\">$url</a>".$matches[2];
        }
?>


Of course, ImgAction is still useful for cool stuff like alt tags, sizes, links, etc
There are 3 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki