2018-05-08 00:15:40 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
2019-05-09 19:31:55 +02:00
|
|
|
/*
|
|
|
|
| Create/Edit a page and save as draft
|
|
|
|
| If the UUID already exists the page is updated
|
|
|
|
|
|
|
|
|
| @_POST['title'] string Page title
|
|
|
|
| @_POST['content'] string Page content
|
|
|
|
| @_POST['uuid'] string Page uuid
|
|
|
|
|
|
|
|
|
| @return array
|
|
|
|
*/
|
|
|
|
|
2018-05-08 00:15:40 +02:00
|
|
|
// $_POST
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
$title = isset($_POST['title']) ? $_POST['title'] : false;
|
|
|
|
$content = isset($_POST['content']) ? $_POST['content'] : false;
|
|
|
|
$uuid = isset($_POST['uuid']) ? $_POST['uuid'] : false;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Check UUID
|
|
|
|
if (empty($uuid)) {
|
2019-05-09 19:31:55 +02:00
|
|
|
ajaxResponse(1, 'Save as draft fail. UUID not defined.');
|
2018-05-08 00:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$page = array(
|
2019-05-09 19:31:55 +02:00
|
|
|
'uuid'=>$uuid,
|
|
|
|
'key'=>$uuid,
|
|
|
|
'slug'=>$uuid,
|
|
|
|
'title'=>$title,
|
2018-05-08 00:15:40 +02:00
|
|
|
'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
|
2019-05-09 19:31:55 +02:00
|
|
|
$pageKey = $pages->getByUUID($uuid);
|
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-05-09 19:31:55 +02:00
|
|
|
ajaxResponse(0, 'Save as draft successfully.', array(
|
|
|
|
'uuid'=>$uuid
|
2019-01-31 20:07:59 +01:00
|
|
|
));
|
2018-05-08 00:15:40 +02:00
|
|
|
|
|
|
|
?>
|