From 41d46178477e5f7c8957ccf2ad38120a4f1da84c Mon Sep 17 00:00:00 2001 From: danpros Date: Fri, 5 Jan 2024 12:41:56 +0700 Subject: [PATCH] Improve offline writing --- system/admin/admin.php | 15 +++++++++++---- system/admin/views/edit-page.html.php | 7 +++++++ system/htmly.php | 14 ++++++++++---- system/includes/functions.php | 8 ++------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/system/admin/admin.php b/system/admin/admin.php index dffd8a8..2d8024a 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -54,7 +54,7 @@ function session($user, $pass) $user_enc = user('encryption', $user); $user_pass = user('password', $user); $user_role = user('role', $user); - + if(is_null($user_enc) || is_null($user_pass) || is_null($user_role)) { return $str = '
'; } @@ -576,7 +576,7 @@ function add_sub_page($title, $url, $content, $static, $draft, $description = nu } else { $post_url = $post_url; } - } + } $post_content = '' . $post_description . "\n\n" . $content; @@ -755,11 +755,18 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { $newfile = $dir . '/' . $post_url . '.md'; + if (!is_dir($dir)) { + mkdir($dir, 0775, true); + } 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 (file_exists($oldfile)) { + rename($oldfile, $newfile); + file_put_contents($newfile, print_r($post_content, true)); + } else { + file_put_contents($newfile, print_r($post_content, true)); + } } rename_category_folder($post_url, $oldfile); diff --git a/system/admin/views/edit-page.html.php b/system/admin/views/edit-page.html.php index 46e1415..34df3f7 100644 --- a/system/admin/views/edit-page.html.php +++ b/system/admin/views/edit-page.html.php @@ -29,6 +29,13 @@ if ($type == 'is_frontpage') { $oldcontent = i18n('Author_Description'); } +} elseif ($type == 'is_category') { + $content = $p->body; + $oldtitle = $p->title; + $olddescription = $p->description; + $oldcontent = $p->body; + $oldmd = $p->md; + $url = 'content/data/category/'. $p->md; } else { if (isset($p->file)) { diff --git a/system/htmly.php b/system/htmly.php index 54a5279..6c0a020 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -1830,6 +1830,11 @@ get('/admin/categories/:category', function ($category) { $desc = $desc[0]; } + if (empty($posts) || $page < 1) { + // a non-existing page + not_found(); + } + $total = $desc->count; render('category-list', array( @@ -1890,13 +1895,13 @@ get('/category/:category', function ($category) { $desc = $desc[0]; } - $total = $desc->count; - if (empty($posts) || $page < 1) { // a non-existing page not_found(); } + $total = $desc->count; + $vroot = rtrim(config('views.root'), '/'); $lt = $vroot . '/layout--category--'. strtolower($category) .'.html.php'; @@ -1968,7 +1973,8 @@ get('/category/:category/edit', function ($category) { config('views.root', 'system/admin/views'); $post = get_category_info($category); - if (!$post) { + + if(empty($post)) { not_found(); } @@ -2052,7 +2058,7 @@ get('/category/:category/delete', function ($category) { config('views.root', 'system/admin/views'); $post = get_category_info($category); - if (!$post) { + if(empty($post)) { not_found(); } diff --git a/system/includes/functions.php b/system/includes/functions.php index a9f7b19..7a70e9c 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -269,18 +269,14 @@ function rebuilt_cache($type = null) foreach ($tmp as $file) { if(strpos($file, '/draft/') === false && strpos($file, '/scheduled/') === false) { $posts_cache[] = pathinfo($file); + $cd = explode('/', $file); + $ctmp[] = $cd[3]; } } } usort($posts_cache, "sortfile_d"); $string_posts = serialize($posts_cache); file_put_contents('cache/index/index-posts.txt', print_r($string_posts, true)); - - // Collect category slug - foreach ($posts_cache as $key => $c) { - $cd = explode('/', $c['dirname']); - $ctmp[] = $cd[3]; - } file_put_contents('cache/index/index-category.txt', print_r(serialize(array_unique($ctmp, SORT_REGULAR)), true)); // Rebuilt static page index