2009-10-18 21:59:40 +00:00
|
|
|
<?php
|
|
|
|
|
2009-10-20 11:22:34 +00:00
|
|
|
require_once('ComicPressStoryline.inc');
|
|
|
|
require_once('ComicPressDBInterface.inc');
|
|
|
|
|
2009-10-18 21:59:40 +00:00
|
|
|
class ComicPressNavigation {
|
2009-11-11 13:46:26 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2009-10-20 11:22:34 +00:00
|
|
|
function init($storyline) {
|
|
|
|
$this->_storyline = $storyline;
|
|
|
|
$this->_dbi = ComicPressDBInterface::get_instance();
|
|
|
|
}
|
2009-11-11 13:46:26 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2009-10-20 11:22:34 +00:00
|
|
|
|
2009-11-21 14:56:31 +00:00
|
|
|
function get_post_nav($post, $restrictions = null) {
|
2009-10-20 11:22:34 +00:00
|
|
|
$nav = array();
|
2009-11-07 16:52:01 +00:00
|
|
|
if (is_object($post)) {
|
|
|
|
if (isset($post->ID)) {
|
|
|
|
$cache_key = 'navigation-' . $post->ID;
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
if (($result = wp_cache_get($cache_key, 'comicpress')) !== false) {
|
|
|
|
foreach ($result as $key => $post_id) {
|
2009-11-12 02:07:35 +00:00
|
|
|
$nav[$key] = get_post($post_id);
|
2009-11-07 16:52:01 +00:00
|
|
|
}
|
2009-11-12 02:07:35 +00:00
|
|
|
return $nav;
|
2009-11-07 16:52:01 +00:00
|
|
|
}
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-21 14:56:31 +00:00
|
|
|
$categories = $this->_storyline->build_from_restrictions($restrictions);
|
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
// global previous/next
|
|
|
|
foreach (array('previous', 'next') as $field) {
|
2009-11-21 14:56:31 +00:00
|
|
|
$nav[$field] = $this->_dbi->{"get_${field}_comic"}($categories, $post);
|
2009-11-07 16:52:01 +00:00
|
|
|
}
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
// global first/last
|
|
|
|
foreach (array('first', 'last') as $field) {
|
2009-11-21 14:56:31 +00:00
|
|
|
$nav[$field] = $this->_dbi->{"get_${field}_comic"}($categories);
|
2009-11-07 16:52:01 +00:00
|
|
|
}
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
if ($category = $this->_storyline->get_valid_post_category($post->ID)) {
|
|
|
|
// storyline previous/next
|
|
|
|
foreach (array('previous', 'next') as $field) {
|
|
|
|
$nav["storyline-${field}"] = $this->_dbi->{"get_${field}_comic"}($category, $post);
|
|
|
|
}
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
// adjacent storyline nodes
|
|
|
|
if (is_array($valid = $this->_storyline->valid($category))) {
|
|
|
|
foreach ($valid as $field) {
|
2009-11-10 02:12:42 +00:00
|
|
|
$all_adjacents = $this->_storyline->all_adjacent($category, $field);
|
|
|
|
foreach ($all_adjacents as $adjacent_category) {
|
|
|
|
$result = $this->_dbi->get_first_comic($adjacent_category);
|
|
|
|
if (!empty($result)) {
|
|
|
|
$nav["storyline-chapter-${field}"] = $result; break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-07 16:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
$cache_data = array();
|
|
|
|
foreach ($nav as $key => $output_post) {
|
|
|
|
if (!empty($output_post)) { $cache_data[$key] = $output_post->ID; }
|
|
|
|
}
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
wp_cache_set($cache_key, $cache_data, 'comicpress');
|
2009-11-10 02:12:42 +00:00
|
|
|
|
2009-11-07 16:52:01 +00:00
|
|
|
return $nav;
|
|
|
|
}
|
|
|
|
}
|
2009-11-11 13:46:26 +00:00
|
|
|
return false;
|
2009-10-20 11:22:34 +00:00
|
|
|
}
|
2009-10-18 21:59:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-21 14:56:31 +00:00
|
|
|
?>
|