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 @@ +
Name: | ++ |
---|---|
Short name (used in template tags): | ++ |
Default image type? | +/> | +
Dimensions | ++ + x + + | +