diff --git a/system/config.ini b/system/config.ini index acefdcf..fe1fc0c 100644 --- a/system/config.ini +++ b/system/config.ini @@ -29,6 +29,7 @@ posts.perpage = "5" tag.perpage = "10" archive.perpage = "10" search.perpage = "10" +profile.perpage = "30" rss.count = "30" json.count = "10" diff --git a/system/htmly.php b/system/htmly.php index eb5b9ca..d3e2381 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -157,7 +157,7 @@ get('/:year/:month/:name', function($year, $month, $name){ )); }); -// The static page +// The search page get('/search/:keyword', function($keyword){ $page = from($_GET, 'page'); @@ -211,24 +211,37 @@ get('/:spage', function($spage){ }); // The author page -get('/author/:author', function($author){ +get('/author/:profile',function($profile){ + + $page = from($_GET, 'page'); + $page = $page ? (int)$page : 1; + $perpage = config('profile.perpage'); + + $posts = get_profile($profile); + $bio = bio($profile); - $post = find_author($author); + $total = count($posts); - if(!$post){ + // Extract a specific page with results + $posts = array_slice($posts, ($page-1) * $perpage, $perpage); + + if(empty($posts) || $page < 1){ + // a non-existing page not_found(); } - - render('post',array( - 'title' => $post->title .' - ' . config('blog.title'), - 'canonical' => $post->url, - 'description' => $description = get_description($post->body), - 'bodyclass' => 'inpage', - 'breadcrumb' => 'Home » ' . $post->title, - 'p' => $post, - 'type' => 'profilepage', + + render('profile',array( + 'title' => 'Author - '. $bio->title .' - ' . config('blog.title'), + 'page' => $page, + 'posts' => $posts, + 'bio' => $bio->body, + 'name' => $bio->title, + 'canonical' => config('site.url') . '/author/' . $profile, + 'description' => 'Profile page and all posts by ' . $bio->title . ' on ' . config('blog.title') . '.', + 'bodyclass' => 'inprofile', + 'breadcrumb' => 'Home » Profile page for ' . $bio->title, + 'pagination' => has_pagination($total, $perpage, $page) )); - }); // The JSON API diff --git a/system/includes/functions.php b/system/includes/functions.php index 79ce4a5..478194d 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -395,8 +395,68 @@ function find_spage($spage){ return false; } -// Return author page -function get_author($names, $author){ +// Return profile page +function get_profile($profile){ + + $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, "$profile") !== false){ + + $post = new stdClass; + + // 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]; + + // Make sure the tag request available + if ($profile === $author) { + + // 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])); + + // The post URL + $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); + + // 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('