__CLASS__, 'description' => __('Display a dropdown list of your archives, styled.','comicpress') ); $this->WP_Widget(__CLASS__, __('ComicPress Archive Dropdown','comicpress'), $widget_ops); } $this->modes = array( 'monthly_archive' => __('Monthly archive', 'comicpress'), 'comic_archive' => __('Comic archive', 'comicpress'), 'storyline_order' => array( 'requires_storyline' => true, 'label' => __('Storyline archive pages', 'comicpress'), ), 'storyline_order_post_link' => array( 'requires_storyline' => true, 'label' => __('Storyline posts', 'comicpress'), ) ); } function _verify_nonce() { return __comicpress_verify_nonce(); } function template_redirect() { if (ComicPressArchiveDropdownWidget::_verify_nonce() == 'follow-archive-dropdown') { wp_redirect($_GET['cp']['urls']); } } /** * Build a dropdown geared toward quick links to posts. */ function build_dropdown($entries) { if (is_string($entries) || is_array($entries)) { $id = 'archive-dropdown-' . md5(rand()); $button_id = 'archive-dropdown-submit-' . md5(rand()); $nonce = wp_create_nonce('comicpress'); $action_nonce = wp_create_nonce('comicpress-follow-archive-dropdown'); ob_start(); ?> build_dropdown(wp_get_archives('type=monthly&format=option&show_post_count=-1&echo=0')); } function _new_comicpressstoryline() { return new ComicPressStoryline(); } function _new_comicpressdbinterface() { return new ComicPressDBInterface(); } function _new_wp_query() { return new WP_Query(); } /** * Build the comic archive dropdown. */ function build_comic_archive_dropdown() { $storyline = $this->_new_comicpressstoryline(); $storyline->read_from_options(); $query = $this->_new_wp_query(); $query->query(array( 'showposts' => -1, 'category__in' => $storyline->build_from_restrictions() )); $results = array(); while($query->have_posts()) { $post = $query->next_post(); $results[get_permalink($post)] = get_the_title($post); } return $this->build_dropdown($results); } /** * Build dropdown based on storyline order. */ function build_storyline_order_dropdown() { $storyline = $this->_new_comicpressstoryline(); $storyline->read_from_options(); $results = array(); if (!empty($storyline->_structure)) { foreach ($storyline->_structure as $id => $info) { $category = get_category($id); if (!empty($category)) { $results[get_category_link($id)] = str_repeat(' ', ($info['level'] - 1) * 3) . $category->name; } } } return $this->build_dropdown($results); } /** * Build dropdown based on storyline order, linking to the first post in each category. */ function build_storyline_order_post_link_dropdown() { $storyline = $this->_new_comicpressstoryline(); $storyline->read_from_options(); $dbi = $this->_new_comicpressdbinterface(); $results = array(); if (!empty($storyline->_structure)) { foreach ($storyline->_structure as $id => $info) { $category = get_category($id); if (!empty($category)) { $post = $dbi->get_first_post($id); if (!empty($post)) { $results[get_permalink($post)] = str_repeat(' ', ($info['level'] - 1) * 3) . $category->name; } } } } return $this->build_dropdown($results); } /** * Render the widget. */ function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; }; if (method_exists($this, "build_{$instance['mode']}_dropdown")) { echo $this->{"build_{$instance['mode']}_dropdown"}(); } echo $after_widget; } /** * Update widget parameters. */ function update($new_instance, $old_instance) { $instance = array(); foreach (array('title', 'mode') as $field) { if (isset($new_instance[$field])) { switch ($field) { case 'mode': if (isset($this->modes[$new_instance[$field]])) { $instance[$field] = $new_instance[$field]; } break; default: $instance[$field] = strip_tags($new_instance[$field]); break; } } } return $instance; } /** * Show the widget editor. */ function form($instance) { $valid_mode = array_shift(array_keys($this->modes)); $instance = wp_parse_args((array)$instance, array('title' => '', 'mode' => $valid_mode)); foreach (array( 'title' => __('Title:', 'comicpress'), 'mode' => __('Show in widget:', 'comicpress') ) as $field => $label) { ?>


modes as $mode => $label) { $requires_storyline = false; if (is_array($label)) { extract($label); } $is_enabled = ($requires_storyline === false) || ($requires_storyline === (get_option('comicpress-enable-storyline-support') == 1)); ?>