<?php
defined('_JEXEC') or die( 'Restricted access' );

class KipConfig
{
	var $_params = array();

	function &getInstance()
	{
		static $instance;

		if (!is_object( $instance )) {
			$instance = new KipConfig();
			$instance->load();
		}

		return $instance;
	}

	function getKeys()
	{
		return array_keys($this->_params);
	}

	function getParamsInfo()
	{
		$db = & JFactory::getDBO();
		$db->setQuery("SELECT * FROM #__kip_settings");
		return $db->loadObjectList('name');
	}

	function get( $name, $default = '' )
	{
		return isset($this->_params[$name]) ? $this->_params[$name] : $default;
	}

	function set( $name, $value )
	{
		$this->_params[$name] = $value;
	}

	function _load()
	{
		$db = & JFactory::getDBO();
		$db->setQuery("SELECT * FROM #__kip_settings");
		return $db->loadObjectList();
	}

	function load()
	{
		$cache = & JFactory::getCache('com_kip');
		//$cache->setCaching(1);
		$params = (array) $cache->call('KipConfig::_load');

		foreach ($params as $param)
			$this->_params[$param->name] = $param->value;
		
		unset( $params );
	}
}
?>