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

version 0.3:

- added metadata extraction for epub documents, these will now have full entries where metadata is available
 - metadata is cached in the database
 - feed 'entry' template updated to 'full entry' according to OPDS v1.1
This commit is contained in:
frankdelange 2014-12-13 02:47:12 +01:00
parent fdeb32755a
commit ab06703347
8 changed files with 224 additions and 11 deletions

View file

@ -21,7 +21,7 @@ use \DOMDocument;
* based on https://github.com/splitbrain/php-epub-meta
*/
class Epub {
protected $xml;
public $xml;
protected $xpath;
protected $file;
protected $meta;
@ -75,7 +75,7 @@ class Epub {
* @brief file name getter
* @return string filename
*/
public static function file() {
public function file() {
return $this->file;
}
@ -84,7 +84,7 @@ class Epub {
*
* @return array $authors
*/
public static function Authors() {
public function Authors() {
// read current data
$rolefix = false;
$authors = array();
@ -127,6 +127,15 @@ class Epub {
return $this->get('dc:language');
}
/**
* @brief get date
*
* @param string $date
*/
public function Date(){
return $this->get('dc:date');
}
/**
* @brief get publisher info
*

View file

@ -35,6 +35,7 @@ class Files extends \OCA\Files\Helper
$entry['preview'] = self::getPreview($i);
$entry['thumbnail'] = self::getThumbnail($i);
$entry['humansize'] = \OC_Helper::humanFileSize($i['size']);
$entry['meta'] = Util::getMeta($i['fileid']);
} else {
$entry['icon'] = self::determineIcon($i);
}

View file

@ -148,4 +148,76 @@ class Util
public static function logWarn($msg) {
\OCP\Util::writeLog('files_opds', $msg, \OCP\Util::WARN);
}
/**
* @brief get metadata for fileid
*
* Long function, to be split later
*
* @param int $id fileid
* @return array of metadata
*/
public static function getMeta($id) {
$sql = 'SELECT * FROM `*PREFIX*opds_metadata` WHERE id = ?';
$args = array($id);
$query = \OCP\DB::prepare($sql);
$result = $query->execute($args);
if ($row = $result->fetchRow()) {
return $row;
} else {
/* start with empty values, except for id. This way, files only get
* scanned once, even if they don't contain valid metadate.
*/
$meta = array();
$meta['id'] = $id;
$meta['updated'] = date("Y-m-d\TH:i:sP");
$meta['date'] = '';
$meta['author'] = '';
$meta['title'] = '';
$meta['language'] = '';
$meta['publisher'] = '';
$meta['isbn'] = '';
$meta['copyright'] = '';
$meta['description'] = '';
$meta['subjects'] = '';
$path = \OC\Files\Filesystem::getLocalFile(\OC\Files\Filesystem::getPath($id));
switch (strtolower(substr(strrchr($path, "."), 1))) {
case 'epub':
$epub = new Epub($path);
$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'] = $epub->Subjects();
break;
default:
// set title to filename minus extension
$info = pathinfo($path);
$meta['title'] = basename($path,'.'.$info['extension']);
break;
}
$sql = "INSERT INTO *PREFIX*opds_metadata (`id`, `updated`, `date`, `author`, `title`, `language`, `publisher`, `isbn`, `copyright`, `description`, `subjects`) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
$args = array(
$meta['id'],
$meta['updated'],
$meta['date'],
$meta['author'],
$meta['title'],
$meta['language'],
$meta['publisher'],
$meta['isbn'],
$meta['copyright'],
$meta['description'],
$meta['subjects']
);
$query = \OCP\DB::prepare($sql);
$result = $query->execute($args);
return $meta;
}
}
}