/** * Retrieves a document specified by the ID and returns a MARC record. * * @param string $id The document to retrieve from Solr * @access public * @throws object PEAR Error * @return string The requested resource */ function getRecord($id) { if ($this->debug) { echo "<pre>Get Record: {$id}</pre>\n"; } // Query String Parameters $options = array('operation' => 'searchRetrieve', 'query' => "rec.id=\"{$id}\"", 'maximumRecords' => 1, 'startRecord' => 1, 'recordSchema' => 'marcxml'); $result = $this->_call('GET', $options, false); if (PEAR_Singleton::isError($result)) { PEAR_Singleton::raiseError($result); } $style = new DOMDocument(); $style->load('xsl/sru-marcxml.xsl'); $xsl = new XSLTProcessor(); $xsl->importStyleSheet($style); $xml = new DOMDocument(); $xml->loadXML($result); $marcxml = $xsl->transformToXML($xml); $marc = new File_MARCXML($marcxml, File_MARC::SOURCE_STRING); return $marc->next(); }
$sru_url = $config['sru']; $sru_url .= "?operation=searchRetrieve"; $sru_url .= "&version={$version}"; $sru_url .= "&query={$query}"; $sru_url .= "&recordSchema={$recordSchema}"; $sru_url .= "&startRecord={$startRecord}"; $sru_url .= "&maximumRecords={$maximumRecords}"; // Fetch the SRU data $sru_data = file_get_contents($sru_url) or exit("SRU error"); // Turn the returned XML in to pure MARCXML $sru_data = str_replace("<record xmlns=\"http://www.loc.gov/MARC21/slim\">", "<record>", $sru_data); preg_match_all('/(<record>.*?<\\/record>)/si', $sru_data, $treff); $marcxml = implode("\n\n", $treff[0]); $marcxml = '<?xml version="1.0" encoding="utf-8"?>' . "\n<collection>\n{$marcxml}\n</collection>"; // Parse the XML $records = new File_MARCXML($marcxml, File_MARC::SOURCE_STRING); // Get the first (and only) record $record = $records->next(); $out = ''; // Decide what to do based on the contents of the MARC record // Journals // Fetch TOC (most recent articles) by way of Journal TOCs // http://www.journaltocs.hw.ac.uk/index.php?action=api if ($record->getField("022") && $record->getField("022")->getSubfield("a")) { $issn = marctrim($record->getField("022")->getSubfield("a")); if ($issn) { $url = 'http://www.journaltocs.hw.ac.uk/api/journals/' . $issn . '?output=articles'; $xml = simplexml_load_file($url); $xml->registerXPathNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); $xml->registerXPathNamespace("prism", "http://prismstandard.org/namespaces/1.2/basic/"); $xml->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
/** * Set holdings structure * * @param String $holdingsXml * @throws \File_MARC_Exception */ protected function setHoldingsContent($holdingsXml) { if (is_string($holdingsXml) && strlen($holdingsXml) > 30) { $holdingsMarcXml = new \File_MARCXML($holdingsXml, \File_MARCXML::SOURCE_STRING); $marcData = $holdingsMarcXml->next(); if (!$marcData) { throw new \File_MARC_Exception('Cannot Process Holdings Structure'); } $this->holdings = $marcData; } else { // Invalid input data. Currently just ignore it $this->holdings = false; $this->holdingData = array(); } }
/** * Constructor * * @access public */ public function __construct() { global $configArray; global $interface; parent::__construct(); // Assign the ID of the last search so the user can return to it. $interface->assign('lastsearch', isset($_SESSION['lastSearchURL']) ? $_SESSION['lastSearchURL'] : false); $this->id = $_REQUEST['id']; $interface->assign('id', $this->id); $this->cacheId = 'WCRecord|' . $this->id . '|' . get_class($this); // Define Default Tab $tab = isset($_GET['action']) && $_GET['action'] != 'Record' ? $_GET['action'] : 'Holdings'; $interface->assign('tab', $tab); // Fetch Record $this->worldcat = new Worldcat(); $record = $this->worldcat->getRecord($this->id); if (PEAR::isError($record)) { PEAR::raiseError($record); } // Process MARCXML Data $marc = new File_MARCXML($record, File_MARC::SOURCE_STRING); if ($this->record = $marc->next()) { $interface->assign('marc', $this->record); } else { PEAR::raiseError('Cannot Process MARC Record'); } // Save best available ISBN value: $this->isbn = $this->_getBestISBN(); // Define External Content Provider if ($this->isbn) { $interface->assign('isbn', $this->isbn); if (isset($configArray['Content']['reviews'])) { $interface->assign('hasReviews', true); } if (isset($configArray['Content']['excerpts'])) { $interface->assign('hasExcerpt', true); } } // Retrieve tags associated with the record $resource = new Resource(); $resource->record_id = $this->id; $resource->source = 'WorldCat'; $tags = $resource->getTags(); $interface->assign('tagList', is_array($tags) ? $tags : array()); // Find Similar Records $similar = $this->worldcat->getMoreLikeThis($this->record); $interface->assign('similarRecords', $similar['record']); // Find Other Editions $editions = $this->_getEditions(); if (!PEAR::isError($editions)) { $interface->assign('editions', $editions); } // Define CoINs Identifier $coinsID = isset($configArray['OpenURL']['rfr_id']) ? $configArray['OpenURL']['rfr_id'] : $configArray['COinS']['identifier']; if (empty($coinsID)) { $coinsID = 'vufind.svn.sourceforge.net'; } $interface->assign('coinsID', $coinsID); // Set Proxy URL $interface->assign('proxy', isset($configArray['EZproxy']['host']) ? $configArray['EZproxy']['host'] : false); $interface->setPageTitle($this->_getBestTitle()); }
/** * Given a subject term, get related (broader/narrower/alternate) terms. * Loosely adapted from Eric Lease Morgan's Term Finder demo (see * http://zoia.library.nd.edu/sandbox/term-finder/). Note that this is * intended as a fairly fuzzy search -- $term need not be an exact subject * heading; this function will return best guess matches in the 'exact' * key, possible broader terms in the 'broader' key and possible narrower * terms in the 'narrower' key of the return array. * * @param string $term Term to get related terms for. * @param string $vocabulary Vocabulary to search (default = LCSH; see OCLC docs * for other options). * @param int $maxRecords Max # of records to read from API (more = slower). * * @return mixed False on error, otherwise array of related terms, * keyed by category. * @access public */ public function getRelatedTerms($term, $vocabulary = 'lcsh', $maxRecords = 10) { // Strip quotes from incoming term: $term = str_replace('"', '', $term); // Build the request URL: $url = "http://tspilot.oclc.org/" . urlencode($vocabulary) . "/?" . "query=oclcts.preferredTerm+%3D+%22" . urlencode($term) . "%22+OR+oclcts.alternativeTerms+%3D+%22" . urlencode($term) . "%22" . "&version=1.1" . "&operation=searchRetrieve" . "&recordSchema=info%3Asrw%2Fschema%2F1%2Fmarcxml-v1.1" . "&maximumRecords=" . intval($maxRecords) . "&startRecord=1" . "&resultSetTTL=300" . "&recordPacking=xml" . "&recordXPath=" . "&sortKeys=recordcount"; // Get the API response: $data = @file_get_contents($url); // Extract plain MARCXML from the WorldCat response: $style = new DOMDocument(); $style->load('xsl/wcterms-marcxml.xsl'); $xsl = new XSLTProcessor(); $xsl->importStyleSheet($style); $xml = new DOMDocument(); $xml->loadXML($data); $marcxml = $xsl->transformToXML($xml); // Try to parse the MARCXML into a File_MARC object; if this fails, // we probably have bad MARCXML, which may indicate an API failure // or an empty record set. Just give up if this happens! try { $marc = new File_MARCXML($marcxml, File_MARCXML::SOURCE_STRING); } catch (File_MARC_Exception $e) { return false; } // Initialize arrays: $exact = array(); $broader = array(); $narrower = array(); while ($record = $marc->next()) { // Get exact terms: $actual = $record->getField('150'); if ($actual) { $main = $actual->getSubfield('a'); if ($main) { // Some versions of File_MARCXML seem to have trouble returning // strings properly (giving back XML objects instead); let's // cast to string to be sure we get what we expect! $main = (string) $main->getData(); // Add subdivisions: $subdivisions = $actual->getSubfields('x'); if ($subdivisions) { foreach ($subdivisions as $current) { $main .= ', ' . (string) $current->getData(); } } // Only save the actual term if it is not a subset of the // requested term. if (!stristr($term, $main)) { $exact[] = $main; } } } // Get broader/narrower terms: $related = $record->getFields('550'); foreach ($related as $current) { $type = $current->getSubfield('w'); $value = $current->getSubfield('a'); if ($type && $value) { $type = (string) $type->getData(); $value = (string) $value->getData(); if ($type == 'g') { // Don't save exact matches to the user-entered term: if (strcasecmp($term, $value) != 0) { $broader[] = $value; } } else { if ($type == 'h') { // Don't save exact matches to the user-entered term: if (strcasecmp($term, $value) != 0) { $narrower[] = $value; } } } } } } // Send back everything we found, sorted and filtered for uniqueness; note // that we do NOT sort FAST results since they support relevance ranking. // As of this writing, other vocabularies do not support relevance. if ($vocabulary !== 'fast') { natcasesort($exact); natcasesort($broader); natcasesort($narrower); } return array('exact' => array_unique($exact), 'broader' => array_unique($broader), 'narrower' => array_unique($narrower)); }
function postvisning($id) { global $config; $marcxml = ''; if (!empty($config['libraries'][$_GET['bib']]['sru'])) { $marcxml = get_sru('rec.id=' . urlencode($id), 1); } else { $marcxml = get_z('tnr=' . urlencode($id), 1); } if ($config['debug']) { echo "\n\n <!-- \n\n {$marcxml} \n\n --> \n\n "; } // Variabel som skal samle opp output $out = ""; // Hent ut MARC-postene fra strengen i $marcxml $poster = new File_MARCXML($marcxml, File_MARC::SOURCE_STRING); // Gå igjennom postene while ($post = $poster->next()) { $out .= '<p class="tilbake"><a href="javascript:history.go(-1)">Tilbake til trefflista</a></p>'; $data = get_basisinfo($post, true); $out .= $data['post']; $out .= get_detaljer($post); } return $out; }
function glitre_sort($marcxml, $sort_by = 'default', $sort_order = 'default') { global $config; if ($sort_by == 'default') { $sort_by = $config['default_sort_by']; } if ($sort_order == 'default') { $sort_order = $config['default_sort_order']; } // Check that sort_by and sort_order are valid $allowed_sort_by = array('author', 'year', 'title'); if (!in_array($sort_by, $allowed_sort_by)) { exit("Invalid sort_by: {$sort_by}"); } $allowed_sort_order = array('descending', 'ascending'); if (!in_array($sort_order, $allowed_sort_order)) { exit("Invalid sort_order: {$sort_order}"); } // Parse the records $rawrecords = new File_MARCXML($marcxml, File_MARC::SOURCE_STRING); // Make the records sortable $records = array(); while ($rawrec = $rawrecords->next()) { $records[] = get_sortable_record($rawrec); } // Do the actual sorting if ($sort_by == 'year' && $sort_order == 'descending') { usort($records, "sort_year_descending"); } elseif ($sort_by == 'year' && $sort_order == 'ascending') { usort($records, "sort_year_ascending"); } elseif ($sort_by == 'title' && $sort_order == 'descending') { usort($records, "sort_title_descending"); } elseif ($sort_by == 'title' && $sort_order == 'ascending') { usort($records, "sort_title_ascending"); } elseif ($sort_by == 'author' && $sort_order == 'descending') { usort($records, "sort_author_descending"); } elseif ($sort_by == 'author' && $sort_order == 'ascending') { usort($records, "sort_author_ascending"); } return $records; }