Updated OSB to work with KH 3.1
This commit is contained in:
22
application/classes/auth/orm.php
Normal file
22
application/classes/auth/orm.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's Auth
|
||||
*
|
||||
* @package OSB/Modifications
|
||||
* @category Classes
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Auth_ORM extends Kohana_Auth_ORM {
|
||||
// Override Kohana Auth requirement to have a hash_key
|
||||
public function hash($str) {
|
||||
if ($this->_config['hash_method'] == 'md5')
|
||||
return md5($str);
|
||||
else
|
||||
return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -11,6 +11,14 @@
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class Controller_lnApp_Default extends Controller {
|
||||
/**
|
||||
* The variable that our output is stored in
|
||||
*/
|
||||
protected $output = NULL;
|
||||
/**
|
||||
* @var string page media route as per [Route]
|
||||
*/
|
||||
protected $mediaroute = 'default/media';
|
||||
/**
|
||||
* Controls access to this controller.
|
||||
* Can be set to a string or an array, for example 'login' or array('login', 'admin')
|
||||
@@ -48,8 +56,8 @@ abstract class Controller_lnApp_Default extends Controller {
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in() === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action,$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action]) === FALSE));
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action()]) === FALSE));
|
||||
}
|
||||
|
||||
public function before() {
|
||||
@@ -58,16 +66,16 @@ abstract class Controller_lnApp_Default extends Controller {
|
||||
// Check user auth and role
|
||||
if ($this->_auth_required()) {
|
||||
// For AJAX/JSON requests, authorisation is controlled in the method.
|
||||
if (Request::$is_ajax && $this->request->action === 'json') {
|
||||
if (Request::current()->is_ajax() && $this->request->action() === 'json') {
|
||||
// Nothing required.
|
||||
|
||||
// For no AJAX/JSON requests, display an access page
|
||||
} elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) {
|
||||
Request::instance()->redirect('login/noaccess');
|
||||
Request::current()->redirect('login/noaccess');
|
||||
|
||||
} else {
|
||||
Session::instance()->set('afterlogin',Request::instance()->uri());
|
||||
Request::instance()->redirect($this->noauth_redirect);
|
||||
Session::instance()->set('afterlogin',Request::detect_uri());
|
||||
Request::current()->redirect($this->noauth_redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,26 +16,20 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// If there is a post and $_POST is not empty
|
||||
if ($_POST) {
|
||||
// Instantiate a new user
|
||||
$user = ORM::factory('account');
|
||||
|
||||
// Check Auth
|
||||
$status = $user->login($_POST);
|
||||
|
||||
// If the post data validates using the rules setup in the user model
|
||||
if ($status) {
|
||||
if (Auth::instance()->login($_POST['username'],$_POST['password'])) {
|
||||
// Redirect to the user account
|
||||
if ($redir = Session::instance()->get('afterlogin')) {
|
||||
Session::instance()->delete('afterlogin');
|
||||
Request::instance()->redirect($redir);
|
||||
Request::current()->redirect($redir);
|
||||
|
||||
} else
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
|
||||
} else {
|
||||
SystemMessage::add(array(
|
||||
@@ -53,7 +47,6 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
));
|
||||
|
||||
$this->template->control = HTML::anchor($this->request->uri(),'Login',array('id'=>'ajxbody'));
|
||||
$this->template->content = Block::factory();
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
@@ -66,7 +59,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// Instantiate a new user
|
||||
@@ -112,12 +105,10 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
'title'=>_('Register'),
|
||||
'body'=>View::factory('bregister')
|
||||
->set('account',$account)
|
||||
->set('errors',$account->validate()->errors()),
|
||||
'style'=>array('css/bregister.css'=>'screen'),
|
||||
->set('errors',$account->validation()->errors('form/register')),
|
||||
));
|
||||
|
||||
$this->template->control = HTML::anchor($this->request->uri(),'Register',array('id'=>'ajxbody'));
|
||||
$this->template->content = Block::factory();
|
||||
$this->template->left = HTML::anchor('login','Login').'...';
|
||||
}
|
||||
|
||||
@@ -128,7 +119,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
// Redirect to the user account
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
}
|
||||
|
||||
// If the user posted their details to reset their password
|
||||
@@ -172,7 +163,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
|
||||
// Redirect to our password reset, the Auth will validate the token.
|
||||
} elseif (! empty($_REQUEST['token'])) {
|
||||
Request::instance()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
|
||||
Request::current()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
|
||||
}
|
||||
|
||||
// Show our token screen even if the email was invalid.
|
||||
@@ -183,7 +174,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
else
|
||||
Request::instance()->redirect('login');
|
||||
Request::current()->redirect('login');
|
||||
|
||||
} else {
|
||||
Block::add(array(
|
||||
@@ -192,13 +183,9 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
|
||||
'style'=>array('css/login.css'=>'screen'),
|
||||
));
|
||||
}
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
|
||||
public function action_noaccess() {
|
||||
$this->template->content = ' ';
|
||||
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('No access to requested resource'),
|
||||
'type'=>'error',
|
||||
|
@@ -17,10 +17,10 @@ class Controller_lnApp_Logout extends Controller {
|
||||
if (Auth::instance()->logged_in()!= 0) {
|
||||
Auth::instance()->logout();
|
||||
|
||||
Request::instance()->redirect('login');
|
||||
Request::current()->redirect('login');
|
||||
}
|
||||
|
||||
Request::instance()->redirect('welcome/index');
|
||||
Request::current()->redirect('welcome/index');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -15,10 +15,6 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
* @var string page template
|
||||
*/
|
||||
public $template = 'lnapp/default';
|
||||
/**
|
||||
* @var string page media route as per [Route]
|
||||
*/
|
||||
protected $mediaroute = 'default/media';
|
||||
/**
|
||||
* @var object meta object information as per [meta]
|
||||
*/
|
||||
@@ -62,8 +58,8 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
return FALSE;
|
||||
|
||||
return (($this->auth_required !== FALSE && Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__) === FALSE) ||
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action,$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action],get_class($this).'|'.__METHOD__) === FALSE));
|
||||
(is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) &&
|
||||
Auth::instance()->logged_in($this->secure_actions[$this->request->action()],get_class($this).'|'.__METHOD__) === FALSE));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +70,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
*/
|
||||
public function before() {
|
||||
// Do not template media files
|
||||
if ($this->request->action === 'media') {
|
||||
if ($this->request->action() === 'media') {
|
||||
$this->auto_render = FALSE;
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +80,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
// Check user auth and role
|
||||
if ($this->_auth_required()) {
|
||||
if (Kohana::$is_cli)
|
||||
throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action));
|
||||
throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action()));
|
||||
|
||||
// If auth is required and the user is logged in, then they dont have access.
|
||||
// (We have already checked authorisation.)
|
||||
@@ -93,24 +89,24 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Insufficient Access'),
|
||||
'type'=>'debug',
|
||||
'body'=>Kohana::debug(array('required'=>$this->auth_required,'action'=>$this->request->action,'user'=>Auth::instance()->get_user()->username)),
|
||||
'body'=>Kohana::debug(array('required'=>$this->auth_required,'action'=>$this->request->action(),'user'=>Auth::instance()->get_user()->username)),
|
||||
));
|
||||
|
||||
// @todo Login No Access redirects are not handled in JS?
|
||||
if (Request::$is_ajax) {
|
||||
if ($this->request->is_ajax()) {
|
||||
echo _('You dont have enough permissions.');
|
||||
die();
|
||||
} else
|
||||
Request::instance()->redirect('login/noaccess');
|
||||
Request::current()->redirect('login/noaccess');
|
||||
|
||||
} else {
|
||||
Session::instance()->set('afterlogin',Request::instance()->uri());
|
||||
Request::instance()->redirect($this->noauth_redirect);
|
||||
Session::instance()->set('afterlogin',Request::detect_uri());
|
||||
Request::current()->redirect($this->noauth_redirect);
|
||||
}
|
||||
}
|
||||
|
||||
// For AJAX calls, we dont need to render the complete page.
|
||||
if (Request::$is_ajax) {
|
||||
if ($this->request->is_ajax()) {
|
||||
$this->auto_render = FALSE;
|
||||
return;
|
||||
}
|
||||
@@ -181,20 +177,21 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
$this->template->footer = $this->_footer();
|
||||
|
||||
// For any ajax rendered actions, we'll need to capture the content and put it in the response
|
||||
} elseif (Request::$is_ajax && isset($this->template->content) && ! $this->request->response) {
|
||||
} elseif ($this->request->is_ajax() && isset($this->template->content) && ! $this->response->body()) {
|
||||
// @todo move this formatting to a view?
|
||||
if ($s = $this->_sysmsg() AND (string)$s) {
|
||||
$this->request->response = sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s);
|
||||
} else
|
||||
$this->request->response = '';
|
||||
if ($s = $this->_sysmsg() AND (string)$s)
|
||||
$this->response->body(sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s));
|
||||
|
||||
# In case there any style sheets or scrpits for this render.
|
||||
$this->request->response .= Style::factory();
|
||||
$this->response->bodyadd(Style::factory());
|
||||
|
||||
# Get the response body
|
||||
$this->request->response .= sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content);
|
||||
$this->response->bodyadd(sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content));
|
||||
}
|
||||
|
||||
if (isset($this->template->content) AND ! $this->template->content)
|
||||
$this->template->content = Block::factory();
|
||||
|
||||
parent::after();
|
||||
}
|
||||
|
||||
@@ -244,7 +241,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
*/
|
||||
final public function action_media() {
|
||||
// Generate and check the ETag for this file
|
||||
$this->request->check_cache(sha1($this->request->uri));
|
||||
$this->response->check_cache(NULL,$this->request);
|
||||
|
||||
// Get the file path from the request
|
||||
$file = $this->request->param('file');
|
||||
@@ -258,22 +255,22 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
|
||||
// First try and find media files for the site_id
|
||||
if ($f = Kohana::find_file(sprintf('media/%s',Config::siteid()), $file, $ext)) {
|
||||
// Send the file content as the response
|
||||
$this->request->response = file_get_contents($f);
|
||||
$this->response->body(file_get_contents($f));
|
||||
|
||||
// If not found try a default media file
|
||||
} elseif ($f = Kohana::find_file('media', $file, $ext)) {
|
||||
// Send the file content as the response
|
||||
$this->request->response = file_get_contents($f);
|
||||
$this->response->body(file_get_contents($f));
|
||||
|
||||
} else {
|
||||
// Return a 404 status
|
||||
$this->request->status = 404;
|
||||
$this->response->status(404);
|
||||
}
|
||||
|
||||
// Set the proper headers to allow caching
|
||||
$this->request->headers['Content-Type'] = File::mime_by_ext($ext);
|
||||
$this->request->headers['Content-Length'] = filesize($f);
|
||||
$this->request->headers['Last-Modified'] = date('r', filemtime($f));
|
||||
$this->response->headers('Content-Type',File::mime_by_ext($ext));
|
||||
$this->response->headers('Content-Length',(string)filesize($f));
|
||||
$this->response->headers('Last-Modified',date('r', filemtime($f)));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -11,22 +11,20 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_lnApp_Tree extends Controller_Default {
|
||||
// Our tree data
|
||||
protected $treedata;
|
||||
/**
|
||||
* @var string page media route as per [Route]
|
||||
*/
|
||||
protected static $mediaroute = 'default/media';
|
||||
protected static $jsmediaroute = 'default/media';
|
||||
|
||||
public function after() {
|
||||
parent::after();
|
||||
|
||||
$this->request->headers['Content-Type'] = 'application/json';
|
||||
$this->request->response = sprintf('[%s]',json_encode($this->treedata));
|
||||
$this->response->headers('Content-Type','application/json');
|
||||
$this->response->body(sprintf('[%s]',json_encode($this->output)));
|
||||
}
|
||||
|
||||
public static function js() {
|
||||
$mediapath = Route::get(static::$mediaroute);
|
||||
$mediapath = Route::get(static::$jsmediaroute);
|
||||
|
||||
return '
|
||||
<div id="tree" class=""></div>
|
||||
|
@@ -23,7 +23,7 @@ class Controller_Tree extends Controller_lnApp_Tree {
|
||||
*/
|
||||
public function action_json($id=null) {
|
||||
if ($this->_auth_required()) {
|
||||
$this->treedata = array('attr'=>array('id'=>'a_login'),
|
||||
$this->output = array('attr'=>array('id'=>'a_login'),
|
||||
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('/login'))));
|
||||
|
||||
return;
|
||||
@@ -74,10 +74,10 @@ class Controller_Tree extends Controller_lnApp_Tree {
|
||||
}
|
||||
}
|
||||
|
||||
$this->treedata = array();
|
||||
$this->output = array();
|
||||
|
||||
foreach ($data as $branch) {
|
||||
array_push($this->treedata,array(
|
||||
array_push($this->output,array(
|
||||
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
||||
'state'=>$branch['state'],
|
||||
'data'=>array('title'=>$branch['name']),
|
||||
|
@@ -19,11 +19,8 @@ class Controller_Welcome extends Controller_TemplateDefault {
|
||||
'footer'=>'lnApp makes building websites easy! '.time(),
|
||||
));
|
||||
|
||||
if (Auth::instance()->logged_in()) {
|
||||
$this->template->control = HTML::anchor('/logout',_('Logout'),array('id'=>'ajxbody'));
|
||||
} else {
|
||||
$this->template->control = HTML::anchor('/login',_('Login'),array('id'=>'ajxbody'));
|
||||
|
||||
// @todo Show a login/logout on the breadcrumb
|
||||
if (! Auth::instance()->logged_in()) {
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("#ajxbody").click(function() {$("#ajBODY").load("'.URL::site('/login').'",null,function(x,s,r) {}); return false;});
|
||||
@@ -31,8 +28,6 @@ class Controller_Welcome extends Controller_TemplateDefault {
|
||||
});'
|
||||
));
|
||||
}
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
30
application/classes/db.php
Normal file
30
application/classes/db.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's DB
|
||||
*
|
||||
* @package OSB/Modifications
|
||||
* @category Classes
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class DB extends Kohana_DB {
|
||||
// Add the site_id to the delete query
|
||||
public static function delete($table = NULL)
|
||||
{
|
||||
$db = new Database_Query_Builder_Delete($table);
|
||||
|
||||
return $db->where($table.'.site_id','=',Config::siteid());
|
||||
}
|
||||
|
||||
// Add the site_id to the update query
|
||||
final public static function update($table = NULL)
|
||||
{
|
||||
$db = new Database_Query_Builder_Update($table);
|
||||
|
||||
return $db->where($table.'.site_id','=',Config::siteid());
|
||||
}
|
||||
}
|
||||
?>
|
19
application/classes/form.php
Normal file
19
application/classes/form.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's Form
|
||||
*
|
||||
* @package OSB/Modifications
|
||||
* @category Classes
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Form extends Kohana_Form {
|
||||
// Enable 3.0 features, default to current URI for empty Form::open()
|
||||
public static function open($action = NULL, array $attributes = NULL) {
|
||||
return parent::open(is_null($action) ? Request::detect_uri() : $action,$attributes);
|
||||
}
|
||||
}
|
||||
?>
|
30
application/classes/http/exception/404.php
Normal file
30
application/classes/http/exception/404.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's 404 Exception
|
||||
*
|
||||
* @package OSB/Modifications
|
||||
* @category Classes
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
|
||||
public function __construct($message, array $variables = NULL, $code = 0)
|
||||
{
|
||||
set_exception_handler(array(get_class($this),'handler'));
|
||||
parent::__construct($message, $variables, (int) $code);
|
||||
}
|
||||
|
||||
public static function handler(Exception $e)
|
||||
{
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Page not found'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('The page [%s] you requested was not found?'),Request::detect_uri()),
|
||||
));
|
||||
|
||||
Request::factory()->redirect('/welcome');
|
||||
}
|
||||
}
|
@@ -49,7 +49,7 @@ class lnApp_Breadcrumb extends HTMLRender {
|
||||
protected function render() {
|
||||
$output = HTML::anchor('/',_('Home'));
|
||||
|
||||
$data = empty(static::$_data['path']) ? explode('/',Request::instance()->uri) : static::$_data['path'];
|
||||
$data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path'];
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
$output .= static::$_spacer;
|
||||
|
@@ -11,7 +11,7 @@
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_Config extends Kohana {
|
||||
abstract class lnApp_Config extends Kohana_Config {
|
||||
/**
|
||||
* Return our site name
|
||||
*/
|
||||
|
76
application/classes/orm.php
Normal file
76
application/classes/orm.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's ORM
|
||||
*
|
||||
* @package OSB/Modifications
|
||||
* @category Classes
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class ORM extends Kohana_ORM {
|
||||
protected $_table_names_plural = false;
|
||||
private $_object_formated = array();
|
||||
private $_formated = FALSE;
|
||||
// Our filters used to display values in a friendly format
|
||||
protected $_display_filters = array();
|
||||
|
||||
// Override check() so that it doesnt throw an exception.
|
||||
// @todo Need to figure out how to show the items that fail validation
|
||||
final public function check(Validation $extra_validation = NULL) {
|
||||
// Determine if any external validation failed
|
||||
$extra_errors = ($extra_validation AND ! $extra_validation->check());
|
||||
|
||||
// Always build a new validation object
|
||||
$this->_validation();
|
||||
|
||||
$array = $this->_validation;
|
||||
|
||||
if (($this->_valid = $array->check()) === FALSE OR $extra_errors)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Add our OSB site_id to each SELECT query
|
||||
final protected function _build($type) {
|
||||
$this->where($this->_table_name.'.site_id','=',Config::siteid());
|
||||
|
||||
return parent::_build($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format fields for display purposes
|
||||
*
|
||||
* @param string column name
|
||||
* @return mixed
|
||||
*/
|
||||
private function _format() {
|
||||
foreach ($this->_display_filters as $column => $formats)
|
||||
$this->_object_formated[$column] = $this->run_filter($column,$this->__get($column),array($column=>$formats));
|
||||
|
||||
$this->_formated = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formated columns, as per the model definition
|
||||
*/
|
||||
public function display($column) {
|
||||
// Trigger a load of the record.
|
||||
$value = $this->__get($column);
|
||||
|
||||
// If some of our fields need to be formated for display purposes.
|
||||
if ($this->_loaded AND ! $this->_formated AND $this->_display_filters)
|
||||
$this->_format();
|
||||
|
||||
if (isset($this->_object_formated[$column]))
|
||||
return $this->_object_formated[$column];
|
||||
else
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -15,80 +15,32 @@ abstract class ORMOSB extends ORM {
|
||||
* @var string Database to connect to
|
||||
*/
|
||||
protected $_db = 'default';
|
||||
protected $_object_formated = array();
|
||||
protected $_formated = FALSE;
|
||||
protected $_formats = array();
|
||||
|
||||
/**
|
||||
* @var boolean Database names plural configuration
|
||||
*/
|
||||
protected $_table_names_plural = false;
|
||||
|
||||
protected $_created_column = array('column'=>'date_orig','format'=>TRUE);
|
||||
protected $_updated_column = array('column'=>'date_last','format'=>TRUE);
|
||||
|
||||
protected $_callbacks = array(
|
||||
'id'=>array('get_next_id'),
|
||||
'site_id'=>array('set_site_id'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Format fields for display purposes
|
||||
*
|
||||
* @param string column name
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _format() {
|
||||
$format = Validate::factory($this->_object);
|
||||
|
||||
foreach ($this->_formats as $column => $formats)
|
||||
$format->filters($column,$formats);
|
||||
|
||||
if ($format->check())
|
||||
foreach ($format as $column => $value)
|
||||
$this->_object_formated[$column] = $value;
|
||||
|
||||
$this->_formated = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formated columns, as per the model definition
|
||||
*/
|
||||
public function display($column) {
|
||||
// Trigger a load of the record.
|
||||
$value = $this->__get($column);
|
||||
|
||||
// If some of our fields need to be formated for display purposes.
|
||||
if ($this->_loaded AND ! $this->_formated AND $this->_formats)
|
||||
$this->_format();
|
||||
|
||||
if (isset($this->_object_formated[$column]))
|
||||
return $this->_object_formated[$column];
|
||||
else
|
||||
return $value;
|
||||
// @todo Rules are no longer used?
|
||||
public function rules() {
|
||||
return array(
|
||||
'id'=>array(
|
||||
array('ORMOSB::get_next_id',array(':validation',':model',':field')),
|
||||
),
|
||||
'site_id'=>array(
|
||||
array('ORMOSB::set_site_id',array(':validation',':model',':field')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Our child models should provide an invoice display, this is shown
|
||||
* on printed invoices.
|
||||
*
|
||||
* @todo This is no longer used I think?
|
||||
*/
|
||||
public function invoice_display() {
|
||||
throw new Kohana_Exception(':module has not configured an :method, but has made the call',array(':module'=>get_class($this),'method'=>__METHOD__));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the _load_result() function so that our site ID is automatically
|
||||
* added to the SQL query
|
||||
* @todo This is not picked up by all queries. Need to investigate why
|
||||
* @todo This is not being done by inserts
|
||||
*/
|
||||
protected function _load_result($multiple = FALSE)
|
||||
{
|
||||
$this->_db_builder->where($this->_table_name.'.site_id','=',Config::siteid());
|
||||
|
||||
return parent::_load_result($multiple);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will enhance the [Validate::filter], since it always passes
|
||||
* the value as the first argument and sometimes functions need that to not
|
||||
@@ -105,6 +57,7 @@ abstract class ORMOSB extends ORM {
|
||||
* @param mixed $val Value to be processed
|
||||
* @param string $func Name of function to call
|
||||
* @param string $arg Other arguments for the function
|
||||
* @todo This has probably changed in KH 3.1
|
||||
*/
|
||||
final public static function _filters($val,$func,$arg) {
|
||||
switch ($func) {
|
||||
@@ -121,31 +74,30 @@ abstract class ORMOSB extends ORM {
|
||||
* @param array Validate object
|
||||
* @param string Primary Key
|
||||
*/
|
||||
public function get_next_id(Validate $array,$field) {
|
||||
if (! is_null($array[$field]))
|
||||
public static function get_next_id(Validation $array,$model,$field) {
|
||||
if (! is_null($model->$field))
|
||||
return TRUE;
|
||||
|
||||
$this->_changed[$field] = $field;
|
||||
$model->_changed[$field] = $field;
|
||||
|
||||
$ido = ORM::factory('module')
|
||||
->where('name','=',$this->_table_name)
|
||||
->where('name','=',$model->_table_name)
|
||||
->find();
|
||||
|
||||
if (! $ido->loaded())
|
||||
throw new Kohana_Exception('Problem getting record_id for :table',array(':table'=>$this->_table_name));
|
||||
throw new Kohana_Exception('Problem getting record_id for :table',array(':table'=>$model->_table_name));
|
||||
|
||||
$array[$field] = $ido->record_id->next_id($ido->id);
|
||||
$model->$field = $ido->record_id->next_id($ido->id);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function set_site_id(Validate $array,$field) {
|
||||
if (! is_null($array[$field]))
|
||||
public static function set_site_id(Validation $array,$model,$field) {
|
||||
if (! is_null($model->$field))
|
||||
return TRUE;
|
||||
|
||||
// @todo This should be a config item
|
||||
$this->_changed[$field] = $field;
|
||||
$array[$field] = Config::siteid();
|
||||
$model->_changed[$field] = $field;
|
||||
$model->$field = Config::siteid();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
19
application/classes/response.php
Normal file
19
application/classes/response.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's Response
|
||||
*
|
||||
* @package OSB/Modifications
|
||||
* @category Classes
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Response extends Kohana_Response {
|
||||
// Append to the body.
|
||||
public function bodyadd($content) {
|
||||
$this->_body .= (string) $content;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -9,21 +9,19 @@
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Validate extends Kohana_Validate {
|
||||
class Valid extends Kohana_Valid {
|
||||
/**
|
||||
* Checks if a field matches the value of another field, if it is set.
|
||||
* Field is ignored if it is blank.
|
||||
*
|
||||
* This function is only invoked anyway when the value is set as per
|
||||
* $this->_empty_rules
|
||||
*
|
||||
* @param string field value
|
||||
* @param array array of values
|
||||
* @param string field name
|
||||
* @param string field name to match
|
||||
* @return boolean
|
||||
*/
|
||||
protected function matches_ifset($value, $match)
|
||||
{
|
||||
return ($value === $this[$match]);
|
||||
public static function matches_ifset($array, $field, $match)
|
||||
{
|
||||
return isset($array[$match]) ? ($array[$field] === $array[$match]) : TRUE;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -9,12 +9,12 @@
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
|
||||
return array(
|
||||
'driver' => 'OSB',
|
||||
'hash_method' => 'md5',
|
||||
'salt_pattern' => null,
|
||||
'hash_key' => '',
|
||||
'lifetime' => 1209600,
|
||||
'session_key' => 'auth_user',
|
||||
'forced_key' => 'auth_forced',
|
||||
);
|
||||
?>
|
||||
|
Reference in New Issue
Block a user