function blog_publish_months() { $tree = dir_rscandir("{$GLOBALS['smarty']->template_dir}/.posts", false); $list = dir_flatten($tree); $li = array(); foreach ($list[2] as $m) { $li[] = "\t<li><a href=\"{$m}\">" . substr($m, 1) . "</a></li>\n"; } file_put_contents("{$GLOBALS['smarty']->template_dir}/.months.html", "<ul id=\"months\">\n" . implode("", $li) . "</ul>\n", LOCK_EX); }
function dir_rscandir($dir, $all = true) { $ls = array_diff(scandir($dir), array(".", "..")); $out = array(); foreach ($ls as $l) { if (is_dir("{$dir}/{$l}")) { $out[$l] = dir_rscandir("{$dir}/{$l}", $all); } else { if ($all) { $out[$l] = false; } } } return sizeof($out) ? $out : false; }