diff --git a/README.md b/README.md index 853421b..104191c 100644 --- a/README.md +++ b/README.md @@ -140,17 +140,25 @@ Here's the explanation (separated by an underscore): - `2014-01-31-12-56-40` is the published date. The date format is `yyyy-mm-dd-hh-mm-ss` - `tag1,tag2,tag3` is the tag, separated by comma - `databaseless-blogging-platform-flat-file-blog` is the URL - + For static pages, we use the following format: ```` -about.md +content/static/about.md ```` -That is means if `about` is the URL. +That means the URL is `about`. So if you write it offline then you must naming the .md file as above. +For static sub pages, we use the following format: + +```` +content/static/about/me.md +```` + +That means the URL is `about/me`. + Content Title ------------- If you write it offline, for the title of the post you need to add a title in the following format: diff --git a/system/admin/admin.php b/system/admin/admin.php index 6293791..47d469d 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1,550 +1,563 @@ 0 && $user_enc !== 'clear' && $user_enc !== 'none')?hash($user_enc,$pass):$pass; - - 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.
  • '; - } + $user_file = 'config/users/' . $user . '.ini'; + $user_enc = user('encryption', $user); + $user_pass = user('password', $user); + $password = (strlen($user_enc) > 0 && $user_enc !== 'clear' && $user_enc !== 'none') ? hash($user_enc, $pass) : $pass; + + 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"); + } +} + +// Add static sub page +function add_sub_page($title, $url, $content, $static) { + + $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/' . $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 ''; - 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
    '; - } - } + 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 ''; - 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 ''; - if(config("views.counter") == "true") echo ''; - echo ''; - echo ''; - } - echo '
    TitleViewsOperations
    ' . $p->title . '' . $p->views . 'Edit Delete
    '; - } - } + if (isset($_SESSION[config("site.url")]['user'])) { + $posts = get_static_post(null); + if (!empty($posts)) { + krsort($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 ''; + 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); - } + $b = str_replace('/', '#', site_path() . '/'); + $p = 'cache/page/' . $b . $url . '.cache'; + if (file_exists($p)) { + unlink($p); + } } diff --git a/system/admin/views/delete-page.html.php b/system/admin/views/delete-page.html.php index 99aafa8..3a25687 100644 --- a/system/admin/views/delete-page.html.php +++ b/system/admin/views/delete-page.html.php @@ -1,33 +1,30 @@ file; - - $dir = substr($url, 0, strrpos($url, '/')); - $oldurl = str_replace($dir . '/','',$url); - $oldmd = str_replace('.md','',$oldurl); - - $post = site_url() . $oldmd; - - if(isset($destination)) { - - if($destination == 'post') { - $back = $post; - } - else { - $back = site_url() . $destination; - } - } - else { - $back = site_url(); - } + if (isset($_GET['destination'])) { + $destination = $_GET['destination']; + } + $url = $p->file; + $dir = substr($url, 0, strrpos($url, '/')); + $oldurl = str_replace($dir . '/', '', $url); + $oldmd = str_replace('.md', '', $oldurl); + + $post = $p->url; + + if (isset($destination)) { + + if ($destination == 'post') { + $back = $post; + } else { + $back = site_url() . $destination; + } + } else { + $back = site_url(); + } ?> -Are you sure want to delete ' . $p->title . '?

    ';?> +

    Are you sure want to delete title; ?>?

    -
    - - - Cancel +
    + + + Cancel
    \ No newline at end of file diff --git a/system/admin/views/edit-page.html.php b/system/admin/views/edit-page.html.php index 58a0009..e5b500e 100644 --- a/system/admin/views/edit-page.html.php +++ b/system/admin/views/edit-page.html.php @@ -27,7 +27,7 @@ $oldurl = str_replace($dir . '/','',$url); $oldmd = str_replace('.md','',$oldurl); - $delete = site_url() . $oldmd . '/delete?destination=' . $destination; + $delete = $p->url . '/delete?destination=' . $destination; ?> diff --git a/system/htmly.php b/system/htmly.php index 0fd5586..062b18b 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -108,6 +108,133 @@ post('/login', function() { } }); +get("/:static/:sub/edit", function($static,$sub) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_static_post($static); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + $page = get_static_sub_post($static,$sub); + + if (!$page) { + not_found(); + } + + $page = $page[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' => $page, + 'type' => 'staticpage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); +post("/:static/:sub/edit", function($static,$sub) { + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + if(!login()) + { + $login = site_url() . 'login'; + header("location: $login"); + } + + $title = from($_REQUEST, 'title'); + $url = from($_REQUEST, 'url'); + $content = from($_REQUEST, 'content'); + $oldfile = from($_REQUEST, 'oldfile'); + $destination = from($_GET, 'destination'); + if($destination === null) + { + $destination = $static . "/" . $sub; + } + 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' + )); + } +}); + +get("/:static/:sub/delete", function($static,$sub) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_static_post($static); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + $page = get_static_sub_post($static,$sub); + + if (!$page) { + not_found(); + } + + $page = $page[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 . '' . $page->title, + 'p' => $page, + 'type' => 'staticpage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); +post("/:static/:sub/delete", function() { + + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + if ($proper && login()) { + $file = from($_REQUEST, 'file'); + $destination = from($_GET, 'destination'); + delete_page($file, $destination); + } +}); + // The blog post page get('/:year/:month/:name', function($year, $month, $name) { @@ -135,7 +262,6 @@ get('/:year/:month/:name', function($year, $month, $name) { } } - $bio = get_bio($current->author); if (isset($bio[0])) { @@ -296,7 +422,7 @@ get('/:year/:month/:name/delete', function($year, $month, $name) { post('/:year/:month/:name/delete', function() { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if ($proper) { + if ($proper && login()) { $file = from($_REQUEST, 'file'); $destination = from($_GET, 'destination'); delete_post($file, $destination); @@ -643,6 +769,12 @@ get('/:static/edit', function($static) { post('/:static/edit', function() { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + if(!login()) + { + $login = site_url() . 'login'; + header("location: $login"); + } + $title = from($_REQUEST, 'title'); $url = from($_REQUEST, 'url'); $content = from($_REQUEST, 'content'); @@ -712,7 +844,7 @@ get('/:static/delete', function($static) { post('/:static/delete', function() { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if ($proper) { + if ($proper && login()) { $file = from($_REQUEST, 'file'); $destination = from($_GET, 'destination'); delete_page($file, $destination); @@ -808,7 +940,7 @@ post('/add/page', function() { $title = from($_REQUEST, 'title'); $url = from($_REQUEST, 'url'); $content = from($_REQUEST, 'content'); - if ($proper && !empty($title) && !empty($content)) { + if ($proper && !empty($title) && !empty($content) && login()) { if (!empty($url)) { add_page($title, $url, $content); } else { @@ -1099,6 +1231,99 @@ get('/admin/update/now/:csrf', function($CSRF) { } }); +get('/:static/add', function($static) { + + if (login()) { + + config('views.root', 'system/admin/views'); + + $post = get_static_post($static); + + if(! $post) + { + not_found(); + } + + $post = $post[0]; + + render('add-page', array( + 'head_contents' => head_contents('Add page - ' . blog_title(), blog_description(), site_url()), + 'bodyclass' => 'addpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' Add page' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); +post('/:static/add', function($static) { + + $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) && login()) { + if (!empty($url)) { + add_sub_page($title, $url, $content, $static); + } else { + $url = $title; + add_sub_page($title, $url, $content, $static); + } + } 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') . ' » ' . $post->title . ' Add page' + )); + } +}); + +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") + { + 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') . ' » ' . $father_post[0]->title . ' » ' . $post->title, + 'p' => $post, + 'type' => 'staticpage', + )); +}); + // If we get here, it means that // nothing has been matched above diff --git a/system/includes/functions.php b/system/includes/functions.php index 716c6e6..7672f1e 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'); } } @@ -472,6 +505,53 @@ function get_static_post($static) { 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('