bludit/bl-kernel/ajax/save-as-draft.php

43 lines
1.1 KiB
PHP
Raw Normal View History

2018-05-08 00:15:40 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
// $_POST
// ----------------------------------------------------------------------------
// (string) $_POST['title']
$title = isset($_POST['title']) ? $_POST['title'] : false;
// (string) $_POST['content']
$content = isset($_POST['content']) ? $_POST['content'] : false;
// (string) $_POST['uuid']
$uuid = isset($_POST['uuid']) ? $_POST['uuid'] : false;
// ----------------------------------------------------------------------------
// Check UUID
if (empty($uuid)) {
2019-01-31 20:07:59 +01:00
ajaxResponse(1, 'Autosave fail. UUID not defined.');
2018-05-08 00:15:40 +02:00
}
$autosaveUUID = 'autosave-'.$uuid;
$page = array(
'uuid'=>$autosaveUUID,
'key'=>$autosaveUUID,
'slug'=>$autosaveUUID,
'title'=>$title.' [ Autosave ] ',
'content'=>$content,
2018-07-17 23:58:01 +02:00
'type'=>'draft'
2018-05-08 00:15:40 +02:00
);
// Get the page key by the UUID
2018-08-03 18:59:23 +02:00
$pageKey = $pages->getByUUID($autosaveUUID);
2018-05-08 00:15:40 +02:00
// if pageKey is empty means the autosave page doesn't exist
if (empty($pageKey)) {
createPage($page);
} else {
editPage($page);
}
2019-01-31 20:07:59 +01:00
ajaxResponse(0, 'Autosave successfully.', array(
2018-05-08 00:15:40 +02:00
'uuid'=>$autosaveUUID
2019-01-31 20:07:59 +01:00
));
2018-05-08 00:15:40 +02:00
?>