<?php
/*
fiemeCP - BETA.
Written by, and managed by xDario.

The script may be altered at wish, but redistributing any part of it, even with credets, is prohibited. Currently, only myself and my website (http://www.dario-ml.com/) along with kryptodev are aloud to host my script.

©2011 xDario (created for Ohai Online)

You must provide a thanks on the page from which this is called, unless you have donated. If I find my class used without copyright, or a mention of appreciation, I will pursude you. Fiesta servers aren't thousands, so you're not hard to spot out.

Page: class.languages.php
Last Change: 10 June 2011
*/

if (!defined('IN_FIEME'))
{
	die("canno't directly access this page");
}

class fieme_lang
{
	public $path;
	public $language;
	public $opts;

	function use_language($language = "en")
	{	
		//Did the user call a valid language? Let's kill him if he didn't.
		if(!$this->language_exists($language))
		{
			die("LANGUAGE [$language] DOESN'T EXIST");
		}
		
		$this->language = $language;
		
		require $this->path . $language . ".php";
		$this->opts = $langopt;
	}

	//load the appropriate files now, falling back to english if possibl or needed
	function load($section)
	{

		$lang_file = $this->path . $this->language . "\language." . $section . ".php";
		
		if(file_exists($lang_file))
		{
			require_once $lang_file;
		}
		elseif(file_exists($this->path . "en\language." . $section . ".php"))
		{
			require_once $this->path . "en\language." . $section . ".php";
		}
		
		// These shall not be edited!
		$dont_use = array('language', 'path', 'lang_options');
		
		if(is_array($lang))
		{
			foreach($lang as $one => $two)
			{
				if((empty($this->$one) || $this->$one != $two) && !in_array($one, $dont_use))
				{
					$this->$one = $two;
					if (FIEME_DEV == 1)
					{
						global $dev_content;
						$dev_content .= "success load lang: $one<br />";
					}
				}
			}
		}
	}
	
	function sprintf($string)
	{
		$arg_list = func_get_args();
		$num_args = count($arg_list);
		
		for($i = 1; $i < $num_args; $i++)
		{
			$string = str_replace('{'.$i.'}', $arg_list[$i], $string);
		}
		
		return $string;
	}
	
	function language_exists($language)
	{
		if(file_exists($this->path . $language . ".php"))
		{
			return true;
		}
		else
		{
			echo $this->path . $language . ".php";
			return false;
		}
	}
}


/*
if ($handle = opendir("$cfg[script_root]includes/lang/en/"))
{
	while (false !== ($file = readdir($handle)))
	{
		if ($file != "." && $file != "..") 
		{
			if (preg_match('/\.php/', $file))
			{
				include("lang/" . $cfg['lang_prefix'] . "/$file");
			}
		}
	}
}
else
{
	die("FATAL ERROR. COULD NOT LOAD LANGUAGE FILES");
}

*/
