/** * Test Invalid ISBN-10. * * @return void */ public function testInvalidISBN10() { // 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 */ public function getCleanISBN() { // 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. * * @return bool True if image displayed, false on failure. */ protected function fetchFromISBN() { if (empty($this->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($this->isn); if ($isbn->get13()) { $this->localFile = $this->getCachePath($this->size, $isbn->get13()); } else { // Invalid ISBN? Keep it as-is to avoid a bad file path; the error will // be caught later down the line anyway. $this->localFile = $this->getCachePath($this->size, $this->isn); } if (!is_readable($this->localFile) && $isbn->get10()) { $this->localFile = $this->getCachePath($this->size, $isbn->get10()); } if (is_readable($this->localFile)) { // Load local cache if available $this->contentType = 'image/jpeg'; $this->image = file_get_contents($this->localFile); return true; } else { // Fetch from provider if (isset($this->config->Content->coverimages)) { $providers = explode(',', $this->config->Content->coverimages); foreach ($providers as $provider) { $provider = explode(':', trim($provider)); $func = trim($provider[0]); $key = isset($provider[1]) ? trim($provider[1]) : null; if ($this->{$func}($key)) { return true; } } } } return false; }