Exemple #1
0
 /**
  * Guardian Reviews
  *
  * This method is responsible for connecting to the Guardian and abstracting
  * reviews for the specific ISBN.
  *
  * @param string           $key     API key (unused here)
  * @param \VuFindCode\ISBN $isbnObj ISBN object
  *
  * @throws \Exception
  * @return array     Returns array with review data.
  * @author Eoghan Ó Carragáin <*****@*****.**>
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function loadByIsbn($key, \VuFindCode\ISBN $isbnObj)
 {
     // Base request URL:
     $url = "http://content.guardianapis.com/search?order-by=newest&format=json" . "&show-fields=all&reference=isbn%2F" . $isbnObj->get13();
     // Only add api-key if one has been provided in config.ini. If no key is
     // provided, a link to the Guardian can still be shown.
     if (strlen($key) > 0) {
         $url = $url . "&api-key=" . $key;
     }
     $this->debug('Guardian request: ' . $url);
     // Find out if there are any reviews:
     $result = $this->getHttpClient($url)->send();
     // Was the request successful?
     if ($result->isSuccess()) {
         // parse json from response
         $data = json_decode($result->getBody(), true);
         if ($data) {
             $result = [];
             $i = 0;
             foreach ($data['response']['results'] as $review) {
                 $result[$i]['Date'] = $review['webPublicationDate'];
                 $result[$i]['Summary'] = $review['fields']['headline'] . ". " . preg_replace('/<p>|<p [^>]*>|<\\/p>/', '', html_entity_decode($review['fields']['trailText']));
                 $result[$i]['ReviewURL'] = $review['fields']['shortUrl'];
                 // TODO: Make this configurable (or store it locally), so users
                 //       running VuFind behind SSL don't get warnings due to
                 //       inclusion of this non-SSL image URL:
                 $poweredImage = 'http://image.guardian.co.uk/sys-images/Guardian/' . 'Pix/pictures/2010/03/01/poweredbyguardianBLACK.png';
                 $result[$i]['Copyright'] = "<a href=\"" . $review['fields']['shortUrl'] . "\" target=\"new\">" . "<img src=\"{$poweredImage}\" " . "alt=\"Powered by the Guardian\" /></a>";
                 $result[$i]['Source'] = $review['fields']['byline'];
                 // Only return Content if the body tag contains a usable review
                 $redist = "Redistribution rights for this field are unavailable";
                 if (strlen($review['fields']['body']) > 0 && !strstr($review['fields']['body'], $redist)) {
                     $result[$i]['Content'] = $review['fields']['body'];
                 }
                 $i++;
             }
             return $result;
         } else {
             throw new \Exception('Could not parse Guardian response.');
         }
     } else {
         return [];
     }
 }
Exemple #2
0
 /**
  * Get all valid identifiers as an associative array.
  *
  * @return array
  */
 protected function getIdentifiers()
 {
     $ids = [];
     if ($this->isbn && $this->isbn->isValid()) {
         $ids['isbn'] = $this->isbn;
     }
     if ($this->issn && strlen($this->issn) == 8) {
         $ids['issn'] = $this->issn;
     }
     if ($this->oclc && strlen($this->oclc) > 0) {
         $ids['oclc'] = $this->oclc;
     }
     if ($this->upc && strlen($this->upc) > 0) {
         $ids['upc'] = $this->upc;
     }
     return $ids;
 }
Exemple #3
0
 /**
  * Test Invalid ISBN-10.
  *
  * @return void
  */
 public function testInvalidISBN10()
 {
     // Invalid ISBN-10:
     $isbn = new ISBN('2314346323');
     $this->assertFalse($isbn->get10());
     $this->assertFalse($isbn->get13());
     $this->assertFalse($isbn->isValid());
 }
 /**
  * Parse OpenURL and return a keyed array
  *
  * @return array
  */
 protected function parseOpenURL()
 {
     $title = '';
     $atitle = '';
     $author = '';
     $isbn = '';
     $issn = '';
     $eissn = '';
     $date = '';
     $volume = '';
     $issue = '';
     $spage = '';
     $journal = false;
     $request = $this->getRequest()->getQuery()->toArray() + $this->getRequest()->getPost()->toArray();
     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
             $isbn = isset($request['rft_isbn']) ? $request['rft_isbn'] : '';
             if (isset($request['rft_btitle'])) {
                 $title = $request['rft_btitle'];
             } else {
                 if (isset($request['rft_title'])) {
                     $title = $request['rft_title'];
                 }
             }
         } else {
             // Journal / Article / something
             $journal = true;
             $eissn = isset($request['rft_eissn']) ? $request['rft_eissn'] : '';
             $atitle = isset($request['rft_atitle']) ? $request['rft_atitle'] : '';
             if (isset($request['rft_jtitle'])) {
                 $title = $request['rft_jtitle'];
             } else {
                 if (isset($request['rft_title'])) {
                     $title = $request['rft_title'];
                 }
             }
         }
         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'] : '';
         $atitle = isset($request['atitle']) ? $request['atitle'] : '';
         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', 'atitle', 'title', 'author', 'isbn', 'issn', 'eissn', 'date', 'volume', 'issue', 'spage');
 }
Exemple #5
0
 /**
  * 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;
 }
 /**
  * Check if passed string is an ISBN and convert to ISBN-13
  *
  * @param string $searchString The query string
  *
  * @return valid ISBN-13 or the original string
  */
 protected function normalizeISBN($searchString)
 {
     if (!ISBN::isValidISBN10($searchString)) {
         return $searchString;
     }
     $isbn = new ISBN($searchString);
     return $isbn->get13();
 }