From 36f4c2d4df02da7e4b332ac1ae3dad499631a14c Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Fri, 7 Feb 2014 07:14:05 +0700 Subject: [PATCH] Various improvements Various improvements --- changelog.txt | 1 + config/{config.ini => config.ini.example} | 0 system/admin/admin.php | 144 +++++++++++--- system/admin/views/add-page.html.php | 11 +- system/admin/views/add-post.html.php | 13 +- system/admin/views/delete-page.html.php | 20 +- system/admin/views/delete-post.html.php | 27 ++- system/admin/views/edit-page.html.php | 22 ++- system/admin/views/edit-post.html.php | 37 +++- system/admin/views/edit-profile.html.php | 9 +- system/admin/views/import.html.php | 10 + system/admin/views/layout.html.php | 1 + system/admin/views/login.html.php | 12 +- system/htmly.php | 310 +++++++++++++++++++++++++++--- system/includes/functions.php | 109 ++++++++--- themes/clean/css/style.css | 11 +- themes/clean/layout.html.php | 1 + themes/default/css/style.css | 31 ++- themes/default/layout.html.php | 1 + 19 files changed, 655 insertions(+), 115 deletions(-) rename config/{config.ini => config.ini.example} (100%) create mode 100644 system/admin/views/import.html.php diff --git a/changelog.txt b/changelog.txt index 91e01cd..bf8b03f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,2 +1,3 @@ +2014-02-01: HTMLy v1.0. 2014-01-26: RC version. 2014-01-01: Initial release. \ No newline at end of file diff --git a/config/config.ini b/config/config.ini.example similarity index 100% rename from config/config.ini rename to config/config.ini.example diff --git a/system/admin/admin.php b/system/admin/admin.php index 42ada8c..46c1855 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -9,11 +9,7 @@ function user($key, $user=null) { } } -function login_message($str = null) { - echo $str; -} - -function session($user, $pass) { +function session($user, $pass, $str = null) { $user_file = 'config/users/' . $user . '.ini'; $user_pass = user('password', $user); @@ -23,13 +19,11 @@ function session($user, $pass) { header('location: admin'); } else { - $str = '

Your username and password are wrong.

Back

'; - login_message($str); + return $str = '
  • Your username and password mismatch.
  • '; } } else { - $str = '

    Username not found in our record.

    Back

    '; - login_message($str); + return $str = '
  • Username not found in our record.
  • '; } } @@ -39,9 +33,12 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) $post_title = $title; $post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tag); - $post_tag = rtrim($post_tag, ',\.\-'); - $post_url = preg_replace('/[^A-Za-z0-9,.-]/u', '', $url); - $post_url = rtrim($post_url, ',\.\-'); + $post_tag = str_replace(' ', '-',$post_tag); + $post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-'); + $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); + $post_url = str_replace(' ', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); + $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { @@ -59,7 +56,8 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) $replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/'; $dt = str_replace($replaced,'',$oldurl[0]); - $time = new DateTime($dt); + $t = str_replace('-','',$dt); + $time = new DateTime($t); $timestamp= $time->format("Y-m-d"); // The post date $postdate = strtotime($timestamp); @@ -90,8 +88,10 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) { $dir = substr($oldfile, 0, strrpos($oldfile, '/')); $post_title = $title; - $post_url = preg_replace('/[^A-Za-z0-9,.-]/u', '', $url); - $post_url = rtrim($post_url, ',\.\-'); + $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); + $post_url = str_replace(' ', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); + $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { @@ -127,12 +127,14 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) { function add_post($title, $tag, $url, $content, $user) { - $post_date = date('Y-m-d-H-i'); + $post_date = date('Y-m-d-H-i-s'); $post_title = $title; $post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tag); - $post_tag = rtrim($post_tag, ',\.\-'); - $post_url = preg_replace('/[^A-Za-z0-9,.-]/u', '', $url); - $post_url = rtrim($post_url, ',\.\-'); + $post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-'); + $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); + $post_url = str_replace(' ', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); + $post_url = rtrim(ltrim($post_url, ' \,\.\-'), ' \,\.\-'); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { @@ -157,8 +159,10 @@ function add_post($title, $tag, $url, $content, $user) { function add_page($title, $url, $content) { $post_title = $title; - $post_url = preg_replace('/[^A-Za-z0-9,.-]/u', '', $url); - $post_url = rtrim($post_url, ',\.\-'); + $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); + $post_url = str_replace(' ', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); + $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { @@ -184,8 +188,14 @@ function delete_post($file, $destination) { $deleted_content = $file; if(!empty($deleted_content)) { unlink($deleted_content); - $redirect = site_url() . $destination; - header("Location: $redirect"); + if($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } + else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } } } @@ -193,8 +203,14 @@ function delete_page($file, $destination) { $deleted_content = $file; if(!empty($deleted_content)) { unlink($deleted_content); - $redirect = site_url() . $destination; - header("Location: $redirect"); + if($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } + else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } } } @@ -222,6 +238,84 @@ function edit_profile($title, $content, $user) { } +function migrate($title, $time, $tags, $content, $url, $user, $source) { + + $post_date = date('Y-m-d-H-i-s', $time); + $post_title = $title; + $post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tags); + $post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-'); + $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); + $post_url = str_replace(' ', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); + $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); + if(!empty($source)) { + $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; + } + else { + $post_content = '' . "\n\n" . $content; + } + if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if(get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; + $dir = 'content/' . $user. '/blog/'; + if(is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } + else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + $redirect = site_url() . 'admin/posts'; + header("Location: $redirect"); + } + +} + +function get_feed($feed_url, $credit, $message=null) { + $source = file_get_contents($feed_url); + $feed = new SimpleXmlElement($source); + if(!empty($feed->channel->item)) { + foreach($feed->channel->item as $entry) { + $descriptionA = $entry->children('content', true); + $descriptionB = $entry->description; + if(!empty($descriptionA)) { + $content = $descriptionA; + } + else if (!empty($descriptionB)) { + $content = preg_replace('##i', "\n", $descriptionB); + } + else { + return $str = '
  • Can not read the feed content.
  • '; + } + $time = new DateTime($entry->pubDate); + $timestamp= $time->format("Y-m-d H:i:s"); + $time = strtotime($timestamp); + $tags = strip_tags(preg_replace('/[^A-Za-z0-9,.-]/u', '', $entry->category)); + $title = rtrim($entry->title, ' \,\.\-'); + $title = ltrim($title, ' \,\.\-'); + $user = $_SESSION['user']; + $url = preg_replace('/[^A-Za-z0-9 .-]/u', '', strtolower($title)); + $url = str_replace(' ', '-',$url); + $url = str_replace('--', '-',$url); + $url = rtrim($url, ',\.\-'); + $url = ltrim($url, ',\.\-'); + if ($credit == 'yes') { + $source = $entry->link; + } + else { + $source= null; + } + migrate($title, $time, $tags, $content, $url, $user, $source); + } + } + else { + return $str= '
  • Unsupported feed.
  • '; + } + +} + function get_recent_posts() { if (isset($_SESSION['user'])) { $posts = get_profile($_SESSION['user'], 1, 5); diff --git a/system/admin/views/add-page.html.php b/system/admin/views/add-page.html.php index 7d68ee8..c0412cc 100644 --- a/system/admin/views/add-page.html.php +++ b/system/admin/views/add-page.html.php @@ -2,12 +2,17 @@ + +
    +
    - Title:


    - Url:


    + Title *


    + Url (optional)

    + If the url leave empty we will use the page title. +

    -
    +
    diff --git a/system/admin/views/add-post.html.php b/system/admin/views/add-post.html.php index 3dc53b1..4c62a1b 100644 --- a/system/admin/views/add-post.html.php +++ b/system/admin/views/add-post.html.php @@ -2,13 +2,18 @@ + +
    +
    - Title:


    - Tag:


    - Url:


    + Title *


    + Tag *


    + Url (optional)

    + If the url leave empty we will use the post title. +

    -
    +
    diff --git a/system/admin/views/delete-page.html.php b/system/admin/views/delete-page.html.php index 1dfabac..56c4e6d 100644 --- a/system/admin/views/delete-page.html.php +++ b/system/admin/views/delete-page.html.php @@ -1,6 +1,24 @@ +file; + + $dir = substr($url, 0, strrpos($url, '/')); + $oldurl = str_replace($dir . '/','',$url); + $oldmd = str_replace('.md','',$oldurl); + + $post = site_url() . $oldmd; + + if($destination == 'post') { + $back = $post; + } + else { + $back = site_url() . $destination; + } + +?> Are you sure want to delete ' . $p->title . '?

    ';?>

    - Cancel + Cancel
    \ No newline at end of file diff --git a/system/admin/views/delete-post.html.php b/system/admin/views/delete-post.html.php index 4f79066..adea149 100644 --- a/system/admin/views/delete-post.html.php +++ b/system/admin/views/delete-post.html.php @@ -1,6 +1,31 @@ +file; + $oldurl = explode('_', $url); + $oldtag = $oldurl[1]; + $oldmd = str_replace('.md','',$oldurl[2]); + + $replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/'; + $dt = str_replace($replaced,'',$oldurl[0]); + $t = str_replace('-','',$dt); + $time = new DateTime($t); + $timestamp= $time->format("Y-m-d"); + // The post date + $postdate = strtotime($timestamp); + // The post URL + $post = site_url().date('Y/m', $postdate).'/'.$oldmd; + + if($destination == 'post') { + $back = $post; + } + else { + $back = site_url() . $destination; + } + +?> Are you sure want to delete ' . $p->title . '?

    ';?>

    - Cancel + Cancel
    \ No newline at end of file diff --git a/system/admin/views/edit-page.html.php b/system/admin/views/edit-page.html.php index 4799f23..039c3ce 100644 --- a/system/admin/views/edit-page.html.php +++ b/system/admin/views/edit-page.html.php @@ -1,6 +1,11 @@ file; + if(isset($p->file)) { + $url = $p->file; + } + else { + $url = $oldfile; + } $content = file_get_contents($url); $arr = explode('t-->', $content); if(isset($arr[1])) { @@ -12,23 +17,30 @@ $oldcontent = ltrim($arr[0]); } + $destination = $_GET['destination']; $dir = substr($url, 0, strrpos($url, '/')); $oldurl = str_replace($dir . '/','',$url); $oldmd = str_replace('.md','',$oldurl); + $delete = site_url() . $oldmd . '/delete?destination=' . $destination; + ?> + +
    +
    - Title:


    - Url:


    + Title *


    + Url (optional)

    + If the url leave empty we will use the page title.

    -
    +
    - + Delete
    diff --git a/system/admin/views/edit-post.html.php b/system/admin/views/edit-post.html.php index 1426ab8..0d4f79b 100644 --- a/system/admin/views/edit-post.html.php +++ b/system/admin/views/edit-post.html.php @@ -1,5 +1,11 @@ -file; +file)) { + $url = $p->file; + } + else { + $url = $oldfile; + } + $content = file_get_contents($url); $arr = explode('t-->', $content); if(isset($arr[1])) { @@ -19,20 +25,37 @@ $oldmd = str_replace('.md','',$oldurl[2]); + $destination = $_GET['destination']; + $replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/'; + $dt = str_replace($replaced,'',$oldurl[0]); + $t = str_replace('-','',$dt); + $time = new DateTime($t); + $timestamp= $time->format("Y-m-d"); + // The post date + $postdate = strtotime($timestamp); + // The post URL + $delete= site_url().date('Y/m', $postdate).'/'.$oldmd . '/delete?destination=' . $destination; + + ?> + +
    +
    - Title:


    - Tag:


    - Url:


    + Title *


    + Tag *


    + Url (optional)

    + If the url leave empty we will use the post title. +

    -
    +
    - + Delete
    diff --git a/system/admin/views/edit-profile.html.php b/system/admin/views/edit-profile.html.php index 5e63c58..6169d7d 100644 --- a/system/admin/views/edit-profile.html.php +++ b/system/admin/views/edit-profile.html.php @@ -29,12 +29,15 @@ + +
    +
    - Title:


    + Title *


    -
    - +
    +
    diff --git a/system/admin/views/import.html.php b/system/admin/views/import.html.php new file mode 100644 index 0000000..edabbdb --- /dev/null +++ b/system/admin/views/import.html.php @@ -0,0 +1,10 @@ + +
    + +

    Import RSS Feed 2.0

    +

    By using this importer you are agree if the feed is yours.

    +
    + Feed Url *


    + Add source link (optional)

    + +
    \ No newline at end of file diff --git a/system/admin/views/layout.html.php b/system/admin/views/layout.html.php index 7731542..6a4a1cf 100644 --- a/system/admin/views/layout.html.php +++ b/system/admin/views/layout.html.php @@ -33,6 +33,7 @@
  • Add post
  • Add page
  • Edit profile
  • +
  • Import
  • Logout
  • diff --git a/system/admin/views/login.html.php b/system/admin/views/login.html.php index db37225..e5d3d0b 100644 --- a/system/admin/views/login.html.php +++ b/system/admin/views/login.html.php @@ -1,11 +1,13 @@ + +
    + -

    Login

    - User:
    -

    - Pass:
    -

    + User *
    +

    + Password *
    +

    \ No newline at end of file diff --git a/system/htmly.php b/system/htmly.php index 9605061..9959fb1 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -50,10 +50,50 @@ get('/index', function () { // Get submitted login data post('/login', function() { - + $user = from($_REQUEST, 'user'); $pass = from($_REQUEST, 'password'); - session($user, $pass); + if(!empty($user) && !empty($pass)) { + + session($user, $pass, null); + $log = session($user, $pass, null); + + if(!empty($log)) { + + config('views.root', 'system/admin/views'); + + render('login',array( + 'error' => '', + 'title' => 'Login - ' . config('blog.title'), + 'canonical' => config('site.url'), + 'description' => 'Login page on ' .config('blog.title'), + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Login' + )); + } + } + else { + $message['error'] = ''; + if(empty($user)) { + $message['error'] .= '
  • User field is required.
  • '; + } + if (empty($pass)) { + $message['error'] .= '
  • Password field is required.
  • '; + } + + config('views.root', 'system/admin/views'); + + render('login',array( + 'error' => '', + 'title' => 'Login - ' . config('blog.title'), + 'username' => $user, + 'password' => $pass, + 'canonical' => config('site.url'), + 'description' => 'Login page on ' .config('blog.title'), + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Login' + )); + } }); @@ -136,15 +176,49 @@ get('/:year/:month/:name/edit', function($year, $month, $name){ // Get edited data for blog post post('/:year/:month/:name/edit', function() { - + $title = from($_REQUEST, 'title'); $tag = from($_REQUEST, 'tag'); $url = from($_REQUEST, 'url'); $content = from($_REQUEST, 'content'); $oldfile = from($_REQUEST, 'oldfile'); $destination = from($_GET, 'destination'); - - edit_post($title, $tag, $url, $content, $oldfile, $destination); + if(!empty($title) && !empty($tag) && !empty($content)) { + if(!empty($url)) { + edit_post($title, $tag, $url, $content, $oldfile, $destination); + } + else { + $url = $title; + edit_post($title, $tag, $url, $content, $oldfile, $destination); + } + } + else { + $message['error'] = ''; + if(empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($tag)) { + $message['error'] .= '
  • Tag field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-post',array( + 'error' => '', + 'title' => 'Edit post - ' . config('blog.title'), + 'oldfile' => $oldfile, + 'postTitle' => $title, + 'postTag' => $tag, + 'postUrl' => $url, + 'postContent' => $content, + 'canonical' => config('site.url'), + 'description' => 'Adit post on ' .config('blog.title'), + 'bodyclass' => 'editpost', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Edit post' + )); + } }); @@ -262,7 +336,30 @@ post('/edit/profile', function() { $user = $_SESSION['user']; $title = from($_REQUEST, 'title'); $content = from($_REQUEST, 'content'); - edit_profile($title, $content, $user); + if(!empty($title) && !empty($content)) { + edit_profile($title, $content, $user); + } + else { + $message['error'] = ''; + if(empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-profile',array( + 'error' => '', + 'title' => 'Edit profile - ' . config('blog.title'), + 'postTitle' => $title, + 'postContent' => $content, + 'canonical' => config('site.url'), + 'description' => 'Edit profile on ' .config('blog.title'), + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Edit profile' + )); + } }); @@ -404,24 +501,25 @@ get('/:static', function($static){ } die; } - - $post = get_static_post($static); - - if(!$post){ - not_found(); - } - - $post = $post[0]; + else { + $post = get_static_post($static); + + if(!$post){ + not_found(); + } + + $post = $post[0]; - render('post',array( - 'title' => $post->title .' - ' . config('blog.title'), - 'canonical' => $post->url, - 'description' => $description = get_description($post->body), - 'bodyclass' => 'inpage', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » ' . $post->title, - 'p' => $post, - 'type' => 'staticpage', - )); + render('post',array( + 'title' => $post->title .' - ' . config('blog.title'), + 'canonical' => $post->url, + 'description' => $description = get_description($post->body), + 'bodyclass' => 'inpage', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » ' . $post->title, + 'p' => $post, + 'type' => 'staticpage', + )); + } }); @@ -463,8 +561,38 @@ post('/:static/edit', function() { $content = from($_REQUEST, 'content'); $oldfile = from($_REQUEST, 'oldfile'); $destination = from($_GET, 'destination'); - - edit_page($title, $url, $content, $oldfile, $destination); + if(!empty($title) && !empty($content)) { + if(!empty($url)) { + edit_page($title, $url, $content, $oldfile, $destination); + } + else { + $url = $title; + edit_page($title, $url, $content, $oldfile, $destination); + } + } + else { + $message['error'] = ''; + if(empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-page',array( + 'error' => '', + 'title' => 'Edit page - ' . config('blog.title'), + 'oldfile' => $oldfile, + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'canonical' => config('site.url'), + 'description' => 'Edit page on ' .config('blog.title'), + 'bodyclass' => 'editpage', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Edit page' + )); + } }); @@ -536,7 +664,40 @@ post('/add/post', function(){ $url = from($_REQUEST, 'url'); $content = from($_REQUEST, 'content'); $user = $_SESSION['user']; - add_post($title, $tag, $url, $content, $user); + if(!empty($title) && !empty($tag) && !empty($content)) { + if(!empty($url)) { + add_post($title, $tag, $url, $content, $user); + } + else { + $url = $title; + add_post($title, $tag, $url, $content, $user); + } + } + else { + $message['error'] = ''; + if(empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($tag)) { + $message['error'] .= '
  • Tag field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + config('views.root', 'system/admin/views'); + render('add-post',array( + 'error' => '', + 'title' => 'Add post - ' . config('blog.title'), + 'postTitle' => $title, + 'postTag' => $tag, + 'postUrl' => $url, + 'postContent' => $content, + 'canonical' => config('site.url') . '/add/post', + 'description' => 'Add post on ' .config('blog.title'), + 'bodyclass' => 'addpost', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Add post' + )); + } }); @@ -567,7 +728,100 @@ post('/add/page', function(){ $title = from($_REQUEST, 'title'); $url = from($_REQUEST, 'url'); $content = from($_REQUEST, 'content'); - add_page($title, $url, $content); + if(!empty($title) && !empty($content)) { + if(!empty($url)) { + add_page($title, $url, $content); + } + else { + $url = $title; + add_page($title, $url, $content); + } + } + else { + $message['error'] = ''; + if(empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + config('views.root', 'system/admin/views'); + render('add-page',array( + 'error' => '', + 'title' => 'Add page - ' . config('blog.title'), + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'canonical' => config('site.url') . '/add/page', + 'description' => 'Add page on ' .config('blog.title'), + 'bodyclass' => 'addpage', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Add page' + )); + } + +}); + +// Import page +get('/admin/import',function(){ + if(login()) { + config('views.root', 'system/admin/views'); + render('import', array( + 'title' => 'Import feed - ' . config('blog.title'), + 'canonical' => config('site.url') . '/import', + 'description' => 'Import feed to ' . config('blog.title') . '.', + 'bodyclass' => 'importfeed', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Import feed' + )); + } + else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; +}); + +// Get import post +post('/admin/import', function() { + + $url = from($_REQUEST, 'url'); + $credit = from($_REQUEST, 'credit'); + if(!empty($url)) { + + get_feed($url, $credit, null); + $log = get_feed($url, $credit, null); + + if(!empty($log)) { + + config('views.root', 'system/admin/views'); + + render('import',array( + 'error' => '', + 'title' => 'Import feed - ' . config('blog.title'), + 'canonical' => config('site.url'), + 'description' => 'Import feed on ' .config('blog.title'), + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Import feed' + )); + } + } + else { + $message['error'] = ''; + if(empty($url)) { + $message['error'] .= '
  • You need to specify the feed url.
  • '; + } + + config('views.root', 'system/admin/views'); + + render('import',array( + 'error' => '', + 'title' => 'Login - ' . config('blog.title'), + 'url' => $url, + 'canonical' => config('site.url'), + 'description' => 'Login page on ' .config('blog.title'), + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' .config('breadcrumb.home'). ' » Login' + )); + } }); @@ -578,7 +832,7 @@ get('/tag/:tag',function($tag){ $page = $page ? (int)$page : 1; $perpage = config('tag.perpage'); - $posts = get_tag($tag, $page, $perpage); + $posts = get_tag($tag, $page, $perpage, false); $total = get_count($tag, 'filename'); diff --git a/system/includes/functions.php b/system/includes/functions.php index 12885a7..85d7a37 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -124,14 +124,15 @@ function get_posts($posts, $page = 1, $perpage = 0){ $post->authorurl = site_url() . 'author/' . $author; $dt = str_replace($replaced,'',$arr[0]); - $time = new DateTime($dt); - $timestamp= $time->format("Y-m-d"); + $t = str_replace('-', '', $dt); + $time = new DateTime($t); + $timestamp= $time->format("Y-m-d H:i:s"); // The post date $post->date = strtotime($timestamp); // The archive per day - $post->archive = site_url(). 'archive/' . $timestamp ; + $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]); @@ -162,11 +163,13 @@ function get_posts($posts, $page = 1, $perpage = 0){ // Extract the title and body $arr = explode('t-->', $content); if(isset($arr[1])) { - $post->title = str_replace('', $content); - if(isset($arr[1])) { - $post->title = str_replace('', $content); if(isset($arr[1])) { - $post->title = str_replace('', $content); if(isset($arr[1])) { - $post->title = str_replace('', $content); + if(isset($arr[1])) { + $title = str_replace('