add comicpress options and start dimension selector bits

This commit is contained in:
John Bintz 2009-07-05 15:46:32 -04:00
parent d8a8a9aa2a
commit c8db41accf
3 changed files with 52 additions and 4 deletions

View File

@ -1,8 +1,16 @@
<?php
class ComicPressOptionsAdmin {
var $comicpress_options = array(
'comic_category_id' => 1,
'thumbnail_dimensions' => '760x'
);
function render_admin() {
$nonce = wp_create_nonce('comicpress');
$root_categories = $this->get_root_categories();
$this->get_comicpress_options();
include(dirname(__FILE__) . '/partials/options-admin.inc');
}
@ -42,6 +50,34 @@ class ComicPressOptionsAdmin {
}
return implode("\n", $output);
}
function create_dimension_selector($root, $dimension) {
$output = array();
$parts = explode("x", $dimension);
foreach (array(
'width' => __('Width', 'comicpress'),
'height' => __('Height', 'comicpress')
) as $id => $name) {
$dim = array_shift($parts);
if (!empty($dim) && !is_numeric($dim)) { $dim = ""; }
$output[] = '<label>' . $name . ': <input type="text" name="' . $root . '[' . $id . ']" value="' . $dim . '" /></label>';
}
return implode("\n", $output);
}
function get_comicpress_options() {
$result = get_option('comicpress-options');
if (is_array($result)) {
$this->comicpress_options = $result;
}
}
function update_comicpress_options() {
if (is_array($this->comicpress_options)) {
update_option('comicpress-options', $this->comicpress_options);
}
}
}
$comicpress_options_admin = new ComicPressOptionsAdmin();

View File

@ -6,7 +6,8 @@
<tr>
<th scope="row">Master Comic Category</th>
<td>
<select name="cp[comiccat]">
<select name="cp[comic_category_id]">
<?php echo $this->create_category_options($root_categories, $this->comicpress_options['comicpress_category_id']) ?>
</select>
</td>
</tr>

View File

@ -20,7 +20,7 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(($xml = _to_xml($source)) !== false);
foreach (array(
'//input[@name="cp[_nonce]" and @value="' . $nonce . '"]' => true,
'//select[@name="cp[comiccat]"]' => true
'//select[@name="cp[comic_category_id]"]' => true
) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
@ -67,8 +67,6 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
var_dump($source);
foreach (array(
'//option[@value="1" and @selected="selected"]' => "test-one",
'//option[@value="2"]' => "test-two",
@ -77,6 +75,19 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase {
}
}
}
function testCreateDimensionSelector() {
$source = $this->admin->create_dimension_selector("test", "760x340");
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
foreach (array(
'//input[@name="test[width]" and @value="760"]' => true,
'//input[@name="test[height]" and @value="340"]' => true,
) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
}
}
?>