<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://www.gekkoware.org
	*/

	if (!defined("IN-GEKKO")) die("Get a life!");

	function msie_img_pngfix($tag) {
		preg_match_all("/([a-z]*)\=\"(.*?)\"/i", " $tag ", $m);
		$attr = null;
		foreach ($m[1] as $i => $n) {
			$attr[$n] = $m[2][$i];
		}
		if (isset($attr["src"]) && file_extension($attr["src"]) == "png") {
			// image is png, adding garbage for msie to apply alpha channel

			// avoid problems when style attribute is set
			if (isset($attr["style"])) {
				if (substr($attr["style"], -1) != ";") $attr["style"] .= ";";
			} else {
				$attr["style"] = "";
			}
			// dimensions
			foreach (Array("width", "height") as $d) {
				if (isset($attr[$d]) && !ereg("$d\:", $attr["style"])) {
					$attr["style"] .= "$d:{$attr["$d"]}px;";
				}
			}
			$attr["style"] .= "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$attr["src"]}', sizingMethod='scale');";
			// reemplazing src with a transparent 1x1 gif
			$attr["src"] = _l("C_SITE.REL_URL")."media/blank.gif";
		}
		$tag = "";
		foreach ($attr as $n => $v) {
			$tag .= "$n=\"$v\" ";
		}
		$tag .= "/";
		return $tag;
	}

	function msie_hack(&$buff) {
		// pngfix
		$buff = preg_replace("/<img(.*?)>/e", "'<img '.msie_img_pngfix(\"\\1\").'>'", $buff);
	}

	function msiepngfix_output(&$buff) {
		// ugly hacks for an ugly browser
		// Opera Browser it's MSIE 6.0 compatible :-S!
		if (ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]) && !ereg("Opera", $_SERVER["HTTP_USER_AGENT"])) {
			// may not work under MSIE 7, who cares?
			msie_hack($buff);
		}
	}

?>