From 10baa173ec1c661eaaa798d9e1e992ba7217ec41 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 10 Jul 2009 20:27:36 -0400 Subject: [PATCH] comic attachment metadata working --- addons/Core/Core.inc | 123 ++++++++++++++++++++++---------- classes/ComicPressComicPost.inc | 12 ++-- 2 files changed, 92 insertions(+), 43 deletions(-) diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index 85fca4c..49a8f8c 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -1,8 +1,11 @@ comicpress = $comicpress; } @@ -14,6 +17,40 @@ class ComicPressAddonCore extends ComicPressAddon { add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low"); } } + + function setup_comic_metadata_buttons($form_fields, $post) { + $comic_image_types = array( + 'none' => __('Not a comic', 'comicpress'), + 'comic' => __('Comic', 'comicpress'), + 'rss' => __('RSS', 'comicpress'), + 'archive' => __('Archive', 'comicpress'), + ); + + $current_type = get_post_meta($post->ID, 'comic_image_type', true); + + $field_html_lines = array(); + $field_html_lines[] = ''; + foreach ($comic_image_types as $field => $label) { + $field_html_lines[] = ''; + } + + $form_fields['comic_image_type'] = array( + 'label' => __("Comic Image Type", 'comicpress'), + 'input' => 'html', + 'html' => '
' . implode("\n", $field_html_lines) . '
' + ); + + return $form_fields; + } function render_admin() { $nonce = wp_create_nonce('comicpress'); @@ -78,47 +115,57 @@ class ComicPressAddonCore extends ComicPressAddon { } function handle_update() { - foreach ($this->comicpress->comicpress_options as $option => $value) { - if (isset($_POST['cp'][$option])) { - switch ($option) { - case 'comic_category_id': - if (is_numeric($_POST['cp'][$option])) { - $result = get_category($_POST['cp'][$option]); - if (!(is_a($result, 'WP_Error') || empty($result))) { - $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; - } - } - break; - case 'comic_dimensions': - case 'rss_dimensions': - case 'archive_dimensions': - if (is_array($_POST['cp'][$option])) { - $dim_parts = array(); - $is_valid = true; - foreach (array('width', 'height') as $field) { - $requested_dim = trim($_POST['cp'][$option][$field]); - if ($requested_dim == "") { - $dim_parts[] = $requested_dim; - } else { - if ((int)$requested_dim == $requested_dim) { - $dim_parts[] = $requested_dim; - } else { - $is_valid = false; break; - } - } - } - - if ($is_valid) { - $this->comicpress->comicpress_options[$option] = implode("x", $dim_parts); - } - } - break; + if (isset($_POST['attachments'])) { + //coming from media editor + foreach ($_POST['attachments'] as $post_id => $settings) { + if (isset($settings['comic_image_type'])) { + update_post_meta($post_id, 'comic_image_type', $settings['comic_image_type']); } } + } else { + //coming from us + foreach ($this->comicpress->comicpress_options as $option => $value) { + if (isset($_POST['cp'][$option])) { + switch ($option) { + case 'comic_category_id': + if (is_numeric($_POST['cp'][$option])) { + $result = get_category($_POST['cp'][$option]); + if (!(is_a($result, 'WP_Error') || empty($result))) { + $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; + } + } + break; + case 'comic_dimensions': + case 'rss_dimensions': + case 'archive_dimensions': + if (is_array($_POST['cp'][$option])) { + $dim_parts = array(); + $is_valid = true; + foreach (array('width', 'height') as $field) { + $requested_dim = trim($_POST['cp'][$option][$field]); + if ($requested_dim == "") { + $dim_parts[] = $requested_dim; + } else { + if ((int)$requested_dim == $requested_dim) { + $dim_parts[] = $requested_dim; + } else { + $is_valid = false; break; + } + } + } + + if ($is_valid) { + $this->comicpress->comicpress_options[$option] = implode("x", $dim_parts); + } + } + break; + } + } + } + $this->comicpress->save(); + + $this->info("ComicPress configuration updated."); } - $this->comicpress->save(); - - $this->info("ComicPress configuration updated."); } } diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index 02f40df..c082cd9 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -2,7 +2,7 @@ class ComicPressComicPost { var $post; - var $attachments; + var $attachments = null; var $comicpress; function ComicPressComicPost($post = null, $comicpress = null) { @@ -11,7 +11,7 @@ class ComicPressComicPost { } function get_comic_image_attachments() { - if (!isset($this->attachments)) { + if (is_null($this->attachments)) { $this->attachments = get_children(array( 'post_parent' => $this->post->ID, 'post_type' => 'attachment', @@ -22,9 +22,11 @@ class ComicPressComicPost { } function display_comics() { - 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 (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)); + } + } } function get_comic_img_tag($url, $type, $additional_parameters = array()) {