working on backends

This commit is contained in:
John Bintz 2010-01-24 19:24:57 -05:00
parent cc1044392d
commit 3bec106b8a
9 changed files with 113 additions and 37 deletions

View File

@ -31,6 +31,7 @@ class ComicPress {
), ),
'helpers' => array(), 'helpers' => array(),
'storyline_order' => '', 'storyline_order' => '',
'active_backends' => null
); );
var $backends = array(); var $backends = array();
@ -141,6 +142,8 @@ class ComicPress {
} }
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
function _get_declared_classes() { return get_declared_classes(); }
// @codeCoverageIgnoreEnd
/** /**
* Initialize the class. * Initialize the class.
@ -153,12 +156,27 @@ class ComicPress {
$this->normalize_image_size_options(); $this->normalize_image_size_options();
foreach (get_declared_classes() as $class) { foreach ($this->normalize_active_backends() as $class) {
if (preg_match('#^ComicPressBackend.+Factory$#', $class) > 0) {
$this->backends[] = new $class(); $this->backends[] = new $class();
} }
} }
function normalize_active_backends() {
$available_backends = array();
foreach ($this->_get_declared_classes() as $class) {
if (preg_match('#^ComicPressBackend(.*)Factory$#', $class, $matches) > 0) {
$available_backends[] = $class;
} }
}
if (!is_array($this->comicpress_options['active_backends'])) {
$this->comicpress_options['active_backends'] = array();
}
$this->comicpress_options['active_backends'] = array_intersect($available_backends, $this->comicpress_options['active_backends']);
}
// @codeCoverageIgnoreStart
function announce_activated_helpers() { function announce_activated_helpers() {
echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>"; echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>";
@ -248,5 +266,3 @@ class ComicPress {
return false; return false;
} }
} }
?>

View File

@ -46,6 +46,10 @@ class ComicPressBackendAttachment extends ComicPressBackend {
} }
class ComicPressBackendAttachmentFactory { class ComicPressBackendAttachmentFactory {
function __construct() {
$this->description = __('Uses post attachments as comic images.', 'comicpress');
}
function generate_from_post($post) { function generate_from_post($post) {
$result = array(); $result = array();
if (is_object($post)) { if (is_object($post)) {
@ -71,7 +75,6 @@ class ComicPressBackendAttachmentFactory {
return $result; return $result;
} }
function generate_from_id($id) { function generate_from_id($id) {
if (strpos($id, 'attachment-') === 0) { if (strpos($id, 'attachment-') === 0) {
$id = str_replace('attachment-', '', $id); $id = str_replace('attachment-', '', $id);

View File

@ -239,6 +239,10 @@ class ComicPressBackendFilesystemFactory {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
class ComicPressBackendFilesystemAdmin { class ComicPressBackendFilesystemAdmin {
function __construct() {
$this->description = __('Uses files on the filesystem as comic images, similar to ComicPress Legacy.', 'comicpress');
}
function options_admin() { function options_admin() {
$pattern = ComicPressBackendFilesystemFactory::_get_search_pattern(); $pattern = ComicPressBackendFilesystemFactory::_get_search_pattern();

View File

@ -56,6 +56,10 @@ class ComicPressBackendURL extends ComicPressBackend {
} }
class ComicPressBackendURLFactory { class ComicPressBackendURLFactory {
function __construct() {
$this->description = __('Uses URLs assigned to posts as comic images.', 'comicpress');
}
function generate_from_id($id) { function generate_from_id($id) {
if (preg_match('#^url-([0-9]+)-(.+)$#', $id, $matches) > 0) { if (preg_match('#^url-([0-9]+)-(.+)$#', $id, $matches) > 0) {
list($all, $post_id, $key) = $matches; list($all, $post_id, $key) = $matches;

View File

@ -16,6 +16,7 @@
</p> </p>
<ul> <ul>
<li><?php _e('<strong>%wordpress%</strong>: the local path to the WordPress installation', 'comicpress') ?></li> <li><?php _e('<strong>%wordpress%</strong>: the local path to the WordPress installation', 'comicpress') ?></li>
<li><?php _e('<strong>%upload-path%</strong>: the value of the upload_path option, used by WMPU', 'comicpress') ?></li>
<li><?php _e('<strong>%type%</strong>: the image type short name', 'comicpress') ?></li> <li><?php _e('<strong>%type%</strong>: the image type short name', 'comicpress') ?></li>
<li><?php _e('<strong>%type-folder%</strong>: the image type folder', 'comicpress') ?></li> <li><?php _e('<strong>%type-folder%</strong>: the image type folder', 'comicpress') ?></li>
<li><?php _e('<strong>%date-(pattern)%</strong>: the date of the post as run through the date() function. Ex: <em>%date-Y-m-d%</em>', 'comicpress') ?></li> <li><?php _e('<strong>%date-(pattern)%</strong>: the date of the post as run through the date() function. Ex: <em>%date-Y-m-d%</em>', 'comicpress') ?></li>

View File

@ -0,0 +1,12 @@
<h3><?php _e('Comic Image Types', 'comicpress') ?></h3>
<div id="comicpress-image-types-holder" class="comicpress-holder">
<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" href="#">[+] Add a new image type</a>
<script type="text/javascript">ComicImageTypes.setup()</script>
<input class="button-primary" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" />
</div>

View File

@ -0,0 +1,17 @@
<h3>
<?php _e('Storyline Order', 'comicpress') ?>
</h3>
<div id="comicpress-storyline-category-order-holder" class="comicpress-holder">
<input type="hidden" name="cp[storyline_order]" value="" />
<div id="storyline-sorter">
<div class="cp-children">
<?php
$this->_render_admin_storyline_tree(reset($storyline->get_simple_storyline()))
?>
</div>
</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>
<input class="button-primary" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" />
</div>

View File

@ -5,36 +5,9 @@
<input type="hidden" name="cp[action]" value="comicpress-options" /> <input type="hidden" name="cp[action]" value="comicpress-options" />
<input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" /> <input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" />
<h3> <?php include('_storyline-order.inc') ?>
<?php _e('Storyline Order', 'comicpress') ?>
</h3>
<div id="comicpress-storyline-category-order-holder" class="comicpress-holder">
<input type="hidden" name="cp[storyline_order]" value="" />
<div id="storyline-sorter">
<div class="cp-children">
<?php
$this->_render_admin_storyline_tree(reset($storyline->get_simple_storyline()))
?>
</div>
</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>
<input class="button-primary" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" /> <?php include('_comic-image-types.inc') ?>
</div>
<h3><?php _e('Comic Image Types', 'comicpress') ?></h3>
<div id="comicpress-image-types-holder" class="comicpress-holder">
<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" href="#">[+] Add a new image type</a>
<script type="text/javascript">ComicImageTypes.setup()</script>
<input class="button-primary" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" />
</div>
<h3><?php _e('Active Components', 'comicpress') ?></h3> <h3><?php _e('Active Components', 'comicpress') ?></h3>
<div id="comicpress-active-components-holder" class="comicpress-holder"> <div id="comicpress-active-components-holder" class="comicpress-holder">

View File

@ -319,4 +319,50 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_result, $this->cp->get_default_image_type()); $this->assertEquals($expected_result, $this->cp->get_default_image_type());
} }
function testInit() {
$cp = $this->getMock('ComicPress', array('load', 'normalize_image_size_options', 'normalize_active_backends'));
$cp->comicpress_options = array(
'active_backends' => array('ComicPressBackendURLFactory')
);
$cp->expects($this->once())->method('load');
$cp->expects($this->once())->method('normalize_image_size_options');
$cp->expects($this->once())->method('normalize_active_backends')->will($this->returnValue(array(
'ComicPressBackendURLFactory'
)));
$cp->init();
$this->assertEquals(array(new ComicPressBackendURLFactory()), $cp->backends);
}
function providerTestNormalizeActiveBackends() {
return array(
array(
array(), array('ComicPressBackendBadFactory'), array()
),
array(
array('ComicPressBackendURLFactory'), array(), array()
),
array(
array('ComicPressBackendURLFactory'), array('ComicPressBackendURLFactory'), array('ComicPressBackendURLFactory')
),
);
}
/**
* @dataProvider providerTestNormalizeActiveBackends
*/
function testNormalizeActiveBackends($available_backends, $enabled_backends, $expected_backends) {
$cp = $this->getMock('ComicPress', array('_get_declared_classes'));
$cp->comicpress_options['active_backends'] = $enabled_backends;
$cp->expects($this->once())->method('_get_declared_classes')->will($this->returnValue($available_backends));
$cp->normalize_active_backends();
$this->assertEquals($expected_backends, $cp->comicpress_options['active_backends']);
}
} }