inline image ordering

This commit is contained in:
John Bintz 2009-08-03 21:28:59 -04:00
parent 2ce436ef45
commit 1f230256fe
5 changed files with 84 additions and 32 deletions

View File

@ -17,6 +17,11 @@ class ComicPressAddonCore extends ComicPressAddon {
add_action('template_redirect', array(&$this, 'go_to_random_comic')); add_action('template_redirect', array(&$this, 'go_to_random_comic'));
} }
if (current_user_can('edit_posts') && isset($comicpress->comicpress_options['helpers']['show_inline_comic_ordering'])) {
add_filter('comicpress_attached_image', array(&$this, 'comicpress_attached_image'), 10, 3);
add_filter('comicpress_display_attached_images', array(&$this, 'comicpress_display_attached_images'), 10, 2);
}
$this->comicpress = $comicpress; $this->comicpress = $comicpress;
$this->comic_image_types = array( $this->comic_image_types = array(
@ -27,6 +32,36 @@ class ComicPressAddonCore extends ComicPressAddon {
); );
} }
function comicpress_attached_image($content, $attachment_id, $index) {
$content .= '<label class="comic-image-ordering">'
. __('Image index:', 'comicpress')
. ' '
. '<input type="text" name="cp[ordering][comic]['
. $attachment_id
. ']" value="'
. $index
. '" /></label>';
return $content;
}
function comicpress_display_attached_images($content, $post_id) {
$content = '<form method="post">'
. '<input type="hidden" name="cp[_nonce]" value="'
. wp_create_nonce('comicpress')
. '" />'
. '<input type="hidden" name="post_ID" value="'
. $post_id
. '" />'
. $content
. '<input type="submit" value="'
. __('Change image ordering', 'comicpress')
. '" />'
. '</form>';
return $content;
}
/** /**
* Callback to send the reader to a random comic. * Callback to send the reader to a random comic.
*/ */
@ -77,14 +112,14 @@ class ComicPressAddonCore extends ComicPressAddon {
* @param object $override_post If not nul;, the post to use instead of the current Loop post. * @param object $override_post If not nul;, the post to use instead of the current Loop post.
* @param string $method The method to call on the comic post. * @param string $method The method to call on the comic post.
*/ */
function show_media($override_post, $method) { function show_media($override_post, $method, $format) {
global $post; global $post;
$post_to_use = (is_null($override_post)) ? $this->comicpress->get_last_comic() : $post; $post_to_use = (is_null($override_post)) ? $this->comicpress->get_last_comic() : $post;
switch ($this->comicpress->comicpress_options['comic_space']) { switch ($this->comicpress->comicpress_options['comic_space']) {
case "comic_only": case "comic_only":
$comic_post = new ComicPressComicPost($post_to_use, &$this->comicpress); $comic_post = new ComicPressComicPost($post_to_use, &$this->comicpress);
$comic_post->{$method}(); $comic_post->{$method}($format);
break; break;
case "post_content": case "post_content":
$t = $post; $t = $post;
@ -98,22 +133,22 @@ class ComicPressAddonCore extends ComicPressAddon {
/** /**
* Show a comic. * Show a comic.
*/ */
function show_comic($override_post = null) { function show_comic($override_post = null, $format = "%s<br />") {
$this->show_media($override_post, "display_comics"); $this->show_media($override_post, "display_comics", $format);
} }
/** /**
* Show an archive comic. * Show an archive comic.
*/ */
function show_archive($override_post = null) { function show_archive($override_post = null, $format = "") {
$this->show_media($override_post, "display_archive"); $this->show_media($override_post, "display_archive", $format);
} }
/** /**
* Show an RSS comic. * Show an RSS comic.
*/ */
function show_rss($override_post = null) { function show_rss($override_post = null, $format = "%s<br />") {
$this->show_media($override_post, "display_rss"); $this->show_media($override_post, "display_rss", $format);
} }
/** /**
@ -434,6 +469,10 @@ class ComicPressAddonCore extends ComicPressAddon {
if ($post = get_post($_POST['post_ID'])) { if ($post = get_post($_POST['post_ID'])) {
$comic_post = new ComicPressComicPost(&$post); $comic_post = new ComicPressComicPost(&$post);
$comic_post->change_comic_image_ordering($_POST['cp']['ordering']); $comic_post->change_comic_image_ordering($_POST['cp']['ordering']);
if (isset($this->comicpress->comicpress_options['helpers']['show_inline_comic_ordering']) && !is_admin()) {
$this->info(sprintf(__("Comic ordering for post #%s updated", 'comicpress'), $_POST['post_ID']));
}
} }
} }
} }
@ -448,6 +487,7 @@ class ComicPressAddonCore extends ComicPressAddon {
} else if (is_array($_POST['cp']['ordering'])) { } else if (is_array($_POST['cp']['ordering'])) {
// comic ordering // comic ordering
if (isset($_POST['meta'])) {
$meta_key_to_ignore = false; $meta_key_to_ignore = false;
foreach ($_POST['meta'] as $meta_key => $params) { foreach ($_POST['meta'] as $meta_key => $params) {
foreach ($params as $type => $value) { foreach ($params as $type => $value) {
@ -460,6 +500,7 @@ class ComicPressAddonCore extends ComicPressAddon {
if ($meta_key_to_ignore !== false) { if ($meta_key_to_ignore !== false) {
unset($_POST['meta'][$meta_key_to_ignore]); unset($_POST['meta'][$meta_key_to_ignore]);
} }
}
$this->handle_update_comic_ordering(); $this->handle_update_comic_ordering();
} else { } else {

View File

@ -104,9 +104,10 @@
<td> <td>
<?php <?php
foreach (array( foreach (array(
"show_partials_info" => __('Show partials info', 'comicpress') "show_partials_info" => __('Show partials info', 'comicpress'),
"show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress')
) as $key => $label) { ?> ) 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> <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><br />
<?php } <?php }
?> ?>
</td> </td>

View File

@ -21,17 +21,21 @@ class ComicPressComicPost {
return $this->attachments; return $this->attachments;
} }
function display_attached_images($type = "comic", $limit = null, $size_type = null) { function display_attached_images($type = "comic", $limit = null, $size_type = null, $format = "%s") {
if (is_null($size_type)) { $size_type = $type; } if (is_null($size_type)) { $size_type = $type; }
$found = false; $found = false;
$ordering = $this->normalize_comic_image_ordering($this->post->ID); $ordering = $this->normalize_comic_image_ordering($this->post->ID);
$output = array();
if (is_array($ordering[$type])) { if (is_array($ordering[$type])) {
$i = 1;
foreach ($ordering[$type] as $attachment_id) { foreach ($ordering[$type] as $attachment_id) {
if (get_post_meta($attachment_id, "comic_image_type", true) == $type) { if (get_post_meta($attachment_id, "comic_image_type", true) == $type) {
$attachment = get_post($attachment_id); $attachment = get_post($attachment_id);
$title = (!empty($attachment->post_excerpt) ? $attachment->post_excerpt : $attachment->post_title); $title = (!empty($attachment->post_excerpt) ? $attachment->post_excerpt : $attachment->post_title);
echo $this->get_comic_img_tag(wp_get_attachment_url($attachment->ID, ''), $size_type, array('title' => $title)); $output[] = apply_filters('comicpress_attached_image',
echo "<br />"; sprintf($format, $this->get_comic_img_tag(wp_get_attachment_url($attachment->ID, ''), $size_type, array('title' => $title))),
$attachment_id,
$i++);
$found = true; $found = true;
if (!is_null($limit)) { if (!is_null($limit)) {
@ -40,20 +44,22 @@ class ComicPressComicPost {
} }
} }
} }
echo apply_filters('comicpress_display_attached_images', implode("\n", $output), $this->post->ID);
return $found; return $found;
} }
function display_comics() { $this->display_attached_images(); } function display_comics($format) { $this->display_attached_images('comic', null, 'comic', $format); }
function display_archive() { function display_archive($format) {
if (!$this->display_attached_images('archive', 1)) { if (!$this->display_attached_images('archive', 1, 'archive', $format)) {
$this->display_attached_images('comic', 1, 'archive'); $this->display_attached_images('comic', 1, 'archive', $format);
} }
} }
function display_rss() { function display_rss($format) {
if (!$this->display_attached_images('rss')) { if (!$this->display_attached_images('rss', null, 'rss', $formar)) {
$this->display_attached_images('comic', null, 'rss'); $this->display_attached_images('comic', null, 'rss', $format);
} }
} }

View File

@ -30,7 +30,7 @@ function __comicpress_init() {
if (class_exists($classname)) { if (class_exists($classname)) {
$addons[] = new $classname(); $addons[] = new $classname();
end($addons)->init(&$comicpress); end($addons)->init(&$comicpress);
if (is_admin()) { if (current_user_can('edit_posts')) {
if (is_array($_REQUEST['cp'])) { if (is_array($_REQUEST['cp'])) {
if (isset($_REQUEST['cp']['_nonce'])) { if (isset($_REQUEST['cp']['_nonce'])) {
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
@ -40,7 +40,11 @@ function __comicpress_init() {
} }
} }
} }
if (is_admin()) {
add_action('admin_notices', array(end($addons), 'display_messages')); add_action('admin_notices', array(end($addons), 'display_messages'));
} else {
add_action('wp_head', array(end($addons), 'display_messages'));
}
} }
} }
} }

View File

@ -1,3 +1,3 @@
<div id="comic-head"></div> <div id="comic-head"></div>
<div id="comic"><?php do_action('show_comic', null); ?></div> <div id="comic"><?php do_action('show_comic', null, "%s<br />"); ?></div>
<div id="comic-foot"></div> <div id="comic-foot"></div>