Changeset 8249 for trunk/admin
- Timestamp:
- Dec 23, 2010, 11:22:51 AM (13 years ago)
- Location:
- trunk/admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions_upload.inc.php
r8227 r8249 1 1 <?php 2 // TODO 3 // * check md5sum (already exists?) 4 5 include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); 6 include_once(PHPWG_ROOT_PATH.'include/ws_functions.inc.php'); 2 // +-----------------------------------------------------------------------+ 3 // | Piwigo - a PHP based picture gallery | 4 // +-----------------------------------------------------------------------+ 5 // | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | 6 // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | 7 // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | 8 // +-----------------------------------------------------------------------+ 9 // | This program is free software; you can redistribute it and/or modify | 10 // | it under the terms of the GNU General Public License as published by | 11 // | the Free Software Foundation | 12 // | | 13 // | This program is distributed in the hope that it will be useful, but | 14 // | WITHOUT ANY WARRANTY; without even the implied warranty of | 15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 // | General Public License for more details. | 17 // | | 18 // | You should have received a copy of the GNU General Public License | 19 // | along with this program; if not, write to the Free Software | 20 // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | 21 // | USA. | 22 // +-----------------------------------------------------------------------+ 23 7 24 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 8 9 // Here is the plan10 //11 // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg12 //13 // 2) if taller than max_height or wider than max_width, move to pwg_high14 // + web sized creation15 //16 // 3) thumbnail creation from web sized17 //18 // 4) register in database19 25 20 26 // add default event handler for image and thumbnail resize … … 22 28 add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 7); 23 29 30 function get_upload_form_config() 31 { 32 // default configuration for upload 33 $upload_form_config = array( 34 'websize_resize' => array( 35 'default' => true, 36 'can_be_null' => false, 37 ), 38 39 'websize_maxwidth' => array( 40 'default' => 800, 41 'min' => 100, 42 'max' => 1600, 43 'pattern' => '/^\d+$/', 44 'can_be_null' => true, 45 'error_message' => l10n('The websize maximum width must be a number between %d and %d'), 46 ), 47 48 'websize_maxheight' => array( 49 'default' => 600, 50 'min' => 100, 51 'max' => 1200, 52 'pattern' => '/^\d+$/', 53 'can_be_null' => true, 54 'error_message' => l10n('The websize maximum height must be a number between %d and %d'), 55 ), 56 57 'websize_quality' => array( 58 'default' => 95, 59 'min' => 50, 60 'max' => 100, 61 'pattern' => '/^\d+$/', 62 'can_be_null' => false, 63 'error_message' => l10n('The websize image quality must be a number between %d and %d'), 64 ), 65 66 'thumb_maxwidth' => array( 67 'default' => 128, 68 'min' => 50, 69 'max' => 300, 70 'pattern' => '/^\d+$/', 71 'can_be_null' => false, 72 'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'), 73 ), 74 75 'thumb_maxheight' => array( 76 'default' => 96, 77 'min' => 50, 78 'max' => 300, 79 'pattern' => '/^\d+$/', 80 'can_be_null' => false, 81 'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'), 82 ), 83 84 'thumb_quality' => array( 85 'default' => 95, 86 'min' => 50, 87 'max' => 100, 88 'pattern' => '/^\d+$/', 89 'can_be_null' => false, 90 'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'), 91 ), 92 93 'hd_keep' => array( 94 'default' => true, 95 'can_be_null' => false, 96 ), 97 98 'hd_resize' => array( 99 'default' => false, 100 'can_be_null' => false, 101 ), 102 103 'hd_maxwidth' => array( 104 'default' => 2000, 105 'min' => 500, 106 'max' => 20000, 107 'pattern' => '/^\d+$/', 108 'can_be_null' => false, 109 'error_message' => l10n('The high definition maximum width must be a number between %d and %d'), 110 ), 111 112 'hd_maxheight' => array( 113 'default' => 2000, 114 'min' => 500, 115 'max' => 20000, 116 'pattern' => '/^\d+$/', 117 'can_be_null' => false, 118 'error_message' => l10n('The high definition maximum height must be a number between %d and %d'), 119 ), 120 121 'hd_quality' => array( 122 'default' => 95, 123 'min' => 50, 124 'max' => 100, 125 'pattern' => '/^\d+$/', 126 'can_be_null' => false, 127 'error_message' => l10n('The high definition image quality must be a number between %d and %d'), 128 ), 129 ); 130 131 return $upload_form_config; 132 } 133 134 /* 135 * automatic fill of configuration parameters 136 */ 137 function prepare_upload_configuration() 138 { 139 global $conf; 140 141 $inserts = array(); 142 143 foreach (get_upload_form_config() as $param_shortname => $param) 144 { 145 $param_name = 'upload_form_'.$param_shortname; 146 147 if (!isset($conf[$param_name])) 148 { 149 $param_value = boolean_to_string($param['default']); 150 151 array_push( 152 $inserts, 153 array( 154 'param' => $param_name, 155 'value' => $param_value, 156 ) 157 ); 158 159 $conf[$param_name] = $param_value; 160 if (is_bool($param['default'])) 161 { 162 $conf[$param_name] = get_boolean($param_value); 163 } 164 } 165 } 166 167 if (count($inserts) > 0) 168 { 169 mass_inserts( 170 CONFIG_TABLE, 171 array_keys($inserts[0]), 172 $inserts 173 ); 174 } 175 } 176 24 177 function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null) 25 178 { 179 // Here is the plan 180 // 181 // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg 182 // 183 // 2) if taller than max_height or wider than max_width, move to pwg_high 184 // + web sized creation 185 // 186 // 3) thumbnail creation from web sized 187 // 188 // 4) register in database 189 190 // TODO 191 // * check md5sum (already exists?) 192 26 193 global $conf; 27 194 28 195 // current date 29 196 list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); … … 90 257 if ($conf['upload_form_hd_keep']) 91 258 { 92 $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']); 259 if ($conf['upload_form_hd_resize']) 260 { 261 $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']); 93 262 94 if ($conf['upload_form_hd_resize'] and $need_resize) 95 { 96 pwg_image_resize( 97 false, 98 $high_path, 99 $high_path, 100 $conf['upload_form_hd_maxwidth'], 101 $conf['upload_form_hd_maxheight'], 102 $conf['upload_form_hd_quality'], 103 false 104 ); 105 $high_infos = pwg_image_infos($high_path); 263 if ($need_resize) 264 { 265 pwg_image_resize( 266 false, 267 $high_path, 268 $high_path, 269 $conf['upload_form_hd_maxwidth'], 270 $conf['upload_form_hd_maxheight'], 271 $conf['upload_form_hd_quality'], 272 false 273 ); 274 $high_infos = pwg_image_infos($high_path); 275 } 106 276 } 107 277 } … … 558 728 return false; 559 729 } 730 731 function ready_for_upload_message() 732 { 733 global $conf; 734 735 $relative_dir = preg_replace('#^'.PHPWG_ROOT_PATH.'#', '', $conf['upload_dir']); 736 737 if (!is_dir($conf['upload_dir'])) 738 { 739 if (!is_writable(dirname($conf['upload_dir']))) 740 { 741 return sprintf( 742 l10n('Create the "%s" directory at the root of your Piwigo installation'), 743 $relative_dir 744 ); 745 } 746 } 747 else 748 { 749 if (!is_writable($conf['upload_dir'])) 750 { 751 @chmod($conf['upload_dir'], 0777); 752 753 if (!is_writable($conf['upload_dir'])) 754 { 755 return sprintf( 756 l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'), 757 $relative_dir 758 ); 759 } 760 } 761 } 762 763 return null; 764 } 765 766 function file_path_for_type($file_path, $type='thumb') 767 { 768 // resolve the $file_path depending on the $type 769 if ('thumb' == $type) { 770 $file_path = get_thumbnail_location( 771 array( 772 'path' => $file_path, 773 'tn_ext' => 'jpg', 774 ) 775 ); 776 } 777 778 if ('high' == $type) { 779 @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); 780 $file_path = get_high_location( 781 array( 782 'path' => $file_path, 783 'has_high' => 'true' 784 ) 785 ); 786 } 787 788 return $file_path; 789 } 560 790 ?> -
trunk/admin/photos_add.php
r8227 r8249 44 44 // +-----------------------------------------------------------------------+ 45 45 46 // automatic fill of configuration parameters 47 $upload_form_config = array( 48 'websize_resize' => array( 49 'default' => true, 50 'can_be_null' => false, 51 ), 52 53 'websize_maxwidth' => array( 54 'default' => 800, 55 'min' => 100, 56 'max' => 1600, 57 'pattern' => '/^\d+$/', 58 'can_be_null' => true, 59 'error_message' => l10n('The websize maximum width must be a number between %d and %d'), 60 ), 61 62 'websize_maxheight' => array( 63 'default' => 600, 64 'min' => 100, 65 'max' => 1200, 66 'pattern' => '/^\d+$/', 67 'can_be_null' => true, 68 'error_message' => l10n('The websize maximum height must be a number between %d and %d'), 69 ), 70 71 'websize_quality' => array( 72 'default' => 95, 73 'min' => 50, 74 'max' => 100, 75 'pattern' => '/^\d+$/', 76 'can_be_null' => false, 77 'error_message' => l10n('The websize image quality must be a number between %d and %d'), 78 ), 79 80 'thumb_maxwidth' => array( 81 'default' => 128, 82 'min' => 50, 83 'max' => 300, 84 'pattern' => '/^\d+$/', 85 'can_be_null' => false, 86 'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'), 87 ), 88 89 'thumb_maxheight' => array( 90 'default' => 96, 91 'min' => 50, 92 'max' => 300, 93 'pattern' => '/^\d+$/', 94 'can_be_null' => false, 95 'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'), 96 ), 97 98 'thumb_quality' => array( 99 'default' => 95, 100 'min' => 50, 101 'max' => 100, 102 'pattern' => '/^\d+$/', 103 'can_be_null' => false, 104 'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'), 105 ), 106 107 'hd_keep' => array( 108 'default' => true, 109 'can_be_null' => false, 110 ), 111 112 'hd_resize' => array( 113 'default' => false, 114 'can_be_null' => false, 115 ), 116 117 'hd_maxwidth' => array( 118 'default' => 2000, 119 'min' => 500, 120 'max' => 20000, 121 'pattern' => '/^\d+$/', 122 'can_be_null' => false, 123 'error_message' => l10n('The high definition maximum width must be a number between %d and %d'), 124 ), 125 126 'hd_maxheight' => array( 127 'default' => 2000, 128 'min' => 500, 129 'max' => 20000, 130 'pattern' => '/^\d+$/', 131 'can_be_null' => false, 132 'error_message' => l10n('The high definition maximum height must be a number between %d and %d'), 133 ), 134 135 'hd_quality' => array( 136 'default' => 95, 137 'min' => 50, 138 'max' => 100, 139 'pattern' => '/^\d+$/', 140 'can_be_null' => false, 141 'error_message' => l10n('The high definition image quality must be a number between %d and %d'), 142 ), 143 ); 46 prepare_upload_configuration(); 144 47 145 $inserts = array(); 146 147 foreach ($upload_form_config as $param_shortname => $param) 148 { 149 $param_name = 'upload_form_'.$param_shortname; 150 151 if (!isset($conf[$param_name])) 152 { 153 $param_value = boolean_to_string($param['default']); 154 155 array_push( 156 $inserts, 157 array( 158 'param' => $param_name, 159 'value' => $param_value, 160 ) 161 ); 162 $conf[$param_name] = $param_value; 163 } 164 } 165 166 if (count($inserts) > 0) 167 { 168 mass_inserts( 169 CONFIG_TABLE, 170 array_keys($inserts[0]), 171 $inserts 172 ); 173 } 48 $upload_form_config = get_upload_form_config(); 174 49 175 50 // +-----------------------------------------------------------------------+ … … 239 114 ); 240 115 241 // $template->append(242 // 'head_elements',243 // '<link rel="stylesheet" type="text/css" href="'.UPLOAD_FORM_PATH.'upload.css">'."\n"244 // );245 246 116 // +-----------------------------------------------------------------------+ 247 117 // | Load the tab |
Note: See TracChangeset
for help on using the changeset viewer.