Although a nice idea, this functionality is covered as of version 0.25 through use of proper InterWiki-entries. Just add entries to point towards local image or document directory, and then 'Tavi does the magic for you. --EvenHolen

idea

The idea of this Macro is letting you write a relative path for images and documents instead of the absolute one:

so:

mylogo.jpg instead of http//www.mysite.com/local/images/mylogo.jpg

Advantages:

how to use

  1. define a directory for your images (default: /img)
  2. define a directory for your docs (default: /doc)
  3. write [[img mylogo.jpg]] or [[doc mydoc.pdf]]

how to install

Save the following code in imgdoc.php in you personal template directory

<?php
function view_macro_img($text)
{	
	$ImgDir = './img';
	return '<img src=' . $ImgDir . $text . ' />';
}
function view_macro_doc($text)
{	
	$DocDir = 'doc/';
	return '<a href=' . $DocDir . $text . '>' . $text . '</a>';
}
?>

Edit the file lib/defaults.php and add the following lines to the $ViewMacroEngine array

 'img'			 => 'view_macro_img',
 'doc'			 => 'view_macro_doc'

Add your file to parse/macros.php:

 require('nkoniTemplate/imgdoc.php');

Thats'it!

MassimoI - massimoi@email.it


Patch to this patch:

Use the following functions and you get new advanced features

Notice: you can use even full http:// type reference too...

function view_macro_img($text)
{
	list($url,$width,$height) = explode(" ",$text,3);
        $res = "<img src=\"" . $url . "\" ";
        if ($width != "") {
            $res = $res . "width=\"" . $width . "\" ";
        }
        if ($height != "") {
            $res = $res . "height=\"" . $height . "\" ";
        }
        $res = $res . "/>";
        return $res;
}

function view_macro_doc($text)
{
	list($url,$label) = explode(" ",$text,2);
	if($label=="") {
	    return "<a href=\"" . $url . "\">" . $url . "</a>";
	}
	return "<a href=\"" . $url . "\">" . $label . "</a>";
}

Have fun!

bartusl (bartus at alpha.tmit.bme.hu)