|
// +----------------------------------------------------------------------+
//
// $Id: abstraction.php,v 1.3 2007/01/08 09:41:11 ah Exp $
/**
* HTML/XML Generator.
*
* @version 1
*/
class xml_gen
{
/**
* Generate XML for plain link.
*
* If $uri is false a grey text will be displayed instead.
*
* @param string uri URI to open
* @param string text Text or HTML used for linking
* @param string attr Additional HTML attributes, e.g. "target=main width='100%'".
*/
public static function a($uri, $text, $attr = false)
{
if (!$uri) {
return "$text";
}
// Replace & with & in uri
$uri = str_replace('&', '&', $uri);
return "$text";
}
/**
* Generate XML code for image.
*
* Automatically locates file- looks for it in any ../ (max 20 levels)
* Can extract width and height automatically.
* Border defaults to 0. Can be overridden with $attr
*
* @param string filename Relative filename of picture or uri.
* @param string width Forced width of picture.
* @param string height Forced height of picture.
* @param string attr Additional HTML attributes, e.g. "target=main width='100%'".
* @return string Generated XML.
*/
public static function img($filename, $attr = false, $width = false, $height = false)
{
// If filename is a local file, locate it somewhere in (../)*
if (!strstr($filename, "http://") && !strstr($filename, "?")) {
$name = preg_replace("/^\//", "", $filename);
$i= 21;
while (--$i && !file_exists($name)) {
$name = '../'.$name;
}
if (!file_exists($name)) {
return false;
}
$fn_size = $name;
// Replace relative filename with correct path
if (@$filename[0] != "/") {
$filename = $name;
}
}
// Get height and width
if (!empty($fn_size) && (!$height || !$width)) {
$sz = GetImageSize($fn_size);
if (!$width) {
$width= $sz[0];
}
if (!$height) {
$height= $sz[1];
}
}
// Add border code?
$border= (stristr(" $attr", " border=")) ? '' : "border='0'";
// Add alt code?
$alt= (stristr(" $attr", " alt=")) ? '' : 'alt=""';
// Replace & with & in filename
$filename = str_replace('&', '&', $filename);
// Output
$result = "\n";
}
/**
* Generate XML for pictorial link with image swapping -or- Simple picture -depending- on $condition.
*
* @param bool condition Show Picture or xml_gen::a_img?
* @param string selected Filename for image to display if $condition == true. - use m_over if set to null
* @param string uri URI to open
* @param string filename Filename for image to display if $condition == false.
* @param string m_over Filename for image to display when mouse is over image.
* @param string attr Additional HTML attributes, e.g. "target=main width='100%'".
* Except for onmouse* $attr is only added to
| Requires flash version '.$requied_flash_version.' |
$text\n"; } /** * Generate XML for paragraph. */ public static function p($text, $attr = null) { if (is_array($text)) { $text = implode("
$text
\n"; } /** * Generate XML for error paragraph. */ public static function p_err($text) { if (is_array($text)) { $text = implode("