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

50 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');
/*
2019-05-10 11:35:23 +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)) {
ajaxResponse(1, 'Save as draft fail. UUID not defined.');
2018-05-08 00:15:40 +02:00
}
$page = array(
'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
$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);
}
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
?>