Browse Source

Draft for pages and subpages

pull/674/head
danpros 1 year ago
parent
commit
0ec68537c5
10 changed files with 387 additions and 112 deletions
  1. +180
    -29
      system/admin/admin.php
  2. +1
    -1
      system/admin/views/add-page.html.php
  3. +2
    -1
      system/admin/views/delete-category.html.php
  4. +2
    -1
      system/admin/views/delete-page.html.php
  5. +2
    -2
      system/admin/views/delete-post.html.php
  6. +10
    -4
      system/admin/views/edit-page.html.php
  7. +47
    -44
      system/admin/views/static-pages.html.php
  8. +44
    -0
      system/admin/views/user-draft.html.php
  9. +56
    -27
      system/htmly.php
  10. +43
    -3
      system/includes/functions.php

+ 180
- 29
system/admin/admin.php View File

@ -1,6 +1,8 @@
<?php
if (!defined('HTMLY')) die('HTMLy');
use \Michelf\MarkdownExtra;
// Return username.ini value
function user($key, $user = null)
{
@ -351,18 +353,15 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
$dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/';
$dirScheduled = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/' . $type . '/scheduled/';
if (is_dir($dirBlog)) {
} else {
if (!is_dir($dirBlog)) {
mkdir($dirBlog, 0775, true);
}
if (is_dir($dirDraft)) {
} else {
if (!is_dir($dirDraft)) {
mkdir($dirDraft, 0775, true);
}
if (is_dir($dirScheduled)) {
} else {
if (!is_dir($dirScheduled)) {
mkdir($dirScheduled, 0775, true);
}
@ -490,7 +489,7 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
}
// Add static page
function add_page($title, $url, $content, $description = null)
function add_page($title, $url, $content, $draft, $description = null)
{
$post_title = safe_html($title);
@ -522,22 +521,37 @@ function add_page($title, $url, $content, $description = null)
$filename = $post_url . '.md';
$dir = 'content/static/';
if (is_dir($dir)) {
file_put_contents($dir . $filename, print_r($post_content, true));
} else {
$dirDraft = 'content/static/draft/';
if (!is_dir($dir)) {
mkdir($dir, 0775, true);
}
if (!is_dir($dirDraft)) {
mkdir($dirDraft, 0775, true);
}
if (empty($draft)) {
file_put_contents($dir . $filename, print_r($post_content, true));
} else {
file_put_contents($dirDraft . $filename, print_r($post_content, true));
}
rebuilt_cache('all');
clear_page_cache($post_url);
$redirect = site_url() . 'admin/pages';
header("Location: $redirect");
if (empty($draft)) {
$redirect = site_url() . 'admin/pages';
header("Location: $redirect");
} else {
$redirect = site_url() . 'admin/draft';
header("Location: $redirect");
}
}
}
// Add static sub page
function add_sub_page($title, $url, $content, $static, $description = null)
function add_sub_page($title, $url, $content, $static, $draft, $description = null)
{
$post_title = safe_html($title);
@ -558,11 +572,20 @@ function add_sub_page($title, $url, $content, $static, $description = null)
$filename = $post_url . '.md';
$dir = 'content/static/' . $static . '/';
if (is_dir($dir)) {
file_put_contents($dir . $filename, print_r($post_content, true));
} else {
$dirDraft = 'content/static/' . $static . '/draft/';
if (!is_dir($dir)) {
mkdir($dir, 0775, true);
}
if (!is_dir($dirDraft)) {
mkdir($dirDraft, 0775, true);
}
if (empty($draft)) {
file_put_contents($dir . $filename, print_r($post_content, true));
} else {
file_put_contents($dirDraft . $filename, print_r($post_content, true));
}
rebuilt_cache('all');
@ -573,9 +596,9 @@ function add_sub_page($title, $url, $content, $static, $description = null)
}
// Edit static page and sub page
function edit_page($title, $url, $content, $oldfile, $destination = null, $description = null, $static = null)
function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination = null, $description = null, $static = null)
{
$dir = substr($oldfile, 0, strrpos($oldfile, '/'));
$dir = pathinfo($oldfile, PATHINFO_DIRNAME);
$views = array();
$viewsFile = "content/data/views.json";
$post_title = safe_html($title);
@ -594,20 +617,41 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
$newfile = $dir . '/' . $post_url . '.md';
if ($oldfile === $newfile) {
file_put_contents($oldfile, print_r($post_content, true));
} else {
rename($oldfile, $newfile);
if(!empty($revertPage)) {
$newfile = $dir . '/draft/' . $post_url . '.md';
file_put_contents($newfile, print_r($post_content, true));
if (empty($static)) {
$old = pathinfo($oldfile, PATHINFO_FILENAME);
if(is_dir($dir . '/' . $old)) {
rename($dir . '/' . $old, $dir . '/' . $post_url);
}
}
unlink($oldfile);
} elseif(!empty($publishDraft)) {
$newfile = dirname($dir) . '/' . $post_url . '.md';
file_put_contents($newfile, print_r($post_content, true));
if (empty($static)) {
$path = pathinfo($oldfile);
$old = substr($path['filename'], strrpos($path['filename'], '/'));
$old = pathinfo($oldfile, PATHINFO_FILENAME);
if(is_dir($dir . '/' . $old)) {
rename($dir . '/' . $old, $dir . '/' . $post_url);
}
}
unlink($oldfile);
}else {
$newfile = $dir . '/' . $post_url . '.md';
if ($oldfile === $newfile) {
file_put_contents($oldfile, print_r($post_content, true));
} else {
rename($oldfile, $newfile);
file_put_contents($newfile, print_r($post_content, true));
if (empty($static)) {
$old = pathinfo($oldfile, PATHINFO_FILENAME);
if(is_dir($dir . '/' . $old)) {
rename($dir . '/' . $old, $dir . '/' . $post_url);
}
}
}
}
if (!empty($static)) {
@ -628,7 +672,12 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr
}
if ($destination == 'post') {
header("Location: $posturl");
if(!empty($revertPage)) {
$drafturl = site_url() . 'admin/draft';
header("Location: $drafturl");
} else {
header("Location: $posturl");
}
} else {
$redirect = site_url() . $destination;
header("Location: $redirect");
@ -639,7 +688,6 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr
// Add category
function add_category($title, $url, $content, $description = null)
{
$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);
@ -675,7 +723,7 @@ function add_category($title, $url, $content, $description = null)
// Edit category
function edit_category($title, $url, $content, $oldfile, $destination = null, $description = null)
{
$dir = substr($oldfile, 0, strrpos($oldfile, '/'));
$dir = pathinfo($oldfile, PATHINFO_DIRNAME);
$post_title = safe_html($title);
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
@ -1154,3 +1202,106 @@ function rename_category_folder($new_name, $old_file)
}
}
// Return static page.
function find_draft_pages($static = null)
{
$posts = get_draft_pages();
$tmp = array();
if (!empty($posts)) {
foreach ($posts as $index => $v) {
if (stripos($v['basename'], $static . '.md') !== false) {
$post = new stdClass;
// The static page URL
$url= $v['filename'];
$post->url = site_url() . $url;
$post->file = $v['dirname'] . '/' . $v['basename'];
$post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file)));
$post->md = $url;
// Get the contents and convert it to HTML
$content = file_get_contents($post->file);
// Extract the title and body
$post->title = get_content_tag('t', $content, 'Untitled static page: ' . format_date($post->lastMod, 'l, j F Y, H:i'));
// Get the contents and convert it to HTML
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
if (config('views.counter') == 'true') {
$post->views = get_views($post->file);
}
$post->description = get_content_tag("d", $content, get_description($post->body));
$word_count = str_word_count(strip_tags($post->body));
$post->readTime = ceil($word_count / 200);
$tmp[] = $post;
}
}
}
return $tmp;
}
// Return static page.
function find_draft_subpages($static = null, $sub_static = null)
{
$posts = get_draft_subpages();
$tmp = array();
if (!empty($posts)) {
foreach ($posts as $index => $v) {
if (stripos($v['basename'], $sub_static . '.md') !== false) {
$post = new stdClass;
if (is_null($static)) {
$static = str_replace('content/static/', '', dirname($v['dirname']));
}
// The static page URL
$url= $v['filename'];
$post->url = site_url() . $static . "/" . $url;
$post->file = $v['dirname'] . '/' . $v['basename'];
$post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file)));
$post->md = $url;
$post->parent = $static;
// Get the contents and convert it to HTML
$content = file_get_contents($post->file);
// Extract the title and body
$post->title = get_content_tag('t', $content, 'Untitled static subpage: ' . format_date($post->lastMod, 'l, j F Y, H:i'));
// Get the contents and convert it to HTML
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
$post->views = get_views($post->file);
$post->description = get_content_tag("d", $content, get_description($post->body));
$word_count = str_word_count(strip_tags($post->body));
$post->readTime = ceil($word_count / 200);
$tmp[] = $post;
}
}
}
return $tmp;
}

+ 1
- 1
system/admin/views/add-page.html.php View File

@ -42,7 +42,7 @@
<br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($type == 'is_page') :?>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Publish');?>"/>
<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') :?>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Add_category');?>"/>


+ 2
- 1
system/admin/views/delete-category.html.php View File

@ -21,8 +21,9 @@ if (isset($destination)) {
} else {
$back = site_url();
}
$info = $p->title . ' (' . $p->file . ')';
?>
<p><?php echo sprintf(i18n('Are_you_sure_you_want_to_delete_'), $p->title);?></p>
<p><?php echo sprintf(i18n('Are_you_sure_you_want_to_delete_'), $info);?></p>
<form method="POST">
<input type="hidden" name="file" value="<?php echo $p->file ?>"/><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">


+ 2
- 1
system/admin/views/delete-page.html.php View File

@ -21,8 +21,9 @@ if (isset($destination)) {
} else {
$back = site_url();
}
$info = $p->title . ' (' . $p->file . ')';
?>
<p><?php echo sprintf(i18n('Are_you_sure_you_want_to_delete_'), $p->title);?></p>
<p><?php echo sprintf(i18n('Are_you_sure_you_want_to_delete_'), $info);?></p>
<form method="POST">
<input type="hidden" name="file" value="<?php echo $p->file ?>"/><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">


+ 2
- 2
system/admin/views/delete-post.html.php View File

@ -28,9 +28,9 @@ if (isset($destination)) {
} else {
$back = site_url();
}
$info = $p->title . ' (' . $p->file . ')';
?>
<p><?php echo sprintf(i18n('Are_you_sure_you_want_to_delete_'), $p->title);?></p>
<p><?php echo sprintf(i18n('Are_you_sure_you_want_to_delete_'), $info);?></p>
<form method="POST">
<input type="hidden" name="file" value="<?php echo $p->file ?>"/><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">


+ 10
- 4
system/admin/views/edit-page.html.php View File

@ -46,9 +46,9 @@ if ($type == 'is_frontpage') {
} else {
$destination = 'admin';
}
$dir = substr($url, 0, strrpos($url, '/'));
$oldurl = str_replace($dir . '/', '', $url);
$oldmd = str_replace('.md', '', $oldurl);
$dir = pathinfo($url, PATHINFO_DIRNAME);
$oldurl = pathinfo($url, PATHINFO_BASENAME);
$oldmd = pathinfo($url, PATHINFO_FILENAME);
if (isset($p->url)) {
$delete = $p->url . '/delete?destination=' . $destination;
@ -118,7 +118,13 @@ $images = get_gallery();
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save_category');?>"/>
<?php } else {?>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save');?>"/> <a class="btn btn-danger" href="<?php echo $delete ?>"><?php echo i18n('Delete');?></a>
<?php $count = count(get_static_sub_post($oldmd)); ?>
<?php if (stripos($dir . '/', '/draft/') !== false) { ?>
<input type="submit" name="publishdraft" class="btn btn-primary submit" value="<?php echo i18n('Publish_draft');?>"/> <input type="submit" name="updatedraft" class="btn btn-primary draft" value="<?php echo i18n('Update_draft');?>"/> <?php if ($count == 0 && $type != 'is_page'):?><a class="btn btn-danger" href="<?php echo $delete ?>"><?php echo i18n('Delete');?></a><?php endif;?>
<?php } else { ?>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save');?>"/> <input type="submit" name="revertpage" class="btn btn-primary revert" value="<?php echo i18n('Revert_to_draft');?>"/> <?php if ($count == 0 && $type != 'is_page'):?><a class="btn btn-danger" href="<?php echo $delete ?>"><?php echo i18n('Delete');?></a><?php endif;?>
<?php } ?>
<?php } ?>
</div>
<div class="col-sm-6">


+ 47
- 44
system/admin/views/static-pages.html.php View File

@ -3,48 +3,51 @@
<br>
<a class="btn btn-primary right" href="<?php echo site_url();?>add/page"><?php echo i18n('Add_new_page');?></a>
<br><br>
<?php
<?php if (isset($_SESSION[config("site.url")]['user'])):?>
<?php $posts = get_static_post();
if (!empty($posts)): ?>
<table class="table post-list">
<tr class="head">
<th><?php echo i18n('Title');?> </th>
<?php if (config("views.counter") == "true"):?>
<th><?php echo i18n('Views');?></th>
<?php endif;?>
<th><?php echo i18n('Operations');?></th>
<th>Sub Pages</th>
</tr>
<?php foreach ($posts as $p):?>
<?php $count = count(get_static_sub_post($p->md)); ?>
<tr>
<td><a target="_blank" href="<?php echo $p->url;?>"><?php echo $p->title;?></a></td>
<?php if (config("views.counter") == "true"):?>
<td><?php echo $p->views;?></td>
<?php endif;?>
<td><a class="btn btn-primary btn-xs" href="<?php echo $p->url;?>/add?destination=admin/pages"><?php echo i18n('Add_sub');?></a> <a class="btn btn-primary btn-xs" href="<?php echo $p->url;?>/edit?destination=admin/pages"><?php echo i18n('Edit');?></a> <?php if ($count == 0):?><a class="btn btn-danger btn-xs" href="<?php echo $p->url;?>/delete?destination=admin/pages"><?php echo i18n('Delete');?></a><?php endif;?></td>
<td>
<table>
<?php $subPages = get_static_sub_post($p->md);
foreach ($subPages as $sp):?>
<div class="row">
<div class="col-6 col-md-4">
<span><a target="_blank" href="<?php echo $sp->url;?>"><?php echo $sp->title;?></a></span>
</div>
<div class="col-6 col-md-4">
<?php if (config("views.counter") == "true"):?>
<span><i class="nav-icon fa fa-line-chart"></i> <?php echo $sp->views;?></span>
<?php endif;?></div>
<div class="col-6 col-md-4">
<span><a class="btn btn-primary btn-xs" href="<?php echo $sp->url;?>/edit?destination=admin/pages"><?php echo i18n('Edit');?></a> <a class="btn btn-danger btn-xs" href="<?php echo $sp->url;?>/delete?destination=admin/pages"><?php echo i18n('Delete');?></a></span>
</div>
</div>
<?php endforeach;?>
</table>
</td>
</tr>
if (isset($_SESSION[config("site.url")]['user'])) {
$posts = get_static_post(null);
if (!empty($posts)) {
echo '<table class="table post-list">';
echo '<tr class="head"><th>' . i18n('Title') . '</th>';
if (config("views.counter") == "true")
echo '<th>'.i18n('Views').'</th>';
echo '<th>' . i18n('Operations') . '</th></tr>';
$i = 0;
$len = count($posts);
foreach ($posts as $p) {
if ($i == 0) {
$class = 'item first';
} elseif ($i == $len - 1) {
$class = 'item last';
} else {
$class = 'item';
}
$i++;
echo '<tr class="' . $class . '">';
echo '<td><a target="_blank" href="' . $p->url . '">' . $p->title . '</a></td>';
if (config("views.counter") == "true")
echo '<td>' . $p->views . '</td>';
echo '<td><a class="btn btn-primary btn-xs" href="' . $p->url . '/add?destination=admin/pages">' . i18n('Add_sub') . '</a> <a class="btn btn-primary btn-xs" href="' . $p->url . '/edit?destination=admin/pages">' . i18n('Edit') . '</a> <a class="btn btn-danger btn-xs" href="' . $p->url . '/delete?destination=admin/pages">' . i18n('Delete') . '</a></td>';
echo '</tr>';
$subPages = get_static_sub_post($p->md);
foreach ($subPages as $sp) {
echo '<tr class="' . $class . '">';
echo '<td> <span style="margin-left:30px;">&raquo; <a target="_blank" href="' . $sp->url . '">' . $sp->title . '</a></span></td>';
if (config("views.counter") == "true")
echo '<td>' . $sp->views . '</td>';
echo '<td><a class="btn btn-primary btn-xs" href="' . $sp->url . '/edit?destination=admin/pages">' . i18n('Edit') . '</a> <a class="btn btn-danger btn-xs" href="' . $sp->url . '/delete?destination=admin/pages">' . i18n('Delete') . '</a></td>';
echo '</tr>';
}
}
echo '</table>';
}
}
?>
<?php endforeach;?>
</table>
<?php endif;?>
<?php endif;?>

+ 44
- 0
system/admin/views/user-draft.html.php View File

@ -43,3 +43,47 @@
<?php } else {
echo i18n('No_draft_found') . '!';
} ?>
<?php if (!empty($draftPages)):?>
<br><br>
<hr>
<h2 class="post-index"><?php echo i18n('Draft');?>: <?php echo i18n('Static_pages');?></h2>
<table class="table post-list">
<tr class="head">
<th><?php echo i18n('Title');?></th>
<th><?php echo i18n('Created');?></th>
<th><?php echo i18n('Operations');?></th>
</tr>
<?php foreach ($draftPages as $d): ?>
<?php $count = count(get_static_sub_post($d->md)); ?>
<tr>
<td><?php echo $d->title ?></td>
<td><?php echo format_date($d->lastMod) ?></td>
<td><a class="btn btn-primary btn-xs" href="<?php echo $d->url ?>/edit?destination=admin/draft"><?php echo i18n('Edit');?></a> <?php if ($count == 0):?><a class="btn btn-danger btn-xs" href="<?php echo $d->url ?>/delete?destination=admin/draft"><?php echo i18n('Delete');?></a><?php endif;?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif;?>
<?php if (!empty($draftSubpages)):?>
<br><br>
<hr>
<h2 class="post-index"><?php echo i18n('Draft');?>: Sub</h2>
<table class="table post-list">
<tr class="head">
<th><?php echo i18n('Title');?></th>
<th><?php echo i18n('Created');?></th>
<th><?php echo i18n('Operations');?></th>
<th><?php echo i18n('Static_pages');?></th>
</tr>
<?php foreach ($draftSubpages as $sp): ?>
<?php $parent = get_static_post($sp->parent);?>
<tr>
<td><?php echo $sp->title ?></td>
<td><?php echo format_date($sp->lastMod) ?></td>
<td><a class="btn btn-primary btn-xs" href="<?php echo $sp->url ?>/edit?destination=admin/draft"><?php echo i18n('Edit');?></a> <a class="btn btn-danger btn-xs" href="<?php echo $sp->url ?>/delete?destination=admin/draft"><?php echo i18n('Delete');?></a></td>
<td><a href="<?php echo $parent['current']->url;?>"><?php echo $parent['current']->title;?></a></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif;?>

+ 56
- 27
system/htmly.php View File

@ -616,12 +616,13 @@ post('/add/page', function () {
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$description = from($_REQUEST, 'description');
$draft = from($_REQUEST, 'draft');
if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
add_page($title, $url, $content, $description);
add_page($title, $url, $content, $draft, $description);
} else {
$url = $title;
add_page($title, $url, $content, $description);
add_page($title, $url, $content, $draft, $description);
}
} else {
$message['error'] = '';
@ -936,6 +937,10 @@ get('/admin/draft', function () {
$perpage = config('profile.perpage');
$posts = get_draft($name, $page, $perpage);
$draftPages = find_draft_pages();
$draftSubpages = find_draft_subpages();
$total = get_draftcount($name);
@ -955,6 +960,8 @@ get('/admin/draft', function () {
'page' => $page,
'heading' => i18n('My_draft'),
'posts' => null,
'draftPages' => $draftPages,
'draftSubpages' => $draftSubpages,
'about' => $author->about,
'name' => $author->name,
'type' => 'is_admin-draft',
@ -965,7 +972,7 @@ get('/admin/draft', function () {
));
die;
}
render('user-draft', array(
'title' => i18n('My_draft') . ' - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -973,6 +980,8 @@ get('/admin/draft', function () {
'heading' => i18n('My_draft'),
'page' => $page,
'posts' => $posts,
'draftPages' => $draftPages,
'draftSubpages' => $draftSubpages,
'about' => $author->about,
'name' => $author->name,
'type' => 'is_admin-draft',
@ -1752,11 +1761,6 @@ get('/admin/categories/:category', function ($category) {
$total = $desc->count;
if (empty($posts) || $page < 1) {
// a non-existing page
not_found();
}
render('category-list', array(
'title' => $desc->title . ' - ' . blog_title(),
'description' => $desc->description,
@ -2381,7 +2385,7 @@ get('/post/:name', function ($name) {
} else {
$blog = '';
}
$vroot = rtrim(config('views.root'), '/');
$lt = $vroot . '/layout--post--' . $current->ct . '.html.php';
@ -2961,12 +2965,13 @@ post('/:static/add', function ($static) {
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$description = from($_REQUEST, 'description');
$draft = from($_REQUEST, 'draft');
if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
add_sub_page($title, $url, $content, $static, $description);
add_sub_page($title, $url, $content, $static, $draft, $description);
} else {
$url = $title;
add_sub_page($title, $url, $content, $static, $description);
add_sub_page($title, $url, $content, $static, $draft, $description);
}
} else {
$message['error'] = '';
@ -3005,11 +3010,16 @@ get('/:static/edit', function ($static) {
$post = get_static_post($static);
if (!$post) {
not_found();
$post = find_draft_pages($static);
if (!$post) {
not_found();
} else {
$post = $post[0];
}
} else {
$post = $post['current'];
}
$post = $post['current'];
render('edit-page', array(
'title' => i18n('Edit') . ': ' . $post->title . ' - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -3042,12 +3052,14 @@ post('/:static/edit', function () {
$oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
$revertPage = from($_REQUEST, 'revertpage');
$publishDraft = from($_REQUEST, 'publishdraft');
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
edit_page($title, $url, $content, $oldfile, $destination, $description);
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description);
} else {
$url = $title;
edit_page($title, $url, $content, $oldfile, $destination, $description);
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description);
}
} else {
$message['error'] = '';
@ -3087,11 +3099,16 @@ get('/:static/delete', function ($static) {
$post = get_static_post($static);
if (!$post) {
not_found();
$post = find_draft_pages($static);
if (!$post) {
not_found();
} else {
$post = $post[0];
}
} else {
$post = $post['current'];
}
$post = $post['current'];
render('delete-page', array(
'title' => i18n('Delete') . ': ' . $post->title . ' - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -3222,11 +3239,16 @@ get('/:static/:sub/edit', function ($static, $sub) {
$page = get_static_sub_post($static, $sub);
if (!$page) {
not_found();
$page = find_draft_subpages($static, $sub);
if (!$page) {
not_found();
} else {
$page = $page[0];
}
} else {
$page = $page['current'];
}
$page = $page['current'];
render('edit-page', array(
'title' => i18n('Edit') . ': ' . $page->title . ' - ' . blog_title(),
'description' => strip_tags(blog_description()),
@ -3259,15 +3281,17 @@ post('/:static/:sub/edit', function ($static, $sub) {
$oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
$revertPage = from($_REQUEST, 'revertpage');
$publishDraft = from($_REQUEST, 'publishdraft');
if ($destination === null) {
$destination = $static . "/" . $sub;
}
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
edit_page($title, $url, $content, $oldfile, $destination, $description, $static);
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static);
} else {
$url = $title;
edit_page($title, $url, $content, $oldfile, $destination, $description, $static);
edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft, $destination, $description, $static);
}
} else {
$message['error'] = '';
@ -3317,11 +3341,16 @@ get('/:static/:sub/delete', function ($static, $sub) {
$page = get_static_sub_post($static, $sub);
if (!$page) {
not_found();
$page = find_draft_subpages($static, $sub);
if (!$page) {
not_found();
} else {
$page = $page[0];
}
} else {
$page = $page['current'];
}
$page = $page['current'];
render('delete-page', array(
'title' => i18n('Delete') . ': ' . $page->title . ' - ' . blog_title(),
'description' => strip_tags(blog_description()),


+ 43
- 3
system/includes/functions.php View File

@ -110,6 +110,40 @@ function get_draft_posts()
return $_draft;
}
// Get static page draft.
function get_draft_pages()
{
static $_draftPage = array();
if (empty($_draftPage)) {
$tmp = array();
$tmp = glob('content/static/draft/*.md', GLOB_NOSORT);
if (is_array($tmp)) {
foreach ($tmp as $file) {
$_draftPage[] = pathinfo($file);
}
}
usort($_draftPage, "sortfile_a");
}
return $_draftPage;
}
// Get static subpage draft.
function get_draft_subpages()
{
static $_draftSubpage = array();
if (empty($_draftSubpage)) {
$tmp = array();
$tmp = glob('content/static/*/draft/*.md', GLOB_NOSORT);
if (is_array($tmp)) {
foreach ($tmp as $file) {
$_draftSubpage[] = pathinfo($file);
}
}
usort($_draftSubpage, "sortfile_a");
}
return $_draftSubpage;
}
// Get scheduled posts.
function get_scheduled_posts()
{
@ -221,7 +255,9 @@ function rebuilt_cache($type = null)
$ptmp = glob('content/static/*.md', GLOB_NOSORT);
if (is_array($ptmp)) {
foreach ($ptmp as $file) {
$page_cache[] = pathinfo($file);
if(strpos($file, '/draft/') === false) {
$page_cache[] = pathinfo($file);
}
}
}
usort($page_cache, "sortfile_a");
@ -233,7 +269,9 @@ function rebuilt_cache($type = null)
$sptmp = glob('content/static/*/*.md', GLOB_NOSORT);
if (is_array($sptmp)) {
foreach ($sptmp as $file) {
$subpage_cache[] = pathinfo($file);
if(strpos($file, '/draft/') === false) {
$subpage_cache[] = pathinfo($file);
}
}
}
usort($subpage_cache, "sortfile_a");
@ -1048,6 +1086,8 @@ function default_profile($name)
function get_static_post($static = null)
{
$pages = get_static_pages();
$tmp = array();
if (!empty($pages)) {
@ -1084,7 +1124,7 @@ function get_static_post($static = null)
$post->readTime = ceil($word_count / 200);
$tmp[] = $post;
} elseif (stripos($v['basename'], $static . '.md') !== false) {
// Use the get_posts method to return


Loading…
Cancel
Save