From 16371ed5fd9f0df6e8c3d6d349845bc2ec057081 Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 23 Dec 2010 10:22:51 +0000 Subject: feature 2083 added: implement method pwg.images.addSimple in core makes admin/include/function_upload.inc.php not dependant from include/ws_functions.inc.php (moves functions file_path_for_type and ready_for_upload_message) cleaner method to initialize the upload settings git-svn-id: http://piwigo.org/svn/trunk@8249 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions_upload.inc.php | 288 +++++++++++++++++++++++++++++---- 1 file changed, 259 insertions(+), 29 deletions(-) (limited to 'admin/include') diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index 7eaeb90f5..2dc21d7bf 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -1,30 +1,197 @@ 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'), + ), + + 'hd_keep' => array( + 'default' => true, + 'can_be_null' => false, + ), + + 'hd_resize' => array( + 'default' => false, + 'can_be_null' => false, + ), + + 'hd_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'), + ), + + 'hd_maxheight' => array( + 'default' => 2000, + 'min' => 500, + 'max' => 20000, + 'pattern' => '/^\d+$/', + 'can_be_null' => false, + 'error_message' => l10n('The high definition maximum height must be a number between %d and %d'), + ), + + 'hd_quality' => array( + 'default' => 95, + 'min' => 50, + 'max' => 100, + 'pattern' => '/^\d+$/', + 'can_be_null' => false, + 'error_message' => l10n('The high definition image quality must be a number between %d and %d'), + ), + ); + + return $upload_form_config; +} + +/* + * automatic fill of configuration parameters + */ +function prepare_upload_configuration() { global $conf; + $inserts = array(); + + foreach (get_upload_form_config() as $param_shortname => $param) + { + $param_name = 'upload_form_'.$param_shortname; + + if (!isset($conf[$param_name])) + { + $param_value = boolean_to_string($param['default']); + + array_push( + $inserts, + array( + 'param' => $param_name, + 'value' => $param_value, + ) + ); + + $conf[$param_name] = $param_value; + if (is_bool($param['default'])) + { + $conf[$param_name] = get_boolean($param_value); + } + } + } + + if (count($inserts) > 0) + { + mass_inserts( + CONFIG_TABLE, + array_keys($inserts[0]), + $inserts + ); + } +} + +function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=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 + // + // 4) register in database + + // TODO + // * check md5sum (already exists?) + + global $conf; + // current date list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); @@ -89,20 +256,23 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie { if ($conf['upload_form_hd_keep']) { - $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']); - - if ($conf['upload_form_hd_resize'] and $need_resize) + if ($conf['upload_form_hd_resize']) { - pwg_image_resize( - false, - $high_path, - $high_path, - $conf['upload_form_hd_maxwidth'], - $conf['upload_form_hd_maxheight'], - $conf['upload_form_hd_quality'], - false - ); - $high_infos = pwg_image_infos($high_path); + $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']); + + if ($need_resize) + { + pwg_image_resize( + false, + $high_path, + $high_path, + $conf['upload_form_hd_maxwidth'], + $conf['upload_form_hd_maxheight'], + $conf['upload_form_hd_quality'], + false + ); + $high_infos = pwg_image_infos($high_path); + } } } else @@ -557,4 +727,64 @@ function is_imagick() return false; } + +function ready_for_upload_message() +{ + global $conf; + + $relative_dir = preg_replace('#^'.PHPWG_ROOT_PATH.'#', '', $conf['upload_dir']); + + if (!is_dir($conf['upload_dir'])) + { + if (!is_writable(dirname($conf['upload_dir']))) + { + return sprintf( + l10n('Create the "%s" directory at the root of your Piwigo installation'), + $relative_dir + ); + } + } + else + { + if (!is_writable($conf['upload_dir'])) + { + @chmod($conf['upload_dir'], 0777); + + if (!is_writable($conf['upload_dir'])) + { + return sprintf( + l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'), + $relative_dir + ); + } + } + } + + return null; +} + +function file_path_for_type($file_path, $type='thumb') +{ + // resolve the $file_path depending on the $type + if ('thumb' == $type) { + $file_path = get_thumbnail_location( + array( + 'path' => $file_path, + 'tn_ext' => 'jpg', + ) + ); + } + + if ('high' == $type) { + @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); + $file_path = get_high_location( + array( + 'path' => $file_path, + 'has_high' => 'true' + ) + ); + } + + return $file_path; +} ?> \ No newline at end of file -- cgit v1.2.3