comic image order sorting working in edit post
This commit is contained in:
parent
de57ff0444
commit
2ce436ef45
@ -175,6 +175,7 @@ class ComicPressAddonCore extends ComicPressAddon {
|
|||||||
if (isset($_REQUEST['post'])) {
|
if (isset($_REQUEST['post'])) {
|
||||||
$comic_post = new ComicPressComicPost(get_post($_REQUEST['post']), &$this->comicpress);
|
$comic_post = new ComicPressComicPost(get_post($_REQUEST['post']), &$this->comicpress);
|
||||||
$ordering = $comic_post->normalize_comic_image_ordering();
|
$ordering = $comic_post->normalize_comic_image_ordering();
|
||||||
|
echo '<input type="hidden" name="cp[_nonce]" value="' . wp_create_nonce('comicpress') . '" />';
|
||||||
if (is_array($ordering)) {
|
if (is_array($ordering)) {
|
||||||
foreach ($ordering as $type => $attachment_ids) {
|
foreach ($ordering as $type => $attachment_ids) {
|
||||||
echo '<h3>' . $this->comic_image_types[$type] . '</h3>';
|
echo '<h3>' . $this->comic_image_types[$type] . '</h3>';
|
||||||
@ -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.
|
* Handle an update.
|
||||||
*/
|
*/
|
||||||
@ -435,8 +445,22 @@ class ComicPressAddonCore extends ComicPressAddon {
|
|||||||
if (isset($_POST['attachments'])) {
|
if (isset($_POST['attachments'])) {
|
||||||
//coming from media editor
|
//coming from media editor
|
||||||
$this->handle_update_attachments();
|
$this->handle_update_attachments();
|
||||||
} else if (isset($_POST['cp']['ordering'])) {
|
} else if (is_array($_POST['cp']['ordering'])) {
|
||||||
// comic 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();
|
$this->handle_update_comic_ordering();
|
||||||
} else {
|
} else {
|
||||||
//coming from us
|
//coming from us
|
||||||
|
@ -169,38 +169,39 @@ class ComicPressComicPost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function change_comic_image_ordering($requested_new_order) {
|
function change_comic_image_ordering($requested_new_order) {
|
||||||
|
$orderings = array();
|
||||||
if (($order_string = get_post_meta($this->post->ID, 'comic_ordering', true)) !== false) {
|
if (($order_string = get_post_meta($this->post->ID, 'comic_ordering', true)) !== false) {
|
||||||
$orderings = $this->breakdown_comic_ordering_string($order_string);
|
$orderings = $this->breakdown_comic_ordering_string($order_string);
|
||||||
|
}
|
||||||
|
|
||||||
$new_order = array();
|
$new_order = array();
|
||||||
|
|
||||||
foreach ($orderings as $type => $current_order) {
|
foreach ($orderings as $type => $current_order) {
|
||||||
$new_order[$type] = array();
|
$new_order[$type] = array();
|
||||||
$sort_by_position = array();
|
$sort_by_position = array();
|
||||||
foreach ($requested_new_order[$type] as $id => $position) {
|
foreach ($requested_new_order[$type] as $id => $position) {
|
||||||
if (!isset($sort_by_position[$position])) {
|
if (!isset($sort_by_position[$position])) {
|
||||||
$sort_by_position[$position] = array();
|
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user