function shownewsdate($url)
{
- $parts = pathinfo($url);
- $year = pathinfo($parts['dirname'], PATHINFO_FILENAME);
- @list ($month, $day) = explode('-', $parts['filename'], 3);
+ if (!preg_match('</(\d{4})/(\d{2})/(\d{2})->', $url, $parts)) return;
global $monthname;
- return sprintf('<small class="date">%s %s %s</small>',
- intval($day), $monthname[intval($month)], $year);
+ return implode(' ', array_filter([
+ intval($parts[3]), $monthname[intval($parts[2])], $parts[1],
+ ]));
}
function shownewsarticle($url, $link = TRUE, $title = NULL)
function shownews($root, $limit = 5)
{
- foreach (array_reverse(glob("$root/*/*.html")) as $url) {
+ if (strpos($root, '/') === FALSE) $root .= '/*';
+ foreach (array_reverse(glob("$root/*.html")) as $url) {
print "<article>";
ob_start();
include $url;
if (--$limit <= 0) break;
}
}
+
+function printtoc($root)
+{
+ print '<ul>';
+ foreach (array_reverse(glob("$root/*.html")) as $page) {
+ $title = fgets(fopen($page, 'r'));
+ $title = strip_tags($title);
+ $linkurl = preg_replace('/\.html$/', '', $page);
+ printf('<li><a href="/%s">%s <small class="date">%s</small></a></li>',
+ $linkurl, $title, shownewsdate($linkurl));
+ }
+ print "</ul>\n";
+}