From ad944ed208f0f24bdcf05d8c9768cbe07bd07d2f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 3 Nov 2009 21:45:56 -0500 Subject: [PATCH] totally get sorting to work --- addons/Core/Core.inc | 69 ++++++++----- .../_comic-image-ordering-sorters.inc | 91 ++++++++++++++++++ .../Core/partials/_comic-image-ordering.inc | 64 ++++++------ classes/ComicPressComicPost.inc | 8 +- .../backends/ComicPressBackendAttachment.inc | 17 ++++ css/cp-admin.css | 37 +++++++ functions.php | 13 ++- images/system-search.png | Bin 0 -> 935 bytes images/view-refresh.png | Bin 0 -> 912 bytes test/ComicPressComicPostTest.php | 7 +- 10 files changed, 240 insertions(+), 66 deletions(-) create mode 100644 addons/Core/partials/_comic-image-ordering-sorters.inc create mode 100644 classes/backends/ComicPressBackendAttachment.inc create mode 100644 images/system-search.png create mode 100644 images/view-refresh.png 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 0000000000000000000000000000000000000000..fd7f0b07a558cb6d59af96bebb672bf1abe96c88 GIT binary patch literal 935 zcmV;Y16cftP)&ujZZ2vcpl1 zMZ@GK2apA{PG?ddXEM`!?RHyZ=kcza{{|ocz_G78)~3_xTfzOGVc*@!;z&{~D4M34 z#HCy|oAJK^O5@u;x%xm;z_nWd04$M+pY+%HrNI}599Zr)1O{&1Fr9gQ zRx^nN(=^?Ylb_Xc3crTMTm|}8W6tGCdm-gHU zoivEbfP*V-h@Y#f29hN4c>od3S|m}D80SwWrl%O%n5zs-y=aEVV!4n`6c;!WFs{rR zhNug$8$G1gD4`4AaS<H7=eg9>uBL$90I_nW$UopHtf^aCQMJwQhI406Q(#?y zO-@ZpM5e?TYiVd$*M}u5U8hd09vd6~!{hc8oX&FDU*~sLS6AD5dV3x{dHP7z^Tsz$ zm;I-vElqH5_&#iSZzKKk>qUmIhNJ7$iG2Xj914Xt0)Xc8`7QxKZ+qL(^TA-S6B++< zPs?7gTFc=3v)=)}CSYu?u#}a#&H(^gTU%RH&GN(C?nC&$dI>wJW|L@7q6Gi|002ov JPDHLkV1n1##MS@+ literal 0 HcmV?d00001 diff --git a/images/view-refresh.png b/images/view-refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..3fd71d6e5929ba0c40db1960e36e9acba9d7e525 GIT binary patch literal 912 zcmV;B18@9^P)oWowDaEkzU!j%l38$)o7}}cCnx7z zVrKYAWwOsS=-Lqw-t?qu)r6QQ!notg696vQmg&~r9t3cLe1UW(yG7H)Ku^~yeO+g> z(bg0Jm{BNJFfw+(d}sQhCl&9uE%R)8S2n|p?*PPznUTt5*BiPR+1l3~ipPS`iO?Jk zARN#U4H*a;0yD)$9M29{3dM>Y4K?&WE>{g^G!Zl7)jelV^{i|AG#D_%trsJC8h7YDw+>Nu`!(E)&&KfE(t5U!_KF)uRXGsl%@ z#;0eK6ZhtiUhin`+P8I6C=m!d1ufk}o{_gOutKfI-_b^R{JP z`QzJ2^LHMWS&9G(o-t)@yh1Uq9cxfG6X$C)H~ghbOC7?WrZ-yyL0>0QOs`0x)U>uAAQg z>;&LGL0Gpf^PVr@oj>}%1`wDT7wv!4sq=s3q*Oh&WftpMhqGg=O68@F-$%x80Ep=T zKm-sG?*3PXAs8nI|0Dok)RR-0Y?z4d_HJBzCO6*s&6^5?o^0No>h2ra)My_p{u2^&LcltM%9%NL@3OcL;J5G-fbF(raxE|ez 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);