<?php

/*
	Author
		]erous
	History
		1.0: *basic img-tag
		1.1: *resize when exceeding the dimensions (and the option is turned on)
*/

/*if the width or height exceed respectively one of the constants defined next,
	then the image will be resized (html-resized) and a link will be created
	to the fullsized image. Autoresize only happens when UBB_IMG_RESIZE is set to true.
*/
define(UBB_IMG_RESIZE, true);

define(UBB_IMG_MAX_WIDTH, 400);
define(UBB_IMG_MAX_HEIGHT, 800);

class UBB_IMG extends UBB
{
	var $allow1 = 'EMPTY';
	var $allow2 = 'URL';
	
	var $info = array('Name'=>'IMG', 'Version'=>'1.0', 'Info'=>'Show an image in the browser');
	
	function process($value1, $value2)
	{
		list($width, $height, $type, $attr) = @getimagesize($value2);
		
		if (UBB_IMG_RESIZE)
		{
			if ($width>UBB_IMG_MAX_WIDTH && $height>UBB_IMG_MAX_HEIGHT)
			{
				if ($width/UBB_IMG_MAX_WIDTH>$height/UBB_IMG_MAX_HEIGHT)
					$s = array(UBB_IMG_MAX_WIDTH, $height/$width*UBB_IMG_MAX_WIDTH);
				else
					$s = array($width/$height*UBB_IMG_MAX_HEIGHT, UBB_IMG_MAX_HEIGHT);
			}
			elseif ($width>UBB_IMG_MAX_WIDTH)
				$s = array(UBB_IMG_MAX_WIDTH, $height/$width*UBB_IMG_MAX_WIDTH);
			elseif ($height>UBB_IMG_MAX_HEIGHT)
				$s = array($width/$height*UBB_IMG_MAX_HEIGHT, UBB_IMG_MAX_HEIGHT);
			
			list($nwidth, $nheight)=$s;
			
			if ($nwidth!='')
				return "<a href='$value2'	target='_blank'><img src='$value2'	alt='$value2'	width='$nwidth'	height='$nheight' /></a>";
		}
		
		return "<img src='$value2'	alt='$value2' $resize/>";
	}
}
?>