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

56 lines
1.4 KiB
PHP
Raw Permalink 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)) {
exit (json_encode(array(
'status'=>1,
'message'=>'Autosave fail. UUID not defined.'
)));
}
// Check content length to create the autosave page
if (Text::length($content)<100) {
exit (json_encode(array(
'status'=>1,
'message'=>'Autosave not completed. The content length is less than 100 characters.'
)));
}
$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);
}
exit (json_encode(array(
'status'=>0,
'message'=>'Autosave successfully.',
'uuid'=>$autosaveUUID
)));
?>