2009-11-21 15:15:53 +00:00
|
|
|
<?php
|
|
|
|
|
2009-11-21 15:46:13 +00:00
|
|
|
class BookmarkWidget extends WP_Widget {
|
2009-12-20 23:54:01 +00:00
|
|
|
var $text_fields;
|
|
|
|
|
2009-12-20 21:00:17 +00:00
|
|
|
function BookmarkWidget($skip_widget_init = false) {
|
|
|
|
if (!$skip_widget_init) {
|
|
|
|
$widget_ops = array('classname' => __CLASS__, 'description' => __('Allow the user to bookmark a page and then jump to it upon return.','comicpress') );
|
|
|
|
$this->WP_Widget(__CLASS__, __('ComicPress Bookmark','comicpress'), $widget_ops);
|
|
|
|
}
|
2009-12-20 23:54:01 +00:00
|
|
|
|
|
|
|
$this->text_fields = array(
|
|
|
|
'three-button' => array(
|
|
|
|
'tag-page' => array(
|
|
|
|
'label' => __('Tag page', 'comicpress'),
|
|
|
|
'default' => __('Bookmark', 'comicpress')
|
|
|
|
),
|
|
|
|
'clear-tag-off' => array(
|
|
|
|
'label' => __('Clear tag off', 'comicpress'),
|
|
|
|
'default' => ''
|
|
|
|
),
|
|
|
|
'clear-tag-on' => array(
|
|
|
|
'label' => __('Clear tag on', 'comicpress'),
|
|
|
|
'default' => __('Clear', 'comicpress')
|
|
|
|
),
|
|
|
|
'goto-tag-off' => array(
|
|
|
|
'label' => __('Goto tag off', 'comicpress'),
|
|
|
|
'default' => ''
|
|
|
|
),
|
|
|
|
'goto-tag-on' => array(
|
|
|
|
'label' => __('Goto tag on', 'comicpress'),
|
|
|
|
'default' => __('Goto', 'comicpress')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'one-button' => array(
|
|
|
|
'set-bookmark' => array(
|
|
|
|
'label' => __('Set bookmark', 'comicpress'),
|
|
|
|
'default' => __('+Bookmark', 'comicpress')
|
|
|
|
),
|
|
|
|
'use-bookmark' => array(
|
|
|
|
'label' => __('Use bookmark', 'comicpress'),
|
|
|
|
'default' => __('>>Bookmark', 'comicpress')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2009-11-21 15:46:13 +00:00
|
|
|
}
|
2009-11-21 15:15:53 +00:00
|
|
|
|
2009-11-21 15:46:13 +00:00
|
|
|
function init() {
|
2009-11-21 15:15:53 +00:00
|
|
|
add_action('wp_head', array(&$this, 'wp_head'));
|
2009-12-20 21:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function is_active() {
|
2009-11-23 13:03:48 +00:00
|
|
|
add_action('template_redirect', array(&$this, 'template_redirect'));
|
|
|
|
}
|
2009-11-21 15:24:01 +00:00
|
|
|
|
2009-11-23 13:03:48 +00:00
|
|
|
function template_redirect() {
|
2009-11-21 15:15:53 +00:00
|
|
|
wp_enqueue_script('prototype');
|
|
|
|
wp_enqueue_script('cookiejar', get_template_directory_uri() . '/js/cookiejar.js', array('prototype'));
|
|
|
|
wp_enqueue_script('bookmark', get_template_directory_uri() . '/js/bookmark.js', array('prototype', 'cookiejar'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function wp_head() { ?>
|
|
|
|
<script type="text/javascript">
|
2009-11-21 15:46:13 +00:00
|
|
|
var image_root = '<?php echo get_template_directory_uri() ?>/images/';
|
2009-11-21 15:24:01 +00:00
|
|
|
var permalink = '<?php the_permalink() ?>';
|
2009-11-21 15:15:53 +00:00
|
|
|
</script>
|
|
|
|
<?php }
|
|
|
|
|
2009-12-20 23:54:01 +00:00
|
|
|
function form($instance) {
|
|
|
|
?>
|
|
|
|
<div id="<?php echo $this->get_field_id('wrapper') ?>">
|
|
|
|
<p>
|
|
|
|
<label><?php _e('Title', 'comicpress') ?><br />
|
|
|
|
<input class="widefat" type="text"
|
|
|
|
name="<?php echo $this->get_field_name('title') ?>"
|
|
|
|
value="<?php echo esc_attr($instance['title']) ?>" />
|
|
|
|
</label>
|
|
|
|
</p>
|
|
|
|
<?php
|
|
|
|
foreach (array(
|
|
|
|
'three-button' => __('Three-button mode', 'comicpress'),
|
|
|
|
'one-button' => __('One-button mode', 'comicpress')
|
|
|
|
) as $mode => $label) { ?>
|
|
|
|
<p>
|
|
|
|
<label>
|
|
|
|
<input type="radio"
|
|
|
|
id="<?php echo $this->get_field_id($mode) ?>"
|
|
|
|
name="<?php echo $this->get_field_name('mode') ?>"
|
|
|
|
value="<?php echo esc_attr($mode) ?>"
|
|
|
|
<?php echo $instance['mode'] == $mode ? 'checked="checked"' : '' ?> /> <?php echo $label ?>
|
|
|
|
</label>
|
|
|
|
</p>
|
|
|
|
<div id="<?php echo $this->get_field_id("${mode}-options") ?>"><p>
|
|
|
|
<?php
|
|
|
|
foreach ($this->text_fields[$mode] as $name => $info) {
|
|
|
|
extract($info);
|
|
|
|
$value = empty($instance[$name]) ? $default : $instance[$name];
|
|
|
|
?>
|
|
|
|
<label><?php echo $label ?><br />
|
|
|
|
<input class="widefat" type="text"
|
|
|
|
name="<?php echo $this->get_field_name($name) ?>"
|
|
|
|
value="<?php echo esc_attr($value) ?>" />
|
|
|
|
</label>
|
|
|
|
<br /><?php
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</p></div>
|
|
|
|
<?php } ?>
|
|
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
(function($) {
|
|
|
|
var wrapper = '<?php echo $this->get_field_id('wrapper') ?>';
|
|
|
|
var radios = $('#' + wrapper + ' input[type=radio]');
|
|
|
|
|
|
|
|
var show = function() {
|
|
|
|
radios.each(function() {
|
|
|
|
$('#' + this.id + '-options')[this.checked ? 'show' : 'hide']();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
radios.click(show);
|
|
|
|
show();
|
|
|
|
}(jQuery));
|
|
|
|
</script>
|
|
|
|
<?php }
|
|
|
|
|
|
|
|
function update($new_instance, $old_instance) {
|
|
|
|
$instance = array();
|
|
|
|
|
|
|
|
$all_text_fields = array('title');
|
|
|
|
foreach ($this->text_fields as $type => $fields) {
|
|
|
|
$all_text_fields = array_merge($all_text_fields, array_keys($fields));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($all_text_fields as $key) {
|
|
|
|
$instance[$key] = strip_tags($new_instance[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->text_fields[$new_instance['mode']])) {
|
|
|
|
$instance['mode'] = $new_instance['mode'];
|
|
|
|
} else {
|
|
|
|
$instance['mode'] = array_shift(array_keys($this->text_fields));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
function widget($instance) {
|
2009-11-21 15:15:53 +00:00
|
|
|
?>
|
|
|
|
<div id="comic-bookmark-holder">
|
2009-11-21 19:58:27 +00:00
|
|
|
<a href="#" class="tag-page"><img src="<?php echo get_template_directory_uri() ?>/images/1.gif" /></a><a href="#" class="goto-tag"><img /></a><a href="#" class="clear-tag"><img /></a>
|
2009-11-21 15:15:53 +00:00
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|