comicpress-core/classes/ComicPressDBInterface.inc

92 lines
2.7 KiB
PHP
Raw Normal View History

2009-10-20 01:22:00 +00:00
<?php
class ComicPressDBInterface {
var $_non_comic_categories, $_all_categories;
function ComicPressDBInterface() {}
function get_instance() {
static $instance;
2009-10-20 02:20:25 +00:00
if (!isset($instance)) { $instance = new ComicPressDBInterface(); }
2009-10-20 01:22:00 +00:00
return $instance;
}
2009-10-20 01:41:55 +00:00
2009-10-20 02:20:25 +00:00
function _get_categories() { return get_categories("hide_empty=0"); }
2009-10-20 01:41:55 +00:00
2009-10-20 02:20:25 +00:00
/**
* Set the comic categories for the current run of ComicPress.
*/
2009-10-20 01:22:00 +00:00
function set_comic_categories($categories) {
$this->_all_categories = get_all_category_ids();
2009-10-20 01:41:55 +00:00
$this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories));
2009-10-20 01:22:00 +00:00
}
2009-10-20 02:20:25 +00:00
function _get_categories_to_exclude($category = null) {
return (is_null($category)) ? $this->_non_comic_categories : array_values(array_diff($this->_all_categories, array($category)));
}
2009-10-20 01:22:00 +00:00
/**
* Find the terminal post in a specific category.
*/
function get_terminal_post_in_category($category_id, $first = true) {
$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");
if ($terminal_comic_query->have_posts()) {
return reset($terminal_comic_query->posts);
}
return false;
}
/**
* Get the first comic in a category.
*/
function get_first_comic($category_id) {
return $this->get_terminal_post_in_category($category_id);
}
/**
* Get the last comic in a category.
*/
function get_last_comic($category_id) {
return $this->get_terminal_post_in_category($category_id, false);
}
/**
* Get the comic post adjacent to the current comic.
* Wrapper around get_adjacent_post(). Don't unit test this method.
2009-10-20 01:22:00 +00:00
*/
function get_adjacent_comic($category, $next = false, $override_post = null) {
global $wp_query, $post;
$temp_single = $wp_query->is_single;
2009-10-20 01:22:00 +00:00
$wp_query->is_single = true;
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);
2009-10-20 01:22:00 +00:00
$wp_query->is_single = $temp_single;
2009-10-20 01:22:00 +00:00
if (!is_null($override_post)) {
$post = $temp_post;
}
return empty($result) ? false : $result;
}
/**
* 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); }
/**
* 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); }
}
?>