}
$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));
+ $contents = $this->getLatestMarkdown($id);
$fluidbook=FluidbookPublication::find($id);
- $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 getLatestMarkdown($book_id) {
+ $fluidbook=FluidbookPublication::find($book_id);
+ $dir = self::getMarkdownsDir($book_id);
+ $filePath = $dir . 'latest.markdown3.gz';
+ if(file_exists($filePath)) {
+ $file = gzdecode(file_get_contents($filePath));
+ $typeOf = gettype($file);
+
+ if($typeOf === "string") {
+ return json_decode($file,true);
+ }
+ }
+
+ return $fluidbook->getAccessibleContents()['pages'];
+ }
+
protected function saveMarkdown($fluidbook_id, $message = '', $md = '[]')
{
if (!FluidbookPublication::hasPermission($fluidbook_id)) {