ModifiedTimestamp->format('Y-m-dTH:i:sZ') . ' ' . $ebook->Identifier] = $ebook; } krsort($sortedContentFiles); $url = SITE_URL . '/opds/all'; $feed = Template::OpdsFeed(['id' => $url, 'url' => $url, 'title' => 'All Standard Ebooks', 'updatedTimestamp' => $updatedTimestamp, 'isCrawlable' => true, 'entries' => $sortedContentFiles]); $tempFilename = tempnam('/tmp/', 'se-opds-'); file_put_contents($tempFilename, $feed); exec('se clean ' . escapeshellarg($tempFilename)); // If the feed has changed compared to the version currently on disk, copy our new version over // and update the updated timestamp in the master opds index. try{ if(filesize($webRoot . '/www/opds/all.xml') !== filesize($tempFilename)){ $oldFeed = file_get_contents($webRoot . '/www/opds/all.xml'); $newFeed = file_get_contents($tempFilename); if($oldFeed != $newFeed){ file_put_contents($webRoot . '/www/opds/all.xml', $newFeed); // Update the index feed with the last updated timestamp $xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents($webRoot . '/www/opds/index.xml'))); $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); $xml->registerXPathNamespace('schema', 'http://schema.org/'); $allUpdated = $xml->xpath('/feed/entry[id="https://standardebooks.org/opds/all"]/updated')[0]; $allUpdated[0] = $updatedTimestamp; file_put_contents($webRoot . '/www/opds/index.xml', str_replace(" ns=", " xmlns=", $xml->asXml())); exec('se clean ' . escapeshellarg($webRoot) . '/www/opds/index.xml'); } } } catch(Exception $ex){ rename($tempFilename, $webRoot . '/www/opds/all.xml'); } unlink($tempFilename); ?>