Revision [7067]

This is an old revision of EnhancedImageAction made by TimoK on 2005-04-01 18:37:04.


Enhances Image Action

This is the development page for the enhanced image action.

The code here below is just a quick modification to the offical image action code. Only works from release!

 * Displays an image.
 * You have to specify the url for the location of the image. In contrary to inline images you can set the
 * apperance of the image better:
 * You can specify "width" and "height" for the image (note that the image is just displayed different, it does
 * not save any bandwidth), set a target link or make the full size image open in a new window (only possible
 * if you don't assign a link to the image).
 * Syntax:
 * {{image url ="" alt="describing text" [link="] [heigth=""] [width=""] [class="class"]}}
 * @package Actions
 * @subpackage  ?
 * @name    image
 * @author  ?
 * @author  {@link ChristianBarthelemy} (heigth+width+openfull)
 * @author  {@link NilsLindenberg} (default values, minor corrections)
 * @version 0.9
 * @copyright   Copyright © ?
 * @license GNU Lesser General Public License
 * @since   ?
 * @input   string  $url  mandatory: url of the image to be displayed;
 * @input   string  $alt  mandatory: alternative text for the image;
 * @input   string  $link  optional: target link for image (optional). Supports URL, WikiName links,
 *              InterWiki links etc.;
 *              default: none;
 * @input   integer  $width  optional: alternative width for the image;
 *              default:  
 * @input   integer  $height  optional: alternative heigth for the image;
 *              default:
 * @input   string  $class  optional: a class for the image;
 *              default: none;
 * @output  the given image;
 * @uses        cleanUrl();
 * @todo        - do we need to pass the output through SafeHtml?
 *      - handling when no url and/or alternative text is/are provided
 *      - documentation for src (also possible instead of url)
 *      - option to open "full-image" in another window?

//setting default values
$link = $class = $output =  $title =  $width = $height = NULL;

//getting the paramters
if (is_array($vars))
    foreach ($vars as $param => $value)
        if ($param == 'src' and $vars['url'] == '') {$vars['url']=$value;}
        if ($param == 'title') {$title=$this->htmlspecialchars_ent($vars['title']);}
        if ($param == 'class') {$class=$this->htmlspecialchars_ent($vars['class']);}
        if ($param == 'alt') {$alt=$this->htmlspecialchars_ent($vars['alt']);}
        if ($param == 'width') {$width=$this->htmlspecialchars_ent($vars['width']);}
        if ($param == 'heigth') {$height=$this->htmlspecialchars_ent($vars['height']);}
        if ($param == 'link') {$link=$this->cleanUrl(trim($vars['link']));}

//sanatizing url and proofing if it is an image
$url = $this->cleanUrl(trim($vars['url']));
$image = getimagesize($url);

//if it is an image, prepare the output
if ((is_array($image)) && ($alt))
    if (!isset($width)) $width = $image[0];
    if (!isset($height)) $height = $image[1];
    $output.="<img ";
    if ($class) {$output.="class=\"".$class."\" ";}
    $output.="src=\"".$url."\" ";
    if ($alt) {$output.="alt=\"".$alt."\" ";}
    if ($title && !$link) {$output.="title=\"".$title."\" ";}
    $output.="width=\"".$width."\" height=\"".$height."\" />";

    if ($link && !$title) {$output = $this->Link($link, "", $output, 1, 0, 0);}
                elseif ($link && $title) {$output = $this->Link($link, "", $output, 1, 0, $title);}

    //make the output save and print it
    $output = $this->ReturnSafeHTML($output);
elseif (!$alt) {echo 'The necessary parameter alt was not provided';}
else {echo 'The image could not be found or it was no image. Please check the url';}

Note that we have to change the function Link in the wikka.php, too:

return $url ? "<a class=\"ext\" href=\"$url\" >$text</a>$external_link_tail" : $text;

return $url ? "<a class=\"ext\" href=\"$url\" title=\"$title\">$text</a>$external_link_tail" : $text;

There are 6 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki