diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index b4dae99..5246823 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -413,7 +413,7 @@ class ComicPressAddonCore extends ComicPressAddon { $this->comicpress->comicpress_options[$option] = (int)$_POST['cp'][$option]; break; case 'comic_space': - case 'category_page_usage': + case 'category_usage': case 'layout'; $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; break; diff --git a/addons/Core/partials/options-admin.inc b/addons/Core/partials/options-admin.inc index cd7d6ae..75eca70 100644 --- a/addons/Core/partials/options-admin.inc +++ b/addons/Core/partials/options-admin.inc @@ -73,7 +73,7 @@ - Insert into comic space: + __("The comic only, with post content below", 'comicpress'), @@ -84,13 +84,13 @@ - Use comic category pages as: + __("The normal way, as a list of posts in that category", 'comicpress'), - "comic_frontpage" => __("As the front page to the comics in that category", 'comicpress') + "storyline" => __("Storyline indicators for a single comic", 'comicpress'), + "multicomic" => __("Multicomic indicators, with direct descendents being separate comics", 'comicpress') ) as $value => $label) { ?> -
+
diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index f06ec77..88f048f 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -13,7 +13,7 @@ class ComicPress { 'category_order' => false, 'blogpost_count' => 10, 'comic_space' => 'comic_only', - 'category_page_usage' => 'archive_list', + 'category_usage' => 'storyline', 'layout' => 'classic.inc', 'helpers' => array() ); @@ -70,6 +70,14 @@ class ComicPress { } } + function needs_storyline_nav() { + return (count($this->category_tree) > 1) && ($this->comicpress_options['category_usage'] == "storyline"); + } + + function is_multicomic() { + return $this->comicpress_options['category_usage'] == "multicomic"; + } + function wp_head() { foreach ($this->additional_stylesheets as $uri) { ?> @@ -463,6 +471,24 @@ class ComicPress { return $prev_next_categories; } + + function get_sorted_post_categories($override_post = null) { + global $post; + $post_to_use = (!empty($override_post)) ? $override_post : $post; + + $categories = wp_get_post_categories($post_to_use->ID); + + $sorted_categories = array(); + + foreach ($this->category_tree as $node) { + $category_id = end(explode("/", $node)); + if (in_array($category_id, $categories)) { + $sorted_categories[] = $category_id; + } + } + + return $sorted_categories; + } } ?> \ No newline at end of file diff --git a/functions.php b/functions.php index 4e31553..91a0391 100644 --- a/functions.php +++ b/functions.php @@ -64,7 +64,7 @@ function comicpress_init() { global $post, $comicpress; if (!empty($post)) { - if (in_comic_category()) { + 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) { diff --git a/partials/index-comic-post.inc b/partials/index-comic-post.inc index 71625cf..a6192bf 100644 --- a/partials/index-comic-post.inc +++ b/partials/index-comic-post.inc @@ -1,26 +1,17 @@
-
- -
-
- - - +
+

-
- -
+
-
- -
+
-
+
\ No newline at end of file diff --git a/partials/nav.inc b/partials/nav.inc index b9d88a9..f2db2e1 100644 --- a/partials/nav.inc +++ b/partials/nav.inc @@ -1,26 +1,53 @@ - + '‹‹ ' . __('First', 'comicpress'), + 'previous' => '‹ ' . __('Previous', 'comicpress'), + 'next' => __('Next', 'comicpress') . ' ›', + 'last' => __('Last', 'comicpress') . ' ››' + ); + + if ($comicpress->needs_storyline_nav()) { + $nav_fields = array_merge( + array('prior' => '‹‹ ' . __('Prior Storyline', 'comicpress')), + $nav_fields, + array('upcoming' => __('Upcoming Storyline', 'comicpress') . ' ››') + ); + + foreach ($comicpress->get_sorted_post_categories() as $category_id) { + $prev_next_categories = $comicpress->get_previous_next_categories($category_id); + + foreach ($prev_next_categories as $master_id => $cat_list) { + foreach ($cat_list as $which => $id) { + switch ($which) { + case "previous": + $terminal_post = $comicpress->get_last_comic($id); + $which_field = "prior"; + break; + case "next": + $terminal_post = $comicpress->get_first_comic($id); + $which_field = "upcoming"; + break; + } + + if (is_object($terminal_post)) { + $nav_comics[$which_field] = $terminal_post; + $nav_comics["show_${which_field}"] =true; + } + + if (count($terminal_post) == 2) { break; } + } + } + } + } + + ?> + \ No newline at end of file diff --git a/single.php b/single.php index cc37c34..cc17426 100644 --- a/single.php +++ b/single.php @@ -1,7 +1,7 @@ get_nav_comics(); diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php index 3812479..f328228 100644 --- a/test/ComicPressTest.php +++ b/test/ComicPressTest.php @@ -276,6 +276,37 @@ FILE $this->assertEquals($expected_results, $cp->get_layout_choices()); } + + function providerTestGetSortedPostCategories() { + return array( + array( + array(1), + array('0/1'), + array(1) + ), + array( + array(2, 1), + array('0/1', '0/1/2'), + array(1, 2) + ), + array( + array(2, 1), + array('0/1', '0/1/3', '0/1/2'), + array(1, 2) + ), + ); + } + + /** + * @dataProvider providerTestGetSortedPostCategories + */ + function testGetSortedPostCategories($post_categories, $category_tree, $expected_sort_order) { + $this->cp->category_tree = $category_tree; + + wp_set_post_categories(1, $post_categories); + + $this->assertEquals($expected_sort_order, $this->cp->get_sorted_post_categories((object)array('ID' => 1))); + } } ?> \ No newline at end of file