'tache' => 'extranet_task',
'changedate' => 'updated_at',
'compiledate' => 'compilation_date',
- 'composition_update' => 'composition_update_at',
+ 'composition_update' => 'composition_updated_at',
'exportdatas' => 'export_data',
];
namespace App\Fluidbook;
use App\Models\FluidbookPublication;
+use Cubist\PDF\PDFTools;
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Math;
class PDF
{
* @param $log
* @return false|string|void
*/
- public static function compilePDF($fluidbook,$log = null)
+ public static function compilePDF($fluidbook, $log = null)
{
- global $core;
- if (substr($book->parametres->pdfName, 0, 4) == 'http') {
+
+ $pdfName = $fluidbook->getAttribute('pdfName');
+ if (str_starts_with($pdfName, 'http')) {
return false;
}
- $cacheDir = WS_BOOKS . '/pdf/' . $book->book_id;
- if (!file_exists($cacheDir)) {
- mkdir($cacheDir, 0777, true);
- }
+ $cacheDir = Files::mkdir(protected_path('fluidbookpublication/pdf/' . $fluidbook->id));
- $normalPDF = $cacheDir . '/normal.pdf';
- $originalPDF = $cacheDir . '/original.pdf';
- $compressedPDF = $cacheDir . '/compressed.pdf';
+ $normalPDF = $cacheDir . 'normal.pdf';
+ $originalPDF = $cacheDir . 'original.pdf';
+ $compressedPDF = $cacheDir . 'compressed.pdf';
$files = [$normalPDF, $originalPDF, $compressedPDF];
if (file_exists($originalPDF)) {
$fmtime = filemtime($originalPDF);
- if ($fmtime >= $book->composition_update) {
+ if ($fmtime >= $fluidbook->getCompositionUpdate()) {
$invalid = false;
- foreach ($pages as $i => $infos) {
- $doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf';
+ foreach ($fluidbook->composition as $i => $infos) {
+ $doc = $fluidbook->getPDFSource($i);
if (file_exists($doc) && filemtime($doc) > $fmtime) {
if (null !== $log) {
$log->log('PDF File invalide : one most recent ' . $infos['document_id']);
}
if ($invalid) {
-
if (file_exists($originalPDF)) {
- self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf', false);
+ self::copy($originalPDF, $cacheDir . '/original.' . time() . '.pdf', false);
}
$pdfList = array();
$k = 0;
$original = true;
- foreach ($pages as $i => $infos) {
+ foreach ($fluidbook->composition as $i => $infos) {
if (!isset($firstDoc)) {
- $firstDoc = $infos['document_id'];
+ $firstDoc = $infos[0];
}
- $doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf';
+ $doc = $fluidbook->getPDFSource($i);
if (!isset($pdfList[$doc])) {
$pdfList[$doc] = $j;
- $nb_pages[$doc] = $infos['nb_pages'];
+ $nb_pages[$doc] = $fluidbook->getDocument($i)->pages;
$k = $j;
$j++;
} else {
$k = $pdfList[$doc];
}
- $pagesList[$i] = array($k, $infos['document_page']);
+ $pagesList[$i] = array($k, $infos[1]);
- if ($i != $infos['document_page'] || $infos['document_id'] != $firstDoc) {
+ if ($i != $infos[1] || $infos[0] != $firstDoc) {
$original = false;
}
}
if ($original) {
- self::copy(wsDocument::getDir($firstDoc) . 'crop.pdf', $originalPDF, false);
+ // Si on a un seul document source utilisé pour le fluidbook, on le copie directement
+ self::copy($fluidbook->getPDFSource(1), $originalPDF, false);
} else {
$args = '';
foreach ($pdfList as $doc => $index) {
- $lettre = cubeMath::toPDFLetter($index, true);
+ $lettre = Math::toPDFLetter($index, true);
$args .= $lettre . '=' . $doc . ' ';
}
$currentRange = null;
foreach ($pagesList as $p) {
- $lettre = cubeMath::toPDFLetter($p[0], true);
+ $lettre = Math::toPDFLetter($p[0], true);
$page = $p[1];
// Initialise l'intervale
$hash = sha1($args);
$args .= ' output ' . $originalPDF;
-
- $cached = WS_BOOKS . '/pdf/' . $hash . '.pdf';
+ $cached = $cacheDir . '/' . $hash . '.pdf';
if (file_exists($cached) && filesize($cached) > 0) {
self::copy($cached, $originalPDF, false);
} else {
- $pdftk = new cubeCommandLine('pdftk');
- $pdftk->setPath(CONVERTER_PATH);
+ $pdftk = new CommandLine('pdftk');
$pdftk->setManualArg($args);
$pdftk->execute();
self::copy($normalPDF, $cached, false);
}
- if ($book->parametres->pdfReplace) {
- $replace = $book->getAssetDir() . $book->parametres->pdfReplace;
+ if ($fluidbook->pdfReplace) {
+ $replace = $fluidbook->getAssetDir() . $fluidbook->pdfReplace;
if (file_exists($replace) && filesize($replace) > 0) {
if (!file_exists($normalPDF) || filemtime($normalPDF) < filemtime($replace) || filesize($normalPDF) != filesize($replace)) {
self::copy($replace, $normalPDF, false);
self::copy($originalPDF, $normalPDF, false);
}
- if ($book->parametres->pdfCompress) {
+ if ($fluidbook->pdfCompress) {
if (!file_exists($compressedPDF) || filemtime($compressedPDF) < filemtime($normalPDF)) {
-
+ PDFTools::compressPDF($normalPDF, $compressedPDF);
}
return $compressedPDF;
}
return $normalPDF;
}
+
+ protected static function copy($from, $to, $touch = true)
+ {
+ return Files::copyFile($from, $to, false, $touch);
+ }
}
namespace App\Fluidbook\SEO;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Files\VirtualDirectory;
+use Cubist\Util\Text;
+
class Page
{
public $page;
public $footer;
/**
- * @var wsHTML5Seo
+ * @var Document
*/
public $_container;
'seoContent' => $this->getSEOContent(),
'startpage' => '<script type="text/javascript">var FLUIDBOOK_START_PAGE="' . $this->page . '";</script>' . "\n"];
- if (!$this->_container->compiler->book->parametres->seoVersion) {
+ if (!$this->_container->compiler->fluidbookSettings->seoVersion) {
$vars['canonical'] = $vars['next'] = $vars['prev'] = '';
}
public function getURL()
{
if (null === $this->url) {
- return $this->page . '-' . CubeIT_Text::str2URL(CubeIT_Text::removeAccents($this->title)) . '.html';
+ return $this->page . '-' . Text::str2URL(Text::removeAccents($this->title)) . '.html';
}
return $this->url;
}
$res = 'p/' . $url;
}
- if ($this->_container->compiler->book->parametres->seoBaseURL == '') {
+ if($this->_container->compiler->fluidbookSettings->seoBaseURL == '') {
$res = $url;
} else {
- $res = str_replace($this->_container->compiler->book->parametres->seoBaseURL, '', $url);
+ $res = str_replace($this->_container->compiler->fluidbookSettings->seoBaseURL, '', $url);
}
return ltrim($res, '/');
/**
* @param string $html
- * @param CubeIT_Files_VirtualDirectory $vdir
+ * @param VirtualDirectory $vdir
* @param null|string $path
*/
public function writePage($html, $vdir, $path = null)
}
$html = str_replace('<!-- $base -->', $base, $html);
- $dir = WS_BOOKS . '/seo/' . $this->_container->compiler->book_id . '/';
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
+ $dir = Files::mkdir(protected_path('fluidbookpublication/seo/' . $this->_container->compiler->getFluidbook()->id));
$file = $dir . $this->page . '.html';
$hash = sha1($html);
$hashfile = $dir . $this->page . '.hash';
namespace App\Jobs;
+use App\Fluidbook\PDF;
use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\SocialImageOperation;
use App\Models\Signature;
use App\Fluidbook\SearchIndex;
}
$this->writeJs();
$this->log('Js written');
- $this->vdir->sync($delete, $this);
+ $this->vdir->sync(true, $this);
$this->log('Files Synced');
// $f=rtrim(str_replace('/html5/', '/compiletime/', $this->dir));
// touch($f);
return;
}
- $res = wsUtil::compilePDF($this->book, $this->pages, $this);
+ $res = PDF::compilePDF($this->getFluidbook());
if (!$this->config->pdfName) {
$this->config->pdfName = 'document.pdf';
}
$this->config->defaultLang = $this->getFluidbook()->locale;
$l10n = FluidbookTranslate::getCompiledTranslations();
$l10n['default'] = $l10n[$this->config->defaultLang];
- foreach ($this->getFluidbook()->translations as $k => $v) {
- $l10n['default'][$k] = $v;
+ if($this->getFluidbook()->translations) {
+ foreach ($this->getFluidbook()->translations as $k => $v) {
+ $l10n['default'][$k] = $v;
+ }
}
$this->config->setRaw('l10n', $l10n);
public function writeTexts()
{
- $cache = sha1($this->fluidbookSettings->highlightResults . '/--/' . $this->fluidbookSettings->searchWordSelectionAlgorithm . '///' . $this->fluidbookSettings->textExtraction . '|--|' . $this->fluidbookSettings->ignoreSearchSeparators . '|||' . $this->getFluidbook()->composition_update . '()()()' . FWSTK::lastUpdate());
+ $cache = sha1($this->fluidbookSettings->highlightResults . '/--/' . $this->fluidbookSettings->searchWordSelectionAlgorithm . '///' . $this->fluidbookSettings->textExtraction . '|--|' . $this->fluidbookSettings->ignoreSearchSeparators . '|||' . $this->getFluidbook()->getCompositionUpdate(). '()()()' . FWSTK::lastUpdate());
$cacheDir = Files::mkdir(protected_path('fluidbookpublication/index/' . $this->book_id . '/' . $cache . '/'));
$indexFile = $cacheDir . '/search.index.js';
$textFile = $cacheDir . '/search.texts.js';
{
$fixed = $this->path('fixed.pdf');
$original = $this->path('original.pdf');
+ $crop = $this->path('crop.pdf');
if (!file_exists($fixed) || filesize($fixed) === 0 || filemtime($fixed) < filemtime($original)) {
PDFTools::fixPDF($original, $fixed);
}
+ if (!file_exists($crop)) {
+ `ln -s $fixed $crop`;
+ }
return $fixed;
}
return $this->path('texts/' . $sepFolder . $prefix . $type . $page . '.txt');
}
+ public function getPDFSource($type = 'crop'): string
+ {
+ return $this->path($type . '.pdf');
+ }
+
}
class FluidbookPublication extends ToolboxSettingsModel
{
+ public mixed $pdfName;
protected $table = 'fluidbook_publication';
protected $_options = ['name' => 'fluidbook-publication',
'singular' => 'publication',
}
+ /**
+ * @param $page
+ * @return FluidbookDocument
+ */
+ public function getDocument($page)
+ {
+ return self::_getDocument($this->composition[$page][0]);
+ }
+
public function getDocumentSize($page = 1)
{
$sizes = $this->getDocumentSizes();
return Files::mkdir('/data1/extranet/www/fluidbook/books/working/' . $this->id);
}
+ public function getCompositionUpdate(): int
+ {
+ if (null === $this->composition_updated_at) {
+ $this->composition_updated_at = new Datetime();
+ $this->saveQuietly();
+ }
+ return $this->composition_updated_at->getTimestamp();
+ }
+
+ public function getPDFSource($page, $type = 'crop'): string
+ {
+ $compo = $this->composition[$page];
+ return self::_getDocument($compo[0])->getPDFSource($type);
+ }
+
public function compile($dest)
{
"source": {
"type": "git",
"url": "git://git.cubedesigners.com/cubist_pdf.git",
- "reference": "a3712f58ac4d727c1a4c2e7263d39f6b7dce5b3a"
+ "reference": "64dd253b4d64f65b5700e15997b76bd0a9a6a584"
},
"dist": {
"type": "tar",
- "url": "https://composer.cubedesigners.com/dist/cubist/pdf/cubist-pdf-dev-master-b055ea.tar",
- "reference": "a3712f58ac4d727c1a4c2e7263d39f6b7dce5b3a",
- "shasum": "67b078a6c6a157a4f32eacedc086cdb7e2bf9f88"
+ "url": "https://composer.cubedesigners.com/dist/cubist/pdf/cubist-pdf-dev-master-71a4c6.tar",
+ "reference": "64dd253b4d64f65b5700e15997b76bd0a9a6a584",
+ "shasum": "887dc51cca2c64c9cbd7cca9273d0e8f77428fae"
},
"require": {
"cubist/util": "dev-master",
"cubist",
"pdf"
],
- "time": "2022-08-23T07:38:41+00:00"
+ "time": "2022-08-23T18:14:00+00:00"
},
{
"name": "cubist/scorm",