updated core to 7.73
This commit is contained in:
@@ -92,6 +92,7 @@ function file_field_instance_settings_form($field, $instance) {
|
||||
'#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
|
||||
'#element_validate' => array('_file_generic_settings_extensions'),
|
||||
'#weight' => 1,
|
||||
'#maxlength' => 256,
|
||||
// By making this field required, we prevent a potential security issue
|
||||
// that would allow files of any type to be uploaded.
|
||||
'#required' => TRUE,
|
||||
@@ -186,7 +187,7 @@ function file_field_load($entity_type, $entities, $field, $instances, $langcode,
|
||||
$items[$id][$delta] = NULL;
|
||||
}
|
||||
else {
|
||||
$items[$id][$delta] = array_merge($item, (array) $files[$item['fid']]);
|
||||
$items[$id][$delta] = array_merge((array) $files[$item['fid']], $item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,8 +216,16 @@ function file_field_presave($entity_type, $entity, $field, $instance, $langcode,
|
||||
// Make sure that each file which will be saved with this object has a
|
||||
// permanent status, so that it will not be removed when temporary files are
|
||||
// cleaned up.
|
||||
foreach ($items as $item) {
|
||||
foreach ($items as $delta => $item) {
|
||||
if (empty($item['fid'])) {
|
||||
unset($items[$delta]);
|
||||
continue;
|
||||
}
|
||||
$file = file_load($item['fid']);
|
||||
if (empty($file)) {
|
||||
unset($items[$delta]);
|
||||
continue;
|
||||
}
|
||||
if (!$file->status) {
|
||||
$file->status = FILE_STATUS_PERMANENT;
|
||||
file_save($file);
|
||||
@@ -243,6 +252,12 @@ function file_field_insert($entity_type, $entity, $field, $instance, $langcode,
|
||||
* Checks for files that have been removed from the object.
|
||||
*/
|
||||
function file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
// Check whether the field is defined on the object.
|
||||
if (!isset($entity->{$field['field_name']})) {
|
||||
// We cannot check for removed files if the field is not defined.
|
||||
return;
|
||||
}
|
||||
|
||||
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
|
||||
// On new revisions, all files are considered to be a new usage and no
|
||||
@@ -584,7 +599,7 @@ function file_field_widget_value($element, $input = FALSE, $form_state) {
|
||||
// If the display field is present make sure its unchecked value is saved.
|
||||
$field = field_widget_field($element, $form_state);
|
||||
if (empty($input['display'])) {
|
||||
$input['display'] = $field['settings']['display_field'] ? 0 : 1;
|
||||
$input['display'] = !empty($field['settings']['display_field']) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,7 +632,7 @@ function file_field_widget_process($element, &$form_state, $form) {
|
||||
$element['#theme'] = 'file_widget';
|
||||
|
||||
// Add the display field if enabled.
|
||||
if (!empty($field['settings']['display_field']) && $item['fid']) {
|
||||
if (!empty($field['settings']['display_field'])) {
|
||||
$element['display'] = array(
|
||||
'#type' => empty($item['fid']) ? 'hidden' : 'checkbox',
|
||||
'#title' => t('Include file in display'),
|
||||
@@ -760,7 +775,7 @@ function file_field_widget_submit($form, &$form_state) {
|
||||
$langcode = $element['#language'];
|
||||
$parents = $element['#field_parents'];
|
||||
|
||||
$submitted_values = drupal_array_get_nested_value($form_state['values'], array_slice($button['#array_parents'], 0, -2));
|
||||
$submitted_values = drupal_array_get_nested_value($form_state['values'], array_slice($button['#parents'], 0, -2));
|
||||
foreach ($submitted_values as $delta => $submitted_value) {
|
||||
if (!$submitted_value['fid']) {
|
||||
unset($submitted_values[$delta]);
|
||||
@@ -771,7 +786,7 @@ function file_field_widget_submit($form, &$form_state) {
|
||||
$submitted_values = array_values($submitted_values);
|
||||
|
||||
// Update form_state values.
|
||||
drupal_array_set_nested_value($form_state['values'], array_slice($button['#array_parents'], 0, -2), $submitted_values);
|
||||
drupal_array_set_nested_value($form_state['values'], array_slice($button['#parents'], 0, -2), $submitted_values);
|
||||
|
||||
// Update items.
|
||||
$field_state = field_form_get_state($parents, $field_name, $langcode, $form_state);
|
||||
|
||||
@@ -6,8 +6,7 @@ core = 7.x
|
||||
dependencies[] = field
|
||||
files[] = tests/file.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-04-03
|
||||
version = "7.22"
|
||||
; Information added by Drupal.org packaging script on 2020-09-16
|
||||
version = "7.73"
|
||||
project = "drupal"
|
||||
datestamp = "1365027012"
|
||||
|
||||
datestamp = "1600272641"
|
||||
|
||||
@@ -83,7 +83,7 @@ Drupal.file = Drupal.file || {
|
||||
'%filename': this.value.replace('C:\\fakepath\\', ''),
|
||||
'%extensions': extensionPattern.replace(/\|/g, ', ')
|
||||
});
|
||||
$(this).closest('div.form-managed-file').prepend('<div class="messages error file-upload-js-error">' + error + '</div>');
|
||||
$(this).closest('div.form-managed-file').prepend('<div class="messages error file-upload-js-error" aria-live="polite">' + error + '</div>');
|
||||
this.value = '';
|
||||
return false;
|
||||
}
|
||||
|
||||
+115
-19
@@ -92,7 +92,7 @@ function file_theme() {
|
||||
'variables' => array('file' => NULL, 'icon_directory' => NULL),
|
||||
),
|
||||
'file_icon' => array(
|
||||
'variables' => array('file' => NULL, 'icon_directory' => NULL),
|
||||
'variables' => array('file' => NULL, 'icon_directory' => NULL, 'alt' => ''),
|
||||
),
|
||||
'file_managed_file' => array(
|
||||
'render element' => 'element',
|
||||
@@ -140,14 +140,15 @@ function file_file_download($uri, $field_type = 'file') {
|
||||
}
|
||||
|
||||
// Find out which (if any) fields of this type contain the file.
|
||||
$references = file_get_file_references($file, NULL, FIELD_LOAD_CURRENT, $field_type);
|
||||
$references = file_get_file_references($file, NULL, FIELD_LOAD_CURRENT, $field_type, FALSE);
|
||||
|
||||
// Stop processing if there are no references in order to avoid returning
|
||||
// headers for files controlled by other modules. Make an exception for
|
||||
// temporary files where the host entity has not yet been saved (for example,
|
||||
// an image preview on a node/add form) in which case, allow download by the
|
||||
// file's owner.
|
||||
if (empty($references) && ($file->status == FILE_STATUS_PERMANENT || $file->uid != $user->uid)) {
|
||||
// file's owner. For anonymous file owners, only the browser session that
|
||||
// uploaded the file should be granted access.
|
||||
if (empty($references) && ($file->status == FILE_STATUS_PERMANENT || $file->uid != $user->uid || (!$user->uid && empty($_SESSION['anonymous_allowed_file_ids'][$file->fid])))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -238,6 +239,9 @@ function file_ajax_upload() {
|
||||
$form_parents = func_get_args();
|
||||
$form_build_id = (string) array_pop($form_parents);
|
||||
|
||||
// Sanitize form parents before using them.
|
||||
$form_parents = array_filter($form_parents, 'element_child');
|
||||
|
||||
if (empty($_POST['form_build_id']) || $form_build_id != $_POST['form_build_id']) {
|
||||
// Invalid request.
|
||||
drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error');
|
||||
@@ -246,7 +250,7 @@ function file_ajax_upload() {
|
||||
return array('#type' => 'ajax', '#commands' => $commands);
|
||||
}
|
||||
|
||||
list($form, $form_state) = ajax_get_form();
|
||||
list($form, $form_state, $form_id, $form_build_id, $commands) = ajax_get_form();
|
||||
|
||||
if (!$form) {
|
||||
// Invalid form_build_id.
|
||||
@@ -280,11 +284,11 @@ function file_ajax_upload() {
|
||||
$form['#suffix'] .= '<span class="ajax-new-content"></span>';
|
||||
}
|
||||
|
||||
$output = theme('status_messages') . drupal_render($form);
|
||||
$form['#prefix'] .= theme('status_messages');
|
||||
$output = drupal_render($form);
|
||||
$js = drupal_add_js();
|
||||
$settings = call_user_func_array('array_merge_recursive', $js['settings']['data']);
|
||||
$settings = drupal_array_merge_deep_array($js['settings']['data']);
|
||||
|
||||
$commands = array();
|
||||
$commands[] = ajax_command_replace(NULL, $output, $settings);
|
||||
return array('#type' => 'ajax', '#commands' => $commands);
|
||||
}
|
||||
@@ -358,6 +362,10 @@ function file_file_delete($file) {
|
||||
* support for a default value.
|
||||
*/
|
||||
function file_managed_file_process($element, &$form_state, $form) {
|
||||
// Append the '-upload' to the #id so the field label's 'for' attribute
|
||||
// corresponds with the file element.
|
||||
$original_id = $element['#id'];
|
||||
$element['#id'] .= '-upload';
|
||||
$fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0;
|
||||
|
||||
// Set some default element properties.
|
||||
@@ -367,7 +375,7 @@ function file_managed_file_process($element, &$form_state, $form) {
|
||||
|
||||
$ajax_settings = array(
|
||||
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
|
||||
'wrapper' => $element['#id'] . '-ajax-wrapper',
|
||||
'wrapper' => $original_id . '-ajax-wrapper',
|
||||
'effect' => 'fade',
|
||||
'progress' => array(
|
||||
'type' => $element['#progress_indicator'],
|
||||
@@ -454,6 +462,17 @@ function file_managed_file_process($element, &$form_state, $form) {
|
||||
'#markup' => theme('file_link', array('file' => $element['#file'])) . ' ',
|
||||
'#weight' => -10,
|
||||
);
|
||||
// Anonymous users who have uploaded a temporary file need a
|
||||
// non-session-based token added so file_managed_file_value() can check
|
||||
// that they have permission to use this file on subsequent submissions of
|
||||
// the same form (for example, after an Ajax upload or form validation
|
||||
// error).
|
||||
if (!$GLOBALS['user']->uid && $element['#file']->status != FILE_STATUS_PERMANENT) {
|
||||
$element['fid_token'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => drupal_hmac_base64('file-' . $fid, drupal_get_private_key() . drupal_get_hash_salt()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the extension list to the page as JavaScript settings.
|
||||
@@ -462,13 +481,13 @@ function file_managed_file_process($element, &$form_state, $form) {
|
||||
$element['upload']['#attached']['js'] = array(
|
||||
array(
|
||||
'type' => 'setting',
|
||||
'data' => array('file' => array('elements' => array('#' . $element['#id'] . '-upload' => $extension_list)))
|
||||
'data' => array('file' => array('elements' => array('#' . $element['#id'] => $extension_list)))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Prefix and suffix used for Ajax replacement.
|
||||
$element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper">';
|
||||
$element['#prefix'] = '<div id="' . $original_id . '-ajax-wrapper">';
|
||||
$element['#suffix'] = '</div>';
|
||||
|
||||
return $element;
|
||||
@@ -479,6 +498,7 @@ function file_managed_file_process($element, &$form_state, $form) {
|
||||
*/
|
||||
function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL) {
|
||||
$fid = 0;
|
||||
$force_default = FALSE;
|
||||
|
||||
// Find the current value of this field from the form state.
|
||||
$form_state_fid = $form_state['values'];
|
||||
@@ -511,15 +531,51 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL)
|
||||
$callback($element, $input, $form_state);
|
||||
}
|
||||
}
|
||||
// Load file if the FID has changed to confirm it exists.
|
||||
if (isset($input['fid']) && $file = file_load($input['fid'])) {
|
||||
$fid = $file->fid;
|
||||
// If a FID was submitted, load the file (and check access if it's not a
|
||||
// public file) to confirm it exists and that the current user has access
|
||||
// to it.
|
||||
if (isset($input['fid']) && ($file = file_load($input['fid']))) {
|
||||
// By default the public:// file scheme provided by Drupal core is the
|
||||
// only one that allows files to be publicly accessible to everyone, so
|
||||
// it is the only one for which the file access checks are bypassed.
|
||||
// Other modules which provide publicly accessible streams of their own
|
||||
// in hook_stream_wrappers() can add the corresponding scheme to the
|
||||
// 'file_public_schema' variable to bypass file access checks for those
|
||||
// as well. This should only be done for schemes that are completely
|
||||
// publicly accessible, with no download restrictions; for security
|
||||
// reasons all other schemes must go through the file_download_access()
|
||||
// check.
|
||||
if (!in_array(file_uri_scheme($file->uri), variable_get('file_public_schema', array('public'))) && !file_download_access($file->uri)) {
|
||||
$force_default = TRUE;
|
||||
}
|
||||
// Temporary files that belong to other users should never be allowed.
|
||||
elseif ($file->status != FILE_STATUS_PERMANENT) {
|
||||
if ($GLOBALS['user']->uid && $file->uid != $GLOBALS['user']->uid) {
|
||||
$force_default = TRUE;
|
||||
}
|
||||
// Since file ownership can't be determined for anonymous users, they
|
||||
// are not allowed to reuse temporary files at all. But they do need
|
||||
// to be able to reuse their own files from earlier submissions of
|
||||
// the same form, so to allow that, check for the token added by
|
||||
// file_managed_file_process().
|
||||
elseif (!$GLOBALS['user']->uid) {
|
||||
$token = drupal_array_get_nested_value($form_state['input'], array_merge($element['#parents'], array('fid_token')));
|
||||
if ($token !== drupal_hmac_base64('file-' . $file->fid, drupal_get_private_key() . drupal_get_hash_salt())) {
|
||||
$force_default = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If all checks pass, allow the file to be changed.
|
||||
if (!$force_default) {
|
||||
$fid = $file->fid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no input, set the default value.
|
||||
else {
|
||||
// If there is no input or if the default value was requested above, use the
|
||||
// default value.
|
||||
if ($input === FALSE || $force_default) {
|
||||
if ($element['#extended']) {
|
||||
$default_fid = isset($element['#default_value']['fid']) ? $element['#default_value']['fid'] : 0;
|
||||
$return = isset($element['#default_value']) ? $element['#default_value'] : array('fid' => 0);
|
||||
@@ -725,7 +781,32 @@ function theme_file_link($variables) {
|
||||
$icon_directory = $variables['icon_directory'];
|
||||
|
||||
$url = file_create_url($file->uri);
|
||||
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
|
||||
|
||||
// Human-readable names, for use as text-alternatives to icons.
|
||||
$mime_name = array(
|
||||
'application/msword' => t('Microsoft Office document icon'),
|
||||
'application/vnd.ms-excel' => t('Office spreadsheet icon'),
|
||||
'application/vnd.ms-powerpoint' => t('Office presentation icon'),
|
||||
'application/pdf' => t('PDF icon'),
|
||||
'video/quicktime' => t('Movie icon'),
|
||||
'audio/mpeg' => t('Audio icon'),
|
||||
'audio/wav' => t('Audio icon'),
|
||||
'image/jpeg' => t('Image icon'),
|
||||
'image/png' => t('Image icon'),
|
||||
'image/gif' => t('Image icon'),
|
||||
'application/zip' => t('Package icon'),
|
||||
'text/html' => t('HTML icon'),
|
||||
'text/plain' => t('Plain text icon'),
|
||||
'application/octet-stream' => t('Binary Data'),
|
||||
);
|
||||
|
||||
$mimetype = file_get_mimetype($file->uri);
|
||||
|
||||
$icon = theme('file_icon', array(
|
||||
'file' => $file,
|
||||
'icon_directory' => $icon_directory,
|
||||
'alt' => !empty($mime_name[$mimetype]) ? $mime_name[$mimetype] : t('File'),
|
||||
));
|
||||
|
||||
// Set options as per anchor format described at
|
||||
// http://microformats.org/wiki/file-format-examples
|
||||
@@ -755,16 +836,19 @@ function theme_file_link($variables) {
|
||||
* - file: A file object for which to make an icon.
|
||||
* - icon_directory: (optional) A path to a directory of icons to be used for
|
||||
* files. Defaults to the value of the "file_icon_directory" variable.
|
||||
* - alt: (optional) The alternative text to represent the icon in text-based
|
||||
* browsers. Defaults to an empty string.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_file_icon($variables) {
|
||||
$file = $variables['file'];
|
||||
$alt = $variables['alt'];
|
||||
$icon_directory = $variables['icon_directory'];
|
||||
|
||||
$mime = check_plain($file->filemime);
|
||||
$icon_url = file_icon_url($file, $icon_directory);
|
||||
return '<img class="file-icon" alt="" title="' . $mime . '" src="' . $icon_url . '" />';
|
||||
return '<img class="file-icon" alt="' . check_plain($alt) . '" title="' . $mime . '" src="' . $icon_url . '" />';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -986,11 +1070,18 @@ function file_icon_map($file) {
|
||||
* @param $field_type
|
||||
* (optional) The name of a field type. If given, limits the reference check
|
||||
* to fields of the given type.
|
||||
* @param $check_access
|
||||
* (optional) A boolean that specifies whether the permissions of the current
|
||||
* user should be checked when retrieving references. If FALSE, all
|
||||
* references to the file are returned. If TRUE, only references from
|
||||
* entities that the current user has access to are returned. Defaults to
|
||||
* TRUE for backwards compatibility reasons, but FALSE is recommended for
|
||||
* most situations.
|
||||
*
|
||||
* @return
|
||||
* An integer value.
|
||||
*/
|
||||
function file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file') {
|
||||
function file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file', $check_access = TRUE) {
|
||||
$references = drupal_static(__FUNCTION__, array());
|
||||
$fields = isset($field) ? array($field['field_name'] => $field) : field_info_fields();
|
||||
|
||||
@@ -1001,6 +1092,11 @@ function file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISI
|
||||
$query
|
||||
->fieldCondition($file_field, 'fid', $file->fid)
|
||||
->age($age);
|
||||
if (!$check_access) {
|
||||
// Neutralize the 'entity_field_access' query tag added by
|
||||
// field_sql_storage_field_storage_query().
|
||||
$query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
|
||||
}
|
||||
$references[$field_name] = $query->execute();
|
||||
}
|
||||
}
|
||||
|
||||
+853
-90
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,7 @@ version = VERSION
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-04-03
|
||||
version = "7.22"
|
||||
; Information added by Drupal.org packaging script on 2020-09-16
|
||||
version = "7.73"
|
||||
project = "drupal"
|
||||
datestamp = "1365027012"
|
||||
|
||||
datestamp = "1600272641"
|
||||
|
||||
@@ -67,3 +67,18 @@ function file_module_test_form_submit($form, &$form_state) {
|
||||
}
|
||||
drupal_set_message(t('The file id is %fid.', array('%fid' => $fid)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_download().
|
||||
*/
|
||||
function file_module_test_file_download($uri) {
|
||||
if (variable_get('file_module_test_grant_download_access')) {
|
||||
// Mimic what file_get_content_headers() would do if we had a full $file
|
||||
// object to pass to it.
|
||||
return array(
|
||||
'Content-Type' => mime_header_encode(file_get_mimetype($uri)),
|
||||
'Content-Length' => filesize($uri),
|
||||
'Cache-Control' => 'private',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user