diff --git a/config/config.ini.example b/config/config.ini.example index 41edb78..ccef248 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -80,5 +80,8 @@ lightbox = "off" ; Set the theme here views.root = "themes/logs" + ;Enable view Counter, the options is "true" and "false". If set to "true", you can see the Counts in Admin page. +views.counter = "true" + ; Framework config. No need to edit. views.layout = "layout" \ No newline at end of file diff --git a/system/admin/admin.php b/system/admin/admin.php index 147a6ff..48bebae 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1,542 +1,532 @@ Your username and password mismatch.'; - } - } - else { - return $str = '
  • Username not found in our record.
  • '; - } + $user_file = 'config/users/' . $user . '.ini'; + $user_pass = user('password', $user); + + if (file_exists($user_file)) { + if ($pass === $user_pass) { + $_SESSION[config("site.url")]['user'] = $user; + header('location: admin'); + } else { + return $str = '
  • Your username and password mismatch.
  • '; + } + } else { + return $str = '
  • Username not found in our record.
  • '; + } } // Clean URLs -function remove_accent($str) -{ - $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); - $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); - return str_replace($a, $b, $str); -} +function remove_accent($str) { + $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); + $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); + return str_replace($a, $b, $str); +} // Edit blog posts function edit_post($title, $tag, $url, $content, $oldfile, $destination = 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(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - if($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); - } - else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); - } - - $replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/'; - $dt = str_replace($replaced,'',$oldurl[0]); - $t = str_replace('-','',$dt); - $time = new DateTime($t); - $timestamp= $time->format("Y-m-d"); - - // The post date - $postdate = strtotime($timestamp); - - // The post URL - $posturl = site_url().date('Y/m', $postdate).'/'.$post_url; - - rebuilt_cache('all'); - clear_post_cache($dt, $post_tag, $post_url, $newfile); - - if ($destination == 'post') { - header("Location: $posturl"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - - } - + $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 (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; + if ($oldfile === $newfile) { + file_put_contents($oldfile, print_r($post_content, true)); + } else { + rename($oldfile, $newfile); + file_put_contents($newfile, print_r($post_content, true)); + } + + $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + $dt = str_replace($replaced, '', $oldurl[0]); + $t = str_replace('-', '', $dt); + $time = new DateTime($t); + $timestamp = $time->format("Y-m-d"); + + // The post date + $postdate = strtotime($timestamp); + + // The post URL + $posturl = site_url() . date('Y/m', $postdate) . '/' . $post_url; + + rebuilt_cache('all'); + clear_post_cache($dt, $post_tag, $post_url, $newfile); + + if ($destination == 'post') { + header("Location: $posturl"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Edit static page function edit_page($title, $url, $content, $oldfile, $destination = 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(!empty($post_title) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $newfile = $dir . '/' . $post_url . '.md'; - if($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); - } - else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); - } - - $posturl = site_url() . $post_url; - - rebuilt_cache('all'); - clear_page_cache($post_url); - if ($destination == 'post') { - header("Location: $posturl"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - - } - + $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 (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $newfile = $dir . '/' . $post_url . '.md'; + if ($oldfile === $newfile) { + file_put_contents($oldfile, print_r($post_content, true)); + } else { + rename($oldfile, $newfile); + file_put_contents($newfile, print_r($post_content, true)); + } + + $posturl = site_url() . $post_url; + + rebuilt_cache('all'); + clear_page_cache($post_url); + if ($destination == 'post') { + header("Location: $posturl"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Add blog post function add_post($title, $tag, $url, $content, $user) { - $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(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; - $dir = 'content/' . $user. '/blog/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - rebuilt_cache('all'); - clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename); - $redirect = site_url() . 'admin/mine'; - header("Location: $redirect"); - } - + $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 (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; + $dir = 'content/' . $user . '/blog/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_post_cache($post_date, $post_tag, $post_url, $dir . $filename); + $redirect = site_url() . 'admin/mine'; + header("Location: $redirect"); + } } // Add static page function add_page($title, $url, $content) { - $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(!empty($post_title) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_url . '.md'; - $dir = 'content/static/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - rebuilt_cache('all'); - clear_page_cache($post_url); - $redirect = site_url() . 'admin'; - header("Location: $redirect"); - } - + $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 (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_url . '.md'; + $dir = 'content/static/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_page_cache($post_url); + $redirect = site_url() . 'admin'; + header("Location: $redirect"); + } } // Delete blog post function delete_post($file, $destination) { - if(!login()) return null; - $deleted_content = $file; - - // Get cache file - $arr = explode('_', $file); - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - $dt = str_replace($replaced,'',$arr[0]); - clear_post_cache($dt, $arr[1], str_replace('.md','',$arr[2]), $file); - - if(!empty($deleted_content)) { - unlink($deleted_content); - rebuilt_cache('all'); - if($destination == 'post') { - $redirect = site_url(); - header("Location: $redirect"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - } + if (!login()) + return null; + $deleted_content = $file; + + // Get cache file + $arr = explode('_', $file); + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + $dt = str_replace($replaced, '', $arr[0]); + clear_post_cache($dt, $arr[1], str_replace('.md', '', $arr[2]), $file); + + if (!empty($deleted_content)) { + unlink($deleted_content); + rebuilt_cache('all'); + if ($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Delete static page function delete_page($file, $destination) { - if(!login()) return null; - $deleted_content = $file; - - if (!empty($menu)) { - foreach(glob('cache/page/*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - } - else { - $replaced = substr($file, 0, strrpos($file, '/')) . '/'; - $url = str_replace($replaced,'',$file); - clear_page_cache($url); - } - - if(!empty($deleted_content)) { - unlink($deleted_content); - rebuilt_cache('all'); - if($destination == 'post') { - $redirect = site_url(); - header("Location: $redirect"); - } - else { - $redirect = site_url() . $destination; - header("Location: $redirect"); - } - } + if (!login()) + return null; + $deleted_content = $file; + + if (!empty($menu)) { + foreach (glob('cache/page/*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + } else { + $replaced = substr($file, 0, strrpos($file, '/')) . '/'; + $url = str_replace($replaced, '', $file); + clear_page_cache($url); + } + + if (!empty($deleted_content)) { + unlink($deleted_content); + rebuilt_cache('all'); + if ($destination == 'post') { + $redirect = site_url(); + header("Location: $redirect"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } } // Edit user profile function edit_profile($title, $content, $user) { - $user_title = $title; - $user_content = '' . "\n\n" . $content; - - if(!empty($user_title) && !empty($user_content)) { - if(get_magic_quotes_gpc()) { - $user_content = stripslashes($user_content); - } - $dir = 'content/' . $user. '/'; - $filename = 'content/' . $user . '/author.md'; - if(is_dir($dir)) { - file_put_contents($filename, print_r($user_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($filename, print_r($user_content, true)); - } - rebuilt_cache('all'); - $redirect = site_url() . 'author/' . $user; - header("Location: $redirect"); - } - + $user_title = $title; + $user_content = '' . "\n\n" . $content; + + if (!empty($user_title) && !empty($user_content)) { + if (get_magic_quotes_gpc()) { + $user_content = stripslashes($user_content); + } + $dir = 'content/' . $user . '/'; + $filename = 'content/' . $user . '/author.md'; + if (is_dir($dir)) { + file_put_contents($filename, print_r($user_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($filename, print_r($user_content, true)); + } + rebuilt_cache('all'); + $redirect = site_url() . 'author/' . $user; + header("Location: $redirect"); + } } // Import RSS feed function migrate($title, $time, $tags, $content, $url, $user, $source) { - $post_date = date('Y-m-d-H-i-s', $time); - $post_title = $title; - $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags)); - $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); - if(!empty($source)) { - $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; - } - else { - $post_content = '' . "\n\n" . $content; - } - if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { - if(get_magic_quotes_gpc()) { - $post_content = stripslashes($post_content); - } - $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; - $dir = 'content/' . $user. '/blog/'; - if(is_dir($dir)) { - file_put_contents($dir . $filename, print_r($post_content, true)); - } - else { - mkdir($dir, 0777, true); - file_put_contents($dir . $filename, print_r($post_content, true)); - } - - $redirect = site_url() . 'admin/clear-cache'; - header("Location: $redirect"); - } - + $post_date = date('Y-m-d-H-i-s', $time); + $post_title = $title; + $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags)); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + if (!empty($source)) { + $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; + } else { + $post_content = '' . "\n\n" . $content; + } + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; + $dir = 'content/' . $user . '/blog/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0777, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + $redirect = site_url() . 'admin/clear-cache'; + header("Location: $redirect"); + } } // Fetch RSS feed -function get_feed($feed_url, $credit, $message=null) { +function get_feed($feed_url, $credit, $message = null) { $source = file_get_contents($feed_url); $feed = new SimpleXmlElement($source); - if(!empty($feed->channel->item)) { - foreach($feed->channel->item as $entry) { - $descriptionA = $entry->children('content', true); - $descriptionB = $entry->description; - if(!empty($descriptionA)) { - $content = $descriptionA; - } - else if (!empty($descriptionB)) { - $content = preg_replace('##i', "\n", $descriptionB); - } - else { - return $str = '
  • Can not read the feed content.
  • '; - } - $time = new DateTime($entry->pubDate); - $timestamp= $time->format("Y-m-d H:i:s"); - $time = strtotime($timestamp); - $tags = strip_tags(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($entry->category))); - $title = rtrim($entry->title, ' \,\.\-'); - $title = ltrim($title, ' \,\.\-'); - $user = $_SESSION[config("site.url")]['user']; - $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); - if ($credit == 'yes') { - $source = $entry->link; - } - else { - $source= null; - } - migrate($title, $time, $tags, $content, $url, $user, $source); - } - } - else { - return $str= '
  • Unsupported feed.
  • '; - } - -} + if (!empty($feed->channel->item)) { + foreach ($feed->channel->item as $entry) { + $descriptionA = $entry->children('content', true); + $descriptionB = $entry->description; + if (!empty($descriptionA)) { + $content = $descriptionA; + } else if (!empty($descriptionB)) { + $content = preg_replace('##i', "\n", $descriptionB); + } else { + return $str = '
  • Can not read the feed content.
  • '; + } + $time = new DateTime($entry->pubDate); + $timestamp = $time->format("Y-m-d H:i:s"); + $time = strtotime($timestamp); + $tags = strip_tags(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($entry->category))); + $title = rtrim($entry->title, ' \,\.\-'); + $title = ltrim($title, ' \,\.\-'); + $user = $_SESSION[config("site.url")]['user']; + $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); + if ($credit == 'yes') { + $source = $entry->link; + } else { + $source = null; + } + migrate($title, $time, $tags, $content, $url, $user, $source); + } + } else { + return $str = '
  • Unsupported feed.
  • '; + } +} // Get recent posts by user function get_recent_posts() { - if (isset($_SESSION[config("site.url")]['user'])) { - $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); - if(!empty($posts)) { - echo ''; - echo ''; - $i = 0; $len = count($posts); - foreach($posts as $p) { - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    TitlePublishedTagOperations
    ' . $p->title . '' . date('d F Y', $p->date) . '' . $p->tag . 'Edit Delete
    '; - } - } + if (isset($_SESSION[config("site.url")]['user'])) { + $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); + if (!empty($posts)) { + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + $i = 0; + $len = count($posts); + foreach ($posts as $p) { + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + echo ''; + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
    TitlePublishedViewsTagOperations
    ' . $p->title . '' . date('d F Y', $p->date) . '' . $p->views . '' . $p->tag . 'Edit Delete
    '; + } + } } // Get all static pages function get_recent_pages() { - if (isset($_SESSION[config("site.url")]['user'])) { - $posts = get_static_post(null); - if(!empty($posts)) { - krsort($posts); - echo ''; - echo ''; - $i = 0; $len = count($posts); - foreach($posts as $p) { - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    TitleOperations
    ' . $p->title . 'Edit Delete
    '; - } - } + if (isset($_SESSION[config("site.url")]['user'])) { + $posts = get_static_post(null); + if (!empty($posts)) { + krsort($posts); + echo ''; + echo ''; + $i = 0; + $len = count($posts); + foreach ($posts as $p) { + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + echo ''; + + $shortUrl = substr($p->url,strrpos($p->url, "/") + 1); + $subPages = get_static_sub_post($shortUrl,null); + + foreach($subPages as $sp) + { + echo ''; + echo ''; + if (config("views.counter") == "true") + echo ''; + echo ''; + echo ''; + } + } + echo '
    TitleViewsOperations
    ' . $p->title . '' . $p->views . 'Add Sub Edit Delete
    »' . $sp->title . '' . $sp->views . 'Edit Delete
    '; + } + } } // Get all available zip files -function get_backup_files () { - if (isset($_SESSION[config("site.url")]['user'])) { - $files = get_zip_files(); - if(!empty($files)) { - krsort($files); - echo ''; - echo ''; - $i = 0; $len = count($files); - foreach($files as $file) { - - if ($i == 0) { - $class = 'item first'; - } - elseif ($i == $len - 1) { - $class = 'item last'; - } - else { - $class = 'item'; - } - $i++; - - // Extract the date - $arr = explode('_', $file); - - // Replaced string - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - - $name = str_replace($replaced,'',$file); - - $date = str_replace('.zip','',$arr[1]); - $t = str_replace('-', '', $date); - $time = new DateTime($t); - $timestamp= $time->format("D, d F Y, H:i:s"); - - $url = site_url() . $file; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    FilenameDateOperations
    ' . $name . '' . $timestamp . 'Download
    '; - } - else { - echo 'No available backup!'; - } - } +function get_backup_files() { + if (isset($_SESSION[config("site.url")]['user'])) { + $files = get_zip_files(); + if (!empty($files)) { + krsort($files); + echo ''; + echo ''; + $i = 0; + $len = count($files); + foreach ($files as $file) { + + if ($i == 0) { + $class = 'item first'; + } elseif ($i == $len - 1) { + $class = 'item last'; + } else { + $class = 'item'; + } + $i++; + + // Extract the date + $arr = explode('_', $file); + + // Replaced string + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + + $name = str_replace($replaced, '', $file); + + $date = str_replace('.zip', '', $arr[1]); + $t = str_replace('-', '', $date); + $time = new DateTime($t); + $timestamp = $time->format("D, d F Y, H:i:s"); + + $url = site_url() . $file; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
    FilenameDateOperations
    ' . $name . '' . $timestamp . 'Download
    '; + } else { + echo 'No available backup!'; + } + } } function clear_post_cache($post_date, $post_tag, $post_url, $filename) { - $b = str_replace('/', '#', site_path() . '/'); - $t = explode('-', $post_date); - $c = explode(',', $post_tag); - $p = 'cache/page/'.$b.$t[0].'#'.$t[1].'#'.$post_url.'.cache'; - - // Delete post - if (file_exists($p)) { - unlink($p); - } - - // Delete homepage - $yd = 'cache/page/'.$b.'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year - $yd = 'cache/page/'.$b.'archive#'.$t[0].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year-month - $yd = 'cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete year-month-day - $yd = 'cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'-'.$t[2].'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'archive#'.$t[0].'-'.$t[1].'-'.$t[2].'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - // Delete tag - foreach($c as $tag) { - $yd = 'cache/page/'.$b.'tag#'.$tag.'.cache'; - if (file_exists($yd)) { - unlink($yd); - } - foreach(glob('cache/page/'.$b.'tag#'.$tag.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - } - - // Delete search - foreach(glob('cache/page/'.$b.'search#*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - - - // Get cache post author - $arr = explode('_', $filename); - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - $str = explode('/', $replaced); - $author = $str[count($str)-3]; - // Delete author post list cache - $a = 'cache/page/'.$b.'author#'.$author.'.cache'; - if (file_exists($a)) { - unlink($a); - } - foreach(glob('cache/page/'.$b.'author#'.$author.'~*.cache', GLOB_NOSORT) as $file) { - unlink($file); - } - + $b = str_replace('/', '#', site_path() . '/'); + $t = explode('-', $post_date); + $c = explode(',', $post_tag); + $p = 'cache/page/' . $b . $t[0] . '#' . $t[1] . '#' . $post_url . '.cache'; + + // Delete post + if (file_exists($p)) { + unlink($p); + } + + // Delete homepage + $yd = 'cache/page/' . $b . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year-month + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete year-month-day + $yd = 'cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '-' . $t[2] . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'archive#' . $t[0] . '-' . $t[1] . '-' . $t[2] . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + // Delete tag + foreach ($c as $tag) { + $yd = 'cache/page/' . $b . 'tag#' . $tag . '.cache'; + if (file_exists($yd)) { + unlink($yd); + } + foreach (glob('cache/page/' . $b . 'tag#' . $tag . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + } + + // Delete search + foreach (glob('cache/page/' . $b . 'search#*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } + + + // Get cache post author + $arr = explode('_', $filename); + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + $str = explode('/', $replaced); + $author = $str[count($str) - 3]; + // Delete author post list cache + $a = 'cache/page/' . $b . 'author#' . $author . '.cache'; + if (file_exists($a)) { + unlink($a); + } + foreach (glob('cache/page/' . $b . 'author#' . $author . '~*.cache', GLOB_NOSORT) as $file) { + unlink($file); + } } function clear_page_cache($url) { - $b = str_replace('/', '#', site_path() . '/'); - $p = 'cache/page/'.$b.$url.'.cache'; - if (file_exists($p)) { - unlink($p); - } -} \ No newline at end of file + $b = str_replace('/', '#', site_path() . '/'); + $p = 'cache/page/' . $b . $url . '.cache'; + if (file_exists($p)) { + unlink($p); + } +} diff --git a/system/admin/views/posts-list.html.php b/system/admin/views/posts-list.html.php index 3f9354e..9457c3e 100644 --- a/system/admin/views/posts-list.html.php +++ b/system/admin/views/posts-list.html.php @@ -1,7 +1,7 @@

    - + "> + diff --git a/system/admin/views/user-posts.html.php b/system/admin/views/user-posts.html.php index 427f970..2fc3624 100644 --- a/system/admin/views/user-posts.html.php +++ b/system/admin/views/user-posts.html.php @@ -1,7 +1,7 @@

    TitlePublishedAuthorTagOperations
    TitlePublishedViewsAuthorTagOperations
    title ?> date) ?>views ?> author ?> tag ?> Edit Delete
    - + "> + diff --git a/system/htmly.php b/system/htmly.php index 0c29618..e0b310a 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -19,1123 +19,1148 @@ config('source', 'config/config.ini'); // This will match the root url get('/index', function () { - if(!login()) { - file_cache($_SERVER['REQUEST_URI']); - } - - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = config('posts.perpage'); - - $posts = get_posts(null, $page, $perpage); - - $total = ''; - - $tl = blog_tagline(); - - if($tl){ $tagline = ' - ' . $tl;} else {$tagline = '';} - - if(empty($posts) || $page < 1){ - - // a non-existing page - render('no-posts',array( - 'head_contents' => head_contents(blog_title() . $tagline, blog_description(), site_url()), - 'bodyclass' => 'noposts', - )); - - die; - } - - render('main',array( - 'head_contents' => head_contents(blog_title() . $tagline, blog_description(), site_url()), - 'page' => $page, - 'posts' => $posts, - 'bodyclass' => 'infront', - 'breadcrumb' => '', - 'pagination' => has_pagination($total, $perpage, $page) - )); + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + + $page = from($_GET, 'page'); + $page = $page ? (int) $page : 1; + $perpage = config('posts.perpage'); + + $posts = get_posts(null, $page, $perpage); + + $total = ''; + + $tl = blog_tagline(); + + if ($tl) { + $tagline = ' - ' . $tl; + } else { + $tagline = ''; + } + + if (empty($posts) || $page < 1) { + + // a non-existing page + render('no-posts', array( + 'head_contents' => head_contents(blog_title() . $tagline, blog_description(), site_url()), + 'bodyclass' => 'noposts', + )); + + die; + } + + render('main', array( + 'head_contents' => head_contents(blog_title() . $tagline, blog_description(), site_url()), + 'page' => $page, + 'posts' => $posts, + 'bodyclass' => 'infront', + 'breadcrumb' => '', + 'pagination' => has_pagination($total, $perpage, $page) + )); }); // Get submitted login data post('/login', function() { - - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - - $user = from($_REQUEST, 'user'); - $pass = from($_REQUEST, 'password'); - if($proper && !empty($user) && !empty($pass)) { - - session($user, $pass, null); - $log = session($user, $pass, null); - - if(!empty($log)) { - - config('views.root', 'system/admin/views'); - - render('login',array( - 'head_contents' => head_contents('Login - ' . blog_title(), 'Login page on ' .blog_title(), site_url()), - 'error' => '', - 'bodyclass' => 'editprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Login' - )); - } - } - else { - $message['error'] = ''; - if(empty($user)) { - $message['error'] .= '
  • User field is required.
  • '; - } - if (empty($pass)) { - $message['error'] .= '
  • Password field is required.
  • '; - } - if(! $proper ) { - $message['error'] .= '
  • CSRF Token not correct.
  • '; - } - - config('views.root', 'system/admin/views'); - - render('login',array( - 'head_contents' => head_contents('Login - ' . blog_title(), 'Login page on ' .blog_title(), site_url()), - 'error' => '', - 'username' => $user, - 'password' => $pass, - 'bodyclass' => 'editprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Login' - )); - } + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $user = from($_REQUEST, 'user'); + $pass = from($_REQUEST, 'password'); + if ($proper && !empty($user) && !empty($pass)) { + + session($user, $pass, null); + $log = session($user, $pass, null); + + if (!empty($log)) { + + config('views.root', 'system/admin/views'); + + render('login', array( + 'head_contents' => head_contents('Login - ' . blog_title(), 'Login page on ' . blog_title(), site_url()), + 'error' => '', + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Login' + )); + } + } else { + $message['error'] = ''; + if (empty($user)) { + $message['error'] .= '
  • User field is required.
  • '; + } + if (empty($pass)) { + $message['error'] .= '
  • Password field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + + config('views.root', 'system/admin/views'); + + render('login', array( + 'head_contents' => head_contents('Login - ' . blog_title(), 'Login page on ' . blog_title(), site_url()), + 'error' => '', + 'username' => $user, + 'password' => $pass, + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Login' + )); + } }); -// The blog post page -get('/:year/:month/:name', function($year, $month, $name){ +get("/:static/:sub/edit", function($static,$sub){ + echo $static,$sub,"edit"; + die(); +}); +post("/:static/:sub/edit", function($static,$sub){ + echo $static,$sub,"edit."; + die(); +}); - if(!login()) { - file_cache($_SERVER['REQUEST_URI']); - } +get("/:static/:sub/delete", function($static,$sub){ + echo $static,$sub,"delete"; + die(); +}); +post("/:static/:sub/delete", function($static,$sub){ + echo $static,$sub,"delete."; + die(); +}); - $post = find_post($year, $month, $name); - - $current = $post['current']; - - if(!$current){ - not_found(); - } - - $bio = get_bio($current->author); - - if(isset($bio[0])) { - $bio = $bio[0]; - } - else { - $bio = default_profile($current->author); - } - - if (array_key_exists('prev', $post)) { - $prev = $post['prev']; - } - else { - $prev = array(); - } - - if (array_key_exists('next', $post)) { - $next= $post['next']; - } - else { - $next = array(); - } - - render('post',array( - 'head_contents' => head_contents($current->title .' - ' . blog_title(), $description = get_description($current->body), $current->url), - 'p' => $current, - 'authorinfo' => authorinfo($bio->title, $bio->body), - 'bodyclass' => 'inpost', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » '. $current->tagb . ' » ' . $current->title, - 'prev' => has_prev($prev), - 'next' => has_next($next), - 'type' => 'blogpost', - )); - +// The blog post page +get('/:year/:month/:name', function($year, $month, $name) { + + if(config("views.counter") != "true") + { + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + } + + $post = find_post($year, $month, $name); + + $current = $post['current']; + + if (!$current) { + not_found(); + } + + if(config("views.counter") == "true") + { + add_view($current->file); + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + } + + $bio = get_bio($current->author); + + if (isset($bio[0])) { + $bio = $bio[0]; + } else { + $bio = default_profile($current->author); + } + + if (array_key_exists('prev', $post)) { + $prev = $post['prev']; + } else { + $prev = array(); + } + + if (array_key_exists('next', $post)) { + $next = $post['next']; + } else { + $next = array(); + } + + render('post', array( + 'head_contents' => head_contents($current->title . ' - ' . blog_title(), $description = get_description($current->body), $current->url), + 'p' => $current, + 'authorinfo' => authorinfo($bio->title, $bio->body), + 'bodyclass' => 'inpost', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title, + 'prev' => has_prev($prev), + 'next' => has_next($next), + 'type' => 'blogpost', + )); }); // Edit blog post -get('/:year/:month/:name/edit', function($year, $month, $name){ - - if(login()) { - - $user = $_SESSION[config("site.url")]['user']; - $role = user('role', $user); - - config('views.root', 'system/admin/views'); - $post = find_post($year, $month, $name); - - if(!$post){ - not_found(); - } - - $current = $post['current']; - - if($user === $current->author || $role === 'admin') { - render('edit-post',array( - 'head_contents' => head_contents('Edit post - ' . blog_title(), blog_description(), site_url()), - 'p' => $current, - 'bodyclass' => 'editpost', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » '. $current->tagb . ' » ' . $current->title - )); - } - else { - render('denied',array( - 'head_contents' => head_contents('Edit post - ' . blog_title(), blog_description(), site_url()), - 'p' => $current, - 'bodyclass' => 'denied', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » '. $current->tagb . ' » ' . $current->title - )); - } - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } +get('/:year/:month/:name/edit', function($year, $month, $name) { + + if (login()) { + + $user = $_SESSION[config("site.url")]['user']; + $role = user('role', $user); + + config('views.root', 'system/admin/views'); + $post = find_post($year, $month, $name); + + if (!$post) { + not_found(); + } + + $current = $post['current']; + + if ($user === $current->author || $role === 'admin') { + render('edit-post', array( + 'head_contents' => head_contents('Edit post - ' . blog_title(), blog_description(), site_url()), + 'p' => $current, + 'bodyclass' => 'editpost', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title + )); + } else { + render('denied', array( + 'head_contents' => head_contents('Edit post - ' . blog_title(), blog_description(), site_url()), + 'p' => $current, + 'bodyclass' => 'denied', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title + )); + } + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // Get edited data for blog post post('/:year/:month/:name/edit', function() { - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - - $title = from($_REQUEST, 'title'); - $tag = from($_REQUEST, 'tag'); - $url = from($_REQUEST, 'url'); - $content = from($_REQUEST, 'content'); - $oldfile = from($_REQUEST, 'oldfile'); - $destination = from($_GET, 'destination'); - if($proper && !empty($title) && !empty($tag) && !empty($content)) { - if(!empty($url)) { - edit_post($title, $tag, $url, $content, $oldfile, $destination); - } - else { - $url = $title; - edit_post($title, $tag, $url, $content, $oldfile, $destination); - } - } - else { - $message['error'] = ''; - if(empty($title)) { - $message['error'] .= '
  • Title field is required.
  • '; - } - if (empty($tag)) { - $message['error'] .= '
  • Tag field is required.
  • '; - } - if (empty($content)) { - $message['error'] .= '
  • Content field is required.
  • '; - } - if(! $proper ) { - $message['error'] .= '
  • CSRF Token not correct.
  • '; - } - config('views.root', 'system/admin/views'); - - render('edit-post',array( - 'head_contents' => head_contents('Edit post - ' . blog_title(), blog_description(), site_url()), - 'error' => '', - 'oldfile' => $oldfile, - 'postTitle' => $title, - 'postTag' => $tag, - 'postUrl' => $url, - 'postContent' => $content, - 'bodyclass' => 'editpost', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Edit post' - )); - } - + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $title = from($_REQUEST, 'title'); + $tag = from($_REQUEST, 'tag'); + $url = from($_REQUEST, 'url'); + $content = from($_REQUEST, 'content'); + $oldfile = from($_REQUEST, 'oldfile'); + $destination = from($_GET, 'destination'); + if ($proper && !empty($title) && !empty($tag) && !empty($content)) { + if (!empty($url)) { + edit_post($title, $tag, $url, $content, $oldfile, $destination); + } else { + $url = $title; + edit_post($title, $tag, $url, $content, $oldfile, $destination); + } + } else { + $message['error'] = ''; + if (empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($tag)) { + $message['error'] .= '
  • Tag field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-post', array( + 'head_contents' => head_contents('Edit post - ' . blog_title(), blog_description(), site_url()), + 'error' => '', + 'oldfile' => $oldfile, + 'postTitle' => $title, + 'postTag' => $tag, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'editpost', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit post' + )); + } }); // Delete blog post -get('/:year/:month/:name/delete', function($year, $month, $name){ - - if(login()) { - - $user = $_SESSION[config("site.url")]['user']; - $role = user('role', $user); - - config('views.root', 'system/admin/views'); - $post = find_post($year, $month, $name); - - if(!$post){ - not_found(); - } - - $current = $post['current']; - - if($user === $current->author || $role === 'admin') { - render('delete-post',array( - 'head_contents' => head_contents('Delete post - ' . blog_title(), blog_description(), site_url()), - 'p' => $current, - 'bodyclass' => 'deletepost', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » '. $current->tagb . ' » ' . $current->title - )); - } - else { - render('denied',array( - 'head_contents' => head_contents('Delete post - ' . blog_title(), blog_description(), site_url()), - 'p' => $current, - 'bodyclass' => 'deletepost', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » '. $current->tagb . ' » ' . $current->title - )); - } - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } +get('/:year/:month/:name/delete', function($year, $month, $name) { + + if (login()) { + + $user = $_SESSION[config("site.url")]['user']; + $role = user('role', $user); + + config('views.root', 'system/admin/views'); + $post = find_post($year, $month, $name); + + if (!$post) { + not_found(); + } + + $current = $post['current']; + + if ($user === $current->author || $role === 'admin') { + render('delete-post', array( + 'head_contents' => head_contents('Delete post - ' . blog_title(), blog_description(), site_url()), + 'p' => $current, + 'bodyclass' => 'deletepost', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title + )); + } else { + render('denied', array( + 'head_contents' => head_contents('Delete post - ' . blog_title(), blog_description(), site_url()), + 'p' => $current, + 'bodyclass' => 'deletepost', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title + )); + } + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // Get deleted data for blog post post('/:year/:month/:name/delete', function() { - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if($proper) - { - $file = from($_REQUEST, 'file'); - $destination = from($_GET, 'destination'); - delete_post($file, $destination); - } + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + if ($proper) { + $file = from($_REQUEST, 'file'); + $destination = from($_GET, 'destination'); + delete_post($file, $destination); + } }); // The author page -get('/author/:profile', function($profile){ - - if(!login()) { - file_cache($_SERVER['REQUEST_URI']); - } - - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = config('profile.perpage'); - - $posts = get_profile($profile, $page, $perpage); - - $total = get_count($profile, 'dirname'); - - $bio = get_bio($profile); - - if(isset($bio[0])) { - $bio = $bio[0]; - } - else { - $bio = default_profile($profile); - } - - 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), - 'page' => $page, - 'posts' => null, - 'bio' => $bio->body, - 'name' => $bio->title, - 'bodyclass' => 'inprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Profile for: ' . $bio->title, - 'pagination' => has_pagination($total, $perpage, $page) - )); - die; - } - - 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), - 'page' => $page, - 'posts' => $posts, - 'bio' => $bio->body, - 'name' => $bio->title, - 'bodyclass' => 'inprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Profile for: ' . $bio->title, - 'pagination' => has_pagination($total, $perpage, $page) - )); +get('/author/:profile', function($profile) { + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + + $page = from($_GET, 'page'); + $page = $page ? (int) $page : 1; + $perpage = config('profile.perpage'); + + $posts = get_profile($profile, $page, $perpage); + + $total = get_count($profile, 'dirname'); + + $bio = get_bio($profile); + + if (isset($bio[0])) { + $bio = $bio[0]; + } else { + $bio = default_profile($profile); + } + + 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), + 'page' => $page, + 'posts' => null, + 'bio' => $bio->body, + 'name' => $bio->title, + 'bodyclass' => 'inprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, + 'pagination' => has_pagination($total, $perpage, $page) + )); + die; + } + + 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), + 'page' => $page, + 'posts' => $posts, + 'bio' => $bio->body, + 'name' => $bio->title, + 'bodyclass' => 'inprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, + 'pagination' => has_pagination($total, $perpage, $page) + )); }); // Edit the profile -get('/edit/profile', function(){ - - if(login()) { - - config('views.root', 'system/admin/views'); - render('edit-profile',array( - 'head_contents' => head_contents('Edit profile - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'editprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Edit profile', - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } +get('/edit/profile', function() { + + if (login()) { + + config('views.root', 'system/admin/views'); + render('edit-profile', array( + 'head_contents' => head_contents('Edit profile - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit profile', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // Get edited data for static page post('/edit/profile', function() { - - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - - $user = $_SESSION[config("site.url")]['user']; - $title = from($_REQUEST, 'title'); - $content = from($_REQUEST, 'content'); - if($proper && !empty($title) && !empty($content)) { - edit_profile($title, $content, $user); - } - else { - $message['error'] = ''; - if(empty($title)) { - $message['error'] .= '
  • Title field is required.
  • '; - } - if (empty($content)) { - $message['error'] .= '
  • Content field is required.
  • '; - } - if(! $proper ) { - $message['error'] .= '
  • CSRF Token not correct.
  • '; - } - config('views.root', 'system/admin/views'); - - render('edit-profile',array( - 'head_contents' => head_contents('Edit profile - ' . blog_title(), blog_description(), site_url()), - 'error' => '', - 'postTitle' => $title, - 'postContent' => $content, - 'bodyclass' => 'editprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Edit profile' - )); - } - + + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $user = $_SESSION[config("site.url")]['user']; + $title = from($_REQUEST, 'title'); + $content = from($_REQUEST, 'content'); + if ($proper && !empty($title) && !empty($content)) { + edit_profile($title, $content, $user); + } else { + $message['error'] = ''; + if (empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-profile', array( + 'head_contents' => head_contents('Edit profile - ' . blog_title(), blog_description(), site_url()), + 'error' => '', + 'postTitle' => $title, + 'postContent' => $content, + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit profile' + )); + } }); get('/admin/posts', function () { - $user = $_SESSION[config("site.url")]['user']; - $role = user('role', $user); - if(login()) { - - config('views.root', 'system/admin/views'); - if($role === 'admin') { - - config('views.root', 'system/admin/views'); - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = 20; - - $posts = get_posts(null, $page, $perpage); - - $total = ''; - - if(empty($posts) || $page < 1){ - - // a non-existing page - render('no-posts',array( - 'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'noposts', - )); - - die; - } - - $tl = blog_tagline(); - - if($tl){ $tagline = ' - ' . $tl;} else {$tagline = '';} - - render('posts-list',array( - 'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()), - 'heading' => 'All blog posts', - 'page' => $page, - 'posts' => $posts, - 'bodyclass' => 'all-posts', - 'breadcrumb' => '', - 'pagination' => has_pagination($total, $perpage, $page) - )); - } - else { - render('denied',array( - 'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'denied', - 'breadcrumb' => '', - )); - } - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } + $user = $_SESSION[config("site.url")]['user']; + $role = user('role', $user); + if (login()) { + + config('views.root', 'system/admin/views'); + if ($role === 'admin') { + + config('views.root', 'system/admin/views'); + $page = from($_GET, 'page'); + $page = $page ? (int) $page : 1; + $perpage = 20; + + $posts = get_posts(null, $page, $perpage); + + $total = ''; + + if (empty($posts) || $page < 1) { + + // a non-existing page + render('no-posts', array( + 'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'noposts', + )); + + die; + } + + $tl = blog_tagline(); + + if ($tl) { + $tagline = ' - ' . $tl; + } else { + $tagline = ''; + } + + render('posts-list', array( + 'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()), + 'heading' => 'All blog posts', + 'page' => $page, + 'posts' => $posts, + 'bodyclass' => 'all-posts', + 'breadcrumb' => '', + 'pagination' => has_pagination($total, $perpage, $page) + )); + } else { + render('denied', array( + 'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'denied', + 'breadcrumb' => '', + )); + } + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // The author page -get('/admin/mine', function(){ - - if(login()) { - - config('views.root', 'system/admin/views'); - - $profile = $_SESSION[config("site.url")]['user']; - - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = config('profile.perpage'); - - $posts = get_profile($profile, $page, $perpage); - - $total = get_count($profile, 'dirname'); - - $bio = get_bio($profile); - - if(isset($bio[0])) { - $bio = $bio[0]; - } - else { - $bio = default_profile($profile); - } - - if(empty($posts) || $page < 1){ - render('user-posts',array( - 'head_contents' => head_contents('My blog posts - ' . blog_title(), blog_description(), site_url()), - 'page' => $page, - 'heading' => 'My posts', - 'posts' => null, - 'bio' => $bio->body, - 'name' => $bio->title, - 'bodyclass' => 'userposts', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Profile for: ' . $bio->title, - 'pagination' => has_pagination($total, $perpage, $page) - )); - die; - } - - render('user-posts',array( - 'head_contents' => head_contents('My blog posts - ' . blog_title(), blog_description(), site_url()), - 'heading' => 'My posts', - 'page' => $page, - 'posts' => $posts, - 'bio' => $bio->body, - 'name' => $bio->title, - 'bodyclass' => 'userposts', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Profile for: ' . $bio->title, - 'pagination' => has_pagination($total, $perpage, $page) - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } +get('/admin/mine', function() { + + if (login()) { + + config('views.root', 'system/admin/views'); + + $profile = $_SESSION[config("site.url")]['user']; + + $page = from($_GET, 'page'); + $page = $page ? (int) $page : 1; + $perpage = config('profile.perpage'); + + $posts = get_profile($profile, $page, $perpage); + + $total = get_count($profile, 'dirname'); + + $bio = get_bio($profile); + + if (isset($bio[0])) { + $bio = $bio[0]; + } else { + $bio = default_profile($profile); + } + + if (empty($posts) || $page < 1) { + render('user-posts', array( + 'head_contents' => head_contents('My blog posts - ' . blog_title(), blog_description(), site_url()), + 'page' => $page, + 'heading' => 'My posts', + 'posts' => null, + 'bio' => $bio->body, + 'name' => $bio->title, + 'bodyclass' => 'userposts', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, + 'pagination' => has_pagination($total, $perpage, $page) + )); + die; + } + + render('user-posts', array( + 'head_contents' => head_contents('My blog posts - ' . blog_title(), blog_description(), site_url()), + 'heading' => 'My posts', + 'page' => $page, + 'posts' => $posts, + 'bio' => $bio->body, + 'name' => $bio->title, + 'bodyclass' => 'userposts', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, + 'pagination' => has_pagination($total, $perpage, $page) + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // The static page -get('/:static', function($static){ - - if($static === 'sitemap.xml' || $static === 'sitemap.base.xml' || $static === 'sitemap.post.xml' || $static === 'sitemap.static.xml' || $static === 'sitemap.tag.xml' || $static === 'sitemap.archive.xml' || $static === 'sitemap.author.xml') { - - header('Content-Type: text/xml'); - - if ($static === 'sitemap.xml') { - generate_sitemap('index'); - } - else if ($static === 'sitemap.base.xml') { - generate_sitemap('base'); - } - else if ($static === 'sitemap.post.xml') { - generate_sitemap('post'); - } - else if ($static === 'sitemap.static.xml') { - generate_sitemap('static'); - } - else if ($static === 'sitemap.tag.xml') { - generate_sitemap('tag'); - } - else if ($static === 'sitemap.archive.xml') { - generate_sitemap('archive'); - } - else if ($static === 'sitemap.author.xml') { - generate_sitemap('author'); - } - - die; - - } - elseif($static === 'admin') { - if(login()) { - config('views.root', 'system/admin/views'); - render('main', array( - 'head_contents' => head_contents('Admin - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'adminfront', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Admin' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } - die; - } - elseif($static === 'login') { - config('views.root', 'system/admin/views'); - render('login', array( - 'head_contents' => head_contents('Login - ' . blog_title(), 'Login page from ' . blog_title() . '.', site_url() . '/login'), - 'bodyclass' => 'inlogin', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Login' - )); - die; - } - elseif($static === 'logout') { - if(login()) { - config('views.root', 'system/admin/views'); - render('logout', array( - 'head_contents' => head_contents('Logout - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'inlogout', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Logout' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } - die; - } - else { - - if(!login()) { - file_cache($_SERVER['REQUEST_URI']); - } - - $post = get_static_post($static); - - if(!$post){ - not_found(); - } - - $post = $post[0]; - - render('static',array( - 'head_contents' => head_contents($post->title .' - ' . blog_title(), $description = get_description($post->body), $post->url), - 'bodyclass' => 'inpage', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » ' . $post->title, - 'p' => $post, - 'type' => 'staticpage', - )); - } - +get('/:static', function($static) { + + if ($static === 'sitemap.xml' || $static === 'sitemap.base.xml' || $static === 'sitemap.post.xml' || $static === 'sitemap.static.xml' || $static === 'sitemap.tag.xml' || $static === 'sitemap.archive.xml' || $static === 'sitemap.author.xml') { + + header('Content-Type: text/xml'); + + if ($static === 'sitemap.xml') { + generate_sitemap('index'); + } else if ($static === 'sitemap.base.xml') { + generate_sitemap('base'); + } else if ($static === 'sitemap.post.xml') { + generate_sitemap('post'); + } else if ($static === 'sitemap.static.xml') { + generate_sitemap('static'); + } else if ($static === 'sitemap.tag.xml') { + generate_sitemap('tag'); + } else if ($static === 'sitemap.archive.xml') { + generate_sitemap('archive'); + } else if ($static === 'sitemap.author.xml') { + generate_sitemap('author'); + } + + die; + } elseif ($static === 'admin') { + if (login()) { + config('views.root', 'system/admin/views'); + render('main', array( + 'head_contents' => head_contents('Admin - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'adminfront', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Admin' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; + } elseif ($static === 'login') { + config('views.root', 'system/admin/views'); + render('login', array( + 'head_contents' => head_contents('Login - ' . blog_title(), 'Login page from ' . blog_title() . '.', site_url() . '/login'), + 'bodyclass' => 'inlogin', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Login' + )); + die; + } elseif ($static === 'logout') { + if (login()) { + config('views.root', 'system/admin/views'); + render('logout', array( + 'head_contents' => head_contents('Logout - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'inlogout', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Logout' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; + } else { + + if( config("views.counter") != "true") + { + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + } + + $post = get_static_post($static); + + 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' => '' . config('breadcrumb.home') . ' » ' . $post->title, + 'p' => $post, + 'type' => 'staticpage', + )); + } }); // Edit the static page -get('/:static/edit', function($static){ - - if(login()) { - - config('views.root', 'system/admin/views'); - $post = get_static_post($static); - - if(!$post){ - not_found(); - } - - $post = $post[0]; - - render('edit-page',array( - 'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'editpage', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » ' . $post->title, - 'p' => $post, - 'type' => 'staticpage', - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } +get('/:static/edit', function($static) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_static_post($static); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + render('edit-page', array( + 'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'editpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title, + 'p' => $post, + 'type' => 'staticpage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // Get edited data for static page post('/:static/edit', function() { - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - - $title = from($_REQUEST, 'title'); - $url = from($_REQUEST, 'url'); - $content = from($_REQUEST, 'content'); - $oldfile = from($_REQUEST, 'oldfile'); - $destination = from($_GET, 'destination'); - 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'] .= '
  • Title field is required.
  • '; - } - if (empty($content)) { - $message['error'] .= '
  • Content field is required.
  • '; - } - if(! $proper ) { - $message['error'] .= '
  • CSRF Token not correct.
  • '; - } - config('views.root', 'system/admin/views'); - - render('edit-page',array( - 'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()), - 'error' => '', - 'oldfile' => $oldfile, - 'postTitle' => $title, - 'postUrl' => $url, - 'postContent' => $content, - 'bodyclass' => 'editpage', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Edit page' - )); - } - + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $title = from($_REQUEST, 'title'); + $url = from($_REQUEST, 'url'); + $content = from($_REQUEST, 'content'); + $oldfile = from($_REQUEST, 'oldfile'); + $destination = from($_GET, 'destination'); + 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'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + + render('edit-page', array( + 'head_contents' => head_contents('Edit page - ' . blog_title(), blog_description(), site_url()), + 'error' => '', + 'oldfile' => $oldfile, + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'editpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit page' + )); + } }); // Deleted the static page -get('/:static/delete', function($static){ - - if(login()) { - - config('views.root', 'system/admin/views'); - $post = get_static_post($static); - - if(!$post){ - not_found(); - } - - $post = $post[0]; - - render('delete-page',array( - 'head_contents' => head_contents('Delete page - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'deletepage', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » ' . $post->title, - 'p' => $post, - 'type' => 'staticpage', - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } +get('/:static/delete', function($static) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_static_post($static); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + render('delete-page', array( + 'head_contents' => head_contents('Delete page - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'deletepage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title, + 'p' => $post, + 'type' => 'staticpage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // Get deleted data for static page post('/:static/delete', function() { - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if($proper) - { - $file = from($_REQUEST, 'file'); - $destination = from($_GET, 'destination'); - delete_page($file, $destination); - } + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + if ($proper) { + $file = from($_REQUEST, 'file'); + $destination = from($_GET, 'destination'); + delete_page($file, $destination); + } }); // Add blog post -get('/add/post', function(){ +get('/add/post', function() { - if(login()) { + if (login()) { - config('views.root', 'system/admin/views'); - - render('add-post',array( - 'head_contents' => head_contents('Add post - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'addpost', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Add post' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } + config('views.root', 'system/admin/views'); + + render('add-post', array( + 'head_contents' => head_contents('Add post - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'addpost', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add post' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // Get submitted blog post data -post('/add/post', function(){ - - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - - $title = from($_REQUEST, 'title'); - $tag = from($_REQUEST, 'tag'); - $url = from($_REQUEST, 'url'); - $content = from($_REQUEST, 'content'); - $user = $_SESSION[config("site.url")]['user']; - if($proper && !empty($title) && !empty($tag) && !empty($content)) { - if(!empty($url)) { - add_post($title, $tag, $url, $content, $user); - } - else { - $url = $title; - add_post($title, $tag, $url, $content, $user); - } - } - else { - $message['error'] = ''; - if(empty($title)) { - $message['error'] .= '
  • Title field is required.
  • '; - } - if (empty($tag)) { - $message['error'] .= '
  • Tag field is required.
  • '; - } - if (empty($content)) { - $message['error'] .= '
  • Content field is required.
  • '; - } - if(! $proper ) { - $message['error'] .= '
  • CSRF Token not correct.
  • '; - } - config('views.root', 'system/admin/views'); - render('add-post',array( - 'head_contents' => head_contents('Add post - ' . blog_title(), blog_description(), site_url()), - 'error' => '', - 'postTitle' => $title, - 'postTag' => $tag, - 'postUrl' => $url, - 'postContent' => $content, - 'bodyclass' => 'addpost', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Add post' - )); - } - +post('/add/post', function() { + + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $title = from($_REQUEST, 'title'); + $tag = from($_REQUEST, 'tag'); + $url = from($_REQUEST, 'url'); + $content = from($_REQUEST, 'content'); + $user = $_SESSION[config("site.url")]['user']; + if ($proper && !empty($title) && !empty($tag) && !empty($content)) { + if (!empty($url)) { + add_post($title, $tag, $url, $content, $user); + } else { + $url = $title; + add_post($title, $tag, $url, $content, $user); + } + } else { + $message['error'] = ''; + if (empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($tag)) { + $message['error'] .= '
  • Tag field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + render('add-post', array( + 'head_contents' => head_contents('Add post - ' . blog_title(), blog_description(), site_url()), + 'error' => '', + 'postTitle' => $title, + 'postTag' => $tag, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'addpost', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add post' + )); + } }); // Add the static page -get('/add/page', function(){ +get('/add/page', function() { - if(login()) { + if (login()) { - config('views.root', 'system/admin/views'); - - render('add-page',array( - 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'addpage', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Add page' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } + config('views.root', 'system/admin/views'); + + render('add-page', array( + 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'addpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); // Get submitted static page data -post('/add/page', function(){ - - $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)) { - if(!empty($url)) { - add_page($title, $url, $content); - } - else { - $url = $title; - add_page($title, $url, $content); - } - } - else { - $message['error'] = ''; - if(empty($title)) { - $message['error'] .= '
  • Title field is required.
  • '; - } - if (empty($content)) { - $message['error'] .= '
  • Content field is required.
  • '; - } - if(! $proper ) { - $message['error'] .= '
  • CSRF Token not correct.
  • '; - } - config('views.root', 'system/admin/views'); - render('add-page',array( - 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), - 'error' => '', - 'postTitle' => $title, - 'postUrl' => $url, - 'postContent' => $content, - 'bodyclass' => 'addpage', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Add page' - )); - } - +post('/add/page', function() { + + $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)) { + if (!empty($url)) { + add_page($title, $url, $content); + } else { + $url = $title; + add_page($title, $url, $content); + } + } else { + $message['error'] = ''; + if (empty($title)) { + $message['error'] .= '
  • Title field is required.
  • '; + } + if (empty($content)) { + $message['error'] .= '
  • Content field is required.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + config('views.root', 'system/admin/views'); + render('add-page', array( + 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), + 'error' => '', + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'addpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page' + )); + } }); // Import page -get('/admin/import',function(){ - if(login()) { - config('views.root', 'system/admin/views'); - render('import', array( - 'head_contents' => head_contents('Import feed - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'importfeed', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Import feed' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } - die; +get('/admin/import', function() { + if (login()) { + config('views.root', 'system/admin/views'); + render('import', array( + 'head_contents' => head_contents('Import feed - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'importfeed', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Import feed' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; }); // Get import post post('/admin/import', function() { - $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - - $url = from($_REQUEST, 'url'); - $credit = from($_REQUEST, 'credit'); - if(!empty($url)) { - - get_feed($url, $credit, null); - $log = get_feed($url, $credit, null); - - if(!empty($log)) { - - config('views.root', 'system/admin/views'); - - render('import',array( - 'head_contents' => head_contents('Import feed - ' . blog_title(), blog_description(), site_url()), - 'error' => '', - 'bodyclass' => 'editprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Import feed' - )); - } - } - else { - $message['error'] = ''; - if(empty($url)) { - $message['error'] .= '
  • You need to specify the feed url.
  • '; - } - if(! $proper ) { - $message['error'] .= '
  • CSRF Token not correct.
  • '; - } - - config('views.root', 'system/admin/views'); - - render('import',array( - 'head_contents' => head_contents('Import feed - ' . blog_title(), blog_description(), site_url()), - 'error' => '', - 'url' => $url, - 'bodyclass' => 'editprofile', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Login' - )); - } - + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $url = from($_REQUEST, 'url'); + $credit = from($_REQUEST, 'credit'); + if (!empty($url)) { + + get_feed($url, $credit, null); + $log = get_feed($url, $credit, null); + + if (!empty($log)) { + + config('views.root', 'system/admin/views'); + + render('import', array( + 'head_contents' => head_contents('Import feed - ' . blog_title(), blog_description(), site_url()), + 'error' => '', + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Import feed' + )); + } + } else { + $message['error'] = ''; + if (empty($url)) { + $message['error'] .= '
  • You need to specify the feed url.
  • '; + } + if (!$proper) { + $message['error'] .= '
  • CSRF Token not correct.
  • '; + } + + config('views.root', 'system/admin/views'); + + render('import', array( + 'head_contents' => head_contents('Import feed - ' . blog_title(), blog_description(), site_url()), + 'error' => '', + 'url' => $url, + 'bodyclass' => 'editprofile', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Login' + )); + } }); // Backup page -get('/admin/backup',function(){ - if(login()) { - config('views.root', 'system/admin/views'); - render('backup', array( - 'head_contents' => head_contents('Backup content - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'backup', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Backup' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } - die; +get('/admin/backup', function() { + if (login()) { + config('views.root', 'system/admin/views'); + render('backup', array( + 'head_contents' => head_contents('Backup content - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'backup', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Backup' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; }); // Create Zip file -get('/admin/backup-start',function(){ - if(login()) { - config('views.root', 'system/admin/views'); - render('backup-start', array( - 'head_contents' => head_contents('Backup content started - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'startbackup', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Backup started' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } - die; +get('/admin/backup-start', function() { + if (login()) { + config('views.root', 'system/admin/views'); + render('backup-start', array( + 'head_contents' => head_contents('Backup content started - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'startbackup', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Backup started' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; }); // Delete all cache -get('/admin/clear-cache',function(){ - if(login()) { - config('views.root', 'system/admin/views'); - render('clear-cache', array( - 'head_contents' => head_contents('Clearing cache started - ' . blog_title(), blog_description(), site_url()), - 'bodyclass' => 'clearcache', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Clearing cache started' - )); - } - else { - $login = site_url() . 'login'; - header("location: $login"); - } - die; +get('/admin/clear-cache', function() { + if (login()) { + config('views.root', 'system/admin/views'); + render('clear-cache', array( + 'head_contents' => head_contents('Clearing cache started - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'clearcache', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Clearing cache started' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; }); // The tag page -get('/tag/:tag',function($tag){ +get('/tag/:tag', function($tag) { - if(!login()) { - file_cache($_SERVER['REQUEST_URI']); - } - - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = config('tag.perpage'); + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } - $posts = get_tag($tag, $page, $perpage, false); - - $total = get_count($tag, 'filename'); + $page = from($_GET, 'page'); + $page = $page ? (int) $page : 1; + $perpage = config('tag.perpage'); - if(empty($posts) || $page < 1){ - // a non-existing page - not_found(); - } - - render('main',array( - 'head_contents' => head_contents('Posts tagged: ' . $tag .' - ' . blog_title(), 'All posts tagged: ' . $tag . ' on '. blog_title() . '.', site_url() . 'tag/' . $tag), - 'page' => $page, - 'posts' => $posts, - 'bodyclass' => 'intag', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Posts tagged: ' . $tag, - 'pagination' => has_pagination($total, $perpage, $page) - )); -}); + $posts = get_tag($tag, $page, $perpage, false); -// The archive page -get('/archive/:req',function($req){ - - if(!login()) { - file_cache($_SERVER['REQUEST_URI']); - } + $total = get_count($tag, 'filename'); - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = config('archive.perpage'); + if (empty($posts) || $page < 1) { + // a non-existing page + not_found(); + } - $posts = get_archive($req, $page, $perpage); - - $total = get_count($req, 'filename'); + render('main', array( + 'head_contents' => head_contents('Posts tagged: ' . $tag . ' - ' . blog_title(), 'All posts tagged: ' . $tag . ' on ' . blog_title() . '.', site_url() . 'tag/' . $tag), + 'page' => $page, + 'posts' => $posts, + 'bodyclass' => 'intag', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Posts tagged: ' . $tag, + 'pagination' => has_pagination($total, $perpage, $page) + )); +}); - if(empty($posts) || $page < 1){ - // a non-existing page - not_found(); - } - - $time = explode('-', $req); - $date = strtotime($req); - - if (isset($time[0]) && isset($time[1]) && isset($time[2])) { - $timestamp = date('d F Y', $date); - } - else if (isset($time[0]) && isset($time[1])) { - $timestamp = date('F Y', $date); - } - else { - $timestamp = $req; - } - - if(!$date){ - // a non-existing page - not_found(); - } - - render('main',array( - 'head_contents' => head_contents('Archive for: ' . $timestamp .' - ' . blog_title(), 'Archive page for: ' . $timestamp . ' on ' . blog_title() . '.', site_url() . 'archive/' . $req), - 'page' => $page, - 'posts' => $posts, - 'bodyclass' => 'inarchive', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Archive for: ' . $timestamp, - 'pagination' => has_pagination($total, $perpage, $page) - )); +// The archive page +get('/archive/:req', function($req) { + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + + $page = from($_GET, 'page'); + $page = $page ? (int) $page : 1; + $perpage = config('archive.perpage'); + + $posts = get_archive($req, $page, $perpage); + + $total = get_count($req, 'filename'); + + if (empty($posts) || $page < 1) { + // a non-existing page + not_found(); + } + + $time = explode('-', $req); + $date = strtotime($req); + + if (isset($time[0]) && isset($time[1]) && isset($time[2])) { + $timestamp = date('d F Y', $date); + } else if (isset($time[0]) && isset($time[1])) { + $timestamp = date('F Y', $date); + } else { + $timestamp = $req; + } + + if (!$date) { + // a non-existing page + not_found(); + } + + render('main', array( + 'head_contents' => head_contents('Archive for: ' . $timestamp . ' - ' . blog_title(), 'Archive page for: ' . $timestamp . ' on ' . blog_title() . '.', site_url() . 'archive/' . $req), + 'page' => $page, + 'posts' => $posts, + 'bodyclass' => 'inarchive', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Archive for: ' . $timestamp, + 'pagination' => has_pagination($total, $perpage, $page) + )); }); // The search page -get('/search/:keyword', function($keyword){ - - if(!login()) { - file_cache($_SERVER['REQUEST_URI']); - } - - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = config('search.perpage'); - - $posts = get_keyword($keyword, $page, $perpage); - - $total = keyword_count($keyword); - - if(empty($posts) || $page < 1){ - // a non-existing page - render('404-search', null, false); - die; - } - - render('main',array( - 'head_contents' => head_contents('Search results for: ' . $keyword . ' - ' . blog_title(), 'Search results for: ' . $keyword . ' on '. blog_title() . '.', site_url() . 'search/' . $keyword), - 'page' => $page, - 'posts' => $posts, - 'bodyclass' => 'insearch', - 'breadcrumb' => '' .config('breadcrumb.home'). ' » Search results for: ' . $keyword, - 'pagination' => has_pagination($total, $perpage, $page) - )); - +get('/search/:keyword', function($keyword) { + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + + $page = from($_GET, 'page'); + $page = $page ? (int) $page : 1; + $perpage = config('search.perpage'); + + $posts = get_keyword($keyword, $page, $perpage); + + $total = keyword_count($keyword); + + if (empty($posts) || $page < 1) { + // a non-existing page + render('404-search', null, false); + die; + } + + render('main', array( + 'head_contents' => head_contents('Search results for: ' . $keyword . ' - ' . blog_title(), 'Search results for: ' . $keyword . ' on ' . blog_title() . '.', site_url() . 'search/' . $keyword), + 'page' => $page, + 'posts' => $posts, + 'bodyclass' => 'insearch', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Search results for: ' . $keyword, + 'pagination' => has_pagination($total, $perpage, $page) + )); }); // The JSON API -get('/api/json',function(){ +get('/api/json', function() { - header('Content-type: application/json'); + header('Content-type: application/json'); - // Print the 10 latest posts as JSON - echo generate_json(get_posts(null, 1, config('json.count'))); + // Print the 10 latest posts as JSON + echo generate_json(get_posts(null, 1, config('json.count'))); }); // Show the RSS feed -get('/feed/rss',function(){ +get('/feed/rss', function() { - header('Content-Type: application/rss+xml'); + header('Content-Type: application/rss+xml'); - // Show an RSS feed with the 30 latest posts - echo generate_rss(get_posts(null, 1, config('rss.count'))); + // Show an RSS feed with the 30 latest posts + echo generate_rss(get_posts(null, 1, config('rss.count'))); }); // Generate OPML file -get('/feed/opml',function(){ +get('/feed/opml', function() { + + header('Content-Type: text/xml'); + + // Generate OPML file for the RSS + echo generate_opml(); +}); - header('Content-Type: text/xml'); - - // Generate OPML file for the RSS - echo generate_opml(); - +get('/admin/update/now/:csrf', function($CSRF) { + + $proper = is_csrf_proper($CSRF); + $updater = new Updater; + if (login() && $proper && $updater->updateAble()) { + $updater->update(); + config('views.root', 'system/admin/views'); + render('updated-to', array( + 'head_contents' => head_contents('Updated - ' . blog_title(), blog_description(), site_url()), + 'updater' => $updater, + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } }); -get('/admin/update/now/:csrf',function($CSRF){ +get('/:static/add', function($static){ + echo $static,"add"; + die(); +}); +post('/:static/add', function($static){ + echo $static,"add."; + die(); +}); - $proper = is_csrf_proper($CSRF); - $updater = new Updater; - if( login() && $proper && $updater->updateAble()) +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") { - $updater->update(); - config('views.root', 'system/admin/views'); - render('updated-to', array( - 'head_contents' => head_contents('Updated - ' . blog_title(), blog_description(), site_url()), - 'updater' => $updater, - )); - } - else - { - $login = site_url() . 'login'; - header("location: $login"); + add_view($post->file); } + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + + render('static-sub', array( + 'head_contents' => head_contents($post->title . ' - ' . blog_title(), $description = get_description($post->body), $post->url), + 'bodyclass' => 'inpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $father_post[0]->title . ' » ' . $post->title, + 'p' => $post, + 'type' => 'staticpage', + )); }); // If we get here, it means that // nothing has been matched above -get('.*',function(){ - not_found(); +get('.*', function() { + not_found(); }); // Serve the blog -dispatch(); \ No newline at end of file +dispatch(); diff --git a/system/includes/functions.php b/system/includes/functions.php index 0e2cd8b..e40a138 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -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'); } } @@ -223,6 +256,11 @@ function get_posts($posts, $page = 1, $perpage = 0) { $post->body = $arr[0]; } + if(config("views.counter")) + { + $post->views = get_views($post->file); + } + $tmp[] = $post; } @@ -454,6 +492,58 @@ function get_static_post($static) { $post->title = $static; $post->body = $arr[0]; } + + if(config("views.counter")) + { + $post->views = get_views($post->file); + } + + $tmp[] = $post; + } + } + } + + 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('', $content); + if (isset($arr[1])) { + $title = str_replace('', $content); - if (isset($arr[1])) { - $title = str_replace('
    TitlePublishedTagOperations
    TitlePublishedViewsTagOperations
    title ?> date) ?>views ?> tag ?> Edit Delete