work on cleaning up sidebar rendering

This commit is contained in:
John Bintz 2009-06-18 07:26:27 -04:00
parent a02562d9b0
commit 65c1ed1fbb
3 changed files with 110 additions and 49 deletions

View File

@ -31,14 +31,38 @@ class ComicPressSidebarStandard extends ComicPressView {
}
}
function render() {
global $comicpress_manager;
function init() {
$this->_get_subdir_path();
$this->_all_comic_dates_ok();
$this->_get_thumbnail_generation_info();
}
function render() {
global $comicpress_manager, $comicpress_manager_admin;
import($this->_partial_path("sidebar"));
foreach (array(
'comiccat' => 'comic_category',
'blogcat' => 'blog_category'
) as $param => $field) {
$result = false;
if (isset($comicpress_manager->properties[$param])) {
$check = $comicpress_manager->properties[$param];
if (!is_array($check)) { $check = array($check); }
$result = array();
foreach ($check as $cat_id) {
$category = get_category($cat_id);
if (!is_wp_error($category)) {
$result[] = $category;
} else {
$result = false; break;
}
}
}
$this->{$field} = $result;
}
include($this->_partial_path("sidebar"));
}
function _get_thumbnail_generation_info() {

View File

@ -29,53 +29,48 @@
<?php foreach (array('archive' => __('Archive folder:', 'comicpress-manager'),
'rss' => __('RSS feed folder:', 'comicpress-manager'))
as $type => $title) { ?>
<li><strong><?php echo $title ?></strong> <?php echo $comicpress_manager->properties["${type}_comic_folder"] . $subdir_path; ?>
<?php if (
($comicpress_manager->scale_method !== false) &&
($comicpress_manager->get_cpm_option("cpm-${type}-generate-thumbnails") == 1) &&
($comicpress_manager->separate_thumbs_folder_defined[$type]) &&
($comicpress_manager->thumbs_folder_writable[$type])
) { ?>
(<em><?php _e('generating', 'comicpress-manager') ?></em>)
<?php } else {
$reasons = array();
if ($comicpress_manager->scale_method == false) { $reasons[] = __("No scaling software", 'comicpress-manager'); }
if ($comicpress_manager->get_cpm_option("cpm-${type}-generate-thumbnails") == 0) {
$reasons[] = __("Generation disabled", 'comicpress-manager');
<li>
<strong><?php echo $title ?></strong>
<?php echo $comicpress_manager->properties["${type}_comic_folder"] . $subdir_path; ?>
(<?php
if ($this->thumbnail_generation[$type] === true) {
echo "<em>";
_e('generating', 'comicpress-manager');
echo "</em>";
} else {
if (!$comicpress_manager->separate_thumbs_folder_defined[$type]) { $reasons[] = __("Same as comics folder", 'comicpress-manager'); }
if (!$comicpress_manager->thumbs_folder_writable[$type]) { $reasons[] = __("Not writable", 'comicpress-manager'); }
echo '<em style="cursor: help; text-decoration: underline" title="' . implode(", ", $this->thumbnail_generation[$type]) . '">';
_e('not generating', 'comicpress-manager');
echo "</em>";
}
?>
(<em style="cursor: help; text-decoration: underline" title="<?php echo implode(", ", $reasons) ?>">not generating</em>)
<?php } ?>
?>)
</li>
<?php } ?>
<li><strong>
<?php
if (is_array($comicpress_manager->properties['comiccat']) && count($comicpress_manager->properties['comiccat']) != 1) {
_e("Comic categories:", 'comicpress-manager');
} else {
_e("Comic category:", 'comicpress-manager');
}
?></strong>
<?php if (is_array($comicpress_manager->properties['comiccat'])) { ?>
<ul>
<?php foreach ($comicpress_manager->properties['comiccat'] as $cat_id) { ?>
<li><a href="<?php echo get_category_link($cat_id) ?>"><?php echo get_cat_name($cat_id) ?></a>
<?php printf(__('(ID %s)', 'comicpress-manager'), $cat_id) ?></li>
<?php } ?>
</ul>
<?php } else { ?>
<a href="<?php echo get_category_link($comicpress_manager->properties['comiccat']) ?>"><?php echo $comicpress_manager->category_info['comiccat']['name'] ?></a>
<?php printf(__('(ID %s)', 'comicpress-manager'), $comicpress_manager->properties['comiccat']) ?>
<?php } ?>
</li>
<li><strong><?php _e('Blog category:', 'comicpress-manager') ?></strong> <a href="<?php echo get_category_link($comicpress_manager->properties['blogcat']) ?>" ?>
<?php echo $comicpress_manager->category_info['blogcat']['name'] ?></a> <?php printf(__('(ID %s)', 'comicpress-manager'), $comicpress_manager->properties['blogcat']) ?></li>
<?php foreach (array('comic_category' => __("Comic categories:", 'comicpress-manager'),
'blog_category' => __("Blog categories:", 'comicpress-manager'))
as $type => $title) { ?>
<li>
<strong><?php echo $title ?></strong>
<?php if ($this->{$type} === false) { ?>
<em>Not defined!</em>
<?php } else { ?>
<?php if (is_array($comicpress_manager->properties['comiccat'])) { ?>
<ul>
<?php foreach ($comicpress_manager->properties['comiccat'] as $cat_id) { ?>
<li><a href="<?php echo get_category_link($cat_id) ?>"><?php echo get_cat_name($cat_id) ?></a>
<?php printf(__('(ID %s)', 'comicpress-manager'), $cat_id) ?></li>
<?php } ?>
</ul>
<?php } else { ?>
<a href="<?php echo get_category_link($comicpress_manager->properties['comiccat']) ?>"><?php echo $comicpress_manager->category_info['comiccat']['name'] ?></a>
<?php printf(__('(ID %s)', 'comicpress-manager'), $comicpress_manager->properties['comiccat']) ?>
<?php } ?>
<?php } ?>
</li>
<?php } ?>
<?php if (!function_exists('get_site_option')) { ?>
<li><strong><?php _e("PHP Version:", 'comicpress-manager') ?></strong> <?php echo phpversion() ?>
<?php if (substr(phpversion(), 0, 3) < 5.2) { ?>
@ -103,7 +98,7 @@
<?php } ?>
<li>
<strong><a href="#" onclick="Element.show('debug-info'); $('cpm-right-column').style.minHeight = $('cpm-left-column').offsetHeight + 'px'; return false"><?php _e('Show debug info', 'comicpress-manager') ?></a></strong> (<em><?php _e("this data is sanitized to protect your server's configuration", 'comicpress-manager') ?></em>)
<?php echo cpm_show_debug_info() ?>
<?php echo $comicpress_manager_admin->show_debug_info() ?>
</li>
<?php } ?>
</ul>

View File

@ -113,10 +113,52 @@ class ComicPressSidebarStandardTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($info['result'], $result);
}
function testRender() {
global $comicpress_manager;
function testRenderCategoryIssues() {
global $comicpress_manager, $comicpress_manager_admin;
//
$s = new ComicPressSidebarStandard();
$s->thumbnail_generation = array('rss' => true, 'archive' => array("test"));
$comicpress_manager_admin = $this->getMock('ComicPressManagerAdmin', array('show_debug_info'));
ob_start();
$s->render();
$source = ob_get_clean();
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
$this->assertFalse($s->comic_category);
$this->assertFalse($s->blog_category);
foreach (array(
'//em[text()="Not defined!"]/../strong[text()="Comic categories:"]' => true,
'//em[text()="Not defined!"]/../strong[text()="Blog categories:"]' => true,
) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
}
function testRenderGenerationStates() {
global $comicpress_manager, $comicpress_manager_admin;
add_category(1, (object)array('name' => 'Comics'));
add_category(2, (object)array('name' => 'Blog'));
$s = new ComicPressSidebarStandard();
$s->thumbnail_generation = array('rss' => true, 'archive' => array("test"));
$comicpress_manager_admin = $this->getMock('ComicPressManagerAdmin', array('show_debug_info'));
ob_start();
$s->render();
$source = ob_get_clean();
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
foreach (array(
) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
$this->markTestIncomplete();
}
}