2012-06-26 15:27:06 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* COPS (Calibre OPDS PHP Server) class file
|
|
|
|
|
*
|
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
|
|
|
|
* @author S<EFBFBD>bastien Lucas <sebastien@slucas.fr>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require_once('base.php');
|
|
|
|
|
|
|
|
|
|
class Data extends Base {
|
|
|
|
|
public $id;
|
|
|
|
|
public $name;
|
|
|
|
|
public $format;
|
|
|
|
|
public $realFormat;
|
|
|
|
|
public $extension;
|
|
|
|
|
public $book;
|
|
|
|
|
|
|
|
|
|
public static $mimetypes = array(
|
2012-06-26 15:52:01 +03:00
|
|
|
|
'azw' => 'application/x-mobipocket-ebook',
|
2013-01-19 22:28:07 +02:00
|
|
|
|
'azw3' => 'application/x-mobipocket-ebook',
|
2012-06-26 15:52:01 +03:00
|
|
|
|
'cbz' => 'application/x-cbz',
|
|
|
|
|
'cbr' => 'application/x-cbr',
|
|
|
|
|
'doc' => 'application/msword',
|
|
|
|
|
'epub' => 'application/epub+zip',
|
|
|
|
|
'fb2' => 'text/fb2+xml',
|
|
|
|
|
'kobo' => 'application/x-koboreader-ebook',
|
|
|
|
|
'mobi' => 'application/x-mobipocket-ebook',
|
|
|
|
|
'lit' => 'application/x-ms-reader',
|
|
|
|
|
'lrs' => 'text/x-sony-bbeb+xml',
|
|
|
|
|
'lrf' => 'application/x-sony-bbeb',
|
|
|
|
|
'lrx' => 'application/x-sony-bbeb',
|
|
|
|
|
'ncx' => 'application/x-dtbncx+xml',
|
|
|
|
|
'opf' => 'application/oebps-package+xml',
|
|
|
|
|
'otf' => 'application/x-font-opentype',
|
|
|
|
|
'pdb' => 'application/vnd.palm',
|
|
|
|
|
'pdf' => 'application/pdf',
|
|
|
|
|
'prc' => 'application/x-mobipocket-ebook',
|
|
|
|
|
'rtf' => 'application/rtf',
|
|
|
|
|
'svg' => 'image/svg+xml',
|
|
|
|
|
'ttf' => 'application/x-font-truetype',
|
|
|
|
|
'wmf' => 'image/wmf',
|
|
|
|
|
'xhtml' => 'application/xhtml+xml',
|
|
|
|
|
'xpgt' => 'application/adobe-page-template+xml',
|
|
|
|
|
'zip' => 'application/zip'
|
2012-06-26 15:27:06 +03:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
public function __construct($post, $book = null) {
|
|
|
|
|
$this->id = $post->id;
|
|
|
|
|
$this->name = $post->name;
|
|
|
|
|
$this->format = $post->format;
|
|
|
|
|
$this->realFormat = str_replace ("ORIGINAL_", "", $post->format);
|
|
|
|
|
$this->extension = strtolower ($this->realFormat);
|
|
|
|
|
$this->book = $book;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isKnownType () {
|
|
|
|
|
return array_key_exists ($this->extension, self::$mimetypes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getMimeType () {
|
2012-12-23 14:42:53 +02:00
|
|
|
|
if ($this->isKnownType ()) {
|
|
|
|
|
return self::$mimetypes [$this->extension];
|
|
|
|
|
} else {
|
|
|
|
|
return "application/octet-stream";
|
|
|
|
|
}
|
2012-06-26 15:27:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getFilename () {
|
2012-07-01 15:55:24 +03:00
|
|
|
|
return $this->name . "." . strtolower ($this->format);
|
2012-06-26 15:27:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-31 15:30:04 +02:00
|
|
|
|
public function getUpdatedFilename () {
|
|
|
|
|
return $this->book->getAuthorsName () . " - " . $this->book->title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUpdatedFilenameEpub () {
|
|
|
|
|
return $this->getUpdatedFilename () . ".epub";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUpdatedFilenameKepub () {
|
|
|
|
|
return $this->getUpdatedFilename () . ".kepub.epub";
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-26 15:27:06 +03:00
|
|
|
|
public function getDataLink ($rel, $title = NULL) {
|
|
|
|
|
return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-30 09:34:54 +02:00
|
|
|
|
public function getLocalPath () {
|
|
|
|
|
return $this->book->path . "/" . $this->getFilename ();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-26 15:45:09 +03:00
|
|
|
|
public function getHtmlLink () {
|
2012-07-01 15:24:54 +03:00
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
|
|
if ($config['cops_use_url_rewriting'] == "1")
|
|
|
|
|
{
|
2013-04-05 09:14:44 +03:00
|
|
|
|
$database = "";
|
|
|
|
|
if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/";
|
2013-02-05 22:08:28 +02:00
|
|
|
|
if ($config['cops_provide_kepub'] == "1" && preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
|
2013-04-05 09:14:44 +03:00
|
|
|
|
return "download/" . $this->id . "/" . $database . urlencode ($this->getUpdatedFilenameKepub ());
|
2013-02-05 22:08:28 +02:00
|
|
|
|
} else {
|
2013-04-05 09:14:44 +03:00
|
|
|
|
return "download/" . $this->id . "/" . $database . urlencode ($this->getFilename ());
|
2013-02-05 22:08:28 +02:00
|
|
|
|
}
|
2012-07-01 15:24:54 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-25 09:40:08 +03:00
|
|
|
|
return self::getLink ($this->book, $this->extension, $this->getMimeType (), NULL, $this->getFilename (), $this->id, NULL)->href;
|
2012-07-01 15:24:54 +03:00
|
|
|
|
}
|
2012-06-26 15:45:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 22:10:28 +03:00
|
|
|
|
public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL)
|
2012-06-26 15:27:06 +03:00
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
|
2013-04-03 21:59:53 +03:00
|
|
|
|
$urlParam = addURLParameter("", "data", $idData);
|
2012-06-26 15:27:06 +03:00
|
|
|
|
|
2013-04-03 16:00:09 +03:00
|
|
|
|
if (preg_match ('/^\//', Base::getDbDirectory ()) || // Linux /
|
|
|
|
|
preg_match ('/^\w\:/', Base::getDbDirectory ()) || // Windows X:
|
2013-04-03 21:59:53 +03:00
|
|
|
|
$rel == Link::OPDS_THUMBNAIL_TYPE ||
|
2013-01-22 10:05:32 +02:00
|
|
|
|
($type == "epub" && $config['cops_update_epub-metadata']))
|
2012-06-26 15:27:06 +03:00
|
|
|
|
{
|
2013-04-03 21:59:53 +03:00
|
|
|
|
if ($type != "jpg") $urlParam = addURLParameter($urlParam, "type", $type);
|
|
|
|
|
if ($rel == Link::OPDS_THUMBNAIL_TYPE) {
|
2013-04-03 22:10:28 +03:00
|
|
|
|
if (is_null ($height)) {
|
|
|
|
|
if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) {
|
|
|
|
|
$height = $config['cops_opds_thumbnail_height'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$height = $config['cops_html_thumbnail_height'];
|
|
|
|
|
}
|
2013-04-03 21:59:53 +03:00
|
|
|
|
}
|
|
|
|
|
$urlParam = addURLParameter($urlParam, "height", $height);
|
|
|
|
|
}
|
|
|
|
|
$urlParam = addURLParameter($urlParam, "id", $book->id);
|
2013-04-04 09:55:58 +03:00
|
|
|
|
if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
|
2013-04-03 21:59:53 +03:00
|
|
|
|
return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title);
|
2012-06-26 15:27:06 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|