add support for editor helpers, starting with partials

This commit is contained in:
John Bintz 2009-07-27 22:09:20 -04:00
parent 9f963e1fbd
commit a2e5159a58
4 changed files with 81 additions and 8 deletions

View File

@ -5,7 +5,7 @@ class ComicPressAddonCore extends ComicPressAddon {
* Initialize the addon.
* @param ComicPress $comicpress The master ComicPress object.
*/
function init($comicpress) {
function init(&$comicpress) {
add_action('admin_menu', array(&$this, 'setup_admin_interface'));
add_filter('attachment_fields_to_edit', array(&$this, 'setup_comic_metadata_buttons'), 10, 2);
add_action('show_comic', array(&$this, 'show_comic'), 1, 1);
@ -372,6 +372,7 @@ class ComicPressAddonCore extends ComicPressAddon {
* Update ComicPress options.
*/
function handle_update_comicpress_options() {
$this->comicpress->comicpress_options['helpers'] = array();
foreach ($this->comicpress->comicpress_options as $option => $value) {
if (isset($_POST['cp'][$option])) {
switch ($option) {
@ -416,6 +417,11 @@ class ComicPressAddonCore extends ComicPressAddon {
case 'layout';
$this->comicpress->comicpress_options[$option] = $_POST['cp'][$option];
break;
case 'helpers':
foreach ($_POST['cp'][$option] as $helper => $set) {
$this->comicpress->comicpress_options['helpers'][$helper] = true;
}
break;
}
}
}

View File

@ -2,7 +2,8 @@
<h2><?php _e('ComicPress Config', 'comicpress') ?></h2>
<form method="post">
<input type="hidden" name="cp[_nonce]" value="<?php echo $nonce ?>" />
<table>
<h3><?php _e('Global Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<th scope="row" valign="top"><?php _e('Master Comic Category', 'comicpress') ?></th>
<td>
@ -93,10 +94,23 @@
<?php } ?>
</td>
</tr>
</table>
<h3><?php _e('Admin Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="<?php _e("Submit Changes", 'comicpress') ?>" /></td>
<th scope="row">
Enable editing helpers
</th>
<td>
<?php
foreach (array(
"show_partials_info" => __('Show partials info', 'comicpress')
) as $key => $label) { ?>
<label><input type="checkbox" name="cp[helpers][<?php echo $key ?>]" value="yes" <?php echo (($this->comicpress->comicpress_options['helpers'][$key] === true) ? 'checked="checked"' : '') ?> /> <?php echo $label ?></label>
<?php }
?>
</td>
</tr>
</table>
</form>
<input type="submit" value="<?php _e("Submit Changes", 'comicpress') ?>" /> </form>
</div>

View File

@ -14,7 +14,8 @@ class ComicPress {
'blogpost_count' => 10,
'comic_space' => 'comic_only',
'category_page_usage' => 'archive_list',
'layout' => 'classic.inc'
'layout' => 'classic.inc',
'helpers' => array()
);
var $additional_stylesheets = array();
@ -56,6 +57,17 @@ class ComicPress {
$this->sort_comic_categories();
add_action('wp_head', array(&$this, 'wp_head'));
if (current_user_can('edit_themes')) {
if (!empty($this->comicpress_options['helpers'])) {
if (isset($this->comicpress_options['helpers']['show_partials_info'])) {
add_filter('comicpress_partial', array(&$this, 'comicpress_partial'), 10, 2);
add_action('wp_head', array(&$this, 'setup_comicpress_partial'));
}
add_action('wp_footer', array(&$this, 'announce_activated_helpers'));
}
}
}
function wp_head() {
@ -67,6 +79,43 @@ class ComicPress {
<?php }
}
function announce_activated_helpers() {
echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>";
}
function setup_comicpress_partial() { ?>
<style type="text/css">
.partial-helper {
position: absolute;
z-index: 100;
padding: 4px;
border: solid #333 1px;
background-color: #447;
opacity: 0.1;
-moz-opacity: 0.1;
-khtml-opacity: 0.1;
zoom: 1;
cursor: crosshair
}
.partial-helper:hover {
opacity: 1;
-moz-opacity: 1;
-khtml-opacity: 1;
}
</style>
<!--[if IE gte 6]>
<style type="text/css">
.partial-helper { filter: alpha(opacity=10); }
.partial-helper:hover { filter: alpha(opacity=100); }
</style>
<![endif]-->
<?php }
function comicpress_partial($content, $target) {
return '<div class="partial-helper">' . substr(realpath($target), strlen(realpath(get_template_directory())) + 1) . '</div>' . $content;
}
/**
* Flatten all WP categories into nodes like 0/3/5.
* @tested

View File

@ -95,7 +95,11 @@ function include_partial($partials = '') {
$target = $comicpress->get_partial_path($partials);
if ($target !== false) { include($target); }
if ($target !== false) {
ob_start();
include($target);
echo apply_filters("comicpress_partial", ob_get_clean(), $target);
}
}
function in_comic_category() {