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

50 lines
1.1 KiB
PHP

<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
/*
| 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
*/
// $_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.');
}
$page = array(
'uuid'=>$uuid,
'key'=>$uuid,
'slug'=>$uuid,
'title'=>$title,
'content'=>$content,
'type'=>'draft'
);
// Get the page key by the UUID
$pageKey = $pages->getByUUID($uuid);
// if pageKey is empty means the page doesn't exist
if (empty($pageKey)) {
createPage($page);
} else {
editPage($page);
}
ajaxResponse(0, 'Save as draft successfully.', array(
'uuid'=>$uuid
));
?>