|
|
|
@ -25,7 +25,7 @@ use Twig\Loader\ArrayLoader;
|
|
|
|
|
use ZipArchive;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The "main" command
|
|
|
|
|
* The “main” command
|
|
|
|
|
*/
|
|
|
|
|
class Main {
|
|
|
|
|
/**
|
|
|
|
@ -34,14 +34,16 @@ class Main {
|
|
|
|
|
private const string ARGUMENT_FILES = 'files';
|
|
|
|
|
|
|
|
|
|
private const string DOM_NAMESPACE_ATTRIBUTE = 'http://www.w3.org/2000/xmlns/';
|
|
|
|
|
/** @noinspection HttpUrlsUsage */
|
|
|
|
|
private const string OPF_NAMESPACE_DC = 'http://purl.org/dc/elements/1.1/';
|
|
|
|
|
/** @noinspection HttpUrlsUsage */
|
|
|
|
|
private const string OPF_NAMESPACE_OPF = 'http://www.idpf.org/2007/opf';
|
|
|
|
|
|
|
|
|
|
private const string TWIG_TEMPLATE_METADATA_DESCRIPTION = 'metadata_description.html';
|
|
|
|
|
private const array TWIG_TEMPLATES = [
|
|
|
|
|
self::TWIG_TEMPLATE_METADATA_DESCRIPTION => <<<'TWIG'
|
|
|
|
|
<div>
|
|
|
|
|
<p>{{ description }}</p>
|
|
|
|
|
<p>{{ summary }}</p>
|
|
|
|
|
<p><strong>Chapters:</strong> {{ chapters ?? 1 }}</p>
|
|
|
|
|
<p><strong>Word count:</strong> {{ words }}</p>
|
|
|
|
|
<p><strong>Published:</strong> {{ publishDate }}</p>
|
|
|
|
@ -478,12 +480,12 @@ EOF
|
|
|
|
|
}
|
|
|
|
|
//endregion
|
|
|
|
|
//region Delete description if present
|
|
|
|
|
//region Deletion form DOM
|
|
|
|
|
//region Deletion from DOM
|
|
|
|
|
$rootFileDirty = false;
|
|
|
|
|
/** @noinspection HttpUrlsUsage */
|
|
|
|
|
$rootFileXPath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
|
|
|
|
|
if (($descriptionNodeList = $rootFileXPath->query('/r:package/r:metadata/dc:description')) !== false && $descriptionNodeList->count() > 0) {
|
|
|
|
|
$output->writeln($descriptionNodeList->count() . ' descriptions found → removing', OutputInterface::VERBOSITY_VERBOSE);
|
|
|
|
|
$output->writeln($descriptionNodeList->count() . ' existing descriptions found → removing', OutputInterface::VERBOSITY_VERBOSE);
|
|
|
|
|
/** @var DOMNode $descriptionNode */
|
|
|
|
|
foreach ($descriptionNodeList as $descriptionNode) {
|
|
|
|
|
$descriptionNode->parentNode->removeChild($descriptionNode);
|
|
|
|
@ -491,7 +493,7 @@ EOF
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$output->writeln('no descriptions found', OutputInterface::VERBOSITY_VERBOSE);
|
|
|
|
|
$output->writeln('No existing description found', OutputInterface::VERBOSITY_VERBOSE);
|
|
|
|
|
}
|
|
|
|
|
//endregion
|
|
|
|
|
//region Overwrite root file in ZIP
|
|
|
|
@ -524,7 +526,6 @@ EOF
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @noinspection PhpVoidFunctionResultUsedInspection */
|
|
|
|
|
if (!$fileArchive->replaceFile(
|
|
|
|
|
$rootFilePathTemp,
|
|
|
|
|
$rootFileIndex,
|
|
|
|
|