Browse Source

Static frontpage and improvements

Add new config: static.frontpage = "true" to enable the static
frontpage.
pull/255/head
Danang Probo Sayekti 10 years ago
parent
commit
eb8e0ac503
7 changed files with 281 additions and 40 deletions
  1. +3
    -0
      config/config.ini.example
  2. +27
    -3
      system/admin/admin.php
  3. +62
    -0
      system/admin/views/edit-frontpage.html.php
  4. +0
    -1
      system/admin/views/layout.html.php
  5. +131
    -31
      system/htmly.php
  6. +57
    -4
      system/includes/functions.php
  7. +1
    -1
      themes/blog/static.html.php

+ 3
- 0
config/config.ini.example View File

@ -13,6 +13,9 @@ blog.copyright = "(c) Your name."
; Set permalink type. "default" using /year/month/title. "post" using /post/title ; Set permalink type. "default" using /year/month/title. "post" using /post/title
permalink.type = "default" 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" ; Show the /blog url as the blog homepage. Options "false" and "true"
blog.enable = "false" blog.enable = "false"


+ 27
- 3
system/admin/admin.php View File

@ -1069,7 +1069,7 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d
} }
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content; $post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$post_content = stripslashes($post_content); $post_content = stripslashes($post_content);
} }
@ -1080,8 +1080,8 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d
rename($oldfile, $newfile); rename($oldfile, $newfile);
file_put_contents($newfile, print_r($post_content, true)); file_put_contents($newfile, print_r($post_content, true));
} }
rename_category_folder($post_url, $oldfile);
rename_category_folder($post_url, $oldfile);
rebuilt_cache('all'); rebuilt_cache('all');
if ($destination == 'post') { 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 = '<!--t ' . $front_title . ' t-->' . "\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 // Import RSS feed
function migrate($title, $time, $tags, $content, $url, $user, $source) function migrate($title, $time, $tags, $content, $url, $user, $source)
{ {


+ 62
- 0
system/admin/views/edit-frontpage.html.php View File

@ -0,0 +1,62 @@
<?php
$filename = 'content/data/frontpage/frontpage.md';
if (file_exists($filename)) {
$content = file_get_contents($filename);
$oldtitle = get_content_tag('t', $content, 'Welcome');
$oldcontent = remove_html_comments($content);
} else {
$oldtitle = 'Welcome';
$oldcontent = 'Welcome to our website.';
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
<script src="<?php echo site_url() ?>system/resources/js/jquery.min.js"></script>
<script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/jquery.ajaxfileupload.js"></script>
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
<?php } ?>
<div class="wmd-panel">
<form method="POST">
Title <span class="required">*</span> <br><input type="text" name="title"
class="text <?php if (isset($postTitle)) {
if (empty($postTitle)) {
echo 'error';
}
} ?>" value="<?php echo $oldtitle ?>"/><br><br>
<br>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="wmd-input <?php if (isset($postContent)) {
if (empty($postContent)) {
echo 'error';
}
} ?>" name="content" cols="20" rows="10"><?php echo $oldcontent ?></textarea><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" name="submit" class="submit" value="Save"/>
</form>
</div>
<div id="insertImageDialog" title="Insert Image">
<h4>URL</h4>
<input type="text" placeholder="Enter image URL" />
<h4>Upload</h4>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
</form>
<style>
#insertImageDialog { display:none; padding: 10px; font-size:12px;}
.wmd-prompt-background {z-index:10!important;}
</style>
</div>
<div id="wmd-preview" class="wmd-panel wmd-preview"></div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>';</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>

+ 0
- 1
system/admin/views/layout.html.php View File

@ -37,7 +37,6 @@
<header id="header"> <header id="header">
<section id="branding"> <section id="branding">
<h1 class="blog-title"><a href="<?php echo site_url() ?>"><?php echo blog_title() ?></a></h1> <h1 class="blog-title"><a href="<?php echo site_url() ?>"><?php echo blog_title() ?></a></h1>
<div class="blog-tagline"><p><?php echo blog_tagline() ?></p></div> <div class="blog-tagline"><p><?php echo blog_tagline() ?></p></div>
</section> </section>
</header> </header>


+ 131
- 31
system/htmly.php View File

@ -16,48 +16,76 @@ get('/index', function () {
if (!login()) { if (!login()) {
file_cache($_SERVER['REQUEST_URI']); 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, 'title' => blog_title() . $tagline,
'description' => blog_description(), 'description' => blog_description(),
'canonical' => site_url(), 'canonical' => site_url(),
'bodyclass' => 'noposts',
'page' => $page,
'posts' => $posts,
'bodyclass' => 'infront',
'breadcrumb' => '',
'pagination' => has_pagination($total, $perpage, $page),
'is_front' => true, '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 // 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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; 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'] .= '<li>Title field is required.</li>';
}
if (empty($content)) {
$message['error'] .= '<li>Content field is required.</li>';
}
if (!$proper) {
$message['error'] .= '<li>CSRF Token not correct.</li>';
}
config('views.root', 'system/admin/views');
render('edit-frontpage', array(
'title' => 'Edit frontpage - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '<ul>' . $message['error'] . '</ul>',
'postTitle' => $title,
'postContent' => $content,
'bodyclass' => 'editfrontpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; 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 // Show the "Add post" page
get('/add/post', function () { get('/add/post', function () {
@ -1303,9 +1398,9 @@ get('/category/:category', function ($category) {
$page = from($_GET, 'page'); $page = from($_GET, 'page');
$page = $page ? (int)$page : 1; $page = $page ? (int)$page : 1;
$perpage = config('category.perpage'); $perpage = config('category.perpage');
if (empty($perpage)) { if (empty($perpage)) {
$perpage = 10;
$perpage = 10;
} }
$posts = get_category($category, $page, $perpage); $posts = get_category($category, $page, $perpage);
@ -2068,6 +2163,11 @@ get('/:static', function ($static) {
'pagination' => has_pagination($total, $perpage, $page), 'pagination' => has_pagination($total, $perpage, $page),
'is_blog' => true, 'is_blog' => true,
)); ));
} elseif ($static === 'front') {
$redir = site_url();
header("location: $redir", TRUE, 301);
} else { } else {
if (config("views.counter") != "true") { if (config("views.counter") != "true") {


+ 57
- 4
system/includes/functions.php View File

@ -187,7 +187,7 @@ function rebuilt_cache($type)
$tmpu = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); $tmpu = glob('content/*/blog/*/*/*.md', GLOB_NOSORT);
if (is_array($tmpu)) { if (is_array($tmpu)) {
foreach ($tmpu as $fileu) { foreach ($tmpu as $fileu) {
if(strpos($fileu, 'draft') === false) {
if(strpos($fileu, '/draft/') === false) {
$posts_cache_unsorted[] = $fileu; $posts_cache_unsorted[] = $fileu;
} }
} }
@ -200,7 +200,7 @@ function rebuilt_cache($type)
if (is_array($tmp)) { if (is_array($tmp)) {
foreach ($tmp as $file) { foreach ($tmp as $file) {
if(strpos($file, 'draft') === false) {
if(strpos($file, '/draft/') === false) {
$posts_cache_sorted[] = pathinfo($file); $posts_cache_sorted[] = pathinfo($file);
} }
} }
@ -793,6 +793,27 @@ function get_static_sub_post($static, $sub_static)
return $tmp; 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. // Return search page.
function get_keyword($keyword, $page, $perpage) function get_keyword($keyword, $page, $perpage)
{ {
@ -1269,7 +1290,23 @@ function has_prev($prev)
if (!empty($prev)) { if (!empty($prev)) {
return array( return array(
'url' => $prev->url, '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)) { if (!empty($next)) {
return array( return array(
'url' => $next->url, '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
); );
} }
} }


+ 1
- 1
themes/blog/static.html.php View File

@ -6,7 +6,7 @@
<div class="content"> <div class="content">
<?php if (login()) { echo tab($p); } ?> <?php if (login()) { echo tab($p); } ?>
<div class="item"> <div class="item">
<h2 class="title" itemprop="headline"><a href="<?php echo $p->url;?>"><?php echo $p->title;?></a></h2>
<h1 class="title" itemprop="headline"><?php echo $p->title;?></h1>
<div class="desc text-left" itemprop="articleBody"> <div class="desc text-left" itemprop="articleBody">
<?php echo $p->body; ?> <?php echo $p->body; ?>
</div><!--//desc--> </div><!--//desc-->


Loading…
Cancel
Save