diff --git a/application/classes/config.php b/application/classes/config.php index 9ad3bb00..8ac52fe2 100644 --- a/application/classes/config.php +++ b/application/classes/config.php @@ -1,6 +1,27 @@ so AND $this->so->loaded()) + return $this; + + $this->so = ORM::factory('setup',array('nonssl_url'=>URL::base('http'))); + + if (! $this->so->loaded()) + throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http'))); + + return $this; + } + /** * Find a list of all database enabled modules * diff --git a/application/classes/controller/templatedefault.php b/application/classes/controller/templatedefault.php index b6d6e5e3..881ed40c 100644 --- a/application/classes/controller/templatedefault.php +++ b/application/classes/controller/templatedefault.php @@ -11,6 +11,18 @@ * @license http://dev.leenooks.net/license.html */ class Controller_TemplateDefault extends Controller_lnApp_TemplateDefault { + protected function _headimages() { + // This is where we should be able to change our country + // @todo To implement + $co = Config::instance()->so->country; + HeadImages::add(array( + 'img'=>sprintf('img/country/%s.png',strtolower($co->two_code)), + 'attrs'=>array('onclick'=>"target='_blank';",'title'=>$co->display('name')) + )); + + return HeadImages::factory(); + } + protected function _left() { if ($this->template->left) return $this->template->left; diff --git a/application/classes/lnapp/config.php b/application/classes/lnapp/config.php index 7bc3d8fe..a373084a 100644 --- a/application/classes/lnapp/config.php +++ b/application/classes/lnapp/config.php @@ -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'))); } /** diff --git a/application/classes/lnapp/headimages.php b/application/classes/lnapp/headimages.php index 21f3ac77..6e0751fb 100644 --- a/application/classes/lnapp/headimages.php +++ b/application/classes/lnapp/headimages.php @@ -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; } diff --git a/application/classes/orm.php b/application/classes/orm.php index b9389a67..a46197c9 100644 --- a/application/classes/orm.php +++ b/application/classes/orm.php @@ -39,7 +39,9 @@ class ORM extends Kohana_ORM { // Add our OSB site_id to each SELECT query final protected function _build($type) { - $this->where($this->_table_name.'.site_id','=',Config::siteid()); + // Exclude tables without site ID's + if (! in_array($this->_table_name,array('setup','country','currency','tax'))) + $this->where($this->_table_name.'.site_id','=',Config::siteid()); return parent::_build($type); } diff --git a/modules/core/database.inc.php b/modules/core/database.inc.php index ea3dc698..fd8aa454 100644 --- a/modules/core/database.inc.php +++ b/modules/core/database.inc.php @@ -223,7 +223,10 @@ function sqlConditions($db,$Conditions=false,$Tables=false) { # Add the SITE ID if (! is_array($Tables) || count($Tables) == 1) { - $where .= sprintf('site_id=%s',DEFAULT_SITE); + if ($Tables == 'setup') + $where .= sprintf('id=%s',DEFAULT_SITE); + else + $where .= sprintf('site_id=%s',DEFAULT_SITE); } else { $tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V');