Better handling of content type for book. Reported by Morg.
This commit is contained in:
parent
67f1a53ba2
commit
38b61c89da
26
book.php
26
book.php
|
@ -166,6 +166,17 @@ class Book extends Base {
|
||||||
return $this->datas;
|
return $this->datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDataById ($idData)
|
||||||
|
{
|
||||||
|
foreach ($this->getDatas () as $data) {
|
||||||
|
if ($data->id == $idData) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getTagsName () {
|
public function getTagsName () {
|
||||||
$tagList = null;
|
$tagList = null;
|
||||||
foreach ($this->getTags () as $tag) {
|
foreach ($this->getTags () as $tag) {
|
||||||
|
@ -230,14 +241,8 @@ class Book extends Base {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$result = parent::getDb ()->prepare('select format, name
|
$data = $this->getDataById ($idData);
|
||||||
from data where id = ?');
|
$file = $data->name . "." . strtolower ($data->format);
|
||||||
$result->execute (array ($idData));
|
|
||||||
|
|
||||||
while ($post = $result->fetchObject ())
|
|
||||||
{
|
|
||||||
$file = $post->name . "." . strtolower ($post->format);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($relative)
|
if ($relative)
|
||||||
|
@ -340,13 +345,16 @@ where books.id = ?');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getBookByDataId($dataId) {
|
public static function getBookByDataId($dataId) {
|
||||||
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
|
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format
|
||||||
from data, books ' . self::SQL_BOOKS_LEFT_JOIN . '
|
from data, books ' . self::SQL_BOOKS_LEFT_JOIN . '
|
||||||
where data.book = books.id and data.id = ?');
|
where data.book = books.id and data.id = ?');
|
||||||
$result->execute (array ($dataId));
|
$result->execute (array ($dataId));
|
||||||
while ($post = $result->fetchObject ())
|
while ($post = $result->fetchObject ())
|
||||||
{
|
{
|
||||||
$book = new Book ($post);
|
$book = new Book ($post);
|
||||||
|
$data = new Data ($post, $book);
|
||||||
|
$data->id = $dataId;
|
||||||
|
$book->datas = array ($data);
|
||||||
return $book;
|
return $book;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
6
data.php
6
data.php
|
@ -58,7 +58,11 @@ class Data extends Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMimeType () {
|
public function getMimeType () {
|
||||||
return self::$mimetypes [$this->extension];
|
if ($this->isKnownType ()) {
|
||||||
|
return self::$mimetypes [$this->extension];
|
||||||
|
} else {
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilename () {
|
public function getFilename () {
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$file = $book->getFilePath ($type, $idData, true);
|
$file = $book->getFilePath ($type, $idData, true);
|
||||||
header('Content-Type: application/octet-stream');
|
header('Content-Type: ' . $book->getDataById ($idData)->getMimeType ());
|
||||||
header('Content-Disposition: attachment; filename="' . basename ($file) . '"');
|
header('Content-Disposition: attachment; filename="' . basename ($file) . '"');
|
||||||
header ($config['cops_x_accel_redirect'] . ": " . $config['calibre_internal_directory'] . $file);
|
header ($config['cops_x_accel_redirect'] . ": " . $config['calibre_internal_directory'] . $file);
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue