2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
/**
|
2013-03-19 22:35:19 +00:00
|
|
|
* This class extends the core Kohana class by adding some core application
|
|
|
|
* specific functions, and configuration.
|
2011-09-28 06:46:22 +00:00
|
|
|
*
|
|
|
|
* @package OSB
|
2013-03-19 22:35:19 +00:00
|
|
|
* @category Modifications
|
2011-09-28 06:46:22 +00:00
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
2011-09-28 06:46:22 +00:00
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-01-10 00:53:13 +00:00
|
|
|
class Config extends Kohana_Config {
|
2013-02-12 11:14:59 +00:00
|
|
|
// Our default logo, if there is no site logo
|
|
|
|
public static $logo = 'img/logo-small.png';
|
2011-09-29 07:13:32 +00:00
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
/**
|
|
|
|
* @compat Restore KH 3.1 functionality
|
|
|
|
* @var Kohana_Config Singleton static instance
|
|
|
|
*/
|
|
|
|
protected static $_instance;
|
|
|
|
|
2013-01-10 00:53:13 +00:00
|
|
|
/**
|
|
|
|
* Some early initialisation
|
|
|
|
*
|
|
|
|
* At this point, KH hasnt been fully initialised either, so we cant rely on
|
|
|
|
* too many KH functions yet.
|
2013-02-12 11:14:59 +00:00
|
|
|
*
|
2013-01-10 00:53:13 +00:00
|
|
|
* NOTE: Kohana doesnt provide a parent construct for the Kohana_Config class.
|
|
|
|
*/
|
2012-11-09 23:13:57 +00:00
|
|
|
public function __construct() {
|
2013-01-10 00:53:13 +00:00
|
|
|
if (defined('PHPUNITTEST'))
|
|
|
|
$_SERVER['SERVER_NAME'] = PHPUNITTEST;
|
2012-11-09 23:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2013-02-12 11:14:59 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
2012-08-23 10:14:46 +00:00
|
|
|
|
|
|
|
public static function date($date) {
|
2013-06-05 14:03:55 +00:00
|
|
|
return is_null($date) ? ' ' : date(Company::instance()->date_format(),$date);
|
2012-08-23 10:14:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
/**
|
|
|
|
* 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));
|
|
|
|
}
|
|
|
|
|
2013-02-12 11:14:59 +00:00
|
|
|
public static function language() {
|
|
|
|
return Company::instance()->language();
|
2012-08-23 10:14:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 07:13:32 +00:00
|
|
|
/**
|
2013-02-12 11:14:59 +00:00
|
|
|
* The URI to show for the login prompt.
|
2013-03-19 22:35:19 +00:00
|
|
|
* Normally if the user is logged in, we can replace it with something else
|
2011-09-29 07:13:32 +00:00
|
|
|
*/
|
2013-02-12 11:14:59 +00:00
|
|
|
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'));
|
|
|
|
}
|
2011-09-29 07:13:32 +00:00
|
|
|
|
2013-04-26 01:42:09 +00:00
|
|
|
public static function logout_uri() {
|
|
|
|
return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor('logout','Logout',array('class'=>'lnk_logout')) : '';
|
|
|
|
}
|
|
|
|
|
2013-02-12 11:14:59 +00:00
|
|
|
public static function logo() {
|
|
|
|
return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
|
|
|
|
}
|
2011-09-29 07:13:32 +00:00
|
|
|
|
2013-03-19 22:35:19 +00:00
|
|
|
public static function logo_uri($protocol=NULL) {
|
2013-02-12 11:14:59 +00:00
|
|
|
list ($path,$suffix) = explode('.',static::$logo);
|
2011-10-14 05:44:12 +00:00
|
|
|
|
2013-03-19 22:35:19 +00:00
|
|
|
return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),$protocol);
|
2011-09-29 07:13:32 +00:00
|
|
|
}
|
|
|
|
|
2011-05-02 12:28:17 +00:00
|
|
|
/**
|
|
|
|
* Find a list of all database enabled modules
|
|
|
|
*
|
2011-09-17 10:45:08 +00:00
|
|
|
* Our available modules are defined in the DB (along with method
|
|
|
|
* security).
|
2011-05-02 12:28:17 +00:00
|
|
|
*/
|
2011-09-28 06:46:22 +00:00
|
|
|
public static function modules() {
|
2013-04-05 12:50:08 +00:00
|
|
|
static $result = array();
|
2011-05-02 12:28:17 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
if (! count($result)) {
|
2013-02-26 03:19:32 +00:00
|
|
|
// We need to know our site here, so that we can subsequently load our enabled modules.
|
|
|
|
if (PHP_SAPI === 'cli') {
|
2013-04-26 01:42:09 +00:00
|
|
|
if (! ($site = Minion_CLI::options('site'))) {
|
|
|
|
echo _('Cant figure out the site, use --site= for CLI')."\n";
|
|
|
|
die();
|
|
|
|
|
|
|
|
} else
|
2013-02-26 03:19:32 +00:00
|
|
|
$_SERVER['SERVER_NAME'] = $site;
|
2013-04-26 01:42:09 +00:00
|
|
|
|
2013-02-26 03:19:32 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
foreach (ORM::factory('Module')->list_external() as $mo)
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$mo->name] = MODPATH.$mo->name;
|
2013-02-26 03:19:32 +00:00
|
|
|
}
|
2011-05-02 12:28:17 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2011-09-28 06:46:22 +00:00
|
|
|
}
|
2011-05-02 12:28:17 +00:00
|
|
|
|
2013-02-12 11:14:59 +00:00
|
|
|
public static function module_config($item) {
|
|
|
|
return Company::instance()->module_config($item);
|
2012-01-29 06:23:24 +00:00
|
|
|
}
|
2013-01-10 00:53:13 +00:00
|
|
|
|
2013-02-12 11:14:59 +00:00
|
|
|
public static function module_exist($module) {
|
|
|
|
return array_key_exists(strtolower($module),static::modules()) ? TRUE : FALSE;
|
2013-01-10 00:53:13 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 11:14:59 +00:00
|
|
|
public static function siteid($format=FALSE) {
|
|
|
|
return Company::instance()->site($format);
|
2013-01-10 00:53:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 22:35:19 +00:00
|
|
|
/**
|
|
|
|
* Work out our site mode (dev,test,prod)
|
|
|
|
*/
|
2013-02-12 11:14:59 +00:00
|
|
|
public static function sitemode() {
|
|
|
|
return Company::instance()->sitemode();
|
2013-01-10 00:53:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 22:35:19 +00:00
|
|
|
public static function sitename() {
|
|
|
|
return Company::instance()->name();
|
|
|
|
}
|
|
|
|
|
2013-01-10 00:53:13 +00:00
|
|
|
/**
|
|
|
|
* 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() {
|
2013-04-18 08:17:33 +00:00
|
|
|
// If we are using user admin pages (and login), we'll choose the admin theme.
|
2013-05-09 14:42:54 +00:00
|
|
|
return URL::admin_url() ? 'theme/'.Kohana::$config->load('config')->theme_admin : 'theme/'.Kohana::$config->load('config')->theme;
|
2013-01-10 00:53:13 +00:00
|
|
|
}
|
2013-02-12 11:14:59 +00:00
|
|
|
|
|
|
|
public static function time($date) {
|
|
|
|
return date(Company::instance()->time_format(),($date ? $date : time()));
|
|
|
|
}
|
2011-05-02 12:28:17 +00:00
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
?>
|