diff --git a/system/admin/views/categories.html.php b/system/admin/views/categories.html.php index 12d8564..cc72d32 100644 --- a/system/admin/views/categories.html.php +++ b/system/admin/views/categories.html.php @@ -2,7 +2,6 @@


diff --git a/system/admin/views/category-list.html.php b/system/admin/views/category-list.html.php index 4b8bc2d..b3548db 100644 --- a/system/admin/views/category-list.html.php +++ b/system/admin/views/category-list.html.php @@ -11,20 +11,8 @@ - - - + title ?> date) ?> url !== site_url() . 'category/uncategorized') {?> diff --git a/system/htmly.php b/system/htmly.php index 65d5193..54a5279 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -1826,8 +1826,8 @@ get('/admin/categories/:category', function ($category) { $desc = get_category_info($category); - if(strtolower($category) !== 'uncategorized') { - $desc = $desc[0]; + if(!empty($desc)) { + $desc = $desc[0]; } $total = $desc->count; @@ -1885,10 +1885,9 @@ get('/category/:category', function ($category) { $desc = get_category_info($category); - if(strtolower($category) !== 'uncategorized') { - if(!empty($desc)) { - $desc = $desc[0]; - } + + if(!empty($desc)) { + $desc = $desc[0]; } $total = $desc->count; @@ -1953,10 +1952,8 @@ get('/category/:category/feed', function ($category) { $data = get_category_info($category); - if(strtolower($category) !== 'uncategorized') { - if(!empty($data)) { - $data = $data[0]; - } + if(!empty($data)) { + $data = $data[0]; } // Show an RSS feed diff --git a/system/includes/functions.php b/system/includes/functions.php index 48d0e49..ba3cd05 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -173,7 +173,7 @@ function get_category_files() { static $_desc = array(); if (empty($_desc)) { - $url = 'cache/index/index-category.txt'; + $url = 'cache/index/index-category-files.txt'; if (!file_exists($url)) { rebuilt_cache('all'); } @@ -198,6 +198,20 @@ function get_category_folder() return $_dfolder; } +// Get category info files. +function get_category_slug() +{ + static $_cslug = array(); + if (empty($_cslug)) { + $url = 'cache/index/index-category.txt'; + if (!file_exists($url)) { + rebuilt_cache('all'); + } + $_cslug = unserialize(file_get_contents($url)); + } + return $_cslug; +} + // Get images in content/images folder function get_gallery() { static $_gallery = array(); @@ -241,6 +255,8 @@ function rebuilt_cache($type = null) $subpage_cache = array(); $author_cache = array(); $scheduled = array(); + $category_cache = array(); + $ctmp = array(); if (is_dir($dir) === false) { mkdir($dir, 0775, true); @@ -260,6 +276,13 @@ function rebuilt_cache($type = null) $string_posts = serialize($posts_cache); file_put_contents('cache/index/index-posts.txt', print_r($string_posts, true)); + // Collect category slug + foreach ($posts_cache as $key => $c) { + $cd = explode('/', $c['dirname']); + $ctmp[] = $cd[3]; + } + file_put_contents('cache/index/index-category.txt', print_r(serialize(array_unique($ctmp, SORT_REGULAR)), true)); + // Rebuilt static page index $ptmp = array(); $ptmp = glob('content/static/*.md', GLOB_NOSORT); @@ -300,7 +323,7 @@ function rebuilt_cache($type = null) $author_string = serialize($author_cache); file_put_contents('cache/index/index-author.txt', print_r($author_string, true)); - // Rebuilt category index + // Rebuilt category files index $ctmp = array(); $ctmp = glob('content/data/category/*.md', GLOB_NOSORT); if (is_array($ctmp)) { @@ -310,7 +333,7 @@ function rebuilt_cache($type = null) } usort($category_cache, "sortfile_a"); $category_string = serialize($category_cache); - file_put_contents('cache/index/index-category.txt', print_r($category_string, true)); + file_put_contents('cache/index/index-category-files.txt', print_r($category_string, true)); // Rebuilt scheduled posts index $stmp = array(); @@ -837,21 +860,44 @@ function get_category($category, $page, $perpage, $random = null) } // Return category info. -function get_category_info($category) +function get_category_info($category = null) { $tmp = array(); - if (is_null($category)) { - $tmp[] = default_category(); - } elseif (strtolower($category) == 'uncategorized') { - return default_category(); + $cslug= get_category_slug(); + + if (!empty($cslug)) { + if (is_null($category)) { + foreach ($cslug as $key => $c){ + $ctmp = read_category_info($c); + if (!empty($ctmp[0])) { + $tmp[] = $ctmp[0]; + } else { + $tmp[] = default_category($c); + } + } + } else { + foreach ($cslug as $key => $c){ + if ($c === $category) { + $ctmp = read_category_info($category); + if (!empty($ctmp[0])) { + $tmp[] = $ctmp[0]; + } else { + $tmp[] = default_category($category); + } + } + } + } } - - $posts = get_category_files(); - - if (!empty($posts)) { + return $tmp; +} - foreach ($posts as $index => $v) { +function read_category_info($category) +{ + $cFiles = get_category_files(); + $tmp = array(); + if (!empty($cFiles)) { + foreach ($cFiles as $index => $v) { if (stripos($v['basename'], $category . '.md') !== false) { $desc = new stdClass; @@ -883,27 +929,37 @@ function get_category_info($category) $desc->description = get_content_tag("d", $content, get_description($desc->body)); $tmp[] = $desc; - } + } } } - - return $tmp; + return $tmp; } // Return default category -function default_category() +function default_category($category = null) { $tmp = array(); $desc = new stdClass; - $desc->title = i18n("Uncategorized"); - $desc->url = site_url() . 'category/uncategorized'; - $desc->slug = 'uncategorized'; - $desc->body = '

' . i18n('Uncategorized_comment') . '

'; - $desc->md = 'uncategorized'; - $desc->description = i18n('Uncategorized_comment'); - $desc->file = ''; - $desc->count = get_categorycount($desc->md); + if ($category == 'uncategorized') { + $desc->title = i18n("Uncategorized"); + $desc->url = site_url() . 'category/uncategorized'; + $desc->slug = 'uncategorized'; + $desc->body = '

' . i18n('Uncategorized_comment') . '

'; + $desc->md = 'uncategorized'; + $desc->description = i18n('Uncategorized_comment'); + $desc->file = ''; + $desc->count = get_categorycount($desc->md); + } else { + $desc->title = $category; + $desc->url = site_url() . 'category/' . $category; + $desc->slug = $category; + $desc->body = '

' . i18n('All_blog_posts') . ': ' . $category . '

'; + $desc->md = $category; + $desc->description = i18n('All_blog_posts') . ': ' . $category; + $desc->file = ''; + $desc->count = get_categorycount($category); + } return $tmp[] = $desc; } @@ -925,11 +981,10 @@ function category_list($custom = null) { $cat = unserialize(file_get_contents($filename)); } else { $arr = get_category_info(null); - foreach ($arr as $a) { - $cat[] = array($a->md, $a->title, $a->count); + foreach ($arr as $i => $a) { + $cat[] = array($a->md, $a->title, $a->count, $a->description); } - asort($cat); $tmp = serialize($cat); file_put_contents($filename, print_r($tmp, true)); }