more polishing

This commit is contained in:
John Bintz 2009-11-18 21:25:35 -05:00
parent 2d03a4db01
commit cd64f57885
6 changed files with 78 additions and 48 deletions

View File

@ -95,11 +95,13 @@ class ComicPress {
} }
function editor_max_image_size($current_max, $size) { function editor_max_image_size($current_max, $size) {
if (isset($this->comicpress_options['image_types'])) { if (is_string($size)) {
if (isset($this->comicpress_options['image_types'][$size])) { if (isset($this->comicpress_options['image_types'])) {
if (isset($this->comicpress_options['image_types'][$size]['dimensions'])) { if (isset($this->comicpress_options['image_types'][$size])) {
list($width, $height) = explode('x', $this->comicpress_options['image_types'][$size]['dimensions']); if (isset($this->comicpress_options['image_types'][$size]['dimensions'])) {
$current_max = array(intval($width), intval($height)); list($width, $height) = explode('x', $this->comicpress_options['image_types'][$size]['dimensions']);
$current_max = array(intval($width), intval($height));
}
} }
} }
} }

View File

@ -122,15 +122,24 @@ class ComicPressAdmin {
$is_managed = $comicpress_info['managed']; $is_managed = $comicpress_info['managed'];
} }
$form_fields['comicpress_management'] = array(
'label' => __("Let ComicPress Manage?", 'comicpress'),
'input' => 'html',
'html' => '<label><input type="checkbox" name="attachments[' . esc_attr($post->ID) . '][comicpress_management]" value="yes" ' . ($is_managed ? 'checked="checked"' : '') . '/> '
. __('Let ComicPress treat this image as a comic media file', 'comicpress')
. '</label>'
. '<input type="hidden" name="cp[_nonce]" value="' . wp_create_nonce('comicpress') . '" />'
. '<input type="hidden" name="attachments[' . $post->ID . '][post_parent]" value="' . $post->post_parent . '" />'
);
if ($pagenow !== "media.php") { if ($pagenow !== "media.php") {
$form_fields['auto_attach'] = array( $form_fields['attach_parent'] = array(
'label' => __("Let ComicPress Manage?", 'comicpress'), 'label' => __("Change parent?", 'comicpress'),
'input' => 'html', 'input' => 'html',
'html' => '<label><input type="checkbox" name="attachments[' . $post->ID . '][comicpress_management]" value="yes" ' . ($is_managed ? 'checked="checked"' : '') . '/> ' 'html' => '<label><input type="checkbox" name="attachments[' . esc_attr($post->ID) . '][change_parent]" value="yes" /> '
. __('Let ComicPress treat this image as a comic media file', 'comicpress') . __('Attach this image to the current post being edited?', 'comicpress')
. '</label>' . '</label>'
. '<input type="hidden" name="cp[_nonce]" value="' . wp_create_nonce('comicpress') . '" />'
. '<input type="hidden" name="attachments[' . $post->ID . '][post_parent]" value="' . $post->post_parent . '" />'
); );
} }
@ -209,42 +218,46 @@ class ComicPressAdmin {
$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
if (is_numeric($override_post)) { $uploading_iframe_ID = $override_post; } if (is_numeric($override_post)) { $uploading_iframe_ID = $override_post; }
$comic_post = new ComicPressComicPost(get_post($uploading_iframe_ID)); if ($uploading_iframe_ID > 0) {
$ordering = $comic_post->normalize_ordering(); $comic_post = new ComicPressComicPost(get_post($uploading_iframe_ID));
$ordering = $comic_post->normalize_ordering();
$nonce = wp_create_nonce('comicpress'); $nonce = wp_create_nonce('comicpress');
$action_nonce = wp_create_nonce('comicpress-comic-ordering'); $action_nonce = wp_create_nonce('comicpress-comic-ordering');
$zoom_level = 40; $zoom_level = 40;
$current_user = wp_get_current_user(); $current_user = wp_get_current_user();
if (!empty($current_user)) { if (!empty($current_user)) {
$comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings'); $comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
if (is_array($comicpress_meta)) { if (is_array($comicpress_meta)) {
if (isset($comicpress_meta['zoom_level'])) { if (isset($comicpress_meta['zoom_level'])) {
$zoom_level = floor($comicpress_meta['zoom_level']); $zoom_level = floor($comicpress_meta['zoom_level']);
}
} }
} }
}
// from wp-admin/includes/media.php O_o // from wp-admin/includes/media.php O_o
$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID"; $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&amp;type=image&amp;TB_iframe=true"); $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&amp;type=image&amp;TB_iframe=true");
$comicpress = ComicPress::get_instance(); $comicpress = ComicPress::get_instance();
$available_attachments = array(); $available_attachments = array();
foreach ($this->get_editable_attachment_list($ordering) as $id => $info) { foreach ($this->get_editable_attachment_list($ordering) as $id => $info) {
$result = ComicPressBackend::generate_from_id($id); $result = ComicPressBackend::generate_from_id($id);
if (!empty($result)) { if (!empty($result)) {
$attachment_info = $result->get_info(); $attachment_info = $result->get_info();
$available_attachments[] = array('id' => $id, 'name' => basename($attachment_info['file']), 'type' => $result->source_name, 'attachment' => $attachment_info, 'ordering' => $info); $available_attachments[] = array('id' => $id, 'name' => basename($attachment_info['file']), 'type' => $result->source_name, 'attachment' => $attachment_info, 'ordering' => $info);
}
} }
}
if ($is_ajax === true) { if ($is_ajax === true) {
include(dirname(__FILE__) . '/partials/_comic-image-ordering-sorters.inc'); include(dirname(__FILE__) . '/partials/_comic-image-ordering-sorters.inc');
} else {
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
}
} else { } else {
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc'); _e('You\'ll need to save your post as a draft or publish it before you can order comic images.', 'comicpress');
} }
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
@ -297,7 +310,7 @@ class ComicPressAdmin {
*/ */
function handle_update_attachments() { function handle_update_attachments() {
foreach ($_POST['attachments'] as $post_id => $settings) { foreach ($_POST['attachments'] as $post_id => $settings) {
if (isset($settings['comicpress_management'])) { if (isset($settings['change_parent'])) {
$media_post = get_post($post_id); $media_post = get_post($post_id);
if (isset($media_post->post_parent)) { if (isset($media_post->post_parent)) {
$media_post->post_parent = $settings['post_parent']; $media_post->post_parent = $settings['post_parent'];

View File

@ -7,7 +7,6 @@
) )
?> ?>
<?php _e('Click the Refesh button underneath the zoom slider if you\'ve changed the images attached to this post.', 'comicpress') ?> <?php _e('Click the Refesh button underneath the zoom slider if you\'ve changed the images attached to this post.', 'comicpress') ?>
</em></p> </em></p>
<?php if (!empty($ordering)) { ?> <?php if (!empty($ordering)) { ?>
<div id="comic-ordering"> <div id="comic-ordering">

View File

@ -31,11 +31,16 @@ function F($name, $path, $override_post = null) {
/** /**
* Protect global $post and $wp_query. * Protect global $post and $wp_query.
*/ */
function Protect() { function Protect($use_this_post = null) {
global $post, $wp_query, $__post, $__wp_query; global $post, $wp_query, $__post, $__wp_query;
$__post = $post; $__post = $post;
$__wp_query = $wp_query; $__wp_query = $wp_query;
if (!is_null($use_this_post)) {
$post = $use_this_post;
setup_postdata($post);
}
} }
/** /**
@ -102,11 +107,7 @@ function R($which, $restrictions = null, $override_post = null) {
global $post; global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post; $post_to_use = !is_null($override_post) ? $override_post : $post;
$storyline = new ComicPressStoryline(); $categories = RL($restrictions, $post_to_use);
$restrictions = __prep_R($restrictions, $post_to_use);
$categories = $storyline->build_from_restrictions($restrictions);
$dbi = ComicPressDBInterface::get_instance(); $dbi = ComicPressDBInterface::get_instance();
@ -138,6 +139,17 @@ function RT($which, $restrictions = null, $override_post = null) {
return $post; return $post;
} }
function RL($restrictions = null, $override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$storyline = new ComicPressStoryline();
$restrictions = __prep_R($restrictions, $post_to_use);
return $storyline->build_from_restrictions($restrictions);
}
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
function M($override_post = null) { function M($override_post = null) {
@ -206,4 +218,4 @@ function SC($which = 'current', $relative_to = null) {
} }
return false; return false;
} }

View File

@ -7,7 +7,7 @@ Event.observe(window, 'load', function() {
var show_insert = function(t) { var show_insert = function(t) {
var b = item.select('input[name*=send]').pop(); var b = item.select('input[name*=send]').pop();
if (b) { b[(t.value == 'none') ? 'show' : 'hide'](); } if (b) { b[(t.checked) ? 'hide' : 'show'](); }
} }
var type = item.select('input[name*=comicpress_management][checked]').pop(); var type = item.select('input[name*=comicpress_management][checked]').pop();
@ -15,5 +15,8 @@ Event.observe(window, 'load', function() {
item.select('.filename.new').pop().insert({bottom: new Element('div').addClassName('comicpress-is-managing')}); item.select('.filename.new').pop().insert({bottom: new Element('div').addClassName('comicpress-is-managing')});
show_insert(type); show_insert(type);
} }
item.select('input[name*=comicpress_management]').invoke('observe', 'change', function(e) { show_insert(e.target); });
}); });
}); });

View File

@ -173,7 +173,8 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
), ),
array( array(
'post_parent' => "2", 'post_parent' => "2",
'comicpress_management' => "yes" 'comicpress_management' => "yes",
'change_parent' => "yes"
), ),
array( array(
'post' => array( 'post' => array(