fix up more storyline issues
This commit is contained in:
parent
1cafcc9e3b
commit
96eb1e0695
|
@ -1,8 +1,6 @@
|
|||
<?php
|
||||
|
||||
class ComicPressDBInterface {
|
||||
var $_non_comic_categories, $_all_categories;
|
||||
|
||||
function ComicPressDBInterface() {}
|
||||
|
||||
function get_instance() {
|
||||
|
@ -12,34 +10,28 @@ class ComicPressDBInterface {
|
|||
return $instance;
|
||||
}
|
||||
|
||||
function _get_categories() { return get_categories("hide_empty=0"); }
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
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);
|
||||
function _get_categories_to_exclude($categories = null) {
|
||||
if (is_array($categories)) {
|
||||
return array_diff(get_all_category_ids(), $categories);
|
||||
} else {
|
||||
return $this->_non_comic_categories;
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the terminal post in a specific category.
|
||||
*/
|
||||
function get_terminal_post_in_category($category_id, $first = true) {
|
||||
function get_terminal_post_in_categories($categories, $first = true) {
|
||||
$this->_prepare_wp_query();
|
||||
|
||||
$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");
|
||||
$terminal_comic_query->query(array(
|
||||
'showposts' => 1,
|
||||
'order' => $sort_order,
|
||||
'category__in' => $categories,
|
||||
'status' => 'publish'
|
||||
));
|
||||
$post = false;
|
||||
if ($terminal_comic_query->have_posts()) {
|
||||
$post = reset($terminal_comic_query->posts);
|
||||
|
@ -52,28 +44,28 @@ class ComicPressDBInterface {
|
|||
/**
|
||||
* Get the first comic in a category.
|
||||
*/
|
||||
function get_first_comic($category_id) {
|
||||
return $this->get_terminal_post_in_category($category_id);
|
||||
function get_first_post($categories) {
|
||||
return $this->get_terminal_post_in_categories($categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last comic in a category.
|
||||
*/
|
||||
function get_last_comic($category_id) {
|
||||
return $this->get_terminal_post_in_category($category_id, false);
|
||||
function get_last_post($categories) {
|
||||
return $this->get_terminal_post_in_categories($categories, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
function get_adjacent_post($categories, $next = false, $override_post = null) {
|
||||
global $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 ", $this->_get_categories_to_exclude($categories)), !$next);
|
||||
|
||||
$this->_reset_wp_query();
|
||||
if (!is_null($override_post)) { $post = $temp_post; }
|
||||
|
@ -100,12 +92,12 @@ class ComicPressDBInterface {
|
|||
/**
|
||||
* 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); }
|
||||
function get_previous_post($categories = null, $override_post = null) { return $this->get_adjacent_post($categories, false, $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); }
|
||||
function get_next_post($categories = null, $override_post = null) { return $this->get_adjacent_post($categories, true, $override_post); }
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -129,7 +129,9 @@ function R($which, $restrictions = null, $override_post = null) {
|
|||
|
||||
$storyline = new ComicPressStoryline();
|
||||
|
||||
$categories = $storyline->build_from_restrictions(__prep_R($restrictions));
|
||||
$restrictions = __prep_R($restrictions, $post_to_use);
|
||||
|
||||
$categories = $storyline->build_from_restrictions($restrictions);
|
||||
|
||||
$dbi = ComicPressDBInterface::get_instance();
|
||||
|
||||
|
|
32
single.php
32
single.php
|
@ -2,31 +2,31 @@
|
|||
$storyline = new ComicPressStoryline();
|
||||
$storyline->read_from_options();
|
||||
|
||||
the_title(); echo '<br />';
|
||||
echo 'Current: '; the_title(); echo '<br />';
|
||||
|
||||
Protect();
|
||||
|
||||
RT('first', 'from_post'); the_title(); echo '<br />';
|
||||
RT('previous', 'from_post'); the_title(); echo '<br />';
|
||||
RT('previous', array('root_of' => '__post')); the_title(); echo '<br />';
|
||||
RT('previous'); the_title(); echo '<br />';
|
||||
Restore(); the_title(); echo '<br />';
|
||||
echo 'First in category: '; RT('first', 'from_post'); the_title(); echo '<br />';
|
||||
echo 'Previous in category: '; RT('previous', 'from_post'); the_title(); echo '<br />';
|
||||
echo 'Previous in root category: '; RT('previous', array('root_of' => '__post')); the_title(); echo '<br />';
|
||||
echo 'Chronologically previous: '; RT('previous'); the_title(); echo '<br />';
|
||||
echo 'Current: '; Restore(); the_title(); echo '<br />';
|
||||
|
||||
foreach (M() as $image) {
|
||||
echo $image->embed();
|
||||
echo $image->embed('comic');
|
||||
echo $image->embed('rss');
|
||||
echo $image->embed('archive');
|
||||
echo 'Default: '; echo $image->embed();
|
||||
echo 'Comic: '; echo $image->embed('comic');
|
||||
echo 'RSS: '; echo $image->embed('rss');
|
||||
echo 'Archive: '; echo $image->embed('archive');
|
||||
}
|
||||
|
||||
RT('next'); the_title(); echo '<br />';
|
||||
RT('next', array('root_of' => '__post')); the_title(); echo '<br />';
|
||||
RT('next', 'from_post'); the_title(); echo '<br />';
|
||||
RT('last', 'from_post'); the_title(); echo '<br />';
|
||||
echo 'Chronologically next: '; RT('next'); the_title(); echo '<br />';
|
||||
echo 'Next in root category: '; RT('next', array('root_of' => '__post')); the_title(); echo '<br />';
|
||||
echo 'Next in category: '; RT('next', 'from_post'); the_title(); echo '<br />';
|
||||
echo 'Last in category: '; RT('last', 'from_post'); the_title(); echo '<br />';
|
||||
|
||||
Unprotect();
|
||||
|
||||
the_title(); echo '<br />';
|
||||
echo 'Current: '; the_title(); echo '<br />';
|
||||
|
||||
finish_comicpress();
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -16,4 +16,4 @@ class ComicPressDBInterfaceTest extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue