make first link work with multipage
This commit is contained in:
parent
0b9e530582
commit
81832d0b5a
|
@ -28,18 +28,24 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
function providerTestIsNavLinkVisible() {
|
function providerTestIsNavLinkVisible() {
|
||||||
return array(
|
return array(
|
||||||
array('first', 1, 2, true),
|
array('first', 1, 2, 1, 1, true),
|
||||||
array('first', 1, 1, false),
|
array('first', 1, 1, 1, 1, false),
|
||||||
array('last', 1, 2, true),
|
array('last', 1, 2, 1, 1, true),
|
||||||
array('last', 1, 1, false),
|
array('last', 1, 1, 1, 1, false),
|
||||||
array('prev', 1, 2, true),
|
array('prev', 1, 2, 1, 1, true),
|
||||||
|
array('first', 1, 1, 2, 2, true),
|
||||||
|
array('first', 1, 1, 1, 2, false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerTestIsNavLinkVisible
|
* @dataProvider providerTestIsNavLinkVisible
|
||||||
*/
|
*/
|
||||||
function testIsNavLinkVisible($which, $current_id, $target_id, $expected_result) {
|
function testIsNavLinkVisible($which, $current_id, $target_id, $_page, $_numpages, $expected_result) {
|
||||||
|
global $page, $numpages;
|
||||||
|
$page = $_page;
|
||||||
|
$numpages = $_numpages;
|
||||||
|
|
||||||
$current = (object)array('ID' => $current_id);
|
$current = (object)array('ID' => $current_id);
|
||||||
$target = (object)array('ID' => $target_id);
|
$target = (object)array('ID' => $target_id);
|
||||||
|
|
||||||
|
|
|
@ -170,10 +170,16 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
* @return boolean True if this link should be visible.
|
* @return boolean True if this link should be visible.
|
||||||
*/
|
*/
|
||||||
function _will_display_nav_link($which, $current, $target) {
|
function _will_display_nav_link($which, $current, $target) {
|
||||||
|
global $page, $numpages;
|
||||||
|
|
||||||
$return = true;
|
$return = true;
|
||||||
|
|
||||||
switch ($which) {
|
switch ($which) {
|
||||||
case 'first':
|
case 'first':
|
||||||
|
if ($page != 1 && $numpages > 1) {
|
||||||
|
$return = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'last':
|
case 'last':
|
||||||
$return = ($target->ID != $current->ID);
|
$return = ($target->ID != $current->ID);
|
||||||
break;
|
break;
|
||||||
|
@ -335,6 +341,10 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
return array($post_nav, $post, $instance);
|
return array($post_nav, $post, $instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _get_page_count($post) {
|
||||||
|
return preg_match_all('#<!--nextpage-->#', $post->post_content, $matches);
|
||||||
|
}
|
||||||
|
|
||||||
function _comicpress_set_up_post_nav_multi_page_support($info) {
|
function _comicpress_set_up_post_nav_multi_page_support($info) {
|
||||||
global $page, $numpages;
|
global $page, $numpages;
|
||||||
list($post_nav, $post, $instance) = $info;
|
list($post_nav, $post, $instance) = $info;
|
||||||
|
@ -349,7 +359,7 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
if ($page == 1) {
|
if ($page == 1) {
|
||||||
foreach (array('previous', 'previous_storyline') as $which) {
|
foreach (array('previous', 'previous_storyline') as $which) {
|
||||||
if (isset($post_nav[$which])) {
|
if (isset($post_nav[$which])) {
|
||||||
$count = preg_match_all('#<!--nextpage-->#', $post_nav[$which]->post_content, $matches);
|
$count = $this->_get_page_count($post_nav[$which]);
|
||||||
if (!empty($count)) {
|
if (!empty($count)) {
|
||||||
$post_nav[$which] = $this->_build_in_post_page_link($post_nav[$which], $count + 1);
|
$post_nav[$which] = $this->_build_in_post_page_link($post_nav[$which], $count + 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue