/** * Get data and output in JSON * * @return void * @access public */ public function getSearchLinkStatuses() { $metalib = new MetaLib(); if (!$metalib->available()) { // MetaLib not enabled return $this->output(array(), JSON::STATUS_OK); } // Cache values and status in an array $results = array(); $authorized = UserAccount::isAuthorized(); foreach ($_REQUEST['id'] as $id) { $ird = explode('.', $id, 2); if (!isset($ird[1])) { continue; } $ird = $ird[1]; $irdInfo = $metalib->getIRDInfo($ird); if ($irdInfo && ($authorized || strcasecmp($irdInfo['access'], 'guest') == 0)) { $results[] = array('id' => $id, 'status' => $irdInfo['searchable'] ? 'allowed' : 'nonsearchable'); } else { $results[] = array('id' => $id, 'status' => 'denied'); } } return $this->output($results, JSON::STATUS_OK); }
/** * Process parameters and display the page. * * @return void * @access public */ public function launch() { global $interface; global $configArray; if (isset($_REQUEST['export'])) { $ml = new MetaLib(); $format = strtolower($_REQUEST['export']); return $interface->fetch($ml->export($this->record, $format, true)); } // Send basic information to the template. $interface->assign('record', $this->record); $interface->setPageTitle($this->record['Title'][0]); // Assign the ID of the last search so the user can return to it. $lastsearch = isset($_SESSION['lastSearchURL']) ? $_SESSION['lastSearchURL'] : false; $interface->assign('lastsearch', $lastsearch); if ($lastsearch) { // Retrieve active filters and assign them to searchbox template. // Since SearchObjects use $_REQUEST to init filters, we stash the current $_REQUEST // and fill it temporarily with URL parameters from last search. $query = parse_url($lastsearch, PHP_URL_QUERY); parse_str($query, $vars); $oldReq = $_REQUEST; $_REQUEST = $vars; $searchObject = SearchObjectFactory::initSearchObject('MetaLib'); $searchObject->init(); // This is needed for facet labels $searchObject->initRecommendations(); $filterList = $searchObject->getFilterList(); $filterListOthers = $searchObject->getFilterListOthers(); $checkboxFilters = $searchObject->getCheckboxFacets(); $filterUrlParams = $searchObject->getfilterUrlParams(); if (isset($vars['lookfor'])) { $interface->assign('lookfor', $vars['lookfor']); } $interface->assign('filterUrlParam', $filterUrlParams[0]); $interface->assign(compact('filterList')); $interface->assign(compact('filterListOthers')); $interface->assign('checkboxFilters', $checkboxFilters); if (isset($_SERVER['HTTP_REFERER'])) { // Set followup module & action for next search $parts = parse_url($_SERVER['HTTP_REFERER']); $pathParts = explode('/', $parts['path']); $refAction = array_pop($pathParts); $refModule = array_pop($pathParts); $interface->assign('followupSearchModule', $refModule); $interface->assign('followupSearchAction', $refAction); } $_REQUEST = $oldReq; } // Set bX flag $interface->assign('bXEnabled', isset($configArray['bX']['token']) ? true : false); // Display Page $interface->setTemplate('record.tpl'); $interface->display('layout.tpl'); }
/** * Get data and output in JSON * * @return void * @access public */ public function getRSIStatuses() { //<SFX server>:<port>/<sfx_instance>/cgi/core/rsi/rsi.cgi global $configArray; if (!isset($configArray['OpenURL']['url'])) { return $this->output(array(), JSON::STATUS_OK); } $sfxUrl = $configArray['OpenURL']['url'] . "/cgi/core/rsi/rsi.cgi"; $metalib = new MetaLib(); $indexEngine = SearchObjectFactory::initSearchObject()->getIndexEngine(); $dom = new DOMDocument('1.0', 'UTF-8'); // ID REQUEST $idReq = $dom->createElement('IDENTIFIER_REQUEST', ''); $idReq->setAttribute("VERSION", "1.0"); $idReq->setAttribute("xsi:noNamespaceSchemaLocation", "ISSNRequest.xsd"); $idReq->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); $dom->appendChild($idReq); // Cache values and status in an array $rsiResults = array(); $validRequest = false; foreach ($_REQUEST['id'] as $id) { if (strncmp($id, 'metalib.', 8) == 0) { if (!($record = $metalib->getRecord($id))) { $this->output('Record does not exist', JSON::STATUS_ERROR); return; } $values = array('isbn' => !empty($record['ISBN']) ? $record['ISBN'][0] : '', 'issn' => !empty($record['ISSN']) ? $record['ISSN'][0] : '', 'year' => !empty($record['PublicationDate']) ? $record['PublicationDate'][0] : '', 'volume' => !empty($record['Volume']) ? $record['Volume'] : '', 'issue' => !empty($record['Issue']) ? $record['Issue'] : '', 'institute' => isset($configArray['OpenURL']['institute']) ? $configArray['OpenURL']['institute'] : ''); } else { if (!($record = $indexEngine->getRecord($id))) { $this->output('Record does not exist', JSON::STATUS_ERROR); return; } $recordDriver = RecordDriverFactory::initRecordDriver($record); $values = $recordDriver->getRSIValues($recordDriver); } $result = array('id' => $id, 'status' => 'noInformation'); // Ignore the record if mandatory elements are not available if (empty($values['issn']) && empty($values['isbn'])) { // Mark this result invalid so it can be skipped when processing results $result['invalid'] = true; $rsiResults[] = $result; continue; } $rsiResults[] = $result; $validRequest = true; // ID REQUEST ITEM $idReqItem = $dom->createElement('IDENTIFIER_REQUEST_ITEM', ''); $idReq->appendChild($idReqItem); // ID if (!empty($values['issn'])) { $identifier = $dom->createElement('IDENTIFIER', 'issn:' . $values['issn']); $idReqItem->appendChild($identifier); } if (!empty($values['isbn'])) { $identifier = $dom->createElement('IDENTIFIER', 'isbn:' . $values['isbn']); $idReqItem->appendChild($identifier); } // Optional elements if ($values['year']) { $year = $dom->createElement('YEAR', $values['year']); $idReqItem->appendChild($year); } if ($values['volume']) { $volume = $dom->createElement('VOLUME', $values['volume']); $idReqItem->appendChild($volume); } if ($values['issue']) { $issue = $dom->createElement('ISSUE', $values['issue']); $idReqItem->appendChild($issue); } if ($values['institute']) { $institute = $dom->createElement('INSTITUTE_NAME', $values['institute']); $idReqItem->appendChild($institute); } } if (!$validRequest) { return $this->output(array(), JSON::STATUS_OK); } $xml = $dom->saveXML(); $req = new Proxy_Request($sfxUrl, array('saveBody' => true)); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->addPostData('request_xml', $xml); $req->sendRequest(); $code = $req->getResponseCode(); if ($code != 200) { $this->output("SFX RSI request failed ({$code})", JSON::STATUS_ERROR); return; } $dom->loadXML($req->getResponseBody()); $items = $dom->getElementsByTagName('IDENTIFIER_RESPONSE_ITEM'); $position = -1; foreach ($items as $item) { $requests = $dom->getElementsByTagName('IDENTIFIER_REQUEST_ITEM'); $request = $requests->item(0); $position++; // Bypass invalid ID's and stop if at the end of list. while (isset($rsiResults[$position]['invalid'])) { ++$position; } if (!isset($rsiResults[$position])) { break; } $result = $item->getElementsByTagName('RESULT')->item(0)->nodeValue; if ($result == 'not found') { $rsiResults[$position]['status'] = 'noFullText'; } elseif ($result == 'maybe') { $rsiResults[$position]['status'] = 'maybeFullText'; } else { foreach ($item->getElementsByTagName('AVAILABLE_SERVICES') as $service) { if ($service->nodeValue == 'getFullTxt') { $peerReviewed = false; foreach ($item->getElementsByTagName('PEER_REVIEWED') as $peer) { if ($peer->nodeValue == 'YES') { $peerReviewed = true; break; } } $rsiResults[$position]['status'] = $peerReviewed ? 'peerReviewedFullText' : 'fullText'; break; } } } } $results = array(); foreach ($rsiResults as $result) { $results[] = array('id' => $result['id'], 'status' => $result['status']); } return $this->output($results, JSON::STATUS_OK); }
/** * Get data and output in JSON * * @return void * @access public */ public function getbXRecommendations() { global $configArray; if (!isset($configArray['bX']['token'])) { $this->output('bX support not enabled', JSON::STATUS_ERROR); return; } $id = $_REQUEST['id']; if (strncmp($id, 'metalib.', 8) == 0) { include_once 'sys/MetaLib.php'; $metalib = new MetaLib(); if (!($record = $metalib->getRecord($id))) { $this->output('Record does not exist', JSON::STATUS_ERROR); return; } $openUrl = $record['openUrl']; } elseif (strncmp($id, 'pci.', 4) == 0) { include_once 'sys/PCI.php'; $pci = new PCI(); if (!($record = $pci->getRecord($id))) { $this->output('Record does not exist', JSON::STATUS_ERROR); return; } $openUrl = $record['openUrl']; } else { $searchObject = SearchObjectFactory::initSearchObject(); if (!($record = $searchObject->getIndexEngine()->getRecord($id))) { $this->output('Record does not exist', JSON::STATUS_ERROR); return; } $recordDriver = RecordDriverFactory::initRecordDriver($record); $openUrl = $recordDriver->getOpenURL(); } $params = http_build_query(array('token' => $configArray['bX']['token'], 'format' => 'xml', 'source' => isset($configArray['bX']['source']) ? $configArray['bX']['source'] : 'global', 'maxRecords' => isset($configArray['bX']['maxRecords']) ? $configArray['bX']['maxRecords'] : '5', 'threshold' => isset($configArray['bX']['threshold']) ? $configArray['bX']['threshold'] : '50')); $openUrl .= '&res_dat=' . urlencode($params); $baseUrl = isset($configArray['bX']['baseUrl']) ? $configArray['bX']['baseUrl'] : 'http://recommender.service.exlibrisgroup.com/service/recommender/openurl'; $client = new HTTP_Request(); $client->setMethod(HTTP_REQUEST_METHOD_GET); $client->setURL($baseUrl . "?{$openUrl}"); $result = $client->sendRequest(); if (!PEAR::isError($result)) { // Even if we get a response, make sure it's a 'good' one. if ($client->getResponseCode() != 200) { $this->output('bX request failed, response code ' . $client->getResponseCode(), JSON::STATUS_ERROR); } } else { $this->_output('bX request failed: ' . $result, JSON::STATUS_ERROR); } $xml = simplexml_load_string($client->getResponseBody()); $data = array(); $jnl = 'info:ofi/fmt:xml:xsd:journal'; $xml->registerXPathNamespace('jnl', $jnl); foreach ($xml->xpath('//jnl:journal') as $journal) { $item = $this->convertToArray($journal, $jnl); if (!isset($item['authors']['author'][0])) { $item['authors']['author'] = array($item['authors']['author']); } $item['openurl'] = $this->createOpenUrl($item); $data[] = $item; } $this->output($data, JSON::STATUS_OK); }
/** * Get record and export data * Display error message on terminal error or email details page on success * * @param string $format The desired export format * @param array $ids A list of bib IDs * * @return array Record data for each ID, plus an list of IDs without results * @access public */ public function exportAll($format, $ids) { global $interface; global $configArray; $exportDetails = array(); $errorMsgDetails = array(); // MARC-XML needs a container at the start: if ($format == 'MARCXML') { $exportDetails[] = '<?xml version="1.0" encoding="UTF-8"?>' . '<collection xmlns="http://www.loc.gov/MARC21/slim">'; } foreach ($ids as $id) { // Retrieve the record from the index list($index, $recId) = explode('.', $id, 2); $current = null; if ($index === 'pci' || $index === 'metalib') { $format = strtolower($format); if ($index === 'pci') { $db = new SearchObject_PCI(); if ($rec = $db->getRecord($id)) { $pci = new PCI(); $current = $interface->fetch($pci->export($rec, $format)); } } else { if ($index === 'metalib') { $db = new MetaLib(); if ($rec = $db->getRecord($id)) { $current = $interface->fetch($db->export($rec, $format)); } } } if ($current) { $exportDetails[] = $current; } else { $errorMsgDetails[] = $id; } } else { if (!($record = $this->db->getRecord($id))) { $errorMsgDetails[] = $id; } else { $recordDetails = RecordDriverFactory::initRecordDriver($record); // Assign core metadata to be sure export has all necessary values // available: $recordDetails->getCoreMetadata(); $result = $recordDetails->getExport($format); if (!empty($result)) { $interface->assign('id', $id); $current = $interface->fetch($result); // For MARC-XML, extract <record> from <collection>: if ($format == 'MARCXML') { $current = $this->extractXMLRecord($current); } if (!empty($current)) { $exportDetails[] = $current; } } else { $errorMsgDetails[] = $id; } } } } // MARC-XML needs a container close at the end: if ($format == 'MARCXML') { $exportDetails[] = '</collection>'; } $results = array('exportDetails' => $exportDetails, 'errorDetails' => $errorMsgDetails); return $results; }
/** * Support method -- get details about records based on an array of IDs. * * @param array $ids IDs to look up. * * @return array * @access protected */ protected function getRecordDetails($ids) { global $interface; $recordList = array(); $metalib = null; $pci = null; foreach ($ids as $id) { if (strncmp($id, 'metalib.', 8) == 0) { if (!isset($metalib)) { $metalib = new MetaLib(); } $record = $metalib->getRecord($id); $record['id'] = $id; $interface->assign('record', $record); $email = $interface->fetch('MetaLib/result-email.tpl'); $recordList[] = array('id' => $id, 'isbn' => isset($record['ISBN'][0]) ? $record['ISBN'][0] : '', 'author' => isset($record['Author'][0]) ? $record['Author'][0] : '', 'title' => isset($record['Title'][0]) ? $record['Title'][0] : '', 'format' => isset($record['format'][0]) ? $record['format'][0] : '', 'email' => $email); } elseif (strncmp($id, 'pci.', 4) == 0) { if (!isset($pci)) { $pci = new PCI(); } $record = $pci->getRecord($id); $interface->assign('record', $record); $email = $interface->fetch('PCI/result-email.tpl'); $recordList[] = array('id' => $id, 'isbn' => '', 'author' => isset($record['author'][0]) ? $record['author'][0] : '', 'title' => isset($record['title']) ? $record['title'] : '', 'format' => isset($record['format']) ? $record['format'] : '', 'email' => $email); } else { $record = $this->db->getRecord($id); $driver = RecordDriverFactory::initRecordDriver($record); $email = $interface->fetch($driver->getSearchResult('email')); $recordList[] = array('id' => $id, 'isbn' => isset($record['isbn']) ? $record['isbn'] : '', 'author' => isset($record['author']) ? $record['author'] : '', 'title' => $driver->getTitle(), 'format' => $record['format'], 'email' => $email); } } return $recordList; }