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) {
if (preg_match('#^ComicPressBackend.+$#', $class) > 0) {
$this->backends[] = new $class();
$this->backends[] = $class;
}
}
}

View File

@ -246,20 +246,26 @@ class ComicPressAdmin {
$defined_default = null;
foreach ($info['image_types'] as $type => $image_info) {
if (is_array($image_info)) {
$new_value = array();
$new_type = $type;
foreach ($image_info as $field => $field_value) {
$new_value = array();
switch ($field) {
case "default": $defined_default = $type; break;
case "dimensions":
case 'default': $defined_default = $type; break;
case 'dimensions':
if (is_array($field_value)) {
if (count(array_intersect(array('width', 'height'), array_keys($field_value))) == 2) {
$new_value['dimensions'] = "{$field_value['width']}x{$field_value['height']}";
}
}
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() {
if (isset($_POST['post_ID'])) {
if (is_numeric($_POST['post_ID'])) {

View File

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

@ -1,83 +1,81 @@
<div class="wrap">
<h2><?php _e('ComicPress Config', 'comicpress') ?></h2>
<form method="post">
<input type="hidden" name="cp[_nonce]" value="<?php echo $nonce ?>" />
<h3><?php _e('Global Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<th scope="row" valign="top"><?php _e("Arrange storyline category order", 'comicpress') ?></th>
<td>
<h2><?php _e('ComicPress Config', 'comicpress') ?></h2>
<form method="post">
<input type="hidden" name="cp[_nonce]" value="<?php echo $nonce ?>" />
<h3><?php _e('Global Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<th width="25%" scope="row" valign="top"><?php _e("Arrange storyline category order", 'comicpress') ?></th>
<td width="75%">
<input type="hidden" name="cp[storyline_order]" />
<div id="storyline-sorter" class="cp-children">
<?php
<?php
$this->_render_admin_storyline_tree(reset($storyline->get_simple_storyline()))
?>
</div>
<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>
</td>
</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>
<th scope="row" valign="top"><?php echo $name ?></th>
<td>
<?php echo $this->create_dimension_selector('cp[' . $field . ']', $this->comicpress->comicpress_options[$field]) ?>
</td>
</tr>
<?php } ?>
</table>
<h3><?php _e('Admin Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<th scope="row"><?php _e('Enable editing helpers', 'comicpress') ?></th>
<td>
<?php
foreach (array(
"show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress')
) as $key => $label) { ?>
<label>
<input type="checkbox"
name="cp[helpers][<?php echo $key ?>]"
value="yes"
<?php echo (($this->comicpress->comicpress_options['helpers'][$key] === true) ? 'checked="checked"' : '') ?> />
<?php echo $label ?>
</label>
<br />
<?php }
?>
</td>
</tr>
<?php if (is_array($this->all_addons)) { ?>
<tr>
<th scope="row"><?php _e('Enable addons', 'comicpress') ?></th>
<td>
<?php
foreach ($this->all_addons as $addon) {
if (!empty($addon->name)) {
$enabled = ($addon->is_addon_manager !== true);
$checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name];
?>
<p><em><?php _e('(drag and drop desired order. categories can be modified on the Posts -> Categories page)', 'comicpress') ?></em></p>
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e('Set up comic image types', 'comicpress') ?></th>
<td>
<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>
</tr>
</table>
<h3><?php _e('Admin Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<th scope="row"><?php _e('Enable editing helpers', 'comicpress') ?></th>
<td>
<?php
foreach (array(
"show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress')
) as $key => $label) { ?>
<label>
<input type="checkbox"
name="cp[helpers][<?php echo $key ?>]"
value="yes"
<?php echo (($this->comicpress->comicpress_options['helpers'][$key] === true) ? 'checked="checked"' : '') ?> />
<?php echo $label ?>
</label>
<br />
<?php }
?>
</td>
</tr>
<?php if (is_array($this->all_addons)) { ?>
<tr>
<th scope="row"><?php _e('Enable addons', 'comicpress') ?></th>
<td>
<?php
foreach ($this->all_addons as $addon) {
if (!empty($addon->name)) {
$enabled = ($addon->is_addon_manager !== true);
$checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name];
?>
<label>
<input type="checkbox"
name="cp[addons][<?php echo $addon->name ?>]"
value="yes"
<?php echo !$enabled ? 'disabled="disabled"' : '' ?>
<?php echo $checked ? 'checked="checked"' : '' ?> />
<?php echo $addon->name ?>
</label><br />
<?php }
}
?>
</td>
</tr>
<?php } ?>
</table>
<input class="button" type="submit" value="<?php _e('Submit Changes', 'comicpress') ?>" />
</form>
<label>
<input type="checkbox"
name="cp[addons][<?php echo $addon->name ?>]"
value="yes"
<?php echo !$enabled ? 'disabled="disabled"' : '' ?>
<?php echo $checked ? 'checked="checked"' : '' ?> />
<?php echo $addon->name ?>
</label><br />
<?php }
}
?>
</td>
</tr>
<?php } ?>
</table>
<input class="button" type="submit" value="<?php _e('Submit Changes', 'comicpress') ?>" />
</form>
</div>

View File

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