more cleanup of index.php and nav things

This commit is contained in:
John Bintz 2009-07-11 15:39:05 -04:00
parent 10baa173ec
commit b8d7682921
5 changed files with 147 additions and 79 deletions

View File

@ -1,11 +1,10 @@
<?php
require_once('FirePHPCore/fb.php');
class ComicPressAddonCore extends ComicPressAddon {
function init($comicpress) {
add_action('admin_init', array(&$this, 'setup_admin_interface'));
add_filter('attachment_fields_to_edit', array(&$this, 'setup_comic_metadata_buttons'), 10, 2);
add_action('show_comic', array(&$this, 'show_comic'), 1, 1);
$this->comicpress = $comicpress;
}
@ -18,6 +17,14 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
function show_comic($override_post) {
global $post;
$post_to_use = (is_null($override_post)) ? $this->comicpress->get_last_comic() : $post;
$comic_post = new ComicPressComicPost($post_to_use, &$this);
$comic_post->display_comics();
}
function setup_comic_metadata_buttons($form_fields, $post) {
$comic_image_types = array(
'none' => __('Not a comic', 'comicpress'),
@ -159,6 +166,9 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
break;
case 'blogpost_count':
$this->comicpress->comicpress_options[$option] = (int)$_POST['cp'][$option];
break;
}
}
}

View File

@ -23,6 +23,12 @@
</td>
</tr>
<?php } ?>
<tr>
<th scope="row"><?php _e("Number of blog posts on home page") ?></th>
<td>
<input type="text" name="cp[blogpost_count]" value="<?php echo $this->comicpress->comicpress_options['blogpost_count'] ?>" size="3" />
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit Changes" /></td>

View File

@ -6,7 +6,8 @@ class ComicPress {
'comic_dimensions' => '760x',
'rss_dimensions' => '350x',
'archive_dimensions' => '125x',
'category_order' => false
'category_order' => false,
'blogpost_count' => 10
);
var $comic_post_attachments_cache = array();
@ -16,7 +17,7 @@ class ComicPress {
function load() {
$result = get_option('comicpress-options');
if (is_array($result)) {
$this->comicpress_options = $result;
$this->comicpress_options = array_merge($this->comicpress_options, $result);
}
}
@ -157,7 +158,7 @@ class ComicPress {
function get_terminal_post_in_category($category_id, $first = true) {
$sort_order = $first ? "asc" : "desc";
$terminal_comic_query =$this->_new_wp_query();
$terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}");
$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);
}
@ -165,20 +166,50 @@ class ComicPress {
}
function get_first_comic() {
return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string);
return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string());
}
function get_last_comic() {
return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string, false);
return $this->get_terminal_post_in_category($this->get_all_comic_categories_as_cat_string(), false);
}
function get_adjacent_comic($category, $next = false) {
$categories_to_exclude = $this->non_comic_categories;
if (!is_null($category)) {
$categories_to_exclude = $this->get_string_to_exclude_all_but_provided_categories($category);
function get_nav_comics() {
$comic_posts = array();
foreach (array('first', 'last', 'previous', 'next') as $which) {
$comic_posts[$which] = $this->{"get_${which}_comic"}();
}
return get_adjacent_post(false, $categories_to_exclude, $next);
$comic_posts['show_first'] = ($comic_posts['first']->ID !== $comic_posts['last']->ID);
$comic_posts['show_previous'] = (!empty($comic_posts['previous']) && ($comic_posts['first']->ID !== $comic_posts['previous']->ID));
$comic_posts['show_next'] = (!empty($comic_posts['next']) && ($comic_posts['last']->ID !== $comic_posts['next']->ID));
return $comic_posts;
}
function get_adjacent_comic($category, $next = false, $override_post = null) {
global $wp_query, $post;
$temp = $wp_query->is_single;
$wp_query->is_single = true;
if (!is_null($override_post)) {
$temp_post = $post;
$post = $override_post;
}
$categories_to_exclude = $this->get_leaves_of_tree($this->non_comic_categories);
if (!is_null($category)) {
$categories_to_exclude = $this->exclude_all_but_provided_categories($category);
}
$result = get_adjacent_post(false, implode(" and ", $categories_to_exclude), !$next);
$wp_query->is_single = $temp;
if (!is_null($override_post)) {
$post = $temp_post;
}
return empty($result) ? false : $result;
}
/**
@ -186,9 +217,18 @@ class ComicPress {
* filter out every category but the provided ones.
*/
function get_string_to_exclude_all_but_provided_categories($category) {
return implode(",", array_diff($category_ids, $category));
}
function exclude_all_but_provided_categories($category) {
$category_ids = array_keys($this->get_all_category_objects_by_id());
if (!is_array($category)) { $category = array($category); }
return implode(",", array_diff($category_ids, $category));
}
function get_leaves_of_tree($tree) {
$leaves = array();
foreach ($tree as $branch) { $leaves[] = end(explode("/", $branch)); }
return $leaves;
}
function _new_wp_query() {
@ -198,12 +238,12 @@ class ComicPress {
/**
* Get the previous comic from the current one.
*/
function get_previous_comic($category = null) { return get_adjacent_comic($category); }
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) { return get_adjacent_comic($category, true); }
function get_next_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, true, $override_post); }
}
?>

View File

@ -1,5 +1,7 @@
<?php
wp_cache_flush();
include(dirname(__FILE__) . '/comicpress-config.php');
// If any errors occur while searching for a comic file, the error messages will be pushed into here.

136
index.php
View File

@ -1,66 +1,77 @@
<?php get_header(); global $comicpress, $blog_postcount, $blogcat; $first_comic = get_first_comic_permalink() ?>
<?php
global $comicpress;
<?php if (!(is_paged())) { ?>
<?php $wp_query->in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query('showposts=1&cat='.$comicpress->get_all_comic_categories_as_cat_string());
while ($comicFrontpage->have_posts()) {
$comicFrontpage->the_post();
$comic_post = new ComicPressComicPost(&$post, &$comicpress);
?>
<div id="comic-head"></div>
<div id="comic">
<?php $comic_post->display_comics() ?>
</div>
<div id="comic-foot"></div>
<?php } ?>
<div id="content" class="narrowcolumn">
<?php while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post() ?>
<div class="post-comic-head"></div>
<div class="post-comic">
<div class="nav">
<div class="nav-first"><a href="<?php echo $first_comic ?>" title="Go to the First Comic">&lsaquo;&lsaquo; First</a></div>
<div class="nav-previous"><?php global $wp_query; $wp_query->is_single = true; previous_comic_link('%link', '&lsaquo; Previous'); $wp_query->is_single = false ?></div>
</div>
<div class="comicdate">
<?php the_time('F jS, Y') ?>
</div>
<div class="clear"></div>
<?php if (get_option('comicpress-enable-storyline-support') == 1) { ?>
<ul class="storyline-cats"><li class="storyline-root"><?php the_category(' &raquo; </li><li>', multiple) ?></li></ul>
<?php } ?>
<h2>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title() ?>"><?php the_title() ?></a>
</h2>
<div class="entry">
<?php the_content('&darr; Read the rest of this entry...') ?>
</div>
<?php the_transcript('styled') ?>
<div class="tags">
<?php the_tags('&#9492; Tags: ', ', ', ''); edit_post_link('Edit Post', ' [ ', ' ] ') ?>
</div>
<div class="comment-link">
<?php if ('open' == $post->comment_status) { comments_popup_link('&ldquo;Comment&rdquo;', '&ldquo;1 Comment&rdquo;', '&ldquo;% Comments&rdquo;'); } ?>
</div>
<br class="clear-margins" />
</div>
<div class="post-comic-foot"></div>
<?php endwhile; ?>
<div id="blogheader"><!-- This area can be used for a heading above your main page blog posts --></div>
<?php } else { ?>
<div id="content" class="narrowcolumn">
get_header();
?>
<?php if (!is_paged()) { ?>
<div id="comic-head"></div>
<div id="comic"><?php do_action('show_comic', null); ?></div>
<div id="comic-foot"></div>
<?php } ?>
<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('showposts='.$blog_postcount.'&cat=-'.$comiccat.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post() ?>
<div id="content" class="narrowcolumn">
<?php if (!is_paged()) {
$nav_comics = $comicpress->get_nav_comics();
$post = $nav_comics['last']; ?>
<div class="post-comic-head"></div>
<div class="post-comic">
<div class="nav">
<?php if ($nav_comics['show_first']) { ?>
<div class="nav-first">
<a href="<?php echo get_permalink($nav_comics['first']->ID) ?>"
title="<?php _e('Go to the first comic', 'comicpress') ?>">&lsaquo;&lsaquo; First</a>
</div>
<?php } ?>
<?php if ($nav_comics['show_previous']) { ?>
<div class="nav-previous">
<a href="<?php echo get_permalink($nav_comics['previous']->ID) ?>"
title="<?php _e('Go to the previous comic', 'comicpress') ?>">&lsaquo; Previous</a>
</div>
<?php } ?>
</div>
<div class="comicdate">
<?php the_date('F jS, Y') ?>
</div>
<div class="clear"></div>
<?php if (get_option('comicpress-enable-storyline-support') == 1) { ?>
<ul class="storyline-cats"><li class="storyline-root"><?php the_category(' &raquo; </li><li>', multiple) ?></li></ul>
<?php } ?>
<h2>
<a href="<?php get_permalink($last_comic_post->ID) ?>" rel="bookmark" title="Permanent Link to <?php echo $last_comic_post->post_title ?>"><?php echo $last_comic_post->post_title ?></a>
</h2>
<div class="entry">
<?php the_content('&darr; Read the rest of this entry...') ?>
</div>
<?php the_transcript('styled') ?>
<div class="tags">
<?php the_tags('&#9492; Tags: ', ', ', ''); edit_post_link('Edit Post', ' [ ', ' ] ') ?>
</div>
<div class="comment-link">
<?php if ('open' == $post->comment_status) { comments_popup_link('&ldquo;Comment&rdquo;', '&ldquo;1 Comment&rdquo;', '&ldquo;% Comments&rdquo;'); } ?>
</div>
<br class="clear-margins" />
</div>
<div class="post-comic-foot"></div>
<?php } ?>
<div id="blogheader"><!-- This area can be used for a heading above your main page blog posts --></div>
<?php
$wp_query = new WP_Query();
$wp_query->query(
'showposts=' .
(int)$comicpress->comicpress_options['blogpost_count'] .
'&cat=-' .
$comicpress->comicpress_options['comic_category_id'] .
'&paged=' .
$paged
);
while ($wp_query->have_posts()) {
$wp_query->the_post() ?>
<div class="post-head"></div>
<div class="post" id="post-<?php the_ID() ?>">
<h3>
@ -81,16 +92,15 @@
<div class="clear-margins"><br /></div>
</div>
<div class="post-foot"></div>
<?php endwhile; ?>
<?php } ?>
<div class="pagenav">
<div class="pagenav-right"><?php previous_posts_link('Newer Entries &uarr;') ?></div>
<div class="pagenav-left"><?php next_posts_link('&darr; Previous Entries') ?></div>
<div class="clear"></div>
</div>
<?php $wp_query = null; $wp_query = $temp ?>
</div>
<?php include(TEMPLATEPATH . '/sidebar.php') ?>
<?php include(dirname(__FILE__) . '/sidebar.php') ?>
<?php get_footer() ?>