Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 1c0206a368
Fetching contributors…

Cannot retrieve contributors at this time

114 lines (91 sloc) 2.949 kB
<?
class Controller_MOP extends Controller {
public static $topController;
public $resources = array(
'js'=>array(),
'libraryjs'=>array(),
'css'=>array(),
'librarycss'=>array(),
);
public $controllerName;
//constructor
public function __construct($request, $response){
parent::__construct($request, $response);
$this->controllerName = strtolower(substr(get_class($this), 11));
$this->checkAccess();
if($request->is_initial()){
self::$topController = $this;
}
//look up all matching js and css based off controller name
$this->loadResources($this->controllerName);
}
/*
* Function: checkAccess()
* Default function for acccess checking for a controller. Can be overridden in child classes
* Checks logged in user against authrole array in config file for controller
* Parameters:nothing, except config file
* Returns: nothing
*/
public function checkAccess(){
//Authentication check
$role = Kohana::config(strtolower($this->controllerName).'.authrole', FALSE, FALSE);
//checked if logged in
if($role && !Auth::instance()->logged_in()){
Request::current()->redirect('auth/login/'.Request::initial()->uri());
exit;
}
if(is_array($role)){
$accessGranted = false;
foreach($role as $aRole){
if($role=='admin'){
if(Kohana::config('mop.staging_enabled') && !Kohana::config('mop.staging')){
$redirect = 'staging/'. Router::$current_uri;
url::redirect($redirect);
}
}
if(moputil::checkRoleAccess($aRole)){
$accessGranted = true;
}
}
} else {
if($role=='admin'){
if(Kohana::config('mop.staging_enabled') && !Kohana::config('mop.staging')){
$redirect = 'staging/'. Router::$current_uri;
url::redirect($redirect);
}
}
$accessGranted = moputil::checkRoleAccess($role);
}
if(!$accessGranted){
$redirect = 'accessdenied';
url::redirect($redirect);
exit;
}
}
protected function loadResources($key){
if(is_subclass_of(self::$topController, 'Controller_MOP')){
//should add to self, then merge into topController
if($css = Kohana::find_file('views', 'css/'.$key, 'css')){
$this->resources['css'][$css] = helper_mop::convertFullPathToWebPath($css);
}
if($js = Kohana::find_file('views', 'js/'.$key, 'js')){
$this->resources['js'][$js] = helper_mop::convertFullPathToWebPath($js);
}
}
$config = Kohana::config($key);
//look up all matching js and css configured in the config file
if(is_array(Kohana::config($key.'.resources') ) ){
foreach(Kohana::config($key.'.resources') as $key => $paths){
foreach($paths as $path){
$this->resources[$key][$path] = $path;
}
}
}
//and merge into the top controller
if($this != self::$topController){
foreach(array_keys($this->resources) as $key){
self::$topController->resources[$key] = array_merge(self::$topController->resources[$key], $this->resources[$key]);
}
}
}
}
Jump to Line
Something went wrong with that request. Please try again.