Browse Source

Merge pull request #77 from Kanti/master

Added feature custom meta description by @Kanti.
pull/89/head
Danang Probo Sayekti 11 years ago
parent
commit
6f1d7f0c57
8 changed files with 158 additions and 142 deletions
  1. +35
    -12
      system/admin/admin.php
  2. +3
    -2
      system/admin/views/add-page.html.php
  3. +2
    -1
      system/admin/views/add-post.html.php
  4. +2
    -0
      system/admin/views/edit-page.html.php
  5. +2
    -1
      system/admin/views/edit-post.html.php
  6. +2
    -0
      system/admin/views/edit-profile.html.php
  7. +54
    -56
      system/htmly.php
  8. +58
    -70
      system/includes/functions.php

+ 35
- 12
system/admin/admin.php View File

@ -39,14 +39,18 @@ function remove_accent($str) {
}
// Edit blog posts
function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) {
function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, $description = null) {
$oldurl = explode('_', $oldfile);
$post_title = $title;
$post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag));
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
if ($description !== null) {
$post_description = "\n<!--d " . $description . " d-->";
} else {
$post_description = "";
}
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) {
if (get_magic_quotes_gpc()) {
@ -85,13 +89,17 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
}
// Edit static page
function edit_page($title, $url, $content, $oldfile, $destination = null) {
function edit_page($title, $url, $content, $oldfile, $destination = null, $description = null) {
$dir = substr($oldfile, 0, strrpos($oldfile, '/'));
$post_title = $title;
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
if ($description !== null) {
$post_description = "\n<!--d " . $description . " d-->";
} else {
$post_description = '';
}
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
if (get_magic_quotes_gpc()) {
@ -119,13 +127,18 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) {
}
// Add blog post
function add_post($title, $tag, $url, $content, $user) {
function add_post($title, $tag, $url, $content, $user, $desciption = null) {
$post_date = date('Y-m-d-H-i-s');
$post_title = $title;
$post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag));
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
if ($description !== null) {
$post_description = "\n<!--d " . $description . " d-->";
} else {
$post_description = "";
}
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) {
if (get_magic_quotes_gpc()) {
@ -148,11 +161,16 @@ function add_post($title, $tag, $url, $content, $user) {
}
// Add static page
function add_page($title, $url, $content) {
function add_page($title, $url, $content, $description = null) {
$post_title = $title;
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
if ($description !== null) {
$post_description = "\n<!--d " . $description . " d-->";
} else {
$post_description = "";
}
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
if (get_magic_quotes_gpc()) {
@ -175,11 +193,16 @@ function add_page($title, $url, $content) {
}
// Add static sub page
function add_sub_page($title, $url, $content, $static) {
function add_sub_page($title, $url, $content, $static, $description = null) {
$post_title = $title;
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
if ($description !== null) {
$post_description = "\n<!--d " . $description . " d-->";
} else {
$post_description = "";
}
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
if (get_magic_quotes_gpc()) {


+ 3
- 2
system/admin/views/add-page.html.php View File

@ -9,8 +9,9 @@
<form method="POST">
Title <span class="required">*</span><br><input type="text" class="text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'error';}} ?>" name="title" value="<?php if (isset($postTitle)) { echo $postTitle;} ?>"/><br><br>
Url (optional)<br><input type="text" class="text" name="url" value="<?php if (isset($postUrl)) { echo $postUrl;} ?>"/><br>
<span class="help">If the url leave empty we will use the page title.</span>
<br><br>
<span class="help">If the url leave empty we will use the page title.</span><br><br>
Meta Description (optional)<br><input type="text" class="text" name="description" value="<?php if (isset($postDescription)) { echo $postDescription;} ?>"/><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 if (isset($postContent)) { echo $postContent;} ?></textarea><br/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf()?>">


+ 2
- 1
system/admin/views/add-post.html.php View File

@ -10,7 +10,8 @@
Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'error';}} ?>" name="title" value="<?php if (isset($postTitle)) { echo $postTitle;} ?>"/><br><br>
Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) { if (empty($postTag)) { echo 'error';}} ?>" name="tag" value="<?php if (isset($postTag)) { echo $postTag;} ?>"/><br><br>
Url (optional)<br><input type="text" class="text" name="url" value="<?php if (isset($postUrl)) { echo $postUrl;} ?>"/><br>
<span class="help">If the url leave empty we will use the post title.</span>
<span class="help">If the url leave empty we will use the post title.</span><br><br>
Meta Description (optional)<br><input type="text" class="text" name="description" value="<?php if (isset($postDescription)) { echo $postDescription;} ?>"/><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 if (isset($postContent)) { echo $postContent;} ?></textarea><br/>


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

@ -35,6 +35,8 @@
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>
Url (optional)<br><input type="text" name="url" class="text" value="<?php echo $oldmd ?>"/><br>
<span class="help">If the url leave empty we will use the page title.</span><br><br>
Meta Description (optional)<br><input type="text" class="text" name="description" value="<?php if (isset($p->description)) { echo $p->description;} ?>"/><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="oldfile" class="text" value="<?php echo $url ?>"/>


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

@ -48,7 +48,8 @@
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>
Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) { if (empty($postTag)) { echo 'error';}} ?>" value="<?php echo $oldtag?>"/><br><br>
Url (optional)<br><input type="text" name="url" class="text" value="<?php echo $oldmd ?>"/><br>
<span class="help">If the url leave empty we will use the post title.</span>
<span class="help">If the url leave empty we will use the post title.</span><br><br>
Meta Description (optional)<br><input type="text" class="text" name="description" value="<?php if (isset($p->description)) { echo $p->description;} ?>"/><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>


+ 2
- 0
system/admin/views/edit-profile.html.php View File

@ -28,6 +28,8 @@
<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>
Meta Description (optional)<br><input type="text" class="text" name="description" value="<?php if (isset($postDescription)) { echo $postDescription;} ?>"/><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()?>">


+ 54
- 56
system/htmly.php View File

@ -108,7 +108,7 @@ post('/login', function() {
}
});
get("/:static/:sub/edit", function($static,$sub) {
get("/:static/:sub/edit", function($static, $sub) {
if (login()) {
@ -120,8 +120,8 @@ get("/:static/:sub/edit", function($static,$sub) {
}
$post = $post[0];
$page = get_static_sub_post($static,$sub);
$page = get_static_sub_post($static, $sub);
if (!$page) {
not_found();
@ -141,30 +141,29 @@ get("/:static/:sub/edit", function($static,$sub) {
header("location: $login");
}
});
post("/:static/:sub/edit", function($static,$sub) {
post("/:static/:sub/edit", function($static, $sub) {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if(!login())
{
if (!login()) {
$login = site_url() . 'login';
header("location: $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)
{
$description = from($_REQUEST, 'description');
if ($destination === null) {
$destination = $static . "/" . $sub;
}
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
edit_page($title, $url, $content, $oldfile, $destination);
edit_page($title, $url, $content, $oldfile, $destination, $description);
} else {
$url = $title;
edit_page($title, $url, $content, $oldfile, $destination);
edit_page($title, $url, $content, $oldfile, $destination, $description);
}
} else {
$message['error'] = '';
@ -192,7 +191,7 @@ post("/:static/:sub/edit", function($static,$sub) {
}
});
get("/:static/:sub/delete", function($static,$sub) {
get("/:static/:sub/delete", function($static, $sub) {
if (login()) {
@ -205,7 +204,7 @@ get("/:static/:sub/delete", function($static,$sub) {
$post = $post[0];
$page = get_static_sub_post($static,$sub);
$page = get_static_sub_post($static, $sub);
if (!$page) {
not_found();
@ -238,8 +237,7 @@ post("/:static/:sub/delete", function() {
// The blog post page
get('/:year/:month/:name', function($year, $month, $name) {
if(config("views.counter") != "true")
{
if (config("views.counter") != "true") {
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
@ -252,9 +250,8 @@ get('/:year/:month/:name', function($year, $month, $name) {
if (!$current) {
not_found();
}
if(config("views.counter") == "true")
{
if (config("views.counter") == "true") {
add_view($current->file);
if (!login()) {
@ -283,7 +280,7 @@ get('/:year/:month/:name', function($year, $month, $name) {
}
render('post', array(
'head_contents' => head_contents($current->title . ' - ' . blog_title(), $description = get_description($current->body), $current->url),
'head_contents' => head_contents($current->title . ' - ' . blog_title(), $current->description, $current->url),
'p' => $current,
'authorinfo' => authorinfo($bio->title, $bio->body),
'bodyclass' => 'inpost',
@ -343,12 +340,13 @@ post('/:year/:month/:name/edit', function() {
$content = from($_REQUEST, 'content');
$oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
if (!empty($url)) {
edit_post($title, $tag, $url, $content, $oldfile, $destination);
edit_post($title, $tag, $url, $content, $oldfile, $destination, $description);
} else {
$url = $title;
edit_post($title, $tag, $url, $content, $oldfile, $destination);
edit_post($title, $tag, $url, $content, $oldfile, $destination, $description);
}
} else {
$message['error'] = '';
@ -503,8 +501,9 @@ post('/edit/profile', function() {
$user = $_SESSION[config("site.url")]['user'];
$title = from($_REQUEST, 'title');
$content = from($_REQUEST, 'content');
$description = from($_REQUEST, 'description');
if ($proper && !empty($title) && !empty($content)) {
edit_profile($title, $content, $user);
edit_profile($title, $content, $user, $description);
} else {
$message['error'] = '';
if (empty($title)) {
@ -704,14 +703,13 @@ get('/:static', function($static) {
}
die;
} else {
if( config("views.counter") != "true")
{
if (config("views.counter") != "true") {
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
}
$post = get_static_post($static);
if (!$post) {
@ -720,8 +718,7 @@ get('/:static', function($static) {
$post = $post[0];
if(config("views.counter") == "true")
{
if (config("views.counter") == "true") {
add_view($post->file);
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
@ -729,7 +726,7 @@ get('/:static', function($static) {
}
render('static', array(
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $description = get_description($post->body), $post->url),
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $post->description, $post->url),
'bodyclass' => 'inpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $post->title,
'p' => $post,
@ -769,23 +766,23 @@ get('/:static/edit', function($static) {
post('/:static/edit', function() {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if(!login())
{
if (!login()) {
$login = site_url() . 'login';
header("location: $login");
header("location: $login");
}
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
edit_page($title, $url, $content, $oldfile, $destination);
edit_page($title, $url, $content, $oldfile, $destination, $description);
} else {
$url = $title;
edit_page($title, $url, $content, $oldfile, $destination);
edit_page($title, $url, $content, $oldfile, $destination, $description);
}
} else {
$message['error'] = '';
@ -878,13 +875,14 @@ post('/add/post', function() {
$tag = from($_REQUEST, 'tag');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$description = from($_REQUEST, 'description');
$user = $_SESSION[config("site.url")]['user'];
if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
if (!empty($url)) {
add_post($title, $tag, $url, $content, $user);
add_post($title, $tag, $url, $content, $user, $description);
} else {
$url = $title;
add_post($title, $tag, $url, $content, $user);
add_post($title, $tag, $url, $content, $user, $description);
}
} else {
$message['error'] = '';
@ -940,12 +938,13 @@ post('/add/page', function() {
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$description = from($_REQUEST, 'description');
if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
add_page($title, $url, $content);
add_page($title, $url, $content, $description);
} else {
$url = $title;
add_page($title, $url, $content);
add_page($title, $url, $content, $description);
}
} else {
$message['error'] = '';
@ -1238,14 +1237,13 @@ get('/:static/add', function($static) {
config('views.root', 'system/admin/views');
$post = get_static_post($static);
if(! $post)
{
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',
@ -1263,12 +1261,13 @@ post('/:static/add', function($static) {
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$description = from($_REQUEST, 'description');
if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
add_sub_page($title, $url, $content, $static);
add_sub_page($title, $url, $content, $static, $description);
} else {
$url = $title;
add_sub_page($title, $url, $content, $static);
add_sub_page($title, $url, $content, $static, $description);
}
} else {
$message['error'] = '';
@ -1294,29 +1293,28 @@ post('/:static/add', function($static) {
}
});
get('/:static/:sub', function($static,$sub) {
get('/:static/:sub', function($static, $sub) {
$father_post = get_static_post($static);
if (!$father_post) {
not_found();
}
$post = get_static_sub_post($static,$sub);
$post = get_static_sub_post($static, $sub);
if (!$post) {
not_found();
}
$post = $post[0];
if(config("views.counter") == "true")
{
add_view($post->file);
}
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),
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $post->description, $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,


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

@ -16,7 +16,7 @@ function get_post_unsorted() {
if (empty($_unsorted)) {
$url = 'cache/index/index-unsorted.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all');
}
$_unsorted = unserialize(file_get_contents($url));
@ -31,7 +31,7 @@ function get_post_sorted() {
if (empty($_sorted)) {
$url = 'cache/index/index-sorted.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all');
}
$_sorted = unserialize(file_get_contents($url));
@ -46,7 +46,7 @@ function get_static_pages() {
if (empty($_page)) {
$url = 'cache/index/index-page.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all');
}
$_page = unserialize(file_get_contents($url));
@ -61,18 +61,16 @@ function get_static_sub_pages($static = null) {
if (empty($_sub_page)) {
$url = 'cache/index/index-sub-page.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all');
}
$_sub_page = unserialize(file_get_contents($url));
}
if($static != null)
{
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 array_filter($_sub_page, function($sub_page)use($static, $stringLen) {
$x = explode("/", $sub_page);
if ($x[count($x) - 2] == $static) {
return true;
}
return false;
@ -88,7 +86,7 @@ function get_author_names() {
if (empty($_author)) {
$url = 'cache/index/index-author.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all');
}
$_author = unserialize(file_get_contents($url));
@ -245,14 +243,15 @@ function get_posts($posts, $page = 1, $perpage = 0) {
$content = MarkdownExtra::defaultTransform(file_get_contents($filepath));
// Extract the title and body
$post->title = get_content_tag('t',$content,'Untitled: ' . date('l jS \of F Y', $post->date));
$post->title = get_content_tag('t', $content, 'Untitled: ' . date('l jS \of F Y', $post->date));
$post->body = remove_html_comments($content);
if(config("views.counter"))
{
if (config("views.counter")) {
$post->views = get_views($post->file);
}
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post;
}
@ -413,9 +412,11 @@ function get_bio($author) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$post->title = get_content_tag('t',$content,$author);
$post->title = get_content_tag('t', $content, $author);
$post->body = remove_html_comments($content);
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post;
}
}
@ -436,6 +437,8 @@ function default_profile($author) {
$profile->title = $author;
$profile->body = '<p>Just another HTMLy user.</p>';
$profile->descirption = 'Just another HTMLy user';
return $tmp[] = $profile;
}
@ -466,14 +469,15 @@ function get_static_post($static) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$post->title = get_content_tag('t',$content,$static);
$post->title = get_content_tag('t', $content, $static);
$post->body = remove_html_comments($content);
if(config("views.counter"))
{
if (config("views.counter")) {
$post->views = get_views($post->file);
}
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post;
}
}
@ -481,11 +485,12 @@ function get_static_post($static) {
return $tmp;
}
// Return static page.
function get_static_sub_post($static,$sub_static) {
function get_static_sub_post($static, $sub_static) {
$posts = get_static_sub_pages($static);
$tmp = array();
if (!empty($posts)) {
@ -508,11 +513,13 @@ function get_static_sub_post($static,$sub_static) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$post->title = get_content_tag('t',$content,$sub_static);
$post->title = get_content_tag('t', $content, $sub_static);
$post->body = remove_html_comments($content);
$post->views = get_views($post->file);
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post;
}
}
@ -1050,8 +1057,7 @@ function menu() {
}
}
function get_title_from_file($v)
{
function get_title_from_file($v) {
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
@ -1059,12 +1065,11 @@ function get_title_from_file($v)
$base = str_replace($replaced, '', $v);
// Extract the title and body
return get_content_tag('t',$content,str_replace('-', ' ', str_replace('.md', '', $base)));
return get_content_tag('t', $content, str_replace('-', ' ', str_replace('.md', '', $base)));
}
// Auto generate menu from static page
function get_menu() {//aktive Link for Sub Pages ::TODO
$posts = get_static_pages();
$req = $_SERVER['REQUEST_URI'];
@ -1105,29 +1110,25 @@ function get_menu() {//aktive Link for Sub Pages ::TODO
$active = '';
}
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))
{
if (!empty($subPages)) {
echo '<ul>';
$iSub = 0;
$countSub = count($subPages);
foreach($subPages as $index => $sp)
{
foreach ($subPages as $index => $sp) {
$classSub = "item";
if($iSub == 0)
{
if ($iSub == 0) {
$classSub .= " first";
}
if($iSub == $countSub -1)
{
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';
}
@ -1644,52 +1645,40 @@ function is_csrf_proper($csrf_token) {
return false;
}
function add_view($page)
{
function add_view($page) {
$filename = "cache/count.json";
$views = array();
if(file_exists($filename))
{
$views = json_decode(file_get_contents($filename),true);
if (file_exists($filename)) {
$views = json_decode(file_get_contents($filename), true);
}
if(isset($views[$page]))
{
$views[$page]++;
}
else
{
if (isset($views[$page])) {
$views[$page] ++;
} else {
$views[$page] = 1;
}
file_put_contents($filename,json_encode($views));
file_put_contents($filename, json_encode($views));
}
function get_views($page)
{
function get_views($page) {
static $_views = array();
if(empty($_views))
{
if (empty($_views)) {
$filename = "cache/count.json";
if(file_exists($filename))
{
$_views = json_decode(file_get_contents($filename),true);
if (file_exists($filename)) {
$_views = json_decode(file_get_contents($filename), true);
}
}
if(isset($_views[$page]))
{
if (isset($_views[$page])) {
return $_views[$page];
}
return -1;
}
function get_content_tag($tag, $string, $alt = null)
{
$reg = '/\<!--'.$tag.'(.+)'.$tag.'--\>/';
function get_content_tag($tag, $string, $alt = null) {
$reg = '/\<!--' . $tag . '(.+)' . $tag . '--\>/';
$ary = array();
if(preg_match($reg, $string, $ary))
{
if(isset($ary[1]))
{
if (preg_match($reg, $string, $ary)) {
if (isset($ary[1])) {
return trim($ary[1]);
}
}
@ -1697,6 +1686,5 @@ function get_content_tag($tag, $string, $alt = null)
}
function remove_html_comments($content) {
//return $content;
return trim(preg_replace('/(\s|)<!--(.*)-->(\s|)/', '', $content));
}
}

Loading…
Cancel
Save