This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/Config.php

181 lines
5.0 KiB
PHP
Raw Permalink Normal View History

2010-11-29 22:41:08 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
2013-03-19 22:35:19 +00:00
* This class extends the core Kohana class by adding some core application
* specific functions, and configuration.
*
* @package OSB
2013-03-19 22:35:19 +00:00
* @category Modifications
* @author Deon George
2013-03-19 22:35:19 +00:00
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
2013-01-10 00:53:13 +00:00
class Config extends Kohana_Config {
// 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-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;
}
/**
* 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 is_null($date) ? '' : date(Company::instance()->date_format(),$date);
}
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));
}
public static function language() {
return Company::instance()->language();
}
2011-09-29 07:13:32 +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
*/
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
public static function logout_uri() {
return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor('logout','Logout',array('class'=>'lnk_logout')) : '';
}
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) {
list ($path,$suffix) = explode('.',static::$logo);
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
*/
public static function modules() {
static $result = array();
2011-05-02 12:28:17 +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') {
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-02-26 03:19:32 +00:00
}
2012-11-09 23:13:57 +00:00
foreach (ORM::factory('Module')->list_external() as $mo)
$result[$mo->name] = MODPATH.$mo->name;
2013-02-26 03:19:32 +00:00
}
2011-05-02 12:28:17 +00:00
return $result;
}
2011-05-02 12:28:17 +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
public static function module_exist($module) {
return array_key_exists(strtolower($module),static::modules()) ? TRUE : FALSE;
2013-01-10 00:53:13 +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)
*/
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('debug')->email_admin_only;
2013-01-10 00:53:13 +00:00
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-07-05 06:11:37 +00:00
return 'theme/'.(URL::admin_url() ? Kohana::$config->load('config')->theme_admin : Kohana::$config->load('config')->theme);
2013-01-10 00:53:13 +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
?>