/** * 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()); }
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; }
/** * 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; }
/** * Load bookcover fom URL from cache or remote provider and display if possible. * * @param string $isn ISBN (10 characters preferred) * @param string $size Size of cover (large, medium, small) * * @return bool True if image displayed, false on failure. */ function fetchFromISBN($isn, $size) { global $configArray; global $localFile; global $logger; if (empty($isn)) { return false; } $logger->log("ISBN: " . $isn, PEAR_LOG_ERR); // We should check whether we have cached images for the 13- or 10-digit ISBNs. // If no file exists, we'll favor the 10-digit number if available for the sake // of brevity. $isbn = new ISBN($isn); if ($isbn->get13()) { $localFile = array_shift(glob('images/covers/' . $size . '/' . $isbn->get13() . '_*.jpg')); $hlp = array_shift(explode(".jpg", $localFile)); $src = array_pop(explode("_", $hlp)); // var_dump($localFile); // var_dump($hlp); // var_dump($src); // die('CA'); // $localFile = 'images/covers/' . $size . '/' . $isbn->get13() . '.jpg'; } else { // Invalid ISBN? Keep it as-is to avoid a bad file path; the error will // be caught later down the line anyway. $localFile = array_shift(glob('images/covers/' . $size . '/' . $isn . '_*.jpg')); $hlp = array_shift(explode(".jpg", $localFile)); $src = array_pop(explode("_", $hlp)); // var_dump($localFile); // var_dump($hlp); // var_dump($src); // die('CA1'); // $localFile = 'images/covers/' . $size . '/' . $isn . '.jpg'; } if (!is_readable($localFile) && $isbn->get10()) { $localFile = array_shift(glob('images/covers/' . $size . '/' . $isbn->get10() . '_*.jpg')); $hlp = array_shift(explode(".jpg", $localFile)); $src = array_pop(explode("_", $hlp)); // var_dump($localFile); // var_dump($hlp); // var_dump($src); // die('CA2'); // $localFile = 'images/covers/' . $size . '/' . $isbn->get10() . '.jpg'; } if (is_readable($localFile)) { // Load local cache if available // header('Content-type: image/jpeg'); // header('Content-type: application/json'); header("Content-Type: application/json; charset=UTF-8"); // setcookie('Winkler-Cookie' , $src); // $json=json_encode(array('source' => '$src', 'image' => '$localFile')); // echo readfile($json); echo json_encode(array('source' => $src, 'image' => $localFile), JSON_UNESCAPED_SLASHES); return true; } else { // Fetch from provider if (!isset($localFile)) { $localFile = 'images/covers/' . $size . '/' . $isbn->get10(); } if (isset($configArray['Content']['coverimages'])) { $providers = explode(',', $configArray['Content']['coverimages']); foreach ($providers as $provider) { $provider = explode(':', $provider); $func = $provider[0]; $key = isset($provider[1]) ? $provider[1] : null; // var_dump($localFile); if ($func($key)) { return true; } } } } return false; }
/** * Load bookcover fom URL from cache or remote provider and display if possible. * * @param string $isn ISBN (10 characters preferred) * @param string $size Size of cover (large, medium, small) * * @return bool True if image displayed, false on failure. */ function fetchFromISBN($isn, $size) { global $configArray; global $localFile; if (empty($isn)) { return false; } // We should check whether we have cached images for the 13- or 10-digit ISBNs. // If no file exists, we'll favor the 10-digit number if available for the sake // of brevity. $isbn = new ISBN($isn); if ($isbn->get13()) { $localFile = 'images/covers/' . $size . '/' . $isbn->get13() . '.jpg'; } else { // Invalid ISBN? Keep it as-is to avoid a bad file path; the error will // be caught later down the line anyway. $localFile = 'images/covers/' . $size . '/' . $isn . '.jpg'; } if (!is_readable($localFile) && $isbn->get10()) { $localFile = 'images/covers/' . $size . '/' . $isbn->get10() . '.jpg'; } $maxAge = isset($configArray['Content']['covercachetime']) ? $configArray['Content']['covercachetime'] : 1440; if (is_readable($localFile) && time() - filemtime($localFile) < $maxAge * 60) { // Load local cache if available header('Content-type: image/jpeg'); echo readfile($localFile); return true; } else { // Fetch from provider if (isset($configArray['Content']['coverimages'])) { $providers = explode(',', $configArray['Content']['coverimages']); foreach ($providers as $provider) { $provider = explode(':', $provider); $func = $provider[0]; $key = isset($provider[1]) ? $provider[1] : null; if ($func($key)) { return true; } } } } return false; }
/** * 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; } }
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; }