source: trunk/admin/include/photos_add_direct_prepare.inc.php @ 25312

Last change on this file since 25312 was 25018, checked in by mistic100, 11 years ago

remove all array_push (50% slower than []) + some changes missing for feature:2978

File size: 8.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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
29if (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
63if ($upload_max_filesize == get_ini_size('upload_max_filesize'))
64{
65  $upload_max_filesize_shorthand = get_ini_size('upload_max_filesize', false);
66}
67else
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?
82if (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//warn the user if the picture will be resized after upload
109if ($conf['original_resize'])
110{
111  $template->assign(
112    array(
113        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
114        'original_resize_maxheight' => $conf['original_resize_maxheight'],
115      )
116    );
117}
118
119
120$upload_modes = array('html', 'multiple');
121$upload_mode = isset($conf['upload_mode']) ? $conf['upload_mode'] : 'multiple';
122
123if (isset($_GET['upload_mode']) and $upload_mode != $_GET['upload_mode'] and in_array($_GET['upload_mode'], $upload_modes))
124{
125  $upload_mode = $_GET['upload_mode'];
126  conf_update_param('upload_mode', $upload_mode);
127}
128
129// what is the upload switch mode
130$index_of_upload_mode = array_flip($upload_modes);
131$upload_mode_index = $index_of_upload_mode[$upload_mode];
132$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ];
133
134$template->assign(
135    array(
136      'upload_mode' => $upload_mode,
137      'form_action' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;processed=1',
138      'switch_url' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_switch,
139      'upload_id' => md5(rand()),
140      'session_id' => session_id(),
141      'pwg_token' => get_pwg_token(),
142      'another_upload_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode,
143    )
144  );
145
146$upload_file_types = 'jpeg, png, gif';
147if ('html' == $upload_mode)
148{
149  $upload_file_types.= ', zip';
150}
151$template->assign(
152  array(
153    'upload_file_types' => $upload_file_types,
154    )
155  );
156
157// +-----------------------------------------------------------------------+
158// | Categories                                                            |
159// +-----------------------------------------------------------------------+
160
161// we need to know the category in which the last photo was added
162$selected_category = array();
163
164$query = '
165SELECT category_id
166  FROM '.IMAGES_TABLE.' AS i
167    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id
168    JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id
169  ORDER BY i.id DESC
170  LIMIT 1
171;';
172$result = pwg_query($query);
173if (pwg_db_num_rows($result) > 0)
174{
175  $row = pwg_db_fetch_assoc($result);
176 
177  $selected_category = array($row['category_id']);
178}
179
180// existing album
181$query = '
182SELECT id,name,uppercats,global_rank
183  FROM '.CATEGORIES_TABLE.'
184;';
185
186display_select_cat_wrapper(
187  $query,
188  $selected_category,
189  'category_options'
190  );
191
192
193// image level options
194$selected_level = isset($_POST['level']) ? $_POST['level'] : 0;
195$template->assign(
196    array(
197      'level_options'=> get_privacy_level_options(),
198      'level_options_selected' => array($selected_level)
199    )
200  );
201
202// +-----------------------------------------------------------------------+
203// | Setup errors/warnings                                                 |
204// +-----------------------------------------------------------------------+
205
206// Errors
207$setup_errors = array();
208
209$error_message = ready_for_upload_message();
210if (!empty($error_message))
211{
212  $setup_errors[] = $error_message;
213}
214
215if (!function_exists('gd_info'))
216{
217  $setup_errors[] = l10n('GD library is missing');
218}
219
220$template->assign(
221  array(
222    'setup_errors'=> $setup_errors,
223    )
224  );
225
226// Warnings
227if (isset($_GET['hide_warnings']))
228{
229  $_SESSION['upload_hide_warnings'] = true;
230}
231
232if (!isset($_SESSION['upload_hide_warnings']))
233{
234  $setup_warnings = array();
235 
236  if ($conf['use_exif'] and !function_exists('read_exif_data'))
237  {
238    $setup_warnings[] = l10n('Exif extension not available, admin should disable exif use');
239  }
240
241  if (get_ini_size('upload_max_filesize') > get_ini_size('post_max_size'))
242  {
243    $setup_warnings[] = l10n(
244      'In your php.ini file, the upload_max_filesize (%sB) is bigger than post_max_size (%sB), you should change this setting',
245      get_ini_size('upload_max_filesize', false),
246      get_ini_size('post_max_size', false)
247      );
248  }
249  $template->assign(
250    array(
251      'setup_warnings' => $setup_warnings,
252      'hide_warnings_link' => PHOTOS_ADD_BASE_URL.'&amp;upload_mode='.$upload_mode.'&amp;hide_warnings=1'
253      )
254    );
255}
256
257?>
Note: See TracBrowser for help on using the repository browser.