Updates from lnApp

This commit is contained in:
Deon George
2011-07-14 08:59:32 +10:00
parent 5c9750e957
commit 46c3b9a075
31 changed files with 991 additions and 434 deletions

View File

@@ -82,6 +82,8 @@ if (isset($_SERVER['KOHANA_ENV']))
Kohana::init(array(
'base_url' => '/osb',
'index_file' => '',
'caching' => TRUE,
'cache_dir' => '/dev/shm/lnapp',
));
/**
@@ -124,16 +126,6 @@ Route::set('sections', '<directory>/<controller>(/<action>(/<id>(/<sid>)))',
'directory' => '('.implode('|',Kohana::config('config.method_directory')).')'
));
/**
* Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI.
*/
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
// Static file serving (CSS, JS, images)
Route::set('default/media', 'media(/<file>)', array('file' => '.+'))
->defaults(array(
@@ -141,3 +133,14 @@ Route::set('default/media', 'media(/<file>)', array('file' => '.+'))
'action' => 'media',
'file' => NULL,
));
/**
* Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI.
*/
Route::set('default', '(<controller>(/<action>(/<id>)))', array('id' => '[a-zA-Z0-9_.-]+'))
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
?>

View File

@@ -3,9 +3,9 @@
/**
* This class overrides Kohana's Auth
*
* @package OSB/Modifications
* @category Classes
* @category Helpers
* @package lnApp/Modifications
* @subpackage Auth
* @category Overrides
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
@@ -13,10 +13,11 @@
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']);
switch ($this->_config['hash_method']) {
case '' : return $str;
case 'md5': return md5($str);
default: return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
}
}
}
?>

View File

@@ -79,5 +79,12 @@ abstract class Controller_lnApp_Default extends Controller {
}
}
}
public function after() {
parent::after();
// Generate and check the ETag for this file
$this->response->check_cache(NULL,$this->request);
}
}
?>

View File

@@ -12,6 +12,8 @@
* @also [logout]
*/
class Controller_lnApp_Login extends Controller_TemplateDefault {
protected $auth_required = FALSE;
public function action_index() {
// If user already signed-in
if (Auth::instance()->logged_in()!= 0) {
@@ -21,6 +23,10 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
// If there is a post and $_POST is not empty
if ($_POST) {
// Store our details in a session key
Session::instance()->set(Kohana::config('auth.session_key'),$_POST['username']);
Session::instance()->set('password',$_POST['password']);
// If the post data validates using the rules setup in the user model
if (Auth::instance()->login($_POST['username'],$_POST['password'])) {
// Redirect to the user account
@@ -46,8 +52,6 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
'style'=>array('css/login.css'=>'screen'),
));
$this->template->control = HTML::anchor($this->request->uri(),'Login',array('id'=>'ajxbody'));
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("#ajxbody").click(function() {$("#ajBODY").load("'.$this->request->uri().'/"); return false;});
@@ -71,7 +75,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
$status = $account->values($_POST)->check();
if (! $status) {
foreach ($account->validate()->errors() as $f=>$r) {
foreach ($account->validation()->errors('form/register') as $f => $r) {
// $r[0] has our reason for validation failure
switch ($r[0]) {
// Generic validation reason
@@ -79,7 +83,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
SystemMessage::add(array(
'title'=>_('Validation failed'),
'type'=>'error',
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r[0])
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r)
));
}
}
@@ -108,7 +112,6 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
->set('errors',$account->validation()->errors('form/register')),
));
$this->template->control = HTML::anchor($this->request->uri(),'Register',array('id'=>'ajxbody'));
$this->template->left = HTML::anchor('login','Login').'...';
}

View File

@@ -144,6 +144,9 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
}
public function after() {
if (! is_string($this->template) AND empty($this->template->content))
$this->template->content = Block::factory();
if ($this->auto_render) {
// Application Title
$this->meta->title = 'Application Title';
@@ -189,10 +192,10 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
$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();
// Generate and check the ETag for this file
$this->response->check_cache(NULL,$this->request);
}
/**
@@ -240,9 +243,6 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
* @return void
*/
final public function action_media() {
// Generate and check the ETag for this file
$this->response->check_cache(NULL,$this->request);
// Get the file path from the request
$file = $this->request->param('file');
@@ -251,9 +251,14 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
// Remove the extension from the filename
$file = substr($file, 0, -(strlen($ext) + 1));
$f = '';
// If our file is pathed with session, our file is in our session.
if ($fd = Session::instance()->get_once($this->request->param('file'))) {
$this->response->body($fd);
// First try and find media files for the site_id
if ($f = Kohana::find_file(sprintf('media/%s',Config::siteid()), $file, $ext)) {
} elseif ($f = Kohana::find_file(sprintf('media/%s',Config::siteid()), $file, $ext)) {
// Send the file content as the response
$this->response->body(file_get_contents($f));
@@ -267,10 +272,13 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
$this->response->status(404);
}
// Generate and check the ETag for this file
$this->response->check_cache(NULL,$this->request);
// Set the proper headers to allow caching
$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)));
$this->response->headers('Content-Length',(string)$this->response->content_length());
$this->response->headers('Last-Modified',date('r', $f ? filemtime($f) : time()));
}
}
?>

View File

@@ -83,20 +83,18 @@ $(function () {
*
* @param id
*/
public function action_json($id=null) {
#if (! Auth::instance()->logged_in()) {
if ($this->_auth_required()) {
$this->treedata = array('attr'=>array('id'=>'a_login'),
public function action_json($id=null,array $data=array()) {
if ($this->_auth_required() AND ! Auth::instance()->logged_in()) {
$this->output = array('attr'=>array('id'=>'a_login'),
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('/login'))));
return;
}
$this->treedata = array();
$data = 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']),

View File

@@ -21,14 +21,7 @@ class Controller_Tree extends Controller_lnApp_Tree {
*
* @param id
*/
public function action_json($id=null) {
if ($this->_auth_required()) {
$this->output = array('attr'=>array('id'=>'a_login'),
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('/login'))));
return;
}
public function action_json($id=null,array $data=array()) {
// Get the user details
$id = (is_null($id) && isset($_REQUEST['id'])) ? substr($_REQUEST['id'],2) : $id;
$user = Auth::instance()->get_user();
@@ -85,6 +78,8 @@ class Controller_Tree extends Controller_lnApp_Tree {
)
);
}
return parent::action_json($id,$data);
}
}
?>

View File

@@ -1,9 +1,9 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Main home page
* lnApp Main home page
*
* @package OSB
* @package lnApp
* @subpackage Page/Home
* @category Controllers
* @author Deon George
@@ -11,6 +11,8 @@
* @license http://dev.leenooks.net/license.html
*/
class Controller_Welcome extends Controller_TemplateDefault {
protected $auth_required = FALSE;
public function action_index() {
Block::add(array(
'title'=>'Welcome to lnApp (public)!',

View File

@@ -3,7 +3,7 @@
/**
* This class overrides Kohana's Form
*
* @package OSB/Modifications
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class HTML extends lnApp_HTML {}
?>

View File

@@ -3,7 +3,7 @@
/**
* This class overrides Kohana's 404 Exception
*
* @package OSB/Modifications
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
@@ -25,6 +25,6 @@ class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
'body'=>sprintf(_('The page [%s] you requested was not found?'),Request::detect_uri()),
));
Request::factory()->redirect('/welcome');
Request::factory()->redirect('welcome');
}
}

View File

@@ -0,0 +1,21 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends Kohana's HTML
*
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class lnApp_HTML extends Kohana_HTML {
public static function nbsp($string) {
if (strlen((string)$string))
return $string;
else
return '&nbsp;';
}
}
?>

View File

@@ -0,0 +1,105 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is used to sort multiple dimension arrays.
*
* @package lnApp
* @subpackage Sort
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
* @uses Style
*/
class lnApp_Sort {
/**
* Sort a multi dimensional array.
*
* @param array Multi demension array passed by reference
* @param string Comma delimited string of sort keys.
* @param boolean Whether to reverse sort.
* @return array Sorted multi demension array.
*/
public static function masort(&$data,$sortby,$rev=0) {
// if the array to sort is null or empty
if (! $data)
return;
static $MASORT_CACHE = array();
if (empty($MASORT_CACHE[$sortby])) {
$code = "\$c=0;\n";
foreach (explode(',',$sortby) as $key) {
$code .= "if (is_object(\$a) || is_object(\$b)) {\n";
$code .= " if (is_array(\$a->$key)) {\n";
$code .= " asort(\$a->$key);\n";
$code .= " \$aa = array_shift(\$a->$key);\n";
$code .= " } else\n";
$code .= " \$aa = \$a->$key;\n";
$code .= " if (is_array(\$b->$key)) {\n";
$code .= " asort(\$b->$key);\n";
$code .= " \$bb = array_shift(\$b->$key);\n";
$code .= " } else\n";
$code .= " \$bb = \$b->$key;\n";
$code .= " if (\$aa != \$bb)";
if ($rev)
$code .= " return (\$aa < \$bb ? 1 : -1);\n";
else
$code .= " return (\$aa > \$bb ? 1 : -1);\n";
$code .= "} else {\n";
$code .= " \$a = array_change_key_case(\$a);\n";
$code .= " \$b = array_change_key_case(\$b);\n";
$key = strtolower($key);
$code .= " if ((! isset(\$a['$key'])) && isset(\$b['$key'])) return 1;\n";
$code .= " if (isset(\$a['$key']) && (! isset(\$b['$key']))) return -1;\n";
$code .= " if ((isset(\$a['$key'])) && (isset(\$b['$key']))) {\n";
$code .= " if (is_array(\$a['$key'])) {\n";
$code .= " asort(\$a['$key']);\n";
$code .= " \$aa = array_shift(\$a['$key']);\n";
$code .= " } else\n";
$code .= " \$aa = \$a['$key'];\n";
$code .= " if (is_array(\$b['$key'])) {\n";
$code .= " asort(\$b['$key']);\n";
$code .= " \$bb = array_shift(\$b['$key']);\n";
$code .= " } else\n";
$code .= " \$bb = \$b['$key'];\n";
$code .= " if (\$aa != \$bb)\n";
$code .= " if (is_numeric(\$aa) && is_numeric(\$bb)) {\n";
if ($rev)
$code .= " return (\$aa < \$bb ? 1 : -1);\n";
else
$code .= " return (\$aa > \$bb ? 1 : -1);\n";
$code .= " } else {\n";
if ($rev)
$code .= " if ( (\$c = strcasecmp(\$bb,\$aa)) != 0 ) return \$c;\n";
else
$code .= " if ( (\$c = strcasecmp(\$aa,\$bb)) != 0 ) return \$c;\n";
$code .= " }\n";
$code .= " }\n";
$code .= "}\n";
}
$code .= 'return $c;';
$MASORT_CACHE[$sortby] = create_function('$a, $b',$code);
}
uasort($data,$MASORT_CACHE[$sortby]);
}
}
?>

View File

@@ -12,6 +12,7 @@
*/
class ORM extends Kohana_ORM {
protected $_table_names_plural = false;
protected $_model_names_plural = false;
private $_object_formated = array();
private $_formated = FALSE;
// Our filters used to display values in a friendly format
@@ -70,7 +71,7 @@ class ORM extends Kohana_ORM {
if (isset($this->_object_formated[$column]))
return $this->_object_formated[$column];
else
return $value;
return HTML::nbsp($value);
}
}
?>

View File

@@ -3,7 +3,7 @@
/**
* This class overrides Kohana's Response
*
* @package OSB/Modifications
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George

View File

@@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class sort extends lnApp_Sort {}
?>

View File

@@ -3,7 +3,7 @@
/**
* Array and variable validation.
*
* @package OSB/Modifications
* @package lnApp/Modifications
* @category Classes
* @author Deon George
* @copyright (c) 2010 Deon George

View File

@@ -16,5 +16,6 @@ return array(
'hash_key' => '',
'lifetime' => 1209600,
'session_key' => 'auth_user',
'forced_key' => 'auth_forced',
);
?>

View File

@@ -1,10 +1,23 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* lnApp Configuration - Cache Driver
*
* @package lnApp
* @subpackage Cache
* @category Configuration
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
return array
(
'file' => array
(
'driver' => 'file',
'cache_dir' => '/dev/shm/osb',
'cache_dir' => Kohana::$cache_dir ? Kohana::$cache_dir : '/dev/shm/lnapp',
'default_expire' => 3600,
)
);
?>

View File

@@ -4,9 +4,13 @@ table.box-left { border: 1px solid #AAAACC; margin-right: auto; }
table.box-center { border: 1px solid #AAAACC; margin-left: auto; margin-right: auto; }
table.box-full { border: 1px solid #AAAACC; margin-right: auto; width: 100%; }
tr.head { font-weight: bold; }
tr.subhead { background-color: #BBBBDD; }
td.head { font-weight: bold; }
td.bold { font-weight: bold; }
td.bold-right { font-weight: bold; text-align: right; }
td.data { font-weight: bold; }
span.data { font-weight: bold; }
td.data-right { font-weight: bold; text-align: right; }
td.right { text-align: right; }
tr.odd { background-color: #FCFCFE; }
tr.even { background-color: #F6F6F8; }