refactor class and link code and code coverage
This commit is contained in:
parent
50bbc6ff5a
commit
ba6281b2c3
|
@ -3,3 +3,4 @@
|
||||||
.project
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
coverage/
|
||||||
|
|
|
@ -10,9 +10,6 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->w = new GraphicalNavigationWidget();
|
$this->w = new GraphicalNavigationWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers WidgetComicPressGraphicalStorylineNavigation::update
|
|
||||||
*/
|
|
||||||
function testUpdateWidget() {
|
function testUpdateWidget() {
|
||||||
$result = $this->w->update(array(
|
$result = $this->w->update(array(
|
||||||
"next" => "<b>test</b>",
|
"next" => "<b>test</b>",
|
||||||
|
@ -41,7 +38,6 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerTestIsNavLinkVisible
|
* @dataProvider providerTestIsNavLinkVisible
|
||||||
* @covers WidgetComicPressGraphicalStorylineNavigation::_will_display_nav_link
|
|
||||||
*/
|
*/
|
||||||
function testIsNavLinkVisible($which, $current_id, $target_id, $expected_result) {
|
function testIsNavLinkVisible($which, $current_id, $target_id, $expected_result) {
|
||||||
$current = (object)array('ID' => $current_id);
|
$current = (object)array('ID' => $current_id);
|
||||||
|
@ -76,7 +72,6 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerTestGroupNavigationButtons
|
* @dataProvider providerTestGroupNavigationButtons
|
||||||
* @covers WidgetComicPressGraphicalStorylineNavigation::_group_navigation_buttons
|
|
||||||
*/
|
*/
|
||||||
function testGroupNavigationButtons($buttons, $expected_grouping) {
|
function testGroupNavigationButtons($buttons, $expected_grouping) {
|
||||||
_set_filter_expectation('comicpress_navigation_grouping_details', array(array(
|
_set_filter_expectation('comicpress_navigation_grouping_details', array(array(
|
||||||
|
@ -88,6 +83,14 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals($expected_grouping, $this->w->_group_navigation_buttons($buttons, array()));
|
$this->assertEquals($expected_grouping, $this->w->_group_navigation_buttons($buttons, array()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException PHPUnit_Framework_Error
|
||||||
|
*/
|
||||||
|
function testGroupNavigationButtonsNoDefaultGroup() {
|
||||||
|
_set_filter_expectation('comicpress_navigation_grouping_details', array(array()));
|
||||||
|
$this->w->_group_navigation_buttons(array(), array());
|
||||||
|
}
|
||||||
|
|
||||||
function providerTestSetUpPostNavStoryPrev() {
|
function providerTestSetUpPostNavStoryPrev() {
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
|
@ -230,6 +233,43 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$css->set_up_post_nav(array());
|
$css->set_up_post_nav(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestGetLinkNaviClassNames() {
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
'previous', (object)array('guid' => 'previous'), array(), array(
|
||||||
|
'link' => 'previous',
|
||||||
|
'navi_class_names' => array('navi-previous', 'navi-prev')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'last', (object)array('guid' => 'last'), array('lastgohome' => 'off'), array(
|
||||||
|
'link' => 'last',
|
||||||
|
'navi_class_names' => array('navi-last')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'last', (object)array('guid' => 'last'), array('lastgohome' => 'on'), array(
|
||||||
|
'link' => 'home',
|
||||||
|
'navi_class_names' => array('navi-last')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'next', 'next', array(), array(
|
||||||
|
'link' => 'next',
|
||||||
|
'navi_class_names' => array('navi-next')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestGetLinkNaviClassNames
|
||||||
|
*/
|
||||||
|
function testGetLinkNaviClassNames($which, $target, $instance, $expected_results) {
|
||||||
|
_set_bloginfo('url', 'home');
|
||||||
|
$this->assertEquals($expected_results, $this->w->_get_link_navi_class_names($which, null, $target, $instance));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -11,6 +11,7 @@ Author URI: http://frumph.net/
|
||||||
require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc');
|
require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc');
|
||||||
|
|
||||||
class GraphicalNavigationWidget extends WP_Widget {
|
class GraphicalNavigationWidget extends WP_Widget {
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function GraphicalNavigationWidget() {
|
function GraphicalNavigationWidget() {
|
||||||
$widget_ops = array('classname' => 'WidgetComicPressGraphicalStorylineNavigation', 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') );
|
$widget_ops = array('classname' => 'WidgetComicPressGraphicalStorylineNavigation', 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') );
|
||||||
$this->WP_Widget('graphicalstorylinenavigation', __('Comic Navigation','comicpress'), $widget_ops);
|
$this->WP_Widget('graphicalstorylinenavigation', __('Comic Navigation','comicpress'), $widget_ops);
|
||||||
|
@ -23,13 +24,13 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
add_filter('comicpress_display_navigation_order', array(&$this, 'comicpress_display_navigation_order'));
|
add_filter('comicpress_display_navigation_order', array(&$this, 'comicpress_display_navigation_order'));
|
||||||
add_filter('comicpress_display_navigation_link', array(&$this, 'comicpress_display_navigation_link'), 10, 5);
|
add_filter('comicpress_display_navigation_link', array(&$this, 'comicpress_display_navigation_link'), 10, 5);
|
||||||
add_filter('comicpress_wrap_navigation_buttons', array(&$this, 'comicpress_wrap_navigation_buttons'), 10, 2);
|
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_navigation_grouping_details', array(&$this, 'comicpress_navigation_grouping_details'));
|
||||||
|
|
||||||
foreach (get_class_methods($this) as $method) {
|
foreach (get_class_methods($this) as $method) {
|
||||||
if (strpos($method, '_comicpress_set_up_post_nav') === 0) {
|
if (strpos($method, '_comicpress_set_up_post_nav') === 0) {
|
||||||
add_filter('comicpress_set_up_post_nav', array(&$this, $method), 10, 3);
|
add_filter('comicpress_set_up_post_nav', array(&$this, $method), 10, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// these two need to be moved one level up
|
// these two need to be moved one level up
|
||||||
add_filter('comicpress_get_random_link_url', array(&$this, 'comicpress_get_random_link_url'));
|
add_filter('comicpress_get_random_link_url', array(&$this, 'comicpress_get_random_link_url'));
|
||||||
|
@ -58,26 +59,20 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
function comicpress_display_navigation_link($which, $current, $target, $instance, $content = '') {
|
function comicpress_display_navigation_link($which, $current, $target, $instance, $content = '') {
|
||||||
global $id;
|
global $id;
|
||||||
|
|
||||||
$css_name_mapping = array(
|
|
||||||
'story_prev' => 'prevchap',
|
|
||||||
'previous' => 'prev',
|
|
||||||
'story_next' => 'nextchap'
|
|
||||||
);
|
|
||||||
|
|
||||||
$ok = true;
|
$ok = true;
|
||||||
switch ($which) {
|
switch ($which) {
|
||||||
case 'first':
|
case 'first':
|
||||||
case 'last':
|
case 'last':
|
||||||
$ok = $this->_will_display_nav_link($which, $current, $target);
|
$ok = $this->_will_display_nav_link($which, $current, $target);
|
||||||
break;
|
break;
|
||||||
case 'previous':
|
case 'previous':
|
||||||
case 'next':
|
case 'next':
|
||||||
case 'story_prev':
|
case 'story_prev':
|
||||||
case 'story_next':
|
case 'story_next':
|
||||||
case 'story_prev_in':
|
case 'story_prev_in':
|
||||||
case 'story_next_in':
|
case 'story_next_in':
|
||||||
$ok = !empty($target);
|
$ok = !empty($target);
|
||||||
break;
|
break;
|
||||||
case 'archives':
|
case 'archives':
|
||||||
$ok = !empty($instance['archive_path']);
|
$ok = !empty($instance['archive_path']);
|
||||||
break;
|
break;
|
||||||
|
@ -85,57 +80,43 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
switch ($which) {
|
switch ($which) {
|
||||||
case 'first':
|
case 'first':
|
||||||
case 'previous':
|
case 'previous':
|
||||||
case 'next':
|
case 'next':
|
||||||
case 'last':
|
case 'last':
|
||||||
case 'story_prev':
|
case 'story_prev':
|
||||||
case 'story_next':
|
case 'story_next':
|
||||||
case 'story_prev_in':
|
case 'story_prev_in':
|
||||||
case 'story_next_in':
|
case 'story_next_in':
|
||||||
$obj_ok = false;
|
extract($this->_get_link_navi_class_names($which, $current, $target, $instance));
|
||||||
$navi_class_names = array("navi-${which}");
|
|
||||||
$link = false;
|
|
||||||
if (is_object($target)) {
|
|
||||||
$obj_ok = true;
|
|
||||||
if (isset($css_name_mapping[$which])) { $navi_class_names[] = "navi-{$css_name_mapping[$which]}"; }
|
|
||||||
|
|
||||||
$link = get_permalink($target->ID);
|
if ($ok && $link) {
|
||||||
if (($which == 'last') && ($instance['lastgohome'] == 'on')) { $link = get_bloginfo('url'); }
|
?><a href="<?php echo $link; ?>"
|
||||||
}
|
class="navi <?php echo implode(" ", $navi_class_names); ?>"
|
||||||
|
|
||||||
if (($filter_link = array_shift(apply_filters('comicpress_display_navigation_link', $link, $which, $current, $target, $instance))) !== false) {
|
|
||||||
$link = $filter_link;
|
|
||||||
$obj_ok = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($ok && $obj_ok) {
|
|
||||||
?><a href="<?php echo $link; ?>"
|
|
||||||
class="navi <?php echo implode(" ", $navi_class_names); ?>"
|
|
||||||
title="<?php echo $instance["${which}_title"]; ?>"><?php echo htmlspecialchars_decode($instance["${which}_title"]); ?></a><?php
|
title="<?php echo $instance["${which}_title"]; ?>"><?php echo htmlspecialchars_decode($instance["${which}_title"]); ?></a><?php
|
||||||
} else {
|
} else {
|
||||||
?><span class="navi <?php echo implode(" ", $navi_class_names); ?> navi-void"><?php echo htmlspecialchars_decode($instance["${which}_title"]); ?></span><?php
|
?><span class="navi <?php echo implode(" ", $navi_class_names); ?> navi-void"><?php echo htmlspecialchars_decode($instance["${which}_title"]); ?></span><?php
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'archives':
|
case 'archives':
|
||||||
?><a href="<?php echo $instance['archive_path']; ?>"
|
?><a href="<?php echo $instance['archive_path']; ?>"
|
||||||
class="navi navi-archives navi-archive"
|
class="navi navi-archives navi-archive"
|
||||||
title="<?php echo $instance['archives_title']; ?>"><?php echo $instance['archives_title']; ?></a><?php
|
title="<?php echo $instance['archives_title']; ?>"><?php echo $instance['archives_title']; ?></a><?php
|
||||||
break;
|
break;
|
||||||
case 'random':
|
case 'random':
|
||||||
?><a href="<?php echo apply_filters('comicpress_get_random_link_url', '') ?>"
|
?><a href="<?php echo apply_filters('comicpress_get_random_link_url', '') ?>"
|
||||||
class="navi navi-random"
|
class="navi navi-random"
|
||||||
title="<?php echo $instance['random_title']; ?>"><?php echo $instance['random_title']; ?></a><?php
|
title="<?php echo $instance['random_title']; ?>"><?php echo $instance['random_title']; ?></a><?php
|
||||||
break;
|
break;
|
||||||
case 'comictitle':
|
case 'comictitle':
|
||||||
?><span class="navi-comictitle"><a href="<?php echo get_permalink($current) ?>"><?php echo get_the_title($current->ID); ?></a></span><?php
|
?><span class="navi-comictitle"><a href="<?php echo get_permalink($current) ?>"><?php echo get_the_title($current->ID); ?></a></span><?php
|
||||||
break;
|
break;
|
||||||
case 'comments':
|
case 'comments':
|
||||||
$temp_id = $id;
|
$temp_id = $id;
|
||||||
$id = $current->ID;
|
$id = $current->ID;
|
||||||
?><a href="<?php echo get_permalink($current); ?>#comments"
|
?><a href="<?php echo get_permalink($current); ?>#comments"
|
||||||
class="navi navi-comments"
|
class="navi navi-comments"
|
||||||
title="<?php echo $instance['comments_title']; ?>"><span class="navi-comments-count"><?php comments_number('0', '1', '%'); ?></span><?php echo $instance['comments_title']; ?></a><?php
|
title="<?php echo $instance['comments_title']; ?>"><span class="navi-comments-count"><?php comments_number('0', '1', '%'); ?></span><?php echo $instance['comments_title']; ?></a><?php
|
||||||
$id = $temp_id;
|
$id = $temp_id;
|
||||||
break;
|
break;
|
||||||
case 'buyprint':
|
case 'buyprint':
|
||||||
|
@ -145,13 +126,44 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
class="navi-buyprint-form">
|
class="navi-buyprint-form">
|
||||||
<input type="hidden" name="comic" value="<?php echo $current->ID; ?>" />
|
<input type="hidden" name="comic" value="<?php echo $current->ID; ?>" />
|
||||||
<button class="navi navi-buyprint"
|
<button class="navi navi-buyprint"
|
||||||
type="submit"
|
type="submit"
|
||||||
value="submit"><?php echo $instance['buyprint_title']; ?></button>
|
value="submit"><?php echo $instance['buyprint_title']; ?></button>
|
||||||
</form><?php
|
</form><?php
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return array($which, $current, $target, $instance, ob_get_clean());
|
return array($which, $current, $target, $instance, ob_get_clean());
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
function _get_link_navi_class_names($which, $current, $target, $instance) {
|
||||||
|
$css_name_mapping = array(
|
||||||
|
'story_prev' => 'prevchap',
|
||||||
|
'previous' => 'prev',
|
||||||
|
'story_next' => 'nextchap'
|
||||||
|
);
|
||||||
|
|
||||||
|
$navi_class_names = array("navi-${which}");
|
||||||
|
if (isset($css_name_mapping[$which])) { $navi_class_names[] = "navi-{$css_name_mapping[$which]}"; }
|
||||||
|
|
||||||
|
$link = false;
|
||||||
|
if (is_object($target)) {
|
||||||
|
if (($which == 'last') && ($instance['lastgohome'] == 'on')) {
|
||||||
|
$link = get_bloginfo('url');
|
||||||
|
} else {
|
||||||
|
$link = get_permalink($target);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (is_string($target)) {
|
||||||
|
$link = $target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($filter_link = apply_filters('comicpress_display_navigation_link', $link, $which, $current, $target, $instance)) !== false) {
|
||||||
|
$link = $filter_link;
|
||||||
|
}
|
||||||
|
|
||||||
|
return compact('link', 'navi_class_names');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the combination of target and current post will show or hide this nav link.
|
* Returns true if the combination of target and current post will show or hide this nav link.
|
||||||
|
@ -177,52 +189,56 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
return apply_filters('comicpress_graphical_navigation_will_display_nav_link', $return, $which, $current, $target);
|
return apply_filters('comicpress_graphical_navigation_will_display_nav_link', $return, $which, $current, $target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
/**
|
/**
|
||||||
* Get the order of the buttons to be displayed on-screen.
|
* Get the order of the buttons to be displayed on-screen.
|
||||||
*/
|
*/
|
||||||
function comicpress_display_navigation_order($order = array()) {
|
function comicpress_display_navigation_order($order = array()) {
|
||||||
return array(
|
return array(
|
||||||
'first', 'previous', 'story_prev_in', 'story_prev', 'archives', 'random', 'comictitle', 'comments', 'buyprint', 'story_next', 'story_next_in', 'next', 'last'
|
'first', 'previous', 'story_prev_in', 'story_prev', 'archives', 'random', 'comictitle', 'comments', 'buyprint', 'story_next', 'story_next_in', 'next', 'last'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function comicpress_navigation_grouping_details($details = array()) {
|
function comicpress_navigation_grouping_details($details = array()) {
|
||||||
return array(
|
return array(
|
||||||
'comic_navi_left' => array('first', 'previous', 'story_prev_in', 'story_prev'),
|
'comic_navi_left' => array('first', 'previous', 'story_prev_in', 'story_prev'),
|
||||||
'comic_navi_center' => true,
|
'comic_navi_center' => true,
|
||||||
'comic_navi_right' => array('story_next', 'story_next_in', 'next', 'last')
|
'comic_navi_right' => array('story_next', 'story_next_in', 'next', 'last')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
function _group_navigation_buttons($buttons = array(), $grouped_buttons = array()) {
|
function _group_navigation_buttons($buttons = array(), $grouped_buttons = array()) {
|
||||||
$grouping_hash = array();
|
$grouping_hash = array();
|
||||||
|
|
||||||
$default_group = null;
|
$default_group = null;
|
||||||
foreach (apply_filters('comicpress_navigation_grouping_details', array()) as $group => $members) {
|
foreach (apply_filters('comicpress_navigation_grouping_details', array()) as $group => $members) {
|
||||||
if ($members === true) {
|
if ($members === true) {
|
||||||
$default_group = $group;
|
$default_group = $group;
|
||||||
} else {
|
} else {
|
||||||
if (is_array($members)) {
|
if (is_array($members)) {
|
||||||
foreach ($members as $member) { $grouping_hash[$member] = $group; }
|
foreach ($members as $member) { $grouping_hash[$member] = $group; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($default_group)) {
|
if (is_null($default_group)) {
|
||||||
trigger_error('No default group defined for filter comicpress_navigation_grouping_details', E_USER_WARNING);
|
trigger_error('No default group defined for filter comicpress_navigation_grouping_details', E_USER_WARNING);
|
||||||
}
|
// @codeCoverageIgnoreStart
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
$groups = array();
|
$groups = array();
|
||||||
foreach ($buttons as $key => $button) {
|
foreach ($buttons as $key => $button) {
|
||||||
$group = isset($grouping_hash[$key]) ? $grouping_hash[$key] : $default_group;
|
$group = isset($grouping_hash[$key]) ? $grouping_hash[$key] : $default_group;
|
||||||
if (!empty($group)) {
|
if (!empty($group)) {
|
||||||
if (!isset($groups[$group])) { $groups[$group] = array(); }
|
if (!isset($groups[$group])) { $groups[$group] = array(); }
|
||||||
$groups[$group][$key] = $button;
|
$groups[$group][$key] = $button;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $groups;
|
return $groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap navigation buttons in a holder.
|
* Wrap navigation buttons in a holder.
|
||||||
|
@ -231,14 +247,14 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
*/
|
*/
|
||||||
function comicpress_wrap_navigation_buttons($buttons = '', $content = '') {
|
function comicpress_wrap_navigation_buttons($buttons = '', $content = '') {
|
||||||
$buttons_text = $buttons;
|
$buttons_text = $buttons;
|
||||||
if (is_array($buttons)) {
|
if (is_array($buttons)) {
|
||||||
$output = array();
|
$output = array();
|
||||||
foreach ($this->_group_navigation_buttons($buttons) as $group => $grouped_buttons) {
|
foreach ($this->_group_navigation_buttons($buttons) as $group => $grouped_buttons) {
|
||||||
$output[] = '<span class="' . $group . '">' . implode('', array_values($grouped_buttons)) . '</span>';
|
$output[] = '<span class="' . $group . '">' . implode('', array_values($grouped_buttons)) . '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$buttons_text = implode('', $output);
|
$buttons_text = implode('', $output);
|
||||||
}
|
}
|
||||||
ob_start(); ?>
|
ob_start(); ?>
|
||||||
<div id="comic_navi_wrapper">
|
<div id="comic_navi_wrapper">
|
||||||
<div class="comic_navi">
|
<div class="comic_navi">
|
||||||
|
@ -262,8 +278,8 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
$storyline_to_nav_mapping = array(
|
$storyline_to_nav_mapping = array(
|
||||||
'story_prev' => 'storyline-chapter-previous',
|
'story_prev' => 'storyline-chapter-previous',
|
||||||
'story_next' => 'storyline-chapter-next',
|
'story_next' => 'storyline-chapter-next',
|
||||||
'story_prev_in' => 'storyline-previous',
|
'story_prev_in' => 'storyline-previous',
|
||||||
'story_next_in' => 'storyline-next'
|
'story_next_in' => 'storyline-next'
|
||||||
);
|
);
|
||||||
|
|
||||||
$nav_links = array();
|
$nav_links = array();
|
||||||
|
@ -335,29 +351,29 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
return array($post_nav, $post, $instance);
|
return array($post_nav, $post, $instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the current widget instance.
|
* Update the current widget instance.
|
||||||
* @param array $new_instance The new widget instance data.
|
* @param array $new_instance The new widget instance data.
|
||||||
* @param array $old_instance The old widget instance data.
|
* @param array $old_instance The old widget instance data.
|
||||||
*/
|
*/
|
||||||
function update($new_instance, $old_instance) {
|
function update($new_instance, $old_instance) {
|
||||||
$instance = array();
|
$instance = array();
|
||||||
|
|
||||||
$all_fields = array(
|
$all_fields = array(
|
||||||
'first', 'story_prev', 'story_next', 'story_prev_in',
|
'first', 'story_prev', 'story_next', 'story_prev_in',
|
||||||
'story_next_in', 'previous', 'random', 'archives',
|
'story_next_in', 'previous', 'random', 'archives',
|
||||||
'comments', 'next', 'last', 'buyprint', 'comictitle', 'lastgohome',
|
'comments', 'next', 'last', 'buyprint', 'comictitle', 'lastgohome',
|
||||||
'story_prev_acts_as_prev_in'
|
'story_prev_acts_as_prev_in'
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($all_fields as $field) {
|
foreach ($all_fields as $field) {
|
||||||
$instance[$field] = (isset($new_instance[$field])) ? 'on' : 'off';
|
$instance[$field] = (isset($new_instance[$field])) ? 'on' : 'off';
|
||||||
if (isset($new_instance["${field}_title"])) {
|
if (isset($new_instance["${field}_title"])) {
|
||||||
$instance["${field}_title"] = strip_tags($new_instance["${field}_title"]);
|
$instance["${field}_title"] = strip_tags($new_instance["${field}_title"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance['archive_path'] = strip_tags($new_instance['archive_path']);
|
$instance['archive_path'] = strip_tags($new_instance['archive_path']);
|
||||||
|
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
@ -366,9 +382,9 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
$field_defaults = array(
|
$field_defaults = array(
|
||||||
'first' => 'on',
|
'first' => 'on',
|
||||||
'story_prev' => 'off',
|
'story_prev' => 'off',
|
||||||
'story_prev_in' => 'off',
|
'story_prev_in' => 'off',
|
||||||
'story_next' => 'off',
|
'story_next' => 'off',
|
||||||
'story_next_in' => 'off',
|
'story_next_in' => 'off',
|
||||||
'previous' => 'on',
|
'previous' => 'on',
|
||||||
'random' => 'off',
|
'random' => 'off',
|
||||||
'archives' => 'off',
|
'archives' => 'off',
|
||||||
|
@ -386,8 +402,8 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
'first_title' => __('‹‹ First', 'comicpress'),
|
'first_title' => __('‹‹ First', 'comicpress'),
|
||||||
'story_prev_title' => __('Chapter', 'comicpress'),
|
'story_prev_title' => __('Chapter', 'comicpress'),
|
||||||
'story_next_title' => __('Chapter', 'comicpress'),
|
'story_next_title' => __('Chapter', 'comicpress'),
|
||||||
'story_prev_in_title' => __('In Chapter', 'comicpress'),
|
'story_prev_in_title' => __('In Chapter', 'comicpress'),
|
||||||
'story_next_in_title' => __('In Chapter', 'comicpress'),
|
'story_next_in_title' => __('In Chapter', 'comicpress'),
|
||||||
'previous_title' => __('‹ Previous', 'comicpress'),
|
'previous_title' => __('‹ Previous', 'comicpress'),
|
||||||
'random_title' => __('Random', 'comicpress'),
|
'random_title' => __('Random', 'comicpress'),
|
||||||
'archives_title' => __('Archives', 'comicpress'),
|
'archives_title' => __('Archives', 'comicpress'),
|
||||||
|
@ -395,7 +411,7 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
'next_title' => __('Next ›', 'comicpress'),
|
'next_title' => __('Next ›', 'comicpress'),
|
||||||
'last_title' => __('Last ››', 'comicpress'),
|
'last_title' => __('Last ››', 'comicpress'),
|
||||||
'buyprint_title' => __('Buy Print', 'comicpress')
|
'buyprint_title' => __('Buy Print', 'comicpress')
|
||||||
);
|
);
|
||||||
|
|
||||||
$instance = wp_parse_args((array)$instance, array_merge($field_defaults, $title_defaults));
|
$instance = wp_parse_args((array)$instance, array_merge($field_defaults, $title_defaults));
|
||||||
|
|
||||||
|
@ -406,51 +422,51 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
'last' => __('Last ››', 'comicpress'),
|
'last' => __('Last ››', 'comicpress'),
|
||||||
'story_prev' => __('Previous Chapter', 'comicpress'),
|
'story_prev' => __('Previous Chapter', 'comicpress'),
|
||||||
'story_next' => __('Next Chapter', 'comicpress'),
|
'story_next' => __('Next Chapter', 'comicpress'),
|
||||||
'story_prev_in' => __('Previous In Chapter', 'comicpress'),
|
'story_prev_in' => __('Previous In Chapter', 'comicpress'),
|
||||||
'story_next_in' => __('Next In Chapter', 'comicpress'),
|
'story_next_in' => __('Next In Chapter', 'comicpress'),
|
||||||
'comictitle' => __('Comic Title', 'comicpress'),
|
'comictitle' => __('Comic Title', 'comicpress'),
|
||||||
'archives' => __('Archives', 'comicpress'),
|
'archives' => __('Archives', 'comicpress'),
|
||||||
'comments' => __('Comments', 'comicpress'),
|
'comments' => __('Comments', 'comicpress'),
|
||||||
'random' => __('Random', 'comicpress'),
|
'random' => __('Random', 'comicpress'),
|
||||||
'buyprint' => __('Buy Print', 'comicpress')
|
'buyprint' => __('Buy Print', 'comicpress')
|
||||||
) as $field => $label) {
|
) as $field => $label) {
|
||||||
$title_field = "${field}_title"; ?>
|
$title_field = "${field}_title"; ?>
|
||||||
<div class="comicpress-field-holder">
|
<div class="comicpress-field-holder">
|
||||||
<label>
|
<label>
|
||||||
<input id="<?php echo $this->get_field_id($field); ?>"
|
<input id="<?php echo $this->get_field_id($field); ?>"
|
||||||
name="<?php echo $this->get_field_name($field); ?>"
|
name="<?php echo $this->get_field_name($field); ?>"
|
||||||
type="checkbox" class="comicpress-field" value="yes"<?php if ($instance[$field] == "on") { echo ' checked="checked"'; } ?> />
|
type="checkbox" class="comicpress-field" value="yes"<?php if ($instance[$field] == "on") { echo ' checked="checked"'; } ?> />
|
||||||
<strong><?php echo $label; ?></strong>
|
<strong><?php echo $label; ?></strong>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="comicpress-field">
|
<div class="comicpress-field">
|
||||||
<?php if (isset($title_defaults[$title_field])) { ?>
|
<?php if (isset($title_defaults[$title_field])) { ?>
|
||||||
<input class="widefat"
|
<input class="widefat"
|
||||||
id="<?php echo $this->get_field_id($title_field); ?>"
|
id="<?php echo $this->get_field_id($title_field); ?>"
|
||||||
name="<?php echo $this->get_field_name($title_field); ?>"
|
name="<?php echo $this->get_field_name($title_field); ?>"
|
||||||
type="text"
|
type="text"
|
||||||
value="<?php echo htmlspecialchars($instance[$title_field]); ?>" />
|
value="<?php echo htmlspecialchars($instance[$title_field]); ?>" />
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
switch($field) {
|
switch($field) {
|
||||||
case "archives": ?>
|
case "archives": ?>
|
||||||
<div>
|
<div>
|
||||||
<?php _e('Archive URL:', 'comicpress') ?>
|
<?php _e('Archive URL:', 'comicpress') ?>
|
||||||
<br />
|
<br />
|
||||||
<input class="widefat"
|
<input class="widefat"
|
||||||
id="<?php echo $this->get_field_id('archive_path'); ?>"
|
id="<?php echo $this->get_field_id('archive_path'); ?>"
|
||||||
name="<?php echo $this->get_field_name('archive_path'); ?>"
|
name="<?php echo $this->get_field_name('archive_path'); ?>"
|
||||||
type="text"
|
type="text"
|
||||||
value="<?php echo attribute_escape($instance['archive_path']); ?>" />
|
value="<?php echo attribute_escape($instance['archive_path']); ?>" />
|
||||||
</div>
|
</div>
|
||||||
<?php break;
|
<?php break;
|
||||||
case "last": ?>
|
case "last": ?>
|
||||||
<div>
|
<div>
|
||||||
<label>
|
<label>
|
||||||
<input id="<?php echo $this->get_field_id('lastgohome'); ?>"
|
<input id="<?php echo $this->get_field_id('lastgohome'); ?>"
|
||||||
name="<?php echo $this->get_field_name('lastgohome'); ?>"
|
name="<?php echo $this->get_field_name('lastgohome'); ?>"
|
||||||
type="checkbox" class="comicpress-field" value="yes"<?php if ($instance['lastgohome'] == "on") { echo ' checked="checked"'; } ?> />
|
type="checkbox" class="comicpress-field" value="yes"<?php if ($instance['lastgohome'] == "on") { echo ' checked="checked"'; } ?> />
|
||||||
<strong><?php _e('...go Home instead of Last', 'comicpress'); ?></strong>
|
<strong><?php _e('...go Home instead of Last', 'comicpress'); ?></strong>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -458,9 +474,9 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
case "story_prev": ?>
|
case "story_prev": ?>
|
||||||
<div>
|
<div>
|
||||||
<label>
|
<label>
|
||||||
<input id="<?php echo $this->get_field_id('story_prev_acts_as_prev_in'); ?>"
|
<input id="<?php echo $this->get_field_id('story_prev_acts_as_prev_in'); ?>"
|
||||||
name="<?php echo $this->get_field_name('story_prev_acts_as_prev_in'); ?>"
|
name="<?php echo $this->get_field_name('story_prev_acts_as_prev_in'); ?>"
|
||||||
type="checkbox" class="comicpress-field" value="yes"<?php if ($instance['story_prev_acts_as_prev_in'] == "on") { echo ' checked="checked"'; } ?> />
|
type="checkbox" class="comicpress-field" value="yes"<?php if ($instance['story_prev_acts_as_prev_in'] == "on") { echo ' checked="checked"'; } ?> />
|
||||||
<strong><?php _e('Enable alternate behavior', 'comicpress'); ?></strong>
|
<strong><?php _e('Enable alternate behavior', 'comicpress'); ?></strong>
|
||||||
<p>
|
<p>
|
||||||
<em>
|
<em>
|
||||||
|
@ -473,12 +489,12 @@ class GraphicalNavigationWidget extends WP_Widget {
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var _get_comicpress_show_hide_text = function(container, immediate) {
|
var _get_comicpress_show_hide_text = function(container, immediate) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
var checkbox = jQuery('.comicpress-field[type=checkbox]', container).get(0);
|
var checkbox = jQuery('.comicpress-field[type=checkbox]', container).get(0);
|
||||||
if (checkbox) {
|
if (checkbox) {
|
||||||
jQuery('div.comicpress-field', container)[checkbox.checked ? 'show' : 'hide'](immediate ? null : 'fast');
|
jQuery('div.comicpress-field', container)[checkbox.checked ? 'show' : 'hide'](immediate ? null : 'fast');
|
||||||
|
|
Loading…
Reference in New Issue