Location: PHPKode > projects > Todo Manager > todo/classes/messages.class.php
<?php
require_once $_SERVER["DOCUMENT_ROOT"]."/".FOLDER."/library/util.lib.php";

class Messages {

	var $keys;
	
	function Messages($filename = NULL, $language = NULL) {
		$this->keys = array();
		if (!util_empty($filename))
			$this->loadFile($filename, $language);
	}
	
	function loadFile($filename, $language) {
		$handle = fopen($filename.".".$language.".txt", "r");
		if ($handle === FALSE)
			return;
		
		while (!feof($handle)) {
			$line = fgets($handle, 4096);
			if (util_empty(trim($line)))
				continue;
			
			// name = value
			if (preg_match_all("/^(\w+)\s*=(.*)/", $line, $keys)) {
				$name = trim($keys[1][0]);
				$value = trim($keys[2][0]);
				$this->set($name, $value);
			} else
			// coments
			if (!preg_match("/^#/", $line)) {
				break;
			}
		}
		fclose($handle);
	}
	
	function getraw($name) {
		return array_key_exists($name, $this->keys)? $this->keys[$name]: NULL;
	}
	
	function get($name, $class_name = NULL) {
		if (!array_key_exists($name, $this->keys))
			return NULL;
		$ret = htmlentities($this->keys[$name]);
		if (!util_empty($class_name))
			$ret = "<span class='".htmlentities($class_name)."'>".$ret."</span>";
		return $ret;
	}
	
	function getLn($name, $class_name = NULL) {
		if (!array_key_exists($name, $this->keys))
			return NULL;
		$ret = htmlentities($this->keys[$name]);
		if (!util_empty($class_name))
			$ret = "<p class='".htmlentities($class_name)."'>".$ret."</p>";
		return $ret;
	}
	
	function set($name, $value) {
		$this->keys[$name] = $value;
	}
}
?>
Return current item: Todo Manager