1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 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 | |
---|
24 | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | // | Uploaded photos | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | |
---|
29 | if (isset($page['thumbnails'])) |
---|
30 | { |
---|
31 | $template->assign( |
---|
32 | array( |
---|
33 | 'thumbnails' => $page['thumbnails'], |
---|
34 | ) |
---|
35 | ); |
---|
36 | |
---|
37 | // only display the batch link if we have more than 1 photo |
---|
38 | if (count($page['thumbnails']) > 1) |
---|
39 | { |
---|
40 | $template->assign( |
---|
41 | array( |
---|
42 | 'batch_link' => $page['batch_link'], |
---|
43 | 'batch_label' => sprintf( |
---|
44 | l10n('Manage this set of %d photos'), |
---|
45 | count($page['thumbnails']) |
---|
46 | ), |
---|
47 | ) |
---|
48 | ); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | // +-----------------------------------------------------------------------+ |
---|
53 | // | Photo selection | |
---|
54 | // +-----------------------------------------------------------------------+ |
---|
55 | |
---|
56 | $uploadify_path = PHPWG_ROOT_PATH.'admin/include/uploadify'; |
---|
57 | |
---|
58 | $upload_max_filesize = min( |
---|
59 | get_ini_size('upload_max_filesize'), |
---|
60 | get_ini_size('post_max_size') |
---|
61 | ); |
---|
62 | |
---|
63 | if ($upload_max_filesize == get_ini_size('upload_max_filesize')) |
---|
64 | { |
---|
65 | $upload_max_filesize_shorthand = get_ini_size('upload_max_filesize', false); |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | $upload_max_filesize_shorthand = get_ini_size('post_max_filesize', false); |
---|
70 | } |
---|
71 | |
---|
72 | $template->assign( |
---|
73 | array( |
---|
74 | 'F_ADD_ACTION'=> PHOTOS_ADD_BASE_URL, |
---|
75 | 'uploadify_path' => $uploadify_path, |
---|
76 | 'upload_max_filesize' => $upload_max_filesize, |
---|
77 | 'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand, |
---|
78 | ) |
---|
79 | ); |
---|
80 | |
---|
81 | // what is the maximum number of pixels permitted by the memory_limit? |
---|
82 | if (pwg_image::get_library() == 'gd') |
---|
83 | { |
---|
84 | $fudge_factor = 1.7; |
---|
85 | $available_memory = get_ini_size('memory_limit') - memory_get_usage(); |
---|
86 | $max_upload_width = round(sqrt($available_memory/(2 * $fudge_factor))); |
---|
87 | $max_upload_height = round(2 * $max_upload_width / 3); |
---|
88 | |
---|
89 | // we don't want dimensions like 2995x1992 but 3000x2000 |
---|
90 | $max_upload_width = round($max_upload_width/100)*100; |
---|
91 | $max_upload_height = round($max_upload_height/100)*100; |
---|
92 | |
---|
93 | $max_upload_resolution = floor($max_upload_width * $max_upload_height / (1000000)); |
---|
94 | |
---|
95 | // no need to display a limitation warning if the limitation is huge like 20MP |
---|
96 | if ($max_upload_resolution < 25) |
---|
97 | { |
---|
98 | $template->assign( |
---|
99 | array( |
---|
100 | 'max_upload_width' => $max_upload_width, |
---|
101 | 'max_upload_height' => $max_upload_height, |
---|
102 | 'max_upload_resolution' => $max_upload_resolution, |
---|
103 | ) |
---|
104 | ); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | $upload_modes = array('html', 'multiple'); |
---|
109 | $upload_mode = isset($conf['upload_mode']) ? $conf['upload_mode'] : 'multiple'; |
---|
110 | |
---|
111 | if (isset($_GET['upload_mode']) and in_array($_GET['upload_mode'], $upload_modes)) |
---|
112 | { |
---|
113 | $upload_mode = $_GET['upload_mode']; |
---|
114 | conf_update_param('upload_mode', $upload_mode); |
---|
115 | } |
---|
116 | |
---|
117 | // what is the upload switch mode |
---|
118 | $index_of_upload_mode = array_flip($upload_modes); |
---|
119 | $upload_mode_index = $index_of_upload_mode[$upload_mode]; |
---|
120 | $upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ]; |
---|
121 | |
---|
122 | $template->assign( |
---|
123 | array( |
---|
124 | 'upload_mode' => $upload_mode, |
---|
125 | 'form_action' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode.'&processed=1', |
---|
126 | 'switch_url' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_switch, |
---|
127 | 'upload_id' => md5(rand()), |
---|
128 | 'session_id' => session_id(), |
---|
129 | 'pwg_token' => get_pwg_token(), |
---|
130 | 'another_upload_link' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode, |
---|
131 | ) |
---|
132 | ); |
---|
133 | |
---|
134 | $upload_file_types = 'jpeg, png, gif'; |
---|
135 | if ('html' == $upload_mode) |
---|
136 | { |
---|
137 | $upload_file_types.= ', zip'; |
---|
138 | } |
---|
139 | $template->assign( |
---|
140 | array( |
---|
141 | 'upload_file_types' => $upload_file_types, |
---|
142 | ) |
---|
143 | ); |
---|
144 | |
---|
145 | // +-----------------------------------------------------------------------+ |
---|
146 | // | Categories | |
---|
147 | // +-----------------------------------------------------------------------+ |
---|
148 | |
---|
149 | // we need to know the category in which the last photo was added |
---|
150 | $selected_category = array(); |
---|
151 | $selected_parent = array(); |
---|
152 | |
---|
153 | $query = ' |
---|
154 | SELECT |
---|
155 | category_id, |
---|
156 | id_uppercat |
---|
157 | FROM '.IMAGES_TABLE.' AS i |
---|
158 | JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id |
---|
159 | JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id |
---|
160 | ORDER BY i.id DESC |
---|
161 | LIMIT 1 |
---|
162 | ;'; |
---|
163 | $result = pwg_query($query); |
---|
164 | if (pwg_db_num_rows($result) > 0) |
---|
165 | { |
---|
166 | $row = pwg_db_fetch_assoc($result); |
---|
167 | |
---|
168 | $selected_category = array($row['category_id']); |
---|
169 | |
---|
170 | if (!empty($row['id_uppercat'])) |
---|
171 | { |
---|
172 | $selected_parent = array($row['id_uppercat']); |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | // existing album |
---|
177 | $query = ' |
---|
178 | SELECT id,name,uppercats,global_rank |
---|
179 | FROM '.CATEGORIES_TABLE.' |
---|
180 | ;'; |
---|
181 | |
---|
182 | display_select_cat_wrapper( |
---|
183 | $query, |
---|
184 | $selected_category, |
---|
185 | 'category_options' |
---|
186 | ); |
---|
187 | |
---|
188 | // new category |
---|
189 | display_select_cat_wrapper( |
---|
190 | $query, |
---|
191 | $selected_parent, |
---|
192 | 'category_parent_options' |
---|
193 | ); |
---|
194 | |
---|
195 | |
---|
196 | // image level options |
---|
197 | $selected_level = isset($_POST['level']) ? $_POST['level'] : 0; |
---|
198 | $template->assign( |
---|
199 | array( |
---|
200 | 'level_options'=> get_privacy_level_options(), |
---|
201 | 'level_options_selected' => array($selected_level) |
---|
202 | ) |
---|
203 | ); |
---|
204 | |
---|
205 | // +-----------------------------------------------------------------------+ |
---|
206 | // | Setup errors/warnings | |
---|
207 | // +-----------------------------------------------------------------------+ |
---|
208 | |
---|
209 | // Errors |
---|
210 | $setup_errors = array(); |
---|
211 | |
---|
212 | $error_message = ready_for_upload_message(); |
---|
213 | if (!empty($error_message)) |
---|
214 | { |
---|
215 | array_push($setup_errors, $error_message); |
---|
216 | } |
---|
217 | |
---|
218 | if (!function_exists('gd_info')) |
---|
219 | { |
---|
220 | array_push($setup_errors, l10n('GD library is missing')); |
---|
221 | } |
---|
222 | |
---|
223 | $template->assign( |
---|
224 | array( |
---|
225 | 'setup_errors'=> $setup_errors, |
---|
226 | ) |
---|
227 | ); |
---|
228 | |
---|
229 | // Warnings |
---|
230 | if (isset($_GET['hide_warnings'])) |
---|
231 | { |
---|
232 | $_SESSION['upload_hide_warnings'] = true; |
---|
233 | } |
---|
234 | |
---|
235 | if (!isset($_SESSION['upload_hide_warnings'])) |
---|
236 | { |
---|
237 | $setup_warnings = array(); |
---|
238 | |
---|
239 | if ($conf['use_exif'] and !function_exists('read_exif_data')) |
---|
240 | { |
---|
241 | array_push( |
---|
242 | $setup_warnings, |
---|
243 | l10n('Exif extension not available, admin should disable exif use') |
---|
244 | ); |
---|
245 | } |
---|
246 | |
---|
247 | if (get_ini_size('upload_max_filesize') > get_ini_size('post_max_size')) |
---|
248 | { |
---|
249 | array_push( |
---|
250 | $setup_warnings, |
---|
251 | sprintf( |
---|
252 | l10n('In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting'), |
---|
253 | get_ini_size('upload_max_filesize', false), |
---|
254 | get_ini_size('post_max_size', false) |
---|
255 | ) |
---|
256 | ); |
---|
257 | } |
---|
258 | |
---|
259 | $template->assign( |
---|
260 | array( |
---|
261 | 'setup_warnings' => $setup_warnings, |
---|
262 | 'hide_warnings_link' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode.'&hide_warnings=1' |
---|
263 | ) |
---|
264 | ); |
---|
265 | } |
---|
266 | |
---|
267 | ?> |
---|