private function filterHrefWithPath($matches) {

		static $script;
		static $observeRewrite;
		static $config;
		static $assetsPath;

		if(is_null($config)) {
			$application = Application::getInstance();

			$config = $application->getConfig();
			$observeRewrite = $application->getRouter()->getServerSideRewrite();
		}

		if(is_null($script)) {
			$script = basename(trim(Request::createFromGlobals()->getScriptName(), '/'));
		}

		$matchSegments = explode('/', $matches[3]);
		$pathToFind = array_shift($matchSegments);
		
		$recursiveFind = function(Menu $m) use (&$recursiveFind, $pathToFind) {

			foreach($m->getEntries() as $e) {

				if($e->getPath() === $pathToFind) {
					return $e;
				}

				if(($sm = $e->getSubMenu()) && $sm->getType() !== 'dynamic') {
					if($e = $recursiveFind($sm)) {
						return $e;
					}
				}
			}

		};

		foreach($config->menus as $menu) {
			if($menu->getScript() === $script) {
				if(($e = $recursiveFind($menu))) {
					break;
				}
			}
		}

		if(isset($e)) {

			$pathSegments = [$e->getPath()];

			while($e = $e->getMenu()->getParentEntry()) {
				$pathSegments[] = $e->getPath();
			}

			$uriParts = [];

			if($observeRewrite) {
				if($script !== 'index.php') {
					$uriParts[] = basename($script, '.php');
				}
			}
			else {
				if(is_null($assetsPath)) {
					$assetsPath = Application::getInstance()->getRelativeAssetsPath();
				}

				$uriParts[] = ltrim($assetsPath, '/') . $script;
			}
			if(count($pathSegments)) {
				$uriParts[] = implode('/', array_reverse($pathSegments));
			}
			if(count($matchSegments)) {
				$uriParts[] = implode('/', $matchSegments);
			}

			$uri = implode('/', $uriParts) . $matches[4];

			return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";

		}
	}
private function filterHrefWithPath($matches) {

		static $script;
		static $observeRewrite;
		static $config;
		static $assetsPath;

		if(is_null($config)) {
			$application = Application::getInstance();

			$config = $application->getConfig();
			$observeRewrite = $application->getRouter()->getServerSideRewrite();
		}

		if(is_null($script)) {
			$script = basename(trim(Request::createFromGlobals()->getScriptName(), '/'));
		}

		$matchSegments = explode('/', $matches[3]);
		$pathToFind = array_shift($matchSegments);
		
		$recursiveFind = function(Menu $m) use (&$recursiveFind, $pathToFind) {

			foreach($m->getEntries() as $e) {

				if($e->getPath() === $pathToFind) {
					return $e;
				}

				if(($sm = $e->getSubMenu()) && $sm->getType() !== 'dynamic') {
					if($e = $recursiveFind($sm)) {
						return $e;
					}
				}
			}

		};

		foreach($config->menus as $menu) {
			if($menu->getScript() === $script) {
				if(($e = $recursiveFind($menu))) {
					break;
				}
			}
		}

		if(isset($e)) {

			$pathSegments = [$e->getPath()];

			while($e = $e->getMenu()->getParentEntry()) {
				$pathSegments[] = $e->getPath();
			}

			$uriParts = [];

			if($observeRewrite) {
				if($script !== 'index.php') {
					$uriParts[] = basename($script, '.php');
				}
			}
			else {
				if(is_null($assetsPath)) {
					$assetsPath = Application::getInstance()->getRelativeAssetsPath();
				}

				$uriParts[] = ltrim($assetsPath, '/') . $script;
			}
			if(count($pathSegments)) {
				$uriParts[] = implode('/', array_reverse($pathSegments));
			}
			if(count($matchSegments)) {
				$uriParts[] = implode('/', $matchSegments);
			}

			$uri = implode('/', $uriParts) . $matches[4];

			return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";

		}
	}
private function filterHrefWithPath ( $ matches ) { static $ script ; static $ observeRewrite ; static $ config ; static $ assetsPath ; if ( is_null ( $ config ) ) { $ application = Application :: getInstance ( ) ; $ config = $ application -> getConfig ( ) ; $ observeRewrite = $ application -> getRouter ( ) -> getServerSideRewrite ( ) ; } if ( is_null ( $ script ) ) { $ script = basename ( trim ( Request :: createFromGlobals ( ) -> getScriptName ( ) , '/' ) ) ; } $ matchSegments = explode ( '/' , $ matches [ 3 ] ) ; $ pathToFind = array_shift ( $ matchSegments ) ; $ recursiveFind = function ( Menu $ m ) use ( & $ recursiveFind , $ pathToFind ) { foreach ( $ m -> getEntries ( ) as $ e ) { if ( $ e -> getPath ( ) === $ pathToFind ) { return $ e ; } if ( ( $ sm = $ e -> getSubMenu ( ) ) && $ sm -> getType ( ) !== 'dynamic' ) { if ( $ e = $ recursiveFind ( $ sm ) ) { return $ e ; } } } } ; foreach ( $ config -> menus as $ menu ) { if ( $ menu -> getScript ( ) === $ script ) { if ( ( $ e = $ recursiveFind ( $ menu ) ) ) { break ; } } } if ( isset ( $ e ) ) { $ pathSegments = [ $ e -> getPath ( ) ] ; while ( $ e = $ e -> getMenu ( ) -> getParentEntry ( ) ) { $ pathSegments [ ] = $ e -> getPath ( ) ; } $ uriParts = [ ] ; if ( $ observeRewrite ) { if ( $ script !== 'index.php' ) { $ uriParts [ ] = basename ( $ script , '.php' ) ; } } else { if ( is_null ( $ assetsPath ) ) { $ assetsPath = Application :: getInstance ( ) -> getRelativeAssetsPath ( ) ; } $ uriParts [ ] = ltrim ( $ assetsPath , '/' ) . $ script ; } if ( count ( $ pathSegments ) ) { $ uriParts [ ] = implode ( '/' , array_reverse ( $ pathSegments ) ) ; } if ( count ( $ matchSegments ) ) { $ uriParts [ ] = implode ( '/' , $ matchSegments ) ; } $ uri = implode ( '/' , $ uriParts ) . $ matches [ 4 ] ; return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>" ; } }
callback to turn href shortcuts into site conform valid URLs
tries to build a path reflecting the position of the page in a nested menu

$foo/bar?baz=1 becomes /level1/level2/foo/bar?baz=1 or index.php/level1/level2/foo/bar?baz=1

@param array $matches
@return string
callback to turn href shortcuts into site conform valid URLs tries to build a path reflecting the position of the page in a nested menu