From cac417c74bc6d5f528b356190561d244e9b4f93a Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 12 Jan 2012 21:37:28 +0000 Subject: feature 2548, multiple size: * adapt the upload script * remove the resize settings screen * add a new screen [Administration > Configuration > Options > Photo Sizes] with the ability to resize original after upload git-svn-id: http://piwigo.org/svn/trunk@12879 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/batch_manager_global.php | 9 - admin/configuration.php | 62 +++++- admin/include/functions_upload.inc.php | 221 ++++----------------- admin/include/photos_add_direct_process.inc.php | 7 +- admin/include/uploadify/uploadify.php | 2 +- admin/photos_add.php | 4 - admin/photos_add_settings.php | 125 ------------ admin/themes/default/template/configuration.tpl | 48 ++++- .../default/template/photos_add_settings.tpl | 163 --------------- 9 files changed, 146 insertions(+), 495 deletions(-) delete mode 100644 admin/photos_add_settings.php delete mode 100644 admin/themes/default/template/photos_add_settings.tpl (limited to 'admin') diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php index 73e3586b5..c6ee4bd0a 100644 --- a/admin/batch_manager_global.php +++ b/admin/batch_manager_global.php @@ -33,14 +33,6 @@ if (!defined('PHPWG_ROOT_PATH')) } include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); -include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); - -$upload_form_config = get_upload_form_config(); -foreach ($upload_form_config as $param_shortname => $param) -{ - $param_name = 'upload_form_'.$param_shortname; - $form_values[$param_shortname] = $conf[$param_name]; -} // +-----------------------------------------------------------------------+ // | Check Access and exit when user status is not ok | @@ -463,7 +455,6 @@ $template->assign( 'filter' => $_SESSION['bulk_manager_filter'], 'selection' => $collection, 'all_elements' => $page['cat_elements_id'], - 'upload_form_settings' => $form_values, 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), 'F_ACTION'=>$base_url.get_query_string_diff(array('cat')), ) diff --git a/admin/configuration.php b/admin/configuration.php index a59e815fc..bc6f3634d 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -27,6 +27,7 @@ if( !defined("PHPWG_ROOT_PATH") ) } include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); +include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); // +-----------------------------------------------------------------------+ @@ -54,6 +55,10 @@ $main_checkboxes = array( 'allow_user_customization', ); +$sizes_checkboxes = array( + 'original_resize', + ); + $history_checkboxes = array( 'log', 'history_admin', @@ -182,6 +187,36 @@ if (isset($_POST['submit'])) } break; } + 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') + ); + } + + break; + } case 'history' : { foreach( $history_checkboxes as $checkbox) @@ -228,7 +263,7 @@ if (isset($_POST['submit'])) } // updating configuration if no error found - if (count($page['errors']) == 0) + if ('sizes' != $page['section'] and count($page['errors']) == 0) { //echo '
'; print_r($_POST); echo '
'; $result = pwg_query('SELECT param FROM '.CONFIG_TABLE); @@ -268,6 +303,7 @@ $template->set_filename('config', 'configuration.tpl'); $tabsheet = new tabsheet(); // TabSheet initialization $tabsheet->add('main', l10n('Main'), $conf_link.'main'); +$tabsheet->add('sizes', l10n('Photo Sizes'), $conf_link.'sizes'); $tabsheet->add('display', l10n('Display'), $conf_link.'display'); $tabsheet->add('history', l10n('History'), $conf_link.'history'); $tabsheet->add('comments', l10n('Comments'), $conf_link.'comments'); @@ -439,6 +475,30 @@ switch ($page['section']) ); break; } + 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) + { + $template->append( + 'sizes', + array( + $checkbox => $conf[$checkbox] + ), + true + ); + } + + break; + } } //----------------------------------------------------------- sending html code diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index 9181e3dc6..da2e9b700 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -32,110 +32,36 @@ function get_upload_form_config() { // default configuration for upload $upload_form_config = array( - 'websize_resize' => array( - 'default' => true, - 'can_be_null' => false, - ), - - 'websize_maxwidth' => array( - 'default' => 800, - 'min' => 100, - 'max' => 1600, - 'pattern' => '/^\d+$/', - 'can_be_null' => true, - 'error_message' => l10n('The websize maximum width must be a number between %d and %d'), - ), - - 'websize_maxheight' => array( - 'default' => 600, - 'min' => 100, - 'max' => 1200, - 'pattern' => '/^\d+$/', - 'can_be_null' => true, - 'error_message' => l10n('The websize maximum height must be a number between %d and %d'), - ), - - 'websize_quality' => array( - 'default' => 95, - 'min' => 50, - 'max' => 100, - 'pattern' => '/^\d+$/', - 'can_be_null' => false, - 'error_message' => l10n('The websize image quality must be a number between %d and %d'), - ), - - 'thumb_maxwidth' => array( - 'default' => 128, - 'min' => 50, - 'max' => 300, - 'pattern' => '/^\d+$/', - 'can_be_null' => false, - 'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'), - ), - - 'thumb_maxheight' => array( - 'default' => 96, - 'min' => 50, - 'max' => 300, - 'pattern' => '/^\d+$/', - 'can_be_null' => false, - 'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'), - ), - - 'thumb_quality' => array( - 'default' => 95, - 'min' => 50, - 'max' => 100, - 'pattern' => '/^\d+$/', - 'can_be_null' => false, - 'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'), - ), - - 'thumb_crop' => array( - 'default' => false, - 'can_be_null' => false, - ), - - 'thumb_follow_orientation' => array( - 'default' => true, - 'can_be_null' => false, - ), - - 'hd_keep' => array( - 'default' => true, - 'can_be_null' => false, - ), - - 'hd_resize' => array( + 'original_resize' => array( 'default' => false, 'can_be_null' => false, ), - 'hd_maxwidth' => array( + 'original_resize_maxwidth' => array( 'default' => 2000, 'min' => 500, 'max' => 20000, 'pattern' => '/^\d+$/', 'can_be_null' => false, - 'error_message' => l10n('The high definition maximum width must be a number between %d and %d'), + 'error_message' => l10n('The original maximum width must be a number between %d and %d'), ), - 'hd_maxheight' => array( + 'original_resize_maxheight' => array( 'default' => 2000, - 'min' => 500, + 'min' => 300, 'max' => 20000, 'pattern' => '/^\d+$/', 'can_be_null' => false, - 'error_message' => l10n('The high definition maximum height must be a number between %d and %d'), + 'error_message' => l10n('The original maximum height must be a number between %d and %d'), ), - 'hd_quality' => array( + 'original_resize_quality' => array( 'default' => 95, 'min' => 50, - 'max' => 100, + 'max' => 98, 'pattern' => '/^\d+$/', 'can_be_null' => false, - 'error_message' => l10n('The high definition image quality must be a number between %d and %d'), + 'error_message' => l10n('The original image quality must be a number between %d and %d'), ), ); @@ -170,14 +96,14 @@ function save_upload_form_config($data, &$errors=array()) } $updates[] = array( - 'param' => 'upload_form_'.$field, + 'param' => $field, 'value' => boolean_to_string($value) ); } elseif ($upload_form_config[$field]['can_be_null'] and empty($value)) { $updates[] = array( - 'param' => 'upload_form_'.$field, + 'param' => $field, 'value' => 'false' ); } @@ -190,7 +116,7 @@ function save_upload_form_config($data, &$errors=array()) if (preg_match($pattern, $value) and $value >= $min and $value <= $max) { $updates[] = array( - 'param' => 'upload_form_'.$field, + 'param' => $field, 'value' => $value ); } @@ -226,16 +152,11 @@ function save_upload_form_config($data, &$errors=array()) function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null) { - // Here is the plan - // // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg // - // 2) if taller than max_height or wider than max_width, move to pwg_high - // + web sized creation - // - // 3) thumbnail creation from web sized + // 2) keep/resize original // - // 4) register in database + // 3) register in database // TODO // * check md5sum (already exists?) @@ -247,7 +168,7 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie if (isset($image_id)) { - // we are performing an update + // this photo already exists, we update it $query = ' SELECT path @@ -316,83 +237,35 @@ SELECT copy($source_filepath, $file_path); } - if ($conf['upload_form_websize_resize'] - and need_resize($file_path, $conf['upload_form_websize_maxwidth'], $conf['upload_form_websize_maxheight'])) + if (pwg_image::get_library() != 'gd') { - $high_path = file_path_for_type($file_path, 'high'); - $high_dir = dirname($high_path); - prepare_directory($high_dir); - - rename($file_path, $high_path); - $high_infos = pwg_image_infos($high_path); - - $img = new pwg_image($high_path); - - $img->pwg_resize( - $file_path, - $conf['upload_form_websize_maxwidth'], - $conf['upload_form_websize_maxheight'], - $conf['upload_form_websize_quality'], - $conf['upload_form_automatic_rotation'], - false - ); - - if ($img->library != 'gd') + if ($conf['original_resize']) { - if ($conf['upload_form_hd_keep']) + $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']); + + if ($need_resize) { - if ($conf['upload_form_hd_resize']) - { - $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']); + $img = new pwg_image($file_path); + + $img->pwg_resize( + $file_path, + $conf['original_resize_maxwidth'], + $conf['original_resize_maxheight'], + $conf['original_resize_quality'], + $conf['upload_form_automatic_rotation'], + false + ); - if ($need_resize) - { - $img->pwg_resize( - $high_path, - $conf['upload_form_hd_maxwidth'], - $conf['upload_form_hd_maxheight'], - $conf['upload_form_hd_quality'], - $conf['upload_form_automatic_rotation'], - false - ); - $high_infos = pwg_image_infos($high_path); - } - } - } - else - { - unlink($high_path); - $high_infos = null; + $img->destroy(); } } - $img->destroy(); } $file_infos = pwg_image_infos($file_path); - $thumb_path = file_path_for_type($file_path, 'thumb'); - $thumb_dir = dirname($thumb_path); - prepare_directory($thumb_dir); - - $img = new pwg_image($file_path); - $img->pwg_resize( - $thumb_path, - $conf['upload_form_thumb_maxwidth'], - $conf['upload_form_thumb_maxheight'], - $conf['upload_form_thumb_quality'], - false, - true, - $conf['upload_form_thumb_crop'], - $conf['upload_form_thumb_follow_orientation'] - ); - $img->destroy(); - - $thumb_infos = pwg_image_infos($thumb_path); - if (isset($image_id)) { $update = array( - 'id' => $image_id, 'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], @@ -401,33 +274,15 @@ SELECT 'added_by' => $user['id'], ); - if (isset($high_infos)) - { - $update['has_high'] = 'true'; - $update['high_filesize'] = $high_infos['filesize']; - $update['high_width'] = $high_infos['width']; - $update['high_height'] = $high_infos['height']; - } - else - { - $update['has_high'] = 'false'; - $update['high_filesize'] = null; - $update['high_width'] = null; - $update['high_height'] = null; - } - if (isset($level)) { $update['level'] = $level; } - mass_updates( + single_update( IMAGES_TABLE, - array( - 'primary' => array('id'), - 'update' => array_keys($update) - ), - array($update) + $update, + array('id' => $image_id) ); } else @@ -457,12 +312,8 @@ SELECT { $insert['level'] = $level; } - - mass_inserts( - IMAGES_TABLE, - array_keys($insert), - array($insert) - ); + + single_insert(IMAGES_TABLE, $insert); $image_id = pwg_db_insert_id(IMAGES_TABLE); } diff --git a/admin/include/photos_add_direct_process.inc.php b/admin/include/photos_add_direct_process.inc.php index c0cb3e4c0..03900747e 100644 --- a/admin/include/photos_add_direct_process.inc.php +++ b/admin/include/photos_add_direct_process.inc.php @@ -202,12 +202,7 @@ SELECT $thumbnail['file'] = $image_infos['file']; - $thumbnail['src'] = get_thumbnail_location( - array( - 'path' => $image_infos['path'], - 'tn_ext' => $image_infos['tn_ext'], - ) - ); + $thumbnail['src'] = DerivativeImage::thumb_url($image_infos); // TODO: when implementing this plugin in Piwigo core, we should have // a function get_image_name($name, $file) (if name is null, then diff --git a/admin/include/uploadify/uploadify.php b/admin/include/uploadify/uploadify.php index d70e44635..cc30cf9e7 100644 --- a/admin/include/uploadify/uploadify.php +++ b/admin/include/uploadify/uploadify.php @@ -72,7 +72,7 @@ SELECT ;'; $image_infos = pwg_db_fetch_assoc(pwg_query($query)); -$thumbnail_url = preg_replace('#^'.PHPWG_ROOT_PATH.'#', './', get_thumbnail_url($image_infos)); +$thumbnail_url = preg_replace('#^'.PHPWG_ROOT_PATH.'#', './', DerivativeImage::thumb_url($image_infos)); $return = array( 'image_id' => $image_id, diff --git a/admin/photos_add.php b/admin/photos_add.php index 0b7053e64..d1962808a 100644 --- a/admin/photos_add.php +++ b/admin/photos_add.php @@ -55,10 +55,6 @@ $tabs = array( 'code' => 'direct', 'label' => l10n('Upload Photos'), ), - array( - 'code' => 'settings', - 'label' => l10n('Settings'), - ), array( 'code' => 'ploader', 'label' => l10n('Piwigo Uploader'), diff --git a/admin/photos_add_settings.php b/admin/photos_add_settings.php deleted file mode 100644 index eebbec15c..000000000 --- a/admin/photos_add_settings.php +++ /dev/null @@ -1,125 +0,0 @@ - $param) -{ - $param_name = 'upload_form_'.$param_shortname; - $form_values[$param_shortname] = $conf[$param_name]; -} - -// +-----------------------------------------------------------------------+ -// | process form | -// +-----------------------------------------------------------------------+ - -if (isset($_POST['submit'])) -{ - $updates = array(); - - // let's care about the specific checkbox that disable/enable other - // settings - $field = 'websize_resize'; - $fields[] = $field; - - if (!empty($_POST[$field])) - { - $fields[] = 'websize_maxwidth'; - $fields[] = 'websize_maxheight'; - $fields[] = 'websize_quality'; - } - - // hd_keep - $field = 'hd_keep'; - $fields[] = $field; - - if (!empty($_POST[$field])) - { - $field = 'hd_resize'; - $fields[] = $field; - - if (!empty($_POST[$field])) - { - $fields[] = 'hd_maxwidth'; - $fields[] = 'hd_maxheight'; - $fields[] = 'hd_quality'; - } - } - - // and now other fields, processed in a generic way - $fields[] = 'thumb_maxwidth'; - $fields[] = 'thumb_maxheight'; - $fields[] = 'thumb_quality'; - $fields[] = 'thumb_crop'; - $fields[] = 'thumb_follow_orientation'; - - 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') - ); - } -} - -// +-----------------------------------------------------------------------+ -// | template init | -// +-----------------------------------------------------------------------+ - -foreach (array_keys($upload_form_config) as $field) -{ - if (is_bool($upload_form_config[$field]['default'])) - { - $form_values[$field] = $form_values[$field] ? 'checked="checked"' : ''; - } -} - -$template->assign( - array( - 'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL, - 'MANAGE_HD' => pwg_image::get_library() != 'gd', - 'values' => $form_values - ) - ); - - -// +-----------------------------------------------------------------------+ -// | sending html code | -// +-----------------------------------------------------------------------+ - -$template->assign_var_from_handle('ADMIN_CONTENT', 'photos_add'); -?> \ No newline at end of file diff --git a/admin/themes/default/template/configuration.tpl b/admin/themes/default/template/configuration.tpl index 59ab62006..008dfe4e0 100644 --- a/admin/themes/default/template/configuration.tpl +++ b/admin/themes/default/template/configuration.tpl @@ -247,6 +247,52 @@ jQuery(document).ready(function () { +{if isset($sizes)} + +{footer_script}{literal} +jQuery(document).ready(function(){ + function toggleResizeFields(prefix) { + var checkbox = jQuery("#"+prefix+"_resize"); + var needToggle = jQuery("input[name^="+prefix+"_]").not(checkbox).parents('tr'); + + if (jQuery(checkbox).is(':checked')) { + needToggle.show(); + } + else { + needToggle.hide(); + } + } + + toggleResizeFields("original"); + jQuery("#original_resize").click(function () {toggleResizeFields("original")}); +}); +{/literal}{/footer_script} + +
+ {'Original Size'|@translate} + + + + + + + + + + + + + + + + + + +
{'Maximum Width'|@translate} {'pixels'|@translate}
{'Maximum Height'|@translate} {'pixels'|@translate}
{'Image Quality'|@translate} %
+ +
+{/if} + {if isset($default)} {$PROFILE_CONTENT} {/if} @@ -445,7 +491,7 @@ jQuery(document).ready(function () { {if !isset($default)}

- +

diff --git a/admin/themes/default/template/photos_add_settings.tpl b/admin/themes/default/template/photos_add_settings.tpl deleted file mode 100644 index 3180ac024..000000000 --- a/admin/themes/default/template/photos_add_settings.tpl +++ /dev/null @@ -1,163 +0,0 @@ -{footer_script} -var width = '{'Width'|@translate}'; -var height = '{'Height'|@translate}'; -var max_width = '{'Maximum Width'|@translate}'; -var max_height = '{'Maximum Height'|@translate}'; - -{literal} -jQuery(document).ready(function(){ - function toggleResizeFields(prefix) { - var checkbox = jQuery("#"+prefix+"_resize"); - var needToggle = jQuery("input[name^="+prefix+"_]").not(checkbox).not(jQuery("#hd_keep")).parents('tr'); - - if (jQuery(checkbox).is(':checked')) { - needToggle.show(); - - if (prefix == "websize") { - jQuery("#hd_keep").parents("fieldset").show(); - } - } - else { - needToggle.hide(); - - if (prefix == "websize") { - jQuery("#hd_keep").parents("fieldset").hide(); - } - } - } - - function toggleCropFields(prefix) { - if (jQuery("#"+prefix+"_crop").is(':checked')) { - jQuery("#"+prefix+"_width_th").text(width); - jQuery("#"+prefix+"_height_th").text(height); - jQuery("#"+prefix+"_follow_orientation_tr").show(); - } - else { - jQuery("#"+prefix+"_width_th").text(max_width); - jQuery("#"+prefix+"_height_th").text(max_height); - jQuery("#"+prefix+"_follow_orientation_tr").hide(); - } - - } - - toggleResizeFields("websize"); - jQuery("#websize_resize").click(function () {toggleResizeFields("websize")}); - - toggleResizeFields("hd"); - jQuery("#hd_resize").click(function () {toggleResizeFields("hd")}); - - toggleCropFields("thumb"); - jQuery("#thumb_crop").click(function () {toggleCropFields("thumb")}); - - function toggleHdFields() { - var checkbox = jQuery("#hd_keep"); - var needToggle = jQuery("input[name^=hd_]").not(checkbox).parents('tr'); - - if (jQuery(checkbox).is(':checked')) { - needToggle.show(); - toggleResizeFields("hd"); - } - else { - needToggle.hide(); - } - } - - toggleHdFields(); - jQuery("#hd_keep").click(function () {toggleHdFields()}); -}); -{/literal}{/footer_script} - -
-

{'Upload Photos'|@translate}

-
- -
- -
- -
- {'Web size photo'|@translate} - - - - - - - - - - - - - - - - - - -
{'Maximum Width'|@translate} {'pixels'|@translate}
{'Maximum Height'|@translate} {'pixels'|@translate}
{'Image Quality'|@translate} %
-
- -
- {'Thumbnail'|@translate} - - - - - - - - - - - - - - - - - - - - - - -
{'Maximum Width'|@translate} {'pixels'|@translate}
{'Maximum Height'|@translate} {'pixels'|@translate}
{'Image Quality'|@translate} %
-
- -{if $MANAGE_HD} -
- {'High definition'|@translate} - - - - - - - - - - - - - - - - - - - - - - -
{'Maximum Width'|@translate} {'pixels'|@translate}
{'Maximum Height'|@translate} {'pixels'|@translate}
{'Image Quality'|@translate} %
-
-{/if} - -

- -

- -
- -
-- cgit v1.2.3