Browse Source

Merge pull request #74 from Kanti/master

Added Sub Pages by @Kanti.
pull/89/head
Danang Probo Sayekti 11 years ago
parent
commit
6017717a19
9 changed files with 897 additions and 533 deletions
  1. +11
    -3
      README.md
  2. +493
    -480
      system/admin/admin.php
  3. +25
    -28
      system/admin/views/delete-page.html.php
  4. +1
    -1
      system/admin/views/edit-page.html.php
  5. +229
    -4
      system/htmly.php
  6. +135
    -14
      system/includes/functions.php
  7. +1
    -1
      themes/clean/css/style.css
  8. +1
    -1
      themes/default/css/style.css
  9. +1
    -1
      themes/logs/css/style.css

+ 11
- 3
README.md View File

@ -140,17 +140,25 @@ Here's the explanation (separated by an underscore):
- `2014-01-31-12-56-40` is the published date. The date format is `yyyy-mm-dd-hh-mm-ss`
- `tag1,tag2,tag3` is the tag, separated by comma
- `databaseless-blogging-platform-flat-file-blog` is the URL
For static pages, we use the following format:
````
about.md
content/static/about.md
````
That is means if `about` is the URL.
That means the URL is `about`.
So if you write it offline then you must naming the .md file as above.
For static sub pages, we use the following format:
````
content/static/about/me.md
````
That means the URL is `about/me`.
Content Title
-------------
If you write it offline, for the title of the post you need to add a title in the following format:


+ 493
- 480
system/admin/admin.php
File diff suppressed because it is too large
View File


+ 25
- 28
system/admin/views/delete-page.html.php View File

@ -1,33 +1,30 @@
<?php
if(isset($_GET['destination'])) {
$destination = $_GET['destination'];
}
$url = $p->file;
$dir = substr($url, 0, strrpos($url, '/'));
$oldurl = str_replace($dir . '/','',$url);
$oldmd = str_replace('.md','',$oldurl);
$post = site_url() . $oldmd;
if(isset($destination)) {
if($destination == 'post') {
$back = $post;
}
else {
$back = site_url() . $destination;
}
}
else {
$back = site_url();
}
if (isset($_GET['destination'])) {
$destination = $_GET['destination'];
}
$url = $p->file;
$dir = substr($url, 0, strrpos($url, '/'));
$oldurl = str_replace($dir . '/', '', $url);
$oldmd = str_replace('.md', '', $oldurl);
$post = $p->url;
if (isset($destination)) {
if ($destination == 'post') {
$back = $post;
} else {
$back = site_url() . $destination;
}
} else {
$back = site_url();
}
?>
<?php echo '<p>Are you sure want to delete <strong>' . $p->title . '</strong>?</p>';?>
<p>Are you sure want to delete <strong><?php echo $p->title; ?></strong>?</p>
<form method="POST">
<input type="hidden" name="file" value="<?php echo $p->file ?>"/><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf()?>">
<input type="submit" name="submit" value="Delete"/>
<span><a href="<?php echo $back ?>">Cancel</a></span>
<input type="hidden" name="file" value="<?php echo $p->file ?>"/><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" name="submit" value="Delete"/>
<span><a href="<?php echo $back ?>">Cancel</a></span>
</form>

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

@ -27,7 +27,7 @@
$oldurl = str_replace($dir . '/','',$url);
$oldmd = str_replace('.md','',$oldurl);
$delete = site_url() . $oldmd . '/delete?destination=' . $destination;
$delete = $p->url . '/delete?destination=' . $destination;
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css" />


+ 229
- 4
system/htmly.php View File

@ -108,6 +108,133 @@ post('/login', function() {
}
});
get("/:static/:sub/edit", function($static,$sub) {
if (login()) {
config('views.root', 'system/admin/views');
$post = get_static_post($static);
if (!$post) {
not_found();
}
$post = $post[0];
$page = get_static_sub_post($static,$sub);
if (!$page) {
not_found();
}
$page = $page[0];
render('edit-page', array(
'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'editpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $post->url . '">' . $post->title . '</a> &#187; ',
'p' => $page,
'type' => 'staticpage',
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
post("/:static/:sub/edit", function($static,$sub) {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if(!login())
{
$login = site_url() . 'login';
header("location: $login");
}
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination');
if($destination === null)
{
$destination = $static . "/" . $sub;
}
if ($proper && !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'] .= '<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-page', array(
'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()),
'error' => '<ul>' . $message['error'] . '</ul>',
'oldfile' => $oldfile,
'postTitle' => $title,
'postUrl' => $url,
'postContent' => $content,
'bodyclass' => 'editpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Edit page'
));
}
});
get("/:static/:sub/delete", function($static,$sub) {
if (login()) {
config('views.root', 'system/admin/views');
$post = get_static_post($static);
if (!$post) {
not_found();
}
$post = $post[0];
$page = get_static_sub_post($static,$sub);
if (!$page) {
not_found();
}
$page = $page[0];
render('delete-page', array(
'head_contents' => head_contents('Delete page - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'deletepage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $post->url . '">' . $post->title . '</a>' . $page->title,
'p' => $page,
'type' => 'staticpage',
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
post("/:static/:sub/delete", function() {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if ($proper && login()) {
$file = from($_REQUEST, 'file');
$destination = from($_GET, 'destination');
delete_page($file, $destination);
}
});
// The blog post page
get('/:year/:month/:name', function($year, $month, $name) {
@ -135,7 +262,6 @@ get('/:year/:month/:name', function($year, $month, $name) {
}
}
$bio = get_bio($current->author);
if (isset($bio[0])) {
@ -296,7 +422,7 @@ get('/:year/:month/:name/delete', function($year, $month, $name) {
post('/:year/:month/:name/delete', function() {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if ($proper) {
if ($proper && login()) {
$file = from($_REQUEST, 'file');
$destination = from($_GET, 'destination');
delete_post($file, $destination);
@ -643,6 +769,12 @@ get('/:static/edit', function($static) {
post('/:static/edit', function() {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if(!login())
{
$login = site_url() . 'login';
header("location: $login");
}
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
@ -712,7 +844,7 @@ get('/:static/delete', function($static) {
post('/:static/delete', function() {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if ($proper) {
if ($proper && login()) {
$file = from($_REQUEST, 'file');
$destination = from($_GET, 'destination');
delete_page($file, $destination);
@ -808,7 +940,7 @@ post('/add/page', function() {
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
if ($proper && !empty($title) && !empty($content)) {
if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
add_page($title, $url, $content);
} else {
@ -1099,6 +1231,99 @@ get('/admin/update/now/:csrf', function($CSRF) {
}
});
get('/:static/add', function($static) {
if (login()) {
config('views.root', 'system/admin/views');
$post = get_static_post($static);
if(! $post)
{
not_found();
}
$post = $post[0];
render('add-page', array(
'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'addpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $post->url . '">' . $post->title . '</a> Add page'
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
post('/:static/add', function($static) {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
add_sub_page($title, $url, $content, $static);
} else {
$url = $title;
add_sub_page($title, $url, $content, $static);
}
} 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('add-page', array(
'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()),
'error' => '<ul>' . $message['error'] . '</ul>',
'postTitle' => $title,
'postUrl' => $url,
'postContent' => $content,
'bodyclass' => 'addpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $post->url . '">' . $post->title . '</a> Add page'
));
}
});
get('/:static/:sub', function($static,$sub) {
$father_post = get_static_post($static);
if (!$father_post) {
not_found();
}
$post = get_static_sub_post($static,$sub);
if (!$post) {
not_found();
}
$post = $post[0];
if(config("views.counter") == "true")
{
add_view($post->file);
}
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
render('static', array(
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $description = get_description($post->body), $post->url),
'bodyclass' => 'inpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; <a href="' . $father_post[0]->url . '">' . $father_post[0]->title . '</a> &#187; ' . $post->title,
'p' => $post,
'type' => 'staticpage',
));
});
// If we get here, it means that
// nothing has been matched above


+ 135
- 14
system/includes/functions.php View File

@ -54,6 +54,33 @@ function get_static_pages() {
return $_page;
}
// Get static page path. Unsorted.
function get_static_sub_pages($static = null) {
static $_sub_page = array();
if (empty($_sub_page)) {
$url = 'cache/index/index-sub-page.txt';
if(! file_exists($url)) {
rebuilt_cache('all');
}
$_sub_page = unserialize(file_get_contents($url));
}
if($static != null)
{
$stringLen = strlen($static);
return array_filter($_sub_page, function($sub_page)use($static,$stringLen){
$x = explode("/",$sub_page);
if($x[count($x)-2] == $static)
{
return true;
}
return false;
});
}
return $_sub_page;
}
// Get author bio path. Unsorted.
function get_author_names() {
@ -130,6 +157,11 @@ function rebuilt_cache($type) {
$page_cache = glob('content/static/*.md', GLOB_NOSORT);
$string = serialize($page_cache);
file_put_contents('cache/index/index-page.txt', print_r($string, true));
} elseif ($type === 'subpage') {
$page_cache = glob('content/static/*/*.md', GLOB_NOSORT);
$string = serialize($page_cache);
file_put_contents('cache/index/index-sub-page.txt', print_r($string, true));
} elseif ($type === 'author') {
$author_cache = glob('content/*/author.md', GLOB_NOSORT);
@ -138,6 +170,7 @@ function rebuilt_cache($type) {
} elseif ($type === 'all') {
rebuilt_cache('posts');
rebuilt_cache('page');
rebuilt_cache('subpage');
rebuilt_cache('author');
}
}
@ -472,6 +505,53 @@ function get_static_post($static) {
return $tmp;
}
// Return static page.
function get_static_sub_post($static,$sub_static) {
$posts = get_static_sub_pages($static);
$tmp = array();
if (!empty($posts)) {
foreach ($posts as $index => $v) {
if (strpos($v, $sub_static . '.md') !== false) {
$post = new stdClass;
// Replaced string
$replaced = substr($v, 0, strrpos($v, '/')) . '/';
// The static page URL
$url = str_replace($replaced, '', $v);
$post->url = site_url() . $static . "/" . str_replace('.md', '', $url);
$post->file = $v;
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
$post->title = $title;
$post->body = $arr[1];
} else {
$post->title = $sub_static;
$post->body = $arr[0];
}
$post->views = get_views($post->file);
$tmp[] = $post;
}
}
}
return $tmp;
}
// Return search page.
function get_keyword($keyword, $page, $perpage) {
@ -1002,8 +1082,24 @@ function menu() {
}
}
function get_title_from_file($v)
{
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
} else {
$title = str_replace('-', ' ', str_replace('.md', '', $base));
}
return $title;
}
// Auto generate menu from static page
function get_menu() {
function get_menu() {//aktive Link for Sub Pages ::TODO
$posts = get_static_pages();
$req = $_SERVER['REQUEST_URI'];
@ -1036,23 +1132,48 @@ function get_menu() {
$base = str_replace($replaced, '', $v);
$url = site_url() . str_replace('.md', '', $base);
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
$title = get_title_from_file($v);
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
if ($req == site_path() . "/" . str_replace('.md', '', $base)) {
$active = ' active';
$reqBase = '';
} else {
$title = str_replace('-', ' ', str_replace('.md', '', $base));
$active = '';
}
if (strpos($req, str_replace('.md', '', $base)) !== false) {
echo '<li class="' . $class . ' active"><a href="' . $url . '">' . ucwords($title) . '</a></li>';
} else {
echo '<li class="' . $class . '"><a href="' . $url . '">' . ucwords($title) . '</a></li>';
echo '<li class="' . $class . $active . '">';
$subPages = get_static_sub_pages(str_replace('.md', '', $base));
echo '<a href="' . $url . '">' . ucwords($title) . '</a><br/>';
if(!empty($subPages))
{
echo '<ul>';
$iSub = 0;
$countSub = count($subPages);
foreach($subPages as $index => $sp)
{
$classSub = "item";
if($iSub == 0)
{
$classSub .= " first";
}
if($iSub == $countSub -1)
{
$classSub .= " last";
}
$replacedSub = substr($sp, 0, strrpos($sp, '/')) . '/';
$baseSub = str_replace($replacedSub, '', $sp);
if ($req == site_path() . "/" . str_replace('.md', '', $base) . "/" . str_replace('.md', '', $baseSub)) {
$classSub .= ' active';
}
$urlSub = $url . "/" . str_replace('.md', '', $baseSub);
echo '<li class="' . $classSub . '"><a href="' . $urlSub . '">&raquo; ' . get_title_from_file($sp) . '</a></li>';
$iSub++;
}
echo '</ul>';
}
echo '</li>';
}
echo '</ul>';
} else {


+ 1
- 1
themes/clean/css/style.css View File

@ -437,7 +437,7 @@ aside .archive ul li ul, aside .tagcloud ul li {
margin-left:30px;
}
aside .menu ul li a:hover, aside .menu ul li.active a{
aside .menu ul li > a:hover, aside .menu ul li.active > a{
background-color:#389dc1;
color:#fff;
}


+ 1
- 1
themes/default/css/style.css View File

@ -379,7 +379,7 @@ table.post-list td a {
padding-top:3px;
}
#menu ul li.active a {
#menu ul li.active > a {
text-decoration:underline;
}


+ 1
- 1
themes/logs/css/style.css View File

@ -306,7 +306,7 @@ ul li, ol li{
text-decoration: underline;
}
#menu ul li.active a {
#menu ul li.active > a {
text-decoration: underline;
}


Loading…
Cancel
Save