2012-05-28 08:01:33 +03:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* COPS (Calibre OPDS PHP Server) class file
|
|
|
|
|
*
|
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
2014-02-28 12:10:04 +02:00
|
|
|
|
* @author S<EFBFBD>bastien Lucas <sebastien@slucas.fr>
|
2012-05-28 08:01:33 +03:00
|
|
|
|
*/
|
|
|
|
|
|
2014-01-02 13:23:37 +02:00
|
|
|
|
define ("VERSION", "0.9.1beta");
|
2013-04-04 09:55:58 +03:00
|
|
|
|
define ("DB", "db");
|
2012-06-23 15:50:50 +03:00
|
|
|
|
date_default_timezone_set($config['default_timezone']);
|
2013-10-03 10:05:38 +03:00
|
|
|
|
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-08-22 16:20:30 +03:00
|
|
|
|
function useServerSideRendering () {
|
|
|
|
|
global $config;
|
|
|
|
|
return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']);
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2014-01-06 22:24:11 +02:00
|
|
|
|
function serverSideRender ($data) {
|
|
|
|
|
// Get the templates
|
2014-02-06 22:26:20 +02:00
|
|
|
|
$theme = getCurrentTemplate ();
|
|
|
|
|
$header = file_get_contents('templates/' . $theme . '/header.html');
|
|
|
|
|
$footer = file_get_contents('templates/' . $theme . '/footer.html');
|
|
|
|
|
$main = file_get_contents('templates/' . $theme . '/main.html');
|
|
|
|
|
$bookdetail = file_get_contents('templates/' . $theme . '/bookdetail.html');
|
|
|
|
|
$page = file_get_contents('templates/' . $theme . '/page.html');
|
2014-01-06 22:24:11 +02:00
|
|
|
|
|
|
|
|
|
// Generate the function for the template
|
|
|
|
|
$template = new doT ();
|
|
|
|
|
$dot = $template->template ($page, array ("bookdetail" => $bookdetail,
|
|
|
|
|
"header" => $header,
|
|
|
|
|
"footer" => $footer,
|
|
|
|
|
"main" => $main));
|
|
|
|
|
// Execute the template
|
|
|
|
|
if (!empty ($data)) {
|
|
|
|
|
return $dot ($data);
|
|
|
|
|
}
|
2014-01-06 22:24:45 +02:00
|
|
|
|
|
2014-01-06 22:24:11 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 10:34:32 +02:00
|
|
|
|
function getQueryString () {
|
|
|
|
|
if ( isset($_SERVER['QUERY_STRING']) ) {
|
|
|
|
|
return $_SERVER['QUERY_STRING'];
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 19:03:38 +02:00
|
|
|
|
function notFound () {
|
|
|
|
|
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
|
|
|
|
|
header("Status: 404 Not Found");
|
|
|
|
|
|
|
|
|
|
$_SERVER['REDIRECT_STATUS'] = 404;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:05:05 +03:00
|
|
|
|
function getURLParam ($name, $default = NULL) {
|
2013-06-21 09:38:02 +03:00
|
|
|
|
if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") {
|
2012-05-28 08:05:05 +03:00
|
|
|
|
return $_GET[$name];
|
|
|
|
|
}
|
|
|
|
|
return $default;
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
|
2013-05-29 22:13:02 +03:00
|
|
|
|
function getCurrentOption ($option) {
|
|
|
|
|
global $config;
|
|
|
|
|
if (isset($_COOKIE[$option])) {
|
2013-12-17 23:45:51 +02:00
|
|
|
|
if (isset($config ["cops_" . $option]) && is_array ($config ["cops_" . $option])) {
|
|
|
|
|
return explode (",", $_COOKIE[$option]);
|
|
|
|
|
} else {
|
|
|
|
|
return $_COOKIE[$option];
|
|
|
|
|
}
|
2013-05-29 22:13:02 +03:00
|
|
|
|
}
|
|
|
|
|
if ($option == "style") {
|
|
|
|
|
return "default";
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-07-04 00:40:08 +03:00
|
|
|
|
if (isset($config ["cops_" . $option])) {
|
|
|
|
|
return $config ["cops_" . $option];
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-07-04 00:40:08 +03:00
|
|
|
|
return "";
|
2013-05-29 22:13:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 08:49:52 +03:00
|
|
|
|
function getCurrentCss () {
|
2014-02-16 17:55:38 +02:00
|
|
|
|
return "templates/" . getCurrentTemplate () . "/styles/style-" . getCurrentOption ("style") . ".css";
|
2013-05-28 08:49:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 22:26:20 +02:00
|
|
|
|
function getCurrentTemplate () {
|
2014-02-09 22:18:05 +02:00
|
|
|
|
return "default";
|
2014-02-06 22:26:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-02 10:10:54 +03:00
|
|
|
|
function getUrlWithVersion ($url) {
|
|
|
|
|
return $url . "?v=" . VERSION;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-19 22:50:38 +02:00
|
|
|
|
function xml2xhtml($xml) {
|
|
|
|
|
return preg_replace_callback('#<(\w+)([^>]*)\s*/>#s', create_function('$m', '
|
|
|
|
|
$xhtml_tags = array("br", "hr", "input", "frame", "img", "area", "link", "col", "base", "basefont", "param");
|
|
|
|
|
return in_array($m[1], $xhtml_tags) ? "<$m[1]$m[2] />" : "<$m[1]$m[2]></$m[1]>";
|
|
|
|
|
'), $xml);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 15:41:58 +03:00
|
|
|
|
function display_xml_error($error)
|
|
|
|
|
{
|
2014-01-11 19:21:18 +02:00
|
|
|
|
$return = "";
|
2013-04-03 15:41:58 +03:00
|
|
|
|
$return .= str_repeat('-', $error->column) . "^\n";
|
|
|
|
|
|
|
|
|
|
switch ($error->level) {
|
|
|
|
|
case LIBXML_ERR_WARNING:
|
|
|
|
|
$return .= "Warning $error->code: ";
|
|
|
|
|
break;
|
|
|
|
|
case LIBXML_ERR_ERROR:
|
|
|
|
|
$return .= "Error $error->code: ";
|
|
|
|
|
break;
|
|
|
|
|
case LIBXML_ERR_FATAL:
|
|
|
|
|
$return .= "Fatal Error $error->code: ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$return .= trim($error->message) .
|
|
|
|
|
"\n Line: $error->line" .
|
|
|
|
|
"\n Column: $error->column";
|
|
|
|
|
|
|
|
|
|
if ($error->file) {
|
|
|
|
|
$return .= "\n File: $error->file";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "$return\n\n--------------------------------------------\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function are_libxml_errors_ok ()
|
|
|
|
|
{
|
|
|
|
|
$errors = libxml_get_errors();
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-03 15:41:58 +03:00
|
|
|
|
foreach ($errors as $error) {
|
|
|
|
|
if ($error->code == 801) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-19 22:50:38 +02:00
|
|
|
|
function html2xhtml ($html) {
|
|
|
|
|
$doc = new DOMDocument();
|
2013-04-03 15:41:58 +03:00
|
|
|
|
libxml_use_internal_errors(true);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
|
|
|
|
$doc->loadHTML('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' .
|
2013-04-09 22:30:33 +03:00
|
|
|
|
$html . '</body></html>'); // Load the HTML
|
|
|
|
|
$output = $doc->saveXML($doc->documentElement); // Transform to an Ansi xml stream
|
|
|
|
|
$output = xml2xhtml($output);
|
|
|
|
|
if (preg_match ('#<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></meta></head><body>(.*)</body></html>#ms', $output, $matches)) {
|
|
|
|
|
$output = $matches [1]; // Remove <html><body>
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
/*
|
2013-04-03 15:41:58 +03:00
|
|
|
|
// In case of error with summary, use it to debug
|
|
|
|
|
$errors = libxml_get_errors();
|
|
|
|
|
|
|
|
|
|
foreach ($errors as $error) {
|
|
|
|
|
$output .= display_xml_error($error);
|
2013-02-19 22:50:38 +02:00
|
|
|
|
}
|
2013-04-03 15:41:58 +03:00
|
|
|
|
*/
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-03 15:41:58 +03:00
|
|
|
|
if (!are_libxml_errors_ok ()) $output = "HTML code not valid.";
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-09 22:29:43 +03:00
|
|
|
|
libxml_use_internal_errors(false);
|
2013-02-19 22:50:38 +02:00
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 21:10:41 +03:00
|
|
|
|
/**
|
|
|
|
|
* This method is a direct copy-paste from
|
|
|
|
|
* http://tmont.com/blargh/2010/1/string-format-in-php
|
|
|
|
|
*/
|
|
|
|
|
function str_format($format) {
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
$format = array_shift($args);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-29 21:10:41 +03:00
|
|
|
|
preg_match_all('/(?=\{)\{(\d+)\}(?!\})/', $format, $matches, PREG_OFFSET_CAPTURE);
|
|
|
|
|
$offset = 0;
|
|
|
|
|
foreach ($matches[1] as $data) {
|
|
|
|
|
$i = $data[0];
|
|
|
|
|
$format = substr_replace($format, @$args[$i], $offset + $data[1] - 1, 2 + strlen($i));
|
|
|
|
|
$offset += strlen(@$args[$i]) - 2 - strlen($i);
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-29 21:10:41 +03:00
|
|
|
|
return $format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method is based on this page
|
|
|
|
|
* http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/
|
|
|
|
|
*/
|
2013-10-04 13:20:34 +03:00
|
|
|
|
function localize($phrase, $count=-1, $reset=false) {
|
2013-01-05 15:33:12 +02:00
|
|
|
|
if ($count == 0)
|
|
|
|
|
$phrase .= ".none";
|
|
|
|
|
if ($count == 1)
|
|
|
|
|
$phrase .= ".one";
|
|
|
|
|
if ($count > 1)
|
|
|
|
|
$phrase .= ".many";
|
|
|
|
|
|
2012-05-29 21:10:41 +03:00
|
|
|
|
/* Static keyword is used to ensure the file is loaded only once */
|
|
|
|
|
static $translations = NULL;
|
2013-10-04 13:20:34 +03:00
|
|
|
|
if ($reset) {
|
|
|
|
|
$translations = NULL;
|
|
|
|
|
}
|
2012-05-29 21:10:41 +03:00
|
|
|
|
/* If no instance of $translations has occured load the language file */
|
|
|
|
|
if (is_null($translations)) {
|
2012-09-05 11:35:50 +03:00
|
|
|
|
$lang = "en";
|
|
|
|
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
|
|
|
|
{
|
|
|
|
|
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
|
|
|
|
}
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$lang_file_en = NULL;
|
2013-09-11 01:41:14 +03:00
|
|
|
|
$lang_file = dirname(__FILE__). '/lang/Localization_' . $lang . '.json';
|
2012-05-29 21:10:41 +03:00
|
|
|
|
if (!file_exists($lang_file)) {
|
2013-09-11 01:41:14 +03:00
|
|
|
|
$lang_file = dirname(__FILE__). '/lang/' . 'Localization_en.json';
|
2012-05-29 21:10:41 +03:00
|
|
|
|
}
|
|
|
|
|
elseif ($lang != "en") {
|
2013-09-11 01:41:14 +03:00
|
|
|
|
$lang_file_en = dirname(__FILE__). '/lang/' . 'Localization_en.json';
|
2012-05-29 21:10:41 +03:00
|
|
|
|
}
|
|
|
|
|
$lang_file_content = file_get_contents($lang_file);
|
|
|
|
|
/* Load the language file as a JSON object and transform it into an associative array */
|
|
|
|
|
$translations = json_decode($lang_file_content, true);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-09-20 21:44:15 +03:00
|
|
|
|
/* Clean the array of all unfinished translations */
|
2013-11-18 23:00:23 +02:00
|
|
|
|
foreach (array_keys ($translations) as $key) {
|
2013-09-16 21:34:50 +03:00
|
|
|
|
if (preg_match ("/^##TODO##/", $key)) {
|
|
|
|
|
unset ($translations [$key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-29 21:10:41 +03:00
|
|
|
|
if ($lang_file_en)
|
|
|
|
|
{
|
|
|
|
|
$lang_file_content = file_get_contents($lang_file_en);
|
|
|
|
|
$translations_en = json_decode($lang_file_content, true);
|
|
|
|
|
$translations = array_merge ($translations_en, $translations);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-29 11:10:54 +03:00
|
|
|
|
if (array_key_exists ($phrase, $translations)) {
|
|
|
|
|
return $translations[$phrase];
|
|
|
|
|
}
|
|
|
|
|
return $phrase;
|
2012-05-29 21:10:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 09:30:41 +02:00
|
|
|
|
function addURLParameter($urlParams, $paramName, $paramValue) {
|
2013-11-29 08:32:08 +02:00
|
|
|
|
if (empty ($urlParams)) {
|
|
|
|
|
$urlParams = "";
|
|
|
|
|
}
|
2013-04-03 15:54:03 +03:00
|
|
|
|
$start = "";
|
|
|
|
|
if (preg_match ("#^\?(.*)#", $urlParams, $matches)) {
|
|
|
|
|
$start = "?";
|
|
|
|
|
$urlParams = $matches[1];
|
|
|
|
|
}
|
2013-01-20 09:30:41 +02:00
|
|
|
|
$params = array();
|
|
|
|
|
parse_str($urlParams, $params);
|
2013-04-03 15:54:03 +03:00
|
|
|
|
if (empty ($paramValue) && $paramValue != 0) {
|
2013-01-20 09:30:41 +02:00
|
|
|
|
unset ($params[$paramName]);
|
|
|
|
|
} else {
|
2013-10-10 07:25:04 +03:00
|
|
|
|
$params[$paramName] = $paramValue;
|
2013-01-20 09:30:41 +02:00
|
|
|
|
}
|
2013-04-03 15:54:03 +03:00
|
|
|
|
return $start . http_build_query($params);
|
2013-01-20 09:30:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
class Link
|
|
|
|
|
{
|
2012-05-28 08:07:49 +03:00
|
|
|
|
const OPDS_THUMBNAIL_TYPE = "http://opds-spec.org/image/thumbnail";
|
|
|
|
|
const OPDS_IMAGE_TYPE = "http://opds-spec.org/image";
|
|
|
|
|
const OPDS_ACQUISITION_TYPE = "http://opds-spec.org/acquisition";
|
|
|
|
|
const OPDS_NAVIGATION_TYPE = "application/atom+xml;profile=opds-catalog;kind=navigation";
|
2012-09-18 16:39:22 +03:00
|
|
|
|
const OPDS_PAGING_TYPE = "application/atom+xml;profile=opds-catalog;kind=acquisition";
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public $href;
|
|
|
|
|
public $type;
|
|
|
|
|
public $rel;
|
|
|
|
|
public $title;
|
2013-01-11 16:16:15 +02:00
|
|
|
|
public $facetGroup;
|
|
|
|
|
public $activeFacet;
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-01-11 16:16:15 +02:00
|
|
|
|
public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) {
|
2012-05-28 08:01:33 +03:00
|
|
|
|
$this->href = $phref;
|
|
|
|
|
$this->type = $ptype;
|
|
|
|
|
$this->rel = $prel;
|
|
|
|
|
$this->title = $ptitle;
|
2013-01-11 16:16:15 +02:00
|
|
|
|
$this->facetGroup = $pfacetGroup;
|
|
|
|
|
$this->activeFacet = $pactiveFacet;
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:06:12 +03:00
|
|
|
|
public function hrefXhtml () {
|
2013-06-25 09:40:08 +03:00
|
|
|
|
return $this->href;
|
2012-05-28 08:06:12 +03:00
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class LinkNavigation extends Link
|
|
|
|
|
{
|
|
|
|
|
public function __construct($phref, $prel = NULL, $ptitle = NULL) {
|
2012-05-28 08:07:49 +03:00
|
|
|
|
parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle);
|
2013-04-04 09:55:58 +03:00
|
|
|
|
if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
|
2013-04-30 10:57:12 +03:00
|
|
|
|
if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href;
|
2013-06-15 09:03:22 +03:00
|
|
|
|
if (preg_match ("/(bookdetail|getJSON).php/", $_SERVER["SCRIPT_NAME"])) {
|
2013-04-04 22:11:45 +03:00
|
|
|
|
$this->href = "index.php" . $this->href;
|
|
|
|
|
} else {
|
|
|
|
|
$this->href = $_SERVER["SCRIPT_NAME"] . $this->href;
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-11 16:16:15 +02:00
|
|
|
|
class LinkFacet extends Link
|
|
|
|
|
{
|
|
|
|
|
public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) {
|
|
|
|
|
parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet);
|
2013-04-29 17:47:16 +03:00
|
|
|
|
if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB));
|
2013-01-11 16:16:15 +02:00
|
|
|
|
$this->href = $_SERVER["SCRIPT_NAME"] . $this->href;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
|
|
|
|
|
class Entry
|
|
|
|
|
{
|
|
|
|
|
public $title;
|
|
|
|
|
public $id;
|
|
|
|
|
public $content;
|
|
|
|
|
public $contentType;
|
|
|
|
|
public $linkArray;
|
|
|
|
|
public $localUpdated;
|
2013-12-22 19:40:03 +02:00
|
|
|
|
public $className;
|
2012-05-28 08:01:33 +03:00
|
|
|
|
private static $updated = NULL;
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:07:49 +03:00
|
|
|
|
public static $icons = array(
|
2013-01-19 08:08:47 +02:00
|
|
|
|
Author::ALL_AUTHORS_ID => 'images/author.png',
|
|
|
|
|
Serie::ALL_SERIES_ID => 'images/serie.png',
|
|
|
|
|
Book::ALL_RECENT_BOOKS_ID => 'images/recent.png',
|
|
|
|
|
Tag::ALL_TAGS_ID => 'images/tag.png',
|
2013-05-21 20:49:21 +03:00
|
|
|
|
Language::ALL_LANGUAGES_ID => 'images/language.png',
|
2013-01-19 08:08:47 +02:00
|
|
|
|
CustomColumn::ALL_CUSTOMS_ID => 'images/tag.png',
|
2013-10-25 08:59:27 +03:00
|
|
|
|
"cops:books$" => 'images/allbook.png',
|
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
|
|
|
|
"cops:books:letter" => 'images/allbook.png',
|
2013-11-30 17:21:52 +02:00
|
|
|
|
Publisher::ALL_PUBLISHERS_ID => 'images/publisher.png'
|
2012-05-28 08:07:49 +03:00
|
|
|
|
);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public function getUpdatedTime () {
|
|
|
|
|
if (!is_null ($this->localUpdated)) {
|
|
|
|
|
return date (DATE_ATOM, $this->localUpdated);
|
|
|
|
|
}
|
|
|
|
|
if (is_null (self::$updated)) {
|
|
|
|
|
self::$updated = time();
|
|
|
|
|
}
|
|
|
|
|
return date (DATE_ATOM, self::$updated);
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-10-06 19:58:16 +03:00
|
|
|
|
public function getNavLink () {
|
2013-10-10 07:25:04 +03:00
|
|
|
|
foreach ($this->linkArray as $link) {
|
2013-06-15 09:03:22 +03:00
|
|
|
|
if ($link->type != Link::OPDS_NAVIGATION_TYPE) { continue; }
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-10-06 19:58:16 +03:00
|
|
|
|
return $link->hrefXhtml ();
|
2013-06-15 09:03:22 +03:00
|
|
|
|
}
|
2013-10-06 19:58:16 +03:00
|
|
|
|
return "#";
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-12-22 19:40:03 +02:00
|
|
|
|
public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass = "") {
|
2012-05-28 08:07:49 +03:00
|
|
|
|
global $config;
|
2012-05-28 08:01:33 +03:00
|
|
|
|
$this->title = $ptitle;
|
|
|
|
|
$this->id = $pid;
|
|
|
|
|
$this->content = $pcontent;
|
|
|
|
|
$this->contentType = $pcontentType;
|
|
|
|
|
$this->linkArray = $plinkArray;
|
2013-12-22 19:40:03 +02:00
|
|
|
|
$this->className = $pclass;
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:07:49 +03:00
|
|
|
|
if ($config['cops_show_icons'] == 1)
|
|
|
|
|
{
|
|
|
|
|
foreach (self::$icons as $reg => $image)
|
|
|
|
|
{
|
|
|
|
|
if (preg_match ("/" . $reg . "/", $pid)) {
|
2012-06-02 10:10:54 +03:00
|
|
|
|
array_push ($this->linkArray, new Link (getUrlWithVersion ($image), "image/png", Link::OPDS_THUMBNAIL_TYPE));
|
2012-05-28 08:07:49 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-10-25 08:59:27 +03:00
|
|
|
|
if (!is_null (GetUrlParam (DB))) $this->id = str_replace ("cops:", "cops:" . GetUrlParam (DB) . ":", $this->id);
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class EntryBook extends Entry
|
|
|
|
|
{
|
|
|
|
|
public $book;
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) {
|
|
|
|
|
parent::__construct ($ptitle, $pid, $pcontent, $pcontentType, $plinkArray);
|
|
|
|
|
$this->book = $pbook;
|
|
|
|
|
$this->localUpdated = $pbook->timestamp;
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:06:12 +03:00
|
|
|
|
public function getCoverThumbnail () {
|
|
|
|
|
foreach ($this->linkArray as $link) {
|
2012-05-28 08:07:49 +03:00
|
|
|
|
if ($link->rel == Link::OPDS_THUMBNAIL_TYPE)
|
|
|
|
|
return $link->hrefXhtml ();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:07:49 +03:00
|
|
|
|
public function getCover () {
|
|
|
|
|
foreach ($this->linkArray as $link) {
|
|
|
|
|
if ($link->rel == Link::OPDS_IMAGE_TYPE)
|
2012-05-28 08:06:12 +03:00
|
|
|
|
return $link->hrefXhtml ();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Page
|
|
|
|
|
{
|
|
|
|
|
public $title;
|
2012-12-22 19:23:17 +02:00
|
|
|
|
public $subtitle = "";
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public $authorName = "";
|
|
|
|
|
public $authorUri = "";
|
|
|
|
|
public $authorEmail = "";
|
2012-05-28 08:05:05 +03:00
|
|
|
|
public $idPage;
|
|
|
|
|
public $idGet;
|
|
|
|
|
public $query;
|
2012-12-22 19:03:52 +02:00
|
|
|
|
public $favicon;
|
2012-09-18 16:39:22 +03:00
|
|
|
|
public $n;
|
2013-06-15 17:09:37 +03:00
|
|
|
|
public $book;
|
2012-09-18 16:39:22 +03:00
|
|
|
|
public $totalNumber = -1;
|
2012-05-28 08:05:05 +03:00
|
|
|
|
public $entryArray = array();
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-09-18 16:39:22 +03:00
|
|
|
|
public static function getPage ($pageId, $id, $query, $n)
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
|
|
|
|
switch ($pageId) {
|
|
|
|
|
case Base::PAGE_ALL_AUTHORS :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageAllAuthors ($id, $query, $n);
|
2012-09-29 15:45:27 +03:00
|
|
|
|
case Base::PAGE_AUTHORS_FIRST_LETTER :
|
|
|
|
|
return new PageAllAuthorsLetter ($id, $query, $n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
case Base::PAGE_AUTHOR_DETAIL :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageAuthorDetail ($id, $query, $n);
|
2012-05-28 08:07:49 +03:00
|
|
|
|
case Base::PAGE_ALL_TAGS :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageAllTags ($id, $query, $n);
|
2012-05-28 08:07:49 +03:00
|
|
|
|
case Base::PAGE_TAG_DETAIL :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageTagDetail ($id, $query, $n);
|
2013-05-21 20:49:21 +03:00
|
|
|
|
case Base::PAGE_ALL_LANGUAGES :
|
|
|
|
|
return new PageAllLanguages ($id, $query, $n);
|
|
|
|
|
case Base::PAGE_LANGUAGE_DETAIL :
|
2013-10-10 07:25:04 +03:00
|
|
|
|
return new PageLanguageDetail ($id, $query, $n);
|
2013-01-19 08:08:47 +02:00
|
|
|
|
case Base::PAGE_ALL_CUSTOMS :
|
|
|
|
|
return new PageAllCustoms ($id, $query, $n);
|
|
|
|
|
case Base::PAGE_CUSTOM_DETAIL :
|
|
|
|
|
return new PageCustomDetail ($id, $query, $n);
|
2014-02-27 01:33:40 +02:00
|
|
|
|
case Base::PAGE_ALL_RATINGS :
|
|
|
|
|
return new PageAllRating ($id, $query, $n);
|
|
|
|
|
case Base::PAGE_RATING_DETAIL :
|
|
|
|
|
return new PageRatingDetail ($id, $query, $n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
case Base::PAGE_ALL_SERIES :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageAllSeries ($id, $query, $n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
case Base::PAGE_ALL_BOOKS :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageAllBooks ($id, $query, $n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
case Base::PAGE_ALL_BOOKS_LETTER:
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageAllBooksLetter ($id, $query, $n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
case Base::PAGE_ALL_RECENT_BOOKS :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageRecentBooks ($id, $query, $n);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
case Base::PAGE_SERIE_DETAIL :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageSerieDetail ($id, $query, $n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
case Base::PAGE_OPENSEARCH_QUERY :
|
2012-09-18 16:39:22 +03:00
|
|
|
|
return new PageQueryResult ($id, $query, $n);
|
2012-12-10 07:06:45 +02:00
|
|
|
|
case Base::PAGE_BOOK_DETAIL :
|
|
|
|
|
return new PageBookDetail ($id, $query, $n);
|
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
|
|
|
|
case Base::PAGE_ALL_PUBLISHERS:
|
|
|
|
|
return new PageAllPublishers ($id, $query, $n);
|
|
|
|
|
case Base::PAGE_PUBLISHER_DETAIL :
|
|
|
|
|
return new PagePublisherDetail ($id, $query, $n);
|
2013-04-21 16:00:21 +03:00
|
|
|
|
case Base::PAGE_ABOUT :
|
|
|
|
|
return new PageAbout ($id, $query, $n);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
case Base::PAGE_CUSTOMIZE :
|
2013-06-27 09:27:29 +03:00
|
|
|
|
return new PageCustomize ($id, $query, $n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
default:
|
2012-09-18 16:39:22 +03:00
|
|
|
|
$page = new Page ($id, $query, $n);
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$page->idPage = "cops:catalog";
|
|
|
|
|
return $page;
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-09-18 16:39:22 +03:00
|
|
|
|
public function __construct($pid, $pquery, $pn) {
|
2012-12-22 19:03:52 +02:00
|
|
|
|
global $config;
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:05:05 +03:00
|
|
|
|
$this->idGet = $pid;
|
|
|
|
|
$this->query = $pquery;
|
2012-09-18 16:39:22 +03:00
|
|
|
|
$this->n = $pn;
|
2012-12-22 19:03:52 +02:00
|
|
|
|
$this->favicon = $config['cops_icon'];
|
2014-02-28 12:10:04 +02:00
|
|
|
|
$this->authorName = empty($config['cops_author_name']) ? utf8_encode('S<>bastien Lucas') : $config['cops_author_name'];
|
2013-10-10 08:11:32 +03:00
|
|
|
|
$this->authorUri = empty($config['cops_author_uri']) ? 'http://blog.slucas.fr' : $config['cops_author_uri'];
|
|
|
|
|
$this->authorEmail = empty($config['cops_author_email']) ? 'sebastien@slucas.fr' : $config['cops_author_email'];
|
2012-09-18 16:39:22 +03:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$this->title = $config['cops_title_default'];
|
2012-12-22 19:23:17 +02:00
|
|
|
|
$this->subtitle = $config['cops_subtitle_default'];
|
2013-12-14 12:30:42 +02:00
|
|
|
|
if (Base::noDatabaseSelected ()) {
|
2013-04-04 09:55:58 +03:00
|
|
|
|
$i = 0;
|
2013-12-14 19:25:32 +02:00
|
|
|
|
foreach (Base::getDbNameList () as $key) {
|
2013-05-23 19:55:45 +03:00
|
|
|
|
$nBooks = Book::getBookCount ($i);
|
2013-10-25 09:07:42 +03:00
|
|
|
|
array_push ($this->entryArray, new Entry ($key, "cops:{$i}:catalog",
|
2013-10-10 07:25:04 +03:00
|
|
|
|
str_format (localize ("bookword", $nBooks), $nBooks), "text",
|
2013-04-04 09:55:58 +03:00
|
|
|
|
array ( new LinkNavigation ("?" . DB . "={$i}"))));
|
|
|
|
|
$i++;
|
2013-05-23 19:55:45 +03:00
|
|
|
|
Base::clearDb ();
|
2013-01-19 08:08:47 +02:00
|
|
|
|
}
|
2013-04-04 09:55:58 +03:00
|
|
|
|
} else {
|
2013-12-17 23:45:51 +02:00
|
|
|
|
if (!in_array (PageQueryResult::SCOPE_AUTHOR, getCurrentOption ('ignored_categories'))) {
|
2013-12-17 21:51:22 +02:00
|
|
|
|
array_push ($this->entryArray, Author::getCount());
|
|
|
|
|
}
|
2013-12-17 23:45:51 +02:00
|
|
|
|
if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) {
|
2013-12-17 21:51:22 +02:00
|
|
|
|
$series = Serie::getCount();
|
|
|
|
|
if (!is_null ($series)) array_push ($this->entryArray, $series);
|
|
|
|
|
}
|
2013-12-17 23:45:51 +02:00
|
|
|
|
if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) {
|
2013-12-17 21:51:22 +02:00
|
|
|
|
$publisher = Publisher::getCount();
|
|
|
|
|
if (!is_null ($publisher)) array_push ($this->entryArray, $publisher);
|
|
|
|
|
}
|
2013-12-17 23:45:51 +02:00
|
|
|
|
if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) {
|
2013-12-17 21:51:22 +02:00
|
|
|
|
$tags = Tag::getCount();
|
|
|
|
|
if (!is_null ($tags)) array_push ($this->entryArray, $tags);
|
|
|
|
|
}
|
2014-02-27 01:33:40 +02:00
|
|
|
|
if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) {
|
|
|
|
|
$rating = Rating::getCount();
|
|
|
|
|
if (!is_null ($rating)) array_push ($this->entryArray, $rating);
|
|
|
|
|
}
|
2013-12-17 23:45:51 +02:00
|
|
|
|
if (!in_array ("language", getCurrentOption ('ignored_categories'))) {
|
2013-12-17 21:51:22 +02:00
|
|
|
|
$languages = Language::getCount();
|
|
|
|
|
if (!is_null ($languages)) array_push ($this->entryArray, $languages);
|
|
|
|
|
}
|
2013-04-04 09:55:58 +03:00
|
|
|
|
foreach ($config['cops_calibre_custom_column'] as $lookup) {
|
|
|
|
|
$customId = CustomColumn::getCustomId ($lookup);
|
|
|
|
|
if (!is_null ($customId)) {
|
|
|
|
|
array_push ($this->entryArray, CustomColumn::getCount($customId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-12-14 12:30:42 +02:00
|
|
|
|
if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName ();
|
2013-01-19 08:08:47 +02:00
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
2013-06-15 09:03:22 +03:00
|
|
|
|
|
2012-09-21 15:19:11 +03:00
|
|
|
|
public function isPaginated ()
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
return (getCurrentOption ("max_item_per_page") != -1 &&
|
|
|
|
|
$this->totalNumber != -1 &&
|
2013-06-26 22:28:04 +03:00
|
|
|
|
$this->totalNumber > getCurrentOption ("max_item_per_page"));
|
2012-09-21 15:19:11 +03:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-09-21 14:36:52 +03:00
|
|
|
|
public function getNextLink ()
|
|
|
|
|
{
|
2013-11-29 10:34:32 +02:00
|
|
|
|
$currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . getQueryString ());
|
2013-06-26 22:28:04 +03:00
|
|
|
|
if (($this->n) * getCurrentOption ("max_item_per_page") < $this->totalNumber) {
|
2013-09-17 18:28:42 +03:00
|
|
|
|
return new LinkNavigation ($currentUrl . "&n=" . ($this->n + 1), "next", localize ("paging.next.alternate"));
|
2012-09-21 14:36:52 +03:00
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-09-21 14:36:52 +03:00
|
|
|
|
public function getPrevLink ()
|
|
|
|
|
{
|
2013-11-29 10:34:32 +02:00
|
|
|
|
$currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . getQueryString ());
|
2012-09-21 14:36:52 +03:00
|
|
|
|
if ($this->n > 1) {
|
2013-09-17 18:28:42 +03:00
|
|
|
|
return new LinkNavigation ($currentUrl . "&n=" . ($this->n - 1), "previous", localize ("paging.previous.alternate"));
|
2012-09-21 14:36:52 +03:00
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-10-11 22:14:06 +03:00
|
|
|
|
public function getMaxPage ()
|
|
|
|
|
{
|
2013-06-26 22:28:04 +03:00
|
|
|
|
return ceil ($this->totalNumber / getCurrentOption ("max_item_per_page"));
|
2012-10-11 22:14:06 +03:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-01-11 16:16:15 +02:00
|
|
|
|
public function containsBook ()
|
|
|
|
|
{
|
|
|
|
|
if (count ($this->entryArray) == 0) return false;
|
2013-01-29 10:03:30 +02:00
|
|
|
|
if (get_class ($this->entryArray [0]) == "EntryBook") return true;
|
2013-01-11 16:16:15 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageAllAuthors extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = localize("authors.title");
|
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
|
|
|
|
if (getCurrentOption ("author_split_first_letter") == 1) {
|
2012-09-29 15:45:27 +03:00
|
|
|
|
$this->entryArray = Author::getAllAuthorsByFirstLetter();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this->entryArray = Author::getAllAuthors();
|
|
|
|
|
}
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$this->idPage = Author::ALL_AUTHORS_ID;
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
|
2012-09-29 15:45:27 +03:00
|
|
|
|
class PageAllAuthorsLetter extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-09-29 15:45:27 +03:00
|
|
|
|
{
|
|
|
|
|
$this->idPage = Author::getEntryIdByLetter ($this->idGet);
|
|
|
|
|
$this->entryArray = Author::getAuthorsByStartingLetter ($this->idGet);
|
2013-01-05 19:19:56 +02:00
|
|
|
|
$this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("authorword", count ($this->entryArray)), count ($this->entryArray)), $this->idGet);
|
2012-09-29 15:45:27 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:05:05 +03:00
|
|
|
|
class PageAuthorDetail extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$author = Author::getAuthorById ($this->idGet);
|
|
|
|
|
$this->idPage = $author->getEntryId ();
|
|
|
|
|
$this->title = $author->name;
|
2012-09-20 22:15:03 +03:00
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByAuthor ($this->idGet, $this->n);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
|
|
|
|
class PageAllPublishers extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
2013-12-19 09:24:02 +02:00
|
|
|
|
$this->title = localize("publishers.title");
|
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
|
|
|
|
$this->entryArray = Publisher::getAllPublishers();
|
|
|
|
|
$this->idPage = Publisher::ALL_PUBLISHERS_ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PagePublisherDetail extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
|
|
|
|
$publisher = Publisher::getPublisherById ($this->idGet);
|
|
|
|
|
$this->title = $publisher->name;
|
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByPublisher ($this->idGet, $this->n);
|
|
|
|
|
$this->idPage = $publisher->getEntryId ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:07:49 +03:00
|
|
|
|
class PageAllTags extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:07:49 +03:00
|
|
|
|
{
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = localize("tags.title");
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$this->entryArray = Tag::getAllTags();
|
|
|
|
|
$this->idPage = Tag::ALL_TAGS_ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 20:49:21 +03:00
|
|
|
|
class PageAllLanguages extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2013-05-21 20:49:21 +03:00
|
|
|
|
{
|
|
|
|
|
$this->title = localize("languages.title");
|
|
|
|
|
$this->entryArray = Language::getAllLanguages();
|
|
|
|
|
$this->idPage = Language::ALL_LANGUAGES_ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-19 08:08:47 +02:00
|
|
|
|
class PageCustomDetail extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2013-01-19 08:08:47 +02:00
|
|
|
|
{
|
|
|
|
|
$customId = getURLParam ("custom", NULL);
|
|
|
|
|
$custom = CustomColumn::getCustomById ($customId, $this->idGet);
|
|
|
|
|
$this->idPage = $custom->getEntryId ();
|
|
|
|
|
$this->title = $custom->name;
|
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByCustom ($customId, $this->idGet, $this->n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageAllCustoms extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2013-01-19 08:08:47 +02:00
|
|
|
|
{
|
|
|
|
|
$customId = getURLParam ("custom", NULL);
|
|
|
|
|
$this->title = CustomColumn::getAllTitle ($customId);
|
|
|
|
|
$this->entryArray = CustomColumn::getAllCustoms($customId);
|
|
|
|
|
$this->idPage = CustomColumn::getAllCustomsId ($customId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:07:49 +03:00
|
|
|
|
class PageTagDetail extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:07:49 +03:00
|
|
|
|
{
|
|
|
|
|
$tag = Tag::getTagById ($this->idGet);
|
|
|
|
|
$this->idPage = $tag->getEntryId ();
|
|
|
|
|
$this->title = $tag->name;
|
2012-09-20 22:15:03 +03:00
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByTag ($this->idGet, $this->n);
|
2012-05-28 08:07:49 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 20:49:21 +03:00
|
|
|
|
class PageLanguageDetail extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2013-05-21 20:49:21 +03:00
|
|
|
|
{
|
|
|
|
|
$language = Language::getLanguageById ($this->idGet);
|
|
|
|
|
$this->idPage = $language->getEntryId ();
|
2013-05-22 19:31:44 +03:00
|
|
|
|
$this->title = $language->lang_code;
|
2013-05-21 20:49:21 +03:00
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByLanguage ($this->idGet, $this->n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:05:05 +03:00
|
|
|
|
class PageAllSeries extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = localize("series.title");
|
2012-05-28 08:05:05 +03:00
|
|
|
|
$this->entryArray = Serie::getAllSeries();
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$this->idPage = Serie::ALL_SERIES_ID;
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageSerieDetail extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$serie = Serie::getSerieById ($this->idGet);
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = $serie->name;
|
2012-09-20 22:15:03 +03:00
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksBySeries ($this->idGet, $this->n);
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$this->idPage = $serie->getEntryId ();
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 01:33:40 +02:00
|
|
|
|
class PageAllRating extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
2014-03-05 12:15:20 +02:00
|
|
|
|
$this->title = localize("ratings.title");
|
2014-02-27 01:33:40 +02:00
|
|
|
|
$this->entryArray = Rating::getAllRatings();
|
|
|
|
|
$this->idPage = Rating::ALL_RATING_ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageRatingDetail extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
|
|
|
|
$rating = Rating::getRatingById ($this->idGet);
|
|
|
|
|
$this->idPage = $rating->getEntryId ();
|
2014-02-28 12:10:04 +02:00
|
|
|
|
$this->title =str_format (localize ("ratingword", $rating->name/2), $rating->name/2);
|
2014-02-27 01:33:40 +02:00
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByRating ($this->idGet, $this->n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:05:05 +03:00
|
|
|
|
class PageAllBooks extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = localize ("allbooks.title");
|
2013-11-08 18:53:11 +02:00
|
|
|
|
if (getCurrentOption ("titles_split_first_letter") == 1) {
|
|
|
|
|
$this->entryArray = Book::getAllBooks();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooks ($this->n);
|
|
|
|
|
}
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$this->idPage = Book::ALL_BOOKS_ID;
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageAllBooksLetter extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2012-09-18 16:39:22 +03:00
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByStartingLetter ($this->idGet, $this->n);
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$this->idPage = Book::getEntryIdByLetter ($this->idGet);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-01-05 19:19:56 +02:00
|
|
|
|
$count = $this->totalNumber;
|
|
|
|
|
if ($count == -1)
|
|
|
|
|
$count = count ($this->entryArray);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-01-05 19:19:56 +02:00
|
|
|
|
$this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("bookword", $count), $count), $this->idGet);
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageRecentBooks extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = localize ("recent.title");
|
2012-05-28 08:05:05 +03:00
|
|
|
|
$this->entryArray = Book::getAllRecentBooks ();
|
2012-05-28 08:07:49 +03:00
|
|
|
|
$this->idPage = Book::ALL_RECENT_BOOKS_ID;
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageQueryResult extends Page
|
|
|
|
|
{
|
2013-09-27 18:13:31 +03:00
|
|
|
|
const SCOPE_TAG = "tag";
|
2014-02-27 01:33:40 +02:00
|
|
|
|
const SCOPE_RATING = "rating";
|
2013-09-27 18:13:31 +03:00
|
|
|
|
const SCOPE_SERIES = "series";
|
|
|
|
|
const SCOPE_AUTHOR = "author";
|
|
|
|
|
const SCOPE_BOOK = "book";
|
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
|
|
|
|
const SCOPE_PUBLISHER = "publisher";
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-12-22 19:40:03 +02:00
|
|
|
|
private function useTypeahead () {
|
|
|
|
|
return !is_null (getURLParam ("search"));
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-02 13:23:04 +02:00
|
|
|
|
private function searchByScope ($scope, $limit = FALSE) {
|
|
|
|
|
$n = $this->n;
|
|
|
|
|
$numberPerPage = NULL;
|
|
|
|
|
if ($limit) {
|
|
|
|
|
$n = 1;
|
|
|
|
|
$numberPerPage = 5;
|
|
|
|
|
}
|
|
|
|
|
switch ($scope) {
|
|
|
|
|
case self::SCOPE_BOOK :
|
|
|
|
|
$array = Book::getBooksByStartingLetter ('%' . $this->query, $n, NULL, $numberPerPage);
|
|
|
|
|
break;
|
|
|
|
|
case self::SCOPE_AUTHOR :
|
|
|
|
|
$array = Author::getAuthorsByStartingLetter ('%' . $this->query);
|
|
|
|
|
break;
|
|
|
|
|
case self::SCOPE_SERIES :
|
|
|
|
|
$array = Serie::getAllSeriesByQuery ($this->query);
|
|
|
|
|
break;
|
|
|
|
|
case self::SCOPE_TAG :
|
|
|
|
|
$array = Tag::getAllTagsByQuery ($this->query, $n, NULL, $numberPerPage);
|
|
|
|
|
break;
|
|
|
|
|
case self::SCOPE_PUBLISHER :
|
|
|
|
|
$array = Publisher::getAllPublishersByQuery ($this->query);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$array = Book::getBooksByQuery (
|
|
|
|
|
array ("all" => "%" . $this->query . "%"), $n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 19:40:03 +02:00
|
|
|
|
public function doSearchByCategory () {
|
|
|
|
|
$database = GetUrlParam (DB);
|
|
|
|
|
$out = array ();
|
|
|
|
|
$pagequery = Base::PAGE_OPENSEARCH_QUERY;
|
|
|
|
|
$dbArray = array ("");
|
|
|
|
|
$d = $database;
|
|
|
|
|
$query = $this->query;
|
|
|
|
|
// Special case when no databases were chosen, we search on all databases
|
|
|
|
|
if (Base::noDatabaseSelected ()) {
|
|
|
|
|
$dbArray = Base::getDbNameList ();
|
|
|
|
|
$d = 0;
|
|
|
|
|
}
|
|
|
|
|
foreach ($dbArray as $key) {
|
|
|
|
|
if (Base::noDatabaseSelected ()) {
|
|
|
|
|
array_push ($this->entryArray, new Entry ($key, DB . ":query:{$d}",
|
|
|
|
|
" ", "text",
|
|
|
|
|
array ( new LinkNavigation ("?" . DB . "={$d}")), "tt-header"));
|
|
|
|
|
Base::getDb ($d);
|
|
|
|
|
}
|
|
|
|
|
foreach (array (PageQueryResult::SCOPE_BOOK,
|
|
|
|
|
PageQueryResult::SCOPE_AUTHOR,
|
|
|
|
|
PageQueryResult::SCOPE_SERIES,
|
|
|
|
|
PageQueryResult::SCOPE_TAG,
|
|
|
|
|
PageQueryResult::SCOPE_PUBLISHER) as $key) {
|
|
|
|
|
if (in_array($key, getCurrentOption ('ignored_categories'))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-01-02 13:23:04 +02:00
|
|
|
|
$array = $this->searchByScope ($key, TRUE);
|
2013-12-22 19:40:03 +02:00
|
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
if (count ($array) == 2 && is_array ($array [0])) {
|
|
|
|
|
$total = $array [1];
|
|
|
|
|
$array = $array [0];
|
|
|
|
|
} else {
|
|
|
|
|
$total = count($array);
|
|
|
|
|
}
|
|
|
|
|
if ($total > 0) {
|
|
|
|
|
// Comment to help the perl i18n script
|
|
|
|
|
// str_format (localize("bookword", count($array))
|
|
|
|
|
// str_format (localize("authorword", count($array))
|
|
|
|
|
// str_format (localize("seriesword", count($array))
|
|
|
|
|
// str_format (localize("tagword", count($array))
|
|
|
|
|
// str_format (localize("publisherword", count($array))
|
|
|
|
|
array_push ($this->entryArray, new Entry (str_format (localize ("search.result.{$key}"), $this->query), DB . ":query:{$d}:{$key}",
|
|
|
|
|
str_format (localize("{$key}word", $total), $total), "text",
|
|
|
|
|
array ( new LinkNavigation ("?page={$pagequery}&query={$query}&db={$d}&scope={$key}")),
|
|
|
|
|
Base::noDatabaseSelected () ? "" : "tt-header"));
|
|
|
|
|
}
|
|
|
|
|
if (!Base::noDatabaseSelected () && $this->useTypeahead ()) {
|
|
|
|
|
foreach ($array as $entry) {
|
|
|
|
|
array_push ($this->entryArray, $entry);
|
|
|
|
|
$i++;
|
|
|
|
|
if ($i > 4) { break; };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$d++;
|
|
|
|
|
if (Base::noDatabaseSelected ()) {
|
|
|
|
|
Base::clearDb ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-05-28 08:05:05 +03:00
|
|
|
|
{
|
2013-09-27 18:13:31 +03:00
|
|
|
|
$scope = getURLParam ("scope");
|
2013-12-14 11:44:48 +02:00
|
|
|
|
if (empty ($scope)) {
|
|
|
|
|
$this->title = str_format (localize ("search.result"), $this->query);
|
|
|
|
|
} else {
|
|
|
|
|
// Comment to help the perl i18n script
|
|
|
|
|
// str_format (localize ("search.result.author"), $this->query)
|
|
|
|
|
// str_format (localize ("search.result.tag"), $this->query)
|
|
|
|
|
// str_format (localize ("search.result.series"), $this->query)
|
|
|
|
|
// str_format (localize ("search.result.book"), $this->query)
|
|
|
|
|
// str_format (localize ("search.result.publisher"), $this->query)
|
|
|
|
|
$this->title = str_format (localize ("search.result.{$scope}"), $this->query);
|
2013-10-06 19:08:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-27 18:13:31 +03:00
|
|
|
|
$crit = "%" . $this->query . "%";
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-29 17:46:52 +03:00
|
|
|
|
// Special case when we are doing a search and no database is selected
|
2013-12-22 19:40:03 +02:00
|
|
|
|
if (Base::noDatabaseSelected () && !$this->useTypeahead ()) {
|
2013-04-29 17:46:52 +03:00
|
|
|
|
$i = 0;
|
2013-12-14 19:25:32 +02:00
|
|
|
|
foreach (Base::getDbNameList () as $key) {
|
2013-04-29 17:46:52 +03:00
|
|
|
|
Base::clearDb ();
|
2013-12-08 22:01:17 +02:00
|
|
|
|
list ($array, $totalNumber) = Book::getBooksByQuery (array ("all" => $crit), 1, $i, 1);
|
2013-10-10 07:25:04 +03:00
|
|
|
|
array_push ($this->entryArray, new Entry ($key, DB . ":query:{$i}",
|
2013-12-07 22:29:37 +02:00
|
|
|
|
str_format (localize ("bookword", $totalNumber), $totalNumber), "text",
|
2013-04-29 17:46:52 +03:00
|
|
|
|
array ( new LinkNavigation ("?" . DB . "={$i}&page=9&query=" . $this->query))));
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-12-23 09:58:56 +02:00
|
|
|
|
if (empty ($scope)) {
|
2013-12-22 19:40:03 +02:00
|
|
|
|
$this->doSearchByCategory ();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-02 13:23:04 +02:00
|
|
|
|
|
|
|
|
|
$array = $this->searchByScope ($scope);
|
|
|
|
|
if (count ($array) == 2 && is_array ($array [0])) {
|
|
|
|
|
list ($this->entryArray, $this->totalNumber) = $array;
|
|
|
|
|
} else {
|
|
|
|
|
$this->entryArray = $array;
|
2013-03-08 10:40:25 +02:00
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 07:06:45 +02:00
|
|
|
|
class PageBookDetail extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2012-12-10 07:06:45 +02:00
|
|
|
|
{
|
2013-06-15 17:09:37 +03:00
|
|
|
|
$this->book = Book::getBookById ($this->idGet);
|
|
|
|
|
$this->title = $this->book->title;
|
2012-12-10 07:06:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 16:00:21 +03:00
|
|
|
|
class PageAbout extends Page
|
|
|
|
|
{
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2013-04-21 16:00:21 +03:00
|
|
|
|
{
|
2013-04-21 16:47:32 +03:00
|
|
|
|
$this->title = localize ("about.title");
|
2013-04-21 16:00:21 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 09:27:29 +03:00
|
|
|
|
class PageCustomize extends Page
|
|
|
|
|
{
|
2013-12-20 16:16:57 +02:00
|
|
|
|
private function isChecked ($key, $testedValue = 1) {
|
2013-12-19 09:38:26 +02:00
|
|
|
|
$value = getCurrentOption ($key);
|
2013-12-20 16:16:57 +02:00
|
|
|
|
if (is_array ($value)) {
|
2013-12-19 09:38:26 +02:00
|
|
|
|
if (in_array ($testedValue, $value)) {
|
|
|
|
|
return "checked='checked'";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-12-20 16:16:57 +02:00
|
|
|
|
if ($value == $testedValue) {
|
2013-12-19 09:38:26 +02:00
|
|
|
|
return "checked='checked'";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-20 16:16:57 +02:00
|
|
|
|
private function isSelected ($key, $value) {
|
|
|
|
|
if (getCurrentOption ($key) == $value) {
|
|
|
|
|
return "selected='selected'";
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getStyleList () {
|
|
|
|
|
$result = array ();
|
2014-02-16 17:55:38 +02:00
|
|
|
|
foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) {
|
2013-12-20 16:16:57 +02:00
|
|
|
|
if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) {
|
|
|
|
|
array_push ($result, $m [1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 07:25:04 +03:00
|
|
|
|
public function InitializeContent ()
|
2013-06-27 09:27:29 +03:00
|
|
|
|
{
|
|
|
|
|
$this->title = localize ("customize.title");
|
|
|
|
|
$this->entryArray = array ();
|
2013-12-20 16:16:57 +02:00
|
|
|
|
|
2013-12-17 23:45:51 +02:00
|
|
|
|
$ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR,
|
|
|
|
|
PageQueryResult::SCOPE_TAG,
|
|
|
|
|
PageQueryResult::SCOPE_SERIES,
|
|
|
|
|
PageQueryResult::SCOPE_PUBLISHER,
|
2014-03-05 12:15:20 +02:00
|
|
|
|
PageQueryResult::SCOPE_RATING,
|
2013-12-17 23:45:51 +02:00
|
|
|
|
"language");
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-06-27 09:27:29 +03:00
|
|
|
|
$content = "";
|
|
|
|
|
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
|
|
|
|
|
$content .= '<select id="style" onchange="updateCookie (this);">';
|
2013-12-20 16:16:57 +02:00
|
|
|
|
foreach ($this-> getStyleList () as $filename) {
|
|
|
|
|
$content .= "<option value='{$filename}' " . $this->isSelected ("style", $filename) . ">{$filename}</option>";
|
2013-06-27 09:27:29 +03:00
|
|
|
|
}
|
|
|
|
|
$content .= '</select>';
|
2013-12-20 16:16:57 +02:00
|
|
|
|
} else {
|
|
|
|
|
foreach ($this-> getStyleList () as $filename) {
|
|
|
|
|
$content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked ("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>";
|
|
|
|
|
}
|
2013-06-27 09:27:29 +03:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.style"), "",
|
|
|
|
|
$content, "text",
|
2013-06-27 09:27:29 +03:00
|
|
|
|
array ()));
|
2013-09-05 09:41:40 +03:00
|
|
|
|
if (!useServerSideRendering ()) {
|
2013-12-19 09:38:26 +02:00
|
|
|
|
$content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked ("use_fancyapps") . ' />';
|
2013-10-10 07:25:04 +03:00
|
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "",
|
|
|
|
|
$content, "text",
|
2013-09-05 09:41:40 +03:00
|
|
|
|
array ()));
|
|
|
|
|
}
|
2013-06-27 09:27:29 +03:00
|
|
|
|
$content = '<input type="number" onchange="updateCookie (this);" id="max_item_per_page" value="' . getCurrentOption ("max_item_per_page") . '" min="-1" max="1200" pattern="^[-+]?[0-9]+$" />';
|
2013-10-10 07:25:04 +03:00
|
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.paging"), "",
|
|
|
|
|
$content, "text",
|
2013-06-27 09:27:29 +03:00
|
|
|
|
array ()));
|
2013-07-24 21:49:24 +03:00
|
|
|
|
$content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption ("email") . '" />';
|
2013-10-10 07:25:04 +03:00
|
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.email"), "",
|
|
|
|
|
$content, "text",
|
2013-07-04 00:40:08 +03:00
|
|
|
|
array ()));
|
2013-12-19 09:38:26 +02:00
|
|
|
|
$content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked ("html_tag_filter") . ' />';
|
2013-10-10 07:25:04 +03:00
|
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.filter"), "",
|
|
|
|
|
$content, "text",
|
2013-07-13 09:29:17 +03:00
|
|
|
|
array ()));
|
2013-12-17 23:45:51 +02:00
|
|
|
|
$content = "";
|
|
|
|
|
foreach ($ignoredBaseArray as $key) {
|
|
|
|
|
$keyPlural = preg_replace ('/(ss)$/', 's', $key . "s");
|
2013-12-19 09:38:26 +02:00
|
|
|
|
$content .= '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked ("ignored_categories", $key) . ' > ' . localize ("{$keyPlural}.title") . '</input> ';
|
2013-12-17 23:45:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.ignored"), "",
|
|
|
|
|
$content, "text",
|
|
|
|
|
array ()));
|
2013-06-27 09:27:29 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 16:00:21 +03:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
abstract class Base
|
|
|
|
|
{
|
|
|
|
|
const PAGE_INDEX = "index";
|
|
|
|
|
const PAGE_ALL_AUTHORS = "1";
|
|
|
|
|
const PAGE_AUTHORS_FIRST_LETTER = "2";
|
|
|
|
|
const PAGE_AUTHOR_DETAIL = "3";
|
|
|
|
|
const PAGE_ALL_BOOKS = "4";
|
|
|
|
|
const PAGE_ALL_BOOKS_LETTER = "5";
|
|
|
|
|
const PAGE_ALL_SERIES = "6";
|
|
|
|
|
const PAGE_SERIE_DETAIL = "7";
|
|
|
|
|
const PAGE_OPENSEARCH = "8";
|
|
|
|
|
const PAGE_OPENSEARCH_QUERY = "9";
|
|
|
|
|
const PAGE_ALL_RECENT_BOOKS = "10";
|
2012-05-28 08:07:49 +03:00
|
|
|
|
const PAGE_ALL_TAGS = "11";
|
|
|
|
|
const PAGE_TAG_DETAIL = "12";
|
2012-12-10 07:06:45 +02:00
|
|
|
|
const PAGE_BOOK_DETAIL = "13";
|
2013-01-19 08:08:47 +02:00
|
|
|
|
const PAGE_ALL_CUSTOMS = "14";
|
|
|
|
|
const PAGE_CUSTOM_DETAIL = "15";
|
2013-04-21 16:00:21 +03:00
|
|
|
|
const PAGE_ABOUT = "16";
|
2013-05-21 20:49:21 +03:00
|
|
|
|
const PAGE_ALL_LANGUAGES = "17";
|
2013-10-10 07:25:04 +03:00
|
|
|
|
const PAGE_LANGUAGE_DETAIL = "18";
|
|
|
|
|
const PAGE_CUSTOMIZE = "19";
|
**2012-11-22**
**Added global support for publishers**
Files modified:
*base.php*
- changed class Entry,
- adding a constant ```cops:publishers``` to the icon array for the feed.
- changed class Page
- added branches to the page selector switch
- changed Page->public function InitializeContent
- added call to pull publisher count from database
- changed class PageAllBooks
- changed it so ```getCurrentOption``` is actually used...
- added page descendant class ```PageAllPublishers```
- handles pulling the publishers category from database
- added page descendant class ```PagePublisherDetail```
- handles pulling the books per publisher data from database
- changed class PageQueryResult
- added constant and switches for publisher search scope
- abstract class Base
- added constants for the publisher pages
*book.php*
- added require statement for publisher.php
- added ```SQL_BOOKS_BY_PUBLISHER``` query to retrieve books by publisher.
- changed class Book
- added query constant
- added publisher item
- added test in case no known publisher
- added publishername and url array elements for the JSON output
- added public function ```getPublisher```
- added public static function ```getBooksByPublisher``` to fire the query
- changed function getJson
- added publisher category to search
- added publishername (single) and publishertitle(plural) localization entries to i18n translation array
*index.php*
- added require statement for publisher.php
*lang/Localization_en.json
- added new localization entries for publisher labels (see below)
```
"publisher.alphabetical.many":"Alphabetical index of the {0} publishers",
"publisher.alphabetical.none":"Alphabetical index of absolutely no publisher",
"publisher.alphabetical.one":"Alphabetical index of the single publisher",
"publisher.name":"Publisher",
"publisher.title":"Publishers",
"publisherword.many":"{0} publishers",
"publisherword.none":"No publisher",
"publisherword.one":"1 publisher",
"search.result.publisher":"Search result for *{0}* in publishers",
```
*templates\bookdetail.html*
- added publisher label and item to bookdetail popup
*test\bookTest.php*
- added indices and names of publishers added to testdatabase as comment
- added test function ```testGetBooksByPublisher```
- changed test function testGetBookById to add assertion for publisher name
- changed test function testTypeaheadSearch to add search on partial publisher name.
*test\pageTest.php*
- changed test function testPageIndex to insert publisher category and adjust page indices
- changed test function testPageIndexWithCustomColum to adjust for the changed page indices
- added test function testPageAllPublishers
- added test function testPagePublishersDetail
- added test function testPageSearchScopePublishers
*test\BaseWithSomeBooks\metadata.db*
- added 5 publishers spread across all 14 books, replacing the original publisher Feedbooks
Files added:
*publisher.php*
2013-11-22 23:08:09 +02:00
|
|
|
|
const PAGE_ALL_PUBLISHERS = "20";
|
|
|
|
|
const PAGE_PUBLISHER_DETAIL = "21";
|
2014-02-27 01:33:40 +02:00
|
|
|
|
const PAGE_ALL_RATINGS = "22";
|
|
|
|
|
const PAGE_RATING_DETAIL = "23";
|
2012-05-28 08:07:49 +03:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
const COMPATIBILITY_XML_ALDIKO = "aldiko";
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
private static $db = NULL;
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2013-11-22 15:36:39 +02:00
|
|
|
|
public static function isMultipleDatabaseEnabled () {
|
|
|
|
|
global $config;
|
|
|
|
|
return is_array ($config['calibre_directory']);
|
|
|
|
|
}
|
2013-12-20 16:16:57 +02:00
|
|
|
|
|
2014-03-10 22:14:54 +02:00
|
|
|
|
public static function useAbsolutePath () {
|
|
|
|
|
global $config;
|
|
|
|
|
$path = self::getDbDirectory();
|
|
|
|
|
return preg_match ('/^\//', Base::getDbDirectory ()) || // Linux /
|
|
|
|
|
preg_match ('/^\w\:/', Base::getDbDirectory ()); // Windows X:
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 12:30:42 +02:00
|
|
|
|
public static function noDatabaseSelected () {
|
|
|
|
|
return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB));
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-04 21:53:44 +03:00
|
|
|
|
public static function getDbList () {
|
|
|
|
|
global $config;
|
2013-12-14 11:32:28 +02:00
|
|
|
|
if (self::isMultipleDatabaseEnabled ()) {
|
2013-04-04 21:53:44 +03:00
|
|
|
|
return $config['calibre_directory'];
|
|
|
|
|
} else {
|
|
|
|
|
return array ("" => $config['calibre_directory']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-20 16:16:57 +02:00
|
|
|
|
|
2013-12-14 19:25:32 +02:00
|
|
|
|
public static function getDbNameList () {
|
|
|
|
|
global $config;
|
|
|
|
|
if (self::isMultipleDatabaseEnabled ()) {
|
|
|
|
|
return array_keys ($config['calibre_directory']);
|
|
|
|
|
} else {
|
|
|
|
|
return array ("");
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-17 14:36:19 +03:00
|
|
|
|
|
|
|
|
|
public static function getDbName ($database = NULL) {
|
|
|
|
|
global $config;
|
2013-12-14 11:32:28 +02:00
|
|
|
|
if (self::isMultipleDatabaseEnabled ()) {
|
2013-04-17 14:36:19 +03:00
|
|
|
|
if (is_null ($database)) $database = GetUrlParam (DB, 0);
|
|
|
|
|
$array = array_keys ($config['calibre_directory']);
|
|
|
|
|
return $array[$database];
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-04 21:53:44 +03:00
|
|
|
|
public static function getDbDirectory ($database = NULL) {
|
2013-01-05 08:35:19 +02:00
|
|
|
|
global $config;
|
2013-12-14 11:32:28 +02:00
|
|
|
|
if (self::isMultipleDatabaseEnabled ()) {
|
2013-04-04 21:53:44 +03:00
|
|
|
|
if (is_null ($database)) $database = GetUrlParam (DB, 0);
|
2013-04-03 16:00:09 +03:00
|
|
|
|
$array = array_values ($config['calibre_directory']);
|
|
|
|
|
return $array[$database];
|
|
|
|
|
}
|
|
|
|
|
return $config['calibre_directory'];
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-04 21:53:44 +03:00
|
|
|
|
public static function getDbFileName ($database = NULL) {
|
|
|
|
|
return self::getDbDirectory ($database) .'metadata.db';
|
2013-01-05 08:35:19 +02:00
|
|
|
|
}
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2013-11-25 18:10:43 +02:00
|
|
|
|
private static function error () {
|
2013-12-14 19:48:34 +02:00
|
|
|
|
if (php_sapi_name() != "cli") {
|
|
|
|
|
header("location: checkconfig.php?err=1");
|
|
|
|
|
}
|
|
|
|
|
throw new Exception('Database not found.');
|
2013-11-25 18:10:43 +02:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-29 17:46:52 +03:00
|
|
|
|
public static function getDb ($database = NULL) {
|
2012-05-28 08:01:33 +03:00
|
|
|
|
if (is_null (self::$db)) {
|
|
|
|
|
try {
|
2013-11-25 22:16:34 +02:00
|
|
|
|
if (is_readable (self::getDbFileName ($database))) {
|
2013-11-25 18:10:43 +02:00
|
|
|
|
self::$db = new PDO('sqlite:'. self::getDbFileName ($database));
|
|
|
|
|
} else {
|
|
|
|
|
self::error ();
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
} catch (Exception $e) {
|
2013-11-25 18:10:43 +02:00
|
|
|
|
self::error ();
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return self::$db;
|
2012-09-18 16:39:22 +03:00
|
|
|
|
}
|
2013-12-20 16:16:57 +02:00
|
|
|
|
|
2013-12-14 19:25:32 +02:00
|
|
|
|
public static function checkDatabaseAvailability () {
|
|
|
|
|
if (self::noDatabaseSelected ()) {
|
|
|
|
|
for ($i = 0; $i < count (self::getDbList ()); $i++) {
|
|
|
|
|
self::getDb ($i);
|
|
|
|
|
self::clearDb ();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
self::getDb ();
|
|
|
|
|
}
|
2013-12-14 19:48:34 +02:00
|
|
|
|
return true;
|
2013-12-14 19:25:32 +02:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-29 17:46:52 +03:00
|
|
|
|
public static function clearDb () {
|
|
|
|
|
self::$db = NULL;
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-11-22 15:36:39 +02:00
|
|
|
|
public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) {
|
2012-09-18 16:39:22 +03:00
|
|
|
|
$totalResult = -1;
|
2013-12-05 11:52:51 +02:00
|
|
|
|
|
2013-11-22 15:36:39 +02:00
|
|
|
|
if (is_null ($numberPerPage)) {
|
|
|
|
|
$numberPerPage = getCurrentOption ("max_item_per_page");
|
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-11-22 15:36:39 +02:00
|
|
|
|
if ($numberPerPage != -1 && $n != -1)
|
2012-09-18 16:39:22 +03:00
|
|
|
|
{
|
|
|
|
|
// First check total number of results
|
2013-04-29 17:46:52 +03:00
|
|
|
|
$result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter));
|
2012-09-18 16:39:22 +03:00
|
|
|
|
$result->execute ($params);
|
|
|
|
|
$totalResult = $result->fetchColumn ();
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2012-09-18 16:39:22 +03:00
|
|
|
|
// Next modify the query and params
|
|
|
|
|
$query .= " limit ?, ?";
|
2013-11-22 15:36:39 +02:00
|
|
|
|
array_push ($params, ($n - 1) * $numberPerPage, $numberPerPage);
|
2012-09-18 16:39:22 +03:00
|
|
|
|
}
|
2013-10-10 07:25:04 +03:00
|
|
|
|
|
2013-04-29 17:46:52 +03:00
|
|
|
|
$result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter));
|
2012-09-18 16:39:22 +03:00
|
|
|
|
$result->execute ($params);
|
|
|
|
|
return array ($totalResult, $result);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|