<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>19649</integer>
    </number>
    <user>
      <string>rsinger</string>
    </user>
    <title>
      <string>proxy_url -- PHP</string>
    </title>
    <contents>
      <string>**
 * @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[&quot;url&quot;] . &quot;proxy_url&quot;;		
	$xmlOpts = array(&quot;complexType&quot;=&gt;&quot;array&quot;,
						&quot;keyAttribute&quot;=&gt;&quot;&quot;,
						&quot;parseAttributes&quot;=&gt;true);	
	$us = new XML_Unserializer($xmlOpts);
	$http = new HttpClient($proxyResolver);
	$contents = $http-&gt;quickPost($proxyResolver, array(&quot;xml&quot;=&gt;$xml));		
	$proxiedLinks = array();
	$us-&gt;unserialize($contents, false);		
	$unXml = $us-&gt;getUnserializedData();
	
	$urls = $unXml[&quot;proxy_urls&quot;][&quot;url&quot;];		
	if(!is_array($urls[0])) {		
		if($urls[&quot;proxy&quot;] == &quot;true&quot;) {			
			$url = $urls[&quot;scheme&quot;] . &quot;://&quot; . $urls[&quot;hostname&quot;];
			if($urls[&quot;port&quot;]) {
				$url .= &quot;:&quot; . $urls[&quot;port&quot;];
			}
			$url .= $urls[&quot;login_path&quot;];
			$url .= $urls[&quot;_content&quot;];
			$proxiedLinks[html_entity_decode($urls[&quot;_content&quot;])] = $url;
		}	
	} else {
	
		for($i = 0; $i &lt; count($urls); $i++) {			
			if($urls[$i][&quot;proxy&quot;] == &quot;true&quot;) {					
				$url = $urls[$i][&quot;scheme&quot;] . &quot;://&quot; . $urls[$i][&quot;hostname&quot;];
				if($urls[$i][&quot;port&quot;]) {
					$url .= &quot;:&quot; . $urls[$i][&quot;port&quot;];
				}
				$url .= $urls[$i][&quot;login_path&quot;];
				//$url .= $urls[$i][&quot;_content&quot;];
				
				if($urls[$i][&quot;encode&quot;] == &quot;true&quot;) {
					$url .= urlencode(html_entity_decode($urls[$i][&quot;_content&quot;]));
				} else {
					$url .= html_entity_decode($urls[$i][&quot;_content&quot;]);
				}
					
				//$proxiedLinks[html_entity_decode($urls[$i][&quot;_content&quot;])] = $url;				
				$proxiedLinks[$urls[$i][&quot;_content&quot;]] = $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&lt;count($proxies);$i++) {
		$xml = makeXMLLinkDocument($links, $proxies[key($proxies)]);			
		$proxiedLinks = proxyUrls($xml, $proxies[key($proxies)]);				
		//$proxiedLinks = checkEZProxyConfig($links);
		for($i = 0; $i &lt; count(array_keys($proxiedLinks)); $i++) {		
			$html = str_replace(&quot;href=\&quot;&quot; . key($proxiedLinks) . &quot;\&quot;&quot;, &quot;href=\&quot;&quot; . $proxiedLinks[key($proxiedLinks)] . &quot;\&quot; class=\&quot;proxiedLink\&quot; &quot;, $html);
			//$html = str_replace(&quot;href=&quot; . $proxiedLinks[key($proxiedLinks)], &quot;href=\&quot;&quot; . $proxiedLinks[key($proxiedLinks)] . &quot;\&quot; class=\&quot;proxiedLink\&quot; &quot;, $html);
			next($proxiedLinks);	
		}
		next($proxies);
	}
	return $html;
}</string>
    </contents>
    <universal-time>
      <integer>3355671580</integer>
    </universal-time>
    <channel>
      <string>None</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
  </paste>
</paste-with-annotations>