/** * This method is responsible for connecting to Syndetics and abstracting * author notes. * * It first queries the master url for the ISBN entry seeking a note URL. * If a note URL is found, the script will then use HTTP request to * retrieve the script. The script will then parse the note according to * US MARC (I believe). It will provide a link to the URL master HTML page * for more information. * Configuration: Sources are processed in order - refer to $sourceList. * * @param string $id Client access key * @param bool $s_plus Are we operating in Syndetics Plus mode? * * @throws \Exception * @return array Returns array with author note data. * @author Joel Timothy Norman <*****@*****.**> * @author Andrew Nagy <*****@*****.**> */ protected function loadSyndetics($id, $s_plus = false) { $sourceList = array('ANOTES' => array('title' => 'Author Notes', 'file' => 'ANOTES.XML', 'div' => '<div id="syn_anotes"></div>')); //first request url $baseUrl = isset($this->config->Syndetics->url) ? $this->config->Syndetics->url : 'http://syndetics.com'; $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/index.xml&client=' . $id . '&type=rw12,hw7'; $anotes = array(); //find out if there are any notes $client = new HttpClient(); $client->setUri($url); $result = $client->setMethod('GET')->send(); if (!$result->isSuccess()) { return $anotes; } // Test XML Response if (!($xmldoc = DOMDocument::loadXML($result->getBody()))) { throw new \Exception('Invalid XML'); } $i = 0; foreach ($sourceList as $source => $sourceInfo) { $nodes = $xmldoc->getElementsByTagName($source); if ($nodes->length) { // Load notes $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; $client->setUri($url); $result2 = $client->send(); if (!$result2->isSuccess()) { continue; } // Test XML Response $xmldoc2 = DOMDocument::loadXML($result2->getBody()); if (!$xmldoc2) { throw new \Exception('Invalid XML'); } // If we have syndetics plus, we don't actually want the content // we'll just stick in the relevant div if ($s_plus) { $anotes[$i]['Content'] = $sourceInfo['div']; } else { // Get the marc field for author notes (980) $nodes = $xmldoc2->GetElementsbyTagName("Fld980"); if (!$nodes->length) { // Skip fields with missing text continue; } // Decode the content and strip unwanted <a> tags: $anotes[$i]['Content'] = preg_replace('/<a>|<a [^>]*>|<\\/a>/', '', html_entity_decode($xmldoc2->saveXML($nodes->item(0)))); /* // Get the marc field for copyright (997) $nodes = $xmldoc->GetElementsbyTagName("Fld997"); if ($nodes->length) { $anotes[$i]['Copyright'] = html_entity_decode( $xmldoc2->saveXML($nodes->item(0)) ); } else { $anotes[$i]['Copyright'] = null; } if ($anotes[$i]['Copyright']) { //stop duplicate copyrights $location = strripos( $anotes[0]['Content'], $anotes[0]['Copyright'] ); if ($location > 0) { $anotes[$i]['Content'] = substr($anotes[0]['Content'], 0, $location); } } */ } // change the xml to actual title: $anotes[$i]['Source'] = $sourceInfo['title']; $anotes[$i]['ISBN'] = $this->getIsbn10(); //show more link $anotes[$i]['username'] = $id; $i++; } } return $anotes; }
/** * syndetics * * This method is responsible for connecting to Syndetics and abstracting * reviews from multiple providers. * * It first queries the master url for the ISBN entry seeking a review URL. * If a review URL is found, the script will then use HTTP request to * retrieve the script. The script will then parse the review according to * US MARC (I believe). It will provide a link to the URL master HTML page * for more information. * Configuration: Sources are processed in order - refer to $sourceList. * If your library prefers one reviewer over another change the order. * If your library does not like a reviewer, remove it. If there are more * syndetics reviewers add another entry. * * @param string $id Client access key * @param bool $s_plus Are we operating in Syndetics Plus mode? * * @throws \Exception * @return array Returns array with review data. * @author Joel Timothy Norman <*****@*****.**> * @author Andrew Nagy <*****@*****.**> */ protected function loadSyndetics($id, $s_plus = false) { //list of syndetic reviews $sourceList = array('CHREVIEW' => array('title' => 'Choice Review', 'file' => 'CHREVIEW.XML', 'div' => '<div id="syn_chreview"></div>'), 'NYREVIEW' => array('title' => 'New York Times Review', 'file' => 'NYREVIEW.XML', 'div' => '<div id="syn_nyreview"></div>'), 'BLREVIEW' => array('title' => 'Booklist Review', 'file' => 'BLREVIEW.XML', 'div' => '<div id="syn_blreview"></div>'), 'PWREVIEW' => array('title' => "Publisher's Weekly Review", 'file' => 'PWREVIEW.XML', 'div' => '<div id="syn_pwreview"></div>'), 'LJREVIEW' => array('title' => 'Library Journal Review', 'file' => 'LJREVIEW.XML', 'div' => '<div id="syn_ljreview"></div>'), 'SLJREVIEW' => array('title' => 'School Library Journal Review', 'file' => 'SLJREVIEW.XML', 'div' => '<div id="syn_sljreview"></div>'), 'HBREVIEW' => array('title' => 'Horn Book Review', 'file' => 'HBREVIEW.XML', 'div' => '<div id="syn_hbreview"></div>'), 'KIRKREVIEW' => array('title' => 'Kirkus Book Review', 'file' => 'KIRKREVIEW.XML', 'div' => '<div id="syn_kireview"></div>'), 'CRITICASREVIEW' => array('title' => 'Criticas Review', 'file' => 'CRITICASREVIEW.XML', 'div' => '<div id="syn_criticasreview"></div>'), 'KIREVIEW' => array('title' => 'Kirkus Book Review', 'file' => 'KIREVIEW.XML'), 'CRITICASEREVIEW' => array('title' => 'Criti Case Review', 'file' => 'CRITICASEREVIEW.XML')); //first request url $baseUrl = isset($this->config->Syndetics->url) ? $this->config->Syndetics->url : 'http://syndetics.com'; $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . 'index.xml&client=' . $id . '&type=rw12,hw7'; $review = array(); //find out if there are any reviews $client = new HttpClient(); $client->setUri($url); $result = $client->setMethod('GET')->send(); if (!$result->isSuccess()) { return $review; } // Test XML Response if (!($xmldoc = DOMDocument::loadXML($result->getBody()))) { throw new \Exception('Invalid XML'); } $i = 0; foreach ($sourceList as $source => $sourceInfo) { $nodes = $xmldoc->getElementsByTagName($source); if ($nodes->length) { // Load reviews $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; $client->setUri($url); $result2 = $client->send(); if (!$result2->isSuccess()) { continue; } // Test XML Response $xmldoc2 = DOMDocument::loadXML($result2->getBody()); if (!$xmldoc2) { throw new \Exception('Invalid XML'); } // If we have syndetics plus, we don't actually want the content // we'll just stick in the relevant div if ($s_plus) { $review[$i]['Content'] = $sourceInfo['div']; } else { // Get the marc field for reviews (520) $nodes = $xmldoc2->GetElementsbyTagName("Fld520"); if (!$nodes->length) { // Skip reviews with missing text continue; } // Decode the content and strip unwanted <a> tags: $review[$i]['Content'] = preg_replace('/<a>|<a [^>]*>|<\\/a>/', '', html_entity_decode($xmldoc2->saveXML($nodes->item(0)))); // Get the marc field for copyright (997) $nodes = $xmldoc2->GetElementsbyTagName("Fld997"); if ($nodes->length) { $review[$i]['Copyright'] = html_entity_decode($xmldoc2->saveXML($nodes->item(0))); } else { $review[$i]['Copyright'] = null; } if ($review[$i]['Copyright']) { //stop duplicate copyrights $location = strripos($review[0]['Content'], $review[0]['Copyright']); if ($location > 0) { $review[$i]['Content'] = substr($review[0]['Content'], 0, $location); } } } //change the xml to actual title: $review[$i]['Source'] = $sourceInfo['title']; $review[$i]['ISBN'] = $this->getIsbn10(); //show more link $i++; } } return $review; }
/** * Send a request to the SIRSI side API script and returns the response. * * @param array $params Associative array of query parameters to send. * * @return string */ protected function querySirsi($params) { // make sure null parameters are sent as empty strings instead or else the // driver.pl may choke on null parameter values foreach ($params as $key => $value) { if ($value == null) { $params[$key] = ''; } } $url = $this->url; if (empty($url)) { $url = $this->host; if ($this->port) { $url = "http://" . $url . ":" . $this->port . "/" . $this->search_prog; } else { $url = "http://" . $url . "/" . $this->search_prog; } } $httpClient = new HttpClient(); $httpClient->setMethod('POST'); $httpClient->setUri($url); $httpClient->setRawBody(http_build_query($params)); $httpClient->setEncType('application/x-www-form-urlencoded'); // use HTTP POST so parameters like user id and PIN are NOT logged by web // servers $result = $httpClient->send(); // Even if we get a response, make sure it's a 'good' one. if (!$result->isSuccess()) { throw new ILSException("Error response code received from {$url}"); } // get the response data $response = $result->getBody(); return rtrim($response); }
/** * This method is responsible for connecting to Syndetics and abstracting * excerpts. * * It first queries the master url for the ISBN entry seeking an excerpt URL. * If an excerpt URL is found, the script will then use HTTP request to * retrieve the script. The script will then parse the excerpt according to * US MARC (I believe). It will provide a link to the URL master HTML page * for more information. * Configuration: Sources are processed in order - refer to $sourceList. * * @param string $id Client access key * @param bool $s_plus Are we operating in Syndetics Plus mode? * * @throws \Exception * @return array Returns array with excerpt data. * @author Joel Timothy Norman <*****@*****.**> * @author Andrew Nagy <*****@*****.**> */ protected function loadSyndetics($id, $s_plus = false) { //list of syndetic excerpts $sourceList = array('DBCHAPTER' => array('title' => 'First Chapter or Excerpt', 'file' => 'DBCHAPTER.XML', 'div' => '<div id="syn_dbchapter"></div>')); //first request url $baseUrl = isset($this->config->Syndetics->url) ? $this->config->Syndetics->url : 'http://syndetics.com'; $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/index.xml&client=' . $id . '&type=rw12,hw7'; $review = array(); //find out if there are any excerpts $client = new HttpClient(); $client->setUri($url); $result = $client->setMethod('GET')->send(); if (!$result->isSuccess()) { return $review; } // Test XML Response if (!($xmldoc = DOMDocument::loadXML($result->getBody()))) { throw new \Exception('Invalid XML'); } $i = 0; foreach ($sourceList as $source => $sourceInfo) { $nodes = $xmldoc->getElementsByTagName($source); if ($nodes->length) { // Load excerpts $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; $client->setUri($url); $result2 = $client->send(); if (!$result2->isSuccess()) { continue; } // Test XML Response $xmldoc2 = DOMDocument::loadXML($result2->getBody()); if (!$xmldoc2) { throw new \Exception('Invalid XML'); } // If we have syndetics plus, we don't actually want the content // we'll just stick in the relevant div if ($s_plus) { $review[$i]['Content'] = $sourceInfo['div']; } else { // Get the marc field for excerpts (520) $nodes = $xmldoc2->GetElementsbyTagName("Fld520"); if (!$nodes->length) { // Skip excerpts with missing text continue; } $review[$i]['Content'] = html_entity_decode($xmldoc2->saveXML($nodes->item(0))); // Get the marc field for copyright (997) $nodes = $xmldoc->GetElementsbyTagName("Fld997"); if ($nodes->length) { $review[$i]['Copyright'] = html_entity_decode($xmldoc2->saveXML($nodes->item(0))); } else { $review[$i]['Copyright'] = null; } if ($review[$i]['Copyright']) { //stop duplicate copyrights $location = strripos($review[0]['Content'], $review[0]['Copyright']); if ($location > 0) { $review[$i]['Content'] = substr($review[0]['Content'], 0, $location); } } } // change the xml to actual title: $review[$i]['Source'] = $sourceInfo['title']; $review[$i]['ISBN'] = $this->getIsbn10(); //show more link $review[$i]['username'] = $id; $i++; } } return $review; }
/** * Load image from URL, store in cache if requested, display if possible. * * @param string $url URL to load image from * @param string $cache Boolean -- should we store in local cache? * * @return bool True if image displayed, false on failure. */ protected function processImageURL($url, $cache = true) { // Attempt to pull down the image: $client = new HttpClient(); $client->setUri($url); $result = $client->send(); if ($result->isSuccess()) { $image = $result->getBody(); // Figure out file paths -- $tempFile will be used to store the // image for analysis. $finalFile will be used for long-term storage if // $cache is true or for temporary display purposes if $cache is false. $tempFile = str_replace('.jpg', uniqid(), $this->localFile); $finalFile = $cache ? $this->localFile : $tempFile . '.jpg'; // If some services can't provide an image, they will serve a 1x1 blank // or give us invalid image data. Let's analyze what came back before // proceeding. if (!@file_put_contents($tempFile, $image)) { throw new \Exception("Unable to write to image directory."); } list($width, $height, $type) = @getimagesize($tempFile); // File too small -- delete it and report failure. if ($width < 2 && $height < 2) { @unlink($tempFile); return false; } // Conversion needed -- do some normalization for non-JPEG images: if ($type != IMAGETYPE_JPEG) { // We no longer need the temp file: @unlink($tempFile); // We can't proceed if we don't have image conversion functions: if (!is_callable('imagecreatefromstring')) { return false; } // Try to create a GD image and rewrite as JPEG, fail if we can't: if (!($imageGD = @imagecreatefromstring($image))) { return false; } if (!@imagejpeg($imageGD, $finalFile)) { return false; } } else { // If $tempFile is already a JPEG, let's store it in the cache. @rename($tempFile, $finalFile); } // Display the image: $this->contentType = 'image/jpeg'; $this->image = file_get_contents($finalFile); // If we don't want to cache the image, delete it now that we're done. if (!$cache) { @unlink($finalFile); } return true; } else { return false; } }
/** * This method is responsible for connecting to Syndetics and abstracting * clips. * * It first queries the master url for the ISBN entry seeking a clip URL. * If a clip URL is found, the script will then use HTTP request to * retrieve the script. The script will then parse the clip according to * US MARC (I believe). It will provide a link to the URL master HTML page * for more information. * Configuration: Sources are processed in order - refer to $sourceList. * * @param string $id Client access key * @param bool $s_plus Are we operating in Syndetics Plus mode? * * @throws \Exception * @return array Returns array with video clip data. * @author Joel Timothy Norman <*****@*****.**> * @author Andrew Nagy <*****@*****.**> */ protected function loadSyndetics($id, $s_plus = false) { $sourceList = array('VIDEOCLIP' => array('title' => 'Video Clips', 'file' => 'VIDEOCLIP.XML', 'div' => '<div id="syn_video_clip"></div>')); //first request url $baseUrl = isset($this->config->Syndetics->url) ? $this->config->Syndetics->url : 'http://syndetics.com'; $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/index.xml&client=' . $id . '&type=rw12,hw7'; $vclips = array(); //find out if there are any clips $client = new HttpClient(); $client->setUri($url); $result = $client->setMethod('GET')->send(); if (!$result->isSuccess()) { return $vclips; } // Test XML Response if (!($xmldoc = DOMDocument::loadXML($result->getBody()))) { throw new \Exception('Invalid XML'); } $i = 0; foreach ($sourceList as $source => $sourceInfo) { $nodes = $xmldoc->getElementsByTagName($source); if ($nodes->length) { // Load clips $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; $client->setUri($url); $result2 = $client->send(); if (!$result2->isSuccess()) { continue; } // Test XML Response $xmldoc2 = DOMDocument::loadXML($result2->getBody()); if (!$xmldoc2) { throw new \Exception('Invalid XML'); } // If we have syndetics plus, we don't actually want the content // we'll just stick in the relevant div if ($s_plus) { $vclips[$i]['Content'] = $sourceInfo['div']; } else { // Get the field for video clips (VideoLink) $nodes = $xmldoc2->GetElementsbyTagName("VideoLink"); if (!$nodes->length) { // Skip clips with missing text continue; } // stick the link into an embed tag. $vclips[$i]['Content'] = '<embed width="400" height="300" type="' . 'application/x-shockwave-flash"' . 'allowfullscreen="true" src="' . html_entity_decode($nodes->item(0)->nodeValue) . '">'; // Get the marc field for copyright (997) $nodes = $xmldoc->GetElementsbyTagName("Fld997"); if ($nodes->length) { $vclips[$i]['Copyright'] = html_entity_decode($xmldoc2->saveXML($nodes->item(0))); } else { $vclips[$i]['Copyright'] = null; } } // change the xml to actual title: $vclips[$i]['Source'] = $sourceInfo['title']; $vclips[$i]['ISBN'] = $this->getIsbn10(); //show more link $vclips[$i]['username'] = $id; $i++; } } return $vclips; }