Browse Source

Permalink without year-month

pull/189/head
Danang Probo Sayekti 10 years ago
parent
commit
26a1a97082
10 changed files with 491 additions and 21 deletions
  1. +3
    -0
      config/config.ini.example
  2. +31
    -7
      system/admin/admin.php
  3. +6
    -2
      system/admin/views/edit-audio.html.php
  4. +6
    -2
      system/admin/views/edit-image.html.php
  5. +6
    -1
      system/admin/views/edit-link.html.php
  6. +6
    -1
      system/admin/views/edit-post.html.php
  7. +6
    -1
      system/admin/views/edit-quote.html.php
  8. +6
    -1
      system/admin/views/edit-video.html.php
  9. +351
    -1
      system/htmly.php
  10. +70
    -5
      system/includes/functions.php

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

@ -10,6 +10,9 @@ blog.tagline = "Just another HTMLy blog"
blog.description = "Proudly powered by HTMLy, a databaseless blogging platform."
blog.copyright = "(c) Your name."
; Set permalink type. "default" using /year/month/title. "post" using /post/title
permalink.type = "default"
; Show the /blog url as the blog homepage
blog.enable = "false"


+ 31
- 7
system/admin/admin.php View File

@ -174,9 +174,13 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null,
// The post date
$postdate = strtotime($timestamp);
// The post URL
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
if (config('permalink.type') == 'post') {
$posturl = site_url() . 'post/' . $post_url;
} else {
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
}
save_tag_i18n($post_tag, $post_tagmd);
@ -300,7 +304,11 @@ function edit_image($title, $tag, $url, $content, $oldfile, $destination = null,
$postdate = strtotime($timestamp);
// The post URL
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
if (config('permalink.type') == 'post') {
$posturl = site_url() . 'post/' . $post_url;
} else {
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
}
save_tag_i18n($post_tag, $post_tagmd);
@ -424,7 +432,11 @@ function edit_video($title, $tag, $url, $content, $oldfile, $destination = null,
$postdate = strtotime($timestamp);
// The post URL
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
if (config('permalink.type') == 'post') {
$posturl = site_url() . 'post/' . $post_url;
} else {
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
}
save_tag_i18n($post_tag, $post_tagmd);
@ -548,7 +560,11 @@ function edit_link($title, $tag, $url, $content, $oldfile, $destination = null,
$postdate = strtotime($timestamp);
// The post URL
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
if (config('permalink.type') == 'post') {
$posturl = site_url() . 'post/' . $post_url;
} else {
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
}
save_tag_i18n($post_tag, $post_tagmd);
@ -672,7 +688,11 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null,
$postdate = strtotime($timestamp);
// The post URL
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
if (config('permalink.type') == 'post') {
$posturl = site_url() . 'post/' . $post_url;
} else {
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
}
save_tag_i18n($post_tag, $post_tagmd);
@ -796,7 +816,11 @@ function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null,
$postdate = strtotime($timestamp);
// The post URL
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
if (config('permalink.type') == 'post') {
$posturl = site_url() . 'post/' . $post_url;
} else {
$posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url;
}
save_tag_i18n($post_tag, $post_tagmd);


+ 6
- 2
system/admin/views/edit-audio.html.php View File

@ -34,9 +34,13 @@ $time = new DateTime($t);
$timestamp = $time->format("Y-m-d H:i:s");
// The post date
$postdate = strtotime($timestamp);
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
if (config('permalink.type') == 'post') {
$delete = site_url() . 'post/' . $oldmd . '/delete?destination=' . $destination;
} else {
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
}
?>
<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>


+ 6
- 2
system/admin/views/edit-image.html.php View File

@ -35,8 +35,12 @@ $timestamp = $time->format("Y-m-d H:i:s");
// The post date
$postdate = strtotime($timestamp);
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
if (config('permalink.type') == 'post') {
$delete = site_url() . 'post/' . $oldmd . '/delete?destination=' . $destination;
} else {
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
}
?>
<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>


+ 6
- 1
system/admin/views/edit-link.html.php View File

@ -35,7 +35,12 @@ $timestamp = $time->format("Y-m-d H:i:s");
// The post date
$postdate = strtotime($timestamp);
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
if (config('permalink.type') == 'post') {
$delete = site_url() . 'post/' . $oldmd . '/delete?destination=' . $destination;
} else {
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>


+ 6
- 1
system/admin/views/edit-post.html.php View File

@ -34,7 +34,12 @@ $timestamp = $time->format("Y-m-d H:i:s");
// The post date
$postdate = strtotime($timestamp);
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
if (config('permalink.type') == 'post') {
$delete = site_url() . 'post/' . $oldmd . '/delete?destination=' . $destination;
} else {
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>


+ 6
- 1
system/admin/views/edit-quote.html.php View File

@ -35,7 +35,12 @@ $timestamp = $time->format("Y-m-d H:i:s");
// The post date
$postdate = strtotime($timestamp);
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
if (config('permalink.type') == 'post') {
$delete = site_url() . 'post/' . $oldmd . '/delete?destination=' . $destination;
} else {
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>


+ 6
- 1
system/admin/views/edit-video.html.php View File

@ -36,7 +36,12 @@ $timestamp = $time->format("Y-m-d H:i:s");
// The post date
$postdate = strtotime($timestamp);
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
if (config('permalink.type') == 'post') {
$delete = site_url() . 'post/' . $oldmd . '/delete?destination=' . $destination;
} else {
// The post URL
$delete = site_url() . date('Y/m', $postdate) . '/' . $oldmd . '/delete?destination=' . $destination;
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>


+ 351
- 1
system/htmly.php View File

@ -1353,6 +1353,351 @@ get('/feed/opml', function () {
echo generate_opml();
});
// Show blog post without year-month
get('/post/:name', function ($name) {
if (config('permalink.type') != 'post') {
$post = find_post(null, null, $name);
$current = $post['current'];
$redir = site_url() . date('Y/m', $current->date) . '/' . $name;
header("location: $redir", TRUE, 301);
}
if (config("views.counter") != "true") {
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
}
$post = find_post(null, null, $name);
$current = $post['current'];
if (!$current) {
not_found();
}
if (config("views.counter") == "true") {
add_view($current->file);
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
}
$author = get_author($current->author);
if (isset($author[0])) {
$author = $author[0];
} else {
$author = default_profile($current->author);
}
if (array_key_exists('prev', $post)) {
$prev = $post['prev'];
} else {
$prev = array();
}
if (array_key_exists('next', $post)) {
$next = $post['next'];
} else {
$next = array();
}
if (isset($current->image)) {
$var = 'imagePost';
} elseif (isset($current->link)) {
$var = 'linkPost';
} elseif (isset($current->quote)) {
$var = 'quotePost';
} elseif (isset($current->audio)) {
$var = 'audioPost';
} elseif (isset($current->video)) {
$var = 'videoPost'; }
else {
$var = 'blogPost';
}
if (config('blog.enable') === 'true') {
$blog = ' <span typeof="v:Breadcrumb"><a href="' . site_url() . 'blog">Blog</a></span> &#187; ';
} else {
$blog = '';
}
render('post', array(
'title' => $current->title . ' - ' . blog_title(),
'description' => $current->description,
'canonical' => $current->url,
'p' => $current,
'author' => $author,
'bodyclass' => 'inpost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; '. $blog . $current->tagb . ' &#187; ' . $current->title,
'prev' => has_prev($prev),
'next' => has_next($next),
'type' => $var,
'is_post' => is_post(true),
));
});
// Edit blog post
get('/post/:name/edit', function ($name) {
if (login()) {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
config('views.root', 'system/admin/views');
$post = find_post(null, null, $name);
if (!$post) {
$post = find_draft(null, null, $name);
if (!$post) {
not_found();
}
}
$current = $post['current'];
if (isset($current->image)) {
$var = 'edit-image';
} elseif (isset($current->link)) {
$var = 'edit-link';
} elseif (isset($current->quote)) {
$var = 'edit-quote';
} elseif (isset($current->audio)) {
$var = 'edit-audio';
} elseif (isset($current->video)) {
$var = 'edit-video';
} else {
$var = 'edit-post';
}
if ($user === $current->author || $role === 'admin') {
render($var, array(
'title' => $var .' '. blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'p' => $current,
'bodyclass' => 'editcontent',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->tagb . ' &#187; ' . $current->title
));
} else {
render('denied', array(
'title' => $var .' '. blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'p' => $current,
'bodyclass' => 'denied',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->tagb . ' &#187; ' . $current->title
));
}
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Get edited data from blog post
post('/post/:name/edit', function () {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
$title = from($_REQUEST, 'title');
$is_post = from($_REQUEST, 'is_post');
$image = from($_REQUEST, 'image');
$is_image = from($_REQUEST, 'is_image');
$video = from($_REQUEST, 'video');
$is_video = from($_REQUEST, 'is_video');
$link = from($_REQUEST, 'link');
$is_link = from($_REQUEST, 'is_link');
$audio = from($_REQUEST, 'audio');
$is_audio = from($_REQUEST, 'is_audio');
$quote = from($_REQUEST, 'quote');
$is_quote = from($_REQUEST, 'is_quote');
$tag = from($_REQUEST, 'tag');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
$date = from($_REQUEST, 'date');
$time = from($_REQUEST, 'time');
$dateTime = null;
$revertPost = from($_REQUEST, 'revertpost');
$publishDraft = from($_REQUEST, 'publishdraft');
if ($date !== null && $time !== null) {
$dateTime = $date . ' ' . $time;
}
if (!empty($is_image)) {
$var = 'edit-image';
} elseif (!empty($is_video)) {
$var = 'edit-video';
} elseif (!empty($is_link)) {
$var = 'edit-link';
} elseif (!empty($is_quote)) {
$var = 'edit-quote';
} elseif (!empty($is_audio)) {
$var = 'edit-audio';
} elseif (!empty($is_post)) {
$var = 'edit-post';
}
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
if (empty($url)) {
$url = $title;
}
edit_image($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $image, $revertPost, $publishDraft);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (empty($url)) {
$url = $title;
}
edit_video($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $video, $revertPost, $publishDraft);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (empty($url)) {
$url = $title;
}
edit_link($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $link, $revertPost, $publishDraft);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (empty($url)) {
$url = $title;
}
edit_quote($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $quote, $revertPost, $publishDraft);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (empty($url)) {
$url = $title;
}
edit_audio($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $audio, $revertPost, $publishDraft);
} else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
if (empty($url)) {
$url = $title;
}
edit_post($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $revertPost, $publishDraft);
} else {
$message['error'] = '';
if (empty($title)) {
$message['error'] .= '<li>Title field is required.</li>';
}
if (empty($tag)) {
$message['error'] .= '<li>Tag 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>';
}
if (!empty($is_image)) {
if (empty($image)) {
$message['error'] .= '<li>Image field is required.</li>';
}
} elseif (!empty($is_video)) {
if (empty($video)) {
$message['error'] .= '<li>Video field is required.</li>';
}
} elseif (!empty($is_link)) {
if (empty($link)) {
$message['error'] .= '<li>Link field is required.</li>';
}
} elseif (!empty($is_quote)) {
if (empty($quote)) {
$message['error'] .= '<li>Quote field is required.</li>';
}
} elseif (!empty($is_audio)) {
if (empty($audio)) {
$message['error'] .= '<li>Audio field is required.</li>';
}
}
config('views.root', 'system/admin/views');
render($var, array(
'title' => 'Edit content - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '<ul>' . $message['error'] . '</ul>',
'oldfile' => $oldfile,
'postTitle' => $title,
'postImage' => $image,
'postVideo' => $video,
'postLink' => $link,
'postQuote' => $quote,
'postAudio' => $audio,
'postTag' => $tag,
'postUrl' => $url,
'postContent' => $content,
'bodyclass' => 'editcontent',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit content'
));
}
});
// Delete blog post
get('/post/:name/delete', function ($name) {
if (login()) {
$user = $_SESSION[config("site.url")]['user'];
$role = user('role', $user);
config('views.root', 'system/admin/views');
$post = find_post(null, null, $name);
if (!$post) {
$post = find_draft(null, null, $name);
if (!$post) {
not_found();
}
}
$current = $post['current'];
if ($user === $current->author || $role === 'admin') {
render('delete-post', array(
'title' => 'Delete post - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'p' => $current,
'bodyclass' => 'deletepost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->tagb . ' &#187; ' . $current->title
));
} else {
render('denied', array(
'title' => 'Delete post - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'p' => $current,
'bodyclass' => 'deletepost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; ' . $current->tagb . ' &#187; ' . $current->title
));
}
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Get deleted data from blog post
post('/post/:name/delete', function () {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if ($proper && login()) {
$file = from($_REQUEST, 'file');
$destination = from($_GET, 'destination');
delete_post($file, $destination);
}
});
// Show various page (top-level), admin, login, sitemap, static page.
get('/:static', function ($static) {
@ -1864,8 +2209,13 @@ post('/:static/:sub/delete', function () {
}
});
// Show blog post page
// Show blog post with year-month
get('/:year/:month/:name', function ($year, $month, $name) {
if (config('permalink.type') == 'post') {
$redir = site_url() . 'post/' . $name;
header("location: $redir", TRUE, 301);
}
if (config("views.counter") != "true") {
if (!login()) {


+ 70
- 5
system/includes/functions.php View File

@ -232,10 +232,13 @@ function get_posts($posts, $page = 1, $perpage = 0)
// The archive per day
$post->archive = site_url() . 'archive/' . date('Y-m', $post->date);
// The post URL
$post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]);
if (config('permalink.type') == 'post') {
$post->url = site_url() . 'post/' . str_replace('.md', '', $arr[2]);
} else {
$post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]);
}
$post->file = $filepath;
$content = file_get_contents($filepath);
@ -335,6 +338,35 @@ function find_post($year, $month, $name)
'prev' => $pr[0]
);
}
} else if (strpos($url, $name . '.md') !== false) {
$ar = get_posts($posts, $index + 1, 1);
$nx = get_posts($posts, $index, 1);
$pr = get_posts($posts, $index + 2, 1);
if ($index == 0) {
if (isset($pr[0])) {
return array(
'current' => $ar[0],
'prev' => $pr[0]
);
} else {
return array(
'current' => $ar[0],
'prev' => null
);
}
} elseif (count($posts) == $index + 1) {
return array(
'current' => $ar[0],
'next' => $nx[0]
);
} else {
return array(
'current' => $ar[0],
'next' => $nx[0],
'prev' => $pr[0]
);
}
}
}
}
@ -379,6 +411,35 @@ function find_draft($year, $month, $name)
'prev' => $pr[0]
);
}
} else if (strpos($url, $name . '.md') !== false) {
$ar = get_posts($posts, $index + 1, 1);
$nx = get_posts($posts, $index, 1);
$pr = get_posts($posts, $index + 2, 1);
if ($index == 0) {
if (isset($pr[0])) {
return array(
'current' => $ar[0],
'prev' => $pr[0]
);
} else {
return array(
'current' => $ar[0],
'prev' => null
);
}
} elseif (count($posts) == $index + 1) {
return array(
'current' => $ar[0],
'next' => $nx[0]
);
} else {
return array(
'current' => $ar[0],
'next' => $nx[0],
'prev' => $pr[0]
);
}
}
}
}
@ -1558,7 +1619,11 @@ function sitemap_post_path()
$post->archiveyear = site_url() . 'archive/' . date('Y', $post->date);
// The post URL
$post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]);
if (config('permalink.type') == 'post') {
$post->url = site_url() . 'post/' . str_replace('.md', '', $arr[2]);
} else {
$post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]);
}
$tmp[] = $post;
}


Loading…
Cancel
Save