Enable kepub.epub download. re #39
This commit is contained in:
parent
0d1506a078
commit
4bce0d3349
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
<IfModule mod_rewrite.c>
|
<IfModule mod_rewrite.c>
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
|
RewriteRule ^download/(.*)/.*\.kepub\.epub$ fetch.php?data=$1&type=epub [L]
|
||||||
RewriteRule ^download/(.*)/.*\.(.*)$ fetch.php?data=$1&type=$2 [L]
|
RewriteRule ^download/(.*)/.*\.(.*)$ fetch.php?data=$1&type=$2 [L]
|
||||||
</IfModule>
|
</IfModule>
|
||||||
|
|
||||||
|
|
4
book.php
4
book.php
|
@ -298,6 +298,7 @@ class Book extends Base {
|
||||||
|
|
||||||
public function getUpdatedEpub ($idData)
|
public function getUpdatedEpub ($idData)
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
$data = $this->getDataById ($idData);
|
$data = $this->getDataById ($idData);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -320,6 +321,9 @@ class Book extends Base {
|
||||||
$epub->Serie ($se->name);
|
$epub->Serie ($se->name);
|
||||||
$epub->SerieIndex ($this->seriesIndex);
|
$epub->SerieIndex ($this->seriesIndex);
|
||||||
}
|
}
|
||||||
|
if ($config['cops_provide_kepub'] == "1") {
|
||||||
|
$epub->updateForKepub ();
|
||||||
|
}
|
||||||
$epub->download ($data->getUpdatedFilenameEpub ());
|
$epub->download ($data->getUpdatedFilenameEpub ());
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
|
|
|
@ -155,4 +155,11 @@
|
||||||
* Note that for now only the first, second and forth type of custom columns are supported
|
* Note that for now only the first, second and forth type of custom columns are supported
|
||||||
*/
|
*/
|
||||||
$config['cops_calibre_custom_column'] = array ();
|
$config['cops_calibre_custom_column'] = array ();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rename .epub to .kepub.epub if downloaded from a Kobo eReader
|
||||||
|
* The ebook will then be recognized a Kepub so with chaptered paging, statistics, ...
|
||||||
|
* You have to enable URL rewriting if you want to enable kepup.epub download
|
||||||
|
*/
|
||||||
|
$config['cops_provide_kepub'] = "1";
|
||||||
?>
|
?>
|
6
data.php
6
data.php
|
@ -95,7 +95,11 @@ class Data extends Base {
|
||||||
|
|
||||||
if ($config['cops_use_url_rewriting'] == "1")
|
if ($config['cops_use_url_rewriting'] == "1")
|
||||||
{
|
{
|
||||||
return "download/" . $this->id . "/" . urlencode ($this->getFilename ());
|
if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
|
||||||
|
return "download/" . $this->id . "/" . urlencode ($this->getUpdatedFilenameKepub ());
|
||||||
|
} else {
|
||||||
|
return "download/" . $this->id . "/" . urlencode ($this->getFilename ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -393,30 +393,37 @@ class EPub {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCoverItem () {
|
||||||
|
$nodes = $this->xpath->query('//opf:metadata/opf:meta[@name="cover"]');
|
||||||
|
if(!$nodes->length) return NULL;
|
||||||
|
|
||||||
|
$coverid = (String) $nodes->item(0)->attr('opf:content');
|
||||||
|
if(!$coverid) return NULL;
|
||||||
|
|
||||||
|
$nodes = $this->xpath->query('//opf:manifest/opf:item[@id="'.$coverid.'"]');
|
||||||
|
if(!$nodes->length) return NULL;
|
||||||
|
|
||||||
|
return $nodes->item(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateForKepub () {
|
||||||
|
$item = $this->getCoverItem ();
|
||||||
|
if (!is_null ($item)) {
|
||||||
|
$item->attr('opf:properties', 'cover-image');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function Cover2($path=false, $mime=false){
|
public function Cover2($path=false, $mime=false){
|
||||||
$hascover = true;
|
$hascover = true;
|
||||||
$item;
|
$item = $this->getCoverItem ();
|
||||||
// load cover
|
if (is_null ($item)) {
|
||||||
$nodes = $this->xpath->query('//opf:metadata/opf:meta[@name="cover"]');
|
|
||||||
if(!$nodes->length){
|
|
||||||
$hascover = false;
|
$hascover = false;
|
||||||
} else{
|
} else {
|
||||||
$coverid = (String) $nodes->item(0)->attr('opf:content');
|
$mime = $item->attr('opf:media-type');
|
||||||
if(!$coverid){
|
$this->coverpath = $item->attr('opf:href');
|
||||||
$hascover = false;
|
$this->coverpath = dirname('/'.$this->meta).'/'.$this->coverpath; // image path is relative to meta file
|
||||||
} else{
|
$this->coverpath = ltrim($this->coverpath,'/');
|
||||||
$nodes = $this->xpath->query('//opf:manifest/opf:item[@id="'.$coverid.'"]');
|
|
||||||
if(!$nodes->length){
|
|
||||||
$hascover = false;
|
|
||||||
} else{
|
|
||||||
$item = $nodes->item(0);
|
|
||||||
$mime = $item->attr('opf:media-type');
|
|
||||||
$this->coverpath = $item->attr('opf:href');
|
|
||||||
$this->coverpath = dirname('/'.$this->meta).'/'.$this->coverpath; // image path is relative to meta file
|
|
||||||
$this->coverpath = ltrim($this->coverpath,'/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set cover
|
// set cover
|
||||||
|
|
Loading…
Reference in a new issue