From 90c7a23747430b0d4e95b8ab030a2b9ace8ff1bc Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 29 Jul 2009 20:07:56 -0400 Subject: [PATCH] factor out partials code to comicpress --- classes/ComicPress.inc | 17 +++++++++++++++++ functions.php | 14 ++------------ test/ComicPressTest.php | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 38b55f0..63dc3d4 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -548,6 +548,23 @@ class ComicPress { return $sorted_categories; } + + function _is_dir($dir) { return is_dir($dir); } + + function setup_multicomic_partial_paths($post_id) { + $this->partial_paths = array(); + $category_ids = wp_get_post_categories($post_id); + if (is_array($category_ids)) { + foreach ($category_ids as $id) { + $category = get_category($id); + if (!empty($category)) { + if ($this->_is_dir($target = get_template_directory() . '/subthemes/' . $category->slug)) { + $this->partial_paths[] = $target; + } + } + } + } + } } ?> \ No newline at end of file diff --git a/functions.php b/functions.php index 91a0391..6fa8dbd 100644 --- a/functions.php +++ b/functions.php @@ -64,18 +64,8 @@ function comicpress_init() { global $post, $comicpress; if (!empty($post)) { - if (in_comic_category() && $comicpress->is_multicomic()) { - $category_ids = wp_get_post_categories($post->ID); - if (is_array($category_ids)) { - foreach ($category_ids as $id) { - $category = get_category($id); - if (!empty($category)) { - if (is_dir($target = get_template_directory() . '/subthemes/' . $category->slug)) { - $comicpress->partial_paths[] = $target; - } - } - } - } + if (in_comic_category() && $comicpress->is_multicomic() && !is_index()) { + $comicpress->setup_multicomic_partial_paths($post->ID); } } diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php index 6641706..2ab9455 100644 --- a/test/ComicPressTest.php +++ b/test/ComicPressTest.php @@ -407,6 +407,22 @@ FILE $this->assertEquals($expected_sort_order, $this->cp->get_sorted_post_categories((object)array('ID' => 1))); } + + function testSetupMulticomicPartialPaths() { + $cp = $this->getMock('ComicPress', array('_is_dir')); + + wp_set_post_categories(1, array('2', '3')); + + add_category('2', (object)array('slug' => 'test-one')); + add_category('3', (object)array('slug' => 'test-two')); + + $cp->expects($this->at(0))->method('_is_dir')->with('/subthemes/test-one')->will($this->returnValue(true)); + $cp->expects($this->at(1))->method('_is_dir')->with('/subthemes/test-two')->will($this->returnValue(false)); + + $cp->setup_multicomic_partial_paths(1); + + $this->assertEquals(array('/subthemes/test-one'), $cp->partial_paths); + } } ?> \ No newline at end of file