multipage link filtering

This commit is contained in:
John Bintz 2009-11-28 10:32:34 -05:00
parent a5a72a9128
commit 50bbc6ff5a
2 changed files with 86 additions and 8 deletions

View File

@ -117,14 +117,77 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
* @dataProvider providerTestSetUpPostNavStoryPrev
*/
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)));
$this->assertEquals($expected_post_nav, array_shift($this->w->_comicpress_set_up_post_nav_story_prev($post_nav, null, $instance)));
}
/*function testComicPressSetUpPostNavFilterMultiPageSupport($instance, $post_nav, $_page, $_numpages, $expected_post_nav) {
function providerTestComicPressSetUpPostNavFilterMultiPageSupport() {
return array(
array(
array('enable_multipage_support' => 'off'),
array('previous' => 'prev-post', 'next' => 'next-post'),
1, 4,
array('previous' => 'prev-post', 'next' => 'next-post')
),
array(
array('enable_multipage_support' => 'on'),
array('previous' => 'prev-post', 'next' => 'next-post'),
1, 1,
array('previous' => 'prev-post', 'next' => 'next-post')
),
array(
array('enable_multipage_support' => 'on'),
array('previous' => 'prev-post', 'next' => 'next-post'),
1, 2,
array(
'previous' => 'prev-post',
'next' => 'current-post/2/',
'storyline-next' => 'current-post/2/',
)
),
array(
array('enable_multipage_support' => 'on'),
array('previous' => 'prev-post', 'next' => 'next-post'),
2, 2,
array(
'previous' => 'current-post/1/',
'storyline-previous' => 'current-post/1/',
'next' => 'next-post'
)
),
array(
array('enable_multipage_support' => 'on'),
array(
'previous' => 'prev-post',
'next' => 'next-post',
'storyline-previous' => 'prev-post',
'storyline-next' => 'next-post',
),
2, 3,
array(
'previous' => 'current-post/1/',
'next' => 'current-post/3/',
'storyline-previous' => 'current-post/1/',
'storyline-next' => 'current-post/3/',
)
),
);
}
/**
* @dataProvider providerTestComicPressSetUpPostNavFilterMultiPageSupport
* @return unknown_type
*/
function testComicPressSetUpPostNavFilterMultiPageSupport($instance, $post_nav, $_page, $_numpages, $expected_post_nav) {
global $post, $page, $numpages;
$post = (object)array('ID' => 1);
}*/
update_option('permalink_structure', '/test/');
$post = (object)array('ID' => 1, 'guid' => 'current-post', 'post_status' => 'publish');
$page = $_page;
$numpages = $_numpages;
$this->assertEquals($expected_post_nav, array_shift($this->w->_comicpress_set_up_post_nav_multi_page_support($post_nav, $post, $instance)));
}
function providerTestBuildInPostPageLink() {
return array(

View File

@ -27,7 +27,7 @@ class GraphicalNavigationWidget extends WP_Widget {
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);
add_filter('comicpress_set_up_post_nav', array(&$this, $method), 10, 3);
}
}
@ -295,7 +295,7 @@ class GraphicalNavigationWidget extends WP_Widget {
$navigation->init($storyline);
$post_nav = $navigation->get_post_nav($post);
$result = apply_filters('comicpress_set_up_post_nav', $post_nav, $instance);
$result = apply_filters('comicpress_set_up_post_nav', $post_nav, $post, $instance);
if (is_array($result)) {
return array_shift($result);
} else {
@ -311,13 +311,28 @@ class GraphicalNavigationWidget extends WP_Widget {
}
}
function _comicpress_set_up_post_nav_story_prev($post_nav, $instance) {
function _comicpress_set_up_post_nav_story_prev($post_nav, $post, $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'];
}
}
return array($post_nav, $instance);
return array($post_nav, $post, $instance);
}
function _comicpress_set_up_post_nav_multi_page_support($post_nav, $post, $instance) {
global $page, $numpages;
if ($instance['enable_multipage_support'] == 'on') {
if ($page < $numpages && $numpages != 1) {
$post_nav['next'] = $post_nav['storyline-next'] = $this->_build_in_post_page_link($post, $page + 1);
}
if ($page != 1 && $numpages > 1) {
$post_nav['previous'] = $post_nav['storyline-previous'] = $this->_build_in_post_page_link($post, $page - 1);
}
}
return array($post_nav, $post, $instance);
}
/**