From 225b45f2b88d3193ec4012a589749c5814c42205 Mon Sep 17 00:00:00 2001 From: rvelices Date: Sun, 8 Jan 2012 19:25:52 +0000 Subject: feature 2548 multisize - added a page to build missing derivatives - browser driven, chained ws calls to retrieve urls, visual feedback of progress through slideshow git-svn-id: http://piwigo.org/svn/trunk@12865 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/derivatives_build.php | 30 ++++ admin/include/functions.php | 3 - admin/include/image.class.php | 1 + admin/themes/default/template/derivatives.tpl | 1 + .../themes/default/template/derivatives_build.tpl | 152 +++++++++++++++++++++ 5 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 admin/derivatives_build.php create mode 100644 admin/themes/default/template/derivatives_build.tpl (limited to 'admin') diff --git a/admin/derivatives_build.php b/admin/derivatives_build.php new file mode 100644 index 000000000..4203124ac --- /dev/null +++ b/admin/derivatives_build.php @@ -0,0 +1,30 @@ +assign('derivatives', array_keys(ImageStdParams::get_defined_type_map())); + +$template->set_filename('derivatives', 'derivatives_build.tpl'); +$template->assign_var_from_handle('ADMIN_CONTENT', 'derivatives'); +?> \ No newline at end of file diff --git a/admin/include/functions.php b/admin/include/functions.php index 59e59e5c2..84bae9154 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -200,11 +200,8 @@ SELECT $files = array(); $files[] = get_element_path($row); - if (!empty($row['representative_ext'])) { - $pi = pathinfo($row['path']); - $file_wo_ext = get_filename_wo_extension($pi['basename']); $files[] = original_to_representative( $files[0], $row['representative_ext']); } diff --git a/admin/include/image.class.php b/admin/include/image.class.php index 03cf419a4..c8e61a829 100644 --- a/admin/include/image.class.php +++ b/admin/include/image.class.php @@ -704,6 +704,7 @@ class image_gd implements imageInterface // Place the source image in the destination image imagecopy($cut, $ioverlay, 0, 0, 0, 0, $ow, $oh); imagecopymerge($this->image, $cut, $x, $y, 0, 0, $ow, $oh, $opacity); + imagedestroy($cut); return true; } diff --git a/admin/themes/default/template/derivatives.tpl b/admin/themes/default/template/derivatives.tpl index 59f6344a7..dcf52a4ec 100644 --- a/admin/themes/default/template/derivatives.tpl +++ b/admin/themes/default/template/derivatives.tpl @@ -22,6 +22,7 @@ {/literal}{/html_head} +

Build missing derivatives

{'Watermark'|@translate} diff --git a/admin/themes/default/template/derivatives_build.tpl b/admin/themes/default/template/derivatives_build.tpl new file mode 100644 index 000000000..6e0c8e35d --- /dev/null +++ b/admin/themes/default/template/derivatives_build.tpl @@ -0,0 +1,152 @@ +{html_head}{literal} + +{/literal}{/html_head} + +

+ + + + +

+
+

+ + + + + + + + + + + + + +
Errors0
Loaded0
Remaining0
+

+ +
+

+ +
+
+ +{combine_script id='iloader' load='footer' path='themes/default/js/image.loader.js'} + +{footer_script require='jquery.effects.slide'}{literal} + +var loader = new ImageLoader( {onChanged: loaderChanged} ) + , pending_next_page = null + , last_image_show_time = 0 + , allDoneDfd, urlDfd; + +function start() { + allDoneDfd = jQuery.Deferred(); + urlDfd = jQuery.Deferred(); + + allDoneDfd.always( function() { + jQuery("#startLink").attr('disabled', false).css("opacity", 1); + jQuery("#pauseLink,#stopLink").attr('disabled', true).css("opacity", 0.5); + } ); + + urlDfd.always( function() { + if (loader.remaining()==0) + allDoneDfd.resolve(); + } ); + + jQuery("#startLink").attr('disabled', true).css("opacity", 0.5); + jQuery("#pauseLink,#stopLink").attr('disabled', false).css("opacity", 1); + + loader.pause(false); + updateStats(); + getUrls(); +} + +function pause() { + loader.pause( !loader.pause() ); +} + +function stop() { + loader.clear(); + urlDfd.resolve(); +} + +function getUrls(page_token) { + data = {max_urls: 500, types: []}; + jQuery.each(jQuery("#types").serializeArray(), function(i, t) { + data.types.push( t.value ); + } ); + + if (page_token) + data['prev_page'] = page_token; + jQuery.post( '{/literal}{$ROOT_URL}{literal}ws.php?format=json&method=pwg.getMissingDerivatives', + data, wsData, "json").fail( wsError ); +} + +function wsData(data) { + if (!data.stat || data.stat != "ok") { + wsError(); + return; + } + loader.add( data.result.urls ); + if (data.result.next_page) { + if (loader.pause() || loader.remaining() > 100) { + pending_next_page = data.result.next_page; + } + else { + getUrls(data.result.next_page); + } + } +} + +function wsError() { + urlDfd.reject(); +} + +function updateStats() { + jQuery("#loaded").text( loader.loaded ); + jQuery("#errors").text( loader.errors ); + jQuery("#remaining").text( loader.remaining() ); +} + +function loaderChanged(type, img) { + updateStats(); + if (img) { + if (type==="load") { + var now = jQuery.now(); + if (now - last_image_show_time > 3000) { + last_image_show_time = now; + var h=img.height, url=img.src; + jQuery("#feedbackWrap").hide("slide", {direction:'down'}, function() { + last_image_show_time = jQuery.now(); + if (h > 300 ) + jQuery("#feedbackImg").attr("height", 300); + else + jQuery("#feedbackImg").removeAttr("height"); + jQuery("#feedbackImg").attr("src", url); + jQuery("#feedbackWrap").show("slide", {direction:'up'} ); + } ); + } + } + else { + jQuery("#errorList").prepend( ''+img.src+'' + "
"); + } + } + if (pending_next_page && 100 > loader.remaining() ) { + getUrls(pending_next_page); + pending_next_page = null; + } + else if (loader.remaining() == 0 && (urlDfd.isResolved() || urlDfd.isRejected())) { + allDoneDfd.resolve(); + } +} +{/literal}{/footer_script} \ No newline at end of file -- cgit v1.2.3