diff --git a/lib/OpdsFeed.php b/lib/OpdsFeed.php index 05193dce..6d1f47ec 100644 --- a/lib/OpdsFeed.php +++ b/lib/OpdsFeed.php @@ -20,17 +20,23 @@ class OpdsFeed{ } private function Sha1Entries(string $xmlString): string{ - $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $xmlString)); - $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); - $xml->registerXPathNamespace('schema', 'http://schema.org/'); - $entries = $xml->xpath('/feed/entry') ?? []; + try{ + $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $xmlString)); + $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); + $xml->registerXPathNamespace('schema', 'http://schema.org/'); + $entries = $xml->xpath('/feed/entry') ?? []; - $output = ''; - foreach($entries as $entry){ - $output .= $entry->asXml(); + $output = ''; + foreach($entries as $entry){ + $output .= $entry->asXml(); + } + + return sha1(preg_replace('/\s/ius', '', $output)); + } + catch(Exception $ex){ + // Invalid XML + return ''; } - - return sha1(preg_replace('/\s/ius', '', $output)); } public function Save(string $filename): void{ diff --git a/scripts/deploy-ebook-to-www b/scripts/deploy-ebook-to-www index 9cba8e56..cf3643e6 100755 --- a/scripts/deploy-ebook-to-www +++ b/scripts/deploy-ebook-to-www @@ -227,7 +227,10 @@ if [ "${verbose}" = "true" ]; then printf "Rebuilding OPDS catalog ... " fi -bash -c "php \"${scriptsDir}\"/generate-opds.php --webroot \"${webRoot}\" --weburl \"${webUrl}\"" +php "${scriptsDir}/generate-opds.php" --webroot "${webRoot}" --weburl "${webUrl}" + +sudo chown se:committers /standardebooks.org/web/www/opds/*.xml +sudo chmod 664 /standardebooks.org/web/www/opds/*.xml if [ "${verbose}" = "true" ]; then printf "Done.\n" diff --git a/templates/OpdsFeed.php b/templates/OpdsFeed.php index 62287525..d5f7700c 100644 --- a/templates/OpdsFeed.php +++ b/templates/OpdsFeed.php @@ -14,7 +14,7 @@ if(!isset($isCrawlable)){ print("\n"); ?> - + xmlns:fh="http://purl.org/syndication/history/1.0">