diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc
index ed09760..85cae41 100644
--- a/addons/Core/Core.inc
+++ b/addons/Core/Core.inc
@@ -100,7 +100,8 @@ class ComicPressAddonCore extends ComicPressAddon {
* Set up the admin interface and meta boxes.
*/
function setup_admin_interface() {
- add_theme_page(__("ComicPress Core", 'comicpress'), __('ComicPress Core', 'comicpress'), 'edit_themes', basename(__FILE__), array(&$this, 'render_admin'));
+ add_theme_page(__("ComicPress Core", 'comicpress'), __('ComicPress Core', 'comicpress'), 'edit_themes', 'comicpress/render_admin', array(&$this, 'render_admin'));
+ add_theme_page(__("Edit Partials", 'comicpress'), __('Edit Partials', 'comicpress'), 'edit_themes', 'comicpress/edit_partials', array(&$this, 'render_edit_partials'));
if (isset($_REQUEST['post'])) {
add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low");
@@ -202,6 +203,12 @@ class ComicPressAddonCore extends ComicPressAddon {
include(dirname(__FILE__) . '/partials/options-admin.inc');
}
+
+ function render_edit_partials() {
+ $nonce = wp_create_nonce('comicpress');
+
+ include(dirname(__FILE__) . '/partials/edit-partials.inc');
+ }
/**
* Render the comic image ordering interface.
@@ -476,7 +483,18 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
}
-
+
+ function handle_update_override_partial($info) {
+ switch ($info['action']) {
+ case __('Update partial', 'comicpress'):
+ $this->comicpress->comicpress_options['override_partials'][$info['partial']] = $info['code'];
+ break;
+ case __('Delete override partial', 'comicpress'):
+ unset($this->comicpress->comicpress_options['override_partials'][$info['partial']]);
+ break;
+ }
+ }
+
/**
* Handle an update.
*/
@@ -503,6 +521,12 @@ class ComicPressAddonCore extends ComicPressAddon {
}
$this->handle_update_comic_ordering();
+ } else if (isset($_POST['cp']['partial'])) {
+ $this->handle_update_override_partial($_POST['cp']);
+ $this->info(sprintf(__("Partial %s updated.", 'comicpress'), $_POST['cp']['partial']));
+
+ $this->comicpress->save();
+ $this->comicpress->init();
} else {
//coming from us
$this->handle_update_comicpress_options();
@@ -513,7 +537,7 @@ class ComicPressAddonCore extends ComicPressAddon {
$this->comicpress->save();
- $this->info("ComicPress configuration updated.");
+ $this->info(__("ComicPress configuration updated.", 'comicpress'));
$this->comicpress->init();
}
diff --git a/addons/Core/partials/edit-partials.inc b/addons/Core/partials/edit-partials.inc
new file mode 100644
index 0000000..03bdc93
--- /dev/null
+++ b/addons/Core/partials/edit-partials.inc
@@ -0,0 +1,81 @@
+
+
Edit partials
+
+
+ 0) {
+ $valid_partials[] = $matches[1];
+ }
+ }
+
+ $selected = reset($valid_partials);
+ if (isset($_REQUEST['cp']['partial'])) {
+ if (in_array($_REQUEST['cp']['partial'], $valid_partials)) {
+ $selected = $_REQUEST['cp']['partial'];
+ }
+ }
+
+ echo '
';
+ foreach ($valid_partials as $partial_name) {
+ echo '- ';
+ if ($partial_name == $selected) { echo ''; }
+ echo '' . $partial_name . '';
+ if ($partial_name == $selected) { echo ''; }
+ echo '
';
+ }
+ echo '
';
+
+ $is_original = false;
+ if ($_REQUEST['cp']['action'] == __('Delete override partial', 'comicpress')) {
+ unset($_REQUEST['cp']['code']);
+ }
+
+ if (isset($_REQUEST['cp']['code'])) {
+ $partial_code = htmlentities($_REQUEST['cp']['code']);
+ } else {
+ if (isset($this->comicpress->comicpress_options['override_partials'][$selected])) {
+ $partial_code = htmlentities($this->comicpress->comicpress_options['override_partials'][$selected]);
+ } else {
+ $is_original = true;
+ $partial_code = htmlentities(file_get_contents(get_template_directory() . DIRECTORY_SEPARATOR . $selected . '.inc'));
+ }
+ }
+
+ ?>
+
+
+
+
diff --git a/addons/Core/test/CoreTest.php b/addons/Core/test/CoreTest.php
index cc3a7ca..ad7c0e6 100644
--- a/addons/Core/test/CoreTest.php
+++ b/addons/Core/test/CoreTest.php
@@ -15,7 +15,7 @@ class CoreTest extends PHPUnit_Framework_TestCase {
function testShowOptionsPage() {
$nonce = wp_create_nonce('comicpress');
- $this->core->comicpress = $this->getMock('ComicPress');
+ $this->core->comicpress = $this->getMock('ComicPress', array('get_layout_choices'));
$this->core->comicpress->expects($this->once())->method('get_layout_choices')->will($this->returnValue(array()));
ob_start();
@@ -388,6 +388,38 @@ class CoreTest extends PHPUnit_Framework_TestCase {
}
}
}
+
+ function providerTestHandleUpdateOverridePartial() {
+ return array(
+ array(
+ 'hello',
+ 'Update partial'
+ ),
+ array(
+ 'meow',
+ 'Delete override partial'
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider providerTestHandleUpdateOverridePartial
+ */
+ function testHandleUpdateOverridePartial($code, $action) {
+ $this->core->comicpress = (object)array(
+ 'comicpress_options' => array(
+ 'override_partials' => array(
+ 'index' => '$hiss;'
+ )
+ )
+ );
+
+ $this->core->handle_update_override_partial(array_merge(compact('code', 'action'), array('partial' => 'index')));
+
+ if ($result && $action == "Update partial") {
+ $this->assertEquals($code, $this->core->comicpress->comicpress_options['override_partials']['index']);
+ }
+ }
}
?>
diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc
index d98b710..e55c7ac 100644
--- a/classes/ComicPress.inc
+++ b/classes/ComicPress.inc
@@ -15,7 +15,8 @@ class ComicPress {
'comic_space' => 'comic_only',
'category_usage' => 'storyline',
'layout' => 'classic.inc',
- 'helpers' => array()
+ 'helpers' => array(),
+ 'override_partials' => array()
);
var $additional_stylesheets = array();
@@ -159,7 +160,7 @@ class ComicPress {
' . substr(realpath($target), strlen(realpath(get_template_directory())) + 1) . '' . $content;
+ return '' . str_replace(get_template_directory() . DIRECTORY_SEPARATOR, '', $target) . '
' . $content;
}
/**
@@ -461,6 +462,19 @@ class ComicPress {
return false;
}
+ function get_options_partial($partials) {
+ foreach ($partials as $partial) {
+ foreach ($this->partial_paths as $path) {
+ $target = str_replace(get_template_directory() . DIRECTORY_SEPARATOR, '', $path) . DIRECTORY_SEPARATOR . $partial;
+
+ if (isset($this->comicpress_options['override_partials'][$target])) {
+ return array($target, $this->comicpress_options['override_partials'][$target]);
+ }
+ }
+ }
+ return false;
+ }
+
/**
* Gather blog posts for the given index page.
*/
@@ -526,7 +540,7 @@ class ComicPress {
if (count($compare_parts) == count($parts)) {
$target_category = array_pop($compare_parts);
$parent_category = array_pop($compare_parts);
-
+
if (!isset($prev_next_categories[$parent_category])) {
$prev_next_categories[$parent_category] = array();
}
diff --git a/functions.php b/functions.php
index 743755e..1c09f3f 100644
--- a/functions.php
+++ b/functions.php
@@ -18,6 +18,12 @@ function __comicpress_init() {
$comicpress->init();
$addons = array();
+ if (get_magic_quotes_gpc()) {
+ $_POST = stripslashes_deep($_POST);
+ $_GET = stripslashes_deep($_GET);
+ $_REQUEST = stripslashes_deep($_REQUEST);
+ }
+
if (is_dir($addons_dir = (dirname(__FILE__) . '/addons'))) {
$entries = glob($addons_dir . '/*');
if (is_array($entries)) {
@@ -28,24 +34,26 @@ function __comicpress_init() {
require_once($entry . "/${classname}.inc");
$classname = "ComicPressAddon${classname}";
if (class_exists($classname)) {
- $addons[] = new $classname();
- end($addons)->init(&$comicpress);
+ $addon =& new $classname();
+
+ $addon->init(&$comicpress);
if (current_user_can('edit_posts')) {
if (is_array($_REQUEST['cp'])) {
if (isset($_REQUEST['cp']['_nonce'])) {
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
- if (method_exists(end($addons), 'handle_update')) {
- end($addons)->handle_update();
+ if (method_exists($addon, 'handle_update')) {
+ $addon->handle_update();
}
}
}
}
if (is_admin()) {
- add_action('admin_notices', array(end($addons), 'display_messages'));
+ add_action('admin_notices', array(&$addon, 'display_messages'));
} else {
- add_action('wp_head', array(end($addons), 'display_messages'));
+ add_action('wp_head', array(&$addon, 'display_messages'));
}
}
+ $addons[] = $addon;
}
}
}
@@ -83,16 +91,23 @@ function comicpress_get_header() {
function include_partial($partials = '') {
global $comicpress, $post, $nav_comics;
- if (!is_array($partials)) {
- $partials = func_get_args();
- }
-
- $target = $comicpress->get_partial_path($partials);
+ if (!is_array($partials)) { $partials = func_get_args(); }
- if ($target !== false) {
- ob_start();
- include($target);
- echo apply_filters("comicpress_partial", ob_get_clean(), $target);
+ $content = $target = null;
+
+ if (($result = $comicpress->get_options_partial($partials)) !== false) {
+ list($target, $code) = $result;
+ ob_start(); eval('?>' . $code . ''); $content = ob_get_clean();
+ } else {
+ $target = $comicpress->get_partial_path($partials);
+
+ if ($target !== false) {
+ ob_start(); include($target); $content = ob_get_clean();
+ }
+ }
+
+ if (!empty($target) && !empty($content)) {
+ echo apply_filters("comicpress_partial", $content, $target);
}
}
diff --git a/style.css b/style.css
index 5e07724..ae166e4 100644
--- a/style.css
+++ b/style.css
@@ -4,7 +4,7 @@ Theme URI: http://comicpress.org
Description: Publish a comic with WordPress. Development version. Visit the ComicPress Website.
Author: Tyler Martin, John Bintz, Philip Hofer
Author URI: http://comicpres.org/
-Version: 2.8-git
+Version: 2.999-git
.
The CSS, XHTML and design is released under GPL v3:
http://www.opensource.org/licenses/gpl-3.0.html
diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php
index 2ab9455..e75e6e9 100644
--- a/test/ComicPressTest.php
+++ b/test/ComicPressTest.php
@@ -423,6 +423,34 @@ FILE
$this->assertEquals(array('/subthemes/test-one'), $cp->partial_paths);
}
+
+ function providerTestGetOverridePartials() {
+ return array(
+ array(
+ array('partials'),
+ array('index'),
+ array('partials/index'),
+ array('partials/index', true)
+ ),
+ array(
+ array('partials'),
+ array('index'),
+ array('partials/single'),
+ false
+ )
+ );
+ }
+
+ /**
+ * @dataProvider providerTestGetOverridePartials
+ */
+ function testGetOverridePartials($partial_paths, $requested_partials, $override_partials, $expected_result) {
+ $this->cp->partial_paths = $partial_paths;
+ foreach ($override_partials as $partial) {
+ $this->cp->comicpress_options['override_partials'][$partial] = true;
+ }
+ $this->assertEquals($expected_result, $this->cp->get_options_partial($requested_partials));
+ }
}
?>
\ No newline at end of file