Browse Source

Bugs fixes and improvements

Bugs fixes and improvements. Multi author fixed, post sort by date fixed
etc.
pull/4/merge
Danang Probo Sayekti 12 years ago
parent
commit
8d4e2abf72
5 changed files with 87 additions and 87 deletions
  1. +9
    -12
      system/htmly.php
  2. +73
    -70
      system/includes/functions.php
  3. +1
    -1
      themes/default/main.html.php
  4. +1
    -1
      themes/default/post.html.php
  5. +3
    -3
      themes/default/profile.html.php

+ 9
- 12
system/htmly.php View File

@ -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')));
});


+ 73
- 70
system/includes/functions.php View File

@ -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('</h1>', $content);
$post->title = str_replace('<h1>','',$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 '<h3>Tags</h3>';
echo '<ul class="taglist">';
foreach ($tag_collection as $tag => $count){
echo '<li class="item"><a href="' . site_url() . 'tag/' . $tag . '">' . ucfirst($tag) . '</a> <span class="count">(' . $count . ')</span></li>';
echo '<li class="item"><a href="' . site_url() . 'tag/' . $tag . '">' . $tag . '</a> <span class="count">(' . $count . ')</span></li>';
}
echo '</ul>';


+ 1
- 1
themes/default/main.html.php View File

@ -16,7 +16,7 @@
<div class="post <?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="main">
<h2 class="title-index" itemprop="name"><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></h2>
<div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo ucfirst($p->tag) ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div>
<div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo $p->tag ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div>
<div itemprop="articleBody">
<?php if (config('img.thumbnail') == 'true'):?>
<?php echo get_thumbnail($p->body)?>


+ 1
- 1
themes/default/post.html.php View File

@ -6,7 +6,7 @@
<?php endif;?>
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
<?php if ($type == 'blogpost'):?>
<div class="date"><span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo ucfirst($p->tag) ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> - <span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span></div>
<div class="date"><span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo $p->tag ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> - <span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span></div>
<?php endif;?>
<div itemprop="articleBody">
<?php echo $p->body; ?>


+ 3
- 3
themes/default/profile.html.php View File

@ -1,7 +1,7 @@
<?php if (!empty($breadcrumb)):?><div class="breadcrumb"><?php echo $breadcrumb ?></div><?php endif;?>
<div class="profile">
<h1 class="title-post"><?php echo $name ?></h1>
<div class="bio"><?php echo $bio ?></div>
<div class="profile" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="Person">
<h1 class="title-post" itemprop="name"><?php echo $name ?></h1>
<div class="bio" itemprop="description"><?php echo $bio ?></div>
</div>
<h2 class="post-index">Posts by this author</h2>
<ul class="post-list">


Loading…
Cancel
Save