Browse Source

Support Multi Author

It has changed the structure of the folder content and some changes in
functions.php and htmly.php, so that it can support multi-author.
pull/4/merge
Danang Probo Sayekti 12 years ago
parent
commit
32132caa3d
10 changed files with 182 additions and 87 deletions
  1. +3
    -0
      content/admin/author.md
  2. +3
    -0
      content/admin/blog/2014-01-01_general_welcome.md
  3. +3
    -0
      content/admin/static/about.md
  4. +3
    -0
      content/admin/static/contact.md
  5. +0
    -3
      content/blog/2014-01-01_general_welcome.md
  6. +0
    -3
      content/static/about.md
  7. +0
    -3
      content/static/contact.md
  8. +1
    -6
      system/config.ini
  9. +24
    -39
      system/htmly.php
  10. +145
    -33
      system/includes/functions.php

+ 3
- 0
content/admin/author.md View File

@ -0,0 +1,3 @@
# Administrator #
I'm this blog administrator.

+ 3
- 0
content/admin/blog/2014-01-01_general_welcome.md View File

@ -0,0 +1,3 @@
# Welcome #
Welcome to Example.com.

+ 3
- 0
content/admin/static/about.md View File

@ -0,0 +1,3 @@
# About
About this blog.

+ 3
- 0
content/admin/static/contact.md View File

@ -0,0 +1,3 @@
# Contact
Contact blog owner at contact@example.com.

+ 0
- 3
content/blog/2014-01-01_general_welcome.md View File

@ -1,3 +0,0 @@
# Welcome #
Welcome Example.com.

+ 0
- 3
content/static/about.md View File

@ -1,3 +0,0 @@
# About
Edit this.

+ 0
- 3
content/static/contact.md View File

@ -1,3 +0,0 @@
# Contact
Edit this.

+ 1
- 6
system/config.ini View File

@ -4,11 +4,6 @@ site.url = ""
; Blog info ; Blog info
blog.title = "HTMLy" blog.title = "HTMLy"
blog.description = "Databaseless Blogging Platform." blog.description = "Databaseless Blogging Platform."
; Author info
blog.author = "Admin"
blog.authorid = "admin"
blog.authorbio = "<p>I'm this blog admin.</p>"
blog.copyright = "(c) Your name." blog.copyright = "(c) Your name."
; Social account ; Social account
@ -51,4 +46,4 @@ default.thumbnail = ""
views.root = "themes/default" views.root = "themes/default"
; Framework config. No need to edit. ; Framework config. No need to edit.
views.layout = "layout"
views.layout = "layout"

+ 24
- 39
system/htmly.php View File

@ -90,32 +90,17 @@ get('/archive/:req',function($req){
} }
$time = explode('-', $req); $time = explode('-', $req);
$date = strtotime($req);
if (isset($time[0]))
{
$y = 'Y';
}
else {
$y = '';
}
if (isset($time[1]))
{
$m = 'F ';
}
else {
$m = '';
}
if (isset($time[2]))
{
$d = 'd ';
if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
$timestamp = date('d F Y', $date);
} }
else if (isset($time[0]) && isset($time[1])) {
$timestamp = date('F Y', $date);
}
else { else {
$d = '';
}
$date = strtotime($req);
$timestamp = $req;
}
if(!$date){ if(!$date){
// a non-existing page // a non-existing page
@ -123,13 +108,13 @@ get('/archive/:req',function($req){
} }
render('main',array( render('main',array(
'title' => 'Archive - ' . date($d . $m . $y, $date) .' - ' . config('blog.title'),
'title' => 'Archive - ' . $timestamp .' - ' . config('blog.title'),
'page' => $page, 'page' => $page,
'posts' => $posts, 'posts' => $posts,
'canonical' => config('site.url') . '/archive/' . $req, 'canonical' => config('site.url') . '/archive/' . $req,
'description' => 'Archive page for ' . date($d . $m . $y, $date) . ' on ' . config('blog.title') . '.',
'description' => 'Archive page for ' . $timestamp . ' on ' . config('blog.title') . '.',
'bodyclass' => 'inarchive', 'bodyclass' => 'inarchive',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; Archive for ' . date($d . $m . $y, $date),
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; Archive for ' . $timestamp,
'pagination' => has_pagination($total, $perpage, $page) 'pagination' => has_pagination($total, $perpage, $page)
)); ));
}); });
@ -226,22 +211,22 @@ get('/:spage', function($spage){
}); });
// The author page // The author page
get('/author/' . config('blog.authorid'), function(){
get('/author/:author', function($author){
$user= new stdClass;
$user->body = config('blog.authorbio');
$user->title = config('blog.author');
$user->authorurl = config('site.url') . '/author/' . config('blog.authorid');
$post = find_author($author);
if(!$post){
not_found();
}
render('post',array( render('post',array(
'title' => $user->title .' - ' . config('blog.title'),
'canonical' => $user->authorurl,
'description' => $description = get_description($user->body),
'bodyclass' => 'inprofile',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; ' . $user->title,
'p' => $user,
'type' => 'profile',
'title' => $post->title .' - ' . config('blog.title'),
'canonical' => $post->url,
'description' => $description = get_description($post->body),
'bodyclass' => 'inpage',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; ' . $post->title,
'p' => $post,
'type' => 'profilepage',
)); ));
}); });


+ 145
- 33
system/includes/functions.php View File

@ -18,7 +18,7 @@ function get_post_names(){
// Get the names of all the // Get the names of all the
// posts (newest first): // posts (newest first):
$_cache = array_reverse(glob('content/blog/*.md'));
$_cache = array_reverse(glob('content/*/blog/*.md'));
} }
return $_cache; return $_cache;
@ -34,7 +34,23 @@ function get_spage_names(){
// Get the names of all the // Get the names of all the
// static page (newest first): // static page (newest first):
$_cache = array_reverse(glob('content/static/*.md'));
$_cache = glob('content/*/static/*.md', GLOB_NOSORT);
}
return $_cache;
}
// Get author bio
function get_author_names(){
static $_cache = array();
if(empty($_cache)){
// Get the names of all the
// author:
$_cache = glob('content/*/author.md', GLOB_NOSORT);
} }
return $_cache; return $_cache;
@ -64,21 +80,28 @@ function get_posts($page = 1, $perpage = 0){
// Extract the date // Extract the date
$arr = explode('_', $v); $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 // The post author + author url
$post->author = config('blog.author');
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
$post->author = $author;
$post->authorurl = site_url() . 'author/' . $author;
// The post date // The post date
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
// The archive per day // The archive per day
$post->archive = site_url(). str_replace('content/blog/','archive/',$arr[0]);
$post->archive = site_url(). 'archive/' . date('Y-m-d', $post->date) ;
// The post URL // The post URL
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
// The post tag // The post tag
$post->tag = str_replace('content/blog/','',$arr[1]);
$post->tag = str_replace($replaced,'',$arr[1]);
// The post tag url // The post tag url
$post->tagurl = site_url(). 'tag/' . $arr[1]; $post->tagurl = site_url(). 'tag/' . $arr[1];
@ -164,18 +187,25 @@ function get_tag($tag){
// Make sure the tag request available // Make sure the tag request available
if ($tag === $arr[1]) { if ($tag === $arr[1]) {
// 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 // The post author + author url
$post->author = config('blog.author');
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
$post->author = $author;
$post->authorurl = site_url() . 'author/' . $author;
// The post date // The post date
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
// The post URL // The post URL
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
// The post tag // The post tag
$post->tag = str_replace('content/blog/','',$arr[1]);
$post->tag = str_replace($replaced,'',$arr[1]);
// The post tag URL // The post tag URL
$post->tagurl = site_url(). 'tag/' . $arr[1]; $post->tagurl = site_url(). 'tag/' . $arr[1];
@ -216,18 +246,25 @@ function get_archive($req){
// Extract the date // Extract the date
$arr = explode('_', $v); $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 // The post author + author url
$post->author = config('blog.author');
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
$post->author = $author;
$post->authorurl = site_url() . 'author/' . $author;
// The post date // The post date
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
// The post URL // The post URL
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
// The post tag // The post tag
$post->tag = str_replace('content/blog/','',$arr[1]);
$post->tag = str_replace($replaced,'',$arr[1]);
// The post tag URL // The post tag URL
$post->tagurl = site_url(). 'tag/' . $arr[1]; $post->tagurl = site_url(). 'tag/' . $arr[1];
@ -257,7 +294,12 @@ function archive_list() {
foreach($posts as $index => $v){ foreach($posts as $index => $v){
$arr = explode('_', $v); $arr = explode('_', $v);
$date = str_replace('content/blog/','',$arr[0]);
// Replaced string
$str = $arr[0];
$replaced = substr($str, 0,strrpos($str, '/')) . '/';
$date = str_replace($replaced,'',$arr[0]);
$data = explode('-', $date); $data = explode('-', $date);
$col[] = $data; $col[] = $data;
@ -312,8 +354,11 @@ function get_spage($posts, $spage){
// Extract the array // Extract the array
$arr = explode('_', $v); $arr = explode('_', $v);
// Replaced string
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
// The static page URL // The static page URL
$url = str_replace('content/static/','',$arr[0]);
$url = str_replace($replaced,'',$arr[0]);
$post->url = site_url() . str_replace('.md','',$url); $post->url = site_url() . str_replace('.md','',$url);
// Get the contents and convert it to HTML // Get the contents and convert it to HTML
@ -350,6 +395,68 @@ function find_spage($spage){
return false; return false;
} }
// Return author page
function get_author($names, $author){
$tmp = array();
// Create a new instance of the markdown parser
$md = new MarkdownParser();
foreach($names as $index => $v){
$post = new stdClass;
// Extract the array
$arr = explode('_', $v);
// Replaced string
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
// Author string
$str = explode('/', $replaced);
$profile = $str[count($str)-2];
if($author === $profile){
// Profile URL
$url = str_replace($replaced,'',$arr[0]);
$post->url = site_url() . 'author/' . $profile;
// 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;
}
else {
not_found();
}
}
return $tmp;
}
// Find static page
function find_author($author){
$names = get_author_names();
foreach($names as $index => $v){
if( strpos($v, $author) !== false && strpos($v, 'author.md') !== false){
// Use the get_spage method to return
// a properly parsed object
$arr = get_author($names, $author);
return $arr[0];
}
}
return false;
}
// Return search page // Return search page
function get_keyword($keyword){ function get_keyword($keyword){
@ -370,20 +477,25 @@ function get_keyword($keyword){
// Extract the date // Extract the date
$arr = explode('_', $v); $arr = explode('_', $v);
// Make sure the tag request available
// 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 // The post author + author url
$post->author = config('blog.author');
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
$post->author = $author;
$post->authorurl = site_url() . 'author/' . $author;
// The post date // The post date
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
// The post URL // The post URL
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
// The post tag // The post tag
$post->tag = str_replace('content/blog/','',$arr[1]);
$post->tag = str_replace($replaced,'',$arr[1]);
// The post tag URL // The post tag URL
$post->tagurl = site_url(). 'tag/' . $arr[1]; $post->tagurl = site_url(). 'tag/' . $arr[1];
@ -604,16 +716,16 @@ function publisher(){
function analytics(){ function analytics(){
$analytics = config('google.analytics.id'); $analytics = config('google.analytics.id');
$script = <<<EOF $script = <<<EOF
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{$analytics}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{$analytics}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
EOF; EOF;
if (!empty($analytics)) { if (!empty($analytics)) {
return $script; return $script;
@ -661,4 +773,4 @@ function generate_rss($posts){
// Turn an array of posts into a JSON // Turn an array of posts into a JSON
function generate_json($posts){ function generate_json($posts){
return json_encode($posts); return json_encode($posts);
}
}

Loading…
Cancel
Save