use App\Models\FluidbookDocument;
use App\Models\FluidbookPublication;
+use App\Util\FluidbookLinks;
use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
use Illuminate\Support\Facades\Route;
protected function setupEditRoutes($segment, $routeName, $controller)
{
Route::match(['get'], $segment . '/{id}/edit/links', $controller . '@links');
+ Route::put($segment . '/{id}/save/links', $controller . '@saveLinks');
Route::get($segment . '/{id}/edit/{type}_{page}.{format}', $controller . '@getLinkPage')
- // ->whereIn('type', ['raster', 'images', 'texts', 'vector'])
+ // ->whereIn('type', ['raster', 'images', 'texts', 'vector'])
->whereNumber('page');
- //->whereIn('format', ['jpg', 'png', 'avif', 'webp', 'svg']);
+ //->whereIn('format', ['jpg', 'png', 'avif', 'webp', 'svg']);
}
+ protected function saveLinks($fluidbook_id)
+ {
+ if (!FluidbookPublication::hasPermission($fluidbook_id)) {
+ abort(401);
+ }
+ FluidbookLinks::saveLinksInFile($fluidbook_id,
+ backpack_user()->id,
+ request('message'),
+ request('links', []),
+ request('rulers', [])
+ );
+ }
+
protected function getLinkPage($fluidbook_id, $type, $page, $format = 'jpg')
{
/** @var FluidbookPublication $fluibdook */
use Cubist\Util\Files\Files;
use Cubist\Util\ObjectUtil;
use Cubist\Util\Str;
+use PhpOffice\PhpSpreadsheet\Cell\DataType;
+use PhpOffice\PhpSpreadsheet\Exception;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use SodiumException;
class FluidbookLinks
protected static $_testLinkCache = null;
protected static $_linksKey = null;
+ /**
+ * @throws Exception
+ */
public static function linksToExcel($links, $rulers, $pages = null)
{
set_time_limit(0);
$comments = array();
- $xls = new PHPExcel();
+ $xls = new Spreadsheet();
$s = $xls->setActiveSheetIndex(0);
$s->setTitle('Links');
foreach ($cols as $id => $label) {
$s->setCellValueByColumnAndRow($i, 1, $id);
$s->getColumnDimensionByColumn($i)->setAutoSize(true);
- $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $s->getStyleByColumnAndRow($i, 1)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$i++;
}
}
}
if ($id === 'to') {
- $s->getCellByColumnAndRow($i, $j)->setDataType(PHPExcel_Cell_DataType::TYPE_STRING)->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
+ $s->getCellByColumnAndRow($i, $j)->setDataType(DataType::TYPE_STRING)->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);
}
$value = $l[$id];
} else {
}
}
- $s->setCellValueExplicitByColumnAndRow($i, $j, $value);
+ $s->setCellValueExplicitByColumnAndRow($i, $j, $value, DataType::TYPE_STRING);
$i++;
}
$j++;
$value = $r[$id];
}
$s->setCellValueByColumnAndRow($i, $j, $value);
- $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
+ $s->getStyleByColumnAndRow($i, $j)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
$i++;
}
$j++;
}
$dir = self::getLinksDir($book_id);
- $file = $dir . '/' . $time . '.links.gz';
+ $file = $dir . '/' . $time . '.links3.gz';
if ($time === 'latest' && !file_exists($file)) {
$versions = self::getLinksVersions($book_id);
foreach ($versions as $version => $m) {
- copy($dir . '/' . $version . '.links.gz', $dir . '/latest.links.gz');
- copy($dir . '/' . $version . '.meta.gz', $dir . '/latest.meta.gz');
+ copy(Files::firstThatExists($dir . '/' . $version . '.links3.gz', $dir . '/' . $version . '.links.gz'), $dir . '/latest.links3.gz');
+ copy(Files::firstThatExists($dir . '/' . $version . '.meta3.gz', $dir . '/' . $version . '.meta.gz'), $dir . '/latest.meta3.gz');
break;
}
}
$lr = self::mergeLinksAndRulers($links, $rulers, $specialLinks, $specialRulers);
$meta = ['links' => count($lr['links']), 'rulers' => count($lr['rulers']), 'comments' => $comments, 'user' => $user_id];
$base = self::getLinksDir($book_id) . '/' . time();
- $latestLinks = self::getLinksDir($book_id) . '/latest.links.gz';
- $latestMeta = self::getLinksDir($book_id) . '/latest.meta.gz';
- file_put_contents($base . '.meta.gz', gzencode(json_encode($meta)));
- file_put_contents($base . '.links.gz', gzencode(json_encode($lr)));
- copy($base . '.links.gz', $latestLinks);
- copy($base . '.meta.gz', $latestMeta);
+ $latestLinks = self::getLinksDir($book_id) . '/latest.links3.gz';
+ $latestMeta = self::getLinksDir($book_id) . '/latest.meta3.gz';
+ file_put_contents($base . '.meta3.gz', gzencode(json_encode($meta)));
+ file_put_contents($base . '.links3.gz', gzencode(json_encode($lr)));
+ copy($base . '.links3.gz', $latestLinks);
+ copy($base . '.meta3.gz', $latestMeta);
}
continue;
}
$e = explode('.', $f, 2);
- if ($e[1] !== 'meta.gz' || $e[0] === 'latest') {
+ if (($e[1] !== 'meta.gz' && $e[1] !== 'meta3.gz') || $e[0] === 'latest') {
continue;
}
public static function getMeta($book_id, $update = 'latest')
{
- return json_decode(gzdecode(file_get_contents(self::getLinksDir($book_id) . '/' . $update . '.meta.gz')), true);
+ return json_decode(gzdecode(file_get_contents(Files::firstThatExists(self::getLinksDir($book_id) . '/' . $update . '.meta3.gz', self::getLinksDir($book_id) . '/' . $update . '.meta.gz'))), true);
}
public static function mergeLinksAndRulers($links, $rulers, $specialLinks, $specialRulers)
if (!$line) {
break;
}
+
// Commentaire || ligne vide
if (substr($line[0], 0, 1) == '#' || is_null($line[0])) {
continue;
window[act]();
}
-function saveLinks() {
-
+function saveLinks(message) {
+ if (message === undefined) {
+ message = TRANSLATIONS.manual_save_message;
+ }
+ $.ajax({
+ url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/save/links', method: 'post', data: {
+ _method: 'put', 'message': message, rulers: window.RULERS, links: window.LINKS,
+ }, success: function (data) {
+ new Noty({
+ type: "success", text: TRANSLATIONS.success_save,
+ }).show();
+ unsavedChanges = false;
+ }, error: function (jqXHR, status, error) {
+ new Noty({
+ type: "error", text: TRANSLATIONS.error_save + ' : ' + error,
+ }).show();
+ },
+ });
}
function firstPage() {
if (undefined === uid) {
uid = generateUID();
RULERS[uid] = {page: currentPage, type: axis, uid: uid};
+ hasChanged();
}
var ruler = $('<div class="ruler" data-uid="' + uid + '" fb-ref="editor" data-axis="' + axis + '"></div>');
if (pos === undefined) {
delete RULERS[uid];
$(ruler).remove();
movingRuler = null;
+ hasChanged();
+}
+
+function hasChanged() {
+ unsavedChanges = true;
}
function moveRuler() {
$fbdata['settings']['width']=$fbdata['width']=$fluidbook->getPageWidth();
$fbdata['settings']['height']=$fbdata['height']=$fluidbook->getPageHeight();
$fbdata['settings']['pages']=$fbdata['pages']=$fluidbook->getPagesNumber();
+ $translations=[
+ 'success_save'=>__('Liens sauvegardés'),
+ 'error_save'=>__('Une erreur s\'est produite lors de la sauvegarde des liens'),
+ 'manual_save_message'=>__('Sauvegarde manuelle'),
+ 'automatic_save_message'=>__('Sauvegarde automatique'),
+ 'warning_unsaved_changes'=>__('Des données n\'ont pas été sauvegardées'),
+ ];
@endphp
@extends('layouts.empty')
-@include('fluidbook_publication.link_editor_icons')
-
@section('content')
+ @include('fluidbook_publication.link_editor_icons')
<div draggable="false" id="linkeditor">
<aside id="linkeditor-left"></aside>
<div id="linkeditor-main">
@push('after_scripts')
<script>
+ var TRANSLATIONS =@json($translations);
var FLUIDBOOK_DATA = @json($fbdata);
var LINKS =@json($links);
var RULERS =@json($rulers);