From 9641d10cc9fbfab5d7911f590809725f631886e7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 9 Dec 2009 21:15:08 -0500 Subject: [PATCH 01/13] rework commit action handling --- .../ComicPressPostMediaHandlingMetabox.inc | 34 ++++++++----------- functions.php | 18 +++++----- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/classes/ComicPressPostMediaHandlingMetabox.inc b/classes/ComicPressPostMediaHandlingMetabox.inc index fab0b76..59d5088 100644 --- a/classes/ComicPressPostMediaHandlingMetabox.inc +++ b/classes/ComicPressPostMediaHandlingMetabox.inc @@ -1,34 +1,25 @@ $value) { - if (in_array($field, $valid_types)) { - $result[$field] = strip_tags($value); - } + function save_post($post_id) { + if (__comicpress_verify_nonce() == 'post-media-update') { + $info = $_REQUEST['cp']; + $result = array(); + if (isset($info['urls'])) { + if (is_array($info['urls'])) { + $valid_types = ComicPressPostMediaHandlingMetabox::_get_valid_types(); + foreach ($info['urls'] as $field => $value) { + if (in_array($field, $valid_types)) { + $result[$field] = strip_tags($value); } } } - update_post_meta($info['post_id'], 'backend_url_images', $result); } + update_post_meta($post_id, 'backend_url_images', $result); } } @@ -51,3 +42,6 @@ class ComicPressPostMediaHandlingMetabox { include('partials/post-media-handling/metabox.inc'); } } + +add_action('admin_menu', array('ComicPressPostMediaHandlingMetabox', 'admin_menu')); +add_action('save_post', array('ComicPressPostMediaHandlingMetabox', 'save_post')); \ No newline at end of file diff --git a/functions.php b/functions.php index 6df5d2d..ffd96d5 100644 --- a/functions.php +++ b/functions.php @@ -42,23 +42,20 @@ function __comicpress_init() { do_action('comicpress_init'); + if ($verified_nonce = __comicpress_verify_nonce()) { + do_action("comicpress_init-${verified_nonce}"); + } +} + +function __comicpress_verify_nonce() { if (isset($_REQUEST['cp'])) { if (is_array($_REQUEST['cp'])) { - if (($_REQUEST['cp']['post_id'] <= 0) && ($_POST['post_ID'] > 0)) { - $_REQUEST['cp']['post_id'] = $_POST['post_ID']; - } - if (isset($_REQUEST['cp']['_nonce'])) { if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { if (isset($_REQUEST['cp']['action'])) { if (isset($_REQUEST['cp']['_action_nonce'])) { if (wp_verify_nonce($_REQUEST['cp']['_action_nonce'], 'comicpress-' . $_REQUEST['cp']['action'])) { - $method_name = 'handle_' . str_replace('-', '_', $_REQUEST['cp']['action']); - foreach ($__comicpress_handlable_classes as $class_name) { - if (method_exists($class_name, $method_name)) { - call_user_func(array($class_name, $method_name), $_REQUEST['cp']); - } - } + return $_REQUEST['cp']['action']; } } } @@ -66,6 +63,7 @@ function __comicpress_init() { } } } + return false; } add_action('widgets_init', '__comicpress_widgets_init'); From 4a32858ab4b24d6abca6449a2072b47ab326a695 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 10 Dec 2009 07:32:28 -0500 Subject: [PATCH 02/13] build dropdown --- .../ComicPressPostMediaHandlingMetabox.inc | 4 +- ...ComicPressPostMediaHandlingMetaboxTest.php | 26 ++--- widgets/archive-dropdown.php | 102 ------------------ 3 files changed, 17 insertions(+), 115 deletions(-) delete mode 100644 widgets/archive-dropdown.php diff --git a/classes/ComicPressPostMediaHandlingMetabox.inc b/classes/ComicPressPostMediaHandlingMetabox.inc index 59d5088..7a6cabb 100644 --- a/classes/ComicPressPostMediaHandlingMetabox.inc +++ b/classes/ComicPressPostMediaHandlingMetabox.inc @@ -5,8 +5,10 @@ class ComicPressPostMediaHandlingMetabox { return array_keys(ComicPressMediaHandling::_bundle_global_variables()); } + function _verify_nonce() { return __comicpress_verify_nonce(); } + function save_post($post_id) { - if (__comicpress_verify_nonce() == 'post-media-update') { + if ($this->_verify_nonce() == 'post-media-update') { $info = $_REQUEST['cp']; $result = array(); if (isset($info['urls'])) { diff --git a/test/ComicPressPostMediaHandlingMetaboxTest.php b/test/ComicPressPostMediaHandlingMetaboxTest.php index 39c6039..0711ea9 100644 --- a/test/ComicPressPostMediaHandlingMetaboxTest.php +++ b/test/ComicPressPostMediaHandlingMetaboxTest.php @@ -7,29 +7,31 @@ require_once(dirname(__FILE__) . '/../classes/ComicPressPostMediaHandlingMetabox class ComicPressPostMediaHandlingMetaboxTest extends PHPUnit_Framework_TestCase { function setUp() { _reset_wp(); + $_REQUEST = array(); $this->pmh = new ComicPressPostMediaHandlingMetabox(); } - function providerTestPostMediaUpdate() { + function providerTestSavePost() { return array( - array(array(), ''), - array(array('post_id' => 'test'), ''), - array(array('post_id' => 1), array()), - array(array('post_id' => 1, 'urls' => false), array()), - array(array('post_id' => 1, 'urls' => array()), array()), - array(array('post_id' => 1, 'urls' => array('test' => 'test')), array()), - array(array('post_id' => 1, 'urls' => array('comic' => 'test')), array('comic' => 'test')), + array(array(), array()), + array(array('urls' => false), array()), + array(array('urls' => array()), array()), + array(array('urls' => array('test' => 'test')), array()), + array(array('urls' => array('comic' => 'test')), array('comic' => 'test')), ); } /** - * @dataProvider providerTestPostMediaUpdate + * @dataProvider providerTestSavePost */ - function testPostMediaUpdate($input, $expected_post_metadata) { - $pmh = $this->getMock('ComicPressPostMediaHandlingMetabox', array('_get_valid_types')); + function testSavePost($input, $expected_post_metadata) { + $pmh = $this->getMock('ComicPressPostMediaHandlingMetabox', array('_get_valid_types', '_verify_nonce')); + $pmh->expects($this->once())->method('_verify_nonce')->will($this->returnValue(true)); $pmh->expects($this->any())->method('_get_valid_types')->will($this->returnValue(array('comic'))); - $this->pmh->handle_post_media_update($input); + $_REQUEST = array('cp' => $input); + + $pmh->save_post(1); $this->assertEquals($expected_post_metadata, get_post_meta(1, 'backend_url_images', true)); } } diff --git a/widgets/archive-dropdown.php b/widgets/archive-dropdown.php deleted file mode 100644 index 05163c3..0000000 --- a/widgets/archive-dropdown.php +++ /dev/null @@ -1,102 +0,0 @@ -create_structure(get_option('comicpress-storyline-category-order')); - $categories = array_keys($storyline->_structure); - foreach ($categories as $id) { - $post = ComicPressDBInterface::get_instance()->get_first_comic($id); - } -} -*/ - -function comicpress_archive_dropdown() { ?> -
- -
- -
- -
- 'widget_comicpress_archive_dropdown', 'description' => __('Display a dropdown list of your archives, styled.','comicpress') ); - $this->WP_Widget('archive_dropdown', __('ComicPress Archive Dropdown','comicpress'), $widget_ops); - } - - 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 ($instance['showcomicposts'] == 'on') { - comicpress_archive_dropdown_comics(); - } else { - comicpress_archive_dropdown(); - } - echo $after_widget; - } - - function update($new_instance, $old_instance) { - $instance = $old_instance; - $instance['title'] = strip_tags($new_instance['title']); - $instance['showcomicposts'] = $new_instance['showcomicposts']; - return $instance; - } - - function form($instance) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'showcomicposts' => 'off' ) ); - $title = strip_tags($instance['title']); - $showcomicposts = $instance['showcomicposts']; if (empty($showcomicposts)) $showcomicposts = 'off'; - ?> -

-

  />Off

- - \ No newline at end of file From 039763281beb2949eb1bc27e590028acba1bbdaa Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 10 Dec 2009 07:38:18 -0500 Subject: [PATCH 03/13] totally didn't add anything, oops --- test/widgets/ArchiveDropdownWidgetTest.php | 61 ++++++++++ widgets/ArchiveDropdownWidget.inc | 133 +++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 test/widgets/ArchiveDropdownWidgetTest.php create mode 100644 widgets/ArchiveDropdownWidget.inc diff --git a/test/widgets/ArchiveDropdownWidgetTest.php b/test/widgets/ArchiveDropdownWidgetTest.php new file mode 100644 index 0000000..2eb1eaa --- /dev/null +++ b/test/widgets/ArchiveDropdownWidgetTest.php @@ -0,0 +1,61 @@ +w = new ArchiveDropdownWidget(); + } + + function providerTestBuildDropdown() { + return array( + array(null, 'Archives...', null, 'Go'), + array('Test', 'Test', 'Test2', 'Test2'), + ); + } + + /** + * @dataProvider providerTestBuildDropdown + */ + function testBuildDropdown($default_value, $expected_default, $button_value, $expected_button) { + if (!is_null($default_value)) { + _set_filter_expectation('comicpress_archive_dropdown_default_entry', $default_value); + } + + if (!is_null($button_value)) { + _set_filter_expectation('comicpress_archive_dropdown_submit_button', $button_value); + } + + foreach (array( + array('test' => 'Test', 'test2' => 'Test2'), + '' + ) as $entries) { + $html = $this->w->build_dropdown($entries); + + foreach (array( + array('tag' => 'div', 'attributes' => array('class' => 'archive-dropdown-wrap')), + array('tag' => 'form', 'attributes' => array('action' => '', 'method' => 'get')), + array('tag' => 'select', 'attributes' => array('name' => 'cp[urls]')), + array('tag' => 'input', 'attributes' => array('name' => 'cp[_nonce]')), + array('tag' => 'input', 'attributes' => array('name' => 'cp[_action_nonce]')), + array('tag' => 'input', 'attributes' => array('name' => 'cp[action]', 'value' => 'follow-archive-dropdown')), + array('tag' => 'option', 'attributes' => array('value' => ''), 'content' => $expected_default), + array('tag' => 'input', 'attributes' => array('type' => 'submit', 'value' => $expected_button)), + array('tag' => 'option', 'attributes' => array('value' => 'test'), 'content' => 'Test'), + array('tag' => 'option', 'attributes' => array('value' => 'test2'), 'content' => 'Test2'), + ) as $matcher) { + $this->assertTag($matcher, $html); + } + } + } + + function testBuildDropdownNotStringOrArray() { + $html = $this->w->build_dropdown(false); + + $this->assertTrue(empty($html)); + } +} \ No newline at end of file diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc new file mode 100644 index 0000000..91057a8 --- /dev/null +++ b/widgets/ArchiveDropdownWidget.inc @@ -0,0 +1,133 @@ +create_structure(get_option('comicpress-storyline-category-order')); + $categories = array_keys($storyline->_structure); + foreach ($categories as $id) { + $post = ComicPressDBInterface::get_instance()->get_first_comic($id); + } +} +*/ + +function comicpress_archive_dropdown() { ?> +
+ +
+ +
+ +
+ 'ArchiveDropdownWidget', 'description' => __('Display a dropdown list of your archives, styled.','comicpress') ); + $this->WP_Widget('archive_dropdown', __('ComicPress Archive Dropdown','comicpress'), $widget_ops); + } + + function _verify_nonce() { return __comicpress_verify_nonce(); } + + function template_redirect() { + if ($this->_verify_nonce() == 'follow-archive-dropdown') { + + } + } + + function build_dropdown($entries) { + if (is_string($entries) || is_array($entries)) { + $id = 'archive-dropdown-' . md5(rand()); + + $nonce = wp_create_nonce('comicpress'); + $action_nonce = wp_create_nonce('comicpress-follow-archive-dropdown'); + + ob_start(); ?> +
+
+ + + + + + +
+
+ + '', 'showcomicposts' => 'off' ) ); + $title = strip_tags($instance['title']); + $showcomicposts = $instance['showcomicposts']; if (empty($showcomicposts)) $showcomicposts = 'off'; + ?> +

+

  />Off

+ Date: Thu, 10 Dec 2009 07:46:59 -0500 Subject: [PATCH 04/13] work on archive dropdown, currently broken --- widgets/ArchiveDropdownWidget.inc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index 91057a8..dff7cd9 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -3,8 +3,8 @@ Widget Name: comicpress archive dropdown Widget URI: http://comicpress.org/ Description: -Author: Philip M. Hofer (Frumph) -Version: 1.04 +Author: Philip M. Hofer (Frumph) & John Bintz +Version: 1.1 Author URI: http://frumph.net/ */ @@ -24,7 +24,7 @@ function comicpress_archive_dropdown() { ?>
- + 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 build_comic_archive_dropdown() { + $storyline = $this->_new_comicpressstoryline(); + $storyline->read_from_options(); + + + } + function widget($args, $instance) { extract($args, EXTR_SKIP); From b6f7d9601953caa0538d115df460826d8f3a00c1 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 10 Dec 2009 23:24:45 -0500 Subject: [PATCH 05/13] comic archive dropdown --- test/widgets/ArchiveDropdownWidgetTest.php | 28 ++++++++++++++++++++++ widgets/ArchiveDropdownWidget.inc | 22 ++++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/test/widgets/ArchiveDropdownWidgetTest.php b/test/widgets/ArchiveDropdownWidgetTest.php index 2eb1eaa..d9c554f 100644 --- a/test/widgets/ArchiveDropdownWidgetTest.php +++ b/test/widgets/ArchiveDropdownWidgetTest.php @@ -58,4 +58,32 @@ class ArchiveDropdownWidgetTest extends PHPUnit_Framework_TestCase { $this->assertTrue(empty($html)); } + + function testBuildComicArchiveDropdown() { + $w = $this->getMock('ArchiveDropdownWidget', array('_new_comicpressstoryline', '_new_wp_query', 'build_dropdown')); + + $storyline = $this->getMock('ComicPressStoryline', array('read_from_options', 'build_from_restrictions')); + $storyline->expects($this->once())->method('read_from_options'); + $storyline->expects($this->once())->method('build_from_restrictions')->will($this->returnValue(array(1,2,3))); + + $w->expects($this->once())->method('_new_comicpressstoryline')->will($this->returnValue($storyline)); + + $query = $this->getMock('WP_Query', array('query', 'has_posts', 'next_post')); + $query->expects($this->once())->method('query')->with(array( + 'showposts' => -1, + 'category__in' => array(1,2,3) + )); + + wp_insert_post((object)array('ID' => 1, 'guid' => 'guid', 'post_title' => 'title')); + + $query->expects($this->at(1))->method('has_posts')->will($this->returnValue(true)); + $query->expects($this->at(2))->method('next_post')->will($this->returnValue((object)array('ID' => 1, 'guid' => 'guid', 'post_title' => 'title'))); + $query->expects($this->at(3))->method('has_posts')->will($this->returnValue(false)); + + $w->expects($this->once())->method('_new_wp_query')->will($this->returnValue($query)); + + $w->expects($this->once())->method('build_dropdown')->with(array('guid' => 'title')); + + $w->build_comic_archive_dropdown(); + } } \ No newline at end of file diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index dff7cd9..55bb6ae 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -20,15 +20,6 @@ function comicpress_archive_dropdown_storyline() { } */ -function comicpress_archive_dropdown() { ?> -
- -
-_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->has_posts()) { + $post = $query->next_post(); + $results[get_permalink($post)] = get_the_title($post); + } + + return $this->build_dropdown($results); } function widget($args, $instance) { From 0edca9e64a4e57442e371b27dd708235387196d5 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 14 Dec 2009 21:19:21 -0500 Subject: [PATCH 06/13] update --- test/widgets/ArchiveDropdownWidgetTest.php | 28 ++++++++++++++++++++++ widgets/ArchiveDropdownWidget.inc | 27 ++++++++++++++++++--- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/test/widgets/ArchiveDropdownWidgetTest.php b/test/widgets/ArchiveDropdownWidgetTest.php index d9c554f..6608524 100644 --- a/test/widgets/ArchiveDropdownWidgetTest.php +++ b/test/widgets/ArchiveDropdownWidgetTest.php @@ -86,4 +86,32 @@ class ArchiveDropdownWidgetTest extends PHPUnit_Framework_TestCase { $w->build_comic_archive_dropdown(); } + + function providerTestUpdate() { + $w = new ArchiveDropdownWidget(); + $valid_mode = array_shift(array_keys($w->modes)); + + return array( + array(array(), array()), + array( + array('title' => 'test'), + array('title' => 'test'), + ), + array( + array('mode' => 'bad'), + array() + ), + array( + array('mode' => $valid_mode), + array('mode' => $valid_mode) + ) + ); + } + + /** + * @dataProvider providerTestUpdate + */ + function testUpdate($input, $expected_output) { + $this->assertEquals($expected_output, $this->w->update($input, array())); + } } \ No newline at end of file diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index 55bb6ae..5d0cc41 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -40,9 +40,16 @@ function comicpress_archive_dropdown_comics() { } class ArchiveDropdownWidget extends WP_Widget { + var $modes; + function ArchiveDropdownWidget() { $widget_ops = array('classname' => 'ArchiveDropdownWidget', 'description' => __('Display a dropdown list of your archives, styled.','comicpress') ); $this->WP_Widget('archive_dropdown', __('ComicPress Archive Dropdown','comicpress'), $widget_ops); + + $this->modes = array( + 'monthly_archive' => __('Monthly archive', 'comicpress'), + 'comic_archive' => __('Comic archive', 'comicpress') + ); } function _verify_nonce() { return __comicpress_verify_nonce(); } @@ -136,9 +143,23 @@ class ArchiveDropdownWidget extends WP_Widget { } function update($new_instance, $old_instance) { - $instance = $old_instance; - $instance['title'] = strip_tags($new_instance['title']); - $instance['showcomicposts'] = $new_instance['showcomicposts']; + $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; } From 61436fb243be5012108804f49e2a3c179699e66e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 14 Dec 2009 21:30:52 -0500 Subject: [PATCH 07/13] editor form --- widgets/ArchiveDropdownWidget.inc | 32 +++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index 5d0cc41..60fe0e0 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -164,13 +164,29 @@ class ArchiveDropdownWidget extends WP_Widget { } function form($instance) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'showcomicposts' => 'off' ) ); - $title = strip_tags($instance['title']); - $showcomicposts = $instance['showcomicposts']; if (empty($showcomicposts)) $showcomicposts = 'off'; - ?> -

-

  />Off

- 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) { ?> +
+ + +
+ +

+ Date: Mon, 14 Dec 2009 21:31:03 -0500 Subject: [PATCH 08/13] remove template tags --- widgets/ArchiveDropdownWidget.inc | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index 60fe0e0..57121bf 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -9,36 +9,6 @@ Author URI: http://frumph.net/ */ -/* -function comicpress_archive_dropdown_storyline() { - $storyline = new ComicPressStoryline(); - $storyline->create_structure(get_option('comicpress-storyline-category-order')); - $categories = array_keys($storyline->_structure); - foreach ($categories as $id) { - $post = ComicPressDBInterface::get_instance()->get_first_comic($id); - } -} -*/ - -function comicpress_archive_dropdown_comics() { - global $post, $wp_query; - $temp_post = $post; - $temp_query = $wp_query; -?> -
- -
- Date: Mon, 14 Dec 2009 21:34:41 -0500 Subject: [PATCH 09/13] widget display and integration bug --- test/widgets/ArchiveDropdownWidgetTest.php | 6 +++--- widgets/ArchiveDropdownWidget.inc | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/widgets/ArchiveDropdownWidgetTest.php b/test/widgets/ArchiveDropdownWidgetTest.php index 6608524..6a4d6e4 100644 --- a/test/widgets/ArchiveDropdownWidgetTest.php +++ b/test/widgets/ArchiveDropdownWidgetTest.php @@ -68,7 +68,7 @@ class ArchiveDropdownWidgetTest extends PHPUnit_Framework_TestCase { $w->expects($this->once())->method('_new_comicpressstoryline')->will($this->returnValue($storyline)); - $query = $this->getMock('WP_Query', array('query', 'has_posts', 'next_post')); + $query = $this->getMock('WP_Query', array('query', 'have_posts', 'next_post')); $query->expects($this->once())->method('query')->with(array( 'showposts' => -1, 'category__in' => array(1,2,3) @@ -76,9 +76,9 @@ class ArchiveDropdownWidgetTest extends PHPUnit_Framework_TestCase { wp_insert_post((object)array('ID' => 1, 'guid' => 'guid', 'post_title' => 'title')); - $query->expects($this->at(1))->method('has_posts')->will($this->returnValue(true)); + $query->expects($this->at(1))->method('have_posts')->will($this->returnValue(true)); $query->expects($this->at(2))->method('next_post')->will($this->returnValue((object)array('ID' => 1, 'guid' => 'guid', 'post_title' => 'title'))); - $query->expects($this->at(3))->method('has_posts')->will($this->returnValue(false)); + $query->expects($this->at(3))->method('have_posts')->will($this->returnValue(false)); $w->expects($this->once())->method('_new_wp_query')->will($this->returnValue($query)); diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index 57121bf..eef9b84 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -90,7 +90,7 @@ class ArchiveDropdownWidget extends WP_Widget { )); $results = array(); - while($query->has_posts()) { + while($query->have_posts()) { $post = $query->next_post(); $results[get_permalink($post)] = get_the_title($post); } @@ -103,12 +103,12 @@ class ArchiveDropdownWidget extends WP_Widget { echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); - if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; - if ($instance['showcomicposts'] == 'on') { - comicpress_archive_dropdown_comics(); - } else { - comicpress_archive_dropdown(); + 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; } From 200a89bd934599fa00d6310952f74f40d6ebc8d3 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 14 Dec 2009 21:41:40 -0500 Subject: [PATCH 10/13] storyline order --- widgets/ArchiveDropdownWidget.inc | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index eef9b84..de4e7e8 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -18,7 +18,8 @@ class ArchiveDropdownWidget extends WP_Widget { $this->modes = array( 'monthly_archive' => __('Monthly archive', 'comicpress'), - 'comic_archive' => __('Comic archive', 'comicpress') + 'comic_archive' => __('Comic archive', 'comicpress'), + 'storyline_order' => __('Storyline order', 'comicpress'), ); } @@ -30,6 +31,9 @@ class ArchiveDropdownWidget extends WP_Widget { } } + /** + * 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()); @@ -71,6 +75,9 @@ class ArchiveDropdownWidget extends WP_Widget { return ''; } + /** + * Build the monthly archive dropdown. + */ function build_monthly_archive_dropdown() { return $this->build_dropdown(wp_get_archives('type=monthly&format=option&show_post_count=-1&echo=0')); } @@ -79,6 +86,9 @@ class ArchiveDropdownWidget extends WP_Widget { 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(); @@ -98,6 +108,29 @@ class ArchiveDropdownWidget extends WP_Widget { 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); + } + + /** + * Render the widget. + */ function widget($args, $instance) { extract($args, EXTR_SKIP); @@ -112,6 +145,9 @@ class ArchiveDropdownWidget extends WP_Widget { echo $after_widget; } + /** + * Update widget parameters. + */ function update($new_instance, $old_instance) { $instance = array(); @@ -133,6 +169,9 @@ class ArchiveDropdownWidget extends WP_Widget { 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)); From cc516694ef1eb893791efba183b763793dc18504 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 14 Dec 2009 21:44:45 -0500 Subject: [PATCH 11/13] non-javascript redirection --- widgets/ArchiveDropdownWidget.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index de4e7e8..da2f39a 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -26,8 +26,8 @@ class ArchiveDropdownWidget extends WP_Widget { function _verify_nonce() { return __comicpress_verify_nonce(); } function template_redirect() { - if ($this->_verify_nonce() == 'follow-archive-dropdown') { - + if (ArchiveDropdownWidget::_verify_nonce() == 'follow-archive-dropdown') { + wp_redirect($_GET['cp']['urls']); } } @@ -199,3 +199,5 @@ class ArchiveDropdownWidget extends WP_Widget { Date: Tue, 15 Dec 2009 06:27:01 -0500 Subject: [PATCH 12/13] placeholder to nuke old file --- widgets/archive-dropdown.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 widgets/archive-dropdown.php diff --git a/widgets/archive-dropdown.php b/widgets/archive-dropdown.php new file mode 100644 index 0000000..e69de29 From cb83eeb04987d33ae975bec04185db4fb251bdef Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 15 Dec 2009 06:34:26 -0500 Subject: [PATCH 13/13] move widget template tags to separate file and build tags for archive dropdown --- functions.php | 23 -------------- functions/widget-template-tags.php | 48 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 functions/widget-template-tags.php diff --git a/functions.php b/functions.php index f000731..0a02516 100644 --- a/functions.php +++ b/functions.php @@ -839,26 +839,3 @@ function comicpress_gnav_display_css() { } if (comicpress_check_child_file('childfunctions') == false) {} - -/** - * Render the ComicPress calendar widget. - */ -function comicpress_calendar_embed() { - $calendar = new CalendarWidget(); - - $instance = array(); - foreach (array('before_widget', 'after_widget', 'thumbnail', 'link', 'small', 'medium', 'large') as $field) { - $instance[$field] = ''; - } - - $calendar->widget($instance, array()); -} - -/** - * Render the ComicPress bookmark widget. - */ -function comicpress_comic_bookmark_embed() { - $bookmark = new BookmarkWidget(); - $bookmark->init(); - $bookmark->widget(array(), array()); -} diff --git a/functions/widget-template-tags.php b/functions/widget-template-tags.php new file mode 100644 index 0000000..8b617b7 --- /dev/null +++ b/functions/widget-template-tags.php @@ -0,0 +1,48 @@ +widget($instance, array()); +} + +/** + * Render the ComicPress bookmark widget. + */ +function comicpress_comic_bookmark_embed() { + $bookmark = new BookmarkWidget(); + $bookmark->init(); + $bookmark->widget(array(), array()); +} + +/** + * Render the monthly archive dropdown widget + */ +function comicpress_archive_dropdown() { + $archive = new ArchiveDropdownWidget(); + $archive->widget(array(), array('mode' => 'monthly_archive')); +} + +/** + * Render the comic archive dropdown widget + */ +function comicpress_archive_dropdown_comics() { + $archive = new ArchiveDropdownWidget(); + $archive->widget(array(), array('mode' => 'comic_archive')); +} + +/** + * Render the storyline order dropdown widget + */ +function comicpress_archive_dropdown_storyline() { + $archive = new ArchiveDropdownWidget(); + $archive->widget(array(), array('mode' => 'storyline_order')); +}