From a5a72a912800b95d52d422cd621f574c68976c05 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 27 Nov 2009 19:48:01 -0500 Subject: [PATCH] build in post page link --- .../widgets/GraphicalNavigationWidgetTest.php | 33 ++++++++++++++++--- widgets/GraphicalNavigationWidget.inc | 16 +++++++-- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/test/widgets/GraphicalNavigationWidgetTest.php b/test/widgets/GraphicalNavigationWidgetTest.php index cab99c2..e6a9c51 100644 --- a/test/widgets/GraphicalNavigationWidgetTest.php +++ b/test/widgets/GraphicalNavigationWidgetTest.php @@ -88,7 +88,7 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_grouping, $this->w->_group_navigation_buttons($buttons, array())); } - function providerTestSetUpPostNav() { + function providerTestSetUpPostNavStoryPrev() { return array( array( array('story_prev_acts_as_prev_in' => 'off'), @@ -114,10 +114,35 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase { } /** - * @dataProvider providerTestSetUpPostNav + * @dataProvider providerTestSetUpPostNavStoryPrev */ - function testComicPressSetUpPostNavFilter($instance, $post_nav, $expected_post_nav) { - $this->assertEquals($expected_post_nav, array_shift($this->w->comicpress_set_up_post_nav($post_nav, $instance))); + function testComicPressSetUpPostNavFilterStoryPrev($instance, $post_nav, $expected_post_nav) { + $this->assertEquals($expected_post_nav, array_shift($this->w->_comicpress_set_up_post_nav_story_prev($post_nav, $instance))); + } + + /*function testComicPressSetUpPostNavFilterMultiPageSupport($instance, $post_nav, $_page, $_numpages, $expected_post_nav) { + global $post, $page, $numpages; + + $post = (object)array('ID' => 1); + }*/ + + function providerTestBuildInPostPageLink() { + return array( + array('', 'publish', 'post-guid&page=2'), + array('test', 'publish', 'post-guid/2'), + array('test/', 'publish', 'post-guid/2/'), + array('test/', 'draft', 'post-guid&page=2'), + ); + } + + /** + * @dataProvider providerTestBuildInPostPageLink + */ + function testBuildInPostPageLink($permalink_structure, $post_status, $expected_link) { + update_option('permalink_structure', $permalink_structure); + $post = (object)array('guid' => 'post-guid', 'post_status' => $post_status); + + $this->assertEquals($expected_link, $this->w->_build_in_post_page_link($post, 2)); } function testSetUpPostNav() { diff --git a/widgets/GraphicalNavigationWidget.inc b/widgets/GraphicalNavigationWidget.inc index 5a3c39c..4370474 100644 --- a/widgets/GraphicalNavigationWidget.inc +++ b/widgets/GraphicalNavigationWidget.inc @@ -25,7 +25,11 @@ class GraphicalNavigationWidget extends WP_Widget { add_filter('comicpress_wrap_navigation_buttons', array(&$this, 'comicpress_wrap_navigation_buttons'), 10, 2); add_filter('comicpress_navigation_grouping_details', array(&$this, 'comicpress_navigation_grouping_details')); - add_filter('comicpress_set_up_post_nav', array(&$this, 'comicpress_set_up_post_nav'), 10, 2); + foreach (get_class_methods($this) as $method) { + if (strpos($method, '_comicpress_set_up_post_nav') === 0) { + add_filter('comicpress_set_up_post_nav', array(&$this, $method), 10, 2); + } + } // these two need to be moved one level up add_filter('comicpress_get_random_link_url', array(&$this, 'comicpress_get_random_link_url')); @@ -299,7 +303,15 @@ class GraphicalNavigationWidget extends WP_Widget { } } - function comicpress_set_up_post_nav($post_nav, $instance) { + function _build_in_post_page_link($post, $page) { + if (!get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending'))) { + return get_permalink($post) . "&page=${page}"; + } else { + return trailingslashit(get_permalink($post)) . user_trailingslashit($page, 'single_paged'); + } + } + + function _comicpress_set_up_post_nav_story_prev($post_nav, $instance) { if ($instance['story_prev_acts_as_prev_in'] == 'on') { if ($post_nav['storyline-previous'] !== false) { $post_nav['storyline-chapter-previous'] = $post_nav['storyline-previous'];