Update functions.php

This commit is contained in:
danpros 2023-12-06 08:34:49 +07:00
commit 7cbbf00392

View file

@ -3307,29 +3307,17 @@ function safe_tag($string)
} }
// rename category folder // rename category folder
function rename_category_folder($string, $old_url) function rename_category_folder($new_name, $old_file)
{ {
$old = str_replace('.md', '/', $old_url); $old_name = str_replace('.md', '', basename($old_file));
$url = substr($old, 0, strrpos($old, '/'));
$ostr = explode('/', $url);
$url = '/blog/' . $ostr[count($ostr) - 1];
$dir = get_category_folder(); $dir = get_category_folder();
$file = array();
foreach ($dir as $index => $v) { foreach ($dir as $index => $v) {
if (stripos($v, $url) !== false) { if (stripos($v, '/' . $old_name . '/') !== false) {
$str = explode('/', $v); $str = explode('/', $v);
$n = $str[count($ostr) - 4] . '/' . $str[count($ostr) - 3] .'/'. $str[count($ostr) - 2] .'/'. $string . '/'; $old_folder = $str[0] . '/' . $str[1] . '/' . $str[2] . '/' . $old_name . '/';
$file[] = array($v, $n); $new_folder = $str[0] . '/' . $str[1] . '/' . $str[2] . '/' . $new_name . '/';
} rename($old_folder, $new_folder);
}
foreach ($file as $f) {
if(is_dir($f[0])) {
rename($f[0], $f[1]);
} }
} }