add support for 2 digit years, fixes FS#53
This commit is contained in:
parent
b352efe93c
commit
1a83597ba5
@ -176,20 +176,22 @@ function cpm_breakdown_comic_filename($filename, $allow_override = false) {
|
|||||||
if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $pattern = $_POST['upload-date-format']; }
|
if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $pattern = $_POST['upload-date-format']; }
|
||||||
}
|
}
|
||||||
|
|
||||||
$pattern = cpm_transform_date_string($pattern, array("Y" => '[0-9]{4,4}',
|
foreach (array('[0-9]{4}', '[0-9]{2}') as $year_pattern) {
|
||||||
"m" => '[0-9]{2,2}',
|
$new_pattern = cpm_transform_date_string($pattern, array("Y" => $year_pattern,
|
||||||
"d" => '[0-9]{2,2}'));
|
"m" => '[0-9]{2}',
|
||||||
|
"d" => '[0-9]{2}'));
|
||||||
|
|
||||||
if (@preg_match("#^(${pattern})(.*)\.[^\.]+$#", $filename, $matches) > 0) {
|
if (@preg_match("#^(${new_pattern})(.*)\.[^\.]+$#", $filename, $matches) > 0) {
|
||||||
list($all, $date, $title) = $matches;
|
list($all, $date, $title) = $matches;
|
||||||
|
|
||||||
if (strtotime($date) === false) { return false; }
|
if (strtotime($date) === false) { return false; }
|
||||||
$converted_title = ucwords(trim(preg_replace('/[\-\_]/', ' ', $title)));
|
$converted_title = ucwords(trim(preg_replace('/[\-\_]/', ' ', $title)));
|
||||||
|
$date = date($pattern, strtotime($date));
|
||||||
|
|
||||||
return compact('date', 'title', 'converted_title');
|
return compact('date', 'title', 'converted_title');
|
||||||
} else {
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +55,7 @@ class TestComicPressManagerLibrary extends UnitTestCase {
|
|||||||
array("${test_date}-Test.jpg", array("title" => "-Test", "date" => $test_date, "converted_title" => "Test")),
|
array("${test_date}-Test.jpg", array("title" => "-Test", "date" => $test_date, "converted_title" => "Test")),
|
||||||
array("${test_date}-test.jpg", array("title" => "-test", "date" => $test_date, "converted_title" => "Test")),
|
array("${test_date}-test.jpg", array("title" => "-test", "date" => $test_date, "converted_title" => "Test")),
|
||||||
array("1900-01-01.jpg", false),
|
array("1900-01-01.jpg", false),
|
||||||
|
array("08-01-01.jpg", array("title" => "", "date" => $test_date, "converted_title" => "")),
|
||||||
) as $test) {
|
) as $test) {
|
||||||
list($filename, $expected_value) = $test;
|
list($filename, $expected_value) = $test;
|
||||||
$this->assertEqual($expected_value, cpm_breakdown_comic_filename($filename, true));
|
$this->assertEqual($expected_value, cpm_breakdown_comic_filename($filename, true));
|
||||||
|
Loading…
Reference in New Issue
Block a user