Themeing work based on bootstrap

This commit is contained in:
Deon George
2013-04-25 10:22:36 +10:00
parent b310cdb125
commit 74a9c291e4
184 changed files with 37653 additions and 8903 deletions

View File

@@ -1,9 +1,9 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering HTML body blocks (left, center, right).
* This class is for rendering HTML blocks or widget.
*
* It will provide a header, body and footer.
* It will provide a title and body for the content.
*
* @package lnApp
* @category lnApp/Helpers
@@ -14,13 +14,17 @@
*/
abstract class lnApp_Block extends HTMLRender {
protected static $_data = array();
protected static $_spacer = '<table><tr class="spacer"><td>&nbsp;</td></tr></table>';
protected static $_spacer = '';
protected static $_c = 0;
protected $_items = array('body','title','title_icon','type');
protected static $_required_keys = array('body');
/**
* Add a block to be rendered
*
* @param array Block attributes
* @deprecated
*/
public static function add($block,$prepend=FALSE) {
// Any body objects should be converted to a string, so that any calls to Style/Script are processed
@@ -40,43 +44,39 @@ abstract class lnApp_Block extends HTMLRender {
}
/**
* Return an instance of this class
*
* @return Block
*/
public static function factory() {
return new Block;
}
/**
* Render this block
*
* @see HTMLRender::render()
* Render this Block
*/
protected function render() {
$record = static::$_data[$this->_x];
$output = '';
$styles = array();
$output .= '<div class="row">';
$output .= sprintf('<div class="%s">',empty($record['span']) ? 'span12' : $record['span']);
$output .= '<div class="widget stacked">';
$i = 0;
foreach (static::$_data as $value) {
if ($i++)
$output .= static::$_spacer;
if (! empty($record['title']))
$output .= sprintf('<div class="widget-header">%s<h3>%s</h3></div>',empty($record['title_icon']) ? '' : sprintf(' <i class="%s"></i>',$record['title_icon']),$record['title']);
$output .= '<table class="block" border="0">';
$output .= '<div class="widget-content">';
if (! empty($value['title']))
$output .= sprintf('<tr class="title"><td>%s</td></tr>',$value['title']);
if (! empty($record['type']))
switch ($record['type']) {
case 'form-horizontal': $output .= Form::open(NULL,array('class'=>'form-horizontal'));
$output .= (string)$record['body'];
$output .= Form::close();
break;
if (! empty($value['subtitle']))
$output .= sprintf('<tr class="subtitle"><td>%s</td></tr>',$value['subtitle']);
default:
$output .= (string)$record['body'];
}
$output .= sprintf('<tr class="body"><td>%s</td></tr>',$value['body']);
else
$output .= (string)$record['body'];
if (! empty($value['footer']))
$output .= sprintf('<tr class="footer"><td>%s</td></tr>',$value['footer']);
$output .= '</table>';
}
$output .= '</div> <!-- /widget-content -->';
$output .= '</div> <!-- /widget-stacked -->';
$output .= '</div> <!-- /span -->';
$output .= '</div> <!-- /row -->';
return $output;
}

View File

@@ -15,12 +15,16 @@
class lnApp_Block_Sub extends HTMLRender {
protected static $_data = array();
protected static $_spacer = '<table><tr class="spacer"><td>&nbsp;</td></tr></table>';
protected static $_c = 0;
protected $_items = array();
protected static $_required_keys = array('body','position');
/**
* Add a block to be rendered
*
* @param array Block attributes
* @deprecated
*/
public static function add($block,$prepend=FALSE) {
parent::add($block);
@@ -35,15 +39,6 @@ class lnApp_Block_Sub extends HTMLRender {
));
}
/**
* Return an instance of this class
*
* @return Block
*/
public static function factory() {
return new Block_Sub;
}
/**
* Render this block
*

View File

@@ -12,8 +12,49 @@
abstract class lnApp_BreadCrumb extends HTMLRender {
protected static $_data = array();
protected static $_spacer = ' &raquo; ';
protected static $_c = 0;
protected $_items = array('body');
protected static $_required_keys = array('body');
/**
* Enable a friendly name to be used for a path
*/
public static function name($path,$name,$override=TRUE) {
if (isset(static::$_data['name'][$path]) AND ! $override)
return;
static::$_data['name'][$path] = $name;
}
/**
* Render this BreadCrumb
*/
protected function render() {
$output = '<article class="breadcrumbs">';
$output .= HTML::anchor('/',_('Home'));
$data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path'];
$c = count($data);
$i=0;
foreach ($data as $k => $v) {
$i++;
$output .= '<div class="breadcrumb_divider"></div>';
$p = join('/',array_slice($data,0,$k+1));
$output .= $i==$c ? '<span id="active">' : '<span id="inactive">';
$output .= HTML::anchor(
(empty(static::$_data['url'][$p]) ? $p : static::$_data['url'][$p]),
(empty(static::$_data['name'][$p]) ? ucfirst(URL::dir($v)) : static::$_data['name'][$p])
);
$output .= '</span>';
}
$output .= '</article>';
return $output;
}
/**
* Set the BreadCrumb path
*
@@ -30,20 +71,6 @@ abstract class lnApp_BreadCrumb extends HTMLRender {
throw new Kohana_Exception('Path is not a string, nor an array');
}
public static function dump() {
echo Debug::vars(static::$_data);
}
/**
* Enable a friendly name to be used for a path
*/
public static function name($path,$name,$override=TRUE) {
if (isset(static::$_data['name'][$path]) AND ! $override)
return;
static::$_data['name'][$path] = $name;
}
/**
* Enable specifying the URL for a path
*/
@@ -56,41 +83,5 @@ abstract class lnApp_BreadCrumb extends HTMLRender {
static::$_data['url'][$path] = $url;
}
/**
* Return an instance of this class
*
* @return BreadCrumb
*/
public static function factory() {
return new BreadCrumb;
}
/**
* Render this BreadCrumb
*/
protected function render() {
$output = '<ul id="breadcrumb">';
$output .= '<li>'.HTML::anchor('/',_('Home')).'</li>';
$data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path'];
$c = count($data);
$i=0;
foreach ($data as $k => $v) {
$i++;
$p = join('/',array_slice($data,0,$k+1));
$output .= $i==$c ? '<li id="active">' : '<li>';
$output .= HTML::anchor(
(empty(static::$_data['url'][$p]) ? $p : static::$_data['url'][$p]),
(empty(static::$_data['name'][$p]) ? ucfirst(URL::dir($v)) : static::$_data['name'][$p])
);
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
}
?>

View File

@@ -14,18 +14,14 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
protected $auth_required = FALSE;
public function action_index() {
$output = '';
// If user already signed-in
if (Auth::instance()->logged_in() != 0) {
// Redirect to the user account
if (Auth::instance()->logged_in())
HTTP::redirect(URL::link('user','welcome/index'));
}
// If there is a post and $_POST is not empty
if ($_POST) {
// Store our details in a session key
Session::instance()->set(Kohana::$config->load('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
@@ -37,37 +33,28 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
HTTP::redirect(URL::link('user','welcome/index'));
} else {
// We are not successful logging in, so delete our session data
Session::instance()->delete(Kohana::$config->load('auth')->session_key);
Session::instance()->delete('password');
SystemMessage::add(array(
'title'=>_('Invalid username or password'),
'type'=>'error',
'body'=>_('The username or password was invalid.')
));
SystemMessage::factory()
->title(_('Invalid username or password'))
->type('error')
->body(_('The username or password was invalid.'));
}
}
Block::add(array(
'title'=>_('Login to server'),
'body'=>View::factory('login'),
'style'=>array('css/login.css'=>'screen'),
));
$output .= View::factory('pages/login');
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("#ajxbody").click(function() {$("#ajBODY").load("'.$this->request->uri().'/"); return false;});
});'
));
Style::factory()
->type('file')
->data('media/theme/baseadmin/css/pages/login.css');
$this->template->content = $output;
$this->template->shownavbar = FALSE;
}
public function action_noaccess() {
SystemMessage::add(array(
'title'=>_('No access to requested resource'),
'type'=>'error',
'body'=>_('You do not have access to the requested resource, please contact your administrator.')
));
SystemMessage::factory()
->title(_('No access to requested resource'))
->type('error')
->body(_('You do not have access to the requested resource, please contact your administrator.'));
}
}
?>

View File

@@ -13,15 +13,13 @@
class lnApp_Controller_Logout extends Controller {
public function action_index() {
// If user already signed-in
if (Auth::instance()->logged_in() != 0) {
if (Auth::instance()->logged_in()) {
$ao = Auth::instance()->get_user();
if (method_exists($ao,'log'))
$ao->log('Logged Out');
Auth::instance()->logout();
HTTP::redirect('login');
Auth::instance()->logout(TRUE);
}
HTTP::redirect('welcome/index');

View File

@@ -30,16 +30,6 @@ abstract class lnApp_Controller_Media extends Controller {
if ($fd = Session::instance()->get_once($this->request->param('file'))) {
$this->response->body($fd);
// First try and find media files for the theme-site_id
} elseif ($f = Kohana::find_file($x=sprintf('media/site/%s/theme/%s',Config::siteid(),Config::theme()),$file,$ext)) {
// Send the file content as the response
$this->response->body(file_get_contents($f));
// Try and find media files for the site_id
} elseif ($f = Kohana::find_file(sprintf('media/site/%s',Config::siteid()),$file,$ext)) {
// Send the file content as the response
$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
@@ -51,7 +41,7 @@ abstract class lnApp_Controller_Media extends Controller {
}
// Generate and check the ETag for this file
if (Kohana::$environment === Kohana::PRODUCTION OR Kohana::$config->load('debug')->etag)
if (Kohana::$environment < Kohana::TESTING OR Kohana::$config->load('debug')->etag)
$this->check_cache(sha1($this->response->body()));
// Set the proper headers to allow caching

View File

@@ -1,20 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides the default controller for tasks.
*
* @package lnApp
* @category lnApp/Controllers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_Controller_Task extends Controller {
public function before() {
if (! Kohana::$is_cli)
throw new Kohana_Exception('Cant run :method, it must be run by the CLI',array(':method'=>$this->request->action()));
parent::before();
}
}
?>

View File

@@ -10,10 +10,6 @@
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
/**
* @var string page template
*/
public $template = 'theme/bootstrap/default';
/**
* @var object meta object information as per [meta]
*/
@@ -56,7 +52,7 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
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));
! Auth::instance()->logged_in($this->secure_actions[$this->request->action()],get_class($this).'|'.__METHOD__)));
}
/**
@@ -106,6 +102,9 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
}
}
if (! $this->auto_render)
return;
// For AJAX calls, we dont need to render the complete page.
if ($this->request->is_ajax()) {
$this->auto_render = FALSE;
@@ -116,20 +115,8 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
$this->meta = new Meta;
View::bind_global('meta',$this->meta);
// Add our logo
/*
Style::add(array(
'type'=>'stdin',
'data'=>'h1 span{background:url('.Config::logo_uri().') no-repeat;}',
));
*/
// Our default script(s)
/*
foreach (array('file'=>array_reverse(array(
'js/jquery-1.6.4.min.js',
'js/jquery.jstree-1.0rc3.js',
'js/jquery.cookie.js',
))) as $type => $datas) {
foreach ($datas as $data) {
@@ -139,54 +126,41 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
),TRUE);
}
}
*/
// Initialise our content
$this->template->left = '';
$this->template->shownavbar = TRUE;
$this->template->content = '';
$this->template->right = '';
$this->template->footer = '';
}
public function after() {
if (! is_string($this->template) AND empty($this->template->content))
$this->template->content = Block::factory();
if ($this->auto_render) {
$this->template->navbar = $this->template->shownavbar ? View::factory('pages/navbar') : '';
if (empty($this->template->content))
$this->template->content = Block::factory()->render_all();
// Adjust our breadcrumb
if (isset(URL::$method_directory[strtolower($this->request->directory())]))
BreadCrumb::name(URL::$method_directory[strtolower($this->request->directory())],$this->request->directory());
// Application Title
if (class_exists('Model_Module') AND $mo=ORM::factory('Module',array('name'=>Request::current()->controller())) AND $mo->loaded())
$this->meta->title = sprintf('%s: %s',Kohana::$config->load('config')->appname,$mo->display('name'));
else
$this->meta->title = Config::sitename();
$this->template->title = '';
// Language
$this->meta->language = Config::language();
$this->meta->title = Kohana::$config->load('config')->appname;
// Description
$this->meta->description = sprintf('%s::%s',$this->request->controller(),$this->request->action());
// Link images on the header line
$this->template->headimages = $this->_headimages();
// System Messages line
$this->template->sysmsg = $this->_sysmsg();
// Left Item
$this->template->left = '';
// Right Item
$this->template->right = '';
// Footer
$this->template->footer = $this->_footer();
// In case we have some scripting/styling, we need to get that out too
} elseif ($this->request->is_ajax() AND $this->response->body()) {
$this->response->bodyadd(Script::factory()->render_all());
$this->response->bodyadd(Style::factory()->render_all());
// For any ajax rendered actions, we'll need to capture the content and put it in the response
// @todo Do we come here for ajax?
} 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->response->body(sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s));
// In case there any style sheets for this render.
$this->response->bodyadd(Style::factory());
@@ -204,7 +178,8 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
parent::after();
// Generate and check the ETag for this file
$this->check_cache(sha1($this->response->body()));
if (Kohana::$environment < Kohana::TESTING OR Kohana::$config->load('debug')->etag)
$this->check_cache(sha1($this->response->body()));
}
/**
@@ -214,24 +189,6 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
$this->template->content = _('Please choose from the menu on the left - you may need to expand the items by pressing on the plus.');
}
protected function _headimages() {
HeadImages::add(array(
'url'=>'http://dev.leenooks.net',
'img'=>'img/forum-big.png',
'attrs'=>array('onclick'=>"target='_blank';",'title'=>'Link')
));
return HeadImages::factory();
}
protected function _sysmsg() {
return SystemMessage::factory();
}
public function _footer() {
return sprintf('&copy; %s',Config::sitename());
}
/**
* Generate a view path to help View::factory() calls
*
@@ -240,6 +197,7 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
* plugins
*
* @param string Plugin Name (optional)
* @deprecated
*/
public function viewpath($plugin='') {
$request = Request::current();

View File

@@ -1,116 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends renders OSB menu tree.
*
* @package lnApp
* @category lnApp/Controllers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
class lnApp_Controller_Tree extends Controller_Default {
/**
* @var string page media route as per [Route]
*/
protected static $jsmediaroute = 'default/media';
public function after() {
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode($this->output));
parent::after();
}
public static function js() {
$mediapath = Route::get(static::$jsmediaroute);
return '
<div id="tree" class=""></div>
<script type="text/javascript">
<!--
$(function () {
var use_ajax = false;
$("#tree").jstree({
themes : {
"theme" : "classic",
},
ui : {
"select_limit" : 1,
"select_node" : false,
},
cookies : {
"save_selected" : false,
"cookie_options" : { path : "'.URL::site().'" }
},
json_data : {
"correct_state" : "true",
"progressive_render" : "true",
"ajax" : {
"url" : "'.URL::site('tree/json').'",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : "N_"+0 };
}
}
},
plugins : [ "themes", "json_data", "ui", "cookies" ],
});
// On selection
$("#tree").bind("select_node.jstree", function (e, data) {
if (a = data.rslt.obj.attr(\'id\').indexOf(\'_\')) {
id = data.rslt.obj.attr(\'id\').substr(a+1);
if (href = $("#N_"+id).attr("href")) {
if (! use_ajax) {
window.location = href;
return;
}
$("#ajBODY").empty().html("<img src=\"'.URL::site('media/img/ajax-progress.gif').'\" alt=\"Loading...\" />");
$("#ajBODY").load(href, function(r,s,x) {
if (s == "error") {
var msg = "Sorry but there was an error: ";
$("#ajBODY").html(msg + x.status + " " + x.statusText + r);
}
});
} else
alert("Unknown: "+id+" HREF:"+href);
}
});
});
// -->
</script>';
}
/**
* Draw the Tree Menu
*
* The incoming ID is either a Branch B_x or a Node N_x
* Where X is actually the module.
*
* @param array $data Tree data passed in by inherited methods
*/
public function action_json(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->output = array();
foreach ($data as $branch) {
array_push($this->output,array(
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
'state'=>$branch['state'],
'data'=>array('title'=>$branch['name']),
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::link('user',$branch['name'].'/menu',TRUE) : $branch['attr_href']),
)
);
}
}
}
?>

87
classes/lnApp/Form.php Normal file
View File

@@ -0,0 +1,87 @@
<?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
*/
abstract class lnApp_Form extends Kohana_Form {
/**
* Render our control group form attributes
*
* @return array((string) control group wrapper,(array) attributes to exclude
*/
private static function _controlgroup($name,array &$attributes=NULL) {
if (isset($attributes['nocg'])) {
unset($attributes['nocg']);
return '%s';
}
$output = '';
$output .= '<div class="control-group">';
if (isset($attributes['label'])) {
$output .= Form::label($name,$attributes['label'],array('class'=>'control-label'));
unset($attributes['label']);
}
if (isset($attributes['help-block'])) {
$help = $attributes['help-block'];
unset($attributes['help-block']);
}
$output .= '<div class="controls">';
$output .= '%s';
if (isset($help))
$output .= sprintf('<span class="help-block">%s</span>',$help);
$output .= '</div>';
$output .= '</div>';
return $output;
}
/**
* Wrap our Form() functions with boostrap HTML
*
* @usedby Form::hidden
* @usedby Form::password
* @usedby Form::file
* @usedby Form::checkbox
* @usedby Form::radio
* @usedby Form::submit
* @usedby Form::image
*/
public static function input($name,$value=NULL,array $attributes=NULL) {
return sprintf(static::_controlgroup($name,$attributes),parent::input($name,$value,$attributes));
}
public static function select($name,array $options=NULL,$selected=NULL,array $attributes=NULL) {
// If only 1 record, dont show select, but a hidden attribute and a displayed value.
if (isset($attributes['oneonly']) AND $attributes['oneonly']) {
$attributes['disabled'] = 'disabled';
unset($attributes['oneonly']);
}
return sprintf(static::_controlgroup($name,$attributes),parent::select($name,$options,$selected,$attributes));
}
public static function textarea($name,$body='',array $attributes=NULL,$double_encode=TRUE) {
if (! isset($attributes['id']))
$attributes['id'] = preg_replace('/[\[\]]/','_',$name);
Script::factory()
->type('stdin')
->data('$("#'.$attributes['id'].'").wysihtml5();');
return sprintf(static::_controlgroup($name,$attributes),parent::textarea($name,$body,$attributes,$double_encode));
}
}
?>

View File

@@ -11,21 +11,92 @@
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_HTMLRender {
protected static $_media_path = 'default/media';
protected static $_required_keys = array();
protected static $_unique_vals = array();
protected $_x = 0;
abstract protected function render();
public function __call($name,$args=NULL) {
if (! in_array($name,$this->_items))
throw new Kohana_Exception('Unknown call to :name',array(':name'=>$name));
$c = $this->_x;
if (! $args)
return static::$_data[$c][$name];
static::$_data[$c][$name] = array_pop($args);
return $this;
}
public function __construct() {
if (! isset(static::$_data))
throw new Kohana_Exception(':class is missing important static variables',array(':class'=>get_called_class()));
$this->_x = ++static::$_c;
}
/**
* Return the HTML to render the header images
*/
public function __toString() {
if (! static::$_data)
return '';
if (empty(static::$_data[$this->_x]))
$this->record();
return $this->render();
try {
return $this->render();
}
// Display the exception message
catch (Exception $e) {
return $e->getMessage();
}
}
public static function factory() {
$x = get_called_class();
return new $x;
}
public function record($x=NULL) {
$this->_x = (is_null($x) OR empty(static::$_data[$x])) ? max(array_keys(static::$_data)) : $x;
return $this;
}
/**
* Render all of these items
*/
public static function render_all() {
$output = '';
$o = static::factory();
for ($x=0; $x<static::$_c; $x++)
if (isset(static::$_data[$x]))
$output .= (string)$o->record($x);
return $output;
}
/**
* Set the space used between rendering output
*/
public static function spacer($spacer) {
static::$_spacer = $spacer;
}
/**
* Add an item to be rendered
*
* @param array Item to be added
* @deprecated
*/
public static function add($item,$prepend=FALSE) {
public static function add($item) {
static::$_c = count(static::$_data);
foreach (static::$_required_keys as $key)
if (! isset($item[$key]))
throw new Kohana_Exception('Missing key :key for image',array(':key'=>$key));
@@ -37,55 +108,7 @@ abstract class lnApp_HTMLRender {
if (isset($d[$u]) && $d['data'] == $item['data'])
return;
if ($prepend)
array_unshift(static::$_data,$item);
else
array_push(static::$_data,$item);
}
/**
* Set the space used between rendering output
*/
public static function setSpacer($spacer) {
static::$_spacer = $spacer;
}
/**
* Set the Kohana Media Path, used to determine where to find additional
* HTML content required for rendering.
*/
public static function setMediaPath($path) {
static::$_media_path = $path;
}
/**
* Factory instance method must be declared by the child class
*/
public static function factory() {
throw new Kohana_Exception(':class is calling :method, when it should have its own method',
array(':class'=>get_called_class(),':method'=>__METHOD__));
}
/**
* Return the HTML to render the header images
*/
public function __toString() {
try {
return static::render();
}
// Display the exception message
catch (Exception $e) {
Kohana_Exception::handler($e);
}
}
/**
* Rendering must be declared by the child class
*/
protected function render() {
throw new Kohana_Exception(':class is calling :method, when it should have its own method',
array(':class'=>get_called_class(),':method'=>__METHOD__));
static::$_data[++static::$_c] = $item;
}
}
?>

View File

@@ -1,47 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for all image icons shown on the page header.
*
* @package lnApp
* @category lnApp/Helpers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_HeadImages extends HTMLRender {
protected static $_data = array();
protected static $_spacer = '&nbsp;';
protected static $_required_keys = array('img');
/**
* Return an instance of this class
*
* @return HeadImage
*/
public static function factory() {
return new HeadImages;
}
/**
* Render this Header Image
*
* @see HTMLRender::render()
*/
protected function render() {
$output = '';
$mediapath = Route::get(static::$_media_path);
foreach (static::$_data as $value) {
$i = HTML::image($mediapath->uri(array('file'=>$value['img'])),array('alt'=>isset($value['attrs']['title']) ? $value['attrs']['title'] : ''));
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;
}
return $output;
}
}
?>

View File

@@ -12,18 +12,10 @@
abstract class lnApp_Script extends HTMLRender {
protected static $_data = array();
protected static $_spacer = "\n";
protected static $_required_keys = array('type','data');
protected static $_unique_vals = array('file'=>'type');
protected static $_rendered = FALSE;
protected static $_c = 0;
protected $_items = array('data','media','type');
/**
* Return an instance of this class
*
* @return Script
*/
public static function factory() {
return new Script;
}
protected static $_required_keys = array('type','data');
/**
* Render the script tag
@@ -31,34 +23,24 @@ abstract class lnApp_Script extends HTMLRender {
* @see HTMLRender::render()
*/
protected function render() {
$foutput = $soutput = '';
$mediapath = Route::get(static::$_media_path);
$record = static::$_data[$this->_x];
$output = '';
foreach (static::$_data as $value) {
switch ($value['type']) {
case 'file':
$foutput .= HTML::script($mediapath->uri(array('file'=>$value['data'])));
break;
case 'src':
$foutput .= HTML::script($value['data']);
break;
case 'stdin':
$soutput .= sprintf("<script type=\"text/javascript\">//<![CDATA[\n%s\n//]]></script>",$value['data']);
break;
default:
throw new Kohana_Exception('Unknown style type :type',array(':type'=>$value['type']));
}
switch ($record['type']) {
case 'file':
$output .= HTML::script($record['data']);
break;
case 'stdin':
$output .= sprintf("<script type=\"text/javascript\">//<![CDATA[\n%s\n//]]></script>",$record['data']);
break;
case 'src':
$output .= HTML::script($record['data']);
break;
default:
throw new Kohana_Exception('Unknown style type :type',array(':type'=>$record['type']));
}
static::$_rendered = TRUE;
return $foutput.static::$_spacer.$soutput;
}
public static function add($item,$prepend=FALSE,$x='') {
if (static::$_rendered)
throw new Kohana_Exception('Already rendered?');
return parent::add($item,$prepend);
return $output;
}
}
?>

View File

@@ -20,9 +20,12 @@ abstract class lnApp_Sort {
* @return array Sorted multi demension array.
*/
public static function MAsort(&$data,$sortby,$rev=0) {
// if the array to sort is null or empty, or our sortby is bad
if (! preg_match('/^([a-zA-Z0-9_]+(\([a-zA-Z0-9_,]*\)(->[a-zA-Z0-9])?)?,?)+$/',$sortby) || ! $data)
// if the array to sort is null
if (! $data)
return;
// if the array to sort is null or empty, or our sortby is bad
# if (! preg_match('/^([a-zA-Z0-9_]+(\([a-zA-Z0-9_,]*\)(->[a-zA-Z0-9])?)?,?)+$/',$sortby) || ! $data)
# return;
$code = '$c=0;';

View File

@@ -12,17 +12,10 @@
abstract class lnApp_Style extends HTMLRender {
protected static $_data = array();
protected static $_spacer = "\n";
protected static $_required_keys = array('type','data');
protected static $_unique_vals = array('file'=>'type');
protected static $_c = 0;
protected $_items = array('data','media','type');
/**
* Return an instance of this class
*
* @return Style
*/
public static function factory() {
return new Style;
}
protected static $_required_keys = array('type','data');
/**
* Render the style tag
@@ -30,24 +23,21 @@ abstract class lnApp_Style extends HTMLRender {
* @see HTMLRender::render()
*/
protected function render() {
$foutput = $soutput = '';
$mediapath = Route::get(static::$_media_path);
$record = static::$_data[$this->_x];
foreach (static::$_data as $value) {
switch ($value['type']) {
case 'file':
$foutput .= HTML::style($mediapath->uri(array('file'=>$value['data'])),
array('media'=>(! empty($value['media'])) ? $value['media'] : 'screen'),TRUE);
break;
case 'stdin':
$soutput .= sprintf("<style type=\"text/css\">%s</style>",$value['data']);
break;
default:
throw new Kohana_Exception('Unknown style type :type',array(':type'=>$value['type']));
}
$output = '';
switch ($record['type']) {
case 'file':
$output .= HTML::style($record['data'],array('media'=>(! empty($record['media'])) ? $record['media'] : 'screen'));
break;
case 'stdin':
$output .= sprintf("<style type=\"text/css\">%s</style>",$record['data']);
break;
default:
throw new Kohana_Exception('Unknown style type :type',array(':type'=>$record['type']));
}
return $foutput.static::$_spacer.$soutput;
return $output;
}
}
?>

View File

@@ -11,118 +11,79 @@
*/
abstract class lnApp_SystemMessage extends HTMLRender {
protected static $_data = array();
protected static $_spacer = '<table><tr class="spacer"><td>&nbsp;</td></tr></table>';
protected static $_spacer = '';
protected static $_c = 0;
protected $_items = array('body','title','type');
protected static $_required_keys = array('title','body','type');
public function __call($name,$args=NULL) {
parent::__call($name,$args);
Session::instance()->set('sessionmsgs',static::$_data);
return $this;
}
/**
* Add a system message to be rendered
*
* @param array System Message attributes
* @deprecated
*/
public static function add($msg,$prepend=FALSE) {
if ($msgs = Session::instance()->get('sessionmsgs')) {
if ($msgs = Session::instance()->get_once('sessionmsgs'))
static::$_data = $msgs;
}
parent::add($msg);
// Add a gribber popup
Style::add(array(
'type'=>'file',
'data'=>'css/jquery.gritter.css',
'media'=>'screen',
));
Script::add(array(
'type'=>'file',
'data'=>'js/jquery.gritter-1.5.js',
));
Script::add(array(
'type'=>'stdin',
'data'=>sprintf(
'$(document).ready(function() {
$.extend($.gritter.options, {
fade_in_speed: "medium",
fade_out_speed: 2000,
time: "3000",
sticky: false,
});
$.gritter.add({
title: "%s",
text: "%s",
image: "%s",
});});',$msg['title'],$msg['body'],URL::site().static::image($msg['type'],true))));
static::$_c = count(static::$_data);
// Save our messages in our session, so that we get them for redirects
Session::instance()->set('sessionmsgs',static::$_data);
}
/**
* Return an instance of this class
*
* @return SystemMessage
*/
public static function factory() {
return new SystemMessage;
}
/**
* Render an image for the System Message
*/
public static function image($type,$raw=false,$big=false,$alt='') {
$mediapath = Route::get(static::$_media_path);
switch ($type) {
case 'error':
$file = sprintf('img/dialog-error%s.png',$big ? '-big' : '');
break;
case 'info':
$file = sprintf('img/dialog-information%s.png',$big ? '-big' : '');
break;
case 'warning':
$file = sprintf('img/dialog-warning%s.png',$big ? '-big' : '');
break;
case 'debug':
$file = sprintf('img/dialog-question%s.png',$big ? '-big' : '');
break;
default:
throw new Kohana_Exception('Unknown system message type :type',array(':type'=>$value['type']));
}
if ($raw)
return $mediapath->uri(array('file'=>$file));
else
return HTML::image($mediapath->uri(array('file'=>$file)),array('alt'=>$alt ? $alt : '','class'=>'sysicon'));
}
/**
* Render this system message
*
* @see HTMLRender::render()
*/
protected function render() {
$record = static::$_data[$this->_x];
$output = '';
$mediapath = Route::get(static::$_media_path);
// Reload our message from the session
if ($msgs = Session::instance()->get('sessionmsgs')) {
Session::instance()->delete('sessionmsgs');
static::$_data = $msgs;
$output .= sprintf('<div class="alert %s">',empty($record['type']) ? '' : 'alert-'.$record['type']);
$output .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
switch ($record['type']) {
case 'error':
$output .= '<i class="icon-ban-circle"></i>';
break;
case 'success':
$output .= '<i class="icon-check"></i>';
break;
case 'warning':
$output .= '<i class="icon-warning-sign"></i>';
break;
case 'info':
default:
$output .= '<i class="icon-info-sign"></i>';
}
$i = 0;
foreach (static::$_data as $value) {
if ($i++)
$output .= static::$_spacer;
$output .= '<table><tr>';
$output .= sprintf('<td class="icon" rowspan="2">%s</td>',static::image($value['type'],false,false,isset($value['alt']) ? $value['alt'] : ''));
$output .= sprintf('<td class="head">%s</td>',$value['title']);
$output .= '</tr><tr>';
$output .= sprintf('<td class="body">%s</td>',$value['body']);
$output .= '</tr></table>';
}
$output .= sprintf(' <strong>%s</strong>: %s',$record['title'],$record['body']);
$output .= '</div> <!-- /alert -->';
return $output;
}
/**
* Render all of these items
*/
public static function render_all() {
// Reload our message from the session
if ($msgs = Session::instance()->get_once('sessionmsgs'))
static::$_data = $msgs;
return parent::render_all();
}
}
?>

View File

@@ -14,11 +14,14 @@ abstract class lnApp_Table {
public static function resolve($d,$key) {
if (is_array($d) AND isset($d[$key]))
$x = $d[$key];
// If the key is a method, we need to eval it
elseif (preg_match('/\(/',$key) OR preg_match('/-\>/',$key))
eval("\$x = \$d->$key;");
elseif (preg_match('/^__VALUE__$/',$key))
$x = $d;
else
$x = $d->display($key);
@@ -42,9 +45,9 @@ abstract class lnApp_Table {
else
$button = Form::button('Submit','View/Edit',array('class'=>'form_button','type'=>'submit'));
Script::add(array(
'type'=>'stdin',
'data'=>'
Script::factory()
->type('stdin')
->data('
(function($) {
// Enable Range Selection
$.fn.enableCheckboxRangeSelection = function() {
@@ -129,14 +132,6 @@ $(document).ready(function() {
$("#select-table :checkbox").check("off");
});
// Our mouse over row highlight
$("#select-table tr:not(.head)").hover(function() {
$(this).children().toggleClass("highlight");
},
function() {
$(this).children().toggleClass("highlight");
});
// Click to select Row
$("#select-table tr:not(.head)")
.filter(":has(:checkbox:checked)")
@@ -157,7 +152,7 @@ $(document).ready(function() {
window.location = $("a", this).attr("href");
});
});
'));
');
$output .= Form::open((isset($option['form']) ? $option['form'] : ''));
@@ -168,9 +163,9 @@ $(document).ready(function() {
case 'list':
default:
Script::add(array(
'type'=>'stdin',
'data'=>'
Script::factory()
->type('stdin')
->data('
// Bind our actions
$(document).ready(function() {
// Our mouse over row highlight
@@ -181,7 +176,7 @@ $(document).ready(function() {
$(this).children().toggleClass("highlight");
});
});
'));
');
}
If (! $view)