/** * Process incoming parameters and display the page. * * @return void * @access public */ public function launch() { global $interface; global $configArray; if (isset($_REQUEST['proxyitem'])) { $url = $configArray['OpenURL']['url']; // Strip main directory $url = substr($url, 0, strrpos($url, '/')); $url .= $_REQUEST['proxyitem']; $request = new Proxy_Request(); $request->setMethod(HTTP_REQUEST_METHOD_GET); $request->setURL($url); $request->addHeader('X-Forwarded-For', $_SERVER['REMOTE_ADDR']); if (isset($configArray['OpenURL']['language'][$interface->lang])) { $request->addCookie('user-Profile', '%2B%2B%2B' . $configArray['OpenURL']['language'][$interface->lang]); } $result = $request->sendRequest(); if (PEAR::isError($result)) { die($result->getMessage() . "\n"); } foreach ($request->getResponseHeader() as $name => $value) { if (strcasecmp($name, 'content-type') == 0 || strcasecmp($name, 'content-length') == 0) { header("{$name}: {$value}"); } } echo $request->getResponseBody(); exit; } header('Content-type: text/html; charset=UTF-8'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past if (!isset($_REQUEST['openurl']) || !$_REQUEST['openurl']) { die("Missing parameter 'openurl'"); return; } $url = $configArray['OpenURL']['url']; $baseURL = substr($url, 0, strrpos($url, '/')); $proxyURL = $configArray['Site']['url'] . '/AJAX/SFXMenu?action=SFXMenu&proxyitem='; if (substr($_REQUEST['openurl'], 0, 1) != '?') { $url .= '?'; } $url .= $_REQUEST['openurl']; $request = new Proxy_Request(); $request->setMethod(HTTP_REQUEST_METHOD_GET); $request->setURL($url); $request->addHeader('X-Forwarded-For', $_SERVER['REMOTE_ADDR']); if (isset($configArray['OpenURL']['language'][$interface->lang])) { $request->addCookie('user-Profile', '%2B%2B%2B' . $configArray['OpenURL']['language'][$interface->lang]); } // Perform request and die on error $result = $request->sendRequest(); if (PEAR::isError($result)) { die($result->getMessage() . "\n"); } $html = new simple_html_dom(); $html->load($request->getResponseBody()); echo <<<EOF <html> <head> EOF; // Get style sheets and scripts foreach ($html->find('head link') as $link) { if (substr($link->href, 0, 1) == '/') { $link->href = $proxyURL . urlencode($link->href); } elseif (strcasecmp(substr($link->href, 0, strlen($baseURL)), $baseURL) == 0) { $link->href = $proxyURL . urlencode(substr($link->href, strlen($baseURL))); } echo "{$link}\n"; } foreach ($html->find('head script') as $script) { if (substr($script->src, 0, 1) == '/' || substr($script->src, 0, 1) == '.') { $script->src = $proxyURL . urlencode($script->src); } else { $src = parse_url($script->src); // proxify only if not secure url if (strcasecmp($src['scheme'], 'http') == 0) { $script->src = $proxyURL . urlencode($src['path']); } } echo "{$script}\n"; } echo <<<EOF <script type="text/javascript"> function openWindow(obj, form_name) { var form = \$("form[name=" + form_name + "]"); var url = form.attr('action'); var params = ''; form.find("input[type=hidden]").each(function() { if (params) { params += '&'; } params += encodeURIComponent(\$(this).attr('name')) + '=' + encodeURIComponent(\$(this).attr('value')); }); var win = window.open(); win.location = url + '?' + params; } </script> </head> <body> EOF; $container = $html->find('#basic_target_list_container', 0); if (!$container) { $container = $html->find('#advanced_target_list_container', 0); } if ($container) { // We have some actual items to display $table = $container->parent(); foreach ($table->find('img') as $img) { if (substr($img->src, 0, 1) == '/') { $img->src = $proxyURL . urlencode($img->src); } } foreach ($table->find('form') as $form) { if (substr($form->action, 0, 1) == '/') { $form->action = $baseURL . $form->action; } } echo $table; } echo <<<EOF </body> </html> EOF; }
/** * Make an OAI-PMH request. Die if there is an error; return a SimpleXML object * on success. * * @param string $verb OAI-PMH verb to execute. * @param array $params GET parameters for ListRecords method. * * @return object SimpleXML-formatted response. * @access private */ private function _sendRequest($verb, $params = array()) { // Debug: if ($this->_verbose) { echo "Sending request: verb = {$verb}, params = "; print_r($params); } // Set up retry loop: while (true) { // Set up the request: $request = new Proxy_Request(); $request->setMethod(HTTP_REQUEST_METHOD_GET); $request->setURL($this->_baseURL); // Load request parameters: $request->addQueryString('verb', $verb); foreach ($params as $key => $value) { $request->addQueryString($key, $value); } // Perform request and die on error: $result = $request->sendRequest(); if (PEAR::isError($result)) { die($result->getMessage() . "\n"); } // Check for 503 response. if ($request->getResponseCode() == 503) { $delay = $request->getResponseHeader('Retry-After'); if ($delay > 0) { if ($this->_verbose) { echo "Received 503 response; waiting {$delay} seconds...\n"; } sleep($delay); } } else { // If we didn't get a 503, we can leave the retry loop: break; } } // If we got this far, there was no error -- send back response. $response = $request->getResponseBody(); return $this->_processResponse($response); }