date == $b->date ? 0 : ( $a->date < $b->date ) ? 1 : -1;
}
// Rebuilt cache index
function rebuilt_cache($type) {
$dir = 'cache/index';
$posts_cache_sorted = array();
$posts_cache_unsorted = array();
$page_cache = array();
$author_cache = array();
if(is_dir($dir) === false) {
mkdir($dir, 0777, true);
}
if($type === 'posts') {
$posts_cache_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT);
$string = serialize($posts_cache_unsorted);
file_put_contents('cache/index/index-unsorted.txt', print_r($string, true));
$tmp= array();
$tmp = glob('content/*/blog/*.md', GLOB_NOSORT);
if (is_array($tmp)) {
foreach($tmp as $file) {
$posts_cache_sorted[] = pathinfo($file);
}
}
usort($posts_cache_sorted, "sortfile");
$string = serialize($posts_cache_sorted);
file_put_contents('cache/index/index-sorted.txt', print_r($string, true));
}
elseif ($type === 'page') {
$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 === 'author') {
$author_cache = glob('content/*/author.md', GLOB_NOSORT);
$string = serialize($author_cache);
file_put_contents('cache/index/index-author.txt', print_r($string, true));
}
elseif ($type === 'all') {
$posts_cache_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT);
$string = serialize($posts_cache_unsorted);
file_put_contents('cache/index/index-unsorted.txt', print_r($string, true));
$tmp= array();
$tmp = glob('content/*/blog/*.md', GLOB_NOSORT);
if (is_array($tmp)) {
foreach($tmp as $file) {
$posts_cache_sorted[] = pathinfo($file);
}
}
usort($posts_cache_sorted, "sortfile");
$string = serialize($posts_cache_sorted);
file_put_contents('cache/index/index-sorted.txt', print_r($string, true));
$page_cache = glob('content/static/*.md', GLOB_NOSORT);
$string = serialize($page_cache);
file_put_contents('cache/index/index-page.txt', print_r($string, true));
$author_cache = glob('content/*/author.md', GLOB_NOSORT);
$string = serialize($author_cache);
file_put_contents('cache/index/index-author.txt', print_r($string, true));
}
}
// Return blog posts.
function get_posts($posts, $page = 1, $perpage = 0){
if(empty($posts)) {
$posts = get_post_sorted();
}
$tmp = array();
// Extract a specific page with results
$posts = array_slice($posts, ($page-1) * $perpage, $perpage);
foreach($posts as $index => $v){
$post = new stdClass;
$filepath = $v['dirname'] . '/' . $v['basename'];
// Extract the date
$arr = explode('_', $filepath);
// Replaced string
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
// Author string
$str = explode('/', $replaced);
$author = $str[count($str)-3];
// The post author + author url
$post->author = $author;
$post->authorurl = site_url() . 'author/' . $author;
$dt = str_replace($replaced,'',$arr[0]);
$t = str_replace('-', '', $dt);
$time = new DateTime($t);
$timestamp= $time->format("Y-m-d H:i:s");
// The post date
$post->date = strtotime($timestamp);
// The archive per day
$post->archive = site_url(). 'archive/' . date('Y-m-d', $post->date) ;
// The post URL
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
$tag = array();
$url = array();
$bc = array();
$t = explode(',', $arr[1]);
foreach($t as $tt) {
$tag[] = array($tt, site_url(). 'tag/' . $tt);
}
foreach($tag as $a) {
$url[] = ''. $a[0] .'';
$bc[] = ''. $a[0] .'';
}
$post->tag = implode(', ', $url);
$post->tagb = implode(' ยป ', $bc);
$post->file = $filepath;
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($filepath));
// Extract the title and body
$arr = explode('t-->', $content);
if(isset($arr[1])) {
$title = str_replace('', $content);
if(isset($arr[1])) {
$title = str_replace('', $content);
if(isset($arr[1])) {
$title = str_replace('', $content);
if(isset($arr[1])) {
$title = str_replace('