diff --git a/config/config.ini.example b/config/config.ini.example index 14c5980..d188df4 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -59,6 +59,7 @@ google.reCaptcha.private = "" ; Pagination, RSS, and JSON posts.perpage = "10" +category.perpage = "10" tag.perpage = "10" archive.perpage = "10" search.perpage = "10" diff --git a/system/admin/admin.php b/system/admin/admin.php index 285a6f3..d91f61b 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -86,7 +86,7 @@ function remove_accent($str) } // Edit blog posts -function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $revertPost, $publishDraft) +function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $revertPost, $publishDraft, $category) { $oldurl = explode('_', $oldfile); $dir = explode('/', $oldurl[0]); @@ -97,8 +97,9 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, } $post_title = safe_html($title); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -123,10 +124,10 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, if(!empty($revertPost) || !empty($publishDraft)) { - $dirBlog = $dir[0] . '/' . $dir[1] . '/blog/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/draft/'; + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/post/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[2] == 'draft') { + if($dir[4] == 'draft') { $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; @@ -148,13 +149,39 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, } else { - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - - if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + if ($dir[3] === $category) { + $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)); + } } else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/post/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; + + if($dir[4] == 'draft') { + $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } + + if (is_dir($dirBlog)) { + } else { + mkdir($dirBlog, 0775, true); + } + + if (is_dir($dirDraft)) { + } else { + mkdir($dirDraft, 0775, true); + } + + file_put_contents($filename, print_r($post_content, true)); + unlink($oldfile); + $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } @@ -208,7 +235,7 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, } // Edit image posts -function edit_image($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $image, $revertPost, $publishDraft) +function edit_image($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $image, $revertPost, $publishDraft, $category) { $oldurl = explode('_', $oldfile); $dir = explode('/', $oldurl[0]); @@ -220,8 +247,9 @@ function edit_image($title, $tag, $url, $content, $oldfile, $destination = null, $post_title = safe_html($title); $post_image = preg_replace('/\s\s+/', ' ', strip_tags($image)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -251,10 +279,10 @@ function edit_image($title, $tag, $url, $content, $oldfile, $destination = null, if(!empty($revertPost) || !empty($publishDraft)) { - $dirBlog = $dir[0] . '/' . $dir[1] . '/blog/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/draft/'; + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/image/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[2] == 'draft') { + if($dir[4] == 'draft') { $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; @@ -276,13 +304,39 @@ function edit_image($title, $tag, $url, $content, $oldfile, $destination = null, } else { - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - - if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + if ($dir[3] === $category) { + $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)); + } } else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/image/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; + + if($dir[4] == 'draft') { + $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } + + if (is_dir($dirBlog)) { + } else { + mkdir($dirBlog, 0775, true); + } + + if (is_dir($dirDraft)) { + } else { + mkdir($dirDraft, 0775, true); + } + + file_put_contents($filename, print_r($post_content, true)); + unlink($oldfile); + $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } @@ -336,7 +390,7 @@ function edit_image($title, $tag, $url, $content, $oldfile, $destination = null, } // Edit video posts -function edit_video($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $video, $revertPost, $publishDraft) +function edit_video($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $video, $revertPost, $publishDraft, $category) { $oldurl = explode('_', $oldfile); $dir = explode('/', $oldurl[0]); @@ -348,8 +402,9 @@ function edit_video($title, $tag, $url, $content, $oldfile, $destination = null, $post_title = safe_html($title); $post_video = preg_replace('/\s\s+/', ' ', strip_tags($video)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -379,10 +434,10 @@ function edit_video($title, $tag, $url, $content, $oldfile, $destination = null, if(!empty($revertPost) || !empty($publishDraft)) { - $dirBlog = $dir[0] . '/' . $dir[1] . '/blog/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/draft/'; + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/video/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[2] == 'draft') { + if($dir[4] == 'draft') { $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; @@ -404,13 +459,39 @@ function edit_video($title, $tag, $url, $content, $oldfile, $destination = null, } else { - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - - if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + if ($dir[3] === $category) { + $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)); + } } else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/video/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; + + if($dir[4] == 'draft') { + $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } + + if (is_dir($dirBlog)) { + } else { + mkdir($dirBlog, 0775, true); + } + + if (is_dir($dirDraft)) { + } else { + mkdir($dirDraft, 0775, true); + } + + file_put_contents($filename, print_r($post_content, true)); + unlink($oldfile); + $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } @@ -464,7 +545,7 @@ function edit_video($title, $tag, $url, $content, $oldfile, $destination = null, } // Edit image posts -function edit_link($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $link, $revertPost, $publishDraft) +function edit_link($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $link, $revertPost, $publishDraft, $category) { $oldurl = explode('_', $oldfile); $dir = explode('/', $oldurl[0]); @@ -476,8 +557,9 @@ function edit_link($title, $tag, $url, $content, $oldfile, $destination = null, $post_title = safe_html($title); $post_link = preg_replace('/\s\s+/', ' ', strip_tags($link)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -507,10 +589,10 @@ function edit_link($title, $tag, $url, $content, $oldfile, $destination = null, if(!empty($revertPost) || !empty($publishDraft)) { - $dirBlog = $dir[0] . '/' . $dir[1] . '/blog/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/draft/'; + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/link/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[2] == 'draft') { + if($dir[4] == 'draft') { $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; @@ -532,13 +614,39 @@ function edit_link($title, $tag, $url, $content, $oldfile, $destination = null, } else { - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - - if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + if ($dir[3] === $category) { + $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)); + } } else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/link/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; + + if($dir[4] == 'draft') { + $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } + + if (is_dir($dirBlog)) { + } else { + mkdir($dirBlog, 0775, true); + } + + if (is_dir($dirDraft)) { + } else { + mkdir($dirDraft, 0775, true); + } + + file_put_contents($filename, print_r($post_content, true)); + unlink($oldfile); + $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } @@ -592,7 +700,7 @@ function edit_link($title, $tag, $url, $content, $oldfile, $destination = null, } // Edit quote posts -function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $quote, $revertPost, $publishDraft) +function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $quote, $revertPost, $publishDraft, $category) { $oldurl = explode('_', $oldfile); $dir = explode('/', $oldurl[0]); @@ -604,8 +712,9 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null, $post_title = safe_html($title); $post_quote = preg_replace('/\s\s+/', ' ', strip_tags($quote)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -635,10 +744,10 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null, if(!empty($revertPost) || !empty($publishDraft)) { - $dirBlog = $dir[0] . '/' . $dir[1] . '/blog/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/draft/'; + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/quote/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[2] == 'draft') { + if($dir[4] == 'draft') { $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; @@ -660,17 +769,44 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null, } else { - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - - if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + if ($dir[3] === $category) { + $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)); + } } else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/quote/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; + + if($dir[4] == 'draft') { + $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } + + if (is_dir($dirBlog)) { + } else { + mkdir($dirBlog, 0775, true); + } + + if (is_dir($dirDraft)) { + } else { + mkdir($dirDraft, 0775, true); + } + + file_put_contents($filename, print_r($post_content, true)); + unlink($oldfile); + $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } + if(!empty($publishDraft)) { $dt = $olddate; $t = str_replace('-', '', $dt); @@ -720,7 +856,7 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null, } // Edit audio posts -function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $audio, $revertPost, $publishDraft) +function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $audio, $revertPost, $publishDraft, $category) { $oldurl = explode('_', $oldfile); $dir = explode('/', $oldurl[0]); @@ -732,8 +868,9 @@ function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null, $post_title = safe_html($title); $post_audio = preg_replace('/\s\s+/', ' ', strip_tags($audio)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -763,10 +900,10 @@ function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null, if(!empty($revertPost) || !empty($publishDraft)) { - $dirBlog = $dir[0] . '/' . $dir[1] . '/blog/'; - $dirDraft = $dir[0] . '/' . $dir[1] . '/draft/'; + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/audio/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; - if($dir[2] == 'draft') { + if($dir[4] == 'draft') { $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; } else { $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; @@ -788,13 +925,39 @@ function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null, } else { - $newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md'; - - if ($oldfile === $newfile) { - file_put_contents($oldfile, print_r($post_content, true)); + if ($dir[3] === $category) { + $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)); + } } else { - rename($oldfile, $newfile); - file_put_contents($newfile, print_r($post_content, true)); + + $dirBlog = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/audio/'; + $dirDraft = $dir[0] . '/' . $dir[1] . '/' . $dir[2] . '/' . $category . '/draft/'; + + if($dir[4] == 'draft') { + $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } else { + $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } + + if (is_dir($dirBlog)) { + } else { + mkdir($dirBlog, 0775, true); + } + + if (is_dir($dirDraft)) { + } else { + mkdir($dirDraft, 0775, true); + } + + file_put_contents($filename, print_r($post_content, true)); + unlink($oldfile); + $newfile = $olddate . '_' . $post_tag . '_' . $post_url . '.md'; + } } @@ -891,14 +1054,54 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr } } +// Edit static page +function edit_category($title, $url, $content, $oldfile, $destination = null, $description = null) +{ + $dir = substr($oldfile, 0, strrpos($oldfile, '/')); + + $post_title = safe_html($title); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $description = safe_html($description); + if ($description !== null) { + $post_description = "\n"; + } else { + $post_description = ''; + } + $post_content = '' . $post_description . "\n\n" . $content; + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + + if (get_magic_quotes_gpc()) { + $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)); + } + + rename_category_folder($post_url, $oldfile); + + rebuilt_cache('all'); + if ($destination == 'post') { + header("Location: $posturl"); + } else { + $redirect = site_url() . $destination; + header("Location: $redirect"); + } + } +} + // Add post -function add_post($title, $tag, $url, $content, $user, $description = null, $draft) +function add_post($title, $tag, $url, $content, $user, $description = null, $draft, $category) { $post_date = date('Y-m-d-H-i-s'); $post_title = safe_html($title); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -924,9 +1127,9 @@ function add_post($title, $tag, $url, $content, $user, $description = null, $dra $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; if (empty($draft)) { - $dir = 'content/' . $user . '/blog/'; + $dir = 'content/' . $user . '/blog/' . $category. '/post/'; } else { - $dir = 'content/' . $user . '/draft/'; + $dir = 'content/' . $user . '/blog/' . $category. '/draft/'; } if (is_dir($dir)) { @@ -952,14 +1155,15 @@ function add_post($title, $tag, $url, $content, $user, $description = null, $dra } // Add image -function add_image($title, $tag, $url, $content, $user, $description = null, $image, $draft) +function add_image($title, $tag, $url, $content, $user, $description = null, $image, $draft, $category) { $post_date = date('Y-m-d-H-i-s'); $post_title = safe_html($title); $post_image = preg_replace('/\s\s+/', ' ', strip_tags($image)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -990,9 +1194,9 @@ function add_image($title, $tag, $url, $content, $user, $description = null, $im $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; if (empty($draft)) { - $dir = 'content/' . $user . '/blog/'; + $dir = 'content/' . $user . '/blog/' . $category. '/image/'; } else { - $dir = 'content/' . $user . '/draft/'; + $dir = 'content/' . $user . '/blog/' . $category. '/draft/'; } if (is_dir($dir)) { @@ -1018,14 +1222,15 @@ function add_image($title, $tag, $url, $content, $user, $description = null, $im } // Add video -function add_video($title, $tag, $url, $content, $user, $description = null, $video, $draft) +function add_video($title, $tag, $url, $content, $user, $description = null, $video, $draft, $category) { $post_date = date('Y-m-d-H-i-s'); $post_title = safe_html($title); $post_video = preg_replace('/\s\s+/', ' ', strip_tags($video)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -1056,9 +1261,9 @@ function add_video($title, $tag, $url, $content, $user, $description = null, $vi $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; if (empty($draft)) { - $dir = 'content/' . $user . '/blog/'; + $dir = 'content/' . $user . '/blog/' . $category. '/video/'; } else { - $dir = 'content/' . $user . '/draft/'; + $dir = 'content/' . $user . '/blog/' . $category. '/draft/'; } if (is_dir($dir)) { @@ -1084,14 +1289,15 @@ function add_video($title, $tag, $url, $content, $user, $description = null, $vi } // Add audio -function add_audio($title, $tag, $url, $content, $user, $description = null, $audio, $draft) +function add_audio($title, $tag, $url, $content, $user, $description = null, $audio, $draft, $category) { $post_date = date('Y-m-d-H-i-s'); $post_title = safe_html($title); $post_audio = preg_replace('/\s\s+/', ' ', strip_tags($audio)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -1122,9 +1328,9 @@ function add_audio($title, $tag, $url, $content, $user, $description = null, $au $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; if (empty($draft)) { - $dir = 'content/' . $user . '/blog/'; + $dir = 'content/' . $user . '/blog/' . $category. '/audio/'; } else { - $dir = 'content/' . $user . '/draft/'; + $dir = 'content/' . $user . '/blog/' . $category. '/draft/'; } if (is_dir($dir)) { @@ -1150,14 +1356,15 @@ function add_audio($title, $tag, $url, $content, $user, $description = null, $au } // Add link -function add_link($title, $tag, $url, $content, $user, $description = null, $link, $draft) +function add_link($title, $tag, $url, $content, $user, $description = null, $link, $draft, $category) { $post_date = date('Y-m-d-H-i-s'); $post_title = safe_html($title); $post_link = preg_replace('/\s\s+/', ' ', strip_tags($link)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -1188,9 +1395,9 @@ function add_link($title, $tag, $url, $content, $user, $description = null, $lin $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; if (empty($draft)) { - $dir = 'content/' . $user . '/blog/'; + $dir = 'content/' . $user . '/blog/' . $category. '/link/'; } else { - $dir = 'content/' . $user . '/draft/'; + $dir = 'content/' . $user . '/blog/' . $category. '/draft/'; } if (is_dir($dir)) { @@ -1216,14 +1423,15 @@ function add_link($title, $tag, $url, $content, $user, $description = null, $lin } // Add quote -function add_quote($title, $tag, $url, $content, $user, $description = null, $quote, $draft) +function add_quote($title, $tag, $url, $content, $user, $description = null, $quote, $draft, $category) { $post_date = date('Y-m-d-H-i-s'); $post_title = safe_html($title); $post_quote = preg_replace('/\s\s+/', ' ', strip_tags($quote)); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tag); + $pt = safe_tag($tag); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -1254,9 +1462,9 @@ function add_quote($title, $tag, $url, $content, $user, $description = null, $qu $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; if (empty($draft)) { - $dir = 'content/' . $user . '/blog/'; + $dir = 'content/' . $user . '/blog/' . $category. '/quote/'; } else { - $dir = 'content/' . $user . '/draft/'; + $dir = 'content/' . $user . '/blog/' . $category. '/draft/'; } if (is_dir($dir)) { @@ -1349,6 +1557,40 @@ function add_sub_page($title, $url, $content, $static, $description = null) } } +// Add static page +function add_category($title, $url, $content, $description = null) +{ + + $post_title = safe_html($title); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); + $description = safe_html($description); + if ($description !== null) { + $post_description = "\n"; + } else { + $post_description = ""; + } + $post_content = '' . $post_description . "\n\n" . $content; + + if (!empty($post_title) && !empty($post_url) && !empty($post_content)) { + if (get_magic_quotes_gpc()) { + $post_content = stripslashes($post_content); + } + $filename = $post_url . '.md'; + $dir = 'content/data/category/'; + if (is_dir($dir)) { + file_put_contents($dir . $filename, print_r($post_content, true)); + } else { + mkdir($dir, 0775, true); + file_put_contents($dir . $filename, print_r($post_content, true)); + } + + rebuilt_cache('all'); + clear_page_cache($post_url); + $redirect = site_url() . 'admin/categories'; + header("Location: $redirect"); + } +} + // Delete blog post function delete_post($file, $destination) { @@ -1434,8 +1676,9 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) { $post_date = date('Y-m-d-H-i-s', $time); $post_title = safe_html($title); - $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags))); - $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), $tags); + $pt = safe_tag($tags); + $post_tag = strtolower(preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($pt))); + $post_tagmd = preg_replace(array('/[^a-zA-Z0-9,. \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', ' ', ''), $pt); $post_tag = rtrim($post_tag, ','); $post_tagmd = rtrim($post_tagmd, ','); $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); @@ -1449,7 +1692,7 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) $post_content = stripslashes($post_content); } $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; - $dir = 'content/' . $user . '/blog/'; + $dir = 'content/' . $user . '/blog/uncategorized/post/'; if (is_dir($dir)) { file_put_contents($dir . $filename, print_r($post_content, true)); } else { diff --git a/system/admin/views/add-audio.html.php b/system/admin/views/add-audio.html.php index 321e32d..aaecfdf 100644 --- a/system/admin/views/add-audio.html.php +++ b/system/admin/views/add-audio.html.php @@ -9,6 +9,9 @@
+
Title *


+ Category *
+ +

Tag *
+ + + + + + + + +
+ +
+ + Title *


+ Url (optional)

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

+ Meta Description (optional)
+

+ +
+
+ + + +
+
+

URL

+ +

Upload

+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/system/admin/views/add-image.html.php b/system/admin/views/add-image.html.php index 3eb850e..55e4f64 100644 --- a/system/admin/views/add-image.html.php +++ b/system/admin/views/add-image.html.php @@ -9,6 +9,9 @@
+
Title *


+ Category *
+ +

Tag *
+
Title *


+ Category *
+ +

Tag *
+
Title *


+ Category *
+ +

Tag *
+
Title *


+ Category *
+ +

Tag *
+
Title *


+ Category *
+ +

Tag *
add/category">Add category + + + + + + + + + + + + + + + +
NameDescriptionContentsOperations
title;?>body;?>md) + get_categorycount($d->md); echo $total?>Edit md) == 0 && get_draftcount($d->md) == 0 ){echo 'Delete';}?>
\ No newline at end of file diff --git a/system/admin/views/delete-category.html.php b/system/admin/views/delete-category.html.php new file mode 100644 index 0000000..6e0d237 --- /dev/null +++ b/system/admin/views/delete-category.html.php @@ -0,0 +1,30 @@ +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 title; ?>?

+ +
+ + + Cancel + \ No newline at end of file diff --git a/system/admin/views/edit-audio.html.php b/system/admin/views/edit-audio.html.php index bdc2383..5fb00db 100644 --- a/system/admin/views/edit-audio.html.php +++ b/system/admin/views/edit-audio.html.php @@ -5,6 +5,8 @@ if (isset($p->file)) { $url = $oldfile; } +$desc = get_category_info(null); + $content = file_get_contents($url); $oldtitle = get_content_tag('t', $content, 'Untitled'); $olddescription = get_content_tag('d', $content); @@ -28,6 +30,11 @@ if (isset($_GET['destination'])) { $destination = 'admin'; } $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + +// Category string +$cat = explode('/', $replaced); +$category = $cat[count($cat) - 3]; + $dt = str_replace($replaced, '', $oldurl[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); @@ -61,6 +68,14 @@ if (config('permalink.type') == 'post') { echo 'error'; } } ?>" value=""/>

+ Category *
+ +

Tag *
- + Delete Delete diff --git a/system/admin/views/edit-category.html.php b/system/admin/views/edit-category.html.php new file mode 100644 index 0000000..8bac6cd --- /dev/null +++ b/system/admin/views/edit-category.html.php @@ -0,0 +1,86 @@ +file)) { + $url = $p->file; +} else { + $url = $oldfile; +} +$content = file_get_contents($url); +$oldtitle = get_content_tag('t', $content, 'Untitled'); +$olddescription = get_content_tag('d', $content); +$oldcontent = remove_html_comments($content); + +if (isset($_GET['destination'])) { + $destination = $_GET['destination']; +} else { + $destination = 'admin'; +} +$dir = substr($url, 0, strrpos($url, '/')); +$oldurl = str_replace($dir . '/', '', $url); +$oldmd = str_replace('.md', '', $oldurl); + +if (isset($p->url)) { + $delete = $p->url . '/delete?destination=' . $destination; +} +else { + if(empty($sub)) { + $delete = site_url() . $oldmd . '/delete?destination=' . $destination; + } + else { + $delete = site_url() . $static .'/'. $sub . '/delete?destination=' . $destination; + } +} + +?> + + + + + + + + + +
+ +
+
+ Title *


+ Url (optional)

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

+ Meta Description (optional)
+

+
+
+ + + +
+
+
+

URL

+ +

Upload

+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/system/admin/views/edit-image.html.php b/system/admin/views/edit-image.html.php index 35f60cc..d1be870 100644 --- a/system/admin/views/edit-image.html.php +++ b/system/admin/views/edit-image.html.php @@ -5,6 +5,8 @@ if (isset($p->file)) { $url = $oldfile; } +$desc = get_category_info(null); + $content = file_get_contents($url); $oldtitle = get_content_tag('t', $content, 'Untitled'); $olddescription = get_content_tag('d', $content); @@ -28,6 +30,11 @@ if (isset($_GET['destination'])) { $destination = 'admin'; } $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + +// Category string +$cat = explode('/', $replaced); +$category = $cat[count($cat) - 3]; + $dt = str_replace($replaced, '', $oldurl[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); @@ -61,6 +68,14 @@ if (config('permalink.type') == 'post') { echo 'error'; } } ?>" value=""/>

+ Category *
+ +

Tag *
- + Delete Delete diff --git a/system/admin/views/edit-link.html.php b/system/admin/views/edit-link.html.php index 88a3d43..5322942 100644 --- a/system/admin/views/edit-link.html.php +++ b/system/admin/views/edit-link.html.php @@ -5,6 +5,8 @@ if (isset($p->file)) { $url = $oldfile; } +$desc = get_category_info(null); + $content = file_get_contents($url); $oldtitle = get_content_tag('t', $content, 'Untitled'); $olddescription = get_content_tag('d', $content); @@ -28,6 +30,11 @@ if (isset($_GET['destination'])) { $destination = 'admin'; } $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + +// Category string +$cat = explode('/', $replaced); +$category = $cat[count($cat) - 3]; + $dt = str_replace($replaced, '', $oldurl[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); @@ -62,6 +69,14 @@ if (config('permalink.type') == 'post') { echo 'error'; } } ?>" value=""/>

+ Category *
+ +

Tag *
- + Delete Delete diff --git a/system/admin/views/edit-post.html.php b/system/admin/views/edit-post.html.php index 94bd5d9..ca415d2 100644 --- a/system/admin/views/edit-post.html.php +++ b/system/admin/views/edit-post.html.php @@ -5,6 +5,8 @@ if (isset($p->file)) { $url = $oldfile; } +$desc = get_category_info(null); + $content = file_get_contents($url); $oldtitle = get_content_tag('t', $content, 'Untitled'); $olddescription = get_content_tag('d', $content); @@ -27,6 +29,11 @@ if (isset($_GET['destination'])) { $destination = 'admin'; } $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + +// Category string +$cat = explode('/', $replaced); +$category = $cat[count($cat) - 3]; + $dt = str_replace($replaced, '', $oldurl[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); @@ -61,6 +68,14 @@ if (config('permalink.type') == 'post') { echo 'error'; } } ?>" value=""/>

+ Category *
+ +

Tag *
- + Delete Delete diff --git a/system/admin/views/edit-quote.html.php b/system/admin/views/edit-quote.html.php index 568def0..06ced01 100644 --- a/system/admin/views/edit-quote.html.php +++ b/system/admin/views/edit-quote.html.php @@ -5,6 +5,8 @@ if (isset($p->file)) { $url = $oldfile; } +$desc = get_category_info(null); + $content = file_get_contents($url); $oldtitle = get_content_tag('t', $content, 'Untitled'); $olddescription = get_content_tag('d', $content); @@ -28,6 +30,11 @@ if (isset($_GET['destination'])) { $destination = 'admin'; } $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + +// Category string +$cat = explode('/', $replaced); +$category = $cat[count($cat) - 3]; + $dt = str_replace($replaced, '', $oldurl[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); @@ -62,6 +69,14 @@ if (config('permalink.type') == 'post') { echo 'error'; } } ?>" value=""/>

+ Category *
+ +

Tag *
- + Delete Delete diff --git a/system/admin/views/edit-video.html.php b/system/admin/views/edit-video.html.php index 9604810..80664da 100644 --- a/system/admin/views/edit-video.html.php +++ b/system/admin/views/edit-video.html.php @@ -5,6 +5,8 @@ if (isset($p->file)) { $url = $oldfile; } +$desc = get_category_info(null); + $content = file_get_contents($url); $oldtitle = get_content_tag('t', $content, 'Untitled'); $olddescription = get_content_tag('d', $content); @@ -29,6 +31,11 @@ if (isset($_GET['destination'])) { $destination = 'admin'; } $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; + +// Category string +$cat = explode('/', $replaced); +$category = $cat[count($cat) - 3]; + $dt = str_replace($replaced, '', $oldurl[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); @@ -63,6 +70,14 @@ if (config('permalink.type') == 'post') { echo 'error'; } } ?>" value=""/>

+ Category *
+ +

Tag *
- + Delete Delete diff --git a/system/htmly.php b/system/htmly.php index 30e52e2..dedf411 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -257,12 +257,13 @@ post('/add/post', function () { $description = from($_REQUEST, 'description'); $user = $_SESSION[config("site.url")]['user']; $draft = from($_REQUEST, 'draft'); + $category = from($_REQUEST, 'category'); if ($proper && !empty($title) && !empty($tag) && !empty($content)) { if (!empty($url)) { - add_post($title, $tag, $url, $content, $user, $description, $draft); + add_post($title, $tag, $url, $content, $user, $description, $draft, $category); } else { $url = $title; - add_post($title, $tag, $url, $content, $user, $description, $draft); + add_post($title, $tag, $url, $content, $user, $description, $draft, $category); } } else { $message['error'] = ''; @@ -327,12 +328,13 @@ post('/add/image', function () { $description = from($_REQUEST, 'description'); $user = $_SESSION[config("site.url")]['user']; $draft = from($_REQUEST, 'draft'); + $category = from($_REQUEST, 'category'); if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) { if (!empty($url)) { - add_image($title, $tag, $url, $content, $user, $description, $image, $draft); + add_image($title, $tag, $url, $content, $user, $description, $image, $draft, $category); } else { $url = $title; - add_image($title, $tag, $url, $content, $user, $description, $image, $draft); + add_image($title, $tag, $url, $content, $user, $description, $image, $draft, $category); } } else { $message['error'] = ''; @@ -401,12 +403,13 @@ post('/add/video', function () { $description = from($_REQUEST, 'description'); $user = $_SESSION[config("site.url")]['user']; $draft = from($_REQUEST, 'draft'); + $category = from($_REQUEST, 'category'); if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if (!empty($url)) { - add_video($title, $tag, $url, $content, $user, $description, $video, $draft); + add_video($title, $tag, $url, $content, $user, $description, $video, $draft, $category); } else { $url = $title; - add_video($title, $tag, $url, $content, $user, $description, $video, $draft); + add_video($title, $tag, $url, $content, $user, $description, $video, $draft, $category); } } else { $message['error'] = ''; @@ -477,10 +480,10 @@ post('/add/link', function () { $draft = from($_REQUEST, 'draft'); if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if (!empty($url)) { - add_link($title, $tag, $url, $content, $user, $description, $link, $draft); + add_link($title, $tag, $url, $content, $user, $description, $link, $draft, $category); } else { $url = $title; - add_link($title, $tag, $url, $content, $user, $description, $link, $draft); + add_link($title, $tag, $url, $content, $user, $description, $link, $draft, $category); } } else { $message['error'] = ''; @@ -549,12 +552,13 @@ post('/add/quote', function () { $description = from($_REQUEST, 'description'); $user = $_SESSION[config("site.url")]['user']; $draft = from($_REQUEST, 'draft'); + $category = from($_REQUEST, 'category'); if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if (!empty($url)) { - add_quote($title, $tag, $url, $content, $user, $description, $quote, $draft); + add_quote($title, $tag, $url, $content, $user, $description, $quote, $draft, $category); } else { $url = $title; - add_quote($title, $tag, $url, $content, $user, $description, $quote, $draft); + add_quote($title, $tag, $url, $content, $user, $description, $quote, $draft, $category); } } else { $message['error'] = ''; @@ -623,12 +627,13 @@ post('/add/audio', function () { $description = from($_REQUEST, 'description'); $user = $_SESSION[config("site.url")]['user']; $draft = from($_REQUEST, 'draft'); + $category = from($_REQUEST, 'category'); if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if (!empty($url)) { - add_audio($title, $tag, $url, $content, $user, $description, $audio, $draft); + add_audio($title, $tag, $url, $content, $user, $description, $audio, $draft, $category); } else { $url = $title; - add_audio($title, $tag, $url, $content, $user, $description, $audio, $draft); + add_audio($title, $tag, $url, $content, $user, $description, $audio, $draft, $category); } } else { $message['error'] = ''; @@ -726,6 +731,68 @@ post('/add/page', function () { } }); +// Show the add category +get('/add/category', function () { + + if (login()) { + + config('views.root', 'system/admin/views'); + + render('add-category', array( + 'title' => 'Add page - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'addpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); + +// Submitted add category +post('/add/category', function () { + + $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); + + $title = from($_REQUEST, 'title'); + $url = from($_REQUEST, 'url'); + $content = from($_REQUEST, 'content'); + $description = from($_REQUEST, 'description'); + if ($proper && !empty($title) && !empty($content) && login()) { + if (!empty($url)) { + add_category($title, $url, $content, $description); + } else { + $url = $title; + add_category($title, $url, $content, $description); + } + } 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-category', array( + 'title' => 'Add page - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'error' => '', + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'addpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page' + )); + } +}); + // Show admin/posts get('/admin/posts', function () { @@ -1207,6 +1274,183 @@ get('/admin/update/now/:csrf', function ($CSRF) { } }); +// Show category page +get('/admin/categories', function () { + if (login()) { + config('views.root', 'system/admin/views'); + render('categories', array( + 'title' => 'Categories - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'categoriespage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Categories' + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } + die; +}); + +// Show the category page +get('/category/:category', function ($category) { + + if (!login()) { + file_cache($_SERVER['REQUEST_URI']); + } + + $page = from($_GET, 'page'); + $page = $page ? (int)$page : 1; + $perpage = config('category.perpage'); + + $posts = get_category($category, $page, $perpage); + + $desc = get_category_info($category); + + if(strtolower($category) !== 'uncategorized') { + $desc = $desc[0]; + } + + $total = get_categorycount($category); + + if (empty($posts) || $page < 1) { + // a non-existing page + not_found(); + } + render('main', array( + 'title' => $desc->title . ' - ' . blog_title(), + 'description' => $desc->description, + 'canonical' => $desc->url, + 'page' => $page, + 'posts' => $posts, + 'category' => $desc, + 'bodyclass' => 'incategory', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $desc->title, + 'pagination' => has_pagination($total, $perpage, $page), + 'is_category' => is_category(true), + )); +}); + +// Show edit the category page +get('/category/:category/edit', function ($category) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_category_info($category); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + render('edit-category', array( + 'title' => 'Edit category - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'editpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title, + 'p' => $post, + 'type' => 'categoryPage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); + +// Get edited data from category page +post('/category/:category/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'); + $oldfile = from($_REQUEST, 'oldfile'); + $destination = from($_GET, 'destination'); + $description = from($_REQUEST, 'description'); + if ($proper && !empty($title) && !empty($content)) { + if (!empty($url)) { + edit_category($title, $url, $content, $oldfile, $destination, $description); + } else { + $url = $title; + edit_category($title, $url, $content, $oldfile, $destination, $description); + } + } 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-category', array( + 'title' => 'Edit category - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'error' => '', + 'oldfile' => $oldfile, + 'postTitle' => $title, + 'postUrl' => $url, + 'postContent' => $content, + 'bodyclass' => 'editcategory', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit category' + )); + } +}); + +// Delete category +get('/category/:category/delete', function ($category) { + + if (login()) { + + config('views.root', 'system/admin/views'); + $post = get_category_info($category); + + if (!$post) { + not_found(); + } + + $post = $post[0]; + + render('delete-category', array( + 'title' => 'Delete category - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'editpage', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title, + 'p' => $post, + 'type' => 'categoryPage', + )); + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); + +// Get deleted category data +post('/category/:category/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); + } +}); + // Show the tag page get('/tag/:tag', function ($tag) { @@ -1437,7 +1681,7 @@ get('/post/:name', function ($name) { 'p' => $current, 'author' => $author, 'bodyclass' => 'inpost', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » '. $blog . $current->tagb . ' » ' . $current->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » '. $blog . $current->category . ' » ' . $current->title, 'prev' => has_prev($prev), 'next' => has_next($next), 'type' => $var, @@ -1533,6 +1777,7 @@ post('/post/:name/edit', function () { $dateTime = null; $revertPost = from($_REQUEST, 'revertpost'); $publishDraft = from($_REQUEST, 'publishdraft'); + $category = from($_REQUEST, 'category'); if ($date !== null && $time !== null) { $dateTime = $date . ' ' . $time; } @@ -1555,37 +1800,37 @@ post('/post/:name/edit', function () { if (empty($url)) { $url = $title; } - edit_image($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $image, $revertPost, $publishDraft); + edit_image($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $image, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if (empty($url)) { $url = $title; } - edit_video($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $video, $revertPost, $publishDraft); + edit_video($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $video, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if (empty($url)) { $url = $title; } - edit_link($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $link, $revertPost, $publishDraft); + edit_link($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $link, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if (empty($url)) { $url = $title; } - edit_quote($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $quote, $revertPost, $publishDraft); + edit_quote($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $quote, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if (empty($url)) { $url = $title; } - edit_audio($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $audio, $revertPost, $publishDraft); + edit_audio($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $audio, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) { if (empty($url)) { $url = $title; } - edit_post($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $revertPost, $publishDraft); + edit_post($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $revertPost, $publishDraft, $category); } else { $message['error'] = ''; @@ -2291,7 +2536,7 @@ get('/:year/:month/:name', function ($year, $month, $name) { 'p' => $current, 'author' => $author, 'bodyclass' => 'inpost', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » '. $blog . $current->tagb . ' » ' . $current->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » '. $blog . $current->category . ' » ' . $current->title, 'prev' => has_prev($prev), 'next' => has_next($next), 'type' => $var, @@ -2387,6 +2632,7 @@ post('/:year/:month/:name/edit', function () { $dateTime = null; $revertPost = from($_REQUEST, 'revertpost'); $publishDraft = from($_REQUEST, 'publishdraft'); + $category = from($_REQUEST, 'category'); if ($date !== null && $time !== null) { $dateTime = $date . ' ' . $time; } @@ -2409,37 +2655,37 @@ post('/:year/:month/:name/edit', function () { if (empty($url)) { $url = $title; } - edit_image($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $image, $revertPost, $publishDraft); + edit_image($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $image, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if (empty($url)) { $url = $title; } - edit_video($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $video, $revertPost, $publishDraft); + edit_video($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $video, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if (empty($url)) { $url = $title; } - edit_link($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $link, $revertPost, $publishDraft); + edit_link($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $link, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if (empty($url)) { $url = $title; } - edit_quote($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $quote, $revertPost, $publishDraft); + edit_quote($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $quote, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if (empty($url)) { $url = $title; } - edit_audio($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $audio, $revertPost, $publishDraft); + edit_audio($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $audio, $revertPost, $publishDraft, $category); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) { if (empty($url)) { $url = $title; } - edit_post($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $revertPost, $publishDraft); + edit_post($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $revertPost, $publishDraft, $category); } else { $message['error'] = ''; diff --git a/system/includes/functions.php b/system/includes/functions.php index 928f4d4..75edfe0 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -114,7 +114,7 @@ function get_draft_posts() static $_draft = array(); if (empty($_draft)) { $tmp = array(); - $tmp = glob('content/*/draft/*.md', GLOB_NOSORT); + $tmp = glob('content/*/*/*/draft/*.md', GLOB_NOSORT); if (is_array($tmp)) { foreach ($tmp as $file) { $_draft[] = pathinfo($file); @@ -125,6 +125,38 @@ function get_draft_posts() return $_draft; } +// Get user draft. +function get_category_files() +{ + static $_desc = array(); + if (empty($_desc)) { + $tmp = array(); + $tmp = glob('content/data/category/*.md', GLOB_NOSORT); + if (is_array($tmp)) { + foreach ($tmp as $file) { + $_desc[] = $file; + } + } + } + return $_desc; +} + +// Get user draft. +function get_category_folder() +{ + static $_dfolder = array(); + if (empty($_dfolder)) { + $tmp = array(); + $tmp = glob('content/*/blog/*/', GLOB_ONLYDIR); + if (is_array($tmp)) { + foreach ($tmp as $dir) { + $_dfolder[] = $dir; + } + } + } + return $_dfolder; +} + // usort function. Sort by filename. function sortfile($a, $b) { @@ -151,16 +183,26 @@ function rebuilt_cache($type) } if ($type === 'posts') { - $posts_cache_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT); + $tmpu = array(); + $tmpu = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); + if (is_array($tmpu)) { + foreach ($tmpu as $fileu) { + if(strpos($fileu, 'draft') === false) { + $posts_cache_unsorted[] = $fileu; + } + } + } $string = serialize($posts_cache_unsorted); file_put_contents('cache/index/index-unsorted.txt', print_r($string, true)); $tmp = array(); - $tmp = glob('content/*/blog/*.md', GLOB_NOSORT); + $tmp = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); if (is_array($tmp)) { foreach ($tmp as $file) { - $posts_cache_sorted[] = pathinfo($file); + if(strpos($file, 'draft') === false) { + $posts_cache_sorted[] = pathinfo($file); + } } } usort($posts_cache_sorted, "sortfile"); @@ -220,11 +262,21 @@ function get_posts($posts, $page = 1, $perpage = 0) // Author string $str = explode('/', $replaced); - $author = $str[count($str) - 3]; + $author = $str[count($str) - 5]; + if($str[count($str) - 3] == 'uncategorized') { + $category = default_category(); + $post->category = '' . $category->title . ''; + } else { + $category = get_category_info($str[count($str) - 3]); + $post->category = '' . $category[0]->title . ''; + } + $type = $str[count($str) - 2]; // The post author + author url $post->author = $author; $post->authorUrl = site_url() . 'author/' . $author; + + $post->type = $type; $dt = str_replace($replaced, '', $arr[0]); $t = str_replace('-', '', $dt); @@ -258,6 +310,7 @@ function get_posts($posts, $page = 1, $perpage = 0) $tag = array(); $url = array(); $bc = array(); + $rel = array(); $tagt = get_content_tag('tag', $content); $t = explode(',', rtrim($arr[1], ',')); @@ -279,13 +332,15 @@ function get_posts($posts, $page = 1, $perpage = 0) } foreach ($tag as $a) { - $url[] = '' . $a[0] . ''; + $url[] = ''; $bc[] = '' . $a[0] . ''; } - $post->tag = implode(', ', $url); + $post->tag = implode(' ', $url); $post->tagb = implode(' ยป ', $bc); + + $post->related = rtrim($arr[1], ','); // Get the contents and convert it to HTML $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); @@ -390,6 +445,103 @@ function find_draft($year, $month, $name) } } +// Return category page. +function get_category($category, $page, $perpage) +{ + $posts = get_post_sorted(); + + $tmp = array(); + + foreach ($posts as $index => $v) { + + $filepath = $v['dirname'] . '/' . $v['basename']; + + // Extract the date + $arr = explode('_', $filepath); + + // Replaced string + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + + // Author string + $str = explode('/', $replaced); + $cat = $str[count($str) - 3]; + + if (strtolower($category) === strtolower($cat)) { + $tmp[] = $v; + } + } + + if (empty($tmp)) { + not_found(); + } + + $tmp = array_unique($tmp, SORT_REGULAR); + + return $tmp = get_posts($tmp, $page, $perpage); +} + +// Return category data. +function get_category_info($category) +{ + $posts = get_category_files(); + + $tmp = array(); + + if (!empty($posts)) { + + foreach ($posts as $index => $v) { + if (stripos($v, $category . '.md') !== false) { + + $desc = new stdClass; + + // Replaced string + $replaced = substr($v, 0, strrpos($v, '/')) . '/'; + + // The static page URL + $url= str_replace($replaced, '', $v); + + $desc->url = site_url() . 'category/' . str_replace('.md', '', $url); + + $desc->md = str_replace('.md', '', $url); + + $desc->file = $v; + + // Get the contents and convert it to HTML + $content = file_get_contents($v); + + // Extract the title and body + $desc->title = get_content_tag('t', $content, $category); + $desc->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); + + $desc->description = get_content_tag("d", $content, get_description($desc->body)); + + $tmp[] = $desc; + } + } + } + + if (strtolower($category) == 'uncategorized') { + return default_category(); + } + + return $tmp; +} + +// Return default profile +function default_category() +{ + $tmp = array(); + $desc = new stdClass; + + $desc->title = 'Uncategorized'; + $desc->url = site_url() . 'category/uncategorized'; + $desc->body = "

    Topics that don't need a category, or don't fit into any other existing category.

    "; + + $desc->description = 'Uncategorized Posts'; + + return $tmp[] = $desc; +} + // Return tag page. function get_tag($tag, $page, $perpage, $random) { @@ -454,7 +606,7 @@ function get_profile_posts($name, $page, $perpage) foreach ($posts as $index => $v) { $str = explode('/', $v['dirname']); - $author = $str[count($str) - 2]; + $author = $str[count($str) - 4]; if (strtolower($name) === strtolower($author)) { $tmp[] = $v; } @@ -476,7 +628,7 @@ function get_draft($profile, $page, $perpage) foreach ($posts as $index => $v) { $str = explode('/', $v['dirname']); - $author = $str[count($str) - 2]; + $author = $str[count($str) - 4]; if (strtolower($profile) === strtolower($author)) { $tmp[] = $v; } @@ -668,7 +820,7 @@ function get_related($tag, $custom = null, $count = null) } } - $posts = get_tag(strip_tags(remove_accent($tag)), 1, $count + 1, true); + $posts = get_tag($tag, 1, $count + 1, true); $tmp = array(); $req = urldecode($_SERVER['REQUEST_URI']); @@ -722,6 +874,64 @@ function get_count($var, $str) return count($tmp); } +// Return tag count. Matching $var and $str provided. +function get_categorycount($var) +{ + $posts = get_post_sorted(); + + $tmp = array(); + + foreach ($posts as $index => $v) { + + $filepath = $v['dirname'] . '/' . $v['basename']; + + // Extract the date + $arr = explode('_', $filepath); + + // Replaced string + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + + // Author string + $str = explode('/', $replaced); + $cat = $str[count($str) - 3]; + + if (stripos($cat, "$var") !== false) { + $tmp[] = $v; + } + } + + return count($tmp); +} + +// Return tag count. Matching $var and $str provided. +function get_draftcount($var) +{ + $posts = get_draft_posts(); + + $tmp = array(); + + foreach ($posts as $index => $v) { + + $filepath = $v['dirname'] . '/' . $v['basename']; + + // Extract the date + $arr = explode('_', $filepath); + + // Replaced string + $replaced = substr($arr[0], 0, strrpos($arr[0], '/')) . '/'; + + // Author string + $str = explode('/', $replaced); + $cat = $str[count($str) - 3]; + + if (stripos($cat, "$var") !== false) { + $tmp[] = $v; + } + } + + return count($tmp); +} + // Return tag count. Matching $var and $str provided. function get_tagcount($var, $str) { @@ -1577,10 +1787,10 @@ function generate_rss($posts) } $item = new Item(); - $tags = explode(',', str_replace(' ', '', strip_tags(remove_accent($p->tag)))); - foreach ($tags as $tag) { + $cats = explode(',', str_replace(' ', '', strip_tags(remove_accent($p->category)))); + foreach ($cats as $cat) { $item - ->category(tag_i18n($tag), site_url() . 'tag/' . strtolower($tag)); + ->category($cat, site_url() . 'category/' . strtolower($cat)); } $item ->title($p->title) @@ -1952,7 +2162,7 @@ function Zip($source, $destination, $include_dir = false) function is_index() { $req = $_SERVER['REQUEST_URI']; - if (stripos($req, '/archive/') !== false || stripos($req, '/tag/') !== false || stripos($req, '/search/') !== false || stripos($req, '/blog') !== false || $req == site_path() . '/' || stripos($req, site_path() . '/?page') !== false) { + if (stripos($req, '/category/') !== false || stripos($req, '/archive/') !== false || stripos($req, '/tag/') !== false || stripos($req, '/search/') !== false || stripos($req, '/blog') !== false || $req == site_path() . '/' || stripos($req, site_path() . '/?page') !== false) { return true; } else { return false; @@ -2009,6 +2219,16 @@ function is_search($value = null) } } +// TRUE if the current page is category index. +function is_category($value = null) +{ + if (!empty($value)) { + return true; + } else { + return false; + } +} + // TRUE if the current page is profile page. function is_profile($value = null) { @@ -2125,6 +2345,9 @@ EOF; echo '
  • Mine
  • '; echo '
  • Draft
  • '; echo '
  • Add content
  • '; + if ($role === 'admin') { + echo '
  • Categories
  • '; + } echo '
  • Edit profile
  • '; echo '
  • Import
  • '; echo '
  • Backup
  • '; @@ -2340,4 +2563,49 @@ function safe_html($string) $string = preg_replace('/\s\s+/', ' ', $string); $string = ltrim(rtrim($string)); return $string; -} \ No newline at end of file +} + +// return tag safe string +function safe_tag($string) +{ + $tags = array(); + $string = preg_replace('/[\s-]+/', ' ', $string); + $string = explode(',', $string); + $string = array_map('trim', $string); + foreach ($string as $str) { + $tags[] = $str; + } + $string = implode(',', $tags); + $string = preg_replace('/[\s_]/', '-', $string); + return $string; + +} + +// rename category folder +function rename_category_folder($string, $old_url) +{ + + $old = str_replace('.md', '/', $old_url); + $url = substr($old, 0, strrpos($old, '/')); + $ostr = explode('/', $url); + $url = '/blog/' . $ostr[count($ostr) - 1]; + + $dir = get_category_folder(); + + $file = array(); + + foreach ($dir as $index => $v) { + if (stripos($v, $url) !== false) { + $str = explode('/', $v); + $n = $str[count($ostr) - 4] . '/' . $str[count($ostr) - 3] .'/'. $str[count($ostr) - 2] .'/'. $string . '/'; + $file[] = array($v, $n); + } + } + + foreach ($file as $f) { + if(is_dir($f[0])) { + rename($f[0], $f[1]); + } + } + +} diff --git a/themes/blog/main.html.php b/themes/blog/main.html.php index 3e1f154..7ff7604 100644 --- a/themes/blog/main.html.php +++ b/themes/blog/main.html.php @@ -1,6 +1,20 @@ + +
    +
    +
    +
    +

    title;?>

    +
    + body; ?> +
    +
    +
    +
    +
    + title;?>

    - Posted in - tag;?> by + category;?> by with comments diff --git a/themes/blog/post.html.php b/themes/blog/post.html.php index bbb431b..abaa2e4 100644 --- a/themes/blog/post.html.php +++ b/themes/blog/post.html.php @@ -35,7 +35,7 @@

    title;?>

    - Posted in - tag;?> by + category;?> by

    @@ -43,6 +43,7 @@ body; ?>
    + tag;?> comments @@ -71,7 +72,7 @@ - tag, true, config('related.count'));?> + related, true, config('related.count'));?> = 1) { ?>
    diff --git a/themes/default/post.html.php b/themes/default/post.html.php index 12f97b2..5e54a71 100644 --- a/themes/default/post.html.php +++ b/themes/default/post.html.php @@ -57,7 +57,7 @@
    diff --git a/themes/logs/post.html.php b/themes/logs/post.html.php index cc5e3a4..9ca8d47 100644 --- a/themes/logs/post.html.php +++ b/themes/logs/post.html.php @@ -60,7 +60,7 @@