Basic multidatabase support. re #40

TODO :
 * Document the new option
 * Handle URL rewriting
 * Handle bookdetail
 * Test the case without fancybox
 * Update the title with database name
This commit is contained in:
Sébastien Lucas 2013-04-04 08:55:58 +02:00
parent 91cf377d95
commit 78b60baebd
2 changed files with 23 additions and 9 deletions

View file

@ -7,6 +7,7 @@
*/ */
define ("VERSION", "0.3.4"); define ("VERSION", "0.3.4");
define ("DB", "db");
date_default_timezone_set($config['default_timezone']); date_default_timezone_set($config['default_timezone']);
function getURLParam ($name, $default = NULL) { function getURLParam ($name, $default = NULL) {
@ -223,6 +224,7 @@ class LinkNavigation extends Link
{ {
public function __construct($phref, $prel = NULL, $ptitle = NULL) { public function __construct($phref, $prel = NULL, $ptitle = NULL) {
parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle);
if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
$this->href = $_SERVER["SCRIPT_NAME"] . $this->href; $this->href = $_SERVER["SCRIPT_NAME"] . $this->href;
} }
} }
@ -377,6 +379,16 @@ class Page
global $config; global $config;
$this->title = $config['cops_title_default']; $this->title = $config['cops_title_default'];
$this->subtitle = $config['cops_subtitle_default']; $this->subtitle = $config['cops_subtitle_default'];
$database = GetUrlParam (DB);
if (is_array ($config['calibre_directory']) && is_null ($database)) {
$i = 0;
foreach ($config['calibre_directory'] as $key => $value) {
array_push ($this->entryArray, new Entry ($key, DB . ":{$i}",
"", "text",
array ( new LinkNavigation ("?" . DB . "={$i}"))));
$i++;
}
} else {
array_push ($this->entryArray, Author::getCount()); array_push ($this->entryArray, Author::getCount());
array_push ($this->entryArray, Serie::getCount()); array_push ($this->entryArray, Serie::getCount());
array_push ($this->entryArray, Tag::getCount()); array_push ($this->entryArray, Tag::getCount());
@ -388,6 +400,7 @@ class Page
} }
$this->entryArray = array_merge ($this->entryArray, Book::getCount()); $this->entryArray = array_merge ($this->entryArray, Book::getCount());
} }
}
public function isPaginated () public function isPaginated ()
{ {
@ -626,7 +639,7 @@ abstract class Base
public static function getDbDirectory () { public static function getDbDirectory () {
global $config; global $config;
if (is_array ($config['calibre_directory'])) { if (is_array ($config['calibre_directory'])) {
$database = GetUrlParam ("database", 0); $database = GetUrlParam (DB, 0);
$array = array_values ($config['calibre_directory']); $array = array_values ($config['calibre_directory']);
return $array[$database]; return $array[$database];
} }

View file

@ -132,6 +132,7 @@ class Data extends Base {
$urlParam = addURLParameter($urlParam, "height", $height); $urlParam = addURLParameter($urlParam, "height", $height);
} }
$urlParam = addURLParameter($urlParam, "id", $book->id); $urlParam = addURLParameter($urlParam, "id", $book->id);
if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title); return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title);
} }
else else