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
|
|
|
/*
|
2019-05-10 11:35:23 +02:00
|
|
|
| Create/edit a page and save as draft
|
2019-05-09 19:31:55 +02:00
|
|
|
| If the UUID already exists the page is updated
|
|
|
|
|
|
|
|
|
| @_POST['title'] string Page title
|
|
|
|
| @_POST['content'] string Page content
|
|
|
|
| @_POST['uuid'] string Page uuid
|
2019-05-24 19:00:22 +02:00
|
|
|
| @_POST['uuid'] string Page type, by default is draft
|
2019-05-09 19:31:55 +02:00
|
|
|
|
|
|
|
|
| @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;
|
2019-05-24 19:00:22 +02:00
|
|
|
$type = isset($_POST['type']) ? $_POST['type'] : 'draft';
|
2018-05-08 00:15:40 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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,
|
2019-05-24 19:00:22 +02:00
|
|
|
'type'=>$type
|
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
|
|
|
|
2019-05-10 11:35:23 +02:00
|
|
|
// if pageKey is empty means the page doesn't exist
|
2018-05-08 00:15:40 +02:00
|
|
|
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
|
|
|
|
|
|
|
?>
|