Added getting site config from DB
This commit is contained in:
@@ -12,49 +12,43 @@
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Config extends Kohana_Config {
|
||||
protected static $logo = 'img/logo-small.png';
|
||||
|
||||
/**
|
||||
* 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 (Kohana::$is_cli) {
|
||||
if (! $site = CLI::options('site'))
|
||||
throw new Kohana_Exception(_('Cant figure out the site, use --site= for CLI'));
|
||||
else
|
||||
$_SERVER['SERVER_NAME'] = $site['site'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return our site name
|
||||
*/
|
||||
public static function site() {
|
||||
if (! empty($_SERVER['SERVER_NAME']))
|
||||
return $_SERVER['SERVER_NAME'];
|
||||
|
||||
if (! $site = CLI::options('site'))
|
||||
throw new Kohana_Exception(_('Cant figure out the site, use --site= for CLI'));
|
||||
|
||||
// @todo Need to move this to earlier into the processing stream.
|
||||
// we can then do away with the test above.
|
||||
$_SERVER['SERVER_NAME'] = $site['site'];
|
||||
|
||||
return $site['site'];
|
||||
return $_SERVER['SERVER_NAME'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out our site ID for multiehosting
|
||||
* @todo Change this to query the DB for site number.
|
||||
*/
|
||||
public static function siteid() {
|
||||
$sites = Kohana::config('config.site');
|
||||
|
||||
// If we havent been configured for sites
|
||||
if (is_null($sites) OR ! is_array($sites) OR ! isset($sites[static::site()]))
|
||||
return 0;
|
||||
else
|
||||
return $sites[static::site()];
|
||||
return Config::instance()->loadsite()->so->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out our site mode (dev,test,prod)
|
||||
* @todo Change this to query the DB for mode.
|
||||
*/
|
||||
public static function sitemode() {
|
||||
$sites = Kohana::config('config.site_mode');
|
||||
|
||||
// If we havent been configured for sites
|
||||
if (is_null($sites) OR ! is_array($sites) OR ! isset($sites[static::site()]))
|
||||
return Kohana::PRODUCTION;
|
||||
else
|
||||
return $sites[static::site()];
|
||||
return Config::instance()->loadsite()->so->status;
|
||||
}
|
||||
|
||||
public static function sitemodeverbose() {
|
||||
@@ -65,24 +59,26 @@ abstract class lnApp_Config extends Kohana_Config {
|
||||
Kohana::DEVELOPMENT=>'Development',
|
||||
);
|
||||
|
||||
return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()];
|
||||
return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()];
|
||||
}
|
||||
|
||||
public static function sitename() {
|
||||
return Kohana::config('config.site_name');
|
||||
return Config::instance()->loadsite()->so->site_name;
|
||||
}
|
||||
|
||||
// Called in Invoice/Emailing to embed the file.
|
||||
public static function logo_file() {
|
||||
// @todo Move the logo filename to a config file
|
||||
return Kohana::find_file(sprintf('media/%s',Config::siteid()),'img/logo-small','png');
|
||||
list ($path,$suffix) = explode('.',static::$logo);
|
||||
return Kohana::find_file(sprintf('media/%s',Config::siteid()),$path,$suffix);
|
||||
}
|
||||
|
||||
public static function logo_uri() {
|
||||
list ($path,$suffix) = explode('.',static::$logo);
|
||||
return Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename()));
|
||||
}
|
||||
|
||||
public static function logo() {
|
||||
// @todo Move the logo filename to a config file
|
||||
$mediapath = Route::get('default/media');
|
||||
$logo = $mediapath->uri(array('file'=>'img/logo-small.png'),array('alt'=>static::sitename()));
|
||||
|
||||
return HTML::image($logo,array('class'=>'headlogo','alt'=>_('Logo')));
|
||||
return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -13,7 +13,7 @@
|
||||
class lnApp_HeadImages extends HTMLRender {
|
||||
protected static $_data = array();
|
||||
protected static $_spacer = ' ';
|
||||
protected static $_required_keys = array('url','img');
|
||||
protected static $_required_keys = array('img');
|
||||
|
||||
/**
|
||||
* Return an instance of this class
|
||||
@@ -35,7 +35,10 @@ class lnApp_HeadImages extends HTMLRender {
|
||||
|
||||
foreach (static::$_data as $value) {
|
||||
$i = HTML::image($mediapath->uri(array('file'=>$value['img'])),array('alt'=>isset($value['attrs']['title']) ? $value['attrs']['title'] : ''));
|
||||
$output .= HTML::anchor($value['url'],$i,(isset($value['attrs']) && is_array($value['attrs'])) ? $value['attrs'] : null);
|
||||
if (isset($value['url']))
|
||||
$output .= HTML::anchor($value['url'],$i,(isset($value['attrs']) && is_array($value['attrs'])) ? $value['attrs'] : null);
|
||||
else
|
||||
$output .= $i;
|
||||
$output .= static::$_spacer;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user