$v) { $aline=array(); if (is_array($v)) { $aline=$v; #is instuction limiting processing to one direction if (array_key_exists('Direction',$aline)) { if ($direction!=$aline['Direction']) { continue; } } } else { #default to basic instruction format $aline['Mode']='BeginsWith'; $aline['PageName']=$k; $aline['Url']=$v; } $aline['Direction']=$direction; if (!array_key_exists('Mode',$aline)) { continue; } $modefunc='RT_'.$aline['Mode']; if (!function_exists($modefunc)) { continue; } $path=$modefunc($path,$aline); } return $path; } /// /// Determines search and replace values based on inbound/outbound direction of /// the link being processed /// function RouteGetSearchReplace($aline) { if ('Out'==@$aline['Direction']) { return array( @$aline['PageName'] #search ,@$aline['Url'] #replace ); } return array( @$aline['Url'] #search ,@$aline['PageName'] #replace ); } /// /// For a match, the search value must start at the beginning of the path. /// function RT_BeginsWith($path,$aline) { list($search,$replace)=RouteGetSearchReplace($aline); if (strpos($path,$search)===0) { $path=substr_replace($path,$replace,0,strlen($search)); } return $path; } /// /// For a match, the search value can be found anywhere in the path /// function RT_Contains($path,$aline) { list($search,$replace)=RouteGetSearchReplace($aline); $path=str_replace($search,$replace,$path); return $path; } /// /// For a match, the search value must be at the end of the path /// function RT_EndsWith($path,$aline) { list($search,$replace)=RouteGetSearchReplace($aline); if (substr($path,-strlen($search))===$search) { $path=substr_replace($path,$replace,-strlen($search),strlen($search)); } return $path; } /// /// For a match, the search value must be exactly equal to the path /// function RT_ExactMatch($path,$aline) { list($search,$replace)=RouteGetSearchReplace($aline); if ($path==$search) { return $replace; } return $path; } /// /// Process a search/replace pair with preg_replace() /// function RT_RegReplace($path,$aline) { if (!array_key_exists('Search',$aline) or !array_key_exists('Replace',$aline)) { return $path; } $limit=-1; if (array_key_exists('Limit',$aline)) { $limit=$aline['Limit']; } $path=preg_replace($aline['Search'],$aline['Replace'],$path,$limit); return $path; } /// /// Converts between lower-case-urls and CamelCase page names /// function RT_CamelCaseToLowerCase($path,$aline) { if('In'==@$aline['Direction']) { $path=strtr($path,array('-'=>' ','/'=>"\t",'.'=>"\t")); $path=ucwords($path); $path=strtr($path,array(' '=>'',"\t"=>'/')); return $path; } $path=addcslashes($path,'A..Z'); $path=strtr($path,array('/\\'=>'/','\\'=>'-')); $path=strtolower($path); $path=ltrim($path,'-'); return $path; }