Merge pull request #95 from Marsender/master
Add an application to run actions
This commit is contained in:
commit
938843596a
|
@ -113,13 +113,13 @@ class OPDSRenderer
|
||||||
self::getXmlStream ()->endElement ();
|
self::getXmlStream ()->endElement ();
|
||||||
self::getXmlStream ()->startElement ("author");
|
self::getXmlStream ()->startElement ("author");
|
||||||
self::getXmlStream ()->startElement ("name");
|
self::getXmlStream ()->startElement ("name");
|
||||||
self::getXmlStream ()->text (utf8_encode ("Sébastien Lucas"));
|
self::getXmlStream ()->text ($page->authorName);
|
||||||
self::getXmlStream ()->endElement ();
|
self::getXmlStream ()->endElement ();
|
||||||
self::getXmlStream ()->startElement ("uri");
|
self::getXmlStream ()->startElement ("uri");
|
||||||
self::getXmlStream ()->text ("http://blog.slucas.fr");
|
self::getXmlStream ()->text ($page->authorUri);
|
||||||
self::getXmlStream ()->endElement ();
|
self::getXmlStream ()->endElement ();
|
||||||
self::getXmlStream ()->startElement ("email");
|
self::getXmlStream ()->startElement ("email");
|
||||||
self::getXmlStream ()->text ("sebastien@slucas.fr");
|
self::getXmlStream ()->text ($page->authorEmail);
|
||||||
self::getXmlStream ()->endElement ();
|
self::getXmlStream ()->endElement ();
|
||||||
self::getXmlStream ()->endElement ();
|
self::getXmlStream ()->endElement ();
|
||||||
$link = new LinkNavigation ("", "start", "Home");
|
$link = new LinkNavigation ("", "start", "Home");
|
||||||
|
|
6
base.php
6
base.php
|
@ -360,6 +360,9 @@ class Page
|
||||||
{
|
{
|
||||||
public $title;
|
public $title;
|
||||||
public $subtitle = "";
|
public $subtitle = "";
|
||||||
|
public $authorName = "";
|
||||||
|
public $authorUri = "";
|
||||||
|
public $authorEmail = "";
|
||||||
public $idPage;
|
public $idPage;
|
||||||
public $idGet;
|
public $idGet;
|
||||||
public $query;
|
public $query;
|
||||||
|
@ -422,6 +425,9 @@ class Page
|
||||||
$this->query = $pquery;
|
$this->query = $pquery;
|
||||||
$this->n = $pn;
|
$this->n = $pn;
|
||||||
$this->favicon = $config['cops_icon'];
|
$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 ()
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'config_default.php';
|
require_once 'config_default.php';
|
||||||
if (file_exists('config_local.php'))
|
if (file_exists(dirname(__FILE__). '/config_local.php'))
|
||||||
require_once 'config_local.php';
|
require_once 'config_local.php';
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* COPS (Calibre OPDS PHP Server) class file
|
* COPS (Calibre OPDS PHP Server) class file
|
||||||
*
|
*
|
||||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
* @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))
|
if (!isset($config))
|
||||||
|
@ -37,6 +37,21 @@
|
||||||
*/
|
*/
|
||||||
$config['cops_recentbooks_limit'] = '50';
|
$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
|
* Catalog's title
|
||||||
*/
|
*/
|
||||||
|
@ -212,4 +227,3 @@
|
||||||
* This item is used as regular expression so "." will force server side rendering for all devices
|
* 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";
|
$config['cops_server_side_render'] = "Kindle|EBRD1101|EBRD1201|cybook";
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class BookExport
|
||||||
{
|
{
|
||||||
switch ($inExportType) {
|
switch ($inExportType) {
|
||||||
case self::eExportTypeCsv:
|
case self::eExportTypeCsv:
|
||||||
$this->mExport = new CsvExport($inFileName);
|
$this->mExport = new CsvExport($inFileName, $inCreate);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$error = sprintf('Incorrect export type: %d', $inExportType);
|
$error = sprintf('Incorrect export type: %d', $inExportType);
|
||||||
|
@ -42,16 +42,25 @@ class BookExport
|
||||||
* @param string Epub file name
|
* @param string Epub file name
|
||||||
* @throws Exception if error
|
* @throws Exception if error
|
||||||
*
|
*
|
||||||
* @return void
|
* @return string Empty string or error if any
|
||||||
*/
|
*/
|
||||||
public function AddEpub($inFileName)
|
public function AddEpub($inFileName)
|
||||||
{
|
{
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
try {
|
||||||
// Load the book infos
|
// Load the book infos
|
||||||
$bookInfos = new BookInfos();
|
$bookInfos = new BookInfos();
|
||||||
$bookInfos->LoadFromEpub($inFileName);
|
$bookInfos->LoadFromEpub($inFileName);
|
||||||
// Add the book
|
// Add the book
|
||||||
$this->AddBook($bookInfos);
|
$this->AddBook($bookInfos);
|
||||||
}
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$error = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new book to the export
|
* Add a new book to the export
|
||||||
|
@ -81,6 +90,10 @@ class BookExport
|
||||||
$this->mExport->SetProperty($i++, 'Isbn');
|
$this->mExport->SetProperty($i++, 'Isbn');
|
||||||
$this->mExport->SetProperty($i++, 'Rights');
|
$this->mExport->SetProperty($i++, 'Rights');
|
||||||
$this->mExport->SetProperty($i++, 'Publisher');
|
$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();
|
$this->mExport->AddContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +114,10 @@ class BookExport
|
||||||
$this->mExport->SetProperty($i++, $inBookInfo->mIsbn);
|
$this->mExport->SetProperty($i++, $inBookInfo->mIsbn);
|
||||||
$this->mExport->SetProperty($i++, $inBookInfo->mRights);
|
$this->mExport->SetProperty($i++, $inBookInfo->mRights);
|
||||||
$this->mExport->SetProperty($i++, $inBookInfo->mPublisher);
|
$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();
|
$this->mExport->AddContent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,10 @@ class BookInfos
|
||||||
public $mIsbn = '';
|
public $mIsbn = '';
|
||||||
public $mRights = '';
|
public $mRights = '';
|
||||||
public $mPublisher = '';
|
public $mPublisher = '';
|
||||||
|
public $mSerie = '';
|
||||||
|
public $mSerieIndex = '';
|
||||||
|
public $mCreationDate = '';
|
||||||
|
public $mModificationDate = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads book infos from an epub file
|
* Loads book infos from an epub file
|
||||||
|
@ -41,23 +45,28 @@ class BookInfos
|
||||||
public function LoadFromEpub($inFileName)
|
public function LoadFromEpub($inFileName)
|
||||||
{
|
{
|
||||||
// Load the epub file
|
// Load the epub file
|
||||||
$epub = new EPub($inFileName, 'ZipFile');
|
$ePub = new EPub($inFileName, 'ZipFile');
|
||||||
|
|
||||||
// Get the epub infos
|
// Get the epub infos
|
||||||
$this->mFormat = 'epub';
|
$this->mFormat = 'epub';
|
||||||
$this->mPath = pathinfo($inFileName, PATHINFO_DIRNAME);
|
$this->mPath = pathinfo($inFileName, PATHINFO_DIRNAME);
|
||||||
$this->mName = pathinfo($inFileName, PATHINFO_FILENAME);
|
$this->mName = pathinfo($inFileName, PATHINFO_FILENAME);
|
||||||
$this->mUuid = $epub->Uuid();
|
$this->mUuid = $ePub->Uuid();
|
||||||
$this->mUri = $epub->Uri();
|
$this->mUri = $ePub->Uri();
|
||||||
$this->mTitle = $epub->Title();
|
$this->mTitle = $ePub->Title();
|
||||||
$this->mAuthors = $epub->Authors();
|
$this->mAuthors = $ePub->Authors();
|
||||||
$this->mLanguage = $epub->Language();
|
$this->mLanguage = $ePub->Language();
|
||||||
$this->mDescription = $epub->Description();
|
$this->mDescription = $ePub->Description();
|
||||||
$this->mSubjects = $epub->Subjects();
|
$this->mSubjects = $ePub->Subjects();
|
||||||
$this->mCover = $epub->getCoverItem();
|
$cover = $ePub->Cover();
|
||||||
$this->mIsbn = $epub->ISBN();
|
$this->mCover = ($cover['found'] !== false) ? $cover['found'] : '';
|
||||||
$this->mRights = $epub->Copyright();
|
$this->mIsbn = $ePub->ISBN();
|
||||||
$this->mPublisher = $epub->Publisher();
|
$this->mRights = $ePub->Copyright();
|
||||||
|
$this->mPublisher = $ePub->Publisher();
|
||||||
|
$this->mSerie = $ePub->Serie();
|
||||||
|
$this->mSerieIndex = $ePub->SerieIndex();
|
||||||
|
$this->mCreationDate = $ePub->CreationDate();
|
||||||
|
$this->mModificationDate = $ePub->ModificationDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class CalibreDbLoader
|
||||||
*/
|
*/
|
||||||
public function __construct($inDbFileName, $inCreate = false)
|
public function __construct($inDbFileName, $inCreate = false)
|
||||||
{
|
{
|
||||||
if ($inCreate || !file_exists($inDbFileName)) {
|
if ($inCreate) {
|
||||||
$this->CreateDatabase($inDbFileName);
|
$this->CreateDatabase($inDbFileName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -51,7 +51,7 @@ class CalibreDbLoader
|
||||||
// Read the sql file
|
// Read the sql file
|
||||||
$content = file_get_contents(CalibreCreateDbSql);
|
$content = file_get_contents(CalibreCreateDbSql);
|
||||||
if ($content === false) {
|
if ($content === false) {
|
||||||
$error = sprintf('Cannot read sql file: %s', $inDbFileName);
|
$error = sprintf('Cannot read sql file: %s', CalibreCreateDbSql);
|
||||||
throw new Exception($error);
|
throw new Exception($error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,16 +120,26 @@ class CalibreDbLoader
|
||||||
* @param string Epub file name
|
* @param string Epub file name
|
||||||
* @throws Exception if error
|
* @throws Exception if error
|
||||||
*
|
*
|
||||||
* @return void
|
* @return string Empty string or error if any
|
||||||
*/
|
*/
|
||||||
public function AddEpub($inFileName)
|
public function AddEpub($inFileName)
|
||||||
{
|
{
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
try {
|
||||||
// Load the book infos
|
// Load the book infos
|
||||||
$bookInfos = new BookInfos();
|
$bookInfos = new BookInfos();
|
||||||
$bookInfos->LoadFromEpub($inFileName);
|
$bookInfos->LoadFromEpub($inFileName);
|
||||||
// Add the book
|
// Add the book
|
||||||
$this->AddBook($bookInfos);
|
$this->AddBook($bookInfos);
|
||||||
}
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$error = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $error;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new book into the db
|
* Add a new book into the db
|
||||||
|
@ -141,27 +151,35 @@ class CalibreDbLoader
|
||||||
*/
|
*/
|
||||||
private function AddBook($inBookInfo)
|
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 = $this->mDb->prepare($sql);
|
||||||
$stmt->bindParam(':title', $inBookInfo->mTitle);
|
$stmt->bindParam(':title', $inBookInfo->mTitle);
|
||||||
$stmt->bindParam(':sort', $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(':uuid', $inBookInfo->mUuid);
|
||||||
$stmt->bindParam(':path', $inBookInfo->mPath);
|
$stmt->bindParam(':path', $inBookInfo->mPath);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
// Get the book id
|
// 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 = $this->mDb->prepare($sql);
|
||||||
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
|
$stmt->bindParam(':uuid', $inBookInfo->mUuid);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$idBook = null;
|
$idBook = null;
|
||||||
while ($post = $stmt->fetchObject()) {
|
while ($post = $stmt->fetchObject()) {
|
||||||
if (!isset($idBook)) {
|
|
||||||
$idBook = $post->id;
|
$idBook = $post->id;
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
$error = sprintf('Multiple book id for uuid: %s (already in title "%s")', $inBookInfo->mUuid, $post->title);
|
|
||||||
throw new Exception($error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!isset($idBook)) {
|
if (!isset($idBook)) {
|
||||||
$error = sprintf('Cannot find book id for uuid: %s', $inBookInfo->mUuid);
|
$error = sprintf('Cannot find book id for uuid: %s', $inBookInfo->mUuid);
|
||||||
|
@ -174,17 +192,75 @@ class CalibreDbLoader
|
||||||
$stmt->bindParam(':format', $inBookInfo->mFormat);
|
$stmt->bindParam(':format', $inBookInfo->mFormat);
|
||||||
$stmt->bindParam(':name', $inBookInfo->mName);
|
$stmt->bindParam(':name', $inBookInfo->mName);
|
||||||
$stmt->execute();
|
$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
|
// Add the book identifiers
|
||||||
if (!empty($inBookInfo->mUri)) {
|
if (!empty($inBookInfo->mUri)) {
|
||||||
$sql = 'insert into identifiers(book, type, val) values(:idBook, :type, :value)';
|
$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 = $this->mDb->prepare($sql);
|
||||||
$type = 'URI';
|
|
||||||
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
|
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
|
||||||
$stmt->bindParam(':type', $type);
|
$stmt->bindParam(':type', $key);
|
||||||
$stmt->bindParam(':value', $inBookInfo->mUri);
|
$stmt->bindParam(':value', $value);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
// Add the authors in the db
|
}
|
||||||
|
// 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);
|
||||||
|
$stmt->bindParam(':idBook', $idBook, PDO::PARAM_INT);
|
||||||
|
$stmt->bindParam(':idSerie', $idSerie, PDO::PARAM_INT);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
// Add the book authors
|
||||||
foreach ($inBookInfo->mAuthors as $authorSort => $author) {
|
foreach ($inBookInfo->mAuthors as $authorSort => $author) {
|
||||||
// Get the author id
|
// Get the author id
|
||||||
$sql = 'select id from authors where name=:author';
|
$sql = 'select id from authors where name=:author';
|
||||||
|
@ -221,6 +297,7 @@ class CalibreDbLoader
|
||||||
$error = sprintf('Cannot find author id for name: %s', $author);
|
$error = sprintf('Cannot find author id for name: %s', $author);
|
||||||
throw new Exception($error);
|
throw new Exception($error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Add the book author link
|
// Add the book author link
|
||||||
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
|
$sql = 'insert into books_authors_link(book, author) values(:idBook, :idAuthor)';
|
||||||
$stmt = $this->mDb->prepare($sql);
|
$stmt = $this->mDb->prepare($sql);
|
||||||
|
@ -228,6 +305,95 @@ class CalibreDbLoader
|
||||||
$stmt->bindParam(':idAuthor', $idAuthor, PDO::PARAM_INT);
|
$stmt->bindParam(':idAuthor', $idAuthor, PDO::PARAM_INT);
|
||||||
$stmt->execute();
|
$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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class CsvExport extends BaseExport
|
||||||
* @param string Export file name
|
* @param string Export file name
|
||||||
* @param boolean Force file creation
|
* @param boolean Force file creation
|
||||||
*/
|
*/
|
||||||
public function __construct($inFileName)
|
public function __construct($inFileName, $inCreate = false)
|
||||||
{
|
{
|
||||||
$this->mSearch = array("\r", "\n", self::CsvSeparator);
|
$this->mSearch = array("\r", "\n", self::CsvSeparator);
|
||||||
$this->mReplace = array('', '<br />', '');
|
$this->mReplace = array('', '<br />', '');
|
||||||
|
@ -28,7 +28,7 @@ class CsvExport extends BaseExport
|
||||||
// Init container
|
// Init container
|
||||||
$this->mLines = array();
|
$this->mLines = array();
|
||||||
|
|
||||||
parent::__construct($inFileName);
|
parent::__construct($inFileName, $inCreate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
17
resources/epub-loader/README
Normal file
17
resources/epub-loader/README
Normal 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
1
resources/epub-loader/app/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
epub-loader-config.php
|
31
resources/epub-loader/app/action_csv_export.php
Normal file
31
resources/epub-loader/app/action_csv_export.php
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
30
resources/epub-loader/app/action_db_load.php
Normal file
30
resources/epub-loader/app/action_db_load.php
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
27
resources/epub-loader/app/cops-feed.php
Normal file
27
resources/epub-loader/app/cops-feed.php
Normal 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);
|
||||||
|
|
||||||
|
?>
|
60
resources/epub-loader/app/epub-loader-config.php.example
Normal file
60
resources/epub-loader/app/epub-loader-config.php.example
Normal 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';
|
||||||
|
|
||||||
|
?>
|
47
resources/epub-loader/app/footer.php
Normal file
47
resources/epub-loader/app/footer.php
Normal 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>
|
88
resources/epub-loader/app/header.php
Normal file
88
resources/epub-loader/app/header.php
Normal 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">
|
151
resources/epub-loader/app/index.php
Normal file
151
resources/epub-loader/app/index.php
Normal 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');
|
||||||
|
|
||||||
|
?>
|
|
@ -322,6 +322,30 @@ class EPub {
|
||||||
return $res;
|
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
|
* Set or get the book's URI
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue