From a92b2ad9976c1a99b8bd480c18927940cd6fc811 Mon Sep 17 00:00:00 2001 From: Kanti Date: Wed, 30 Jul 2014 16:46:50 +0200 Subject: [PATCH 01/15] Simple subPages Integration added Need work on edit page and menu. --- system/htmly.php | 28 +++++++++++++++ system/includes/functions.php | 80 +++++++++++++++++++++++++++++++++++++++++ themes/logs/static-sub.html.php | 10 ++++++ 3 files changed, 118 insertions(+) create mode 100644 themes/logs/static-sub.html.php 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('' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - 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)); - } - - $replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/'; - $dt = str_replace($replaced,'',$oldurl[0]); - $t = str_replace('-','',$dt); - $time = new DateTime($t); - $timestamp= $time->format("Y-m-d"); - - // The post date - $postdate = strtotime($timestamp); - - // The post URL - $posturl = site_url().date('Y/m', $postdate).'/'.$post_url; - - rebuilt_cache('all'); - clear_post_cache($dt, $post_tag, $post_url, $newfile); - - if ($destination == 'post') { - header("Location: $posturl"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - - } - + $oldurl = explode('_', $oldfile); + + $post_title = $title; + $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag)); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; + 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)); + } + + $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + $dt = str_replace($replaced, '', $oldurl[0]); + $t = str_replace('-', '', $dt); + $time = new DateTime($t); + $timestamp = $time->format("Y-m-d"); + + // The post date + $postdate = strtotime($timestamp); + + // The post URL + $posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url; + + rebuilt_cache('all'); + clear_post_cache($dt, $post_tag, $post_url, $newfile); + + if ($destination == 'post') { + header("Location: $posturl"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Edit static page function edit_page($title, $url, $content, $oldfile, $destination = null) { - $dir = substr($oldfile, 0, strrpos($oldfile, '/')); - - $post_title = $title; - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - $post_content = '' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $newfile = $dir . '/' . $post_url . '.md'; - 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)); - } - - $posturl = site_url() . $post_url; - - rebuilt_cache('all'); - clear_page_cache($post_url); - if ($destination == 'post') { - header("Location: $posturl"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - - } - + $dir = substr($oldfile, 0, strrpos($oldfile, '/')); + + $post_title = $title; + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $newfile = $dir . '/' . $post_url . '.md'; + 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)); + } + + $posturl = site_url() . $post_url; + + rebuilt_cache('all'); + clear_page_cache($post_url); + if ($destination == 'post') { + header("Location: $posturl"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Add blog post function add_post($title, $tag, $url, $content, $user) { - $post_date = date('Y-m-d-H-i-s'); - $post_title = $title; - $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag)); - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - $post_content = '' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; - $dir = 'content/' . $user. '/blog/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - rebuilt_cache('all'); - clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename); - $redirect = site_url() . 'admin/mine'; - header("Location: $redirect"); - } - + $post_date = date('Y-m-d-H-i-s'); + $post_title = $title; + $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag)); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; + $dir = 'content/' . $user . '/blog/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename); + $redirect = site_url() . 'admin/mine'; + header("Location: $redirect"); + } } // Add static page function add_page($title, $url, $content) { - $post_title = $title; - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - $post_content = '' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_url . '.md'; - $dir = 'content/static/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - rebuilt_cache('all'); - clear_page_cache($post_url); - $redirect = site_url() . 'admin'; - header("Location: $redirect"); - } - + $post_title = $title; + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_url . '.md'; + $dir = 'content/static/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_page_cache($post_url); + $redirect = site_url() . 'admin'; + header("Location: $redirect"); + } } // Delete blog post function delete_post($file, $destination) { - if(!login()) return null; - $deleted_content = $file; - - // Get cache file - $arr = explode('_', $file); - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - $dt = str_replace($replaced,'',$arr[0]); - clear_post_cache($dt, $arr[1], str_replace('.md','',$arr[2]), $file); - - if(!empty($deleted_content)) { - unlink($deleted_content); - rebuilt_cache('all'); - if($destination == 'post') { - $redirect = site_url(); - header("Location: $redirect"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - } + if (!login()) + return null; + $deleted_content = $file; + + // Get cache file + $arr = explode('_', $file); + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + $dt = str_replace($replaced, '', $arr[0]); + clear_post_cache($dt, $arr[1], str_replace('.md', '', $arr[2]), $file); + + if (!empty($deleted_content)) { + unlink($deleted_content); + rebuilt_cache('all'); + if ($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Delete static page function delete_page($file, $destination) { - if(!login()) return null; - $deleted_content = $file; - - if (!empty($menu)) { - foreach(glob('cache/page/*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - } - else { - $replaced = substr($file, 0, strrpos($file, '/')) . '/'; - $url = str_replace($replaced,'',$file); - clear_page_cache($url); - } - - if(!empty($deleted_content)) { - unlink($deleted_content); - rebuilt_cache('all'); - if($destination == 'post') { - $redirect = site_url(); - header("Location: $redirect"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - } + if (!login()) + return null; + $deleted_content = $file; + + if (!empty($menu)) { + foreach (glob('cache/page/*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + } else { + $replaced = substr($file, 0, strrpos($file, '/')) . '/'; + $url = str_replace($replaced, '', $file); + clear_page_cache($url); + } + + if (!empty($deleted_content)) { + unlink($deleted_content); + rebuilt_cache('all'); + if ($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Edit user profile function edit_profile($title, $content, $user) { - $user_title = $title; - $user_content = '' . "\n\n" . $content; - - if(!empty($user_title) && !empty($user_content)) { - if(get_magic_quotes_gpc()) { - $user_content = stripslashes($user_content); - } - $dir = 'content/' . $user. '/'; - $filename = 'content/' . $user . '/author.md'; - if(is_dir($dir)) { - file_put_contents($filename, print_r($user_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($filename, print_r($user_content, true)); - } - rebuilt_cache('all'); - $redirect = site_url() . 'author/' . $user; - header("Location: $redirect"); - } - + $user_title = $title; + $user_content = '' . "\n\n" . $content; + + if (!empty($user_title) && !empty($user_content)) { + if (get_magic_quotes_gpc()) { + $user_content = stripslashes($user_content); + } + $dir = 'content/' . $user . '/'; + $filename = 'content/' . $user . '/author.md'; + if (is_dir($dir)) { + file_put_contents($filename, print_r($user_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($filename, print_r($user_content, true)); + } + rebuilt_cache('all'); + $redirect = site_url() . 'author/' . $user; + header("Location: $redirect"); + } } // Import RSS feed function migrate($title, $time, $tags, $content, $url, $user, $source) { - $post_date = date('Y-m-d-H-i-s', $time); - $post_title = $title; - $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags)); - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - if(!empty($source)) { - $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; - } - else { - $post_content = '' . "\n\n" . $content; - } - if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; - $dir = 'content/' . $user. '/blog/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - $redirect = site_url() . 'admin/clear-cache'; - header("Location: $redirect"); - } - + $post_date = date('Y-m-d-H-i-s', $time); + $post_title = $title; + $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags)); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + if (!empty($source)) { + $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; + } else { + $post_content = '' . "\n\n" . $content; + } + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; + $dir = 'content/' . $user . '/blog/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + $redirect = site_url() . 'admin/clear-cache'; + header("Location: $redirect"); + } } // Fetch RSS feed -function get_feed($feed_url, $credit, $message=null) { +function get_feed($feed_url, $credit, $message = null) { $source = file_get_contents($feed_url); $feed = new SimpleXmlElement($source); - if(!empty($feed->channel->item)) { - foreach($feed->channel->item as $entry) { - $descriptionA = $entry->children('content', true); - $descriptionB = $entry->description; - if(!empty($descriptionA)) { - $content = $descriptionA; - } - else if (!empty($descriptionB)) { - $content = preg_replace('##i', "\n", $descriptionB); - } - else { - return $str = '
  • Can not read the feed content.
  • '; - } - $time = new DateTime($entry->pubDate); - $timestamp= $time->format("Y-m-d H:i:s"); - $time = strtotime($timestamp); - $tags = strip_tags(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($entry->category))); - $title = rtrim($entry->title, ' \,\.\-'); - $title = ltrim($title, ' \,\.\-'); - $user = $_SESSION[config("site.url")]['user']; - $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); - if ($credit == 'yes') { - $source = $entry->link; - } - else { - $source= null; - } - migrate($title, $time, $tags, $content, $url, $user, $source); - } - } - else { - return $str= '
  • Unsupported feed.
  • '; - } - -} + if (!empty($feed->channel->item)) { + foreach ($feed->channel->item as $entry) { + $descriptionA = $entry->children('content', true); + $descriptionB = $entry->description; + if (!empty($descriptionA)) { + $content = $descriptionA; + } else if (!empty($descriptionB)) { + $content = preg_replace('##i', "\n", $descriptionB); + } else { + return $str = '
  • Can not read the feed content.
  • '; + } + $time = new DateTime($entry->pubDate); + $timestamp = $time->format("Y-m-d H:i:s"); + $time = strtotime($timestamp); + $tags = strip_tags(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($entry->category))); + $title = rtrim($entry->title, ' \,\.\-'); + $title = ltrim($title, ' \,\.\-'); + $user = $_SESSION[config("site.url")]['user']; + $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); + if ($credit == 'yes') { + $source = $entry->link; + } else { + $source = null; + } + migrate($title, $time, $tags, $content, $url, $user, $source); + } + } else { + return $str = '
  • Unsupported feed.
  • '; + } +} // Get recent posts by user function get_recent_posts() { - if (isset($_SESSION[config("site.url")]['user'])) { - $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); - if(!empty($posts)) { - echo ''; - echo ''; - $i = 0; $len = count($posts); - foreach($posts as $p) { - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    TitlePublishedViewsTagOperations
    ' . $p->title . '' . date('d F Y', $p->date) . '' . $p->views . '' . $p->tag . 'Edit Delete
    '; - } - } + if (isset($_SESSION[config("site.url")]['user'])) { + $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); + if (!empty($posts)) { + echo ''; + echo ''; + $i = 0; + $len = count($posts); + foreach ($posts as $p) { + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
    TitlePublishedViewsTagOperations
    ' . $p->title . '' . date('d F Y', $p->date) . '' . $p->views . '' . $p->tag . 'Edit Delete
    '; + } + } } // Get all static pages function get_recent_pages() { - if (isset($_SESSION[config("site.url")]['user'])) { - $posts = get_static_post(null); - if(!empty($posts)) { - krsort($posts); - echo ''; - echo ''; - $i = 0; $len = count($posts); - foreach($posts as $p) { - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    TitleViewsOperations
    ' . $p->title . '' . $p->views . 'Edit Delete
    '; - } - } + if (isset($_SESSION[config("site.url")]['user'])) { + $posts = get_static_post(null); + if (!empty($posts)) { + krsort($posts); + echo ''; + echo ''; + $i = 0; + $len = count($posts); + foreach ($posts as $p) { + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + $shortUrl = substr($p->url,strrpos($p->url, "/") + 1); + $subPages = get_static_sub_post($shortUrl,null); + + foreach($subPages as $sp) + { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo '
    TitleViewsOperations
    ' . $p->title . '' . $p->views . 'Edit Delete
    »' . $sp->title . '' . $sp->views . 'Edit Delete
    '; + } + } } // Get all available zip files -function get_backup_files () { - if (isset($_SESSION[config("site.url")]['user'])) { - $files = get_zip_files(); - if(!empty($files)) { - krsort($files); - echo ''; - echo ''; - $i = 0; $len = count($files); - foreach($files as $file) { - - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - - // Extract the date - $arr = explode('_', $file); - - // Replaced string - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - - $name = str_replace($replaced,'',$file); - - $date = str_replace('.zip','',$arr[1]); - $t = str_replace('-', '', $date); - $time = new DateTime($t); - $timestamp= $time->format("D, d F Y, H:i:s"); - - $url = site_url() . $file; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    FilenameDateOperations
    ' . $name . '' . $timestamp . 'Download
    '; - } - else { - echo 'No available backup!'; - } - } +function get_backup_files() { + if (isset($_SESSION[config("site.url")]['user'])) { + $files = get_zip_files(); + if (!empty($files)) { + krsort($files); + echo ''; + echo ''; + $i = 0; + $len = count($files); + foreach ($files as $file) { + + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + + // Extract the date + $arr = explode('_', $file); + + // Replaced string + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + + $name = str_replace($replaced, '', $file); + + $date = str_replace('.zip', '', $arr[1]); + $t = str_replace('-', '', $date); + $time = new DateTime($t); + $timestamp = $time->format("D, d F Y, H:i:s"); + + $url = site_url() . $file; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
    FilenameDateOperations
    ' . $name . '' . $timestamp . 'Download
    '; + } else { + echo 'No available backup!'; + } + } } function clear_post_cache($post_date, $post_tag, $post_url, $filename) { - $b = str_replace('/', '#', site_path() . '/'); - $t = explode('-', $post_date); - $c = explode(',', $post_tag); - $p = 'cache/page/'.$b.$t[0].'#'.$t[1].'#'.$post_url.'.cache'; - - // Delete post - if (file_exists($p)) { - unlink($p); - } - - // Delete homepage - $yd = 'cache/page/'.$b.'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year - $yd = 'cache/page/'.$b.'archive#'.$t[0].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year-month - $yd = 'cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year-month-day - $yd = 'cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'-'.$t[2].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'-'.$t[2].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete tag - foreach($c as $tag) { - $yd = 'cache/page/'.$b.'tag#'.$tag.'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'tag#'.$tag.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - } - - // Delete search - foreach(glob('cache/page/'.$b.'search#*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - - // Get cache post author - $arr = explode('_', $filename); - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - $str = explode('/', $replaced); - $author = $str[count($str)-3]; - // Delete author post list cache - $a = 'cache/page/'.$b.'author#'.$author.'.cache'; - if (file_exists($a)) { - unlink($a); - } - foreach(glob('cache/page/'.$b.'author#'.$author.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - + $b = str_replace('/', '#', site_path() . '/'); + $t = explode('-', $post_date); + $c = explode(',', $post_tag); + $p = 'cache/page/' . $b . $t[0] . '#' . $t[1] . '#' . $post_url . '.cache'; + + // Delete post + if (file_exists($p)) { + unlink($p); + } + + // Delete homepage + $yd = 'cache/page/' . $b . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year-month + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year-month-day + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '-' . $t[2] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '-' . $t[2] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete tag + foreach ($c as $tag) { + $yd = 'cache/page/' . $b . 'tag#' . $tag . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'tag#' . $tag . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + } + + // Delete search + foreach (glob('cache/page/' . $b . 'search#*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + + // Get cache post author + $arr = explode('_', $filename); + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + $str = explode('/', $replaced); + $author = $str[count($str) - 3]; + // Delete author post list cache + $a = 'cache/page/' . $b . 'author#' . $author . '.cache'; + if (file_exists($a)) { + unlink($a); + } + foreach (glob('cache/page/' . $b . 'author#' . $author . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } } function clear_page_cache($url) { - $b = str_replace('/', '#', site_path() . '/'); - $p = 'cache/page/'.$b.$url.'.cache'; - if (file_exists($p)) { - unlink($p); - } -} \ No newline at end of file + $b = str_replace('/', '#', site_path() . '/'); + $p = 'cache/page/' . $b . $url . '.cache'; + if (file_exists($p)) { + unlink($p); + } +} diff --git a/system/htmly.php b/system/htmly.php index a1dd1bb..b4c4540 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -115,15 +115,16 @@ get('/:year/:month/:name', function($year, $month, $name) { $post = find_post($year, $month, $name); $current = $post['current']; - add_view($current->file); - - if (!login()) { - file_cache($_SERVER['REQUEST_URI']); - } if (!$current) { not_found(); } + + add_view($current->file); + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } $bio = get_bio($current->author); From fa77cc805bc3c4356eeff12ed6260c3e9154ad9b Mon Sep 17 00:00:00 2001 From: Kanti Date: Fri, 1 Aug 2014 13:23:14 +0200 Subject: [PATCH 03/15] Basic Support for SubPages Ready to use. Must Add CMS Funktions Add/Edit/delete to it. if Rename a Static page the subFolder must be renamed as well. --- system/admin/admin.php | 6 ++-- system/htmly.php | 26 ++++++++++++++++++ system/includes/functions.php | 64 +++++++++++++++++++++++++++++++++---------- 3 files changed, 79 insertions(+), 17 deletions(-) diff --git a/system/admin/admin.php b/system/admin/admin.php index 46e584e..48bebae 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -374,7 +374,7 @@ function get_recent_pages() { echo '' . $p->title . ''; if (config("views.counter") == "true") echo '' . $p->views . ''; - echo 'Edit Delete'; + echo 'Add Sub Edit Delete'; echo ''; $shortUrl = substr($p->url,strrpos($p->url, "/") + 1); @@ -384,8 +384,8 @@ function get_recent_pages() { { echo ''; echo ' »' . $sp->title . ''; - if (config("views.counter") == "true") - echo '' . $sp->views . ''; + if (config("views.counter") == "true") + echo '' . $sp->views . ''; echo 'Edit Delete'; echo ''; } diff --git a/system/htmly.php b/system/htmly.php index 25a5e82..e0b310a 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -108,6 +108,24 @@ post('/login', function() { } }); +get("/:static/:sub/edit", function($static,$sub){ + echo $static,$sub,"edit"; + die(); +}); +post("/:static/:sub/edit", function($static,$sub){ + echo $static,$sub,"edit."; + die(); +}); + +get("/:static/:sub/delete", function($static,$sub){ + echo $static,$sub,"delete"; + die(); +}); +post("/:static/:sub/delete", function($static,$sub){ + echo $static,$sub,"delete."; + die(); +}); + // The blog post page get('/:year/:month/:name', function($year, $month, $name) { @@ -1098,6 +1116,14 @@ get('/admin/update/now/:csrf', function($CSRF) { } }); +get('/:static/add', function($static){ + echo $static,"add"; + die(); +}); +post('/:static/add', function($static){ + echo $static,"add."; + die(); +}); get('/:static/:sub', function($static,$sub) { diff --git a/system/includes/functions.php b/system/includes/functions.php index c5ed545..e40a138 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -1082,6 +1082,22 @@ function menu() { } } +function get_title_from_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('', $content); - if (isset($arr[1])) { - $title = str_replace('' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_url . '.md'; + $dir = 'content/static/' . $static; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_page_cache($post_url); + $redirect = site_url() . 'admin'; + header("Location: $redirect"); + } +} + // Delete blog post function delete_post($file, $destination) { if (!login()) diff --git a/system/htmly.php b/system/htmly.php index 6abbe26..12da4bd 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -108,22 +108,127 @@ post('/login', function() { } }); -get("/:static/:sub/edit", function($static,$sub){ - echo $static,$sub,"edit"; - die(); +get("/:static/:sub/edit", function($static,$sub) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_static_post($static); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + $page = get_static_sub_post($static,$sub); + + if (!$page) { + not_found(); + } + + $page = $page[0]; + + render('edit-page', array( + 'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'editpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ', + 'p' => $page, + 'type' => 'staticpage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); -post("/:static/:sub/edit", function($static,$sub){ - echo $static,$sub,"edit."; - die(); +post("/:static/:sub/edit", function() { + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + if(!login()) + { + $login = site_url() . 'login'; + header("location: $login"); + } + + $title = from($_REQUEST, 'title'); + $url = from($_REQUEST, 'url'); + $content = from($_REQUEST, 'content'); + $oldfile = from($_REQUEST, 'oldfile'); + $destination = from($_GET, 'destination'); + if ($proper && !empty($title) && !empty($content)) { + if (!empty($url)) { + edit_page($title, $url, $content, $oldfile, $destination); + } else { + $url = $title; + edit_page($title, $url, $content, $oldfile, $destination); + } + } else { + $message['error'] = ''; + if (empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-page', array( + 'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()), + 'error' => '
      ' . $message['error'] . '
    ', + 'oldfile' => $oldfile, + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'editpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit page' + )); + } }); -get("/:static/:sub/delete", function($static,$sub){ - echo $static,$sub,"delete"; - die(); +get("/:static/:sub/delete", function($static,$sub) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_static_post($static); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + $page = get_static_sub_post($static,$sub); + + if (!$page) { + not_found(); + } + + $page = $page[0]; + + render('delete-page', array( + 'head_contents' => head_contents('Delete page - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'deletepage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . '' . $page->title, + 'p' => $page, + 'type' => 'staticpage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); -post("/:static/:sub/delete", function($static,$sub){ - echo $static,$sub,"delete."; - die(); +post("/:static/:sub/delete", function() { + + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + if ($proper && login()) { + $file = from($_REQUEST, 'file'); + $destination = from($_GET, 'destination'); + delete_page($file, $destination); + } }); // The blog post page @@ -313,7 +418,7 @@ get('/:year/:month/:name/delete', function($year, $month, $name) { post('/:year/:month/:name/delete', function() { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if ($proper) { + if ($proper && login()) { $file = from($_REQUEST, 'file'); $destination = from($_GET, 'destination'); delete_post($file, $destination); @@ -660,6 +765,12 @@ get('/:static/edit', function($static) { post('/:static/edit', function() { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + if(!login()) + { + $login = site_url() . 'login'; + header("location: $login"); + } + $title = from($_REQUEST, 'title'); $url = from($_REQUEST, 'url'); $content = from($_REQUEST, 'content'); @@ -729,7 +840,7 @@ get('/:static/delete', function($static) { post('/:static/delete', function() { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if ($proper) { + if ($proper && login()) { $file = from($_REQUEST, 'file'); $destination = from($_GET, 'destination'); delete_page($file, $destination); @@ -825,7 +936,7 @@ post('/add/page', function() { $title = from($_REQUEST, 'title'); $url = from($_REQUEST, 'url'); $content = from($_REQUEST, 'content'); - if ($proper && !empty($title) && !empty($content)) { + if ($proper && !empty($title) && !empty($content) && login()) { if (!empty($url)) { add_page($title, $url, $content); } else { @@ -1116,13 +1227,67 @@ get('/admin/update/now/:csrf', function($CSRF) { } }); -get('/:static/add', function($static){ - echo $static,"add"; - die(); +get('/:static/add', function($static) { + + if (login()) { + + config('views.root', 'system/admin/views'); + + $post = get_static_post($static); + + if(! $post) + { + not_found(); + } + + $post = $post[0]; + + render('add-page', array( + 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'addpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' Add page' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); -post('/:static/add', function($static){ - echo $static,"add."; - die(); +post('/:static/add', function($static) {//not working + + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $title = from($_REQUEST, 'title'); + $url = from($_REQUEST, 'url'); + $content = from($_REQUEST, 'content'); + if ($proper && !empty($title) && !empty($content) && login()) { + if (!empty($url)) { + add_sub_page($title, $url, $content, $static); + } else { + $url = $title; + add_sub_page($title, $url, $content, $static); + } + } else { + $message['error'] = ''; + if (empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + render('add-page', array( + 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), + 'error' => '
      ' . $message['error'] . '
    ', + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'addpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' Add page' + )); + } }); get('/:static/:sub', function($static,$sub) { From 614c64e62dd54509b963ddde18e8a5a0adeb243f Mon Sep 17 00:00:00 2001 From: Kanti Date: Tue, 5 Aug 2014 08:06:03 +0200 Subject: [PATCH 08/15] edit CSS: better menu (active link). --- themes/clean/css/style.css | 2 +- themes/default/css/style.css | 2 +- themes/logs/css/style.css | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/clean/css/style.css b/themes/clean/css/style.css index 85305a7..cb45715 100644 --- a/themes/clean/css/style.css +++ b/themes/clean/css/style.css @@ -437,7 +437,7 @@ aside .archive ul li ul, aside .tagcloud ul li { margin-left:30px; } -aside .menu ul li a:hover, aside .menu ul li.active a{ +aside .menu ul li > a:hover, aside .menu ul li.active > a{ background-color:#389dc1; color:#fff; } diff --git a/themes/default/css/style.css b/themes/default/css/style.css index 00198cf..f977145 100644 --- a/themes/default/css/style.css +++ b/themes/default/css/style.css @@ -379,7 +379,7 @@ table.post-list td a { padding-top:3px; } -#menu ul li.active a { +#menu ul li.active > a { text-decoration:underline; } diff --git a/themes/logs/css/style.css b/themes/logs/css/style.css index 0f46b31..a5e2320 100644 --- a/themes/logs/css/style.css +++ b/themes/logs/css/style.css @@ -306,7 +306,7 @@ ul li, ol li{ text-decoration: underline; } -#menu ul li.active a { +#menu ul li.active > a { text-decoration: underline; } From be5c20d63e1a3e67029dc72c22f13d54550ee5b1 Mon Sep 17 00:00:00 2001 From: Kanti Date: Tue, 5 Aug 2014 17:03:59 +0200 Subject: [PATCH 09/15] 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++; From 02c6a36a1af63c84c872e0fd4e0c14b4f25d0c3e Mon Sep 17 00:00:00 2001 From: Kanti Date: Tue, 5 Aug 2014 17:11:58 +0200 Subject: [PATCH 10/15] Some destination bug fixes (SubPages) --- system/admin/views/delete-page.html.php | 53 ++++++++++++++++----------------- system/admin/views/edit-page.html.php | 2 +- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/system/admin/views/delete-page.html.php b/system/admin/views/delete-page.html.php index 99aafa8..3a25687 100644 --- a/system/admin/views/delete-page.html.php +++ b/system/admin/views/delete-page.html.php @@ -1,33 +1,30 @@ file; - - $dir = substr($url, 0, strrpos($url, '/')); - $oldurl = str_replace($dir . '/','',$url); - $oldmd = str_replace('.md','',$oldurl); - - $post = site_url() . $oldmd; - - if(isset($destination)) { - - if($destination == 'post') { - $back = $post; - } - else { - $back = site_url() . $destination; - } - } - else { - $back = site_url(); - } + if (isset($_GET['destination'])) { + $destination = $_GET['destination']; + } + $url = $p->file; + $dir = substr($url, 0, strrpos($url, '/')); + $oldurl = str_replace($dir . '/', '', $url); + $oldmd = str_replace('.md', '', $oldurl); + + $post = $p->url; + + if (isset($destination)) { + + if ($destination == 'post') { + $back = $post; + } else { + $back = site_url() . $destination; + } + } else { + $back = site_url(); + } ?> -Are you sure want to delete ' . $p->title . '?

    ';?> +

    Are you sure want to delete title; ?>?

    -
    - - - Cancel +
    + + + Cancel
    \ No newline at end of file diff --git a/system/admin/views/edit-page.html.php b/system/admin/views/edit-page.html.php index 58a0009..e5b500e 100644 --- a/system/admin/views/edit-page.html.php +++ b/system/admin/views/edit-page.html.php @@ -27,7 +27,7 @@ $oldurl = str_replace($dir . '/','',$url); $oldmd = str_replace('.md','',$oldurl); - $delete = site_url() . $oldmd . '/delete?destination=' . $destination; + $delete = $p->url . '/delete?destination=' . $destination; ?> From 9e06d495ec642e1c5ec5b49c6ba596cce564ec35 Mon Sep 17 00:00:00 2001 From: Kanti Date: Wed, 6 Aug 2014 07:02:00 +0200 Subject: [PATCH 11/15] active link bugfixed --- system/includes/functions.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/system/includes/functions.php b/system/includes/functions.php index 8ebb630..7672f1e 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -1133,10 +1133,8 @@ function get_menu() {//aktive Link for Sub Pages ::TODO $url = site_url() . str_replace('.md', '', $base); $title = get_title_from_file($v); - - $reqBase = str_replace(substr($req, 0, strrpos($req, '/')) . '/', '', $req); - if ($reqBase == str_replace('.md', '', $base)) { + if ($req == site_path() . "/" . str_replace('.md', '', $base)) { $active = ' active'; $reqBase = ''; } else { @@ -1165,7 +1163,8 @@ function get_menu() {//aktive Link for Sub Pages ::TODO } $replacedSub = substr($sp, 0, strrpos($sp, '/')) . '/'; $baseSub = str_replace($replacedSub, '', $sp); - if ($reqBase == str_replace('.md', '', $baseSub)) { + + if ($req == site_path() . "/" . str_replace('.md', '', $base) . "/" . str_replace('.md', '', $baseSub)) { $classSub .= ' active'; } $urlSub = $url . "/" . str_replace('.md', '', $baseSub); From 7963ae985424147c490b3e8c85ac9482a3220f54 Mon Sep 17 00:00:00 2001 From: Kanti Date: Wed, 6 Aug 2014 07:09:40 +0200 Subject: [PATCH 12/15] Added Blackcodec's password security code --- config/users/username.ini.example | 4 ++++ system/admin/admin.php | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config/users/username.ini.example b/config/users/username.ini.example index befaed5..6154b62 100644 --- a/config/users/username.ini.example +++ b/config/users/username.ini.example @@ -1,5 +1,9 @@ ;Password password = yourpassword +encryption = clear +; encryption: not set, leave blank or set to clear or none to use plain text password for the user, +; else set to encryption algoritm supported by hash function of php to use the selected +; encryption ;Role role = admin \ No newline at end of file diff --git a/system/admin/admin.php b/system/admin/admin.php index 6f8dce8..90c9922 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -15,16 +15,20 @@ function user($key, $user = null) { // Create a session function session($user, $pass, $str = null) { $user_file = 'config/users/' . $user . '.ini'; + $user_enc = user('encryption', $user); $user_pass = user('password', $user); + $password = (strlen($user_enc) > 0 && $user_enc !== 'clear' && $user_enc !== 'none')?hash($user_enc,$pass):$pass; - if (file_exists($user_file)) { - if ($pass === $user_pass) { + if(file_exists($user_file)) { + if($pass === $user_pass) { $_SESSION[config("site.url")]['user'] = $user; header('location: admin'); - } else { + } + else { return $str = '
  • Your username and password mismatch.
  • '; } - } else { + } + else { return $str = '
  • Username not found in our record.
  • '; } } From 7a82c6f7780fdedc4ce4730195b075dfc0e4f3e6 Mon Sep 17 00:00:00 2001 From: Kanti Date: Wed, 6 Aug 2014 07:11:11 +0200 Subject: [PATCH 13/15] Revert "Added Blackcodec's password security code" This reverts commit 7963ae985424147c490b3e8c85ac9482a3220f54. --- config/users/username.ini.example | 4 ---- system/admin/admin.php | 12 ++++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/config/users/username.ini.example b/config/users/username.ini.example index 6154b62..befaed5 100644 --- a/config/users/username.ini.example +++ b/config/users/username.ini.example @@ -1,9 +1,5 @@ ;Password password = yourpassword -encryption = clear -; encryption: not set, leave blank or set to clear or none to use plain text password for the user, -; else set to encryption algoritm supported by hash function of php to use the selected -; encryption ;Role role = admin \ No newline at end of file diff --git a/system/admin/admin.php b/system/admin/admin.php index 90c9922..6f8dce8 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -15,20 +15,16 @@ function user($key, $user = null) { // Create a session function session($user, $pass, $str = null) { $user_file = 'config/users/' . $user . '.ini'; - $user_enc = user('encryption', $user); $user_pass = user('password', $user); - $password = (strlen($user_enc) > 0 && $user_enc !== 'clear' && $user_enc !== 'none')?hash($user_enc,$pass):$pass; - if(file_exists($user_file)) { - if($pass === $user_pass) { + if (file_exists($user_file)) { + if ($pass === $user_pass) { $_SESSION[config("site.url")]['user'] = $user; header('location: admin'); - } - else { + } else { return $str = '
  • Your username and password mismatch.
  • '; } - } - else { + } else { return $str = '
  • Username not found in our record.
  • '; } } From 5f276f65b7cb9928e56a97da35766c0e5ccbabfd Mon Sep 17 00:00:00 2001 From: Kanti Date: Wed, 6 Aug 2014 07:26:38 +0200 Subject: [PATCH 14/15] Fixed Conflicts --- system/admin/admin.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/system/admin/admin.php b/system/admin/admin.php index 6293791..7776158 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -189,6 +189,33 @@ function add_page($title, $url, $content) { } +// Add static sub page +function add_sub_page($title, $url, $content, $static) { + + $post_title = $title; + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_url . '.md'; + $dir = 'content/static/' . $static . '/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_page_cache($post_url); + $redirect = site_url() . 'admin'; + header("Location: $redirect"); + } +} + // Delete blog post function delete_post($file, $destination) { if(!login()) return null; From 481430639d70e6a6f4f97696c1eaa304facfa34e Mon Sep 17 00:00:00 2001 From: Kanti Date: Wed, 6 Aug 2014 07:35:06 +0200 Subject: [PATCH 15/15] Fixed Conflicts II --- system/admin/admin.php | 946 ++++++++++++++++++++++++------------------------- 1 file changed, 466 insertions(+), 480 deletions(-) diff --git a/system/admin/admin.php b/system/admin/admin.php index 7776158..47d469d 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1,192 +1,177 @@ 0 && $user_enc !== 'clear' && $user_enc !== 'none')?hash($user_enc,$pass):$pass; - - if(file_exists($user_file)) { - if($pass === $user_pass) { - $_SESSION[config("site.url")]['user'] = $user; - header('location: admin'); - } - else { - return $str = '
  • Your username and password mismatch.
  • '; - } - } - else { - return $str = '
  • Username not found in our record.
  • '; - } + $user_file = 'config/users/' . $user . '.ini'; + $user_enc = user('encryption', $user); + $user_pass = user('password', $user); + $password = (strlen($user_enc) > 0 && $user_enc !== 'clear' && $user_enc !== 'none') ? hash($user_enc, $pass) : $pass; + + if (file_exists($user_file)) { + if ($pass === $user_pass) { + $_SESSION[config("site.url")]['user'] = $user; + header('location: admin'); + } else { + return $str = '
  • Your username and password mismatch.
  • '; + } + } else { + return $str = '
  • Username not found in our record.
  • '; + } } // Clean URLs -function remove_accent($str) -{ - $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); - $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); - return str_replace($a, $b, $str); -} +function remove_accent($str) { + $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); + $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); + return str_replace($a, $b, $str); +} // Edit blog posts function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) { - $oldurl = explode('_', $oldfile); - - $post_title = $title; - $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag)); - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - $post_content = '' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - 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)); - } - - $replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/'; - $dt = str_replace($replaced,'',$oldurl[0]); - $t = str_replace('-','',$dt); - $time = new DateTime($t); - $timestamp= $time->format("Y-m-d"); - - // The post date - $postdate = strtotime($timestamp); - - // The post URL - $posturl = site_url().date('Y/m', $postdate).'/'.$post_url; - - rebuilt_cache('all'); - clear_post_cache($dt, $post_tag, $post_url, $newfile); - - if ($destination == 'post') { - header("Location: $posturl"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - - } - + $oldurl = explode('_', $oldfile); + + $post_title = $title; + $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag)); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; + 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)); + } + + $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + $dt = str_replace($replaced, '', $oldurl[0]); + $t = str_replace('-', '', $dt); + $time = new DateTime($t); + $timestamp = $time->format("Y-m-d"); + + // The post date + $postdate = strtotime($timestamp); + + // The post URL + $posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url; + + rebuilt_cache('all'); + clear_post_cache($dt, $post_tag, $post_url, $newfile); + + if ($destination == 'post') { + header("Location: $posturl"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Edit static page function edit_page($title, $url, $content, $oldfile, $destination = null) { - $dir = substr($oldfile, 0, strrpos($oldfile, '/')); - - $post_title = $title; - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - $post_content = '' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $newfile = $dir . '/' . $post_url . '.md'; - 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)); - } - - $posturl = site_url() . $post_url; - - rebuilt_cache('all'); - clear_page_cache($post_url); - if ($destination == 'post') { - header("Location: $posturl"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - - } - + $dir = substr($oldfile, 0, strrpos($oldfile, '/')); + + $post_title = $title; + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $newfile = $dir . '/' . $post_url . '.md'; + 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)); + } + + $posturl = site_url() . $post_url; + + rebuilt_cache('all'); + clear_page_cache($post_url); + if ($destination == 'post') { + header("Location: $posturl"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Add blog post function add_post($title, $tag, $url, $content, $user) { - $post_date = date('Y-m-d-H-i-s'); - $post_title = $title; - $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag)); - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - $post_content = '' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; - $dir = 'content/' . $user. '/blog/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - rebuilt_cache('all'); - clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename); - $redirect = site_url() . 'admin/mine'; - header("Location: $redirect"); - } - + $post_date = date('Y-m-d-H-i-s'); + $post_title = $title; + $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag)); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; + $dir = 'content/' . $user . '/blog/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename); + $redirect = site_url() . 'admin/mine'; + header("Location: $redirect"); + } } // Add static page function add_page($title, $url, $content) { - $post_title = $title; - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - $post_content = '' . "\n\n" . $content; - - if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_url . '.md'; - $dir = 'content/static/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - rebuilt_cache('all'); - clear_page_cache($post_url); - $redirect = site_url() . 'admin'; - header("Location: $redirect"); - } - + $post_title = $title; + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $post_content = '' . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_url . '.md'; + $dir = 'content/static/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_page_cache($post_url); + $redirect = site_url() . 'admin'; + header("Location: $redirect"); + } } // Add static sub page @@ -218,360 +203,361 @@ function add_sub_page($title, $url, $content, $static) { // Delete blog post function delete_post($file, $destination) { - if(!login()) return null; - $deleted_content = $file; - - // Get cache file - $arr = explode('_', $file); - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - $dt = str_replace($replaced,'',$arr[0]); - clear_post_cache($dt, $arr[1], str_replace('.md','',$arr[2]), $file); - - if(!empty($deleted_content)) { - unlink($deleted_content); - rebuilt_cache('all'); - if($destination == 'post') { - $redirect = site_url(); - header("Location: $redirect"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - } + if (!login()) + return null; + $deleted_content = $file; + + // Get cache file + $arr = explode('_', $file); + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + $dt = str_replace($replaced, '', $arr[0]); + clear_post_cache($dt, $arr[1], str_replace('.md', '', $arr[2]), $file); + + if (!empty($deleted_content)) { + unlink($deleted_content); + rebuilt_cache('all'); + if ($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Delete static page function delete_page($file, $destination) { - if(!login()) return null; - $deleted_content = $file; - - if (!empty($menu)) { - foreach(glob('cache/page/*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - } - else { - $replaced = substr($file, 0, strrpos($file, '/')) . '/'; - $url = str_replace($replaced,'',$file); - clear_page_cache($url); - } - - if(!empty($deleted_content)) { - unlink($deleted_content); - rebuilt_cache('all'); - if($destination == 'post') { - $redirect = site_url(); - header("Location: $redirect"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - } + if (!login()) + return null; + $deleted_content = $file; + + if (!empty($menu)) { + foreach (glob('cache/page/*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + } else { + $replaced = substr($file, 0, strrpos($file, '/')) . '/'; + $url = str_replace($replaced, '', $file); + clear_page_cache($url); + } + + if (!empty($deleted_content)) { + unlink($deleted_content); + rebuilt_cache('all'); + if ($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Edit user profile function edit_profile($title, $content, $user) { - $user_title = $title; - $user_content = '' . "\n\n" . $content; - - if(!empty($user_title) && !empty($user_content)) { - if(get_magic_quotes_gpc()) { - $user_content = stripslashes($user_content); - } - $dir = 'content/' . $user. '/'; - $filename = 'content/' . $user . '/author.md'; - if(is_dir($dir)) { - file_put_contents($filename, print_r($user_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($filename, print_r($user_content, true)); - } - rebuilt_cache('all'); - $redirect = site_url() . 'author/' . $user; - header("Location: $redirect"); - } - + $user_title = $title; + $user_content = '' . "\n\n" . $content; + + if (!empty($user_title) && !empty($user_content)) { + if (get_magic_quotes_gpc()) { + $user_content = stripslashes($user_content); + } + $dir = 'content/' . $user . '/'; + $filename = 'content/' . $user . '/author.md'; + if (is_dir($dir)) { + file_put_contents($filename, print_r($user_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($filename, print_r($user_content, true)); + } + rebuilt_cache('all'); + $redirect = site_url() . 'author/' . $user; + header("Location: $redirect"); + } } // Import RSS feed function migrate($title, $time, $tags, $content, $url, $user, $source) { - $post_date = date('Y-m-d-H-i-s', $time); - $post_title = $title; - $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags)); - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - if(!empty($source)) { - $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; - } - else { - $post_content = '' . "\n\n" . $content; - } - if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; - $dir = 'content/' . $user. '/blog/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - $redirect = site_url() . 'admin/clear-cache'; - header("Location: $redirect"); - } - + $post_date = date('Y-m-d-H-i-s', $time); + $post_title = $title; + $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags)); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + if (!empty($source)) { + $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; + } else { + $post_content = '' . "\n\n" . $content; + } + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; + $dir = 'content/' . $user . '/blog/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + $redirect = site_url() . 'admin/clear-cache'; + header("Location: $redirect"); + } } // Fetch RSS feed -function get_feed($feed_url, $credit, $message=null) { +function get_feed($feed_url, $credit, $message = null) { $source = file_get_contents($feed_url); $feed = new SimpleXmlElement($source); - if(!empty($feed->channel->item)) { - foreach($feed->channel->item as $entry) { - $descriptionA = $entry->children('content', true); - $descriptionB = $entry->description; - if(!empty($descriptionA)) { - $content = $descriptionA; - } - else if (!empty($descriptionB)) { - $content = preg_replace('##i', "\n", $descriptionB); - } - else { - return $str = '
  • Can not read the feed content.
  • '; - } - $time = new DateTime($entry->pubDate); - $timestamp= $time->format("Y-m-d H:i:s"); - $time = strtotime($timestamp); - $tags = strip_tags(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($entry->category))); - $title = rtrim($entry->title, ' \,\.\-'); - $title = ltrim($title, ' \,\.\-'); - $user = $_SESSION[config("site.url")]['user']; - $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); - if ($credit == 'yes') { - $source = $entry->link; - } - else { - $source= null; - } - migrate($title, $time, $tags, $content, $url, $user, $source); - } - } - else { - return $str= '
  • Unsupported feed.
  • '; - } - -} + if (!empty($feed->channel->item)) { + foreach ($feed->channel->item as $entry) { + $descriptionA = $entry->children('content', true); + $descriptionB = $entry->description; + if (!empty($descriptionA)) { + $content = $descriptionA; + } else if (!empty($descriptionB)) { + $content = preg_replace('##i', "\n", $descriptionB); + } else { + return $str = '
  • Can not read the feed content.
  • '; + } + $time = new DateTime($entry->pubDate); + $timestamp = $time->format("Y-m-d H:i:s"); + $time = strtotime($timestamp); + $tags = strip_tags(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($entry->category))); + $title = rtrim($entry->title, ' \,\.\-'); + $title = ltrim($title, ' \,\.\-'); + $user = $_SESSION[config("site.url")]['user']; + $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); + if ($credit == 'yes') { + $source = $entry->link; + } else { + $source = null; + } + migrate($title, $time, $tags, $content, $url, $user, $source); + } + } else { + return $str = '
  • Unsupported feed.
  • '; + } +} // Get recent posts by user function get_recent_posts() { - if (isset($_SESSION[config("site.url")]['user'])) { - $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); - if(!empty($posts)) { - echo ''; - echo ''; - if(config("views.counter") == "true") echo ''; - echo ''; - $i = 0; $len = count($posts); - foreach($posts as $p) { - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - echo ''; - echo ''; - echo ''; - if(config("views.counter") == "true") echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    TitlePublishedViewsTagOperations
    ' . $p->title . '' . date('d F Y', $p->date) . '' . $p->views . '' . $p->tag . 'Edit Delete
    '; - } - } + if (isset($_SESSION[config("site.url")]['user'])) { + $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); + if (!empty($posts)) { + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + $i = 0; + $len = count($posts); + foreach ($posts as $p) { + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + echo ''; + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
    TitlePublishedViewsTagOperations
    ' . $p->title . '' . date('d F Y', $p->date) . '' . $p->views . '' . $p->tag . 'Edit Delete
    '; + } + } } // Get all static pages function get_recent_pages() { - if (isset($_SESSION[config("site.url")]['user'])) { - $posts = get_static_post(null); - if(!empty($posts)) { - krsort($posts); - echo ''; - echo ''; - if(config("views.counter") == "true") echo ''; - echo ''; - $i = 0; $len = count($posts); - foreach($posts as $p) { - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - echo ''; - echo ''; - if(config("views.counter") == "true") echo ''; - echo ''; - echo ''; - } - echo '
    TitleViewsOperations
    ' . $p->title . '' . $p->views . 'Edit Delete
    '; - } - } + if (isset($_SESSION[config("site.url")]['user'])) { + $posts = get_static_post(null); + if (!empty($posts)) { + krsort($posts); + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + $i = 0; + $len = count($posts); + foreach ($posts as $p) { + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + echo ''; + + $shortUrl = substr($p->url, strrpos($p->url, "/") + 1); + $subPages = get_static_sub_post($shortUrl, null); + + foreach ($subPages as $sp) { + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + echo ''; + } + } + echo '
    TitleViewsOperations
    ' . $p->title . '' . $p->views . 'Add Sub Edit Delete
    »' . $sp->title . '' . $sp->views . 'Edit Delete
    '; + } + } } // Get all available zip files -function get_backup_files () { - if (isset($_SESSION[config("site.url")]['user'])) { - $files = get_zip_files(); - if(!empty($files)) { - krsort($files); - echo ''; - echo ''; - $i = 0; $len = count($files); - foreach($files as $file) { - - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - - // Extract the date - $arr = explode('_', $file); - - // Replaced string - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - - $name = str_replace($replaced,'',$file); - - $date = str_replace('.zip','',$arr[1]); - $t = str_replace('-', '', $date); - $time = new DateTime($t); - $timestamp= $time->format("D, d F Y, H:i:s"); - - $url = site_url() . $file; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    FilenameDateOperations
    ' . $name . '' . $timestamp . 'Download
    '; - } - else { - echo 'No available backup!'; - } - } +function get_backup_files() { + if (isset($_SESSION[config("site.url")]['user'])) { + $files = get_zip_files(); + if (!empty($files)) { + krsort($files); + echo ''; + echo ''; + $i = 0; + $len = count($files); + foreach ($files as $file) { + + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + + // Extract the date + $arr = explode('_', $file); + + // Replaced string + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + + $name = str_replace($replaced, '', $file); + + $date = str_replace('.zip', '', $arr[1]); + $t = str_replace('-', '', $date); + $time = new DateTime($t); + $timestamp = $time->format("D, d F Y, H:i:s"); + + $url = site_url() . $file; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
    FilenameDateOperations
    ' . $name . '' . $timestamp . 'Download
    '; + } else { + echo 'No available backup!'; + } + } } function clear_post_cache($post_date, $post_tag, $post_url, $filename) { - $b = str_replace('/', '#', site_path() . '/'); - $t = explode('-', $post_date); - $c = explode(',', $post_tag); - $p = 'cache/page/'.$b.$t[0].'#'.$t[1].'#'.$post_url.'.cache'; - - // Delete post - if (file_exists($p)) { - unlink($p); - } - - // Delete homepage - $yd = 'cache/page/'.$b.'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year - $yd = 'cache/page/'.$b.'archive#'.$t[0].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year-month - $yd = 'cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year-month-day - $yd = 'cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'-'.$t[2].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'-'.$t[2].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete tag - foreach($c as $tag) { - $yd = 'cache/page/'.$b.'tag#'.$tag.'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'tag#'.$tag.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - } - - // Delete search - foreach(glob('cache/page/'.$b.'search#*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - - // Get cache post author - $arr = explode('_', $filename); - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - $str = explode('/', $replaced); - $author = $str[count($str)-3]; - // Delete author post list cache - $a = 'cache/page/'.$b.'author#'.$author.'.cache'; - if (file_exists($a)) { - unlink($a); - } - foreach(glob('cache/page/'.$b.'author#'.$author.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - + $b = str_replace('/', '#', site_path() . '/'); + $t = explode('-', $post_date); + $c = explode(',', $post_tag); + $p = 'cache/page/' . $b . $t[0] . '#' . $t[1] . '#' . $post_url . '.cache'; + + // Delete post + if (file_exists($p)) { + unlink($p); + } + + // Delete homepage + $yd = 'cache/page/' . $b . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year-month + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year-month-day + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '-' . $t[2] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '-' . $t[2] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete tag + foreach ($c as $tag) { + $yd = 'cache/page/' . $b . 'tag#' . $tag . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'tag#' . $tag . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + } + + // Delete search + foreach (glob('cache/page/' . $b . 'search#*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + + // Get cache post author + $arr = explode('_', $filename); + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + $str = explode('/', $replaced); + $author = $str[count($str) - 3]; + // Delete author post list cache + $a = 'cache/page/' . $b . 'author#' . $author . '.cache'; + if (file_exists($a)) { + unlink($a); + } + foreach (glob('cache/page/' . $b . 'author#' . $author . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } } function clear_page_cache($url) { - $b = str_replace('/', '#', site_path() . '/'); - $p = 'cache/page/'.$b.$url.'.cache'; - if (file_exists($p)) { - unlink($p); - } + $b = str_replace('/', '#', site_path() . '/'); + $p = 'cache/page/' . $b . $url . '.cache'; + if (file_exists($p)) { + unlink($p); + } }