comic attachment metadata working
This commit is contained in:
parent
3df4ad4ff5
commit
10baa173ec
@ -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,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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->comicpress->save();
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("ComicPress configuration updated.");
|
||||
if ($is_valid) {
|
||||
$this->comicpress->comicpress_options[$option] = implode("x", $dim_parts);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->comicpress->save();
|
||||
|
||||
$this->info("ComicPress configuration updated.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user