diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 9f24ab1..76c1307 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -30,6 +30,10 @@ class ComicPressMediaHandling { if (isset($comic_filename_filters[$filter_to_use])) { return $this->_convert_to_percent_filter($comic_filename_filters[$filter_to_use]); } + $options = get_option('comicpress_options'); + if (isset($options['comic_filename_filters'][$filter_to_use])) { + return $this->_convert_to_percent_filter($options['comic_filename_filters'][$filter_to_use]); + } } } @@ -96,6 +100,9 @@ class ComicPressMediaHandling { case 'type-folder': $value = $this->type_folder; break; + case 'upload-path': + $value = get_option('upload_path'); + break; default: if (preg_match('#^date-(.*)$#', $matches[1], $date_matches) > 0) { if (isset($this->post_to_use)) { diff --git a/comicpress-options.php b/comicpress-options.php index 1fe86d8..8a207ef 100644 --- a/comicpress-options.php +++ b/comicpress-options.php @@ -19,6 +19,23 @@ function comicpress_admin_print_styles() { wp_enqueue_style('comicpress-options', get_template_directory_uri() . '/options/options.css'); } +function comicpress_save_options_comic_filename_filters($incoming) { + $filters = array(); + + foreach (array_values($incoming) as $filter) { + $filters[wp_filter_nohtml_kses($filter['name'])] = wp_filter_nohtml_kses($filter['filter']); + } + + if (!empty($filters)) { + if (!isset($filters['default'])) { + $cpmh = new ComicPressMediaHandling(); + $filters['default'] = $cpmh->default_filter; + } + } + + return $filters; +} + function comicpress_admin_page_head() { ?> false, 'enable_scroll_to_top' => false, - 'enable_page_load_info' => false + 'enable_page_load_info' => false, + 'comic_filename_filters' => array() ) as $field => $value) { $comicpress_options[$field] = $value; diff --git a/options/configoptions.php b/options/configoptions.php index dc24c9d..8a1ab90 100644 --- a/options/configoptions.php +++ b/options/configoptions.php @@ -112,7 +112,7 @@ - + @@ -135,7 +135,7 @@ - + @@ -147,18 +147,86 @@ - + - + + default_filter; + } + ?> + + + +

+ For advanced users. Specify the filters used to find the filename. +

+
+
+ + +

+ Available parameters: +

+ + + diff --git a/options/options.css b/options/options.css index f7621fa..11c8287 100644 --- a/options/options.css +++ b/options/options.css @@ -221,3 +221,20 @@ div.show .cpadmin-footer img{ min-width: 80px; text-align: center; } + +/** Comic Filters **/ + +#comicpress-comic-filename-filters-holder div { + border: solid #ddd 1px; + padding: 3px; + overflow: hidden; +} + +#comicpress-comic-filename-filters-holder label { + float: left; + display: inline; +} + +#comicpress-comic-filename-filters-holder input { + margin: 0 10px; +} diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 899d550..d79578a 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -41,7 +41,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { array(null, $default), array('fail', $default), array(array(), $default), - array('test', 'test') + array('test', 'test'), + array('test-from-option', 'test-from-option'), ); } @@ -53,6 +54,12 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $comic_filename_filters['test'] = 'test'; + update_option('comicpress_options', array( + 'comic_filename_filters' => array( + 'test-from-option' => 'test-from-option' + ) + )); + $default = str_replace('{date}', $this->cpmh->default_filename_filter, $this->cpmh->default_filter); $cpmh = $this->getMock('ComicPressMediaHandling', array('_convert_to_percent_filter')); @@ -95,7 +102,8 @@ 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%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*'), + array('%wordpress%/%upload-path%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/1/files/comic/2009-01-01.*\..*') ); } @@ -106,6 +114,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $cpmh = $this->getMock('ComicPressMediaHandling', array('_abspath')); $cpmh->expects($this->any())->method('_abspath')->will($this->returnValue(vfsStream::url('root'))); + update_option('upload_path', '1/files'); + $this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00'))); } diff --git a/test/ComicPressOptionsAdminTest.php b/test/ComicPressOptionsAdminTest.php new file mode 100644 index 0000000..aa363b7 --- /dev/null +++ b/test/ComicPressOptionsAdminTest.php @@ -0,0 +1,43 @@ + array( + 'name' => 'test', 'filter' => 'myfilter' + )), + array( + 'default' => $cpmh->default_filter, + 'test' => 'myfilter' + ) + ), + array( + array(1 => array( + 'name' => 'default', 'filter' => 'test' + )), + array( + 'default' => 'test' + ) + ) + ); + } + + /** + * @dataProvider providerTestSaveComicFilenameFilters + */ + function testSaveComicFilenameFilters($incoming, $expected) { + $this->assertEquals($expected, comicpress_save_options_comic_filename_filters($incoming)); + } +} diff --git a/test/ComicPressRelatedPostsTest.php b/test/ComicPressRelatedPostsTest.php index 9291b85..e739117 100644 --- a/test/ComicPressRelatedPostsTest.php +++ b/test/ComicPressRelatedPostsTest.php @@ -11,7 +11,6 @@ class ComicPressRelatedPostsTest extends PHPUnit_Framework_TestCase { } function testBuildPostTable() { - $this->markTestIncomplete(); $posts = array( (object)array('ID' => 1, 'post_date' => '2009-01-01', 'post_title' => 'Post 1', 'guid' => 'post-1'), (object)array('ID' => 2, 'post_date' => '2009-01-02', 'post_title' => 'Post 2', 'guid' => 'post-2'), @@ -32,7 +31,7 @@ class ComicPressRelatedPostsTest extends PHPUnit_Framework_TestCase { wp_set_post_categories($id, $cats); } - $output = ''; + $output = ''; $this->rp->related_categories = array(2); diff --git a/test/selenium/TestComicFilenameFilters.html b/test/selenium/TestComicFilenameFilters.html new file mode 100644 index 0000000..74b3686 --- /dev/null +++ b/test/selenium/TestComicFilenameFilters.html @@ -0,0 +1,154 @@ + + + + + + +TestComicFilenameFilters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TestComicFilenameFilters
clickAndWaitlink=ComicPress Options
click//div[@id='comicpress-tab-config']/span
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divfilter_count
while${filter_count} > 0
click//div[@id='comicpress-comic-filename-filters-holder']/div[1]/a
assertConfirmationAre you sure?
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divfilter_count
endWhile
clickAndWaitcomicpress_save_config
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divfilter_count
echo${filter_count}
clickadd-new-filter
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divnew_filter_count
assertEval(${new_filter_count}) == (${filter_count} + 1)true
clickAndWaitcomicpress_save_config
assertTextPresentComicPress Settings SAVED!
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divnew_filter_count
assertEval(${new_filter_count}) == (${filter_count} + 1)true
click//div[@id='comicpress-comic-filename-filters-holder']/div[2]/a
assertConfirmationAre you sure?
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divnew_filter_count
assertEval(${new_filter_count}) == (${filter_count})true
clickAndWaitcomicpress_save_config
assertTextPresentComicPress Settings SAVED!
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divnew_filter_count
assertEval(${new_filter_count}) == (${filter_count})true
assertTextPresentComicPress Settings SAVED!
+ +