Fix the handling of kepub.epub.
This commit is contained in:
parent
ac8763f4f5
commit
2aaa7fbd19
9
data.php
9
data.php
|
@ -28,6 +28,7 @@ class Data extends Base {
|
||||||
'doc' => 'application/msword',
|
'doc' => 'application/msword',
|
||||||
'epub' => 'application/epub+zip',
|
'epub' => 'application/epub+zip',
|
||||||
'fb2' => 'text/fb2+xml',
|
'fb2' => 'text/fb2+xml',
|
||||||
|
'kepub' => 'application/epub+zip',
|
||||||
'kobo' => 'application/x-koboreader-ebook',
|
'kobo' => 'application/x-koboreader-ebook',
|
||||||
'mobi' => 'application/x-mobipocket-ebook',
|
'mobi' => 'application/x-mobipocket-ebook',
|
||||||
'lit' => 'application/x-ms-reader',
|
'lit' => 'application/x-ms-reader',
|
||||||
|
@ -81,6 +82,10 @@ class Data extends Base {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isEpubValidOnKobo () {
|
||||||
|
return $this->format == "EPUB" || $this->format == "KEPUB";
|
||||||
|
}
|
||||||
|
|
||||||
public function getFilename () {
|
public function getFilename () {
|
||||||
return $this->name . "." . strtolower ($this->format);
|
return $this->name . "." . strtolower ($this->format);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +117,9 @@ class Data extends Base {
|
||||||
{
|
{
|
||||||
$database = "";
|
$database = "";
|
||||||
if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/";
|
if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/";
|
||||||
if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
|
if ($config['cops_provide_kepub'] == "1" &&
|
||||||
|
$this->isEpubValidOnKobo () &&
|
||||||
|
preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
|
||||||
return "download/" . $this->id . "/" . $database . urlencode ($this->getUpdatedFilenameKepub ());
|
return "download/" . $this->id . "/" . $database . urlencode ($this->getUpdatedFilenameKepub ());
|
||||||
} else {
|
} else {
|
||||||
return "download/" . $this->id . "/" . $database . urlencode ($this->getFilename ());
|
return "download/" . $this->id . "/" . $database . urlencode ($this->getFilename ());
|
||||||
|
|
|
@ -264,6 +264,7 @@ class BookTest extends PHPUnit_Framework_TestCase
|
||||||
$config['cops_provide_kepub'] = "1";
|
$config['cops_provide_kepub'] = "1";
|
||||||
$_SERVER["HTTP_USER_AGENT"] = "Kobo";
|
$_SERVER["HTTP_USER_AGENT"] = "Kobo";
|
||||||
$this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $epub->getHtmlLink ());
|
$this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $epub->getHtmlLink ());
|
||||||
|
$this->assertEquals ("download/17/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.mobi", $mobi->getHtmlLink ());
|
||||||
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
|
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
|
||||||
$this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $epub->getHtmlLink ());
|
$this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $epub->getHtmlLink ());
|
||||||
$config['cops_use_url_rewriting'] = "0";
|
$config['cops_use_url_rewriting'] = "0";
|
||||||
|
@ -292,7 +293,7 @@ class BookTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertFalse ($book->getDataFormat ("FB2"));
|
$this->assertFalse ($book->getDataFormat ("FB2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMimeType () {
|
public function testGetMimeType () {
|
||||||
$book = Book::getBookById(17);
|
$book = Book::getBookById(17);
|
||||||
|
|
||||||
|
@ -303,8 +304,8 @@ class BookTest extends PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals ("application/x-mobipocket-ebook", $data->getMimeType ());
|
$this->assertEquals ("application/x-mobipocket-ebook", $data->getMimeType ());
|
||||||
$data = $book->getDataFormat ("PDF");
|
$data = $book->getDataFormat ("PDF");
|
||||||
$this->assertEquals ("application/pdf", $data->getMimeType ());
|
$this->assertEquals ("application/pdf", $data->getMimeType ());
|
||||||
|
|
||||||
// Alter a data to make a test for finfo_file if enabled
|
// Alter a data to make a test for finfo_file if enabled
|
||||||
$data->extension = "ico";
|
$data->extension = "ico";
|
||||||
$data->format = "ICO";
|
$data->format = "ICO";
|
||||||
$data->name = "favicon";
|
$data->name = "favicon";
|
||||||
|
|
Loading…
Reference in a new issue