diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc
index f6a8b30..f1a613f 100644
--- a/addons/Core/Core.inc
+++ b/addons/Core/Core.inc
@@ -199,7 +199,7 @@ class ComicPressAddonCore extends ComicPressAddon {
if (strpos($pagenow, "post") === 0) {
add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low");
- wp_enqueue_script('cp-ordering', get_stylesheet_directory_uri() . '/js/ComicImageOrdering.js', array('scriptaculous-slider'));
+ wp_enqueue_script('cp-ordering', get_stylesheet_directory_uri() . '/js/ComicImageOrdering.js', array('scriptaculous', 'scriptaculous-slider'));
wp_enqueue_style('cp-admin', get_stylesheet_directory_uri() . '/css/cp-admin.css');
add_action('admin_footer', array(&$this, 'admin_footer'));
}
@@ -347,24 +347,35 @@ class ComicPressAddonCore extends ComicPressAddon {
/**
* Render the comic image ordering interface.
*/
- function render_comic_image_ordering() {
- if (isset($_REQUEST['post'])) {
- $comic_post = new ComicPressComicPost(get_post($_REQUEST['post']));
- $ordering = $comic_post->normalize_comic_image_ordering();
-
- if (is_array($ordering)) {
- $nonce = wp_create_nonce('comicpress');
- $zoom_level = 40;
- $current_user = wp_get_current_user();
- if (!empty($current_user)) {
- $comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
- if (is_array($comicpress_meta)) {
- if (isset($comicpress_meta['zoom_level'])) {
- $zoom_level = floor($comicpress_meta['zoom_level']);
- }
+ function render_comic_image_ordering($is_ajax = false, $override_post = null) {
+ global $post_ID, $temp_ID;
+
+ $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
+ if (is_numeric($override_post)) { $uploading_iframe_ID = $override_post; }
+
+ $comic_post = new ComicPressComicPost(get_post($uploading_iframe_ID));
+ $ordering = $comic_post->normalize_comic_image_ordering();
+
+ if (is_array($ordering)) {
+ $nonce = wp_create_nonce('comicpress');
+ $zoom_level = 40;
+ $current_user = wp_get_current_user();
+ if (!empty($current_user)) {
+ $comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
+ if (is_array($comicpress_meta)) {
+ if (isset($comicpress_meta['zoom_level'])) {
+ $zoom_level = floor($comicpress_meta['zoom_level']);
}
}
+ }
+ // from wp-admin/includes/media.php O_o
+ $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
+ $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image&TB_iframe=true");
+
+ if ($is_ajax === true) {
+ include(dirname(__FILE__) . '/partials/_comic-image-ordering-sorters.inc');
+ } else {
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
}
}
@@ -437,7 +448,15 @@ class ComicPressAddonCore extends ComicPressAddon {
return implode("\n", $output);
}
- /**
+ /**
+ * Update attachment information.
+ */
+ function handle_update_refresh_ordering($info) {
+ $this->render_comic_image_ordering(true, $info['post_id']);
+ exit(0);
+ }
+
+ /**
* Update attachment information.
*/
function handle_update_attachments() {
@@ -518,16 +537,22 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
}
+
+ function _json_decode($string) {
+ if (function_exists('json_decode')) {
+ return json_decode($string);
+ } else {
+ require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
+ $j = new Moxiecode_JSON();
+ return $j->decode($string);
+ }
+ }
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']);
-
- 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']));
- }
+ $comic_post->change_comic_image_ordering($this->_json_decode(stripslashes($_POST['cp']['comic_order'])));
}
}
}
diff --git a/addons/Core/partials/_comic-image-ordering-sorters.inc b/addons/Core/partials/_comic-image-ordering-sorters.inc
new file mode 100644
index 0000000..d3a4daf
--- /dev/null
+++ b/addons/Core/partials/_comic-image-ordering-sorters.inc
@@ -0,0 +1,91 @@
+
+
+ ' . __('Image Uploader', 'comicpress') . ''
+ )
+ ?>
+
+
+
+ $attachment_ids) { ?>
+ comic_image_types[$type] ?>
+
+ get_info(); ?>
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/Core/partials/_comic-image-ordering.inc b/addons/Core/partials/_comic-image-ordering.inc
index c1f91ea..142c13b 100644
--- a/addons/Core/partials/_comic-image-ordering.inc
+++ b/addons/Core/partials/_comic-image-ordering.inc
@@ -1,43 +1,35 @@
-
-
-
-
- $attachment_ids) { ?>
-
comic_image_types[$type] ?>
-
-
-
-
-
-
+
-
+ });
+ }())
+
+
\ No newline at end of file
diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc
index 7b3c74d..fbda9fe 100644
--- a/classes/ComicPressComicPost.inc
+++ b/classes/ComicPressComicPost.inc
@@ -171,15 +171,19 @@ class ComicPressComicPost {
if (!is_array($orderings)) { $orderings = array(); }
$new_order = array();
-
+
+ $requested_new_order = (array)$requested_new_order;
+
foreach ($orderings as $type => $current_order) {
$new_order[$type] = array();
$sort_by_position = array();
- foreach ($requested_new_order[$type] as $id => $position) {
+ $position = 0;
+ foreach ($requested_new_order[$type] as $id) {
if (!isset($sort_by_position[$position])) {
$sort_by_position[$position] = array();
}
$sort_by_position[$position][] = $id;
+ $position++;
}
ksort($sort_by_position);
$requested_order = array();
diff --git a/classes/backends/ComicPressBackendAttachment.inc b/classes/backends/ComicPressBackendAttachment.inc
new file mode 100644
index 0000000..13b04c8
--- /dev/null
+++ b/classes/backends/ComicPressBackendAttachment.inc
@@ -0,0 +1,17 @@
+attachment_id = $attachment_id;
+ }
+
+ function get_url() {
+ return wp_get_attachment_url($this->attachment_id);
+ }
+
+ function get_info() {
+ return wp_get_attachment_metadata($this->attachment_id);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/css/cp-admin.css b/css/cp-admin.css
index 229cd46..e03ce6f 100644
--- a/css/cp-admin.css
+++ b/css/cp-admin.css
@@ -9,6 +9,10 @@
#ordering-zoom-slider-holder {
width: 30px;
+ float: left;
+ display: inline;
+ padding-top: 25px;
+ background: url(../images/system-search.png) top center no-repeat;
}
#ordering-zoom-slider {
@@ -29,3 +33,36 @@
cursor: move;
margin-left: -6px
}
+
+#comic-ordering-holder {
+ margin-left: 35px;
+}
+
+#comic-ordering-holder img {
+ float: left;
+ display: inline;
+ margin-right: 5px;
+}
+
+.comic-attachment {
+ overflow: hidden
+}
+
+.comic-ordering {
+ overflow: hidden;
+ border: solid #ccc 1px;
+ padding: 5px;
+ margin-bottom: 10px;
+}
+
+.cp-comic-attachment {
+ cursor: move
+}
+
+#ordering-refresh {
+ background: url(../images/view-refresh.png) top left no-repeat;
+ width: 16px;
+ height: 16px;
+ display: block;
+ margin: 8px 0 0 8px;
+}
\ No newline at end of file
diff --git a/functions.php b/functions.php
index 560ff04..ca9cdae 100644
--- a/functions.php
+++ b/functions.php
@@ -9,9 +9,16 @@ function __comicpress_init() {
if (current_user_can('edit_files')) {
wp_cache_flush();
}
-
- foreach (glob(dirname(__FILE__) . '/classes/*.inc') as $file) {
- if (is_file($file)) { require_once($file); }
+
+ $classes_search = array(
+ '/classes/',
+ '/classes/backends/'
+ );
+
+ foreach ($classes_search as $path) {
+ foreach (glob(dirname(__FILE__) . $path . '*.inc') as $file) {
+ if (is_file($file)) { require_once($file); }
+ }
}
$comicpress = ComicPress::get_instance();
diff --git a/images/system-search.png b/images/system-search.png
new file mode 100644
index 0000000..fd7f0b0
Binary files /dev/null and b/images/system-search.png differ
diff --git a/images/view-refresh.png b/images/view-refresh.png
new file mode 100644
index 0000000..3fd71d6
Binary files /dev/null and b/images/view-refresh.png differ
diff --git a/test/ComicPressComicPostTest.php b/test/ComicPressComicPostTest.php
index d4fac2b..3dc834d 100644
--- a/test/ComicPressComicPostTest.php
+++ b/test/ComicPressComicPostTest.php
@@ -128,21 +128,21 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
array(
array('comic' => array(1,2,3)),
array(
- 'comic' => array('1' => 3, '2' => 1, '3' => 2)
+ 'comic' => array(2,3,1)
),
array('comic' => array(2,3,1))
),
array(
array('comic' => array(1,2,3)),
array(
- 'comic' => array('1' => 2, '2' => 2, '3' => 1)
+ 'comic' => array(3,1,2)
),
array('comic' => array(3,1,2))
),
array(
array('comic' => array(1,2,3)),
array(
- 'comic' => array('1' => 1, '2' => 2)
+ 'comic' => array(1,2)
),
array('comic' => array(1,2,3))
),
@@ -151,6 +151,7 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider providerTestChangeComicImageOrdering
+ * @covers ComicPressComicPost::change_comic_image_ordering
*/
function testChangeComicImageOrdering($current_ordering, $revised_ordering, $expected_result) {
update_post_meta(1, 'comic_ordering', $current_ordering);