diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc
index 6034f61..45a52ba 100644
--- a/addons/Core/Core.inc
+++ b/addons/Core/Core.inc
@@ -175,6 +175,7 @@ class ComicPressAddonCore extends ComicPressAddon {
if (isset($_REQUEST['post'])) {
$comic_post = new ComicPressComicPost(get_post($_REQUEST['post']), &$this->comicpress);
$ordering = $comic_post->normalize_comic_image_ordering();
+ echo '';
if (is_array($ordering)) {
foreach ($ordering as $type => $attachment_ids) {
echo '
' . $this->comic_image_types[$type] . '
';
@@ -428,6 +429,15 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
+ function handle_update_comic_ordering() {
+ if (is_numeric($_POST['post_ID'])) {
+ if ($post = get_post($_POST['post_ID'])) {
+ $comic_post = new ComicPressComicPost(&$post);
+ $comic_post->change_comic_image_ordering($_POST['cp']['ordering']);
+ }
+ }
+ }
+
/**
* Handle an update.
*/
@@ -435,8 +445,22 @@ class ComicPressAddonCore extends ComicPressAddon {
if (isset($_POST['attachments'])) {
//coming from media editor
$this->handle_update_attachments();
- } else if (isset($_POST['cp']['ordering'])) {
+ } 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 ($meta_key_to_ignore !== false) {
+ unset($_POST['meta'][$meta_key_to_ignore]);
+ }
+
$this->handle_update_comic_ordering();
} else {
//coming from us
diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc
index 11f1568..5c36b60 100644
--- a/classes/ComicPressComicPost.inc
+++ b/classes/ComicPressComicPost.inc
@@ -169,38 +169,39 @@ class ComicPressComicPost {
}
function change_comic_image_ordering($requested_new_order) {
+ $orderings = array();
if (($order_string = get_post_meta($this->post->ID, 'comic_ordering', true)) !== false) {
$orderings = $this->breakdown_comic_ordering_string($order_string);
-
- $new_order = array();
-
- foreach ($orderings as $type => $current_order) {
- $new_order[$type] = array();
- $sort_by_position = array();
- foreach ($requested_new_order[$type] as $id => $position) {
- if (!isset($sort_by_position[$position])) {
- $sort_by_position[$position] = array();
- }
- $sort_by_position[$position][] = $id;
- }
- ksort($sort_by_position);
- $requested_order = array();
- foreach ($sort_by_position as $position => $ids) {
- sort($ids);
- $requested_order = array_merge($requested_order, $ids);
- }
-
- $requested_order = array_merge($requested_order, array_diff($current_order, $requested_order));
-
- foreach ($requested_order as $requested_comic) {
- if (in_array($requested_comic, $current_order)) {
- $new_order[$type][] = $requested_comic;
- }
+ }
+
+ $new_order = array();
+
+ foreach ($orderings as $type => $current_order) {
+ $new_order[$type] = array();
+ $sort_by_position = array();
+ foreach ($requested_new_order[$type] as $id => $position) {
+ if (!isset($sort_by_position[$position])) {
+ $sort_by_position[$position] = array();
}
+ $sort_by_position[$position][] = $id;
+ }
+ ksort($sort_by_position);
+ $requested_order = array();
+ foreach ($sort_by_position as $position => $ids) {
+ sort($ids);
+ $requested_order = array_merge($requested_order, $ids);
}
- update_post_meta($this->post->ID, 'comic_ordering', $this->build_comic_ordering_string($new_order));
+ $requested_order = array_merge($requested_order, array_diff($current_order, $requested_order));
+
+ foreach ($requested_order as $requested_comic) {
+ if (in_array($requested_comic, $current_order)) {
+ $new_order[$type][] = $requested_comic;
+ }
+ }
}
+
+ update_post_meta($this->post->ID, 'comic_ordering', $this->build_comic_ordering_string($new_order));
}
}