<?php
// $Id: language_base.php,v 1.5 2005/10/28 11:56:02 ohwada Exp $

// 2005-09-04 K.OHWADA
// BUG 2932: dont work correctly when register_long_arrays = off

// 2005-01-20 K.OHWADA
// WINDOWS-1252

// 2004-12-26 K.OHWADA
// add get_country() get_google_url()

// 2004-11-28 K.OHWADA
// add presume_agent()
// &getInstance()

// 2004-10-24 K.OHWADA
// utf8
// shorten_text

//=========================================================
// class language_base
// created since v0.7
// porting form XFsection
// 2004/08/10 K.OHWADA
//=========================================================

//=========================================================
// class language_base
//=========================================================
class language_base
{
	var $os;
	var $browser;


//---------------------------------------------------------
// constructor
//---------------------------------------------------------
function language_base()
{
	list($this->os, $this->browser) = $this->presume_agent();
}

function &getInstance()
{
	static $instance;
	if (!isset($instance)) 
	{
		$instance = new language_convert();
	}

	return $instance;
}

//---------------------------------------------------------
// function
//---------------------------------------------------------
function getOS()
{	return $this->os;	}

function getBrowser()
{	return $this->browser;	}

// language_convert extends language_base
function convert_telafriend_subject($text)
{	return $text;	}

function convert_telafriend_body($text)
{	return $text;	}

// bug fix : Downloads not working
function convert_download_filename($text)
{	return $text;	}

// for search
function convert_space_zen_to_han($text)
{	return $text;	}

// utf8
function convert_from_utf8($text)
{
	return utf8_decode($text);
}

function convert_to_utf8($text)
{
	return utf8_decode($text);
}

function convert_encode_to_utf8($text, $encode)
{

	$encode = strtoupper($encode);
	$flag   = false;

	if     ( $encode == "ISO-8859-1" )    $flag = true;
	elseif ( $encode == "WINDOWS-1252" )  $flag = true;

	if ( $flag )
	{
		$text = utf8_encode($text);
	}

	return $text;
}

// shorten_text
function shorten_text($text,$max)
{
	if ( strlen($text) > $max)
	{
		$text = substr( $text, 0, $max )." ...";
	}

	return $text;
}

function send_mail($mailto, $subject, $body, $header)
{
	return mail($mailto, $subject, $body, $header);
}

function get_country()
{
	return "usa";
}

function get_google_url()
{
	return "http://www.google.com/search?hl=en&amp;q=";
}

function get_happy_linux_url()
{
	return "http://linux2.ohwada.net/";
}

//---------------------------------------------------------
// presume os and browser by agent
// porting from XFsection
//---------------------------------------------------------
function presume_agent()
{
// BUG 2932: dont work correctly when register_long_arrays = off
	$agent = getenv("HTTP_USER_AGENT");

	if ( empty($agent) )
	{	return array('','');	}	// undefined

// presume OS
	if     (preg_match("/Win/i",$agent))    $os = 'win';
	elseif (preg_match("/Mac/i",$agent))    $os = 'mac';
	elseif (preg_match("/Linux/i",$agent))  $os = 'linux';
	elseif (preg_match("/BSD/i",$agent))    $os = 'bsd';
	elseif (preg_match("/IRIX/i",$agent))   $os = 'irix';
	elseif (preg_match("/Sun/i",$agent))    $os = 'sun';
	elseif (preg_match("/HP-UX/i",$agent))  $os = 'hpux';
	elseif (preg_match("/AIX/i",$agent))    $os = 'aix';
	elseif (preg_match("/X11/i",$agent))    $os = 'x11';
	else                                    $os = 'unknown';

// presume Browser
	if     (preg_match("/MSIE/i",$agent))    $browser = 'msie';
	elseif (preg_match("/Mozilla/i",$agent)) $browser = 'mozilla';
	else                                     $browser = 'unknown';

	return array($os, $browser);
}


// --- class end ---
}

?>