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)) {
$new_value = array();
$new_type = $type;
foreach ($image_info as $field => $field_value) { foreach ($image_info as $field => $field_value) {
$new_value = array();
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,100 +1,111 @@
<?php <?php
class ComicPressDBInterface { class ComicPressDBInterface {
var $_non_comic_categories, $_all_categories;
function ComicPressDBInterface() {} function ComicPressDBInterface() {}
function get_instance() { function get_instance() {
static $instance; static $instance;
if (!isset($instance)) { $instance = new ComicPressDBInterface(); } if (!isset($instance)) { $instance = new 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.
*/
function set_comic_categories($categories) {
$this->_all_categories = get_all_category_ids();
$this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories));
}
$terminal_comic_query = new WP_Query(); 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;
}
}
$query_parameters = array( /**
'showposts' => 1, * Find the terminal post in a specific category.
'order' => $first ? "asc" : "desc", */
'status' => 'publish' function get_terminal_post_in_category($category_id, $first = true) {
); $this->_prepare_wp_query();
if (is_array($include_categories)) { $sort_order = $first ? "asc" : "desc";
$query_parameters['category_in'] = $include_categories; $terminal_comic_query = new WP_Query();
} $terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish");
$post = false;
if ($terminal_comic_query->have_posts()) {
$post = reset($terminal_comic_query->posts);
}
$terminal_comic_query->query($query_parameters); $this->_reset_wp_query();
$post = false; return $post;
if ($terminal_comic_query->have_posts()) { }
$post = reset($terminal_comic_query->posts);
}
$this->_reset_wp_query(); /**
return $post; * Get the first comic in a category.
} */
function get_first_comic($category_id) {
return $this->get_terminal_post_in_category($category_id);
}
/** /**
* Get the first comic in a category. * Get the last comic in a category.
*/ */
function get_first_post($include_categories = null) { function get_last_comic($category_id) {
return $this->get_terminal_post(true, $include_categories); return $this->get_terminal_post_in_category($category_id, false);
} }
/** /**
* Get the last comic in a category. * Get the comic post adjacent to the current comic.
*/ * Wrapper around get_adjacent_post(). Don't unit test this method.
function get_last_post($include_categories = null) { */
return $this->get_terminal_post(false, $include_categories); function get_adjacent_comic($category, $next = false, $override_post = null) {
} global $post;
/** $this->_prepare_wp_query();
* Get the comic post adjacent to the current comic. if (!is_null($override_post)) { $temp_post = $post; $post = $override_post; }
* Wrapper around get_adjacent_post(). Don't unit test this method.
*/
function get_adjacent_post($categories = array(), $next = false, $override_post = null) {
global $post;
$this->_prepare_wp_query(); $result = get_adjacent_post(false, implode(" and ", $this->_get_categories_to_exclude($category)), !$next);
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); $this->_reset_wp_query();
if (!is_null($override_post)) { $post = $temp_post; }
$this->_reset_wp_query(); return empty($result) ? false : $result;
if (!is_null($override_post)) { $post = $temp_post; } }
return empty($result) ? false : $result; function _prepare_wp_query() {
} global $wp_query;
function _prepare_wp_query() { $this->is_single = $wp_query->is_single;
global $wp_query; $this->in_the_loop = $wp_query->in_the_loop;
$this->is_single = $wp_query->is_single; $wp_query->is_single = $wp_query->in_the_loop = true;
$this->in_the_loop = $wp_query->in_the_loop; }
$wp_query->is_single = $wp_query->in_the_loop = true; function _reset_wp_query() {
} global $wp_query;
function _reset_wp_query() { $wp_query->is_single = $this->is_single;
global $wp_query; $wp_query->in_the_loop = $this->in_the_loop;
}
$wp_query->is_single = $this->is_single; /**
$wp_query->in_the_loop = $this->in_the_loop; * Get the previous comic from the current one.
} */
function get_previous_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, false, $override_post); }
/** /**
* Get the previous comic from the current one. * Get the next 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_next_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, true, $override_post); }
/**
* 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); }
} }
// @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

@ -1,83 +1,81 @@
<div class="wrap"> <div class="wrap">
<h2><?php _e('ComicPress Config', 'comicpress') ?></h2> <h2><?php _e('ComicPress Config', 'comicpress') ?></h2>
<form method="post"> <form method="post">
<input type="hidden" name="cp[_nonce]" value="<?php echo $nonce ?>" /> <input type="hidden" name="cp[_nonce]" value="<?php echo $nonce ?>" />
<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
$this->_render_admin_storyline_tree(reset($storyline->get_simple_storyline())) $this->_render_admin_storyline_tree(reset($storyline->get_simple_storyline()))
?> ?>
</div> </div>
<script type="text/javascript">Storyline.setup()</script> <script type="text/javascript">Storyline.setup()</script>
<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( <tr>
'comic_dimensions' => __('Comic Image Dimensions', 'comicpress'), <th scope="row" valign="top"><?php _e('Set up comic image types', 'comicpress') ?></th>
'rss_dimensions' => __('RSS Feed Image Dimensions', 'comicpress'), <td>
'archive_dimensions' => __('Archive Image Dimensions', 'comicpress'), <div id="image-type-container">
'mini_dimensions' => __('Mini Image Dimensions', 'comicpress'), <?php foreach ($this->comicpress->comicpress_options['image_types'] as $type => $info) { ?>
) as $field => $name) { ?> <?php include('_image-type-editor.inc'); ?>
<tr> <?php } ?>
<th scope="row" valign="top"><?php echo $name ?></th> </div>
<td> <a id="add-new-image-type">Add a new image type</a>
<?php echo $this->create_dimension_selector('cp[' . $field . ']', $this->comicpress->comicpress_options[$field]) ?> </td>
</td> </tr>
</tr> </table>
<?php } ?> <h3><?php _e('Admin Options', 'comicpress') ?></h3>
</table> <table class="widefat fixed">
<h3><?php _e('Admin Options', 'comicpress') ?></h3> <tr>
<table class="widefat fixed"> <th scope="row"><?php _e('Enable editing helpers', 'comicpress') ?></th>
<tr> <td>
<th scope="row"><?php _e('Enable editing helpers', 'comicpress') ?></th> <?php
<td> foreach (array(
<?php "show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress')
foreach (array( ) as $key => $label) { ?>
"show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress') <label>
) as $key => $label) { ?> <input type="checkbox"
<label> name="cp[helpers][<?php echo $key ?>]"
<input type="checkbox" value="yes"
name="cp[helpers][<?php echo $key ?>]" <?php echo (($this->comicpress->comicpress_options['helpers'][$key] === true) ? 'checked="checked"' : '') ?> />
value="yes" <?php echo $label ?>
<?php echo (($this->comicpress->comicpress_options['helpers'][$key] === true) ? 'checked="checked"' : '') ?> /> </label>
<?php echo $label ?> <br />
</label> <?php }
<br /> ?>
<?php } </td>
?> </tr>
</td> <?php if (is_array($this->all_addons)) { ?>
</tr> <tr>
<?php if (is_array($this->all_addons)) { ?> <th scope="row"><?php _e('Enable addons', 'comicpress') ?></th>
<tr> <td>
<th scope="row"><?php _e('Enable addons', 'comicpress') ?></th> <?php
<td> foreach ($this->all_addons as $addon) {
<?php if (!empty($addon->name)) {
foreach ($this->all_addons as $addon) { $enabled = ($addon->is_addon_manager !== true);
if (!empty($addon->name)) { $checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name];
$enabled = ($addon->is_addon_manager !== true); ?>
$checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name];
?>
<label> <label>
<input type="checkbox" <input type="checkbox"
name="cp[addons][<?php echo $addon->name ?>]" name="cp[addons][<?php echo $addon->name ?>]"
value="yes" value="yes"
<?php echo !$enabled ? 'disabled="disabled"' : '' ?> <?php echo !$enabled ? 'disabled="disabled"' : '' ?>
<?php echo $checked ? 'checked="checked"' : '' ?> /> <?php echo $checked ? 'checked="checked"' : '' ?> />
<?php echo $addon->name ?> <?php echo $addon->name ?>
</label><br /> </label><br />
<?php } <?php }
} }
?> ?>
</td> </td>
</tr> </tr>
<?php } ?> <?php } ?>
</table> </table>
<input class="button" type="submit" value="<?php _e('Submit Changes', 'comicpress') ?>" /> <input class="button" type="submit" value="<?php _e('Submit Changes', 'comicpress') ?>" />
</form> </form>
</div> </div>

View File

@ -69,4 +69,28 @@
height: 16px; height: 16px;
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'),
)
)
)
); );
} }