All pastes #888994 Raw Edit

Something

public php v1 · immutable
#888994 ·published 2008-02-02 16:18 UTC
rendered paste body
function proxifyURL($url,$flag='',$absolute=true) {	global $base, $options;		if ( empty($url) ) return '';		// Ignore anchors	if ( $url{0} == '#' ) return $url;		// Ignore javascript	if ( strpos($url,'javascript:') === 0 ) return $url;		// Avoid double proxifying	if ( strpos($url,optURL) === 0 ) return $url;		// Absolute path from root	if ( strlen($url) && $url{0} == '/' ) {		$url = urlHOST . substr($url,1);	} else if ( strpos($url,'http://') !== 0 && strpos($url,'https://') !== 0 ) {		if ( $url == '.' )			$url = '';		if ( $base ) {			// Relative from BASE			$url = $base . $url;		} else {			// Relative from document			$url = urlHOST . urlPATH . $url;		}	}	// Simplify path	# Strip ./ (refers to current directory)	$url = str_replace('/./','/',$url);	if ( strlen($url) > 8 && strpos($url,'//',8) ) 		$url = preg_replace('#(?<!:)//#','/',$url);	# Convert ../ (= up a directory)	if ( strpos($url,'../') ) {		$parts = explode('/',$url);				// No directories to expand		if ( count($parts) == 1 ) return $url;				# Continue to loop through array while we still have ..		while ( in_array('..',$parts) ) {			// Check each part of the URL			foreach ( $parts as $key => $level ) {				// If this is the .., remove it and the previous directory				// so in effect we've travelled up a directory 				if ( $level == '..' ) {					unset($parts[$previous]);					unset($parts[$key]);					break;				}				// If we remove more than one .. part, keys will no				// longer be consecutively ordered				$previous = $key;			}		}		# Return joined URI		$url = implode('/',$parts);	}	// Extract an #anchor	$jumpTo = '';	if ( strpos($url,'#') && preg_match('/#(.*)$/',$url,$anchor) ) {		$jumpTo = $anchor[0];		$url = str_replace($jumpTo,'',$url);	}	// Use base64 to hide target URL	if ( $options['encodeURL'] ) {	$uniquekey = "4";   	global $uniquekey;     $array = str_split($url);     foreach($array as &$a)     {         $a = ord($a);         $a = $a * $uniquekey;     }     $url = implode('_',$array);     return $url;}	$suffix = defined('BITFIELD') ? '&b=' . BITFIELD : '';	if ( $flag ) $suffix .= '&f='.$flag;		$prefix = $absolute ? optURL : '';	return $prefix . 'browse.php?u='.$url . $suffix . $jumpTo;}// Accepts http://yourproxy.site/browse.php?u=STRING and converts to// http://www.domain.com/somepage.phpfunction deproxifyURL($url) {	// Remove our proxy URI	$url = str_replace(array(optURL,'browse.php?u='),'',$url);   global $uniquekey;     $array = explode("_", $url);     foreach($array as &$a)     {         $a = $a / $uniquekey;         $a = chr($a);     }     $url = implode('', $array); 		return $url;}