Paste number 19649: proxy_url -- PHP

Paste number 19649: proxy_url -- PHP
Pasted by: rsinger
When:3 years, 2 months ago
Share:Tweet this! | http://paste.lisp.org/+F5T
Channel:None
Paste contents:
Raw Source | XML | Display As
**
 * @return array
 * @param string $xml
 * @desc Send a request to the proxy resolver and return the results as an array.
*/
function proxyUrls($xml, $proxy) {
	// Change this to the host of your proxy resolver
	$proxyResolver = $proxy["url"] . "proxy_url";		
	$xmlOpts = array("complexType"=>"array",
						"keyAttribute"=>"",
						"parseAttributes"=>true);	
	$us = new XML_Unserializer($xmlOpts);
	$http = new HttpClient($proxyResolver);
	$contents = $http->quickPost($proxyResolver, array("xml"=>$xml));		
	$proxiedLinks = array();
	$us->unserialize($contents, false);		
	$unXml = $us->getUnserializedData();
	
	$urls = $unXml["proxy_urls"]["url"];		
	if(!is_array($urls[0])) {		
		if($urls["proxy"] == "true") {			
			$url = $urls["scheme"] . "://" . $urls["hostname"];
			if($urls["port"]) {
				$url .= ":" . $urls["port"];
			}
			$url .= $urls["login_path"];
			$url .= $urls["_content"];
			$proxiedLinks[html_entity_decode($urls["_content"])] = $url;
		}	
	} else {
	
		for($i = 0; $i < count($urls); $i++) {			
			if($urls[$i]["proxy"] == "true") {					
				$url = $urls[$i]["scheme"] . "://" . $urls[$i]["hostname"];
				if($urls[$i]["port"]) {
					$url .= ":" . $urls[$i]["port"];
				}
				$url .= $urls[$i]["login_path"];
				//$url .= $urls[$i]["_content"];
				
				if($urls[$i]["encode"] == "true") {
					$url .= urlencode(html_entity_decode($urls[$i]["_content"]));
				} else {
					$url .= html_entity_decode($urls[$i]["_content"]);
				}
					
				//$proxiedLinks[html_entity_decode($urls[$i]["_content"])] = $url;				
				$proxiedLinks[$urls[$i]["_content"]] = $url;				
			}	
		}	
	}
	return $proxiedLinks;
}

/**
 * @return string
 * @param array $links
 * @param string $html
 * @desc Take the links array and HTML, rewrite the href attributes to go through the proxy server (when applicable) and return the HTML
*/
function proxyPage($links, $html) {
	$proxies = getProxies();
	for($i=0; $i<count($proxies);$i++) {
		$xml = makeXMLLinkDocument($links, $proxies[key($proxies)]);			
		$proxiedLinks = proxyUrls($xml, $proxies[key($proxies)]);				
		//$proxiedLinks = checkEZProxyConfig($links);
		for($i = 0; $i < count(array_keys($proxiedLinks)); $i++) {		
			$html = str_replace("href=\"" . key($proxiedLinks) . "\"", "href=\"" . $proxiedLinks[key($proxiedLinks)] . "\" class=\"proxiedLink\" ", $html);
			//$html = str_replace("href=" . $proxiedLinks[key($proxiedLinks)], "href=\"" . $proxiedLinks[key($proxiedLinks)] . "\" class=\"proxiedLink\" ", $html);
			next($proxiedLinks);	
		}
		next($proxies);
	}
	return $html;
}

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.