Browse Source

custom Description added

pull/77/head^2
Kanti 11 years ago
parent
commit
0316cf0602
2 changed files with 96 additions and 114 deletions
  1. +38
    -45
      system/htmly.php
  2. +58
    -69
      system/includes/functions.php

+ 38
- 45
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()) { if (login()) {
@ -120,8 +120,8 @@ get("/:static/:sub/edit", function($static,$sub) {
} }
$post = $post[0]; $post = $post[0];
$page = get_static_sub_post($static,$sub);
$page = get_static_sub_post($static, $sub);
if (!$page) { if (!$page) {
not_found(); not_found();
@ -141,22 +141,20 @@ get("/:static/:sub/edit", function($static,$sub) {
header("location: $login"); 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')); $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if(!login())
{
if (!login()) {
$login = site_url() . 'login'; $login = site_url() . 'login';
header("location: $login");
header("location: $login");
} }
$title = from($_REQUEST, 'title'); $title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url'); $url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content'); $content = from($_REQUEST, 'content');
$oldfile = from($_REQUEST, 'oldfile'); $oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination'); $destination = from($_GET, 'destination');
if($destination === null)
{
if ($destination === null) {
$destination = $static . "/" . $sub; $destination = $static . "/" . $sub;
} }
if ($proper && !empty($title) && !empty($content)) { if ($proper && !empty($title) && !empty($content)) {
@ -192,7 +190,7 @@ post("/:static/:sub/edit", function($static,$sub) {
} }
}); });
get("/:static/:sub/delete", function($static,$sub) {
get("/:static/:sub/delete", function($static, $sub) {
if (login()) { if (login()) {
@ -205,7 +203,7 @@ get("/:static/:sub/delete", function($static,$sub) {
$post = $post[0]; $post = $post[0];
$page = get_static_sub_post($static,$sub);
$page = get_static_sub_post($static, $sub);
if (!$page) { if (!$page) {
not_found(); not_found();
@ -238,8 +236,7 @@ post("/:static/:sub/delete", function() {
// The blog post page // The blog post page
get('/:year/:month/:name', function($year, $month, $name) { get('/:year/:month/:name', function($year, $month, $name) {
if(config("views.counter") != "true")
{
if (config("views.counter") != "true") {
if (!login()) { if (!login()) {
file_cache($_SERVER['REQUEST_URI']); file_cache($_SERVER['REQUEST_URI']);
} }
@ -252,9 +249,8 @@ get('/:year/:month/:name', function($year, $month, $name) {
if (!$current) { if (!$current) {
not_found(); not_found();
} }
if(config("views.counter") == "true")
{
if (config("views.counter") == "true") {
add_view($current->file); add_view($current->file);
if (!login()) { if (!login()) {
@ -283,7 +279,7 @@ get('/:year/:month/:name', function($year, $month, $name) {
} }
render('post', array( 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, 'p' => $current,
'authorinfo' => authorinfo($bio->title, $bio->body), 'authorinfo' => authorinfo($bio->title, $bio->body),
'bodyclass' => 'inpost', 'bodyclass' => 'inpost',
@ -452,9 +448,11 @@ get('/author/:profile', function($profile) {
$bio = default_profile($profile); $bio = default_profile($profile);
} }
$description = 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.';
if (empty($posts) || $page < 1) { if (empty($posts) || $page < 1) {
render('profile', array( render('profile', array(
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.', site_url() . 'author/' . $profile),
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), $description, site_url() . 'author/' . $profile),
'page' => $page, 'page' => $page,
'posts' => null, 'posts' => null,
'bio' => $bio->body, 'bio' => $bio->body,
@ -467,7 +465,7 @@ get('/author/:profile', function($profile) {
} }
render('profile', array( render('profile', array(
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.', site_url() . 'author/' . $profile),
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), $description, site_url() . 'author/' . $profile),
'page' => $page, 'page' => $page,
'posts' => $posts, 'posts' => $posts,
'bio' => $bio->body, 'bio' => $bio->body,
@ -704,14 +702,13 @@ get('/:static', function($static) {
} }
die; die;
} else { } else {
if( config("views.counter") != "true")
{
if (config("views.counter") != "true") {
if (!login()) { if (!login()) {
file_cache($_SERVER['REQUEST_URI']); file_cache($_SERVER['REQUEST_URI']);
} }
} }
$post = get_static_post($static); $post = get_static_post($static);
if (!$post) { if (!$post) {
@ -720,8 +717,7 @@ get('/:static', function($static) {
$post = $post[0]; $post = $post[0];
if(config("views.counter") == "true")
{
if (config("views.counter") == "true") {
add_view($post->file); add_view($post->file);
if (!login()) { if (!login()) {
file_cache($_SERVER['REQUEST_URI']); file_cache($_SERVER['REQUEST_URI']);
@ -729,7 +725,7 @@ get('/:static', function($static) {
} }
render('static', array( 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', 'bodyclass' => 'inpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $post->title, 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $post->title,
'p' => $post, 'p' => $post,
@ -769,12 +765,11 @@ get('/:static/edit', function($static) {
post('/:static/edit', function() { post('/:static/edit', function() {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
if(!login())
{
if (!login()) {
$login = site_url() . 'login'; $login = site_url() . 'login';
header("location: $login");
header("location: $login");
} }
$title = from($_REQUEST, 'title'); $title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url'); $url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content'); $content = from($_REQUEST, 'content');
@ -1238,14 +1233,13 @@ get('/:static/add', function($static) {
config('views.root', 'system/admin/views'); config('views.root', 'system/admin/views');
$post = get_static_post($static); $post = get_static_post($static);
if(! $post)
{
if (!$post) {
not_found(); not_found();
} }
$post = $post[0]; $post = $post[0];
render('add-page', array( render('add-page', array(
'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'addpage', 'bodyclass' => 'addpage',
@ -1294,29 +1288,28 @@ post('/:static/add', function($static) {
} }
}); });
get('/:static/:sub', function($static,$sub) {
get('/:static/:sub', function($static, $sub) {
$father_post = get_static_post($static); $father_post = get_static_post($static);
if (!$father_post) { if (!$father_post) {
not_found(); not_found();
} }
$post = get_static_sub_post($static,$sub);
$post = get_static_sub_post($static, $sub);
if (!$post) { if (!$post) {
not_found(); not_found();
} }
$post = $post[0]; $post = $post[0];
if(config("views.counter") == "true")
{
add_view($post->file);
}
if (config("views.counter") == "true") {
add_view($post->file);
}
if (!login()) { if (!login()) {
file_cache($_SERVER['REQUEST_URI']); file_cache($_SERVER['REQUEST_URI']);
} }
render('static', array( 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', '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, '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, 'p' => $post,


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

@ -16,7 +16,7 @@ function get_post_unsorted() {
if (empty($_unsorted)) { if (empty($_unsorted)) {
$url = 'cache/index/index-unsorted.txt'; $url = 'cache/index/index-unsorted.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all'); rebuilt_cache('all');
} }
$_unsorted = unserialize(file_get_contents($url)); $_unsorted = unserialize(file_get_contents($url));
@ -31,7 +31,7 @@ function get_post_sorted() {
if (empty($_sorted)) { if (empty($_sorted)) {
$url = 'cache/index/index-sorted.txt'; $url = 'cache/index/index-sorted.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all'); rebuilt_cache('all');
} }
$_sorted = unserialize(file_get_contents($url)); $_sorted = unserialize(file_get_contents($url));
@ -46,7 +46,7 @@ function get_static_pages() {
if (empty($_page)) { if (empty($_page)) {
$url = 'cache/index/index-page.txt'; $url = 'cache/index/index-page.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all'); rebuilt_cache('all');
} }
$_page = unserialize(file_get_contents($url)); $_page = unserialize(file_get_contents($url));
@ -61,18 +61,16 @@ function get_static_sub_pages($static = null) {
if (empty($_sub_page)) { if (empty($_sub_page)) {
$url = 'cache/index/index-sub-page.txt'; $url = 'cache/index/index-sub-page.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all'); rebuilt_cache('all');
} }
$_sub_page = unserialize(file_get_contents($url)); $_sub_page = unserialize(file_get_contents($url));
} }
if($static != null)
{
if ($static != null) {
$stringLen = strlen($static); $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 true;
} }
return false; return false;
@ -88,7 +86,7 @@ function get_author_names() {
if (empty($_author)) { if (empty($_author)) {
$url = 'cache/index/index-author.txt'; $url = 'cache/index/index-author.txt';
if(! file_exists($url)) {
if (!file_exists($url)) {
rebuilt_cache('all'); rebuilt_cache('all');
} }
$_author = unserialize(file_get_contents($url)); $_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)); $content = MarkdownExtra::defaultTransform(file_get_contents($filepath));
// Extract the title and body // 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); $post->body = remove_html_comments($content);
if(config("views.counter"))
{
if (config("views.counter")) {
$post->views = get_views($post->file); $post->views = get_views($post->file);
} }
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post; $tmp[] = $post;
} }
@ -413,9 +412,11 @@ function get_bio($author) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v)); $content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body // 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->body = remove_html_comments($content);
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post; $tmp[] = $post;
} }
} }
@ -436,6 +437,8 @@ function default_profile($author) {
$profile->title = $author; $profile->title = $author;
$profile->body = '<p>Just another HTMLy user.</p>'; $profile->body = '<p>Just another HTMLy user.</p>';
$profile->descirption = 'Just another HTMLy user';
return $tmp[] = $profile; return $tmp[] = $profile;
} }
@ -466,14 +469,15 @@ function get_static_post($static) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v)); $content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body // 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); $post->body = remove_html_comments($content);
if(config("views.counter"))
{
if (config("views.counter")) {
$post->views = get_views($post->file); $post->views = get_views($post->file);
} }
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post; $tmp[] = $post;
} }
} }
@ -481,11 +485,12 @@ function get_static_post($static) {
return $tmp; return $tmp;
} }
// Return static page. // 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); $posts = get_static_sub_pages($static);
$tmp = array(); $tmp = array();
if (!empty($posts)) { if (!empty($posts)) {
@ -508,11 +513,13 @@ function get_static_sub_post($static,$sub_static) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v)); $content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body // 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->body = remove_html_comments($content);
$post->views = get_views($post->file); $post->views = get_views($post->file);
$post->description = get_content_tag("d", $content, get_description($post->body));
$tmp[] = $post; $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 // Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v)); $content = MarkdownExtra::defaultTransform(file_get_contents($v));
@ -1059,12 +1065,11 @@ function get_title_from_file($v)
$base = str_replace($replaced, '', $v); $base = str_replace($replaced, '', $v);
// Extract the title and body // 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 // Auto generate menu from static page
function get_menu() {//aktive Link for Sub Pages ::TODO function get_menu() {//aktive Link for Sub Pages ::TODO
$posts = get_static_pages(); $posts = get_static_pages();
$req = $_SERVER['REQUEST_URI']; $req = $_SERVER['REQUEST_URI'];
@ -1105,29 +1110,25 @@ function get_menu() {//aktive Link for Sub Pages ::TODO
$active = ''; $active = '';
} }
echo '<li class="' . $class . $active . '">'; echo '<li class="' . $class . $active . '">';
$subPages = get_static_sub_pages(str_replace('.md', '', $base)); $subPages = get_static_sub_pages(str_replace('.md', '', $base));
echo '<a href="' . $url . '">' . ucwords($title) . '</a><br/>'; echo '<a href="' . $url . '">' . ucwords($title) . '</a><br/>';
if(!empty($subPages))
{
if (!empty($subPages)) {
echo '<ul>'; echo '<ul>';
$iSub = 0; $iSub = 0;
$countSub = count($subPages); $countSub = count($subPages);
foreach($subPages as $index => $sp)
{
foreach ($subPages as $index => $sp) {
$classSub = "item"; $classSub = "item";
if($iSub == 0)
{
if ($iSub == 0) {
$classSub .= " first"; $classSub .= " first";
} }
if($iSub == $countSub -1)
{
if ($iSub == $countSub - 1) {
$classSub .= " last"; $classSub .= " last";
} }
$replacedSub = substr($sp, 0, strrpos($sp, '/')) . '/'; $replacedSub = substr($sp, 0, strrpos($sp, '/')) . '/';
$baseSub = str_replace($replacedSub, '', $sp); $baseSub = str_replace($replacedSub, '', $sp);
if ($req == site_path() . "/" . str_replace('.md', '', $base) . "/" . str_replace('.md', '', $baseSub)) { if ($req == site_path() . "/" . str_replace('.md', '', $base) . "/" . str_replace('.md', '', $baseSub)) {
$classSub .= ' active'; $classSub .= ' active';
} }
@ -1644,52 +1645,40 @@ function is_csrf_proper($csrf_token) {
return false; return false;
} }
function add_view($page)
{
function add_view($page) {
$filename = "cache/count.json"; $filename = "cache/count.json";
$views = array(); $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; $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(); static $_views = array();
if(empty($_views))
{
if (empty($_views)) {
$filename = "cache/count.json"; $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 $_views[$page];
} }
return -1; 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(); $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]); return trim($ary[1]);
} }
} }
@ -1699,4 +1688,4 @@ function get_content_tag($tag, $string, $alt = null)
function remove_html_comments($content) { function remove_html_comments($content) {
//return $content; //return $content;
return trim(preg_replace('/(\s|)<!--(.*)-->(\s|)/', '', $content)); return trim(preg_replace('/(\s|)<!--(.*)-->(\s|)/', '', $content));
}
}

Loading…
Cancel
Save