get bookmark widget working

This commit is contained in:
John Bintz 2009-07-14 22:24:31 -04:00
parent a9e36d0d6b
commit 69ed6e95b7
3 changed files with 43 additions and 7 deletions

View File

@ -1,13 +1,40 @@
<?php <?php
class ComicPressAddonBookmarkWidget extends ComicPressAddon { class ComicPressAddonBookmarkWidget extends ComicPressAddon {
function init() { function init($comicpress) {
wp_register_sidebar_widget('comic-bookmark', __('Comic Bookmark', 'comicpress'), array(&$this, 'render_widget'), array('description' => __('Let your readers save their place via a cookie.', 'comicpress'))); wp_register_sidebar_widget('comic-bookmark', __('Comic Bookmark', 'comicpress'), array(&$this, 'render_widget'), array('description' => __('Let your readers save their place via a cookie.', 'comicpress')));
$this->comicpress = $comicpress;
add_action('wp_head', array(&$this, 'wp_head'));
$this->comicpress->additional_javascripts[] = '/js/bookmark.js';
}
function wp_head() {
$last_comic = $this->comicpress->get_last_comic(); ?>
<script type="text/javascript">
var imgTag = '<?php bloginfo('template_directory'); ?>/images/1.gif'; //add tag image.
var imgClearOff = '<?php bloginfo('template_directory'); ?>/images/3a.gif'; //no comic tagged, clear not possible
var imgGotoOff = '<?php bloginfo('template_directory'); ?>/images/2a.gif'; //no comic tagged, goto not possible
var imgClearOn = '<?php bloginfo('template_directory'); ?>/images/3.gif'; //clear a tag, shows when comic previously tagged
var imgGotoOn = '<?php bloginfo('template_directory'); ?>/images/2.gif'; //shows when a comic is tagged
var imgInfo = '<?php bloginfo('template_directory'); ?>/images/4.gif'; //img that displays the help
var comicDir = '/'; //alter this if you run multiple comics in different directories on your site.
var comicPermalink = '<?php echo get_permalink($last_comic->ID) ?>';
var isHome = <?php echo is_home() ? "true" : "false" ?>;
var isSingle = <?php echo (is_single() && $this->comicpress->in_comic_category()) ? "true" : "false" ?>;
</script>
<?php
} }
function render_widget() { function render_widget() {
$url_root = bloginfo('template_directory') . '/' . substr(dirname(__FILE__), strlen(realpath(get_stylesheet_directory()))); ?>
var_dump($url_root); <div class="comic-bookmark">
<script type="text/javascript">writeBookmarkWidget()</script>
</div>
<?php
} }
} }

View File

@ -11,8 +11,8 @@
var imgClearOff = '<?php bloginfo('template_directory'); ?>/images/3a.gif'; //no comic tagged, clear not possible var imgClearOff = '<?php bloginfo('template_directory'); ?>/images/3a.gif'; //no comic tagged, clear not possible
var imgGotoOff = '<?php bloginfo('template_directory'); ?>/images/2a.gif'; //no comic tagged, goto not possible var imgGotoOff = '<?php bloginfo('template_directory'); ?>/images/2a.gif'; //no comic tagged, goto not possible
var imgClearOn = '<?php bloginfo('template_directory'); ?>/images/3.gif'; //clear a tag, shows when comic previously tagged var imgClearOn = '<?php bloginfo('template_directory'); ?>/images/3.gif'; //clear a tag, shows when comic previously tagged
var imgGotoOn = '<?php bloginfo('template_directory'); ?>/2.gif'; //shows when a comic is tagged var imgGotoOn = '<?php bloginfo('template_directory'); ?>/images/2.gif'; //shows when a comic is tagged
var imgInfo = '<?php bloginfo('template_directory'); ?>/4.gif'; //img that displays the help var imgInfo = '<?php bloginfo('template_directory'); ?>/images/4.gif'; //img that displays the help
var comicDir = '/'; //alter this if you run multiple comics in different directories on your site. var comicDir = '/'; //alter this if you run multiple comics in different directories on your site.
/* Now write out the applicable links */ /* Now write out the applicable links */

View File

@ -15,6 +15,8 @@ class ComicPress {
); );
var $additional_stylesheets = array(); var $additional_stylesheets = array();
var $additional_javascripts = array();
var $comic_post_attachments_cache = array(); var $comic_post_attachments_cache = array();
var $category_tree = array(); var $category_tree = array();
@ -54,6 +56,9 @@ class ComicPress {
foreach ($this->additional_stylesheets as $uri) { ?> foreach ($this->additional_stylesheets as $uri) { ?>
<link rel="stylesheet" href="<?php echo get_template_directory_uri() . $uri ?>" type="text/css" /> <link rel="stylesheet" href="<?php echo get_template_directory_uri() . $uri ?>" type="text/css" />
<?php } <?php }
foreach ($this->additional_javascripts as $uri) { ?>
<script type="text/javascript" src="<?php echo get_template_directory_uri() . $uri ?>"></script>
<?php }
} }
/** /**
@ -161,8 +166,12 @@ class ComicPress {
/** /**
* Return true if the current post is in the comics category or a child category. * Return true if the current post is in the comics category or a child category.
*/ */
function in_comic_category($post_id) { function in_comic_category($post_id = null) {
$categories = wp_get_post_categories($post_id); global $post;
$post_id_to_use = !is_null($post_id) ? $post_id : $post->ID;
$categories = wp_get_post_categories($post_id_to_use);
if (is_array($categories)) { if (is_array($categories)) {
foreach ($this->category_tree as $node) { foreach ($this->category_tree as $node) {
if (in_array(end(explode("/", $node)), $categories)) { if (in_array(end(explode("/", $node)), $categories)) {