hkit-issues

Jump to: navigation, search

hKit Issues

		private function resolvePath($filepath)
		{	// ugly code ahoy: needs a serious tidy up
					
			$filepath	= $filepath[0];
			
			$bits = parse_url( $filepath );
			if ( !empty( $bits['scheme'] ) ) {
				return $filepath;
			}
			
			$base 	= $this->base;
			$url	= $this->url;
			
			$bits = parse_url( $base );
			if ( !empty( $bits['scheme'] ) )
				$url = $base;
			
			$r		= parse_url($url);
			$domain	= $r['scheme'] . '://' . $r['host'];

			if (!isset($r['path'])) $r['path'] = '/';
			$path	= explode('/', $r['path']);
			$file	= explode('/', $filepath);
			$new	= array('');

			if ($file[0] == ''){
				// absolute path
				return ''.$domain . implode('/', $file);
			}else{
				// relative path
				if ($path[sizeof($path)-1] == '') array_pop($path);
				if (strpos($path[sizeof($path)-1], '.') !== false) array_pop($path);

				foreach ($file as $segment){
					if ($segment == '..'){
						array_pop($path);
					}else{
						$new[]	= $segment;
					}
				}
				return ''.$domain . implode('/', $path) . implode('/', $new);
			}	
		}
hkit-issues was last modified: Monday, July 27th, 2009

Views