From 1f230256fe576ebe24df49691a46aa5e552bf706 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 3 Aug 2009 21:28:59 -0400 Subject: [PATCH] inline image ordering --- addons/Core/Core.inc | 75 ++++++++++++++++++++------ addons/Core/partials/options-admin.inc | 5 +- classes/ComicPressComicPost.inc | 26 +++++---- functions.php | 8 ++- partials/index-display-comic.inc | 2 +- 5 files changed, 84 insertions(+), 32 deletions(-) diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index 45a52ba..adfab38 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -17,6 +17,11 @@ class ComicPressAddonCore extends ComicPressAddon { 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->comic_image_types = array( @@ -27,6 +32,36 @@ class ComicPressAddonCore extends ComicPressAddon { ); } + function comicpress_attached_image($content, $attachment_id, $index) { + $content .= ''; + + return $content; + } + + function comicpress_display_attached_images($content, $post_id) { + $content = '
' + . '' + . '' + . $content + . '' + . '
'; + + return $content; + } + /** * 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 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; $post_to_use = (is_null($override_post)) ? $this->comicpress->get_last_comic() : $post; switch ($this->comicpress->comicpress_options['comic_space']) { case "comic_only": $comic_post = new ComicPressComicPost($post_to_use, &$this->comicpress); - $comic_post->{$method}(); + $comic_post->{$method}($format); break; case "post_content": $t = $post; @@ -98,22 +133,22 @@ class ComicPressAddonCore extends ComicPressAddon { /** * Show a comic. */ - function show_comic($override_post = null) { - $this->show_media($override_post, "display_comics"); + function show_comic($override_post = null, $format = "%s
") { + $this->show_media($override_post, "display_comics", $format); } /** * Show an archive comic. */ - function show_archive($override_post = null) { - $this->show_media($override_post, "display_archive"); + function show_archive($override_post = null, $format = "") { + $this->show_media($override_post, "display_archive", $format); } /** * Show an RSS comic. */ - function show_rss($override_post = null) { - $this->show_media($override_post, "display_rss"); + function show_rss($override_post = null, $format = "%s
") { + $this->show_media($override_post, "display_rss", $format); } /** @@ -434,6 +469,10 @@ class ComicPressAddonCore extends ComicPressAddon { if ($post = get_post($_POST['post_ID'])) { $comic_post = new ComicPressComicPost(&$post); $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,17 +487,19 @@ class ComicPressAddonCore extends ComicPressAddon { } else if (is_array($_POST['cp']['ordering'])) { // comic ordering - $meta_key_to_ignore = false; - foreach ($_POST['meta'] as $meta_key => $params) { - foreach ($params as $type => $value) { - if ($type == "key" && $value == "comic_ordering") { - $meta_key_to_ignore = $meta_key; break; + if (isset($_POST['meta'])) { + $meta_key_to_ignore = false; + foreach ($_POST['meta'] as $meta_key => $params) { + foreach ($params as $type => $value) { + if ($type == "key" && $value == "comic_ordering") { + $meta_key_to_ignore = $meta_key; break; + } } } - } - - if ($meta_key_to_ignore !== false) { - unset($_POST['meta'][$meta_key_to_ignore]); + + if ($meta_key_to_ignore !== false) { + unset($_POST['meta'][$meta_key_to_ignore]); + } } $this->handle_update_comic_ordering(); diff --git a/addons/Core/partials/options-admin.inc b/addons/Core/partials/options-admin.inc index 75eca70..aba14f2 100644 --- a/addons/Core/partials/options-admin.inc +++ b/addons/Core/partials/options-admin.inc @@ -104,9 +104,10 @@ __('Show partials info', 'comicpress') + "show_partials_info" => __('Show partials info', 'comicpress'), + "show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress') ) as $key => $label) { ?> - +
diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index 5c36b60..6d27368 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -21,17 +21,21 @@ class ComicPressComicPost { 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; } $found = false; $ordering = $this->normalize_comic_image_ordering($this->post->ID); + $output = array(); if (is_array($ordering[$type])) { + $i = 1; foreach ($ordering[$type] as $attachment_id) { if (get_post_meta($attachment_id, "comic_image_type", true) == $type) { $attachment = get_post($attachment_id); $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)); - echo "
"; + $output[] = apply_filters('comicpress_attached_image', + sprintf($format, $this->get_comic_img_tag(wp_get_attachment_url($attachment->ID, ''), $size_type, array('title' => $title))), + $attachment_id, + $i++); $found = true; 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; } - function display_comics() { $this->display_attached_images(); } + function display_comics($format) { $this->display_attached_images('comic', null, 'comic', $format); } - function display_archive() { - if (!$this->display_attached_images('archive', 1)) { - $this->display_attached_images('comic', 1, 'archive'); + function display_archive($format) { + if (!$this->display_attached_images('archive', 1, 'archive', $format)) { + $this->display_attached_images('comic', 1, 'archive', $format); } } - function display_rss() { - if (!$this->display_attached_images('rss')) { - $this->display_attached_images('comic', null, 'rss'); + function display_rss($format) { + if (!$this->display_attached_images('rss', null, 'rss', $formar)) { + $this->display_attached_images('comic', null, 'rss', $format); } } diff --git a/functions.php b/functions.php index 6fa8dbd..743755e 100644 --- a/functions.php +++ b/functions.php @@ -30,7 +30,7 @@ function __comicpress_init() { if (class_exists($classname)) { $addons[] = new $classname(); end($addons)->init(&$comicpress); - if (is_admin()) { + if (current_user_can('edit_posts')) { if (is_array($_REQUEST['cp'])) { if (isset($_REQUEST['cp']['_nonce'])) { if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { @@ -40,7 +40,11 @@ function __comicpress_init() { } } } - add_action('admin_notices', array(end($addons), 'display_messages')); + if (is_admin()) { + add_action('admin_notices', array(end($addons), 'display_messages')); + } else { + add_action('wp_head', array(end($addons), 'display_messages')); + } } } } diff --git a/partials/index-display-comic.inc b/partials/index-display-comic.inc index 370fae4..33b6734 100644 --- a/partials/index-display-comic.inc +++ b/partials/index-display-comic.inc @@ -1,3 +1,3 @@
-
+
"); ?>