Updated OSB to work with KH 3.1

This commit is contained in:
Deon George
2011-05-14 17:35:33 +10:00
parent 6d256839fc
commit 9dda9f43f4
42 changed files with 397 additions and 347 deletions

View File

@@ -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)));
}
}
?>