diff options
author | plegall <plg@piwigo.org> | 2012-04-19 14:43:30 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2012-04-19 14:43:30 +0000 |
commit | 796b6b3ffef5bb4798aab075ff197f8cdfd62f3d (patch) | |
tree | dc6f9e450a76ebbe27f1590ceee3bb1da012e8bf /admin | |
parent | fed0c74a920c2c4db209d821f8b59075a2a5a80e (diff) |
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
Diffstat (limited to 'admin')
-rw-r--r-- | admin/configuration.php | 132 | ||||
-rw-r--r-- | admin/include/configuration_sizes_process.inc.php | 265 | ||||
-rw-r--r-- | admin/include/functions_upload.inc.php | 4 | ||||
-rw-r--r-- | admin/themes/default/template/configuration.tpl | 42 |
4 files changed, 354 insertions, 89 deletions
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; + $template->append( + 'sizes', + array( + $checkbox => $conf[$checkbox] + ), + true + ); } - else + + // derivatives = multiple size + $enabled = ImageStdParams::get_defined_type_map(); + $disabled = @unserialize(@$conf['disabled_derivatives']); + if ($disabled === false) { - $tpl_var['enabled']=false; - $params=@$disabled[$type]; + $disabled = array(); } - - if ($params) + + $common_quality = 50; + + $tpl_vars = array(); + foreach(ImageStdParams::get_all_types() as $type) { - list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size; - if ( ($tpl_var['crop'] = round(100*$params->sizing->max_crop)) > 0) + $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]; + } + + 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_var['sharpen'] = $params->sharpen; - $tpl_var['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 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based photo gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | +// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | +// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +if( !defined("PHPWG_ROOT_PATH") ) +{ + die ("Hacking attempt!"); +} + +$errors = array(); + +// original resize +$original_fields = array( + 'original_resize', + 'original_resize_maxwidth', + 'original_resize_maxheight', + 'original_resize_quality', + ); + +$updates = array(); + +foreach ($original_fields as $field) +{ + $value = !empty($_POST[$field]) ? $_POST[$field] : null; + $updates[$field] = $value; +} + +save_upload_form_config($updates, $page['errors'], $errors); + +if ($_POST['resize_quality'] < 50 or $_POST['resize_quality'] > 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} -<style> +{html_head}{literal} +<style type="text/css"> +input[type="text"].dError {border-color:#ff7070; background-color:#FFe5e5;} +.dErrorDesc {background-color:red; color:white; padding:0 5px;border-radius:10px; font-weight:bold;cursor:help;} .sizeEnable {width:50px;} .sizeEditForm {margin:0 0 10px 20px;} .sizeEdit {display:none;} @@ -329,7 +331,7 @@ jQuery(document).ready(function(){ .sizeDetails {display:none;margin-left:10px;} .sizeEditOpen {margin-left:10px;} </style> -{/literal} +{/literal}{/html_head} <fieldset id="sizesConf"> <legend>{'Original Size'|@translate}</legend> @@ -344,27 +346,34 @@ jQuery(document).ready(function(){ <table id="sizeEdit-original"> <tr> <th>{'Maximum Width'|@translate}</th> - <td><input type="text" name="original_resize_maxwidth" value="{$sizes.original_resize_maxwidth}" size="4" maxlength="4"> {'pixels'|@translate}</td> + <td> + <input type="text" name="original_resize_maxwidth" value="{$sizes.original_resize_maxwidth}" size="4" maxlength="4"{if isset($ferrors.original_resize_maxwidth)} class="dError"{/if}> {'pixels'|@translate} + {if isset($ferrors.original_resize_maxwidth)}<span class="dErrorDesc" title="{$ferrors.original_resize_maxwidth}">!</span>{/if} + </td> </tr> <tr> <th>{'Maximum Height'|@translate}</th> - <td><input type="text" name="original_resize_maxheight" value="{$sizes.original_resize_maxheight}" size="4" maxlength="4"> {'pixels'|@translate}</td> + <td> + <input type="text" name="original_resize_maxheight" value="{$sizes.original_resize_maxheight}" size="4" maxlength="4"{if isset($ferrors.original_resize_maxheight)} class="dError"{/if}> {'pixels'|@translate} + {if isset($ferrors.original_resize_maxheight)}<span class="dErrorDesc" title="{$ferrors.original_resize_maxheight}">!</span>{/if} + </td> </tr> <tr> <th>{'Image Quality'|@translate}</th> - <td><input type="text" name="original_resize_quality" value="{$sizes.original_resize_quality}" size="3" maxlength="3"> %</td> + <td> + <input type="text" name="original_resize_quality" value="{$sizes.original_resize_quality}" size="3" maxlength="3"{if isset($ferrors.original_resize_quality)} class="dError"{/if}> % + {if isset($ferrors.original_resize_quality)}<span class="dErrorDesc" title="{$ferrors.original_resize_quality}">!</span>{/if} + </td> </tr> </table> </fieldset> -<div class="warnings">Warning: the following fields are for test "user interface" test only. Any change won't be saved.<br>See screen [Administration > Configuration > Multiple Size] to configure sizes.</div> - <fieldset id="multiSizesConf"> <legend>{'Multiple Size'|@translate}</legend> <div class="showDetails"> - <a href="#" id="showDetails"{if $show_details} style="display:none"{/if}>{'show details'|@translate}</a> + <a href="#" id="showDetails"{if $show_details or isset($ferrors)} style="display:none"{/if}>{'show details'|@translate}</a> </div> <table style="margin:0"> @@ -384,17 +393,17 @@ jQuery(document).ready(function(){ </td> <td> - <span class="sizeDetails">{$d.w} x {$d.h} {'pixels'|@translate}{if $d.crop}, {'Crop'|@translate|lower}{/if}</span> + <span class="sizeDetails"{if isset($ferrors)} style="display:inline"{/if}>{$d.w} x {$d.h} {'pixels'|@translate}{if $d.crop}, {'Crop'|@translate|lower}{/if}</span> </td> <td> - <span class="sizeDetails"> + <span class="sizeDetails"{if isset($ferrors) and !isset($ferrors.$type)} style="display:inline"{/if}> <a href="#" id="sizeEditOpen-{$type}" class="sizeEditOpen">{'edit'|@translate}</a> </span> </td> </tr> - <tr id="sizeEdit-{$type}" class="sizeEdit"> + <tr id="sizeEdit-{$type}" class="sizeEdit" {if isset($ferrors.$type)} style="display:block"{/if}> <td colspan="3"> <table class="sizeEditForm"> {if !$d.must_square} @@ -411,7 +420,7 @@ jQuery(document).ready(function(){ <tr> <td class="sizeEditWidth">{if $d.must_square or $d.crop}{'Width'|@translate}{else}{'Maximum Width'|@translate}{/if}</td> <td> - <input type="text" name="d[{$type}][w]" maxlength="4" size="4" value="{$d.w}"{if isset($ferrors.$type.w)}class="dError"{/if}> + <input type="text" name="d[{$type}][w]" maxlength="4" size="4" value="{$d.w}"{if isset($ferrors.$type.w)} class="dError"{/if}> {'pixels'|@translate} {if isset($ferrors.$type.w)}<span class="dErrorDesc" title="{$ferrors.$type.w}">!</span>{/if} </td> @@ -421,7 +430,7 @@ jQuery(document).ready(function(){ <tr> <td class="sizeEditHeight">{if $d.crop}{'Height'|@translate}{else}{'Maximum Height'|@translate}{/if}</td> <td> - <input type="text" name="d[{$type}][h]" maxlength="4" size="4" value="{$d.h}"{if isset($ferrors.$type.h)}class="dError"{/if}> + <input type="text" name="d[{$type}][h]" maxlength="4" size="4" value="{$d.h}"{if isset($ferrors.$type.h)} class="dError"{/if}> {'pixels'|@translate} {if isset($ferrors.$type.h)}<span class="dErrorDesc" title="{$ferrors.$type.h}">!</span>{/if} </td> @@ -433,9 +442,10 @@ jQuery(document).ready(function(){ {/foreach} </table> -<p style="margin:20px 0 0 0" class="sizeDetails"> +<p style="margin:20px 0 0 0;{if isset($ferrors)} display:block;{/if}" class="sizeDetails"> {'Image Quality'|@translate} - <input type="text" name="original_resize_quality" value="{$sizes.original_resize_quality}" size="3" maxlength="3"> % + <input type="text" name="resize_quality" value="{$resize_quality}" size="3" maxlength="3"{if isset($ferrors.resize_quality)} class="dError"{/if}> % + {if isset($ferrors.resize_quality)}<span class="dErrorDesc" title="{$ferrors.resize_quality}">!</span>{/if} </p> </fieldset> {/if} |