Skip to content

Commit

Permalink
Merge 2f302f5 into 97e4794
Browse files Browse the repository at this point in the history
  • Loading branch information
danrwalker committed Mar 24, 2016
2 parents 97e4794 + 2f302f5 commit 1f18fed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 62 deletions.
62 changes: 3 additions & 59 deletions dist/twist/Core/Models/Debug.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,72 +141,16 @@ public function window($arrCurrentRoute){
$arrTags['current_route'] .= $this->resTemplate->build('components/table-row.tpl',array('key' => $strKey,'value' => is_array($strValue) ? sprintf('<pre>%s</pre>',print_r($strValue,true)) : htmlentities($strValue),'type' => gettype($strValue),'length' => $intLength));
}


$arrTags['routes'] = '';

$arrRestrictions = \Twist::Route()->getRestrictions();

foreach(\Twist::Route()->getAll() as $strType => $arrItems){
foreach($arrItems as $arrEachRoute){

$arrEachRoute['highlight'] = ($arrEachRoute['registered_uri'] === $arrCurrentRoute['registered_uri']) ? 'highlight' : '';
$arrEachRoute['item'] = (is_array($arrEachRoute['item'])) ? implode('->',$arrEachRoute['item']) : $arrEachRoute['item'];


/**
* This might need to be done in a different way (maybe make a public function in routes)
*/
$blRestrict = false;
$arrFoundMatched = array();

foreach($arrRestrictions['restricted'] as $strRestrictURI => $arrRestrictedInfo){

$strRestrictExpression = sprintf("#^(%s[\/]?)%s#", str_replace('/','\/',rtrim($strRestrictURI, '/')), $arrRestrictedInfo['wildcard'] ? '' : '$');

//Check for an exact match
if(rtrim($strRestrictURI,'/') == rtrim($arrEachRoute['uri'],'/')){

$arrMatch = $arrRestrictedInfo;
$blRestrict = true;
break;

}elseif(preg_match($strRestrictExpression, $arrEachRoute['uri'], $arrMatches)){
$arrFoundMatched[] = $arrRestrictedInfo;
}
}

//No exact mach found and there is an array to be processed
if($blRestrict == false && count($arrFoundMatched)){

if(count($arrFoundMatched) == 1){
$blRestrict = true;
$arrMatch = $arrFoundMatched[0];
}else{

//Process Multi-Matches, find the highest level from the found matches, user must match or exceed this level (0 is God)
$intHighestLevel = 0;
foreach($arrFoundMatched as $arrEachMatch){
if($arrEachMatch['level'] == 0 || $arrEachMatch['level'] > $intHighestLevel){
$intHighestLevel = $arrEachMatch['level'];
$arrMatch = $arrEachMatch;
$blRestrict = true;

if($intHighestLevel == 0){
break;
}
}
}
}
}
/**
* Above might need to be done in a different way (maybe make a public function in routes)
*/


$arrEachRoute['restricted'] = '';
//If a match is found
if($blRestrict){
$arrEachRoute['restricted'] = 'Restricted ['.$intHighestLevel.']';
}
$arrRestriction = \Twist::Route()->currentRestriction(($arrEachRoute['registered_uri'] == '') ? '/' : $arrEachRoute['registered_uri']);
$arrEachRoute['restricted'] = ($arrRestriction['restricted_uri']) ? 'Restricted ['.$arrRestriction['restricted_level'].']' : '';

$arrTags['routes'] .= $this->resTemplate->build('components/each-route.tpl',$arrEachRoute);
}
Expand Down
15 changes: 12 additions & 3 deletions dist/twist/Core/Utilities/Route.utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,9 @@ public function currentRestriction($strCurrentURI){
'login_required' => false,
'allow_access' => true,
'login_uri' => $strFullLoginURI,
'status' => 'Ignored, unrestricted page'
'status' => 'Ignored, unrestricted page',
'restricted_uri' => false,
'restricted_level' => null
);

}else{
Expand All @@ -1051,6 +1053,9 @@ public function currentRestriction($strCurrentURI){
$arrMatch['allow_access'] = false;
$arrMatch['status'] = 'User must be logged in to access restricted page';
}

$arrMatch['restricted_uri'] = true;
$arrMatch['restricted_level'] = $arrMatch['level'];
}

$arrMatch['login_uri'] = $strFullLoginURI;
Expand All @@ -1059,15 +1064,19 @@ public function currentRestriction($strCurrentURI){
'login_required' => false,
'allow_access' => true,
'login_uri' => $strFullLoginURI,
'status' => 'No restriction found'
'status' => 'No restriction found',
'restricted_uri' => false,
'restricted_level' => null
);
}
}else{
$arrMatch = array(
'login_required' => false,
'allow_access' => true,
'login_uri' => $strFullLoginURI,
'status' => 'No restriction found'
'status' => 'No restriction found',
'restricted_uri' => false,
'restricted_level' => null
);
}

Expand Down

0 comments on commit 1f18fed

Please sign in to comment.