Add basic application in order to perform the tasks

This commit is contained in:
Didier Corbière 2013-09-25 02:03:52 +01:00
부모 46d993d168
커밋 8d5109d7de
9개의 변경된 파일295개의 추가작업 그리고 5개의 파일을 삭제

파일 보기

@ -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);

파일 보기

@ -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);
}

파일 보기

@ -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);
}
/**

파일 보기

@ -0,0 +1,30 @@
<?php
/**
* Epub loader 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>
*/
foreach ($gConfig['databases'] as $dbConfig) {
// 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 = glob($dbConfig['epub_path'] . DIRECTORY_SEPARATOR . '*.epub');
foreach ($fileList as $fileName) {
$export->AddEpub($fileName);
}
}
$export->SaveToFile();
}
catch (Exception $e) {
$gErrorArray[$fileName] = $e->getMessage();
}
}
?>

파일 보기

@ -0,0 +1,29 @@
<?php
/**
* Epub loader 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>
*/
foreach ($gConfig['databases'] as $dbConfig) {
// 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 = glob($dbConfig['epub_path'] . DIRECTORY_SEPARATOR . '*.epub');
foreach ($fileList as $fileName) {
$db->AddEpub($fileName);
}
}
}
catch (Exception $e) {
$gErrorArray[$fileName] = $e->getMessage();
}
}
?>

파일 보기

@ -0,0 +1,45 @@
<?php
/**
* Epub loader config
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
$gConfig = array();
/**
* Cops directory
*
* This is the base path of Cops library
*/
$gConfig['cops_directory'] = dirname(dirname(dirname(__DIR__)));
/**
* 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
*/
$gConfig['databases'] = array();
$gConfig['databases'][] = array('name' => 'Littérature classique', 'db_path' => '/opt/atoll/opds/demo', 'epub_path' => '/opt/atoll/external/demo');
$gConfig['databases'][] = array('name' => 'Bibliothèque numérique romande', 'db_path' => '/opt/atoll/opds/bnr', 'epub_path' => '/opt/atoll/external/bnr');
$gConfig['databases'][] = array('name' => 'La Bibliothèque d\'Ebooks', 'db_path' => '/opt/atoll/opds/bibebook', 'epub_path' => '/opt/atoll/external/bibebook');
$gConfig['databases'][] = array('name' => 'La Bibliothèque électronique du Québec', 'db_path' => '/opt/atoll/opds/beq', 'epub_path' => '/opt/atoll/external/beq');
/**
* Available actions
*/
$gConfig['actions'] = array();
$gConfig['actions']['cvs_export'] = 'Cvs export';
$gConfig['actions']['db_load'] = 'Calibre database load';

파일 보기

@ -0,0 +1,41 @@
</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">
<script type="text/javascript">
/*<![CDATA[*/
document.write("<n uers=\"znvygb:<?php echo str_rot13(DEF_AppAdminMail); ?>\">".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>
</div>
<!-- Footer end -->
</body>
</html>

파일 보기

@ -0,0 +1,89 @@
<?php
// Spécifie l'encodage
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 DEF_AppName; ?></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: #2F4769;
margin: 20px;
}
a {
color: #CC9966;
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: 5px;
font-size: 80%;
font-style: italic;
}
/*]]>*/
</style>
</head>
<body>
<!-- Header begin -->
<div class="header">
<?php echo ' <a href=".">' . DEF_AppName . '</a>' . "\n"; ?>
</div>
<!-- Header end -->
<!-- Content begin -->
<div class="content">

파일 보기

@ -0,0 +1,56 @@
<?php
/**
* Epub loader application
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
//------------------------------------------------------------------------------
// Global defines
//------------------------------------------------------------------------------
// Application version
define('DEF_AppVersion', '1.0');
// Application name
define('DEF_AppName', 'epub loader');
// Admin email
define('DEF_AppAdminMail', 'didier.corbiere@opale-concept.com');
//------------------------------------------------------------------------------
// Include files
//------------------------------------------------------------------------------
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'config.php');
require_once($gConfig['cops_directory'] . '/resources/epub-loader/CalibreDbLoader.class.php');
require_once($gConfig['cops_directory'] . '/resources/epub-loader/BookExport.class.php');
//------------------------------------------------------------------------------
// Start application
//------------------------------------------------------------------------------
// Global vars
$gErrorArray = array();
// Get the action to execute
$action = isset($_GET['action']) ? $_GET['action'] : null;
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'header.php');
if (isset($action)) {
$phpFile = sprintf('%s%saction_%s.php', realpath(dirname(__FILE__)), DIRECTORY_SEPARATOR, $action);
require_once($phpFile);
}
else {
// Display the available actions
echo ' <ul>' . "\n";
foreach ($gConfig['actions'] as $action => $actionInfo) {
echo ' <li>' . "\n";
echo ' <a href="./index.php?action=' . $action . '">' . $actionInfo . '</a>' . "\n";
echo ' </li>' . "\n";
}
echo ' </ul>' . "\n";
}
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'footer.php');
?>