diff --git a/system/htmly.php b/system/htmly.php index dc41f02..a1dd1bb 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -1078,6 +1078,34 @@ get('/admin/update/now/:csrf', function($CSRF) { } }); + +get('/:static/:sub', function($static,$sub) { + + $father_post = get_static_post($static); + if (!$father_post) { + not_found(); + } + $post = get_static_sub_post($static,$sub); + if (!$post) { + not_found(); + } + $post = $post[0]; + + add_view($post->file); + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + + render('static-sub', array( + 'head_contents' => head_contents($post->title . ' - ' . blog_title(), $description = get_description($post->body), $post->url), + 'bodyclass' => 'inpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $father_post[0]->title . ' » ' . $post->title, + 'p' => $post, + 'type' => 'staticpage', + )); +}); + // If we get here, it means that // nothing has been matched above diff --git a/system/includes/functions.php b/system/includes/functions.php index ae46284..19df00a 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -54,6 +54,33 @@ function get_static_pages() { return $_page; } +// Get static page path. Unsorted. +function get_static_sub_pages($static = null) { + + static $_sub_page = array(); + + if (empty($_sub_page)) { + $url = 'cache/index/index-sub-page.txt'; + if(! file_exists($url)) { + rebuilt_cache('all'); + } + $_sub_page = unserialize(file_get_contents($url)); + } + if($static != null) + { + $stringLen = strlen($static); + return array_filter($_sub_page, function($sub_page)use($static,$stringLen){ + $x = explode("/",$sub_page); + if($x[count($x)-2] == $static) + { + return true; + } + return false; + }); + } + return $_sub_page; +} + // Get author bio path. Unsorted. function get_author_names() { @@ -130,6 +157,11 @@ function rebuilt_cache($type) { $page_cache = glob('content/static/*.md', GLOB_NOSORT); $string = serialize($page_cache); file_put_contents('cache/index/index-page.txt', print_r($string, true)); + } elseif ($type === 'subpage') { + + $page_cache = glob('content/static/*/*.md', GLOB_NOSORT); + $string = serialize($page_cache); + file_put_contents('cache/index/index-sub-page.txt', print_r($string, true)); } elseif ($type === 'author') { $author_cache = glob('content/*/author.md', GLOB_NOSORT); @@ -138,6 +170,7 @@ function rebuilt_cache($type) { } elseif ($type === 'all') { rebuilt_cache('posts'); rebuilt_cache('page'); + rebuilt_cache('subpage'); rebuilt_cache('author'); } } @@ -466,6 +499,53 @@ function get_static_post($static) { return $tmp; } +// Return static page. +function get_static_sub_post($static,$sub_static) { + + $posts = get_static_sub_pages($static); + + $tmp = array(); + + if (!empty($posts)) { + + foreach ($posts as $index => $v) { + if (strpos($v, $sub_static . '.md') !== false) { + + $post = new stdClass; + + // Replaced string + $replaced = substr($v, 0, strrpos($v, '/')) . '/'; + + // The static page URL + $url = str_replace($replaced, '', $v); + $post->url = site_url() . $static . "/" . str_replace('.md', '', $url); + + $post->file = $v; + + // Get the contents and convert it to HTML + $content = MarkdownExtra::defaultTransform(file_get_contents($v)); + + // Extract the title and body + $arr = explode('t-->', $content); + if (isset($arr[1])) { + $title = str_replace('