static function parsePathspec($pathspec, &$date, &$slug, &$fnext)
{
# cut away prefix "content/posts/"
$name = substr($pathspec, 14);
# split filename from filename extension
$lastdot = strrpos($name, '.', strrpos($name, '/'));
if ($lastdot !== false) {
$fnext = substr($name, $lastdot + 1);
$name = substr($name, 0, $lastdot);
} else {
$fnext = null;
}
# parse date and slug
static $subchars = '._/';
static $repchars = '---';
static $ptimes = array('%Y-%m-%d' => 10, '%y-%m-%d' => 8, '%G-%m-%d' => 10, '%g-%m-%d' => 8, '%Y-%m' => 7, '%y-%m' => 5, '%G-%m' => 7, '%g-%m' => 5, '%Y' => 4, '%y' => 2, '%G' => 4, '%g' => 2);
$nametest = strtr($name, $subchars, $repchars);
# first, test gb::$posts_cn_pattern
if (($st = strptime($nametest, strtr(gb::$posts_cn_pattern, $subchars, $repchars))) !== false) {
$slug = ltrim($st['unparsed'], $subchars . '-');
} else {
# next, test common patterns with as many items as gb::$posts_cn_pattern
$ptimes1 = array();
$n = 0;
$slug = false;
if (preg_match_all('/%\\w/', gb::$posts_cn_pattern, $m)) {
$n = count($m[0]);
}
if ($n) {
if ($n == 1) {
$ptimes1 = array('%Y' => 4, '%y' => 2, '%G' => 4, '%g' => 2);
} else {
if ($n == 2) {
$ptimes1 = array('%Y-%m' => 7, '%y-%m' => 5, '%G-%m' => 7, '%g-%m' => 5);
} else {
if ($n == 3) {
$ptimes1 = array('%Y-%m-%d' => 10, '%y-%m-%d' => 8, '%G-%m-%d' => 10, '%g-%m-%d' => 8);
}
}
}
foreach ($ptimes1 as $pattern => $pattern_len) {
if (($st = strptime($nametest, $pattern)) !== false) {
$slug = ltrim(substr($name, $pattern_len), $subchars . '-');
break;
}
}
}
if ($slug === false) {
# finally, try a series of common patterns
foreach ($ptimes as $pattern => $pattern_len) {
if (($st = strptime($nametest, $pattern)) !== false) {
$slug = ltrim(substr($name, $pattern_len), $subchars . '-');
break;
}
}
}
}
# failed to parse
if ($st === false) {
throw new UnexpectedValueException('unable to parse date from ' . var_export($pathspec, 1));
}
$date = gmstrftime('%FT%T+00:00', gb_mkutctime($st));
#$slug = ltrim($st['unparsed'], '-');
$date = new GBDateTime($date . 'T00:00:00Z');
}