'widget_comicpress_graphical_navigation', 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') ); $this->WP_Widget('graphicalnavigation', __('Comic Navigation','comicpress'), $widget_ops); } /** * Initialize the widget class. */ function init() { 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_wrap_navigation_buttons', array(&$this, 'comicpress_wrap_navigation_buttons'), 10, 2); // 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_buy_print_url', array(&$this, 'comicpress_get_buy_print_url')); } /** * Get the random link URL. */ function comicpress_get_random_link_url($url = '') { return get_bloginfo('url') . '/?randomcomic'; } /** * Get the URL to buy a print. * Handles hitting the global namespace for you. */ function comicpress_get_buy_print_url($url = '') { global $buy_print_url; return $buy_print_url; } /** * Render a button. */ function comicpress_display_navigation_link($which, $current, $target, $instance, $content = '') { global $id; $ok = true; switch ($which) { case 'first': case 'last': $ok = $this->_will_display_nav_link($which, $current, $target); break; case 'previous': case 'next': case 'story_prev': case 'story_next': $ok = !empty($target); break; case 'archives': $ok = !empty($instance['archive_path']); break; } ob_start(); switch ($which) { case 'first': case 'last': case 'previous': case 'story_prev': case 'story_next': $link = get_permalink($target); case 'next': if ($instance['nextgohome'] == 'on') { $link = get_bloginfo('url'); } if ($ok) { ?>">
ID; ?>ID != $current->ID); default: return true; } } /** * Get the order of the buttons to be displayed on-screen. */ function comicpress_display_navigation_order($order = array()) { return array( 'first', 'story_prev', 'previous', 'archives', 'random', 'comictitle', 'comments', 'buyprint', 'next', 'story_next', 'last' ); } /** * Wrap navigation buttons in a holder. * @param string|array $buttons The buttons to wrap. * @param string $content The wrapped content. */ function comicpress_wrap_navigation_buttons($buttons = '', $content = '') { $buttons_text = $buttons; if (is_array($buttons)) { $buttons_text = implode('', $buttons); } ob_start(); ?> create_structure(get_option('comicpress-storyline-category-order')); $dbi = ComicPressDBInterface::get_instance(); $dbi->set_comic_categories($storyline->get_comic_categories()); $navigation = new ComicPressNavigation(); $navigation->init($storyline); $post_nav = $navigation->get_post_nav($post); $storyline_to_nav_mapping = array( 'story_prev' => 'storyline-previous', 'story_next' => 'storyline-next' ); $nav_links = array(); foreach (apply_filters('comicpress_display_navigation_order', array()) as $order) { if ($instance[$order] == "on") { $target_post_nav = (isset($storyline_to_nav_mapping[$order])) ? $storyline_to_nav_mapping[$order] : $order; $target_post = null; if (isset($post_nav[$target_post_nav])) { $target_post = $post_nav[$target_post_nav]; } $nav_links[] = end(apply_filters('comicpress_display_navigation_link', $order, $post, $target_post, $instance, '')); } } echo end(apply_filters('comicpress_wrap_navigation_buttons', $nav_links, '')); } } /** * Update the current widget instance. * @param array $new_instance The new widget instance data. * @param array $old_instance The old widget instance data. */ function update($new_instance, $old_instance) { $instance = array(); $all_fields = explode(' ', 'first last story_prev story_next previous random archives comments next buyprint comictitle nextgohome'); foreach ($all_fields as $field) { $instance[$field] = (isset($new_instance[$field])) ? 'on' : 'off'; if (isset($new_instance["${field}_title"])) { $instance["${field}_title"] = strip_tags($new_instance["${field}_title"]); } } $instance['archive_path'] = strip_tags($new_instance['archive_path']); return $instance; } function form($instance) { $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', 'nextgohome' => '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"; ?>