Optimised Company() Setup() Config() and changed method_directory into URL

This commit is contained in:
Deon George
2013-02-12 22:14:59 +11:00
parent 97d894d472
commit 288d974cfa
63 changed files with 422 additions and 346 deletions

View File

@@ -11,10 +11,8 @@
* @license http://dev.osbill.net/license.html
*/
class Config extends Kohana_Config {
// Our setup object
public $so;
public static $no_site_id_tables = array('setup','country','currency','language','tax');
protected static $logo = 'img/logo-small.png';
// Our default logo, if there is no site logo
public static $logo = 'img/logo-small.png';
/**
* @compat Restore KH 3.1 functionality
@@ -27,6 +25,7 @@ class Config extends Kohana_Config {
*
* 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() {
@@ -59,10 +58,23 @@ class Config extends Kohana_Config {
return Config::$_instance;
}
/** Overloaded methods **/
/**
* Return our caching mechanism
*/
public static function cachetype() {
return is_null(Kohana::$config->load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type;
}
public static function copywrite() {
return '(c) Open Source Billing Development Team';
}
public static function country() {
return Company::instance()->country();
}
public static function date($date) {
return date(Config::instance()->loadsite()->so->date_format,($date ? $date : time()));
return date(Company::instance()->date_format(),($date ? $date : time()));
}
/**
@@ -73,38 +85,26 @@ class Config extends Kohana_Config {
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 language() {
return Company::instance()->language();
}
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.
* The URI to show for the login prompt.
* Normally if the user is logged in, we can replace it with a user edit call, instead of login
*/
public function loadsite() {
// Anti-loop, if we have loaded our record, just return;
if ($this->so AND $this->so->loaded())
return $this;
public static function login_uri() {
return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor(URL::link('user','account/edit'),$ao->name()) : HTML::anchor('login',_('Login'));
}
$this->so = ORM::factory('Setup',array('url'=>URL::base('http')));
public static function logo() {
return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
}
if (! $this->so->loaded())
throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http')));
public static function logo_uri() {
list ($path,$suffix) = explode('.',static::$logo);
Kohana::$environment = (int)static::sitemode();
return $this;
return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),'http');
}
/**
@@ -123,66 +123,24 @@ class Config extends Kohana_Config {
return $return;
}
public static function moduleexist($module) {
public static function module_config($item) {
return Company::instance()->module_config($item);
}
public static function module_exist($module) {
return array_key_exists(strtolower($module),static::modules()) ? TRUE : FALSE;
}
public static function copywrite() {
return '(c) Open Source Billing Development Team';
}
/**
* Return our site name
*/
public static function site() {
return $_SERVER['SERVER_NAME'];
}
public static function sitemodeverbose() {
$modes = array(
Kohana::PRODUCTION=>'Production',
Kohana::STAGING=>'Staging',
Kohana::TESTING=>'Testing',
Kohana::DEVELOPMENT=>'Development',
);
return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()];
}
public static function submode() {
$submode = Kohana::$config->load('config.debug.submode');
return (isset($submode[Request::$client_ip])) ? $submode[Request::$client_ip] : FALSE;
public static function siteid($format=FALSE) {
return Company::instance()->site($format);
}
public static function sitename() {
return Kohana::$config->load('config')->site_name;
return Company::instance()->name();
}
// Called in Invoice/Emailing to embed the file.
public static function logo_file() {
list ($path,$suffix) = explode('.',static::$logo);
return ($a=Kohana::find_file(sprintf('media/site/%s',Config::siteid()),$path,$suffix)) ? $a : Kohana::find_file('media',$path,$suffix);
}
public static function logo_uri() {
list ($path,$suffix) = explode('.',static::$logo);
return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),'http');
}
public static function logo() {
return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
}
public static function login_uri() {
return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor('user/account/edit',$ao->name()) : HTML::anchor('login',_('Login'));
}
/**
* Return our caching mechanism
*/
public static function cachetype() {
return is_null(Kohana::$config->load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type;
public static function sitemode() {
return Company::instance()->sitemode();
}
/**
@@ -203,5 +161,9 @@ class Config extends Kohana_Config {
public static function theme() {
return Kohana::$config->load('config')->theme;
}
public static function time($date) {
return date(Company::instance()->time_format(),($date ? $date : time()));
}
}
?>