'."\n"; } } ?>

: (Querying Worldcat)

    0) { if ( strlen($q) > 0) { $searchURL = 'http://worldcat.org/webservices/catalog/search/sru?query=' . $_REQUEST['AddWorldCatSearch-SearchType'] . '%3D%22' . urlencode($_REQUEST['AddWorldCatSearch-SearchString']) . '%22'; if ( isset($_REQUEST['AWC_libraryLimit']) ) { $searchURL = $searchURL . '+and+srw.li%3D%22' . $_REQUEST['AddWorldCatSearch-LibraryLimit'] . '%22'; } $searchURL = $searchURL . '&maximumRecords=10'; $searchURL .= '&wskey='. $WorldCatAPIKey; $xml = simplexml_load_file($searchURL); // Go get the ISBNs in the search results $xml->registerXPathNamespace("marc", "http://www.loc.gov/MARC21/slim"); $lt_ids = ""; $isbns = $xml->xpath("//marc:record/marc:datafield[@tag='020']/marc:subfield[@code='a']"); foreach ((array)$isbns as $isbn) { if (strlen($isbn) > 1) { if (strpos($isbn[0], " ") > 0) { $lt_ids = $lt_ids . substr($isbn, 0, strpos($isbn, " ")); } else { $lt_ids = $lt_ids = $lt_ids . $isbn[0]; } if ($isbn != end($isbns)) { $lt_ids = $lt_ids . ','; } } } $xml->registerXPathNamespace("marc", "http://www.loc.gov/MARC21/slim"); foreach($xml->xpath('//marc:record') as $book ) { $book['xmlns:marc'] = 'http://www.loc.gov/MARC21/slim'; $field = simplexml_load_string($book->asXML()); $title = $field->xpath("marc:datafield[@tag='245']/marc:subfield[@code='a']"); $publisher = $field->xpath("marc:datafield[@tag='260']/marc:subfield[@code='b']"); $publication_date = $field->xpath("marc:datafield[@tag='260']/marc:subfield[@code='c']"); $isbn = $field->xpath("marc:datafield[@tag='020']/marc:subfield[@code='a']"); if (strpos($isbn[0], " ") > 0) { $isbn_1 = substr($isbn[0], 0, strpos($isbn[0], " ")); } else { $isbn_1 = $isbn[0]; } $author = $field->xpath("marc:datafield[@tag='100']/marc:subfield[@code='a']"); $oclcnumber = $field->xpath("marc:controlfield[@tag='001']"); echo '
  1. '; if (strlen($isbn_1) > 0) { // check Open Library for a cover $image_url = 'http://covers.openlibrary.org/b/isbn/' . $isbn_1 . '-S.jpg'; $image_size = getimagesize($image_url); if ($image_size[0] > 1 and $image_size[1] > 1) { echo ''; } else { // check LibraryThing for a cover $image_url = 'http://covers.librarything.com/devkey/' . $librarything_key . '/small/isbn/' . $isbn_1; $image_size = getimagesize($image_url); if ($image_size[0] > 1 and $image_size[1] > 1) { echo ''; } else { //set default thumbnail $image_url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/meta/img/thumbnail-default.gif'; echo ''; } } } echo '

    ' . $title[0] . ''; if ( strlen($isbn_1) > 1 ) { echo '
    '; echo '
    '; echo ''; echo '
    '; echo ''; echo ''; } echo '

    '; echo '
    '; echo '
  2. '; } ?>