diff --git a/config/config.ini.example b/config/config.ini.example index f054d19..8bfe941 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -13,6 +13,9 @@ blog.copyright = "(c) Your name." ; Set permalink type. "default" using /year/month/title. "post" using /post/title permalink.type = "default" +; Make the frontpage static. Options "false" and "true" +static.frontpage = "false" + ; Show the /blog url as the blog homepage. Options "false" and "true" blog.enable = "false" diff --git a/system/admin/admin.php b/system/admin/admin.php index 02972d6..95fa6f8 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1069,7 +1069,7 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d } $post_content = '' . $post_description . "\n\n" . $content; if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { - + if (get_magic_quotes_gpc()) { $post_content = stripslashes($post_content); } @@ -1080,8 +1080,8 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d rename($oldfile, $newfile); file_put_contents($newfile, print_r($post_content, true)); } - - rename_category_folder($post_url, $oldfile); + + rename_category_folder($post_url, $oldfile); rebuilt_cache('all'); if ($destination == 'post') { @@ -1671,6 +1671,30 @@ function edit_profile($title, $content, $user) } } +// Edit homepage +function edit_frontpage($title, $content) +{ + $front_title = safe_html($title); + $front_content = '' . "\n\n" . $content; + + if (!empty($front_title) && !empty($front_content)) { + if (get_magic_quotes_gpc()) { + $front_content = stripslashes($front_content); + } + $dir = 'content/data/frontpage'; + $filename = 'content/data/frontpage/frontpage.md'; + if (is_dir($dir)) { + file_put_contents($filename, print_r($front_content, true)); + } else { + mkdir($dir, 0775, true); + file_put_contents($filename, print_r($front_content, true)); + } + rebuilt_cache('all'); + $redirect = site_url(); + header("Location: $redirect"); + } +} + // Import RSS feed function migrate($title, $time, $tags, $content, $url, $user, $source) { diff --git a/system/admin/views/edit-frontpage.html.php b/system/admin/views/edit-frontpage.html.php new file mode 100644 index 0000000..11cae7c --- /dev/null +++ b/system/admin/views/edit-frontpage.html.php @@ -0,0 +1,62 @@ + + + + + + + + + + + +
+ +
+
+ Title *


+
+ +
+
+ + +
+
+
+

URL

+ +

Upload

+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/system/admin/views/layout.html.php b/system/admin/views/layout.html.php index f467c5a..04892a4 100644 --- a/system/admin/views/layout.html.php +++ b/system/admin/views/layout.html.php @@ -37,7 +37,6 @@ diff --git a/system/htmly.php b/system/htmly.php index ff464d1..a94710d 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -16,48 +16,76 @@ get('/index', function () { if (!login()) { file_cache($_SERVER['REQUEST_URI']); } + + if (config('static.frontpage') == 'true') { + + $front = get_frontpage(); + + $tl = blog_tagline(); - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = config('posts.perpage'); + if ($tl) { + $tagline = ' - ' . $tl; + } else { + $tagline = ''; + } + + render('static', array( + 'title' => blog_title() . $tagline, + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'infront', + 'breadcrumb' => '', + 'p' => $front, + 'type' => 'staticPage', + 'is_front' => true, + )); + + + } else { - $posts = get_posts(null, $page, $perpage); + $page = from($_GET, 'page'); + $page = $page ? (int)$page : 1; + $perpage = config('posts.perpage'); - $total = ''; + $posts = get_posts(null, $page, $perpage); - $tl = blog_tagline(); + $total = ''; - if ($tl) { - $tagline = ' - ' . $tl; - } else { - $tagline = ''; - } + $tl = blog_tagline(); - if (empty($posts) || $page < 1) { + if ($tl) { + $tagline = ' - ' . $tl; + } else { + $tagline = ''; + } - // a non-existing page - render('no-posts', array( + if (empty($posts) || $page < 1) { + + // a non-existing page + render('no-posts', array( + 'title' => blog_title() . $tagline, + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'noposts', + 'is_front' => true, + )); + + die; + } + + render('main', array( 'title' => blog_title() . $tagline, 'description' => blog_description(), 'canonical' => site_url(), - 'bodyclass' => 'noposts', + 'page' => $page, + 'posts' => $posts, + 'bodyclass' => 'infront', + 'breadcrumb' => '', + 'pagination' => has_pagination($total, $perpage, $page), 'is_front' => true, )); - - die; + } - - render('main', array( - 'title' => blog_title() . $tagline, - 'description' => blog_description(), - 'canonical' => site_url(), - 'page' => $page, - 'posts' => $posts, - 'bodyclass' => 'infront', - 'breadcrumb' => '', - 'pagination' => has_pagination($total, $perpage, $page), - 'is_front' => true, - )); }); // Get submitted login data @@ -226,6 +254,73 @@ post('/edit/profile', function () { } }); +// Edit the frontpage +get('/edit/frontpage', function () { + + if (login()) { + + config('views.root', 'system/admin/views'); + render('edit-frontpage', array( + 'title' => 'Edit frontpage - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'editfrontpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit frontpage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); + +// Get submitted data from edit frontpage +post('/edit/frontpage', function () { + + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $user = $_SESSION[config("site.url")]['user']; + $title = from($_REQUEST, 'title'); + $content = from($_REQUEST, 'content'); + if ($proper && !empty($title) && !empty($content)) { + edit_frontpage($title, $content); + } else { + $message['error'] = ''; + if (empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-frontpage', array( + 'title' => 'Edit frontpage - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'error' => '', + 'postTitle' => $title, + 'postContent' => $content, + 'bodyclass' => 'editfrontpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit frontpage' + )); + } +}); + +// Edit the frontpage +get('/front/edit', function () { + + if (login()) { + $edit = site_url() . 'edit/frontpage'; + header("location: $edit"); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); + // Show the "Add post" page get('/add/post', function () { @@ -1303,9 +1398,9 @@ get('/category/:category', function ($category) { $page = from($_GET, 'page'); $page = $page ? (int)$page : 1; $perpage = config('category.perpage'); - + if (empty($perpage)) { - $perpage = 10; + $perpage = 10; } $posts = get_category($category, $page, $perpage); @@ -2068,6 +2163,11 @@ get('/:static', function ($static) { 'pagination' => has_pagination($total, $perpage, $page), 'is_blog' => true, )); + } elseif ($static === 'front') { + + $redir = site_url(); + header("location: $redir", TRUE, 301); + } else { if (config("views.counter") != "true") { diff --git a/system/includes/functions.php b/system/includes/functions.php index b3231b8..bfb12ed 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -187,7 +187,7 @@ function rebuilt_cache($type) $tmpu = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); if (is_array($tmpu)) { foreach ($tmpu as $fileu) { - if(strpos($fileu, 'draft') === false) { + if(strpos($fileu, '/draft/') === false) { $posts_cache_unsorted[] = $fileu; } } @@ -200,7 +200,7 @@ function rebuilt_cache($type) if (is_array($tmp)) { foreach ($tmp as $file) { - if(strpos($file, 'draft') === false) { + if(strpos($file, '/draft/') === false) { $posts_cache_sorted[] = pathinfo($file); } } @@ -793,6 +793,27 @@ function get_static_sub_post($static, $sub_static) return $tmp; } +// Return frontpage content +function get_frontpage() +{ + $front = new stdClass; + + $filename = 'content/data/frontpage/frontpage.md'; + + if (file_exists($filename)) { + $content = file_get_contents($filename); + $front->title = get_content_tag('t', $content, 'Welcome'); + $front->url = site_url() . 'front'; + $front->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); + } else { + $front->title = 'Welcome'; + $front->url = site_url() . 'front'; + $front->body = 'Welcome to our website.'; + } + + return $front; +} + // Return search page. function get_keyword($keyword, $page, $perpage) { @@ -1269,7 +1290,23 @@ function has_prev($prev) if (!empty($prev)) { return array( 'url' => $prev->url, - 'title' => $prev->title + 'title' => $prev->title, + 'date' => $prev->date, + 'body' => $prev->body, + 'description' => $prev->description, + 'tag' => $prev->tag, + 'category' => $prev->category, + 'author' => $prev->author, + 'authorUrl' => $prev->authorUrl, + 'related' => $prev->related, + 'views' => $prev->views, + 'type' => $prev->type, + 'file' => $prev->file, + 'image' => $prev->image, + 'video' => $prev->video, + 'audio' => $prev->audio, + 'quote' => $prev->quote, + 'link' => $prev->link ); } } @@ -1281,7 +1318,23 @@ function has_next($next) if (!empty($next)) { return array( 'url' => $next->url, - 'title' => $next->title + 'title' => $next->title, + 'date' => $next->date, + 'body' => $next->body, + 'description' => $next->description, + 'tag' => $next->tag, + 'category' => $next->category, + 'author' => $next->author, + 'authorUrl' => $next->authorUrl, + 'related' => $next->related, + 'views' => $next->views, + 'type' => $next->type, + 'file' => $next->file, + 'image' => $next->image, + 'video' => $next->video, + 'audio' => $next->audio, + 'quote' => $next->quote, + 'link' => $next->link ); } } diff --git a/themes/blog/static.html.php b/themes/blog/static.html.php index fddd5e2..fe7e2be 100644 --- a/themes/blog/static.html.php +++ b/themes/blog/static.html.php @@ -6,7 +6,7 @@
    -

    title;?>

    +

    title;?>

    body; ?>