} var proxied = window.XMLHttpRequest.prototype.open; window.XMLHttpRequest.prototype.open = function() { if (arguments[1] !== null && arguments[1] !== undefined) { var url = arguments[1]; url = rel2abs("' . $url . '", url); url = "' . PROXY_PREFIX . '" + url; arguments[1] = url; } return proxied.apply(this, [].slice.call(arguments)); }; } })();'); $scriptElem->setAttribute("type", "text/javascript"); $prependElem->insertBefore($scriptElem, $prependElem->firstChild); } echo "<!-- Proxified page constructed by miniProxy -->\n" . $doc->saveHTML(); } else { if (stripos($contentType, "text/css") !== false) { //This is CSS, so proxify url() references. echo proxifyCSS($responseBody, $url); } else { //This isn't a web page or CSS, so serve unmodified through the proxy with the correct headers (images, JavaScript, etc.) header("Content-Length: " . strlen($responseBody)); echo $responseBody; } }
$element->setAttribute("style", proxifyCSS($element->getAttribute("style"), $url)); } //Proxify any of these attributes appearing in any tag. $proxifyAttributes = array("href", "src"); foreach ($proxifyAttributes as $attrName) { //For every element with the given attribute... foreach ($xpath->query('//*[@' . $attrName . ']') as $element) { $attrContent = $element->getAttribute($attrName); if ($attrName == "href" && (stripos($attrContent, "javascript:") === 0 || stripos($attrContent, "mailto:") === 0)) { continue; } $attrContent = rel2abs($attrContent, $url); //Replace any leftmost question mark with an ampersand to blend an existing query string into the proxified URL $attrContent = preg_replace("/\\?/", "&", $attrContent, 1); $attrContent = PROXY_PREFIX . $attrContent; $element->setAttribute($attrName, $attrContent); } } echo $doc->saveHTML(); } else { if (stripos($file["contentType"], "text/css") !== false) { echo proxifyCSS($file["data"], $url); } else { if (stripos($file["contentType"], "javascript") !== false) { echo proxifyJS($file["data"], $url); } else { header("Content-Length: " . strlen($file["data"])); echo $file["data"]; } } }