$link = preg_replace('/\.html$/', '', $url);
$name = pathinfo($link, PATHINFO_BASENAME);
@list ($date, $suffix) = explode('.', $name, 2);
- if (!filesize($url)) {
+ if (!isset($cal[$date])) {
$cal[$date] = [];
}
- else {
+ if (!is_dir($url) and filesize($url)) {
$cal[$date][$suffix] = $link;
}
}
-$mindate = strtotime($date);
+$year = 3600 * 24 * 365; # seconds per year
+$scale = 8; # em width per year
+$mindate = strtotime($date) + ($year / $scale * 3); # first point plus about 3em for centered text
print '<ul class="timeline">'."\n";
foreach (array_reverse($cal) as $title => $versions) {
- $time = ($mindate - strtotime($title)) / (3600 * 24 * 365 / 8); # ~8em/yr
- printf('<li style="left:%.1fem">', $time);
- if ($url = @$versions['']) {
- printf('<a href="/%s">%s</a>', $url, $title);
- }
- else {
- print '<span>';
- print $title;
- if ($versions and $User->admin("edit $Page$Args")) {
- printf(' (%s)', implode(', ', array_map(
- function ($format, $url) {
- return sprintf('<a href="/%s">%s</a>', $url, $format);
- },
- array_keys($versions), $versions)
- ));
+ $time = 0;
+ $subtime = ($mindate - strtotime($title)) / $year * $scale - $time;
+ printf('<li style="left:%.1fem">', $subtime);
+ if ($url = @$versions['']) {
+ printf('<a href="/%s">%s</a>', $url, $title);
}
- print '</span>';
- }
- print "</li>\n";
+ else {
+ print '<span>';
+ print $title;
+ if ($versions and $User->admin("edit $Page$Args")) {
+ printf(' (%s)', implode(', ', array_map(
+ function ($format, $url) {
+ return sprintf('<a href="/%s">%s</a>', $url, $format);
+ },
+ array_keys($versions), $versions
+ )));
+ }
+ print '</span>';
+ }
+ print "</li>\n";
}
print "</ul>\n\n";