Better handling of book format inside Calibre.
Not tested enough
This commit is contained in:
parent
b2f34f428f
commit
9a8e9bacae
40
book.php
40
book.php
|
@ -139,11 +139,25 @@ class Book extends Base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilePath ($extension, $relative = false)
|
public function getFilePath ($extension, $idData = NULL, $relative = false)
|
||||||
{
|
{
|
||||||
if ($handle = opendir($this->path)) {
|
$file = NULL;
|
||||||
while (false !== ($file = readdir($handle))) {
|
if ($extension == "jpg")
|
||||||
if (preg_match ('/' . $extension . '$/', $file)) {
|
{
|
||||||
|
$file = "cover.jpg";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$result = parent::getDb ()->prepare('select format, name
|
||||||
|
from data where id = ?');
|
||||||
|
$result->execute (array ($idData));
|
||||||
|
|
||||||
|
while ($post = $result->fetchObject ())
|
||||||
|
{
|
||||||
|
$file = $post->name . "." . strtolower ($post->format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($relative)
|
if ($relative)
|
||||||
{
|
{
|
||||||
return $this->relativePath."/".$file;
|
return $this->relativePath."/".$file;
|
||||||
|
@ -153,18 +167,20 @@ class Book extends Base {
|
||||||
return $this->path."/".$file;
|
return $this->path."/".$file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getLink ($type, $mime, $rel, $filename, $title = NULL)
|
private function getLink ($type, $mime, $rel, $filename, $idData, $title = NULL)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
$textData = "";
|
||||||
|
if (!is_null ($idData))
|
||||||
|
{
|
||||||
|
$textData = "&data=" . $idData;
|
||||||
|
}
|
||||||
|
|
||||||
if (preg_match ('/^\//', $config['calibre_directory']))
|
if (preg_match ('/^\//', $config['calibre_directory']))
|
||||||
{
|
{
|
||||||
return new Link ("fetch.php?id=$this->id&type=" . $type, $mime, $rel, $title);
|
return new Link ("fetch.php?id=$this->id" . $textData . "&type=" . $type, $mime, $rel, $title);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -179,7 +195,7 @@ class Book extends Base {
|
||||||
|
|
||||||
if ($this->hasCover)
|
if ($this->hasCover)
|
||||||
{
|
{
|
||||||
array_push ($linkArray, $this->getLink ("jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg"));
|
array_push ($linkArray, $this->getLink ("jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL));
|
||||||
$height = "50";
|
$height = "50";
|
||||||
if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) {
|
if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) {
|
||||||
$height = $config['cops_opds_thumbnail_height'];
|
$height = $config['cops_opds_thumbnail_height'];
|
||||||
|
@ -200,7 +216,7 @@ from data where book = ?');
|
||||||
$ext = strtolower (str_replace ("ORIGINAL_", "", $post->format));
|
$ext = strtolower (str_replace ("ORIGINAL_", "", $post->format));
|
||||||
if (array_key_exists ($ext, self::$mimetypes))
|
if (array_key_exists ($ext, self::$mimetypes))
|
||||||
{
|
{
|
||||||
array_push ($linkArray, $this->getLink ($ext, self::$mimetypes [$ext], Link::OPDS_ACQUISITION_TYPE, $post->name . "." . strtolower ($post->format), "Download"));
|
array_push ($linkArray, $this->getLink ($ext, self::$mimetypes [$ext], Link::OPDS_ACQUISITION_TYPE, $post->name . "." . strtolower ($post->format), $post->id, "Download"));
|
||||||
$this->format [$ext] = $post->name . "." . strtolower ($post->format);
|
$this->format [$ext] = $post->name . "." . strtolower ($post->format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
$bookId = $_GET["id"];
|
$bookId = $_GET["id"];
|
||||||
$book = Book::getBookById($bookId);
|
$book = Book::getBookById($bookId);
|
||||||
$type = getURLParam ("type", "jpg");
|
$type = getURLParam ("type", "jpg");
|
||||||
|
$idData = getURLParam ("data", NULL);
|
||||||
|
|
||||||
switch ($type)
|
switch ($type)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +78,7 @@
|
||||||
header("Content-type: " . Book::$mimetypes[$type]);
|
header("Content-type: " . Book::$mimetypes[$type]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$file = $book->getFilePath ($type, true);
|
$file = $book->getFilePath ($type, $idData, true);
|
||||||
header('Content-Disposition: attachement; filename="' . basename ($file) . '"');
|
header('Content-Disposition: attachement; 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