factor out partials code to comicpress

This commit is contained in:
John Bintz 2009-07-29 20:07:56 -04:00
parent 7b1e8b7348
commit 90c7a23747
3 changed files with 35 additions and 12 deletions

View File

@ -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;
}
}
}
}
}
}
?>

View File

@ -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);
}
}

View File

@ -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);
}
}
?>