From cab85e5f6064bd1940ac0eaa239b958c672c66b0 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 7 Nov 2009 22:42:09 -0500 Subject: [PATCH] RT() function pretty much working --- classes/ComicPressStoryline.inc | 10 +++++++--- functions.php | 16 ++++++++++++++++ single.php | 9 +++++++-- test/ComicPressStorylineTest.php | 4 ++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index 3ea2d4e..17f6cf2 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -499,8 +499,9 @@ class ComicPressStoryline { $comic_post = new ComicPressComicPost(get_post($id)); $parents = $comic_post->find_parents(); if (!empty($parents)) { - $parents = array_keys($parents); $found[] = end($parents); + $parents = array_keys($parents); $found = $this->_find_children(end($parents)); } + } } return $found; @@ -534,11 +535,14 @@ class ComicPressStoryline { $method_type = $type; } - foreach ((array)$list as $restriction) { + if (!is_array($list)) { $list = array($list); } + + foreach ($list as $restriction) { $method = ''; $args = array($restriction); switch ($method_type) { case 'child_of': $method = 'children'; break; + case 'root_of': $method = 'post_root'; break; case 'from_post': $method = 'post_category'; break; case 'previous': $method = 'adjacent'; @@ -555,7 +559,7 @@ class ComicPressStoryline { array_unshift($args, "_find_${method}"); call_user_func_array(array($this, "_${method_root}"), $args); } - } + } } } else { $this->include_all(); diff --git a/functions.php b/functions.php index 240ce5e..b6d07c4 100644 --- a/functions.php +++ b/functions.php @@ -97,6 +97,22 @@ function R($which, $restrictions = null, $override_post = null) { } } + if (is_array($restrictions)) { + $new_restrictions = array(); + foreach ($restrictions as $type => $list) { + if (is_string($list)) { + $value = $list; + switch ($list) { + case '__post': $value = $post_to_use; break; + } + $new_restrictions[$type] = $value; + } else { + $new_restrictions[$type] = $list; + } + } + $restrictions = $new_restrictions; + } + $categories = $storyline->build_from_restrictions($restrictions); $dbi = ComicPressDBInterface::get_instance(); diff --git a/single.php b/single.php index 7e108cc..bab1e6c 100644 --- a/single.php +++ b/single.php @@ -1,13 +1,18 @@ read_from_options(); + the_title(); echo '
'; Protect(); RT('first', 'from_post'); the_title(); echo '
'; RT('previous', 'from_post'); the_title(); echo '
'; - RT('previous'); the_title(); echo '
'; + RT('previous', array('root_of' => '__post')); the_title(); echo '
'; + RT('previous'); the_title(); echo '
'; Restore(); the_title(); echo '
'; - RT('next', array('child_of' => 'amoc')); the_title(); echo '
'; + RT('next'); the_title(); echo '
'; + RT('next', array('root_of' => '__post')); the_title(); echo '
'; RT('next', 'from_post'); the_title(); echo '
'; RT('last', 'from_post'); the_title(); echo '
'; diff --git a/test/ComicPressStorylineTest.php b/test/ComicPressStorylineTest.php index 739be69..805ffc6 100644 --- a/test/ComicPressStorylineTest.php +++ b/test/ComicPressStorylineTest.php @@ -476,8 +476,8 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase { function providerTestFindPostRoot() { return array( - array(array(1), array(1)), - array(array(4), array(1)), + array(array(1), array(1,2,3,4)), + array(array(4), array(1,2,3,4)), array(array(5), array(5)), array(array(1, 5), array()), );