<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 * This class extends the core Kohana class by adding some core application
 * specific functions, and configuration.
 *
 * @package    Redir
 * @category   Modifications
 * @author     Deon George
 * @copyright  (c) 2009-2013 Deon George
 * @license    http://dev.leenooks.net/license.html
 */
class Config extends Kohana_Config {
	// Our default logo, if there is no site logo
	public static $logo = 'img/logo-small.png';

	/**
	 * @compat Restore KH 3.1 functionality
	 * @var  Kohana_Config  Singleton static instance
	 */
	protected static $_instance;

	/**
	 * Some early initialisation
	 *
	 * At this point, KH hasnt been fully initialised either, so we cant rely on
	 * too many KH functions yet.
	 *
	 * NOTE: Kohana doesnt provide a parent construct for the Kohana_Config class.
	 */
	public function __construct() {
		if (defined('PHPUNITTEST'))
			$_SERVER['SERVER_NAME'] = PHPUNITTEST;
	}

	/**
	 * Get the singleton instance of Config.
	 *
	 *     $config = Config::instance();
	 *
	 * @return  Config
	 * @compat Restore KH 3.1 functionality
	 */
	public static function instance() {
		if (Config::$_instance === NULL)
			// Create a new instance
			Config::$_instance = new Config;

		return Config::$_instance;
	}

	public static function copywrite() {
		return '(c) Web Redirection Service';
	}

	public static function language() {
		return '';
	}

	public static function logo_uri($protocol=NULL) {
		list ($path,$suffix) = explode('.',static::$logo);

		return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),$protocol);
	}

	public static function siteid($format=FALSE) {
		return '';
	}

	/**
	 * Work out our site mode (dev,test,prod)
	 */
	public static function sitemode() {
		return '';
	}

	public static function sitename() {
		static $do;

		if (is_null($do))
			$do = ORM::factory('Domain',array('domain'=>$_SERVER['HTTP_HOST']));

		return ($do->loaded() AND $do->description) ? $do->description : 'Web Redirection';
	}

	public static function theme() {
		return Kohana::$config->load('config')->theme;
	}
}
?>
