function smarty_modifier_formatISBN($isbn) { // @codingStandardsIgnoreEnd // Normalize ISBN to an array if it is not already. $isbns = is_array($isbn) ? $isbn : array($isbn); // Loop through the ISBNs, trying to find an ISBN-10 if possible, and returning // the first ISBN-13 encountered as a last resort: $isbn13 = false; foreach ($isbns as $isbn) { // Strip off any unwanted notes: if ($pos = strpos($isbn, ' ')) { $isbn = substr($isbn, 0, $pos); } // If we find an ISBN-10, return it immediately; otherwise, if we find // an ISBN-13, save it if it is the first one encountered. $isbnObj = new ISBN($isbn); if ($isbn10 = $isbnObj->get10()) { return $isbn10; } if (!$isbn13) { $isbn13 = $isbnObj->get13(); } } return $isbn13; }
/** * Test citation generation * * @return void * @access public */ public function testISBNs() { // Valid ISBN-10: $isbn = new ISBN('0123456789'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-13: $isbn = new ISBN('9780123456786'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-10 with dashes: $isbn = new ISBN('0-12-345678-9'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-13 with dashes: $isbn = new ISBN('978-0-12-345678-6'); $this->assertEquals($isbn->get10(), '0123456789'); $this->assertEquals($isbn->get13(), '9780123456786'); $this->assertTrue($isbn->isValid()); // Valid ISBN-13 outside of Bookland EAN: $isbn = new ISBN('9790123456785'); $this->assertEquals($isbn->get10(), false); $this->assertEquals($isbn->get13(), '9790123456785'); $this->assertTrue($isbn->isValid()); // Invalid ISBN-10: $isbn = new ISBN('2314346323'); $this->assertEquals($isbn->get10(), false); $this->assertEquals($isbn->get13(), false); $this->assertFalse($isbn->isValid()); }
/** * Return the first valid ISBN found in the record (favoring ISBN-10 over * ISBN-13 when possible). * * @return mixed * @access protected */ protected function getCleanISBN() { include_once 'sys/ISBN.php'; // Get all the ISBNs and initialize the return value: $isbns = $this->getISBNs(); $isbn13 = false; // Loop through the ISBNs: foreach ($isbns as $isbn) { // Strip off any unwanted notes: if ($pos = strpos($isbn, ' ')) { $isbn = substr($isbn, 0, $pos); } // If we find an ISBN-10, return it immediately; otherwise, if we find // an ISBN-13, save it if it is the first one encountered. $isbnObj = new ISBN($isbn); if ($isbn10 = $isbnObj->get10()) { return $isbn10; } if (!$isbn13) { $isbn13 = $isbnObj->get13(); } } return $isbn13; }
/** * Parse OpenURL and return a keyed array * * @return array Parsed OpenURL values */ protected function parseOpenURL() { $title = ''; $author = ''; $isbn = ''; $issn = ''; $eissn = ''; $date = ''; $volume = ''; $issue = ''; $spage = ''; $journal = false; if (isset($_REQUEST['url_ver']) && $_REQUEST['url_ver'] == 'Z39.88-2004') { // Parse OpenURL 1.0 if (isset($_REQUEST['rft_val_fmt']) && $_REQUEST['rft_val_fmt'] == 'info:ofi/fmt:kev:mtx:book') { // Book format if (isset($_REQUEST['rft_btitle'])) { $title = $_REQUEST['rft_btitle']; } else { if (isset($_REQUEST['rft_title'])) { $title = $_REQUEST['rft_title']; } } $isbn = isset($_REQUEST['rft_isbn']) ? $_REQUEST['rft_isbn'] : ''; } else { // Journal / Article / something $journal = true; if (isset($_REQUEST['rft_atitle'])) { $title = $_REQUEST['rft_atitle']; } else { if (isset($_REQUEST['rft_jtitle'])) { $title = $_REQUEST['rft_jtitle']; } else { if (isset($_REQUEST['rft_title'])) { $title = $_REQUEST['rft_title']; } } } $eissn = isset($_REQUEST['rft_eissn']) ? $_REQUEST['rft_eissn'] : ''; } if (isset($_REQUEST['rft_aulast'])) { $author = $_REQUEST['rft_aulast']; } if (isset($_REQUEST['rft_aufirst'])) { $author .= ' ' . $_REQUEST['rft_aufirst']; } else { if (isset($_REQUEST['rft_auinit'])) { $author .= ' ' . $_REQUEST['rft_auinit']; } } $issn = isset($_REQUEST['rft_issn']) ? $_REQUEST['rft_issn'] : ''; $date = isset($_REQUEST['rft_date']) ? $_REQUEST['rft_date'] : ''; $volume = isset($_REQUEST['rft_volume']) ? $_REQUEST['rft_volume'] : ''; $issue = isset($_REQUEST['rft_issue']) ? $_REQUEST['rft_issue'] : ''; $spage = isset($_REQUEST['rft_spage']) ? $_REQUEST['rft_spage'] : ''; } else { // OpenURL 0.1 $issn = isset($_REQUEST['issn']) ? $_REQUEST['issn'] : ''; $date = isset($_REQUEST['date']) ? $_REQUEST['date'] : ''; $volume = isset($_REQUEST['volume']) ? $_REQUEST['volume'] : ''; $issue = isset($_REQUEST['issue']) ? $_REQUEST['issue'] : ''; $spage = isset($_REQUEST['spage']) ? $_REQUEST['spage'] : ''; $isbn = isset($_REQUEST['isbn']) ? $_REQUEST['isbn'] : ''; if (isset($_REQUEST['atitle'])) { $title = $_REQUEST['atitle']; } else { if (isset($_REQUEST['jtitle'])) { $title = $_REQUEST['jtitle']; } else { if (isset($_REQUEST['btitle'])) { $title = $_REQUEST['btitle']; } else { if (isset($_REQUEST['title'])) { $title = $_REQUEST['title']; } } } } if (isset($_REQUEST['aulast'])) { $author = $_REQUEST['aulast']; } if (isset($_REQUEST['aufirst'])) { $author .= ' ' . $_REQUEST['aufirst']; } else { if (isset($_REQUEST['auinit'])) { $author .= ' ' . $_REQUEST['auinit']; } } } if (ISBN::isValidISBN10($isbn) || ISBN::isValidISBN13($isbn)) { $isbnObj = new ISBN($isbn); $isbn = $isbnObj->get13(); } return compact('journal', 'title', 'author', 'isbn', 'issn', 'eissn', 'date', 'volume', 'issue', 'spage'); }
/** * Retrieve a Buchhandel cover. * * @return bool True if image displayed, false otherwise. */ function buchhandel() { global $configArray; global $logger; // convert normalized 10 char isn to 13 digits $isn = $_GET['isn']; //$logger->log("isn: " . $isn, PEAR_LOG_DEBUG); if (strlen($isn) != 13) { $ISBN = new ISBN($isn); //$logger->log("ISBN: " . print_r($ISBN,1), PEAR_LOG_DEBUG); $isn = $ISBN->get13(); } //$logger->log("isn: " . $isn, PEAR_LOG_DEBUG); // Convert internal size value to openlibrary equivalent: switch ($_GET['size']) { case 'large': $size = 'L'; break; case 'medium': $size = 'M'; break; case 'small': default: $size = 'S'; break; } $url = isset($configArray['buchhandel']['url']) ? $configArray['buchhandel']['url'] : 'http://vlb.de'; $url .= "/GetBlob.aspx?strIsbn=" . $isn . "&size=" . $size; //$logger->log("Buchhandel URL: ". print_r($url,1), PEAR_LOG_DEBUG); return processImageURL($url, true, 'BH'); }
/** * Retrieve a Summon cover. * * @param string $id Serials Solutions client key. * * @return bool True if image displayed, false otherwise. */ function summon($id) { global $configArray; // convert normalized 10 char isn to 13 digits $isn = $_GET['isn']; if (strlen($isn) != 13) { $ISBN = new ISBN($isn); $isn = $ISBN->get13(); } $url = 'http://api.summon.serialssolutions.com/image/isbn/' . $id . '/' . $isn . '/' . $_GET['size']; return processImageURL($url); }
/** * Initialise the object from the global * search parameters in $_REQUEST. * * @access public * @var string|LibrarySearchSource|LocationSearchSource $searchSource * @return boolean */ public function init($searchSource = null) { global $module; global $action; // Call the standard initialization routine in the parent: parent::init($searchSource); $this->indexEngine->setSearchSource($searchSource); //******************** // Check if we have a saved search to restore -- if restored successfully, // our work here is done; if there is an error, we should report failure; // if restoreSavedSearch returns false, we should proceed as normal. $restored = $this->restoreSavedSearch(null, true, true); if ($restored === true) { return true; } else { if (PEAR_Singleton::isError($restored)) { return false; } } //******************** // Initialize standard search parameters $this->initView(); $this->initPage(); $this->initSort(); $this->initFilters(); //Marmot - search both ISBN-10 and ISBN-13 //Check to see if the search term looks like an ISBN10 or ISBN13 if (isset($_REQUEST['type']) && isset($_REQUEST['lookfor']) && ($_REQUEST['type'] == 'ISN' || $_REQUEST['type'] == 'Keyword' || $_REQUEST['type'] == 'AllFields') && (preg_match('/^\\d-?\\d{3}-?\\d{5}-?\\d$/', $_REQUEST['lookfor']) || preg_match('/^\\d{3}-?\\d-?\\d{3}-?\\d{5}-?\\d$/', $_REQUEST['lookfor']))) { require_once ROOT_DIR . '/sys/ISBN.php'; $isbn = new ISBN($_REQUEST['lookfor']); $_REQUEST['lookfor'] = $isbn->get10() . ' OR ' . $isbn->get13(); } //******************** // Basic Search logic if ($this->initBasicSearch()) { // If we found a basic search, we don't need to do anything further. } else { if (isset($_REQUEST['tag']) && $module != 'MyResearch') { // Tags, just treat them as normal searches for now. // The search processer knows what to do with them. if ($_REQUEST['tag'] != '') { $this->searchTerms[] = array('index' => 'tag', 'lookfor' => strip_tags($_REQUEST['tag'])); } } else { $this->initAdvancedSearch(); } } //******************** // Author screens - handled slightly differently if ($module == 'Author') { // *** Things in common to both screens // Log a special type of search $this->searchType = 'author'; // We don't spellcheck this screen // it's not for free user intput anyway $this->spellcheck = false; // *** Author/Home if ($action == 'Home') { $this->searchSubType = 'home'; // Remove our empty basic search (default) $this->searchTerms = array(); // Prepare the search as a normal author search $this->searchTerms[] = array('index' => 'Author', 'lookfor' => trim(strip_tags($_REQUEST['author']))); } // *** Author/Search if ($action == 'Search') { $this->searchSubType = 'search'; // We already have the 'lookfor', just set the index $this->searchTerms[0]['index'] = 'Author'; // We really want author facet data $this->facetConfig = array(); $this->addFacet('authorStr'); // Offset the facet list by the current page of results, and // allow up to ten total pages of results -- since we can't // get a total facet count, this at least allows the paging // mechanism to automatically add more pages to the end of the // list so that users can browse deeper and deeper as they go. // TODO: Make this better in the future if Solr offers a way // to get a total facet count (currently not possible). $this->facetOffset = ($this->page - 1) * $this->limit; $this->facetLimit = $this->limit * 10; // Sorting - defaults to off with unlimited facets, so let's // be explicit here for simplicity. if (isset($_REQUEST['sort']) && $_REQUEST['sort'] == 'author') { $this->setFacetSortOrder('index'); } else { $this->setFacetSortOrder('count'); } } } else { if ($module == 'Search' && ($action == 'NewItem' || $action == 'Reserves')) { // We don't need spell checking $this->spellcheck = false; $this->searchType = strtolower($action); } else { if ($module == 'MyResearch') { $this->spellcheck = false; $this->searchType = $action == 'Home' ? 'favorites' : 'list'; } } } // If a query override has been specified, log it here if (isset($_REQUEST['q'])) { $this->query = strip_tags($_REQUEST['q']); } return true; }
/** * Select the best available ISBN from those contained in the current record. * * @return string * @access private */ private function _getBestISBN() { // Get ISBN for cover and review use $isbn13 = false; if ($isbnFields = $this->record->getFields('020')) { if (is_array($isbnFields)) { foreach ($isbnFields as $isbnField) { if ($isbnSubField = $isbnField->getSubfield('a')) { $isbn = trim($isbnSubField->getData()); if ($pos = strpos($this->isbn, ' ')) { $isbn = substr($this->isbn, 0, $pos); } // If we find an ISBN-10, return it immediately; otherwise, // if we find an ISBN-13, save it if it is the first one // encountered. $isbnObj = new ISBN($isbn); if ($isbn10 = $isbnObj->get10()) { return $isbn10; } if (!$isbn13) { $isbn13 = $isbnObj->get13(); } } } } } return $isbn13; }
/** * Initialize the object's search settings for an advanced search found in the * $_REQUEST superglobal. Advanced searches have numeric subscripts on the * lookfor and type parameters -- this is how they are distinguished from basic * searches. * * @access protected */ protected function initAdvancedSearch() { $this->isAdvanced = true; if (isset($_REQUEST['lookfor'])) { if (is_array($_REQUEST['lookfor'])) { //Advanced search from popup form $this->searchType = $this->advancedSearchType; $group = array(); foreach ($_REQUEST['lookfor'] as $index => $lookfor) { $group[] = array('field' => $_REQUEST['searchType'][$index], 'lookfor' => $lookfor, 'bool' => $_REQUEST['join'][$index]); //var_dump($_REQUEST); if (isset($_REQUEST['groupEnd'])) { if ($_REQUEST['groupEnd'][$index] == 1) { // Add the completed group to the list $this->searchTerms[] = array('group' => $group, 'join' => $_REQUEST['join'][$index]); $group = array(); } } } if (count($group) > 0) { // Add the completed group to the list $this->searchTerms[] = array('group' => $group, 'join' => $_REQUEST['join'][$index]); } } else { } } else { //******************** // Advanced Search logic // 'lookfor0[]' 'type0[]' // 'lookfor1[]' 'type1[]' ... $this->searchType = $this->advancedSearchType; $groupCount = 0; // Loop through each search group while (isset($_REQUEST['lookfor' . $groupCount])) { $group = array(); // Loop through each term inside the group for ($i = 0; $i < count($_REQUEST['lookfor' . $groupCount]); $i++) { // Ignore advanced search fields with no lookup if ($_REQUEST['lookfor' . $groupCount][$i] != '') { // Use default fields if not set if (isset($_REQUEST['type' . $groupCount][$i]) && $_REQUEST['type' . $groupCount][$i] != '') { $type = strip_tags($_REQUEST['type' . $groupCount][$i]); } else { $type = $this->defaultIndex; } //Marmot - search both ISBN-10 and ISBN-13 //Check to see if the search term looks like an ISBN10 or ISBN13 $lookfor = strip_tags($_REQUEST['lookfor' . $groupCount][$i]); if (($type == 'ISN' || $type == 'Keyword' || $type == 'AllFields') && (preg_match('/^\\d-?\\d{3}-?\\d{5}-?\\d$/', $lookfor) || preg_match('/^\\d{3}-?\\d-?\\d{3}-?\\d{5}-?\\d$/', $lookfor))) { require_once ROOT_DIR . '/sys/ISBN.php'; $isbn = new ISBN($lookfor); $lookfor = $isbn->get10() . ' OR ' . $isbn->get13(); } // Add term to this group $group[] = array('field' => $type, 'lookfor' => $lookfor, 'bool' => strip_tags($_REQUEST['bool' . $groupCount][0])); } } // Make sure we aren't adding groups that had no terms if (count($group) > 0) { // Add the completed group to the list $this->searchTerms[] = array('group' => $group, 'join' => strip_tags($_REQUEST['join'])); } // Increment $groupCount++; } // Finally, if every advanced row was empty if (count($this->searchTerms) == 0) { // Treat it as an empty basic search $this->searchType = $this->basicSearchType; $this->searchTerms[] = array('index' => $this->defaultIndex, 'lookfor' => ''); } } }
/** * Return the first valid ISBN found in the record (favoring ISBN-10 over * ISBN-13 when possible). * * @return mixed */ public function getCleanISBN() { require_once ROOT_DIR . '/sys/ISBN.php'; //Check to see if we already have NovelistData loaded with a primary ISBN require_once ROOT_DIR . '/sys/Novelist/NovelistData.php'; $novelistData = new NovelistData(); $novelistData->groupedRecordPermanentId = $this->getPermanentId(); if (!isset($_REQUEST['reload']) && $this->getPermanentId() != null && $this->getPermanentId() != '' && $novelistData->find(true) && $novelistData->primaryISBN != null) { return $novelistData->primaryISBN; } else { // Get all the ISBNs and initialize the return value: $isbns = $this->getISBNs(); $isbn10 = false; // Loop through the ISBNs: foreach ($isbns as $isbn) { // If we find an ISBN-13, return it immediately; otherwise, if we find // an ISBN-10, save it if it is the first one encountered. $isbnObj = new ISBN($isbn); if ($isbnObj->isValid()) { if ($isbn13 = $isbnObj->get13()) { return $isbn13; } if (!$isbn10) { $isbn10 = $isbnObj->get10(); } } } return $isbn10; } }
/** * Checks if passed string is an ISBN and converts to ISBN 13 * * @param string $lookfor The query string * * @return valid ISBN 13 or false * @access protected */ protected function normalizeIfValidISBN($lookfor = false) { if (!$lookfor) { return false; } if (ISBN::isValidISBN10($lookfor) || ISBN::isValidISBN13($lookfor)) { $isbn = new ISBN($lookfor); return $isbn->get13(); } return false; }
public function getCleanISBNs() { require_once ROOT_DIR . '/sys/ISBN.php'; $cleanIsbns = array(); // Get all the ISBNs and initialize the return value: $isbns = $this->getISBNs(); // Loop through the ISBNs: foreach ($isbns as $isbn) { // Strip off any unwanted notes: if ($pos = strpos($isbn, ' ')) { $isbn = substr($isbn, 0, $pos); } // If we find an ISBN-10, return it immediately; otherwise, if we find // an ISBN-13, save it if it is the first one encountered. $isbnObj = new ISBN($isbn); if ($isbn10 = $isbnObj->get10()) { if (!array_key_exists($isbn10, $cleanIsbns)) { $cleanIsbns[$isbn10] = $isbn10; } } $isbn13 = $isbnObj->get13(); if (!array_key_exists($isbn10, $cleanIsbns)) { $cleanIsbns[$isbn13] = $isbn13; } } return $cleanIsbns; }