From b91316be60f61851ad34565d74d6a4a1fe631c80 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 12 Jul 2009 22:31:14 -0400 Subject: [PATCH] archive and rss comics started --- addons/Core/Core.inc | 36 +++++++++++++++++++++++++++++---- archive.php | 6 ++++-- classes/ComicPressComicPost.inc | 33 ++++++++++++++++++++++++++---- functions.php | 18 +++-------------- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index 0f6e6ea..c0fc464 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -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() { ?> +

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'), diff --git a/archive.php b/archive.php index f3c12e4..dcce34b 100644 --- a/archive.php +++ b/archive.php @@ -30,12 +30,14 @@ - +
diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index c082cd9..4555f4d 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -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'); diff --git a/functions.php b/functions.php index a11edd1..17088cd 100644 --- a/functions.php +++ b/functions.php @@ -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() { ?> -

<?php the_title() ?>

query('showposts=1&orderby=rand&cat='.get_all_comic_categories_as_cat_string());