public function getBody() { $body = $this->body; $content_type = $this->getContentType(); switch ($content_type) { case self::CONTENT_TYPE_JAVASCRIPT: case self::CONTENT_TYPE_JSON: case self::CONTENT_TYPE_TEXT_CSS: case self::CONTENT_TYPE_TEXT_HTML: $body = $this->getBodyFilteredByContentType($body, $content_type); // These filters apply to all of the above. TextInternalUrlFilters::applyAll($body); TextExternalUrlFilters::applyAll($body, $content_type); // Run this after the global filters above, to avoid rewriting some URLs twice. if ($content_type == self::CONTENT_TYPE_TEXT_HTML) { RedirectWhenBlockedFull::injectBaseTag($body); } // Remove content-length, since this might be different after modification. if (isset($this->headers['Content-Length'])) { unset($this->headers['Content-Length']); } Log::add($this->response->__toString(), '$this->response->__toString()'); break; } return $body; }
public static function run() { /* * Normal request. Substitute the response with our own page. */ if (!isset($_GET[self::QUERY_STRING_PARAM_NAME])) { $iframe_src = $_SERVER['REQUEST_URI']; if ($_SERVER['QUERY_STRING']) { $iframe_src .= '&'; } else { $iframe_src .= '?'; } $iframe_src .= self::QUERY_STRING_PARAM_NAME . '=' . self::OUTPUT_TYPE_IFRAME; $request_path_depth = count(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); $script_path_depth = count(explode('/', $_SERVER['SCRIPT_NAME'])); $rwb_path_relative_to_request_path = str_repeat('../', $request_path_depth - $script_path_depth) . 'rwb'; require 'substitute-page.php'; exit; } if (self::getOutputType() == self::OUTPUT_TYPE_JSONP) { // Output header now since other header output might block it later. header('Content-Type: application/javascript'); } // Turn on output buffer to capture all output. ob_start(); // Make this run after all output is completed. register_shutdown_function(function () { $html = ob_get_clean(); RedirectWhenBlockedFull::injectBaseTag($html); /* * This request comes from another base url (mirror or source host). * We take the normal output and turn it into a jsonp response. */ if (RedirectWhenBlockedFull::getOutputType() == RedirectWhenBlockedFull::OUTPUT_TYPE_JSONP) { print self::getJsonpCallbackName() . '(' . json_encode(array('html' => mb_convert_encoding_plus($html, 'UTF-8', RedirectWhenBlockedFull::getCharset($html)))) . ')'; } else { print $html; } }); }