/** * Send an NCIP request. * * @param string $xml XML request document * * @return object SimpleXMLElement parsed from response * @access private */ private function _sendRequest($xml) { // Make the NCIP request: $client = new Proxy_Request(null, array('useBrackets' => false)); $client->setMethod(HTTP_REQUEST_METHOD_POST); $client->setURL($this->_config['Catalog']['url']); $client->addHeader('Content-type', 'application/xml; "charset=utf-8"'); $client->setBody($xml); $result = $client->sendRequest(); if (PEAR::isError($result)) { PEAR::raiseError($result); } // Process the NCIP response: $response = $client->getResponseBody(); $result = @simplexml_load_string($response); if (is_a($result, 'SimpleXMLElement')) { $result->registerXPathNamespace('ns1', 'http://www.niso.org/2008/ncip'); return $result; } else { PEAR::raiseError(new PEAR_Error("Problem parsing XML")); } }
/** * 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; }