Browse Source

Cleaning up

pull/663/head
danpros 2 years ago
parent
commit
98d5a4a650
6 changed files with 138 additions and 128 deletions
  1. +4
    -4
      system/admin/admin.php
  2. +0
    -1
      system/admin/views/add-content.html.php
  3. +5
    -8
      system/admin/views/categories.html.php
  4. +0
    -1
      system/admin/views/edit-content.html.php
  5. +26
    -15
      system/htmly.php
  6. +103
    -99
      system/includes/functions.php

+ 4
- 4
system/admin/admin.php View File

@ -402,8 +402,8 @@ function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publ
$time = new DateTime($t); $time = new DateTime($t);
$timestamp = $time->format("Y-m-d"); $timestamp = $time->format("Y-m-d");
} else { } 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); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
$timestamp = $time->format("Y-m-d"); $timestamp = $time->format("Y-m-d");
@ -593,14 +593,14 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr
rebuilt_cache('all'); rebuilt_cache('all');
clear_page_cache($post_url); clear_page_cache($post_url);
if ($oldfile != $newfile) { if ($oldfile != $newfile) {
if (file_exists($viewsFile)) { if (file_exists($viewsFile)) {
$views = json_decode(file_get_contents($viewsFile), true); $views = json_decode(file_get_contents($viewsFile), true);
$arr = replace_key($views, $oldfile, $newfile); $arr = replace_key($views, $oldfile, $newfile);
file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE)); file_put_contents($viewsFile, json_encode($arr, JSON_UNESCAPED_UNICODE));
} }
}
}
if ($destination == 'post') { if ($destination == 'post') {
header("Location: $posturl"); header("Location: $posturl");


+ 0
- 1
system/admin/views/add-content.html.php View File

@ -98,7 +98,6 @@ $( function() {
<br> <br>
<label for="pCategory"><?php echo i18n('Category');?> <span class="required">*</span></label> <label for="pCategory"><?php echo i18n('Category');?> <span class="required">*</span></label>
<select id="pCategory" class="form-control" name="category"> <select id="pCategory" class="form-control" name="category">
<option value="uncategorized"><?php echo i18n("Uncategorized");?></option>
<?php foreach ($desc as $d):?> <?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>"><?php echo $d->title;?></option> <option value="<?php echo $d->md;?>"><?php echo $d->title;?></option>
<?php endforeach;?> <?php endforeach;?>


+ 5
- 8
system/admin/views/categories.html.php View File

@ -2,6 +2,7 @@
<?php <?php
$desc = get_category_info(null); $desc = get_category_info(null);
asort($desc); asort($desc);
?> ?>
<h2><?php echo i18n("Categories");?></h2> <h2><?php echo i18n("Categories");?></h2>
<br> <br>
@ -14,18 +15,14 @@ asort($desc);
<th><?php echo i18n('Contents');?></th> <th><?php echo i18n('Contents');?></th>
<th><?php echo i18n('Operations');?></th> <th><?php echo i18n('Operations');?></th>
</tr> </tr>
<tr>
<td><a href="<?php echo site_url();?>admin/categories/uncategorized"><?php echo i18n("Uncategorized");?></a></td>
<td><p><?php echo i18n('Uncategorized_comment');?>.</p></td>
<td><?php $total = get_draftcount('uncategorized') + get_categorycount('uncategorized') + get_scheduledcount('uncategorized'); echo $total?></td>
<td></td>
</tr>
<?php foreach ($desc as $d):?> <?php foreach ($desc as $d):?>
<tr> <tr>
<td><a href="<?php echo site_url();?>admin/categories/<?php echo $d->md;?>"><?php echo $d->title;?></a></td> <td><a href="<?php echo site_url();?>admin/categories/<?php echo $d->md;?>"><?php echo $d->title;?></a></td>
<td><?php echo $d->body;?></td> <td><?php echo $d->body;?></td>
<td><?php $total = get_draftcount($d->md) + get_categorycount($d->md) + get_scheduledcount($d->md); echo $total?></td>
<td><a class="btn btn-primary btn-xs" href="<?php echo $d->url;?>/edit?destination=admin/categories"><?php echo i18n('Edit');?></a> <?php if (get_categorycount($d->md) == 0 && get_draftcount($d->md) == 0 ){echo '<a class="btn btn-danger btn-xs" href="' . $d->url . '/delete?destination=admin/categories">' . i18n('Delete') . '</a>';}?></td>
<td><?php $total = get_draftcount($d->md) + $d->count + get_scheduledcount($d->md); echo $total?></td>
<?php if($d->md !== 'uncategorized'):?>
<td><a class="btn btn-primary btn-xs" href="<?php echo $d->url;?>/edit?destination=admin/categories"><?php echo i18n('Edit');?></a> <?php if ($d->count == 0 && get_draftcount($d->md) == 0 && get_scheduledcount($d->md) == 0){echo '<a class="btn btn-danger btn-xs" href="' . $d->url . '/delete?destination=admin/categories">' . i18n('Delete') . '</a>';}?></td>
<?php endif;?>
</tr> </tr>
<?php endforeach;?> <?php endforeach;?>
</table> </table>

+ 0
- 1
system/admin/views/edit-content.html.php View File

@ -147,7 +147,6 @@ $( function() {
<br> <br>
<label for="pCategory"><?php echo i18n('Category');?> <span class="required">*</span></label> <label for="pCategory"><?php echo i18n('Category');?> <span class="required">*</span></label>
<select id="pCategory" class="form-control" name="category"> <select id="pCategory" class="form-control" name="category">
<option value="uncategorized"><?php echo i18n("Uncategorized");?></option>
<?php foreach ($desc as $d):?> <?php foreach ($desc as $d):?>
<option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option> <option value="<?php echo $d->md;?>" <?php if($category === $d->md) { echo 'selected="selected"';} ?>><?php echo $d->title;?></option>
<?php endforeach;?> <?php endforeach;?>


+ 26
- 15
system/htmly.php View File

@ -1741,16 +1741,16 @@ get('/admin/categories/:category', function ($category) {
$perpage = 10; $perpage = 10;
} }
$posts = get_category($category, $page, $perpage, false);
$posts = get_category($category, $page, $perpage);
$desc = get_category_info($category); $desc = get_category_info($category);
if(strtolower($category) !== 'uncategorized') { if(strtolower($category) !== 'uncategorized') {
$desc = $desc[0]; $desc = $desc[0];
} }
$total = get_categorycount($category);
$total = $desc->count;
if (empty($posts) || $page < 1) { if (empty($posts) || $page < 1) {
// a non-existing page // a non-existing page
not_found(); not_found();
@ -1805,7 +1805,7 @@ get('/category/:category', function ($category) {
$perpage = 10; $perpage = 10;
} }
$posts = get_category($category, $page, $perpage, false);
$posts = get_category($category, $page, $perpage);
$desc = get_category_info($category); $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) { if (empty($posts) || $page < 1) {
// a non-existing page // a non-existing page
@ -2008,7 +2008,10 @@ get('/type/:type', function ($type) {
$total = get_typecount($type); $total = get_typecount($type);
$ttype = new stdClass; $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) { if (empty($posts) || $page < 1) {
// a non-existing page // a non-existing page
@ -2068,12 +2071,15 @@ get('/tag/:tag', function ($tag) {
$page = $page ? (int)$page : 1; $page = $page ? (int)$page : 1;
$perpage = config('tag.perpage'); $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 = new stdClass;
$ttag->title = tag_i18n($tag); $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) { if (empty($posts) || $page < 1) {
// a non-existing page // a non-existing page
@ -2135,7 +2141,7 @@ get('/archive/:req', function ($req) {
$posts = get_archive($req, $page, $perpage); $posts = get_archive($req, $page, $perpage);
$total = get_count($req, 'basename');
$total = get_count($req);
if (empty($posts) || $page < 1) { if (empty($posts) || $page < 1) {
// a non-existing page // a non-existing page
@ -2155,7 +2161,10 @@ get('/archive/:req', function ($req) {
$tarchive = new stdClass; $tarchive = new stdClass;
$tarchive->title = $timestamp; $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) { if (!$date) {
// a non-existing page // a non-existing page
not_found(); not_found();
@ -2179,7 +2188,7 @@ get('/archive/:req', function ($req) {
render($pview, array( render($pview, array(
'title' => i18n('Archive_for') . ' ' . $timestamp . ' - ' . blog_title(), '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, 'canonical' => site_url() . 'archive/' . $req,
'page' => $page, 'page' => $page,
'posts' => $posts, 'posts' => $posts,
@ -2209,9 +2218,13 @@ get('/search/:keyword', function ($keyword) {
$perpage = config('search.perpage'); $perpage = config('search.perpage');
$posts = get_keyword($keyword, $page, $perpage); $posts = get_keyword($keyword, $page, $perpage);
$total = keyword_count($keyword);
$tsearch = new stdClass; $tsearch = new stdClass;
$tsearch->title = $keyword; $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'), '/'); $vroot = rtrim(config('views.root'), '/');
@ -2235,8 +2248,6 @@ get('/search/:keyword', function ($keyword) {
), $layout); ), $layout);
die; die;
} }
$total = keyword_count($keyword);
$pv = $vroot . '/main--search.html.php'; $pv = $vroot . '/main--search.html.php';
if (file_exists($pv)) { if (file_exists($pv)) {


+ 103
- 99
system/includes/functions.php View File

@ -281,7 +281,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
// Extract a specific page with results // Extract a specific page with results
$posts = array_slice($posts, ($page - 1) * $perpage, $perpage); $posts = array_slice($posts, ($page - 1) * $perpage, $perpage);
$catC = category_list(true);
$cList = category_list(true);
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
@ -292,33 +292,25 @@ function get_posts($posts, $page = 1, $perpage = 0)
// Extract the date // Extract the date
$arr = explode('_', $v['basename']); $arr = explode('_', $v['basename']);
// Replaced string
$replaced = $v['dirname'] . '/';
// dirname string
$dirname = $v['dirname'] . '/';
// Author string // Author string
$str = explode('/', $replaced);
$str = explode('/', $dirname);
$author = $str[1]; $author = $str[1];
if($str[3] == 'uncategorized') {
$category = default_category();
$post->category = '<a href="' . $category->url . '">' . $category->title . '</a>';
$post->categoryUrl = $category->url;
$post->categorySlug = $category->slug;
$post->categoryTitle = $category->title;
$post->categoryb = '<a itemprop="item" href="' . $category->url . '"><span itemprop="name">' . $category->title . '</span></a>';
} else {
foreach ($catC as $k => $v) {
if ($v['0'] === $str[3]) {
$post->category = '<a href="' . site_url() . 'category/' . $v['0'] . '">' . $v['1'] . '</a>';
$post->categoryUrl = site_url() . 'category/' . $v['0'];
$post->categorySlug = $v['0'];
$post->categoryTitle = $v['1'];
$post->categoryb = '<a itemprop="item" href="' . site_url() . 'category/' . $v['0'] . '"><span itemprop="name">' . $v['1'] . '</span></a>';
}
foreach ($cList as $a => $t) {
if ($t['0'] === $str[3]) {
$post->category = '<a href="' . site_url() . 'category/' . $t['0'] . '">' . $t['1'] . '</a>';
$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 = '<a itemprop="item" href="' . site_url() . 'category/' . $t['0'] . '"><span itemprop="name">' . $t['1'] . '</span></a>';
} }
} }
$type = $str[4]; $type = $str[4];
$post->ct = $str[3]; $post->ct = $str[3];
@ -336,7 +328,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
} }
$post->type = $type; $post->type = $type;
$dt = str_replace($replaced, '', $arr[0]);
$dt = str_replace($dirname, '', $arr[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
$timestamp = $time->format("Y-m-d H:i:s"); $timestamp = $time->format("Y-m-d H:i:s");
@ -568,7 +560,7 @@ function find_scheduled($year, $month, $name)
} }
// Return category page. // Return category page.
function get_category($category, $page, $perpage, $random)
function get_category($category, $page, $perpage, $random = null)
{ {
$posts = get_post_sorted(); $posts = get_post_sorted();
@ -584,10 +576,10 @@ function get_category($category, $page, $perpage, $random)
foreach ($posts as $index => $v) { 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])) { if (strtolower($category) === strtolower($str[3])) {
$tmp[] = $v; $tmp[] = $v;
@ -605,10 +597,16 @@ function get_category($category, $page, $perpage, $random)
// Return category info. // Return category info.
function get_category_info($category) function get_category_info($category)
{
$posts = get_category_files();
{
$tmp = array(); $tmp = array();
if (is_null($category)) {
$tmp[] = default_category();
} elseif (strtolower($category) == 'uncategorized') {
return default_category();
}
$posts = get_category_files();
if (!empty($posts)) { if (!empty($posts)) {
@ -617,15 +615,16 @@ function get_category_info($category)
$desc = new stdClass; $desc = new stdClass;
// Replaced string
$replaced = dirname($v) . '/';
// The static page URL // The static page URL
$url= pathinfo($v, PATHINFO_FILENAME); $url= pathinfo($v, PATHINFO_FILENAME);
$desc->url = site_url() . 'category/' . $url; $desc->url = site_url() . 'category/' . $url;
$desc->md = $url; $desc->md = $url;
$desc->slug = $url;
$desc->count = get_categorycount($url);
$desc->file = $v; $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; return $tmp;
} }
@ -667,6 +659,8 @@ function default_category()
$desc->body = '<p>' . i18n('Uncategorized_comment') . '</p>'; $desc->body = '<p>' . i18n('Uncategorized_comment') . '</p>';
$desc->md = 'uncategorized'; $desc->md = 'uncategorized';
$desc->description = i18n('Uncategorized_comment'); $desc->description = i18n('Uncategorized_comment');
$desc->file = '';
$desc->count = get_categorycount($desc->md);
return $tmp[] = $desc; return $tmp[] = $desc;
} }
@ -690,9 +684,9 @@ function category_list($custom = null) {
} else { } else {
$arr = get_category_info(null); $arr = get_category_info(null);
foreach ($arr as $a) { 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); asort($cat);
$tmp = serialize($cat); $tmp = serialize($cat);
file_put_contents($filename, print_r($tmp, true)); file_put_contents($filename, print_r($tmp, true));
@ -705,8 +699,8 @@ function category_list($custom = null) {
echo '<ul>'; echo '<ul>';
foreach ($cat as $k => $v) { foreach ($cat as $k => $v) {
if (get_categorycount($v['0']) !== 0) {
echo '<li><a href="' . site_url() . 'category/' . $v['0'] . '">' . $v['1']. '</a></li>';
if ($v['2'] !== 0) {
echo '<li><a href="' . site_url() . 'category/' . $v['0'] . '">' . $v['1'] . '</a> <span>('. $v['2'] .')</span></li>';
} }
} }
@ -727,10 +721,10 @@ function get_type($type, $page, $perpage)
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
// Replaced string
$replaced = $v['dirname'] . '/';
// dirname string
$dirname = $v['dirname'] . '/';
$str = explode('/', $replaced);
$str = explode('/', $dirname);
if (strtolower($type) === strtolower($str[4])) { if (strtolower($type) === strtolower($str[4])) {
$tmp[] = $v; $tmp[] = $v;
@ -747,7 +741,7 @@ function get_type($type, $page, $perpage)
} }
// Return tag page. // Return tag page.
function get_tag($tag, $page, $perpage, $random)
function get_tag($tag, $page, $perpage, $random = null)
{ {
$posts = get_post_sorted(); $posts = get_post_sorted();
@ -885,11 +879,11 @@ function get_author($name)
$author = new stdClass; $author = new stdClass;
// Replaced string
$replaced = dirname($v) . '/';
// dirname string
$dirname = dirname($v) . '/';
// Author string // Author string
$str = explode('/', $replaced);
$str = explode('/', $dirname);
$profile = $str[1]; $profile = $str[1];
if ($name === $profile) { if ($name === $profile) {
@ -949,9 +943,6 @@ function get_static_post($static)
$post = new stdClass; $post = new stdClass;
// Replaced string
$replaced = dirname($v) . '/';
// The static page URL // The static page URL
$url= pathinfo($v, PATHINFO_FILENAME); $url= pathinfo($v, PATHINFO_FILENAME);
@ -1002,9 +993,6 @@ function get_static_sub_post($static, $sub_static)
$post = new stdClass; $post = new stdClass;
// Replaced string
$replaced = dirname($v) . '/';
// The static page URL // The static page URL
$url= pathinfo($v, PATHINFO_FILENAME); $url= pathinfo($v, PATHINFO_FILENAME);
$post->url = site_url() . $static . "/" . $url; $post->url = site_url() . $static . "/" . $url;
@ -1132,15 +1120,15 @@ function get_related($tag, $custom = null, $count = null)
} }
// Return post count. Matching $var and $str provided.
function get_count($var, $str)
// Return post count. Matching $var.
function get_count($var)
{ {
$posts = get_post_sorted(); $posts = get_post_sorted();
$tmp = array(); $tmp = array();
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$arr = explode('_', $v[$str]);
$arr = explode('_', $v['basename']);
$url = $arr[0]; $url = $arr[0];
if (stripos($url, "$var") !== false) { if (stripos($url, "$var") !== false) {
$tmp[] = $v; $tmp[] = $v;
@ -1150,7 +1138,7 @@ function get_count($var, $str)
return count($tmp); return count($tmp);
} }
// Return category count. Matching $var and $str provided.
// Return category count. Matching $var
function get_categorycount($var) function get_categorycount($var)
{ {
$posts = get_post_sorted(); $posts = get_post_sorted();
@ -1168,7 +1156,7 @@ function get_categorycount($var)
return count($tmp); return count($tmp);
} }
// Return type count. Matching $var and $str provided.
// Return type count. Matching $var
function get_typecount($var) function get_typecount($var)
{ {
$posts = get_post_sorted(); $posts = get_post_sorted();
@ -1187,7 +1175,7 @@ function get_typecount($var)
} }
// Return draft count. Matching $var and $str provided.
// Return draft count. Matching $var
function get_draftcount($var) function get_draftcount($var)
{ {
$posts = get_draft_posts(); $posts = get_draft_posts();
@ -1204,7 +1192,7 @@ function get_draftcount($var)
return count($tmp); return count($tmp);
} }
// Return draft count. Matching $var and $str provided.
// Return draft count. Matching $var
function get_scheduledcount($var) function get_scheduledcount($var)
{ {
$posts = get_scheduled_posts(); $posts = get_scheduled_posts();
@ -1223,15 +1211,15 @@ function get_scheduledcount($var)
} }
// Return tag count. Matching $var and $str provided.
function get_tagcount($var, $str)
// Return tag count. Matching $var
function get_tagcount($var)
{ {
$posts = get_post_sorted(); $posts = get_post_sorted();
$tmp = array(); $tmp = array();
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$arr = explode('_', $v[$str]);
$arr = explode('_', $v['basename']);
$mtag = explode(',', rtrim($arr[1], ',')); $mtag = explode(',', rtrim($arr[1], ','));
foreach ($mtag as $t) { foreach ($mtag as $t) {
if (strtolower($t) === strtolower($var)) { if (strtolower($t) === strtolower($var)) {
@ -1534,6 +1522,23 @@ EOF;
echo '</li>'; echo '</li>';
echo '</ul>'; echo '</ul>';
} }
} 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 '<li class="item"><a href="' . site_url() . 'archive/' . $year . '-' . $month . '">' . $name . ' ' . $year .'</a> ('.$count.')</li>';
}
}
} elseif ($custom == 'year') {
foreach ($by_year as $year => $months) {
$by_month = array_count_values($months);
# Sort the months
krsort($by_month);
echo '<li class="item"><a href="' . site_url() . 'archive/' . $year . '">' . $year .'</a> ('. count($months) .')</li>';
}
} else { } else {
return $by_year; return $by_year;
} }
@ -1628,7 +1633,6 @@ function has_prev($prev)
'body' => $prev->body, 'body' => $prev->body,
'description' => $prev->description, 'description' => $prev->description,
'tag' => $prev->tag, 'tag' => $prev->tag,
'category' => $prev->category,
'author' => $prev->author, 'author' => $prev->author,
'authorName' => $prev->authorName, 'authorName' => $prev->authorName,
'authorAbout' => $prev->authorAbout, 'authorAbout' => $prev->authorAbout,
@ -1642,7 +1646,12 @@ function has_prev($prev)
'audio' => $prev->audio, 'audio' => $prev->audio,
'quote' => $prev->quote, 'quote' => $prev->quote,
'link' => $prev->link, 'link' => $prev->link,
'category' => $prev->category,
'categoryUrl' => $prev->categoryUrl, 'categoryUrl' => $prev->categoryUrl,
'categoryCount' => $prev->categoryCount,
'categorySlug' => $prev->categorySlug,
'categoryMd' => $prev->categoryMd,
'categoryTitle' => $prev->categoryTitle,
'readTime' => $prev->readTime, 'readTime' => $prev->readTime,
'lastMod' => $prev->lastMod 'lastMod' => $prev->lastMod
); );
@ -1661,7 +1670,6 @@ function has_next($next)
'body' => $next->body, 'body' => $next->body,
'description' => $next->description, 'description' => $next->description,
'tag' => $next->tag, 'tag' => $next->tag,
'category' => $next->category,
'author' => $next->author, 'author' => $next->author,
'authorName' => $next->authorName, 'authorName' => $next->authorName,
'authorAbout' => $next->authorAbout, 'authorAbout' => $next->authorAbout,
@ -1675,7 +1683,12 @@ function has_next($next)
'audio' => $next->audio, 'audio' => $next->audio,
'quote' => $next->quote, 'quote' => $next->quote,
'link' => $next->link, 'link' => $next->link,
'category' => $next->category,
'categoryUrl' => $next->categoryUrl, 'categoryUrl' => $next->categoryUrl,
'categoryCount' => $next->categoryCount,
'categorySlug' => $next->categorySlug,
'categoryMd' => $next->categoryMd,
'categoryTitle' => $next->categoryTitle,
'readTime' => $next->readTime, 'readTime' => $next->readTime,
'lastMod' => $next->lastMod 'lastMod' => $next->lastMod
); );
@ -2261,11 +2274,10 @@ function get_title_from_file($v)
// Get the contents and convert it to HTML // Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v)); $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 // 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 // Auto generate menu from static page
@ -2305,21 +2317,20 @@ function get_menu($custom)
} }
$i++; $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); $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'; $active = ' active';
$reqBase = ''; $reqBase = '';
} else { } else {
$active = ''; $active = '';
} }
$subPages = get_static_sub_pages(str_replace('.md', '', $base));
$subPages = get_static_sub_pages($filename);
if (!empty($subPages)) { if (!empty($subPages)) {
asort($subPages); asort($subPages);
echo '<li class="' . $class . $active .' dropdown">'; echo '<li class="' . $class . $active .' dropdown">';
@ -2335,13 +2346,12 @@ function get_menu($custom)
if ($iSub == $countSub - 1) { if ($iSub == $countSub - 1) {
$classSub .= " last"; $classSub .= " last";
} }
$replacedSub = substr($sp, 0, strrpos($sp, '/')) . '/';
$baseSub = str_replace($replacedSub, '', $sp);
if ($req == site_path() . "/" . str_replace('.md', '', $base) . "/" . str_replace('.md', '', $baseSub)) {
$baseSub= pathinfo($sp, PATHINFO_FILENAME);
if ($req == site_path() . "/" . $filename . "/" . $baseSub) {
$classSub .= ' active'; $classSub .= ' active';
} }
$urlSub = $url . "/" . str_replace('.md', '', $baseSub);
$urlSub = $url . "/" . $baseSub;
echo '<li class="' . $classSub . '"><a href="' . $urlSub . '">' . get_title_from_file($sp) . '</a></li>'; echo '<li class="' . $classSub . '"><a href="' . $urlSub . '">' . get_title_from_file($sp) . '</a></li>';
$iSub++; $iSub++;
} }
@ -2475,23 +2485,21 @@ function sitemap_post_path()
$post = new stdClass; $post = new stdClass;
$post = new stdClass;
$filepath = $v['dirname'] . '/' . $v['basename']; $filepath = $v['dirname'] . '/' . $v['basename'];
// Extract the date // Extract the date
$arr = explode('_', $v['basename']); $arr = explode('_', $v['basename']);
// Replaced string
$replaced = $v['dirname'] . '/';
// dirname string
$dirname = $v['dirname'] . '/';
// Author string // Author string
$str = explode('/', $replaced);
$str = explode('/', $dirname);
$author = $str[1]; $author = $str[1];
$post->authorUrl = site_url() . 'author/' . $author; $post->authorUrl = site_url() . 'author/' . $author;
$dt = str_replace($replaced, '', $arr[0]);
$dt = str_replace($dirname, '', $arr[0]);
$t = str_replace('-', '', $dt); $t = str_replace('-', '', $dt);
$time = new DateTime($t); $time = new DateTime($t);
$timestamp = $time->format("Y-m-d H:i:s"); $timestamp = $time->format("Y-m-d H:i:s");
@ -2535,13 +2543,10 @@ function sitemap_page_path()
$post = new stdClass; $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; $tmp[] = $post;
} }
@ -2662,7 +2667,6 @@ function generate_sitemap($str)
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$arr = explode('_', $v); $arr = explode('_', $v);
$data = $arr[1]; $data = $arr[1];
$mtag = explode(',', $data); $mtag = explode(',', $data);
foreach ($mtag as $etag) { foreach ($mtag as $etag) {
@ -2771,8 +2775,8 @@ function generate_sitemap($str)
if($posts) { if($posts) {
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$replaced = dirname($v) . '/';
$str = explode('/', $replaced);
$dirname = dirname($v) . '/';
$str = explode('/', $dirname);
$cats[] = $str[3]; $cats[] = $str[3];
} }
@ -2809,8 +2813,8 @@ function generate_sitemap($str)
if($posts) { if($posts) {
foreach ($posts as $index => $v) { foreach ($posts as $index => $v) {
$replaced = dirname($v) . '/';
$str = explode('/', $replaced);
$dirname = dirname($v) . '/';
$str = explode('/', $dirname);
$types[] = $str[4]; $types[] = $str[4];
} }


Loading…
Cancel
Save