diff --git a/classes/ComicPressAdmin.inc b/classes/ComicPressAdmin.inc index a3a4568..c59933d 100644 --- a/classes/ComicPressAdmin.inc +++ b/classes/ComicPressAdmin.inc @@ -1,5 +1,7 @@ comicpress_options['backend_options']['filesystem']['search_pattern'] + )) { + return (string)$comicpress->comicpress_options['backend_options']['filesystem']['search_pattern']; + } + + return ''; + } + function generate_from_post($post) { $return = array(); $comicpress = ComicPress::get_instance(); - if (isset( - $comicpress->comicpress_options['backend_options'], - $comicpress->comicpress_options['backend_options']['filesystem'], - $comicpress->comicpress_options['backend_options']['filesystem']['search_pattern'] - )) { - $this->search_pattern = (string)$comicpress->comicpress_options['backend_options']['filesystem']['search_pattern']; - } + $this->search_pattern = $this->_get_search_pattern(); if (isset($comicpress->comicpress_options['image_types'])) { $files = array(); @@ -66,7 +72,6 @@ class ComicPressBackendFilesystemFactory { return $return; } - // TODO Make this more generic (ex: date-Ymd calls _replace_date($post, $type, "Ymd")) function process_search_string($post, $type) { $this->_searches = array($this->search_string); @@ -88,6 +93,7 @@ class ComicPressBackendFilesystemFactory { $result = $this->{$method}($post, $type, $additional); if ($result !== false) { $this->_searches[$i] = str_replace($matches[0], $result, $search); + break; } else { // array state change, start over break; @@ -113,6 +119,16 @@ class ComicPressBackendFilesystemFactory { // @codeCoverageIgnoreEnd function _replace_type($post, $type) { return $type; } + + function _replace_type_folder($post, $type) { + $comicpress = ComicPress::get_instance(); + + if (isset($comicpress->comicpress_options['backend_options']['filesystem']['folders'][$type])) { + return $comicpress->comicpress_options['backend_options']['filesystem']['folders'][$type]; + } + return false; + } + function _replace_date($post, $type, $additional) { return date($additional, strtotime($post->post_date)); } @@ -218,3 +234,56 @@ class ComicPressBackendFilesystemFactory { return $roots; } } + +// @codeCoverageIgnoreStart +class ComicPressBackendFilesystemAdmin { + function options_admin() { + $pattern = ComicPressBackendFilesystemFactory::_get_search_pattern(); + + include('partials/backend-filesystem/options-admin.inc'); + } + + function image_type_holder($type) { + $comicpress = ComicPress::get_instance(); + + $path = ''; + if ( + isset($comicpress->comicpress_options['backend_options']['filesystem']['folders'][$type]) + ) { + $path = $comicpress->comicpress_options['backend_options']['filesystem']['folders'][$type]; + } + + include('partials/backend-filesystem/image-type-holder.inc'); + } + + function handle_update_comicpress_options($info) { + if (isset($info['backend_options']['filesystem'])) { + $info = $info['backend_options']['filesystem']; + $comicpress = ComicPress::get_instance(); + + if (!isset($comicpress->comicpress_options['backend_options'])) { + $comicpress->comicpress_options['backend_options'] = array(); + } + if (!isset($comicpress->comicpress_options['backend_options']['filesystem'])) { + $comicpress->comicpress_options['backend_options']['filesystem'] = array(); + } + + foreach (array('folders', 'search_pattern') as $valid_field) { + if (is_array($info[$valid_field])) { + $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = array(); + foreach ($info[$valid_field] as $field => $value) { + $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field][$field] = strip_tags($value); + } + } else { + $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = strip_tags($info[$valid_field]); + } + } + $comicpress->save(); + } + } +} +// @codeCoverageIgnoreEnd + +add_action('comicpress-options-admin', array('ComicPressBackendFilesystemAdmin', 'options_admin')); +add_action('comicpress-image-type-holder', array('ComicPressBackendFilesystemAdmin', 'image_type_holder'), 10, 1); +add_action('comicpress-handle_update_comicpress_options', array('ComicPressBackendFilesystemAdmin', 'handle_update_comicpress_options'), 10, 1); diff --git a/classes/backends/partials/backend-filesystem/image-type-holder.inc b/classes/backends/partials/backend-filesystem/image-type-holder.inc new file mode 100644 index 0000000..1365075 --- /dev/null +++ b/classes/backends/partials/backend-filesystem/image-type-holder.inc @@ -0,0 +1,7 @@ + + + + +
+ + diff --git a/classes/backends/partials/backend-filesystem/options-admin.inc b/classes/backends/partials/backend-filesystem/options-admin.inc new file mode 100644 index 0000000..8d76576 --- /dev/null +++ b/classes/backends/partials/backend-filesystem/options-admin.inc @@ -0,0 +1,24 @@ +

+
+ + + + + +
+ + + +
+ +

+ URL Pattern is similar to how WordPress permalinks are constructed:', 'comicpress') ?> +

+ + +
diff --git a/classes/partials/_image-type-editor.inc b/classes/partials/_image-type-editor.inc index be7b2ca..4ff358e 100644 --- a/classes/partials/_image-type-editor.inc +++ b/classes/partials/_image-type-editor.inc @@ -28,6 +28,6 @@ () - + diff --git a/classes/partials/options-admin.inc b/classes/partials/options-admin.inc index 9b14391..8007353 100644 --- a/classes/partials/options-admin.inc +++ b/classes/partials/options-admin.inc @@ -35,5 +35,7 @@ + + diff --git a/test/backends/ComicPressBackendFilesystemFactoryTest.php b/test/backends/ComicPressBackendFilesystemFactoryTest.php index 6bdb772..fd457fe 100644 --- a/test/backends/ComicPressBackendFilesystemFactoryTest.php +++ b/test/backends/ComicPressBackendFilesystemFactoryTest.php @@ -99,6 +99,7 @@ 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%/%type-folder%/*.jpg', array('/wordpress/comic-folder/*.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')), @@ -141,6 +142,11 @@ class ComicPressBackendFilesystemFactoryTest extends PHPUnit_Framework_TestCase $fs->search_string = $string; + $comicpress = ComicPress::get_instance(true); + $comicpress->comicpress_options = array( + 'backend_options' => array('filesystem' => array('folders' => array('comic' => 'comic-folder'))) + ); + $this->assertEquals($expected_searches, $fs->process_search_string($posts[$post_id_to_use], 'comic')); } @@ -255,4 +261,43 @@ class ComicPressBackendFilesystemFactoryTest extends PHPUnit_Framework_TestCase function testGetRegexFilename($input, $expected_output) { $this->assertEquals($expected_output, $this->fa->get_regex_filename($input)); } + + function providerTestGetSearchPattern() { + return array( + array(false, ''), + array(true, 'test') + ); + } + + /** + * @dataProvider providerTestGetSearchPattern + */ + function testGetSearchPattern($set_pattern, $expected_result) { + $comicpress = ComicPress::get_instance(true); + if ($set_pattern) { + $comicpress->comicpress_options = array( + 'backend_options' => array('filesystem' => array('search_pattern' => 'test')) + ); + } + + $this->assertEquals($expected_result, $this->fa->_get_search_pattern()); + } + + function providerTestReplaceTypeFolder() { + return array( + array('comic', 'comic'), + array('rss', false) + ); + } + + /** + * @dataProvider providerTestReplaceTypeFolder + */ + function testReplaceTypeFolder($type, $expected_result) { + $comicpress = ComicPress::get_instance(true); + $comicpress->comicpress_options = array( + 'backend_options' => array('filesystem' => array('folders' => array('comic' => 'comic'))) + ); + $this->assertEquals($expected_result, $this->fa->_replace_type_folder(null, $type)); + } }