Browse Source

Improve page draft

pull/674/head
danpros 1 year ago
parent
commit
66efbf54cf
4 changed files with 91 additions and 90 deletions
  1. +37
    -47
      system/admin/admin.php
  2. +36
    -35
      system/admin/views/static-pages.html.php
  3. +2
    -2
      system/htmly.php
  4. +16
    -6
      system/includes/functions.php

+ 37
- 47
system/admin/admin.php View File

@ -574,17 +574,15 @@ function add_sub_page($title, $url, $content, $static, $draft, $description = nu
$dir = 'content/static/' . $static . '/'; $dir = 'content/static/' . $static . '/';
$dirDraft = 'content/static/' . $static . '/draft/'; $dirDraft = 'content/static/' . $static . '/draft/';
if (!is_dir($dir)) {
mkdir($dir, 0775, true);
}
if (!is_dir($dirDraft)) {
mkdir($dirDraft, 0775, true);
}
if (empty($draft)) { if (empty($draft)) {
if (!is_dir($dir)) {
mkdir($dir, 0775, true);
}
file_put_contents($dir . $filename, print_r($post_content, true)); file_put_contents($dir . $filename, print_r($post_content, true));
} else { } else {
if (!is_dir($dirDraft)) {
mkdir($dirDraft, 0775, true);
}
file_put_contents($dirDraft . $filename, print_r($post_content, true)); file_put_contents($dirDraft . $filename, print_r($post_content, true));
} }
@ -651,16 +649,9 @@ function edit_page($title, $url, $content, $oldfile, $revertPage, $publishDraft,
file_put_contents($newfile, print_r($post_content, true)); file_put_contents($newfile, print_r($post_content, true));
if (empty($static)) { if (empty($static)) {
$old = pathinfo($oldfile, PATHINFO_FILENAME); $old = pathinfo($oldfile, PATHINFO_FILENAME);
$dd = explode('/', $dir);
if ($dd[2] === 'draft') {
if(is_dir(dirname($dir) . '/' . $old)) {
rename(dirname($dir) . '/' . $old, dirname($dir) . '/' . $post_url);
}
} else {
if(is_dir($dir . '/' . $old)) {
rename($dir . '/' . $old, $dir . '/' . $post_url);
}
}
if(is_dir($dir . '/' . $old)) {
rename($dir . '/' . $old, $dir . '/' . $post_url);
}
} }
} }
} }
@ -1333,9 +1324,9 @@ function find_draft_page($static = null)
} }
// Return draft static subpage. // Return draft static subpage.
function find_draft_subpage($sub_static = null)
function find_draft_subpage($static = null, $sub_static = null)
{ {
$posts = get_draft_subpages();
$posts = get_draft_subpages($static);
$tmp = array(); $tmp = array();
@ -1344,43 +1335,42 @@ function find_draft_subpage($sub_static = null)
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
if (stripos($v['basename'], $sub_static . '.md') !== false) { if (stripos($v['basename'], $sub_static . '.md') !== false) {
$static = str_replace('content/static/', '', dirname($v['dirname']));
$spage = find_page($static);
$post = new stdClass;
if ($spage) {
// The static file
$url= $v['filename'];
$post = new stdClass;
// 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;
if (is_null($static)) {
$parent = str_replace('content/static/', '', dirname($v['dirname']));
$post->parent = $parent;
$post->url = site_url() . $parent . "/" . $url;
} else {
$post->parent = $static; $post->parent = $static;
$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;
// Get the contents and convert it to HTML
$content = file_get_contents($post->file);
// 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'));
// 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));
// Get the contents and convert it to HTML
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
$post->views = get_views($post->file);
$post->views = get_views($post->file);
$post->description = get_content_tag("d", $content, get_description($post->body));
$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);
$word_count = str_word_count(strip_tags($post->body));
$post->readTime = ceil($word_count / 200);
$tmp[] = $post;
}
$tmp[] = $post;
} }
} }
} }


+ 36
- 35
system/admin/views/static-pages.html.php View File

@ -8,43 +8,44 @@
if (!empty($posts)): ?> if (!empty($posts)): ?>
<table class="table post-list"> <table class="table post-list">
<tr class="head"> <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>
<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 foreach ($posts as $p):?>
<?php $count = count(find_subpage($p->md)); ?>
<?php $dd = find_subpage($p->md); ?>
<?php $dr = find_draft_subpage($p->md);?>
<tr> <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 = find_subpage($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>
<td><a target="_blank" href="<?php echo $p->url;?>"><?php echo $p->title;?></a></td>
<?php if (config("views.counter") == "true"):?>
<td><i class="nav-icon fa fa-line-chart"></i> <?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 (empty($dd) && empty($dr)):?><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 = find_subpage($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> </tr>
<?php endforeach;?> <?php endforeach;?>


+ 2
- 2
system/htmly.php View File

@ -3350,7 +3350,7 @@ get('/:static/:sub/edit', function ($static, $sub) {
$page = find_subpage($static, $sub); $page = find_subpage($static, $sub);
if (!$page) { if (!$page) {
$page = find_draft_subpage($sub);
$page = find_draft_subpage($static, $sub);
if (!$page) { if (!$page) {
not_found(); not_found();
} else { } else {
@ -3452,7 +3452,7 @@ get('/:static/:sub/delete', function ($static, $sub) {
$page = find_subpage($static, $sub); $page = find_subpage($static, $sub);
if (!$page) { if (!$page) {
$page = find_draft_subpage($sub);
$page = find_draft_subpage($static, $sub);
if (!$page) { if (!$page) {
not_found(); not_found();
} else { } else {


+ 16
- 6
system/includes/functions.php View File

@ -128,7 +128,7 @@ function get_draft_pages()
} }
// Get static subpage draft. // Get static subpage draft.
function get_draft_subpages()
function get_draft_subpages($static = null)
{ {
static $_draftSubpage = array(); static $_draftSubpage = array();
if (empty($_draftSubpage)) { if (empty($_draftSubpage)) {
@ -141,6 +141,16 @@ function get_draft_subpages()
} }
usort($_draftSubpage, "sortfile_a"); usort($_draftSubpage, "sortfile_a");
} }
if ($static != null) {
$stringLen = strlen($static);
return array_filter($_draftSubpage, function ($sub_page) use ($static, $stringLen) {
$x = explode("/", $sub_page['dirname']);
if ($x[2] == $static) {
return true;
}
return false;
});
}
return $_draftSubpage; return $_draftSubpage;
} }
@ -1086,11 +1096,11 @@ function get_author($name)
// Get the contents and convert it to HTML // Get the contents and convert it to HTML
$author->about = MarkdownExtra::defaultTransform(remove_html_comments($content)); $author->about = MarkdownExtra::defaultTransform(remove_html_comments($content));
$author->body = $author->about; $author->body = $author->about;
$author->title = $author->name; $author->title = $author->name;
$author->description = $author->about; $author->description = $author->about;
$tmp[] = $author; $tmp[] = $author;
@ -2557,7 +2567,7 @@ function generate_rss($posts, $data = null)
$channel = new Channel(); $channel = new Channel();
$rssLength = config('rss.char'); $rssLength = config('rss.char');
$data = $data; $data = $data;
if (is_null($data)) { if (is_null($data)) {
$channel $channel
->title(blog_title()) ->title(blog_title())
@ -2569,7 +2579,7 @@ function generate_rss($posts, $data = null)
->title($data->title) ->title($data->title)
->description(strip_tags($data->body)) ->description(strip_tags($data->body))
->url($data->url) ->url($data->url)
->appendTo($feed);
->appendTo($feed);
} }
foreach ($posts as $p) { foreach ($posts as $p) {


Loading…
Cancel
Save