working on backends
This commit is contained in:
parent
cc1044392d
commit
3bec106b8a
|
@ -31,6 +31,7 @@ class ComicPress {
|
|||
),
|
||||
'helpers' => array(),
|
||||
'storyline_order' => '',
|
||||
'active_backends' => null
|
||||
);
|
||||
|
||||
var $backends = array();
|
||||
|
@ -141,6 +142,8 @@ class ComicPress {
|
|||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function _get_declared_classes() { return get_declared_classes(); }
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/**
|
||||
* Initialize the class.
|
||||
|
@ -153,13 +156,28 @@ class ComicPress {
|
|||
|
||||
$this->normalize_image_size_options();
|
||||
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if (preg_match('#^ComicPressBackend.+Factory$#', $class) > 0) {
|
||||
$this->backends[] = new $class();
|
||||
}
|
||||
}
|
||||
foreach ($this->normalize_active_backends() as $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() {
|
||||
echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>";
|
||||
}
|
||||
|
@ -248,5 +266,3 @@ class ComicPress {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -46,6 +46,10 @@ class ComicPressBackendAttachment extends ComicPressBackend {
|
|||
}
|
||||
|
||||
class ComicPressBackendAttachmentFactory {
|
||||
function __construct() {
|
||||
$this->description = __('Uses post attachments as comic images.', 'comicpress');
|
||||
}
|
||||
|
||||
function generate_from_post($post) {
|
||||
$result = array();
|
||||
if (is_object($post)) {
|
||||
|
@ -71,7 +75,6 @@ class ComicPressBackendAttachmentFactory {
|
|||
return $result;
|
||||
}
|
||||
|
||||
|
||||
function generate_from_id($id) {
|
||||
if (strpos($id, 'attachment-') === 0) {
|
||||
$id = str_replace('attachment-', '', $id);
|
||||
|
|
|
@ -239,6 +239,10 @@ class ComicPressBackendFilesystemFactory {
|
|||
|
||||
// @codeCoverageIgnoreStart
|
||||
class ComicPressBackendFilesystemAdmin {
|
||||
function __construct() {
|
||||
$this->description = __('Uses files on the filesystem as comic images, similar to ComicPress Legacy.', 'comicpress');
|
||||
}
|
||||
|
||||
function options_admin() {
|
||||
$pattern = ComicPressBackendFilesystemFactory::_get_search_pattern();
|
||||
|
||||
|
|
|
@ -56,6 +56,10 @@ class ComicPressBackendURL extends ComicPressBackend {
|
|||
}
|
||||
|
||||
class ComicPressBackendURLFactory {
|
||||
function __construct() {
|
||||
$this->description = __('Uses URLs assigned to posts as comic images.', 'comicpress');
|
||||
}
|
||||
|
||||
function generate_from_id($id) {
|
||||
if (preg_match('#^url-([0-9]+)-(.+)$#', $id, $matches) > 0) {
|
||||
list($all, $post_id, $key) = $matches;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
</p>
|
||||
<ul>
|
||||
<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-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>
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -5,36 +5,9 @@
|
|||
<input type="hidden" name="cp[action]" value="comicpress-options" />
|
||||
<input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" />
|
||||
|
||||
<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>
|
||||
<?php include('_storyline-order.inc') ?>
|
||||
|
||||
<input class="button-primary" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" />
|
||||
</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>
|
||||
<?php include('_comic-image-types.inc') ?>
|
||||
|
||||
<h3><?php _e('Active Components', 'comicpress') ?></h3>
|
||||
<div id="comicpress-active-components-holder" class="comicpress-holder">
|
||||
|
|
|
@ -319,4 +319,50 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue