Improve Autosave

This commit is contained in:
danpros 2024-05-27 07:37:53 +07:00
commit a813ed3b38
10 changed files with 308 additions and 393 deletions

View file

@ -120,8 +120,11 @@ function remove_accent($str)
}
// Add content
function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description = null, $media = null, $dateTime = null)
function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description = null, $media = null, $dateTime = null, $autoSave = null)
{
if (!is_null($autoSave)) {
$draft = 'draft';
}
$tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ',')));
$tag = array_filter(array_unique($tag));
$tagslang = "content/data/tags.lang";
@ -237,11 +240,23 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty
mkdir($dir, 0775, true);
file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX);
}
if (empty($draft)) {
$draftFile = 'content/' . $user . '/blog/' . $category. '/draft/' . $filename;
if (file_exists($draftFile)) {
unlink($draftFile);
}
}
save_tag_i18n($post_tag, $post_tagmd);
rebuilt_cache('all');
clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename, $category, $type);
if (!is_null($autoSave)) {
return "Auto Saved";
}
if (empty($draft)) {
if (date('Y-m-d-H-i-s') >= $post_date) {
@ -258,7 +273,7 @@ function add_content($title, $tag, $url, $content, $user, $draft, $category, $ty
}
// Edit content
function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination = null, $description = null, $date = null, $media = null)
function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination = null, $description = null, $date = null, $media = null, $autoSave = null)
{
$tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ',')));
$tag = array_filter(array_unique($tag));
@ -449,7 +464,7 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
rebuilt_cache('all');
clear_post_cache($dt, $post_tag, $post_url, $oldfile, $category, $type);
$old_filename = pathinfo($oldfile, PATHINFO_FILENAME);
$old_ex = explode('_', $old_filename);
$old_url = $old_ex[2];
@ -465,6 +480,10 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
}
}
}
if (!is_null($autoSave)) {
return "Auto Saved";
}
if ($destination == 'post') {
if(!empty($revertPost)) {
@ -498,8 +517,11 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
}
// Add static page
function add_page($title, $url, $content, $draft, $description = null)
function add_page($title, $url, $content, $draft, $description = null, $autoSave = null)
{
if (!is_null($autoSave)) {
$draft = 'draft';
}
$post_title = safe_html($title);
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$description = safe_html($description);
@ -536,6 +558,10 @@ function add_page($title, $url, $content, $draft, $description = null)
mkdir($dir, 0775, true);
}
file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX);
$draftFile = $dirDraft . $filename;
if (file_exists($draftFile)) {
unlink($draftFile);
}
} else {
if (!is_dir($dirDraft)) {
mkdir($dirDraft, 0775, true);
@ -546,6 +572,10 @@ function add_page($title, $url, $content, $draft, $description = null)
rebuilt_cache('all');
clear_page_cache($post_url);
if (!is_null($autoSave)) {
return "Auto Saved";
}
if (empty($draft)) {
$redirect = site_url() . 'admin/pages';
header("Location: $redirect");
@ -557,8 +587,11 @@ function add_page($title, $url, $content, $draft, $description = null)
}
// Add static sub page
function add_sub_page($title, $url, $content, $static, $draft, $description = null)
function add_sub_page($title, $url, $content, $static, $draft, $description = null, $autoSave = null)
{
if (!is_null($autoSave)) {
$draft = 'draft';
}
$post = find_page($static);
$static = pathinfo($post['current']->md, PATHINFO_FILENAME);
$post_title = safe_html($title);
@ -597,12 +630,20 @@ function add_sub_page($title, $url, $content, $static, $draft, $description = nu
mkdir($dir, 0775, true);
}
file_put_contents($dir . $filename, print_r($post_content, true), LOCK_EX);
$draftFile = $dirDraft . $filename;
if (file_exists($draftFile)) {
unlink($draftFile);
}
} else {
if (!is_dir($dirDraft)) {
mkdir($dirDraft, 0775, true);
}
file_put_contents($dirDraft . $filename, print_r($post_content, true), LOCK_EX);
}
if (!is_null($autoSave)) {
return "Auto Saved";
}
rebuilt_cache('all');
clear_page_cache($post_url);
@ -612,7 +653,7 @@ function add_sub_page($title, $url, $content, $static, $draft, $description = nu
}
// Edit static page and sub page
function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination = null, $description = null, $static = null)
function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination = null, $description = null, $static = null, $autoSave = null)
{
$dir = pathinfo($oldfile, PATHINFO_DIRNAME);
$fn = explode('.', pathinfo($oldfile, PATHINFO_FILENAME));
@ -638,7 +679,7 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft,
}
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
if(!empty($revertPage)) {
@ -655,7 +696,7 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft,
}
}
unlink($oldfile);
} elseif(!empty($publishDraft)) {
} elseif (!empty($publishDraft)) {
$newfile = dirname($dir) . '/' . $post_url . '.md';
file_put_contents($newfile, print_r($post_content, true), LOCK_EX);
if (empty($static)) {
@ -665,7 +706,7 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft,
}
}
unlink($oldfile);
}else {
} else {
$newfile = $dir . '/' . $post_url . '.md';
if ($oldfile === $newfile) {
file_put_contents($oldfile, print_r($post_content, true), LOCK_EX);
@ -697,7 +738,7 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft,
}
rebuilt_cache('all');
clear_page_cache($post_url);
clear_page_cache($post_url);
if (!empty($static)) {
$posturl = site_url() . $static .'/'. $pu;
@ -746,6 +787,10 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft,
}
if (!is_null($autoSave)) {
return "Auto Saved";
}
if ($destination == 'post') {
if(!empty($revertPage)) {
$drafturl = site_url() . 'admin/draft';

View file

@ -151,4 +151,21 @@ pre code {
word-wrap: break-word;
}
}
.notice {
position: fixed;
bottom: 20px;
right: 20px;
padding: 10px 20px;
background-color: #f0f9ff;
border: 1px solid #e0e0e0;
border-radius: 5px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
font-size: 14px;
color: #333;
z-index: 999;
display: flex;
align-items: center;
display: none;
}

View file

@ -35,7 +35,6 @@ $images = image_gallery(null, 1, 40);
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/autosave.css">
<script>
$( function() {
var availableTags = [
@ -291,7 +290,14 @@ $( function() {
</div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>'; var initial_image = '<?php echo $images;?>';</script>
<script type="text/javascript">
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '';
var oldfile = '';
var addEdit = 'add';
var saveInterval = 60000;
</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/resources/js/media.uploader.js"></script>
<script>
@ -313,6 +319,6 @@ $('.img-container').on("click", ".the-img", function(e) {
$('#insertImageDialogURL').val($(e.target).attr('src'));
});
</script>
<?php if (config('autosave.enable') == 'true' ) {
echo '<script src="'.site_url().'system/resources/js/save_draft.js"></script>';
} ?>
<?php if (config('autosave.enable') == 'true' ):?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<?php endif;?>

View file

@ -8,7 +8,6 @@
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/autosave.css">
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
@ -27,7 +26,7 @@
<br>
</div>
<div class="col-sm-6">
<?php if ($type == 'is_page') :?>
<?php if ($type == 'is_page' || $type == 'is_subpage') :?>
<label for="pURL"><?php echo i18n('Slug');?> (<?php echo i18n('optional');?>)</label>
<input type="text" class="form-control text" id="pURL" name="url" value="<?php if (isset($postUrl)) {echo $postUrl;} ?>" placeholder="<?php echo i18n('If_the_url_is_left_empty_we_will_use_the_page_title');?>"/>
<br>
@ -43,7 +42,7 @@
<br>
<input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($type == 'is_page') :?>
<?php if ($type == 'is_page' || $type == 'is_subpage') :?>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Publish');?>"/> <input type="submit" name="draft" class="btn btn-primary draft" value="<?php echo i18n('Save_as_draft');?>"/>
<?php endif;?>
<?php if ($type == 'is_category') :?>
@ -118,7 +117,14 @@
</div>
</div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>'; var initial_image = '<?php echo $images;?>';</script>
<script type="text/javascript">
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '<?php echo $parent;?>';
var oldfile = '';
var addEdit = 'add';
var saveInterval = 60000;
</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
<script>
function loadImages(page) {
@ -139,6 +145,6 @@ $('.img-container').on("click", ".the-img", function(e) {
$('#insertImageDialogURL').val($(e.target).attr('src'));
});
</script>
<?php if (config('autosave.enable') == 'true' ) {
echo '<script src="'.site_url().'system/resources/js/save_draft.js"></script>';
} ?>
<?php if (config('autosave.enable') == 'true' ):?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<?php endif;?>

View file

@ -131,7 +131,7 @@ $( function() {
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
<?php } ?>
<div class="notice" id="response"></div>
<div class="row">
<div class="wmd-panel" style="width:100%;">
<form method="POST">
@ -224,6 +224,7 @@ $( function() {
<div class="row">
<div class="col-sm-6">
<div>
<input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
<label for="wmd-input"><?php echo i18n('Content');?> <span class="required">*</span></label>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'error'; } } ?>" name="content" cols="20" rows="15"><?php echo $oldcontent ?></textarea><br>
@ -339,7 +340,14 @@ $( function() {
</div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>'; var initial_image = '<?php echo $images;?>';</script>
<script type="text/javascript">
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '';
var oldfile = '<?php echo $filename;?>';
var addEdit = 'edit';
var saveInterval = 60000;
</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/resources/js/media.uploader.js"></script>
<script>
@ -361,3 +369,8 @@ $('.img-container').on("click", ".the-img", function(e) {
$('#insertImageDialogURL').val($(e.target).attr('src'));
});
</script>
<?php if (config('autosave.enable') == 'true' ):?>
<?php if ($isdraft[4] == 'draft') : ?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<?php endif;?>
<?php endif;?>

View file

@ -95,7 +95,7 @@ $images = image_gallery(null, 1, 40);
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
<?php } ?>
<div class="notice" id="response"></div>
<div class="row">
<div class="wmd-panel" style="width:100%;">
<form method="POST">
@ -141,6 +141,7 @@ $images = image_gallery(null, 1, 40);
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) {if (empty($postContent)) {echo 'error';}} ?>" name="content" cols="20" rows="10"><?php echo $oldcontent ?></textarea>
<br>
<input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if($type == 'is_frontpage' || $type == 'is_profile') { ?>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save');?>"/>
@ -264,7 +265,14 @@ $images = image_gallery(null, 1, 40);
</div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>'; var initial_image = '<?php echo $images;?>';</script>
<script type="text/javascript">
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '<?php echo $parent;?>';
var oldfile = '<?php echo $url;?>';
var addEdit = 'edit';
var saveInterval = 60000;
</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
<?php if ($type == 'is_profile'):?>
<script type="text/javascript" src="<?php echo site_url() ?>system/resources/js/media.uploader.js"></script>
@ -288,3 +296,8 @@ $('.img-container').on("click", ".the-img", function(e) {
$('#insertImageDialogURL').val($(e.target).attr('src'));
});
</script>
<?php if (config('autosave.enable') == 'true' ):?>
<?php if (stripos($dir . '/', '/draft/') !== false): ?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<?php endif;?>
<?php endif;?>

View file

@ -120,7 +120,7 @@ get('/index', function () {
// Get submitted login data
post('/login', function () {
$proper = (is_csrf_proper(from($_REQUEST, 'csrf_token')));
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
$captcha = config('login.protect.system');
if (is_null($captcha) || $captcha === 'disabled') {
$captcha = true;
@ -714,6 +714,9 @@ post('/add/content', function () {
if ($date !== null && $time !== null) {
$dateTime = $date . ' ' . $time;
}
if (empty($url)) {
$url = $title;
}
if (empty($is_post) && empty($is_image) && empty($is_video) && empty($is_audio) && empty($is_link) && empty($is_quote)) {
$add = site_url() . 'admin/content';
@ -721,47 +724,17 @@ post('/add/content', function () {
}
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
if (!empty($url)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime);
} else {
$url = $title;
add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime);
}
add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null, $dateTime);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
if (!empty($url)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime);
} else {
$url = $title;
add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime);
}
add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image, $dateTime);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (!empty($url)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime);
} else {
$url = $title;
add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime);
}
add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video, $dateTime);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (!empty($url)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime);
} else {
$url = $title;
add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime);
}
add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio, $dateTime);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (!empty($url)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime);
} else {
$url = $title;
add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime);
}
add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote, $dateTime);
} elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (!empty($url)) {
add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime);
} else {
$url = $title;
add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime);
}
add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link, $dateTime);
} else {
$message['error'] = '';
if (empty($title)) {
@ -876,14 +849,12 @@ post('/add/page', function () {
$draft = from($_REQUEST, 'draft');
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if (empty($url)) {
$url = $title;
}
if ($role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
add_page($title, $url, $content, $draft, $description);
} else {
$url = $title;
add_page($title, $url, $content, $draft, $description);
}
add_page($title, $url, $content, $draft, $description);
} else {
$message['error'] = '';
if (empty($title)) {
@ -917,6 +888,93 @@ post('/add/page', function () {
}
});
// Autosave
post('/admin/autosave', function () {
if (login()) {
$title = $_REQUEST['title'];
$url = $_REQUEST['url'];
$content = $_REQUEST['content'];
$description = $_REQUEST['description'];
$draft = 'draft';
$posttype = $_REQUEST['posttype'];
$autoSave = $_REQUEST['autoSave'];
$addEdit = $_REQUEST['addEdit'];
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if (empty($url)) {
$url = $title;
}
if ($addEdit == 'edit') {
$revertPage = '';
$revertPost = '';
$publishDraft = '';
$oldfile = $_REQUEST['oldfile'];
$destination = null;
}
if (!empty($title) && !empty($content)) {
if ($posttype == 'is_page') {
if ($role === 'editor' || $role === 'admin') {
if ($addEdit == 'add') {
$response = add_page($title, $url, $content, $draft, $description, $autoSave);
} else {
$response = edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, null, $autoSave);
}
}
} elseif ($posttype == 'is_subpage') {
if ($role === 'editor' || $role === 'admin') {
$static = $_REQUEST['parent_page'];
if ($addEdit == 'add') {
$response = add_sub_page($title, $url, $content, $static, $draft, $description, $autoSave);
} else {
$response = edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static, $autoSave);
}
}
} else {
$tag = $_REQUEST['tag'];
$category = $_REQUEST['category'];
$dateTime = $_REQUEST['dateTime'];
if ($posttype == 'is_image') {
$type = 'image';
$media = $_REQUEST['pimage'];
} elseif ($posttype == 'is_video') {
$type = 'video';
$media = $_REQUEST['pvideo'];
} elseif ($posttype == 'is_link') {
$type = 'link';
$media = $_REQUEST['plink'];
} elseif ($posttype == 'is_quote') {
$type = 'quote';
$media = $_REQUEST['pquote'];
} elseif ($posttype == 'is_audio') {
$type = 'audio';
$media = $_REQUEST['paudio'];
} elseif ($posttype == 'is_post') {
$type = 'post';
$media = null;
}
if (!empty($title) && !empty($tag) && !empty($content) && !empty($media)) {
if ($addEdit == 'add') {
$response = add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description, $media, $dateTime, $autoSave);
} else {
$arr = explode('/', $oldfile);
if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
$response = edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination, $description, $dateTime, $media, $autoSave);
}
}
}
}
} else {
$response = "No content to save.";
}
echo $response;
}
});
// Show the add category
get('/add/category', function () {
$user = $_SESSION[site_url()]['user'];
@ -966,14 +1024,12 @@ post('/add/category', function () {
$description = from($_REQUEST, 'description');
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if (empty($url)) {
$url = $title;
}
if ($role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
add_category($title, $url, $content, $description);
} else {
$url = $title;
add_category($title, $url, $content, $description);
}
add_category($title, $url, $content, $description);
} else {
$message['error'] = '';
if (empty($title)) {
@ -1452,7 +1508,7 @@ get('/admin/pages/:static', function ($static)
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . '<a href="'. site_url() .'admin/pages">' .i18n('pages').'</a> &#187; ' . $post->title,
'p' => $post,
'static' => $post,
'type' => 'staticSubpage',
'type' => 'is_subpage',
'prev' => static_prev($prev),
'next' => static_next($next),
'is_page' => true
@ -1463,7 +1519,7 @@ get('/admin/pages/:static', function ($static)
'description' => safe_html(strip_tags(blog_description())),
'canonical' => site_url(),
'metatags' => generate_meta(null, null),
'type' => 'staticSubpage',
'type' => 'is_subpage',
'is_admin' => true,
'bodyclass' => 'denied',
'breadcrumb' => '',
@ -2811,14 +2867,12 @@ post('/category/:category/edit', function () {
$description = from($_REQUEST, 'description');
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if (empty($url)) {
$url = $title;
}
if ($role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
edit_category($title, $url, $content, $oldfile, $destination, $description);
} else {
$url = $title;
edit_category($title, $url, $content, $oldfile, $destination, $description);
}
edit_category($title, $url, $content, $oldfile, $destination, $description);
} else {
$message['error'] = '';
if (empty($title)) {
@ -3557,44 +3611,37 @@ post('/post/:name/edit', function () {
} elseif (!empty($is_post)) {
$type = 'is_post';
}
if (empty($url)) {
$url = $title;
}
$arr = explode('/', $oldfile);
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null);
} else {
@ -3931,7 +3978,7 @@ get('/:static', function ($static) {
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $post->title,
'p' => $post,
'static' => $post,
'type' => 'staticPage',
'type' => 'is_page',
'prev' => static_prev($prev),
'next' => static_next($next),
'is_page' => true
@ -3959,7 +4006,8 @@ get('/:static/add', function ($static) {
'description' => safe_html(strip_tags(blog_description())),
'canonical' => site_url(),
'metatags' => generate_meta(null, null),
'type' => 'is_page',
'type' => 'is_subpage',
'parent' => $static,
'is_admin' => true,
'bodyclass' => 'add-page',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . i18n('Add_new_page')
@ -3996,14 +4044,12 @@ post('/:static/add', function ($static) {
$draft = from($_REQUEST, 'draft');
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if (empty($url)) {
$url = $title;
}
if ($role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
add_sub_page($title, $url, $content, $static, $draft, $description);
} else {
$url = $title;
add_sub_page($title, $url, $content, $static, $draft, $description);
}
add_sub_page($title, $url, $content, $static, $draft, $description);
} else {
$message['error'] = '';
if (empty($title)) {
@ -4025,7 +4071,7 @@ post('/:static/add', function ($static) {
'postTitle' => $title,
'postUrl' => $url,
'postContent' => $content,
'type' => 'is_page',
'type' => 'is_subpage',
'is_admin' => true,
'bodyclass' => 'add-page',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $title . '">' . $title . '</a> &#187; ' . i18n('Add_new_page')
@ -4067,7 +4113,8 @@ get('/:static/edit', function ($static) {
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="'. site_url() .'admin/pages">' .i18n('pages').'</a> &#187; ' . $post->title,
'p' => $post,
'static' => $post,
'type' => 'staticPage',
'type' => 'is_page',
'parent' => ''
));
} else {
render('denied', array(
@ -4075,7 +4122,7 @@ get('/:static/edit', function ($static) {
'description' => safe_html(strip_tags(blog_description())),
'canonical' => site_url(),
'metatags' => generate_meta(null, null),
'type' => 'staticPage',
'type' => 'is_page',
'is_admin' => true,
'bodyclass' => 'denied',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
@ -4104,14 +4151,12 @@ post('/:static/edit', function () {
$publishDraft = from($_REQUEST, 'publishdraft');
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if (empty($url)) {
$url = $title;
}
if ($role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description);
} else {
$url = $title;
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description);
}
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description);
} else {
$message['error'] = '';
if (empty($title)) {
@ -4137,6 +4182,8 @@ post('/:static/edit', function () {
'postContent' => $content,
'bodyclass' => 'edit-page',
'is_admin' => true,
'type' => 'is_page',
'parent' => '',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit')
));
}
@ -4176,7 +4223,7 @@ get('/:static/delete', function ($static) {
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Delete') . ': ' . $post->title,
'p' => $post,
'static' => $post,
'type' => 'staticPage',
'type' => 'is_page',
));
} else {
render('denied', array(
@ -4300,7 +4347,7 @@ get('/:static/:sub', function ($static, $sub) {
'parent' => $parent_post,
'prev' => static_prev($prev),
'next' => static_next($next),
'type' => 'subPage',
'type' => 'is_subpage',
'is_subpage' => true
), $layout);
});
@ -4343,7 +4390,8 @@ get('/:static/:sub/edit', function ($static, $sub) {
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . $page->title,
'p' => $page,
'static' => $page,
'type' => 'subPage',
'type' => 'is_subpage',
'parent' => $static
));
} else {
render('denied', array(
@ -4351,7 +4399,7 @@ get('/:static/:sub/edit', function ($static, $sub) {
'description' => safe_html(strip_tags(blog_description())),
'canonical' => site_url(),
'metatags' => generate_meta(null, null),
'type' => 'subPage',
'type' => 'is_subpage',
'is_admin' => true,
'bodyclass' => 'denied',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
@ -4383,14 +4431,12 @@ post('/:static/:sub/edit', function ($static, $sub) {
}
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if (empty($url)) {
$url = $title;
}
if ($role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static);
} else {
$url = $title;
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static);
}
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static);
} else {
$message['error'] = '';
if (empty($title)) {
@ -4416,8 +4462,10 @@ post('/:static/:sub/edit', function ($static, $sub) {
'postContent' => $content,
'static' => $static,
'sub' => $sub,
'type' => 'is_subpage',
'bodyclass' => 'edit-page',
'is_admin' => true,
'parent' => $static,
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Edit')
));
}
@ -4465,7 +4513,7 @@ get('/:static/:sub/delete', function ($static, $sub) {
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . site_url() . 'admin/pages/' . $post->slug . '">' . $post->title . '</a> &#187; ' . $page->title,
'p' => $page,
'static' => $page,
'type' => 'subPage',
'type' => 'is_subpage',
));
} else {
render('denied', array(
@ -4473,7 +4521,7 @@ get('/:static/:sub/delete', function ($static, $sub) {
'description' => safe_html(strip_tags(blog_description())),
'canonical' => site_url(),
'metatags' => generate_meta(null, null),
'type' => 'subPage',
'type' => 'is_subpage',
'is_admin' => true,
'bodyclass' => 'denied',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . i18n('Denied')
@ -4737,46 +4785,38 @@ post('/:year/:month/:name/edit', function () {
} elseif (!empty($is_post)) {
$type = 'is_post';
}
if (empty($url)) {
$url = $title;
}
$arr = explode('/', $oldfile);
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
if ($user === $arr[1] || $role === 'editor' || $role === 'admin') {
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
if (empty($url)) {
$url = $title;
}
edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null);
} else {

View file

@ -1,16 +0,0 @@
.notice {
position: fixed;
bottom: 20px;
right: 20px;
padding: 10px 20px;
background-color: #f0f9ff;
border: 1px solid #e0e0e0;
border-radius: 5px;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
font-size: 14px;
color: #333;
z-index: 999;
display: flex;
align-items: center;
display: none;
}

View file

@ -16,6 +16,7 @@ function updateData() {
var pDate = $("#pDate").val();
var pTime = $("#pTime").val();
var dateTime = pDate + " " + pTime;
var autoSave = 'autoSave';
// Prepare data to send to PHP
var data = {
@ -27,31 +28,35 @@ function updateData() {
category: category,
posttype: posttype,
pimage: pimage,
paudio: paudio,
pvideo: pvideo,
pquote: pquote,
plink: plink,
dateTime: dateTime
paudio: paudio,
pvideo: pvideo,
pquote: pquote,
plink: plink,
dateTime: dateTime,
autoSave: autoSave,
addEdit: addEdit,
oldfile: oldfile,
parent_page: parent_page
};
$.ajax({
url: base_path + 'autosave.php',
url: base_path + 'admin/autosave',
type: "POST",
data: data,
success: function(response) {
$("#response").html(response);
$("#response").fadeIn(600, function() {
$("#response").fadeIn(600, function() {
$("#response").css("display", "block");
});
setTimeout(function() {
$("#response").fadeOut(600, function() {
});
setTimeout(function() {
$("#response").fadeOut(600, function() {
$("#response").css("display", "none");
});
}, 3000);
}, 3000);
}
});
}
$(document).ready(function() {
setInterval(updateData, 60000);
setInterval(updateData, saveInterval);
});