diff --git a/system/admin/admin.php b/system/admin/admin.php index 47d469d..f002a00 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -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 = '' . "\n\n" . $content; + if ($description !== null) { + $post_description = "\n"; + } else { + $post_description = ""; + } + $post_content = '' . $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 = '' . "\n\n" . $content; + if ($description !== null) { + $post_description = "\n"; + } else { + $post_description = ''; + } + $post_content = '' . $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 = '' . "\n\n" . $content; + if ($description !== null) { + $post_description = "\n"; + } else { + $post_description = ""; + } + $post_content = '' . $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 = '' . "\n\n" . $content; + if ($description !== null) { + $post_description = "\n"; + } else { + $post_description = ""; + } + $post_content = '' . $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 = '' . "\n\n" . $content; + if ($description !== null) { + $post_description = "\n"; + } else { + $post_description = ""; + } + $post_content = '' . $post_description . "\n\n" . $content; if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { if (get_magic_quotes_gpc()) { diff --git a/system/admin/views/add-page.html.php b/system/admin/views/add-page.html.php index 5875bee..c48f07f 100644 --- a/system/admin/views/add-page.html.php +++ b/system/admin/views/add-page.html.php @@ -9,8 +9,9 @@
Title *


Url (optional)

- If the url leave empty we will use the page title. -

+ If the url leave empty we will use the page title.

+ Meta Description (optional)

+

diff --git a/system/admin/views/add-post.html.php b/system/admin/views/add-post.html.php index c0f9eae..7955a82 100644 --- a/system/admin/views/add-post.html.php +++ b/system/admin/views/add-post.html.php @@ -10,7 +10,8 @@ Title *


Tag *


Url (optional)

- If the url leave empty we will use the post title. + If the url leave empty we will use the post title.

+ Meta Description (optional)




diff --git a/system/admin/views/edit-page.html.php b/system/admin/views/edit-page.html.php index 76e4863..2ea895d 100644 --- a/system/admin/views/edit-page.html.php +++ b/system/admin/views/edit-page.html.php @@ -35,6 +35,8 @@ Title *


Url (optional)

If the url leave empty we will use the page title.

+ Meta Description (optional)

+


diff --git a/system/admin/views/edit-post.html.php b/system/admin/views/edit-post.html.php index 8d3762f..3b37435 100644 --- a/system/admin/views/edit-post.html.php +++ b/system/admin/views/edit-post.html.php @@ -48,7 +48,8 @@ Title *


Tag *


Url (optional)

- If the url leave empty we will use the post title. + If the url leave empty we will use the post title.

+ Meta Description (optional)




diff --git a/system/admin/views/edit-profile.html.php b/system/admin/views/edit-profile.html.php index 1b0a611..8bda830 100644 --- a/system/admin/views/edit-profile.html.php +++ b/system/admin/views/edit-profile.html.php @@ -28,6 +28,8 @@
Title *


+ Meta Description (optional)

+

diff --git a/system/htmly.php b/system/htmly.php index 062b18b..1db5edb 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,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' => '' . config('breadcrumb.home') . ' » ' . $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' => '' . 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..faf7b47 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 '
      '; - + $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 = '/\(\s|)/', '', $content)); -} \ No newline at end of file +}