Updates from lnApp
This commit is contained in:
parent
e2b84fc063
commit
8301c0f6af
@ -12,33 +12,6 @@
|
||||
abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
|
||||
protected $auth_required = TRUE;
|
||||
|
||||
// Our acccount object
|
||||
protected $ao;
|
||||
|
||||
public function __construct(Request $request, Response $response) {
|
||||
$this->template = Config::theme().'/page';
|
||||
|
||||
return parent::__construct($request,$response);
|
||||
}
|
||||
|
||||
public function before() {
|
||||
// If our action doesnt exist, no point processing any further.
|
||||
if (! method_exists($this,'action_'.Request::current()->action()))
|
||||
return;
|
||||
|
||||
if ($this->auth_required) {
|
||||
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
|
||||
throw HTTP_Exception::factory(403,'Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));
|
||||
|
||||
$this->ao = Auth::instance()->get_user();
|
||||
|
||||
if (! is_null($this->ao) AND (is_string($this->ao) OR ! $this->ao->loaded()))
|
||||
throw HTTP_Exception::factory(501,'Account doesnt exist :account ?',array(':account'=>(is_string($this->ao) OR is_null($this->ao)) ? $this->ao : Auth::instance()->get_user()->id));
|
||||
}
|
||||
|
||||
parent::before();
|
||||
}
|
||||
|
||||
// @todo To rework
|
||||
public function after() {
|
||||
$dc = URL::link('user','welcome/index');
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Menu {
|
||||
class Menu extends lnApp_Menu {
|
||||
private static function collapse(array $array) {
|
||||
$result = array();
|
||||
|
||||
@ -46,16 +46,15 @@ class Menu {
|
||||
return self::collapse($result);
|
||||
}
|
||||
|
||||
public static function ul(array $result,array $append=NULL,$sub=FALSE) {
|
||||
public static function ul($type,array $result,array $append=NULL,$sub=FALSE,$method=NULL) {
|
||||
$output = $sub ? '<ul class="dropdown-menu">' : '<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">';
|
||||
|
||||
foreach ($result as $k => $v)
|
||||
if (is_array($v))
|
||||
$output .= sprintf('<li class="dropdown-submenu">%s%s',HTML::anchor('#',$k,array('nocg'=>TRUE)),self::ul($v,NULL,TRUE).'</li>');
|
||||
$output .= sprintf('<li class="dropdown-submenu">%s%s',HTML::anchor('#',$k,array('nocg'=>TRUE)),self::ul($type,$v,NULL,TRUE).'</li>');
|
||||
else
|
||||
$output .= '<li>'.HTML::anchor($v->url(),$v->menu_display(),array('tabindex'=>-1,'nocg'=>TRUE)).'</li>';
|
||||
|
||||
|
||||
if ($append) {
|
||||
$output .= '<li class="divider"></li>';
|
||||
|
||||
|
@ -12,19 +12,10 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
abstract 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
|
||||
protected $_display_filters = array();
|
||||
abstract class ORM extends lnApp_ORM {
|
||||
// Tables that do not have a site_id column
|
||||
public static $no_site_id_tables = array('setup','country','currency','language','tax');
|
||||
|
||||
// Whether to show a SystemMessage when a record is saved.
|
||||
protected $_save_message = FALSE;
|
||||
|
||||
/**
|
||||
* Add our OSB site_id to each SELECT query
|
||||
* @see parent::__build()
|
||||
@ -48,19 +39,6 @@ abstract class ORM extends Kohana_ORM {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function help to find records that are active
|
||||
*/
|
||||
@ -80,20 +58,6 @@ abstract class ORM extends Kohana_ORM {
|
||||
return in_array($o->{$aid},$ao->RTM->customers($ao->RTM));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides Kohana cache so that it can be globally disabled.
|
||||
*/
|
||||
public function cached($lifetime=NULL) {
|
||||
return $this->_db->caching($this->_table_name) ? parent::cached($lifetime) : $this;
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
$this->_formated = FALSE;
|
||||
$this->_object_formated = array();
|
||||
|
||||
return parent::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override KH's ORM count_relations() function, to include our site_id in the query.
|
||||
*
|
||||
@ -131,27 +95,6 @@ abstract class ORM extends Kohana_ORM {
|
||||
return (int) $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->_formated AND $this->_display_filters)
|
||||
$this->_format();
|
||||
|
||||
if (isset($this->_object_formated[$column]))
|
||||
return $this->_object_formated[$column];
|
||||
else
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function display_filters(array $filters) {
|
||||
$this->_display_filters = Arr::merge($this->_display_filters,$filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function help to find records that are active
|
||||
*/
|
||||
@ -159,94 +102,6 @@ abstract class ORM extends Kohana_ORM {
|
||||
return $this->_where_active()->find_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is our AJAX helper, used by module list_autocomplete()
|
||||
*/
|
||||
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
|
||||
$result = array();
|
||||
|
||||
$query = empty($options['object']) ? $this : $options['object'];
|
||||
|
||||
foreach ($limit as $w) {
|
||||
list($k,$s,$v) = $w;
|
||||
|
||||
$query->and_where($k,$s,$v);
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
foreach ((empty($options['object']) ? $query->find_all() : $query->execute()) as $o) {
|
||||
// If we got here via a DB query, we need to reload our ORM object from the result.
|
||||
if (! is_object($o)) {
|
||||
if (empty($options['key']))
|
||||
throw new Kohana_Exception('Missing key for non object');
|
||||
|
||||
$o = $this->clear()->where($options['key'],'=',$o[$options['key']])->find();
|
||||
}
|
||||
|
||||
switch ($index) {
|
||||
case 'url':
|
||||
if (empty($options['urlprefix']))
|
||||
throw new Kohana_Exception('Missing URL Prefix');
|
||||
|
||||
$v = $options['urlprefix'].$o->resolve($value);
|
||||
|
||||
break;
|
||||
|
||||
default: $v = $o->resolve($value);
|
||||
}
|
||||
|
||||
$k = '';
|
||||
foreach ($label as $k => $details)
|
||||
foreach ($details as $lvalue)
|
||||
$k = preg_replace('/%s/',$o->resolve($lvalue),$k,1);
|
||||
|
||||
$result[$c++] = array(
|
||||
'value'=>$v,
|
||||
'label'=>$k,
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of data that can be used in a SELECT statement.
|
||||
* The ID and VALUE is defined in the model for the select.
|
||||
*/
|
||||
public function list_select($blank=FALSE) {
|
||||
$result = array();
|
||||
|
||||
if ($blank)
|
||||
$result[] = '';
|
||||
|
||||
if ($this->_form AND array_intersect(array('id','value'),$this->_form))
|
||||
foreach ($this->find_all() as $o)
|
||||
$result[$o->{$this->_form['id']}] = $o->resolve($this->_form['value']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used so that methods can be called via variables
|
||||
*/
|
||||
public function resolve($key) {
|
||||
eval("\$x = \$this->$key;");
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
public function save(Validation $validation=NULL) {
|
||||
parent::save();
|
||||
|
||||
if ($this->saved() AND $this->_save_message AND (PHP_SAPI !== 'cli'))
|
||||
SystemMessage::factory()
|
||||
->title('Record Updated')
|
||||
->type('success')
|
||||
->body(sprintf('Record %s:%s Updated',$this->_table_name,$this->id));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function where_active() {
|
||||
return $this->_where_active();
|
||||
}
|
||||
|
@ -10,24 +10,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Request extends Kohana_Request {
|
||||
/**
|
||||
* Sets and gets the directory for the controller.
|
||||
*
|
||||
* We override the Kohana version, so that we can have short directory URLs.
|
||||
* eg: admin=>a,reseller=>r.
|
||||
*
|
||||
* @param string $directory Directory to execute the controller from
|
||||
* @return mixed
|
||||
*/
|
||||
public function directory($directory = NULL) {
|
||||
// If $directory is NULL, we are a getter and see if we need to expand the directory
|
||||
if ($directory === NULL AND $this->_directory)
|
||||
$this->_directory = URL::dir($this->_directory);
|
||||
|
||||
return parent::directory($directory);
|
||||
}
|
||||
|
||||
class Request extends lnApp_Request {
|
||||
/**
|
||||
* Get our Module_Method object for this request
|
||||
*/
|
||||
|
@ -1,78 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's URL
|
||||
*
|
||||
* @package OSB
|
||||
* @category Modifications
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class URL extends Kohana_URL {
|
||||
// Our method paths for different functions
|
||||
public static $method_directory = array(
|
||||
'admin'=>'a',
|
||||
'reseller'=>'r',
|
||||
'user'=>'u',
|
||||
'task'=>'task',
|
||||
);
|
||||
|
||||
public static function admin_url() {
|
||||
return (Request::current() AND ((Auth::instance()->logged_in() AND ! empty(URL::$method_directory[strtolower(Request::current()->directory())])) OR in_array(strtolower(Request::current()->controller()),array('login','oauth'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to reveal the real directory for a URL
|
||||
*/
|
||||
public static function dir($dir) {
|
||||
// Quick check if we can do something here
|
||||
if (! in_array(strtolower($dir),URL::$method_directory))
|
||||
return $dir;
|
||||
|
||||
// OK, we can, find it.
|
||||
foreach (URL::$method_directory as $k=>$v)
|
||||
if (strtolower($dir) == $v)
|
||||
return ucfirst($k);
|
||||
|
||||
// If we get here, we didnt have anything.
|
||||
return $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to provide a URL::site() link based on function
|
||||
*/
|
||||
public static function link($dir,$src,$site=FALSE) {
|
||||
if (! $dir)
|
||||
return $src;
|
||||
|
||||
if (! array_key_exists($dir,URL::$method_directory))
|
||||
throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src));
|
||||
|
||||
$x = URL::$method_directory[$dir].'/'.$src;
|
||||
|
||||
return $site ? URL::site($x) : $x;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,16 +0,0 @@
|
||||
var search = _.debounce(function(url,query,process){
|
||||
$.get(site_url+url,{term: query},function(data) {
|
||||
users = {};
|
||||
userLabels = [];
|
||||
|
||||
_.each(data,function(item,ix,list) {
|
||||
if (_.contains(users,item.label))
|
||||
item.label = item.label + ' #' + item.value;
|
||||
|
||||
userLabels.push(item.label);
|
||||
users[item.label] = item.value;
|
||||
});
|
||||
|
||||
process(userLabels);
|
||||
})
|
||||
}, 300);
|
@ -1,14 +0,0 @@
|
||||
$(document).ready(function() {
|
||||
$("input[name=search-query]").typeahead({
|
||||
minLength: 2,
|
||||
source: function (query,process) {
|
||||
search('u/search/ajaxlist',query,process);
|
||||
},
|
||||
|
||||
matcher: function () { return true; },
|
||||
|
||||
updater: function (item) {
|
||||
window.parent.location.href = site_url+users[item];
|
||||
},
|
||||
});
|
||||
});
|
@ -46,9 +46,13 @@
|
||||
<?php echo $navbar; ?>
|
||||
</ul>
|
||||
|
||||
<form class="navbar-search pull-right">
|
||||
<input type="text" name="search-query" class="search-query" placeholder="Search" data-provide="typeahead">
|
||||
</form>
|
||||
<div class="navbar-search pull-right">
|
||||
<div class="navbar-search-addon">
|
||||
<i class="icon-search"></i>
|
||||
<?php echo HTML::image('media/img/spinner.gif',array('class'=>'right','name'=>'searching')); ?>
|
||||
<input type="text" name="search-query" class="search-query" placeholder="Search" data-provide="typeahead">
|
||||
</div>
|
||||
</div>
|
||||
</div><!--/.nav-collapse -->
|
||||
|
||||
</div> <!-- /container -->
|
||||
|
@ -1,10 +0,0 @@
|
||||
<?php foreach (URL::navbar() as $type => $details) : ?>
|
||||
<?php if ($x = Menu::items($type)) : ?>
|
||||
<ul class="nav pull-right">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="<?php echo $details['icon']; ?>"></i> <?php echo $details['name']; ?> <b class="caret"></b></a>
|
||||
<?php echo Menu::ul($x,$type == 'user' ? array('logout'=>'Logout') : NULL); ?>
|
||||
</li>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
@ -1 +1 @@
|
||||
Subproject commit 6d49edd8a1a8debec29ee0f3984926c672317198
|
||||
Subproject commit a889d25eda0d6c1b8766b15f2d71f3dd4f0357d9
|
Reference in New Issue
Block a user