working on storyline
This commit is contained in:
parent
364c1479a2
commit
d67cc49199
|
@ -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
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
class ComicPressDBInterface {
|
||||
var $is_single, $in_the_loop;
|
||||
function ComicPressDBInterface() {}
|
||||
|
||||
function get_instance() {
|
||||
|
@ -11,6 +12,7 @@ class ComicPressDBInterface {
|
|||
}
|
||||
|
||||
function _get_categories_to_exclude($categories = null) {
|
||||
if (is_numeric($categories)) { $categories = array($categories); }
|
||||
if (is_array($categories)) {
|
||||
return array_values(array_diff(get_all_category_ids(), $categories));
|
||||
} else {
|
||||
|
@ -42,6 +44,8 @@ class ComicPressDBInterface {
|
|||
function get_terminal_post_in_categories($categories, $first = true) {
|
||||
$this->_prepare_wp_query();
|
||||
|
||||
if (!is_array($categories)) { $categories = array($categories); }
|
||||
|
||||
$sort_order = $first ? "asc" : "desc";
|
||||
$terminal_comic_query = new WP_Query();
|
||||
$terminal_comic_query->query(array(
|
||||
|
|
|
@ -28,18 +28,18 @@ class ComicPressNavigation {
|
|||
|
||||
// global previous/next
|
||||
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
|
||||
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)) {
|
||||
// storyline previous/next
|
||||
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
|
||||
|
@ -47,7 +47,7 @@ class ComicPressNavigation {
|
|||
foreach ($valid as $field) {
|
||||
$all_adjacents = $this->_storyline->all_adjacent($category, $field);
|
||||
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)) {
|
||||
$nav["storyline-chapter-${field}"] = $result; break;
|
||||
}
|
||||
|
|
|
@ -15,10 +15,14 @@ class ComicPressStoryline {
|
|||
* Get the flattened storyline from options.
|
||||
*/
|
||||
function get_flattened_storyline() {
|
||||
if (class_exists('ComicPress')) {
|
||||
$comicpress = &ComicPress::get_instance();
|
||||
if (isset($comicpress->comicpress_options['storyline_order'])) {
|
||||
return $comicpress->comicpress_options['storyline_order'];
|
||||
}
|
||||
} else {
|
||||
return get_option("comicpress-storyline-category-order");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,10 +30,12 @@ class ComicPressStoryline {
|
|||
* Set the global storyline as a flattened storyline.
|
||||
*/
|
||||
function set_flattened_storyline($storyline) {
|
||||
if (class_exists('ComicPress')) {
|
||||
$comicpress = &ComicPress::get_instance();
|
||||
$comicpress->comicpress_options['storyline_order'] = $storyline;
|
||||
$comicpress->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the order from a flattened storyline.
|
||||
|
@ -145,13 +151,14 @@ class ComicPressStoryline {
|
|||
|
||||
function _get_field($field, $id) {
|
||||
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][$field])) {
|
||||
return $this->_structure[$id][$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -162,11 +169,13 @@ class ComicPressStoryline {
|
|||
// @codeCoverageIgnoreEnd
|
||||
|
||||
function valid($id) {
|
||||
$id = $this->_ensure_numeric_category($id);
|
||||
$keys = array();
|
||||
foreach ($this->_ensure_category_ids($id) as $id) {
|
||||
if (isset($this->_structure[$id])) {
|
||||
return array_keys($this->_structure[$id]);
|
||||
$keys = array_merge($keys, array_keys($this->_structure[$id]));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return empty($keys) ? false : $keys;
|
||||
}
|
||||
|
||||
function all_adjacent($id, $direction) {
|
||||
|
@ -318,6 +327,14 @@ class ComicPressStoryline {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO finish this method
|
||||
* @return unknown_type
|
||||
*/
|
||||
function normalize_category_groupings() {
|
||||
$comicpress = ComicPress::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort nodes by node count.
|
||||
*/
|
||||
|
@ -406,7 +423,9 @@ class ComicPressStoryline {
|
|||
}
|
||||
|
||||
function &include_all() {
|
||||
if (is_array($this->_structure)) {
|
||||
$this->_category_search = array_keys($this->_structure);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -415,20 +434,43 @@ class ComicPressStoryline {
|
|||
return $this;
|
||||
}
|
||||
|
||||
function _ensure_numeric_category($parent) {
|
||||
if (!is_numeric($parent)) {
|
||||
function _ensure_category_ids($provided_id) {
|
||||
if (!is_numeric($provided_id)) {
|
||||
if (is_string($provided_id)) {
|
||||
$comicpress = ComicPress::get_instance();
|
||||
$found = false;
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
foreach (get_all_category_ids() as $id) {
|
||||
$category = get_category($id);
|
||||
if ($category->slug == $parent) {
|
||||
$parent = $id; break;
|
||||
if ($category->slug == $provided_id) {
|
||||
$provided_id = $id; break;
|
||||
}
|
||||
}
|
||||
$provided_id = array($provided_id);
|
||||
}
|
||||
return $parent;
|
||||
}
|
||||
} 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) {
|
||||
$parent = $this->_ensure_numeric_category($parent);
|
||||
$all_children = array();
|
||||
foreach ($this->_ensure_category_ids($parent) as $parent) {
|
||||
if (is_numeric($parent)) {
|
||||
$children = array($parent);
|
||||
do {
|
||||
|
@ -449,9 +491,10 @@ class ComicPressStoryline {
|
|||
} while ($found_children);
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $children;
|
||||
$all_children = array_merge($all_children, $children);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return empty($all_children) ? false : $all_children;
|
||||
}
|
||||
|
||||
function &_include() {
|
||||
|
|
|
@ -32,7 +32,9 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
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->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));
|
||||
|
||||
$dbi->expects($this->at(0))->method('get_previous_comic')->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(2))->method('get_first_comic')->with(array(1,2,3));
|
||||
$dbi->expects($this->at(3))->method('get_last_comic')->with(array(1,2,3));
|
||||
$dbi->expects($this->at(4))->method('get_previous_comic')->with(2, $post);
|
||||
$dbi->expects($this->at(5))->method('get_next_comic')->with(2, $post);
|
||||
$dbi->expects($this->at(0))->method('get_previous_post')->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_post')->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_post')->with(2, $post);
|
||||
$dbi->expects($this->at(5))->method('get_next_post')->with(2, $post);
|
||||
// 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
|
||||
$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
|
||||
$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
|
||||
$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->_storyline = $storyline;
|
||||
|
||||
$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->assertTrue(wp_cache_get('navigation-1', 'comicpress') !== false);
|
||||
}
|
||||
|
||||
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->_structure = array(
|
||||
|
@ -82,11 +91,16 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
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->_storyline = $storyline;
|
||||
|
||||
$wp_query = (object)array(
|
||||
'is_single' => true,
|
||||
'in_the_loop' => true,
|
||||
);
|
||||
|
||||
$nav = $this->nav->get_post_nav($post);
|
||||
|
||||
$this->assertEquals(10, $nav['storyline-chapter-next']->ID);
|
||||
|
|
|
@ -671,23 +671,35 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals($expected_result, $this->css->_ensure_post_id($thing));
|
||||
}
|
||||
|
||||
function providerTestEnsureNumericCategory() {
|
||||
function providerTestEnsureCategoryIDs() {
|
||||
return array(
|
||||
array(false, false),
|
||||
array(0, 0),
|
||||
array(1, 1),
|
||||
array('comic', 'comic'),
|
||||
array('test', 1)
|
||||
array(false, array()),
|
||||
array(0, array(0)),
|
||||
array(1, array(1)),
|
||||
array('blah', array('blah')),
|
||||
array('test', array(1)),
|
||||
array('comic', array(1))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestEnsureNumericCategory
|
||||
* @dataProvider providerTestEnsureCategoryIDs
|
||||
*/
|
||||
function testEnsureNumericCategory($string, $expected_id) {
|
||||
add_category(1, (object)array('slug' => 'test'));
|
||||
function testEnsureCategoryIDs($string, $expected_id) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue