'WidgetComicPressGraphicalStorylineNavigation', 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') ); $this->WP_Widget('graphicalstorylinenavigation', __('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); add_filter('comicpress_navigation_grouping_details', array(&$this, 'comicpress_navigation_grouping_details')); // 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; $css_name_mapping = array( 'story_prev' => 'prevchap', 'previous' => 'prev', 'story_next' => 'nextchap' ); $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': case 'story_prev_in': case 'story_next_in': $ok = !empty($target); break; case 'archives': $ok = !empty($instance['archive_path']); break; } ob_start(); switch ($which) { case 'first': case 'previous': case 'next': case 'last': case 'story_prev': case 'story_next': case 'story_prev_in': case 'story_next_in': $ok = false; $navi_class_names = array("navi-${which}"); if (is_object($target)) { $ok = true; if (isset($css_name_mapping[$which])) { $navi_class_names[] = "navi-{$css_name_mapping[$which]}"; } $link = get_permalink($target->ID); if (($which == 'last') && ($instance['lastgohome'] == 'on')) { $link = get_bloginfo('url'); } } if ($ok) { ?>" title="">
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', '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()) { return array( 'comic_navi_left' => array('first', 'previous', 'story_prev_in', 'story_prev'), 'comic_navi_center' => true, 'comic_navi_right' => array('story_next', 'story_next_in', 'next', 'last') ); } function _group_navigation_buttons($buttons = array(), $grouped_buttons = array()) { $grouping_hash = array(); $default_group = null; foreach (apply_filters('comicpress_navigation_grouping_details', array()) as $group => $members) { if ($members === true) { $default_group = $group; } else { foreach ($members as $member) { $grouping_hash[$member] = $group; } } } if (is_null($default_group)) { trigger_error('No default group defined for filter comicpress_navigation_grouping_details', E_USER_WARNING); } $groups = array(); foreach ($buttons as $key => $button) { $group = isset($grouping_hash[$key]) ? $grouping_hash[$key] : $default_group; if (!empty($group)) { if (!isset($groups[$group])) { $groups[$group] = array(); } $groups[$group][$key] = $button; } } return $groups; } /** * 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)) { $output = array(); foreach ($this->_group_navigation_buttons($buttons) as $group => $grouped_buttons) { $output[] = '