/** * Turn our results into an RSS feed * * @access public * @public array $result Existing result set (null to do new search) * @return string XML document */ public function buildRSS($result = null) { global $configArray; // XML HTTP header header('Content-type: text/xml', true); // First, get the search results if none were provided // (we'll go for 50 at a time) if (is_null($result)) { $this->limit = 50; $result = $this->processSearch(false, false); } // Now prepare the serializer $serializer_options = array('addDecl' => TRUE, 'encoding' => 'UTF-8', 'indent' => ' ', 'rootName' => 'json', 'mode' => 'simplexml'); $serializer = new XML_Serializer($serializer_options); $baseUrl = $configArray['Site']['url']; for ($i = 0; $i < count($result['response']['docs']); $i++) { //Since the base URL can be different depending on the record type, add the url to the response if (strcasecmp($result['response']['docs'][$i]['recordtype'], 'econtentRecord') == 0) { $id = str_replace('econtentRecord', '', $result['response']['docs'][$i]['id']); $result['response']['docs'][$i]['recordUrl'] = $baseUrl . '/EcontentRecord/' . $id; } else { if (strcasecmp($result['response']['docs'][$i]['recordtype'], 'grouped_work') == 0) { $id = str_replace('econtentRecord', '', $result['response']['docs'][$i]['id']); $result['response']['docs'][$i]['recordUrl'] = $baseUrl . '/GroupedWork/' . $id; require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $groupedWorkDriver = new GroupedWorkDriver($id); $image = $groupedWorkDriver->getBookcoverUrl('medium'); $description = "<img src='{$image}'/> " . $groupedWorkDriver->getDescriptionFast(); $result['response']['docs'][$i]['description'] = $description; } else { $id = $result['response']['docs'][$i]['id']; $result['response']['docs'][$i]['recordUrl'] = $baseUrl . '/Record/' . $id; } } } // Serialize our results from PHP arrays to XML if ($serializer->serialize($result)) { $xmlResults = $serializer->getSerializedData(); } // Prepare an XSLT processor and pass it some variables $xsl = new XSLTProcessor(); $xsl->registerPHPFunctions('urlencode'); $xsl->registerPHPFunctions('translate'); // On-screen display value for our search if ($this->searchType == 'newitem') { $lookfor = translate('New Items'); } else { if ($this->searchType == 'reserves') { $lookfor = translate('Course Reserves'); } else { $lookfor = $this->displayQuery(); } } if (count($this->filterList) > 0) { // TODO : better display of filters $xsl->setParameter('', 'lookfor', $lookfor . " (" . translate('with filters') . ")"); } else { $xsl->setParameter('', 'lookfor', $lookfor); } // The full url to recreate this search $xsl->setParameter('', 'searchUrl', $this->renderSearchUrl()); // Stub of a url for a records screen $xsl->setParameter('', 'baseUrl', $configArray['Site']['url'] . "/Record/"); // Load up the style sheet $style = new DOMDocument(); $style->load('services/Search/xsl/json-rss.xsl'); $xsl->importStyleSheet($style); // Load up the XML document $xml = new DOMDocument(); $xml->loadXML($xmlResults); // Process and return the xml through the style sheet try { $xmlResult = $xsl->transformToXML($xml); return $xmlResult; } catch (Exception $e) { global $logger; $logger->log("Error loading RSS feed {$e}", PEAR_LOG_ERR); return ""; } }