diff --git a/content/admin/author.md b/content/admin/author.md new file mode 100644 index 0000000..c6bbbd2 --- /dev/null +++ b/content/admin/author.md @@ -0,0 +1,3 @@ +# Administrator # + +I'm this blog administrator. \ No newline at end of file diff --git a/content/admin/blog/2014-01-01_general_welcome.md b/content/admin/blog/2014-01-01_general_welcome.md new file mode 100644 index 0000000..335a2a2 --- /dev/null +++ b/content/admin/blog/2014-01-01_general_welcome.md @@ -0,0 +1,3 @@ +# Welcome # + +Welcome to Example.com. \ No newline at end of file diff --git a/content/admin/static/about.md b/content/admin/static/about.md new file mode 100644 index 0000000..d08eeaa --- /dev/null +++ b/content/admin/static/about.md @@ -0,0 +1,3 @@ +# About + +About this blog. \ No newline at end of file diff --git a/content/admin/static/contact.md b/content/admin/static/contact.md new file mode 100644 index 0000000..3b6ff5c --- /dev/null +++ b/content/admin/static/contact.md @@ -0,0 +1,3 @@ +# Contact + +Contact blog owner at contact@example.com. \ No newline at end of file diff --git a/content/blog/2014-01-01_general_welcome.md b/content/blog/2014-01-01_general_welcome.md deleted file mode 100644 index 4890360..0000000 --- a/content/blog/2014-01-01_general_welcome.md +++ /dev/null @@ -1,3 +0,0 @@ -# Welcome # - -Welcome Example.com. \ No newline at end of file diff --git a/content/static/about.md b/content/static/about.md deleted file mode 100644 index e94fb71..0000000 --- a/content/static/about.md +++ /dev/null @@ -1,3 +0,0 @@ -# About - -Edit this. \ No newline at end of file diff --git a/content/static/contact.md b/content/static/contact.md deleted file mode 100644 index a4f7737..0000000 --- a/content/static/contact.md +++ /dev/null @@ -1,3 +0,0 @@ -# Contact - -Edit this. \ No newline at end of file diff --git a/system/config.ini b/system/config.ini index ecf1561..acefdcf 100644 --- a/system/config.ini +++ b/system/config.ini @@ -4,11 +4,6 @@ site.url = "" ; Blog info blog.title = "HTMLy" blog.description = "Databaseless Blogging Platform." - -; Author info -blog.author = "Admin" -blog.authorid = "admin" -blog.authorbio = "

I'm this blog admin.

" blog.copyright = "(c) Your name." ; Social account @@ -51,4 +46,4 @@ default.thumbnail = "" views.root = "themes/default" ; Framework config. No need to edit. -views.layout = "layout" +views.layout = "layout" \ No newline at end of file diff --git a/system/htmly.php b/system/htmly.php index e5a9241..eb5b9ca 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -90,32 +90,17 @@ get('/archive/:req',function($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 { - $d = ''; - } - - $date = strtotime($req); + $timestamp = $req; + } if(!$date){ // a non-existing page @@ -123,13 +108,13 @@ get('/archive/:req',function($req){ } render('main',array( - 'title' => 'Archive - ' . date($d . $m . $y, $date) .' - ' . config('blog.title'), + 'title' => 'Archive - ' . $timestamp .' - ' . config('blog.title'), 'page' => $page, 'posts' => $posts, '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', - 'breadcrumb' => 'Home » Archive for ' . date($d . $m . $y, $date), + 'breadcrumb' => 'Home » Archive for ' . $timestamp, 'pagination' => has_pagination($total, $perpage, $page) )); }); @@ -226,22 +211,22 @@ get('/:spage', function($spage){ }); // 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( - 'title' => $user->title .' - ' . config('blog.title'), - 'canonical' => $user->authorurl, - 'description' => $description = get_description($user->body), - 'bodyclass' => 'inprofile', - 'breadcrumb' => 'Home » ' . $user->title, - 'p' => $user, - 'type' => 'profile', + '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', )); }); diff --git a/system/includes/functions.php b/system/includes/functions.php index 864126e..02d8937 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -18,7 +18,7 @@ function get_post_names(){ // Get the names of all the // posts (newest first): - $_cache = array_reverse(glob('content/blog/*.md')); + $_cache = array_reverse(glob('content/*/blog/*.md')); } return $_cache; @@ -34,7 +34,23 @@ function get_spage_names(){ // Get the names of all the // 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; @@ -64,21 +80,28 @@ function get_posts($page = 1, $perpage = 0){ // 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 = config('blog.author'); - $post->authorurl = site_url() . 'author/' . config('blog.authorid'); + $post->author = $author; + $post->authorurl = site_url() . 'author/' . $author; // The post date - $post->date = strtotime(str_replace('content/blog/','',$arr[0])); + $post->date = strtotime(str_replace($replaced,'',$arr[0])); // 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 $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); // The post tag - $post->tag = str_replace('content/blog/','',$arr[1]); + $post->tag = str_replace($replaced,'',$arr[1]); // The post tag url $post->tagurl = site_url(). 'tag/' . $arr[1]; @@ -164,18 +187,25 @@ function get_tag($tag){ // Make sure the tag request available 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 - $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 - $post->date = strtotime(str_replace('content/blog/','',$arr[0])); + $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('content/blog/','',$arr[1]); + $post->tag = str_replace($replaced,'',$arr[1]); // The post tag URL $post->tagurl = site_url(). 'tag/' . $arr[1]; @@ -216,18 +246,25 @@ function get_archive($req){ // 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 = config('blog.author'); - $post->authorurl = site_url() . 'author/' . config('blog.authorid'); + $post->author = $author; + $post->authorurl = site_url() . 'author/' . $author; // The post date - $post->date = strtotime(str_replace('content/blog/','',$arr[0])); + $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('content/blog/','',$arr[1]); + $post->tag = str_replace($replaced,'',$arr[1]); // The post tag URL $post->tagurl = site_url(). 'tag/' . $arr[1]; @@ -257,7 +294,12 @@ function archive_list() { foreach($posts as $index => $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); $col[] = $data; @@ -312,8 +354,11 @@ function get_spage($posts, $spage){ // Extract the array $arr = explode('_', $v); + // Replaced string + $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; + // 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); // Get the contents and convert it to HTML @@ -350,6 +395,68 @@ function find_spage($spage){ 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('', $content); + $post->title = str_replace('

','',$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 function get_keyword($keyword){ @@ -370,20 +477,25 @@ function get_keyword($keyword){ // Extract the date $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 - $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 - $post->date = strtotime(str_replace('content/blog/','',$arr[0])); + $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('content/blog/','',$arr[1]); + $post->tag = str_replace($replaced,'',$arr[1]); // The post tag URL $post->tagurl = site_url(). 'tag/' . $arr[1]; @@ -604,16 +716,16 @@ function publisher(){ function analytics(){ $analytics = config('google.analytics.id'); $script = << - 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); - })(); - + EOF; if (!empty($analytics)) { return $script; @@ -661,4 +773,4 @@ function generate_rss($posts){ // Turn an array of posts into a JSON function generate_json($posts){ return json_encode($posts); -} +} \ No newline at end of file