2009-08-21 19:29:45 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Widget Name: Graphical Navigation
|
|
|
|
Widget URI: http://comicpress.org/
|
2009-10-21 01:08:17 +00:00
|
|
|
Description: This widget places graphical navigation buttons on your comic. For ComicPress 2.8
|
|
|
|
Author: Philip M. Hofer (Frumph) & John Bintz
|
|
|
|
Version: 1.2
|
2009-08-21 19:29:45 +00:00
|
|
|
Author URI: http://webcomicplanet.com/
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
class widget_comicpress_graphical_navigation extends WP_Widget {
|
|
|
|
function widget_comicpress_graphical_navigation() {
|
2009-10-05 06:08:01 +00:00
|
|
|
$widget_ops = array('classname' => 'widget_comicpress_graphical_navigation', 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') );
|
|
|
|
$this->WP_Widget('graphicalnavigation', __('Comic Navigation','comicpress'), $widget_ops);
|
2009-08-21 19:29:45 +00:00
|
|
|
}
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-08-21 19:29:45 +00:00
|
|
|
function widget($args, $instance) {
|
|
|
|
global $wp_query, $post;
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-10-11 11:48:57 +00:00
|
|
|
if (is_home() || is_single()) {
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-10-11 11:48:57 +00:00
|
|
|
$this_permalink = get_permalink();
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-10-11 11:48:57 +00:00
|
|
|
$temp_query = $wp_query->is_single;
|
|
|
|
$wp_query->is_single = true;
|
|
|
|
$prev_comic = get_previous_comic_permalink();
|
|
|
|
$next_comic = get_next_comic_permalink();
|
|
|
|
$wp_query->is_single = $temp_query;
|
|
|
|
$temp_query = null;
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-10-11 11:48:57 +00:00
|
|
|
$first_comic = get_first_comic_permalink();
|
|
|
|
$last_comic = get_last_comic_permalink();
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-10-11 11:48:57 +00:00
|
|
|
$prev_story = get_previous_storyline_start_permalink();
|
2009-10-21 01:08:17 +00:00
|
|
|
$next_story = get_next_storyline_start_permalink();
|
2009-10-11 11:48:57 +00:00
|
|
|
?>
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-10-11 11:48:57 +00:00
|
|
|
<div id="comic_navi_wrapper">
|
|
|
|
<table id="comic_navi" cellpadding="0" cellspacing="0"><tr><td>
|
|
|
|
<?php if ($instance['first'] != 'off') {
|
|
|
|
if (!empty($first_comic) && ($first_comic != $this_permalink)) { ?>
|
|
|
|
<a href="<?php echo $first_comic; ?>" class="navi navi-first" title="<?php echo $instance['first_title']; ?>"><?php echo $instance['first_title']; ?></a>
|
|
|
|
<?php } else { ?>
|
|
|
|
<div class="navi navi-first navi-void"><?php echo $instance['first_title']; ?></div>
|
2009-10-21 01:08:17 +00:00
|
|
|
<?php }
|
|
|
|
}
|
|
|
|
if ($instance['story_prev'] != 'off') {
|
2009-10-11 11:48:57 +00:00
|
|
|
if (!empty($prev_story)) { ?>
|
|
|
|
<a href="<?php echo $prev_story; ?>" class="navi navi-prevchap" title="<?php echo $instance['story_prev_title']; ?>"><?php echo $instance['story_prev_title']; ?></a>
|
|
|
|
<?php } else { ?>
|
|
|
|
<div class="navi navi-prevchap navi-void"><?php echo $instance['story_prev_title']; ?></div>
|
2009-10-21 01:08:17 +00:00
|
|
|
<?php }
|
|
|
|
}
|
2009-10-11 11:48:57 +00:00
|
|
|
if ($instance['previous'] != 'off') {
|
|
|
|
if (!empty($prev_comic)) { ?>
|
|
|
|
<a href="<?php echo $prev_comic; ?>" class="navi navi-prev" title="<?php echo $instance['previous_title']; ?>"><?php echo $instance['previous_title']; ?></a>
|
|
|
|
<?php } else { ?>
|
|
|
|
<div class="navi navi-prev navi-void"><?php echo $instance['previous_title']; ?></div>
|
2009-10-21 01:08:17 +00:00
|
|
|
<?php }
|
2009-10-11 11:48:57 +00:00
|
|
|
}
|
|
|
|
if ($instance['archives'] != 'off' && !empty($instance['archive_path'])) { ?>
|
|
|
|
<a href="<?php echo $instance['archive_path']; ?>" class="navi navi-archive" title="<?php echo $instance['archives_title']; ?>"><?php echo $instance['archives_title']; ?></a>
|
2009-10-21 01:08:17 +00:00
|
|
|
<?php }
|
2009-10-11 11:48:57 +00:00
|
|
|
if ($instance['random'] != 'off') { ?>
|
|
|
|
<a href="<?php echo bloginfo('url'); ?>/?randomcomic" class="navi navi-random" title="<?php echo $instance['random_title']; ?>"><?php echo $instance['random_title']; ?></a>
|
2009-08-26 00:57:26 +00:00
|
|
|
<?php }
|
2009-10-11 11:48:57 +00:00
|
|
|
if ($instance['comictitle'] != 'off') { ?>
|
|
|
|
<div class="navi-comictitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
|
2009-10-21 01:08:17 +00:00
|
|
|
<?php }
|
2009-10-11 11:48:57 +00:00
|
|
|
if ($instance['comments'] != 'off') { ?>
|
|
|
|
<a href="<?php the_permalink(); ?>#comment" 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>
|
2009-08-26 00:57:26 +00:00
|
|
|
<?php }
|
2009-10-21 01:08:17 +00:00
|
|
|
if ($instance['buyprint'] != 'off') { ?>
|
|
|
|
<form method="post" title="<?php echo $instance['buyprint_title']; ?>" action="<?php global $buy_print_url; echo $buy_print_url; ?>" class="navi-buyprint-form">
|
|
|
|
<input type="hidden" name="comic" value="<?php echo get_the_ID(); ?>" />
|
|
|
|
<button class="navi navi-buyprint" type="submit" value="submit"><?php echo $instance['buyprint_title']; ?></button>
|
|
|
|
</form>
|
|
|
|
<?php }
|
2009-10-11 11:48:57 +00:00
|
|
|
if ($instance['next'] != 'off') {
|
|
|
|
if (!empty($next_comic)) { ?>
|
|
|
|
<a href="<?php echo $next_comic; ?>" class="navi navi-next" title="<?php echo $instance['next_title']; ?>"><?php echo $instance['next_title']; ?></a>
|
|
|
|
<?php } else { ?>
|
|
|
|
<div class="navi navi-next navi-void"><?php echo $instance['next_title']; ?></div>
|
|
|
|
<?php }
|
2009-10-21 01:08:17 +00:00
|
|
|
}
|
|
|
|
if ($instance['story_next'] != 'off') {
|
2009-10-11 11:48:57 +00:00
|
|
|
if (!empty($next_story) && !is_home()) { ?>
|
|
|
|
<a href="<?php echo $next_story; ?>" class="navi navi-nextchap" title="<?php echo $instance['story_next_title']; ?>"><?php echo $instance['story_next_title']; ?></a>
|
|
|
|
<?php } else { ?>
|
|
|
|
<div class="navi navi-nextchap navi-void"><?php echo $instance['story_next_title']; ?></div>
|
|
|
|
<?php }
|
|
|
|
}
|
|
|
|
if ($instance['last'] != 'off') {
|
|
|
|
if (!empty($last_comic) && ($last_comic != $this_permalink)) { ?>
|
|
|
|
<a href="<?php echo $last_comic; ?>" class="navi navi-last" title="<?php echo $instance['last_title']; ?>"><?php echo $instance['last_title']; ?></a>
|
|
|
|
<?php } else { ?>
|
|
|
|
<div class="navi navi-last navi-void"><?php echo $instance['last_title']; ?></div>
|
|
|
|
<?php }
|
|
|
|
} ?>
|
|
|
|
</td></tr></table>
|
|
|
|
</div>
|
2009-10-21 01:08:17 +00:00
|
|
|
|
|
|
|
<?php }
|
2009-10-11 11:48:57 +00:00
|
|
|
}
|
2009-10-21 01:08:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the current widget instance.
|
|
|
|
* @param array $new_instance The new widget instance data.
|
|
|
|
* @param array $old_instance The old widget instance data.
|
|
|
|
*/
|
2009-08-21 19:29:45 +00:00
|
|
|
function update($new_instance, $old_instance) {
|
2009-10-21 01:08:17 +00:00
|
|
|
$instance = array();
|
|
|
|
|
|
|
|
$all_fields = explode(' ', 'first last story_prev story_next previous random archives comments next buyprint comictitle');
|
|
|
|
|
|
|
|
foreach ($all_fields as $field) {
|
2009-10-21 11:39:58 +00:00
|
|
|
$instance[$field] = (isset($new_instance[$field])) ? 'on' : 'off';
|
2009-10-21 01:08:17 +00:00
|
|
|
if (isset($new_instance["${field}_title"])) {
|
|
|
|
$instance["${field}_title"] = strip_tags($new_instance["${field}_title"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance['archive_path'] = strip_tags($new_instance['archive_path']);
|
|
|
|
|
2009-08-25 12:37:13 +00:00
|
|
|
return $instance;
|
2009-08-21 19:29:45 +00:00
|
|
|
}
|
2009-10-21 01:08:17 +00:00
|
|
|
|
2009-08-21 19:29:45 +00:00
|
|
|
function form($instance) {
|
2009-10-21 01:52:59 +00:00
|
|
|
$field_defaults = array(
|
|
|
|
'first' => 'on',
|
|
|
|
'last' => 'on',
|
|
|
|
'story_prev' => 'off',
|
|
|
|
'story_next' => 'off',
|
|
|
|
'previous' => 'on',
|
|
|
|
'random' => 'off',
|
|
|
|
'archives' => 'off',
|
|
|
|
'comments' => 'off',
|
|
|
|
'next' => 'on',
|
|
|
|
'archive_path' => '',
|
|
|
|
'buyprint' => 'off',
|
|
|
|
'comictitle' => 'off'
|
|
|
|
);
|
|
|
|
|
|
|
|
$title_defaults = array(
|
|
|
|
'first_title' => __('First', 'comicpress'),
|
|
|
|
'last_title' => __('Latest', 'comicpress'),
|
|
|
|
'story_prev_title' => __('Chapter', 'comicpress'),
|
|
|
|
'story_next_title' => __('Chapter', 'comicpress'),
|
|
|
|
'previous_title' => __('Previous', 'comicpress'),
|
|
|
|
'random_title' => __('Random', 'comicpress'),
|
|
|
|
'archives_title' => __('Archives', 'comicpress'),
|
|
|
|
'comments_title' => __('Comments', 'comicpress'),
|
|
|
|
'next_title' => __('Next', 'comicpress'),
|
|
|
|
'buyprint_title' => __('Buy Print', 'comicpress')
|
|
|
|
);
|
|
|
|
|
|
|
|
$instance = wp_parse_args((array)$instance, array_merge($field_defaults, $title_defaults));
|
|
|
|
|
|
|
|
foreach (array(
|
|
|
|
'first' => __('First', 'comicpress'),
|
|
|
|
'last' => __('Last', 'comicpress'),
|
|
|
|
'previous' => __('Previous', 'comicpress'),
|
|
|
|
'next' => __('Next', 'comicpress'),
|
|
|
|
'story_prev' => __('Previous Chapter', 'comicpress'),
|
|
|
|
'story_next' => __('Next Chapter', 'comicpress'),
|
|
|
|
'comictitle' => __('Comic Title', 'comicpress'),
|
|
|
|
'archives' => __('Archives', 'comicpress'),
|
|
|
|
'comments' => __('Comments', 'comicpress'),
|
|
|
|
'random' => __('Random', 'comicpress'),
|
|
|
|
'buyprint' => __('Buy Print', 'comicpress'),
|
|
|
|
) as $field => $label) {
|
|
|
|
$title_field = "${field}_title"; ?>
|
2009-10-21 11:39:58 +00:00
|
|
|
<div class="comicpress-field-holder">
|
|
|
|
<label>
|
2009-10-21 01:52:59 +00:00
|
|
|
<input id="<?php echo $this->get_field_id($field); ?>"
|
|
|
|
name="<?php echo $this->get_field_name($field); ?>"
|
2009-10-21 11:39:58 +00:00
|
|
|
type="checkbox" class="comicpress-field" value="yes"<?php if ($instance[$field] == "on") { echo ' checked="checked"'; } ?> />
|
|
|
|
<strong><?php echo $label; ?><strong>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<?php if (isset($title_defaults[$title_field])) { ?>
|
|
|
|
<input class="widefat comicpress-field"
|
|
|
|
id="<?php echo $this->get_field_id($title_field); ?>"
|
|
|
|
name="<?php echo $this->get_field_name($title_field); ?>"
|
|
|
|
type="text"
|
|
|
|
value="<?php echo attribute_escape($instance[$title_field]); ?>" />
|
|
|
|
<?php } ?>
|
|
|
|
|
|
|
|
<?php if ($field == "archives") { ?>
|
|
|
|
<div>
|
|
|
|
<?php _e('Archive URL:', 'comicpress') ?>
|
|
|
|
<br />
|
|
|
|
<input class="widefat"
|
|
|
|
id="<?php echo $this->get_field_id('archive_path'); ?>"
|
|
|
|
name="<?php echo $this->get_field_name('archive_path'); ?>"
|
|
|
|
type="text"
|
|
|
|
value="<?php echo attribute_escape($instance['archive_path']); ?>" />
|
|
|
|
</div>
|
|
|
|
<?php } ?>
|
|
|
|
</label>
|
|
|
|
</div>
|
2009-10-21 01:52:59 +00:00
|
|
|
<?php }
|
2009-10-21 11:39:58 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
var _get_comicpress_show_hide_text = function(container, immediate) {
|
|
|
|
return function(e) {
|
|
|
|
var checkbox = jQuery('.comicpress-field[type=checkbox]', container).get(0);
|
|
|
|
if (checkbox) {
|
|
|
|
jQuery('.comicpress-field[type=text]', container)[checkbox.checked ? 'show' : 'hide'](immediate ? null : 'fast');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
jQuery('.comicpress-field-holder').each(function(fh) {
|
|
|
|
jQuery('.comicpress-field[type=checkbox]', this).bind('click', _get_comicpress_show_hide_text(this, false));
|
|
|
|
_get_comicpress_show_hide_text(this, true)();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<?php
|
2009-08-21 19:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
register_widget('widget_comicpress_graphical_navigation');
|
|
|
|
|
2009-10-21 01:08:17 +00:00
|
|
|
function widget_comicpress_graphical_navigation_init() {
|
|
|
|
new widget_comicpress_graphical_navigation();
|
|
|
|
}
|
2009-08-21 19:29:45 +00:00
|
|
|
|
|
|
|
add_action('widgets_init', 'widget_comicpress_graphical_navigation_init');
|
|
|
|
|
2009-08-21 17:45:23 +00:00
|
|
|
?>
|