rework date handling in filesystem backend
This commit is contained in:
parent
b886b513ab
commit
2d3c1407ff
|
@ -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]));
|
||||
$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)) {
|
||||
$result = $this->{$method}($post, $type);
|
||||
$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);
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue