126 lines
3.3 KiB
PHP
126 lines
3.3 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class is for access system configuration.
|
|
*
|
|
* @package OSB
|
|
* @subpackage Config
|
|
* @category Helpers
|
|
* @author Deon George
|
|
* @copyright (c) 2010 Open Source Billing
|
|
* @license http://dev.osbill.net/license.html
|
|
*/
|
|
class Config extends lnApp_Config {
|
|
// Our setup object
|
|
public $so;
|
|
public static $no_site_id_tables = array('setup','country','currency','language','tax');
|
|
|
|
/**
|
|
* @compat Restore KH 3.1 functionality
|
|
* @var Kohana_Config Singleton static instance
|
|
*/
|
|
protected static $_instance;
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
// We need to know our site here, so that we can subsequently load our enabled modules.
|
|
if (Kohana::$is_cli) {
|
|
if (! $site = Minion_CLI::options('site'))
|
|
// @todo Need to figure out how to make this CLI error nicer.
|
|
throw new Minion_Exception_InvalidTask(_('Cant figure out the site, use --site= for CLI'));
|
|
else
|
|
$_SERVER['SERVER_NAME'] = $site;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/** Overloaded methods **/
|
|
|
|
public static function date($date) {
|
|
return date(Config::instance()->loadsite()->so->date_format,($date ? $date : time()));
|
|
}
|
|
|
|
/**
|
|
* Show a date using a site configured format
|
|
* @note We need this function here, since we call static:: methods, which need to resolve to the child class.
|
|
*/
|
|
public static function datetime($date) {
|
|
return sprintf('%s %s',static::date($date),static::time($date));
|
|
}
|
|
|
|
public static function siteid($format=FALSE) {
|
|
return $format ? sprintf('%02s',Config::instance()->loadsite()->so->id) : Config::instance()->loadsite()->so->id;
|
|
}
|
|
|
|
public static function sitemode() {
|
|
return Config::instance()->loadsite()->so->status;
|
|
}
|
|
|
|
public static function time($date) {
|
|
return date(Config::instance()->loadsite()->so->time_format,($date ? $date : time()));
|
|
}
|
|
|
|
/** Local Methods **/
|
|
|
|
/**
|
|
* Load our site configuration from the DB
|
|
*
|
|
* We cant do this in __construct(), since Kohana hasn't been fully initialised yet.
|
|
*/
|
|
public function loadsite() {
|
|
// Anti-loop, if we have loaded our record, just return;
|
|
if ($this->so AND $this->so->loaded())
|
|
return $this;
|
|
|
|
$this->so = ORM::factory('Setup',array('url'=>URL::base('http')));
|
|
|
|
if (! $this->so->loaded())
|
|
throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http')));
|
|
|
|
Kohana::$environment = (int)static::sitemode();
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Find a list of all database enabled modules
|
|
*
|
|
* Our available modules are defined in the DB (along with method
|
|
* security).
|
|
*/
|
|
public static function modules() {
|
|
static $return = array();
|
|
|
|
if (! count($return))
|
|
foreach (ORM::factory('Module')->list_external() as $mo)
|
|
$return[$mo->name] = MODPATH.$mo->name;
|
|
|
|
return $return;
|
|
}
|
|
|
|
public static function moduleexist($module) {
|
|
return array_key_exists($module,static::modules()) ? TRUE : FALSE;
|
|
}
|
|
|
|
public static function copywrite() {
|
|
return '(c) Open Source Billing Development Team';
|
|
}
|
|
}
|
|
?>
|