diff --git a/dist/twist/Core/Controllers/Base.controller.php b/dist/twist/Core/Controllers/Base.controller.php index 86fc0f04..d65db7e4 100755 --- a/dist/twist/Core/Controllers/Base.controller.php +++ b/dist/twist/Core/Controllers/Base.controller.php @@ -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){ diff --git a/dist/twist/Core/Controllers/Upload.controller.php b/dist/twist/Core/Controllers/Upload.controller.php index b4c65737..c07051d7 100755 --- a/dist/twist/Core/Controllers/Upload.controller.php +++ b/dist/twist/Core/Controllers/Upload.controller.php @@ -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); diff --git a/dist/twist/Core/Utilities/Route.utility.php b/dist/twist/Core/Utilities/Route.utility.php index 69b899c7..fbab7b65 100755 --- a/dist/twist/Core/Utilities/Route.utility.php +++ b/dist/twist/Core/Utilities/Route.utility.php @@ -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; @@ -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, @@ -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; @@ -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