more category and storyline modifications
This commit is contained in:
parent
4815766fe4
commit
7b1e8b7348
@ -57,6 +57,8 @@ class ComicPress {
|
||||
$this->sort_comic_categories();
|
||||
|
||||
add_action('wp_head', array(&$this, 'wp_head'));
|
||||
add_filter('comicpress_nav', array(&$this, 'comicpress_nav'), 10, 2);
|
||||
add_filter('comicpress_nav_fields', array(&$this, 'comicpress_nav_fields'));
|
||||
|
||||
if (current_user_can('edit_themes')) {
|
||||
if (!empty($this->comicpress_options['helpers'])) {
|
||||
@ -77,6 +79,29 @@ class ComicPress {
|
||||
function is_multicomic() {
|
||||
return $this->comicpress_options['category_usage'] == "multicomic";
|
||||
}
|
||||
|
||||
function comicpress_nav($type, $content) {
|
||||
return $type;
|
||||
}
|
||||
|
||||
function comicpress_nav_fields($nav_fields) {
|
||||
$nav_fields = array(
|
||||
'first' => '‹‹ ' . __('First', 'comicpress'),
|
||||
'previous' => '‹ ' . __('Previous', 'comicpress'),
|
||||
'next' => __('Next', 'comicpress') . ' ›',
|
||||
'last' => __('Last', 'comicpress') . ' ››'
|
||||
);
|
||||
|
||||
if ($this->needs_storyline_nav()) {
|
||||
$nav_fields = array_merge(
|
||||
array('prior' => '‹‹ ' . __('Prior Storyline', 'comicpress')),
|
||||
$nav_fields,
|
||||
array('upcoming' => __('Upcoming Storyline', 'comicpress') . ' ››')
|
||||
);
|
||||
}
|
||||
|
||||
return $nav_fields;
|
||||
}
|
||||
|
||||
function wp_head() {
|
||||
foreach ($this->additional_stylesheets as $uri) { ?>
|
||||
@ -297,6 +322,40 @@ class ComicPress {
|
||||
$comic_posts['show_next'] = (!empty($comic_posts['next']) && (trim($comic_posts['last']->ID) != trim($comic_posts['next']->ID)));
|
||||
$comic_posts['show_last'] = (trim($post->ID) != trim($comic_posts['last']->ID));
|
||||
|
||||
if ($this->needs_storyline_nav()) {
|
||||
$comic_posts = array_merge($comic_posts, $this->get_storyline_nav_comics());
|
||||
}
|
||||
|
||||
return $comic_posts;
|
||||
}
|
||||
|
||||
function get_storyline_nav_comics() {
|
||||
$comic_posts = array('prior' => false, 'upcoming' => false);
|
||||
foreach ($this->get_sorted_post_categories() as $category_id) {
|
||||
$prev_next_categories = $this->get_previous_next_categories($category_id);
|
||||
|
||||
foreach ($prev_next_categories as $master_id => $cat_list) {
|
||||
foreach ($cat_list as $which => $id) {
|
||||
switch ($which) {
|
||||
case "previous":
|
||||
$terminal_post = $this->get_last_comic($id);
|
||||
$which_field = "prior";
|
||||
break;
|
||||
case "next":
|
||||
$terminal_post = $this->get_first_comic($id);
|
||||
$which_field = "upcoming";
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_object($terminal_post)) {
|
||||
$comic_posts[$which_field] = $terminal_post;
|
||||
$comic_posts["show_${which_field}"] =true;
|
||||
}
|
||||
|
||||
if (count($terminal_post) == 2) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
return $comic_posts;
|
||||
}
|
||||
|
||||
|
@ -1,53 +1,10 @@
|
||||
<?php
|
||||
$nav_fields = array(
|
||||
'first' => '‹‹ ' . __('First', 'comicpress'),
|
||||
'previous' => '‹ ' . __('Previous', 'comicpress'),
|
||||
'next' => __('Next', 'comicpress') . ' ›',
|
||||
'last' => __('Last', 'comicpress') . ' ››'
|
||||
);
|
||||
|
||||
if ($comicpress->needs_storyline_nav()) {
|
||||
$nav_fields = array_merge(
|
||||
array('prior' => '‹‹ ' . __('Prior Storyline', 'comicpress')),
|
||||
$nav_fields,
|
||||
array('upcoming' => __('Upcoming Storyline', 'comicpress') . ' ››')
|
||||
);
|
||||
|
||||
foreach ($comicpress->get_sorted_post_categories() as $category_id) {
|
||||
$prev_next_categories = $comicpress->get_previous_next_categories($category_id);
|
||||
|
||||
foreach ($prev_next_categories as $master_id => $cat_list) {
|
||||
foreach ($cat_list as $which => $id) {
|
||||
switch ($which) {
|
||||
case "previous":
|
||||
$terminal_post = $comicpress->get_last_comic($id);
|
||||
$which_field = "prior";
|
||||
break;
|
||||
case "next":
|
||||
$terminal_post = $comicpress->get_first_comic($id);
|
||||
$which_field = "upcoming";
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_object($terminal_post)) {
|
||||
$nav_comics[$which_field] = $terminal_post;
|
||||
$nav_comics["show_${which_field}"] =true;
|
||||
}
|
||||
|
||||
if (count($terminal_post) == 2) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="nav">
|
||||
<?php foreach ($nav_fields as $field => $link_text) { ?>
|
||||
<?php if ($nav_comics['show_' . $field]) { ?>
|
||||
<div class="nav-<?php echo $field ?>">
|
||||
<a href="<?php echo (is_object($nav_comics[$field])) ? get_permalink($nav_comics[$field]->ID) : $nav_comics[$field] ?>"
|
||||
title="<?php sprintf(__('Go to the %s comic', 'comicpress'), $field) ?>"><?php echo $link_text ?></a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="nav">
|
||||
<?php foreach (apply_filters('comicpress_nav_fields', array()) as $field => $link_text) { ?>
|
||||
<?php if ($nav_comics['show_' . $field]) { ?>
|
||||
<div class="nav-<?php echo $field ?>">
|
||||
<a href="<?php echo (is_object($nav_comics[$field])) ? get_permalink($nav_comics[$field]->ID) : $nav_comics[$field] ?>"
|
||||
title="<?php sprintf(__('Go to the %s comic', 'comicpress'), $field) ?>"><?php echo apply_filters('comicpress_nav', $link_text, $field) ?></a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
@ -172,6 +172,106 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
function providerTestGetNavStorylineEnabled() {
|
||||
return array(
|
||||
array(
|
||||
array('10'),
|
||||
array(
|
||||
'10' => array(
|
||||
'10' => array('previous' => '9', 'next' => '11')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'9' => true,
|
||||
'11' => true
|
||||
),
|
||||
array(
|
||||
'prior' => true,
|
||||
'upcoming' => true
|
||||
)
|
||||
),
|
||||
array(
|
||||
array('10', '20'),
|
||||
array(
|
||||
'10' => array(
|
||||
'10' => array('previous' => '7', 'next' => '3')
|
||||
),
|
||||
'20' => array(
|
||||
'20' => array('previous' => '9', 'next' => '11')
|
||||
),
|
||||
),
|
||||
array(
|
||||
'9' => true,
|
||||
'11' => true
|
||||
),
|
||||
array(
|
||||
'prior' => true,
|
||||
'upcoming' => true
|
||||
)
|
||||
),
|
||||
array(
|
||||
array('10'),
|
||||
array(
|
||||
'10' => array(
|
||||
'10' => array('previous' => '7', 'next' => '3')
|
||||
),
|
||||
),
|
||||
array(
|
||||
'15' => true,
|
||||
'20' => true
|
||||
),
|
||||
array(
|
||||
'prior' => false,
|
||||
'upcoming' => false
|
||||
)
|
||||
),
|
||||
array(
|
||||
array('10'),
|
||||
array(
|
||||
'10' => array(
|
||||
'7' => array('previous' => '15', 'next' => '20')
|
||||
),
|
||||
),
|
||||
array(
|
||||
'15' => true,
|
||||
'20' => true
|
||||
),
|
||||
array(
|
||||
'prior' => true,
|
||||
'upcoming' => true
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGetNavStorylineEnabled
|
||||
*/
|
||||
function testGetNavComicsStorylineEnabled($post_categories, $previous_next_categories, $terminal_comics, $expected_results) {
|
||||
$cp = $this->getMock('ComicPress', array('get_sorted_post_categories', 'get_previous_next_categories', 'get_last_comic', 'get_first_comic'));
|
||||
|
||||
$cp->expects($this->once())->method('get_sorted_post_categories')->will($this->returnValue($post_categories));
|
||||
$cp->expects($this->any())->method('get_previous_next_categories')->will($this->returnCallback(array(&$this, 'callbackGetPreviousNextCategories')));
|
||||
$cp->expects($this->any())->method('get_first_comic')->will($this->returnCallback(array(&$this, 'callbackGetTerminalComic')));
|
||||
$cp->expects($this->any())->method('get_last_comic')->will($this->returnCallback(array(&$this, 'callbackGetTerminalComic')));
|
||||
|
||||
$this->_previous_next_categories = $previous_next_categories;
|
||||
$this->_terminal_comics = $terminal_comics;
|
||||
|
||||
$result = $cp->get_storyline_nav_comics();
|
||||
foreach ($expected_results as $field => $value) {
|
||||
$this->assertEquals($value, $result["show_${field}"]);
|
||||
}
|
||||
}
|
||||
|
||||
function callbackGetPreviousNextCategories($id) {
|
||||
return $this->_previous_next_categories[$id];
|
||||
}
|
||||
|
||||
function callbackGetTerminalComic($id) {
|
||||
return isset($this->_terminal_comics[$id]) ? (object)array() : false;
|
||||
}
|
||||
|
||||
function providerTestGetPreviousNextCategories() {
|
||||
return array(
|
||||
array(
|
||||
|
Loading…
Reference in New Issue
Block a user