From 8d4e2abf728c93d4dc49e196f0d2e79b84b35bf5 Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Tue, 7 Jan 2014 16:56:10 +0700 Subject: [PATCH] Bugs fixes and improvements Bugs fixes and improvements. Multi author fixed, post sort by date fixed etc. --- system/htmly.php | 21 +++--- system/includes/functions.php | 143 ++++++++++++++++++++-------------------- themes/default/main.html.php | 2 +- themes/default/post.html.php | 2 +- themes/default/profile.html.php | 6 +- 5 files changed, 87 insertions(+), 87 deletions(-) diff --git a/system/htmly.php b/system/htmly.php index 08d6c2a..df7cc7e 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -19,7 +19,7 @@ get('/index', function () { $page = $page ? (int)$page : 1; $perpage = config('posts.perpage'); - $posts = get_posts($page, $perpage); + $posts = get_posts(null, $page, $perpage); $total = ''; @@ -59,7 +59,7 @@ get('/tag/:tag',function($tag){ } render('main',array( - 'title' => ucfirst($tag) .' - ' . config('blog.title'), + 'title' => 'Tag - ' . ucfirst($tag) .' - ' . config('blog.title'), 'page' => $page, 'posts' => $posts, 'canonical' => config('site.url') . '/tag/' . $tag, @@ -122,16 +122,13 @@ get('/archive/:req',function($req){ // The blog post page get('/:year/:month/:name', function($year, $month, $name){ - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = 1; - $post = find_post($year, $month, $name); - // Extract a specific page with results - $post = array_slice($post, 0, $perpage); + $current = $post['current']; - $current = $post[0]; + if(!$current){ + not_found(); + } if (array_key_exists('prev', $post)) { $prev = $post['prev']; @@ -181,7 +178,7 @@ get('/search/:keyword', function($keyword){ } render('main',array( - 'title' => 'Search results for: ' . $keyword . ' - ' . config('blog.title'), + 'title' => 'Search - ' . $keyword . ' - ' . config('blog.title'), 'page' => $page, 'posts' => $posts, 'canonical' => config('site.url') . '/search/' . $keyword, @@ -253,7 +250,7 @@ get('/api/json',function(){ header('Content-type: application/json'); // Print the 10 latest posts as JSON - echo generate_json(get_posts(1, config('json.count'))); + echo generate_json(get_posts(null, 1, config('json.count'))); }); // Show the RSS feed @@ -262,7 +259,7 @@ get('/feed/rss',function(){ header('Content-Type: application/rss+xml'); // Show an RSS feed with the 30 latest posts - echo generate_rss(get_posts(1, config('rss.count'))); + echo generate_rss(get_posts(null, 1, config('rss.count'))); }); diff --git a/system/includes/functions.php b/system/includes/functions.php index 664266f..321b226 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -62,78 +62,18 @@ function cmp($a, $b) { } // Return blog post -function get_posts($page = 1, $perpage = 0){ +function get_posts($posts, $page = 1, $perpage = 0){ - $posts = get_post_names(); - - $tmp = array(); - - // Create a new instance of the markdown parser - $md = new MarkdownParser(); - - foreach($posts as $k=>$v){ - - $post = new stdClass; + if(empty($posts)) { - // Extract the date - $arr = explode('_', $v); - - // 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; - - // The post date - $post->date = strtotime(str_replace($replaced,'',$arr[0])); + $posts = get_post_names(); - // The archive per day - $post->archive = site_url(). 'archive/' . date('Y-m-d', $post->date) ; + $tmp = array(); - // The post URL - $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); + // Create a new instance of the markdown parser + $md = new MarkdownParser(); - // The post tag - $post->tag = str_replace($replaced,'',$arr[1]); - - // The post tag url - $post->tagurl = site_url(). 'tag/' . $arr[1]; - - // Get the contents and convert it to HTML - $content = $md->transformMarkdown(file_get_contents($v)); - - // Extract the title and body - $arr = explode('', $content); - $post->title = str_replace('

','',$arr[0]); - $post->body = $arr[1]; - - $tmp[] = $post; - } - - usort($tmp,'cmp'); - - // Extract a specific page with results - $tmp = array_slice($tmp, ($page-1) * $perpage, $perpage); - - return $tmp; -} - -// Find post by year, month and name, previous, and next. -function find_post($year, $month, $name){ - - $posts = get_post_names(); - $tmp = array(); - - // Create a new instance of the markdown parser - $md = new MarkdownParser(); - - foreach($posts as $index => $v){ - if( strpos($v, "$year-$month") !== false && strpos($v, $name.'.md') !== false){ + foreach($posts as $k=>$v){ $post = new stdClass; @@ -176,10 +116,73 @@ function find_post($year, $month, $name){ $tmp[] = $post; } - } + + usort($tmp,'cmp'); - usort($tmp,'cmp'); + + // Extract a specific page with results + $tmp = array_slice($tmp, ($page-1) * $perpage, $perpage); + + return $tmp; + + } + else { + + // Extract a specific page with results + $tmp = array_slice($posts, ($page-1) * $perpage, $perpage); + return $tmp; + + } +} + +// Find post by year, month and name, previous, and next. +function find_post($year, $month, $name){ + + $posts = get_posts(null, null, null); + $tmp = $posts; + + foreach ($tmp as $index => $v) { + $url = $v->url; + if (strpos($url, $year . '/' . $month . '/' . $name) !== false) { + + // Use the get_posts method to return + // a properly parsed object + + $ar = get_posts($posts, $index+1,1); + $nx = get_posts($posts, $index,1); + $pr = get_posts($posts, $index+2,1); + + if ($index == 0) { + if(isset($pr[0])) { + return array( + 'current'=> $ar[0], + 'prev'=> $pr[0] + ); + } + else { + return array( + 'current'=> $ar[0], + 'prev'=> null + ); + } + } + elseif (count($posts) == $index+1) { + return array( + 'current'=> $ar[0], + 'next'=> $nx[0] + ); + } + else { + return array( + 'current'=> $ar[0], + 'next'=> $nx[0], + 'prev'=> $pr[0] + ); + } + + } + } } // Return tag page @@ -377,7 +380,7 @@ function tag_cloud() { echo '

Tags

'; echo ''; diff --git a/themes/default/main.html.php b/themes/default/main.html.php index aed5180..8c24dc9 100644 --- a/themes/default/main.html.php +++ b/themes/default/main.html.php @@ -16,7 +16,7 @@

title ?>

-
- Posted in tag) ?> by - Comments
+
- Posted in tag ?> by - Comments
body)?> diff --git a/themes/default/post.html.php b/themes/default/post.html.php index fe7c710..c3e2c1a 100644 --- a/themes/default/post.html.php +++ b/themes/default/post.html.php @@ -6,7 +6,7 @@

title ?>

- +
body; ?> diff --git a/themes/default/profile.html.php b/themes/default/profile.html.php index fd6b2db..362fedb 100644 --- a/themes/default/profile.html.php +++ b/themes/default/profile.html.php @@ -1,7 +1,7 @@ -
-

-
+
+

+

Posts by this author