rework date handling in filesystem backend

This commit is contained in:
John Bintz 2009-12-31 19:20:39 -05:00
parent b886b513ab
commit 2d3c1407ff
2 changed files with 27 additions and 17 deletions

View File

@ -77,16 +77,25 @@ class ComicPressBackendFilesystemFactory {
if (preg_match('#%([a-z0-9\-]+)%#i', $search, $matches) > 0) {
$any_found = true;
$method = '_replace_' . strtolower(str_replace('-', '_', $matches[1]));
if (method_exists($this, $method)) {
$result = $this->{$method}($post, $type);
if ($result !== false) {
$this->_searches[$i] = str_replace($matches[0], $result, $search);
} else {
// array state change, start over
break;
$found = false;
$parts = explode('-', $matches[1]);
foreach (array(
'_replace_' . strtolower(str_replace('-', '_', $matches[1])) => null,
'_replace_' . strtolower($parts[0]) => implode('-', array_slice($parts, 1))
) as $method => $additional) {
if (method_exists($this, $method)) {
$found = true;
$result = $this->{$method}($post, $type, $additional);
if ($result !== false) {
$this->_searches[$i] = str_replace($matches[0], $result, $search);
} else {
// array state change, start over
break;
}
}
} else {
}
if (!$found) {
$this->_searches[$i] = str_replace($matches[0], '', $search);
}
}
@ -104,9 +113,10 @@ class ComicPressBackendFilesystemFactory {
// @codeCoverageIgnoreEnd
function _replace_type($post, $type) { return $type; }
function _replace_y_m_d($post, $type) { return date('Y-m-d', strtotime($post->post_date)); }
function _replace_ymd($post, $type) { return date('Ymd', strtotime($post->post_date)); }
function _replace_year($post, $type) { return date('Y', strtotime($post->post_date)); }
function _replace_date($post, $type, $additional) {
return date($additional, strtotime($post->post_date));
}
function _replace_categories($post, $type) {
if (count($post_categories = wp_get_post_categories($post->ID)) == 1) {
$current_parent = reset($post_categories);

View File

@ -99,18 +99,18 @@ class ComicPressBackendFilesystemFactoryTest extends PHPUnit_Framework_TestCase
array('%wordpress%/comic/*.jpg', array('/wordpress/comic/*.jpg')),
array('%test%/comic/*.jpg', array('/comic/*.jpg')),
array('%wordpress%/%type%/*.jpg', array('/wordpress/comic/*.jpg')),
array('%wordpress%/comic/%y-m-d%*.jpg', array('/wordpress/comic/2009-01-01*.jpg')),
array('%wordpress%/comic/%ymd%*.jpg', array('/wordpress/comic/20090101*.jpg')),
array('%wordpress%/comic/%year%/%y-m-d%*.jpg', array('/wordpress/comic/2009/2009-01-01*.jpg')),
array('%wordpress%/comic/%date-Y-m-d%*.jpg', array('/wordpress/comic/2009-01-01*.jpg')),
array('%wordpress%/comic/%date-Ymd%*.jpg', array('/wordpress/comic/20090101*.jpg')),
array('%wordpress%/comic/%date-Y%/%date-Y-m-d%*.jpg', array('/wordpress/comic/2009/2009-01-01*.jpg')),
array(
'%wordpress%/comic/%categories%/%y-m-d%*.jpg',
'%wordpress%/comic/%categories%/%date-Y-m-d%*.jpg',
array(
'/wordpress/comic/parent/child/2009-01-01*.jpg',
'/wordpress/comic/parent/2009-01-01*.jpg',
)
),
array(
'%wordpress%/comic/%categories%/%y-m-d%*.jpg',
'%wordpress%/comic/%categories%/%date-Y-m-d%*.jpg',
array(
'/wordpress/comic//2009-01-01*.jpg',
),