diff --git a/system/admin/admin.php b/system/admin/admin.php index 5e294f4..6ac677e 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -402,8 +402,8 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ $time = new DateTime($t); $timestamp = $time->format("Y-m-d"); } else { - $replaced = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/'; - $dt = str_replace($replaced, '', $oldurl[0]); + $dirname = dirname($oldurl[0]) . '/'; + $dt = str_replace($dirname, '', $oldurl[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); $timestamp = $time->format("Y-m-d"); @@ -593,14 +593,14 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr rebuilt_cache('all'); clear_page_cache($post_url); - + if ($oldfile != $newfile) { if (file_exists($viewsFile)) { $views = json_decode(file_get_contents($viewsFile), true); $arr = replace_key($views, $oldfile, $newfile); file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE)); } - } + } if ($destination == 'post') { header("Location: $posturl"); diff --git a/system/admin/views/add-content.html.php b/system/admin/views/add-content.html.php index 4c7702c..25aa1f3 100644 --- a/system/admin/views/add-content.html.php +++ b/system/admin/views/add-content.html.php @@ -98,7 +98,6 @@ $( function() {
- diff --git a/system/htmly.php b/system/htmly.php index a806c5a..f7d75dc 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -1741,16 +1741,16 @@ get('/admin/categories/:category', function ($category) { $perpage = 10; } - $posts = get_category($category, $page, $perpage, false); + $posts = get_category($category, $page, $perpage); $desc = get_category_info($category); if(strtolower($category) !== 'uncategorized') { $desc = $desc[0]; } - - $total = get_categorycount($category); - + + $total = $desc->count; + if (empty($posts) || $page < 1) { // a non-existing page not_found(); @@ -1805,7 +1805,7 @@ get('/category/:category', function ($category) { $perpage = 10; } - $posts = get_category($category, $page, $perpage, false); + $posts = get_category($category, $page, $perpage); $desc = get_category_info($category); @@ -1815,7 +1815,7 @@ get('/category/:category', function ($category) { } } - $total = get_categorycount($category); + $total = $desc->count; if (empty($posts) || $page < 1) { // a non-existing page @@ -2008,7 +2008,10 @@ get('/type/:type', function ($type) { $total = get_typecount($type); $ttype = new stdClass; - $ttype->title = $type; + $ttype->title = ucfirst($type); + $ttype->url = site_url() . 'type/' . strtolower($type); + $ttype->count = $total; + $ttype->description = i18n('Posts_with_type') . ' ' . ucfirst($type) . ' ' . i18n('by') . ' ' . blog_title() . '.'; if (empty($posts) || $page < 1) { // a non-existing page @@ -2068,12 +2071,15 @@ get('/tag/:tag', function ($tag) { $page = $page ? (int)$page : 1; $perpage = config('tag.perpage'); - $posts = get_tag($tag, $page, $perpage, false); + $posts = get_tag($tag, $page, $perpage); - $total = get_tagcount($tag, 'basename'); + $total = get_tagcount($tag); $ttag = new stdClass; $ttag->title = tag_i18n($tag); + $ttag->url = site_url() . 'tag/' . strtolower($tag); + $ttag->count = $total; + $ttag->description = i18n('All_posts_tagged') . ' ' . tag_i18n($tag) . ' ' . i18n('by') . ' ' . blog_title() . '.'; if (empty($posts) || $page < 1) { // a non-existing page @@ -2135,7 +2141,7 @@ get('/archive/:req', function ($req) { $posts = get_archive($req, $page, $perpage); - $total = get_count($req, 'basename'); + $total = get_count($req); if (empty($posts) || $page < 1) { // a non-existing page @@ -2155,7 +2161,10 @@ get('/archive/:req', function ($req) { $tarchive = new stdClass; $tarchive->title = $timestamp; - + $tarchive->url = site_url() . 'archive/' . $req; + $tarchive->count = $total; + $tarchive->description = i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title() . '.'; + if (!$date) { // a non-existing page not_found(); @@ -2179,7 +2188,7 @@ get('/archive/:req', function ($req) { render($pview, array( 'title' => i18n('Archive_for') . ' ' . $timestamp . ' - ' . blog_title(), - 'description' =>i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title() . '.', + 'description' => i18n('Archive_page_for') . ' ' . $timestamp . ' ' . i18n('by') . ' ' . blog_title() . '.', 'canonical' => site_url() . 'archive/' . $req, 'page' => $page, 'posts' => $posts, @@ -2209,9 +2218,13 @@ get('/search/:keyword', function ($keyword) { $perpage = config('search.perpage'); $posts = get_keyword($keyword, $page, $perpage); - + $total = keyword_count($keyword); + $tsearch = new stdClass; $tsearch->title = $keyword; + $tsearch->url = site_url() . 'search/' . strtolower($keyword); + $tsearch->count = $total; + $tsearch->description = i18n('Search_results_for') . ' ' . tag_i18n($keyword) . ' ' . i18n('by') . ' ' . blog_title() . '.'; $vroot = rtrim(config('views.root'), '/'); @@ -2235,8 +2248,6 @@ get('/search/:keyword', function ($keyword) { ), $layout); die; } - - $total = keyword_count($keyword); $pv = $vroot . '/main--search.html.php'; if (file_exists($pv)) { diff --git a/system/includes/functions.php b/system/includes/functions.php index e7d24bb..c0ff7f4 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -281,7 +281,7 @@ function get_posts($posts, $page = 1, $perpage = 0) // Extract a specific page with results $posts = array_slice($posts, ($page - 1) * $perpage, $perpage); - $catC = category_list(true); + $cList = category_list(true); foreach ($posts as $index => $v) { @@ -292,33 +292,25 @@ function get_posts($posts, $page = 1, $perpage = 0) // Extract the date $arr = explode('_', $v['basename']); - // Replaced string - $replaced = $v['dirname'] . '/'; + // dirname string + $dirname = $v['dirname'] . '/'; // Author string - $str = explode('/', $replaced); + $str = explode('/', $dirname); $author = $str[1]; - if($str[3] == 'uncategorized') { - $category = default_category(); - $post->category = '' . $category->title . ''; - $post->categoryUrl = $category->url; - $post->categorySlug = $category->slug; - $post->categoryTitle = $category->title; - $post->categoryb = '' . $category->title . ''; - } else { - foreach ($catC as $k => $v) { - if ($v['0'] === $str[3]) { - $post->category = '' . $v['1'] . ''; - $post->categoryUrl = site_url() . 'category/' . $v['0']; - $post->categorySlug = $v['0']; - $post->categoryTitle = $v['1']; - $post->categoryb = '' . $v['1'] . ''; - } + foreach ($cList as $a => $t) { + if ($t['0'] === $str[3]) { + $post->category = '' . $t['1'] . ''; + $post->categoryUrl = site_url() . 'category/' . $t['0']; + $post->categoryCount = $t['2']; + $post->categorySlug = $t['0']; + $post->categoryMd = $t['0']; + $post->categoryTitle = $t['1']; + $post->categoryb = '' . $t['1'] . ''; } - } - + $type = $str[4]; $post->ct = $str[3]; @@ -336,7 +328,7 @@ function get_posts($posts, $page = 1, $perpage = 0) } $post->type = $type; - $dt = str_replace($replaced, '', $arr[0]); + $dt = str_replace($dirname, '', $arr[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); $timestamp = $time->format("Y-m-d H:i:s"); @@ -568,7 +560,7 @@ function find_scheduled($year, $month, $name) } // Return category page. -function get_category($category, $page, $perpage, $random) +function get_category($category, $page, $perpage, $random = null) { $posts = get_post_sorted(); @@ -584,10 +576,10 @@ function get_category($category, $page, $perpage, $random) foreach ($posts as $index => $v) { - // Replaced string - $replaced = $v['dirname'] . '/'; + // dirname string + $dirname = $v['dirname'] . '/'; - $str = explode('/', $replaced); + $str = explode('/', $dirname); if (strtolower($category) === strtolower($str[3])) { $tmp[] = $v; @@ -605,10 +597,16 @@ function get_category($category, $page, $perpage, $random) // Return category info. function get_category_info($category) -{ - $posts = get_category_files(); +{ $tmp = array(); + if (is_null($category)) { + $tmp[] = default_category(); + } elseif (strtolower($category) == 'uncategorized') { + return default_category(); + } + + $posts = get_category_files(); if (!empty($posts)) { @@ -617,15 +615,16 @@ function get_category_info($category) $desc = new stdClass; - // Replaced string - $replaced = dirname($v) . '/'; - // The static page URL $url= pathinfo($v, PATHINFO_FILENAME); $desc->url = site_url() . 'category/' . $url; $desc->md = $url; + + $desc->slug = $url; + + $desc->count = get_categorycount($url); $desc->file = $v; @@ -645,13 +644,6 @@ function get_category_info($category) } } - if (is_null($category)) { - $category = ''; - } - if (strtolower($category) == 'uncategorized') { - return default_category(); - } - return $tmp; } @@ -667,6 +659,8 @@ function default_category() $desc->body = '

' . i18n('Uncategorized_comment') . '

'; $desc->md = 'uncategorized'; $desc->description = i18n('Uncategorized_comment'); + $desc->file = ''; + $desc->count = get_categorycount($desc->md); return $tmp[] = $desc; } @@ -690,9 +684,9 @@ function category_list($custom = null) { } else { $arr = get_category_info(null); foreach ($arr as $a) { - $cat[] = array($a->md, $a->title); + $cat[] = array($a->md, $a->title, $a->count); } - array_push($cat, array('uncategorized', i18n('Uncategorized'))); + asort($cat); $tmp = serialize($cat); file_put_contents($filename, print_r($tmp, true)); @@ -705,8 +699,8 @@ function category_list($custom = null) { echo ''; } + } elseif ($custom == 'month-year') { + foreach ($by_year as $year => $months) { + $by_month = array_count_values($months); + # Sort the months + krsort($by_month); + foreach ($by_month as $month => $count) { + $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F'); + echo '
  • ' . $name . ' ' . $year .' ('.$count.')
  • '; + } + } + } elseif ($custom == 'year') { + foreach ($by_year as $year => $months) { + $by_month = array_count_values($months); + # Sort the months + krsort($by_month); + echo '
  • ' . $year .' ('. count($months) .')
  • '; + } } else { return $by_year; } @@ -1628,7 +1633,6 @@ function has_prev($prev) 'body' => $prev->body, 'description' => $prev->description, 'tag' => $prev->tag, - 'category' => $prev->category, 'author' => $prev->author, 'authorName' => $prev->authorName, 'authorAbout' => $prev->authorAbout, @@ -1642,7 +1646,12 @@ function has_prev($prev) 'audio' => $prev->audio, 'quote' => $prev->quote, 'link' => $prev->link, + 'category' => $prev->category, 'categoryUrl' => $prev->categoryUrl, + 'categoryCount' => $prev->categoryCount, + 'categorySlug' => $prev->categorySlug, + 'categoryMd' => $prev->categoryMd, + 'categoryTitle' => $prev->categoryTitle, 'readTime' => $prev->readTime, 'lastMod' => $prev->lastMod ); @@ -1661,7 +1670,6 @@ function has_next($next) 'body' => $next->body, 'description' => $next->description, 'tag' => $next->tag, - 'category' => $next->category, 'author' => $next->author, 'authorName' => $next->authorName, 'authorAbout' => $next->authorAbout, @@ -1675,7 +1683,12 @@ function has_next($next) 'audio' => $next->audio, 'quote' => $next->quote, 'link' => $next->link, + 'category' => $next->category, 'categoryUrl' => $next->categoryUrl, + 'categoryCount' => $next->categoryCount, + 'categorySlug' => $next->categorySlug, + 'categoryMd' => $next->categoryMd, + 'categoryTitle' => $next->categoryTitle, 'readTime' => $next->readTime, 'lastMod' => $next->lastMod ); @@ -2261,11 +2274,10 @@ function get_title_from_file($v) // Get the contents and convert it to HTML $content = MarkdownExtra::defaultTransform(file_get_contents($v)); - $replaced = substr($v, 0, strrpos($v, '/')) . '/'; - $base = str_replace($replaced, '', $v); + $filename= pathinfo($v, PATHINFO_FILENAME); // Extract the title and body - return get_content_tag('t', $content, str_replace('-', ' ', str_replace('.md', '', $base))); + return get_content_tag('t', $content, str_replace('-', ' ', $filename)); } // Auto generate menu from static page @@ -2305,21 +2317,20 @@ function get_menu($custom) } $i++; - // Replaced string - $replaced = substr($v, 0, strrpos($v, '/')) . '/'; - $base = str_replace($replaced, '', $v); - $url = site_url() . str_replace('.md', '', $base); + // Filename string + $filename= pathinfo($v, PATHINFO_FILENAME); + $url = site_url() . $filename; $title = get_title_from_file($v); - if ($req == site_path() . "/" . str_replace('.md', '', $base) || stripos($req, site_path() . "/" . str_replace('.md', '', $base)) !== false) { + if ($req == site_path() . "/" . $filename || stripos($req, site_path() . "/" . $filename) !== false) { $active = ' active'; $reqBase = ''; } else { $active = ''; } - $subPages = get_static_sub_pages(str_replace('.md', '', $base)); + $subPages = get_static_sub_pages($filename); if (!empty($subPages)) { asort($subPages); echo '
  • ' . get_title_from_file($sp) . '
  • '; $iSub++; } @@ -2475,23 +2485,21 @@ function sitemap_post_path() $post = new stdClass; - $post = new stdClass; - $filepath = $v['dirname'] . '/' . $v['basename']; // Extract the date $arr = explode('_', $v['basename']); - // Replaced string - $replaced = $v['dirname'] . '/'; + // dirname string + $dirname = $v['dirname'] . '/'; // Author string - $str = explode('/', $replaced); + $str = explode('/', $dirname); $author = $str[1]; $post->authorUrl = site_url() . 'author/' . $author; - $dt = str_replace($replaced, '', $arr[0]); + $dt = str_replace($dirname, '', $arr[0]); $t = str_replace('-', '', $dt); $time = new DateTime($t); $timestamp = $time->format("Y-m-d H:i:s"); @@ -2535,13 +2543,10 @@ function sitemap_page_path() $post = new stdClass; - // Replaced string - $replaced = substr($v, 0, strrpos($v, '/')) . '/'; - - // The static page URL - $url = str_replace($replaced, '', $v); - $post->url = site_url() . str_replace('.md', '', $url); - $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($v))); + // Filename + $filename= pathinfo($v, PATHINFO_FILENAME); + $post->url = site_url() . $filename; + $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($v))); $tmp[] = $post; } @@ -2662,7 +2667,6 @@ function generate_sitemap($str) foreach ($posts as $index => $v) { $arr = explode('_', $v); - $data = $arr[1]; $mtag = explode(',', $data); foreach ($mtag as $etag) { @@ -2771,8 +2775,8 @@ function generate_sitemap($str) if($posts) { foreach ($posts as $index => $v) { - $replaced = dirname($v) . '/'; - $str = explode('/', $replaced); + $dirname = dirname($v) . '/'; + $str = explode('/', $dirname); $cats[] = $str[3]; } @@ -2809,8 +2813,8 @@ function generate_sitemap($str) if($posts) { foreach ($posts as $index => $v) { - $replaced = dirname($v) . '/'; - $str = explode('/', $replaced); + $dirname = dirname($v) . '/'; + $str = explode('/', $dirname); $types[] = $str[4]; }