diff --git a/system/admin/admin.php b/system/admin/admin.php index cd73c89..f1b588b 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -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'])); - - $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->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; } } } diff --git a/system/admin/views/static-pages.html.php b/system/admin/views/static-pages.html.php index 5fab852..8660c6f 100644 --- a/system/admin/views/static-pages.html.php +++ b/system/admin/views/static-pages.html.php @@ -8,43 +8,44 @@ if (!empty($posts)): ?> - - - - - - - + + + + + + + - md)); ?> + md); ?> + md);?> - - - - - - + + + + + + diff --git a/system/htmly.php b/system/htmly.php index 69be11c..bcf1f8d 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -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 { diff --git a/system/includes/functions.php b/system/includes/functions.php index fcea146..05582b0 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -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) {
Sub Pages
Sub Pages
title;?>views;?> - - md); - foreach ($subPages as $sp):?> - -
-
- title;?> -
-
- - views;?> -
-
- -
-
- - - -
-
title;?> views;?> + + md); + foreach ($subPages as $sp):?> + +
+
+ title;?> +
+
+ + views;?> +
+
+ +
+
+ + + +
+