Extend the URL rewriting url to the OPDS stream. fix #141

This commit is contained in:
Sébastien Lucas 2014-03-19 20:10:21 +01:00
parent 9f2ee975d7
commit 515031d854
2 changed files with 57 additions and 16 deletions

View File

@ -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) {

View File

@ -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);