Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 59f2a51535
Fetching contributors…

Cannot retrieve contributors at this time

147 lines (118 sloc) 3.675 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();
}
/*
* 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(){
Kohana::$log->add(Log::ERROR, 'Skipping login for control panel');
/* SKIPPING LOGIN
//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(){
$this->loadResourcesForKey($this->controllerName);
$parents = $this->getParents();
foreach($parents as $parent){
if($parent == 'Controller_MOP'){
break;
}
if(strstr($parent, 'Controller')){
$parentKey = substr($parent, 11);
} else {
$parentKey = $parent;
}
$this->loadResourcesForKey($parentKey);
}
}
protected function loadResourcesForKey($key){
//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]);
}
}
}
public function getParents($class=null, $plist=array()) {
$class = $class ? $class : $this;
$parent = get_parent_class($class);
if($parent) {
$plist[] = $parent;
/*Do not use $this. Use 'self' here instead, or you
* * will get an infinite loop. */
$plist = self::getParents($parent, $plist);
}
return $plist;
}
}
Jump to Line
Something went wrong with that request. Please try again.