Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/TwistPHP/TwistPHP in…
Browse files Browse the repository at this point in the history
…to jsdocs
  • Loading branch information
ahosgood committed May 17, 2016
2 parents 9227d34 + 830a6d2 commit e6e38be
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/twist/Core/Controllers/Base.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function _model(){
* Get a Route URI var from the route vars, passing in null will return the whole array of route vars.
*
* @param null $strVarKey
* @return array|null
* @return string|array|null
*/
protected function _var($strVarKey = null){

Expand Down
24 changes: 17 additions & 7 deletions dist/twist/Core/Controllers/Upload.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,29 @@ public function asset($strFileKey = null,$intIndex = null){
//Now if the file upload was successful process the asset (if required)
if($arrOut['status']){

$arrDynamicRoute = $this->_route('dynamic');

//Get the asset group to be used for the upload
$arrAssetGroup = array();
$intAssetGroup = \Twist::framework()->setting('ASSET_DEFAULT_GROUP');

if(count($arrDynamicRoute)){
if(count($arrDynamicRoute) > 1 && $arrDynamicRoute[0] == 'asset'){
$intAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[1]);
}elseif($arrDynamicRoute[0] !== 'asset'){
$intAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[0]);
//Allow for a URI to be registered such as: Twist::Route()->upload('/account/upload/{function}/{asset_group}');
if($this->_var('asset_group') != null && $this->_var('asset_group') != ''){
$arrAssetGroup = \Twist::Asset()->getGroupBySlug($this->_var('asset_group'));
}else{
$arrDynamicRoute = $this->_route('dynamic');

if(count($arrDynamicRoute)){
if(count($arrDynamicRoute) > 1 && $arrDynamicRoute[0] == 'asset'){
$arrAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[1]);
}elseif($arrDynamicRoute[0] !== 'asset'){
$arrAssetGroup = \Twist::Asset()->getGroupBySlug($arrDynamicRoute[0]);
}
}
}

if(count($arrAssetGroup)){
$intAssetGroup = $arrAssetGroup['id'];
}

$intAssetID = \Twist::Asset()->add($arrOut['file']['path'],$intAssetGroup);
$arrAsset = \Twist::Asset()->get($intAssetID);

Expand Down
28 changes: 24 additions & 4 deletions dist/twist/Core/Utilities/Route.utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public function baseURI($strBaseURI = null){
public function packageURI($strPackage = null){

if(!is_null($strPackage)){
$strPath = sprintf('%s/%s',rtrim(TWIST_PACKAGES,'/'),ltrim($strPackage,'/'));
$this->strPackageURI = '/'.ltrim(rtrim(str_replace(TWIST_DOCUMENT_ROOT,"",$strPath),'/'),'/');
$strPath = sprintf('%s/%s',rtrim(TWIST_PACKAGES,'/'),ltrim($strPackage,'/'));
$this->strPackageURI = '/'.ltrim(rtrim(str_replace(TWIST_DOCUMENT_ROOT,"",$strPath),'/'),'/');
}

return $this->strPackageURI;
Expand Down Expand Up @@ -280,6 +280,7 @@ protected function _restrictDefault($strURI,$strLoginURI){

if(!array_key_exists($strURI,$this->arrRestrict)){
$this->arrRestrict[$strURI] = array(
'uri' => $strURI,
'wildcard' => $blWildCard,
'login_uri' => '/'.ltrim(rtrim($strLoginURI,'/'),'/').'/',
'level' => null,
Expand Down Expand Up @@ -1003,9 +1004,28 @@ public function currentRestriction($strCurrentURI){
$arrMatch = $arrFoundMatched[0];
}else{

$arrFoundMatchedProcessed = array();
$intHighCount = 0;

//Pre-process the restricted results to get the best match
//Currently this is found by using the URI's will the most parts (These will be more accurate)
foreach($arrFoundMatched as $intKey => $arrEachMatch){

$strProcessedURI = str_replace(array('/%','%'),'',$arrEachMatch['uri']);
$intCount = count(explode('/',$strProcessedURI));

if($intCount > $intHighCount) {
$intHighCount = $intCount;
$arrFoundMatchedProcessed = array();
$arrFoundMatchedProcessed[] = $arrEachMatch;
}elseif($intCount == $intHighCount){
$arrFoundMatchedProcessed[] = $arrEachMatch;
}
}

//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){
foreach($arrFoundMatchedProcessed as $arrEachMatch){
if($arrEachMatch['level'] == 0 || $arrEachMatch['level'] > $intHighestLevel){
$intHighestLevel = $arrEachMatch['level'];
$arrMatch = $arrEachMatch;
Expand Down Expand Up @@ -1260,7 +1280,7 @@ public function serve($blExitOnComplete = true){
$arrRoute = $this->current();

if(count($arrRoute)){

$arrRoute['request_method'] = strtoupper($_SERVER['REQUEST_METHOD']);

//First of all check for a package interface and do that
Expand Down

0 comments on commit e6e38be

Please sign in to comment.