From d9b46aa63e29a3cd07e5760bdcd4a21cc8bb1c9d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 21:07:10 -0500 Subject: [PATCH 1/8] start media handling --- classes/ComicPressMediaHandling.inc | 20 +++++++++++++++++++ test/ComicPressMediaHandlingTest.php | 29 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 classes/ComicPressMediaHandling.inc create mode 100644 test/ComicPressMediaHandlingTest.php diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc new file mode 100644 index 0000000..b01b4a5 --- /dev/null +++ b/classes/ComicPressMediaHandling.inc @@ -0,0 +1,20 @@ +cpmh = new ComicPressMediaHandling(); + } + + function testBundleGlobalVariables() { + global $comic_folder, $archive_comic_folder, $rss_comic_folder, $mini_comic_folder; + + $comic_folder = 'comic'; + $archive_comic_folder = 'archive'; + $rss_comic_folder = 'rss'; + $mini_comic_folder = 'mini'; + + $this->assertEquals(array( + 'comic' => 'comic', + 'archive' => 'archive', + 'rss' => 'rss', + 'mini' => 'mini' + ), $this->cpmh->_bundle_global_variables()); + } +} From 220322318d8500e020ca11194685e5d558e73c74 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 21:14:54 -0500 Subject: [PATCH 2/8] get filter --- classes/ComicPressMediaHandling.inc | 20 +++++++++++++++++++ test/ComicPressMediaHandlingTest.php | 20 +++++++++++++++++++ .../widgets/GraphicalNavigationWidgetTest.php | 5 ----- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index b01b4a5..57e95d7 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -1,6 +1,8 @@ default_filter; + } + + function get_comic_path($source = 'comic', $override_post = null, $filter = 'default', $multi = false) { + + } } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 7b841ce..603f53e 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -26,4 +26,24 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { 'mini' => 'mini' ), $this->cpmh->_bundle_global_variables()); } + + function providerTestGetFilter() { + return array( + array(null, '%wordpress%/%type-folder%/%date-Y-m-d%*.*'), + array('fail', '%wordpress%/%type-folder%/%date-Y-m-d%*.*'), + array(array(), '%wordpress%/%type-folder%/%date-Y-m-d%*.*'), + array('test', 'test') + ); + } + + /** + * @dataProvider providerTestGetFilter + */ + function testGetFilter($filter_to_use, $expected_result) { + global $comic_filename_filters; + + $comic_filename_filters['test'] = 'test'; + + $this->assertEquals($expected_result, $this->cpmh->_get_filter($filter_to_use)); + } } diff --git a/test/widgets/GraphicalNavigationWidgetTest.php b/test/widgets/GraphicalNavigationWidgetTest.php index cab99c2..709acf4 100644 --- a/test/widgets/GraphicalNavigationWidgetTest.php +++ b/test/widgets/GraphicalNavigationWidgetTest.php @@ -10,9 +10,6 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase { $this->w = new GraphicalNavigationWidget(); } - /** - * @covers WidgetComicPressGraphicalStorylineNavigation::update - */ function testUpdateWidget() { $result = $this->w->update(array( "next" => "test", @@ -41,7 +38,6 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerTestIsNavLinkVisible - * @covers WidgetComicPressGraphicalStorylineNavigation::_will_display_nav_link */ function testIsNavLinkVisible($which, $current_id, $target_id, $expected_result) { $current = (object)array('ID' => $current_id); @@ -76,7 +72,6 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase { /** * @dataProvider providerTestGroupNavigationButtons - * @covers WidgetComicPressGraphicalStorylineNavigation::_group_navigation_buttons */ function testGroupNavigationButtons($buttons, $expected_grouping) { _set_filter_expectation('comicpress_navigation_grouping_details', array(array( From 1f428c786a8bca4e4d2f11b670871166ca6785b8 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 21:37:28 -0500 Subject: [PATCH 3/8] filtering --- classes/ComicPressMediaHandling.inc | 50 ++++++++++++++++++++++- test/ComicPressMediaHandlingTest.php | 59 ++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 6 deletions(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 57e95d7..1071585 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -1,6 +1,7 @@ _convert_to_percent_filter($comic_filename_filters[$filter_to_use]); } } } @@ -34,7 +35,52 @@ class ComicPressMediaHandling { return $this->default_filter; } - function get_comic_path($source = 'comic', $override_post = null, $filter = 'default', $multi = false) { + function _convert_to_percent_filter($old) { + if (strpos(strtolower($old), '%wordpress%') !== 0) { + $old = str_replace('{date}', '%date-Y-m-d%', $old); + return $this->root_filter . $old; + } + return $old; + } + function _expand_filter($filter, $type_filter, $override_post = null) { + global $post; + $this->post_to_use = !is_null($override_post) ? $override_post : $post; + $this->type_filter = $type_filter; + + $result = preg_replace_callback('#%([a-z0-9-]+)%#i', array(&$this, '_expand_filter_callback'), $filter); + $result = str_replace('.', '\.', $result); + $result = str_replace('*', '.*', $result); + + unset($this->post_to_use); + unset($this->type_filter); + + return $result; + } + + function _abspath() { return ABSPATH; } + + function _expand_filter_callback($matches) { + $value = ''; + switch (strtolower($matches[1])) { + case 'wordpress': + $value = $this->_abspath(); + break; + case 'type-folder': + $value = $this->type_filter; + break; + default: + if (preg_match('#^date-(.*)$#', $matches[1], $date_matches) > 0) { + $value = date($date_matches[1], strtotime($this->post_to_use->post_date)); + break; + } + $value = $matches[0]; + break; + } + return $value; + } + + function get_comic_path($type = 'comic', $override_post = null, $filter = 'default', $multi = false) { + $filter = $this->get_filter($filter); } } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 603f53e..358c1c5 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -9,6 +9,10 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { function setUp() { _reset_wp(); $this->cpmh = new ComicPressMediaHandling(); + $this->default_filter = $this->cpmh->default_filter; + + vfsStreamWrapper::register(); + vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); } function testBundleGlobalVariables() { @@ -28,10 +32,12 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { } function providerTestGetFilter() { + $cpmh = new ComicPressMediaHandling(); + return array( - array(null, '%wordpress%/%type-folder%/%date-Y-m-d%*.*'), - array('fail', '%wordpress%/%type-folder%/%date-Y-m-d%*.*'), - array(array(), '%wordpress%/%type-folder%/%date-Y-m-d%*.*'), + array(null, $cpmh->default_filter), + array('fail', $cpmh->default_filter), + array(array(), $cpmh->default_filter), array('test', 'test') ); } @@ -44,6 +50,51 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $comic_filename_filters['test'] = 'test'; - $this->assertEquals($expected_result, $this->cpmh->_get_filter($filter_to_use)); + $cpmh = $this->getMock('ComicPressMediaHandling', array('_convert_to_percent_filter')); + if ($expected_result !== $cpmh->default_filter) { + $cpmh->expects($this->once())->method('_convert_to_percent_filter')->with($expected_result)->will($this->returnValue($expected_result)); + } else { + $cpmh->expects($this->never())->method('_convert_to_percent_filter'); + } + + $this->assertEquals($expected_result, $cpmh->_get_filter($filter_to_use)); + } + + function providerTestConvertToPercentFilter() { + return array( + array('', '%wordpress%/%type-folder%/'), + array('{date}', '%wordpress%/%type-folder%/%date-Y-m-d%'), + array('%wordpress%/%type-folder%/{date}', '%wordpress%/%type-folder%/{date}'), + ); + } + + /** + * @dataProvider providerTestConvertToPercentFilter + */ + function testConvertToPercentFilter($old_filter, $new_filter) { + $this->assertEquals($new_filter, $this->cpmh->_convert_to_percent_filter($old_filter)); + } + + function providerTestExpandFilter() { + return array( + array('', ''), + array('%test%', '%test%'), + array('%wordpress%', vfsStream::url('root')), + array('%wordpress%%wordpress%', vfsStream::url('root') . vfsStream::url('root')), + array('%test test%', '%test test%'), + array('%wordpress%/%type-folder%', vfsStream::url('root') . '/comic'), + array('%date-Y%', '2009'), + array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*'), + ); + } + + /** + * @dataProvider providerTestExpandFilter + */ + function testExpandFilter($filter, $expected_result) { + $cpmh = $this->getMock('ComicPressMediaHandling', array('_abspath')); + $cpmh->expects($this->any())->method('_abspath')->will($this->returnValue(vfsStream::url('root'))); + + $this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00'))); } } From 6aea00a8d047820b19f2acd8949077495c04b422 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 21:40:40 -0500 Subject: [PATCH 4/8] wpmu handling --- classes/ComicPressMediaHandling.inc | 10 ++++++++-- test/ComicPressMediaHandlingTest.php | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 1071585..d3892b1 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -58,13 +58,19 @@ class ComicPressMediaHandling { return $result; } - function _abspath() { return ABSPATH; } + function _abspath() { + return ABSPATH; + } function _expand_filter_callback($matches) { $value = ''; switch (strtolower($matches[1])) { case 'wordpress': - $value = $this->_abspath(); + if ($path = get_option('upload_path')) { + $value = $path; + } else { + $value = $this->_abspath(); + } break; case 'type-folder': $value = $this->type_filter; diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 358c1c5..4a88e9e 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -85,16 +85,21 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { array('%wordpress%/%type-folder%', vfsStream::url('root') . '/comic'), array('%date-Y%', '2009'), array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*'), + array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', '/wpmupath/comic/2009-01-01.*\..*', '/wpmupath'), ); } /** * @dataProvider providerTestExpandFilter */ - function testExpandFilter($filter, $expected_result) { + function testExpandFilter($filter, $expected_result, $use_option_path = false) { $cpmh = $this->getMock('ComicPressMediaHandling', array('_abspath')); $cpmh->expects($this->any())->method('_abspath')->will($this->returnValue(vfsStream::url('root'))); + if ($use_option_path !== false) { + update_option('upload_path', $use_option_path); + } + $this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00'))); } } From 3d514a3544a0822c77bb36f33c3e4b6fa93140c3 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 21:53:46 -0500 Subject: [PATCH 5/8] directory reading and more cleanup --- classes/ComicPressMediaHandling.inc | 38 ++++++++++++++++++++++++---- test/ComicPressMediaHandlingTest.php | 23 +++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index d3892b1..926d827 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -43,17 +43,17 @@ class ComicPressMediaHandling { return $old; } - function _expand_filter($filter, $type_filter, $override_post = null) { + function _expand_filter($filter, $type_folder, $override_post = null) { global $post; $this->post_to_use = !is_null($override_post) ? $override_post : $post; - $this->type_filter = $type_filter; + $this->type_folder = $type_folder; $result = preg_replace_callback('#%([a-z0-9-]+)%#i', array(&$this, '_expand_filter_callback'), $filter); $result = str_replace('.', '\.', $result); $result = str_replace('*', '.*', $result); unset($this->post_to_use); - unset($this->type_filter); + unset($this->type_folder); return $result; } @@ -73,7 +73,7 @@ class ComicPressMediaHandling { } break; case 'type-folder': - $value = $this->type_filter; + $value = $this->type_folder; break; default: if (preg_match('#^date-(.*)$#', $matches[1], $date_matches) > 0) { @@ -83,10 +83,38 @@ class ComicPressMediaHandling { $value = $matches[0]; break; } - return $value; + return apply_filters('comicpress_expand_filter_callback', $value, $matches); + } + + function _read_directory($pattern) { + $dirname = dirname($pattern); + $results = false; + if (is_dir($dirname)) { + $results = array(); + if (($dh = opendir($dirname)) !== false) { + $filename_pattern = str_replace('#', '\#', basename($pattern)); + while (($file = readdir($dh)) !== false) { + $target = $dirname . '/' . $file; + if (is_file($target)) { + if (preg_match("#${filename_pattern}#", $file) > 0) { + $results[] = $target; + } + } + } + } + } + return $results; } function get_comic_path($type = 'comic', $override_post = null, $filter = 'default', $multi = false) { + global $post; + $post_to_use = !is_null($override_post) ? $override_post : $post; + $filter = $this->get_filter($filter); + $globals = $this->_bundle_global_variables(); + + if (isset($globals[$type])) { + $filter = $this->_expand_filter($filter, $globals[$type], $post_to_use); + } } } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 4a88e9e..2e30ae4 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -102,4 +102,27 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00'))); } + + function providerTestReadDirectory() { + return array( + array(vfsStream::url('root2/.*'), false), + array(vfsStream::url('root/.*'), array('2009-01-01.jpg', '2009-01-02.jpg', '2009-02-02-two.jpg', '2008-01-01.jpg')), + array(vfsStream::url('root/2009.*'), array('2009-01-01.jpg', '2009-01-02.jpg', '2009-02-02-two.jpg')), + array(vfsStream::url('root/2009-01.*'), array('2009-01-01.jpg', '2009-01-02.jpg')), + array(vfsStream::url('root/2009-01-01.*'), array('2009-01-01.jpg')), + ); + } + + /** + * @dataProvider providerTestReadDirectory + */ + function testReadDirectory($pattern, $expected_results) { + foreach (array('2009-01-01.jpg', '2009-01-02.jpg', '2009-02-02-two.jpg', '2008-01-01.jpg') as $file) { + file_put_contents(vfsStream::url("root/${file}"), 'file'); + } + if (is_array($expected_results)) { + foreach ($expected_results as &$result) { $result = vfsStream::url("root/${result}"); } + } + $this->assertEquals($expected_results, $this->cpmh->_read_directory($pattern)); + } } From 3b0b3a1471151cf6d3ff6c17009155a225c7d37a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 22:13:21 -0500 Subject: [PATCH 6/8] wpmu-specific stuff --- classes/ComicPressMediaHandling.inc | 14 ++++++--- test/ComicPressMediaHandlingTest.php | 46 +++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 926d827..3665d09 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -58,19 +58,17 @@ class ComicPressMediaHandling { return $result; } + // @codeCoverageIgnoreStart function _abspath() { return ABSPATH; } + // @codeCoverageIgnoreEnd function _expand_filter_callback($matches) { $value = ''; switch (strtolower($matches[1])) { case 'wordpress': - if ($path = get_option('upload_path')) { - $value = $path; - } else { - $value = $this->_abspath(); - } + $value = $this->_abspath(); break; case 'type-folder': $value = $this->type_folder; @@ -115,6 +113,12 @@ class ComicPressMediaHandling { if (isset($globals[$type])) { $filter = $this->_expand_filter($filter, $globals[$type], $post_to_use); + + if (is_array($results = $this->_read_directory($filter))) { + if (($pre_handle = apply_filters('comicpress_pre_handle_comic_path_results', false, $results, $type, $post_to_use)) !== false) { + return $pre_handle; + } + } } } } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 2e30ae4..e03c591 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -4,6 +4,7 @@ require_once('PHPUnit/Framework.php'); require_once('MockPress/mockpress.php'); require_once('vfsStream/vfsStream.php'); require_once(dirname(__FILE__) . '/../classes/ComicPressMediaHandling.inc'); +require_once(dirname(__FILE__) . '/../functions/wpmu.php'); class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { function setUp() { @@ -84,25 +85,35 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { array('%test test%', '%test test%'), array('%wordpress%/%type-folder%', vfsStream::url('root') . '/comic'), array('%date-Y%', '2009'), - array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*'), - array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', '/wpmupath/comic/2009-01-01.*\..*', '/wpmupath'), + array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*') ); } /** * @dataProvider providerTestExpandFilter */ - function testExpandFilter($filter, $expected_result, $use_option_path = false) { + function testExpandFilter($filter, $expected_result) { $cpmh = $this->getMock('ComicPressMediaHandling', array('_abspath')); $cpmh->expects($this->any())->method('_abspath')->will($this->returnValue(vfsStream::url('root'))); - if ($use_option_path !== false) { - update_option('upload_path', $use_option_path); - } - $this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00'))); } + function providerTestExpandFilterWPMUCallback() { + return array( + array('', 'original'), + array('new', 'new') + ); + } + + /** + * @dataProvider providerTestExpandFilterWPMUCallback + */ + function testExpandFilterWPMUCallback($option_value, $expected_result) { + update_option('upload_path', $option_value); + $this->assertEquals($expected_result, _comicpress_expand_filter_callback('original', array())); + } + function providerTestReadDirectory() { return array( array(vfsStream::url('root2/.*'), false), @@ -125,4 +136,25 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { } $this->assertEquals($expected_results, $this->cpmh->_read_directory($pattern)); } + + function providerTestPreHandleComicPathResults() { + return array( + array('', '', false), + array('1', '', 'comic/one'), + array('1', 'comic', 'files/one'), + ); + } + + /** + * @dataProvider providerTestPreHandleComicPathResults + */ + function testPreHandleComicPathResults($_wpmu_version, $upload_path, $expected_result) { + global $wpmu_version, $comic_folder; + $wpmu_version = $_wpmu_version; + $comic_folder = 'comic'; + + update_option('upload_path', $upload_path); + + $this->assertEquals($expected_result, _comicpress_pre_handle_comic_path_results(false, array('one/one', 'two/two', 'three/three'), 'comic', (object)array('ID' => 1))); + } } From 91436b4b5133f906ab3f23597d6bfae172dc9bfd Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 22:27:54 -0500 Subject: [PATCH 7/8] finalize get comic path changeover --- classes/ComicPressMediaHandling.inc | 27 +++++++++-- functions.php | 68 +++------------------------- functions/wpmu.php | 33 ++++++++++++++ test/ComicPressMediaHandlingTest.php | 12 +++-- 4 files changed, 71 insertions(+), 69 deletions(-) create mode 100644 functions/wpmu.php diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 3665d09..11ac09b 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -60,7 +60,7 @@ class ComicPressMediaHandling { // @codeCoverageIgnoreStart function _abspath() { - return ABSPATH; + return realpath(ABSPATH); } // @codeCoverageIgnoreEnd @@ -94,21 +94,30 @@ class ComicPressMediaHandling { while (($file = readdir($dh)) !== false) { $target = $dirname . '/' . $file; if (is_file($target)) { - if (preg_match("#${filename_pattern}#", $file) > 0) { + if (preg_match("#^${filename_pattern}$#", $file) > 0) { $results[] = $target; } } } + closedir($dh); } } return $results; } + /** + * Get the comic path. + * @param string $type The type to retrieve. + * @param object $override_post The post to use in place of the Loop post. + * @param string $filter The filter to use. + * @param boolean $multi If true, return all matching files. + * @return string|array|boolean A single comic URI relative to the WordPress base, multiple comic URIs, or false if an error occurred. + */ function get_comic_path($type = 'comic', $override_post = null, $filter = 'default', $multi = false) { global $post; $post_to_use = !is_null($override_post) ? $override_post : $post; - $filter = $this->get_filter($filter); + $filter = $this->_get_filter($filter); $globals = $this->_bundle_global_variables(); if (isset($globals[$type])) { @@ -118,7 +127,19 @@ class ComicPressMediaHandling { if (($pre_handle = apply_filters('comicpress_pre_handle_comic_path_results', false, $results, $type, $post_to_use)) !== false) { return $pre_handle; } + + $new_results = array(); + foreach ($results as $result) { + $new_results[] = str_replace($this->_abspath(), '', $result); + } + + if ($multi) { + return $new_results; + } else { + return reset($new_results); + } } } + return false; } } diff --git a/functions.php b/functions.php index 6f0f669..8f63e5c 100644 --- a/functions.php +++ b/functions.php @@ -75,7 +75,7 @@ function comicpress_load_options() { global $comicpress_options; $comicpress_options = get_option('comicpress_options'); if (empty($comicpress_options)) { - $comicpress_options['comicpress_version'] = '2.9.0.4'; + $comicpress_options['comicpress_version'] = '2.9.0.4'; foreach (array( 'disable_comic_frontpage' => false, 'disable_comic_blog_frontpage' => false, @@ -181,11 +181,9 @@ if ($comicpress_options['remove_wptexturize']) { // WIDGETS WP 2.8 compatible ONLY, no backwards compatibility here. $dirs_to_search = array_unique(array(get_template_directory(),get_stylesheet_directory())); foreach ($dirs_to_search as $dir) { - // Widgets - foreach (glob($dir . '/widgets/*.php') as $__file) { require_once($__file); } - - // FUNCTIONS & Extra's - foreach (glob($dir . '/functions/*.php') as $__file) { require_once($__file); } + foreach (array('widgets' => 'php', 'functions' => 'php', 'classes' => 'inc') as $folder => $extension) { + foreach (glob($dir . "/${folder}/*.${extension}") as $__file) { require_once($__file); } + } } // Dashboard Menu Comicpress Options and ComicPress CSS @@ -217,7 +215,6 @@ if (defined("CPM_DATE_FORMAT")) { // Note that it's quite possible to slurp up the wrong file if your expressions are too broad. $comic_filename_filters = array(); -$comic_filename_filters['default'] = "{date}*.*"; // load all of the comic & non-comic category information add_action('init', 'get_all_comic_categories'); @@ -427,61 +424,8 @@ function get_adjacent_storyline_category_id($next = false) { */ function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default', $multi = null) { - global $post, $comic_filename_filters, $comic_folder, $archive_comic_folder, $rss_comic_folder, $mini_comic_folder, $comic_pathfinding_errors, $wpmu_version; - - if (isset($comic_filename_filters[$filter])) { - $filter_to_use = $comic_filename_filters[$filter]; - } else { - $filter_to_use = '{date}*.*'; - } - - switch ($folder) { - case "rss": $folder_to_use = $rss_comic_folder; break; - case "archive": $folder_to_use = $archive_comic_folder; break; - case "mini": $folder_to_use = $mini_comic_folder; break; - case "comic": default: $folder_to_use = $comic_folder; break; - } - - if (!empty($wpmu_version)) { - if (($wpmu_path = get_option('upload_path')) !== false) { - $folder_to_use = $wpmu_path . '/' . $folder_to_use; - } - } - - $post_to_use = (is_object($override_post)) ? $override_post : $post; - $post_date = mysql2date(CP_DATE_FORMAT, $post_to_use->post_date); - - $filter_with_date = str_replace('{date}', $post_date, $filter_to_use); - - $cwd = get_template_directory(); - if ($cwd !== false) { - // Strip the wp-admin part and just get to the root. - $root_path = preg_replace('#[\\/]wp-(admin|content).*#', '', $cwd); - } - - $results = array(); - /* have to use root_path to get subdirectory installation directories */ - if (count($results = glob("${root_path}/${folder_to_use}/${filter_with_date}")) > 0) { - - if (!empty($wpmu_version)) { - $comic = reset($results); - $comic = $folder_to_use . '/'. basename($comic); - if ($wpmu_path !== false) { $comic = str_replace($wpmu_path, "files", $comic); } - return $comic; - } - - if (!empty($multi)) { - return $results; - } else { - /* clear the root path */ - $comic = reset($results); - $comic = $folder_to_use .'/'. basename($comic); - return $comic; - } - } - - $comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the %s folder that matched the pattern %s. Check your WordPress and ComicPress settings.", 'comicpress'), $folder_to_use, $filter_with_date); - return false; + $mh = new ComicPressMediaHandling(); + return $mh->get_comic_path($folder, $override_post, $filter, $multi); } diff --git a/functions/wpmu.php b/functions/wpmu.php new file mode 100644 index 0000000..f2651dd --- /dev/null +++ b/functions/wpmu.php @@ -0,0 +1,33 @@ +assertEquals($expected_result, _comicpress_expand_filter_callback('original', array())); + $this->assertEquals($expected_result, _comicpress_expand_filter_callback('original', array('all', 'wordpress'))); } function providerTestReadDirectory() { From 23742b8fe2c698d070c852500a345eae01050449 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 2 Dec 2009 22:40:08 -0500 Subject: [PATCH 8/8] fix issue with periods in directory names --- classes/ComicPressMediaHandling.inc | 7 ++++++- test/ComicPressMediaHandlingTest.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 11ac09b..887c1aa 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -58,6 +58,11 @@ class ComicPressMediaHandling { return $result; } + function _resolve_regex_path($input) { + $input = str_replace('\.', '.', $input); + return $input; + } + // @codeCoverageIgnoreStart function _abspath() { return realpath(ABSPATH); @@ -85,7 +90,7 @@ class ComicPressMediaHandling { } function _read_directory($pattern) { - $dirname = dirname($pattern); + $dirname = $this->_resolve_regex_path(dirname($pattern)); $results = false; if (is_dir($dirname)) { $results = array(); diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index d41b15b..03ab451 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -141,6 +141,20 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_results, $this->cpmh->_read_directory($pattern)); } + function providerTestResolveRegexPath() { + return array( + array('test', 'test'), + array('te\.st', 'te.st') + ); + } + + /** + * @dataProvider providerTestResolveRegexPath + */ + function testResolveRegexPath($input, $expected_output) { + $this->assertEquals($expected_output, $this->cpmh->_resolve_regex_path($input)); + } + function providerTestPreHandleComicPathResults() { return array( array('', '', false),