From 0316cf0602eb76e6c2a4302fc5250d2ce9485d46 Mon Sep 17 00:00:00 2001 From: Kanti Date: Mon, 11 Aug 2014 20:26:46 +0200 Subject: [PATCH 1/3] custom Description added --- system/htmly.php | 83 +++++++++++++-------------- system/includes/functions.php | 127 +++++++++++++++++++----------------------- 2 files changed, 96 insertions(+), 114 deletions(-) diff --git a/system/htmly.php b/system/htmly.php index 062b18b..f67f333 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -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,22 +141,20 @@ 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) - { + if ($destination === null) { $destination = $static . "/" . $sub; } 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()) { @@ -205,7 +203,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 +236,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 +249,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 +279,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', @@ -452,9 +448,11 @@ get('/author/:profile', function($profile) { $bio = default_profile($profile); } + $description = 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.'; + if (empty($posts) || $page < 1) { 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, 'posts' => null, 'bio' => $bio->body, @@ -467,7 +465,7 @@ get('/author/:profile', function($profile) { } 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, 'posts' => $posts, 'bio' => $bio->body, @@ -704,14 +702,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 +717,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 +725,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' => '' . config('breadcrumb.home') . ' » ' . $post->title, 'p' => $post, @@ -769,12 +765,11 @@ 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'); @@ -1238,14 +1233,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', @@ -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); 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' => '' . config('breadcrumb.home') . ' » ' . $father_post[0]->title . ' » ' . $post->title, 'p' => $post, diff --git a/system/includes/functions.php b/system/includes/functions.php index ee15f08..6bf654e 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -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 = '

Just another HTMLy user.

'; + $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 '
  • '; - + $subPages = get_static_sub_pages(str_replace('.md', '', $base)); echo '' . ucwords($title) . '
    '; - if(!empty($subPages)) - { + if (!empty($subPages)) { echo '