Révision 9a28ac3f
Ajouté par Assos Assos il y a presque 4 ans
drupal7/sites/all/modules/file_entity/file_entity.pages.inc | ||
---|---|---|
63 | 63 |
else { |
64 | 64 |
// For remote files, just redirect the user to that file's actual URL. |
65 | 65 |
$headers['Location'] = file_create_url($file->uri); |
66 |
// If using S3 as a replacement for the file system, default headers |
|
67 |
// for downloading will cause the server to not respond. Remove them. |
|
68 |
if (module_exists('s3fs')) { |
|
69 |
unset($headers['Content-Length']); |
|
70 |
unset($headers['Content-Transfer-Encoding']); |
|
71 |
} |
|
66 | 72 |
foreach ($headers as $name => $value) { |
67 | 73 |
drupal_add_http_header($name, $value); |
68 | 74 |
} |
... | ... | |
127 | 133 |
'#default_value' => isset($form_state['storage']['upload']) ? $form_state['storage']['upload'] : NULL, |
128 | 134 |
); |
129 | 135 |
|
136 |
$form['upload']['#description'] = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($form['upload']['#upload_validators']['file_entity_validate_size_extensions'][0]) . '</strong>')); |
|
137 |
|
|
138 |
// Get list of extensions. |
|
139 |
$extensions = explode("\n", variable_get('file_entity_max_filesize_extensions')); |
|
140 |
|
|
141 |
if (!empty($extensions)) { |
|
142 |
|
|
143 |
$limits = ''; |
|
144 |
|
|
145 |
foreach ($extensions as $position => $text) { |
|
146 |
$matches = array(); |
|
147 |
preg_match('/(.*)\|(.*)/', $text, $matches); |
|
148 |
|
|
149 |
if (is_array($matches) && count($matches) == 3) { |
|
150 |
$extension = $matches[1]; |
|
151 |
$filesize = $matches[2]; |
|
152 |
|
|
153 |
$limits .= $extension . ': ' . $filesize . ','; |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
$limits = rtrim($limits, ','); |
|
158 |
|
|
159 |
$form['upload']['#description'] = t('Files must be less than !size (!limits).', array('!size' => '<strong>' . format_size($form['upload']['#upload_validators']['file_entity_validate_size_extensions'][0]) . '</strong>', '!limits' => $limits)); |
|
160 |
|
|
161 |
} |
|
162 |
|
|
130 | 163 |
$form['actions'] = array('#type' => 'actions'); |
131 | 164 |
$form['actions']['next'] = array( |
132 | 165 |
'#type' => 'submit', |
... | ... | |
138 | 171 |
return $form; |
139 | 172 |
} |
140 | 173 |
|
174 |
function file_entity_validate_size_extensions(stdClass $file, $file_limit = 0, $user_limit = 0) { |
|
175 |
global $user; |
|
176 |
$errors = array(); |
|
177 |
|
|
178 |
// Current file extension. |
|
179 |
$current_extension = pathinfo($file->filename, PATHINFO_EXTENSION); |
|
180 |
|
|
181 |
// Get list of extensions. |
|
182 |
$extensions = explode("\n", variable_get('file_entity_max_filesize_extensions')); |
|
183 |
|
|
184 |
if ($extensions) { |
|
185 |
foreach ($extensions as $position => $text) { |
|
186 |
$matches = array(); |
|
187 |
preg_match('/(.*)\|(.*)/', $text, $matches); |
|
188 |
|
|
189 |
if (is_array($matches) && count($matches) == 3) { |
|
190 |
$extension = $matches[1]; |
|
191 |
$filesize = $matches[2]; |
|
192 |
|
|
193 |
if (strtolower($extension) == strtolower($current_extension)) { |
|
194 |
$file_limit = parse_size($filesize); |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
200 |
if ($file_limit && $file->filesize > $file_limit) { |
|
201 |
$errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit))); |
|
202 |
} |
|
203 |
|
|
204 |
// Save a query by only calling file_space_used() when a limit is provided. |
|
205 |
if ($user_limit && (file_space_used($user->uid) + $file->filesize) > $user_limit) { |
|
206 |
$errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit))); |
|
207 |
} |
|
208 |
|
|
209 |
return $errors; |
|
210 |
} |
|
211 |
|
|
141 | 212 |
/** |
142 | 213 |
* Generate form fields for the second step in the add file wizard. |
143 | 214 |
*/ |
... | ... | |
265 | 336 |
|
266 | 337 |
// Determine all of the locations where a file is used, then loop through the |
267 | 338 |
// occurrences and filter out any duplicates. |
268 |
foreach (file_usage_list($file) as $module => $type) {
|
|
339 |
foreach (file_usage_list($file) as $type) { |
|
269 | 340 |
foreach ($type as $entity_type => $entity_ids) { |
270 | 341 |
// There are cases where the actual entity doesn't exist. |
271 | 342 |
// We have to handle this. |
... | ... | |
277 | 348 |
// additional usage to the total count column in the table row and |
278 | 349 |
// continue on to the next iteration of the loop. |
279 | 350 |
if (isset($occured_entities[$entity_type][$entity_id])) { |
280 |
$rows[$occured_entities[$entity_type][$entity_id]][2] += $count;
|
|
351 |
$rows[$occured_entities[$entity_type][$entity_id]][3] += $count;
|
|
281 | 352 |
continue; |
282 | 353 |
} |
283 | 354 |
|
284 | 355 |
// Retrieve the label and the URI of the entity. |
285 |
$label = empty($entities[$entity_id]) ? $module : entity_label($entity_type, $entities[$entity_id]); |
|
356 |
$label = empty($entities[$entity_id]) ? t('(entity not loaded)') : entity_label($entity_type, $entities[$entity_id]); |
|
357 |
if (empty($label)) { |
|
358 |
$label = t('(entity label not loaded)'); |
|
359 |
} |
|
286 | 360 |
$entity_uri = empty($entities[$entity_id]) ? NULL : entity_uri($entity_type, $entities[$entity_id]); |
287 | 361 |
|
288 | 362 |
// Link the label to the URI when possible. |
289 | 363 |
if (!empty($entity_uri['path']) && $entity_type != 'paragraphs_item') { |
290 |
$entity_label = l($label, $entity_uri['path']); |
|
364 |
if (empty($entity_uri['options'])) { |
|
365 |
$entity_label = l($label, $entity_uri['path']); |
|
366 |
} |
|
367 |
else { |
|
368 |
$entity_label = l($label, $entity_uri['path'], $entity_uri['options']); |
|
369 |
} |
|
291 | 370 |
} |
292 | 371 |
// For paragraphs items, we are searching for usages in nodes. |
293 | 372 |
elseif ($entity_type == 'paragraphs_item') { |
... | ... | |
311 | 390 |
$entity_label = check_plain($label); |
312 | 391 |
} |
313 | 392 |
|
314 |
$rows[] = array($entity_label, $entity_type, $count); |
|
393 |
$rows[] = array( |
|
394 |
$entity_label, |
|
395 |
$entity_id, |
|
396 |
$entity_type, |
|
397 |
$count, |
|
398 |
); |
|
315 | 399 |
|
316 | 400 |
// Record the occurrence of the entity to ensure that it isn't listed in |
317 | 401 |
// the table again. |
... | ... | |
320 | 404 |
} |
321 | 405 |
} |
322 | 406 |
|
323 |
$header = array(t('Entity'), t('Entity type'), t('Use count')); |
|
407 |
$header = array( |
|
408 |
t('Entity label'), |
|
409 |
t('Entity ID'), |
|
410 |
t('Entity type'), |
|
411 |
t('Times this file used by this entity'), |
|
412 |
); |
|
324 | 413 |
$build['usage_table'] = array( |
325 | 414 |
'#theme' => 'table', |
326 | 415 |
'#header' => $header, |
... | ... | |
1149 | 1238 |
} |
1150 | 1239 |
|
1151 | 1240 |
// There is always a file size limit due to the PHP server limit. |
1152 |
$validators['file_validate_size'] = array($max_filesize);
|
|
1241 |
$validators['file_entity_validate_size_extensions'] = array($max_filesize);
|
|
1153 | 1242 |
|
1154 | 1243 |
// Add image validators. |
1155 | 1244 |
$options += array('min_resolution' => 0, 'max_resolution' => 0); |
... | ... | |
1215 | 1304 |
$extract_location = 'temporary://' . $destination; |
1216 | 1305 |
$extract_location = file_destination($extract_location, FILE_EXISTS_RENAME); |
1217 | 1306 |
if (!file_prepare_directory($extract_location, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) { |
1218 |
throw new Exception(t('Unable to prepar, a temporary directory %dir for extraction.', array('%dir' => $extract_location))); |
|
1307 |
throw new Exception(t('Unable to prepare, a temporary directory %dir for extraction.', array('%dir' => $extract_location)));
|
|
1219 | 1308 |
} |
1220 | 1309 |
|
1221 | 1310 |
// Prepare target directory where files are going to be saved. |
1222 | 1311 |
$target_dir = file_default_scheme() . '://' . $destination; |
1223 | 1312 |
$target_dir = file_destination($target_dir, FILE_EXISTS_RENAME); |
1224 | 1313 |
if (!file_prepare_directory($target_dir, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) { |
1225 |
throw new Exception(t('Unable to prepar, a directory %dir for extraction.', array('%dir' => $target_dir))); |
|
1314 |
throw new Exception(t('Unable to prepare, a directory %dir for extraction.', array('%dir' => $target_dir)));
|
|
1226 | 1315 |
} |
1227 | 1316 |
|
1228 | 1317 |
$archiver->extract($extract_location); |
... | ... | |
1254 | 1343 |
// directory hierarchy of the file. |
1255 | 1344 |
$destination = pathinfo($file->uri, PATHINFO_DIRNAME); |
1256 | 1345 |
if (!file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) { |
1257 |
throw new Exception(t('Unable to prepar, a directory %dir for extraction.', array('%dir' => $destination))); |
|
1346 |
throw new Exception(t('Unable to prepare, a directory %dir for extraction.', array('%dir' => $destination)));
|
|
1258 | 1347 |
} |
1259 | 1348 |
|
1260 | 1349 |
if (!file_unmanaged_move($extracted_file->uri, $file->uri)) { |
Formats disponibles : Unified diff
Weekly update of contrib modules