mirror of
https://github.com/danpros/htmly.git
synced 2026-04-17 19:26:08 +05:30
Improve page draft
This commit is contained in:
parent
a8e7ede67d
commit
66efbf54cf
4 changed files with 91 additions and 90 deletions
|
|
@ -574,17 +574,15 @@ function add_sub_page($title, $url, $content, $static, $draft, $description = nu
|
|||
$dir = 'content/static/' . $static . '/';
|
||||
$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 (!is_dir($dir)) {
|
||||
mkdir($dir, 0775, true);
|
||||
}
|
||||
file_put_contents($dir . $filename, print_r($post_content, true));
|
||||
} else {
|
||||
if (!is_dir($dirDraft)) {
|
||||
mkdir($dirDraft, 0775, 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));
|
||||
if (empty($static)) {
|
||||
$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.
|
||||
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();
|
||||
|
||||
|
|
@ -1344,43 +1335,42 @@ function find_draft_subpage($sub_static = null)
|
|||
foreach ($posts as $index => $v) {
|
||||
if (stripos($v['basename'], $sub_static . '.md') !== false) {
|
||||
|
||||
$static = str_replace('content/static/', '', dirname($v['dirname']));
|
||||
$post = new stdClass;
|
||||
|
||||
$spage = find_page($static);
|
||||
// The static file
|
||||
$url= $v['filename'];
|
||||
|
||||
if ($spage) {
|
||||
|
||||
$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;
|
||||
|
||||
// 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;
|
||||
$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);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,43 +8,44 @@
|
|||
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>
|
||||
<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(find_subpage($p->md)); ?>
|
||||
<?php $dd = find_subpage($p->md); ?>
|
||||
<?php $dr = find_draft_subpage($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 = 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>
|
||||
|
||||
<?php endforeach;?>
|
||||
|
|
|
|||
|
|
@ -3350,7 +3350,7 @@ get('/:static/:sub/edit', function ($static, $sub) {
|
|||
$page = find_subpage($static, $sub);
|
||||
|
||||
if (!$page) {
|
||||
$page = find_draft_subpage($sub);
|
||||
$page = find_draft_subpage($static, $sub);
|
||||
if (!$page) {
|
||||
not_found();
|
||||
} else {
|
||||
|
|
@ -3452,7 +3452,7 @@ get('/:static/:sub/delete', function ($static, $sub) {
|
|||
$page = find_subpage($static, $sub);
|
||||
|
||||
if (!$page) {
|
||||
$page = find_draft_subpage($sub);
|
||||
$page = find_draft_subpage($static, $sub);
|
||||
if (!$page) {
|
||||
not_found();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ function get_draft_pages()
|
|||
}
|
||||
|
||||
// Get static subpage draft.
|
||||
function get_draft_subpages()
|
||||
function get_draft_subpages($static = null)
|
||||
{
|
||||
static $_draftSubpage = array();
|
||||
if (empty($_draftSubpage)) {
|
||||
|
|
@ -141,6 +141,16 @@ function get_draft_subpages()
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -1086,11 +1096,11 @@ function get_author($name)
|
|||
|
||||
// Get the contents and convert it to HTML
|
||||
$author->about = MarkdownExtra::defaultTransform(remove_html_comments($content));
|
||||
|
||||
|
||||
$author->body = $author->about;
|
||||
|
||||
|
||||
$author->title = $author->name;
|
||||
|
||||
|
||||
$author->description = $author->about;
|
||||
|
||||
$tmp[] = $author;
|
||||
|
|
@ -2557,7 +2567,7 @@ function generate_rss($posts, $data = null)
|
|||
$channel = new Channel();
|
||||
$rssLength = config('rss.char');
|
||||
$data = $data;
|
||||
|
||||
|
||||
if (is_null($data)) {
|
||||
$channel
|
||||
->title(blog_title())
|
||||
|
|
@ -2569,7 +2579,7 @@ function generate_rss($posts, $data = null)
|
|||
->title($data->title)
|
||||
->description(strip_tags($data->body))
|
||||
->url($data->url)
|
||||
->appendTo($feed);
|
||||
->appendTo($feed);
|
||||
}
|
||||
foreach ($posts as $p) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue