working on image type editor

This commit is contained in:
John Bintz 2009-11-12 22:13:05 -05:00
parent 2f5777e5f0
commit b1db6deb7b
7 changed files with 246 additions and 154 deletions

View File

@ -155,7 +155,7 @@ class ComicPress {
foreach (get_declared_classes() as $class) { foreach (get_declared_classes() as $class) {
if (preg_match('#^ComicPressBackend.+$#', $class) > 0) { if (preg_match('#^ComicPressBackend.+$#', $class) > 0) {
$this->backends[] = new $class(); $this->backends[] = $class;
} }
} }
} }

View File

@ -246,20 +246,26 @@ class ComicPressAdmin {
$defined_default = null; $defined_default = null;
foreach ($info['image_types'] as $type => $image_info) { foreach ($info['image_types'] as $type => $image_info) {
if (is_array($image_info)) { if (is_array($image_info)) {
foreach ($image_info as $field => $field_value) {
$new_value = array(); $new_value = array();
$new_type = $type;
foreach ($image_info as $field => $field_value) {
switch ($field) { switch ($field) {
case "default": $defined_default = $type; break; case 'default': $defined_default = $type; break;
case "dimensions": case 'dimensions':
if (is_array($field_value)) { if (is_array($field_value)) {
if (count(array_intersect(array('width', 'height'), array_keys($field_value))) == 2) { if (count(array_intersect(array('width', 'height'), array_keys($field_value))) == 2) {
$new_value['dimensions'] = "{$field_value['width']}x{$field_value['height']}"; $new_value['dimensions'] = "{$field_value['width']}x{$field_value['height']}";
} }
} }
break; break;
case 'name': $new_value['name'] = (string)$field_value; break;
case 'short_name': $new_type = $field_value; break;
} }
$this->comicpress->comicpress_options['image_types'][$type] = $new_value;
} }
if ($type != $new_type) {
unset($this->comicpress->comicpress_options['image_types'][$new_type]);
}
$this->comicpress->comicpress_options['image_types'][$new_type] = $new_value;
} }
} }
} }
@ -300,6 +306,16 @@ class ComicPressAdmin {
} }
} }
function _json_encode($data) {
if (function_exists('json_encode')) {
return json_decode($data);
} else {
require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
$j = new Moxiecode_JSON();
return $j->encode($data);
}
}
function handle_update_comic_ordering() { function handle_update_comic_ordering() {
if (isset($_POST['post_ID'])) { if (isset($_POST['post_ID'])) {
if (is_numeric($_POST['post_ID'])) { if (is_numeric($_POST['post_ID'])) {

View File

@ -1,6 +1,8 @@
<?php <?php
class ComicPressDBInterface { class ComicPressDBInterface {
var $_non_comic_categories, $_all_categories;
function ComicPressDBInterface() {} function ComicPressDBInterface() {}
function get_instance() { function get_instance() {
@ -10,25 +12,34 @@ class ComicPressDBInterface {
return $instance; return $instance;
} }
// @codeCoverageIgnoreStart
function _get_categories() { return get_categories("hide_empty=0"); } function _get_categories() { return get_categories("hide_empty=0"); }
function get_terminal_post($first = true, $include_categories = null) { /**
$this->_prepare_wp_query(); * Set the comic categories for the current run of ComicPress.
*/
$terminal_comic_query = new WP_Query(); function set_comic_categories($categories) {
$this->_all_categories = get_all_category_ids();
$query_parameters = array( $this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories));
'showposts' => 1,
'order' => $first ? "asc" : "desc",
'status' => 'publish'
);
if (is_array($include_categories)) {
$query_parameters['category_in'] = $include_categories;
} }
$terminal_comic_query->query($query_parameters); function _get_categories_to_exclude($category = null) {
$result = array_diff($this->_all_categories, array($category));
if (is_array($result)) {
return (is_null($category)) ? $this->_non_comic_categories : array_values($result);
} else {
return $this->_non_comic_categories;
}
}
/**
* Find the terminal post in a specific category.
*/
function get_terminal_post_in_category($category_id, $first = true) {
$this->_prepare_wp_query();
$sort_order = $first ? "asc" : "desc";
$terminal_comic_query = new WP_Query();
$terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish");
$post = false; $post = false;
if ($terminal_comic_query->have_posts()) { if ($terminal_comic_query->have_posts()) {
$post = reset($terminal_comic_query->posts); $post = reset($terminal_comic_query->posts);
@ -41,28 +52,28 @@ class ComicPressDBInterface {
/** /**
* Get the first comic in a category. * Get the first comic in a category.
*/ */
function get_first_post($include_categories = null) { function get_first_comic($category_id) {
return $this->get_terminal_post(true, $include_categories); return $this->get_terminal_post_in_category($category_id);
} }
/** /**
* Get the last comic in a category. * Get the last comic in a category.
*/ */
function get_last_post($include_categories = null) { function get_last_comic($category_id) {
return $this->get_terminal_post(false, $include_categories); return $this->get_terminal_post_in_category($category_id, false);
} }
/** /**
* Get the comic post adjacent to the current comic. * Get the comic post adjacent to the current comic.
* Wrapper around get_adjacent_post(). Don't unit test this method. * Wrapper around get_adjacent_post(). Don't unit test this method.
*/ */
function get_adjacent_post($categories = array(), $next = false, $override_post = null) { function get_adjacent_comic($category, $next = false, $override_post = null) {
global $post; global $post;
$this->_prepare_wp_query(); $this->_prepare_wp_query();
if (!is_null($override_post)) { $temp_post = $post; $post = $override_post; } if (!is_null($override_post)) { $temp_post = $post; $post = $override_post; }
$result = get_adjacent_post(false, implode(" and ", array_diff(get_all_category_ids(), $categories)), !$next); $result = get_adjacent_post(false, implode(" and ", $this->_get_categories_to_exclude($category)), !$next);
$this->_reset_wp_query(); $this->_reset_wp_query();
if (!is_null($override_post)) { $post = $temp_post; } if (!is_null($override_post)) { $post = $temp_post; }
@ -89,12 +100,12 @@ class ComicPressDBInterface {
/** /**
* Get the previous comic from the current one. * Get the previous comic from the current one.
*/ */
function get_previous_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, false, $override_post); } function get_previous_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, false, $override_post); }
/** /**
* Get the next comic from the current one. * Get the next comic from the current one.
*/ */
function get_next_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, true, $override_post); } function get_next_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, true, $override_post); }
} }
// @codeCoverageIngoreEnd ?>

View File

@ -0,0 +1,26 @@
<div class="image-type-holder">
<a class="delete-image-type">X</a>
<table cellspacing="0">
<tr class="image-type-editor-name">
<th scope="row" width="30%">Name:</th>
<td width="70%"><input type="text" name="cp[image_types][<?php echo $type ?>][name]" value="<?php echo $info['name'] ?>" /></td>
</tr>
<tr class="image-type-editor-short-name">
<th scope="row">Short name <em>(used in template tags):</em></th>
<td><input type="text" name="cp[image_types][<?php echo $type ?>][short_name]" value="<?php echo $type ?>" /></td>
</tr>
<tr class="image-type-editor-default">
<th scope="row">Default image type?</th>
<td><input type="checkbox" name="cp[image_types][<?php echo $type ?>][default]" value="yes" <?php echo (!empty($info['default'])) ? 'checked="checked"' : '' ?> /></td>
</tr>
<tr class="image-type-editor-dimensions">
<th scope="row">Dimensions</th>
<td>
<?php list($width, $height) = explode("x", $info['dimensions']) ?>
<input type="text" name="cp[image_types][<?php echo $type ?>][dimensions][width]" value="<?php echo $width ?>" size="5" /> x
<input type="text" name="cp[image_types][<?php echo $type ?>][dimensions][height]" value="<?php echo $height ?>" size="5" />
</td>
</tr>
<?php do_action('comicpress_image_type_holder') ?>
</table>
</div>

View File

@ -5,8 +5,8 @@
<h3><?php _e('Global Options', 'comicpress') ?></h3> <h3><?php _e('Global Options', 'comicpress') ?></h3>
<table class="widefat fixed"> <table class="widefat fixed">
<tr> <tr>
<th scope="row" valign="top"><?php _e("Arrange storyline category order", 'comicpress') ?></th> <th width="25%" scope="row" valign="top"><?php _e("Arrange storyline category order", 'comicpress') ?></th>
<td> <td width="75%">
<input type="hidden" name="cp[storyline_order]" /> <input type="hidden" name="cp[storyline_order]" />
<div id="storyline-sorter" class="cp-children"> <div id="storyline-sorter" class="cp-children">
<?php <?php
@ -17,19 +17,17 @@
<p><em><?php _e('(drag and drop desired order. categories can be modified on the Posts -> Categories page)', 'comicpress') ?></em></p> <p><em><?php _e('(drag and drop desired order. categories can be modified on the Posts -> Categories page)', 'comicpress') ?></em></p>
</td> </td>
</tr> </tr>
<?php foreach (array(
'comic_dimensions' => __('Comic Image Dimensions', 'comicpress'),
'rss_dimensions' => __('RSS Feed Image Dimensions', 'comicpress'),
'archive_dimensions' => __('Archive Image Dimensions', 'comicpress'),
'mini_dimensions' => __('Mini Image Dimensions', 'comicpress'),
) as $field => $name) { ?>
<tr> <tr>
<th scope="row" valign="top"><?php echo $name ?></th> <th scope="row" valign="top"><?php _e('Set up comic image types', 'comicpress') ?></th>
<td> <td>
<?php echo $this->create_dimension_selector('cp[' . $field . ']', $this->comicpress->comicpress_options[$field]) ?> <div id="image-type-container">
<?php foreach ($this->comicpress->comicpress_options['image_types'] as $type => $info) { ?>
<?php include('_image-type-editor.inc'); ?>
<?php } ?>
</div>
<a id="add-new-image-type">Add a new image type</a>
</td> </td>
</tr> </tr>
<?php } ?>
</table> </table>
<h3><?php _e('Admin Options', 'comicpress') ?></h3> <h3><?php _e('Admin Options', 'comicpress') ?></h3>
<table class="widefat fixed"> <table class="widefat fixed">

View File

@ -70,3 +70,27 @@
display: block; display: block;
margin: 8px 0 0 8px; margin: 8px 0 0 8px;
} }
.image-type-holder {
border: solid #aaa 1px;
margin: 10px 0;
padding: 5px;
}
.image-type-holder table {
width: 90%
}
.image-type-editor-name input {
font-size: 1.5em;
width: 100%
}
.delete-image-type {
float: right;
display: inline;
padding: 3px;
border: solid #aaa 1px;
font-weight: bold;
color: #aaa
}

View File

@ -34,12 +34,12 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
), ),
array( array(
'image_types' => array( 'image_types' => array(
'comic' => array('default' => 'yes', 'dimensions' => array('width' => '100', 'height' => '100')) 'comic' => array('default' => 'yes', 'name' => 'Test', 'dimensions' => array('width' => '100', 'height' => '100'))
) )
), ),
array( array(
'image_types' => array( 'image_types' => array(
'comic' => array('default' => true, 'dimensions' => '100x100') 'comic' => array('default' => true, 'name' => 'Test', 'dimensions' => '100x100')
) )
) )
), ),
@ -98,6 +98,23 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
) )
) )
), ),
array(
array(
'image_types' => array(
'comic' => array('default' => true, 'dimensions' => '500x50'),
)
),
array(
'image_types' => array(
'comic' => array('short_name' => 'newcomic', 'dimensions' => array('width' => '100', 'height' => '100')),
)
),
array(
'image_types' => array(
'newcomic' => array('default' => true, 'dimensions' => '100x100'),
)
)
)
); );
} }