trait MarkdownOperation
{
static $_names = [];
+
protected function setupMarkdownRoutes($segment, $routeName, $controller)
{
Route::match(['get'], $segment . '/{id}/edit/markdown', $controller . '@markdown')->name('fluidbook_markdowneditor');
Route::match(['get'], $segment . '/{id}/edit/markdown/versions', $controller . '@getMarkdownsVersions');
+ Route::match(['get'], $segment . '/{id}/edit/markdown/versions/restore/{version}', $controller . '@restoreMarkdowns');
Route::match(['get'], $segment . '/{id}/markdown', $controller . '@getFilesById');
Route::match(['put'], $segment . '/{id}/save/markdown', $controller . '@saveMarkdown');
}
}
$token = Str::random(10);
+ $dir = self::getMarkdownsDir($id);
+ $file = $dir . 'latest.markdown3.gz';
+ $basefile = $dir . 'latest.markdown.gz';
+ $latest = json_decode(gzdecode(file_get_contents($file))) == "[]" ? gzdecode(file_get_contents($basefile)) : gzdecode(file_get_contents($file));
+ //dd(gzdecode(file_get_contents($file)) === "[]");
$fluidbook=FluidbookPublication::find($id);
- $contents=$fluidbook->getAccessibleContents();
+ $isArray = gettype(json_decode($latest,true));
+ $contents=($isArray === "array" ? json_decode($latest,true) : json_decode(json_decode($latest, true),true)) ?? $fluidbook->getAccessibleContents()['pages'];
return view('fluidbook_publication.markdown_editor', ['contents' => $contents, 'version' => 'stable', 'id' => $id, 'fluidbook' => $fluidbook, 'access' => "", 'token' => $token]);
}
- protected function saveMarkdown($fluidbook_id)
+ protected function saveMarkdown($fluidbook_id, $message = '', $md = '[]')
{
if (!FluidbookPublication::hasPermission($fluidbook_id)) {
abort(401);
}
- $markdowns = request('markdowns', '[]');
- $comments = request('message');
+ $markdowns = request('markdowns', $md);
+ $comments = $message ?? request('message');
$user_id = backpack_user()->id;
/** @var FluidbookPublication $fluidbook */
return static::$_names[$u];
}
+ protected function restoreMarkdowns($fluidbook_id, $version)
+ {
+ if (!FluidbookPublication::hasPermission($fluidbook_id)) {
+ abort(401);
+ }
+
+ $dir = self::getMarkdownsDir($fluidbook_id);
+ $markdowns = Files::firstThatExists($dir . '/' . $version . '.markdown3.gz', $dir . '/' . $version . '.markdown.gz');
+ $markdowns = gzdecode(file_get_contents($markdowns));
+ $this->saveMarkdown($fluidbook_id, __('Restaurer la sauvegarde des liens :date', ['date' => date('Y-m-d H:i:s', $version)]), $markdowns);
+
+ //return response()->json(['success' => 'ok']);
+ }
}
}
//Restore links from 2022-12-07 13:37:15
- this.linkeditor.save.saveIfUnsavedChanges(TRANSLATIONS.before_restore_message,false,callback);
+ this.markdowneditor.save.saveIfUnsavedChanges(TRANSLATIONS.before_restore_message,false,callback);
},
_restoreVersion(timestamp) {
$.ajax({
- url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/edit/links/versions/restore/' + timestamp + '',
+ url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/edit/markdown/versions/restore/' + timestamp + '',
success: function (data) {
window.location.reload();
},