1
0
Fork 0
mirror of https://github.com/Yetangitu/owncloud-apps.git synced 2025-10-02 14:49:17 +02:00

files_opds:

- throw exceptions from epub constructor, catch them in metadata gatherer to avoid problems with bad files
 - change datetime format in metadata to avoid problems with empty database on some installations
This commit is contained in:
frankdelange 2015-01-08 22:50:58 +01:00
parent ede5449eec
commit 33348f0af7
2 changed files with 26 additions and 25 deletions

View file

@ -37,15 +37,12 @@ class Epub {
$this->file = $file;
$zip = new \ZipArchive();
if(!($zip->open($this->file))){
\OC_Log::write('epub', "Failed to read epub file", \OC_Log::ERROR);
return false;
throw new \Exception("Failed to read epub file");
}
// read container data
$data = $zip->getFromName('META-INF/container.xml');
if($data == false){
\OC_Log::write('epub', "Failed to access epub container data", \OC_Log::ERROR);
return false;
if(!($data = $zip->getFromName('META-INF/container.xml'))) {
throw new \Exception("Failed to access epub container data");
}
$xml = new DOMDocument();
@ -56,17 +53,17 @@ class Epub {
$this->meta = $nodes->item(0)->attr('full-path');
// load metadata
$data = $zip->getFromName($this->meta);
if(!$data){
\OC_Log::write('epub', 'Failed to access epub metadata', \OC_Log::ERROR);
return false;
if(!($data = $zip->getFromName($this->meta))) {
throw new \Exception("Failed to access epub metadata");
}
$this->xml = new \DOMDocument();
$this->xml->registerNodeClass('DOMElement','\OCA\Files_Opds\EPubDOMElement');
$this->xml->loadXML($data);
$this->xml->formatOutput = true;
$this->xpath = new EPubDOMXPath($this->xml);
if(!($this->xpath = new EPubDOMXPath($this->xml))) {
throw new \Exception("Failed to instantiate xpath");
}
$zip->close();
}

View file

@ -30,7 +30,7 @@ class Meta
* scanned once, even if they don't contain valid metadate.
*/
$meta['id'] = $id;
$meta['updated'] = date("Y-m-d\TH:i:sP");
$meta['updated'] = date("Y-m-d H:i:s");
$meta['date'] = '';
$meta['author'] = '';
$meta['title'] = '';
@ -189,19 +189,23 @@ class Meta
*/
public static function epub($path,&$meta) {
$success = false;
$epub = new Epub($path);
/* first try ISBN */
if(!(($isbn = $epub->ISBN()) && (Isbn::get($isbn, $meta)))) {
/* use EPUB internal metadata instead */
$meta['author'] = json_encode($epub->Authors());
$meta['title'] = $epub->Title();
$meta['date'] = $epub->Date();
$meta['publisher'] = $epub->Publisher();
$meta['copyright'] = $epub->Copyright();
$meta['language'] = $epub->Language();
$meta['description'] = strip_tags($epub->Description());
$meta['isbn'] = $epub->ISBN();
$meta['subjects'] = json_encode($epub->Subjects());
try {
$epub = new Epub($path);
/* first try ISBN */
if(!(($isbn = $epub->ISBN()) && (Isbn::get($isbn, $meta)))) {
/* use EPUB internal metadata instead */
$meta['author'] = json_encode($epub->Authors());
$meta['title'] = $epub->Title();
$meta['date'] = $epub->Date();
$meta['publisher'] = $epub->Publisher();
$meta['copyright'] = $epub->Copyright();
$meta['language'] = $epub->Language();
$meta['description'] = strip_tags($epub->Description());
$meta['isbn'] = $epub->ISBN();
$meta['subjects'] = json_encode($epub->Subjects());
}
} catch (\Exception $e) {
\OC_Log::write(get_class(), $e->getMessage(), \OC_LOG::ERROR);
}
}