From 796b6b3ffef5bb4798aab075ff197f8cdfd62f3d Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 19 Apr 2012 14:43:30 +0000 Subject: [PATCH] feature 2606: second step on multiple size configuration screen redesign. Configuration settings are saved on form submission. The old screen is still available for tests. Default resize quality set to 95 instead of 85. git-svn-id: http://piwigo.org/svn/trunk@14221 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/configuration.php | 134 ++++----- .../configuration_sizes_process.inc.php | 265 ++++++++++++++++++ admin/include/functions_upload.inc.php | 4 +- .../themes/default/template/configuration.tpl | 42 +-- include/derivative_params.inc.php | 2 +- 5 files changed, 356 insertions(+), 91 deletions(-) create mode 100644 admin/include/configuration_sizes_process.inc.php diff --git a/admin/configuration.php b/admin/configuration.php index 2258dab99..4258c3437 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -175,32 +175,7 @@ if (isset($_POST['submit'])) } case 'sizes' : { - $fields = array( - 'original_resize', - 'original_resize_maxwidth', - 'original_resize_maxheight', - 'original_resize_quality', - ); - - $updates = array(); - - foreach ($fields as $field) - { - $value = !empty($_POST[$field]) ? $_POST[$field] : null; - $form_values[$field] = $value; - $updates[$field] = $value; - } - - save_upload_form_config($updates, $page['errors']); - - if (count($page['errors']) == 0) - { - array_push( - $page['infos'], - l10n('Your configuration settings are saved') - ); - } - + include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php'); break; } case 'comments' : @@ -428,69 +403,82 @@ switch ($page['section']) } case 'sizes' : { - $template->assign( - 'sizes', - array( - 'original_resize_maxwidth' => $conf['original_resize_maxwidth'], - 'original_resize_maxheight' => $conf['original_resize_maxheight'], - 'original_resize_quality' => $conf['original_resize_quality'], - ) - ); - - foreach ($sizes_checkboxes as $checkbox) + // we only load the derivatives if it was not already loaded: it occurs + // when submitting the form and an error remains + if (!isset($page['sizes_loaded_in_tpl'])) { - $template->append( + $template->assign( 'sizes', array( - $checkbox => $conf[$checkbox] - ), - true + 'original_resize_maxwidth' => $conf['original_resize_maxwidth'], + 'original_resize_maxheight' => $conf['original_resize_maxheight'], + 'original_resize_quality' => $conf['original_resize_quality'], + ) ); - } - - // derivaties = multiple size - $enabled = ImageStdParams::get_defined_type_map(); - $disabled = @unserialize(@$conf['disabled_derivatives']); - if ($disabled === false) - { - $disabled = array(); - } - - $tpl_vars = array(); - foreach(ImageStdParams::get_all_types() as $type) - { - $tpl_var = array(); - $tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false); - $tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false; - - if ($params=@$enabled[$type]) + foreach ($sizes_checkboxes as $checkbox) { - $tpl_var['enabled']=true; - } - else - { - $tpl_var['enabled']=false; - $params=@$disabled[$type]; + $template->append( + 'sizes', + array( + $checkbox => $conf[$checkbox] + ), + true + ); } - if ($params) + // derivatives = multiple size + $enabled = ImageStdParams::get_defined_type_map(); + $disabled = @unserialize(@$conf['disabled_derivatives']); + if ($disabled === false) { - list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size; - if ( ($tpl_var['crop'] = round(100*$params->sizing->max_crop)) > 0) + $disabled = array(); + } + + $common_quality = 50; + + $tpl_vars = array(); + foreach(ImageStdParams::get_all_types() as $type) + { + $tpl_var = array(); + + $tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false); + $tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false; + + if ($params = @$enabled[$type]) { - list($tpl_var['minw'],$tpl_var['minh']) = $params->sizing->min_size; + $tpl_var['enabled'] = true; } else { - $tpl_var['minw'] = $tpl_var['minh'] = ""; + $tpl_var['enabled']=false; + $params=@$disabled[$type]; } - $tpl_var['sharpen'] = $params->sharpen; - $tpl_var['quality'] = $params->quality; + + if ($params) + { + list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size; + if ( ($tpl_var['crop'] = round(100*$params->sizing->max_crop)) > 0) + { + list($tpl_var['minw'],$tpl_var['minh']) = $params->sizing->min_size; + } + else + { + $tpl_var['minw'] = $tpl_var['minh'] = ""; + } + $tpl_var['sharpen'] = $params->sharpen; + $tpl_var['quality'] = $params->quality; + + if ($params->quality > $common_quality and $tpl_var['enabled']) + { + $common_quality = $params->quality; + } + } + $tpl_vars[$type]=$tpl_var; } - $tpl_vars[$type]=$tpl_var; + $template->assign('derivatives', $tpl_vars); + $template->assign('resize_quality', $common_quality); } - $template->assign('derivatives', $tpl_vars); break; } diff --git a/admin/include/configuration_sizes_process.inc.php b/admin/include/configuration_sizes_process.inc.php new file mode 100644 index 000000000..603103fe1 --- /dev/null +++ b/admin/include/configuration_sizes_process.inc.php @@ -0,0 +1,265 @@ + 98) +{ + $errors['resize_quality'] = '[50..98]'; +} + +$pderivatives = $_POST['d']; + +// step 1 - sanitize HTML input +foreach ($pderivatives as $type => &$pderivative) +{ + if ($pderivative['must_square'] = ($type==IMG_SQUARE ? true : false)) + { + $pderivative['h'] = $pderivative['w']; + $pderivative['minh'] = $pderivative['minw'] = $pderivative['w']; + $pderivative['crop'] = 100; + } + $pderivative['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false; + $pderivative['enabled'] = isset($pderivative['enabled']) || $pderivative['must_enable'] ? true : false; + + if (isset($pderivative['crop'])) + { + $pderivative['crop'] = 100; + $pderivative['minw'] = $pderivative['w']; + $pderivative['minh'] = $pderivative['h']; + } + else + { + $pderivative['crop'] = 0; + $pderivative['minw'] = null; + $pderivative['minh'] = null; + } +} +unset($pderivative); + +// step 2 - check validity +$prev_w = $prev_h = 0; +foreach(ImageStdParams::get_all_types() as $type) +{ + $pderivative = $pderivatives[$type]; + if (!$pderivative['enabled']) + { + continue; + } + + if ($type == IMG_THUMB) + { + $w = intval($pderivative['w']); + if ($w <= 0) + { + $errors[$type]['w'] = '>0'; + } + + $h = intval($pderivative['h']); + if ($h <= 0) + { + $errors[$type]['h'] = '>0'; + } + + if (max($w,$h) <= $prev_w) + { + $errors[$type]['w'] = $errors[$type]['h'] = '>'.$prev_w; + } + } + else + { + $v = intval($pderivative['w']); + if ($v <= 0 or $v <= $prev_w) + { + $errors[$type]['w'] = '>'.$prev_w; + } + + $v = intval($pderivative['h']); + if ($v <= 0 or $v <= $prev_h) + { + $errors[$type]['h'] = '>'.$prev_h; + } + } + + if (count($errors) == 0) + { + $prev_w = intval($pderivative['w']); + $prev_h = intval($pderivative['h']); + } +} + +// step 3 - save data +if (count($errors) == 0) +{ + $enabled = ImageStdParams::get_defined_type_map(); + $disabled = @unserialize( @$conf['disabled_derivatives'] ); + if ($disabled === false) + { + $disabled = array(); + } + $changed_types = array(); + + foreach (ImageStdParams::get_all_types() as $type) + { + $pderivative = $pderivatives[$type]; + + if ($pderivative['enabled']) + { + $new_params = new DerivativeParams( + new SizingParams( + array(intval($pderivative['w']), intval($pderivative['h'])), + round($pderivative['crop'] / 100, 2), + array(intval($pderivative['minw']), intval($pderivative['minh'])) + ) + ); + + $new_params->quality = intval($_POST['resize_quality']); + + ImageStdParams::apply_global($new_params); + + if (isset($enabled[$type])) + { + $old_params = $enabled[$type]; + $same = true; + if (!size_equals($old_params->sizing->ideal_size, $new_params->sizing->ideal_size) + or $old_params->sizing->max_crop != $new_params->sizing->max_crop) + { + $same = false; + } + + if ($same + and $new_params->sizing->max_crop != 0 + and !size_equals($old_params->sizing->min_size, $new_params->sizing->min_size)) + { + $same = false; + } + + if ($new_params->quality != $old_params->quality) + { + $same = false; + } + + if (!$same) + { + $new_params->last_mod_time = time(); + $changed_types[] = $type; + } + else + { + $new_params->last_mod_time = $old_params->last_mod_time; + } + $enabled[$type] = $new_params; + } + else + {// now enabled, before was disabled + $enabled[$type] = $new_params; + unset($disabled[$type]); + } + } + else + {// disabled + if (isset($enabled[$type])) + {// now disabled, before was enabled + $changed_types[] = $type; + $disabled[$type] = $enabled[$type]; + unset($enabled[$type]); + } + } + } + + $enabled_by = array(); // keys ordered by all types + foreach(ImageStdParams::get_all_types() as $type) + { + if (isset($enabled[$type])) + { + $enabled_by[$type] = $enabled[$type]; + } + } + + ImageStdParams::set_and_save($enabled_by); + if (count($disabled) == 0) + { + $query='DELETE FROM '.CONFIG_TABLE.' WHERE param = \'disabled_derivatives\''; + pwg_query($query); + } + else + { + conf_update_param('disabled_derivatives', addslashes(serialize($disabled)) ); + } + $conf['disabled_derivatives'] = serialize($disabled); + + if (count($changed_types)) + { + clear_derivative_cache($changed_types); + } + + array_push( + $page['infos'], + l10n('Your configuration settings are saved') + ); +} +else +{ + foreach ($original_fields as $field) + { + if (isset($_POST[$field])) + { + $template->append( + 'sizes', + array( + $field => $_POST[$field] + ), + true + ); + } + } + + $template->assign('derivatives', $pderivatives); + $template->assign('ferrors', $errors); + $template->assign('resize_quality', $_POST['resize_quality']); + $page['sizes_loaded_in_tpl'] = true; +} +?> \ No newline at end of file diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index 19482ee02..3df881a2b 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -68,7 +68,7 @@ function get_upload_form_config() return $upload_form_config; } -function save_upload_form_config($data, &$errors=array()) +function save_upload_form_config($data, &$errors=array(), &$form_errors=array()) { if (!is_array($data) or empty($data)) { @@ -130,6 +130,8 @@ function save_upload_form_config($data, &$errors=array()) $max ) ); + + $form_errors[$field] = '['.$min.' .. '.$max.']'; } } } diff --git a/admin/themes/default/template/configuration.tpl b/admin/themes/default/template/configuration.tpl index ca54e90d1..d6f0b0064 100644 --- a/admin/themes/default/template/configuration.tpl +++ b/admin/themes/default/template/configuration.tpl @@ -319,8 +319,10 @@ jQuery(document).ready(function(){ }); {/literal}{/footer_script} -{literal} - -{/literal} +{/literal}{/html_head}
{'Original Size'|@translate} @@ -344,27 +346,34 @@ jQuery(document).ready(function(){ - + - + - +
{'Maximum Width'|@translate} {'pixels'|@translate} + {'pixels'|@translate} + {if isset($ferrors.original_resize_maxwidth)}!{/if} +
{'Maximum Height'|@translate} {'pixels'|@translate} + {'pixels'|@translate} + {if isset($ferrors.original_resize_maxheight)}!{/if} +
{'Image Quality'|@translate} % + % + {if isset($ferrors.original_resize_quality)}!{/if} +
-
Warning: the following fields are for test "user interface" test only. Any change won't be saved.
See screen [Administration > Configuration > Multiple Size] to configure sizes.
-
{'Multiple Size'|@translate} @@ -384,17 +393,17 @@ jQuery(document).ready(function(){ - +
- {$d.w} x {$d.h} {'pixels'|@translate}{if $d.crop}, {'Crop'|@translate|lower}{/if} + {$d.w} x {$d.h} {'pixels'|@translate}{if $d.crop}, {'Crop'|@translate|lower}{/if} - + {'edit'|@translate}
{if !$d.must_square} @@ -411,7 +420,7 @@ jQuery(document).ready(function(){ @@ -421,7 +430,7 @@ jQuery(document).ready(function(){ @@ -433,9 +442,10 @@ jQuery(document).ready(function(){ {/foreach}
{if $d.must_square or $d.crop}{'Width'|@translate}{else}{'Maximum Width'|@translate}{/if} - + {'pixels'|@translate} {if isset($ferrors.$type.w)}!{/if}
{if $d.crop}{'Height'|@translate}{else}{'Maximum Height'|@translate}{/if} - + {'pixels'|@translate} {if isset($ferrors.$type.h)}!{/if}
-

+

{'Image Quality'|@translate} - % + % + {if isset($ferrors.resize_quality)}!{/if}

{/if} diff --git a/include/derivative_params.inc.php b/include/derivative_params.inc.php index b0090cafa..dc375da2c 100644 --- a/include/derivative_params.inc.php +++ b/include/derivative_params.inc.php @@ -240,7 +240,7 @@ final class DerivativeParams public $use_watermark = false; public $sizing; public $sharpen = 0; - public $quality = 85; + public $quality = 95; function __construct($sizing) {