comicpress-core/classes/ComicPressDBInterface.inc

101 lines
2.7 KiB
PHP
Raw Normal View History

2009-10-20 01:22:00 +00:00
<?php
class ComicPressDBInterface {
2009-11-08 03:00:14 +00:00
function ComicPressDBInterface() {}
2009-11-08 01:56:49 +00:00
2009-10-20 01:22:00 +00:00
function get_instance() {
static $instance;
2009-11-08 01:56:49 +00:00
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
// @codeCoverageIgnoreStart
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-11-08 01:56:49 +00:00
function get_terminal_post($first = true, $include_categories = null) {
$this->_prepare_wp_query();
2009-11-08 01:56:49 +00:00
2009-10-20 01:22:00 +00:00
$terminal_comic_query = new WP_Query();
2009-11-08 01:56:49 +00:00
$query_parameters = array(
'showposts' => 1,
'order' => $first ? "asc" : "desc",
'status' => 'publish'
);
if (is_array($include_categories)) {
$query_parameters['category_in'] = $include_categories;
}
$terminal_comic_query->query($query_parameters);
2009-10-22 02:41:35 +00:00
$post = false;
2009-10-20 01:22:00 +00:00
if ($terminal_comic_query->have_posts()) {
2009-10-22 02:41:35 +00:00
$post = reset($terminal_comic_query->posts);
2009-10-20 01:22:00 +00:00
}
$this->_reset_wp_query();
2009-10-22 02:41:35 +00:00
return $post;
2009-10-20 01:22:00 +00:00
}
2009-11-08 01:56:49 +00:00
2009-10-20 01:22:00 +00:00
/**
* Get the first comic in a category.
*/
2009-11-08 03:00:14 +00:00
function get_first_post($include_categories = null) {
2009-11-08 01:56:49 +00:00
return $this->get_terminal_post(true, $include_categories);
2009-10-20 01:22:00 +00:00
}
2009-11-08 01:56:49 +00:00
2009-10-20 01:22:00 +00:00
/**
* Get the last comic in a category.
*/
2009-11-08 03:00:14 +00:00
function get_last_post($include_categories = null) {
2009-11-08 01:56:49 +00:00
return $this->get_terminal_post(false, $include_categories);
2009-10-20 01:22:00 +00:00
}
/**
* 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
*/
2009-11-08 03:00:14 +00:00
function get_adjacent_post($categories = array(), $next = false, $override_post = null) {
global $post;
$this->_prepare_wp_query();
if (!is_null($override_post)) { $temp_post = $post; $post = $override_post; }
2009-11-08 01:56:49 +00:00
2009-11-08 03:00:14 +00:00
$result = get_adjacent_post(false, implode(" and ", array_diff(get_all_category_ids(), $categories)), !$next);
2009-10-20 01:22:00 +00:00
$this->_reset_wp_query();
if (!is_null($override_post)) { $post = $temp_post; }
2009-10-20 01:22:00 +00:00
return empty($result) ? false : $result;
}
function _prepare_wp_query() {
global $wp_query;
$this->is_single = $wp_query->is_single;
$this->in_the_loop = $wp_query->in_the_loop;
$wp_query->is_single = $wp_query->in_the_loop = true;
}
function _reset_wp_query() {
global $wp_query;
$wp_query->is_single = $this->is_single;
$wp_query->in_the_loop = $this->in_the_loop;
}
2009-11-08 01:56:49 +00:00
2009-10-20 01:22:00 +00:00
/**
* Get the previous comic from the current one.
*/
2009-11-08 03:00:14 +00:00
function get_previous_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, false, $override_post); }
2009-10-20 01:22:00 +00:00
/**
* Get the next comic from the current one.
*/
2009-11-08 03:00:14 +00:00
function get_next_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, true, $override_post); }
2009-10-20 01:22:00 +00:00
}
// @codeCoverageIngoreEnd