comic attachment metadata working

This commit is contained in:
John Bintz 2009-07-10 20:27:36 -04:00
parent 3df4ad4ff5
commit 10baa173ec
2 changed files with 92 additions and 43 deletions

View File

@ -1,8 +1,11 @@
<?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);
$this->comicpress = $comicpress;
}
@ -15,6 +18,40 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
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[] = '<input type="hidden" name="cp[_nonce]" value="' . wp_create_nonce('comicpress') . '" />';
foreach ($comic_image_types as $field => $label) {
$field_html_lines[] = '<label>'
. ' <input type="radio" name="attachments['
. $post->ID
. '][comic_image_type]" value="'
. $field
. '"'
. (($field == $current_type) ? ' checked="checked"' : '')
. ' /> '
. $label
. '</label>';
}
$form_fields['comic_image_type'] = array(
'label' => __("Comic Image Type", 'comicpress'),
'input' => 'html',
'html' => '<center>' . implode("\n", $field_html_lines) . '</center>'
);
return $form_fields;
}
function render_admin() {
$nonce = wp_create_nonce('comicpress');
$root_categories = $this->get_root_categories();
@ -78,6 +115,15 @@ class ComicPressAddonCore extends ComicPressAddon {
}
function handle_update() {
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) {
@ -120,6 +166,7 @@ class ComicPressAddonCore extends ComicPressAddon {
$this->info("ComicPress configuration updated.");
}
}
}
?>

View File

@ -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,10 +22,12 @@ class ComicPressComicPost {
}
function display_comics() {
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()) {
$dimensions = array();