Simple subPages Integration added

Need work on edit page and menu.
This commit is contained in:
Kanti 2014-07-30 16:46:50 +02:00
commit a92b2ad997
3 changed files with 118 additions and 0 deletions

View file

@ -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('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
$post->title = $title;
$post->body = $arr[1];
} else {
$post->title = $sub_static;
$post->body = $arr[0];
}
$post->views = get_views($post->file);
$tmp[] = $post;
}
}
}
return $tmp;
}
// Return search page.
function get_keyword($keyword, $page, $perpage) {