170 lines
4.6 KiB
PHP
170 lines
4.6 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 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;
|
|
|
|
// 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;
|
|
}
|
|
|
|
/**
|
|
* 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(Company::instance()->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 language() {
|
|
return Company::instance()->language();
|
|
}
|
|
|
|
/**
|
|
* 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 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'));
|
|
}
|
|
|
|
public static function logo() {
|
|
return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
|
|
}
|
|
|
|
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');
|
|
}
|
|
|
|
/**
|
|
* 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 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 siteid($format=FALSE) {
|
|
return Company::instance()->site($format);
|
|
}
|
|
|
|
public static function sitename() {
|
|
return Company::instance()->name();
|
|
}
|
|
|
|
public static function sitemode() {
|
|
return Company::instance()->sitemode();
|
|
}
|
|
|
|
/**
|
|
* See if our emails for the template should be sent to configured admin(s)
|
|
*
|
|
* @param string template - Template to test for
|
|
* @return mixed|array - Email to send test emails to
|
|
*/
|
|
public static function testmail($template) {
|
|
$config = Kohana::$config->load('config')->email_admin_only;
|
|
|
|
if (is_null($config) OR ! is_array($config) OR empty($config[$template]))
|
|
return FALSE;
|
|
else
|
|
return $config[$template];
|
|
}
|
|
|
|
public static function theme() {
|
|
return Kohana::$config->load('config')->theme;
|
|
}
|
|
|
|
public static function time($date) {
|
|
return date(Company::instance()->time_format(),($date ? $date : time()));
|
|
}
|
|
}
|
|
?>
|