working on storyline

This commit is contained in:
John Bintz 2009-11-23 20:54:07 -05:00
parent 364c1479a2
commit d67cc49199
6 changed files with 419 additions and 338 deletions

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
comicpress28 = $(realpath ../../themes/comicpress-2.8)
.PHONY : copy-storyline
copy-storyline :
ifdef comicpress28
cp classes/ComicPressDBInterface.inc classes/ComicPressNavigation.inc classes/ComicPressStoryline.inc $(comicpress28)/classes
endif

View File

@ -1,6 +1,7 @@
<?php <?php
class ComicPressDBInterface { class ComicPressDBInterface {
var $is_single, $in_the_loop;
function ComicPressDBInterface() {} function ComicPressDBInterface() {}
function get_instance() { function get_instance() {
@ -11,6 +12,7 @@ class ComicPressDBInterface {
} }
function _get_categories_to_exclude($categories = null) { function _get_categories_to_exclude($categories = null) {
if (is_numeric($categories)) { $categories = array($categories); }
if (is_array($categories)) { if (is_array($categories)) {
return array_values(array_diff(get_all_category_ids(), $categories)); return array_values(array_diff(get_all_category_ids(), $categories));
} else { } else {
@ -42,6 +44,8 @@ class ComicPressDBInterface {
function get_terminal_post_in_categories($categories, $first = true) { function get_terminal_post_in_categories($categories, $first = true) {
$this->_prepare_wp_query(); $this->_prepare_wp_query();
if (!is_array($categories)) { $categories = array($categories); }
$sort_order = $first ? "asc" : "desc"; $sort_order = $first ? "asc" : "desc";
$terminal_comic_query = new WP_Query(); $terminal_comic_query = new WP_Query();
$terminal_comic_query->query(array( $terminal_comic_query->query(array(

View File

@ -28,18 +28,18 @@ class ComicPressNavigation {
// global previous/next // global previous/next
foreach (array('previous', 'next') as $field) { foreach (array('previous', 'next') as $field) {
$nav[$field] = $this->_dbi->{"get_${field}_comic"}($categories, $post); $nav[$field] = $this->_dbi->{"get_${field}_post"}($categories, $post);
} }
// global first/last // global first/last
foreach (array('first', 'last') as $field) { foreach (array('first', 'last') as $field) {
$nav[$field] = $this->_dbi->{"get_${field}_comic"}($categories); $nav[$field] = $this->_dbi->{"get_${field}_post"}($categories);
} }
if ($category = $this->_storyline->get_valid_post_category($post->ID)) { if ($category = $this->_storyline->get_valid_post_category($post->ID)) {
// storyline previous/next // storyline previous/next
foreach (array('previous', 'next') as $field) { foreach (array('previous', 'next') as $field) {
$nav["storyline-${field}"] = $this->_dbi->{"get_${field}_comic"}($category, $post); $nav["storyline-${field}"] = $this->_dbi->{"get_${field}_post"}($category, $post);
} }
// adjacent storyline nodes // adjacent storyline nodes
@ -47,7 +47,7 @@ class ComicPressNavigation {
foreach ($valid as $field) { foreach ($valid as $field) {
$all_adjacents = $this->_storyline->all_adjacent($category, $field); $all_adjacents = $this->_storyline->all_adjacent($category, $field);
foreach ($all_adjacents as $adjacent_category) { foreach ($all_adjacents as $adjacent_category) {
$result = $this->_dbi->get_first_comic($adjacent_category); $result = $this->_dbi->get_first_post($adjacent_category);
if (!empty($result)) { if (!empty($result)) {
$nav["storyline-chapter-${field}"] = $result; break; $nav["storyline-chapter-${field}"] = $result; break;
} }

View File

@ -3,37 +3,43 @@
require_once('ComicPressDBInterface.inc'); require_once('ComicPressDBInterface.inc');
class ComicPressStoryline { class ComicPressStoryline {
var $_structure; var $_structure;
var $_category_search; var $_category_search;
function &read_from_options() { function &read_from_options() {
$this->create_structure($this->get_flattened_storyline()); $this->create_structure($this->get_flattened_storyline());
return $this; return $this;
} }
/** /**
* Get the flattened storyline from options. * Get the flattened storyline from options.
*/ */
function get_flattened_storyline() { function get_flattened_storyline() {
$comicpress = &ComicPress::get_instance(); if (class_exists('ComicPress')) {
if (isset($comicpress->comicpress_options['storyline_order'])) { $comicpress = &ComicPress::get_instance();
return $comicpress->comicpress_options['storyline_order']; if (isset($comicpress->comicpress_options['storyline_order'])) {
return $comicpress->comicpress_options['storyline_order'];
}
} else {
return get_option("comicpress-storyline-category-order");
} }
return false; return false;
} }
/** /**
* Set the global storyline as a flattened storyline. * Set the global storyline as a flattened storyline.
*/ */
function set_flattened_storyline($storyline) { function set_flattened_storyline($storyline) {
$comicpress = &ComicPress::get_instance(); if (class_exists('ComicPress')) {
$comicpress->comicpress_options['storyline_order'] = $storyline; $comicpress = &ComicPress::get_instance();
$comicpress->save(); $comicpress->comicpress_options['storyline_order'] = $storyline;
$comicpress->save();
}
} }
/** /**
* Set the order from a flattened storyline. * Set the order from a flattened storyline.
*/ */
function set_order_via_flattened_storyline($order) { function set_order_via_flattened_storyline($order) {
$nodes = explode(',', $order); $nodes = explode(',', $order);
$original_nodes = explode(',', $this->get_flattened_storyline()); $original_nodes = explode(',', $this->get_flattened_storyline());
@ -60,170 +66,173 @@ class ComicPressStoryline {
return false; return false;
} }
/** /**
* Create a searchable structure from a node list. * Create a searchable structure from a node list.
* @param array $structure The structure to process. * @param array $structure The structure to process.
* @return boolean True if the structure was valid. * @return boolean True if the structure was valid.
*/ */
function create_structure($structure) { function create_structure($structure) {
$key = $this->_create_structure_key($structure); $key = $this->_create_structure_key($structure);
if ($key !== false) { if ($key !== false) {
if (is_string($structure)) { if (is_string($structure)) {
$structure = explode(',', $structure); $structure = explode(',', $structure);
} else { } else {
if (is_array($structure)) { if (is_array($structure)) {
$fixed_structure = array(); $fixed_structure = array();
foreach ($structure as $s) { foreach ($structure as $s) {
if (!is_array($s)) { $fixed_structure[] = $s; } if (!is_array($s)) { $fixed_structure[] = $s; }
} }
$structure = $fixed_structure; $structure = $fixed_structure;
} }
} }
if (($result = wp_cache_get($key, 'comicpress')) !== false) { if (($result = wp_cache_get($key, 'comicpress')) !== false) {
$this->_structure = $result; $this->_structure = $result;
} else { } else {
$new_structure = array(); $new_structure = array();
$parent = null; $parent = null;
$all_leaves = array(); $all_leaves = array();
$adjacents_by_parent = array(); $adjacents_by_parent = array();
if (is_array($structure)) { if (is_array($structure)) {
$is_valid = true; $is_valid = true;
foreach ($structure as $branch) { foreach ($structure as $branch) {
if (is_string($branch)) { if (is_string($branch)) {
$parts = explode('/', $branch); $parts = explode('/', $branch);
$valid = false; $valid = false;
if (count($parts) > 1) { if (count($parts) > 1) {
if ($parts[0] == '0') { $valid = true; } if ($parts[0] == '0') { $valid = true; }
} }
if (!$valid) { if (!$valid) {
$is_valid = false; break; $is_valid = false; break;
} else { } else {
$data = array(); $data = array();
$leaf = end($parts); $leaf = end($parts);
$all_leaves[] = $leaf; $all_leaves[] = $leaf;
$data['level'] = count($parts) - 1; $data['level'] = count($parts) - 1;
if (count($parts) > 2) { if (count($parts) > 2) {
$parent = $parts[count($parts) - 2]; $parent = $parts[count($parts) - 2];
if (!isset($adjacents_by_parent[$parent])) { if (!isset($adjacents_by_parent[$parent])) {
$adjacents_by_parent[$parent] = array(); $adjacents_by_parent[$parent] = array();
} }
$adjacents_by_parent[$parent][] = $leaf; $adjacents_by_parent[$parent][] = $leaf;
$data['parent'] = $parent; $data['parent'] = $parent;
} }
$new_structure[$leaf] = $data; $new_structure[$leaf] = $data;
} }
} else { } else {
$is_valid = false; break; $is_valid = false; break;
} }
} }
if ($is_valid) { if ($is_valid) {
for ($i = 0; $i < count($all_leaves); ++$i) { for ($i = 0; $i < count($all_leaves); ++$i) {
foreach (array('previous' => -1, 'next' => 1) as $type => $dir) { foreach (array('previous' => -1, 'next' => 1) as $type => $dir) {
if (isset($all_leaves[$i + $dir])) { if (isset($all_leaves[$i + $dir])) {
$new_structure[$all_leaves[$i]][$type] = $all_leaves[$i + $dir]; $new_structure[$all_leaves[$i]][$type] = $all_leaves[$i + $dir];
} }
} }
} }
$this->_structure = $new_structure; $this->_structure = $new_structure;
} }
} }
wp_cache_set($key, $this->_structure, 'comicpress'); wp_cache_set($key, $this->_structure, 'comicpress');
} }
} }
return is_array($this->_structure); return is_array($this->_structure);
} }
function _get_field($field, $id) { function _get_field($field, $id) {
if (isset($this->_structure)) { if (isset($this->_structure)) {
$id = $this->_ensure_numeric_category($id); foreach ($this->_ensure_category_ids($id) as $id) {
if (isset($this->_structure[$id])) { if (isset($this->_structure[$id])) {
if (isset($this->_structure[$id][$field])) { if (isset($this->_structure[$id][$field])) {
return $this->_structure[$id][$field]; return $this->_structure[$id][$field];
} }
} }
} }
return false; }
} return false;
}
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
function parent($id) { return $this->_get_field('parent', $id); } function parent($id) { return $this->_get_field('parent', $id); }
function previous($id) { return $this->_get_field('previous', $id); } function previous($id) { return $this->_get_field('previous', $id); }
function next($id) { return $this->_get_field('next', $id); } function next($id) { return $this->_get_field('next', $id); }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
function valid($id) { function valid($id) {
$id = $this->_ensure_numeric_category($id); $keys = array();
if (isset($this->_structure[$id])) { foreach ($this->_ensure_category_ids($id) as $id) {
return array_keys($this->_structure[$id]); if (isset($this->_structure[$id])) {
} $keys = array_merge($keys, array_keys($this->_structure[$id]));
return false; }
} }
return empty($keys) ? false : $keys;
}
function all_adjacent($id, $direction) { function all_adjacent($id, $direction) {
if (isset($this->_structure[$id])) { if (isset($this->_structure[$id])) {
$all_adjacent = array(); $all_adjacent = array();
do { do {
$has_adjacent = false; $has_adjacent = false;
if (isset($this->_structure[$id][$direction])) { if (isset($this->_structure[$id][$direction])) {
$new_id = $this->_structure[$id][$direction]; $new_id = $this->_structure[$id][$direction];
if (!in_array($new_id, $all_adjacent)) { if (!in_array($new_id, $all_adjacent)) {
if ($has_adjacent = isset($this->_structure[$id][$direction])) { if ($has_adjacent = isset($this->_structure[$id][$direction])) {
$all_adjacent[] = $new_id; $all_adjacent[] = $new_id;
$id = $new_id; $id = $new_id;
} }
} }
} }
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
} while ($has_adjacent); } while ($has_adjacent);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
return $all_adjacent; return $all_adjacent;
} }
return false; return false;
} }
/** /**
* Get the valid navigation directions for a particular post. * Get the valid navigation directions for a particular post.
*/ */
function get_valid_nav($post_id) { function get_valid_nav($post_id) {
if (($category = $this->get_valid_post_category($post_id)) !== false) { if (($category = $this->get_valid_post_category($post_id)) !== false) {
return $this->valid($category); return $this->valid($category);
} }
return false; return false;
} }
/** /**
* Get the valid comic category for this post. * Get the valid comic category for this post.
*/ */
function get_valid_post_category($post_id) { function get_valid_post_category($post_id) {
$result = false; $result = false;
foreach (wp_get_post_categories($post_id) as $category) { foreach (wp_get_post_categories($post_id) as $category) {
if ($this->valid($category)) { if ($this->valid($category)) {
if ($result) { return false; } if ($result) { return false; }
$result = $category; $result = $category;
} }
} }
return $result; return $result;
} }
/** /**
* Get a simple storyline. * Get a simple storyline.
*/ */
function get_simple_storyline() { function get_simple_storyline() {
$simple_storyline = array('0' => array()); $simple_storyline = array('0' => array());
foreach ($this->_structure as $category_id => $adjacents) { foreach ($this->_structure as $category_id => $adjacents) {
$parent = 0; $parent = 0;
if (isset($adjacents['parent'])) { $parent = $adjacents['parent']; } if (isset($adjacents['parent'])) { $parent = $adjacents['parent']; }
@ -236,9 +245,9 @@ class ComicPressStoryline {
return $this->_merge_simple_storyline($simple_storyline); return $this->_merge_simple_storyline($simple_storyline);
} }
/** /**
* Get a simple structure. * Get a simple structure.
*/ */
function get_category_simple_structure($parent = null) { function get_category_simple_structure($parent = null) {
$structure = array(); $structure = array();
foreach (get_all_category_ids() as $category_id) { foreach (get_all_category_ids() as $category_id) {
@ -249,28 +258,28 @@ class ComicPressStoryline {
$structure[$category->parent][$category_id] = true; $structure[$category->parent][$category_id] = true;
} }
$structure = $this->_merge_simple_storyline($structure); $structure = $this->_merge_simple_storyline($structure);
if (!empty($parent)) { if (!empty($parent)) {
if (isset($structure[0])) { if (isset($structure[0])) {
foreach ($structure[0] as $key => $children) { foreach ($structure[0] as $key => $children) {
if ($key != $parent) { unset($structure[0][$key]); } if ($key != $parent) { unset($structure[0][$key]); }
} }
} }
} }
return $structure; return $structure;
} }
/** /**
* Get a flattened category node list. * Get a flattened category node list.
*/ */
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
function get_category_flattened($parent = null) { function get_category_flattened($parent = null) {
return $this->flatten_simple_storyline($this->get_category_simple_structure($parent)); return $this->flatten_simple_storyline($this->get_category_simple_structure($parent));
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
/** /**
* Merge a flat simple storyline into a tree. * Merge a flat simple storyline into a tree.
*/ */
function _merge_simple_storyline($simple_storyline) { function _merge_simple_storyline($simple_storyline) {
while (count($simple_storyline) > 0) { while (count($simple_storyline) > 0) {
$merge_found = false; $merge_found = false;
@ -291,7 +300,7 @@ class ComicPressStoryline {
if ($merge_found !== false) { if ($merge_found !== false) {
foreach ($simple_storyline as $parent => $children) { foreach ($simple_storyline as $parent => $children) {
if (isset($children[$merge_found])) { if (isset($children[$merge_found])) {
$simple_storyline[$parent][$merge_found] = $simple_storyline[$merge_found]; $simple_storyline[$parent][$merge_found] = $simple_storyline[$merge_found];
unset($simple_storyline[$merge_found]); unset($simple_storyline[$merge_found]);
break; break;
} }
@ -318,13 +327,21 @@ class ComicPressStoryline {
return $result; return $result;
} }
/** /**
* Sort nodes by node count. * TODO finish this method
*/ * @return unknown_type
*/
function normalize_category_groupings() {
$comicpress = ComicPress::get_instance();
}
/**
* Sort nodes by node count.
*/
function _length_sort($parts) { function _length_sort($parts) {
$new = array(); $new = array();
foreach ($parts as $part) { foreach ($parts as $part) {
$p = explode('/', $part); $p = explode('/', $part);
if (!isset($new[count($p)])) { if (!isset($new[count($p)])) {
$new[count($p)] = array(); $new[count($p)] = array();
} }
@ -338,9 +355,9 @@ class ComicPressStoryline {
return $output; return $output;
} }
/** /**
* Normalize a flattened storyline, inserting and removing categories from the list is necessary. * Normalize a flattened storyline, inserting and removing categories from the list is necessary.
*/ */
function normalize_flattened_storyline($storyline, $comic_categories) { function normalize_flattened_storyline($storyline, $comic_categories) {
$storyline_nodes = explode(",", $storyline); $storyline_nodes = explode(",", $storyline);
$category_nodes = explode(",", $comic_categories); $category_nodes = explode(",", $comic_categories);
@ -379,16 +396,16 @@ class ComicPressStoryline {
return implode(',', $storyline_nodes); return implode(',', $storyline_nodes);
} }
/** /**
* Flatten a simple storyline. * Flatten a simple storyline.
*/ */
function flatten_simple_storyline($storyline) { function flatten_simple_storyline($storyline) {
return implode(',', $this->_follow_simple_storyline($storyline)); return implode(',', $this->_follow_simple_storyline($storyline));
} }
/** /**
* Follow the nodes of a simple storyline, creating a node list. * Follow the nodes of a simple storyline, creating a node list.
*/ */
function _follow_simple_storyline($storyline, $parent = null) { function _follow_simple_storyline($storyline, $parent = null) {
$output = array(); $output = array();
foreach ($storyline as $key => $children) { foreach ($storyline as $key => $children) {
@ -405,158 +422,184 @@ class ComicPressStoryline {
return $output; return $output;
} }
function &include_all() { function &include_all() {
$this->_category_search = array_keys($this->_structure); if (is_array($this->_structure)) {
return $this; $this->_category_search = array_keys($this->_structure);
} }
return $this;
}
function &exclude_all() { function &exclude_all() {
$this->_category_search = array(); $this->_category_search = array();
return $this; return $this;
} }
function _ensure_numeric_category($parent) { function _ensure_category_ids($provided_id) {
if (!is_numeric($parent)) { if (!is_numeric($provided_id)) {
foreach (get_all_category_ids() as $id) { if (is_string($provided_id)) {
$category = get_category($id); $comicpress = ComicPress::get_instance();
if ($category->slug == $parent) { $found = false;
$parent = $id; break; if (isset($comicpress->comicpress_options['category_groupings'])) {
} if (isset($comicpress->comicpress_options['category_groupings'][$provided_id])) {
} $provided_id = $comicpress->comicpress_options['category_groupings'][$provided_id];
} $found = true;
return $parent; }
} }
if (!$found) {
foreach (get_all_category_ids() as $id) {
$category = get_category($id);
if ($category->slug == $provided_id) {
$provided_id = $id; break;
}
}
$provided_id = array($provided_id);
}
}
} else {
$provided_id = array($provided_id);
}
if (!is_array($provided_id)) {
if (is_numeric($provided_id)) {
$provided_id = array($provided_id);
} else {
$provided_id = array();
}
}
return $provided_id;
}
function _find_children($parent) { function _find_children($parent) {
$parent = $this->_ensure_numeric_category($parent); $all_children = array();
if (is_numeric($parent)) { foreach ($this->_ensure_category_ids($parent) as $parent) {
$children = array($parent); if (is_numeric($parent)) {
do { $children = array($parent);
$found_children = false; do {
if (is_array($this->_structure)) { $found_children = false;
foreach ($this->_structure as $category_id => $info) { if (is_array($this->_structure)) {
if (!in_array($category_id, $children)) { foreach ($this->_structure as $category_id => $info) {
if (isset($info['parent'])) { if (!in_array($category_id, $children)) {
if (in_array($info['parent'], $children)) { if (isset($info['parent'])) {
$children[] = $category_id; if (in_array($info['parent'], $children)) {
$found_children = true; $children[] = $category_id;
} $found_children = true;
} }
} }
} }
} }
// @codeCoverageIgnoreStart }
} while ($found_children); // @codeCoverageIgnoreStart
// @codeCoverageIgnoreEnd } while ($found_children);
// @codeCoverageIgnoreEnd
return $children; $all_children = array_merge($all_children, $children);
} }
return false; }
} return empty($all_children) ? false : $all_children;
}
function &_include() { function &_include() {
$args = func_get_args(); $args = func_get_args();
$method = array_shift($args); $method = array_shift($args);
$this->_category_search = array_unique(array_merge($this->_category_search, call_user_func_array(array($this, $method), $args))); $this->_category_search = array_unique(array_merge($this->_category_search, call_user_func_array(array($this, $method), $args)));
sort($this->_category_search); sort($this->_category_search);
return $this; return $this;
} }
function &_exclude() { function &_exclude() {
$args = func_get_args(); $args = func_get_args();
$method = array_shift($args); $method = array_shift($args);
$this->_category_search = array_diff($this->_category_search, call_user_func_array(array($this, $method), $args)); $this->_category_search = array_diff($this->_category_search, call_user_func_array(array($this, $method), $args));
sort($this->_category_search); sort($this->_category_search);
return $this; return $this;
} }
function _find_level_or_above($level = null) { function _find_level_or_above($level = null) {
$found = array(); $found = array();
foreach ($this->_structure as $category_id => $info) { foreach ($this->_structure as $category_id => $info) {
if ($info['level'] <= $level) { $found[] = $category_id; } if ($info['level'] <= $level) { $found[] = $category_id; }
} }
return $found; return $found;
} }
function _find_only($id = null) { function _find_only($id = null) {
if (isset($this->_structure[$id])) { if (isset($this->_structure[$id])) {
return array($id); return array($id);
} }
return array(); return array();
} }
function _find_level($level = null) { function _find_level($level = null) {
$found = array(); $found = array();
foreach ($this->_structure as $category_id => $info) { foreach ($this->_structure as $category_id => $info) {
if ($info['level'] == $level) { $found[] = $category_id; } if ($info['level'] == $level) { $found[] = $category_id; }
} }
return $found; return $found;
} }
function _ensure_post_id($thing) { function _ensure_post_id($thing) {
$id = null; $id = null;
if (is_object($thing)) { if (is_object($thing)) {
if (isset($thing->ID)) { $id = $thing->ID; } if (isset($thing->ID)) { $id = $thing->ID; }
} else { } else {
if (is_numeric($thing)) { $id = $thing; } if (is_numeric($thing)) { $id = $thing; }
} }
return $id; return $id;
} }
function _find_post_category($post = null) { function _find_post_category($post = null) {
$found = array(); $found = array();
$id = $this->_ensure_post_id($post); $id = $this->_ensure_post_id($post);
if (!is_null($id)) { if (!is_null($id)) {
if (count($categories = wp_get_post_categories($id)) == 1) { if (count($categories = wp_get_post_categories($id)) == 1) {
$found = $categories; $found = $categories;
} }
} }
return $found; return $found;
} }
function _find_adjacent($category = null, $next = false) { function _find_adjacent($category = null, $next = false) {
$found = array(); $found = array();
if (!is_null($category)) { if (!is_null($category)) {
if (isset($this->_structure[$category])) { if (isset($this->_structure[$category])) {
$field = $next ? 'next' : 'previous'; $field = $next ? 'next' : 'previous';
if (isset($this->_structure[$category][$field])) { if (isset($this->_structure[$category][$field])) {
$found = array($this->_structure[$category][$field]); $found = array($this->_structure[$category][$field]);
} }
} }
} }
return $found; return $found;
} }
function _find_post_root($post = null) { function _find_post_root($post = null) {
$found = array(); $found = array();
$id = $this->_ensure_post_id($post); $id = $this->_ensure_post_id($post);
if (!is_null($id)) { if (!is_null($id)) {
if (count($categories = wp_get_post_categories($id)) == 1) { if (count($categories = wp_get_post_categories($id)) == 1) {
$comic_post = new ComicPressComicPost(get_post($id)); $comic_post = new ComicPressComicPost(get_post($id));
$parents = $comic_post->find_parents(); $parents = $comic_post->find_parents();
if (!empty($parents)) { if (!empty($parents)) {
$parents = array_keys($parents); $found = $this->_find_children(end($parents)); $parents = array_keys($parents); $found = $this->_find_children(end($parents));
} }
} }
} }
return $found; return $found;
} }
function end_search() { function end_search() {
$result = $this->_category_search; $result = $this->_category_search;
$this->_category_search = array(); $this->_category_search = array();
return $result; return $result;
} }
function build_from_restrictions($restrictions = null) { function build_from_restrictions($restrictions = null) {
global $post; global $post;
$this->read_from_options(); $this->read_from_options();
$this->exclude_all(); $this->exclude_all();
@ -582,7 +625,7 @@ class ComicPressStoryline {
list($type, $list) = $info; list($type, $list) = $info;
if (substr($type, 0, 1) == "!") { if (substr($type, 0, 1) == "!") {
$method_root = 'exclude'; $method_root = 'exclude';
$method_type = substr($type, 1); $method_type = substr($type, 1);
} else { } else {
$method_root = 'include'; $method_root = 'include';
@ -621,7 +664,7 @@ class ComicPressStoryline {
} }
return $this->end_search(); return $this->end_search();
} }
} }
?> ?>

View File

@ -32,7 +32,9 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
} }
function testGetPostNav() { function testGetPostNav() {
$dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic', 'get_first_comic', 'get_last_comic')); global $wp_query;
$dbi = $this->getMock('ComicPressDBInterface', array('get_previous_post', 'get_next_post', 'get_first_post', 'get_last_post'));
$storyline = new ComicPressStoryline(); $storyline = new ComicPressStoryline();
$storyline->set_flattened_storyline('0/1,0/1/2,0/3'); $storyline->set_flattened_storyline('0/1,0/1/2,0/3');
@ -42,33 +44,40 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
wp_set_post_categories(1, array(2)); wp_set_post_categories(1, array(2));
$dbi->expects($this->at(0))->method('get_previous_comic')->with(array(1,2,3), $post); $dbi->expects($this->at(0))->method('get_previous_post')->with(array(1,2,3), $post);
$dbi->expects($this->at(1))->method('get_next_comic')->with(array(1,2,3), $post); $dbi->expects($this->at(1))->method('get_next_post')->with(array(1,2,3), $post);
$dbi->expects($this->at(2))->method('get_first_comic')->with(array(1,2,3)); $dbi->expects($this->at(2))->method('get_first_post')->with(array(1,2,3));
$dbi->expects($this->at(3))->method('get_last_comic')->with(array(1,2,3)); $dbi->expects($this->at(3))->method('get_last_post')->with(array(1,2,3));
$dbi->expects($this->at(4))->method('get_previous_comic')->with(2, $post); $dbi->expects($this->at(4))->method('get_previous_post')->with(2, $post);
$dbi->expects($this->at(5))->method('get_next_comic')->with(2, $post); $dbi->expects($this->at(5))->method('get_next_post')->with(2, $post);
// level // level
$dbi->expects($this->at(6))->method('get_first_comic')->with(2)->will($this->returnValue((object)array('ID' => 1))); $dbi->expects($this->at(6))->method('get_first_post')->with(2)->will($this->returnValue((object)array('ID' => 1)));
// parent // parent
$dbi->expects($this->at(7))->method('get_first_comic')->with(1)->will($this->returnValue((object)array('ID' => 1))); $dbi->expects($this->at(7))->method('get_first_post')->with(1)->will($this->returnValue((object)array('ID' => 1)));
// previous // previous
$dbi->expects($this->at(8))->method('get_first_comic')->with(1)->will($this->returnValue((object)array('ID' => 1))); $dbi->expects($this->at(8))->method('get_first_post')->with(1)->will($this->returnValue((object)array('ID' => 1)));
// next // next
$dbi->expects($this->at(9))->method('get_first_comic')->with(3)->will($this->returnValue((object)array('ID' => 1))); $dbi->expects($this->at(9))->method('get_first_post')->with(3)->will($this->returnValue((object)array('ID' => 1)));
$this->nav->_dbi = $dbi; $this->nav->_dbi = $dbi;
$this->nav->_storyline = $storyline; $this->nav->_storyline = $storyline;
$this->assertFalse(wp_cache_get('navigation-1', 'comicpress')); $this->assertFalse(wp_cache_get('navigation-1', 'comicpress'));
$wp_query = (object)array(
'is_single' => true,
'in_the_loop' => true,
);
$this->nav->get_post_nav($post); $this->nav->get_post_nav($post);
$this->assertTrue(wp_cache_get('navigation-1', 'comicpress') !== false); $this->assertTrue(wp_cache_get('navigation-1', 'comicpress') !== false);
} }
function testSkipEmptyCategories() { function testSkipEmptyCategories() {
$dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic', 'get_first_comic', 'get_last_comic')); global $wp_query;
$dbi = $this->getMock('ComicPressDBInterface', array('get_previous_post', 'get_next_post', 'get_first_post', 'get_last_post'));
$storyline = new ComicPressStoryline(); $storyline = new ComicPressStoryline();
$storyline->_structure = array( $storyline->_structure = array(
@ -82,11 +91,16 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
wp_set_post_categories(1, array(1)); wp_set_post_categories(1, array(1));
$dbi->expects($this->any())->method('get_first_comic')->will($this->returnCallback(array(&$this, 'callbackTestSkipEmptyCategories'))); $dbi->expects($this->any())->method('get_first_post')->will($this->returnCallback(array(&$this, 'callbackTestSkipEmptyCategories')));
$this->nav->_dbi = $dbi; $this->nav->_dbi = $dbi;
$this->nav->_storyline = $storyline; $this->nav->_storyline = $storyline;
$wp_query = (object)array(
'is_single' => true,
'in_the_loop' => true,
);
$nav = $this->nav->get_post_nav($post); $nav = $this->nav->get_post_nav($post);
$this->assertEquals(10, $nav['storyline-chapter-next']->ID); $this->assertEquals(10, $nav['storyline-chapter-next']->ID);

View File

@ -671,23 +671,35 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_result, $this->css->_ensure_post_id($thing)); $this->assertEquals($expected_result, $this->css->_ensure_post_id($thing));
} }
function providerTestEnsureNumericCategory() { function providerTestEnsureCategoryIDs() {
return array( return array(
array(false, false), array(false, array()),
array(0, 0), array(0, array(0)),
array(1, 1), array(1, array(1)),
array('comic', 'comic'), array('blah', array('blah')),
array('test', 1) array('test', array(1)),
array('comic', array(1))
); );
} }
/** /**
* @dataProvider providerTestEnsureNumericCategory * @dataProvider providerTestEnsureCategoryIDs
*/ */
function testEnsureNumericCategory($string, $expected_id) { function testEnsureCategoryIDs($string, $expected_id) {
add_category(1, (object)array('slug' => 'test')); add_category(1, (object)array('slug' => 'test', 'parent' => 0));
add_category(2, (object)array('slug' => 'test-2', 'parent' => 1));
add_category(3, (object)array('slug' => 'my-rants', 'parent' => 0));
$comicpress = ComicPress::get_instance();
$comicpress->comicpress_options['category_groupings'] = array(
'comic' => array(1),
'blog' => array(3)
);
$this->assertEquals($expected_id, $this->css->_ensure_numeric_category($string)); $this->assertEquals($expected_id, $this->css->_ensure_category_ids($string));
}
function testNormalizeCategoryGroupings() {
$this->markTestIncomplete();
} }
} }