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)
|
|
|
|
|
* @author S<EFBFBD>bastien Lucas <sebastien@slucas.fr>
|
|
|
|
|
*/
|
|
|
|
|
|
2013-02-14 10:19:31 +02:00
|
|
|
|
define ("VERSION", "0.3.2");
|
2012-06-23 15:50:50 +03:00
|
|
|
|
date_default_timezone_set($config['default_timezone']);
|
2012-06-02 10:10:54 +03:00
|
|
|
|
|
2012-05-28 08:05:05 +03:00
|
|
|
|
function getURLParam ($name, $default = NULL) {
|
|
|
|
|
if (!empty ($_GET) && isset($_GET[$name])) {
|
|
|
|
|
return $_GET[$name];
|
|
|
|
|
}
|
|
|
|
|
return $default;
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03: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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function html2xhtml ($html) {
|
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
|
$doc->loadHTML($html); // Load the HTML
|
|
|
|
|
$output = utf8_decode($doc->saveXML($doc->documentElement)); // Transform to an Ansi xml stream
|
|
|
|
|
$output = xml2xhtml($output); // Fix the br / hr ...
|
|
|
|
|
if (preg_match ("/<html><body>(.*)<\/body><\/html>/", $output, $matches)) {
|
|
|
|
|
$output = $matches [1]; // Remove <html><body>
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-01-05 15:33:12 +02:00
|
|
|
|
function localize($phrase, $count=-1) {
|
|
|
|
|
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;
|
|
|
|
|
/* 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;
|
|
|
|
|
$lang_file = 'lang/Localization_' . $lang . '.json';
|
|
|
|
|
if (!file_exists($lang_file)) {
|
|
|
|
|
$lang_file = 'lang/' . 'Localization_en.json';
|
|
|
|
|
}
|
|
|
|
|
elseif ($lang != "en") {
|
|
|
|
|
$lang_file_en = 'lang/' . 'Localization_en.json';
|
|
|
|
|
}
|
|
|
|
|
$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);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $translations[$phrase];
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 09:30:41 +02:00
|
|
|
|
function addURLParameter($urlParams, $paramName, $paramValue) {
|
|
|
|
|
$params = array();
|
|
|
|
|
parse_str($urlParams, $params);
|
|
|
|
|
if (empty ($paramValue)) {
|
|
|
|
|
unset ($params[$paramName]);
|
|
|
|
|
} else {
|
|
|
|
|
$params[$paramName] = $paramValue;
|
|
|
|
|
}
|
|
|
|
|
return http_build_query($params);
|
|
|
|
|
}
|
|
|
|
|
|
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";
|
2012-05-28 08:07:49 +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;
|
2012-05-28 08:01:33 +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
|
|
|
|
}
|
2012-05-28 08:06:12 +03:00
|
|
|
|
|
|
|
|
|
public function hrefXhtml () {
|
|
|
|
|
return str_replace ("&", "&", $this->href);
|
|
|
|
|
}
|
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);
|
2012-05-28 08:06:12 +03:00
|
|
|
|
$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);
|
|
|
|
|
$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;
|
|
|
|
|
private static $updated = NULL;
|
|
|
|
|
|
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',
|
|
|
|
|
CustomColumn::ALL_CUSTOMS_ID => 'images/tag.png',
|
|
|
|
|
"calibre:books$" => 'images/allbook.png',
|
|
|
|
|
"calibre:books:letter" => 'images/allbook.png'
|
2012-05-28 08:07:49 +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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray) {
|
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;
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class EntryBook extends Entry
|
|
|
|
|
{
|
|
|
|
|
public $book;
|
|
|
|
|
|
|
|
|
|
public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pbook) {
|
|
|
|
|
parent::__construct ($ptitle, $pid, $pcontent, $pcontentType, $plinkArray);
|
|
|
|
|
$this->book = $pbook;
|
|
|
|
|
$this->localUpdated = $pbook->timestamp;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 = "";
|
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;
|
|
|
|
|
public $totalNumber = -1;
|
2012-05-28 08:05:05 +03:00
|
|
|
|
public $entryArray = array();
|
|
|
|
|
|
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-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);
|
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);
|
2012-05-28 08:05:05 +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-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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-18 16:39:22 +03:00
|
|
|
|
public function __construct($pid, $pquery, $pn) {
|
2012-12-22 19:03:52 +02:00
|
|
|
|
global $config;
|
|
|
|
|
|
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'];
|
2012-09-18 16:39:22 +03:00
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$this->title = $config['cops_title_default'];
|
2012-12-22 19:23:17 +02:00
|
|
|
|
$this->subtitle = $config['cops_subtitle_default'];
|
2012-05-28 08:05:05 +03:00
|
|
|
|
array_push ($this->entryArray, Author::getCount());
|
|
|
|
|
array_push ($this->entryArray, Serie::getCount());
|
2012-05-28 08:07:49 +03:00
|
|
|
|
array_push ($this->entryArray, Tag::getCount());
|
2013-01-19 08:08:47 +02:00
|
|
|
|
foreach ($config['cops_calibre_custom_column'] as $lookup) {
|
|
|
|
|
$customId = CustomColumn::getCustomId ($lookup);
|
|
|
|
|
if (!is_null ($customId)) {
|
|
|
|
|
array_push ($this->entryArray, CustomColumn::getCount($customId));
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-28 08:05:05 +03:00
|
|
|
|
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
|
|
|
|
|
}
|
2012-09-21 14:36:52 +03:00
|
|
|
|
|
2012-09-21 15:19:11 +03:00
|
|
|
|
public function isPaginated ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
2012-10-11 22:14:06 +03:00
|
|
|
|
return ($config['cops_max_item_per_page'] != -1 &&
|
|
|
|
|
$this->totalNumber != -1 &&
|
|
|
|
|
$this->totalNumber > $config['cops_max_item_per_page']);
|
2012-09-21 15:19:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-21 14:36:52 +03:00
|
|
|
|
public function getNextLink ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$currentUrl = $_SERVER['QUERY_STRING'];
|
|
|
|
|
$currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . $_SERVER['QUERY_STRING']);
|
|
|
|
|
if (($this->n) * $config['cops_max_item_per_page'] < $this->totalNumber) {
|
|
|
|
|
return new LinkNavigation ($currentUrl . "&n=" . ($this->n + 1), "next", "Page suivante");
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPrevLink ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
$currentUrl = $_SERVER['QUERY_STRING'];
|
|
|
|
|
$currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . $_SERVER['QUERY_STRING']);
|
|
|
|
|
if ($this->n > 1) {
|
|
|
|
|
return new LinkNavigation ($currentUrl . "&n=" . ($this->n - 1), "previous", "Page precedente");
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-10-11 22:14:06 +03:00
|
|
|
|
|
|
|
|
|
public function getMaxPage ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
return ceil ($this->totalNumber / $config['cops_max_item_per_page']);
|
|
|
|
|
}
|
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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
2012-09-29 15:45:27 +03:00
|
|
|
|
global $config;
|
|
|
|
|
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = localize("authors.title");
|
2012-09-29 15:45:27 +03:00
|
|
|
|
if ($config['cops_author_split_first_letter'] == 1) {
|
|
|
|
|
$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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
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-05-28 08:07:49 +03:00
|
|
|
|
class PageAllTags extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
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-01-19 08:08:47 +02:00
|
|
|
|
class PageCustomDetail extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
|
|
|
|
$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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
|
|
|
|
$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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
|
|
|
|
$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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:05:05 +03:00
|
|
|
|
class PageAllSeries extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PageAllBooks extends Page
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = localize ("allbooks.title");
|
2012-05-28 08:05:05 +03:00
|
|
|
|
$this->entryArray = Book::getAllBooks ();
|
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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
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-01-05 19:19:56 +02:00
|
|
|
|
|
|
|
|
|
$count = $this->totalNumber;
|
|
|
|
|
if ($count == -1)
|
|
|
|
|
$count = count ($this->entryArray);
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
2012-05-29 21:10:41 +03:00
|
|
|
|
$this->title = "Search result for query *" . $this->query . "*"; // TODO I18N
|
2012-09-20 22:15:03 +03:00
|
|
|
|
list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery ($this->query, $this->n);
|
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
|
|
|
|
|
{
|
|
|
|
|
public function InitializeContent ()
|
|
|
|
|
{
|
2013-01-03 22:40:43 +02:00
|
|
|
|
$book = Book::getBookById ($this->idGet);
|
|
|
|
|
$this->title = $book->title;
|
2012-12-10 07:06:45 +02: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";
|
2012-05-28 08:07:49 +03:00
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
const COMPATIBILITY_XML_ALDIKO = "aldiko";
|
|
|
|
|
|
|
|
|
|
private static $db = NULL;
|
|
|
|
|
|
2013-01-05 08:35:19 +02:00
|
|
|
|
public static function getDbFileName () {
|
|
|
|
|
global $config;
|
|
|
|
|
return $config['calibre_directory'] .'metadata.db';
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 08:01:33 +03:00
|
|
|
|
public static function getDb () {
|
|
|
|
|
global $config;
|
|
|
|
|
if (is_null (self::$db)) {
|
|
|
|
|
try {
|
2013-01-05 08:35:19 +02:00
|
|
|
|
self::$db = new PDO('sqlite:'. self::getDbFileName ());
|
2012-05-28 08:01:33 +03:00
|
|
|
|
} catch (Exception $e) {
|
2013-01-06 10:49:05 +02:00
|
|
|
|
header("location: checkconfig.php?err=1");
|
2013-01-05 08:35:19 +02:00
|
|
|
|
exit();
|
2012-05-28 08:01:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return self::$db;
|
2012-09-18 16:39:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-11 16:16:15 +02:00
|
|
|
|
public static function executeQuery($query, $columns, $filter, $params, $n) {
|
2012-09-18 16:39:22 +03:00
|
|
|
|
global $config;
|
|
|
|
|
$totalResult = -1;
|
|
|
|
|
|
2012-09-30 15:39:53 +03:00
|
|
|
|
if ($config['cops_max_item_per_page'] != -1 && $n != -1)
|
2012-09-18 16:39:22 +03:00
|
|
|
|
{
|
|
|
|
|
// First check total number of results
|
2013-01-11 16:16:15 +02:00
|
|
|
|
$result = self::getDb ()->prepare (str_format ($query, "count(*)", $filter));
|
2012-09-18 16:39:22 +03:00
|
|
|
|
$result->execute ($params);
|
|
|
|
|
$totalResult = $result->fetchColumn ();
|
|
|
|
|
|
|
|
|
|
// Next modify the query and params
|
|
|
|
|
$query .= " limit ?, ?";
|
|
|
|
|
array_push ($params, ($n - 1) * $config['cops_max_item_per_page'], $config['cops_max_item_per_page']);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-11 16:16:15 +02:00
|
|
|
|
$result = self::getDb ()->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
|
|
|
|
}
|
|
|
|
|
?>
|