archive and rss comics started

This commit is contained in:
John Bintz 2009-07-12 22:31:14 -04:00
parent 058a866f95
commit b91316be60
4 changed files with 68 additions and 25 deletions

View File

@ -5,10 +5,26 @@ class ComicPressAddonCore extends ComicPressAddon {
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);
add_action('show_archive', array(&$this, 'show_archive'), 1, 1);
add_action('show_rss', array(&$this, 'show_rss'), 1, 1);
add_filter('the_content', array(&$this, 'insert_comic_feed'));
$this->comicpress = $comicpress;
}
function comic_feed() { ?>
<p><a href="<?php the_permalink() ?>"><?php do_action('show_rss') ?></a></p><?php
}
function insert_comic_feed($content) {
if (is_feed() && in_comic_category()) {
return $this->comic_feed() . $content;
} else {
return $content;
}
}
function setup_admin_interface() {
add_theme_page(__("ComicPress Core", 'comicpress'), __('ComicPress Core', 'comicpress'), 'edit_themes', basename(__FILE__), array(&$this, 'render_admin'));
@ -17,14 +33,26 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
function show_comic($override_post) {
function show_media($override_post, $method) {
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();
$comic_post = new ComicPressComicPost($post_to_use, &$this->comicpress);
$comic_post->{$method}();
}
function show_comic($override_post = null) {
$this->show_media($override_post, "display_comics");
}
function show_archive($override_post = null) {
$this->show_media($override_post, "display_archive");
}
function show_rss($override_post = null) {
$this->show_media($override_post, "display_rss");
}
function setup_comic_metadata_buttons($form_fields, $post) {
$comic_image_types = array(
'none' => __('Not a comic', 'comicpress'),

View File

@ -30,12 +30,14 @@
<?php $posts = query_posts($query_string.'&order=asc');
while (have_posts()) : the_post() ?>
<?php global $archive_comic_width; if (in_comic_category()) { ?>
<?php if (in_comic_category()) { ?>
<div class="post-comic-head"></div>
<div class="post-comic">
<div class="comicarchiveframe" style="width:<?php echo $archive_comic_width; ?>px;">
<a href="<?php the_permalink() ?>"><img src="<?php the_comic_archive() ?>" alt="<?php the_title() ?>" title="Click for full size." width="<?php echo $archive_comic_width ?>" /><br />
<a href="<?php the_permalink() ?>">
<?php do_action('show_archive') ?>
<br />
<h3><?php the_title() ?></h3>
<small><?php the_time('F jS, Y') ?></small></a>
</div>

View File

@ -21,16 +21,41 @@ class ComicPressComicPost {
return $this->attachments;
}
function display_comics() {
if (is_array($this->get_comic_image_attachments())) {
function display_attached_images($type = "comic", $limit = null, $size_type = null) {
if (is_null($size_type)) { $size_type = $type; }
$found = false;
if (is_array($this->get_comic_image_attachments())) {
foreach ($this->get_comic_image_attachments() as $attachment) {
echo $this->get_comic_img_tag(wp_get_attachment_url($attachment->ID), "comic", array('title' => $attachment->post_title));
if (get_post_meta($attachment->ID, "comic_image_type", true) == $type) {
echo $this->get_comic_img_tag(wp_get_attachment_url($attachment->ID, ''), $size_type, array('title' => $attachment->post_title));
$found = true;
if (!is_null($limit)) {
if (--$limit == 0) { break; }
}
}
}
}
}
return $found;
}
function display_comics() { $this->display_attached_images(); }
function display_archive() {
if (!$this->display_attached_images('archive', 1)) {
$this->display_attached_images('comic', 1, 'archive');
}
}
function display_rss() {
if (!$this->display_attached_images('rss')) {
$this->display_attached_images('comic', null, 'rss');
}
}
function get_comic_img_tag($url, $type, $additional_parameters = array()) {
$dimensions = array();
if (isset($this->comicpress->comicpress_options["${type}_dimensions"])) {
list($width, $height) = explode("x", $this->comicpress->comicpress_options["${type}_dimensions"]);
$dimensions = compact('width', 'height');

View File

@ -64,7 +64,9 @@ function __comicpress_init() {
if (is_array($_POST['cp'])) {
if (isset($_POST['cp']['_nonce'])) {
if (wp_verify_nonce($_POST['cp']['_nonce'], 'comicpress')) {
$addon->handle_update();
if (method_exists($addon, 'handle_update')) {
$addon->handle_update();
}
}
}
}
@ -177,20 +179,6 @@ function the_transcript($displaymode = 'raw') {
}
}
//Insert the comic image into the RSS feed
function comic_feed() { ?>
<p><a href="<?php the_permalink() ?>"><img src="<?php the_comic_rss() ?>" border="0" alt="<?php the_title() ?>" title="<?php the_hovertext() ?>" /></a></p><?php
}
function insert_comic_feed($content) {
if (is_feed() && in_comic_category()) {
return comic_feed() . $content;
} else {
return $content;
}
}
add_filter('the_content','insert_comic_feed');
//Generate a random comic page - to use simply create a URL link to "/?randomcomic"
function random_comic() {
$randomComicQuery = new WP_Query(); $randomComicQuery->query('showposts=1&orderby=rand&cat='.get_all_comic_categories_as_cat_string());