From b287c05e21fe219870a3c1272e4fb63602e807ee Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 11 Nov 2009 22:31:36 -0500 Subject: [PATCH] get attachment info --- classes/ComicPress.inc | 10 ++++++-- .../backends/ComicPressBackendAttachment.inc | 23 +++++++++++++------ .../_comic-image-ordering-sorters.inc | 23 +++++++++---------- .../ComicPressBackendAttachmentTest.php | 23 ++++++++++++++++++- 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 6418b14..8a92d93 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -21,7 +21,7 @@ class ComicPress { ) ); - var $backends = array('ComicPressBackendAttachment'); + var $backends = array(); function &get_instance() { static $instance; @@ -53,7 +53,7 @@ class ComicPress { } // @codeCoverageIgnoreStart - + /** * Initialize the class. */ @@ -75,6 +75,12 @@ class ComicPress { update_option("${size}_size_h", $h); update_option("${size}_crop", 0); } + + foreach (get_declared_classes() as $class) { + if (preg_match('#^ComicPressBackend.+$#', $class) > 0) { + $this->backends[] = new $class(); + } + } } // WordPress Filters diff --git a/classes/backends/ComicPressBackendAttachment.inc b/classes/backends/ComicPressBackendAttachment.inc index e2ece1e..8b0e8d9 100644 --- a/classes/backends/ComicPressBackendAttachment.inc +++ b/classes/backends/ComicPressBackendAttachment.inc @@ -57,23 +57,32 @@ class ComicPressBackendAttachment extends ComicPressBackend { } // @codeCoverageIgnoreStart - function embed($size = 'comic') { - return $this->_embed_image($size); - } - + function embed($size = 'comic') { return $this->_embed_image($size); } + function file($size = 'comic') { return $this->attachment->guid; } function alt() { return $this->attachment->post_title; } function title() { return $this->attachment->post_excerpt; } - - function get_info() { return array(); } // @codeCoverageIgnoreEnd + function get_info($size = 'comic') { + $info = array(); + foreach (array('dims', 'url', 'file') as $field) { + $result = $this->{$field}($size); + if (is_array($result)) { + $info = array_merge($info, $result); + } else { + $info[$field] = $result; + } + } + return $info; + } + function generate_from_id($id) { if (strpos($id, 'attachment-') === 0) { $id = str_replace('attachment-', '', $id); if (is_numeric($id)) { $post = get_post($id); if (!empty($post)) { - return $post; + return new ComicPressBackendAttachment($post); } } } diff --git a/classes/partials/_comic-image-ordering-sorters.inc b/classes/partials/_comic-image-ordering-sorters.inc index 9de8d93..ad74df3 100644 --- a/classes/partials/_comic-image-ordering-sorters.inc +++ b/classes/partials/_comic-image-ordering-sorters.inc @@ -1,5 +1,5 @@

- +

- $attachment_ids) { ?> -

comic_image_types[$type] ?>

-
- get_info(); ?> -
- +
+ $info) { + $result = ComicPressBackend::generate_from_id($id); + if (!empty($result)) { + $info = $result->get_info(); ?> +
+

@@ -31,9 +30,9 @@

- -
- + + +