Browse Source

Add category

Add category feature to the core.
pull/255/head
Danang Probo Sayekti 10 years ago
parent
commit
a4b6fe18db
26 changed files with 1282 additions and 159 deletions
  1. +1
    -0
      config/config.ini.example
  2. +348
    -105
      system/admin/admin.php
  3. +11
    -0
      system/admin/views/add-audio.html.php
  4. +57
    -0
      system/admin/views/add-category.html.php
  5. +11
    -0
      system/admin/views/add-image.html.php
  6. +11
    -0
      system/admin/views/add-link.html.php
  7. +11
    -0
      system/admin/views/add-post.html.php
  8. +11
    -0
      system/admin/views/add-quote.html.php
  9. +11
    -0
      system/admin/views/add-video.html.php
  10. +21
    -0
      system/admin/views/categories.html.php
  11. +30
    -0
      system/admin/views/delete-category.html.php
  12. +16
    -1
      system/admin/views/edit-audio.html.php
  13. +86
    -0
      system/admin/views/edit-category.html.php
  14. +16
    -1
      system/admin/views/edit-image.html.php
  15. +16
    -1
      system/admin/views/edit-link.html.php
  16. +16
    -1
      system/admin/views/edit-post.html.php
  17. +16
    -1
      system/admin/views/edit-quote.html.php
  18. +16
    -1
      system/admin/views/edit-video.html.php
  19. +272
    -26
      system/htmly.php
  20. +283
    -15
      system/includes/functions.php
  21. +15
    -1
      themes/blog/main.html.php
  22. +3
    -2
      themes/blog/post.html.php
  23. +1
    -1
      themes/blog/profile.html.php
  24. +1
    -1
      themes/clean/post.html.php
  25. +1
    -1
      themes/default/post.html.php
  26. +1
    -1
      themes/logs/post.html.php

+ 1
- 0
config/config.ini.example View File

@ -59,6 +59,7 @@ google.reCaptcha.private = ""
; Pagination, RSS, and JSON ; Pagination, RSS, and JSON
posts.perpage = "10" posts.perpage = "10"
category.perpage = "10"
tag.perpage = "10" tag.perpage = "10"
archive.perpage = "10" archive.perpage = "10"
search.perpage = "10" search.perpage = "10"


+ 348
- 105
system/admin/admin.php View File

@ -86,7 +86,7 @@ function remove_accent($str)
} }
// Edit blog posts // 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); $oldurl = explode('_', $oldfile);
$dir = explode('/', $oldurl[0]); $dir = explode('/', $oldurl[0]);
@ -97,8 +97,9 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null,
} }
$post_title = safe_html($title); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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)) { 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'; $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
@ -148,13 +149,39 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null,
} else { } 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 { } 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 // 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); $oldurl = explode('_', $oldfile);
$dir = explode('/', $oldurl[0]); $dir = explode('/', $oldurl[0]);
@ -220,8 +247,9 @@ function edit_image($title, $tag, $url, $content, $oldfile, $destination = null,
$post_title = safe_html($title); $post_title = safe_html($title);
$post_image = preg_replace('/\s\s+/', ' ', strip_tags($image)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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)) { 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'; $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
@ -276,13 +304,39 @@ function edit_image($title, $tag, $url, $content, $oldfile, $destination = null,
} else { } 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 { } 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 // 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); $oldurl = explode('_', $oldfile);
$dir = explode('/', $oldurl[0]); $dir = explode('/', $oldurl[0]);
@ -348,8 +402,9 @@ function edit_video($title, $tag, $url, $content, $oldfile, $destination = null,
$post_title = safe_html($title); $post_title = safe_html($title);
$post_video = preg_replace('/\s\s+/', ' ', strip_tags($video)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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)) { 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'; $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
@ -404,13 +459,39 @@ function edit_video($title, $tag, $url, $content, $oldfile, $destination = null,
} else { } 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 { } 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 // 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); $oldurl = explode('_', $oldfile);
$dir = explode('/', $oldurl[0]); $dir = explode('/', $oldurl[0]);
@ -476,8 +557,9 @@ function edit_link($title, $tag, $url, $content, $oldfile, $destination = null,
$post_title = safe_html($title); $post_title = safe_html($title);
$post_link = preg_replace('/\s\s+/', ' ', strip_tags($link)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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)) { 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'; $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
@ -532,13 +614,39 @@ function edit_link($title, $tag, $url, $content, $oldfile, $destination = null,
} else { } 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 { } 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 // 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); $oldurl = explode('_', $oldfile);
$dir = explode('/', $oldurl[0]); $dir = explode('/', $oldurl[0]);
@ -604,8 +712,9 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null,
$post_title = safe_html($title); $post_title = safe_html($title);
$post_quote = preg_replace('/\s\s+/', ' ', strip_tags($quote)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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)) { 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'; $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
@ -660,17 +769,44 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null,
} else { } 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 { } 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)) { if(!empty($publishDraft)) {
$dt = $olddate; $dt = $olddate;
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
@ -720,7 +856,7 @@ function edit_quote($title, $tag, $url, $content, $oldfile, $destination = null,
} }
// Edit audio posts // 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); $oldurl = explode('_', $oldfile);
$dir = explode('/', $oldurl[0]); $dir = explode('/', $oldurl[0]);
@ -732,8 +868,9 @@ function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null,
$post_title = safe_html($title); $post_title = safe_html($title);
$post_audio = preg_replace('/\s\s+/', ' ', strip_tags($audio)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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)) { 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'; $filename = $dirBlog . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
} else { } else {
$filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $dirDraft . $olddate . '_' . $post_tag . '_' . $post_url . '.md';
@ -788,13 +925,39 @@ function edit_audio($title, $tag, $url, $content, $oldfile, $destination = null,
} else { } 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 { } 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<!--d " . $description . " d-->";
} else {
$post_description = '';
}
$post_content = '<!--t ' . $post_title . ' t-->' . $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 // 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_date = date('Y-m-d-H-i-s');
$post_title = safe_html($title); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
if (empty($draft)) { if (empty($draft)) {
$dir = 'content/' . $user . '/blog/';
$dir = 'content/' . $user . '/blog/' . $category. '/post/';
} else { } else {
$dir = 'content/' . $user . '/draft/';
$dir = 'content/' . $user . '/blog/' . $category. '/draft/';
} }
if (is_dir($dir)) { if (is_dir($dir)) {
@ -952,14 +1155,15 @@ function add_post($title, $tag, $url, $content, $user, $description = null, $dra
} }
// Add image // 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_date = date('Y-m-d-H-i-s');
$post_title = safe_html($title); $post_title = safe_html($title);
$post_image = preg_replace('/\s\s+/', ' ', strip_tags($image)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
if (empty($draft)) { if (empty($draft)) {
$dir = 'content/' . $user . '/blog/';
$dir = 'content/' . $user . '/blog/' . $category. '/image/';
} else { } else {
$dir = 'content/' . $user . '/draft/';
$dir = 'content/' . $user . '/blog/' . $category. '/draft/';
} }
if (is_dir($dir)) { if (is_dir($dir)) {
@ -1018,14 +1222,15 @@ function add_image($title, $tag, $url, $content, $user, $description = null, $im
} }
// Add video // 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_date = date('Y-m-d-H-i-s');
$post_title = safe_html($title); $post_title = safe_html($title);
$post_video = preg_replace('/\s\s+/', ' ', strip_tags($video)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
if (empty($draft)) { if (empty($draft)) {
$dir = 'content/' . $user . '/blog/';
$dir = 'content/' . $user . '/blog/' . $category. '/video/';
} else { } else {
$dir = 'content/' . $user . '/draft/';
$dir = 'content/' . $user . '/blog/' . $category. '/draft/';
} }
if (is_dir($dir)) { if (is_dir($dir)) {
@ -1084,14 +1289,15 @@ function add_video($title, $tag, $url, $content, $user, $description = null, $vi
} }
// Add audio // 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_date = date('Y-m-d-H-i-s');
$post_title = safe_html($title); $post_title = safe_html($title);
$post_audio = preg_replace('/\s\s+/', ' ', strip_tags($audio)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
if (empty($draft)) { if (empty($draft)) {
$dir = 'content/' . $user . '/blog/';
$dir = 'content/' . $user . '/blog/' . $category. '/audio/';
} else { } else {
$dir = 'content/' . $user . '/draft/';
$dir = 'content/' . $user . '/blog/' . $category. '/draft/';
} }
if (is_dir($dir)) { if (is_dir($dir)) {
@ -1150,14 +1356,15 @@ function add_audio($title, $tag, $url, $content, $user, $description = null, $au
} }
// Add link // 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_date = date('Y-m-d-H-i-s');
$post_title = safe_html($title); $post_title = safe_html($title);
$post_link = preg_replace('/\s\s+/', ' ', strip_tags($link)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
if (empty($draft)) { if (empty($draft)) {
$dir = 'content/' . $user . '/blog/';
$dir = 'content/' . $user . '/blog/' . $category. '/link/';
} else { } else {
$dir = 'content/' . $user . '/draft/';
$dir = 'content/' . $user . '/blog/' . $category. '/draft/';
} }
if (is_dir($dir)) { if (is_dir($dir)) {
@ -1216,14 +1423,15 @@ function add_link($title, $tag, $url, $content, $user, $description = null, $lin
} }
// Add quote // 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_date = date('Y-m-d-H-i-s');
$post_title = safe_html($title); $post_title = safe_html($title);
$post_quote = preg_replace('/\s\s+/', ' ', strip_tags($quote)); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
if (empty($draft)) { if (empty($draft)) {
$dir = 'content/' . $user . '/blog/';
$dir = 'content/' . $user . '/blog/' . $category. '/quote/';
} else { } else {
$dir = 'content/' . $user . '/draft/';
$dir = 'content/' . $user . '/blog/' . $category. '/draft/';
} }
if (is_dir($dir)) { 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<!--d " . $description . " d-->";
} else {
$post_description = "";
}
$post_content = '<!--t ' . $post_title . ' t-->' . $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 // Delete blog post
function delete_post($file, $destination) 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_date = date('Y-m-d-H-i-s', $time);
$post_title = safe_html($title); $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_tag = rtrim($post_tag, ',');
$post_tagmd = rtrim($post_tagmd, ','); $post_tagmd = rtrim($post_tagmd, ',');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $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); $post_content = stripslashes($post_content);
} }
$filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md'; $filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
$dir = 'content/' . $user . '/blog/';
$dir = 'content/' . $user . '/blog/uncategorized/post/';
if (is_dir($dir)) { if (is_dir($dir)) {
file_put_contents($dir . $filename, print_r($post_content, true)); file_put_contents($dir . $filename, print_r($post_content, true));
} else { } else {


+ 11
- 0
system/admin/views/add-audio.html.php View File

@ -9,6 +9,9 @@
<?php if (isset($error)) { ?> <?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div> <div class="error-message"><?php echo $error ?></div>
<?php } ?> <?php } ?>
<?php
$desc = get_category_info(null);
?>
<div class="wmd-panel"> <div class="wmd-panel">
<form method="POST"> <form method="POST">
Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) { Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) {
@ -18,6 +21,14 @@
} ?>" name="title" value="<?php if (isset($postTitle)) { } ?>" name="title" value="<?php if (isset($postTitle)) {
echo $postTitle; echo $postTitle;
} ?>"/><br><br> } ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>"><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';


+ 57
- 0
system/admin/views/add-category.html.php View File

@ -0,0 +1,57 @@
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
<script src="<?php echo site_url() ?>system/resources/js/jquery.min.js"></script>
<script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/jquery.ajaxfileupload.js"></script>
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
<?php } ?>
<div class="wmd-panel">
<form method="POST">
Title <span class="required">*</span><br><input type="text" class="text <?php if (isset($postTitle)) {
if (empty($postTitle)) {
echo 'error';
}
} ?>" name="title" value="<?php if (isset($postTitle)) {
echo $postTitle;
} ?>"/><br><br>
Url (optional)<br><input type="text" class="text" name="url" value="<?php if (isset($postUrl)) {
echo $postUrl;
} ?>"/><br>
<span class="help">If the url leave empty we will use the page title.</span><br><br>
Meta Description (optional)<br><textarea name="description" rows="3" cols="20"><?php if (isset($p->description)) {
echo $p->description;
} ?></textarea>
<br><br>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="wmd-input <?php if (isset($postContent)) {
if (empty($postContent)) {
echo 'error';
}
} ?>" name="content" cols="20" rows="10"><?php if (isset($postContent)) {
echo $postContent;
} ?></textarea><br/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" name="submit" class="submit" value="Add category"/>
</form>
</div>
<div id="insertImageDialog" title="Insert Image">
<h4>URL</h4>
<input type="text" placeholder="Enter image URL" />
<h4>Upload</h4>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
</form>
<style>
#insertImageDialog { display:none; padding: 10px; font-size:12px;}
.wmd-prompt-background {z-index:10!important;}
</style>
</div>
<div id="wmd-preview" class="wmd-panel wmd-preview"></div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>';</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/image.js"></script>

+ 11
- 0
system/admin/views/add-image.html.php View File

@ -9,6 +9,9 @@
<?php if (isset($error)) { ?> <?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div> <div class="error-message"><?php echo $error ?></div>
<?php } ?> <?php } ?>
<?php
$desc = get_category_info(null);
?>
<div class="wmd-panel"> <div class="wmd-panel">
<form method="POST"> <form method="POST">
Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) { Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) {
@ -18,6 +21,14 @@
} ?>" name="title" value="<?php if (isset($postTitle)) { } ?>" name="title" value="<?php if (isset($postTitle)) {
echo $postTitle; echo $postTitle;
} ?>"/><br><br> } ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>"><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';


+ 11
- 0
system/admin/views/add-link.html.php View File

@ -9,6 +9,9 @@
<?php if (isset($error)) { ?> <?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div> <div class="error-message"><?php echo $error ?></div>
<?php } ?> <?php } ?>
<?php
$desc = get_category_info(null);
?>
<div class="wmd-panel"> <div class="wmd-panel">
<form method="POST"> <form method="POST">
Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) { Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) {
@ -18,6 +21,14 @@
} ?>" name="title" value="<?php if (isset($postTitle)) { } ?>" name="title" value="<?php if (isset($postTitle)) {
echo $postTitle; echo $postTitle;
} ?>"/><br><br> } ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>"><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';


+ 11
- 0
system/admin/views/add-post.html.php View File

@ -9,6 +9,9 @@
<?php if (isset($error)) { ?> <?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div> <div class="error-message"><?php echo $error ?></div>
<?php } ?> <?php } ?>
<?php
$desc = get_category_info(null);
?>
<div class="wmd-panel"> <div class="wmd-panel">
<form method="POST"> <form method="POST">
Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) { Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) {
@ -18,6 +21,14 @@
} ?>" name="title" value="<?php if (isset($postTitle)) { } ?>" name="title" value="<?php if (isset($postTitle)) {
echo $postTitle; echo $postTitle;
} ?>"/><br><br> } ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>"><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';


+ 11
- 0
system/admin/views/add-quote.html.php View File

@ -9,6 +9,9 @@
<?php if (isset($error)) { ?> <?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div> <div class="error-message"><?php echo $error ?></div>
<?php } ?> <?php } ?>
<?php
$desc = get_category_info(null);
?>
<div class="wmd-panel"> <div class="wmd-panel">
<form method="POST"> <form method="POST">
Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) { Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) {
@ -18,6 +21,14 @@
} ?>" name="title" value="<?php if (isset($postTitle)) { } ?>" name="title" value="<?php if (isset($postTitle)) {
echo $postTitle; echo $postTitle;
} ?>"/><br><br> } ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>"><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';


+ 11
- 0
system/admin/views/add-video.html.php View File

@ -9,6 +9,9 @@
<?php if (isset($error)) { ?> <?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div> <div class="error-message"><?php echo $error ?></div>
<?php } ?> <?php } ?>
<?php
$desc = get_category_info(null);
?>
<div class="wmd-panel"> <div class="wmd-panel">
<form method="POST"> <form method="POST">
Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) { Title <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTitle)) {
@ -18,6 +21,14 @@
} ?>" name="title" value="<?php if (isset($postTitle)) { } ?>" name="title" value="<?php if (isset($postTitle)) {
echo $postTitle; echo $postTitle;
} ?>"/><br><br> } ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>"><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';


+ 21
- 0
system/admin/views/categories.html.php View File

@ -0,0 +1,21 @@
<?php
$desc = get_category_info(null);
?>
<a href="<?php echo site_url();?>add/category">Add category</a>
<table class="category-list">
<tr class="head">
<th>Name</th>
<th>Description</th>
<th>Contents</th>
<th>Operations</th>
</tr>
<?php foreach ($desc as $d):?>
<tr>
<td><a href="<?php echo $d->url;?>" target="_blank"><?php echo $d->title;?></a></td>
<td><?php echo $d->body;?></td>
<td><?php $total = get_draftcount($d->md) + get_categorycount($d->md); echo $total?></td>
<td><a href="<?php echo $d->url;?>/edit?destination=admin/categories">Edit</a> <?php if (get_categorycount($d->md) == 0 && get_draftcount($d->md) == 0 ){echo '<a href="' . $d->url . '/delete?destination=admin/categories">Delete</a>';}?></td>
</tr>
<?php endforeach;?>
</table>

+ 30
- 0
system/admin/views/delete-category.html.php View File

@ -0,0 +1,30 @@
<?php
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();
}
?>
<p>Are you sure want to delete <strong><?php echo $p->title; ?></strong>?</p>
<form method="POST">
<input type="hidden" name="file" value="<?php echo $p->file ?>"/><br>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" name="submit" value="Delete"/>
<span><a href="<?php echo $back ?>">Cancel</a></span>
</form>

+ 16
- 1
system/admin/views/edit-audio.html.php View File

@ -5,6 +5,8 @@ if (isset($p->file)) {
$url = $oldfile; $url = $oldfile;
} }
$desc = get_category_info(null);
$content = file_get_contents($url); $content = file_get_contents($url);
$oldtitle = get_content_tag('t', $content, 'Untitled'); $oldtitle = get_content_tag('t', $content, 'Untitled');
$olddescription = get_content_tag('d', $content); $olddescription = get_content_tag('d', $content);
@ -28,6 +30,11 @@ if (isset($_GET['destination'])) {
$destination = 'admin'; $destination = 'admin';
} }
$replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/';
// Category string
$cat = explode('/', $replaced);
$category = $cat[count($cat) - 3];
$dt = str_replace($replaced, '', $oldurl[0]); $dt = str_replace($replaced, '', $oldurl[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
@ -61,6 +68,14 @@ if (config('permalink.type') == 'post') {
echo 'error'; echo 'error';
} }
} ?>" value="<?php echo $oldtitle ?>"/><br><br> } ?>" value="<?php echo $oldtitle ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';
@ -89,7 +104,7 @@ if (config('permalink.type') == 'post') {
<input type="hidden" name="is_audio" class="text" value="is_audio"/> <input type="hidden" name="is_audio" class="text" value="is_audio"/>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/> <input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>"> <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($isdraft[2] == 'draft') { ?>
<?php if ($isdraft[4] == 'draft') { ?>
<input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a>
<?php } else { ?> <?php } else { ?>
<input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a>


+ 86
- 0
system/admin/views/edit-category.html.php View File

@ -0,0 +1,86 @@
<?php
if (isset($p->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;
}
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
<script src="<?php echo site_url() ?>system/resources/js/jquery.min.js"></script>
<script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
<link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/jquery.ajaxfileupload.js"></script>
<?php if (isset($error)) { ?>
<div class="error-message"><?php echo $error ?></div>
<?php } ?>
<div class="wmd-panel">
<form method="POST">
Title <span class="required">*</span><br><input type="text" name="title"
class="text <?php if (isset($postTitle)) {
if (empty($postTitle)) {
echo 'error';
}
} ?>" value="<?php echo $oldtitle ?>"/><br><br>
Url (optional)<br><input type="text" name="url" class="text" value="<?php echo $oldmd ?>"/><br>
<span class="help">If the url leave empty we will use the page title.</span><br><br>
Meta Description (optional)<br><textarea name="description" rows="3" cols="20"><?php if (isset($p->description)) {
echo $p->description;
} else {echo $olddescription;}?></textarea>
<br><br>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="wmd-input <?php if (isset($postContent)) {
if (empty($postContent)) {
echo 'error';
}
} ?>" name="content" cols="20" rows="10"><?php echo $oldcontent ?></textarea><br>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<input type="submit" name="submit" class="submit" value="Save category"/>
</form>
</div>
<div id="insertImageDialog" title="Insert Image">
<h4>URL</h4>
<input type="text" placeholder="Enter image URL" />
<h4>Upload</h4>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
</form>
<style>
#insertImageDialog { display:none; padding: 10px; font-size:12px;}
.wmd-prompt-background {z-index:10!important;}
</style>
</div>
<div id="wmd-preview" class="wmd-panel wmd-preview"></div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>';</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/image.js"></script>

+ 16
- 1
system/admin/views/edit-image.html.php View File

@ -5,6 +5,8 @@ if (isset($p->file)) {
$url = $oldfile; $url = $oldfile;
} }
$desc = get_category_info(null);
$content = file_get_contents($url); $content = file_get_contents($url);
$oldtitle = get_content_tag('t', $content, 'Untitled'); $oldtitle = get_content_tag('t', $content, 'Untitled');
$olddescription = get_content_tag('d', $content); $olddescription = get_content_tag('d', $content);
@ -28,6 +30,11 @@ if (isset($_GET['destination'])) {
$destination = 'admin'; $destination = 'admin';
} }
$replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/';
// Category string
$cat = explode('/', $replaced);
$category = $cat[count($cat) - 3];
$dt = str_replace($replaced, '', $oldurl[0]); $dt = str_replace($replaced, '', $oldurl[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
@ -61,6 +68,14 @@ if (config('permalink.type') == 'post') {
echo 'error'; echo 'error';
} }
} ?>" value="<?php echo $oldtitle ?>"/><br><br> } ?>" value="<?php echo $oldtitle ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';
@ -89,7 +104,7 @@ if (config('permalink.type') == 'post') {
<input type="hidden" name="is_image" class="text" value="is_image"/> <input type="hidden" name="is_image" class="text" value="is_image"/>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/> <input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>"> <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($isdraft[2] == 'draft') { ?>
<?php if ($isdraft[4] == 'draft') { ?>
<input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a>
<?php } else { ?> <?php } else { ?>
<input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a>


+ 16
- 1
system/admin/views/edit-link.html.php View File

@ -5,6 +5,8 @@ if (isset($p->file)) {
$url = $oldfile; $url = $oldfile;
} }
$desc = get_category_info(null);
$content = file_get_contents($url); $content = file_get_contents($url);
$oldtitle = get_content_tag('t', $content, 'Untitled'); $oldtitle = get_content_tag('t', $content, 'Untitled');
$olddescription = get_content_tag('d', $content); $olddescription = get_content_tag('d', $content);
@ -28,6 +30,11 @@ if (isset($_GET['destination'])) {
$destination = 'admin'; $destination = 'admin';
} }
$replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/';
// Category string
$cat = explode('/', $replaced);
$category = $cat[count($cat) - 3];
$dt = str_replace($replaced, '', $oldurl[0]); $dt = str_replace($replaced, '', $oldurl[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
@ -62,6 +69,14 @@ if (config('permalink.type') == 'post') {
echo 'error'; echo 'error';
} }
} ?>" value="<?php echo $oldtitle ?>"/><br><br> } ?>" value="<?php echo $oldtitle ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';
@ -90,7 +105,7 @@ if (config('permalink.type') == 'post') {
<input type="hidden" name="is_link" class="text" value="is_link"/> <input type="hidden" name="is_link" class="text" value="is_link"/>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/> <input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>"> <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($isdraft[2] == 'draft') { ?>
<?php if ($isdraft[4] == 'draft') { ?>
<input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a>
<?php } else { ?> <?php } else { ?>
<input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a>


+ 16
- 1
system/admin/views/edit-post.html.php View File

@ -5,6 +5,8 @@ if (isset($p->file)) {
$url = $oldfile; $url = $oldfile;
} }
$desc = get_category_info(null);
$content = file_get_contents($url); $content = file_get_contents($url);
$oldtitle = get_content_tag('t', $content, 'Untitled'); $oldtitle = get_content_tag('t', $content, 'Untitled');
$olddescription = get_content_tag('d', $content); $olddescription = get_content_tag('d', $content);
@ -27,6 +29,11 @@ if (isset($_GET['destination'])) {
$destination = 'admin'; $destination = 'admin';
} }
$replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/';
// Category string
$cat = explode('/', $replaced);
$category = $cat[count($cat) - 3];
$dt = str_replace($replaced, '', $oldurl[0]); $dt = str_replace($replaced, '', $oldurl[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
@ -61,6 +68,14 @@ if (config('permalink.type') == 'post') {
echo 'error'; echo 'error';
} }
} ?>" value="<?php echo $oldtitle ?>"/><br><br> } ?>" value="<?php echo $oldtitle ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';
@ -84,7 +99,7 @@ if (config('permalink.type') == 'post') {
<input type="hidden" name="is_post" class="text" value="is_post"/> <input type="hidden" name="is_post" class="text" value="is_post"/>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/> <input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>"> <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($isdraft[2] == 'draft') { ?>
<?php if ($isdraft[4] == 'draft') { ?>
<input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a>
<?php } else { ?> <?php } else { ?>
<input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a>


+ 16
- 1
system/admin/views/edit-quote.html.php View File

@ -5,6 +5,8 @@ if (isset($p->file)) {
$url = $oldfile; $url = $oldfile;
} }
$desc = get_category_info(null);
$content = file_get_contents($url); $content = file_get_contents($url);
$oldtitle = get_content_tag('t', $content, 'Untitled'); $oldtitle = get_content_tag('t', $content, 'Untitled');
$olddescription = get_content_tag('d', $content); $olddescription = get_content_tag('d', $content);
@ -28,6 +30,11 @@ if (isset($_GET['destination'])) {
$destination = 'admin'; $destination = 'admin';
} }
$replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/';
// Category string
$cat = explode('/', $replaced);
$category = $cat[count($cat) - 3];
$dt = str_replace($replaced, '', $oldurl[0]); $dt = str_replace($replaced, '', $oldurl[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
@ -62,6 +69,14 @@ if (config('permalink.type') == 'post') {
echo 'error'; echo 'error';
} }
} ?>" value="<?php echo $oldtitle ?>"/><br><br> } ?>" value="<?php echo $oldtitle ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';
@ -90,7 +105,7 @@ if (config('permalink.type') == 'post') {
<input type="hidden" name="is_quote" class="text" value="is_quote"/> <input type="hidden" name="is_quote" class="text" value="is_quote"/>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/> <input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>"> <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($isdraft[2] == 'draft') { ?>
<?php if ($isdraft[4] == 'draft') { ?>
<input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a>
<?php } else { ?> <?php } else { ?>
<input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a>


+ 16
- 1
system/admin/views/edit-video.html.php View File

@ -5,6 +5,8 @@ if (isset($p->file)) {
$url = $oldfile; $url = $oldfile;
} }
$desc = get_category_info(null);
$content = file_get_contents($url); $content = file_get_contents($url);
$oldtitle = get_content_tag('t', $content, 'Untitled'); $oldtitle = get_content_tag('t', $content, 'Untitled');
$olddescription = get_content_tag('d', $content); $olddescription = get_content_tag('d', $content);
@ -29,6 +31,11 @@ if (isset($_GET['destination'])) {
$destination = 'admin'; $destination = 'admin';
} }
$replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/';
// Category string
$cat = explode('/', $replaced);
$category = $cat[count($cat) - 3];
$dt = str_replace($replaced, '', $oldurl[0]); $dt = str_replace($replaced, '', $oldurl[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
@ -63,6 +70,14 @@ if (config('permalink.type') == 'post') {
echo 'error'; echo 'error';
} }
} ?>" value="<?php echo $oldtitle ?>"/><br><br> } ?>" value="<?php echo $oldtitle ?>"/><br><br>
Category <span class="required">*</span> <br>
<select name="category">
<option value="uncategorized">Uncategorized</option>
<?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option>
<?php endforeach;?>
</select>
<br><br>
Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) { Tag <span class="required">*</span> <br><input type="text" name="tag" class="text <?php if (isset($postTag)) {
if (empty($postTag)) { if (empty($postTag)) {
echo 'error'; echo 'error';
@ -91,7 +106,7 @@ if (config('permalink.type') == 'post') {
<input type="hidden" name="is_video" class="text" value="is_video"/> <input type="hidden" name="is_video" class="text" value="is_video"/>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/> <input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>"> <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($isdraft[2] == 'draft') { ?>
<?php if ($isdraft[4] == 'draft') { ?>
<input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="publishdraft" class="submit" value="Publish draft"/> <input type="submit" name="updatedraft" class="draft" value="Update draft"/> <a href="<?php echo $delete ?>">Delete</a>
<?php } else { ?> <?php } else { ?>
<input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a> <input type="submit" name="updatepost" class="submit" value="Update post"/> <input type="submit" name="revertpost" class="revert" value="Revert to draft"/> <a href="<?php echo $delete ?>">Delete</a>


+ 272
- 26
system/htmly.php View File

@ -257,12 +257,13 @@ post('/add/post', function () {
$description = from($_REQUEST, 'description'); $description = from($_REQUEST, 'description');
$user = $_SESSION[config("site.url")]['user']; $user = $_SESSION[config("site.url")]['user'];
$draft = from($_REQUEST, 'draft'); $draft = from($_REQUEST, 'draft');
$category = from($_REQUEST, 'category');
if ($proper && !empty($title) && !empty($tag) && !empty($content)) { if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
if (!empty($url)) { if (!empty($url)) {
add_post($title, $tag, $url, $content, $user, $description, $draft);
add_post($title, $tag, $url, $content, $user, $description, $draft, $category);
} else { } else {
$url = $title; $url = $title;
add_post($title, $tag, $url, $content, $user, $description, $draft);
add_post($title, $tag, $url, $content, $user, $description, $draft, $category);
} }
} else { } else {
$message['error'] = ''; $message['error'] = '';
@ -327,12 +328,13 @@ post('/add/image', function () {
$description = from($_REQUEST, 'description'); $description = from($_REQUEST, 'description');
$user = $_SESSION[config("site.url")]['user']; $user = $_SESSION[config("site.url")]['user'];
$draft = from($_REQUEST, 'draft'); $draft = from($_REQUEST, 'draft');
$category = from($_REQUEST, 'category');
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) { if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) {
if (!empty($url)) { 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 { } else {
$url = $title; $url = $title;
add_image($title, $tag, $url, $content, $user, $description, $image, $draft);
add_image($title, $tag, $url, $content, $user, $description, $image, $draft, $category);
} }
} else { } else {
$message['error'] = ''; $message['error'] = '';
@ -401,12 +403,13 @@ post('/add/video', function () {
$description = from($_REQUEST, 'description'); $description = from($_REQUEST, 'description');
$user = $_SESSION[config("site.url")]['user']; $user = $_SESSION[config("site.url")]['user'];
$draft = from($_REQUEST, 'draft'); $draft = from($_REQUEST, 'draft');
$category = from($_REQUEST, 'category');
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (!empty($url)) { 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 { } else {
$url = $title; $url = $title;
add_video($title, $tag, $url, $content, $user, $description, $video, $draft);
add_video($title, $tag, $url, $content, $user, $description, $video, $draft, $category);
} }
} else { } else {
$message['error'] = ''; $message['error'] = '';
@ -477,10 +480,10 @@ post('/add/link', function () {
$draft = from($_REQUEST, 'draft'); $draft = from($_REQUEST, 'draft');
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (!empty($url)) { 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 { } else {
$url = $title; $url = $title;
add_link($title, $tag, $url, $content, $user, $description, $link, $draft);
add_link($title, $tag, $url, $content, $user, $description, $link, $draft, $category);
} }
} else { } else {
$message['error'] = ''; $message['error'] = '';
@ -549,12 +552,13 @@ post('/add/quote', function () {
$description = from($_REQUEST, 'description'); $description = from($_REQUEST, 'description');
$user = $_SESSION[config("site.url")]['user']; $user = $_SESSION[config("site.url")]['user'];
$draft = from($_REQUEST, 'draft'); $draft = from($_REQUEST, 'draft');
$category = from($_REQUEST, 'category');
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (!empty($url)) { 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 { } else {
$url = $title; $url = $title;
add_quote($title, $tag, $url, $content, $user, $description, $quote, $draft);
add_quote($title, $tag, $url, $content, $user, $description, $quote, $draft, $category);
} }
} else { } else {
$message['error'] = ''; $message['error'] = '';
@ -623,12 +627,13 @@ post('/add/audio', function () {
$description = from($_REQUEST, 'description'); $description = from($_REQUEST, 'description');
$user = $_SESSION[config("site.url")]['user']; $user = $_SESSION[config("site.url")]['user'];
$draft = from($_REQUEST, 'draft'); $draft = from($_REQUEST, 'draft');
$category = from($_REQUEST, 'category');
if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (!empty($url)) { 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 { } else {
$url = $title; $url = $title;
add_audio($title, $tag, $url, $content, $user, $description, $audio, $draft);
add_audio($title, $tag, $url, $content, $user, $description, $audio, $draft, $category);
} }
} else { } else {
$message['error'] = ''; $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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; 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'] .= '<li>Title field is required.</li>';
}
if (empty($content)) {
$message['error'] .= '<li>Content field is required.</li>';
}
if (!$proper) {
$message['error'] .= '<li>CSRF Token not correct.</li>';
}
config('views.root', 'system/admin/views');
render('add-category', array(
'title' => 'Add page - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '<ul>' . $message['error'] . '</ul>',
'postTitle' => $title,
'postUrl' => $url,
'postContent' => $content,
'bodyclass' => 'addpage',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Add page'
));
}
});
// Show admin/posts // Show admin/posts
get('/admin/posts', function () { 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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; 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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $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'] .= '<li>Title field is required.</li>';
}
if (empty($content)) {
$message['error'] .= '<li>Content field is required.</li>';
}
if (!$proper) {
$message['error'] .= '<li>CSRF Token not correct.</li>';
}
config('views.root', 'system/admin/views');
render('edit-category', array(
'title' => 'Edit category - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '<ul>' . $message['error'] . '</ul>',
'oldfile' => $oldfile,
'postTitle' => $title,
'postUrl' => $url,
'postContent' => $content,
'bodyclass' => 'editcategory',
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; 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' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $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 // Show the tag page
get('/tag/:tag', function ($tag) { get('/tag/:tag', function ($tag) {
@ -1437,7 +1681,7 @@ get('/post/:name', function ($name) {
'p' => $current, 'p' => $current,
'author' => $author, 'author' => $author,
'bodyclass' => 'inpost', 'bodyclass' => 'inpost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; '. $blog . $current->tagb . ' &#187; ' . $current->title,
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; '. $blog . $current->category . ' &#187; ' . $current->title,
'prev' => has_prev($prev), 'prev' => has_prev($prev),
'next' => has_next($next), 'next' => has_next($next),
'type' => $var, 'type' => $var,
@ -1533,6 +1777,7 @@ post('/post/:name/edit', function () {
$dateTime = null; $dateTime = null;
$revertPost = from($_REQUEST, 'revertpost'); $revertPost = from($_REQUEST, 'revertpost');
$publishDraft = from($_REQUEST, 'publishdraft'); $publishDraft = from($_REQUEST, 'publishdraft');
$category = from($_REQUEST, 'category');
if ($date !== null && $time !== null) { if ($date !== null && $time !== null) {
$dateTime = $date . ' ' . $time; $dateTime = $date . ' ' . $time;
} }
@ -1555,37 +1800,37 @@ post('/post/:name/edit', function () {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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 { } else {
$message['error'] = ''; $message['error'] = '';
@ -2291,7 +2536,7 @@ get('/:year/:month/:name', function ($year, $month, $name) {
'p' => $current, 'p' => $current,
'author' => $author, 'author' => $author,
'bodyclass' => 'inpost', 'bodyclass' => 'inpost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; '. $blog . $current->tagb . ' &#187; ' . $current->title,
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' . config('breadcrumb.home') . '</a></span> &#187; '. $blog . $current->category . ' &#187; ' . $current->title,
'prev' => has_prev($prev), 'prev' => has_prev($prev),
'next' => has_next($next), 'next' => has_next($next),
'type' => $var, 'type' => $var,
@ -2387,6 +2632,7 @@ post('/:year/:month/:name/edit', function () {
$dateTime = null; $dateTime = null;
$revertPost = from($_REQUEST, 'revertpost'); $revertPost = from($_REQUEST, 'revertpost');
$publishDraft = from($_REQUEST, 'publishdraft'); $publishDraft = from($_REQUEST, 'publishdraft');
$category = from($_REQUEST, 'category');
if ($date !== null && $time !== null) { if ($date !== null && $time !== null) {
$dateTime = $date . ' ' . $time; $dateTime = $date . ' ' . $time;
} }
@ -2409,37 +2655,37 @@ post('/:year/:month/:name/edit', function () {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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)) { } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) {
if (empty($url)) { if (empty($url)) {
$url = $title; $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 { } else {
$message['error'] = ''; $message['error'] = '';


+ 283
- 15
system/includes/functions.php View File

@ -114,7 +114,7 @@ function get_draft_posts()
static $_draft = array(); static $_draft = array();
if (empty($_draft)) { if (empty($_draft)) {
$tmp = array(); $tmp = array();
$tmp = glob('content/*/draft/*.md', GLOB_NOSORT);
$tmp = glob('content/*/*/*/draft/*.md', GLOB_NOSORT);
if (is_array($tmp)) { if (is_array($tmp)) {
foreach ($tmp as $file) { foreach ($tmp as $file) {
$_draft[] = pathinfo($file); $_draft[] = pathinfo($file);
@ -125,6 +125,38 @@ function get_draft_posts()
return $_draft; 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. // usort function. Sort by filename.
function sortfile($a, $b) function sortfile($a, $b)
{ {
@ -151,16 +183,26 @@ function rebuilt_cache($type)
} }
if ($type === 'posts') { 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); $string = serialize($posts_cache_unsorted);
file_put_contents('cache/index/index-unsorted.txt', print_r($string, true)); file_put_contents('cache/index/index-unsorted.txt', print_r($string, true));
$tmp = array(); $tmp = array();
$tmp = glob('content/*/blog/*.md', GLOB_NOSORT);
$tmp = glob('content/*/blog/*/*/*.md', GLOB_NOSORT);
if (is_array($tmp)) { if (is_array($tmp)) {
foreach ($tmp as $file) { foreach ($tmp as $file) {
$posts_cache_sorted[] = pathinfo($file);
if(strpos($file, 'draft') === false) {
$posts_cache_sorted[] = pathinfo($file);
}
} }
} }
usort($posts_cache_sorted, "sortfile"); usort($posts_cache_sorted, "sortfile");
@ -220,11 +262,21 @@ function get_posts($posts, $page = 1, $perpage = 0)
// Author string // Author string
$str = explode('/', $replaced); $str = explode('/', $replaced);
$author = $str[count($str) - 3];
$author = $str[count($str) - 5];
if($str[count($str) - 3] == 'uncategorized') {
$category = default_category();
$post->category = '<a href="' . $category->url . '">' . $category->title . '</a>';
} else {
$category = get_category_info($str[count($str) - 3]);
$post->category = '<a href="' . $category[0]->url . '">' . $category[0]->title . '</a>';
}
$type = $str[count($str) - 2];
// The post author + author url // The post author + author url
$post->author = $author; $post->author = $author;
$post->authorUrl = site_url() . 'author/' . $author; $post->authorUrl = site_url() . 'author/' . $author;
$post->type = $type;
$dt = str_replace($replaced, '', $arr[0]); $dt = str_replace($replaced, '', $arr[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
@ -258,6 +310,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
$tag = array(); $tag = array();
$url = array(); $url = array();
$bc = array(); $bc = array();
$rel = array();
$tagt = get_content_tag('tag', $content); $tagt = get_content_tag('tag', $content);
$t = explode(',', rtrim($arr[1], ',')); $t = explode(',', rtrim($arr[1], ','));
@ -279,13 +332,15 @@ function get_posts($posts, $page = 1, $perpage = 0)
} }
foreach ($tag as $a) { foreach ($tag as $a) {
$url[] = '<span><a href="' . $a[1] . '">' . $a[0] . '</a></span>';
$url[] = '<a rel="tag" href="' . $a[1] . '">' . $a[0] . '</a>';
$bc[] = '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . $a[1] . '">' . $a[0] . '</a></span>'; $bc[] = '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . $a[1] . '">' . $a[0] . '</a></span>';
} }
$post->tag = implode(', ', $url);
$post->tag = implode(' ', $url);
$post->tagb = implode(' » ', $bc); $post->tagb = implode(' » ', $bc);
$post->related = rtrim($arr[1], ',');
// Get the contents and convert it to HTML // Get the contents and convert it to HTML
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); $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 = "<p>Topics that don't need a category, or don't fit into any other existing category.</p>";
$desc->description = 'Uncategorized Posts';
return $tmp[] = $desc;
}
// Return tag page. // Return tag page.
function get_tag($tag, $page, $perpage, $random) function get_tag($tag, $page, $perpage, $random)
{ {
@ -454,7 +606,7 @@ function get_profile_posts($name, $page, $perpage)
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$str = explode('/', $v['dirname']); $str = explode('/', $v['dirname']);
$author = $str[count($str) - 2];
$author = $str[count($str) - 4];
if (strtolower($name) === strtolower($author)) { if (strtolower($name) === strtolower($author)) {
$tmp[] = $v; $tmp[] = $v;
} }
@ -476,7 +628,7 @@ function get_draft($profile, $page, $perpage)
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$str = explode('/', $v['dirname']); $str = explode('/', $v['dirname']);
$author = $str[count($str) - 2];
$author = $str[count($str) - 4];
if (strtolower($profile) === strtolower($author)) { if (strtolower($profile) === strtolower($author)) {
$tmp[] = $v; $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(); $tmp = array();
$req = urldecode($_SERVER['REQUEST_URI']); $req = urldecode($_SERVER['REQUEST_URI']);
@ -722,6 +874,64 @@ function get_count($var, $str)
return count($tmp); 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. // Return tag count. Matching $var and $str provided.
function get_tagcount($var, $str) function get_tagcount($var, $str)
{ {
@ -1577,10 +1787,10 @@ function generate_rss($posts)
} }
$item = new Item(); $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 $item
->category(tag_i18n($tag), site_url() . 'tag/' . strtolower($tag));
->category($cat, site_url() . 'category/' . strtolower($cat));
} }
$item $item
->title($p->title) ->title($p->title)
@ -1952,7 +2162,7 @@ function Zip($source, $destination, $include_dir = false)
function is_index() function is_index()
{ {
$req = $_SERVER['REQUEST_URI']; $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; return true;
} else { } else {
return false; 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. // TRUE if the current page is profile page.
function is_profile($value = null) function is_profile($value = null)
{ {
@ -2125,6 +2345,9 @@ EOF;
echo '<li><a href="' . $base . 'admin/mine">Mine</a></li>'; echo '<li><a href="' . $base . 'admin/mine">Mine</a></li>';
echo '<li><a href="' . $base . 'admin/draft">Draft</a></li>'; echo '<li><a href="' . $base . 'admin/draft">Draft</a></li>';
echo '<li><a href="' . $base . 'admin/content">Add content</a></li>'; echo '<li><a href="' . $base . 'admin/content">Add content</a></li>';
if ($role === 'admin') {
echo '<li><a href="' . $base . 'admin/categories">Categories</a></li>';
}
echo '<li><a href="' . $base . 'edit/profile">Edit profile</a></li>'; echo '<li><a href="' . $base . 'edit/profile">Edit profile</a></li>';
echo '<li><a href="' . $base . 'admin/import">Import</a></li>'; echo '<li><a href="' . $base . 'admin/import">Import</a></li>';
echo '<li><a href="' . $base . 'admin/backup">Backup</a></li>'; echo '<li><a href="' . $base . 'admin/backup">Backup</a></li>';
@ -2340,4 +2563,49 @@ function safe_html($string)
$string = preg_replace('/\s\s+/', ' ', $string); $string = preg_replace('/\s\s+/', ' ', $string);
$string = ltrim(rtrim($string)); $string = ltrim(rtrim($string));
return $string; return $string;
}
}
// 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]);
}
}
}

+ 15
- 1
themes/blog/main.html.php View File

@ -1,6 +1,20 @@
<?php if (!empty($breadcrumb)): ?> <?php if (!empty($breadcrumb)): ?>
<div class="breadcrumb"><?php echo $breadcrumb ?></div> <div class="breadcrumb"><?php echo $breadcrumb ?></div>
<?php endif; ?> <?php endif; ?>
<?php if (!empty($category)): ?>
<div class="section">
<div class="section-inner">
<div class="content">
<div class="item">
<h2 class="title"><?php echo $category->title;?></h2>
<div class="text-left">
<?php echo $category->body; ?>
</div><!--//desc-->
</div><!--//item-->
</div><!--//content-->
</div>
</div>
<?php endif; ?>
<?php $i = 0; $len = count($posts); ?> <?php $i = 0; $len = count($posts); ?>
<?php foreach ($posts as $p): ?> <?php foreach ($posts as $p): ?>
<?php if ($i == 0) { <?php if ($i == 0) {
@ -44,7 +58,7 @@
<h2 class="title" itemprop="headline"><a href="<?php echo $p->url;?>"><?php echo $p->title;?></a></h2> <h2 class="title" itemprop="headline"><a href="<?php echo $p->url;?>"><?php echo $p->title;?></a></h2>
<p class="meta"> <p class="meta">
<span class="date" itemprop="datePublished"><?php echo date('d F Y', $p->date) ?></span> - Posted in <span class="date" itemprop="datePublished"><?php echo date('d F Y', $p->date) ?></span> - Posted in
<span itemprop="articleSection"><?php echo $p->tag;?></span> by
<span itemprop="articleSection"><?php echo $p->category;?></span> by
<span itemprop="author"><a href="<?php echo $p->authorUrl;?>"><?php echo $p->author;?></a></span> <span itemprop="author"><a href="<?php echo $p->authorUrl;?>"><?php echo $p->author;?></a></span>
<?php if (disqus_count()) { ?> <?php if (disqus_count()) { ?>
with <span><i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#disqus_thread"> comments</a></span> with <span><i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#disqus_thread"> comments</a></span>


+ 3
- 2
themes/blog/post.html.php View File

@ -35,7 +35,7 @@
<h1 class="title" itemprop="headline"><?php echo $p->title;?></h1> <h1 class="title" itemprop="headline"><?php echo $p->title;?></h1>
<p class="meta"> <p class="meta">
<span class="date" itemprop="datePublished"><?php echo date('d F Y', $p->date) ?></span> - Posted in <span class="date" itemprop="datePublished"><?php echo date('d F Y', $p->date) ?></span> - Posted in
<span itemprop="articleSection"><?php echo $p->tag;?></span> by
<span itemprop="articleSection"><?php echo $p->category;?></span> by
<span itemprop="author"><a href="<?php echo $p->authorUrl;?>"><?php echo $p->author;?></a></span> <span itemprop="author"><a href="<?php echo $p->authorUrl;?>"><?php echo $p->author;?></a></span>
</p> </p>
</div> </div>
@ -43,6 +43,7 @@
<?php echo $p->body; ?> <?php echo $p->body; ?>
</div><!--//desc--> </div><!--//desc-->
<div style="margin-top:30px;position:relative;"> <div style="margin-top:30px;position:relative;">
<span class="tags"><i class="fa fa-tags"></i> <?php echo $p->tag;?></span>
<?php if (disqus_count()) { ?> <?php if (disqus_count()) { ?>
<span><i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#disqus_thread"> comments</a></span> <span><i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#disqus_thread"> comments</a></span>
<?php } elseif (facebook()) { ?> <?php } elseif (facebook()) { ?>
@ -71,7 +72,7 @@
<?php if (disqus_count()): ?> <?php if (disqus_count()): ?>
<?php echo disqus_count() ?> <?php echo disqus_count() ?>
<?php endif; ?> <?php endif; ?>
<?php $tags = get_related($p->tag, true, config('related.count'));?>
<?php $tags = get_related($p->related, true, config('related.count'));?>
<?php $char = 30; $total = count($tags); $i = 1; if ($total >= 1) { ?> <?php $char = 30; $total = count($tags); $i = 1; if ($total >= 1) { ?>
<div class="related related-posts" style="margin-top:30px;position:relative;"> <div class="related related-posts" style="margin-top:30px;position:relative;">
<hr> <hr>


+ 1
- 1
themes/blog/profile.html.php View File

@ -24,7 +24,7 @@
$i++; ?> $i++; ?>
<li class="<?php echo $class; ?>"> <li class="<?php echo $class; ?>">
<span><a href="<?php echo $p->url ?>"><?php echo $p->title ?></a></span> on <span><a href="<?php echo $p->url ?>"><?php echo $p->title ?></a></span> on
<span><?php echo date('d F Y', $p->date) ?></span> - Posted in <span><?php echo $p->tag ?></span>
<span><?php echo date('d F Y', $p->date) ?></span> - Posted in <span><?php echo $p->category ?></span>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>


+ 1
- 1
themes/clean/post.html.php View File

@ -60,7 +60,7 @@
</div> </div>
<div class="related"> <div class="related">
<h4>Related posts</h4> <h4>Related posts</h4>
<?php echo get_related($p->tag)?>
<?php echo get_related($p->related)?>
</div> </div>
<div id="comments" class="comments border"> <div id="comments" class="comments border">
<?php if (facebook()): ?> <?php if (facebook()): ?>


+ 1
- 1
themes/default/post.html.php View File

@ -57,7 +57,7 @@
</div> </div>
<div class="related"> <div class="related">
<h4>Related posts</h4> <h4>Related posts</h4>
<?php echo get_related($p->tag)?>
<?php echo get_related($p->related)?>
</div> </div>
<div id="comments" class="comments border"> <div id="comments" class="comments border">
<?php if (facebook()): ?> <?php if (facebook()): ?>


+ 1
- 1
themes/logs/post.html.php View File

@ -60,7 +60,7 @@
</div> </div>
<div class="related"> <div class="related">
<h4>Related posts</h4> <h4>Related posts</h4>
<?php echo get_related($p->tag)?>
<?php echo get_related($p->related)?>
</div> </div>
<div id="comments" class="comments border"> <div id="comments" class="comments border">
<?php if (facebook()): ?> <?php if (facebook()): ?>


Loading…
Cancel
Save