diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 17ae07d..cadcbc1 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -31,7 +31,7 @@ class ComicPress { ), 'helpers' => array(), 'storyline_order' => '', - 'active_backends' => null + 'enabled_backends' => null ); var $backends = array(); @@ -156,19 +156,42 @@ class ComicPress { $this->normalize_image_size_options(); + $this->reset_backend_admin(); + foreach ($this->normalize_active_backends() as $class) { $this->backends[] = new $class(); + + $admin_class = preg_replace('#Factory$#', 'Admin', $class); + if (class_exists($admin_class)) { + if (method_exists($admin_class, 'actions')) { + foreach (call_user_func(array($admin_class, 'actions')) as $options) { + call_user_func_array('add_action', $options); + } + } + } } } + function reset_backend_admin() { + foreach ($this->_get_declared_classes() as $class) { + if (preg_match('#^ComicPressBackend(.*)Admin$#', $class)) { + if (method_exists($class, 'actions')) { + foreach (call_user_func(array($class, 'actions')) as $options) { + call_user_func_array('remove_action', $options); + } + } + } + } + } + function normalize_active_backends() { - if (!is_array($this->comicpress_options['active_backends'])) { - $this->comicpress_options['active_backends'] = array(); + if (!is_array($this->comicpress_options['enabled_backends'])) { + $this->comicpress_options['enabled_backends'] = $this->get_valid_backends(); } - $this->comicpress_options['active_backends'] = array_intersect($this->get_valid_backends(), $this->comicpress_options['active_backends']); + $this->comicpress_options['enabled_backends'] = array_intersect($this->get_valid_backends(), $this->comicpress_options['enabled_backends']); - return $this->comicpress_options['active_backends']; + return $this->comicpress_options['enabled_backends']; } function get_valid_backends() { diff --git a/classes/ComicPressAdmin.inc b/classes/ComicPressAdmin.inc index b4222e6..ba9c0d9 100644 --- a/classes/ComicPressAdmin.inc +++ b/classes/ComicPressAdmin.inc @@ -167,6 +167,8 @@ class ComicPressAdmin { $storyline->normalize(); $storyline->read_from_options(); + $backends = $this->comicpress->get_valid_backends(); + include(dirname(__FILE__) . '/partials/options-admin.inc'); } @@ -389,6 +391,9 @@ class ComicPressAdmin { $storyline->normalize($info[$option]); break; // @codeCoverageIgnoreEnd + case 'enabled_backends': + $this->comicpress->comicpress_options['enabled_backends'] = array_intersect(array_keys($info[$option]), $this->comicpress->get_valid_backends()); + break; } } } diff --git a/classes/ComicPressTagBuilder.inc b/classes/ComicPressTagBuilder.inc new file mode 100644 index 0000000..855e145 --- /dev/null +++ b/classes/ComicPressTagBuilder.inc @@ -0,0 +1,49 @@ +storyline = new ComicPressStoryline(); + $this->storyline->read_from_options(); + + if (is_null($dbi)) { + $this->dbi = ComicPressDBInterface::get_instance(); + } else { + $this->dbi = $dbi; + } + } + + public function __call($method, $arguments) { + global $post; + + $a = new ComicPressTagBuilder($post, $this->storyline, $this->dbi); + return call_user_func_array(array($a, $method), $arguments); + } +} + +class ComicPressTagBuilder { + public $categories, $restrictions, $storyline, $dbi, $parent_post, $post; + + public function __construct($parent_post, $storyline, $dbi) { + $this->restrictions = array(); + $this->storyline = $storyline; + $this->dbi = $dbi; + $this->parent_post = $parent_post; + } + + public function __call($method, $arguments) { + switch ($method) { + case 'next': + case 'previous': + case 'first': + case 'last': + $this->post = call_user_func(array($this->dbi, "get_${method}_post"), $this->storyline->build_from_restrictions($this->restrictions), $this->parent_post); + break; + } + + return $this; + } +} diff --git a/classes/backends/ComicPressBackendFilesystem.inc b/classes/backends/ComicPressBackendFilesystem.inc index f014177..a6824fc 100644 --- a/classes/backends/ComicPressBackendFilesystem.inc +++ b/classes/backends/ComicPressBackendFilesystem.inc @@ -8,6 +8,10 @@ class ComicPressBackendFilesystem extends ComicPressBackend { } class ComicPressBackendFilesystemFactory { + function __construct() { + $this->description = __('Uses files on the filesystem as comic images, similar to ComicPress Legacy.', 'comicpress'); + } + function generate_from_id($id) { if (preg_match('#^filesystem-([0-9]+)-(.*)$#', $id, $matches) > 0) { list($all, $post_id, $root) = $matches; @@ -239,10 +243,6 @@ 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(); @@ -287,9 +287,13 @@ class ComicPressBackendFilesystemAdmin { $comicpress->save(); } } + + function actions() { + return array( + array('comicpress-options-admin', array('ComicPressBackendFilesystemAdmin', 'options_admin')), + array('comicpress-image-type-holder', array('ComicPressBackendFilesystemAdmin', 'image_type_holder'), 10, 1), + array('comicpress-handle_update_comicpress_options', array('ComicPressBackendFilesystemAdmin', 'handle_update_comicpress_options'), 10, 1) + ); + } } // @codeCoverageIgnoreEnd - -add_action('comicpress-options-admin', array('ComicPressBackendFilesystemAdmin', 'options_admin')); -add_action('comicpress-image-type-holder', array('ComicPressBackendFilesystemAdmin', 'image_type_holder'), 10, 1); -add_action('comicpress-handle_update_comicpress_options', array('ComicPressBackendFilesystemAdmin', 'handle_update_comicpress_options'), 10, 1); diff --git a/classes/backends/ComicPressBackendURL.inc b/classes/backends/ComicPressBackendURL.inc index 774b30f..d9d6cef 100644 --- a/classes/backends/ComicPressBackendURL.inc +++ b/classes/backends/ComicPressBackendURL.inc @@ -149,8 +149,12 @@ class ComicPressBackendURLAdmin { } } // @codeCoverageIgnoreEnd -} -add_action('admin_menu', array('ComicPressBackendURLAdmin', 'admin_menu')); -add_action('comicpress-handle_update_backend_url_new_editor', array('ComicPressBackendURLAdmin', 'handle_update_backend_url_new_editor')); -add_action('save_post', array('ComicPressBackendURLAdmin', 'save_post'), 10, 1); + function actions() { + return array( + array('admin_menu', array('ComicPressBackendURLAdmin', 'admin_menu')), + array('comicpress-handle_update_backend_url_new_editor', array('ComicPressBackendURLAdmin', 'handle_update_backend_url_new_editor')), + array('save_post', array('ComicPressBackendURLAdmin', 'save_post'), 10, 1) + ); + } +} diff --git a/classes/partials/options-admin.inc b/classes/partials/options-admin.inc index b4e0bf4..b3324ad 100644 --- a/classes/partials/options-admin.inc +++ b/classes/partials/options-admin.inc @@ -1,5 +1,5 @@