Extend the URL rewriting url to the OPDS stream. fix #141
This commit is contained in:
parent
9f2ee975d7
commit
515031d854
39
data.php
39
data.php
|
@ -103,32 +103,39 @@ class Data extends Base {
|
|||
}
|
||||
|
||||
public function getDataLink ($rel, $title = NULL) {
|
||||
global $config;
|
||||
|
||||
if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") {
|
||||
return $this->getHtmlLinkWithRewriting($title);
|
||||
}
|
||||
|
||||
return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title);
|
||||
}
|
||||
|
||||
public function getHtmlLink () {
|
||||
return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href;
|
||||
}
|
||||
|
||||
public function getLocalPath () {
|
||||
return $this->book->path . "/" . $this->getFilename ();
|
||||
}
|
||||
|
||||
public function getHtmlLink () {
|
||||
public function getHtmlLinkWithRewriting ($title = NULL) {
|
||||
global $config;
|
||||
|
||||
if ($config['cops_use_url_rewriting'] == "1")
|
||||
{
|
||||
$database = "";
|
||||
if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/";
|
||||
if ($config['cops_provide_kepub'] == "1" &&
|
||||
$this->isEpubValidOnKobo () &&
|
||||
preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
|
||||
return "download/" . $this->id . "/" . $database . urlencode ($this->getUpdatedFilenameKepub ());
|
||||
} else {
|
||||
return "download/" . $this->id . "/" . $database . urlencode ($this->getFilename ());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::getLink ($this->book, $this->extension, $this->getMimeType (), NULL, $this->getFilename (), $this->id, NULL)->href;
|
||||
$database = "";
|
||||
if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/";
|
||||
|
||||
$href = "download/" . $this->id . "/" . $database;
|
||||
|
||||
if ($config['cops_provide_kepub'] == "1" &&
|
||||
$this->isEpubValidOnKobo () &&
|
||||
preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) {
|
||||
$href .= urlencode ($this->getUpdatedFilenameKepub ());
|
||||
} else {
|
||||
$href .= urlencode ($this->getFilename ());
|
||||
}
|
||||
return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title);
|
||||
}
|
||||
|
||||
public static function getDataByBook ($book) {
|
||||
|
|
|
@ -195,6 +195,40 @@ class BookTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals ("Strand Magazine", $book->getPublisher()->name);
|
||||
}
|
||||
|
||||
public function testBookGetLinkArrayWithUrlRewriting ()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$book = Book::getBookById(2);
|
||||
$config['cops_use_url_rewriting'] = "1";
|
||||
|
||||
$linkArray = $book->getLinkArray ();
|
||||
foreach ($linkArray as $link) {
|
||||
if ($link->rel == Link::OPDS_ACQUISITION_TYPE && $link->title == "EPUB" ) {
|
||||
$this->assertEquals ("download/1/The+Return+of+Sherlock+Holmes+-+Arthur+Conan+Doyle.epub", $link->href);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->fail ();
|
||||
}
|
||||
|
||||
public function testBookGetLinkArrayWithoutUrlRewriting ()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$book = Book::getBookById(2);
|
||||
$config['cops_use_url_rewriting'] = "0";
|
||||
|
||||
$linkArray = $book->getLinkArray ();
|
||||
foreach ($linkArray as $link) {
|
||||
if ($link->rel == Link::OPDS_ACQUISITION_TYPE && $link->title == "EPUB" ) {
|
||||
$this->assertEquals ("fetch.php?data=1&type=epub&id=2", $link->href);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->fail ();
|
||||
}
|
||||
|
||||
public function testGetThumbnailNotNeeded ()
|
||||
{
|
||||
$book = Book::getBookById(2);
|
||||
|
|
Loading…
Reference in a new issue