template_dir; $files = scandir("$base$dir"); $paths = array(); $ii = sizeof($files); for ($i = 0; $i < $ii; ++$i) { if (preg_match('!^\.!', $files[$i])) { unset($files[$i]); } else { $paths[] = array( 'rel' => "$dir/{$files[$i]}", 'abs' => "$base$dir/{$files[$i]}" ); } } usort($paths, '_blog_crawl_mtime_sort'); $posts = array(); $ii = sizeof($paths); for ($i = 0; $i < $ii; ++$i) { if (is_dir($paths[$i]['abs'])) { $sub = blog_crawl($force, $paths[$i]['rel']); foreach ($sub as $s) { $posts[] = $s; } } else if (preg_match('!^/[0-9]{4}/[0-9]{2}/[0-9]{2}!', $paths[$i]['rel'])) { $posts[] = $paths[$i]['rel']; } } cache_set('blog_crawl', $posts); } return $posts; } # Callback function for sorting by file modified time function _blog_crawl_mtime_sort($a, $b) { $a_mtime = filemtime($a['abs']); $b_mtime = filemtime($b['abs']); if ($a_mtime == $b_mtime) return 0; return $a > $b ? -1 : 1; } # Return an array of months with posts function blog_months_with_posts() { $dates = cache_get('blog_months_with_posts'); if (!$dates) { $base = $GLOBALS['smarty']->template_dir; $years = scandir($base); $dates = array(); foreach ($years as $y) { if (preg_match('!^[0-9]{4}$!', $y)) { $months = scandir("$base/$y"); foreach ($months as $m) { if (preg_match('!^[0-9]{2}$!', $m)) { $dates[] = strtotime("$y-$m-01"); } } } } sort($dates, SORT_NUMERIC); $dates= array_reverse($dates); cache_set('blog_months_with_posts', $dates); } return $dates; } # Filter posts list by date function blog_date_archive($regex) { global $smarty; $posts = blog_crawl(); $out = array(); foreach ($posts as $p) { if (preg_match($regex, $p)) { $out[] = $p; } } $smarty->assign('posts', $out); $smarty->display('.posts.html'); } ?>