1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-05 13:47:37 +02:00

Add onPageUpdated

This commit is contained in:
trendschau
2024-08-07 16:43:03 +02:00
parent aeef379c1f
commit 4bed92e236
2 changed files with 45 additions and 15 deletions

View File

@@ -255,15 +255,13 @@ class ControllerApiAuthorArticle extends Controller
# save draft content
$content = new Content($urlinfo['baseurl'], $this->settings, $this->c->get('dispatcher'));
$oldMarkdown = $content->getDraftMarkdown($item);
$markdown = $params['title'] . PHP_EOL . PHP_EOL . $params['body'];
$markdownArray = $content->markdownTextToArray($markdown);
$content->saveDraftMarkdown($item, $markdownArray);
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($markdown), 'onPageUpdated');
$naviFileName = $navigation->getNaviFileNameForPath($item->path);
$navigation->clearNavigation([$naviFileName]);
$draftNavigation = $navigation->getFullDraftNavigation($urlinfo, $this->settings['langattr']);
$draftNavigation = $navigation->setActiveNaviItemsWithKeyPath($draftNavigation, $item->keyPathArray);
$item = $navigation->getItemWithKeyPath($draftNavigation, $item->keyPathArray);
@@ -272,6 +270,14 @@ class ControllerApiAuthorArticle extends Controller
$draftMarkdown = $content->getDraftMarkdown($item);
$draftMarkdownHtml = $content->addDraftHtml($draftMarkdown);
$onPageUpdated = [
'oldMarkdown' => $content->markdownArrayToText($oldMarkdown),
'newMarkdown' => $content->markdownArrayToText($draftMarkdown),
'username' => $request->getAttribute('c_username'),
'item' => $item,
];
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($onPageUpdated), 'onPageUpdated');
$response->getBody()->write(json_encode([
'item' => $item,
'navigation' => $draftNavigation,

View File

@@ -62,6 +62,7 @@ class ControllerApiAuthorBlock extends Controller
$content = new Content($urlinfo['baseurl'], $this->settings, $this->c->get('dispatcher'));
$draftMarkdown = $content->getDraftMarkdown($item);
$oldMarkdown = $draftMarkdown;
# if it is a new content-block
if($params['block_id'] > 9999)
@@ -97,11 +98,16 @@ class ControllerApiAuthorBlock extends Controller
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
}
$markdown = $content->markdownArrayToText($draftMarkdown);
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($markdown), 'onPageUpdated');
$draftMarkdownHtml = $content->addDraftHtml($draftMarkdown);
$onPageUpdated = [
'oldMarkdown' => $content->markdownArrayToText($oldMarkdown),
'newMarkdown' => $content->markdownArrayToText($draftMarkdown),
'username' => $request->getAttribute('c_username'),
'item' => $item,
];
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($onPageUpdated), 'onPageUpdated');
# if it was published before, then we need to refresh the navigation
if($item->status == 'published')
{
@@ -178,6 +184,7 @@ class ControllerApiAuthorBlock extends Controller
$content = new Content($urlinfo['baseurl'], $this->settings, $this->c->get('dispatcher'));
$draftMarkdown = $content->getDraftMarkdown($item);
$oldMarkdown = $draftMarkdown;
if(!isset($draftMarkdown[$params['index_old']]))
{
@@ -201,11 +208,16 @@ class ControllerApiAuthorBlock extends Controller
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
}
$markdown = $content->markdownArrayToText($draftMarkdown);
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($markdown), 'onPageUpdated');
$draftMarkdownHtml = $content->addDraftHtml($draftMarkdown);
$onPageUpdated = [
'oldMarkdown' => $content->markdownArrayToText($oldMarkdown),
'newMarkdown' => $content->markdownArrayToText($draftMarkdown),
'username' => $request->getAttribute('c_username'),
'item' => $item,
];
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($onPageUpdated), 'onPageUpdated');
# if it was published before, then we need to refresh the navigation
if($item->status == 'published')
{
@@ -282,6 +294,7 @@ class ControllerApiAuthorBlock extends Controller
$content = new Content($urlinfo['baseurl'], $this->settings, $this->c->get('dispatcher'));
$draftMarkdown = $content->getDraftMarkdown($item);
$oldMarkdown = $draftMarkdown;
if(!isset($draftMarkdown[$params['block_id']]))
{
@@ -318,11 +331,16 @@ class ControllerApiAuthorBlock extends Controller
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
}
$markdown = $content->markdownArrayToText($draftMarkdown);
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($markdown), 'onPageUpdated');
$draftMarkdownHtml = $content->addDraftHtml($draftMarkdown);
$onPageUpdated = [
'oldMarkdown' => $content->markdownArrayToText($oldMarkdown),
'newMarkdown' => $content->markdownArrayToText($draftMarkdown),
'username' => $request->getAttribute('c_username'),
'item' => $item,
];
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($onPageUpdated), 'onPageUpdated');
# if it was published before, then we need to refresh the navigation
if($item->status == 'published')
{
@@ -399,6 +417,7 @@ class ControllerApiAuthorBlock extends Controller
$content = new Content($urlinfo['baseurl'], $this->settings, $this->c->get('dispatcher'));
$draftMarkdown = $content->getDraftMarkdown($item);
$oldMarkdown = $draftMarkdown;
# check if id exists
if(!isset($draftMarkdown[$params['block_id']]))
@@ -426,11 +445,16 @@ class ControllerApiAuthorBlock extends Controller
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
}
$markdown = $content->markdownArrayToText($draftMarkdown);
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($markdown), 'onPageUpdated');
$draftMarkdownHtml = $content->addDraftHtml($draftMarkdown);
$onPageUpdated = [
'oldMarkdown' => $content->markdownArrayToText($oldMarkdown),
'newMarkdown' => $content->markdownArrayToText($draftMarkdown),
'username' => $request->getAttribute('c_username'),
'item' => $item,
];
$this->c->get('dispatcher')->dispatch(new OnPageUpdated($onPageUpdated), 'onPageUpdated');
# if it was published before, then we need to refresh the navigation
if($item->status == 'published')
{