start removing template tags

This commit is contained in:
John Bintz 2010-02-02 21:31:17 -05:00
parent 8e3108f1f9
commit 4db64182ea
2 changed files with 0 additions and 199 deletions

View File

@ -5,10 +5,6 @@ foreach (array(
'Protect' => 0, 'Protect' => 0,
'Restore' => 0, 'Restore' => 0,
'Unprotect' => 0, 'Unprotect' => 0,
'R' => 3,
'RT' => 3,
'RL' => 2,
'In_R' => 2,
'M' => 1, 'M' => 1,
'EM' => 3, 'EM' => 3,
'SL' => 1, 'SL' => 1,
@ -70,143 +66,6 @@ function Unprotect() {
$__post = $__wp_query = null; $__post = $__wp_query = null;
} }
/**
* Prepare the restrictions for R functions.
* This does some pre-processing before the R functions send the restrictions off to get_${which}_post.
* @param array $restrictions The restrictions to use to find categories.
* @param object $override_post The post to use for restrictions that reference a post automatically.
* @return array The list of restrictions to use.
*/
function __prep_R($restrictions, $post_to_use) {
if (is_string($restrictions)) {
switch ($restrictions) {
case 'from_post':
$restrictions = array('from_post' => $post_to_use);
break;
default:
foreach (get_all_category_ids() as $id) {
$category = get_category($id);
if (strtolower($category->slug) == strtolower($restrictions)) {
$restrictions = array('child_of' => $category->slug);
break;
}
}
}
}
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;
}
return $restrictions;
}
// @codeCoverageIgnoreStart
/**
* Find a post relative to the provided post.
* @param string $which The relative direction to search. Choices: first, last, next, previous
* @param array $restrictions The restrictions to use to find categories.
* @param object $override_post The post to check. If not provided, use the Loop post saved by Protect().
* @return object|false The found post, or false if not found.
*/
function R($which, $restrictions = null, $override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$categories = RL($restrictions, $post_to_use);
$dbi = ComicPressDBInterface::get_instance();
$new_post = false;
switch ($which) {
case 'first': $new_post = $dbi->get_first_post($categories); break;
case 'last': $new_post = $dbi->get_last_post($categories); break;
case 'next': $new_post = $dbi->get_next_post($categories, $post_to_use); break;
case 'previous': $new_post = $dbi->get_previous_post($categories, $post_to_use); break;
}
return $new_post;
}
/**
* Find a post relative to the provided post and, if found, force the Loop to use this post for template tags.
* @param string $which The relative direction to search. Choices: first, last, next, previous
* @param array $restrictions The restrictions to use to find categories.
* @param object $override_post The post to check. If not provided, use the Loop post saved by Protect().
* @return object|false The found post that is now being used for template tags, or false if not found.
*/
function RT($which, $restrictions = null, $override_post = null) {
global $post, $__post;
if (!empty($override_post)) {
$post_to_use = $override_post;
} else {
$post_to_use = (!empty($__post)) ? $__post : $post;
}
$post = false;
if (($new_post = R($which, $restrictions, $post_to_use)) !== false) {
$post = $new_post;
setup_postdata($post);
}
return $post;
}
// @codeCoverageIgnoreEnd
/**
* Get the list of categories that match the provided restrictions.
* @param array $restrictions The restrictions to use to find categories.
* @param object $override_post The post to check. If not provided, use the current Loop post.
* @return array The list of categories that match the provided restrictions.
*/
function RL($restrictions = null, $override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$storyline = new ComicPressStoryline();
$restrictions = __prep_R($restrictions, $post_to_use);
return $storyline->build_from_restrictions($restrictions);
}
/**
* Check if the provided post is in any of the categories matched by the restrictions.
* @param array $restrictions The restrictions to use to find categories.
* @param object $override_post The post to check. If not provided, use the current Loop post.
* @return boolean True if the post is in the list of categories matched by the restrictions.
*/
function In_R($restrictions = null, $override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$post_categories = wp_get_post_categories($post_to_use->ID);
if (is_array($post_categories)) {
if (count($post_categories) == 1) {
$category_id = reset($post_categories);
if (is_numeric($category_id)) {
return in_array($category_id, RL($restrictions, $post_to_use));
}
}
}
return false;
}
/** /**
* Retrieve post attachment info to be used with EM(). * Retrieve post attachment info to be used with EM().
* @param object $override_post The post to retrieve attachment info for. If not provided, use the current Loop post. * @param object $override_post The post to retrieve attachment info for. If not provided, use the current Loop post.

View File

@ -100,40 +100,6 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(is_null($__wp_query)); $this->assertTrue(is_null($__wp_query));
} }
function providerTestPrepR() {
$post = (object)array('ID' => 1);
return array(
array(
array(), array()
),
array(
'from_post', array('from_post' => $post)
),
array(
array('test' => 'test'), array('test' => 'test')
),
array(
array('test' => '__post'), array('test' => $post)
),
array(
array('test' => array('test')), array('test' => array('test'))
),
array(
'my-category', array('child_of' => 'my-category')
)
);
}
/**
* @dataProvider providerTestPrepR
*/
function testPrepR($restrictions, $expected_result) {
add_category(1, (object)array('slug' => 'my-category'));
$this->assertEquals($expected_result, __prep_R($restrictions, (object)array('ID' => 1)));
}
function providerTestEM() { function providerTestEM() {
return array( return array(
array(array(), 'embed', 'default', false, false), array(array(), 'embed', 'default', false, false),
@ -235,30 +201,6 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
} }
} }
function providerTestIn_R() {
return array(
array(array(1), true),
array(array(5), false),
array(array(1,5), false),
array(array('test'), false)
);
}
/**
* @dataProvider providerTestIn_R
*/
function testIn_R($categories, $expected_result) {
global $post;
$post = (object)array('ID' => 1);
wp_set_post_categories(1, $categories);
$s = new ComicPressStoryline();
$s->set_flattened_storyline('0/1,0/2,0/2/3,0/2/4');
$this->assertEquals($expected_result, In_R());
}
function providerTestF() { function providerTestF() {
return array( return array(
array(null, array(1 => 'one')), array(null, array(1 => 'one')),