Merge pull request #95 from Marsender/master

Add an application to run actions
This commit is contained in:
Sébastien Lucas 2013-10-10 06:24:20 -07:00
commit 938843596a
18 changed files with 855 additions and 167 deletions

View file

@ -7,7 +7,7 @@
*/
require_once ("base.php");
class OPDSRenderer
{
const PAGE_OPENSEARCH = "8";
@ -15,14 +15,14 @@ class OPDSRenderer
private $xmlStream = NULL;
private $updated = NULL;
private function getUpdatedTime () {
if (is_null ($this->updated)) {
$this->updated = time();
}
return date (DATE_ATOM, $this->updated);
}
private function getXmlStream () {
if (is_null ($this->xmlStream)) {
$this->xmlStream = new XMLWriter();
@ -31,7 +31,7 @@ class OPDSRenderer
}
return $this->xmlStream;
}
public function getOpenSearch () {
global $config;
$xml = new XMLWriter ();
@ -74,7 +74,7 @@ class OPDSRenderer
$xml->endDocument();
return $xml->outputMemory(true);
}
private function startXmlDocument ($page) {
global $config;
self::getXmlStream ()->startDocument('1.0','UTF-8');
@ -113,13 +113,13 @@ class OPDSRenderer
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("author");
self::getXmlStream ()->startElement ("name");
self::getXmlStream ()->text (utf8_encode ("Sébastien Lucas"));
self::getXmlStream ()->text ($page->authorName);
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("uri");
self::getXmlStream ()->text ("http://blog.slucas.fr");
self::getXmlStream ()->text ($page->authorUri);
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("email");
self::getXmlStream ()->text ("sebastien@slucas.fr");
self::getXmlStream ()->text ($page->authorEmail);
self::getXmlStream ()->endElement ();
self::getXmlStream ()->endElement ();
$link = new LinkNavigation ("", "start", "Home");
@ -146,13 +146,13 @@ class OPDSRenderer
}
}
}
private function endXmlDocument () {
self::getXmlStream ()->endElement ();
self::getXmlStream ()->endDocument ();
return self::getXmlStream ()->outputMemory(true);
}
private function renderLink ($link) {
self::getXmlStream ()->startElement ("link");
self::getXmlStream ()->writeAttribute ("href", $link->href);
@ -172,7 +172,7 @@ class OPDSRenderer
self::getXmlStream ()->endElement ();
}
private function renderEntry ($entry) {
self::getXmlStream ()->startElement ("title");
self::getXmlStream ()->text ($entry->title);
@ -194,11 +194,11 @@ class OPDSRenderer
foreach ($entry->linkArray as $link) {
self::renderLink ($link);
}
if (get_class ($entry) != "EntryBook") {
return;
}
foreach ($entry->book->getAuthors () as $author) {
self::getXmlStream ()->startElement ("author");
self::getXmlStream ()->startElement ("name");
@ -223,7 +223,7 @@ class OPDSRenderer
self::getXmlStream ()->text (date ("Y-m-d", $entry->book->pubdate) . "T08:08:08Z");
self::getXmlStream ()->endElement ();
}
$lang = $entry->book->getLanguages ();
if (!empty ($lang)) {
self::getXmlStream ()->startElement ("dcterms:language");
@ -232,7 +232,7 @@ class OPDSRenderer
}
}
public function render ($page) {
global $config;
self::startXmlDocument ($page);
@ -264,4 +264,4 @@ class OPDSRenderer
return self::endXmlDocument ();
}
}

204
base.php
View file

@ -10,12 +10,12 @@ define ("VERSION", "0.7.0beta");
define ("DB", "db");
date_default_timezone_set($config['default_timezone']);
function useServerSideRendering () {
global $config;
return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']);
}
function getURLParam ($name, $default = NULL) {
if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") {
return $_GET[$name];
@ -31,11 +31,11 @@ function getCurrentOption ($option) {
if ($option == "style") {
return "default";
}
if (isset($config ["cops_" . $option])) {
return $config ["cops_" . $option];
}
return "";
}
@ -84,7 +84,7 @@ function display_xml_error($error)
function are_libxml_errors_ok ()
{
$errors = libxml_get_errors();
foreach ($errors as $error) {
if ($error->code == 801) return false;
}
@ -94,15 +94,15 @@ function are_libxml_errors_ok ()
function html2xhtml ($html) {
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' .
$doc->loadHTML('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' .
$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>
}
/*
/*
// In case of error with summary, use it to debug
$errors = libxml_get_errors();
@ -110,9 +110,9 @@ function html2xhtml ($html) {
$output .= display_xml_error($error);
}
*/
if (!are_libxml_errors_ok ()) $output = "HTML code not valid.";
libxml_use_internal_errors(false);
return $output;
}
@ -124,7 +124,7 @@ function html2xhtml ($html) {
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) {
@ -132,7 +132,7 @@ function str_format($format) {
$format = substr_replace($format, @$args[$i], $offset + $data[1] - 1, 2 + strlen($i));
$offset += strlen(@$args[$i]) - 2 - strlen($i);
}
return $format;
}
@ -168,7 +168,7 @@ function localize($phrase, $count=-1) {
$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);
/* Clean the array of all unfinished translations */
foreach ($translations as $key => $val) {
if (preg_match ("/^##TODO##/", $key)) {
@ -199,7 +199,7 @@ function addURLParameter($urlParams, $paramName, $paramValue) {
if (empty ($paramValue) && $paramValue != 0) {
unset ($params[$paramName]);
} else {
$params[$paramName] = $paramValue;
$params[$paramName] = $paramValue;
}
return $start . http_build_query($params);
}
@ -211,14 +211,14 @@ class Link
const OPDS_ACQUISITION_TYPE = "http://opds-spec.org/acquisition";
const OPDS_NAVIGATION_TYPE = "application/atom+xml;profile=opds-catalog;kind=navigation";
const OPDS_PAGING_TYPE = "application/atom+xml;profile=opds-catalog;kind=acquisition";
public $href;
public $type;
public $rel;
public $title;
public $facetGroup;
public $activeFacet;
public function __construct($phref, $ptype, $prel = NULL, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) {
$this->href = $phref;
$this->type = $ptype;
@ -227,7 +227,7 @@ class Link
$this->facetGroup = $pfacetGroup;
$this->activeFacet = $pactiveFacet;
}
public function hrefXhtml () {
return $this->href;
}
@ -265,7 +265,7 @@ class Entry
public $linkArray;
public $localUpdated;
private static $updated = NULL;
public static $icons = array(
Author::ALL_AUTHORS_ID => 'images/author.png',
Serie::ALL_SERIES_ID => 'images/serie.png',
@ -276,7 +276,7 @@ class Entry
"calibre:books$" => 'images/allbook.png',
"calibre:books:letter" => 'images/allbook.png'
);
public function getUpdatedTime () {
if (!is_null ($this->localUpdated)) {
return date (DATE_ATOM, $this->localUpdated);
@ -286,20 +286,20 @@ class Entry
}
return date (DATE_ATOM, self::$updated);
}
public function getNavLink () {
foreach ($this->linkArray as $link) {
foreach ($this->linkArray as $link) {
if ($link->type != Link::OPDS_NAVIGATION_TYPE) { continue; }
return $link->hrefXhtml ();
}
return "#";
}
public function getContentArray () {
return array ( "title" => $this->title, "content" => $this->content, "navlink" => $this->getNavLink () );
}
public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray) {
global $config;
$this->title = $ptitle;
@ -307,7 +307,7 @@ class Entry
$this->content = $pcontent;
$this->contentType = $pcontentType;
$this->linkArray = $plinkArray;
if ($config['cops_show_icons'] == 1)
{
foreach (self::$icons as $reg => $image)
@ -318,7 +318,7 @@ class Entry
}
}
}
if (!is_null (GetUrlParam (DB))) $this->id = GetUrlParam (DB) . ":" . $this->id;
}
}
@ -326,19 +326,19 @@ class Entry
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;
}
public function getContentArray () {
$entry = array ( "title" => $this->title);
$entry ["book"] = $this->book->getContentArray ();
return $entry;
}
public function getCoverThumbnail () {
foreach ($this->linkArray as $link) {
if ($link->rel == Link::OPDS_THUMBNAIL_TYPE)
@ -346,7 +346,7 @@ class EntryBook extends Entry
}
return null;
}
public function getCover () {
foreach ($this->linkArray as $link) {
if ($link->rel == Link::OPDS_IMAGE_TYPE)
@ -360,6 +360,9 @@ class Page
{
public $title;
public $subtitle = "";
public $authorName = "";
public $authorUri = "";
public $authorEmail = "";
public $idPage;
public $idGet;
public $query;
@ -368,7 +371,7 @@ class Page
public $book;
public $totalNumber = -1;
public $entryArray = array();
public static function getPage ($pageId, $id, $query, $n)
{
switch ($pageId) {
@ -385,7 +388,7 @@ class Page
case Base::PAGE_ALL_LANGUAGES :
return new PageAllLanguages ($id, $query, $n);
case Base::PAGE_LANGUAGE_DETAIL :
return new PageLanguageDetail ($id, $query, $n);
return new PageLanguageDetail ($id, $query, $n);
case Base::PAGE_ALL_CUSTOMS :
return new PageAllCustoms ($id, $query, $n);
case Base::PAGE_CUSTOM_DETAIL :
@ -398,7 +401,7 @@ class Page
return new PageAllBooksLetter ($id, $query, $n);
case Base::PAGE_ALL_RECENT_BOOKS :
return new PageRecentBooks ($id, $query, $n);
case Base::PAGE_SERIE_DETAIL :
case Base::PAGE_SERIE_DETAIL :
return new PageSerieDetail ($id, $query, $n);
case Base::PAGE_OPENSEARCH_QUERY :
return new PageQueryResult ($id, $query, $n);
@ -406,7 +409,7 @@ class Page
return new PageBookDetail ($id, $query, $n);
case Base::PAGE_ABOUT :
return new PageAbout ($id, $query, $n);
case Base::PAGE_CUSTOMIZE :
case Base::PAGE_CUSTOMIZE :
return new PageCustomize ($id, $query, $n);
default:
$page = new Page ($id, $query, $n);
@ -414,17 +417,20 @@ class Page
return $page;
}
}
public function __construct($pid, $pquery, $pn) {
global $config;
$this->idGet = $pid;
$this->query = $pquery;
$this->n = $pn;
$this->favicon = $config['cops_icon'];
$this->authorName = empty($config['cops_author_name']) ? utf8_encode('Sébastien Lucas') : $config['cops_author_name'];
$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'];
}
public function InitializeContent ()
public function InitializeContent ()
{
global $config;
$this->title = $config['cops_title_default'];
@ -434,8 +440,8 @@ class Page
$i = 0;
foreach ($config['calibre_directory'] as $key => $value) {
$nBooks = Book::getBookCount ($i);
array_push ($this->entryArray, new Entry ($key, "{$i}:cops:catalog",
str_format (localize ("bookword", $nBooks), $nBooks), "text",
array_push ($this->entryArray, new Entry ($key, "{$i}:cops:catalog",
str_format (localize ("bookword", $nBooks), $nBooks), "text",
array ( new LinkNavigation ("?" . DB . "={$i}"))));
$i++;
Base::clearDb ();
@ -455,7 +461,7 @@ class Page
}
}
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
if (!is_null ($database)) $this->title = Base::getDbName ();
}
}
@ -463,11 +469,11 @@ class Page
public function isPaginated ()
{
global $config;
return (getCurrentOption ("max_item_per_page") != -1 &&
$this->totalNumber != -1 &&
return (getCurrentOption ("max_item_per_page") != -1 &&
$this->totalNumber != -1 &&
$this->totalNumber > getCurrentOption ("max_item_per_page"));
}
public function getNextLink ()
{
global $config;
@ -478,7 +484,7 @@ class Page
}
return NULL;
}
public function getPrevLink ()
{
global $config;
@ -489,13 +495,13 @@ class Page
}
return NULL;
}
public function getMaxPage ()
{
global $config;
return ceil ($this->totalNumber / getCurrentOption ("max_item_per_page"));
}
public function containsBook ()
{
if (count ($this->entryArray) == 0) return false;
@ -507,10 +513,10 @@ class Page
class PageAllAuthors extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
global $config;
$this->title = localize("authors.title");
if ($config['cops_author_split_first_letter'] == 1) {
$this->entryArray = Author::getAllAuthorsByFirstLetter();
@ -524,10 +530,10 @@ class PageAllAuthors extends Page
class PageAllAuthorsLetter extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
global $config;
$this->idPage = Author::getEntryIdByLetter ($this->idGet);
$this->entryArray = Author::getAuthorsByStartingLetter ($this->idGet);
$this->title = str_format (localize ("splitByLetter.letter"), str_format (localize ("authorword", count ($this->entryArray)), count ($this->entryArray)), $this->idGet);
@ -536,7 +542,7 @@ class PageAllAuthorsLetter extends Page
class PageAuthorDetail extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$author = Author::getAuthorById ($this->idGet);
$this->idPage = $author->getEntryId ();
@ -547,7 +553,7 @@ class PageAuthorDetail extends Page
class PageAllTags extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$this->title = localize("tags.title");
$this->entryArray = Tag::getAllTags();
@ -557,7 +563,7 @@ class PageAllTags extends Page
class PageAllLanguages extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$this->title = localize("languages.title");
$this->entryArray = Language::getAllLanguages();
@ -567,7 +573,7 @@ class PageAllLanguages extends Page
class PageCustomDetail extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$customId = getURLParam ("custom", NULL);
$custom = CustomColumn::getCustomById ($customId, $this->idGet);
@ -579,7 +585,7 @@ class PageCustomDetail extends Page
class PageAllCustoms extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$customId = getURLParam ("custom", NULL);
$this->title = CustomColumn::getAllTitle ($customId);
@ -590,7 +596,7 @@ class PageAllCustoms extends Page
class PageTagDetail extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$tag = Tag::getTagById ($this->idGet);
$this->idPage = $tag->getEntryId ();
@ -601,7 +607,7 @@ class PageTagDetail extends Page
class PageLanguageDetail extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$language = Language::getLanguageById ($this->idGet);
$this->idPage = $language->getEntryId ();
@ -612,7 +618,7 @@ class PageLanguageDetail extends Page
class PageAllSeries extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$this->title = localize("series.title");
$this->entryArray = Serie::getAllSeries();
@ -622,7 +628,7 @@ class PageAllSeries extends Page
class PageSerieDetail extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$serie = Serie::getSerieById ($this->idGet);
$this->title = $serie->name;
@ -633,7 +639,7 @@ class PageSerieDetail extends Page
class PageAllBooks extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$this->title = localize ("allbooks.title");
$this->entryArray = Book::getAllBooks ();
@ -643,22 +649,22 @@ class PageAllBooks extends Page
class PageAllBooksLetter extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
list ($this->entryArray, $this->totalNumber) = Book::getBooksByStartingLetter ($this->idGet, $this->n);
$this->idPage = Book::getEntryIdByLetter ($this->idGet);
$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);
}
}
class PageRecentBooks extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$this->title = localize ("recent.title");
$this->entryArray = Book::getAllRecentBooks ();
@ -672,8 +678,8 @@ class PageQueryResult extends Page
const SCOPE_SERIES = "series";
const SCOPE_AUTHOR = "author";
const SCOPE_BOOK = "book";
public function InitializeContent ()
public function InitializeContent ()
{
global $config;
$scope = getURLParam ("scope");
@ -689,22 +695,22 @@ class PageQueryResult extends Page
break;
case self::SCOPE_BOOK :
$this->title = str_format (localize ("search.result.book"), $this->query);
break;
break;
default:
$this->title = str_format (localize ("search.result"), $this->query);
}
$crit = "%" . $this->query . "%";
$bad = "QQQQQ";
// Special case when we are doing a search and no database is selected
if (is_array ($config['calibre_directory']) && is_null (GetUrlParam (DB))) {
$i = 0;
foreach ($config['calibre_directory'] as $key => $value) {
Base::clearDb ();
list ($array, $totalNumber) = Book::getBooksByQuery (array ($crit, $crit, $crit, $crit), $this->n, $i);
array_push ($this->entryArray, new Entry ($key, DB . ":query:{$i}",
str_format (localize ("bookword", count($array)), count($array)), "text",
array_push ($this->entryArray, new Entry ($key, DB . ":query:{$i}",
str_format (localize ("bookword", count($array)), count($array)), "text",
array ( new LinkNavigation ("?" . DB . "={$i}&page=9&query=" . $this->query))));
$i++;
}
@ -723,7 +729,7 @@ class PageQueryResult extends Page
case self::SCOPE_BOOK :
list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery (
array ($bad, $bad, $bad, $crit), $this->n);
break;
break;
default:
list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery (
array ($crit, $crit, $crit, $crit), $this->n);
@ -733,7 +739,7 @@ class PageQueryResult extends Page
class PageBookDetail extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$this->book = Book::getBookById ($this->idGet);
$this->title = $this->book->title;
@ -742,7 +748,7 @@ class PageBookDetail extends Page
class PageAbout extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
$this->title = localize ("about.title");
}
@ -750,12 +756,12 @@ class PageAbout extends Page
class PageCustomize extends Page
{
public function InitializeContent ()
public function InitializeContent ()
{
global $config;
$this->title = localize ("customize.title");
$this->entryArray = array ();
$use_fancybox = "";
if (getCurrentOption ("use_fancyapps") == 1) {
$use_fancybox = "checked='checked'";
@ -764,8 +770,8 @@ class PageCustomize extends Page
if (getCurrentOption ("html_tag_filter") == 1) {
$html_tag_filter = "checked='checked'";
}
$content = "";
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
$content .= '<select id="style" onchange="updateCookie (this);">';
@ -791,26 +797,26 @@ class PageCustomize extends Page
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
$content .= '</select>';
}
array_push ($this->entryArray, new Entry (localize ("customize.style"), "",
$content, "text",
array_push ($this->entryArray, new Entry (localize ("customize.style"), "",
$content, "text",
array ()));
if (!useServerSideRendering ()) {
$content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $use_fancybox . ' />';
array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "",
$content, "text",
array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "",
$content, "text",
array ()));
}
$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]+$" />';
array_push ($this->entryArray, new Entry (localize ("customize.paging"), "",
$content, "text",
array_push ($this->entryArray, new Entry (localize ("customize.paging"), "",
$content, "text",
array ()));
$content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption ("email") . '" />';
array_push ($this->entryArray, new Entry (localize ("customize.email"), "",
$content, "text",
array_push ($this->entryArray, new Entry (localize ("customize.email"), "",
$content, "text",
array ()));
$content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $html_tag_filter . ' />';
array_push ($this->entryArray, new Entry (localize ("customize.filter"), "",
$content, "text",
array_push ($this->entryArray, new Entry (localize ("customize.filter"), "",
$content, "text",
array ()));
}
}
@ -836,13 +842,13 @@ abstract class Base
const PAGE_CUSTOM_DETAIL = "15";
const PAGE_ABOUT = "16";
const PAGE_ALL_LANGUAGES = "17";
const PAGE_LANGUAGE_DETAIL = "18";
const PAGE_CUSTOMIZE = "19";
const PAGE_LANGUAGE_DETAIL = "18";
const PAGE_CUSTOMIZE = "19";
const COMPATIBILITY_XML_ALDIKO = "aldiko";
private static $db = NULL;
public static function getDbList () {
global $config;
if (is_array ($config['calibre_directory'])) {
@ -872,11 +878,11 @@ abstract class Base
return $config['calibre_directory'];
}
public static function getDbFileName ($database = NULL) {
return self::getDbDirectory ($database) .'metadata.db';
}
public static function getDb ($database = NULL) {
global $config;
if (is_null (self::$db)) {
@ -889,27 +895,27 @@ abstract class Base
}
return self::$db;
}
public static function clearDb () {
self::$db = NULL;
}
public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL) {
global $config;
$totalResult = -1;
if (getCurrentOption ("max_item_per_page") != -1 && $n != -1)
{
// First check total number of results
$result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter));
$result->execute ($params);
$totalResult = $result->fetchColumn ();
// Next modify the query and params
$query .= " limit ?, ?";
array_push ($params, ($n - 1) * getCurrentOption ("max_item_per_page"), getCurrentOption ("max_item_per_page"));
}
$result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter));
$result->execute ($params);
return array ($totalResult, $result);

View file

@ -7,5 +7,5 @@
*/
require_once 'config_default.php';
if (file_exists('config_local.php'))
if (file_exists(dirname(__FILE__). '/config_local.php'))
require_once 'config_local.php';

View file

@ -3,7 +3,7 @@
* COPS (Calibre OPDS PHP Server) class file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
if (!isset($config))
@ -37,11 +37,26 @@
*/
$config['cops_recentbooks_limit'] = '50';
/*
* Catalog's author name
*/
$config['cops_author_name'] = "Sébastien Lucas";
/*
* Catalog's author uri
*/
$config['cops_author_uri'] = "http://blog.slucas.fr";
/*
* Catalog's author email
*/
$config['cops_author_email'] = "sebastien@slucas.fr";
/*
* Catalog's title
*/
$config['cops_title_default'] = "COPS";
/*
* Catalog's subtitle
*/
@ -212,4 +227,3 @@
* This item is used as regular expression so "." will force server side rendering for all devices
*/
$config['cops_server_side_render'] = "Kindle|EBRD1101|EBRD1201|cybook";

View file

@ -28,7 +28,7 @@ class BookExport
{
switch ($inExportType) {
case self::eExportTypeCsv:
$this->mExport = new CsvExport($inFileName);
$this->mExport = new CsvExport($inFileName, $inCreate);
break;
default:
$error = sprintf('Incorrect export type: %d', $inExportType);
@ -42,15 +42,24 @@ class BookExport
* @param string Epub file name
* @throws Exception if error
*
* @return void
* @return string Empty string or error if any
*/
public function AddEpub($inFileName)
{
// Load the book infos
$bookInfos = new BookInfos();
$bookInfos->LoadFromEpub($inFileName);
// Add the book
$this->AddBook($bookInfos);
$error = '';
try {
// Load the book infos
$bookInfos = new BookInfos();
$bookInfos->LoadFromEpub($inFileName);
// Add the book
$this->AddBook($bookInfos);
}
catch (Exception $e) {
$error = $e->getMessage();
}
return $error;
}
/**
@ -81,6 +90,10 @@ class BookExport
$this->mExport->SetProperty($i++, 'Isbn');
$this->mExport->SetProperty($i++, 'Rights');
$this->mExport->SetProperty($i++, 'Publisher');
$this->mExport->SetProperty($i++, 'Serie');
$this->mExport->SetProperty($i++, 'SerieIndex');
$this->mExport->SetProperty($i++, 'CreationDate');
$this->mExport->SetProperty($i++, 'ModificationDate');
$this->mExport->AddContent();
}
@ -101,6 +114,10 @@ class BookExport
$this->mExport->SetProperty($i++, $inBookInfo->mIsbn);
$this->mExport->SetProperty($i++, $inBookInfo->mRights);
$this->mExport->SetProperty($i++, $inBookInfo->mPublisher);
$this->mExport->SetProperty($i++, $inBookInfo->mSerie);
$this->mExport->SetProperty($i++, $inBookInfo->mSerieIndex);
$this->mExport->SetProperty($i++, $inBookInfo->mCreationDate);
$this->mExport->SetProperty($i++, $inBookInfo->mModificationDate);
$this->mExport->AddContent();
}

View file

@ -29,6 +29,10 @@ class BookInfos
public $mIsbn = '';
public $mRights = '';
public $mPublisher = '';
public $mSerie = '';
public $mSerieIndex = '';
public $mCreationDate = '';
public $mModificationDate = '';
/**
* Loads book infos from an epub file
@ -41,23 +45,28 @@ class BookInfos
public function LoadFromEpub($inFileName)
{
// Load the epub file
$epub = new EPub($inFileName, 'ZipFile');
$ePub = new EPub($inFileName, 'ZipFile');
// Get the epub infos
$this->mFormat = 'epub';
$this->mPath = pathinfo($inFileName, PATHINFO_DIRNAME);
$this->mName = pathinfo($inFileName, PATHINFO_FILENAME);
$this->mUuid = $epub->Uuid();
$this->mUri = $epub->Uri();
$this->mTitle = $epub->Title();
$this->mAuthors = $epub->Authors();
$this->mLanguage = $epub->Language();
$this->mDescription = $epub->Description();
$this->mSubjects = $epub->Subjects();
$this->mCover = $epub->getCoverItem();
$this->mIsbn = $epub->ISBN();
$this->mRights = $epub->Copyright();
$this->mPublisher = $epub->Publisher();
$this->mUuid = $ePub->Uuid();
$this->mUri = $ePub->Uri();
$this->mTitle = $ePub->Title();
$this->mAuthors = $ePub->Authors();
$this->mLanguage = $ePub->Language();
$this->mDescription = $ePub->Description();
$this->mSubjects = $ePub->Subjects();
$cover = $ePub->Cover();
$this->mCover = ($cover['found'] !== false) ? $cover['found'] : '';
$this->mIsbn = $ePub->ISBN();
$this->mRights = $ePub->Copyright();
$this->mPublisher = $ePub->Publisher();
$this->mSerie = $ePub->Serie();
$this->mSerieIndex = $ePub->SerieIndex();
$this->mCreationDate = $ePub->CreationDate();
$this->mModificationDate = $ePub->ModificationDate();
}
}

View file

@ -30,7 +30,7 @@ class CalibreDbLoader
*/
public function __construct($inDbFileName, $inCreate = false)
{
if ($inCreate || !file_exists($inDbFileName)) {
if ($inCreate) {
$this->CreateDatabase($inDbFileName);
}
else {
@ -51,7 +51,7 @@ class CalibreDbLoader
// Read the sql file
$content = file_get_contents(CalibreCreateDbSql);
if ($content === false) {
$error = sprintf('Cannot read sql file: %s', $inDbFileName);
$error = sprintf('Cannot read sql file: %s', CalibreCreateDbSql);
throw new Exception($error);
}
@ -120,15 +120,25 @@ class CalibreDbLoader
* @param string Epub file name
* @throws Exception if error
*
* @return void
* @return string Empty string or error if any
*/
public function AddEpub($inFileName)
{
// Load the book infos
$bookInfos = new BookInfos();
$bookInfos->LoadFromEpub($inFileName);
// Add the book
$this->AddBook($bookInfos);
$error = '';
try {
// Load the book infos
$bookInfos = new BookInfos();
$bookInfos->LoadFromEpub($inFileName);
// Add the book
$this->AddBook($bookInfos);
}
catch (Exception $e) {
$error = $e->getMessage();
}
return $error;
}
/**
@ -141,27 +151,35 @@ class CalibreDbLoader
*/
private function AddBook($inBookInfo)
{
$sql = 'insert into books(title, sort, uuid, path) values(:title, :sort, :uuid, :path)';
// Check if the book uuid does not already exist
$sql = 'select b.id, b.title, b.path, d.name, d.format from books as b, data as d where d.book = b.id and uuid=:uuid';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
$stmt->execute();
while ($post = $stmt->fetchObject()) {
$error = sprintf('Multiple book id for uuid: %s (already in file "%s/%s.%s" title "%s")', $inBookInfo->mUuid, $post->path, $post->name, $post->format, $post->title);
throw new Exception($error);
}
// Add the book
$sql = 'insert into books(title, sort, pubdate, last_modified, series_index, uuid, path) values(:title, :sort, :pubdate, :lastmodified, :serieindex, :uuid, :path)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':title', $inBookInfo->mTitle);
$stmt->bindParam(':sort', $inBookInfo->mTitle);
$stmt->bindParam(':pubdate', empty($inBookInfo->mCreationDate) ? null : $inBookInfo->mCreationDate);
$stmt->bindParam(':lastmodified', empty($inBookInfo->mModificationDate) ? '2000-01-01 00:00:00+00:00' : $inBookInfo->mModificationDate);
$stmt->bindParam(':serieindex', $inBookInfo->mSerieIndex);
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
$stmt->bindParam(':path', $inBookInfo->mPath);
$stmt->execute();
// Get the book id
$sql = 'select id, title from books where uuid=:uuid';
$sql = 'select id from books where uuid=:uuid';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
$stmt->execute();
$idBook = null;
while ($post = $stmt->fetchObject()) {
if (!isset($idBook)) {
$idBook = $post->id;
}
else {
$error = sprintf('Multiple book id for uuid: %s (already in title "%s")', $inBookInfo->mUuid, $post->title);
throw new Exception($error);
}
$idBook = $post->id;
break;
}
if (!isset($idBook)) {
$error = sprintf('Cannot find book id for uuid: %s', $inBookInfo->mUuid);
@ -174,17 +192,75 @@ class CalibreDbLoader
$stmt->bindParam(':format', $inBookInfo->mFormat);
$stmt->bindParam(':name', $inBookInfo->mName);
$stmt->execute();
// Add the book comments
$sql = 'insert into comments(book, text) values(:idBook, :text)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':text', $inBookInfo->mDescription);
$stmt->execute();
// Add the book identifiers
if (!empty($inBookInfo->mUri)) {
$sql = 'insert into identifiers(book, type, val) values(:idBook, :type, :value)';
$identifiers = array();
$identifiers['URI'] = $inBookInfo->mUri;
$identifiers['ISBN'] = $inBookInfo->mIsbn;
foreach ($identifiers as $key => $value) {
if (empty($value)) {
continue;
}
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':type', $key);
$stmt->bindParam(':value', $value);
$stmt->execute();
}
}
// Add the book serie
if (!empty($inBookInfo->mSerie)) {
// Get the serie id
$sql = 'select id from series where name=:serie';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':serie', $inBookInfo->mSerie);
$stmt->execute();
$post = $stmt->fetchObject();
if ($post) {
$idSerie = $post->id;
}
else {
// Add a new serie
$sql = 'insert into series(name, sort) values(:serie, :sort)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':serie', $inBookInfo->mSerie);
$stmt->bindParam(':sort', $inBookInfo->mSerie);
$stmt->execute();
// Get the serie id
$sql = 'select id from series where name=:serie';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':serie', $inBookInfo->mSerie);
$stmt->execute();
$idSerie = null;
while ($post = $stmt->fetchObject()) {
if (!isset($idSerie)) {
$idSerie = $post->id;
}
else {
$error = sprintf('Multiple series for name: %s', $inBookInfo->mSerie);
throw new Exception($error);
}
}
if (!isset($idSerie)) {
$error = sprintf('Cannot find serie id for name: %s', $inBookInfo->mSerie);
throw new Exception($error);
}
}
// Add the book serie link
$sql = 'insert into books_series_link(book, series) values(:idBook, :idSerie)';
$stmt = $this->mDb->prepare($sql);
$type = 'URI';
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':type', $type);
$stmt->bindParam(':value', $inBookInfo->mUri);
$stmt->bindParam(':idSerie', $idSerie, PDO::PARAM_INT);
$stmt->execute();
}
// Add the authors in the db
// Add the book authors
foreach ($inBookInfo->mAuthors as $authorSort => $author) {
// Get the author id
$sql = 'select id from authors where name=:author';
@ -221,13 +297,103 @@ class CalibreDbLoader
$error = sprintf('Cannot find author id for name: %s', $author);
throw new Exception($error);
}
// Add the book author link
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':idAuthor', $idAuthor, PDO::PARAM_INT);
$stmt->execute();
}
// Add the book author link
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':idAuthor', $idAuthor, PDO::PARAM_INT);
$stmt->execute();
}
// Add the book language
{
// Get the language id
$sql = 'select id from languages where lang_code=:language';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':language', $inBookInfo->mLanguage);
$stmt->execute();
$post = $stmt->fetchObject();
if ($post) {
$idLanguage = $post->id;
}
else {
// Add a new language
$sql = 'insert into languages(lang_code) values(:language)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':language', $inBookInfo->mLanguage);
$stmt->execute();
// Get the language id
$sql = 'select id from languages where lang_code=:language';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':language', $inBookInfo->mLanguage);
$stmt->execute();
$idLanguage = null;
while ($post = $stmt->fetchObject()) {
if (!isset($idLanguage)) {
$idLanguage = $post->id;
}
else {
$error = sprintf('Multiple languages for lang_code: %s', $inBookInfo->mLanguage);
throw new Exception($error);
}
}
if (!isset($idLanguage)) {
$error = sprintf('Cannot find language id for lang_code: %s', $inBookInfo->mLanguage);
throw new Exception($error);
}
}
// Add the book language link
$itemOder = 0;
$sql = 'insert into books_languages_link(book, lang_code, item_order) values(:idBook, :idLanguage, :itemOrder)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':idLanguage', $idLanguage, PDO::PARAM_INT);
$stmt->bindParam(':itemOrder', $itemOder, PDO::PARAM_INT);
$stmt->execute();
}
// Add the book tags (subjects)
foreach ($inBookInfo->mSubjects as $subject) {
// Get the subject id
$sql = 'select id from tags where name=:subject';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':subject', $subject);
$stmt->execute();
$post = $stmt->fetchObject();
if ($post) {
$idSubject = $post->id;
}
else {
// Add a new subject
$sql = 'insert into tags(name) values(:subject)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':subject', $subject);
$stmt->execute();
// Get the subject id
$sql = 'select id from tags where name=:subject';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':subject', $subject);
$stmt->execute();
$idSubject = null;
while ($post = $stmt->fetchObject()) {
if (!isset($idSubject)) {
$idSubject = $post->id;
}
else {
$error = sprintf('Multiple subjects for name: %s', $subject);
throw new Exception($error);
}
}
if (!isset($idSubject)) {
$error = sprintf('Cannot find subject id for name: %s', $subject);
throw new Exception($error);
}
}
// Add the book subject link
$sql = 'insert into books_tags_link(book, tag) values(:idBook, :idSubject)';
$stmt = $this->mDb->prepare($sql);
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
$stmt->bindParam(':idSubject', $idSubject, PDO::PARAM_INT);
$stmt->execute();
}
}

View file

@ -20,7 +20,7 @@ class CsvExport extends BaseExport
* @param string Export file name
* @param boolean Force file creation
*/
public function __construct($inFileName)
public function __construct($inFileName, $inCreate = false)
{
$this->mSearch = array("\r", "\n", self::CsvSeparator);
$this->mReplace = array('', '<br />', '');
@ -28,7 +28,7 @@ class CsvExport extends BaseExport
// Init container
$this->mLines = array();
parent::__construct($inFileName);
parent::__construct($inFileName, $inCreate);
}
/**

View file

@ -0,0 +1,17 @@
## =============================================================================
## epub-loader readme
## =============================================================================
epub-loader is a utility ressource for ebooks.
- CalibreDbLoader class allows create Calibre databases and add ebooks
- BookExport class allows to export ebooks metadata in csv files
- The app directory contains samples and allows to run actions
## Installation
## -----------------------------------------------------------------------------
- If a first-time install, copy app/config.php.example to app/config.php
- Edit config.php to match your config
- Open the app directory url

1
resources/epub-loader/app/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
epub-loader-config.php

View file

@ -0,0 +1,31 @@
<?php
/**
* Epub loader application action: export ebooks info in a csv files
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
// Init csv file
$fileName = $dbConfig['db_path'] . DIRECTORY_SEPARATOR . basename($dbConfig['db_path']) . '_metadata.csv';
try {
// Open or create the export file
$export = new BookExport($fileName, BookExport::eExportTypeCsv, true);
echo sprintf('Export ebooks to %s', $fileName) . '<br />';
// Add the epub files into the export file
if (!empty($dbConfig['epub_path'])) {
$fileList = RecursiveGlob($dbConfig['epub_path'], '*.epub');
foreach ($fileList as $file) {
$error = $export->AddEpub($file);
if (!empty($error)) {
$gErrorArray[$file] = $error;
}
}
}
$export->SaveToFile();
}
catch (Exception $e) {
$gErrorArray[$fileName] = $e->getMessage();
}
?>

View file

@ -0,0 +1,30 @@
<?php
/**
* Epub loader application action: load ebooks into calibre databases
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
// Init database file
$fileName = $dbConfig['db_path'] . DIRECTORY_SEPARATOR . 'metadata.db';
try {
// Open or create the database
$db = new CalibreDbLoader($fileName, $gConfig['create_db']);
echo sprintf('Load database %s', $fileName) . '<br />';
// Add the epub files into the database
if (!empty($dbConfig['epub_path'])) {
$fileList = RecursiveGlob($dbConfig['epub_path'], '*.epub');
foreach ($fileList as $file) {
$error = $db->AddEpub($file);
if (!empty($error)) {
$gErrorArray[$file] = $error;
}
}
}
}
catch (Exception $e) {
$gErrorArray[$fileName] = $e->getMessage();
}
?>

View file

@ -0,0 +1,27 @@
<?php
/**
* Epub loader application: COPS feed loader
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
// Include config file
$fileName = __DIR__ . DIRECTORY_SEPARATOR . 'epub-loader-config.php';
if (!file_exists($fileName)) {
die ('Missing configuration file: ' . $fileName);
}
require_once($fileName);
// Add cops directory to include path
$includePath = ini_get('include_path');
ini_set('include_path', $includePath . PATH_SEPARATOR . $gConfig['cops_directory']);
// Include COPS feed
$fileName = $gConfig['cops_directory'] . '/feed.php';
if (!file_exists($fileName)) {
die ('Incorrect include file: ' . $fileName);
}
require_once($fileName);
?>

View file

@ -0,0 +1,60 @@
<?php
/**
* Epub loader application config
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
$gConfig = array();
/**
* Application name
*/
$gConfig['app_name'] = 'Epub loader';
/**
* Admin email
*/
$gConfig['admin_email'] = 'didier.corbiere@opale-concept.com';
/**
* Cops directory
*
* This is the base path of Cops library
*/
$gConfig['cops_directory'] = dirname(dirname(dirname(__DIR__)));
if (!is_dir($gConfig['cops_directory'])) {
die ('Incorrect Cops directory: ' . $gConfig['cops_directory']);
}
/**
* Create Calibre databases ?
*
* If true: databases are removed and recreated before loading ebooks
* If false: append ebooks into databases
*/
$gConfig['create_db'] = true;
/**
* Databases infos
*
* For each database:
* name: The database name to display
* db_path: The path where to create the database
* epub_path: The path where to look for the epub files to load
* pdf_path: The path where to look for pdf files
*/
$gConfig['databases'] = array();
$gConfig['databases'][] = array('name' => 'Littérature classique', 'db_path' => '/opt/ebooks/calibre/demo', 'epub_path' => '/opt/ebooks/epub/demo', 'pdf_path' => '');
$gConfig['databases'][] = array('name' => 'Bibliothèque numérique romande', 'db_path' => '/opt/ebooks/calibre/bnr', 'epub_path' => '/opt/ebooks/epub/bnr', 'pdf_path' => '');
$gConfig['databases'][] = array('name' => 'La Bibliothèque d\'Ebooks', 'db_path' => '/opt/ebooks/calibre/bibebook', 'epub_path' => '/opt/ebooks/epub/bibebook', 'pdf_path' => '');
/**
* Available actions
*/
$gConfig['actions'] = array();
$gConfig['actions']['csv_export'] = 'Csv export';
$gConfig['actions']['db_load'] = 'Create database';
?>

View file

@ -0,0 +1,47 @@
</div>
<!-- Content end -->
<?php
if (count($gErrorArray)) {
$str = '';
$str .= ' <!-- Error begin -->' . "\n";
$str .= ' <div class="error">' . "\n";
$title = 'Errors (' . count($gErrorArray) . ')';
$str .= ' <table width="100%">' . "\n";
$str .= ' <tr>' . "\n";
$str .= ' <th colspan="2">' . $title . '</th>' . "\n";
$str .= ' </tr>' . "\n";
foreach ($gErrorArray as $fileName => $error) {
// Display error
$str .= ' <tr>' . "\n";
$str .= ' <td class="col_1">' . $fileName . '</td>' . "\n";
$str .= ' <td class="col_2">' . $error . '</td>' . "\n";
$str .= ' </tr>' . "\n";
}
$str .= ' </table>' . "\n";
$str .= ' </div>' . "\n";
$str .= ' <!-- Error end -->' . "\n";
echo $str;
}
?>
</div>
<!-- Footer begin -->
<div class="footer">
<?php
if (!empty($gConfig['admin_email'])) {
?>
<script type="text/javascript">
/*<![CDATA[*/
document.write("<n uers=\"znvygb:<?php echo str_rot13($gConfig['admin_email']); ?>\">".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
document.write("Contact<\/a>");
/*]]>*/
</script>
<?php
}
?>
</div>
<!-- Footer end -->
</body>
</html>

View file

@ -0,0 +1,88 @@
<?php
header('Content-type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $gConfig['app_name']; ?></title>
<meta name="author" content="opale-concept.com" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
body {
font-family: "Times New Roman", Times, serif;
background-color: #ffffff;
color: #333333;
margin: 20px;
}
a {
color: #096DD1;
text-decoration: none;
}
a:hover {
color: #DF7800;
}
a:focus {
color: #6E749F !important;
}
ul, li {
margin: 0;
}
.header {
color: #6E749F;
font-style: bold;
font-size: 120%;
padding-bottom: 10px;
border-bottom: solid #2F4769 1px;
margin-bottom: 15px;
}
.part {
border-top: solid #2F4769 1px;
padding: 10px;
}
.title {
padding-bottom: 5px;
font-weight: bold;
}
table {
border-collapse: collapse;
border-color: #ccc;
}
table th {
text-align: left;
}
table td, table th {
padding-left: 5px;
padding-right: 5px;
}
td.col_1, th.col_1 {
width: 50%;
}
td.col_2, th.col_2 {
width: 50%;
}
.error {
color: #750000;
margin-top: 15px;
}
.footer {
border-top: solid #2F4769 1px;
margin-top: 15px;
padding-top: 10px;
font-size: 80%;
font-style: italic;
}
/*]]>*/
</style>
</head>
<body>
<!-- Header begin -->
<div class="header">
<a href="."><?php echo $gConfig['app_name']; ?></a>
</div>
<!-- Header end -->
<!-- Content begin -->
<div class="content">

View file

@ -0,0 +1,151 @@
<?php
/**
* Epub loader application
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
//------------------------------------------------------------------------------
// Include files
//------------------------------------------------------------------------------
// Include config file
$fileName = __DIR__ . DIRECTORY_SEPARATOR . 'epub-loader-config.php';
if (!file_exists($fileName)) {
die ('Missing configuration file: ' . $fileName);
}
require_once($fileName);
// Include Calibre database loader class
$fileName = $gConfig['cops_directory'] . '/resources/epub-loader/CalibreDbLoader.class.php';
if (!file_exists($fileName)) {
die ('Incorrect include file: ' . $fileName);
}
require_once($fileName);
// Include book export class
$fileName = $gConfig['cops_directory'] . '/resources/epub-loader/BookExport.class.php';
if (!file_exists($fileName)) {
die ('Incorrect include file: ' . $fileName);
}
require_once($fileName);
//------------------------------------------------------------------------------
// Start application
//------------------------------------------------------------------------------
// Global vars
$gErrorArray = array();
// Get the url parameters
$action = isset($_GET['action']) ? $_GET['action'] : null;
$dbNum = isset($_GET['dbnum']) ? (int)$_GET['dbnum'] : null;
// Include html header
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'header.php');
/**
* Recursive get files
*
* @param string Base directory to search in
* @param string Search pattern
*/
function RecursiveGlob($inPath = '', $inPattern = '*')
{
$res = array();
// Check path
if (!is_dir($inPath)) {
return $res;
}
// Get the list of directories
if (substr($inPath, -1) != DIRECTORY_SEPARATOR) {
$inPath .= DIRECTORY_SEPARATOR;
}
// Add files from the current directory
$files = glob($inPath . $inPattern, GLOB_MARK | GLOB_NOSORT);
foreach ($files as $item) {
if (substr($item, -1) == DIRECTORY_SEPARATOR) {
continue;
}
$res[] = $item;
}
// Scan sub directories
$paths = glob($inPath . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
foreach ($paths as $path) {
$res = array_merge($res, RecursiveGlob($path, $inPattern));
}
return $res;
}
// Html content
if (isset($action) && isset($dbNum)) {
if (!isset($gConfig['databases'][$dbNum])) {
die ('Incorrect database num: ' . $dbNum);
}
$dbConfig = $gConfig['databases'][$dbNum];
$dbPath = $dbConfig['db_path'];
if (!is_dir($dbPath)) {
if (!mkdir($dbPath, 0755, true)) {
die ('Cannot create directory: ' . $dbPath);
}
}
$fileName = sprintf('%s%saction_%s.php', __DIR__, DIRECTORY_SEPARATOR, $action);
if (!file_exists($fileName)) {
die ('Incorrect action file: ' . $fileName);
}
require_once($fileName);
}
else {
if (!isset($action)) {
// Display the available actions
$str = '';
$str .= '<div><b>' . 'Select action' . '</b></div>' . "\n";
$str .= ' <ul>' . "\n";
foreach ($gConfig['actions'] as $action => $actionInfo) {
$str .= ' <li>' . "\n";
$str .= ' <a href="./index.php?action=' . $action . '">' . $actionInfo . '</a>' . "\n";
$str .= ' </li>' . "\n";
}
$str .= ' </ul>' . "\n";
echo $str;
}
else {
// Display databases
$str = '';
$str .= '<table width="100%">' . "\n";
$str .= '<tr>' . "\n";
$str .= '<th>' . 'Db num' . '</th>' . "\n";
$str .= '<th>' . 'Db name' . '</th>' . "\n";
$str .= '<th>' . 'Action' . '</th>' . "\n";
$str .= '<th>' . 'Db Path' . '</th>' . "\n";
$str .= '<th>' . 'Epub path' . '</th>' . "\n";
$str .= '<th>' . 'Nb Files' . '</th>' . "\n";
$str .= '</tr>' . "\n";
$actionTitle = $gConfig['actions'][$action];
foreach ($gConfig['databases'] as $dbNum => $dbConfig) {
$fileList = RecursiveGlob($dbConfig['epub_path'], '*.epub');
$str .= '<tr>' . "\n";
$str .= '<td>' . $dbNum . '</td>' . "\n";
$str .= '<td>' . $dbConfig['name'] . '</td>' . "\n";
$str .= '<td>' . '<a href="./index.php?action=' . $action . '&dbnum=' . $dbNum . '">' . $actionTitle . '</a>' . '</td>' . "\n";
$str .= '<td>' . $dbConfig['db_path'] . '</td>' . "\n";
$str .= '<td>' . $dbConfig['epub_path'] . '</td>' . "\n";
$str .= '<td>' . count($fileList) . '</td>' . "\n";
$str .= '</tr>' . "\n";
$numWork++;
}
$str .= '</table>' . "\n";
echo $str;
}
}
// Include html footer
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'footer.php');
?>

View file

@ -322,6 +322,30 @@ class EPub {
return $res;
}
/**
* Set or get the book's creation date
*
* @param string Date eg: 2012-05-19T12:54:25Z
*/
public function CreationDate($date = false)
{
$res = $this->getset('dc:date', $date, 'opf:event', 'creation');
return $res;
}
/**
* Set or get the book's modification date
*
* @param string Date eg: 2012-05-19T12:54:25Z
*/
public function ModificationDate($date = false)
{
$res = $this->getset('dc:date', $date, 'opf:event', 'modification');
return $res;
}
/**
* Set or get the book's URI
*