From c1b1485c10bf91f89a556273820b1411bc2d1150 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 25 Aug 2014 14:41:07 +1000 Subject: [PATCH] Updated for new lnApp --- application/bootstrap.php | 2 +- application/classes/Company.php | 8 - application/classes/Config.php | 82 -------- application/classes/Controller/Debug.php | 36 ---- application/classes/Kohana.php | 6 +- application/classes/Model/Account.php | 4 +- application/classes/Model/Account/Log.php | 2 +- application/classes/Model/Setup.php | 5 + application/classes/ORM/OSB.php | 188 ------------------ application/classes/Period.php | 2 +- application/classes/Site.php | 39 ++++ application/classes/StaticList.php | 66 ------ application/classes/StaticList/YesNo.php | 29 --- application/classes/URL.php | 42 ++++ application/config/debug.php | 3 - application/media/js/custom.js | 0 application/views/theme/baseadmin/page.php | 28 +-- .../classes/Model/Service/Plugin/Adsl.php | 12 +- modules/charge/classes/Model/Charge.php | 4 +- .../classes/Model/Checkout/Notify.php | 6 +- .../classes/Model/Service/Plugin/Domain.php | 4 +- modules/email/classes/Email/Template.php | 6 +- modules/email/classes/Model/Email/Log.php | 6 +- .../classes/Controller/Reseller/Export.php | 2 +- .../export/classes/Model/Export/DataMap.php | 4 + .../export/classes/Model/Export/Module.php | 4 + .../classes/Model/Service/Plugin/Host.php | 2 +- modules/invoice/classes/Model/Invoice.php | 8 +- .../invoice/classes/Model/Invoice/Item.php | 8 +- .../invoice/classes/Model/Invoice/Memo.php | 6 +- modules/oauth/classes/Model/Account/Oauth.php | 4 + modules/payment/classes/Model/Payment.php | 6 +- modules/product/classes/Model/Product.php | 9 +- .../classes/Model/Product/Category.php | 2 +- .../Model/Product/Category/Translate.php | 4 + .../classes/Model/Product/Translate.php | 4 + .../classes/Controller/Admin/Service.php | 6 +- modules/service/classes/Model/Service.php | 14 +- .../service/classes/Model/Service/Change.php | 4 +- .../service/classes/Model/Service/Memo.php | 6 +- modules/service/views/service/admin/add.php | 2 +- modules/ssl/classes/SSL.php | 4 +- modules/task/classes/Model/Task.php | 4 +- modules/task/classes/Model/Task/Log.php | 6 +- 44 files changed, 208 insertions(+), 481 deletions(-) delete mode 100644 application/classes/Controller/Debug.php create mode 100644 application/classes/Site.php delete mode 100644 application/classes/StaticList.php delete mode 100644 application/classes/StaticList/YesNo.php create mode 100644 application/classes/URL.php delete mode 100644 application/media/js/custom.js diff --git a/application/bootstrap.php b/application/bootstrap.php index dbe25e5b..e06af2f9 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -115,7 +115,7 @@ Kohana::$config->attach(new Config_File); * Enable modules. Modules are referenced by a relative or absolute path. */ Kohana::modules(array( - 'lnapp' => MODPATH.'lnApp', // lnApp Base Application Tools + 'lnapp' => MODPATH.'lnapp', // lnApp Base Application Tools 'oauth' => MODPATH.'oauth', // OAuth Module for External Authentication 'auth' => SMDPATH.'auth', // Basic authentication 'cache' => SMDPATH.'cache', // Caching with multiple backends diff --git a/application/classes/Company.php b/application/classes/Company.php index dd0dc4f3..93de1d45 100644 --- a/application/classes/Company.php +++ b/application/classes/Company.php @@ -77,10 +77,6 @@ class Company { return $this->so->language; } - public function logo() { - return Config::logo(); - } - public function logo_file() { list ($path,$suffix) = explode('.',Config::$logo); @@ -119,10 +115,6 @@ class Company { return $this->so->site_details('address2') ? implode($ln,array($this->so->site_details('address1'),$this->so->site_details('address2'))) : $this->so->site_details('address1'); } - public function sitemode() { - return $this->so->status; - } - public function taxid() { // Tax ID details are stored in invoice config $mc = $this->so->module_config('invoice'); diff --git a/application/classes/Config.php b/application/classes/Config.php index 387d864b..03732e9a 100644 --- a/application/classes/Config.php +++ b/application/classes/Config.php @@ -49,62 +49,10 @@ class Config extends Kohana_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(); - } - - /** - * Show a date using a site configured format - */ - public static function date($date) { - return (is_null($date) OR ! $date) ? '' : date(Company::instance()->date_format(),$date); - } - - /** - * Show a date using a site configured format - * @note We need this function here, since we call self:: methods, which need to resolve to the child class. - */ - public static function datetime($date) { - return sprintf('%s %s',self::date($date),self::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 something else - */ - 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 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(self::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo'))); - } - - public static function logo_uri($protocol=NULL) { - list ($path,$suffix) = explode('.',self::$logo); - - return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>self::sitename())),$protocol); - } - /** * Find a list of all database enabled modules * @@ -141,24 +89,6 @@ class Config extends Kohana_Config { return array_key_exists(strtolower($module),self::modules()) ? TRUE : FALSE; } - /** - * Work out our site ID for multiehosting - */ - public static function siteid($format=FALSE) { - return Company::instance()->site($format); - } - - /** - * Work out our site mode (dev,test,prod) - */ - public static function sitemode() { - return Company::instance()->sitemode(); - } - - public static function sitename() { - return Company::instance()->name(); - } - /** * See if our emails for the template should be sent to configured admin(s) * @@ -173,17 +103,5 @@ class Config extends Kohana_Config { else return $config[$template]; } - - public static function theme() { - // If we are using user admin pages (and login), we'll choose the admin theme. - return 'theme/'.(URL::admin_url() ? Kohana::$config->load('config')->theme_admin : Kohana::$config->load('config')->theme); - } - - /** - * Show a date using a site configured format - */ - public static function time($date) { - return date(Company::instance()->time_format(),($date ? $date : time())); - } } ?> diff --git a/application/classes/Controller/Debug.php b/application/classes/Controller/Debug.php deleted file mode 100644 index bf24b47c..00000000 --- a/application/classes/Controller/Debug.php +++ /dev/null @@ -1,36 +0,0 @@ -__METHOD__, - 'site'=>Config::site(), - 'siteID'=>Company::instance()->site(), - 'siteMode'=>Config::sitemodeverbose(), - 'modules'=>Config::appmodules(), - )); - - Block::add(array( - 'title'=>_('Site debug'), - 'body'=>$output, - )); - } -} -?> diff --git a/application/classes/Kohana.php b/application/classes/Kohana.php index c8ab0e21..921e1f25 100644 --- a/application/classes/Kohana.php +++ b/application/classes/Kohana.php @@ -37,9 +37,9 @@ abstract class Kohana extends Kohana_Core { $prefixes = array(''); // Our search order. - array_unshift($prefixes,Config::theme().'/'); - array_unshift($prefixes,sprintf('site/%s/',Config::siteid())); - array_unshift($prefixes,sprintf('site/%s/%s/',Config::siteid(),Config::theme())); + array_unshift($prefixes,Site::Theme().'/'); + array_unshift($prefixes,sprintf('site/%s/',Site::ID())); + array_unshift($prefixes,sprintf('site/%s/%s/',Site::ID(),Site::Theme())); foreach ($prefixes as $p) if ($x = parent::find_file($dir,$p.$file,$ext,$array)) diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php index e6195980..e8fe2fdb 100644 --- a/application/classes/Model/Account.php +++ b/application/classes/Model/Account.php @@ -29,10 +29,10 @@ class Model_Account extends Model_Auth_UserDefault { protected $_display_filters = array( 'date_orig'=>array( - array('Config::date',array(':value')), + array('Site::Date',array(':value')), ), 'date_last'=>array( - array('Config::date',array(':value')), + array('Site::Date',array(':value')), ), 'status'=>array( array('StaticList_YesNo::get',array(':value',TRUE)), diff --git a/application/classes/Model/Account/Log.php b/application/classes/Model/Account/Log.php index 8bd9206d..a5aa201e 100644 --- a/application/classes/Model/Account/Log.php +++ b/application/classes/Model/Account/Log.php @@ -20,7 +20,7 @@ class Model_Account_Log extends ORM_OSB { protected $_display_filters = array( 'date_orig'=>array( - array('Config::datetime',array(':value')), + array('Site::Datetime',array(':value')), ), ); } diff --git a/application/classes/Model/Setup.php b/application/classes/Model/Setup.php index 1bf70a67..9c68c725 100644 --- a/application/classes/Model/Setup.php +++ b/application/classes/Model/Setup.php @@ -22,6 +22,11 @@ class Model_Setup extends ORM_OSB { 'language'=>array('foreign_key'=>'id','far_key'=>'language_id'), ); + protected $_compress_column = array( + 'module_config', + 'site_details', + ); + protected $_save_message = TRUE; // Validation rules diff --git a/application/classes/ORM/OSB.php b/application/classes/ORM/OSB.php index 9e94ce45..f7ddc572 100644 --- a/application/classes/ORM/OSB.php +++ b/application/classes/ORM/OSB.php @@ -15,23 +15,6 @@ abstract class ORM_OSB extends ORM { */ protected $_db = 'default'; - protected $_created_column = array('column'=>'date_orig','format'=>TRUE); - protected $_updated_column = array('column'=>'date_last','format'=>TRUE); - - // Our attributes used in forms. - protected $_form = array(); - - // Our attributes that should be converted to NULL when empty - protected $_nullifempty = array(); - - // Our attribute values that need to be stored as serialized - protected $_serialize_column = array(); - - // If we need to load any sub items on loading this model - protected $_sub_items = array(); - protected $_sub_items_load = array(); - protected $_sub_items_sorted = FALSE; - // Rules to assist with site ID and getting next record ID for inserts. public function rules() { return array( @@ -44,136 +27,12 @@ abstract class ORM_OSB extends ORM { ); } - /** - * Retrieve and Store DB BLOB data. - */ - private function _blob($data,$set=FALSE) { - try { - return $set ? gzcompress($this->_serialize($data,$set)) : $this->_serialize(gzuncompress($data)); - - // Maybe the data isnt compressed? - } catch (Exception $e) { - return $this->_serialize($data,$set); - } - } - - /** - * Auto process some data as it comes from the database - * @see parent::__get() - */ - public function __get($column) { - if (array_key_exists($column,$this->_table_columns)) { - // If the column is a blob, we'll decode it automatically - if ( - $this->_table_columns[$column]['data_type'] == 'blob' - AND ! is_null($this->_object[$column]) - AND ! isset($this->_changed[$column]) - AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert']) - ) { - - // In case our blob hasnt been saved as one. - try { - $this->_object[$column] = $this->_blob($this->_object[$column]); - } - catch(Exception $e) { - HTTP_Exception::factory(501,Kohana_Exception::text($e)); - } - - $this->_table_columns[$column]['auto_convert'] = TRUE; - } - - // If the column is a serialized object, we'll unserialize it. - if ( - in_array($column,$this->_serialize_column) - AND is_string($this->_object[$column]) - AND ! is_null($this->_object[$column]) - AND ! isset($this->_changed[$column]) - AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized']) - ) { - - // In case our object hasnt been saved as serialized. - try { - $this->_object[$column] = unserialize($this->_object[$column]); - } - catch(Exception $e) { - HTTP_Exception::factory(501,Kohana_Exception::text($e)); - } - - $this->_table_columns[$column]['unserialized'] = TRUE; - } - } - - return parent::__get($column); - } - - /** - * Intercept our object load, so that we can load our subitems - */ - protected function _load_values(array $values) { - parent::_load_values($values); - - $sort = FALSE; - if ($this->_loaded AND $this->_sub_items_load AND count($this->_sub_items_load) == 1) - foreach ($this->_sub_items_load as $item => $sort) - $this->_sub_items = $this->$item->find_all()->as_array(); - - if ($sort) { - Sort::MAsort($this->_sub_items,$sort); - $this->_sub_items_sorted = TRUE; - } - - return $this; - } - - /** - * If a column is marked to be nullified if it is empty, this is where it is done. - */ - private function _nullifempty(array $array) { - foreach ($array as $k=>$v) { - if (is_array($v)) { - if (is_null($x=$this->_nullifempty($v))) - unset($array[$k]); - else - $array[$k] = $x; - - } elseif (! $v AND $v !== 0 AND $v !== '0') - unset($array[$k]); - - } - - return count($array) ? $array : NULL; - } - - /** - * Try and (un)serialize our data, and if it fails, just return it. - */ - private function _serialize($data,$set=FALSE) { - try { - return $set ? serialize($data) : unserialize($data); - - // Maybe the data serialized? - } catch (Exception $e) { - return $data; - } - } - public function config($key) { $mc = Config::instance()->module_config($this->_object_name); return empty($mc[$key]) ? '' : $mc[$key]; } - public function dump() { - $result = array(); - - $result['this'] = $this->object(); - - foreach ($this->_sub_items as $o) - $result['sub'][] = $o->dump(); - - return $result; - } - /** * Get Next record id * @@ -209,31 +68,6 @@ abstract class ORM_OSB extends ORM { return ORM::factory('Module',array('name'=>$this->_table_name)); } - public function save(Validation $validation=NULL) { - // Find any fields that have changed, and process them. - if ($this->_changed) - foreach ($this->_changed as $c) { - // Any fields that are blobs, and encode them. - if (! is_null($this->_object[$c]) AND $this->_table_columns[$c]['data_type'] == 'blob') { - $this->_object[$c] = $this->_blob($this->_object[$c],TRUE); - - // We need to reset our auto_convert flag - if (isset($this->_table_columns[$c]['auto_convert'])) - $this->_table_columns[$c]['auto_convert'] = FALSE; - - // Any fields that should be seriailzed, we'll do that. - } elseif (is_array($this->_object[$c]) AND in_array($c,$this->_serialize_column)) { - $this->_object[$c] = serialize($this->_object[$c]); - } - - // Test if the value has still changed - if ($this->_original_values AND $this->_object[$c] == $this->_original_values[$c]) - unset($this->_changed[$c]); - } - - return parent::save($validation); - } - /** * Set the site ID attribute for each row update */ @@ -247,28 +81,6 @@ abstract class ORM_OSB extends ORM { return TRUE; } - public function subitems() { - return $this->_sub_items; - } - - /** - * Override the Kohana processing so we can null values if required. - */ - public function values(array $values,array $expected=NULL) { - foreach ($values as $k=>$v) { - // Convert to NULL - if (in_array($k,$this->_nullifempty)) { - if (is_array($v)) - $values[$k] = $this->_nullifempty($v); - - elseif (! $v AND $v !== 0 AND $v !== '0') - $values[$k] = NULL; - } - } - - return parent::values($values,$expected); - } - /** * Function help to find records that are active */ diff --git a/application/classes/Period.php b/application/classes/Period.php index ee199795..40fea494 100644 --- a/application/classes/Period.php +++ b/application/classes/Period.php @@ -118,7 +118,7 @@ class Period { if ($df) foreach (array('start','date','end') as $key) - $result[$key] = Config::date($result[$key]); + $result[$key] = Site::Date($result[$key]); return $result; } diff --git a/application/classes/Site.php b/application/classes/Site.php new file mode 100644 index 00000000..59254222 --- /dev/null +++ b/application/classes/Site.php @@ -0,0 +1,39 @@ +date_format(),$date); + } + + /** + * Work out our site ID for multihosting + */ + public static function ID($format=FALSE) { + return Company::instance()->site($format); + } + + public static function Theme() { + // If we are using user admin pages (and login), we'll choose the admin theme. + return 'theme/'.(URL::admin_url() ? Kohana::$config->load('config')->theme_admin : Kohana::$config->load('config')->theme); + } + + /** + * Show a date using a site configured format + */ + public static function Time($date) { + return date(Company::instance()->time_format(),($date ? $date : time())); + } +} +?> diff --git a/application/classes/StaticList.php b/application/classes/StaticList.php deleted file mode 100644 index b51b009f..00000000 --- a/application/classes/StaticList.php +++ /dev/null @@ -1,66 +0,0 @@ -_table(); - - if (! $table) - return 'No Table'; - elseif (! $id AND empty($table[$id])) - return ''; - elseif (empty($table[$id])) - return sprintf('No Value (%s)',$id); - else - return $table[$id]; - } - - /** - * Setup our class instantiation - * @note This must be declared in the child class due to static scope - */ - public static function factory() { - $x = get_called_class(); - - return new $x; - } - - /** - * Renders form input - * - * @param string Form name to render - * @param string Default value to populate in the Form input. - */ - public static function form($name,$default='',$addblank=FALSE,array $attributes=NULL) { - $table = self::factory()->_table(); - - if ($addblank) - $table = array_merge(array(''=>' '),$table); - - return Form::Select($name,$table,$default,$attributes); - } - - /** - * Lists our available keys - */ - public static function keys() { - return array_keys(self::factory()->_table()); - } - - public static function table() { - return self::factory()->_table(); - } -} -?> diff --git a/application/classes/StaticList/YesNo.php b/application/classes/StaticList/YesNo.php deleted file mode 100644 index e684f0e3..00000000 --- a/application/classes/StaticList/YesNo.php +++ /dev/null @@ -1,29 +0,0 @@ -_('No'), - 1=>_('Yes'), - ); - } - - public static function get($value,$format=FALSE) { - if (! $value) - $value = 0; - - return $format ? View::factory(Config::theme().'/label/bool') - ->set('label',$value ? 'label-success' : '') - ->set('column',self::factory()->_get($value)) : $value; - } -} -?> diff --git a/application/classes/URL.php b/application/classes/URL.php new file mode 100644 index 00000000..b469dcf3 --- /dev/null +++ b/application/classes/URL.php @@ -0,0 +1,42 @@ +'a', + 'reseller'=>'r', + 'affiliate'=>'f', + 'user'=>'u', + ); + + public static function navbar() { + $result = array(); + + foreach (array_reverse(self::$method_directory) as $k=>$v) + switch ($k) { + case 'admin': $result[$k] = array('name'=>'Administrator','icon'=>'icon-globe'); + break; + + case 'affiliate': + case 'reseller': $result[$k] = array('name'=>'Reseller','icon'=>'icon-th-list'); + break; + + case 'user': $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'icon-user'); + break; + + default: $result[$k] = array('name'=>$k,'icon'=>'icon-question-sign'); + } + + return $result; + } +} +?> diff --git a/application/config/debug.php b/application/config/debug.php index 54d97f36..e486a0de 100644 --- a/application/config/debug.php +++ b/application/config/debug.php @@ -12,8 +12,6 @@ return array ( - 'ajax'=>FALSE, // AJAX actions can only be run by ajax calls if set to FALSE - 'etag'=>FALSE, // Force generating ETAGS 'checkout_notify'=>FALSE, // Test mode to test a particular checkout_notify item 'disabled_noaccess_redirect'=>FALSE, // Disable redirect when noaccess 'email_admin_only'=> array( // Override emails and send them to an admin instead @@ -23,7 +21,6 @@ return array // 'deon@leenooks.net'=>'Deon George', ), 'invoice'=>0, // Number of invoices to generate in a pass - 'site'=>FALSE, // Glogal site debug 'show_errors'=>FALSE, // Show errors instead of logging in the DB. 'show_inactive'=>FALSE, // Show Inactive Items 'task_sim'=>FALSE, // Simulate running tasks diff --git a/application/media/js/custom.js b/application/media/js/custom.js deleted file mode 100644 index e69de29b..00000000 diff --git a/application/views/theme/baseadmin/page.php b/application/views/theme/baseadmin/page.php index 896a084e..41ad8b12 100644 --- a/application/views/theme/baseadmin/page.php +++ b/application/views/theme/baseadmin/page.php @@ -1,7 +1,7 @@ - <?php echo $meta->title; ?> + <?php echo Site::Appname(); ?> @@ -19,12 +19,12 @@ echo HTML::style('media/theme/bootstrap/css/bootstrap-responsive.min.css'); echo HTML::style('media/vendor/font-awesome/css/font-awesome.min.css'); } else { - echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css'); - echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css'); - echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css'); + echo HTML::style(Site::Protocol('netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css')); + echo HTML::style(Site::Protocol('netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css')); + echo HTML::style(Site::Protocol('netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css')); } - echo HTML::style($meta->secure().'fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800'); + echo HTML::style(Site::Protocol('fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800')); echo HTML::style('media/css/ui-lightness/jquery-ui-1.10.0.custom.min.css'); echo HTML::style('media/theme/baseadmin/css/base-admin-2.css'); echo HTML::style('media/theme/baseadmin/css/base-admin-2-responsive.css'); @@ -39,13 +39,14 @@