From be5c20d63e1a3e67029dc72c22f13d54550ee5b1 Mon Sep 17 00:00:00 2001 From: Kanti Date: Tue, 5 Aug 2014 17:03:59 +0200 Subject: [PATCH] ContentManagement of SubPages Finished. (BUG) Active link if Page and Page/subPage have the same Name. --- system/admin/admin.php | 2 +- system/htmly.php | 8 ++++++-- system/includes/functions.php | 14 ++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/system/admin/admin.php b/system/admin/admin.php index 2d24437..6f8dce8 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -184,7 +184,7 @@ function add_sub_page($title, $url, $content, $static) { $post_content = stripslashes($post_content); } $filename = $post_url . '.md'; - $dir = 'content/static/' . $static; + $dir = 'content/static/' . $static . '/'; if (is_dir($dir)) { file_put_contents($dir . $filename, print_r($post_content, true)); } else { diff --git a/system/htmly.php b/system/htmly.php index 12da4bd..062b18b 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -141,7 +141,7 @@ get("/:static/:sub/edit", function($static,$sub) { header("location: $login"); } }); -post("/:static/:sub/edit", function() { +post("/:static/:sub/edit", function($static,$sub) { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); if(!login()) @@ -155,6 +155,10 @@ post("/:static/:sub/edit", function() { $content = from($_REQUEST, 'content'); $oldfile = from($_REQUEST, 'oldfile'); $destination = from($_GET, 'destination'); + if($destination === null) + { + $destination = $static . "/" . $sub; + } if ($proper && !empty($title) && !empty($content)) { if (!empty($url)) { edit_page($title, $url, $content, $oldfile, $destination); @@ -1252,7 +1256,7 @@ get('/:static/add', function($static) { header("location: $login"); } }); -post('/:static/add', function($static) {//not working +post('/:static/add', function($static) { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); diff --git a/system/includes/functions.php b/system/includes/functions.php index 7188c6e..8ebb630 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -1099,7 +1099,7 @@ function get_title_from_file($v) } // Auto generate menu from static page -function get_menu() { +function get_menu() {//aktive Link for Sub Pages ::TODO $posts = get_static_pages(); $req = $_SERVER['REQUEST_URI']; @@ -1133,13 +1133,16 @@ function get_menu() { $url = site_url() . str_replace('.md', '', $base); $title = get_title_from_file($v); - - if (strpos($req, str_replace('.md', '', $base)) !== false) { + + $reqBase = str_replace(substr($req, 0, strrpos($req, '/')) . '/', '', $req); + + if ($reqBase == str_replace('.md', '', $base)) { $active = ' active'; + $reqBase = ''; } else { $active = ''; } - echo '
  • '; + echo '
  • '; $subPages = get_static_sub_pages(str_replace('.md', '', $base)); echo '' . ucwords($title) . '
    '; @@ -1162,6 +1165,9 @@ function get_menu() { } $replacedSub = substr($sp, 0, strrpos($sp, '/')) . '/'; $baseSub = str_replace($replacedSub, '', $sp); + if ($reqBase == str_replace('.md', '', $baseSub)) { + $classSub .= ' active'; + } $urlSub = $url . "/" . str_replace('.md', '', $baseSub); echo '
  • » ' . get_title_from_file($sp) . '
  • '; $iSub++;