From b1db6deb7b029906476de69fa4fb1c57bf495a52 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 12 Nov 2009 22:13:05 -0500 Subject: [PATCH] working on image type editor --- classes/ComicPress.inc | 2 +- classes/ComicPressAdmin.inc | 24 +++- classes/ComicPressDBInterface.inc | 155 +++++++++++++----------- classes/partials/_image-type-editor.inc | 26 ++++ classes/partials/options-admin.inc | 146 +++++++++++----------- css/cp-admin.css | 26 +++- test/ComicPressAdminTest.php | 21 +++- 7 files changed, 246 insertions(+), 154 deletions(-) create mode 100644 classes/partials/_image-type-editor.inc diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 447ad6c..c59b14a 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -155,7 +155,7 @@ class ComicPress { foreach (get_declared_classes() as $class) { if (preg_match('#^ComicPressBackend.+$#', $class) > 0) { - $this->backends[] = new $class(); + $this->backends[] = $class; } } } diff --git a/classes/ComicPressAdmin.inc b/classes/ComicPressAdmin.inc index 4cbaa77..a9b21e1 100644 --- a/classes/ComicPressAdmin.inc +++ b/classes/ComicPressAdmin.inc @@ -246,20 +246,26 @@ class ComicPressAdmin { $defined_default = null; foreach ($info['image_types'] as $type => $image_info) { if (is_array($image_info)) { + $new_value = array(); + $new_type = $type; foreach ($image_info as $field => $field_value) { - $new_value = array(); switch ($field) { - case "default": $defined_default = $type; break; - case "dimensions": + case 'default': $defined_default = $type; break; + case 'dimensions': if (is_array($field_value)) { if (count(array_intersect(array('width', 'height'), array_keys($field_value))) == 2) { $new_value['dimensions'] = "{$field_value['width']}x{$field_value['height']}"; } } break; + case 'name': $new_value['name'] = (string)$field_value; break; + case 'short_name': $new_type = $field_value; break; } - $this->comicpress->comicpress_options['image_types'][$type] = $new_value; } + if ($type != $new_type) { + unset($this->comicpress->comicpress_options['image_types'][$new_type]); + } + $this->comicpress->comicpress_options['image_types'][$new_type] = $new_value; } } } @@ -300,6 +306,16 @@ class ComicPressAdmin { } } + function _json_encode($data) { + if (function_exists('json_encode')) { + return json_decode($data); + } else { + require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php"); + $j = new Moxiecode_JSON(); + return $j->encode($data); + } + } + function handle_update_comic_ordering() { if (isset($_POST['post_ID'])) { if (is_numeric($_POST['post_ID'])) { diff --git a/classes/ComicPressDBInterface.inc b/classes/ComicPressDBInterface.inc index abf4a2d..79317b1 100644 --- a/classes/ComicPressDBInterface.inc +++ b/classes/ComicPressDBInterface.inc @@ -1,100 +1,111 @@ _prepare_wp_query(); + /** + * Set the comic categories for the current run of ComicPress. + */ + function set_comic_categories($categories) { + $this->_all_categories = get_all_category_ids(); + $this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories)); + } - $terminal_comic_query = new WP_Query(); + function _get_categories_to_exclude($category = null) { + $result = array_diff($this->_all_categories, array($category)); + if (is_array($result)) { + return (is_null($category)) ? $this->_non_comic_categories : array_values($result); + } else { + return $this->_non_comic_categories; + } + } - $query_parameters = array( - 'showposts' => 1, - 'order' => $first ? "asc" : "desc", - 'status' => 'publish' - ); + /** + * Find the terminal post in a specific category. + */ + function get_terminal_post_in_category($category_id, $first = true) { + $this->_prepare_wp_query(); - if (is_array($include_categories)) { - $query_parameters['category_in'] = $include_categories; - } + $sort_order = $first ? "asc" : "desc"; + $terminal_comic_query = new WP_Query(); + $terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish"); + $post = false; + if ($terminal_comic_query->have_posts()) { + $post = reset($terminal_comic_query->posts); + } - $terminal_comic_query->query($query_parameters); - $post = false; - if ($terminal_comic_query->have_posts()) { - $post = reset($terminal_comic_query->posts); - } + $this->_reset_wp_query(); + return $post; + } - $this->_reset_wp_query(); - return $post; - } + /** + * Get the first comic in a category. + */ + function get_first_comic($category_id) { + return $this->get_terminal_post_in_category($category_id); + } - /** - * Get the first comic in a category. - */ - function get_first_post($include_categories = null) { - return $this->get_terminal_post(true, $include_categories); - } + /** + * Get the last comic in a category. + */ + function get_last_comic($category_id) { + return $this->get_terminal_post_in_category($category_id, false); + } - /** - * Get the last comic in a category. - */ - function get_last_post($include_categories = null) { - return $this->get_terminal_post(false, $include_categories); - } + /** + * Get the comic post adjacent to the current comic. + * Wrapper around get_adjacent_post(). Don't unit test this method. + */ + function get_adjacent_comic($category, $next = false, $override_post = null) { + global $post; - /** - * Get the comic post adjacent to the current comic. - * Wrapper around get_adjacent_post(). Don't unit test this method. - */ - function get_adjacent_post($categories = array(), $next = false, $override_post = null) { - global $post; + $this->_prepare_wp_query(); + if (!is_null($override_post)) { $temp_post = $post; $post = $override_post; } - $this->_prepare_wp_query(); - if (!is_null($override_post)) { $temp_post = $post; $post = $override_post; } + $result = get_adjacent_post(false, implode(" and ", $this->_get_categories_to_exclude($category)), !$next); - $result = get_adjacent_post(false, implode(" and ", array_diff(get_all_category_ids(), $categories)), !$next); + $this->_reset_wp_query(); + if (!is_null($override_post)) { $post = $temp_post; } - $this->_reset_wp_query(); - if (!is_null($override_post)) { $post = $temp_post; } + return empty($result) ? false : $result; + } - return empty($result) ? false : $result; - } + function _prepare_wp_query() { + global $wp_query; - function _prepare_wp_query() { - global $wp_query; + $this->is_single = $wp_query->is_single; + $this->in_the_loop = $wp_query->in_the_loop; - $this->is_single = $wp_query->is_single; - $this->in_the_loop = $wp_query->in_the_loop; + $wp_query->is_single = $wp_query->in_the_loop = true; + } - $wp_query->is_single = $wp_query->in_the_loop = true; - } + function _reset_wp_query() { + global $wp_query; - function _reset_wp_query() { - global $wp_query; + $wp_query->is_single = $this->is_single; + $wp_query->in_the_loop = $this->in_the_loop; + } - $wp_query->is_single = $this->is_single; - $wp_query->in_the_loop = $this->in_the_loop; - } + /** + * Get the previous comic from the current one. + */ + function get_previous_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, false, $override_post); } - /** - * Get the previous comic from the current one. - */ - function get_previous_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, false, $override_post); } - - /** - * Get the next comic from the current one. - */ - function get_next_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, true, $override_post); } + /** + * Get the next comic from the current one. + */ + function get_next_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, true, $override_post); } } -// @codeCoverageIngoreEnd +?> diff --git a/classes/partials/_image-type-editor.inc b/classes/partials/_image-type-editor.inc new file mode 100644 index 0000000..04a0569 --- /dev/null +++ b/classes/partials/_image-type-editor.inc @@ -0,0 +1,26 @@ +
+ X + + + + + + + + + + + + + + + + + + +
Name:
Short name (used in template tags):
Default image type? />
Dimensions + + x + +
+
diff --git a/classes/partials/options-admin.inc b/classes/partials/options-admin.inc index 86accba..96bed67 100644 --- a/classes/partials/options-admin.inc +++ b/classes/partials/options-admin.inc @@ -1,83 +1,81 @@
-

-
- -

- - - - + + +
+

+ + +

+ + + + - - __('Comic Image Dimensions', 'comicpress'), - 'rss_dimensions' => __('RSS Feed Image Dimensions', 'comicpress'), - 'archive_dimensions' => __('Archive Image Dimensions', 'comicpress'), - 'mini_dimensions' => __('Mini Image Dimensions', 'comicpress'), - ) as $field => $name) { ?> - - - - - -
- _render_admin_storyline_tree(reset($storyline->get_simple_storyline())) ?>
-

Categories page)', 'comicpress') ?>

-
- create_dimension_selector('cp[' . $field . ']', $this->comicpress->comicpress_options[$field]) ?> -
-

- - - - - - all_addons)) { ?> - - - + + + + + +
- __('Show inline comic ordering', 'comicpress') - ) as $key => $label) { ?> - -
- -
- all_addons as $addon) { - if (!empty($addon->name)) { - $enabled = ($addon->is_addon_manager !== true); - $checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name]; - ?> +

Categories page)', 'comicpress') ?>

+
+
+ comicpress->comicpress_options['image_types'] as $type => $info) { ?> + + +
+ Add a new image type +
+

+ + + + + + all_addons)) { ?> + + + - - -
+ __('Show inline comic ordering', 'comicpress') + ) as $key => $label) { ?> + +
+ +
+ all_addons as $addon) { + if (!empty($addon->name)) { + $enabled = ($addon->is_addon_manager !== true); + $checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name]; + ?> -
- -
- - +
+ +
+ +
diff --git a/css/cp-admin.css b/css/cp-admin.css index c2c731b..6829e84 100644 --- a/css/cp-admin.css +++ b/css/cp-admin.css @@ -69,4 +69,28 @@ height: 16px; display: block; margin: 8px 0 0 8px; -} \ No newline at end of file +} + +.image-type-holder { + border: solid #aaa 1px; + margin: 10px 0; + padding: 5px; +} + +.image-type-holder table { + width: 90% +} + +.image-type-editor-name input { + font-size: 1.5em; + width: 100% +} + +.delete-image-type { + float: right; + display: inline; + padding: 3px; + border: solid #aaa 1px; + font-weight: bold; + color: #aaa +} diff --git a/test/ComicPressAdminTest.php b/test/ComicPressAdminTest.php index 6a15fd2..7c9a2d4 100644 --- a/test/ComicPressAdminTest.php +++ b/test/ComicPressAdminTest.php @@ -34,12 +34,12 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { ), array( 'image_types' => array( - 'comic' => array('default' => 'yes', 'dimensions' => array('width' => '100', 'height' => '100')) + 'comic' => array('default' => 'yes', 'name' => 'Test', 'dimensions' => array('width' => '100', 'height' => '100')) ) ), array( 'image_types' => array( - 'comic' => array('default' => true, 'dimensions' => '100x100') + 'comic' => array('default' => true, 'name' => 'Test', 'dimensions' => '100x100') ) ) ), @@ -98,6 +98,23 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { ) ) ), + array( + array( + 'image_types' => array( + 'comic' => array('default' => true, 'dimensions' => '500x50'), + ) + ), + array( + 'image_types' => array( + 'comic' => array('short_name' => 'newcomic', 'dimensions' => array('width' => '100', 'height' => '100')), + ) + ), + array( + 'image_types' => array( + 'newcomic' => array('default' => true, 'dimensions' => '100x100'), + ) + ) + ) ); }